EBS ORACLE采购对账单自动产生发票
只要传入个对账单号,然后跑数据抛到接口表,运行接口请求,就可以自动生成发票
create or replace package body pkg_ap_check_by_po is
--创建ap发票
procedure ap_invoices_ap_check(p_ap_no varchar2,
p_import_status OUT number) is
--V_INVOICE_ID number := 0;
--V_INVOICE_LINE_ID NUMBER := 0;
--P_LINE_NUMBER NUMBER := 1;
l_big_zero NUMBER := 0; --T6开头,并且数量大于0
l_small_zero NUMBER := 0; --接收单号是T6开头,并且数量小于0
l_cut_quantity NUMBER := 0; --品质扣款
l_no_po NUMBER := 0; --无PO退货
begin
--代表接收单号是T6开头,并且数量大于0
select count(*)
into l_big_zero
from meg_ap_checklist mac
where mac.receipt_num like 'T6%'
and mac.match_dsp > 0
and mac.ap_no = p_ap_no;
--代表接收单号是T6开头,并且数量小于0
select count(*)
into l_small_zero
from meg_ap_checklist mac
where mac.receipt_num like 'T6%'
and mac.match_dsp < 0
and mac.ap_no = p_ap_no;
--品质扣款
SELECT count(*)
into l_cut_quantity
from meg_ap_checklist mac
where /*mac.receipt_num like 'CM%'
and*/ mac.match_dsp < 0
and mac.item_no in ( '索赔','折让','品质调整','超损扣款')
and mac.ap_no = p_ap_no;
--无PO退货
SELECT count(*)
into l_no_po
from meg_ap_checklist mac
where mac.match_dsp < 0
and mac.receipt_num = '无PO退货'
and mac.ap_no = p_ap_no;
--因为如果存在多种情况,发票编号后缀要加,-1,-2,-3
if l_big_zero > 0 then
--代表接收单号是T6开头,并且数量大于0
pkg_ap_check_by_po.insert_ap_invoices_t6_plus(p_ap_no);
end if;
if l_small_zero > 0 then
--接收单号是T6开头,数量小于0
pkg_ap_check_by_po.insert_ap_invoices_t6_minus(p_ap_no, 1);
ELSif l_small_zero > 0 and l_big_zero = 0 then
pkg_ap_check_by_po.insert_ap_invoices_t6_minus(p_ap_no, 0);
end if;
--品质扣款
if l_cut_quantity > 0 then
if l_small_zero > 0 and l_big_zero > 0 then
--品质扣款
pkg_ap_check_by_po.insert_ap_invoices_cut_qty(p_ap_no, 2);
elsif l_small_zero = 0 and l_big_zero = 0 then
--品质扣款
pkg_ap_check_by_po.insert_ap_invoices_cut_qty(p_ap_no, 0);
else
pkg_ap_check_by_po.insert_ap_invoices_cut_qty(p_ap_no, 1);
end if;
end if;
--无PO
if l_no_po > 0 then
if l_big_zero > 0 and l_small_zero > 0 and l_cut_quantity > 0 then
--无PO退货
pkg_ap_check_by_po.insert_ap_invoices_no_po(p_ap_no, 3);
elsif (l_big_zero > 0 and l_small_zero > 0 and l_cut_quantity = 0) or
(l_big_zero > 0 and l_small_zero = 0 and l_cut_quantity > 0) or
(l_big_zero = 0 and l_small_zero > 0 and l_cut_quantity > 0) then
pkg_ap_check_by_po.insert_ap_invoices_no_po(p_ap_no, 2);
elsif (l_small_zero = 0 and l_cut_quantity = 0 and l_big_zero = 0) then
pkg_ap_check_by_po.insert_ap_invoices_no_po(p_ap_no, 0);
else
pkg_ap_check_by_po.insert_ap_invoices_no_po(p_ap_no, 1);
end if;
end if;
-- commit;
P_IMPORT_STATUS := 1;
EXCEPTION
WHEN OTHERS THEN
P_IMPORT_STATUS := 0;
end;
procedure insert_ap_invoices_t6_plus(p_ap_no varchar2) as
cursor cur_ap(p_ap_no varchar2) is
select rt.transaction_id,
pha.po_header_id,
pla.po_line_id,
pll.line_location_id,
PLL.PO_RELEASE_ID,
pha.org_id,
pla.item_id,
mac.up2, -- mac.up_agree,
mac.match_dsp,
mac.line_num,
mac.match_amt_agree,
mac.rem
FROM RCV_TRANSACTIONS RT,
RCV_SHIPMENT_HEADERS SH,
RCV_SHIPMENT_LINES SL,
PO_LINE_LOCATIONS_ALL PLL,
PO_RELEASES_ALL PRA,
PO_LINES_ALL PLA,
PO_HEADERS_ALL PHA,
PO_VENDORS PV,
PO_VENDOR_SITES_ALL PVSA,
MTL_SYSTEM_ITEMS_B MSI,
meg_ap_checklist mac
WHERE 1 = 1
AND RT.TRANSACTION_TYPE IN ('RECEIVE', 'MATCH')
AND MG_COMM_PUB.GETTRAN_ID(RT.TRANSACTION_ID) > 0
AND MSI.INVENTORY_ITEM_ID = PLA.ITEM_ID
AND MSI.ORGANIZATION_ID = 82
AND SH.RECEIPT_SOURCE_CODE = 'VENDOR'
AND RT.SOURCE_DOCUMENT_CODE = 'PO'
AND RT.PO_HEADER_ID = PLL.PO_HEADER_ID(+)
AND RT.PO_LINE_ID = PLL.PO_LINE_ID(+)
AND RT.PO_LINE_LOCATION_ID = PLL.LINE_LOCATION_ID(+)
AND RT.SHIPMENT_HEADER_ID = SL.SHIPMENT_HEADER_ID
AND RT.SHIPMENT_LINE_ID = SL.SHIPMENT_LINE_ID
AND SL.SHIPMENT_HEADER_ID = SH.SHIPMENT_HEADER_ID
AND PLL.PO_HEADER_ID = PHA.PO_HEADER_ID
AND SL.PO_LINE_LOCATION_ID = PLL.LINE_LOCATION_ID
AND PLL.PO_LINE_ID = PLA.PO_LINE_ID
AND PLL.PO_HEADER_ID = PLA.PO_HEADER_ID
AND PLL.PO_RELEASE_ID = PRA.PO_RELEASE_ID(+)
AND PHA.VENDOR_ID = PV.VENDOR_ID
AND PVSA.VENDOR_ID = PHA.VENDOR_ID
AND PVSA.VENDOR_SITE_ID = PHA.VENDOR_SITE_ID
and rt.transaction_id = mac.transaction_id
and mac.receipt_num like 'T6%'
and mac.match_dsp > 0
and mac.ap_no = p_ap_no;
V_AP_INV_IFC_REC AP_INVOICES_INTERFACE%rowtype;
V_AP_INV_LINE_IFC_TBL_C AP_INVOICE_LINES_INTERFACE%ROWTYPE; --发票行
V_INVOICE_ID number := 0;
V_INVOICE_LINE_ID NUMBER := 0;
P_LINE_NUMBER NUMBER := 1;
begin
SELECT AP_INVOICES_INTERFACE_S.NEXTVAL INTO V_INVOICE_ID FROM DUAL;
select vendor_site_id
INTO V_AP_INV_IFC_REC.VENDOR_SITE_ID
from (select itm,pha.vendor_site_id
from MEG_AP_CHECKLIST mac, po_headers_all pha
where pha.segment1 = mac.po_no
and ap_no = p_ap_no
order by itm)
where rownum=1;
--付款方式
begin
SELECT iepp.payment_method_code
INTO V_AP_INV_IFC_REC.PAYMENT_METHOD_CODE
FROM iby_payment_methods_vl ipmv
, iby_ext_party_pmt_mthds iepp
, iby_external_payees_all iepa
WHERE ipmv.payment_method_code = iepp.payment_method_code(+)
AND iepp.payment_flow = 'DISBURSEMENTS'
AND NVL (ipmv.inactive_date, TRUNC (SYSDATE + 1)) > TRUNC (SYSDATE)
AND iepp.payment_function = 'PAYABLES_DISB'
AND iepp.ext_pmt_party_id = iepa.ext_payee_id
AND iepa.org_id =137
and iepp.primary_flag='Y'
AND iepa.supplier_site_id = V_AP_INV_IFC_REC.VENDOR_SITE_ID;
EXCEPTION
WHEN OTHERS THEN
V_AP_INV_IFC_REC.PAYMENT_METHOD_CODE := 'WIRE';
end ;
select mch.invoice_num,
sum(mac.match_amt_agree),
-- sum(mac.match_amt_agree),
mch.org_id,
pv.VENDOR_ID,
pv.VENDOR_NAME,
pv.SEGMENT1,
pv.INVOICE_CURRENCY_CODE
into V_AP_INV_IFC_REC.INVOICE_NUM,
V_AP_INV_IFC_REC.INVOICE_AMOUNT,
V_AP_INV_IFC_REC.ORG_ID,
V_AP_INV_IFC_REC.VENDOR_ID,
V_AP_INV_IFC_REC.Vendor_Name,
V_AP_INV_IFC_REC.Vendor_Num,
V_AP_INV_IFC_REC.INVOICE_CURRENCY_CODE
from meg_ap_checklist_header mch, meg_ap_checklist mac, po_vendors pv --meg_ap_checklist_header mch, po_vendors pv
where mch.ap_no = p_ap_no
and mch.ap_no = mac.ap_no
and mch.vendor_no = pv.SEGMENT1
and mac.receipt_num like 'T6%'
and mac.match_dsp > 0
group by mch.invoice_num,
mch.org_id,
pv.VENDOR_ID,
pv.VENDOR_NAME,
pv.SEGMENT1,
pv.INVOICE_CURRENCY_CODE;
V_AP_INV_IFC_REC.INVOICE_ID := V_INVOICE_ID; --发票ID
V_AP_INV_IFC_REC.INVOICE_TYPE_LOOKUP_CODE := 'STANDARD'; --发票行类型
V_AP_INV_IFC_REC.SOURCE := 'USE'; --发票来源
V_AP_INV_IFC_REC.INVOICE_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ --trunc(sysdate); --发票日期
V_AP_INV_IFC_REC.CONTROL_AMOUNT := NULL;
V_AP_INV_IFC_REC.EXCHANGE_RATE := NULL;
V_AP_INV_IFC_REC.EXCHANGE_RATE_TYPE := NULL;
V_AP_INV_IFC_REC.EXCHANGE_DATE := NULL;
V_AP_INV_IFC_REC.TERMS_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ -- trunc(sysdate); --条件日期
V_AP_INV_IFC_REC.DESCRIPTION := '应付' ||
V_AP_INV_IFC_REC.Vendor_Name
|| p_ap_no||'入库'; --null; --备注
V_AP_INV_IFC_REC.GROUP_ID := V_INVOICE_ID; --对账单处理批次
-- V_AP_INV_IFC_REC.PAYMENT_METHOD_CODE := 'WIRE';
V_AP_INV_IFC_REC.GL_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ -- trunc(sysdate); --总账日期
V_AP_INV_IFC_REC.CALC_TAX_DURING_IMPORT_FLAG := 'Y';
V_AP_INV_IFC_REC.ADD_TAX_TO_INV_AMT_FLAG := 'Y';
V_AP_INV_IFC_REC.LAST_UPDATE_DATE := trunc(sysdate);
V_AP_INV_IFC_REC.LAST_UPDATED_BY := fnd_global.USER_ID;
V_AP_INV_IFC_REC.LAST_UPDATE_LOGIN := fnd_global.LOGIN_ID;
V_AP_INV_IFC_REC.CREATION_DATE := trunc(sysdate);
V_AP_INV_IFC_REC.CREATED_BY := fnd_global.USER_ID;
--付款条件,负债账户
select assa.terms_id, gccc.code_combination_id
into V_AP_INV_IFC_REC.TERMS_ID,
V_AP_INV_IFC_REC.ACCTS_PAY_CODE_COMBINATION_ID
from ap_suppliers ass,
ap_supplier_sites_all assa,
gl_code_combinations gccc,
gl_code_combinations gccr
where ass.vendor_id = assa.vendor_id
and assa.accts_pay_code_combination_id = gccc.code_combination_id(+)
and assa.prepay_code_combination_id = gccr.code_combination_id(+)
and assa.org_id = V_AP_INV_IFC_REC.ORG_ID
and ass.segment1 = V_AP_INV_IFC_REC.Vendor_Num
and assa.vendor_site_id = V_AP_INV_IFC_REC.VENDOR_SITE_ID;
INSERT INTO AP_INVOICES_INTERFACE VALUES V_AP_INV_IFC_REC; --插入发票
for cursor_ap_no in cur_ap(p_ap_no) loop
SELECT AP_INVOICE_LINES_INTERFACE_S.NEXTVAL
INTO V_INVOICE_LINE_ID
FROM DUAL;
V_AP_INV_LINE_IFC_TBL_C.INVOICE_ID := V_INVOICE_ID; --发票ID
V_AP_INV_LINE_IFC_TBL_C.INVOICE_LINE_ID := V_INVOICE_LINE_ID; --发票行ID
V_AP_INV_LINE_IFC_TBL_C.LINE_NUMBER := P_LINE_NUMBER; --p_LINE_NUMBER; --发票行号
V_AP_INV_LINE_IFC_TBL_C.LINE_TYPE_LOOKUP_CODE := 'ITEM'; --发票行类型
V_AP_INV_LINE_IFC_TBL_C.AMOUNT := cursor_ap_no.MATCH_AMT_AGREE; --p_AMOUNT; --金额
V_AP_INV_LINE_IFC_TBL_C.ACCOUNTING_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ --trunc(sysdate); --记账日期
V_AP_INV_LINE_IFC_TBL_C.DESCRIPTION := '应付' ||
V_AP_INV_IFC_REC.Vendor_Name
|| p_ap_no||'入库';--cursor_ap_no.Rem; --'保险管/保险丝座/10A/磷青铜/镀镍/配套φ5*20mm/T=0.35mm/P=5.1mm/编带'; --发票行描述
V_AP_INV_LINE_IFC_TBL_C.AMOUNT_INCLUDES_TAX_FLAG := 'N';
V_AP_INV_LINE_IFC_TBL_C.TAX_CLASSIFICATION_CODE := '13%(外)'; --税分类代码
V_AP_INV_LINE_IFC_TBL_C.LAST_UPDATED_BY := fnd_global.USER_ID;
V_AP_INV_LINE_IFC_TBL_C.LAST_UPDATE_DATE := trunc(sysdate);
V_AP_INV_LINE_IFC_TBL_C.LAST_UPDATE_LOGIN := fnd_global.USER_ID;
V_AP_INV_LINE_IFC_TBL_C.CREATED_BY := fnd_global.USER_ID;
V_AP_INV_LINE_IFC_TBL_C.CREATION_DATE := trunc(sysdate);
V_AP_INV_LINE_IFC_TBL_C.RCV_TRANSACTION_ID := cursor_ap_no.transaction_id;
V_AP_INV_LINE_IFC_TBL_C.PO_HEADER_ID := cursor_ap_no.PO_HEADER_ID;
V_AP_INV_LINE_IFC_TBL_C.PO_LINE_ID := cursor_ap_no.PO_LINE_ID;
V_AP_INV_LINE_IFC_TBL_C.PO_LINE_LOCATION_ID := cursor_ap_no.line_location_id;
V_AP_INV_LINE_IFC_TBL_C.PO_RELEASE_ID := cursor_ap_no.PO_RELEASE_ID;
V_AP_INV_LINE_IFC_TBL_C.ORG_ID := cursor_ap_no.org_id;
V_AP_INV_LINE_IFC_TBL_C.INVENTORY_ITEM_ID := cursor_ap_no.item_id;
V_AP_INV_LINE_IFC_TBL_C.UNIT_PRICE := cursor_ap_no.up2;
V_AP_INV_LINE_IFC_TBL_C.QUANTITY_INVOICED := cursor_ap_no.match_dsp;
INSERT INTO AP_INVOICE_LINES_INTERFACE
VALUES V_AP_INV_LINE_IFC_TBL_C;
P_LINE_NUMBER := P_LINE_NUMBER + 1;
end loop;
commit;
end;
--T6 数量<0
procedure insert_ap_invoices_t6_minus(p_ap_no varchar, p_number number) as
cursor cur_ap(p_ap_no varchar2) is
select rt.transaction_id,
pha.po_header_id,
pla.po_line_id,
pll.line_location_id,
PLL.PO_RELEASE_ID,
pha.org_id,
pla.item_id,
mac.UP2, --up_agree,
mac.match_dsp,
mac.line_num,
mac.match_amt_agree,
mac.rem
FROM RCV_TRANSACTIONS RT,
RCV_SHIPMENT_HEADERS SH,
RCV_SHIPMENT_LINES SL,
PO_LINE_LOCATIONS_ALL PLL,
PO_RELEASES_ALL PRA,
PO_LINES_ALL PLA,
PO_HEADERS_ALL PHA,
PO_VENDORS PV,
PO_VENDOR_SITES_ALL PVSA,
MTL_SYSTEM_ITEMS_B MSI,
meg_ap_checklist mac
WHERE 1 = 1
AND RT.TRANSACTION_TYPE IN ('RECEIVE', 'MATCH')
AND MG_COMM_PUB.GETTRAN_ID(RT.TRANSACTION_ID) > 0
AND MSI.INVENTORY_ITEM_ID = PLA.ITEM_ID
AND MSI.ORGANIZATION_ID = 82
AND SH.RECEIPT_SOURCE_CODE = 'VENDOR'
AND RT.SOURCE_DOCUMENT_CODE = 'PO'
AND RT.PO_HEADER_ID = PLL.PO_HEADER_ID(+)
AND RT.PO_LINE_ID = PLL.PO_LINE_ID(+)
AND RT.PO_LINE_LOCATION_ID = PLL.LINE_LOCATION_ID(+)
AND RT.SHIPMENT_HEADER_ID = SL.SHIPMENT_HEADER_ID
AND RT.SHIPMENT_LINE_ID = SL.SHIPMENT_LINE_ID
AND SL.SHIPMENT_HEADER_ID = SH.SHIPMENT_HEADER_ID
AND PLL.PO_HEADER_ID = PHA.PO_HEADER_ID
AND SL.PO_LINE_LOCATION_ID = PLL.LINE_LOCATION_ID
AND PLL.PO_LINE_ID = PLA.PO_LINE_ID
AND PLL.PO_HEADER_ID = PLA.PO_HEADER_ID
AND PLL.PO_RELEASE_ID = PRA.PO_RELEASE_ID(+)
AND PHA.VENDOR_ID = PV.VENDOR_ID
AND PVSA.VENDOR_ID = PHA.VENDOR_ID
AND PVSA.VENDOR_SITE_ID = PHA.VENDOR_SITE_ID
and rt.transaction_id = mac.transaction_id
and mac.receipt_num like 'T6%'
and mac.match_dsp < 0
and mac.ap_no = p_ap_no;
V_AP_INV_IFC_REC AP_INVOICES_INTERFACE%rowtype;
V_AP_INV_LINE_IFC_TBL_C AP_INVOICE_LINES_INTERFACE%ROWTYPE; --发票行
V_INVOICE_ID number := 0;
V_INVOICE_LINE_ID NUMBER := 0;
P_LINE_NUMBER NUMBER := 1;
--v_total_amount1 number:=0;
--v_total_amount2 number:=0;
v_price_diff number := 0;
begin
SELECT AP_INVOICES_INTERFACE_S.NEXTVAL INTO V_INVOICE_ID FROM DUAL;
select vendor_site_id
INTO V_AP_INV_IFC_REC.VENDOR_SITE_ID
from (select itm,pha.vendor_site_id
from MEG_AP_CHECKLIST mac, po_headers_all pha
where pha.segment1 = mac.po_no
and ap_no = p_ap_no
order by itm)
where rownum=1;
--付款方式
begin
SELECT iepp.payment_method_code
INTO V_AP_INV_IFC_REC.PAYMENT_METHOD_CODE
FROM iby_payment_methods_vl ipmv
, iby_ext_party_pmt_mthds iepp
, iby_external_payees_all iepa
WHERE ipmv.payment_method_code = iepp.payment_method_code(+)
AND iepp.payment_flow = 'DISBURSEMENTS'
AND NVL (ipmv.inactive_date, TRUNC (SYSDATE + 1)) > TRUNC (SYSDATE)
AND iepp.payment_function = 'PAYABLES_DISB'
AND iepp.ext_pmt_party_id = iepa.ext_payee_id
AND iepa.org_id =137
and iepp.primary_flag='Y'
AND iepa.supplier_site_id = V_AP_INV_IFC_REC.VENDOR_SITE_ID;
EXCEPTION
WHEN OTHERS THEN
V_AP_INV_IFC_REC.PAYMENT_METHOD_CODE := 'WIRE';
end ;
select mch.invoice_num || '-' || p_number, --因为
sum(mac.match_amt_agree),
-- sum(mac.match_amt_agree),
mch.org_id,
pv.VENDOR_ID,
pv.VENDOR_NAME,
pv.SEGMENT1,
pv.INVOICE_CURRENCY_CODE
into V_AP_INV_IFC_REC.INVOICE_NUM,
V_AP_INV_IFC_REC.INVOICE_AMOUNT,
V_AP_INV_IFC_REC.ORG_ID,
V_AP_INV_IFC_REC.VENDOR_ID,
V_AP_INV_IFC_REC.Vendor_Name,
V_AP_INV_IFC_REC.Vendor_Num,
V_AP_INV_IFC_REC.INVOICE_CURRENCY_CODE
from meg_ap_checklist_header mch, po_vendors pv, meg_ap_checklist mac
where mch.ap_no = p_ap_no
and mch.ap_no = mac.ap_no
and mch.vendor_no = pv.SEGMENT1
and mac.receipt_num like 'T6%'
and mac.match_dsp < 0
group by mch.invoice_num,
mch.org_id,
pv.VENDOR_ID,
pv.VENDOR_NAME,
pv.SEGMENT1,
pv.INVOICE_CURRENCY_CODE;
V_AP_INV_IFC_REC.INVOICE_ID := V_INVOICE_ID; --发票ID
V_AP_INV_IFC_REC.INVOICE_TYPE_LOOKUP_CODE := 'CREDIT'; --发票行类型
V_AP_INV_IFC_REC.SOURCE := 'USE'; --发票来源
V_AP_INV_IFC_REC.INVOICE_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ --trunc(sysdate); --发票日期
V_AP_INV_IFC_REC.CONTROL_AMOUNT := NULL;
V_AP_INV_IFC_REC.EXCHANGE_RATE := NULL;
V_AP_INV_IFC_REC.EXCHANGE_RATE_TYPE := NULL;
V_AP_INV_IFC_REC.EXCHANGE_DATE := NULL;
V_AP_INV_IFC_REC.TERMS_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ -- trunc(sysdate); --条件日期
V_AP_INV_IFC_REC.DESCRIPTION := '应付' ||
V_AP_INV_IFC_REC.Vendor_Name ||
p_ap_no||'退货' ; --null; --备注
V_AP_INV_IFC_REC.GROUP_ID := V_INVOICE_ID; --对账单处理批次
-- V_AP_INV_IFC_REC.PAYMENT_METHOD_CODE := 'WIRE';
V_AP_INV_IFC_REC.GL_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ -- trunc(sysdate); --总账日期
V_AP_INV_IFC_REC.CALC_TAX_DURING_IMPORT_FLAG := 'Y';
V_AP_INV_IFC_REC.ADD_TAX_TO_INV_AMT_FLAG := 'Y';
V_AP_INV_IFC_REC.LAST_UPDATE_DATE := trunc(sysdate);
V_AP_INV_IFC_REC.LAST_UPDATED_BY := fnd_global.USER_ID;
V_AP_INV_IFC_REC.LAST_UPDATE_LOGIN := fnd_global.LOGIN_ID;
V_AP_INV_IFC_REC.CREATION_DATE := trunc(sysdate);
V_AP_INV_IFC_REC.CREATED_BY := fnd_global.USER_ID;
--付款条件,负债账户
select ass.terms_id, gccc.code_combination_id
into V_AP_INV_IFC_REC.TERMS_ID,
V_AP_INV_IFC_REC.ACCTS_PAY_CODE_COMBINATION_ID
from ap_suppliers ass,
ap_supplier_sites_all assa,
gl_code_combinations gccc,
gl_code_combinations gccr
where ass.vendor_id = assa.vendor_id
and assa.accts_pay_code_combination_id = gccc.code_combination_id(+)
and assa.prepay_code_combination_id = gccr.code_combination_id(+)
and assa.org_id = V_AP_INV_IFC_REC.ORG_ID
and ass.segment1 = V_AP_INV_IFC_REC.Vendor_Num
and assa.vendor_site_id = V_AP_INV_IFC_REC.VENDOR_SITE_ID;
INSERT INTO AP_INVOICES_INTERFACE VALUES V_AP_INV_IFC_REC; --插入发票
for cursor_ap_no in cur_ap(p_ap_no) loop
SELECT AP_INVOICE_LINES_INTERFACE_S.NEXTVAL
INTO V_INVOICE_LINE_ID
FROM DUAL;
if abs((cursor_ap_no.UP2 * cursor_ap_no.match_dsp) -
cursor_ap_no.MATCH_AMT_AGREE) < 0.05 and
abs((cursor_ap_no.UP2 * cursor_ap_no.match_dsp) -
cursor_ap_no.MATCH_AMT_AGREE) > 0 then
v_price_diff := round(cursor_ap_no.MATCH_AMT_AGREE /
cursor_ap_no.match_dsp,6);
else
v_price_diff := cursor_ap_no.UP2;
end if;
V_AP_INV_LINE_IFC_TBL_C.INVOICE_ID := V_INVOICE_ID; --发票ID
V_AP_INV_LINE_IFC_TBL_C.INVOICE_LINE_ID := V_INVOICE_LINE_ID; --发票行ID
V_AP_INV_LINE_IFC_TBL_C.LINE_NUMBER := P_LINE_NUMBER; --p_LINE_NUMBER; --发票行号
V_AP_INV_LINE_IFC_TBL_C.LINE_TYPE_LOOKUP_CODE := 'ITEM'; --发票行类型
V_AP_INV_LINE_IFC_TBL_C.AMOUNT := cursor_ap_no.MATCH_AMT_AGREE; --p_AMOUNT; --金额
V_AP_INV_LINE_IFC_TBL_C.ACCOUNTING_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ --trunc(sysdate); --记账日期
V_AP_INV_LINE_IFC_TBL_C.DESCRIPTION :='应付' ||
V_AP_INV_IFC_REC.Vendor_Name ||
p_ap_no||'退货' ;-- cursor_ap_no.Rem; --'保险管/保险丝座/10A/磷青铜/镀镍/配套φ5*20mm/T=0.35mm/P=5.1mm/编带'; --发票行描述
V_AP_INV_LINE_IFC_TBL_C.AMOUNT_INCLUDES_TAX_FLAG := 'N';
V_AP_INV_LINE_IFC_TBL_C.TAX_CLASSIFICATION_CODE := '13%(外)'; --税分类代码
V_AP_INV_LINE_IFC_TBL_C.LAST_UPDATED_BY := fnd_global.USER_ID;
V_AP_INV_LINE_IFC_TBL_C.LAST_UPDATE_DATE := trunc(sysdate);
V_AP_INV_LINE_IFC_TBL_C.LAST_UPDATE_LOGIN := fnd_global.USER_ID;
V_AP_INV_LINE_IFC_TBL_C.CREATED_BY := fnd_global.USER_ID;
V_AP_INV_LINE_IFC_TBL_C.CREATION_DATE := trunc(sysdate);
V_AP_INV_LINE_IFC_TBL_C.RCV_TRANSACTION_ID := cursor_ap_no.transaction_id;
V_AP_INV_LINE_IFC_TBL_C.PO_HEADER_ID := cursor_ap_no.PO_HEADER_ID;
V_AP_INV_LINE_IFC_TBL_C.PO_LINE_ID := cursor_ap_no.PO_LINE_ID;
V_AP_INV_LINE_IFC_TBL_C.PO_LINE_LOCATION_ID := cursor_ap_no.line_location_id;
V_AP_INV_LINE_IFC_TBL_C.PO_RELEASE_ID := cursor_ap_no.PO_RELEASE_ID;
V_AP_INV_LINE_IFC_TBL_C.ORG_ID := cursor_ap_no.org_id;
V_AP_INV_LINE_IFC_TBL_C.INVENTORY_ITEM_ID := cursor_ap_no.item_id;
V_AP_INV_LINE_IFC_TBL_C.UNIT_PRICE := v_price_diff; --cursor_ap_no.UP2;--up_agree;
V_AP_INV_LINE_IFC_TBL_C.QUANTITY_INVOICED := cursor_ap_no.match_dsp;
INSERT INTO AP_INVOICE_LINES_INTERFACE
VALUES V_AP_INV_LINE_IFC_TBL_C;
P_LINE_NUMBER := P_LINE_NUMBER + 1;
end loop;
commit;
end;
--品质扣款
procedure insert_ap_invoices_cut_qty(p_ap_no varchar, p_number number) as
cursor cur_ap(p_ap_no varchar2) is
select mac.id transaction_id,
null po_header_id,
null po_line_id,
null line_location_id,
null PO_RELEASE_ID,
b.org_id org_id,
null item_id,
mac.UP2,
mac.match_dsp,
mac.line_num,
mac.match_amt_agree,
mac.rem,
mac.item_no
FROM meg_ap_checklist mac, meg_ap_checklist_header b
WHERE /*mac.receipt_num like 'CM%'
and*/ mac.item_no in ( '索赔','折让','品质调整','超损扣款')
and mac.match_dsp < 0
and mac.ap_no = b.ap_no
and mac.ap_no = p_ap_no;
V_AP_INV_IFC_REC AP_INVOICES_INTERFACE%rowtype;
V_AP_INV_LINE_IFC_TBL_C AP_INVOICE_LINES_INTERFACE%ROWTYPE; --发票行
V_INVOICE_ID number := 0;
V_INVOICE_LINE_ID NUMBER := 0;
P_LINE_NUMBER NUMBER := 1;
begin
SELECT AP_INVOICES_INTERFACE_S.NEXTVAL INTO V_INVOICE_ID FROM DUAL;
select vendor_site_id
INTO V_AP_INV_IFC_REC.VENDOR_SITE_ID
from (select itm,pha.vendor_site_id
from MEG_AP_CHECKLIST mac, po_headers_all pha
where pha.segment1 = mac.po_no
and ap_no = p_ap_no
order by itm)
where rownum=1;
--付款方式
begin
SELECT iepp.payment_method_code
INTO V_AP_INV_IFC_REC.PAYMENT_METHOD_CODE
FROM iby_payment_methods_vl ipmv
, iby_ext_party_pmt_mthds iepp
, iby_external_payees_all iepa
WHERE ipmv.payment_method_code = iepp.payment_method_code(+)
AND iepp.payment_flow = 'DISBURSEMENTS'
AND NVL (ipmv.inactive_date, TRUNC (SYSDATE + 1)) > TRUNC (SYSDATE)
AND iepp.payment_function = 'PAYABLES_DISB'
AND iepp.ext_pmt_party_id = iepa.ext_payee_id
AND iepa.org_id =137
and iepp.primary_flag='Y'
AND iepa.supplier_site_id = V_AP_INV_IFC_REC.VENDOR_SITE_ID;
EXCEPTION
WHEN OTHERS THEN
V_AP_INV_IFC_REC.PAYMENT_METHOD_CODE := 'WIRE';
end ;
select mch.invoice_num || '-' || p_number,
sum(mac.match_amt_agree),
-- sum(mac.match_amt_agree),
mch.org_id,
pv.VENDOR_ID,
pv.VENDOR_NAME,
pv.SEGMENT1,
pv.INVOICE_CURRENCY_CODE
into V_AP_INV_IFC_REC.INVOICE_NUM,
V_AP_INV_IFC_REC.INVOICE_AMOUNT,
V_AP_INV_IFC_REC.ORG_ID,
V_AP_INV_IFC_REC.VENDOR_ID,
V_AP_INV_IFC_REC.Vendor_Name,
V_AP_INV_IFC_REC.Vendor_Num,
V_AP_INV_IFC_REC.INVOICE_CURRENCY_CODE
from meg_ap_checklist_header mch, po_vendors pv, meg_ap_checklist mac
where mch.ap_no = p_ap_no
and mch.ap_no = mac.ap_no
and mch.vendor_no = pv.SEGMENT1
-- and mac.receipt_num like 'CM%'
and mac.item_no in ( '索赔','折让','品质调整','超损扣款')
and mac.match_dsp < 0
group by mch.invoice_num || '-' || p_number,
mch.org_id,
pv.VENDOR_ID,
pv.VENDOR_NAME,
pv.SEGMENT1,
pv.INVOICE_CURRENCY_CODE;
V_AP_INV_IFC_REC.INVOICE_ID := V_INVOICE_ID; --发票ID
V_AP_INV_IFC_REC.INVOICE_TYPE_LOOKUP_CODE := 'CREDIT'; --发票行类型
V_AP_INV_IFC_REC.SOURCE := 'USE'; --发票来源
V_AP_INV_IFC_REC.INVOICE_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ --trunc(sysdate); --发票日期
V_AP_INV_IFC_REC.CONTROL_AMOUNT := NULL;
V_AP_INV_IFC_REC.EXCHANGE_RATE := NULL;
V_AP_INV_IFC_REC.EXCHANGE_RATE_TYPE := NULL;
V_AP_INV_IFC_REC.EXCHANGE_DATE := NULL;
V_AP_INV_IFC_REC.TERMS_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ -- trunc(sysdate); --条件日期
V_AP_INV_IFC_REC.DESCRIPTION := '应付' ||
V_AP_INV_IFC_REC.Vendor_Name ||
p_ap_no||'品质扣款' ; --null; --备注
V_AP_INV_IFC_REC.GROUP_ID := V_INVOICE_ID; --对账单处理批次
-- V_AP_INV_IFC_REC.PAYMENT_METHOD_CODE := 'WIRE';
V_AP_INV_IFC_REC.GL_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ -- trunc(sysdate); --总账日期
V_AP_INV_IFC_REC.CALC_TAX_DURING_IMPORT_FLAG := 'Y';
V_AP_INV_IFC_REC.ADD_TAX_TO_INV_AMT_FLAG := 'Y';
V_AP_INV_IFC_REC.LAST_UPDATE_DATE := trunc(sysdate);
V_AP_INV_IFC_REC.LAST_UPDATED_BY := fnd_global.USER_ID;
V_AP_INV_IFC_REC.LAST_UPDATE_LOGIN := fnd_global.LOGIN_ID;
V_AP_INV_IFC_REC.CREATION_DATE := trunc(sysdate);
V_AP_INV_IFC_REC.CREATED_BY := fnd_global.USER_ID;
--付款条件,负债账户
select ass.terms_id, gccc.code_combination_id
into V_AP_INV_IFC_REC.TERMS_ID,
V_AP_INV_IFC_REC.ACCTS_PAY_CODE_COMBINATION_ID
from ap_suppliers ass,
ap_supplier_sites_all assa,
gl_code_combinations gccc,
gl_code_combinations gccr
where ass.vendor_id = assa.vendor_id
and assa.accts_pay_code_combination_id = gccc.code_combination_id(+)
and assa.prepay_code_combination_id = gccr.code_combination_id(+)
and assa.org_id = V_AP_INV_IFC_REC.ORG_ID
and ass.segment1 = V_AP_INV_IFC_REC.Vendor_Num
and assa.vendor_site_id = V_AP_INV_IFC_REC.VENDOR_SITE_ID;
INSERT INTO AP_INVOICES_INTERFACE VALUES V_AP_INV_IFC_REC; --插入发票
for cursor_ap_no in cur_ap(p_ap_no) loop
SELECT AP_INVOICE_LINES_INTERFACE_S.NEXTVAL
INTO V_INVOICE_LINE_ID
FROM DUAL;
V_AP_INV_LINE_IFC_TBL_C.INVOICE_ID := V_INVOICE_ID; --发票ID
V_AP_INV_LINE_IFC_TBL_C.INVOICE_LINE_ID := V_INVOICE_LINE_ID; --发票行ID
V_AP_INV_LINE_IFC_TBL_C.LINE_NUMBER := P_LINE_NUMBER; --p_LINE_NUMBER; --发票行号
V_AP_INV_LINE_IFC_TBL_C.LINE_TYPE_LOOKUP_CODE := 'ITEM'; --发票行类型
V_AP_INV_LINE_IFC_TBL_C.AMOUNT := cursor_ap_no.MATCH_AMT_AGREE; --p_AMOUNT; --金额
V_AP_INV_LINE_IFC_TBL_C.ACCOUNTING_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ --trunc(sysdate); --记账日期
V_AP_INV_LINE_IFC_TBL_C.DESCRIPTION := '应付' ||
V_AP_INV_IFC_REC.Vendor_Name ||
p_ap_no||cursor_ap_no.item_no;--'品质扣款' ;--cursor_ap_no.Rem; --'保险管/保险丝座/10A/磷青铜/镀镍/配套φ5*20mm/T=0.35mm/P=5.1mm/编带'; --发票行描述
V_AP_INV_LINE_IFC_TBL_C.AMOUNT_INCLUDES_TAX_FLAG := 'N';
V_AP_INV_LINE_IFC_TBL_C.TAX_CLASSIFICATION_CODE := '13%(外)'; --税分类代码
V_AP_INV_LINE_IFC_TBL_C.LAST_UPDATED_BY := fnd_global.USER_ID;
V_AP_INV_LINE_IFC_TBL_C.LAST_UPDATE_DATE := trunc(sysdate);
V_AP_INV_LINE_IFC_TBL_C.LAST_UPDATE_LOGIN := fnd_global.USER_ID;
V_AP_INV_LINE_IFC_TBL_C.CREATED_BY := fnd_global.USER_ID;
V_AP_INV_LINE_IFC_TBL_C.CREATION_DATE := trunc(sysdate);
V_AP_INV_LINE_IFC_TBL_C.RCV_TRANSACTION_ID := cursor_ap_no.transaction_id;
V_AP_INV_LINE_IFC_TBL_C.PO_HEADER_ID := null; --cursor_ap_no.PO_HEADER_ID;
V_AP_INV_LINE_IFC_TBL_C.PO_LINE_ID := null; --cursor_ap_no.PO_LINE_ID;
V_AP_INV_LINE_IFC_TBL_C.PO_LINE_LOCATION_ID := null; --cursor_ap_no.line_location_id;
V_AP_INV_LINE_IFC_TBL_C.PO_RELEASE_ID := null; -- cursor_ap_no.PO_RELEASE_ID;
V_AP_INV_LINE_IFC_TBL_C.ORG_ID := 137; --cursor_ap_no.org_id;
V_AP_INV_LINE_IFC_TBL_C.INVENTORY_ITEM_ID := null; --cursor_ap_no.item_id;
V_AP_INV_LINE_IFC_TBL_C.UNIT_PRICE := cursor_ap_no.UP2; --up_agree;
V_AP_INV_LINE_IFC_TBL_C.QUANTITY_INVOICED := cursor_ap_no.match_dsp;
INSERT INTO AP_INVOICE_LINES_INTERFACE
VALUES V_AP_INV_LINE_IFC_TBL_C;
P_LINE_NUMBER := P_LINE_NUMBER + 1;
end loop;
commit;
end;
--无po 退货
procedure insert_ap_invoices_no_po(p_ap_no varchar, p_number number) as
cursor cur_ap(p_ap_no varchar2) is
SELECT a.id transaction_id,
null po_header_id,
null po_line_id,
null line_location_id,
null PO_RELEASE_ID,
b.org_id org_id,
null item_id,
a.UP2,
a.match_dsp,
a.line_num,
a.match_amt_agree,
a.rem
FROM meg_ap_checklist a, meg_ap_checklist_header b
WHERE b.AP_NO = p_ap_no
and a.ap_no = b.ap_no
AND RECEIPT_NUM = '无PO退货';
V_AP_INV_IFC_REC AP_INVOICES_INTERFACE%rowtype;
V_AP_INV_LINE_IFC_TBL_C AP_INVOICE_LINES_INTERFACE%ROWTYPE; --发票行
V_INVOICE_ID number := 0;
V_INVOICE_LINE_ID NUMBER := 0;
P_LINE_NUMBER NUMBER := 1;
begin
SELECT AP_INVOICES_INTERFACE_S.NEXTVAL INTO V_INVOICE_ID FROM DUAL;
select vendor_site_id
INTO V_AP_INV_IFC_REC.VENDOR_SITE_ID
from (select itm,pha.vendor_site_id
from MEG_AP_CHECKLIST mac, po_headers_all pha
where pha.segment1 = mac.po_no
and ap_no = p_ap_no
order by itm)
where rownum=1;
--付款方式
begin
SELECT iepp.payment_method_code
INTO V_AP_INV_IFC_REC.PAYMENT_METHOD_CODE
FROM iby_payment_methods_vl ipmv
, iby_ext_party_pmt_mthds iepp
, iby_external_payees_all iepa
WHERE ipmv.payment_method_code = iepp.payment_method_code(+)
AND iepp.payment_flow = 'DISBURSEMENTS'
AND NVL (ipmv.inactive_date, TRUNC (SYSDATE + 1)) > TRUNC (SYSDATE)
AND iepp.payment_function = 'PAYABLES_DISB'
AND iepp.ext_pmt_party_id = iepa.ext_payee_id
AND iepa.org_id =137
and iepp.primary_flag='Y'
AND iepa.supplier_site_id = V_AP_INV_IFC_REC.VENDOR_SITE_ID;
EXCEPTION
WHEN OTHERS THEN
V_AP_INV_IFC_REC.PAYMENT_METHOD_CODE := 'WIRE';
end ;
select mch.invoice_num || '-' || p_number,
sum(mac.match_amt_agree), --sum(mac.match_amt_agree),
mch.org_id,
pv.VENDOR_ID,
pv.VENDOR_NAME,
pv.SEGMENT1,
pv.INVOICE_CURRENCY_CODE
into V_AP_INV_IFC_REC.INVOICE_NUM,
V_AP_INV_IFC_REC.INVOICE_AMOUNT,
V_AP_INV_IFC_REC.ORG_ID,
V_AP_INV_IFC_REC.VENDOR_ID,
V_AP_INV_IFC_REC.Vendor_Name,
V_AP_INV_IFC_REC.Vendor_Num,
V_AP_INV_IFC_REC.INVOICE_CURRENCY_CODE
from meg_ap_checklist_header mch, po_vendors pv, meg_ap_checklist mac
where mch.ap_no = p_ap_no
and mch.ap_no = mac.ap_no
and mch.vendor_no = pv.SEGMENT1
and mac.match_dsp < 0
and mac.receipt_num = '无PO退货'
group by mch.invoice_num || '-' || p_number,
mch.org_id,
pv.VENDOR_ID,
pv.VENDOR_NAME,
pv.SEGMENT1,
pv.INVOICE_CURRENCY_CODE;
V_AP_INV_IFC_REC.INVOICE_ID := V_INVOICE_ID; --发票ID
V_AP_INV_IFC_REC.INVOICE_TYPE_LOOKUP_CODE := 'CREDIT'; --发票行类型
V_AP_INV_IFC_REC.SOURCE := 'USE'; --发票来源
V_AP_INV_IFC_REC.INVOICE_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ --trunc(sysdate); --发票日期
V_AP_INV_IFC_REC.CONTROL_AMOUNT := NULL;
V_AP_INV_IFC_REC.EXCHANGE_RATE := NULL;
V_AP_INV_IFC_REC.EXCHANGE_RATE_TYPE := NULL;
V_AP_INV_IFC_REC.EXCHANGE_DATE := NULL;
V_AP_INV_IFC_REC.TERMS_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ -- trunc(sysdate); --条件日期
V_AP_INV_IFC_REC.DESCRIPTION := '应付' ||
V_AP_INV_IFC_REC.Vendor_Name
|| p_ap_no||'无PO退货'; --null; --备注
V_AP_INV_IFC_REC.GROUP_ID := V_INVOICE_ID; --对账单处理批次
--V_AP_INV_IFC_REC.PAYMENT_METHOD_CODE := 'WIRE';
V_AP_INV_IFC_REC.GL_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd'); */ -- trunc(sysdate); --总账日期
--V_AP_INV_IFC_REC.ORG_ID := 137; --组织
V_AP_INV_IFC_REC.CALC_TAX_DURING_IMPORT_FLAG := 'Y';
V_AP_INV_IFC_REC.ADD_TAX_TO_INV_AMT_FLAG := 'Y';
V_AP_INV_IFC_REC.LAST_UPDATE_DATE := trunc(sysdate);
V_AP_INV_IFC_REC.LAST_UPDATED_BY := fnd_global.USER_ID;
V_AP_INV_IFC_REC.LAST_UPDATE_LOGIN := fnd_global.LOGIN_ID;
V_AP_INV_IFC_REC.CREATION_DATE := trunc(sysdate);
V_AP_INV_IFC_REC.CREATED_BY := fnd_global.USER_ID;
--付款条件,负债账户
select ass.terms_id, gccc.code_combination_id
into V_AP_INV_IFC_REC.TERMS_ID,
V_AP_INV_IFC_REC.ACCTS_PAY_CODE_COMBINATION_ID
from ap_suppliers ass,
ap_supplier_sites_all assa,
gl_code_combinations gccc,
gl_code_combinations gccr
where ass.vendor_id = assa.vendor_id
and assa.accts_pay_code_combination_id = gccc.code_combination_id(+)
and assa.prepay_code_combination_id = gccr.code_combination_id(+)
and assa.org_id = V_AP_INV_IFC_REC.ORG_ID
and ass.segment1 = V_AP_INV_IFC_REC.Vendor_Num
and assa.vendor_site_id = V_AP_INV_IFC_REC.VENDOR_SITE_ID;
INSERT INTO AP_INVOICES_INTERFACE VALUES V_AP_INV_IFC_REC; --插入发票
for cursor_ap_no in cur_ap(p_ap_no) loop
SELECT AP_INVOICE_LINES_INTERFACE_S.NEXTVAL
INTO V_INVOICE_LINE_ID
FROM DUAL;
V_AP_INV_LINE_IFC_TBL_C.INVOICE_ID := V_INVOICE_ID; --发票ID
V_AP_INV_LINE_IFC_TBL_C.INVOICE_LINE_ID := V_INVOICE_LINE_ID; --发票行ID
V_AP_INV_LINE_IFC_TBL_C.LINE_NUMBER := P_LINE_NUMBER; --p_LINE_NUMBER; --发票行号
V_AP_INV_LINE_IFC_TBL_C.LINE_TYPE_LOOKUP_CODE := 'ITEM'; --发票行类型
V_AP_INV_LINE_IFC_TBL_C.AMOUNT := cursor_ap_no.MATCH_AMT_AGREE; --p_AMOUNT; --金额
V_AP_INV_LINE_IFC_TBL_C.ACCOUNTING_DATE := trunc(sysdate); /*TO_DATE(sysdate,--'2018.07.01',
'yyyy-mm-dd');*/ --trunc(sysdate); --记账日期
V_AP_INV_LINE_IFC_TBL_C.DESCRIPTION :='应付' ||
V_AP_INV_IFC_REC.Vendor_Name
|| p_ap_no||'无PO退货';-- cursor_ap_no.Rem; --'保险管/保险丝座/10A/磷青铜/镀镍/配套φ5*20mm/T=0.35mm/P=5.1mm/编带'; --发票行描述
V_AP_INV_LINE_IFC_TBL_C.AMOUNT_INCLUDES_TAX_FLAG := 'N';
V_AP_INV_LINE_IFC_TBL_C.TAX_CLASSIFICATION_CODE := '13%(外)'; --税分类代码
V_AP_INV_LINE_IFC_TBL_C.LAST_UPDATED_BY := fnd_global.USER_ID;
V_AP_INV_LINE_IFC_TBL_C.LAST_UPDATE_DATE := trunc(sysdate);
V_AP_INV_LINE_IFC_TBL_C.LAST_UPDATE_LOGIN := fnd_global.USER_ID;
V_AP_INV_LINE_IFC_TBL_C.CREATED_BY := fnd_global.USER_ID;
V_AP_INV_LINE_IFC_TBL_C.CREATION_DATE := trunc(sysdate);
V_AP_INV_LINE_IFC_TBL_C.RCV_TRANSACTION_ID := cursor_ap_no.transaction_id;
V_AP_INV_LINE_IFC_TBL_C.PO_HEADER_ID := cursor_ap_no.PO_HEADER_ID;
V_AP_INV_LINE_IFC_TBL_C.PO_LINE_ID := cursor_ap_no.PO_LINE_ID;
V_AP_INV_LINE_IFC_TBL_C.PO_LINE_LOCATION_ID := cursor_ap_no.line_location_id;
V_AP_INV_LINE_IFC_TBL_C.PO_RELEASE_ID := cursor_ap_no.PO_RELEASE_ID;
V_AP_INV_LINE_IFC_TBL_C.ORG_ID := cursor_ap_no.org_id;
V_AP_INV_LINE_IFC_TBL_C.INVENTORY_ITEM_ID := cursor_ap_no.item_id;
V_AP_INV_LINE_IFC_TBL_C.UNIT_PRICE := cursor_ap_no.UP2; --up_agree;
V_AP_INV_LINE_IFC_TBL_C.QUANTITY_INVOICED := cursor_ap_no.match_dsp;
INSERT INTO AP_INVOICE_LINES_INTERFACE
VALUES V_AP_INV_LINE_IFC_TBL_C;
P_LINE_NUMBER := P_LINE_NUMBER + 1;
end loop;
commit;
end;
--检查发票有没有最终关闭
procedure get_last_close_by_ap_no(p_ap_no varchar,
P_IMPORT_STATUS OUT varchar) as
cursor CUR_CLOSE IS
select rsh.receipt_num || '第' || rsl.line_num || '行' receipt_line
from MEG_AP_CHECKLIST MAC,
po_line_locations_all pll,
rcv_shipment_headers rsh,
rcv_shipment_lines rsl
where pll.line_location_id = rsl.po_line_location_id
and rsh.shipment_header_id = rsl.shipment_header_id
and pll.closed_code = 'FINALLY CLOSED'
and rsh.receipt_num = MAC.RECEIPT_NUM
and rsl.line_num = MAC.LINE_NUM
and MAC.AP_NO = p_ap_no;
--po退货
cursor get_no_po is
select mac.receipt_num || '第' || mac.line_num || '行' no_po_line
from rcv_transactions rt, MEG_AP_CHECKLIST MAC
where exists
(select 1
from rcv_transactions rts
where rts.transaction_type = 'RETURN TO VENDOR'
START WITH rts.transaction_id = rt.transaction_id
connect by prior rts.transaction_id = rts.parent_transaction_id)
and rt.transaction_id = MAC.TRANSACTION_ID
AND ap_no = p_ap_no;
--
l_count number := 0; --最终关闭
l_count_re number := 0; --退货的笔数
begin
--最终关闭的判断
select count(*)
into l_count
from MEG_AP_CHECKLIST MAC,
po_line_locations_all pll,
rcv_shipment_headers rsh,
rcv_shipment_lines rsl
where pll.line_location_id = rsl.po_line_location_id
and rsh.shipment_header_id = rsl.shipment_header_id
and pll.closed_code = 'FINALLY CLOSED'
and rsh.receipt_num = MAC.RECEIPT_NUM
and rsl.line_num = MAC.LINE_NUM
and MAC.AP_NO = p_ap_no; --'530986-1706Z';
if l_count > 0 then
for cur_close_status in CUR_CLOSE loop
P_IMPORT_STATUS := '存在最终关闭的T6单号有';
P_IMPORT_STATUS := P_IMPORT_STATUS || cur_close_status.receipt_line || ',';
end loop;
else
P_IMPORT_STATUS := '1';
end if;
select count(*)
into l_count_re --MAC.*--mac.ap_no,mac.receipt_num,mac.line_num,mac.po_no
from rcv_transactions rt, MEG_AP_CHECKLIST MAC
where exists
(select 1
from rcv_transactions rts
where rts.transaction_type = 'RETURN TO VENDOR'
START WITH rts.transaction_id = rt.transaction_id
connect by prior rts.transaction_id = rts.parent_transaction_id)
and rt.transaction_id = MAC.TRANSACTION_ID
AND ap_no = p_ap_no; --'530873-1803Z';
-- return P_IMPORT_STATUS;
if l_count_re > 0 then
for cur_no_po in get_no_po loop
P_IMPORT_STATUS := '存在退货的T6单号有';
P_IMPORT_STATUS := P_IMPORT_STATUS || cur_no_po.no_po_line;
end loop;
else
P_IMPORT_STATUS := '1';
end if;
end;
end pkg_ap_check_by_po;
EBS ORACLE采购对账单自动产生发票的更多相关文章
- Oracle采购模块中的多组织访问控制(MOAC)
1. 概述 从Release12开始启用多组织访问控制功能,将允许用户在一个单独的职责中访问一个或者多个经营单位(OU-Operation Units)的数据.这个功能允许用户在一个可共享服务的 ...
- Windows环境下Oracle数据库的自动备份脚本
批处理文件(.bat) @echo off echo ================================================ echo Windows环境下Oracle数据 ...
- Oracle中的自动增长字段
Oracle中的自动增长字段 Oracle 中不像MYSQL 和MSSQLServer 中那样指定一个列为自动增长列的方式,不过在Oracle中可以通过SEQUENCE序列来实现自动增长字段. 在Or ...
- SAP交货单过账自动生产采购订单、采购订单自动收货入库
公司间需要买卖操作,由于发货和收货都是同一批人在操作,为了减少业务人员的工作量,提高工作效率,特实现以上功能 1.增强实现:增强点为交货单过账成功时触发,在提交前触发,如果遇到不可预知问题,可能造成数 ...
- oracle 主键自动增长
oracle 主键自动增长 2009-12-11 16:07:00| 分类: 数据库资料|字号 订阅 这几天搞Oracle,想让表的主键实现自动增长,查网络实现如下: create tabl ...
- Oracle数据库的自动备份脚本
@echo off echo ================================================ echo Windows环境下Oracle数据库的自动备份脚本 echo ...
- 利用powerDesigner15.1连接oracle数据库并自动生成表结构
利用powerDesigner15.1连接oracle数据库并自动生成表结构 参考:http://blog.csdn.net/qq_24531461/article/details/76713802 ...
- Windows环境下Oracle数据库的自动备份脚本自动删除30天前的备份
@echo off echo ================================================ echo Windows环境下Oracle数据库的自动备份脚本 echo ...
- Oracle EBS AP 已经完全付款的发票仍然可以选择并进行零金额的付款
1>找出相应的发票; SELECT DISTINCT ai.invoice_id, ai.invoice_num invoice_num, pv.segment1 vendor_num, pv. ...
随机推荐
- 任务26:dotnet watch run 和attach到进程调试
任务26:dotnet watch run 和attach到进程调试 dotnet watch run 的一种调试方法 打开VSCode,先关闭当前的文件夹 Ctrl+~快捷键 打开窗体. ls应该是 ...
- Linux2.6 内核中结构体初始化(转载)
转自:http://hnniyan123.blog.chinaunix.net/uid-29917301-id-4989879.html 在Linux2.6版本的内核中,我们经常可以看到下面的结构体的 ...
- Codeforces - 773A - Success Rate - 二分 - 简单数论
https://codeforces.com/problemset/problem/773/A 一开始二分枚举d,使得(x+d)/(y+d)>=p/q&&x/(y+d)<= ...
- 洛谷 - P1198 - 最大数 - 线段树
https://www.luogu.org/problemnew/show/P1198 要问区间最大值,肯定是要用线段树的,不能用树状数组.(因为没有逆元?但是题目求的是最后一段,可以改成类似前缀和啊 ...
- noi.ac 邀请赛1 By cellur925
A. array 考场:上来就想暴力,首先第一个子任务肯定没问题,怎么搞都行.然后第二个子任务用个数组记下新修的值就行了.第三个子任务用一下等差数列求和公式帮助求解,每次都重新算(因为每次改变全部元素 ...
- 《对“XXX::Invoke”类型的已垃圾回收委托进行了回调。这可能会导致应用程序崩溃、损坏和数据丢失。向非托管代码传递委托时,托管应用程序必须让这些委托保持活动状态,直到确信不会再次调用它们》的问题的解决方法
<对“XXX::Invoke”类型的已垃圾回收委托进行了回调.这可能会导致应用程序崩溃.损坏和数据丢失.向非托管代码传递委托时,托管应用程序必须让这些委托保持活动状态,直到确信不会再次调用它们& ...
- Tomcat | 修改默认端口
Tomcat安装目录下 conf 目录下 server.xml 找到 <Connector connectionTimeout="/> 修改其中port值即可
- Codeforces Round #544 (Div. 3) B.Preparation for International Women's Day
链接:https://codeforces.com/contest/1133/problem/B 题意: 给n个数,和一个k,在n个数中选几对数,保证没对数相加可以整除k. 求最大能选几个数. 思路: ...
- Hibernate Could not obtain transaction-synchronized Session for current thread问题处理
项目通过Hibernate查询时报出如下错误: Hibernate Could not obtain transaction-synchronized Session for current thre ...
- Hu矩
close all; clear all; I1=imread('lena.bmp'); angle=; T=[cos(angle),sin(angle),;-sin(angle),cos(angle ...