Vous êtes sur la page 1sur 4

/

*==================================================================================
================*/
CREATE OR REPLACE PACKAGE xx_ms_receipt_interface_pkg as
PROCEDURE xx_ms_receipt_interface_prc (err_buf OUT VARCHAR2, ret_code OUT
VARCHAR2);
END xx_ms_receipt_interface_pkg;
/

CREATE OR REPLACE PACKAGE BODY xx_ms_receipt_interface_pkg as

PROCEDURE xx_ms_receipt_interface_prc (err_buf OUT VARCHAR2, ret_code OUT VARCHAR2)


IS
CURSOR xx_ms_rcpt_cur
IS (SELECT * FROM xx_stage_receipts_interface WHERE PROCESS_FLAG IN ('N', 'E'));
v_return_status VARCHAR2 (1);
v_msg_count NUMBER;
v_msg_data VARCHAR2 (2000);
v_cr_id NUMBER;
--v_payment_amount NUMBER (30, 5);
v_receipt_method_id NUMBER;
--v_bank_account_id NUMBER;
v_cust_account_id NUMBER;
v_cust_account_number NUMBER;
v_error VARCHAR2 (500);
v_user_id NUMBER;
v_resp_id NUMBER;
v_resp_appl_id NUMBER;
v_total_count NUMBER:=0;
v_count_success NUMBER:=0;
v_count_error NUMBER:=0;
v_attribute_rec AR_RECEIPT_API_PUB.attribute_rec_type;

BEGIN
v_resp_appl_id := fnd_global.resp_appl_id;
v_resp_id := fnd_global.resp_id;
v_user_id := fnd_global.user_id;
mo_global.init('AR');
mo_global.set_policy_context('S','101');
FND_GLOBAL.APPS_INITIALIZE(v_user_id,v_resp_id, v_resp_appl_id);--
(1090,50595,222);
FOR i IN xx_ms_rcpt_cur
LOOP
v_error:=NULL;
v_total_count:=v_total_count+1;
v_attribute_rec.attribute_category := i.attribute_category;
v_attribute_rec.attribute1 := i.attribute1;
v_attribute_rec.attribute2 := i.attribute2;
v_attribute_rec.attribute3 := i.attribute3;
v_attribute_rec.attribute4 := i.attribute4;
v_attribute_rec.attribute5 := i.attribute5;
BEGIN
SELECT cust_account_id, account_number
INTO v_cust_account_id, v_cust_account_number
FROM hz_parties hp, hz_cust_accounts hca
WHERE hca.account_number = i.customer_number
AND hp.party_id = hca.party_id;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
fnd_file.put_line (fnd_file.LOG, 'Customer Not Available');
v_error := v_error || 'Customer Not Available';
END;

BEGIN
SELECT receipt_method_id
INTO v_receipt_method_id
FROM ar_receipt_methods
WHERE receipt_method_id = i.receipt_method_id
AND NVL (i.receipt_date, SYSDATE) BETWEEN start_date AND NVL
(end_date,'31-DEC-4712');
EXCEPTION
WHEN NO_DATA_FOUND
THEN
fnd_file.put_line (fnd_file.LOG, 'Receipt Method Not Available');
v_error := v_error || 'Receipt Method Not Available';
END;

BEGIN
SELECT bank_account_id
INTO v_bank_account_id
FROM ce_bank_accounts ceba
WHERE UPPER(bank_account_name) = UPPER(i.remittance_bank)
AND EXISTS
(SELECT ceausa.bank_account_id
FROM ar_receipt_method_accounts_all arma, ce_bank_acct_uses_all
ceausa
WHERE arma.remit_bank_acct_use_id = ceausa.bank_acct_use_id
AND arma.receipt_method_id = v_receipt_method_id
);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
fnd_file.put_line (fnd_file.LOG, 'Invalid Bank Account');
v_error := v_error || 'Invalid Bank Account';
WHEN TOO_MANY_ROWS
THEN
fnd_file.put_line (fnd_file.LOG, 'Invalid Bank Account');
v_error := v_error || 'Invalid Bank Account';
END;

IF v_error IS NULL
THEN
ar_receipt_api_pub.create_cash
(p_api_version => 1.0,
p_init_msg_list => FND_API.G_TRUE,
p_commit => FND_API.G_FALSE,
p_validation_level =>
FND_API.G_VALID_LEVEL_FULL,
x_return_status => v_return_status,
x_msg_count => v_msg_count,
x_msg_data => v_msg_data,
-- Receipt info. parameters
p_usr_currency_code => NULL, --the
translated currency code
p_currency_code =>
UPPER(i.currency_code),
p_usr_exchange_rate_type => NULL,
p_exchange_rate_type => NULL,
p_exchange_rate => NULL,
p_exchange_rate_date => NULL,
p_amount =>
LTRIM(RTRIM(i.receipt_amount)),
p_factor_discount_amount => NULL,
p_receipt_number =>
LTRIM(RTRIM(i.receipt_number)),
p_receipt_date => i.receipt_date,
p_gl_date => i.gl_date,
p_maturity_date => NULL,
p_postmark_date => NULL,
p_customer_id => NULL,--
v_cust_account_id,
p_customer_name => NULL,
p_customer_number =>
v_cust_account_number,
p_customer_bank_account_id => NULL,
p_customer_bank_account_num => NULL,
p_customer_bank_account_name => NULL,
p_payment_trxn_extension_id => NULL,
p_location => NULL,
p_customer_site_use_id => NULL,
p_default_site_use => NULL,
p_customer_receipt_reference => NULL,
p_override_remit_account_flag => NULL,
p_remittance_bank_account_id => NULL,--
v_bank_account_id,
p_remittance_bank_account_num => NULL,
p_remittance_bank_account_name => NULL,
p_deposit_date => NULL,
p_receipt_method_id =>
v_receipt_method_id,
p_receipt_method_name => NULL,
p_doc_sequence_value => NULL,
p_ussgl_transaction_code => NULL,
p_anticipated_clearing_date => NULL,
p_called_from => NULL,
p_attribute_rec => v_attribute_rec,
-- ******* Global Flexfield parameters *******
p_global_attribute_rec => NULL,
p_comments => NULL,
-- *** Notes Receivable Additional Information ***
p_issuer_name => NULL,
p_issue_date => NULL,
p_issuer_bank_branch_id => NULL,
p_org_id => '101',
p_installment => NULL,
-- ** OUT NOCOPY variables
p_cr_id => v_cr_id);
fnd_file.put_line (fnd_file.LOG, 'Line Number:'||v_total_count ||
v_return_status);
IF v_return_status <> 'S'
THEN
IF NVL (v_msg_count, 0) > 0
THEN
FOR i IN 1 .. v_msg_count
LOOP
v_error := v_error || fnd_msg_pub.get (i, NULL);
END LOOP;

fnd_file.put_line (fnd_file.LOG, 'API Error :' || v_error);


v_count_error:=v_count_error+1;
UPDATE xx_stage_receipts_interface
SET ERROR_TEXT = v_error,
process_flag = 'E'
WHERE trim(upper(customer_number)) = trim(upper(i.customer_number))
AND trim(upper(receipt_number)) = trim(upper(i.receipt_number));
ret_code := 2;
END IF;

ELSE
v_count_success:=v_count_success+1;
UPDATE xx_stage_receipts_interface
SET process_flag = 'S',
ERROR_TEXT = NULL
WHERE trim(upper(customer_number)) = trim(upper(i.customer_number))
AND trim(upper(receipt_number)) = trim(upper(i.receipt_number));
END IF;

ELSE
v_count_error:=v_count_error+1;
--fnd_file.put_line (fnd_file.LOG, 'Record Successfully createdAPI Error :'
|| v_error);
UPDATE xx_stage_receipts_interface
SET process_flag = 'E',
ERROR_TEXT = v_error
WHERE trim(upper(customer_number)) = trim(upper(i.customer_number))
AND trim(upper(receipt_number)) = trim(upper(i.receipt_number));
ret_code := 2;
END IF;
COMMIT;
END LOOP;

FND_FILE.PUT_LINE(FND_FILE.LOG,' *************************** STATISTICS


*******************************');
FND_FILE.PUT_LINE(FND_FILE.LOG,'
');
FND_FILE.PUT_LINE(FND_FILE.LOG,' TOTAL NO. OF RECORDS
' ||(v_total_count));
FND_FILE.PUT_LINE(FND_FILE.LOG,' NO.OF RECORDS INSERTED
' ||(v_count_success));
FND_FILE.PUT_LINE(FND_FILE.LOG,' NO.OF RECORDS FAILED
' ||(v_count_error));
FND_FILE.PUT_LINE(FND_FILE.LOG,'
');
FND_FILE.PUT_LINE(FND_FILE.LOG,' *************************** STATISTICS
*******************************');

COMMIT;

END xx_ms_receipt_interface_prc;

END xx_ms_receipt_interface_pkg;
/

Vous aimerez peut-être aussi