AR customers pay back this month

Source: Internet
Author: User
Function returnmoneyformula return number is
Rochelle receive_amount1 number;
Rochelle receive_amount2 number;
Returnmoney number;
Begin
Select nvl (sum (acr. functional_amount), 0) -- Payment
Into l_receive_amount1
From ar_cash_receipts_v acr
Where to_char (acr. gl_date, 'yyyy-MM-DD ')
To_char (: startdate, 'yyyy-MM-DD ') and
To_char (: enddate, 'yyyy-MM-DD ')
And acr. state! = 'Reversed'
And acr. customer_id =
(Select a. customer_id
From ar_customers
Where a. customer_number =: customer_number );
Select nvl (sum (araa. amount_applied), 0) -- refund
Into l_receive_amount2
From ar_cash_receipt_history_all acrh,
Ar_cash_receipts_all acr,
Ar_receivable_applications_all araa
Where to_char (acrh. gl_date, 'yyyy-MM-DD ')
To_char (: startdate, 'yyyy-MM-DD ') and
To_char (: enddate, 'yyyy-MM-DD ')
And acrh. status! = 'Reversed'
And acr. cash_receipt_id = acrh. cash_receipt_id
And acrh. cash_receipt_history_id = araa. cash_receipt_history_id
And araa. applied_customer_trx_id is null
And acrh.org _ id = acr.org _ id
And araa. display = 'y'
And araa. status = 'active'
And acr. pay_from_customer =
(Select a. customer_id
From ar_customers
Where a. customer_number =: customer_number );
Returnmoney: = (l_receive_amount1-l_receive_amount2 );
Return nvl (returnmoney, 0 );
End;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.