DBA Data[Home] [Help]

PACKAGE BODY: APPS.JL_BR_AP_PAY_SCHED_GDF_PKG

Source


1 PACKAGE BODY JL_BR_AP_PAY_SCHED_GDF_PKG AS
2 /* $Header: jlbrpgpb.pls 120.12 2006/09/20 01:09:23 dbetanco ship $ */
3 
4 -- =====================================================================
5 --                   P R I V A T E    O B J E C T S
6 -- =====================================================================
7 --
8 -- Validate p_date with the Brazilian calendar business days if the date is
9 -- not business day the procedure return a date before o after according to
10 -- the setup.
11 ------------------------------------------------------------------------
12 Procedure VALIDATE_DATE
13             (
14              p_date date,
15              p_city varchar2,
16              p_new_date IN OUT NOCOPY date,
17              p_status IN OUT NOCOPY number) IS
18 
19   -- Local Variables
20 
21   l_calendar varchar2(10);
22   l_payment_action varchar2(1);
23   l_change_date varchar2(1);
24   return_question number;
25   returned_date   varchar2(11);
26 
27   l_org_id  NUMBER;   --  MOAC  Bug # 2306001
28 
29   BEGIN
30     ------------------------------------------------------------------------
31     -- Validate the profile options.
32     ------------------------------------------------------------------------
33     if p_date IS NOT NULL then
34        l_org_id := MO_GLOBAL.get_current_org_id;
35        l_payment_action := JL_ZZ_SYS_OPTIONS_PKG.get_payment_action(l_org_id);  -- MOAC
36        -- Bug 4715379
37        l_calendar := jl_zz_sys_options_pkg.get_calendar;
38        l_change_date := jl_zz_sys_options_pkg.get_change_date_automatically(l_org_id);
39        if l_payment_action is NOT NULL then
40           if l_calendar is NOT NULL then
41              if l_change_date is NOT NULL then
42                 ------------------------------------------------------------
43                 -- Get the new date.
44                 ------------------------------------------------------------
45                 jl_br_workday_calendar.jl_br_check_date(to_char(p_date,'DD-MM-YYYY'),l_calendar,
46                         p_city,l_payment_action,returned_date,p_status);
47                 if p_status = 0 then /* procedure successfull */
48                    -----------------------------------------------------------
49                    -- Return the new date.
50                    -----------------------------------------------------------
51                    p_new_date := to_date(returned_date,'DD-MM-YYYY');
52                    if p_date <> p_new_date then
53                       if l_change_date = 'N' then
54                           RETURN;
55                       end if;
56                    end if;
57                 end if;
58              else
59                 p_status := 1;
60              end if;
61           else
62             p_status := 2;
63           end if;
64        else
65          p_status := 3;
66        end if;
67     end if;
68 END VALIDATE_DATE;
69 
70 Procedure APXWKB_BR_VALIDATE_DATE_LOCAL
71             (
72              p_in_date Date,
73              p_vendor_site_id Number,
74              new_date_val IN OUT NOCOPY Varchar2) IS
75 
76     X_payment_location         VARCHAR2(80);
77     p_city                     VARCHAR2(25);
78     p_state                    VARCHAR2(60); --Bug # 2319552
79     p_new_date                 DATE;
80     p_status                   NUMBER(38);
81     l_vendor_site_id           NUMBER(38);
82 
83     l_form_name                varchar2(50);
84     errcode1                   number;
85     sqlstat1                   varchar2(2000);
86 
87     X_org_id                   NUMBER;  -- Bug 2306001
88 
89   BEGIN
90 
91     -- Bug # 2306001 (MOAC)/ 4715379
92     X_org_id := MO_GLOBAL.get_current_org_id;
93     X_payment_location := JL_ZZ_SYS_OPTIONS_PKG.get_payment_location(X_org_id);
94 
95     IF X_payment_location IS Null THEN
96        RETURN;
97     END IF;
98 
99     IF NVL(X_payment_location,'$') = '1' THEN           -- 1 COMPANY ---------
100       -- Get city from ap_system_parameters
101 
102       -- Bug 2319552 : BDC - State Lov
103       JL_ZZ_AP_LIBRARY_1_PKG.get_city_frm_sys(p_city,1, errcode1, p_state);
104     ELSIF NVL(X_payment_location,'$') = '2' THEN        -- 2 SUPPLIER --------
105       -- Get city from po_vendor_sites
106 
107       -- Bug 2319552 : BDC - State Lov : Start ------
108       JL_ZZ_AP_LIBRARY_1_PKG.get_city_frm_povend(p_vendor_site_id, p_city, 1, errcode1, p_state);
109 
110     END IF;
111 
112     VALIDATE_DATE (p_in_date,
113                    p_city,
114                    p_new_date,
115                    p_status,
116                    p_state); -- Bug # 2319552
117 
118 
119     IF p_status = 0 THEN
120       new_date_val := To_Char(p_new_date,'DD-MON-YYYY'); -- OUT Parameter
121     END IF;
122 
123   END APXWKB_BR_Validate_Date_Local;
124   --------------------------------------------------------------
125   -- Update the AP_PAYMENTS_SCHEDULES GDF taken the information
126   -- from Supplier's site.
127   --------------------------------------------------------------
128 Procedure APXINWKB_BR_DEF_PS_SEGMENTS
129            (
130             P_Invoice_ID Number,
131             p_vendor_site_id Number
132            ) IS
133   -------------------------------------------------------------
134   -- Variables for Interest Values
135   -------------------------------------------------------------
136   v_inttyp VARCHAR2(150);
137   v_intamt VARCHAR2(150);
138   v_intprd VARCHAR2(150);
139   v_intfml VARCHAR2(150);
140   v_intgrd VARCHAR2(150);
141   v_pnttyp VARCHAR2(150);
142   v_pntamt VARCHAR2(150);
143   v_asscn  VARCHAR2(150);
144   -----------------------------------------------------------
145   -- Global Attribute Category
146   -----------------------------------------------------------
147   v_glbattctg VARCHAR2(150) := 'JL.BR.APXINWKB.AP_PAY_SCHED';
148   -----------------------------------------------------------
149   -- Variables for Errors
150   -----------------------------------------------------------
151   errcode1    NUMBER;
152   errcode2    NUMBER;
153   errcode3    NUMBER;
154   errcode4    NUMBER;
155   errcode5    NUMBER;
156   errcode6    NUMBER;
157   errcode7    NUMBER;
158 
159  BEGIN
160     -------------------------------------------------------
161     -- Get interest type as follows for global_attribute1
162     -------------------------------------------------------
163     JL_ZZ_AP_LIBRARY_1_PKG.Get_interest_type(p_vendor_site_id, v_inttyp, 1, errcode1);
164     ------------------------------------------------------
165     -- Get penanlty rate/amount days, interest grace days,
166     -- interest period, interest rate/amount as follows for
167     -- global_attribute7, global_attribute5, global_attribute3, global_attribute2
168     ------------------------------------------------------
169     JL_ZZ_AP_LIBRARY_1_PKG.Get_Interest_Penalty_Details(p_vendor_site_id, v_pntamt, v_intgrd,
170                                                         v_intprd, v_intamt, 1, errcode2);
171     ------------------------------------------------------
172     -- Get interest formula as follows for global_attribute4
173     ------------------------------------------------------
174     JL_ZZ_AP_LIBRARY_1_PKG.Get_Interest_Formula(p_vendor_site_id, v_intfml, 1, errcode4);
175     ------------------------------------------------------
176     -- Get penalty type as follows for global_attribute6
177     ------------------------------------------------------
178     JL_ZZ_AP_LIBRARY_1_PKG.Get_Penalty_Type(p_vendor_site_id, v_pnttyp, 1, errcode6);
179     -----------------------------------------------------
180     -- Update payment_schedules with these default values
181     -----------------------------------------------------
182        UPDATE AP_PAYMENT_SCHEDULES
183                    SET GLOBAL_ATTRIBUTE1 = v_inttyp,
184                        GLOBAL_ATTRIBUTE2 = v_intamt,
185                        GLOBAL_ATTRIBUTE3 = v_intprd,
186                        GLOBAL_ATTRIBUTE4 = v_intfml,
187                        GLOBAL_ATTRIBUTE5 = v_intgrd,
188                        GLOBAL_ATTRIBUTE6 = v_pnttyp,
189                        GLOBAL_ATTRIBUTE7 = v_pntamt,
190                        GLOBAL_ATTRIBUTE8 = 'N',
191                        GLOBAL_ATTRIBUTE_CATEGORY = v_glbattctg
192        WHERE INVOICE_ID = P_Invoice_ID;
193 
194  EXCEPTION
195    WHEN OTHERS THEN
196         NULL;
197 END APXINWKB_BR_Def_PS_Segments;
198 
199 -----------------------------------------------------------
200 -- Validate the dates for DUE_DATE and DISCOUNT_DATE
201 -- also call the procedure to associate collection documents.
202 -----------------------------------------------------------
203 PROCEDURE APXINWKB_BR_VALIDATE_PAY_SCHED
204             (
205              P_Invoice_ID Number,
206              p_invoice_type_lookup_code Varchar2,
207              p_colldoc_assoc Varchar2,
208              P_Vendor_Site_Id Number
209             ) IS
210     X_association_method          Varchar2(25);
211     s_bank_collection_id          jl_br_ap_collection_docs.bank_collection_id%Type;
212     s_associate_flag              Varchar2(1);
213     l_rec_count                   Number;
214     l_new_date_char               Varchar2(30);
215     errcode1                      Number;
216     -- Cursor on AP_PAYMENT_SCHEDULES
217     CURSOR Payments IS
218       SELECT  due_date, discount_date, payment_num
219         FROM  ap_payment_schedules
220        WHERE  invoice_id = P_Invoice_ID;
221 BEGIN
222   -------------------------------------------------------------------
223   -- Get Association Method from ap_system_parameters
224   -------------------------------------------------------------------
225   JL_ZZ_AP_LIBRARY_1_PKG.get_association_method(X_association_method, 1, errcode1);
226   -------------------------------------------------------------------
227   -- Loop Cursor Payments
228   ------------------------------------------------------------------
229   FOR db_reg IN Payments LOOP
230      BEGIN
231         IF db_reg.due_date IS NOT NULL THEN
232             l_new_date_char := '';
233             ---------------------------------------------------------
234             -- Validate Business Day Calendar for DUE DATE
235             ---------------------------------------------------------
236             APXWKB_BR_VALIDATE_DATE_LOCAL(db_reg.due_date,P_Vendor_Site_Id,l_new_date_char);
237             IF l_new_date_char IS NOT NULL THEN
238                -----------------------------------------------------
239                -- Update AP_PAYMNET_SCHEDULES.due_date
240                -----------------------------------------------------
241                UPDATE ap_payment_schedules
242                       SET due_date = to_date(l_new_date_char,'DD-MM-YYYY')
243                 WHERE invoice_id   = P_Invoice_ID
244                   AND payment_num  = db_reg.payment_num;
245             END IF;
246         END IF;
247         IF db_reg.discount_date IS NOT NULL THEN
248             l_new_date_char := '';
249             ---------------------------------------------------------
250             -- Validate Business Day Calendar for DISCOUNT DATE
251             ---------------------------------------------------------
252             APXWKB_BR_VALIDATE_DATE_LOCAL(db_reg.discount_date,P_Vendor_Site_Id,l_new_date_char);
253             IF l_new_date_char IS NOT NULL THEN
254                -----------------------------------------------------
255                -- Update AP_PAYMNET_SCHEDULES.discount_date
256                -----------------------------------------------------
257                UPDATE ap_payment_schedules
258                       SET discount_date = to_date(l_new_date_char ,'DD-MM-YYYY')
259                 WHERE invoice_id  = P_Invoice_ID
260                   AND payment_num = db_reg.payment_num ;
261             END IF;
262         END IF;
263         -----------------------------------------------------------
264         -- Associate the Collection Documents to Payments Schedules
265         -- Only for Invoice Type STANDARD
266         -----------------------------------------------------------
267         IF nvl(p_invoice_type_lookup_code,'$') = 'STANDARD' THEN
268            IF nvl(p_colldoc_assoc,'N') = 'Y' THEN
269               JL_BR_AP_ASSOCIATE_COLLECTION.JL_BR_AP_ASSOCIATE_TRADE_NOTE
270                                      ( P_Invoice_ID,
271                                        db_reg.payment_num,
272                                        X_association_method,
273                                        s_bank_collection_id,
274                                        s_associate_flag
275                                       );
276               IF Upper(nvl(s_associate_flag,'N')) = 'Y' THEN
277                  UPDATE ap_payment_schedules
278                         SET global_attribute11 = s_bank_collection_id
279                   WHERE invoice_id  = P_Invoice_ID
280                     AND payment_num = db_reg.payment_num;
281               END IF;  -- if s_associate = 'Y'
282            END IF;  -- if nvl(p_colldoc_assoc,'N') <> 'Y'
283         END IF;  -- if nvl(p_invoice_type_lookup_code,'$') <> 'STANDARD'
284      EXCEPTION
285         WHEN OTHERS THEN
286              NULL;
287      END;
288   END LOOP;
289 END APXINWKB_BR_Validate_Pay_Sched;
290 
291 --
292 -- =====================================================================
293 --                   P U B L I C    O B J E C T S
294 -- =====================================================================
295 --
296 --
297 
298 PROCEDURE Suppl_Def_Pay_Sched_GDF
299             ( P_Invoice_Id  ap_invoices_all.invoice_id%TYPE
300              ) IS
301   l_invoice_type_lookup_code  varchar2(25);
302   s_colldoc_assoc             varchar2(1);
303   v_vndstid                   number;
304   BEGIN
305     ----------------------------------------------------------------------------
306     -- Select the Vendor Site ID, Invoice Type and Global_Attr1 from the invoice.
307     ----------------------------------------------------------------------------
308     SELECT vendor_site_id, invoice_type_lookup_code, substr(global_attribute1,1,1)
309       INTO v_vndstid, l_invoice_type_lookup_code, s_colldoc_assoc
310       FROM ap_invoices
311      WHERE invoice_id = P_Invoice_ID;
312    ------------------------------------------------------------------------------------------
313    -- First fill the AP_Payment_Schedules GDF
314    ------------------------------------------------------------------------------------------
315    APXINWKB_BR_DEF_PS_SEGMENTS
316                 ( P_Invoice_ID,
317                   v_vndstid
318                 );
319 
320    ------------------------------------------------------------------------------------------
321    -- Validate Calendar (Due_Date,Discount_Date) and Call Trade Note Association
322    -- for every payment schedule for this invoice_id thru this following proc.
323    -------------------------------------------------------------------------------------------
324    APXINWKB_BR_VALIDATE_PAY_SCHED
325                 ( P_Invoice_ID,
326                   l_invoice_type_lookup_code,
327                   s_colldoc_assoc,
328                   v_vndstid
329                 );
330   EXCEPTION
331       WHEN OTHERS THEN
332            NULL;
333   END Suppl_Def_Pay_Sched_GDF;
334 
335 Procedure VALIDATE_DATE
336             (
337              p_date date,
338              p_city varchar2,
339              p_new_date IN OUT NOCOPY date,
340              p_status IN OUT NOCOPY number,
341              p_state varchar2) IS --Bug 2319552
342 
343 
344   -- Local Variables
345 
346   l_calendar varchar2(10);
347   l_payment_action varchar2(1);
348   l_change_date varchar2(1);
349   return_question number;
350   returned_date   varchar2(11);
351 
352   l_org_id   NUMBER;   --  MOAC Bug # 2306001
353 
354   BEGIN
355     ------------------------------------------------------------------------
356     -- Validate the profile options.
357     ------------------------------------------------------------------------
358     if p_date IS NOT NULL then
359        l_org_id := MO_GLOBAL.get_current_org_id;
360        l_payment_action := JL_ZZ_SYS_OPTIONS_PKG.get_payment_action(l_org_id);  -- MOAC
361        -- Bug 4715379
362        l_calendar := jl_zz_sys_options_pkg.get_calendar;
363        l_change_date := jl_zz_sys_options_pkg.get_change_date_automatically(l_org_id);
364        if l_payment_action is NOT NULL then
365           if l_calendar is NOT NULL then
366              if l_change_date is NOT NULL then
367                 ------------------------------------------------------------
368                 -- Get the new date.
369                 ------------------------------------------------------------
370                   -- Bug 2319552 : BDC - State Lov : Start ------
371                   jl_br_workday_calendar.jl_br_check_date(to_char(p_date,'DD-MM-YYYY'),l_calendar,
372                           p_city,l_payment_action,returned_date,p_status, p_state);
373                 if p_status = 0 then /* procedure successfull */
374                    -----------------------------------------------------------
375                    -- Return the new date.
376                    -----------------------------------------------------------
377                    p_new_date := to_date(returned_date,'DD-MM-YYYY');
378                    if p_date <> p_new_date then
379                       if l_change_date = 'N' then
380                           RETURN;
381                       end if;
382                    end if;
383                 end if;
384              else
385                 p_status := 1;
386              end if;
387           else
388             p_status := 2;
389           end if;
390        else
391          p_status := 3;
392        end if;
393     end if;
394 END VALIDATE_DATE;
395 
396 /* ***************************************************************
397    Function : GET_BORDERO_BANK_REF
398    Return   : jl_br_ap_collection_docs.OUR_NUMBER
399    Type     : Varchar2
400    Objective: Return Bank references stored in 'our_number'
401               to ipayments extract. This field is display in
402               Bordero as Bank Reference.
403    *************************************************************** */
404 FUNCTION Get_Bordero_Bank_Ref
405            (P_Doc_Payable_ID    IN  IBY_Docs_Payable_All.document_payable_id%TYPE,
406             P_RETURN_STATUS     OUT NOCOPY  Varchar2)
407             RETURN Varchar2
408 IS
409 Cursor Bank_Ref IS
410     Select  jl.our_number
411       From  jl_br_ap_collection_docs jl
412            ,ap_payment_schedules_all ap
413            ,iby_docs_payable_all iby
414     Where   iby.document_payable_id     = P_Doc_Payable_ID
415       And   iby.calling_app_doc_unique_ref2 = ap.invoice_id
416       And   iby.calling_app_doc_unique_ref3 = ap.payment_num
417       And   jl.bank_collection_id       = ap.global_attribute11;
418 
419     Bank_Reference jl_br_ap_collection_docs.our_number%TYPE;
420 
421 Begin
422   P_RETURN_STATUS := FND_API.G_RET_STS_SUCCESS;
423   Bank_Reference  := NULL;
424   FOR Rec IN Bank_Ref LOOP
425       Bank_Reference := Rec.our_number;
426       RETURN(Bank_Reference);
427   END LOOP;
428   RETURN(Bank_Reference);
429 
430 EXCEPTION
431    WHEN OTHERS THEN
432         -- It was agreed with IBY to do not fail
433         NULL;
434 End Get_Bordero_Bank_Ref;
435 
436 /* ***************************************************************
437    Function : GET_BORDERO_INT_AMT
438    Return   : Invoice Interest Amount
439    Type     : Number
440    Objective: Return Invoice Interest Amount
441    *************************************************************** */
442 FUNCTION Get_Bordero_Int_Amt
443            (P_Doc_Payable_ID    IN  IBY_Docs_Payable_All.document_payable_id%TYPE,
444             P_Process_Type      IN  VARCHAR2,
445             P_RETURN_STATUS     OUT NOCOPY  Varchar2)
446             RETURN Number
447 IS
448   CURSOR Process_Type IS
449     SELECT pays.process_type
450       FROM iby_payments_all     pays
451           ,iby_docs_payable_all docs
452      WHERE pays.payment_id = docs.payment_id
453        AND docs.document_payable_id  = P_Doc_Payable_ID;
454 
455    int_amt number;
456    l_process_type iby_payments_all.process_type%Type;
457 
458 Begin
459      P_RETURN_STATUS := FND_API.G_RET_STS_SUCCESS;
460      int_amt := 0;
461      IF P_Process_Type is null THEN
462         For db_reg in Process_Type Loop
463             l_process_type := db_reg.process_type;
464         End Loop;
465      ELSE
466             l_process_type := P_Process_Type;
467      END IF;
468      Begin
469        IF (l_process_type = 'IMMEDIATE') THEN
470 
471           select sum(nvl(int.invoice_amount,0))
472             into int_amt
473             from ap_invoices_all int,
474                  ap_invoice_relationships  rel,
475                  iby_docs_payable_all iby
476            where rel.original_invoice_id = iby.calling_app_doc_unique_ref2 -- ap.invoice_id
477              and rel.original_payment_num = iby.calling_app_doc_unique_ref3 -- ap.payment_num
478              and int.invoice_id = rel.related_invoice_id
479              and iby.document_payable_id  = P_Doc_Payable_ID;
480             return(int_amt);
481         END IF;
482      Exception
483              WHEN OTHERS THEN
484                   return(0);
485      End;
486 
487      IF (l_process_type <> 'IMMEDIATE'  or P_Process_Type IS NULL) THEN
488         SELECT sum(nvl(invoice_amount,0))
489           INTO int_amt
490           FROM ap_selected_invoices_all ap,
491                iby_docs_payable_all iby
492          WHERE original_invoice_id  = iby.calling_app_doc_unique_ref2 -- :invoice_id
493            AND original_payment_num = iby.calling_app_doc_unique_ref3 -- :payment_num
494            AND iby.document_payable_id  = P_Doc_Payable_ID;
495            return(int_amt);
496      END IF;
497     return(int_amt);
498 
499 EXCEPTION
500    WHEN OTHERS THEN
501         -- It was agreed with IBY to do not fail
502         Return(0);
503 End Get_Bordero_Int_Amt;
504 
505 /* ***************************************************************
506    Function : GET_BORDERO_ABATEMENT
507    Return   : Invoice Interest Amount
508    Type     : Number
509    Objective: Return Invoice Abatement Amount
510    *************************************************************** */
511 FUNCTION Get_Bordero_Abatement
512            (P_Doc_Payable_ID    IN  IBY_Docs_Payable_All.document_payable_id%TYPE,
513             P_Process_Type      IN  VARCHAR2,
514             P_RETURN_STATUS     OUT NOCOPY  Varchar2)
515             RETURN Number
516 IS
517    CURSOR Process_Type IS
518     SELECT pays.process_type
519       FROM iby_payments_all     pays
520           ,iby_docs_payable_all docs
521      WHERE pays.payment_id = docs.payment_id
522        AND docs.document_payable_id  = P_Doc_Payable_ID;
523 
524    abate number;
525    l_process_type iby_payments_all.process_type%Type;
526 
527 Begin
528    P_RETURN_STATUS := FND_API.G_RET_STS_SUCCESS;
529    abate := 0;
530 
531    IF P_Process_Type is null THEN
532       For db_reg in Process_Type Loop
533           l_process_type := db_reg.process_type;
534       End Loop;
535    ELSE
536           l_process_type := P_Process_Type;
537    END IF;
538    Begin
539      IF (l_process_type = 'IMMEDIATE') THEN
540 
541         SELECT abs(sum(nvl(aid.amount,0)))
542         INTO abate
543         FROM ap_invoice_distributions_all aid,
544              ap_invoice_payments_all aip,
545              ap_checks_all ac,
546              iby_docs_payable_all iby
547         WHERE aid.invoice_id = aip.invoice_id
548           AND ac.check_number = iby.payment_id -- :check_number
549           AND ac.check_id = aip.check_id
550           AND aid.parent_invoice_id = iby.calling_app_doc_unique_ref2 -- :invoice_id
551           AND iby.document_payable_id  = P_Doc_Payable_ID;
552      ELSE
553         SELECT abs(sum(nvl(aid.amount,0)))
554         INTO abate
555         FROM ap_invoice_distributions_all aid,
556              ap_selected_invoices_all asi,
557              iby_docs_payable_all iby,
558              iby_pay_service_requests proc,
559              iby_payments_all paym
560         WHERE aid.invoice_id = asi.invoice_id
561           AND asi.checkrun_name = proc.call_app_pay_service_req_code -- :p_payment_batch
562           AND paym.payment_service_request_id = proc.payment_service_request_id
563           AND iby.payment_id = paym.payment_id
564           AND asi.ok_to_pay_flag <> 'N'
565           AND aid.parent_invoice_id = iby.calling_app_doc_unique_ref2 -- :invoice_id
566           AND aid.parent_invoice_id <> aid.invoice_id -- fix for bug 2676773
567           AND iby.calling_app_id= 200
568           AND iby.document_payable_id  = P_Doc_Payable_ID;
569 
570      END IF; -- (l_process_type = 'IMMEDIATE')
571    EXCEPTION
572       WHEN NO_DATA_FOUND THEN
573            NULL;
574    END;
575 
576   RETURN(nvl(abate, 0));
577 
578 EXCEPTION
579    WHEN OTHERS THEN
580         -- It was agreed with IBY to do not fail
581         RETURN(nvl(abate, 0));
582 End Get_Bordero_Abatement;
583 
584 /* ***************************************************************
585    Function : Check_Brazil
586    Return   : Checking if country is brazil
587    Type     : Number
588    Objective: Verify if invoice country is brazil
589    *************************************************************** */
590 Function Check_Brazil
591            (P_Doc_Payable_ID    IN  IBY_Docs_Payable_All.document_payable_id%TYPE,
592             P_RETURN_STATUS     OUT NOCOPY  Varchar2)
593 RETURN Number
594 IS
595   Cursor ap_inv IS
596    SELECT 1 br_c
597      FROM ap_invoices_all ap,
598           iby_docs_payable_all iby
599     WHERE ap.invoice_id = iby.calling_app_doc_unique_ref2
600       AND ap.global_attribute_category = 'JL.BR.APXINWKB.AP_INVOICES'
601       AND iby.document_payable_id  = P_Doc_Payable_ID;
602 BEGIN
603     P_RETURN_STATUS := FND_API.G_RET_STS_SUCCESS;
604     For db_reg in ap_inv Loop
605         If db_reg.br_c = 1 Then
606            Return(1);
607         Else
608            Return(0);
609         End if;
610     End Loop;
611     Return(0);
612 EXCEPTION
613    WHEN OTHERS THEN
614         -- It was agreed with IBY to do not fail
615         RETURN(0);
616 END Check_Brazil;
617 
618 END JL_BR_AP_PAY_SCHED_GDF_PKG; -- Package