29: -- current parent condition calling object called object
30: -- level level
31: ------------------------------------------------------------------------------------------------------------------------------------------
32: -- 1 1 insert or trigger calc_taxes_for_invoices
33: -- update on pa_draft_invoices_all
34: --
35: -- 2 1 when request is not null calc_taxes_for_invoices dflt_taxes_for_invoice_lines
36: -- (work in loop for multi invoices)
37: --
94: -------------------------------------------------------------------------------------------------------------
95:
96: type global_type is record
97: (
98: lv_inv_currency_code pa_draft_invoices_all.inv_currency_code%type ,
99: ln_inv_exchange_rate pa_draft_invoices_all.inv_exchange_rate%type ,
100: ln_customer_id pa_draft_invoices_all.customer_id%type ,
101: ln_bill_to_customer_id pa_draft_invoices_all.bill_to_customer_id%type ,
102: ln_ship_to_customer_id pa_draft_invoices_all.ship_to_customer_id%type ,
95:
96: type global_type is record
97: (
98: lv_inv_currency_code pa_draft_invoices_all.inv_currency_code%type ,
99: ln_inv_exchange_rate pa_draft_invoices_all.inv_exchange_rate%type ,
100: ln_customer_id pa_draft_invoices_all.customer_id%type ,
101: ln_bill_to_customer_id pa_draft_invoices_all.bill_to_customer_id%type ,
102: ln_ship_to_customer_id pa_draft_invoices_all.ship_to_customer_id%type ,
103: ln_bill_to_address_id pa_draft_invoices_all.bill_to_address_id%type ,
96: type global_type is record
97: (
98: lv_inv_currency_code pa_draft_invoices_all.inv_currency_code%type ,
99: ln_inv_exchange_rate pa_draft_invoices_all.inv_exchange_rate%type ,
100: ln_customer_id pa_draft_invoices_all.customer_id%type ,
101: ln_bill_to_customer_id pa_draft_invoices_all.bill_to_customer_id%type ,
102: ln_ship_to_customer_id pa_draft_invoices_all.ship_to_customer_id%type ,
103: ln_bill_to_address_id pa_draft_invoices_all.bill_to_address_id%type ,
104: ln_ship_to_address_id pa_draft_invoices_all.ship_to_address_id%type ,
97: (
98: lv_inv_currency_code pa_draft_invoices_all.inv_currency_code%type ,
99: ln_inv_exchange_rate pa_draft_invoices_all.inv_exchange_rate%type ,
100: ln_customer_id pa_draft_invoices_all.customer_id%type ,
101: ln_bill_to_customer_id pa_draft_invoices_all.bill_to_customer_id%type ,
102: ln_ship_to_customer_id pa_draft_invoices_all.ship_to_customer_id%type ,
103: ln_bill_to_address_id pa_draft_invoices_all.bill_to_address_id%type ,
104: ln_ship_to_address_id pa_draft_invoices_all.ship_to_address_id%type ,
105: -- for credit memo ( invoice ) variables
98: lv_inv_currency_code pa_draft_invoices_all.inv_currency_code%type ,
99: ln_inv_exchange_rate pa_draft_invoices_all.inv_exchange_rate%type ,
100: ln_customer_id pa_draft_invoices_all.customer_id%type ,
101: ln_bill_to_customer_id pa_draft_invoices_all.bill_to_customer_id%type ,
102: ln_ship_to_customer_id pa_draft_invoices_all.ship_to_customer_id%type ,
103: ln_bill_to_address_id pa_draft_invoices_all.bill_to_address_id%type ,
104: ln_ship_to_address_id pa_draft_invoices_all.ship_to_address_id%type ,
105: -- for credit memo ( invoice ) variables
106: ln_draft_invoice_num_credited pa_draft_invoices_all.draft_invoice_num_credited%type ,
99: ln_inv_exchange_rate pa_draft_invoices_all.inv_exchange_rate%type ,
100: ln_customer_id pa_draft_invoices_all.customer_id%type ,
101: ln_bill_to_customer_id pa_draft_invoices_all.bill_to_customer_id%type ,
102: ln_ship_to_customer_id pa_draft_invoices_all.ship_to_customer_id%type ,
103: ln_bill_to_address_id pa_draft_invoices_all.bill_to_address_id%type ,
104: ln_ship_to_address_id pa_draft_invoices_all.ship_to_address_id%type ,
105: -- for credit memo ( invoice ) variables
106: ln_draft_invoice_num_credited pa_draft_invoices_all.draft_invoice_num_credited%type ,
107: ln_write_off_flag pa_draft_invoices_all.write_off_flag%type ,
100: ln_customer_id pa_draft_invoices_all.customer_id%type ,
101: ln_bill_to_customer_id pa_draft_invoices_all.bill_to_customer_id%type ,
102: ln_ship_to_customer_id pa_draft_invoices_all.ship_to_customer_id%type ,
103: ln_bill_to_address_id pa_draft_invoices_all.bill_to_address_id%type ,
104: ln_ship_to_address_id pa_draft_invoices_all.ship_to_address_id%type ,
105: -- for credit memo ( invoice ) variables
106: ln_draft_invoice_num_credited pa_draft_invoices_all.draft_invoice_num_credited%type ,
107: ln_write_off_flag pa_draft_invoices_all.write_off_flag%type ,
108: ln_draft_invoice_line_id jai_pa_draft_invoice_lines.draft_invoice_line_id%type,
102: ln_ship_to_customer_id pa_draft_invoices_all.ship_to_customer_id%type ,
103: ln_bill_to_address_id pa_draft_invoices_all.bill_to_address_id%type ,
104: ln_ship_to_address_id pa_draft_invoices_all.ship_to_address_id%type ,
105: -- for credit memo ( invoice ) variables
106: ln_draft_invoice_num_credited pa_draft_invoices_all.draft_invoice_num_credited%type ,
107: ln_write_off_flag pa_draft_invoices_all.write_off_flag%type ,
108: ln_draft_invoice_line_id jai_pa_draft_invoice_lines.draft_invoice_line_id%type,
109: ln_draft_invoice_id jai_pa_draft_invoice_lines.draft_invoice_id%type ,
110: ln_line_amt jai_pa_draft_invoice_lines.line_amt%type
103: ln_bill_to_address_id pa_draft_invoices_all.bill_to_address_id%type ,
104: ln_ship_to_address_id pa_draft_invoices_all.ship_to_address_id%type ,
105: -- for credit memo ( invoice ) variables
106: ln_draft_invoice_num_credited pa_draft_invoices_all.draft_invoice_num_credited%type ,
107: ln_write_off_flag pa_draft_invoices_all.write_off_flag%type ,
108: ln_draft_invoice_line_id jai_pa_draft_invoice_lines.draft_invoice_line_id%type,
109: ln_draft_invoice_id jai_pa_draft_invoice_lines.draft_invoice_id%type ,
110: ln_line_amt jai_pa_draft_invoice_lines.line_amt%type
111: ) ;
117: procedure calc_taxes_for_invoices
118: (
119: err_buf out nocopy varchar2 ,
120: retcode out nocopy varchar2 ,
121: pn_request_id in pa_draft_invoices_all.request_id%type ,
122: pn_project_id in pa_draft_invoices_all.project_id%type ,
123: pn_draft_invoice_num in pa_draft_invoices_all.draft_invoice_num%type ,
124: pv_event in varchar2
125: ) is
118: (
119: err_buf out nocopy varchar2 ,
120: retcode out nocopy varchar2 ,
121: pn_request_id in pa_draft_invoices_all.request_id%type ,
122: pn_project_id in pa_draft_invoices_all.project_id%type ,
123: pn_draft_invoice_num in pa_draft_invoices_all.draft_invoice_num%type ,
124: pv_event in varchar2
125: ) is
126:
119: err_buf out nocopy varchar2 ,
120: retcode out nocopy varchar2 ,
121: pn_request_id in pa_draft_invoices_all.request_id%type ,
122: pn_project_id in pa_draft_invoices_all.project_id%type ,
123: pn_draft_invoice_num in pa_draft_invoices_all.draft_invoice_num%type ,
124: pv_event in varchar2
125: ) is
126:
127: -- cursor is responsible for getting range of invoices
124: pv_event in varchar2
125: ) is
126:
127: -- cursor is responsible for getting range of invoices
128: lr_get_invoices pa_draft_invoices_all%rowtype ;
129: lv_process_flag varchar2(30);
130: lv_process_message varchar2(2000);
131: v_parent_request_id NUMBER;
132: req_status BOOLEAN := TRUE;
137: v_message VARCHAR2(100);
138:
139: -- cursor for getting invoices detail depends upon request id
140: cursor cur_get_invoices is
141: select pa_draft_invoices_all.*
142: from pa_draft_invoices_all
143: where request_id = pn_request_id ;
144:
145: -- cursor for getting one single invoice detail for corresponding project id and draft invoice num
138:
139: -- cursor for getting invoices detail depends upon request id
140: cursor cur_get_invoices is
141: select pa_draft_invoices_all.*
142: from pa_draft_invoices_all
143: where request_id = pn_request_id ;
144:
145: -- cursor for getting one single invoice detail for corresponding project id and draft invoice num
146:
144:
145: -- cursor for getting one single invoice detail for corresponding project id and draft invoice num
146:
147: Cursor cur_get_inv_detail is
148: select pa_draft_invoices_all.*
149: from pa_draft_invoices_all
150: where project_id = pn_project_id and
151: draft_invoice_num = pn_draft_invoice_num ;
152:
145: -- cursor for getting one single invoice detail for corresponding project id and draft invoice num
146:
147: Cursor cur_get_inv_detail is
148: select pa_draft_invoices_all.*
149: from pa_draft_invoices_all
150: where project_id = pn_project_id and
151: draft_invoice_num = pn_draft_invoice_num ;
152:
153: begin
201: /*-------------------------------begin local method dflt_taxes_for_invoice_lines -----------------------------*/
202:
203:
204: procedure dflt_taxes_for_invoice_lines(
205: r_new in pa_draft_invoices_all%rowtype,
206: pv_action in varchar2,
207: pv_process_message out nocopy varchar2,
208: pv_process_flag out nocopy varchar2
209: ) is
345:
346: /*-------------------------------BEGIN LOCAL METHOD GET_TAX_CATEGORY -----------------------------*/
347:
348: procedure get_tax_category(
349: pn_project_id in pa_draft_invoices_all.project_id%type ,
350: pn_draft_invoice_num in pa_draft_invoices_all.draft_invoice_num%type ,
351: pn_line_num in pa_draft_invoice_items.line_num%type ,
352: pn_event_task_id in pa_draft_invoice_items.event_task_id%type,
353: pn_event_num in pa_draft_invoice_items.event_num%type,
346: /*-------------------------------BEGIN LOCAL METHOD GET_TAX_CATEGORY -----------------------------*/
347:
348: procedure get_tax_category(
349: pn_project_id in pa_draft_invoices_all.project_id%type ,
350: pn_draft_invoice_num in pa_draft_invoices_all.draft_invoice_num%type ,
351: pn_line_num in pa_draft_invoice_items.line_num%type ,
352: pn_event_task_id in pa_draft_invoice_items.event_task_id%type,
353: pn_event_num in pa_draft_invoice_items.event_num%type,
354: pv_action in varchar2,
473: pv_process_flag := jai_constants.expected_error;
474: end get_tax_category ;
475: /*-------------------------------BEGIN LOCAL METHOD GET_EVENT_TAX_CATEGORY -----------------------------*/
476: procedure get_event_tax_category(
477: pn_project_id in pa_draft_invoices_all.project_id%type ,
478: pn_draft_invoice_num in pa_draft_invoices_all.draft_invoice_num%type ,
479: pn_line_num in pa_draft_invoice_items.line_num%type ,
480: pn_event_task_id in pa_draft_invoice_items.event_task_id%type,
481: pn_event_num in pa_draft_invoice_items.event_num%type,
474: end get_tax_category ;
475: /*-------------------------------BEGIN LOCAL METHOD GET_EVENT_TAX_CATEGORY -----------------------------*/
476: procedure get_event_tax_category(
477: pn_project_id in pa_draft_invoices_all.project_id%type ,
478: pn_draft_invoice_num in pa_draft_invoices_all.draft_invoice_num%type ,
479: pn_line_num in pa_draft_invoice_items.line_num%type ,
480: pn_event_task_id in pa_draft_invoice_items.event_task_id%type,
481: pn_event_num in pa_draft_invoice_items.event_num%type,
482: pn_tax_category_id out nocopy JAI_CMN_TAX_CTGS_ALL.tax_category_id%type ,
591: end get_event_tax_category ;
592:
593: /*-------------------------------begin local method get_project_tax_category -----------------------------*/
594: procedure get_project_tax_category
595: ( pn_project_id in pa_draft_invoices_all.project_id%type ,
596: pn_draft_invoice_num in pa_draft_invoices_all.draft_invoice_num%type ,
597: pn_line_num in pa_draft_invoice_items.line_num%type ,
598: pn_tax_category_id out nocopy JAI_CMN_TAX_CTGS_ALL.tax_category_id%type ,
599: pv_process_status out nocopy varchar2 ,
592:
593: /*-------------------------------begin local method get_project_tax_category -----------------------------*/
594: procedure get_project_tax_category
595: ( pn_project_id in pa_draft_invoices_all.project_id%type ,
596: pn_draft_invoice_num in pa_draft_invoices_all.draft_invoice_num%type ,
597: pn_line_num in pa_draft_invoice_items.line_num%type ,
598: pn_tax_category_id out nocopy JAI_CMN_TAX_CTGS_ALL.tax_category_id%type ,
599: pv_process_status out nocopy varchar2 ,
600: pv_process_message out nocopy varchar2,
647: pv_process_flag := jai_constants.unexpected_error;
648: end get_project_tax_category;
649: /*-------------------------------begin local method get_cust_tax_category -----------------------------*/
650: procedure get_cust_tax_category
651: ( pn_project_id in pa_draft_invoices_all.project_id%type ,
652: pn_draft_invoice_num in pa_draft_invoices_all.draft_invoice_num%type ,
653: pn_line_num in pa_draft_invoice_items.line_num%type ,
654: pn_tax_category_id out nocopy JAI_CMN_TAX_CTGS_ALL.tax_category_id%type ,
655: pv_process_status out nocopy varchar2 ,
648: end get_project_tax_category;
649: /*-------------------------------begin local method get_cust_tax_category -----------------------------*/
650: procedure get_cust_tax_category
651: ( pn_project_id in pa_draft_invoices_all.project_id%type ,
652: pn_draft_invoice_num in pa_draft_invoices_all.draft_invoice_num%type ,
653: pn_line_num in pa_draft_invoice_items.line_num%type ,
654: pn_tax_category_id out nocopy JAI_CMN_TAX_CTGS_ALL.tax_category_id%type ,
655: pv_process_status out nocopy varchar2 ,
656: pv_process_message out nocopy varchar2,
657: pv_process_flag out nocopy varchar2
658: ) is
659: ----------------variable declarations---------------------------
660: ln_tax_category_id JAI_CMN_TAX_CTGS_ALL.tax_category_id%type;
661: ln_tax_customer_id pa_draft_invoices_all.ship_to_customer_id%type ;
662: ln_tax_address_id pa_draft_invoices_all.ship_to_address_id%type ;
663: ln_org_id NUMBER; /*Bug 8348822*/
664: ----------------cursor declarations------------------------------
665: -- responsible for getting tax category attached with customer / site combination or customer / null site combination
658: ) is
659: ----------------variable declarations---------------------------
660: ln_tax_category_id JAI_CMN_TAX_CTGS_ALL.tax_category_id%type;
661: ln_tax_customer_id pa_draft_invoices_all.ship_to_customer_id%type ;
662: ln_tax_address_id pa_draft_invoices_all.ship_to_address_id%type ;
663: ln_org_id NUMBER; /*Bug 8348822*/
664: ----------------cursor declarations------------------------------
665: -- responsible for getting tax category attached with customer / site combination or customer / null site combination
666: cursor cur_cust_site_tax(cn_customer_id pa_draft_invoices_all.ship_to_customer_id%type ,
662: ln_tax_address_id pa_draft_invoices_all.ship_to_address_id%type ;
663: ln_org_id NUMBER; /*Bug 8348822*/
664: ----------------cursor declarations------------------------------
665: -- responsible for getting tax category attached with customer / site combination or customer / null site combination
666: cursor cur_cust_site_tax(cn_customer_id pa_draft_invoices_all.ship_to_customer_id%type ,
667: cn_address_id pa_draft_invoices_all.ship_to_address_id%type) is
668: select setup_value1
669: from jai_pa_setup_values
670: where attribute1 = cn_customer_id and
663: ln_org_id NUMBER; /*Bug 8348822*/
664: ----------------cursor declarations------------------------------
665: -- responsible for getting tax category attached with customer / site combination or customer / null site combination
666: cursor cur_cust_site_tax(cn_customer_id pa_draft_invoices_all.ship_to_customer_id%type ,
667: cn_address_id pa_draft_invoices_all.ship_to_address_id%type) is
668: select setup_value1
669: from jai_pa_setup_values
670: where attribute1 = cn_customer_id and
671: attribute2 = cn_address_id and
671: attribute2 = cn_address_id and
672: context = jai_constants.setup_customer_site and
673: org_id = ln_org_id; /*Bug 8348822 - Tax defaulted based on ORG_ID of the project*/
674:
675: cursor cur_cust_tax(cn_customer_id pa_draft_invoices_all.ship_to_customer_id%type) is
676: select setup_value1
677: from jai_pa_setup_values
678: where attribute1 = cn_customer_id and
679: context = jai_constants.setup_customer_site and
732: end get_cust_tax_category;
733:
734: /*-------------------------------BEGIN LOCAL METHOD GET_EXPN_TAX_CATEGORY -----------------------------*/
735: procedure get_expn_tax_category
736: ( pn_project_id in pa_draft_invoices_all.project_id%type ,
737: pn_draft_invoice_num in pa_draft_invoices_all.draft_invoice_num%type ,
738: pn_line_num in pa_draft_invoice_items.line_num%type ,
739: pn_tax_category_id out nocopy JAI_CMN_TAX_CTGS_ALL.tax_category_id%type ,
740: pv_process_status out nocopy varchar2 ,
733:
734: /*-------------------------------BEGIN LOCAL METHOD GET_EXPN_TAX_CATEGORY -----------------------------*/
735: procedure get_expn_tax_category
736: ( pn_project_id in pa_draft_invoices_all.project_id%type ,
737: pn_draft_invoice_num in pa_draft_invoices_all.draft_invoice_num%type ,
738: pn_line_num in pa_draft_invoice_items.line_num%type ,
739: pn_tax_category_id out nocopy JAI_CMN_TAX_CTGS_ALL.tax_category_id%type ,
740: pv_process_status out nocopy varchar2 ,
741: pv_process_message out nocopy varchar2,
1034:
1035: ----------------variable declarations---------------------------
1036: ln_tax_amount number ;
1037: ln_tax_category_id JAI_CMN_TAX_CTGS_ALL.tax_category_id%type ;
1038: lv_inv_currency_code pa_draft_invoices_all.inv_currency_code%type;
1039: ln_inv_exchange_rate pa_draft_invoices_all.inv_exchange_rate%type;
1040: ----------------------------------------------------------------
1041: -- responsible to check for tax category id whether it is already exists .
1042: cursor cur_get_tax_caegotry is
1035: ----------------variable declarations---------------------------
1036: ln_tax_amount number ;
1037: ln_tax_category_id JAI_CMN_TAX_CTGS_ALL.tax_category_id%type ;
1038: lv_inv_currency_code pa_draft_invoices_all.inv_currency_code%type;
1039: ln_inv_exchange_rate pa_draft_invoices_all.inv_exchange_rate%type;
1040: ----------------------------------------------------------------
1041: -- responsible to check for tax category id whether it is already exists .
1042: cursor cur_get_tax_caegotry is
1043: select tax_category_id
1047: source_doc_type = jai_constants.pa_draft_invoice ;
1048:
1049: cursor cur_get_inv_info is
1050: select pdia.inv_currency_code , nvl(projfunc_invtrans_ex_rate,1) /*13513070 - Replaced inv_exchange_rate*/
1051: from pa_draft_invoices_all pdia, jai_pa_draft_invoice_lines jpdil
1052: where pdia.project_id = jpdil.project_id and
1053: pdia.draft_invoice_num = jpdil.draft_invoice_num and
1054: jpdil.draft_invoice_line_id = pn_draft_invoice_line_id and
1055: draft_invoice_id = pn_draft_invoice_id ;
1179: end if ;
1180:
1181: IF PV_CALLED_FROM IS NOT NULL AND PV_CALLED_FROM = 'JAINRWDI' THEN
1182: -- procedure is being called from invoice review - india ui hence get currency related
1183: -- information from the header table (pa_draft_invoices_all).
1184: --
1185: -- if procedure is being called from trigger this control should never come here
1186: -- it will result in mutation
1187: open cur_get_inv_info;
1293: bill_to_address_id,
1294: ship_to_address_id,
1295: draft_invoice_num_credited,
1296: write_off_flag
1297: from pa_draft_invoices_all
1298: where project_id = pn_project_id and
1299: draft_invoice_num = pn_draft_invoice_num ;
1300:
1301: begin
1329: pv_process_message out nocopy varchar2,
1330: pv_process_flag out nocopy varchar2
1331: ) is
1332:
1333: lv_inv_currency_code pa_draft_invoices_all.inv_currency_code%type;
1334: ln_inv_exchange_rate pa_draft_invoices_all.inv_exchange_rate%type;
1335: ln_tax_amount number ;
1336:
1337: cursor cur_get_line_detail is
1330: pv_process_flag out nocopy varchar2
1331: ) is
1332:
1333: lv_inv_currency_code pa_draft_invoices_all.inv_currency_code%type;
1334: ln_inv_exchange_rate pa_draft_invoices_all.inv_exchange_rate%type;
1335: ln_tax_amount number ;
1336:
1337: cursor cur_get_line_detail is
1338: select draft_invoice_id , draft_invoice_line_id