304: from
305: ap_invoices_all
306: where invoice_id = pn_invoice_id;
307:
308: cursor c_JAI_AP_TDS_INVOICES(pn_parent_invoice_id number, pv_tds_invoice_num varchar2) is
309: select
310: invoice_id parent_invoice_id ,
311: invoice_amount taxable_basis ,
312: tds_tax_id tds_tax_id ,
313: tds_section tds_section ,
314: tds_tax_rate tds_tax_rate ,
315: tds_amount tax_amount
316: from
317: JAI_AP_TDS_INVOICES
318: where invoice_id = nvl(pn_parent_invoice_id, invoice_id)
319: and tds_invoice_num = pv_tds_invoice_num
320: and source_attribute = lv_source_attribute;
321:
319: and tds_invoice_num = pv_tds_invoice_num
320: and source_attribute = lv_source_attribute;
321:
322: /* identifies parent on basis of invoice number */
323: cursor c_JAI_AP_TDS_INVOICES_1(pv_tds_invoice_num varchar2) is
324: select
325: invoice_id parent_invoice_id ,
326: invoice_amount taxable_basis ,
327: tds_tax_id tds_tax_id ,
328: tds_section tds_section ,
329: tds_tax_rate tds_tax_rate ,
330: tds_amount tax_amount
331: from
332: JAI_AP_TDS_INVOICES
333: where tds_invoice_num = pv_tds_invoice_num
334: and source_attribute = lv_source_attribute;
335:
336:
336:
337:
338: cursor c_get_section_if_one(pn_invoice_id number) is
339: select jiati_1.tds_section
340: from JAI_AP_TDS_INVOICES jiati_1
341: where jiati_1.invoice_id = pn_invoice_id
342: and source_attribute = lv_source_attribute
343: and not exists
344: (
342: and source_attribute = lv_source_attribute
343: and not exists
344: (
345: select '1'
346: from JAI_AP_TDS_INVOICES jiati_2
347: where jiati_1.rowid <> jiati_2.rowid
348: and source_attribute = lv_source_attribute
349: and jiati_1.invoice_id = jiati_2.invoice_id
350: and jiati_1.tds_section <> jiati_2.tds_section
354: cursor c_get_tax_if_one(pn_invoice_id number) is
355: select
356: jiati_1.tds_tax_id ,
357: jiati_1.tds_tax_rate
358: from JAI_AP_TDS_INVOICES jiati_1
359: where jiati_1.invoice_id = pn_invoice_id
360: and source_attribute = lv_source_attribute
361: and not exists
362: (
360: and source_attribute = lv_source_attribute
361: and not exists
362: (
363: select '1'
364: from JAI_AP_TDS_INVOICES jiati_2
365: where jiati_1.rowid <> jiati_2.rowid
366: and source_attribute = lv_source_attribute
367: and jiati_1.invoice_id = jiati_2.invoice_id
368: and jiati_1.tds_tax_id <> jiati_2.tds_tax_id
520: ln_vendor_site_id number(15);
521:
522:
523: r_ap_invoices_all c_ap_invoices_all%rowtype;
524: r_JAI_AP_TDS_INVOICES c_JAI_AP_TDS_INVOICES%rowtype;
525: ln_record_count number;
526: ln_threshold_trx_id number;
527: r_get_payment_details c_get_payment_details%rowtype;
528:
725: ln_vendor_id := null;
726: ln_vendor_site_id := null;
727:
728: r_ap_invoices_all := null;
729: r_JAI_AP_TDS_INVOICES := null;
730:
731: ln_tax_amount := cur_rec.tax_amount;
732:
733:
735: ln_parent_invoice_id := cur_rec.parent_invoice_id;
736: end if;
737:
738: if ln_parent_invoice_id is not null then
739: open c_JAI_AP_TDS_INVOICES(ln_parent_invoice_id, cur_rec.invoice_num);
740: fetch c_JAI_AP_TDS_INVOICES into r_JAI_AP_TDS_INVOICES;
741: close c_JAI_AP_TDS_INVOICES;
742: else
743: /* try n find the parent based on invoice number */
736: end if;
737:
738: if ln_parent_invoice_id is not null then
739: open c_JAI_AP_TDS_INVOICES(ln_parent_invoice_id, cur_rec.invoice_num);
740: fetch c_JAI_AP_TDS_INVOICES into r_JAI_AP_TDS_INVOICES;
741: close c_JAI_AP_TDS_INVOICES;
742: else
743: /* try n find the parent based on invoice number */
744: open c_JAI_AP_TDS_INVOICES_1(cur_rec.invoice_num);
737:
738: if ln_parent_invoice_id is not null then
739: open c_JAI_AP_TDS_INVOICES(ln_parent_invoice_id, cur_rec.invoice_num);
740: fetch c_JAI_AP_TDS_INVOICES into r_JAI_AP_TDS_INVOICES;
741: close c_JAI_AP_TDS_INVOICES;
742: else
743: /* try n find the parent based on invoice number */
744: open c_JAI_AP_TDS_INVOICES_1(cur_rec.invoice_num);
745: fetch c_JAI_AP_TDS_INVOICES_1 into r_JAI_AP_TDS_INVOICES;
740: fetch c_JAI_AP_TDS_INVOICES into r_JAI_AP_TDS_INVOICES;
741: close c_JAI_AP_TDS_INVOICES;
742: else
743: /* try n find the parent based on invoice number */
744: open c_JAI_AP_TDS_INVOICES_1(cur_rec.invoice_num);
745: fetch c_JAI_AP_TDS_INVOICES_1 into r_JAI_AP_TDS_INVOICES;
746: close c_JAI_AP_TDS_INVOICES_1;
747: end if;
748:
741: close c_JAI_AP_TDS_INVOICES;
742: else
743: /* try n find the parent based on invoice number */
744: open c_JAI_AP_TDS_INVOICES_1(cur_rec.invoice_num);
745: fetch c_JAI_AP_TDS_INVOICES_1 into r_JAI_AP_TDS_INVOICES;
746: close c_JAI_AP_TDS_INVOICES_1;
747: end if;
748:
749: if ln_parent_invoice_id is null and r_JAI_AP_TDS_INVOICES.parent_invoice_id is null then
742: else
743: /* try n find the parent based on invoice number */
744: open c_JAI_AP_TDS_INVOICES_1(cur_rec.invoice_num);
745: fetch c_JAI_AP_TDS_INVOICES_1 into r_JAI_AP_TDS_INVOICES;
746: close c_JAI_AP_TDS_INVOICES_1;
747: end if;
748:
749: if ln_parent_invoice_id is null and r_JAI_AP_TDS_INVOICES.parent_invoice_id is null then
750: /* parent is not found in ap_invoices_all or JAI_AP_TDS_INVOICES,
745: fetch c_JAI_AP_TDS_INVOICES_1 into r_JAI_AP_TDS_INVOICES;
746: close c_JAI_AP_TDS_INVOICES_1;
747: end if;
748:
749: if ln_parent_invoice_id is null and r_JAI_AP_TDS_INVOICES.parent_invoice_id is null then
750: /* parent is not found in ap_invoices_all or JAI_AP_TDS_INVOICES,
751: no other details can be found */
752: goto populate_old_invoice_details;
753: end if;
746: close c_JAI_AP_TDS_INVOICES_1;
747: end if;
748:
749: if ln_parent_invoice_id is null and r_JAI_AP_TDS_INVOICES.parent_invoice_id is null then
750: /* parent is not found in ap_invoices_all or JAI_AP_TDS_INVOICES,
751: no other details can be found */
752: goto populate_old_invoice_details;
753: end if;
754:
753: end if;
754:
755: /* A parent invoice has been traced, check if it passes filtering condition of vendor and site if given */
756: if pn_vendor_id is not null or pn_vendor_site_id is not null then
757: open c_ap_invoices_all( nvl(ln_parent_invoice_id, r_JAI_AP_TDS_INVOICES.parent_invoice_id) );
758: fetch c_ap_invoices_all into r_ap_invoices_all;
759: close c_ap_invoices_all;
760:
761: if r_ap_invoices_all.vendor_id <> nvl(pn_vendor_id, r_ap_invoices_all.vendor_id) or
766:
767: end if; /* checking parent vendor or site */
768:
769:
770: if ln_parent_invoice_id is not null and r_JAI_AP_TDS_INVOICES.parent_invoice_id is null then
771: /* parent invoice has been found, but details not captured in JAI_AP_TDS_INVOICES.
772: could be a return invoice, check if only one section was applicable against the parent and populate if so */
773: open c_get_section_if_one(ln_parent_invoice_id);
774: fetch c_get_section_if_one into lv_section_code;
767: end if; /* checking parent vendor or site */
768:
769:
770: if ln_parent_invoice_id is not null and r_JAI_AP_TDS_INVOICES.parent_invoice_id is null then
771: /* parent invoice has been found, but details not captured in JAI_AP_TDS_INVOICES.
772: could be a return invoice, check if only one section was applicable against the parent and populate if so */
773: open c_get_section_if_one(ln_parent_invoice_id);
774: fetch c_get_section_if_one into lv_section_code;
775: close c_get_section_if_one;
785:
786: ln_taxable_basis := ln_tax_amount * (100/ln_tax_rate);
787: end if;
788:
789: elsif r_JAI_AP_TDS_INVOICES.parent_invoice_id is not null then
790: /* A record in ja_in_ap_tds_invoice has been identified */
791:
792: if r_JAI_AP_TDS_INVOICES.tds_section <> nvl(pv_tds_section, r_JAI_AP_TDS_INVOICES.tds_section) then
793: goto continue_with_next_record;
788:
789: elsif r_JAI_AP_TDS_INVOICES.parent_invoice_id is not null then
790: /* A record in ja_in_ap_tds_invoice has been identified */
791:
792: if r_JAI_AP_TDS_INVOICES.tds_section <> nvl(pv_tds_section, r_JAI_AP_TDS_INVOICES.tds_section) then
793: goto continue_with_next_record;
794: end if;
795:
796: ln_parent_invoice_id := r_JAI_AP_TDS_INVOICES.parent_invoice_id;
792: if r_JAI_AP_TDS_INVOICES.tds_section <> nvl(pv_tds_section, r_JAI_AP_TDS_INVOICES.tds_section) then
793: goto continue_with_next_record;
794: end if;
795:
796: ln_parent_invoice_id := r_JAI_AP_TDS_INVOICES.parent_invoice_id;
797: lv_section_code := r_JAI_AP_TDS_INVOICES.tds_section;
798: ln_tax_id := r_JAI_AP_TDS_INVOICES.tds_tax_id;
799: ln_tax_rate := r_JAI_AP_TDS_INVOICES.tds_tax_rate;
800: ln_taxable_basis := r_JAI_AP_TDS_INVOICES.taxable_basis;
793: goto continue_with_next_record;
794: end if;
795:
796: ln_parent_invoice_id := r_JAI_AP_TDS_INVOICES.parent_invoice_id;
797: lv_section_code := r_JAI_AP_TDS_INVOICES.tds_section;
798: ln_tax_id := r_JAI_AP_TDS_INVOICES.tds_tax_id;
799: ln_tax_rate := r_JAI_AP_TDS_INVOICES.tds_tax_rate;
800: ln_taxable_basis := r_JAI_AP_TDS_INVOICES.taxable_basis;
801: ln_tax_amount := r_JAI_AP_TDS_INVOICES.tax_amount;
794: end if;
795:
796: ln_parent_invoice_id := r_JAI_AP_TDS_INVOICES.parent_invoice_id;
797: lv_section_code := r_JAI_AP_TDS_INVOICES.tds_section;
798: ln_tax_id := r_JAI_AP_TDS_INVOICES.tds_tax_id;
799: ln_tax_rate := r_JAI_AP_TDS_INVOICES.tds_tax_rate;
800: ln_taxable_basis := r_JAI_AP_TDS_INVOICES.taxable_basis;
801: ln_tax_amount := r_JAI_AP_TDS_INVOICES.tax_amount;
802:
795:
796: ln_parent_invoice_id := r_JAI_AP_TDS_INVOICES.parent_invoice_id;
797: lv_section_code := r_JAI_AP_TDS_INVOICES.tds_section;
798: ln_tax_id := r_JAI_AP_TDS_INVOICES.tds_tax_id;
799: ln_tax_rate := r_JAI_AP_TDS_INVOICES.tds_tax_rate;
800: ln_taxable_basis := r_JAI_AP_TDS_INVOICES.taxable_basis;
801: ln_tax_amount := r_JAI_AP_TDS_INVOICES.tax_amount;
802:
803: end if;
796: ln_parent_invoice_id := r_JAI_AP_TDS_INVOICES.parent_invoice_id;
797: lv_section_code := r_JAI_AP_TDS_INVOICES.tds_section;
798: ln_tax_id := r_JAI_AP_TDS_INVOICES.tds_tax_id;
799: ln_tax_rate := r_JAI_AP_TDS_INVOICES.tds_tax_rate;
800: ln_taxable_basis := r_JAI_AP_TDS_INVOICES.taxable_basis;
801: ln_tax_amount := r_JAI_AP_TDS_INVOICES.tax_amount;
802:
803: end if;
804:
797: lv_section_code := r_JAI_AP_TDS_INVOICES.tds_section;
798: ln_tax_id := r_JAI_AP_TDS_INVOICES.tds_tax_id;
799: ln_tax_rate := r_JAI_AP_TDS_INVOICES.tds_tax_rate;
800: ln_taxable_basis := r_JAI_AP_TDS_INVOICES.taxable_basis;
801: ln_tax_amount := r_JAI_AP_TDS_INVOICES.tax_amount;
802:
803: end if;
804:
805: -- added, Harshita for Bug 4643633
913: ln_vendor_id := null;
914: ln_vendor_site_id := null;
915:
916: r_ap_invoices_all := null;
917: r_JAI_AP_TDS_INVOICES := null;
918:
919:
920: /* Get payment information against the prepayment */
921: r_get_payment_details := null;
948: ln_parent_invoice_id := cur_rec.parent_invoice_id;
949: end if;
950:
951: if ln_parent_invoice_id is not null then
952: open c_JAI_AP_TDS_INVOICES(ln_parent_invoice_id, cur_rec.invoice_num);
953: fetch c_JAI_AP_TDS_INVOICES into r_JAI_AP_TDS_INVOICES;
954: close c_JAI_AP_TDS_INVOICES;
955: else
956: /* try n find the parent based on invoice number */
949: end if;
950:
951: if ln_parent_invoice_id is not null then
952: open c_JAI_AP_TDS_INVOICES(ln_parent_invoice_id, cur_rec.invoice_num);
953: fetch c_JAI_AP_TDS_INVOICES into r_JAI_AP_TDS_INVOICES;
954: close c_JAI_AP_TDS_INVOICES;
955: else
956: /* try n find the parent based on invoice number */
957: open c_JAI_AP_TDS_INVOICES_1(cur_rec.invoice_num);
950:
951: if ln_parent_invoice_id is not null then
952: open c_JAI_AP_TDS_INVOICES(ln_parent_invoice_id, cur_rec.invoice_num);
953: fetch c_JAI_AP_TDS_INVOICES into r_JAI_AP_TDS_INVOICES;
954: close c_JAI_AP_TDS_INVOICES;
955: else
956: /* try n find the parent based on invoice number */
957: open c_JAI_AP_TDS_INVOICES_1(cur_rec.invoice_num);
958: fetch c_JAI_AP_TDS_INVOICES_1 into r_JAI_AP_TDS_INVOICES;
953: fetch c_JAI_AP_TDS_INVOICES into r_JAI_AP_TDS_INVOICES;
954: close c_JAI_AP_TDS_INVOICES;
955: else
956: /* try n find the parent based on invoice number */
957: open c_JAI_AP_TDS_INVOICES_1(cur_rec.invoice_num);
958: fetch c_JAI_AP_TDS_INVOICES_1 into r_JAI_AP_TDS_INVOICES;
959: close c_JAI_AP_TDS_INVOICES_1;
960: end if;
961:
954: close c_JAI_AP_TDS_INVOICES;
955: else
956: /* try n find the parent based on invoice number */
957: open c_JAI_AP_TDS_INVOICES_1(cur_rec.invoice_num);
958: fetch c_JAI_AP_TDS_INVOICES_1 into r_JAI_AP_TDS_INVOICES;
959: close c_JAI_AP_TDS_INVOICES_1;
960: end if;
961:
962: if ln_parent_invoice_id is null and r_JAI_AP_TDS_INVOICES.parent_invoice_id is null then
955: else
956: /* try n find the parent based on invoice number */
957: open c_JAI_AP_TDS_INVOICES_1(cur_rec.invoice_num);
958: fetch c_JAI_AP_TDS_INVOICES_1 into r_JAI_AP_TDS_INVOICES;
959: close c_JAI_AP_TDS_INVOICES_1;
960: end if;
961:
962: if ln_parent_invoice_id is null and r_JAI_AP_TDS_INVOICES.parent_invoice_id is null then
963: /* parent is not found in ap_invoices_all or JAI_AP_TDS_INVOICES,
958: fetch c_JAI_AP_TDS_INVOICES_1 into r_JAI_AP_TDS_INVOICES;
959: close c_JAI_AP_TDS_INVOICES_1;
960: end if;
961:
962: if ln_parent_invoice_id is null and r_JAI_AP_TDS_INVOICES.parent_invoice_id is null then
963: /* parent is not found in ap_invoices_all or JAI_AP_TDS_INVOICES,
964: no other details can be found */
965: goto populate_invoice_details;
966: end if;
959: close c_JAI_AP_TDS_INVOICES_1;
960: end if;
961:
962: if ln_parent_invoice_id is null and r_JAI_AP_TDS_INVOICES.parent_invoice_id is null then
963: /* parent is not found in ap_invoices_all or JAI_AP_TDS_INVOICES,
964: no other details can be found */
965: goto populate_invoice_details;
966: end if;
967:
966: end if;
967:
968: /* A parent invoice has been traced, check if it passes filtering condition of vendor and site if given */
969: if pn_vendor_id is not null or pn_vendor_site_id is not null then
970: open c_ap_invoices_all( nvl(ln_parent_invoice_id, r_JAI_AP_TDS_INVOICES.parent_invoice_id) );
971: fetch c_ap_invoices_all into r_ap_invoices_all;
972: close c_ap_invoices_all;
973:
974: if r_ap_invoices_all.vendor_id <> nvl(pn_vendor_id, r_ap_invoices_all.vendor_id) or
979:
980: end if; /* checking parent vendor or site */
981:
982:
983: if ln_parent_invoice_id is not null and r_JAI_AP_TDS_INVOICES.parent_invoice_id is null then
984: /* parent invoice has been found, but details not captured in JAI_AP_TDS_INVOICES.
985: could be a return invoice, check if only one section was applicable against the parent and populate if so */
986: open c_get_section_if_one(ln_parent_invoice_id);
987: fetch c_get_section_if_one into lv_section_code;
980: end if; /* checking parent vendor or site */
981:
982:
983: if ln_parent_invoice_id is not null and r_JAI_AP_TDS_INVOICES.parent_invoice_id is null then
984: /* parent invoice has been found, but details not captured in JAI_AP_TDS_INVOICES.
985: could be a return invoice, check if only one section was applicable against the parent and populate if so */
986: open c_get_section_if_one(ln_parent_invoice_id);
987: fetch c_get_section_if_one into lv_section_code;
988: close c_get_section_if_one;
998:
999: ln_taxable_basis := ln_tax_amount * (100/ln_tax_rate);
1000: end if;
1001:
1002: elsif r_JAI_AP_TDS_INVOICES.parent_invoice_id is not null then
1003: /* A record in ja_in_ap_tds_invoice has been identified */
1004:
1005: if r_JAI_AP_TDS_INVOICES.tds_section <> nvl(pv_tds_section, r_JAI_AP_TDS_INVOICES.tds_section) then
1006: goto continue_with_next_record;
1001:
1002: elsif r_JAI_AP_TDS_INVOICES.parent_invoice_id is not null then
1003: /* A record in ja_in_ap_tds_invoice has been identified */
1004:
1005: if r_JAI_AP_TDS_INVOICES.tds_section <> nvl(pv_tds_section, r_JAI_AP_TDS_INVOICES.tds_section) then
1006: goto continue_with_next_record;
1007: end if;
1008:
1009: ln_parent_invoice_id := r_JAI_AP_TDS_INVOICES.parent_invoice_id;
1005: if r_JAI_AP_TDS_INVOICES.tds_section <> nvl(pv_tds_section, r_JAI_AP_TDS_INVOICES.tds_section) then
1006: goto continue_with_next_record;
1007: end if;
1008:
1009: ln_parent_invoice_id := r_JAI_AP_TDS_INVOICES.parent_invoice_id;
1010: lv_section_code := r_JAI_AP_TDS_INVOICES.tds_section;
1011: ln_tax_id := r_JAI_AP_TDS_INVOICES.tds_tax_id;
1012: ln_tax_rate := r_JAI_AP_TDS_INVOICES.tds_tax_rate;
1013: ln_taxable_basis := r_JAI_AP_TDS_INVOICES.taxable_basis;
1006: goto continue_with_next_record;
1007: end if;
1008:
1009: ln_parent_invoice_id := r_JAI_AP_TDS_INVOICES.parent_invoice_id;
1010: lv_section_code := r_JAI_AP_TDS_INVOICES.tds_section;
1011: ln_tax_id := r_JAI_AP_TDS_INVOICES.tds_tax_id;
1012: ln_tax_rate := r_JAI_AP_TDS_INVOICES.tds_tax_rate;
1013: ln_taxable_basis := r_JAI_AP_TDS_INVOICES.taxable_basis;
1014: ln_tax_amount := r_JAI_AP_TDS_INVOICES.tax_amount;
1007: end if;
1008:
1009: ln_parent_invoice_id := r_JAI_AP_TDS_INVOICES.parent_invoice_id;
1010: lv_section_code := r_JAI_AP_TDS_INVOICES.tds_section;
1011: ln_tax_id := r_JAI_AP_TDS_INVOICES.tds_tax_id;
1012: ln_tax_rate := r_JAI_AP_TDS_INVOICES.tds_tax_rate;
1013: ln_taxable_basis := r_JAI_AP_TDS_INVOICES.taxable_basis;
1014: ln_tax_amount := r_JAI_AP_TDS_INVOICES.tax_amount;
1015:
1008:
1009: ln_parent_invoice_id := r_JAI_AP_TDS_INVOICES.parent_invoice_id;
1010: lv_section_code := r_JAI_AP_TDS_INVOICES.tds_section;
1011: ln_tax_id := r_JAI_AP_TDS_INVOICES.tds_tax_id;
1012: ln_tax_rate := r_JAI_AP_TDS_INVOICES.tds_tax_rate;
1013: ln_taxable_basis := r_JAI_AP_TDS_INVOICES.taxable_basis;
1014: ln_tax_amount := r_JAI_AP_TDS_INVOICES.tax_amount;
1015:
1016: end if;
1009: ln_parent_invoice_id := r_JAI_AP_TDS_INVOICES.parent_invoice_id;
1010: lv_section_code := r_JAI_AP_TDS_INVOICES.tds_section;
1011: ln_tax_id := r_JAI_AP_TDS_INVOICES.tds_tax_id;
1012: ln_tax_rate := r_JAI_AP_TDS_INVOICES.tds_tax_rate;
1013: ln_taxable_basis := r_JAI_AP_TDS_INVOICES.taxable_basis;
1014: ln_tax_amount := r_JAI_AP_TDS_INVOICES.tax_amount;
1015:
1016: end if;
1017:
1010: lv_section_code := r_JAI_AP_TDS_INVOICES.tds_section;
1011: ln_tax_id := r_JAI_AP_TDS_INVOICES.tds_tax_id;
1012: ln_tax_rate := r_JAI_AP_TDS_INVOICES.tds_tax_rate;
1013: ln_taxable_basis := r_JAI_AP_TDS_INVOICES.taxable_basis;
1014: ln_tax_amount := r_JAI_AP_TDS_INVOICES.tax_amount;
1015:
1016: end if;
1017:
1018: << populate_invoice_details >>