Sie sind auf Seite 1von 4

SELECT DISTINCT a.trx_number trx_number, d.gl_date order_date, /* changed trx date to gl date */ SUBSTR (a.comments || ' ' || a.

ct_reference, 1, 75) remarks, DECODE (b.TYPE, 'INV', 'Invoice', 'CM', 'Credit Memo', 'RCT', 'Receipt' , 'DM','Debit Memo' ) trx_type, a.interface_header_attribute1 || '-' || a.interface_header_attribute2 sales_order_det, --SUM (c.extended_amount * NVL (a.exchange_rate, 1)) debit, sUM (d.AMOUNT * NVL (a.exchange_rate, 1)) debit, 0 credit FROM ra_customer_trx_all a, ra_cust_trx_types b, ra_customer_trx_lines_all c, ra_cust_trx_line_gl_dist_all d /* added to get gl date*/ WHERE a.cust_trx_type_id = b.cust_trx_type_id AND a.customer_trx_id = c.customer_trx_id AND d.customer_trx_line_id = c.customer_trx_line_id AND d.customer_trx_id = a.customer_trx_id AND a.bill_to_customer_id = :p_cust_id AND a.org_id = :p_org_id AND a.complete_flag = 'Y' AND --and d.type='INV' c.extended_amount > 0 AND --a.trx_date between nvl(:p_trx_date_from,a.trx_date) and nvl(:p _trx_date_to,a.trx_date) and d.gl_date BETWEEN NVL (:p_trx_date_from, d.gl_date) AND NVL (:p_trx_date_to, d.gl_date) AND /* added to get gl date */ a.bill_to_site_use_id = NVL (:p_site_use_id, a.bill_to_site_use_id) GROUP BY a.trx_number, d.gl_date, /* changed trx date to gl date */ SUBSTR (a.comments || ' ' || a.ct_reference, 1, 75), a.interface_header_attribute1 || '-' || a.interface_header_attribute2, b.TYPE UNION ALL ------------credit memo ----------------SELECT a.trx_number trx_number, d.gl_date order_date, /* changed trx date to gl date */ SUBSTR (a.comments || ' ' || a.ct_reference, 1, 75) remarks, DECODE (b.TYPE, 'INV', 'Invoice', 'CM', 'Credit Memo', 'RCT', 'Receipt' , 'DM','Debit Memo' ) trx_type, a.interface_header_attribute1 || '-' || a.interface_header_attribute2 sales_order_det, 0 debit, SUM (d.AMOUNT * NVL (a.exchange_rate, 1)) * -1 credit

--SUM (c.extended_amount * NVL (a.exchange_rate, 1)) * -1 credit FROM ra_customer_trx_all a, ra_cust_trx_types b, ra_customer_trx_lines_all c, ra_cust_trx_line_gl_dist_all d /* added to get gl date*/ WHERE a.cust_trx_type_id = b.cust_trx_type_id AND a.customer_trx_id = c.customer_trx_id AND d.customer_trx_line_id = c.customer_trx_line_id AND d.customer_trx_id = a.customer_trx_id AND a.bill_to_customer_id = :p_cust_id AND a.org_id = :p_org_id AND a.complete_flag = 'Y' AND --and d.type='INV' c.extended_amount < 0 AND --a.trx_date between nvl(:p_trx_date_from,a.trx_date) and nvl(:p_trx_da te_to,a.trx_date) and d.gl_date BETWEEN NVL (:p_trx_date_from, d.gl_date) AND NVL (:p_trx_date_to, d.gl_date) AND /* added to get gl date */ a.bill_to_site_use_id = NVL (:p_site_use_id, a.bill_to_site_use_id) GROUP BY a.trx_number, d.gl_date, SUBSTR (a.comments || ' ' || a.ct_reference, 1, 75), a.interface_header_attribute1 || '-' || a.interface_header_attribute2, b.TYPE UNION ALL --Adjust ment Section---/* Added By Shaik.........24-12-2008 (To Bring Positive Adjustment on Debit side & Negative Adjustments on Credit side) */ SELECT a.trx_number trx_number, a.trx_date order_date, SUBSTR (a.comments || ' ' || a.ct_reference, 1, 75) remarks, 'ADJ', a.interface_header_attribute1 || '-' || a.interface_header_attribute2 sales_order_det, -- SUM (c.amount_approved*NVL(a.EXCHANGE_RATE,1)) debit, 0 credit (CASE WHEN c.amount_approved > 0 THEN SUM (c.amount_approved * NVL (a.exchange_rate, 1)) ELSE 0 END ) debit, (CASE WHEN c.amount_approved < 0 THEN SUM (c.amount_approved * NVL (a.exchange_rate, 1)) * -1 ELSE 0 END ) credit ra_customer_trx_all a, ra_cust_trx_types b, ar_adjustments_v c a.cust_trx_type_id = b.cust_trx_type_id a.customer_trx_id = c.customer_trx_id a.bill_to_customer_id = :p_cust_id a.org_id = :p_org_id a.complete_flag = 'Y' c.gl_date BETWEEN NVL (:p_trx_date_from, a.trx_date) AND NVL (:p_trx_date_to, a.trx_date) a.bill_to_site_use_id = NVL (:p_site_use_id, a.bill_to_site_use_id)

FROM WHERE AND AND AND AND AND AND

AND c.status NOT IN ('R', 'U') GROUP BY a.trx_number, a.trx_date, SUBSTR (a.comments || ' ' || a.ct_reference, 1, 75), a.interface_header_attribute1 || '-' || a.interface_header_attribute2, 'ADJ', c.amount_approved UNION ALL -----Receipt Section---SELECT c.receipt_number, c.gl_date, /* changed receipt date to gl date */ c.comments, 'Receipt' rct, c.document_number || ' ' || ' ', 0 debit, -- decode(c.exchange_rate,null,c.amount,(c.amount*nvl(c.exchange_rate,1 ))) -----------functional_amount removed as per vinod request nvl( (SUM ( c.amount * nvl(c.exchange_rate,1))),0) functional_amount /* - NVL ((SELECT SUM (exchange_gain_loss) FROM ar_receivable_applications_v WHERE applied_flag = 'Y' AND cash_receipt_id = c.cash_receipt_id), 0 ) */ FROM ar_cash_receipts_v c WHERE c.customer_id = :p_cust_id AND c.gl_date BETWEEN NVL (:p_trx_date_from, c.gl_date) AND NVL (:p_trx_date_to, c.gl_date) AND /* changed receipt date to gl date */ c.receipt_status NOT IN ('NSF','REV', 'STOP','CC_CHARGEBACK_REV' ) AND c.customer_site_use_id = NVL (:p_site_use_id, c.customer_site_use_id) GROUP BY c.receipt_number, c.gl_date, c.comments, 'RCT', c.document_number || ' ' || ' ', 0 UNION ALL --DISCOUNT SECTION----SELECT c.receipt_number, --c.receipt_date , (SELECT DISTINCT gl_date FROM ar_receivable_applications_all ara WHERE ara.cash_receipt_id = c.cash_receipt_id) receipt_date, c.comments, 'DISC', c.doc_sequence_value || ' ' || ' ', 0 debit, TO_NUMBER (DECODE (SIGN (d.applied_payment_schedule_id), -1, NULL, NVL (d.earned_discount_taken, 0) + NVL (d.unearned_discount_taken, 0) ) ) discount FROM ar_cash_receipts_all c, ar_receivable_applications_all d WHERE c.pay_from_customer = :p_cust_id

AND c.cash_receipt_id = d.cash_receipt_id AND TO_NUMBER (DECODE (SIGN (d.applied_payment_schedule_id), -1, NULL, NVL (d.earned_discount_taken, 0) + NVL (d.unearned_discount_taken, 0) ) ) > 0 --and c.receipt_date between nvl(:p_trx_date_from,c.receipt_date ) and nvl (:p_trx_date_to,c.receipt_date) AND d.gl_date BETWEEN NVL (:p_trx_date_from, d.gl_date) AND NVL (:p_trx_date_to, d.gl_date) /* added to sort by gl date */ AND c.status NOT IN ('NSF','REV', 'STOP','CC_CHARGEBACK_REV') AND c.org_id = :p_org_id AND c.customer_site_use_id = NVL (:p_site_use_id, c.customer_site_use_id) ORDER BY 2, 1

Das könnte Ihnen auch gefallen