返利是指公司间应收款项按一定比率的返还给客户。返利开发实质就是实现对应收发票的更改和新增(暂时我的理解)
一.对发票行更改
PACKAGE AP_INVOICE_LINES_ALL_PRIVATE IS
PROCEDURE INSERT_ROW (X_LINE_NUM OUT NUMBER,P_FLAG VARCHAR2,P_AMOUNT NUMBER);
PROCEDURE UPDATE_ROW (P_LINE_NUM IN NUMBER,P_INVOICE_ID IN NUMBER,P_ORG_ID IN NUMBER);
END;
PACKAGE BODY AP_INVOICE_LINES_ALL_PRIVATE IS
PROCEDURE INSERT_ROW (X_LINE_NUM OUT NUMBER,P_FLAG VARCHAR2,P_AMOUNT NUMBER)IS
v_row_id VARCHAR2(1000);
v_line_number number;
g_user_id CONSTANT NUMBER := fnd_global.user_id;
g_login_id CONSTANT NUMBER := fnd_global.conc_login_id;
g_request_id CONSTANT NUMBER := fnd_global.conc_request_id;
g_prog_appl_id CONSTANT NUMBER := fnd_global.prog_appl_id;
g_conc_program_id CONSTANT NUMBER := fnd_global.conc_program_id;
x_ccid number;
V_AMOUNT NUMBER;
BEGIN
select max(NVL(line_number,0))
into v_line_number
from AP_INVOICE_LINES_ALL
where invoice_id = :parameter.G_INVOICE_ID;
X_LINE_NUM := v_line_number + 1;
cux_cuxaprebate_utl.create_account(p_org_id =>:parameter.g_org_id,
p_ccid =>:parameter.G_CCID,
x_ccid =>x_ccid);
IF P_FLAG = 'CANCEL' THEN
V_AMOUNT := P_AMOUNT;
ELSIF P_FLAG = 'APPLY' THEN
V_AMOUNT := - P_AMOUNT;
END IF;
/*mo_global.init('AP');
mo_global.set_policy_context(p_access_mode => 'S',
p_org_id => :parameter.g_org_id);--mo_global.get_current_org_id*/
ap_ail_table_handler_pkg.insert_row(p_rowid => v_row_id,
p_invoice_id => :parameter.G_INVOICE_ID,
p_line_number => X_LINE_NUM,
p_line_type_lookup_code => 'MISCELLANEOUS',--杂项
p_line_group_number => NULL,
p_requester_id => NULL,
p_description => NULL,
p_line_source => NULL,
p_org_id => NULL,
p_inventory_item_id => NULL,
p_item_description => NULL,
p_serial_number => NULL,
p_manufacturer => NULL,
p_model_number => NULL,
p_warranty_number => NULL,
p_generate_dists => NULL,
p_match_type => NULL,
p_distribution_set_id => NULL,
p_account_segment => NULL,
p_balancing_segment => NULL,
p_cost_center_segment => NULL,
p_overlay_dist_code_concat => NULL,
p_default_dist_ccid => x_ccid,--ccid
p_prorate_across_all_items => NULL,
p_accounting_date => :parameter.G_GL_DATE,--gl_date
p_period_name => NULL,
p_deferred_acctg_flag => NULL,
p_def_acctg_start_date => NULL,
p_def_acctg_end_date => NULL,
p_def_acctg_number_of_periods => NULL,
p_def_acctg_period_type => NULL,
p_set_of_books_id => :parameter.G_SET_OF_BOOKS_ID,--
p_amount => V_AMOUNT,--金额
p_base_amount => NULL,
p_rounding_amt => NULL,
p_quantity_invoiced => NULL,
p_unit_meas_lookup_code => NULL,
p_unit_price => NULL,
p_wfapproval_status => 'NOT REQUIRED',--
p_discarded_flag => NULL,
p_original_amount => NULL,
p_original_base_amount => NULL,
p_original_rounding_amt => NULL,
p_cancelled_flag => NULL,
p_income_tax_region => NULL,
p_type_1099 => NULL,
p_stat_amount => NULL,
p_prepay_invoice_id => NULL,
p_prepay_line_number => NULL,
p_invoice_includes_prepay_flag => NULL,
p_corrected_inv_id => NULL,
p_corrected_line_number => NULL,
p_po_header_id => NULL,
p_po_line_id => NULL,
p_po_release_id => NULL,
p_po_line_location_id => NULL,
p_po_distribution_id => NULL,
p_rcv_transaction_id => NULL,
p_final_match_flag => NULL,
p_assets_tracking_flag => NULL,
p_asset_book_type_code => NULL,
p_asset_category_id => NULL,
p_project_id => NULL,
p_task_id => NULL,
p_expenditure_type => NULL,
p_expenditure_item_date => NULL,
p_expenditure_organization_id => NULL,
p_pa_quantity => NULL,
p_pa_cc_ar_invoice_id => NULL,
p_pa_cc_ar_invoice_line_num => NULL,
p_pa_cc_processed_code => NULL,
p_award_id => NULL,
p_awt_group_id => NULL,
p_pay_awt_group_id => NULL, --NUMBER,--bug6639866
p_reference_1 => NULL,
p_reference_2 => NULL,
p_receipt_verified_flag => NULL,
p_receipt_required_flag => NULL,
p_receipt_missing_flag => NULL,
p_justification => NULL,
p_expense_group => NULL,
p_start_expense_date => NULL,
p_end_expense_date => NULL,
p_receipt_currency_code => NULL,
p_receipt_conversion_rate => NULL,
p_receipt_currency_amount => NULL,
p_daily_amount => NULL,
p_web_parameter_id => NULL,
p_adjustment_reason => NULL,
p_merchant_document_number => NULL,
p_merchant_name => NULL,
p_merchant_reference => NULL,
p_merchant_tax_reg_number => NULL,
p_merchant_taxpayer_id => NULL,
p_country_of_supply => NULL,
p_credit_card_trx_id => NULL,
p_company_prepaid_invoice_id => NULL,
p_cc_reversal_flag => NULL,
p_creation_date => sysdate,
p_created_by => g_user_id,
p_last_updated_by => g_user_id,
p_last_update_date => sysdate,
p_last_update_login => g_login_id,
p_program_application_id => NULL,
p_program_id => NULL,
p_program_update_date => sysdate,
p_request_id => NULL,
p_attribute_category => NULL,
p_attribute1 => NULL,
p_attribute2 => NULL,
p_attribute3 => NULL,
p_attribute4 => NULL,
p_attribute5 => NULL,
/* p_attribute6 VARCHAR2 DEFAULT NULL,
p_attribute7 VARCHAR2 DEFAULT NULL,
p_attribute8 VARCHAR2 DEFAULT NULL,
p_attribute9 VARCHAR2 DEFAULT NULL,
p_attribute10 VARCHAR2 DEFAULT NULL,
p_attribute11 VARCHAR2 DEFAULT NULL,
p_attribute12 VARCHAR2 DEFAULT NULL,
p_attribute13 VARCHAR2 DEFAULT NULL,
p_attribute14 VARCHAR2 DEFAULT NULL,
p_attribute15 VARCHAR2 DEFAULT NULL,
p_global_attribute_category VARCHAR2 DEFAULT NULL,
p_global_attribute1 VARCHAR2 DEFAULT NULL,
p_global_attribute2 VARCHAR2 DEFAULT NULL,
p_global_attribute3 VARCHAR2 DEFAULT NULL,
p_global_attribute4 VARCHAR2 DEFAULT NULL,
p_global_attribute5 VARCHAR2 DEFAULT NULL,
p_global_attribute6 VARCHAR2 DEFAULT NULL,
p_global_attribute7 VARCHAR2 DEFAULT NULL,
p_global_attribute8 VARCHAR2 DEFAULT NULL,
p_global_attribute9 VARCHAR2 DEFAULT NULL,
p_global_attribute10 VARCHAR2 DEFAULT NULL,
p_global_attribute11 VARCHAR2 DEFAULT NULL,
p_global_attribute12 VARCHAR2 DEFAULT NULL,
p_global_attribute13 VARCHAR2 DEFAULT NULL,
p_global_attribute14 VARCHAR2 DEFAULT NULL,
p_global_attribute15 VARCHAR2 DEFAULT NULL,
p_global_attribute16 VARCHAR2 DEFAULT NULL,
p_global_attribute17 VARCHAR2 DEFAULT NULL,
p_global_attribute18 VARCHAR2 DEFAULT NULL,
p_global_attribute19 VARCHAR2 DEFAULT NULL,
p_global_attribute20 VARCHAR2 DEFAULT NULL,
p_primary_intended_use VARCHAR2 DEFAULT NULL,
p_ship_to_location_id NUMBER DEFAULT NULL,
p_product_fisc_classification VARCHAR2 DEFAULT NULL,
p_user_defined_fisc_class VARCHAR2 DEFAULT NULL,
p_trx_business_category VARCHAR2 DEFAULT NULL,
p_product_type VARCHAR2 DEFAULT NULL,
p_product_category VARCHAR2 DEFAULT NULL,
p_assessable_value NUMBER DEFAULT NULL,
p_control_amount NUMBER DEFAULT NULL,
p_tax_regime_code VARCHAR2 DEFAULT NULL,
p_tax VARCHAR2 DEFAULT NULL,
p_tax_status_code VARCHAR2 DEFAULT NULL,*/
p_tax_rate_code => 'CN_VAT_IN_17',
/* p_tax_rate_id NUMBER DEFAULT NULL,
p_tax_rate NUMBER DEFAULT NULL,
p_tax_jurisdiction_code VARCHAR2 DEFAULT NULL,
p_purchasing_category_id NUMBER DEFAULT NULL,
p_cost_factor_id NUMBER DEFAULT NULL,
p_retained_amount NUMBER DEFAULT NULL,
p_retained_invoice_id NUMBER DEFAULT NULL,
p_retained_line_number NUMBER DEFAULT NULL,
p_tax_classification_code VARCHAR2 DEFAULT NULL,*/
p_calling_sequence => NULL);
EXCEPTION
WHEN OTHERS THEN
FND_MESSAGE.DEBUG('给应付发票行插值时出现错误 : '||SQLERRM);
raise form_trigger_failure;
END; PROCEDURE UPDATE_ROW (P_LINE_NUM IN NUMBER,P_INVOICE_ID IN NUMBER,P_ORG_ID IN NUMBER)IS
V_AMOUNT NUMBER;
BEGIN
-- fnd_message.debug('@@@P_LINE_NUM'||P_LINE_NUM);
-- fnd_message.debug('@@@P_INVOICE_ID'||P_INVOICE_ID);
SELECT AMOUNT
INTO V_AMOUNT
FROM AP_INVOICE_LINES_ALL
WHERE INVOICE_ID = P_INVOICE_ID
-- AND (ORG_ID = P_ORG_ID or ORG_ID is null)
AND LINE_NUMBER = P_LINE_NUM
FOR UPDATE NOWAIT; UPDATE AP_INVOICE_LINES_ALL
SET AMOUNT = 0
WHERE INVOICE_ID = P_INVOICE_ID
-- AND ORG_ID = P_ORG_ID
AND LINE_NUMBER = P_LINE_NUM;
--commit;
EXCEPTION
WHEN OTHERS THEN
FND_MESSAGE.DEBUG('更新发票行时出现错误 : '||SQLERRM);
raise form_trigger_failure;
END;
END;
二.对发票分配行更改
PACKAGE AP_DISTRIBUTIONS_PRIVATE IS
PROCEDURE INSERT_ROW (P_LINE_NUM IN NUMBER,P_FLAG VARCHAR2,P_AMOUNT NUMBER,p_invoice_id in number);
END;
PACKAGE BODY AP_DISTRIBUTIONS_PRIVATE IS
PROCEDURE INSERT_ROW (P_LINE_NUM IN NUMBER,P_FLAG VARCHAR2,P_AMOUNT NUMBER,p_invoice_id in number)IS
v_row_id VARCHAR2(1000);
v_line_number NUMBER;
g_user_id CONSTANT NUMBER := fnd_global.user_id;
g_login_id CONSTANT NUMBER := fnd_global.conc_login_id;
g_request_id CONSTANT NUMBER := fnd_global.conc_request_id;
g_prog_appl_id CONSTANT NUMBER := fnd_global.prog_appl_id;
g_conc_program_id CONSTANT NUMBER := fnd_global.conc_program_id;
x_ccid number := 0;
p_invoice_distribution_id NUMBER;
V_period_name VARCHAR2(100);
X_DIS_LINE_NUM NUMBER;
V_AMOUNT NUMBER;
BEGIN
-- fnd_message.debug(' SELECT MAX( NVL(DISTRIBUTION_LINE_NUMBER,0)) P_LINE_NUM:'||P_LINE_NUM);
SELECT nvl(MAX( NVL(DISTRIBUTION_LINE_NUMBER,0)),0)
INTO v_line_number
FROM AP_INVOICE_DISTRIBUTIONS_ALL
WHERE invoice_id = p_invoice_id
AND invoice_line_number = P_LINE_NUM; X_DIS_LINE_NUM := v_line_number + 1;
-- fnd_message.debug(' SELECT MAX( NVL(DISTRIBUTION_LINE_NUMBER,0)) v_line_number:'||v_line_number);
-- fnd_message.debug(' SELECT MAX( NVL(DISTRIBUTION_LINE_NUMBER,0)) X_DIS_LINE_NUM:'||X_DIS_LINE_NUM);
V_period_name := cux_gl_public_pkg.get_period_name(p_org_id =>:parameter.g_org_id,
p_gl_date =>:parameter.G_GL_DATE);
cux_cuxaprebate_utl.create_account(p_org_id =>:parameter.g_org_id,
p_ccid =>:parameter.G_CCID,
x_ccid =>x_ccid);
SELECT ap_invoice_distributions_s.nextval INTO p_invoice_distribution_id FROM DUAL; IF P_FLAG = 'CANCEL' THEN
V_AMOUNT := P_AMOUNT;
ELSIF P_FLAG = 'APPLY' THEN
V_AMOUNT := - P_AMOUNT;
END IF;
mo_global.init('AR');
mo_global.set_policy_context(p_access_mode => 'S',
p_org_id => :parameter.g_org_id);--:parameter.g_org_id--mo_global.get_current_org_id
ap_aid_table_handler_pkg.insert_row(p_rowid => v_row_id,
p_invoice_id => p_invoice_id,
p_invoice_line_number => P_LINE_NUM,--行上的信息
p_distribution_class => null,
p_invoice_distribution_id => p_invoice_distribution_id,
p_dist_code_combination_id => x_ccid,--ccid
p_last_update_date => SYSDATE,
p_last_updated_by => g_user_id,
p_accounting_date => sysdate,--gl date
p_period_name => V_period_name,
p_set_of_books_id=> :parameter.G_SET_OF_BOOKS_ID,
p_amount => V_AMOUNT,--金额
p_description => null,
p_type_1099 => null,
p_posted_flag => null,
p_batch_id => null,
p_quantity_invoiced => null,
p_unit_price => null,
p_match_status_flag => null,
p_attribute_category => null,
p_attribute1 => null,
p_attribute2 => null,
p_attribute3 => null,
p_attribute4 => null,
p_attribute5 => null,
p_prepay_amount_remaining => null,
p_assets_addition_flag => 'U',
p_assets_tracking_flag => 'N',
p_distribution_line_number => X_DIS_LINE_NUM,--v_line_number + 1,--
p_line_type_lookup_code => 'MISCELLANEOUS',--杂项
p_po_distribution_id => null,
p_base_amount => null,
p_pa_addition_flag => null,
p_posted_amount => null,
p_posted_base_amount => null,
p_encumbered_flag => null,
p_accrual_posted_flag => null,
p_cash_posted_flag => null,
p_last_update_login => null,
p_creation_date => null,
p_created_by => null,
p_stat_amount => null,
p_attribute11 => null,
p_attribute12 => null,
p_attribute13 => null,
p_attribute14 => 'N',
p_attribute6 => null,
p_attribute7=> null,
p_attribute8 => null,
p_attribute9 => null,
p_attribute10 => null,
p_attribute15 => 'Y',
p_accts_pay_code_comb_id => null,
p_reversal_flag => null,
p_parent_invoice_id => null,
p_income_tax_region => null,
p_final_match_flag => null,
-- Removed for bug 4277744
-- p_Ussgl_Transaction_Code VARCHAR2,
-- p_Ussgl_Trx_Code_Context VARCHAR2,
p_expenditure_item_date => null,
p_expenditure_organization_id => null,
p_expenditure_type => null,
p_pa_quantity => null,
p_project_id => null,
p_task_id => null,
p_quantity_variance => null,
p_base_quantity_variance => null,
p_packet_id => null,
p_awt_flag => null,
p_awt_group_id => null,
p_pay_awt_group_id => null, --bug6639866
p_awt_tax_rate_id => null,
p_awt_gross_amount => null,
p_reference_1 => null,
p_reference_2 => null,
p_org_id => :parameter.g_org_id,--------------------------------
p_other_invoice_id => null,
p_awt_invoice_id => null,
p_awt_origin_group_id => null,
p_program_application_id => null,
p_program_id => null,
p_program_update_date => null,
p_request_id => null,
p_tax_recoverable_flag => null,
p_award_id => null,
p_start_expense_date => null,
p_merchant_document_number => null,
p_merchant_name => null,
p_merchant_tax_reg_number => null,
p_merchant_taxpayer_id => null,
p_country_of_supply => null,
p_merchant_reference => null,
p_parent_reversal_id => null,
p_rcv_transaction_id => null,
p_matched_uom_lookup_code => null,
/* p_global_attribute_category VARCHAR2 DEFAULT NULL,
p_global_attribute1 VARCHAR2 DEFAULT NULL,
p_global_attribute2 VARCHAR2 DEFAULT NULL,
p_global_attribute3 VARCHAR2 DEFAULT NULL,
p_global_attribute4 VARCHAR2 DEFAULT NULL,
p_global_attribute5 VARCHAR2 DEFAULT NULL,
p_global_attribute6 VARCHAR2 DEFAULT NULL,
p_global_attribute7 VARCHAR2 DEFAULT NULL,
p_global_attribute8 VARCHAR2 DEFAULT NULL,
p_global_attribute9 VARCHAR2 DEFAULT NULL,
p_global_attribute10 VARCHAR2 DEFAULT NULL,
p_global_attribute11 VARCHAR2 DEFAULT NULL,
p_global_attribute12 VARCHAR2 DEFAULT NULL,
p_global_attribute13 VARCHAR2 DEFAULT NULL,
p_global_attribute14 VARCHAR2 DEFAULT NULL,
p_global_attribute15 VARCHAR2 DEFAULT NULL,
p_global_attribute16 VARCHAR2 DEFAULT NULL,
p_global_attribute17 VARCHAR2 DEFAULT NULL,
p_global_attribute18 VARCHAR2 DEFAULT NULL,
p_global_attribute19 VARCHAR2 DEFAULT NULL,
p_global_attribute20 VARCHAR2 DEFAULT NULL,*/
p_calling_sequence=>NULL,
/* p_receipt_verified_flag VARCHAR2 DEFAULT NULL,
p_receipt_required_flag VARCHAR2 DEFAULT NULL,
p_receipt_missing_flag VARCHAR2 DEFAULT NULL,
p_justification VARCHAR2 DEFAULT NULL,
p_expense_group VARCHAR2 DEFAULT NULL,
p_end_expense_date DATE DEFAULT NULL,
p_receipt_currency_code VARCHAR2 DEFAULT NULL,
p_receipt_conversion_rate VARCHAR2 DEFAULT NULL,
p_receipt_currency_amount NUMBER DEFAULT NULL,
p_daily_amount NUMBER DEFAULT NULL,
p_web_parameter_id NUMBER DEFAULT NULL,
p_adjustment_reason VARCHAR2 DEFAULT NULL,
p_credit_card_trx_id NUMBER DEFAULT NULL,
p_company_prepaid_invoice_id NUMBER DEFAULT NULL,
-- Invoice Lines Project Stage 1
p_rounding_amt NUMBER DEFAULT NULL,
p_charge_applicable_to_dist_id NUMBER DEFAULT NULL,
p_corrected_invoice_dist_id NUMBER DEFAULT NULL,
p_related_id NUMBER DEFAULT NULL,
p_asset_book_type_code VARCHAR2 DEFAULT NULL,
p_asset_category_id NUMBER DEFAULT NULL,
--ETAX: Invwkb
p_intended_use VARCHAR2 DEFAULT NULL,*\*/
p_rcv_charge_addition_flag => 'N');
EXCEPTION
WHEN OTHERS THEN
FND_MESSAGE.DEBUG('给应付发票分配行插值时出现错误 : '||SQLERRM);
raise form_trigger_failure;
END; END;