SELECT cux_po_imp_temp_batch_s.nextval
INTO l_batch_id
FROM dual;
SELECT po_headers_interface_s.nextval
INTO l_iface_rec.interface_header_id
FROM dual;
l_iface_rec.org_id := rec_header.org_id;
l_iface_rec.process_code := 'PENDING';
l_iface_rec.action := 'ORIGINAL';
l_iface_rec.document_type_code := 'STANDARD';
-- l_iface_rec.document_subtype := 'CATALOG';
-- l_iface_rec.quote_warning_delay := 10;
l_iface_rec.document_num := rec_header.po_number;
l_iface_rec.approval_status := 'APPROVED';
l_iface_rec.approved_date := SYSDATE;
l_iface_rec.agent_id := rec_header.agent_id;
l_iface_rec.vendor_id := rec_header.vendor_id;
l_iface_rec.vendor_site_id := rec_header.vendor_site_id;
l_iface_rec.interface_source_code := 'IMP';
l_iface_rec.currency_code := rec_header.curry_currency;
l_iface_rec.rate_type_code := rec_header.rate_type_code;
--l_iface_rec.Payment_Terms :='25%預付,73%月結30天,2%尾款';--
l_iface_rec.payment_terms := rec_header.pay_term;
l_iface_rec.rate_date := rec_header.rate_date;
--l_iface_rec.rate := rec_header.rate;
l_iface_rec.batch_id := l_batch_id;
l_iface_rec.attribute_category := rec_header.org_id;
l_iface_rec.attribute1 := 'LC';
l_iface_rec.attribute2 := rec_header.h_attribute2;
l_iface_rec.attribute3 := rec_header.h_attribute3;
l_iface_rec.attribute4 := rec_header.h_attribute4;
l_iface_rec.attribute5 := rec_header.h_attribute5;
l_iface_rec.attribute6 := rec_header.h_attribute6;
l_iface_rec.attribute7 := rec_header.h_attribute7;
l_iface_rec.attribute8 := rec_header.h_attribute8;
l_iface_rec.attribute9 := rec_header.h_attribute9;
l_iface_rec.attribute10 := rec_header.h_attribute10;
l_iface_rec.attribute11 := rec_header.h_attribute11;
l_iface_rec.attribute12 := rec_header.h_attribute12;
l_iface_rec.attribute13 := rec_header.h_attribute3;
l_iface_rec.attribute14 := rec_header.h_attribute14;
l_iface_rec.attribute15 := rec_header.h_attribute15;
INSERT INTO po.po_headers_interface
VALUES l_iface_rec;
FOR rec_line IN csr_lines(rec_header.row_id)
LOOP
select z.PERCENTAGE_RATE into l_rate from zx_rates_vl z where z.TAX_RATE_CODE = rec_line.rate_code and z.ACTIVE_FLAG = 'Y';
l_iface_lines_rec := NULL;
l_iface_lines_rec.interface_header_id := l_iface_rec.interface_header_id;
l_iface_lines_rec.process_code := 'PENDING';
l_iface_lines_rec.action := 'ORIGINAL';
l_iface_lines_rec.line_num := rec_line.line_num;
l_iface_lines_rec.item_id := rec_line.item_id;
l_iface_lines_rec.quantity := rec_line.quantity;
l_iface_lines_rec.unit_price := round(rec_line.unit_price / (1 + l_rate / 100),6);-----含稅轉不含稅
l_iface_lines_rec.need_by_date := rec_line.need_by_date;
l_iface_lines_rec.line_attribute_category_lines := rec_header.org_id;
l_iface_lines_rec.line_attribute1 := rec_line.l_attribute1;
l_iface_lines_rec.line_attribute2 := rec_line.l_attribute2;
l_iface_lines_rec.line_attribute3 := rec_line.l_attribute3;
l_iface_lines_rec.line_attribute4 := rec_line.l_attribute4;
l_iface_lines_rec.line_attribute5 := rec_line.l_attribute5;
l_iface_lines_rec.line_attribute6 := rec_line.l_attribute6;
l_iface_lines_rec.line_attribute7 := rec_line.l_attribute7;
l_iface_lines_rec.line_attribute8 := rec_line.l_attribute8;
l_iface_lines_rec.line_attribute9 := rec_line.l_attribute9;
l_iface_lines_rec.line_attribute10 := rec_line.l_attribute10;
l_iface_lines_rec.line_attribute11 := rec_line.l_attribute11;
l_iface_lines_rec.line_attribute12 := rec_line.l_attribute12;
l_iface_lines_rec.line_attribute13 := rec_line.l_attribute13;
l_iface_lines_rec.line_attribute14 := rec_line.l_attribute14;
l_iface_lines_rec.line_attribute15 := rec_line.l_attribute15;
SELECT po_lines_interface_s.nextval
INTO l_iface_lines_rec.interface_line_id
FROM dual;
INSERT INTO po_lines_interface
VALUES l_iface_lines_rec;
l_iface_dis_rec.interface_header_id := l_iface_lines_rec.interface_header_id;
l_iface_dis_rec.distribution_num := 1;
l_iface_dis_rec.quantity_delivered := 0;
l_iface_dis_rec.quantity_billed := 0;
l_iface_dis_rec.quantity_cancelled := 0; --Must Be 0
l_iface_dis_rec.charge_account_id := NULL;
--l_iface_dis_rec.QUANTITY_ORDERED := 10;
l_iface_dis_rec.interface_line_id := l_iface_lines_rec.interface_line_id;
l_iface_dis_rec.quantity_ordered := l_iface_lines_rec.quantity;
SELECT po.po_distributions_interface_s.nextval
INTO l_iface_dis_rec.interface_distribution_id
FROM dual;
INSERT INTO po.po_distributions_interface
VALUES l_iface_dis_rec;
--設置數量稅碼--
IF rec_line.rate_code IS NOT NULL THEN
l_item_rec := l_item_rec_null;
l_item_rec.organization_id := rec_header.organization_id;
l_item_rec.inventory_item_id := rec_line.item_id;
l_item_rec.purchasing_tax_code := rec_line.rate_code;
l_item_rec.taxable_flag := 'Y';
inv_item_grp.update_item(p_item_rec => l_item_rec,
x_item_rec => lx_item_rec,
x_return_status => x_return_status,
x_error_tbl => l_error_tbl,
p_template_id => NULL);
IF l_error_tbl.count > 0 THEN
FOR i IN l_error_tbl.first .. l_error_tbl.last
LOOP
l_error_msg := l_error_msg || '-' || l_error_tbl(1).message_text;
END LOOP;
stack_message('更新物料稅碼出錯:' || l_error_msg);
END IF;
END IF;
END LOOP;
mo_global.set_policy_context('S',
l_iface_rec.org_id);
po_docs_interface_sv5.process_po_headers_interface(x_selected_batch_id => NULL, --l_iface_rec.batch_id,
x_buyer_id => NULL,
x_document_type => l_iface_rec.document_type_code,
x_document_subtype => l_iface_rec.document_subtype,
x_create_items => 'N',
x_create_sourcing_rules_flag => NULL,
x_rel_gen_method => NULL,
x_approved_status => NULL, -- l_iface_rec.approval_status,
x_commit_interval => 1,
x_process_code => 'PENDING',
x_interface_header_id => l_iface_rec.interface_header_id,
x_org_id_param => NULL,
x_ga_flag => NULL);
COMMIT;
SELECT MAX(pie.error_message)
INTO l_error_message
FROM po_interface_errors pie
WHERE pie.interface_header_id = l_iface_rec.interface_header_id;