and( (trunc(h.journal_date)<=trunc(to_date('2020-01-31','yyyy-mm-dd')) and h.description='MANUAL_IMPORT')or(trunc(h.journal_date)>trunc(to_date('2020-01-31','yyyy-mm-dd'))))
AND not EXISTS (SELECT 1
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.vat_interface_status = 'BACK'
AND to_char(hi.invoice_date,'yyyymm') <= ${@base_period}
AND (li.cashflow_id = l.cashflow_id OR
li.ref_n04 = l.journal_line_id))
GROUP BY l.reference1,
reference3,
reference4,
h.journal_num,
l.cashflow_id,
l.journal_header_id,
h.je_transaction_code,
h.period_year,
h.period_num,
h.internal_period_num,
h.journal_date
UNION
SELECT h.period_year,
h.period_num,
h.internal_period_num,
h.journal_date,
h.journal_num,
reference3 contract_number,
reference4 bp_code,
(SELECT BP_NAME
FROM hls_bp_master
WHERE bp_code = reference4
AND ROWNUM = 1) bp_name,
l.journal_header_id,
(SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N'
AND hi.vat_interface_status = 'BACK'
AND li.cf_item = 2
and hi.contract_id = l.source_doc_id
AND ROWNUM = 1) invoice_date,
l.amount_dr amount_tax,
'首付款' times,
(SELECT due_date
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1) due_date,
(SELECT due_amount
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1)
due_amount,
(SELECT principal
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1) principal,
(SELECT interest
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1) interest,
(SELECT vat_due_amount
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1) vat_due_amount,
NVL(ROUND((
(SELECT vat_due_amount
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1)
/
(SELECT net_due_amount
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1)
),
2) * 100,
0) || '%' vat_rate,
h.je_transaction_code
FROM hls_journal_header h, hls_journal_detail l
WHERE h.journal_header_id = l.journal_header_id
AND h.je_transaction_code = 'LEASE_INCEPT'
AND l.je_template_ln_id = 8797
and( (trunc(h.journal_date)<=trunc(to_date('2020-01-31','yyyy-mm-dd')) and h.description='MANUAL_IMPORT')or(trunc(h.journal_date)>trunc(to_date('2020-01-31','yyyy-mm-dd'))))
AND not EXISTS
(SELECT 1
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.vat_interface_status = 'BACK'
AND to_char(hi.invoice_date,'yyyymm') <= ${@base_period}
AND ((hi.contract_id = l.source_doc_id AND li.cf_item IN (2))))
and( (trunc(h.journal_date)<=trunc(to_date('2020-01-31','yyyy-mm-dd')) and h.description='MANUAL_IMPORT')or(trunc(h.journal_date)>trunc(to_date('2020-01-31','yyyy-mm-dd'))))
AND not EXISTS (SELECT 1
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.vat_interface_status = 'BACK'
AND to_char(hi.invoice_date,'yyyymm') <= ${@base_period}
AND (li.cashflow_id = l.cashflow_id OR
li.ref_n04 = l.journal_line_id))
GROUP BY l.reference1,
reference3,
reference4,
h.journal_num,
l.cashflow_id,
l.journal_header_id,
h.je_transaction_code,
h.period_year,
h.period_num,
h.internal_period_num,
h.journal_date
UNION
SELECT h.period_year,
h.period_num,
h.internal_period_num,
h.journal_date,
h.journal_num,
reference3 contract_number,
reference4 bp_code,
(SELECT BP_NAME
FROM hls_bp_master
WHERE bp_code = reference4
AND ROWNUM = 1) bp_name,
l.journal_header_id,
(SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N'
AND hi.vat_interface_status = 'BACK'
AND li.cf_item = 2
and hi.contract_id = l.source_doc_id
AND ROWNUM = 1) invoice_date,
l.amount_dr amount_tax,
'首付款' times,
(SELECT due_date
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1) due_date,
(SELECT due_amount
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1)
due_amount,
(SELECT principal
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1) principal,
(SELECT interest
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1) interest,
(SELECT vat_due_amount
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1) vat_due_amount,
NVL(ROUND((
(SELECT vat_due_amount
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1)
/
(SELECT net_due_amount
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1)
),
2) * 100,
0) || '%' vat_rate,
h.je_transaction_code
FROM hls_journal_header h, hls_journal_detail l
WHERE h.journal_header_id = l.journal_header_id
AND h.je_transaction_code = 'LEASE_INCEPT'
AND l.je_template_ln_id = 8797
and( (trunc(h.journal_date)<=trunc(to_date('2020-01-31','yyyy-mm-dd')) and h.description='MANUAL_IMPORT')or(trunc(h.journal_date)>trunc(to_date('2020-01-31','yyyy-mm-dd'))))
AND not EXISTS
(SELECT 1
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.vat_interface_status = 'BACK'
AND to_char(hi.invoice_date,'yyyymm') <= ${@base_period}
AND ((hi.contract_id = l.source_doc_id AND li.cf_item IN (2))))