DBA Data[Home] [Help]

PACKAGE BODY: APPS.JAI_CMN_RGM_VAT_ACCNT_PKG

Source


1 PACKAGE BODY  jai_cmn_rgm_vat_accnt_pkg
2 /* $Header: jai_cmn_rgm_vat.plb 120.11 2008/04/09 09:38:58 jmeena ship $ */
3 /*****************************************************************************************************************************************************************
4 Created By       : aiyer
5 Created Date     : 17-Mar-2005
6 Enhancement Bug  : 4247989
7 Purpose          : Process the VAT Tax AR records (Invoice,Debit Memo and Credit memo) and populate the jai_rgms_trx_records and gl_interface appropriately.
8 
9                    Dependency Due To The Current Bug :
10                    This object has been newly created with as a part of the VAT enhancement.
11                    Needs to be always released along with the bug 4247989.Lot of Datamodel changes in this enhancement.
12                    For details refer base bug 4247989
13 
14 116.2                08-Jun-2005  Version 116.2 jai_cmn_rgm_vat -Object is Modified to refer to New DB Entity names in place of Old DB Entity Names
15           as required for CASE COMPLAINCE.
16 
17 13-Jun-2005    File Version: 116.3
18                Ramananda for bug#4428980. Removal of SQL LITERALs is done
19 
20 7     24/04/2007   Vijay Shankar for Bug#6012570 (5876390), Version:120.2 (115.8 )
21                      Forward Porting to R12:
22                        Modified the code to hit repository + GL for Projects Billing
23                        Modified the main cursor cur_get_deliveries and related code to handle projects billing
24 
25 3     14-jun-2007    sacsethi for bug 6072461 file version 120.3
26 
27 		     This bug is used to fp 11i bug 5183031 for vat reveresal
28 		     Problem - Vat Reversal Enhancement not forward ported
29 		     Solution - Changes has been done to make it compatible for vat reversal functioanlity also.
30 
31   		     Changed the two queries to include VAT REVERSAL tax type
32                      Changed the logic to charge recovery and expense accounts if the tax type is VAT REVERSAL
33 
34 4   28-jun-2007      ssumaith - bug#6147385
35 
36 		     changed the width of the variable lv_source from 30 to 100
37 
38 5.  01-08-2007       rchandan for bug#6030615 , Version 120.5
39                      Issue : Inter org Forward porting
40 
41 6.  21-aug-2007	     vkaranam for bug#6030615 ,File version 120.6
42                      Changes are done as part of the performance issue.
43 
44 Future Dependencies For the release Of this Object:-
45 (Please add a row in the section below only if your bug introduces a dependency due to spec change/ A new call to a object/
46 A datamodel change )
47 
48 ----------------------------------------------------------------------------------------------------------------------------------------------------
49 Current Version       Current Bug    Dependent         Dependency On Files       Version   Author   Date         Remarks
50 Of File                              On Bug/Patchset
51 jai_cmn_rgm_vat_accnt_pkg_pkg_b.sql
52 ----------------------------------------------------------------------------------------------------------------------------------------------------
53 115.0                  4247989       IN60106 +                                            Aiyer   17-Mar-2005   4146708 is the release bug for SERVICE/CESS
54                                      4146708 +                                                                             enhancement.
55                                      4245089                                                                    4245089 - Base bug for VAT Enhancement.
56 
57 ----------------------------------------------------------------------------------------------------------------------------------------------------
58 
59 7.  19-Sep-2007	     Bug 5739005. Added by vkantamn ,Version 120.7
60 		     Included source, source_trx_type and source_table_name in the
61 		     inner query of the cursor cur_get_deliveries and
62 		     cur_get_man_ar_inv_taxes for performance issue
63 		     reported.
64 		     It increased the performance
65 		     as these columns have index defined on them in
66 		     jai_rgm_trx_records.
67 
68 *****************************************************************************************************************************************************************/
69 AS
70 /*  */
71 
72 PROCEDURE record_debug_messages ( p_message VARCHAR2 )
73 /**************************************************************************
74 Created By       : aiyer
75 Created Date     : 17-Mar-2005
76 Enhancement Bug  : 4247989
77 Purpose          : write debug messages into the request log
78 Called From      :
79 ***************************************************************************/
80 AS
81 
82 BEGIN
83   IF nvl(upper(p_record_debug),'N') = 'Y' THEN
84     fnd_file.put_line(fnd_file.LOG,p_message);
85   END IF;
86 END record_debug_messages;
87 
88 PROCEDURE process_order_invoice
89 (
90     p_regime_id               IN      JAI_RGM_DEFINITIONS.REGIME_ID%TYPE                               ,
91     p_source                  IN      VARCHAR2                                                 ,
92     p_organization_id         IN      JAI_OM_WSH_LINES_ALL.ORGANIZATION_id%TYPE              ,
93     p_location_id             IN      JAI_OM_WSH_LINES_ALL.LOCATION_ID%TYPE                  ,
94     p_delivery_id             IN      JAI_OM_WSH_LINES_ALL.DELIVERY_ID%TYPE                  ,
95     p_customer_trx_id         IN      RA_CUSTOMER_TRX_ALL.CUSTOMER_TRX_ID%TYPE                 ,
96     p_transaction_type        IN      RA_CUST_TRX_TYPES.TYPE%TYPE, -- DEFAULT 'INV'   /* This parameter is used only for AR Accounting */ File.Sql.35 by Brathod
97     p_vat_invoice_no          IN      JAI_OM_WSH_LINES_ALL.VAT_INVOICE_NO%TYPE               ,
98     p_default_invoice_date    IN      DATE                                                     ,
99     p_batch_id                IN      NUMBER                                                   ,
100     p_called_from             IN      VARCHAR2                                                 ,
101     p_debug                   IN      VARCHAR2,   -- DEFAULT 'N'   File.Sql.35 by Brathod
102     p_process_flag    OUT NOCOPY      VARCHAR2                                                 ,
103     p_process_message OUT NOCOPY      VARCHAR2
104 )
105 /****************************************************************************************************
106 Created By       : aiyer
107 Created Date     : 17-Mar-2005
108 Enhancement Bug  : 4247989
109 Purpose          : Process the VAT Tax AR records (Invoice,Debit Memo and Credit memo)
110                    and populate the jai_rgms_trx_records and gl_interface appropriately.
111 
112 Called From      : India VAT Invoice Number/Accounting Concurrent Program:-
113                    =====================================================
114                    Procedure ja_.process
115 
116                    AR Invoice Completion:-
117                    =======================
118                     Trigger ja_in_loc_ar_hdr_update_trg for Invoice and Debit Memo
119                     Trigger ja_in_loc_ar_hdr_update_trg_vat for Credit Memo
120 
121 Changed History:
122 
123 1.	09-APR-2008	JMEENA for bug#6944839 File Version 120.1.12000000.4
124 			Modified the cursor cur_get_man_ar_inv_taxes, Changed jrttv1.tax_type to jrttv1.regime_code in where clause.
125 ***************************************************************************************************/
126 AS
127 
128   ln_repository_id                  JAI_RGM_TRX_RECORDS.REPOSITORY_ID%TYPE                          ;
129   ln_liab_acct_ccid                 GL_CODE_COMBINATIONS.code_combination_id%TYPE                   ;
130   ln_intliab_acct_ccid              GL_CODE_COMBINATIONS.code_combination_id%TYPE                   ;
131   ln_charge_ac_id                   GL_CODE_COMBINATIONS.code_combination_id%TYPE                   ;
132   ln_balancing_ac_id                GL_CODE_COMBINATIONS.code_combination_id%TYPE                   ;
133 
134   lv_process_flag                   VARCHAR2(2)                                                     ;
135   lv_process_message                VARCHAR2(1996)                                                  ;
136   ln_debit_amount                   JAI_RGM_TRX_RECORDS.DEBIT_AMOUNT%TYPE                           ;
137   ln_credit_amount                  JAI_RGM_TRX_RECORDS.CREDIT_AMOUNT%TYPE                          ;
138 
139   --Date 14/06/2007 by sacsethi for bug 6072461 (for VAT Reversal)
140   ln_recov_acct_ccid                 GL_CODE_COMBINATIONS.code_combination_id%TYPE                  ;
141   ln_expense_acct_ccid               GL_CODE_COMBINATIONS.code_combination_id%TYPE                  ;
142   lc_account_name                    VARCHAR2(50);
143   -- End 6072461
144   /*added the below cursors for performance issue,for bug#6030615*/
145       --start
146   CURSOR c_chk_rgm_trxs(cp_transaction_header_id in number,cp_transaction_temp_id in number,cp_tax_id in number) IS
147   SELECT 1
148           FROM
149           jai_rgm_trx_records jrtr
150           WHERE
151            jrtr.attribute1         = cp_transaction_header_id         AND
152            jrtr.source_document_id = cp_transaction_temp_id   AND
153            jrtr.reference_id       = cp_tax_id AND
154            jrtr.organization_id    = p_organization_id AND
155            jrtr.location_id        = p_location_id;
156 ln_rgm_cnt number;
157 
158   --end
159   /*added by rchandan for bug #6030615*/
160 /*
161 ||Fetch the information from jai_mtl_trxs and jai_cmn_document_taxes
162 */
163 CURSOR cur_get_mtltxns
164 IS
165 SELECT
166 	 jtc.tax_type,
167 	 jtc.tax_rate,
168 	 jtc.tax_id,
169 	 jmt.transaction_temp_id,
170 	 jmt.transaction_header_id,
171 	 jmt.vat_assessable_value,
172 	 jmt.creation_date,
173 	 jcdt.tax_amt
174 FROM
175 	 jai_mtl_trxs jmt,
176 	 jai_cmn_document_taxes jcdt,
177 	 jai_cmn_taxes_all jtc,
178 	 jai_rgm_registrations jrg,
179          jai_rgm_definitions jrr
180 WHERE
181 	 jmt.from_organization   = p_organization_id
182 			--   AND jmt.location_id        = p_location_id
183 	 AND jmt.transaction_header_id  = p_delivery_id
184 	 AND jmt.transaction_header_id=jcdt.source_doc_id
185 	 AND jmt.transaction_temp_id=jcdt.source_doc_line_id
186 	 AND jcdt.tax_id=jtc.tax_id
187 	 AND jtc.tax_type= jrg.attribute_code
188 	AND jrr.regime_code = jai_constants.vat_regime
189 	AND jrg.regime_id = jrr.regime_id
190 	AND jrg.registration_type = 'TAX_TYPES' ;
191 
192 
193   /*
194   || Fetch the delivery information from JAI_OM_WSH_LINES_ALL and JAI_OM_WSH_LINE_TAXES
195   */
196   /* Bug 5739005. Added by vkantamn
197      * Included source, source_trx_type and source_table_name in the inner
198      * query for performance issue reported.
199   */
200   CURSOR cur_get_deliveries
201     ( cp_source                  IN jai_rgm_trx_records.source%TYPE,
202        cp_source_trx_type	 IN jai_rgm_trx_records.source_trx_type%TYPE,
203        cp_source_table_name      IN jai_rgm_trx_records.source_table_name%TYPE
204     )
205   IS
206   SELECT
207         jspl.delivery_id                                        ,
208         jspl.delivery_detail_id                                 ,
209         jspl.vat_assessable_value                               ,
210         nvl(jspl.vat_exemption_flag,'N') vat_exemption_flag     ,
211         jspl.order_line_id                                      ,
212         jsptl.tax_id                                            ,
213         jsptl.tax_rate                                          ,
214         /* Bug# 6012570 (5876390)  jsptl.tax_amount                                        ,  */
215         jsptl.func_tax_amount                                   ,
216         jsptl.creation_date                                     ,
217         jtc.tax_type
218   FROM
219         JAI_OM_WSH_LINES_ALL       jspl              ,
220         JAI_OM_WSH_LINE_TAXES      jsptl             ,
221         JAI_CMN_TAXES_ALL          jtc               ,
222 	 ( --Date 14/06/2007 by sacsethi for bug 6072461 , View is replaced by subquery with vat reversal
223                SELECT jrttv1.tax_type  tax_type
224                FROM   jai_regime_tax_types_v  jrttv1
225                WHERE  jrttv1.regime_code = jai_constants.vat_regime --Modified by JMEENA from jrttv1.tax_type to jrttv1.regime_code for bug#6944839
226                UNION
227                SELECT 'VAT REVERSAL' tax_type FROM DUAL
228          ) jrttv
229   WHERE
230         jspl.organization_id    = p_organization_id                                                AND
231         jspl.location_id        = p_location_id                                                    AND
232         jspl.delivery_id        = p_delivery_id                                                    AND
233         jspl.delivery_detail_id = jsptl.delivery_detail_id                                         AND
234         jsptl.tax_id            = jtc.tax_id                                                       AND
235         jtc.tax_type            = jrttv.tax_type                                                   AND
236      -- jrttv.regime_code       = jai_constants.vat_regime                                         AND --Date 14/06/2007 by sacsethi for bug 6072461
237         NOT EXISTS                 ( SELECT 1
238                                      FROM jai_rgm_trx_records jrtr
239                                      WHERE
240 						-- Bug 5739005. Added by vkantamn
241 						jrtr.source             = cp_source AND
242 						jrtr.source_trx_type    =   cp_source_trx_type AND
243 						jrtr.organization_id    =  p_organization_id AND
244 						jrtr.location_id        =  p_location_id  AND
245 						jrtr.source_table_name  =  cp_source_table_name AND
246 					        -- End for bug 5739005.
247 						jrtr.attribute1         = jspl.delivery_id          AND
248 						jrtr.source_document_id = jspl.delivery_detail_id   AND
249 						jrtr.reference_id       = jsptl.tax_id
250                                    )
251       AND cp_source =  jai_constants.source_wsh /* Bug# 6012570 (5876390) */
252      /* start. bug#Bug# 6012570 (5876390). added the union condition */
253      UNION
254      SELECT
255              jpdi.draft_invoice_id                                       ,
256              null                             delivery_detail_id         ,
257              sum(jpdil.line_amt)              vat_assessable_value       ,
258              'N'                              vat_exemption_flag         ,
259              null                             order_line_id              ,
260              jcdt.tax_id                      tax_id                     ,
261              jcdt.tax_rate                    tax_rate                   ,
262              /* Bug# 6012570 (5876390) null                             tax_amount                 , */
263              sum(jcdt.func_tax_amt)           func_tax_amount            ,
264              max(jpdi.last_update_date)       creation_date              ,
265              jcdt.tax_type                    tax_type
266        FROM
267              jai_pa_draft_invoices           jpdi                        ,
268              jai_pa_draft_invoice_lines      jpdil                       ,
269              jai_cmn_document_taxes          jcdt                        ,
270              (
271                SELECT jrttv1.tax_type  tax_type
272                FROM   jai_regime_tax_types_v  jrttv1
273                WHERE  jrttv1.regime_code = jai_constants.vat_regime
274                UNION
275                SELECT 'VAT REVERSAL' tax_type FROM DUAL
276              ) jrttv
277        WHERE cp_source                 = jai_pa_billing_pkg.gv_source_projects
278        AND   jpdi.draft_invoice_id     = jpdil.draft_invoice_id
279        AND   jpdil.draft_invoice_line_id =  jcdt.source_doc_line_id
280        AND   jcdt.source_doc_id        = jpdi.draft_invoice_id
281        AND   jcdt.source_doc_type      = jai_pa_billing_pkg.gv_source_projects
282        AND   jcdt.tax_type             = jrttv.tax_type
283        AND   jpdi.draft_invoice_id     = p_delivery_id
284        GROUP BY jpdi.draft_invoice_id, jcdt.tax_type, jcdt.tax_id, jcdt.tax_rate;
285        /* end bug# 6012570 (5876390) */
286   /*
287   || Fetch the invoice information from ja_in_ra_customer_trx_tax_lines so_picking_lines and JAI_OM_WSH_LINE_TAXES
288   */
289    /* Bug 5739005. Added by vkantamn
290    * Included source, source_trx_type and source_table_name in the inner
291    * query for performance issue reported.
292    */
293   CURSOR cur_get_man_ar_inv_taxes
294   ( cp_source                  IN jai_rgm_trx_records.source%TYPE,
295        cp_source_trx_type     IN jai_rgm_trx_records.source_trx_type%TYPE,
296        cp_source_table_name IN jai_rgm_trx_records.source_table_name%TYPE
297      )
298   IS
299   SELECT
300         jctl.customer_trx_id                                    ,
301         jctl.vat_assessable_value                               ,
302         nvl(jctl.vat_exemption_flag,'N') vat_exemption_flag     ,
303         jcttl.customer_trx_line_id                              ,
304         jcttl.tax_id                                            ,
305         jcttl.link_to_cust_trx_line_id                          ,
306         jcttl.func_tax_amount                                   ,
307         jcttl.creation_date                                     ,
308         jtc.tax_type                                            ,
309         jcttl.tax_rate
310   FROM
311         JAI_AR_TRX_LINES jctl  ,
312         JAI_AR_TRX_TAX_LINES jcttl ,
313         JAI_CMN_TAXES_ALL              jtc  ,
314          ( --Date 14/06/2007 by sacsethi for bug 6072461 , View is replaced by subquery with vat reversal
315           SELECT jrttv1.tax_type  tax_type
316           FROM   jai_regime_tax_types_v  jrttv1
317           WHERE  jrttv1.regime_code  = jai_constants.vat_regime
318           UNION
319           SELECT 'VAT REVERSAL' tax_type
320           FROM DUAL
321          ) jrttv
322   WHERE
323         jctl.customer_trx_id      = p_customer_trx_id               AND
324         jctl.customer_trx_line_id = jcttl.link_to_cust_trx_line_id  AND
325         jcttl.tax_id              = jtc.tax_id                      AND
326         jtc.tax_type              = jrttv.tax_type                  AND
327         NOT EXISTS                 ( SELECT
328                                                1
329                                      FROM
330                                                jai_rgm_trx_records jrtr
331                                      WHERE
332                                                -- Bug 5739005. Added by vkantamn
333    						jrtr.source             = cp_source AND
334 						jrtr.source_trx_type    = cp_source_trx_type AND
335 						jrtr.organization_id    =  p_organization_id AND
336 						jrtr.location_id        =  p_location_id AND
337 						jrtr.source_table_name  =  cp_source_table_name AND
338 						-- End for bug 5739005
339 					        jrtr.attribute1         = p_customer_trx_id            AND
340                                                 jrtr.source_document_id = jcttl.customer_trx_line_id   AND
341                                                 jrtr.reference_id       = jcttl.tax_id
342                                    ) ;
343 
344 
345   /* Following variables added for Projects Billing. Bug# 6012570 (5876390) */
346   lv_source_trx_type    jai_rgm_trx_records.source_trx_type%type;
347   lv_source_table_name  VARCHAR2(30);
348   lv_called_from        VARCHAR2(100); /*ssumaith - changed the width to 100 from 30 */
349   lv_attribute_context  VARCHAR2(30);
350   ln_source_id          NUMBER(15);
351 
352 BEGIN
353 
354   record_debug_messages ('**********************1- START OF jai_cmn_rgm_processing_pkg.PROCESS_ORDER_INVOICE-P_DELIVERY ID ->'||p_delivery_id||' **********************');
355 
356   record_debug_messages ('2- Input parameters passed are p_called_from ->'||p_called_from
357                                                    ||', p_regime_id  -> '           || p_regime_id
358                                                    ||', p_source -> '           || p_source
359                                                    ||', p_organization_id -> '  || p_organization_id
360                                                    ||', p_location_id -> '      || p_location_id
361                                                    ||', p_delivery_id -> '      || p_delivery_id
362                                                    ||', p_customer_trx_id -> '  || p_customer_trx_id
363                                                    ||', p_transaction_type-> '  || p_transaction_type
364                                                    ||', p_vat_invoice_no ->'    || p_vat_invoice_no
365                                                    ||', p_batch_id -> '         || p_batch_id
366 
367                         );
368 
369 
370   /******************************************************************************************
371   ||Variable Initialization
372   ******************************************************************************************/
373 
374   lv_process_flag       := jai_constants.successful     ;
375   lv_process_message    := null                         ;
376 
377   p_process_flag        := lv_process_flag              ;
378   p_process_message     := lv_process_message           ;
379 
380   p_record_debug        := p_debug                      ;
381   ln_debit_amount       := NULL                         ;
382   ln_credit_amount      := NULL                         ;
383 
384 
385 
386   /******************************************************************************************
387   || Validate input parameters
388   ******************************************************************************************/
389 
390   IF p_regime_id IS NULL THEN
391     record_debug_messages('2.1 REGIME ID cannot be null');
392     p_process_flag    := jai_constants.expected_error;
393     p_process_message := 'Invalid REGIME';
394     return;
395   END IF;
396 
397   /*
398   || Validate that organization and location cannot be null
399   */
400 
401   IF p_organization_id IS NULL OR
402      p_location_id     IS NULL
403   THEN
404     record_debug_messages('3 Organization_id or Location_id cannot be null. Please provide a valid value for these fields');
405     p_process_flag    := jai_constants.expected_error;
406     p_process_message := 'Organization_id or Location_id cannot be null. Please provide a valid value for these fields';
407     return;
408   END IF;
409 
410 
411   /*
412   || Validate that organization and location cannot be null
413   */
414   IF p_delivery_id     IS NULL AND
415      p_customer_trx_id IS NULL
416   THEN
417     record_debug_messages(' 4 Delivery ID/Customer_trx_id both cannot be null. Please provide a valid value for either one of the two');
418     p_process_flag    := jai_constants.expected_error;
419     p_process_message := 'Delivery ID/Customer_trx_id both cannot be null. Please provide a valid value for either one of the two';
420     return;
421   END IF;
422 
423   /*
424   || Validate vat invoice number is passed
425   || Only in case of a CM the vat invoice number can be null (i.e called from JA_IN_LOC_AR_HDR_UPD_TRG_VAT )in all other
426   || cases if found as null then stop processing
427   */
428   IF p_vat_invoice_no          IS NULL                              AND
429      nvl(p_called_from,'####') <> 'JA_IN_LOC_AR_HDR_UPD_TRG_VAT'
430      AND  nvl(p_transaction_type ,'####') <> 'DRAFT_INVOICE_CM'   /* bug#6012570 (5876390) introduced for Projects Billing Implementation */
431   THEN
432     record_debug_messages('5 Vat Invoice Number cannot be null. Please provide a valid VAT Invoice Number');
433     p_process_flag    := jai_constants.expected_error;
434     p_process_message := nvl(p_transaction_type ,'####') /* bug#6012570 (5876390) */
435                             || 'Vat Invoice Number cannot be null. Please provide a valid VAT Invoice Number';
436     return;
437   END IF;
438 
439 
440   /******************************************************************************************
441   || Process the Deliver (In case of OM) and the Manual Invoice (in case of AR) and pass suitable
442   || accounting entries.
443   ******************************************************************************************/
444 
445   IF upper(p_source) in (
446                              upper(jai_constants.source_wsh)
447                              , jai_pa_billing_pkg.gv_source_projects     /* Bug# 6012570 (5876390) */
448                            )
449   THEN
450 
451     if jai_pa_billing_pkg.gv_debug then
452       jai_cmn_utils_pkg.print_log ( jai_pa_billing_pkg.file, '3 rgm_om_ar_vat_accnt_pkg.process_order_invoice . Psource:'||p_source);
453     end if;
454 
455     /* Start Bug# 6012570 (5876390) */
456     if upper(p_source) =  upper(jai_constants.source_wsh) then
457       record_debug_messages ('6 Delivery PROCESSING');
458       lv_source_trx_type    := jai_constants.source_ttype_delivery;
459       lv_source_table_name  := jai_constants.tname_dlry_dtl;
460       lv_called_from        := jai_constants.vat_repo_call_from_om_ar;
461       lv_attribute_context  := jai_constants.contxt_delivery;
462 
463     elsif p_source = jai_pa_billing_pkg.gv_source_projects then
464       record_debug_messages ('6 Projects Draft Invoice PROCESSING');
465       lv_source_trx_type    := jai_pa_billing_pkg.gv_trx_type_draft_invoice;    -- 'DRAFT_INVOICE';
466       lv_source_table_name  := jai_pa_billing_pkg.gv_draft_invoice_table;       -- 'JAI_PA_DRAFT_INVOICES';
467       lv_called_from        := p_called_from;
468       lv_attribute_context  := jai_pa_billing_pkg.gv_draft_invoice_release;     -- 'DRAFT_INVOICE_RELEASE';
469 
470     end if;
471     /* End Bug# 6012570 (5876390) */
472 
473 
474     /*
475     || Process Orders - OM side processing
476     */
477     /* Bug# 6012570 (5876390) FOR  rec_cur_get_deliveries IN cur_get_deliveries */
478     /* Bug 5739005 vkantamn --Parameters needed in cur_get_deliveries */
479     FOR  rec_cur_get_deliveries IN cur_get_deliveries(p_source, lv_source_trx_type, lv_source_table_name)
480     LOOP
481 
482       if jai_pa_billing_pkg.gv_debug then
483         jai_cmn_utils_pkg.print_log ( jai_pa_billing_pkg.file, '4 rgm_om_ar_vat_accnt_pkg.process_order_invoice. Loop TaxId:'||rec_cur_get_deliveries.tax_id);
484       end if;
485 
486       record_debug_messages (' ************7 PROCESSING Delivery id -> '|| p_delivery_id||'Delivery Details ID -> '||rec_cur_get_deliveries.delivery_detail_id||' ************' );
487       /*******************************
488       ||Variable Initialization
489       *******************************/
490       ln_liab_acct_ccid    := null;
491       ln_intliab_acct_ccid := null;
492       ln_debit_amount      := rec_cur_get_deliveries.func_tax_amount;
493 
494       /* Start - sacsethi, Added w.r.t BUG#6072461 ( for VAT Reversal)*/
495       ln_credit_amount     := null;
496       ln_debit_amount      := null;
497       ln_recov_acct_ccid   := null;
498       ln_expense_acct_ccid := null;
499       ln_charge_ac_id      := null;
500       ln_balancing_ac_id   := null;
501       lc_account_name      := null;
502       /* End - sacsethi, Added w.r.t BUG#6072461 ( for VAT Reversal)*/
503 
504       /* Start Bug# 6012570 (5876390) */
505        if upper(p_source) =  upper(jai_constants.source_wsh) then
506          ln_source_id  := rec_cur_get_deliveries.delivery_detail_id;
507 
508        elsif p_source = jai_pa_billing_pkg.gv_source_projects then
509          ln_source_id  := rec_cur_get_deliveries.delivery_id;  /* this is draft_invoice_id */
510 
511        end if;
512        /* End Bug# 6012570 (5876390) */
513 
514       record_debug_messages ('8 Variables Initialised');
515 
516 
517       IF ( rec_cur_get_deliveries.tax_type = 'VAT REVERSAL' ) THEN
518         /* Start - sacsethi, Added w.r.t BUG#6072461 ( for VAT Reversal)*/
519         /*******************************
520         ||Get the code combination id
521         ||for the "RECOVERY ACCOUNT"
522         *******************************/
523         ln_recov_acct_ccid   :=    jai_cmn_rgm_recording_pkg.get_account(
524                                                                           p_regime_id         => p_regime_id                        ,
525                                                                           p_organization_type => jai_constants.orgn_type_io         ,
526                                                                           p_organization_id   => p_organization_id                  ,
527                                                                           p_location_id       => p_location_id                      ,
528                                                                           p_tax_type          => rec_cur_get_deliveries.tax_type    ,
529                                                                           p_account_name      => jai_constants.recovery
530                                                                         ) ;
531 
532         /*******************************
533         || Get the code combination id
534         || for the "EXPENSE ACCOUNT"
535         *******************************/
536         ln_expense_acct_ccid :=    jai_cmn_rgm_recording_pkg.get_account(
537                                                                           p_regime_id         => p_regime_id                        ,
538                                                                           p_organization_type => jai_constants.orgn_type_io         ,
539                                                                           p_organization_id   => p_organization_id                  ,
540                                                                           p_location_id       => p_location_id                      ,
541                                                                           p_tax_type          => rec_cur_get_deliveries.tax_type    ,
542                                                                           p_account_name      => jai_constants.expense
543                                                                         ) ;
544         lc_account_name       := jai_constants.recovery;
545         ln_charge_ac_id       := ln_recov_acct_ccid;
546         ln_balancing_ac_id    := ln_expense_acct_ccid;
547         ln_credit_amount      := rec_cur_get_deliveries.func_tax_amount;
548         IF  ln_charge_ac_id  IS NULL OR
549             ln_balancing_ac_id IS NULL
550         THEN
551           record_debug_messages('9 VAT delivery accounting entries cannot be passed. Please set up the Recovery account and the Expense account for VAT Reversal');
552           p_process_flag    := jai_constants.expected_error;
553           p_process_message := 'VAT delivery accounting entries cannot be passed. Please set up the Recovery account and the Expense account for VAT reversal';
554           return;
555         END IF;
556         /* End - sacsethi, Added w.r.t BUG#6072461 ( for VAT Reversal)*/
557       ELSE
558 
559       /*******************************
560       ||Get the code combination id
561       ||for the "LIABILITY ACCOUNT"
562       *******************************/
563       ln_liab_acct_ccid    :=    jai_cmn_rgm_recording_pkg.get_account(
564                                                                           p_regime_id         => p_regime_id                        ,
565                                                                           p_organization_type => jai_constants.orgn_type_io         ,
566                                                                           p_organization_id   => p_organization_id                  ,
567                                                                           p_location_id       => p_location_id                      ,
568                                                                           p_tax_type          => rec_cur_get_deliveries.tax_type    ,
569                                                                           p_account_name      => jai_constants.liability
570                                                                       ) ;
571 
572       /*******************************
573       || Get the code combination id
574       || for the "INTERIM LIABILITY ACCOUNT"
575       *******************************/
576       ln_intliab_acct_ccid :=    jai_cmn_rgm_recording_pkg.get_account(
577                                                                           p_regime_id         => p_regime_id                        ,
578                                                                           p_organization_type => jai_constants.orgn_type_io         ,
579                                                                           p_organization_id   => p_organization_id                  ,
580                                                                           p_location_id       => p_location_id                      ,
581                                                                           p_tax_type          => rec_cur_get_deliveries.tax_type    ,
582                                                                           p_account_name      => jai_constants.liability_interim
583                                                                       ) ;
584 
585 
586         /* Start - sacsethi, Added w.r.t BUG#6072461 ( for VAT Reversal)*/
587         lc_account_name       := jai_constants.liability;
588         ln_charge_ac_id       := ln_liab_acct_ccid;
589         ln_balancing_ac_id    := ln_intliab_acct_ccid;
590         ln_debit_amount       := rec_cur_get_deliveries.func_tax_amount;
591         IF  ln_charge_ac_id    IS NULL OR
592             ln_balancing_ac_id IS NULL
593         THEN
594           record_debug_messages('9 VAT delivery accounting entries cannot be passed. Please set up the Liability account and the Interim Liability account for the corresponding VAT regime');
595           p_process_flag    := jai_constants.expected_error;
596           p_process_message := 'VAT delivery accounting entries cannot be passed. Please set up the Liability account and the Interim Liability account for the corresponding VAT regime';
597           return;
598         END IF;
599       END IF;
600 
601       --Date 14/06/2007 by sacsethi for bug 6072461
602 	      -- FOR VAT REVERSAL
603 
604       /*
605       || Validate that if any one of the liability account or interim liability account is not defined then error our
606       */
607       /*
608       IF ln_liab_acct_ccid    IS NULL OR
609          ln_intliab_acct_ccid IS NULL
610       THEN
611         record_debug_messages('9 VAT delivery accouting entries cannot be passed. Please set up the Liability account and the Interim Liability account for the corresponding VAT regime');
612         p_process_flag    := jai_constants.expected_error;
613         p_process_message := 'VAT delivery accouting entries cannot be passed. Please set up the Liability account and the Interim Liability account for the corresponding VAT regime';
614         return;
615       END IF;
616       END IF ;
617    */
618 
619       record_debug_messages ('10 Processing the delivery, parameters are delivery_id -> '           || rec_cur_get_deliveries.delivery_id
620                                            ||', source_document_type_id i.e delivery_detail_id -> ' || rec_cur_get_deliveries.delivery_detail_id
621                                            ||', rec_cur_get_deliveries.tax_type  -> '               || rec_cur_get_deliveries.tax_type
622                                            ||', p_organization_id -> '                              || p_organization_id
623                                            ||', p_location_id -> '                                  || p_location_id
624                                            ||', vat_exemption_flag -> '                             || rec_cur_get_deliveries.vat_exemption_flag
625                                            ||', pn_assessable_value ->'                             || rec_cur_get_deliveries.vat_assessable_value
626                                            ||', account_name -> '                                   || jai_constants.liability
627                                            ||', p_charge_account_id-> '                             || ln_liab_acct_ccid
628                                            ||', p_balancing_account_id-> '                          || ln_intliab_acct_ccid
629                                            ||',ln_debit_amount -> '                                 || ln_debit_amount
630                                            ||',ln_credit_amount -> '                                || ln_credit_amount
631                                            ||', p_amount-> '                                        || rec_cur_get_deliveries.func_tax_amount
632                                            ||', p_trx_amount-> '                                    || rec_cur_get_deliveries.func_tax_amount
633                                            ||', p_tax_rate -> '                                     || rec_cur_get_deliveries.tax_rate
634                                            ||', p_reference_id  i.e tax_id -> '                     || rec_cur_get_deliveries.tax_id
635                                            ||', p_inv_organization_id -> '                          || p_organization_id
636                                            ||', p_attribute1 i.e delivery_id -> '                   || rec_cur_get_deliveries.delivery_id
637                                            ||', p_attribute2 i.e order_line_id -> '                 || rec_cur_get_deliveries.order_line_id
638                                            ||', p_attribute_context -> '                            || jai_constants.contxt_delivery
639                             );
640 
641       record_debug_messages ('11 Before call to jai_cmn_rgm_recording_pkg.insert_vat_repository_entry');
642 
643 
644        if jai_pa_billing_pkg.gv_debug then
645          jai_cmn_utils_pkg.print_log ( jai_pa_billing_pkg.file, '6 rgm_om_ar_vat_accnt_pkg.process_order_invoice. Bef jai_cmn_rgm_recording_pkg.insert_vat_repository_entry');
646        end if;
647 
648        jai_cmn_rgm_recording_pkg.insert_vat_repository_entry (
649             pn_repository_id            => ln_repository_id                                                   ,
650             pn_regime_id                => p_regime_id                                                        ,
651             pv_tax_type                 => rec_cur_get_deliveries.tax_type                                    ,
652             pv_organization_type        => jai_constants.orgn_type_io                                         ,
653             pn_organization_id          => p_organization_id                                                  ,
654             pn_location_id              => p_location_id                                                      ,
655             pv_source                   => p_source                                                           ,
656             pv_source_trx_type          => lv_source_trx_type,  /* Bug# 6012570 (5876390) jai_constants.source_ttype_delivery                                , */
657             pv_source_table_name        => lv_source_table_name, /* Bug# 6012570 (5876390) jai_constants.tname_dlry_dtl                                       , */
658             pn_source_id                => ln_source_id,          /* Bug# 6012570 (5876390) rec_cur_get_deliveries.delivery_detail_id                          , */
659             pd_transaction_date         => rec_cur_get_deliveries.creation_date                               ,
660 /*  Date 14/06/2007 by sacsethi for bug 6072461
661 	    pv_account_name             => jai_constants.liability                                            ,
662             pn_charge_account_id        => ln_liab_acct_ccid                                                  ,
663             pn_balancing_account_id     => ln_intliab_acct_ccid                                               ,
664     Changes in account name , charge account id and balancing account id      */
665             pv_account_name             => lc_account_name                                                    ,
666             pn_charge_account_id        => ln_charge_ac_id                                                    ,
667             pn_balancing_account_id     => ln_balancing_ac_id                                                 ,
668             pn_credit_amount            => ln_credit_amount                                                   ,
669             pn_debit_amount             => ln_debit_amount                                                    ,
670             pn_assessable_value         => rec_cur_get_deliveries.vat_assessable_value                        ,
671             pn_tax_rate                 => rec_cur_get_deliveries.tax_rate                                    ,
672             pn_reference_id             => rec_cur_get_deliveries.tax_id                                      ,
673             pn_batch_id                 => p_batch_id                                                         ,
674             pn_inv_organization_id      => p_organization_id                                                  ,
675             pv_invoice_no               => p_vat_invoice_no                                                   ,
676             pd_invoice_date             => nvl(p_default_invoice_date,rec_cur_get_deliveries.creation_date)   ,
677             pv_called_from              => lv_called_from,    /* Bug# 6012570 (5876390) jai_constants.vat_repo_call_from_om_ar                                  , */
678             pv_process_flag             => lv_process_flag                                                    ,
679             pv_process_message          => lv_process_message                                                 ,
680             pv_attribute_context        => lv_attribute_context,    /* Bug# 6012570 (5876390) jai_constants.contxt_delivery                                      , */
681             pv_attribute1               => rec_cur_get_deliveries.delivery_id                                 ,
682             pv_attribute2               => rec_cur_get_deliveries.order_line_id                               ,
683             pv_attribute3               => NULL                                                               ,
684             pv_attribute4               => NULL                                                               ,
685             pv_attribute5               => NULL
686       );
687 
688         if jai_pa_billing_pkg.gv_debug then
689           jai_cmn_utils_pkg.print_log ( jai_pa_billing_pkg.file, '7 rgm_om_ar_vat_accnt_pkg.process_order_invoice. After callto insert_vat_repository_entry'
690               ||', ln_repository_id:'||ln_repository_id
691               ||', lv_process_flag:'||lv_process_flag
692               ||', lv_process_message:'||lv_process_message
693           );
694         end if;
695 
696         IF lv_process_flag = jai_constants.expected_error    OR
697            lv_process_flag = jai_constants.unexpected_error
698         THEN
699           /*
700           || As Returned status is an error hence:-
701           ||1. Delivery processing should be terminated,Rollback the insert and exit Loop
702           ||2. Set out variables p_process_flag and p_process_message accordingly
703           ||3. Return from the procedure
704           */
705           record_debug_messages(' 12 Error in call to jai_cmn_rgm_recording_pkg.insert_vat_repository_entry - lv_process_flag '||lv_process_flag
706                                             ||', lv_process_message'     || lv_process_message
707                                             ||', Delivery id -  '        || rec_cur_get_deliveries.delivery_id
708                                             ||', Delivery_details_id -> '|| rec_cur_get_deliveries.delivery_detail_id
709                                             ||', Tax_amount -> '         || rec_cur_get_deliveries.func_tax_amount
710                                             ||', Tax_id -> '             || rec_cur_get_deliveries.tax_id
711                                             ||', Tax_type -> '           || rec_cur_get_deliveries.tax_type
712                            );
713           p_process_flag    := lv_process_flag    ;
714           p_process_message := lv_process_message ;
715           return;
716         END IF;
717 
718         record_debug_messages ('13 Returned from jai_cmn_rgm_recording_pkg.insert_vat_repository_entry and ');
719 
720         IF rec_cur_get_deliveries.vat_exemption_flag = 'N' THEN
721           record_debug_messages ('13.1 before call to jai_cmn_rgm_recording_pkg.do_vat_accounting');
722 
723 
724           record_debug_messages ('14 Processing the delivery,parameters are delivery_id -> '            || rec_cur_get_deliveries.delivery_id
725                            ||', source_document_type_id i.e delivery_detail_id -> ' || rec_cur_get_deliveries.delivery_detail_id
726                            ||', rec_cur_get_deliveries.tax_type  -> '               || rec_cur_get_deliveries.tax_type
727                            ||', p_organization_id -> '                              || p_organization_id
728                            ||', p_location_id -> '                                  || p_location_id
729                            ||', vat_exemption_flag -> '                             || rec_cur_get_deliveries.vat_exemption_flag
730                            ||', pn_assessable_value ->'                             || rec_cur_get_deliveries.vat_assessable_value
731                            ||', account_name -> '                                   || jai_constants.liability
732                            ||', p_charge_account_id-> '                             || ln_liab_acct_ccid
733                            ||', p_balancing_account_id-> '                          || ln_intliab_acct_ccid
734                            ||', ln_debit_amount -> '                                || ln_debit_amount
735                            ||', ln_credit_amount -> '                               || ln_credit_amount
736                            ||', p_amount-> '                                        || rec_cur_get_deliveries.func_tax_amount
737                            ||', p_trx_amount-> '                                    || rec_cur_get_deliveries.func_tax_amount
738                            ||', p_tax_rate -> '                                     || rec_cur_get_deliveries.tax_rate
739                            ||', accounting_date -> '                                || nvl(p_default_invoice_date,rec_cur_get_deliveries.creation_date)
740                            ||', p_reference_id  i.e tax_id -> '                     || rec_cur_get_deliveries.tax_id
741                            ||', p_inv_organization_id -> '                          || p_organization_id
742                            ||', p_attribute1 i.e delivery_id -> '                   || rec_cur_get_deliveries.delivery_id
743                            ||', p_attribute2 i.e order_line_id -> '                 || rec_cur_get_deliveries.order_line_id
744                            ||', p_attribute_context -> '                            || jai_constants.contxt_delivery
745             );
746 
747 
748           if jai_pa_billing_pkg.gv_debug then
749             jai_cmn_utils_pkg.print_log ( jai_pa_billing_pkg.file, '9 rgm_om_ar_vat_accnt_pkg.process_order_invoice. Before callto jai_cmn_rgm_recording_pkg.do_vat_accounting.');
750           end if;
751 
752           jai_cmn_rgm_recording_pkg.do_vat_accounting (
753               pn_regime_id            =>  p_regime_id                                                       ,
754               pn_repository_id        =>  ln_repository_id                                                  ,
755               pv_organization_type    =>  jai_constants.orgn_type_io                                        ,
756               pn_organization_id      =>  p_organization_id                                                 ,
757               /*Check with support whether this should be transaction date or sysdate */
758               pd_accounting_date      =>  nvl(p_default_invoice_date,rec_cur_get_deliveries.creation_date)  ,
759               pd_transaction_date     =>  rec_cur_get_deliveries.creation_date                              ,
760 /*   --Date 14/06/2007 by sacsethi for bug 6072461
761 	      pn_credit_amount        =>  ln_debit_amount                                                   ,
762               pn_debit_amount         =>  ln_debit_amount                                                   ,
763               pn_credit_ccid          =>  ln_liab_acct_ccid                                                 ,
764               pn_debit_ccid           =>  ln_intliab_acct_ccid                                              ,
765 */            pn_credit_amount        =>  nvl(ln_debit_amount,ln_credit_amount)                             ,
766               pn_debit_amount         =>  nvl(ln_debit_amount,ln_credit_amount)                             ,
767               pn_credit_ccid          =>  ln_charge_ac_id                                                   ,
768               pn_debit_ccid           =>  ln_balancing_ac_id                                                ,
769               pv_called_from          =>  lv_called_from,   /* Bug# 6012570 (5876390) jai_constants.vat_repo_call_from_om_ar                                 , */
770               pv_process_flag         =>  lv_process_flag                                                   ,
771               pv_process_message      =>  lv_process_message                                                ,
772               pv_tax_type             =>  rec_cur_get_deliveries.tax_type                                   ,
773               pv_source               =>  p_source                                                          ,
774               pv_source_trx_type      =>  lv_source_trx_type,   /* Bug# 6012570 (5876390) jai_constants.source_ttype_delivery                               ,*/
775               pv_source_table_name    =>  lv_source_table_name,   /* Bug# 6012570 (5876390) jai_constants.tname_dlry_dtl                                      ,*/
776               pn_source_id            =>  ln_source_id,     /* Bug# 6012570 (5876390) rec_cur_get_deliveries.delivery_detail_id                         ,*/
777               pv_reference_name       =>  /*jai_constants.JAI_CMN_TAXES_ALL*/'JA_IN_TAX_CODES'                ,
778               pn_reference_id         =>  rec_cur_get_deliveries.tax_id
779              );
780 
781           if jai_pa_billing_pkg.gv_debug then
782             jai_cmn_utils_pkg.print_log ( jai_pa_billing_pkg.file, '9 rgm_om_ar_vat_accnt_pkg.process_order_invoice. After callto do_vat_accounting.'
783               ||', lv_process_flag:'||lv_process_flag
784               ||', lv_process_message:'||lv_process_message
785             );
786           end if;
787 
788 
789           IF lv_process_flag = jai_constants.expected_error    OR
790              lv_process_flag = jai_constants.unexpected_error
791           THEN
792             /*
793             || As Returned status is an error hence:-
794             ||1. Delivery processing should be terminated,Rollback the insert and exit Loop
795             ||2. Set out variables p_process_flag and p_process_message accordingly
796             ||3. Return from the procedure
797             */
798             record_debug_messages(' 15 Error in call to jai_cmn_rgm_recording_pkg.do_vat_accounting - lv_process_flag '||lv_process_flag
799                                               ||', lv_process_message'     || lv_process_message
800                                               ||', Delivery id -  '        || rec_cur_get_deliveries.delivery_id
801                                               ||', Delivery_details_id -> '|| rec_cur_get_deliveries.delivery_detail_id
802                                               ||', Tax_amount -> '         || rec_cur_get_deliveries.func_tax_amount
803                                               ||', Tax_id -> '             || rec_cur_get_deliveries.tax_id
804                                               ||', Tax_type -> '           || rec_cur_get_deliveries.tax_type
805                              );
806             p_process_flag    := lv_process_flag    ;
807             p_process_message := lv_process_message ;
808             return;
809           END IF;
810 
811           record_debug_messages ('16 Returned from jai_cmn_rgm_recording_pkg.do_vat_accounting');
812         END IF; /* End IF of Vat Exemption Flag*/
813 
814     END LOOP;
815 
816  /*added by rchandan for bug#6030615*/
817 	 ELSIF p_source='INTERORG_XFER' THEN
818 	 --jai_constants.source_intxfer
819 				 /*
820 		 || Process Interorg Transfers - INV side processing
821 		 */
822 		 ln_rgm_cnt := 0;
823 		 FOR  rec_cur_get_mtl_txns IN cur_get_mtltxns
824 		 LOOP
825 		  open c_chk_rgm_trxs(rec_cur_get_mtl_txns.transaction_header_id,rec_cur_get_mtl_txns.transaction_temp_id,rec_cur_get_mtl_txns.tax_id);
826 		  fetch c_chk_rgm_trxs into ln_rgm_cnt;
827 	          close c_chk_rgm_trxs;
828 
829 	          if nvl(ln_rgm_cnt,0) = 0 then
830 			 record_debug_messages (' ************7 PROCESSING Delivery id -> '|| p_delivery_id||'Delivery Details ID -> '||rec_cur_get_mtl_txns.transaction_temp_id||' ************' );
831 			 /*******************************
832 			 ||Variable Initialization
833 			 *******************************/
834 			 ln_liab_acct_ccid    := null;
835 			 ln_intliab_acct_ccid := null;
836 			 ln_credit_amount     := null;
837 			 ln_debit_amount      := null;
838 			 ln_recov_acct_ccid   := null;
839 			 ln_expense_acct_ccid := null;
840 			 ln_charge_ac_id      := null;
841 			 ln_balancing_ac_id:= null;
842 			 lc_account_name      := null;
843 			 record_debug_messages ('8 Variables Initialised');
844 			 IF ( rec_cur_get_mtl_txns.tax_type = 'VAT REVERSAL' ) THEN
845 				 /*******************************
846 				 ||Get the code combination id
847 				 ||for the "RECOVERY ACCOUNT"
848 				 *******************************/
849 				 ln_recov_acct_ccid   :=    jai_cmn_rgm_recording_pkg.get_account(
850 																																					 p_regime_id         => p_regime_id                        ,
851 																																					 p_organization_type => jai_constants.orgn_type_io         ,
852 																																					 p_organization_id   => p_organization_id                  ,
853 																																					 p_location_id       => p_location_id                      ,
854 																																					 p_tax_type          => rec_cur_get_mtl_txns.tax_type    ,
855 																																					 p_account_name      => jai_constants.recovery
856 																																				 ) ;
857 				 /*******************************
858 				 || Get the code combination id
859 				 || for the "EXPENSE ACCOUNT"
860 				 *******************************/
861 				 ln_expense_acct_ccid :=    jai_cmn_rgm_recording_pkg.get_account(
862 																																					 p_regime_id         => p_regime_id                        ,
863 																																					 p_organization_type => jai_constants.orgn_type_io         ,
864 																																					 p_organization_id   => p_organization_id                  ,
865 																																					 p_location_id       => p_location_id                      ,
866 																																					 p_tax_type          => rec_cur_get_mtl_txns.tax_type    ,
867 																																					 p_account_name      => jai_constants.expense
868 																																				 ) ;
869 				 lc_account_name       := jai_constants.recovery;
870 				 ln_charge_ac_id       := ln_recov_acct_ccid;
871 				 ln_balancing_ac_id    := ln_expense_acct_ccid;
872 				 ln_credit_amount      := rec_cur_get_mtl_txns.tax_amt;
873 				 IF  ln_charge_ac_id  IS NULL OR
874 						 ln_balancing_ac_id IS NULL
875 				 THEN
876 					 record_debug_messages('9 VAT delivery accounting entries cannot be passed. Please set up the Recovery account and the Expense account for VAT Reversal');
877 					 p_process_flag    := jai_constants.expected_error;
878 					 p_process_message := 'VAT delivery accounting entries cannot be passed. Please set up the Recovery account and the Expense account for VAT reversal';
879 					 return;
880 				 END IF;
881 			 ELSE
882 				 /*******************************
883 				 ||Get the code combination id
884 				 ||for the "LIABILITY ACCOUNT"
885 				 *******************************/
886 				 ln_liab_acct_ccid    :=    jai_cmn_rgm_recording_pkg.get_account(
887 																																					 p_regime_id         => p_regime_id                        ,
888 																																					 p_organization_type => jai_constants.orgn_type_io         ,
889 																																					 p_organization_id   => p_organization_id                  ,
890 																																					 p_location_id       => p_location_id                      ,
891 																																					 p_tax_type          => rec_cur_get_mtl_txns.tax_type    ,
892 																																					 p_account_name      => jai_constants.liability
893 																																				 ) ;
894 				 /*******************************
895 				 || Get the code combination id
896 				 || for the "INTERIM LIABILITY ACCOUNT"
897 				 *******************************/
898 				 ln_intliab_acct_ccid :=    jai_cmn_rgm_recording_pkg.get_account(
899 																																					 p_regime_id         => p_regime_id                        ,
900 																																					 p_organization_type => jai_constants.orgn_type_io         ,
901 																																					 p_organization_id   => p_organization_id                  ,
902 																																					 p_location_id       => p_location_id                      ,
903 																																					 p_tax_type          => rec_cur_get_mtl_txns.tax_type    ,
904 																																					 p_account_name      => jai_constants.liability_interim
905 																																				 ) ;
906 				 lc_account_name       := jai_constants.liability;
907 				 ln_charge_ac_id       := ln_liab_acct_ccid;
908 				 ln_balancing_ac_id    := ln_intliab_acct_ccid;
909 				 ln_debit_amount       := rec_cur_get_mtl_txns.tax_amt;
910 				 IF  ln_charge_ac_id    IS NULL OR
911 						 ln_balancing_ac_id IS NULL
912 				 THEN
913 					 record_debug_messages('9 VAT delivery accounting entries cannot be passed. Please set up the Liability account and the Interim Liability account for the corresponding VAT regime');
914 					 p_process_flag    := jai_constants.expected_error;
915 					 p_process_message := 'VAT delivery accounting entries cannot be passed. Please set up the Liability account and the Interim Liability account for the corresponding VAT regime';
916 					 return;
917 				 END IF;
918 			 END IF;
919 			 record_debug_messages ('10 Processing the delivery, parameters are delivery_id -> '           || rec_cur_get_mtl_txns.transaction_header_id
920 																						||', source_document_type_id i.e delivery_detail_id -> ' || rec_cur_get_mtl_txns.transaction_temp_id
921 																						||', rec_cur_get_deliveries.tax_type  -> '               || rec_cur_get_mtl_txns.tax_type
922 																						||', p_organization_id -> '                              || p_organization_id
923 																						||', p_location_id -> '                                  || p_location_id
924 																						||', vat_exemption_flag -> '                             || null
925 																						||', pn_assessable_value ->'                             || rec_cur_get_mtl_txns.vat_assessable_value
926 																						||', account_name -> '                                   || lc_account_name
927 																						||', p_charge_account_id-> '                             || ln_charge_ac_id
928 																						||', p_balancing_account_id-> '                          || ln_balancing_ac_id
929 																						||',ln_debit_amount -> '                                 || ln_debit_amount
930 																						||',ln_credit_amount -> '                                || ln_credit_amount
931 																						||', p_amount-> '                                        || rec_cur_get_mtl_txns.tax_amt
932 																						||', p_trx_amount-> '                                    || rec_cur_get_mtl_txns.tax_amt
933 																						||', p_tax_rate -> '                                     || rec_cur_get_mtl_txns.tax_rate
934 																						||', p_reference_id  i.e tax_id -> '                     || rec_cur_get_mtl_txns.tax_id
935 																						||', p_inv_organization_id -> '                          || p_organization_id
936 																						||', p_attribute1 i.e delivery_id -> '                   || rec_cur_get_mtl_txns.transaction_header_id
937 																						||', p_attribute2 i.e order_line_id -> '                 || null
938 																						||', p_attribute_context -> '                            || jai_constants.contxt_delivery
939 														 );
940 			 record_debug_messages ('11 Before call to jai_cmn_rgm_recording_pkg.insert_repository_entry');
941 				jai_cmn_rgm_recording_pkg.insert_vat_repository_entry (
942 																																		 pn_repository_id            => ln_repository_id                                                   ,
943 																																		 pn_regime_id                => p_regime_id                                                        ,
944 																																		 pv_tax_type                 => rec_cur_get_mtl_txns.tax_type                                    ,
945 																																		 pv_organization_type        => jai_constants.orgn_type_io                                         ,
946 																																		 pn_organization_id          => p_organization_id                                                  ,
947 																																		 pn_location_id              => p_location_id                                                      ,
948 																																		 pv_source                   => p_source                                                           ,
949 																																		 pv_source_trx_type          => jai_constants.source_ttype_delivery                                ,
950 																																		 pv_source_table_name        => jai_constants.tname_dlry_dtl                                       ,
951 																																		 pn_source_id                => rec_cur_get_mtl_txns.transaction_temp_id                         ,
952 																																		 pd_transaction_date         => rec_cur_get_mtl_txns.creation_date                               ,
953 																																		 pv_account_name             => lc_account_name                                                    ,
954 																																		 pn_charge_account_id        => ln_charge_ac_id                                                    ,
955 																																		 pn_balancing_account_id     => ln_balancing_ac_id                                                 ,
956 																																		 pn_credit_amount            => LN_CREDIT_AMOUNT                                                   ,
957 																																		 pn_debit_amount             => ln_debit_amount                                                    ,
958 																																		 pn_assessable_value         => rec_cur_get_mtl_txns.vat_assessable_value                        ,
959 																																		 pn_tax_rate                 => rec_cur_get_mtl_txns.tax_rate                                    ,
960 																																		 pn_reference_id             => rec_cur_get_mtl_txns.tax_id                                      ,
961 																																		 pn_batch_id                 => p_batch_id                                                         ,
962 																																		 pn_inv_organization_id      => p_organization_id                                                  ,
963 																																		 pv_invoice_no               => p_vat_invoice_no                                                   ,
964 																																		 pd_invoice_date             => nvl(p_default_invoice_date,rec_cur_get_mtl_txns.creation_date)   ,
965 																																		 pv_called_from              => jai_constants.vat_repo_call_from_om_ar                                  ,
966 																																		 pv_process_flag             => lv_process_flag                                                    ,
967 																																		 pv_process_message          => lv_process_message                                                 ,
968 																																		 pv_attribute_context        => jai_constants.contxt_delivery                                      ,
969 																																		 pv_attribute1               => rec_cur_get_mtl_txns.transaction_header_id                                ,
970 																																		 pv_attribute2               => NULL                              ,
971 																																		 pv_attribute3               => NULL                                                               ,
972 																																		 pv_attribute4               => NULL                                                               ,
973 																																		 pv_attribute5               => NULL
974 																															 );
975 				 IF lv_process_flag = jai_constants.expected_error    OR
976 						lv_process_flag = jai_constants.unexpected_error
977 				 THEN
978 					 /*
979 					 || As Returned status is an error hence:-
980 					 ||1. Delivery processing should be terminated,Rollback the insert and exit Loop
981 					 ||2. Set out variables p_process_flag and p_process_message accordingly
982 					 ||3. Return from the procedure
983 					 */
984 					 record_debug_messages(' 12 Error in call to jai_cmn_rgm_recording_pkg.insert_vat_repository_entry - lv_process_flag '||lv_process_flag
985 																						 ||', lv_process_message'     || lv_process_message
986 																						 ||', Delivery id -  '        ||rec_cur_get_mtl_txns.transaction_header_id
987 																						 ||', Delivery_details_id -> '|| rec_cur_get_mtl_txns.transaction_temp_id
988 																						 ||', Tax_amount -> '         || rec_cur_get_mtl_txns.tax_amt
989 																						 ||', Tax_id -> '             || rec_cur_get_mtl_txns.tax_id
990 																						 ||', Tax_type -> '           || rec_cur_get_mtl_txns.tax_type
991 														);
992 					 p_process_flag    := lv_process_flag    ;
993 					 p_process_message := lv_process_message ;
994 					 return;
995 				 END IF;
996 				 record_debug_messages ('13 Returned from jai_cmn_rgm_recording_pkg.insert_vat_repository_entry and ');
997 					 record_debug_messages ('13.1 before call to jai_cmn_rgm_recording_pkg.do_vat_accounting');
998 					 record_debug_messages ('14 Processing the delivery,parameters are delivery_id -> '            || rec_cur_get_mtl_txns.transaction_header_id
999 																								||', source_document_type_id i.e delivery_detail_id -> ' || rec_cur_get_mtl_txns.transaction_temp_id
1000 																								||', rec_cur_get_deliveries.tax_type  -> '               || rec_cur_get_mtl_txns.tax_type
1001 																								||', p_organization_id -> '                              || p_organization_id
1002 																								||', p_location_id -> '                                  || p_location_id
1003 																								||', vat_exemption_flag -> '                             || 'N'
1004 																								||', account_name -> '                                   || lc_account_name
1005 																								||', p_charge_account_id-> '                             || ln_charge_ac_id
1006 																								||', p_balancing_account_id-> '                          || ln_balancing_ac_id
1007 																								||', ln_debit_amount -> '                                || ln_debit_amount
1008 																								||', ln_credit_amount -> '                               || ln_credit_amount
1009 																								||', p_amount-> '                                        || rec_cur_get_mtl_txns.tax_amt
1010 																								||', p_trx_amount-> '                                    || rec_cur_get_mtl_txns.tax_amt
1011 																								||', p_tax_rate -> '                                     || rec_cur_get_mtl_txns.tax_rate
1012 																								||', p_reference_id  i.e tax_id -> '                     || rec_cur_get_mtl_txns.tax_id
1013 																								||', p_inv_organization_id -> '                          || p_organization_id
1014 																								||', p_attribute1 i.e delivery_id -> '                   || rec_cur_get_mtl_txns.transaction_header_id
1015 																								||', p_attribute2 i.e order_line_id -> '                 || null
1016 																								||', p_attribute_context -> '                            || jai_constants.contxt_delivery
1017 																 );
1018 																 /*commented by vasavi*/
1019 																 /*
1020 					 jai_cmn_rgm_recording_pkg.do_vat_accounting (
1021 																													 pn_regime_id            =>  p_regime_id                                                       ,
1022 																													 pn_repository_id        =>  ln_repository_id                                                  ,
1023 																													 pv_organization_type    =>  jai_constants.orgn_type_io                                        ,
1024 																													 pn_organization_id      =>  p_organization_id                                                 ,
1025 																													 pd_accounting_date      =>  nvl(p_default_invoice_date,rec_cur_get_mtl_txns.creation_date)  ,
1026 																													 pd_transaction_date     =>  rec_cur_get_mtl_txns.creation_date                              ,
1027 																													 pn_credit_amount        =>  nvl(ln_debit_amount,ln_credit_amount)                             ,
1028 																													 pn_debit_amount         =>  nvl(ln_debit_amount,ln_credit_amount)                             ,
1029 																													 pn_credit_ccid          =>  ln_charge_ac_id                                                   ,
1030 																													 pn_debit_ccid           =>  ln_balancing_ac_id                                                ,
1031 																													 pv_called_from          =>  jai_constants.vat_repo_call_from_om_ar                                 ,
1032 																													 pv_process_flag         =>  lv_process_flag                                                   ,
1033 																													 pv_process_message      =>  lv_process_message                                                ,
1034 																													 pv_tax_type             =>  rec_cur_get_mtl_txns.tax_type                                   ,
1035 																													 pv_source               =>  p_source                                                          ,
1036 																													 pv_source_trx_type      =>  jai_constants.source_ttype_delivery                               ,
1037 																													 pv_source_table_name    =>  jai_constants.tname_dlry_dtl                                      ,
1038 																													 pn_source_id            =>  rec_cur_get_mtl_txns.transaction_temp_id                         ,
1039 																													 pv_reference_name       =>  'JA_IN_TAX_CODES'                ,
1040 																													 pn_reference_id         =>  rec_cur_get_mtl_txns.tax_id
1041 																													);
1042 					 IF lv_process_flag = jai_constants.expected_error    OR
1043 							lv_process_flag = jai_constants.unexpected_error
1044 					 THEN
1045 						 record_debug_messages(' 15 Error in call to jai_cmn_rgm_recording_pkg.do_vat_accounting - lv_process_flag '||lv_process_flag
1046 																							 ||', lv_process_message'     || lv_process_message
1047 																							 ||', Delivery id -  '        || rec_cur_get_mtl_txns.transaction_header_id
1048 																							 ||', Delivery_details_id -> '|| rec_cur_get_mtl_txns.transaction_temp_id
1049 																							 ||', Tax_amount -> '         || rec_cur_get_mtl_txns.tax_amt
1050 																							 ||', Tax_id -> '             || rec_cur_get_mtl_txns.tax_id
1051 																							 ||', Tax_type -> '           || rec_cur_get_mtl_txns.tax_type
1052 															);
1053 						 p_process_flag    := lv_process_flag    ;
1054 						 p_process_message := lv_process_message ;
1055 						 return;
1056 					 END IF;
1057 					 record_debug_messages ('16 Returned from jai_cmn_rgm_recording_pkg.do_vat_accounting');
1058 				 --END IF;
1059 				 */
1060           end if;---ln_rgm_cnt if
1061 	 END LOOP;
1062 
1063   ELSIF upper(p_source) = upper(jai_constants.source_ar) THEN
1064 
1065       record_debug_messages ('17 Manual AR processing for customer_trx_id -> '||p_customer_trx_id);
1066     /*
1067     || Process Invoices - AR side processing
1068     */
1069     /*  Bug 5739005. Added by vkantamn
1070      * Included parameters for the cursor.
1071      */
1072     FOR rec_cur_get_man_ar_inv_taxes IN cur_get_man_ar_inv_taxes(upper(p_source),jai_constants.source_ttype_man_ar_inv,jai_constants.tname_cus_trx_lines)
1073     LOOP
1074       record_debug_messages (' ************18 PROCESSING customer_trx_id -> '|| p_customer_trx_id
1075         ||'link_to_cust_trx_line_id -> '||rec_cur_get_man_ar_inv_taxes.link_to_cust_trx_line_id
1076         ||'customer_trx_line_id ->'||rec_cur_get_man_ar_inv_taxes.customer_trx_line_id
1077         ||' ************' );
1078 
1079       /*******************************
1080       ||Variable Initialization
1081       *******************************/
1082       ln_liab_acct_ccid    := null;
1083       ln_intliab_acct_ccid := null;
1084       ln_charge_ac_id      := null;
1085       ln_balancing_ac_id   := null;
1086 
1087       /* Start - sacsethi, Added w.r.t BUG#6072461 ( for VAT Reversal)*/
1088       ln_credit_amount     := null;
1089       ln_debit_amount      := null;
1090       ln_recov_acct_ccid   := null;
1091       ln_expense_acct_ccid := null;
1092       lc_account_name      := null;
1093       /* End -  sacsethi, Added w.r.t BUG#6072461 ( for VAT Reversal)*/
1094 
1095       record_debug_messages ('19 Variables Initialised');
1096 
1097       IF ( rec_cur_get_man_ar_inv_taxes.tax_type = 'VAT REVERSAL' ) THEN
1098         /* Start - sacsethi, Added w.r.t BUG#6072461 ( for VAT Reversal)*/
1099         /*******************************
1100         ||Get the code combination id
1101         ||for the "RECOVERY ACCOUNT"
1102         *******************************/
1103         ln_recov_acct_ccid   :=    jai_cmn_rgm_recording_pkg.get_account(
1104                                                                           p_regime_id         => p_regime_id                        ,
1105                                                                           p_organization_type => jai_constants.orgn_type_io         ,
1106                                                                           p_organization_id   => p_organization_id                  ,
1107                                                                           p_location_id       => p_location_id                      ,
1108                                                                           p_tax_type          => rec_cur_get_man_ar_inv_taxes.tax_type,
1109                                                                           p_account_name      => jai_constants.recovery
1110                                                                         ) ;
1111 
1112         /*******************************
1113         || Get the code combination id
1114         || for the "EXPENSE ACCOUNT"
1115         *******************************/
1116         ln_expense_acct_ccid :=    jai_cmn_rgm_recording_pkg.get_account(
1117                                                                           p_regime_id         => p_regime_id                        ,
1118                                                                           p_organization_type => jai_constants.orgn_type_io         ,
1119                                                                           p_organization_id   => p_organization_id                  ,
1120                                                                           p_location_id       => p_location_id                      ,
1121                                                                           p_tax_type          => rec_cur_get_man_ar_inv_taxes.tax_type,
1122                                                                           p_account_name      => jai_constants.expense
1123                                                                         ) ;
1124         IF  ln_recov_acct_ccid   IS NULL OR
1125             ln_expense_acct_ccid IS NULL
1126         THEN
1127           record_debug_messages('20 VAT receivables accouting entries cannot be passed. Please set up the Recovery account and the Expense account for VAT Reversal');
1128           p_process_flag    := jai_constants.expected_error;
1129           p_process_message := 'VAT receivables accouting entries cannot be passed. Please set up the Recovery account and the Expense account for VAT Reversal';
1130           return;
1131         END IF;
1132         /* End - sacsethi, Added w.r.t BUG#6072461 ( for VAT Reversal)*/
1133        ELSE
1134 
1135       /*******************************
1136       ||Get the code combination id
1137       ||for the "LIABILITY ACCOUNT"
1138       *******************************/
1139       ln_liab_acct_ccid    :=    jai_cmn_rgm_recording_pkg.get_account(
1140                                                                           p_regime_id         => p_regime_id                                ,
1141                                                                           p_organization_type => jai_constants.orgn_type_io                 ,
1142                                                                           p_organization_id   => p_organization_id                          ,
1143                                                                           p_location_id       => p_location_id                              ,
1144                                                                           p_tax_type          => rec_cur_get_man_ar_inv_taxes.tax_type      ,
1145                                                                           p_account_name      => jai_constants.liability
1146                                                                       ) ;
1147 
1148       /*******************************
1149       || Get the code combination id
1150       || for the "INTERIM LIABILITY ACCOUNT"
1151       *******************************/
1152       ln_intliab_acct_ccid :=    jai_cmn_rgm_recording_pkg.get_account(
1153                                                                           p_regime_id         => p_regime_id                                ,
1154                                                                           p_organization_type => jai_constants.orgn_type_io                 ,
1155                                                                           p_organization_id   => p_organization_id                          ,
1156                                                                           p_location_id       => p_location_id                              ,
1157                                                                           p_tax_type          => rec_cur_get_man_ar_inv_taxes.tax_type      ,
1158                                                                           p_account_name      => jai_constants.liability_interim
1159                                                                       ) ;
1160 
1161 
1162       /*
1163       || Validate that if any one of the liability account or interim liability account is not defined then error our
1164       */
1165       IF ln_liab_acct_ccid    IS NULL OR
1166          ln_intliab_acct_ccid IS NULL
1167       THEN
1168         record_debug_messages('20 VAT receivable accouting entries cannot be passed. Please set up the Liability account and the Interim Liability account for the corresponding VAT regime');
1169         p_process_flag    := jai_constants.expected_error;
1170         p_process_message := 'VAT receivable accouting entries cannot be passed. Please set up the Liability account and the Interim Liability account for the corresponding VAT regime';
1171         return;
1172       END IF;
1173      END IF;
1174 
1175       /*********************************************************************************************************************************
1176       || Population of Credit and debit amounts and CCID in case Invoice and Credit Memo
1177       +=============================================================================================================================+
1178       ||                 ||||<---------------VAT REPOSITORY ENTRY--------------->||||<-------------GL INTERFACE---------------->
1179       ||================ ||||====================================================||||==================================================
1180       ||Transaction Type ||||CHARGE A/C     ||  BALANCING A/C  ||   CR  ||   DR  ||||Slno || Account ID    || CR    ||   DR  ||
1181       ||================ ||||============   ||=================||=======||=======||||=====||===============||=======||=======||
1182       ||  Invoice/       ||||  Liab A/C     ||  Int Liab A/C   ||   0   ||  100  ||||1.   || Liab A/C      || 100   ||   0   ||
1183       ||  Debit Memo     ||||               ||                 ||       ||       ||||2.   || Int Liab A/C  ||   0   || 100   ||
1184       ||                 ||||               ||                 ||       ||       ||||     ||               ||       ||       ||
1185       ||=================||||===============||=================||=======||=======||||=====||===============||=======||=======||
1186       ||                 ||||               ||                 ||       ||       ||||     ||               ||       ||       ||
1187       ||  Credit Memo    |||| Int Liab A/C  ||  Liab A/C       || 100   ||    0  ||||1.   ||  Int Liab A/C ||  100  ||   0   ||
1188       ||                 ||||               ||                 ||       ||       ||||2.   ||  Liab A/C     ||  0    || 100   ||
1189       +==============================================================================================================================+
1190 
1191       *********************************************************************************************************************************/
1192 
1193 
1194        IF p_transaction_type IN ('INV','DM') THEN
1195            /* Start - sacsethi, Added w.r.t 6072461 ( for VAT Reversal)*/
1196           IF ( rec_cur_get_man_ar_inv_taxes.tax_type = 'VAT REVERSAL' ) THEN
1197             lc_account_name         :=    jai_constants.recovery                                ;
1198             ln_charge_ac_id         :=    ln_recov_acct_ccid                                    ;
1199             ln_balancing_ac_id      :=    ln_expense_acct_ccid                                  ;
1200             ln_debit_amount         :=    null                                                  ;
1201             ln_credit_amount        :=    abs(rec_cur_get_man_ar_inv_taxes.func_tax_amount)     ;
1202           ELSE
1203             lc_account_name         :=    jai_constants.liability                               ;
1204           /* End - sacsethi, Added w.r.t 6072461 ( for VAT Reversal)*/
1205             ln_charge_ac_id         :=    ln_liab_acct_ccid                                     ;
1206             ln_balancing_ac_id      :=    ln_intliab_acct_ccid                                  ;
1207             ln_debit_amount         :=    abs(rec_cur_get_man_ar_inv_taxes.func_tax_amount)     ;
1208             ln_credit_amount        :=    null                                                  ;
1209           END IF;
1210 
1211        ELSIF p_transaction_type = 'CM' THEN
1212         ln_charge_ac_id         :=    ln_intliab_acct_ccid                                  ;
1213         ln_balancing_ac_id      :=    ln_liab_acct_ccid                                     ;
1214         ln_debit_amount         :=    null                                                  ;
1215         ln_credit_amount        :=    abs(rec_cur_get_man_ar_inv_taxes.func_tax_amount)     ;
1216        END IF;
1217 
1218 
1219 
1220       record_debug_messages ('21 Processing the manual_ar_invoice , Parameters passed are for the customer_trx_id  -> ' || p_customer_trx_id
1221                                            ||', line.customer_trx_line_id  -> '                         || rec_cur_get_man_ar_inv_taxes.link_to_cust_trx_line_id
1222                                            ||', source_document_type_id tax.customer_trx_line_id -> '   || rec_cur_get_man_ar_inv_taxes.customer_trx_line_id
1223                                            ||', rec_cur_get_man_ar_inv_taxes.tax_type  -> '             || rec_cur_get_man_ar_inv_taxes.tax_type
1224                                            ||', p_organization_id -> '                                  || p_organization_id
1225                                            ||', p_location_id -> '                                      || p_location_id
1226                                            ||', vat_exemption_flag -> '                                 || rec_cur_get_man_ar_inv_taxes.vat_exemption_flag
1227                                            ||', pn_assessable_value ->'                                 || rec_cur_get_man_ar_inv_taxes.vat_assessable_value
1228                                            ||', account_name -> '                                       || jai_constants.liability
1229                                            ||', p_charge_account_id-> '                                 || ln_charge_ac_id
1230                                            ||', p_balancing_account_id-> '                              || ln_balancing_ac_id
1231                                            ||', ln_debit_amount -> '                                    || ln_debit_amount
1232                                            ||', ln_credit_amount -> '                                   || ln_credit_amount
1233                                            ||', p_amount-> '                                            || rec_cur_get_man_ar_inv_taxes.func_tax_amount
1234                                            ||', p_trx_amount-> '                                        || rec_cur_get_man_ar_inv_taxes.func_tax_amount
1235                                            ||', p_tax_rate -> '                                         || rec_cur_get_man_ar_inv_taxes.tax_rate
1236                                            ||', p_reference_id  i.e tax_id -> '                         || rec_cur_get_man_ar_inv_taxes.tax_id
1237                                            ||', p_inv_organization_id -> '                              || p_organization_id
1238                                            ||', p_attribute1 i.e customer_trx_id -> '                   || rec_cur_get_man_ar_inv_taxes.customer_trx_id
1239                                            ||', p_attribute2 i.e link_to_cust_trx_line_id -> '          || rec_cur_get_man_ar_inv_taxes.link_to_cust_trx_line_id
1240                                            ||', p_attribute_context -> '                                || jai_constants.contxt_manual_ar
1241                             );
1242 
1243 
1244       record_debug_messages ('22 Before call to jai_cmn_rgm_recording_pkg.insert_vat_repository_entry');
1245 
1246 
1247       jai_cmn_rgm_recording_pkg.insert_vat_repository_entry (
1248                                                                pn_repository_id            =>  ln_repository_id                                                         ,
1249                                                                pn_regime_id                =>  p_regime_id                                                              ,
1250                                                                pv_tax_type                 =>  rec_cur_get_man_ar_inv_taxes.tax_type                                    ,
1251                                                                pv_organization_type        =>  jai_constants.orgn_type_io                                               ,
1252                                                                pn_organization_id          =>  p_organization_id                                                        ,
1253                                                                pn_location_id              =>  p_location_id                                                            ,
1254                                                                pv_source                   =>  p_source                                                                 ,
1255                                                                pv_source_trx_type          =>  jai_constants.source_ttype_man_ar_inv                                    ,
1256                                                                pv_source_table_name        =>  jai_constants.tname_cus_trx_lines                                        ,
1257                                                                pn_source_id                =>  rec_cur_get_man_ar_inv_taxes.customer_trx_line_id                        ,
1258                                                                pd_transaction_date         =>  rec_cur_get_man_ar_inv_taxes.creation_date                               ,
1259                                                                pv_account_name             =>  lc_account_name                                                          ,  --Date 14/06/2007 by sacsethi for bug 6072461
1260                                                                pn_charge_account_id        =>  ln_charge_ac_id                                                          ,
1261                                                                pn_balancing_account_id     =>  ln_balancing_ac_id                                                       ,
1262                                                                pn_credit_amount            =>  ln_credit_amount                                                         ,
1263                                                                pn_debit_amount             =>  ln_debit_amount                                                          ,
1264                                                                pn_assessable_value         =>  rec_cur_get_man_ar_inv_taxes.vat_assessable_value                        ,
1265                                                                pn_tax_rate                 =>  rec_cur_get_man_ar_inv_taxes.tax_rate                                    ,
1266                                                                pn_reference_id             =>  rec_cur_get_man_ar_inv_taxes.tax_id                                      ,
1267                                                                pn_batch_id                 =>  p_batch_id                                                               ,
1268                                                                pn_inv_organization_id      =>  p_organization_id                                                        ,
1269                                                                pv_invoice_no               =>  p_vat_invoice_no                                                         ,
1270                                                                pd_invoice_date             =>  nvl(p_default_invoice_date,rec_cur_get_man_ar_inv_taxes.creation_date)   ,
1271                                                                pv_called_from              =>  jai_constants.vat_repo_call_from_om_ar                                   ,
1272                                                                pv_process_flag             =>  lv_process_flag                                                          ,
1273                                                                pv_process_message          =>  lv_process_message                                                       ,
1274                                                                pv_attribute_context        =>  jai_constants.contxt_manual_ar                                           ,
1275                                                                pv_attribute1               =>  rec_cur_get_man_ar_inv_taxes.customer_trx_id                             ,
1276                                                                pv_attribute2               =>  rec_cur_get_man_ar_inv_taxes.link_to_cust_trx_line_id                    ,
1277                                                                pv_attribute3               =>  NULL                                                                     ,
1278                                                                pv_attribute4               =>  NULL                                                                     ,
1279                                                                pv_attribute5               =>  NULL
1280                                                            );
1281 
1282 
1283 
1284       IF lv_process_flag = jai_constants.expected_error    OR
1285          lv_process_flag = jai_constants.unexpected_error
1286       THEN
1287         /*
1288         || As Returned status is an error hence:-
1289         ||1. Delivery processing should be terminated,Rollback the insert and exit Loop
1290         ||2. Set out variables p_process_flag and p_process_message accordingly
1291         ||3. Return from the procedure
1292         */
1293         record_debug_messages(' 23 Error in call to jai_cmn_rgm_recording_pkg.insert_vat_repository_entry - lv_process_flag '||lv_process_flag
1294                                           ||', lv_process_message'            || lv_process_message
1295                                           ||', customer_trx_id -  '           || p_customer_trx_id
1296                                           ||', customer_trx_line_id -> '      || rec_cur_get_man_ar_inv_taxes.customer_trx_line_id
1297                                           ||', link_to_cust_trx_line_id -> '  || rec_cur_get_man_ar_inv_taxes.link_to_cust_trx_line_id
1298                                           ||', Tax_amount -> '                || rec_cur_get_man_ar_inv_taxes.func_tax_amount
1299                                           ||', Tax_id -> '                    || rec_cur_get_man_ar_inv_taxes.tax_id
1300                                           ||', Tax_type -> '                  || rec_cur_get_man_ar_inv_taxes.tax_type
1301                          );
1302         p_process_flag    := lv_process_flag    ;
1303         p_process_message := lv_process_message ;
1304         return;
1305       END IF;
1306 
1307       record_debug_messages (' 24 Returned from jai_cmn_rgm_recording_pkg.insert_vat_repository_entry');
1308       IF rec_cur_get_man_ar_inv_taxes.vat_exemption_flag = 'N' THEN
1309 
1310         record_debug_messages ('25 Parameters passed to  jai_cmn_rgm_recording_pkg.do_vat_accounting, customer_trx_id  -> '            || p_customer_trx_id
1311                                              ||', line.customer_trx_line_id  -> '                         || rec_cur_get_man_ar_inv_taxes.link_to_cust_trx_line_id
1312                                              ||', source_document_type_id tax.customer_trx_line_id -> '   || rec_cur_get_man_ar_inv_taxes.customer_trx_line_id
1313                                              ||', rec_cur_get_man_ar_inv_taxes.tax_type  -> '             || rec_cur_get_man_ar_inv_taxes.tax_type
1314                                              ||', p_organization_id -> '                                  || p_organization_id
1315                                              ||', p_location_id -> '                                      || p_location_id
1316                                              ||', vat_exemption_flag -> '                                 || rec_cur_get_man_ar_inv_taxes.vat_exemption_flag
1317                                              ||', pn_assessable_value ->'                                 || rec_cur_get_man_ar_inv_taxes.vat_assessable_value
1318                                              ||', account_name -> '                                       || jai_constants.liability
1319                                              ||', pn_credit_ccid-> '                                      || ln_charge_ac_id
1320                                              ||', pn_debit_ccid         -> '                              || ln_balancing_ac_id
1321                                              ||', ln_debit_amount -> '                                    || ln_debit_amount
1322                                              ||', ln_credit_amount -> '                                   || ln_credit_amount
1323                                              ||', p_amount-> '                                            || rec_cur_get_man_ar_inv_taxes.func_tax_amount
1324                                              ||', p_trx_amount-> '                                        || rec_cur_get_man_ar_inv_taxes.func_tax_amount
1325                                              ||', p_tax_rate -> '                                         || rec_cur_get_man_ar_inv_taxes.tax_rate
1326                                              ||', p_reference_id  i.e tax_id -> '                         || rec_cur_get_man_ar_inv_taxes.tax_id
1327                                              ||', p_inv_organization_id -> '                              || p_organization_id
1328                                              ||', p_attribute1 i.e customer_trx_id -> '                   || rec_cur_get_man_ar_inv_taxes.customer_trx_id
1329                                              ||', p_attribute2 i.e link_to_cust_trx_line_id -> '          || rec_cur_get_man_ar_inv_taxes.link_to_cust_trx_line_id
1330                                              ||', p_attribute_context -> '                                || jai_constants.contxt_manual_ar
1331                               );
1332 
1333 
1334 
1335         jai_cmn_rgm_recording_pkg.do_vat_accounting (
1336           pn_regime_id            =>  p_regime_id                                                               ,
1337           pn_repository_id        =>  ln_repository_id                                                          ,
1338           pv_organization_type    =>  jai_constants.orgn_type_io                                                ,
1339           pn_organization_id      =>  p_organization_id                                                         ,
1340           /*Check with support whether this should be transaction date or sysdate */
1341           pd_accounting_date      =>  nvl(p_default_invoice_date,rec_cur_get_man_ar_inv_taxes.creation_date)    ,
1342           pd_transaction_date     =>  rec_cur_get_man_ar_inv_taxes.creation_date                                ,
1343           pn_credit_amount        =>  nvl(ln_credit_amount,ln_debit_amount)                                     ,
1344           pn_debit_amount         =>  nvl(ln_debit_amount,ln_credit_amount)                                     ,
1345           pn_credit_ccid          =>  ln_charge_ac_id                                                           ,
1346           pn_debit_ccid           =>  ln_balancing_ac_id                                                        ,
1347           pv_called_from          =>  jai_constants.vat_repo_call_from_om_ar                                    ,
1348           pv_process_flag         =>  lv_process_flag                                                           ,
1349           pv_process_message      =>  lv_process_message                                                        ,
1350           pv_tax_type             =>  rec_cur_get_man_ar_inv_taxes.tax_type                                     ,
1351           pv_source               =>  p_source                                                                  ,
1352           pv_source_trx_type      =>  jai_constants.source_ttype_man_ar_inv                                     ,
1353           pv_source_table_name    =>  jai_constants.tname_cus_trx_lines                                         ,
1354           pn_source_id            =>  rec_cur_get_man_ar_inv_taxes.customer_trx_line_id                         ,
1355           pv_reference_name       =>  /*jai_constants.JAI_CMN_TAXES_ALL*/ 'JA_IN_TAX_CODES'                       ,
1356           pn_reference_id         =>  rec_cur_get_man_ar_inv_taxes.tax_id
1357          );
1358 
1359         IF lv_process_flag = jai_constants.expected_error    OR
1360            lv_process_flag = jai_constants.unexpected_error
1361         THEN
1362           /*
1363           || As Returned status is an error hence:-
1364           ||1. Delivery processing should be terminated,Rollback the insert and exit Loop
1365           ||2. Set out variables p_process_flag and p_process_message accordingly
1366           ||3. Return from the procedure
1367           */
1368         record_debug_messages(' 26 Error in call to jai_cmn_rgm_recording_pkg.do_vat_accounting - lv_process_flag '||lv_process_flag
1369                                           ||', lv_process_message'            || lv_process_message
1370                                           ||', customer_trx_id -  '           || p_customer_trx_id
1371                                           ||', customer_trx_line_id -> '      || rec_cur_get_man_ar_inv_taxes.customer_trx_line_id
1372                                           ||', link_to_cust_trx_line_id -> '  || rec_cur_get_man_ar_inv_taxes.link_to_cust_trx_line_id
1373                                           ||', Tax_amount -> '                || rec_cur_get_man_ar_inv_taxes.func_tax_amount
1374                                           ||', Tax_id -> '                    || rec_cur_get_man_ar_inv_taxes.tax_id
1375                                           ||', Tax_type -> '                  || rec_cur_get_man_ar_inv_taxes.tax_type
1376                          );
1377           p_process_flag    := lv_process_flag    ;
1378           p_process_message := lv_process_message ;
1379           return;
1380         END IF;
1381 
1382         record_debug_messages ('27 Returned from jai_cmn_rgm_recording_pkg.do_vat_accounting');
1383         END IF; /* ENd if OF VAT Exemption = 'N'*/
1384 
1385     END LOOP;
1386 
1387   END IF;
1388 
1389   record_debug_messages ('28 ********************************END OF PROCESS_ORDER_INVOICE********************************');
1390 
1391 EXCEPTION
1392   WHEN OTHERS THEN
1393     record_debug_messages (' 29 In Exception Section - SQLERRM ->'||substr(sqlerrm,1,300) );
1394     p_process_flag        := jai_constants.unexpected_error ;
1395     p_process_message     := 'Unexpeced error occured in procedure process_order_invoice for document_id -> '||nvl(p_delivery_id,p_customer_trx_id)||substr(SQLERRM,1,300);
1396 
1397 END process_order_invoice;
1398 
1399 END jai_cmn_rgm_vat_accnt_pkg;