The following lines contain the word 'select', 'insert', 'update' or 'delete':
SELECT COUNT(DISTINCT ai.invoice_id)
INTO l_affected_invoices
FROM ap_invoices_all ai, ap_payment_schedules_all aps
WHERE aps.external_bank_account_id = p_external_bank_account_id
AND ai.invoice_id = aps.invoice_id
-- AND ai.payment_status_flag IN ('N','P') /* Bug 11783234 Exclude 'partial paid payment schedules' status */
AND ai.payment_status_flag = 'N'
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
AND ai.org_id = p_org_id
AND (ai.party_site_id = p_party_site_id
or ( ai.party_site_id is null
and ai.vendor_site_id in (select vendor_site_id
from ap_supplier_sites ass
where ass.party_site_id = p_party_site_id
and ass.vendor_id = p_vendor_id)
)
)
AND aps.checkrun_id IS NULL; /* Bug 11783234 Added condition to remove selected invoices from this API */
SELECT COUNT(DISTINCT ai.invoice_id)
INTO l_affected_invoices
FROM ap_invoices_all ai, ap_payment_schedules_all aps
WHERE aps.external_bank_account_id = p_external_bank_account_id
AND ai.invoice_id = aps.invoice_id
-- AND ai.payment_status_flag IN ('N','P') /* Bug 11783234 Exclude 'partial paid payment schedules' status */
AND ai.payment_status_flag = 'N'
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
AND (ai.party_site_id = p_party_site_id
or ( ai.party_site_id is null
and ai.vendor_site_id in (select vendor_site_id
from ap_supplier_sites ass
where ass.party_site_id = p_party_site_id
and ass.vendor_id = p_vendor_id)
)
)
AND aps.checkrun_id IS NULL; /* Bug 11783234 Added condition to remove selected invoices from this API */
SELECT COUNT(DISTINCT ai.invoice_id)
INTO l_affected_invoices
FROM ap_invoices_all ai, ap_payment_schedules_all aps
WHERE aps.external_bank_account_id = p_external_bank_account_id
AND ai.invoice_id = aps.invoice_id
-- AND ai.payment_status_flag IN ('N','P') /* Bug 11783234 Exclude 'partial paid payment schedules' status */
AND ai.payment_status_flag = 'N'
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
AND ai.vendor_site_id = p_vendor_site_id
AND aps.checkrun_id IS NULL; /* Bug 11783234 Added condition to remove selected invoices from this API */
SELECT COUNT(DISTINCT ai.invoice_id)
INTO l_affected_invoices
FROM ap_invoices_all ai, ap_payment_schedules_all aps
WHERE aps.external_bank_account_id = p_external_bank_account_id
AND ai.invoice_id = aps.invoice_id
-- AND ai.payment_status_flag IN ('N','P') /* Bug 11783234 Exclude 'partial paid payment schedules' status */
AND ai.payment_status_flag = 'N'
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
AND aps.checkrun_id IS NULL; /* Bug 11783234 Added condition to remove selected invoices from this API */
/* Bug 10634847 Added API to return selected invoices for payments count */
FUNCTION Get_Selected_Invoices_Count(
P_external_bank_account_id iby_ext_bank_accounts.ext_bank_account_id%TYPE,
P_vendor_id ap_suppliers.vendor_id%TYPE,
P_vendor_site_id ap_supplier_sites.vendor_site_id%TYPE DEFAULT NULL,
P_party_Site_Id ap_supplier_sites.party_site_id%TYPE DEFAULT NULL,
P_org_id ap_invoices.org_id%TYPE DEFAULT NULL
) RETURN NUMBER IS
l_affected_invoices NUMBER := 0;
l_api_name VARCHAR2(100) := 'Get_Selected_Invoices_Count';
l_debug_info := 'ENTER Get_Selected_Invoices_Count';
SELECT COUNT(DISTINCT ai.invoice_id)
INTO l_affected_invoices
FROM ap_invoices_all ai, ap_payment_schedules_all aps
WHERE aps.external_bank_account_id = p_external_bank_account_id
AND ai.invoice_id = aps.invoice_id
AND ai.payment_status_flag IN ('N','P')
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
AND ai.org_id = p_org_id
AND (ai.party_site_id = p_party_site_id
or ( ai.party_site_id is null
and ai.vendor_site_id in (select vendor_site_id
from ap_supplier_sites ass
where ass.party_site_id = p_party_site_id
and ass.vendor_id = p_vendor_id)
)
)
AND aps.checkrun_id IS NOT NULL;
SELECT COUNT(DISTINCT ai.invoice_id)
INTO l_affected_invoices
FROM ap_invoices_all ai, ap_payment_schedules_all aps
WHERE aps.external_bank_account_id = p_external_bank_account_id
AND ai.invoice_id = aps.invoice_id
AND ai.payment_status_flag IN ('N','P')
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
AND (ai.party_site_id = p_party_site_id
or ( ai.party_site_id is null
and ai.vendor_site_id in (select vendor_site_id
from ap_supplier_sites ass
where ass.party_site_id = p_party_site_id
and ass.vendor_id = p_vendor_id)
)
)
AND aps.checkrun_id IS NOT NULL;
SELECT COUNT(DISTINCT ai.invoice_id)
INTO l_affected_invoices
FROM ap_invoices_all ai, ap_payment_schedules_all aps
WHERE aps.external_bank_account_id = p_external_bank_account_id
AND ai.invoice_id = aps.invoice_id
AND ai.payment_status_flag IN ('N','P')
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
AND ai.vendor_site_id = p_vendor_site_id
AND aps.checkrun_id IS NOT NULL;
SELECT COUNT(DISTINCT ai.invoice_id)
INTO l_affected_invoices
FROM ap_invoices_all ai, ap_payment_schedules_all aps
WHERE aps.external_bank_account_id = p_external_bank_account_id
AND ai.invoice_id = aps.invoice_id
AND ai.payment_status_flag IN ('N','P')
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
AND aps.checkrun_id IS NOT NULL;
l_debug_info := 'Exception occured in Get_Selected_Invoices_Count :'||SQLERRM;
END Get_Selected_Invoices_Count;
PROCEDURE Update_Payment_Schedules (
p_from_bank_account_id iby_ext_bank_accounts.ext_bank_account_id%TYPE,
p_to_bank_account_id iby_ext_bank_accounts.ext_bank_account_id%TYPE,
p_vendor_id ap_suppliers.vendor_id%TYPE,
P_vendor_site_id ap_supplier_sites.vendor_site_id%TYPE DEFAULT NULL,
P_party_Site_Id ap_supplier_sites.party_site_id%TYPE DEFAULT NULL,
P_org_id ap_invoices.org_id%TYPE DEFAULT NULL,
P_party_id ap_suppliers.party_id%TYPE DEFAULT NULL -- Added for bug 9410719
) IS
-- Added for bug 9410719
G_LEVEL_STATEMENT CONSTANT NUMBER := FND_LOG.LEVEL_STATEMENT;
l_api_name VARCHAR2(100) := 'Update_Payment_Schedules';
l_debug_info := 'ENTER Update_Payment_Schedules';
FOR x IN (SELECT aps.invoice_id, aps.payment_num, ai.payment_currency_code, ai.vendor_site_id
FROM ap_payment_schedules_all aps,ap_invoices_all ai
WHERE aps.invoice_id = ai.invoice_id
AND aps.external_bank_account_id = p_from_bank_account_id
-- Added the below two condition for the bug 10401158
AND aps.checkrun_id is NULL
AND nvl(aps.payment_status_flag , 'N') = 'N'
AND ai.payment_status_flag IN ('N','P')
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
AND ai.org_id = p_org_id
AND (ai.party_site_id = p_party_site_id
OR (ai.party_site_id is NULL
AND ai.vendor_site_id in (SELECT vendor_site_id
FROM ap_supplier_sites ass
WHERE ass.party_site_id = p_party_site_id
AND ass.vendor_id = p_vendor_id)
)
)
)
LOOP
BEGIN
IBY_DISBURSE_UI_API_PUB_PKG.get_default_bank_acct(x.payment_currency_code,
P_party_id,
P_party_Site_Id,
x.vendor_site_id,
P_org_id,
P_org_type,
P_pmt_function,
p_from_bank_account_id,
l_to_bank_account_id
);
UPDATE ap_payment_schedules_all aps
SET aps.external_bank_account_id = l_to_bank_account_id,
last_update_date = SYSDATE,
last_updated_by = FND_GLOBAL.user_id,
last_update_login = FND_GLOBAL.login_id
WHERE aps.invoice_id = x.invoice_id -- Added and commented below code for bug 9410719
AND aps.payment_num = x.payment_num;
--Bug10065192: Update the bank at invoice header level, so recalculation of
--payment schedules does not reinstate the inactive bank
UPDATE ap_invoices_all ai
SET ai.external_bank_account_id = l_to_bank_account_id,
ai.last_update_date = SYSDATE,
ai.last_updated_by = FND_GLOBAL.user_id,
ai.last_update_login = FND_GLOBAL.login_id
WHERE ai.invoice_id = x.invoice_id;
(SELECT DISTINCT ai.invoice_id
FROM ap_invoices_all ai, ap_payment_schedules_all aps
WHERE aps.external_bank_account_id = p_from_bank_account_id
AND ai.invoice_id = aps.invoice_id
AND ai.payment_status_flag IN ('N','P')
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
AND ai.org_id = p_org_id
AND (ai.party_site_id = p_party_site_id
or ( ai.party_site_id is null
and ai.vendor_site_id in (select vendor_site_id
from ap_supplier_sites ass
where ass.party_site_id = p_party_site_id
and ass.vendor_id = p_vendor_id)
)
)
);
FOR x IN (SELECT aps.invoice_id, aps.payment_num, ai.payment_currency_code, ai.vendor_site_id, ai.org_id
FROM ap_payment_schedules_all aps,ap_invoices_all ai
WHERE aps.invoice_id = ai.invoice_id
AND aps.external_bank_account_id = p_from_bank_account_id
-- Added the below two condition for the bug 10401158
AND aps.checkrun_id is NULL
AND nvl(aps.payment_status_flag , 'N') = 'N'
AND ai.payment_status_flag IN ('N','P')
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
AND (ai.party_site_id = p_party_site_id
OR (ai.party_site_id IS NULL
AND ai.vendor_site_id IN (SELECT vendor_site_id
FROM ap_supplier_sites ass
WHERE ass.party_site_id = p_party_site_id
AND ass.vendor_id = p_vendor_id)
)
)
)
LOOP
BEGIN
IBY_DISBURSE_UI_API_PUB_PKG.get_default_bank_acct(x.payment_currency_code,
P_party_id,
P_party_Site_Id,
x.vendor_site_id,
x.org_id,
P_org_type,
P_pmt_function,
p_from_bank_account_id,
l_to_bank_account_id
);
UPDATE ap_payment_schedules_all aps
SET aps.external_bank_account_id = l_to_bank_account_id,
last_update_date = SYSDATE,
last_updated_by = FND_GLOBAL.user_id,
last_update_login = FND_GLOBAL.login_id
WHERE aps.invoice_id = x.invoice_id -- Added and commented below code for bug 9410719
AND aps.payment_num = x.payment_num;
--Bug10065192: Update the bank at invoice header level, so recalculation of
--payment schedules does not reinstate the inactive bank
UPDATE ap_invoices_all ai
SET ai.external_bank_account_id = l_to_bank_account_id,
ai.last_update_date = SYSDATE,
ai.last_updated_by = FND_GLOBAL.user_id,
ai.last_update_login = FND_GLOBAL.login_id
WHERE ai.invoice_id = x.invoice_id;
(SELECT DISTINCT ai.invoice_id
FROM ap_invoices_all ai, ap_payment_schedules_all aps
WHERE aps.external_bank_account_id = p_from_bank_account_id
AND ai.invoice_id = aps.invoice_id
AND ai.payment_status_flag IN ('N','P')
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
AND (ai.party_site_id = p_party_site_id
or ( ai.party_site_id is null
and ai.vendor_site_id in (select vendor_site_id
from ap_supplier_sites ass
where ass.party_site_id = p_party_site_id
and ass.vendor_id = p_vendor_id)
)
)
);
FOR x in (SELECT aps.invoice_id, aps.payment_num, ai.payment_currency_code, ai.party_site_id, ai.org_id
FROM ap_payment_schedules_all aps,ap_invoices_all ai
WHERE aps.invoice_id = ai.invoice_id
AND aps.external_bank_account_id = p_from_bank_account_id
-- Added the below two condition for the bug 10401158
AND aps.checkrun_id is NULL
AND nvl(aps.payment_status_flag , 'N') = 'N'
AND ai.payment_status_flag IN ('N','P')
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
AND ai.vendor_site_id = p_vendor_site_id
)
LOOP
BEGIN
IBY_DISBURSE_UI_API_PUB_PKG.get_default_bank_acct(x.payment_currency_code,
P_party_id,
x.party_Site_Id,
P_vendor_site_id,
x.org_id,
P_org_type,
P_pmt_function,
p_from_bank_account_id,
l_to_bank_account_id
);
UPDATE ap_payment_schedules_all aps
SET aps.external_bank_account_id = l_to_bank_account_id,
last_update_date = SYSDATE,
last_updated_by = FND_GLOBAL.user_id,
last_update_login = FND_GLOBAL.login_id
WHERE aps.invoice_id = x.invoice_id -- Added and commented below code for bug 9410719
AND aps.payment_num = x.payment_num;
--Bug10065192: Update the bank at invoice header level, so recalculation of
--payment schedules does not reinstate the inactive bank
UPDATE ap_invoices_all ai
SET ai.external_bank_account_id = l_to_bank_account_id,
ai.last_update_date = SYSDATE,
ai.last_updated_by = FND_GLOBAL.user_id,
ai.last_update_login = FND_GLOBAL.login_id
WHERE ai.invoice_id = x.invoice_id;
(SELECT DISTINCT ai.invoice_id
FROM ap_invoices_all ai, ap_payment_schedules_all aps
WHERE aps.external_bank_account_id = p_from_bank_account_id
AND ai.invoice_id = aps.invoice_id
AND ai.payment_status_flag IN ('N','P')
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
AND ai.vendor_site_id = p_vendor_site_id);
FOR x in (SELECT aps.invoice_id, aps.payment_num, ai.payment_currency_code, ai.party_site_id, ai.org_id, ai.vendor_site_id
FROM ap_payment_schedules_all aps,ap_invoices_all ai
WHERE aps.invoice_id = ai.invoice_id
AND aps.external_bank_account_id = p_from_bank_account_id
-- Added the below two condition for the bug 10401158
AND aps.checkrun_id is NULL
AND nvl(aps.payment_status_flag , 'N') = 'N'
AND ai.payment_status_flag IN ('N','P')
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id
)
LOOP
BEGIN
IBY_DISBURSE_UI_API_PUB_PKG.get_default_bank_acct(x.payment_currency_code,
P_party_id,
x.party_Site_Id,
x.vendor_site_id,
x.org_id,
P_org_type,
P_pmt_function,
p_from_bank_account_id,
l_to_bank_account_id
);
UPDATE ap_payment_schedules_all aps
SET aps.external_bank_account_id = l_to_bank_account_id,
last_update_date = SYSDATE,
last_updated_by = FND_GLOBAL.user_id,
last_update_login = FND_GLOBAL.login_id
WHERE aps.invoice_id = x.invoice_id -- Added and commented below code for bug 9410719
AND aps.payment_num = x.payment_num;
--Bug10065192: Update the bank at invoice header level, so recalculation of
--payment schedules does not reinstate the inactive bank
UPDATE ap_invoices_all ai
SET ai.external_bank_account_id = l_to_bank_account_id,
ai.last_update_date = SYSDATE,
ai.last_updated_by = FND_GLOBAL.user_id,
ai.last_update_login = FND_GLOBAL.login_id
WHERE ai.invoice_id = x.invoice_id;
(SELECT DISTINCT ai.invoice_id
FROM ap_invoices_all ai, ap_payment_schedules_all aps
WHERE aps.external_bank_account_id = p_from_bank_account_id
AND ai.invoice_id = aps.invoice_id
AND ai.payment_status_flag IN ('N','P')
AND ai.cancelled_date IS NULL
AND ai.vendor_id = p_vendor_id)
*/
EXCEPTION
WHEN OTHERS THEN
l_debug_info := 'Exception occured when vendor_id is not null :'||SQLERRM;
END Update_Payment_Schedules;