select
x.*
from
(
select
hou.name operating_unit,
to_char(add_months(nvl(aia_tds.gl_date,aia.gl_date),-3),'YYYY')||'-'||to_char(add_months(nvl(aia_tds.gl_date,aia.gl_date),9),'YY') financial_year,
'Q'||(trunc(mod(to_number(to_char(nvl(aia_tds.gl_date,aia.gl_date),'MM'))+8,12)/3)+1) quarter,
aps.vendor_name supplier,
aps.segment1 supplier_number,
assa.vendor_site_code supplier_site,
nvl(pan_site.pan,pan_hdr.pan) "Supplier PAN",
nvl2(pan_site.pan,pan_site.effective_from,pan_hdr.effective_from) "PAN Effective From",
nvl2(pan_site.pan,pan_site.creation_date,pan_hdr.creation_date) "PAN Entered On",
nvl2(pan_site.pan,pan_site.vendor_type,pan_hdr.vendor_type) "TDS Vendor Type",
xxen_util.meaning(jattt.tds_section_code,'JAI_TDS_SECTION',7000) section,
jtr.tax_rate_name tax,
initcap(jattt.tds_event) "TDS Event",
aia.invoice_num invoice_number,
aia.invoice_date,
aia.gl_date "Invoice GL Date",
aia.invoice_currency_code invoice_currency,
aia.invoice_amount,
decode(sign(jattt.invoice_to_vendor_amt),1,-1,1)*jattt.taxable_amount taxable_amount,
jattt.tax_rate "TDS Rate",
decode(sign(jattt.invoice_to_vendor_amt),1,-1,1)*jattt.tax_amount "TDS Amount",
aia_tds.invoice_num "TDS Invoice Number",
aia_tds.invoice_date "TDS Invoice Date",
aia_tds.gl_date "TDS Invoice GL Date",
aia_tds.invoice_amount "TDS Invoice Amount",
xxen_util.ap_invoice_status(aia_tds.invoice_id,aia_tds.invoice_amount,aia_tds.payment_status_flag,aia_tds.invoice_type_lookup_code,aia_tds.validation_request_id) "TDS Invoice Status",
aps_auth.vendor_name "TDS Authority",
aia_tds.amount_paid "TDS Paid Amount",
pay.payment_date "TDS Payment Date",
pay.payment_number "TDS Payment Number",
pay.challan_number,
pay.challan_date,
pay.bsr_code "BSR Code",
jattt.invoice_to_vendor_num "Supplier TDS Document",
jattt.invoice_to_vendor_amt "Supplier TDS Document Amount",
(select max(jatip.certificate_num) from jai_ap_tds_inv_payments jatip where jattt.invoice_to_tds_authority_id=jatip.invoice_id) certificate_number,
xxen_util.yes(jattt.tds_rollbacked) rolled_back
from
jai_ap_tds_thhold_trxs jattt,
ap_invoices_all aia,
hr_operating_units hou,
ap_suppliers aps,
ap_supplier_sites_all assa,
jai_tax_rates jtr,
ap_invoices_all aia_tds,
ap_suppliers aps_auth,
(
select
aipa.invoice_id,
max(aca.check_date) payment_date,
max(aca.check_number) keep (dense_rank last order by aca.check_date, aca.check_id) payment_number,
max(jatp.challan_no) keep (dense_rank last order by aca.check_date, aca.check_id) challan_number,
max(jatp.check_deposit_date) keep (dense_rank last order by aca.check_date, aca.check_id) challan_date,
max(jatp.bsr_code) keep (dense_rank last order by aca.check_date, aca.check_id) bsr_code
from
ap_invoice_payments_all aipa,
ap_checks_all aca,
jai_ap_tds_payments jatp
where
aipa.invoice_id in (select jattt2.invoice_to_tds_authority_id from jai_ap_tds_thhold_trxs jattt2) and
aipa.check_id=aca.check_id and
aca.status_lookup_code not in ('VOIDED','STOP INITIATED') and
aca.check_id=jatp.check_id(+)
group by
aipa.invoice_id
) pay,
(
select
jpr.party_site_id,
max(decode(jprl.registration_type_code,'PAN',jprl.registration_number,jprl.secondary_registration_number)) keep (dense_rank last order by jprl.effective_from) pan,
max(jprl.effective_from) effective_from,
max(jprl.creation_date) keep (dense_rank last order by jprl.effective_from) creation_date,
max(jra.reporting_code) vendor_type
from
jai_party_regs jpr,
jai_party_reg_lines jprl,
jai_regimes jr,
jai_reporting_associations jra
where
jpr.party_type_code='THIRD_PARTY_SITE' and
jpr.supplier_flag='Y' and
jpr.party_reg_id=jprl.party_reg_id and
jprl.regime_id=jr.regime_id and
jr.regime_type='W' and
'PAN' in (jprl.registration_type_code,jprl.sec_registration_type_code) and
(jprl.effective_to is null or jprl.effective_to>=sysdate) and
jprl.party_reg_id=jra.entity_id(+) and
jprl.regime_id=jra.regime_id(+) and
jra.entity_code(+)='THIRD_PARTY' and
jra.reporting_type_name(+)='Vendor Type'
group by
jpr.party_site_id
) pan_site,
(
select
jpr.party_id,
max(decode(jprl.registration_type_code,'PAN',jprl.registration_number,jprl.secondary_registration_number)) keep (dense_rank last order by jprl.effective_from) pan,
max(jprl.effective_from) effective_from,
max(jprl.creation_date) keep (dense_rank last order by jprl.effective_from) creation_date,
max(jra.reporting_code) vendor_type
from
jai_party_regs jpr,
jai_party_reg_lines jprl,
jai_regimes jr,
jai_reporting_associations jra
where
jpr.party_type_code='THIRD_PARTY' and
jpr.supplier_flag='Y' and
jpr.party_reg_id=jprl.party_reg_id and
jprl.regime_id=jr.regime_id and
jr.regime_type='W' and
'PAN' in (jprl.registration_type_code,jprl.sec_registration_type_code) and
(jprl.effective_to is null or jprl.effective_to>=sysdate) and
jprl.party_reg_id=jra.entity_id(+) and
jprl.regime_id=jra.regime_id(+) and
jra.entity_code(+)='THIRD_PARTY' and
jra.reporting_type_name(+)='Vendor Type'
group by
jpr.party_id
) pan_hdr
where
1=1 and
jattt.invoice_id=aia.invoice_id and
aia.org_id=hou.organization_id and
jattt.vendor_id=aps.vendor_id and
jattt.vendor_site_id=assa.vendor_site_id and
jattt.tax_id=jtr.tax_rate_id(+) and
jattt.invoice_to_tds_authority_id=aia_tds.invoice_id(+) and
jattt.tds_authority_vendor_id=aps_auth.vendor_id(+) and
jattt.invoice_to_tds_authority_id=pay.invoice_id(+) and
jattt.vendor_site_id=pan_site.party_site_id(+) and
jattt.vendor_id=pan_hdr.party_id(+) and
hou.organization_id in (select xroa.id from xxen_report_org_access xroa where xroa.access_type='OU')
) x
order by
x.operating_unit,
x.supplier,
x.supplier_site,
x."Invoice GL Date",
x.invoice_number,
x.section,
x."TDS Invoice Number" |