1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
v_orgid := NULL;
FOR factures IN ( SELECT org_id, set_of_books_id, invoice_id, period_name, check_id
FROM XXBP_PROV_FACTURES_ANNULEES
WHERE code_annulation = 'AT'
ORDER BY org_id
FOR UPDATE
)
LOOP
-- Si on est sur un nouvel org_id ou le premier
IF v_orgid <> factures.org_id OR v_orgid = NULL
THEN
v_orgid := factures.org_id;
XXBP_AP_PROVISIONS_PKG.connection_oa_p(v_orgid);
END IF;
BEGIN
v_result_annulation := AP_CANCEL_PKG.ap_cancel_single_invoice
( P_invoice_id => factures.invoice_id,
P_last_updated_by => 0,
P_last_update_login => 0,
P_set_of_books_id => factures.set_of_books_id,
P_accounting_date => TRUNC(SYSDATE),
P_period_name => factures.period_name,
P_message_name => v_message_name,
P_invoice_amount => v_invoice_amount,
P_base_amount => v_base_amount,
P_tax_amount => v_tax_amount,
P_temp_cancelled_amount => v_temp_cancelled_amount,
P_cancelled_by => v_cancelled_by,
P_cancelled_amount => v_cancelled_amount,
P_cancelled_date => v_cancelled_date,
P_last_update_date => v_last_update_date,
P_original_prepayment_amount => v_original_prepayment_amount,
P_check_id => factures.check_id,
P_pay_curr_invoice_amount => v_pay_curr_invoice_amount,
P_calling_sequence => 'APXINWKB'
);
EXCEPTION
WHEN OTHERS THEN
v_message_name := SQLCODE||' '||SQLERRM;
END;
UPDATE XXBP_PROV_FACTURES_ANNULEES
SET code_annulation = DECODE(v_message_name, NULL, 'OK', 'KO'),
message_annulation = v_message_name
-- Si invoice_id est bien unique.
WHERE CURRENT OF factures;
-- WHERE invoice_id = factures.invoice_id;
UPDATE AP_INVOICE_DISTRIBUTIONS_ALL AIDA
SET global_attribute2 = 'Y'
WHERE cancellation_flag = 'Y'
AND last_updated_by = 0
AND invoice_id = factures.invoice_id;
END LOOP;
COMMIT; |
Partager