Commit d68aaa1b authored by 王炜's avatar 王炜

回租销项科目调整

parent 50b17b51
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
$Author: ZLF $Author: ZLF
$Date: 2015-1-21 下午3:09:38 $Date: 2015-1-21 下午3:09:38
$Revision: 1.0 $Revision: 1.0
$Purpose: $Purpose:
--> -->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false"> <bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
<bm:operations> <bm:operations>
<bm:operation name="query"> <bm:operation name="query">
<bm:query-sql><![CDATA[ <bm:query-sql><![CDATA[
SELECT * FROM ( SELECT * FROM (
SELECT h.period_year, SELECT h.period_year,
h.period_num, h.period_num,
h.internal_period_num, h.internal_period_num,
h.journal_date, h.journal_date,
h.sbo_num journal_num, h.sbo_num journal_num,
reference3 contract_number, reference3 contract_number,
reference1 bp_code, reference1 bp_code,
(SELECT BP_NAME (SELECT BP_NAME
FROM hls_bp_master FROM hls_bp_master
WHERE bp_code = reference1 WHERE bp_code = reference1
AND ROWNUM = 1) bp_name, AND ROWNUM = 1) bp_name,
l.journal_header_id, l.journal_header_id,
(SELECT hi.invoice_date (SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N' AND hi.reversed_flag = 'N'
AND (li.cashflow_id = l.cashflow_id OR AND (li.cashflow_id = l.cashflow_id OR
li.ref_n03 = l.journal_header_id) li.ref_n03 = l.journal_header_id)
AND ROWNUM = 1) invoice_date, AND ROWNUM = 1) invoice_date,
l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where ah.contract_id=h.source_id l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where ah.contract_id=h.source_id
and ah.invoice_hd_id=al.invoice_hd_id and ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N' and ah.reversed_flag='N'
and ah.invoice_status='CONFIRM' and ah.invoice_status='CONFIRM'
and al.cf_item = 2 and al.cf_item = 2
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period} AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
and ah.invoice_status = 'CONFIRM'),0) amount_tax, and ah.invoice_status = 'CONFIRM'),0) amount_tax,
'首付款' times, '首付款' times,
(select ccc.due_date from con_contract_cashflow ccc where ccc.contract_id=h.source_id (select ccc.due_date from con_contract_cashflow ccc where ccc.contract_id=h.source_id
and ccc.cf_item=2) due_date, and ccc.cf_item=2) due_date,
(select ccc.due_amount from con_contract_cashflow ccc where ccc.contract_id=h.source_id (select ccc.due_amount from con_contract_cashflow ccc where ccc.contract_id=h.source_id
and ccc.cf_item=2) due_amount, and ccc.cf_item=2) due_amount,
(select ccc.due_amount from con_contract_cashflow ccc where ccc.contract_id=h.source_id (select ccc.due_amount from con_contract_cashflow ccc where ccc.contract_id=h.source_id
and ccc.cf_item=2) principal, and ccc.cf_item=2) principal,
null interest, null interest,
l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where ah.contract_id=h.source_id l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where ah.contract_id=h.source_id
and ah.invoice_hd_id=al.invoice_hd_id and ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N' and ah.reversed_flag='N'
and ah.invoice_status='CONFIRM' and ah.invoice_status='CONFIRM'
and al.cf_item = 2 and al.cf_item = 2
AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period} AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period}
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND ah.vat_interface_status = 'BACK' AND ah.vat_interface_status = 'BACK'
and ah.invoice_status = 'CONFIRM'),0) vat_due_amount, and ah.invoice_status = 'CONFIRM'),0) vat_due_amount,
(select (select
case when nvl(ccc.due_amount-ccc.vat_due_amount,0)<>0 then case when nvl(ccc.due_amount-ccc.vat_due_amount,0)<>0 then
round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2) round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2)
else else
null null
end end
from con_contract_cashflow ccc where ccc.contract_id=h.source_id from con_contract_cashflow ccc where ccc.contract_id=h.source_id
and ccc.cf_item=2) vat_rate, and ccc.cf_item=2) vat_rate,
h.je_transaction_code, h.je_transaction_code,
l.cashflow_id l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
WHERE h.journal_header_id = l.journal_header_id WHERE h.journal_header_id = l.journal_header_id
and h.sbo_num is not null and h.sbo_num is not null
and h.total_amount_dr!=0 and h.total_amount_dr!=0
and ga.account_id=l.account_id and ga.account_id=l.account_id
and ga.account_code in('2221001020','2221001023') and ga.account_code in('2221001020','2221001023','2221001024')
and h.reversed_flag='N' and h.reversed_flag='N'
and h.internal_period_num=to_number(${@base_period}) and h.internal_period_num=to_number(${@base_period})
AND (h.je_transaction_code= 'LEASE_INCEPT') AND (h.je_transaction_code= 'LEASE_INCEPT')
and exists (select 1 and exists (select 1
from gld_je_template_hds hd from gld_je_template_hds hd
where hd.je_template_hd_id = where hd.je_template_hd_id =
h.je_template_hd_id h.je_template_hd_id
and hd.je_template_code = and hd.je_template_code =
'HL_INCEPT_DOWN_PAYMENT_CF') 'HL_INCEPT_DOWN_PAYMENT_CF')
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( (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'))))
union union
SELECT h.period_year, SELECT h.period_year,
h.period_num, h.period_num,
h.internal_period_num, h.internal_period_num,
h.journal_date, h.journal_date,
h.sbo_num journal_num, h.sbo_num journal_num,
reference3 contract_number, reference3 contract_number,
reference1 bp_code, reference1 bp_code,
(SELECT BP_NAME (SELECT BP_NAME
FROM hls_bp_master FROM hls_bp_master
WHERE bp_code = reference1 WHERE bp_code = reference1
AND ROWNUM = 1) bp_name, AND ROWNUM = 1) bp_name,
l.journal_header_id, l.journal_header_id,
(SELECT hi.invoice_date (SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N' AND hi.reversed_flag = 'N'
AND (li.cashflow_id = l.cashflow_id OR AND (li.cashflow_id = l.cashflow_id OR
li.ref_n03 = l.journal_header_id) li.ref_n03 = l.journal_header_id)
AND ROWNUM = 1) invoice_date, AND ROWNUM = 1) invoice_date,
l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where ah.invoice_hd_id=al.invoice_hd_id l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N' and ah.reversed_flag='N'
and al.cashflow_id=l.cashflow_id and al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period} AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
and ah.invoice_status = 'CONFIRM'),0) amount_tax, and ah.invoice_status = 'CONFIRM'),0) amount_tax,
(select decode(ccc.cf_item, (select decode(ccc.cf_item,
8, 8,
'留购价', '留购价',
to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times, to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times,
(select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date, (select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date,
(select case (select case
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
nvl(ccc.interest, 0) - nvl(ccc.interest, 0) -
nvl((select sum(al.tax_amount) nvl((select sum(al.tax_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period} AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) 0)
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' then when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' then
ccc.due_amount - ccc.due_amount -
nvl((select sum(al.total_amount) nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period} AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) 0)
else else
ccc.due_amount - ccc.due_amount -
nvl((select sum(al.total_amount) nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period} AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) 0)
end end
from con_contract cc, con_contract_cashflow ccc from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id where ccc.cashflow_id = l.cashflow_id
and ccc.contract_id = cc.contract_id) due_amount, and ccc.contract_id = cc.contract_id) due_amount,
(select case (select case
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
0 0
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_amount) nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period} ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) > nvl(ccc.interest,0) then 0) > nvl(ccc.interest,0) then
ccc.due_amount-nvl((select sum(al.total_amount) ccc.due_amount-nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period} ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) 0)
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_amount) nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period} ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) <=nvl(ccc.interest,0) then 0) <=nvl(ccc.interest,0) then
nvl(ccc.principal, 0) nvl(ccc.principal, 0)
else else
ccc.principal ccc.principal
end end
from con_contract cc, con_contract_cashflow ccc from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id where ccc.cashflow_id = l.cashflow_id
and ccc.contract_id = cc.contract_id) principal, and ccc.contract_id = cc.contract_id) principal,
(select case (select case
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
nvl(ccc.interest, 0) - nvl(ccc.interest, 0) -
nvl((select sum(al.tax_amount) nvl((select sum(al.tax_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period} AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) 0)
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_amount) nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period} ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) >nvl(ccc.interest,0) then 0) >nvl(ccc.interest,0) then
0 0
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_amount) nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period} ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) <= nvl(ccc.interest,0) then 0) <= nvl(ccc.interest,0) then
nvl(ccc.interest, 0)-nvl((select sum(al.total_amount) nvl(ccc.interest, 0)-nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period} ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) 0)
else else
ccc.due_amount ccc.due_amount
end end
from con_contract cc, con_contract_cashflow ccc from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id where ccc.cashflow_id = l.cashflow_id
and ccc.contract_id = cc.contract_id) interest, and ccc.contract_id = cc.contract_id) interest,
l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where
ah.invoice_hd_id=al.invoice_hd_id ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N' and ah.reversed_flag='N'
and al.cashflow_id=l.cashflow_id and al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period} AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'),0) vat_due_amount, and ah.invoice_status = 'CONFIRM'),0) vat_due_amount,
(select (select
case when ccc.cf_item=1 and cc.business_type='LEASEBACK' and nvl(ccc.interest-ccc.vat_interest,0) !=0 then case when ccc.cf_item=1 and cc.business_type='LEASEBACK' and nvl(ccc.interest-ccc.vat_interest,0) !=0 then
round(ccc.vat_interest/(ccc.interest-ccc.vat_interest),2) round(ccc.vat_interest/(ccc.interest-ccc.vat_interest),2)
when ((ccc.cf_item=1 and cc.business_type!='LEASEBACK') or ccc.cf_item!=1 ) and nvl(ccc.due_amount-ccc.vat_due_amount,0) !=0 then when ((ccc.cf_item=1 and cc.business_type!='LEASEBACK') or ccc.cf_item!=1 ) and nvl(ccc.due_amount-ccc.vat_due_amount,0) !=0 then
round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2) round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2)
else else
null null
end end
from from
con_contract cc,con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id con_contract cc,con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id
and cc.contract_id=ccc.contract_id) vat_rate, and cc.contract_id=ccc.contract_id) vat_rate,
h.je_transaction_code, h.je_transaction_code,
l.cashflow_id l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
WHERE h.journal_header_id = l.journal_header_id WHERE h.journal_header_id = l.journal_header_id
and h.sbo_num is not null and h.sbo_num is not null
and h.total_amount_dr!=0 and h.total_amount_dr!=0
and ga.account_id=l.account_id and ga.account_id=l.account_id
and ga.account_code in('2221001020','2221001023') and ga.account_code in('2221001020','2221001023','2221001024')
and h.reversed_flag='N' and h.reversed_flag='N'
and h.internal_period_num=to_number(${@base_period}) and h.internal_period_num=to_number(${@base_period})
And (h.je_transaction_code ='HL_SALES_TAX_ACT_NEW' ) And (h.je_transaction_code ='HL_SALES_TAX_ACT_NEW' )
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( (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'))))
union union
SELECT h.period_year, SELECT h.period_year,
h.period_num, h.period_num,
h.internal_period_num, h.internal_period_num,
h.journal_date, h.journal_date,
h.sbo_num journal_num, h.sbo_num journal_num,
reference3 contract_number, reference3 contract_number,
reference1 bp_code, reference1 bp_code,
(SELECT BP_NAME (SELECT BP_NAME
FROM hls_bp_master FROM hls_bp_master
WHERE bp_code = reference1 WHERE bp_code = reference1
AND ROWNUM = 1) bp_name, AND ROWNUM = 1) bp_name,
l.journal_header_id, l.journal_header_id,
(SELECT hi.invoice_date (SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N' AND hi.reversed_flag = 'N'
AND (li.cashflow_id = l.cashflow_id OR AND (li.cashflow_id = l.cashflow_id OR
li.ref_n03 = l.journal_header_id) li.ref_n03 = l.journal_header_id)
AND ROWNUM = 1) invoice_date, AND ROWNUM = 1) invoice_date,
round(l.amount_cr - round(l.amount_cr -
nvl((select sum(al.tax_amount) nvl((select sum(al.tax_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.contract_id = h.source_id where ah.contract_id = h.source_id
and ah.invoice_hd_id = al.invoice_hd_id and ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.ref_n03 = l.journal_header_id and al.ref_n03 = l.journal_header_id
and al.ref_n04 = l.journal_line_id and al.ref_n04 = l.journal_line_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') < =${@base_period} AND to_char(ah.invoice_date, 'yyyymm') < =${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0),2) amount_tax, 0),2) amount_tax,
'违约金' times, '违约金' times,
h.journal_date due_date, h.journal_date due_date,
case when ghd.je_template_code in('HL_RECEIVABLES_AGENT_REPUR_LB','HL_RECEIVABLES_AGENT_REPUR','HL_GLD_BALANCE_PENALTY') then case when ghd.je_template_code in('HL_RECEIVABLES_AGENT_REPUR_LB','HL_RECEIVABLES_AGENT_REPUR','HL_GLD_BALANCE_PENALTY') then
(select d.amount_cr (select d.amount_cr
from hls_journal_detail d from hls_journal_detail d
where d.journal_header_id = h.journal_header_id where d.journal_header_id = h.journal_header_id
and exists and d.reference3=l.reference3
(select 1 and exists
from gld_accounts g (select 1
where g.account_id = d.account_id from gld_accounts g
and g.account_code in ('6041001000')) where g.account_id = d.account_id
and rownum = 1) and g.account_code in ('6041001000'))
else and rownum = 1)
(select d.amount_dr else
from hls_journal_detail d (select nvl(d.amount_dr,d.amount_cr)
where d.journal_header_id = h.journal_header_id from hls_journal_detail d
and exists where d.journal_header_id = h.journal_header_id
(select 1 and d.reference3=l.reference3
from gld_accounts g and exists
where g.account_id = d.account_id (select 1
and g.account_code in ('1122000001', '1122000002')) from gld_accounts g
and rownum = 1) where g.account_id = d.account_id
end due_amount, and g.account_code in ('1122000001', '1122000002'))
null principal, and rownum = 1)
case when ghd.je_template_code in('HL_RECEIVABLES_AGENT_REPUR_LB','HL_RECEIVABLES_AGENT_REPUR','HL_GLD_BALANCE_PENALTY') then end due_amount,
(select d.amount_cr null principal,
from hls_journal_detail d case when ghd.je_template_code in('HL_RECEIVABLES_AGENT_REPUR_LB','HL_RECEIVABLES_AGENT_REPUR','HL_GLD_BALANCE_PENALTY') then
where d.journal_header_id = h.journal_header_id (select d.amount_cr
and exists from hls_journal_detail d
(select 1 where d.journal_header_id = h.journal_header_id
from gld_accounts g and d.reference3=l.reference3
where g.account_id = d.account_id and exists
and g.account_code in ('6041001000')) (select 1
and rownum = 1) from gld_accounts g
else where g.account_id = d.account_id
(select d.amount_dr and g.account_code in ('6041001000'))
from hls_journal_detail d and rownum = 1)
where d.journal_header_id = h.journal_header_id else
and exists (select nvl(d.amount_dr,d.amount_cr)
(select 1 from hls_journal_detail d
from gld_accounts g where d.journal_header_id = h.journal_header_id
where g.account_id = d.account_id and d.reference3=l.reference3
and g.account_code in ('1122000001', '1122000002')) and exists
and rownum = 1) (select 1
end interest, from gld_accounts g
round(l.amount_cr - where g.account_id = d.account_id
nvl((select sum(al.tax_amount) and g.account_code in ('1122000001', '1122000002'))
from acr_invoice_hd ah, acr_invoice_ln al and rownum = 1)
where ah.contract_id = h.source_id end interest,
and ah.invoice_hd_id = al.invoice_hd_id round(l.amount_cr -
and ah.reversed_flag = 'N' nvl((select sum(al.tax_amount)
and al.ref_n03 = l.journal_header_id from acr_invoice_hd ah, acr_invoice_ln al
and al.ref_n04 = l.journal_line_id where ah.contract_id = h.source_id
and ah.invoice_kind in ('0', '2') and ah.invoice_hd_id = al.invoice_hd_id
AND to_char(ah.invoice_date, 'yyyymm') < =${@base_period} and ah.reversed_flag = 'N'
and ah.invoice_status = 'CONFIRM'), and al.ref_n03 = l.journal_header_id
0),2) vat_due_amount, and al.ref_n04 = l.journal_line_id
(select DECODE(CC.BUSINESS_TYPE, 'LEASEBACK', 0.06, 0.13) and ah.invoice_kind in ('0', '2')
from con_contract cc AND to_char(ah.invoice_date, 'yyyymm') < =${@base_period}
WHERE cc.contract_number = l.reference3 and ah.invoice_status = 'CONFIRM'),
and cc.data_class = 'NORMAL') vat_rate, 0),2) vat_due_amount,
h.je_transaction_code, (select DECODE(CC.BUSINESS_TYPE, 'LEASEBACK', 0.06, 0.13)
l.cashflow_id from con_contract cc
FROM hls_journal_header h, hls_journal_detail l, gld_accounts ga,gld_je_template_hds ghd WHERE cc.contract_number = l.reference3
WHERE h.journal_header_id = l.journal_header_id and cc.data_class = 'NORMAL') vat_rate,
and h.je_template_hd_id=ghd.je_template_hd_id h.je_transaction_code,
and h.sbo_num is not null l.cashflow_id
and h.total_amount_dr != 0 FROM hls_journal_header h, hls_journal_detail l, gld_accounts ga,gld_je_template_hds ghd
and ga.account_id = l.account_id WHERE h.journal_header_id = l.journal_header_id
and ga.account_code in ('2221001020', '2221001023') and h.je_template_hd_id=ghd.je_template_hd_id
and h.reversed_flag = 'N' and h.sbo_num is not null
and h.internal_period_num = to_number(${@base_period}) and h.total_amount_dr != 0
And (h.je_transaction_code = and ga.account_id = l.account_id
'HL_CSH_CONSOLIDATION_DALAY' or and ga.account_code in ('2221001020', '2221001023','2221001024')
ghd.je_template_code in and h.reversed_flag = 'N'
('HL_GLD_BALANCE_REPURCHASE','HL_GLD_BALANCE_REPURCHASE_LB','HL_RECEIVABLES_AGENT_REPUR_LB','HL_RECEIVABLES_AGENT_REPUR','HL_GLD_BALANCE_PENALTY','HL_PENALTY_R_ET','HL_PENALTY_R_ET_LB') and h.internal_period_num = to_number(${@base_period})
) And (h.je_transaction_code =
and not exists (SELECT 1 'HL_CSH_CONSOLIDATION_DALAY' or
FROM acr_invoice_hd hi, acr_invoice_ln li ghd.je_template_code in
WHERE hi.invoice_hd_id = li.invoice_hd_id ('HL_GLD_BALANCE_REPURCHASE','HL_GLD_BALANCE_REPURCHASE_LB','HL_RECEIVABLES_AGENT_REPUR_LB','HL_RECEIVABLES_AGENT_REPUR','HL_GLD_BALANCE_PENALTY','HL_PENALTY_R_ET','HL_PENALTY_R_ET_LB')
AND hi.vat_interface_status = 'BACK' )
and hi.invoice_status = 'CONFIRM' and not exists (SELECT 1
AND to_char(hi.invoice_date, 'yyyymm') < =${@base_period} FROM acr_invoice_hd hi, acr_invoice_ln li
and li.ref_n03 = l.journal_header_id WHERE hi.invoice_hd_id = li.invoice_hd_id
and li.ref_n04 = l.journal_line_id) AND hi.vat_interface_status = 'BACK'
union and hi.invoice_status = 'CONFIRM'
SELECT h.period_year, AND to_char(hi.invoice_date, 'yyyymm') < =${@base_period}
h.period_num, and li.ref_n03 = l.journal_header_id
h.internal_period_num, and li.ref_n04 = l.journal_line_id)
h.journal_date, union
h.sbo_num journal_num, SELECT h.period_year,
reference3 contract_number, h.period_num,
reference1 bp_code, h.internal_period_num,
(SELECT BP_NAME h.journal_date,
FROM hls_bp_master h.sbo_num journal_num,
WHERE bp_code = reference1 reference3 contract_number,
AND ROWNUM = 1) bp_name, reference1 bp_code,
l.journal_header_id, (SELECT BP_NAME
(SELECT hi.invoice_date FROM hls_bp_master
FROM acr_invoice_hd hi, acr_invoice_ln li WHERE bp_code = reference1
WHERE hi.invoice_hd_id = li.invoice_hd_id AND ROWNUM = 1) bp_name,
AND hi.reversed_flag = 'N' l.journal_header_id,
AND (li.cashflow_id = l.cashflow_id OR (SELECT hi.invoice_date
li.ref_n03 = l.journal_header_id) FROM acr_invoice_hd hi, acr_invoice_ln li
AND ROWNUM = 1) invoice_date, WHERE hi.invoice_hd_id = li.invoice_hd_id
l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where AND hi.reversed_flag = 'N'
ah.invoice_hd_id=al.invoice_hd_id AND (li.cashflow_id = l.cashflow_id OR
and ah.reversed_flag='N' li.ref_n03 = l.journal_header_id)
and al.cashflow_id=l.cashflow_id AND ROWNUM = 1) invoice_date,
and ah.invoice_kind in ('0', '2') l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period} ah.invoice_hd_id=al.invoice_hd_id
and ah.invoice_status = 'CONFIRM'),0) amount_tax, and ah.reversed_flag='N'
(select decode(ccc.cf_item, and al.cashflow_id=l.cashflow_id
8, and ah.invoice_kind in ('0', '2')
'留购价', AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times, and ah.invoice_status = 'CONFIRM'),0) amount_tax,
(select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date, (select decode(ccc.cf_item,
(select 8,
case when ccc.cf_item=200 then '留购价',
ccc.due_amount-nvl((select sum(al.total_amount) from acr_invoice_hd ah,acr_invoice_ln al where to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times,
ah.invoice_hd_id=al.invoice_hd_id (select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date,
and ah.reversed_flag='N' (select
and al.cashflow_id=l.cashflow_id case when ccc.cf_item=200 then
and ah.invoice_kind in ('0', '2') ccc.due_amount-nvl((select sum(al.total_amount) from acr_invoice_hd ah,acr_invoice_ln al where
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period} ah.invoice_hd_id=al.invoice_hd_id
and ah.invoice_status = 'CONFIRM'),0) and ah.reversed_flag='N'
else and al.cashflow_id=l.cashflow_id
ccc.due_amount and ah.invoice_kind in ('0', '2')
end AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_amount, and ah.invoice_status = 'CONFIRM'),0)
(select case when ccc.cf_item=200 then else
ccc.due_amount-nvl((select sum(al.total_amount) from acr_invoice_hd ah,acr_invoice_ln al where ccc.due_amount
ah.invoice_hd_id=al.invoice_hd_id end
and ah.reversed_flag='N' from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_amount,
and al.cashflow_id=l.cashflow_id (select case when ccc.cf_item=200 then
and ah.invoice_kind in ('0', '2') ccc.due_amount-nvl((select sum(al.total_amount) from acr_invoice_hd ah,acr_invoice_ln al where
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period} ah.invoice_hd_id=al.invoice_hd_id
and ah.invoice_status = 'CONFIRM'),0) and ah.reversed_flag='N'
else and al.cashflow_id=l.cashflow_id
0 and ah.invoice_kind in ('0', '2')
end AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) principal, and ah.invoice_status = 'CONFIRM'),0)
(select decode(ccc.cf_item,'200',0,ccc.due_amount) else
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) interest, 0
l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where end
ah.invoice_hd_id=al.invoice_hd_id from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) principal,
and ah.reversed_flag='N' (select decode(ccc.cf_item,'200',0,ccc.due_amount)
and al.cashflow_id=l.cashflow_id from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) interest,
and ah.invoice_kind in ('0', '2') l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where
AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period} ah.invoice_hd_id=al.invoice_hd_id
and ah.invoice_status = 'CONFIRM'),0) vat_due_amount, and ah.reversed_flag='N'
(select and al.cashflow_id=l.cashflow_id
case when nvl(ccc.due_amount-ccc.vat_due_amount,0)!=0 then and ah.invoice_kind in ('0', '2')
round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2) AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period}
else and ah.invoice_status = 'CONFIRM'),0) vat_due_amount,
null (select
end case when nvl(ccc.due_amount-ccc.vat_due_amount,0)!=0 then
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) vat_rate, round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2)
h.je_transaction_code, else
l.cashflow_id null
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga end
WHERE h.journal_header_id = l.journal_header_id from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) vat_rate,
and h.sbo_num is not null h.je_transaction_code,
and h.total_amount_dr!=0 l.cashflow_id
and ga.account_id=l.account_id FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
and ga.account_code in('2221001020','2221001023') WHERE h.journal_header_id = l.journal_header_id
and h.reversed_flag='N' and h.sbo_num is not null
and h.internal_period_num=to_number(${@base_period}) and h.total_amount_dr!=0
And exists (selEct 1 and ga.account_id=l.account_id
from gld_je_template_hds hd and ga.account_code in('2221001020','2221001023','2221001024')
where hd.je_template_hd_id = and h.reversed_flag='N'
h.je_template_hd_id and h.internal_period_num=to_number(${@base_period})
and hd.je_template_code in And exists (selEct 1
('HL_CON_TAX_ET', from gld_je_template_hds hd
'HL_CON_TAX_ET_N', where hd.je_template_hd_id =
'HL_CON_FIN_ETFEE', h.je_template_hd_id
'HL_CON_FIN_ETFEE_N')) and hd.je_template_code in
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')))) ('HL_CON_TAX_ET',
'HL_CON_TAX_ET_N',
union 'HL_CON_FIN_ETFEE',
SELECT h.period_year, 'HL_CON_FIN_ETFEE_N'))
h.period_num, 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'))))
h.internal_period_num,
h.journal_date, union
h.sbo_num journal_num, SELECT h.period_year,
reference3 contract_number, h.period_num,
reference1 bp_code, h.internal_period_num,
(SELECT BP_NAME h.journal_date,
FROM hls_bp_master h.sbo_num journal_num,
WHERE bp_code = reference1 reference3 contract_number,
AND ROWNUM = 1) bp_name, reference1 bp_code,
l.journal_header_id, (SELECT BP_NAME
(SELECT hi.invoice_date FROM hls_bp_master
FROM acr_invoice_hd hi, acr_invoice_ln li WHERE bp_code = reference1
WHERE hi.invoice_hd_id = li.invoice_hd_id AND ROWNUM = 1) bp_name,
AND hi.reversed_flag = 'N' l.journal_header_id,
AND (li.cashflow_id = l.cashflow_id OR (SELECT hi.invoice_date
li.ref_n03 = l.journal_header_id) FROM acr_invoice_hd hi, acr_invoice_ln li
AND ROWNUM = 1) invoice_date, WHERE hi.invoice_hd_id = li.invoice_hd_id
l.amount_cr amount_tax, AND hi.reversed_flag = 'N'
(select decode(ccc.cf_item, AND (li.cashflow_id = l.cashflow_id OR
8, li.ref_n03 = l.journal_header_id)
'留购价', AND ROWNUM = 1) invoice_date,
'解约回购利息/'||to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times, l.amount_cr amount_tax,
(select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date, (select decode(ccc.cf_item,
(select decode(ccc.cf_item, 8,
250, '留购价',
ccc.interest, '解约回购利息/'||to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times,
ccc.due_amount) (select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date,
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_amount, (select decode(ccc.cf_item,
null principal, 250,
(select decode(ccc.cf_item,250,ccc.interest,ccc.due_amount) ccc.interest,
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) interest, ccc.due_amount)
l.amount_cr vat_due_amount, from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_amount,
(select null principal,
case when ccc.cf_item=250 and nvl(ccc.interest-ccc.vat_interest,0)!=0 then (select decode(ccc.cf_item,250,ccc.interest,ccc.due_amount)
round(ccc.vat_interest/(ccc.interest-ccc.vat_interest),2) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) interest,
when ccc.cf_item!=250 and nvl(ccc.due_amount-ccc.vat_due_amount,0)!=0 then l.amount_cr vat_due_amount,
round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2) (select
else case when ccc.cf_item=250 and nvl(ccc.interest-ccc.vat_interest,0)!=0 then
null round(ccc.vat_interest/(ccc.interest-ccc.vat_interest),2)
end when ccc.cf_item!=250 and nvl(ccc.due_amount-ccc.vat_due_amount,0)!=0 then
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) vat_rate, round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2)
h.je_transaction_code, else
l.cashflow_id null
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga end
WHERE h.journal_header_id = l.journal_header_id from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) vat_rate,
and h.sbo_num is not null h.je_transaction_code,
and h.total_amount_dr!=0 l.cashflow_id
and ga.account_id=l.account_id FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
and ga.account_code in('2221001020','2221001023') WHERE h.journal_header_id = l.journal_header_id
and h.reversed_flag='N' and h.sbo_num is not null
and h.internal_period_num=to_number(${@base_period}) and h.total_amount_dr!=0
AND not EXISTS (SELECT 1 and ga.account_id=l.account_id
FROM acr_invoice_hd hi, acr_invoice_ln li and ga.account_code in('2221001020','2221001023','2221001024')
WHERE hi.invoice_hd_id = li.invoice_hd_id and h.reversed_flag='N'
AND hi.vat_interface_status = 'BACK' and h.internal_period_num=to_number(${@base_period})
and hi.invoice_status='CONFIRM' AND not EXISTS (SELECT 1
AND to_char(hi.invoice_date,'yyyymm') < =${@base_period} FROM acr_invoice_hd hi, acr_invoice_ln li
and li.cashflow_id=l.cashflow_id ) WHERE hi.invoice_hd_id = li.invoice_hd_id
And exists (selEct 1 AND hi.vat_interface_status = 'BACK'
from gld_je_template_hds hd and hi.invoice_status='CONFIRM'
where hd.je_template_hd_id = AND to_char(hi.invoice_date,'yyyymm') < =${@base_period}
h.je_template_hd_id and li.cashflow_id=l.cashflow_id )
and hd.je_template_code in And exists (selEct 1
('HL_FIN_INCOME_REPURCHASE', from gld_je_template_hds hd
'HL_FIN_INCOME_REPURCHASE_N', where hd.je_template_hd_id =
'HL_FIN_INCOME_REPURCHASE_ET', h.je_template_hd_id
'HL_CON_FIN_ETREPUR_INT', and hd.je_template_code in
'HL_CON_FIN_ETREPUR_INT_N')) ('HL_FIN_INCOME_REPURCHASE',
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')))) 'HL_FIN_INCOME_REPURCHASE_N',
'HL_FIN_INCOME_REPURCHASE_ET',
union 'HL_CON_FIN_ETREPUR_INT',
SELECT h.period_year, 'HL_CON_FIN_ETREPUR_INT_N'))
h.period_num, 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'))))
h.internal_period_num,
h.journal_date, union
h.sbo_num journal_num, SELECT h.period_year,
t.contract_number contract_number, h.period_num,
(SELECT bp.bp_code h.internal_period_num,
FROM hls_bp_master bp,hls_journal_detail d h.journal_date,
WHERE bp.bp_code = d.reference1 h.sbo_num journal_num,
and d.journal_header_id=h.journal_header_id t.contract_number contract_number,
AND ROWNUM = 1) bp_code, (SELECT bp.bp_code
(SELECT bp.bp_name FROM hls_bp_master bp,hls_journal_detail d
FROM hls_bp_master bp,hls_journal_detail d WHERE bp.bp_code = d.reference1
WHERE bp.bp_code = d.reference1 and d.journal_header_id=h.journal_header_id
and d.journal_header_id=h.journal_header_id AND ROWNUM = 1) bp_code,
AND ROWNUM = 1) bp_name, (SELECT bp.bp_name
h.journal_header_id, FROM hls_bp_master bp,hls_journal_detail d
(SELECT hi.invoice_date WHERE bp.bp_code = d.reference1
FROM acr_invoice_hd hi, acr_invoice_ln li and d.journal_header_id=h.journal_header_id
WHERE hi.invoice_hd_id = li.invoice_hd_id AND ROWNUM = 1) bp_name,
AND hi.reversed_flag = 'N' h.journal_header_id,
AND (li.cashflow_id = t.cashflow_id OR (SELECT hi.invoice_date
li.ref_n03 = h.journal_header_id) FROM acr_invoice_hd hi, acr_invoice_ln li
AND ROWNUM = 1) invoice_date, WHERE hi.invoice_hd_id = li.invoice_hd_id
t.un_bill_vat_principal amount_tax, AND hi.reversed_flag = 'N'
'解约回购本金'||t.times times, AND (li.cashflow_id = t.cashflow_id OR
h.journal_date due_date, li.ref_n03 = h.journal_header_id)
t.un_bill_principal due_amount, AND ROWNUM = 1) invoice_date,
t.un_bill_principal principal, t.un_bill_vat_principal amount_tax,
null interest, '解约回购本金'||t.times times,
t.un_bill_vat_principal vat_due_amount, h.journal_date due_date,
t.tax_type_rate vat_rate, t.un_bill_principal due_amount,
h.je_transaction_code, t.un_bill_principal principal,
t.cashflow_id null interest,
FROM hls_journal_header h,VAT_ACCOUNT_250_PRIN_TMP t t.un_bill_vat_principal vat_due_amount,
WHERE h.journal_header_id = t.journal_header_id t.tax_type_rate vat_rate,
and t.session_id=${/session/@session_id} h.je_transaction_code,
and nvl(t.un_bill_principal,0)>0 t.cashflow_id
and h.internal_period_num=to_number(${@base_period}) FROM hls_journal_header h,VAT_ACCOUNT_250_PRIN_TMP t
union WHERE h.journal_header_id = t.journal_header_id
SELECT h.period_year, and t.session_id=${/session/@session_id}
h.period_num, and nvl(t.un_bill_principal,0)>0
h.internal_period_num, and h.internal_period_num=to_number(${@base_period})
h.journal_date, union
h.sbo_num journal_num, SELECT h.period_year,
reference3 contract_number, h.period_num,
reference1 bp_code, h.internal_period_num,
(SELECT BP_NAME h.journal_date,
FROM hls_bp_master h.sbo_num journal_num,
WHERE bp_code = reference1 reference3 contract_number,
AND ROWNUM = 1) bp_name, reference1 bp_code,
l.journal_header_id, (SELECT BP_NAME
(SELECT hi.invoice_date FROM hls_bp_master
FROM acr_invoice_hd hi, acr_invoice_ln li WHERE bp_code = reference1
WHERE hi.invoice_hd_id = li.invoice_hd_id AND ROWNUM = 1) bp_name,
AND hi.reversed_flag = 'N' l.journal_header_id,
AND (li.cashflow_id = l.cashflow_id OR (SELECT hi.invoice_date
li.ref_n03 = l.journal_header_id) FROM acr_invoice_hd hi, acr_invoice_ln li
AND ROWNUM = 1) invoice_date, WHERE hi.invoice_hd_id = li.invoice_hd_id
l.amount_cr amount_tax, AND hi.reversed_flag = 'N'
'留购金' times, AND (li.cashflow_id = l.cashflow_id OR
h.journal_date due_date, li.ref_n03 = l.journal_header_id)
to_number(l.reference7) due_amount, AND ROWNUM = 1) invoice_date,
null principal, l.amount_cr amount_tax,
to_number(l.reference7) interest, '留购金' times,
l.amount_cr vat_due_amount, h.journal_date due_date,
case when nvl(l.reference7-abs(l.amount_cr),0)!=0 then to_number(l.reference7) due_amount,
round(abs(l.amount_cr/(l.reference7-abs(l.amount_cr))),2) null principal,
else to_number(l.reference7) interest,
null l.amount_cr vat_due_amount,
end case when nvl(l.reference7-abs(l.amount_cr),0)!=0 then
vat_rate, round(abs(l.amount_cr/(l.reference7-abs(l.amount_cr))),2)
h.je_transaction_code, else
l.cashflow_id null
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga end
WHERE h.journal_header_id = l.journal_header_id vat_rate,
and h.sbo_num is not null h.je_transaction_code,
and h.total_amount_dr!=0 l.cashflow_id
and ga.account_id=l.account_id FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
and l.line_description like '%留购金%' WHERE h.journal_header_id = l.journal_header_id
and ga.account_code in('2221001020','2221001023') and h.sbo_num is not null
and h.reversed_flag='N' and h.total_amount_dr!=0
and h.internal_period_num=to_number(${@base_period}) and ga.account_id=l.account_id
And exists (selEct 1 and l.line_description like '%留购金%'
from gld_je_template_hds hd and ga.account_code in('2221001020','2221001023','2221001024')
where hd.je_template_hd_id = and h.reversed_flag='N'
h.je_template_hd_id and h.internal_period_num=to_number(${@base_period})
and hd.je_template_code in And exists (selEct 1
('HL_CON_CHANGE_REPURCHASE_VAT')) from gld_je_template_hds hd
where hd.je_template_hd_id =
AND EXISTS (SELECT 1 h.je_template_hd_id
FROM con_contract cc,con_contract_cashflow ccc and hd.je_template_code in
where cc.contract_number=l.reference3 ('HL_CON_CHANGE_REPURCHASE_VAT'))
and cc.data_class='NORMAL'
and cc.contract_id=ccc.contract_id AND EXISTS (SELECT 1
and ccc.cf_item=250 FROM con_contract cc,con_contract_cashflow ccc
and ccc.cf_status='RELEASE' where cc.contract_number=l.reference3
and ccc.cf_direction='INFLOW' and cc.data_class='NORMAL'
and ccc.billing_status!='FULL' ) and cc.contract_id=ccc.contract_id
union and ccc.cf_item=250
SELECT h.period_year, and ccc.cf_status='RELEASE'
h.period_num, and ccc.cf_direction='INFLOW'
h.internal_period_num, and ccc.billing_status!='FULL' )
h.journal_date, union
h.sbo_num journal_num, SELECT h.period_year,
reference3 contract_number, h.period_num,
reference1 bp_code, h.internal_period_num,
(SELECT BP_NAME h.journal_date,
FROM hls_bp_master h.sbo_num journal_num,
WHERE bp_code = reference1 reference3 contract_number,
AND ROWNUM = 1) bp_name, reference1 bp_code,
l.journal_header_id, (SELECT BP_NAME
(SELECT hi.invoice_date FROM hls_bp_master
FROM acr_invoice_hd hi, acr_invoice_ln li WHERE bp_code = reference1
WHERE hi.invoice_hd_id = li.invoice_hd_id AND ROWNUM = 1) bp_name,
AND hi.reversed_flag = 'N' l.journal_header_id,
AND (li.cashflow_id = l.cashflow_id OR (SELECT hi.invoice_date
li.ref_n03 = l.journal_header_id) FROM acr_invoice_hd hi, acr_invoice_ln li
AND ROWNUM = 1) invoice_date, WHERE hi.invoice_hd_id = li.invoice_hd_id
abs(l.amount_cr)*-1 AND hi.reversed_flag = 'N'
amount_tax, AND (li.cashflow_id = l.cashflow_id OR
(select decode(ccc.cf_item, li.ref_n03 = l.journal_header_id)
8, AND ROWNUM = 1) invoice_date,
'留购价', abs(l.amount_cr)*-1
to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times, amount_tax,
(select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date, (select decode(ccc.cf_item,
8,
-1* (select case '留购价',
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times,
nvl(ccc.interest, 0) (select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date,
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' then
ccc.due_amount -1* (select case
else when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
ccc.due_amount nvl(ccc.interest, 0)
end when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' then
from con_contract cc, con_contract_cashflow ccc ccc.due_amount
where ccc.cashflow_id = l.cashflow_id else
and ccc.contract_id = cc.contract_id) due_amount, ccc.due_amount
-1* (select case end
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then from con_contract cc, con_contract_cashflow ccc
0 where ccc.cashflow_id = l.cashflow_id
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' then and ccc.contract_id = cc.contract_id) due_amount,
nvl(ccc.principal,0) -1* (select case
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
else 0
ccc.principal when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' then
end nvl(ccc.principal,0)
from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id else
and ccc.contract_id = cc.contract_id) principal, ccc.principal
-1*(select case end
when ccc.cf_item = 1 then from con_contract cc, con_contract_cashflow ccc
nvl(ccc.interest, 0) where ccc.cashflow_id = l.cashflow_id
and ccc.contract_id = cc.contract_id) principal,
else -1*(select case
ccc.due_amount when ccc.cf_item = 1 then
end nvl(ccc.interest, 0)
from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id else
and ccc.contract_id = cc.contract_id) interest, ccc.due_amount
-1*abs(l.amount_cr) vat_due_amount, end
(select from con_contract cc, con_contract_cashflow ccc
case when ccc.cf_item=1 and cc.business_type='LEASEBACK' and nvl(ccc.interest-ccc.vat_interest,0) !=0 then where ccc.cashflow_id = l.cashflow_id
round(ccc.vat_interest/(ccc.interest-ccc.vat_interest),2) and ccc.contract_id = cc.contract_id) interest,
-1*abs(l.amount_cr) vat_due_amount,
when ((ccc.cf_item=1 and cc.business_type!='LEASEBACK') or ccc.cf_item!=1 ) and nvl(ccc.due_amount-ccc.vat_due_amount,0) !=0 then (select
round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2) case when ccc.cf_item=1 and cc.business_type='LEASEBACK' and nvl(ccc.interest-ccc.vat_interest,0) !=0 then
else round(ccc.vat_interest/(ccc.interest-ccc.vat_interest),2)
null
end when ((ccc.cf_item=1 and cc.business_type!='LEASEBACK') or ccc.cf_item!=1 ) and nvl(ccc.due_amount-ccc.vat_due_amount,0) !=0 then
from round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2)
con_contract cc,con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id else
and cc.contract_id=ccc.contract_id) vat_rate, null
h.je_transaction_code, end
l.cashflow_id from
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga con_contract cc,con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id
WHERE h.journal_header_id = l.journal_header_id and cc.contract_id=ccc.contract_id) vat_rate,
and h.sbo_num is not null h.je_transaction_code,
and h.total_amount_dr!=0 l.cashflow_id
and ga.account_id=l.account_id FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
and ga.account_code in('2221001020','2221001023') WHERE h.journal_header_id = l.journal_header_id
and h.reversed_flag='N' and h.sbo_num is not null
and h.internal_period_num = to_number(${@base_period}) and h.total_amount_dr!=0
and exists(select 1 from gld_je_template_hds hd and ga.account_id=l.account_id
where hd.je_template_hd_id=h.je_template_hd_id and ga.account_code in('2221001020','2221001023','2221001024')
and hd.je_template_code in and h.reversed_flag='N'
('HL_CON_VAT_REVERSE_REPURCHASE','HL_VAT_REVERSE_REPURCHASE_LB','HL_CON_VAT_REVERSE_ET','HL_CON_VAT_REVERSE_ET_LB','HL_REPURCHASE_VAT_REVERSE') and h.internal_period_num = to_number(${@base_period})
) and exists(select 1 from gld_je_template_hds hd
where hd.je_template_hd_id=h.je_template_hd_id
) t1 and hd.je_template_code in
#WHERE_CLAUSE# ('HL_CON_VAT_REVERSE_REPURCHASE','HL_VAT_REVERSE_REPURCHASE_LB','HL_CON_VAT_REVERSE_ET','HL_CON_VAT_REVERSE_ET_LB','HL_REPURCHASE_VAT_REVERSE')
]]></bm:query-sql> )
</bm:operation>
</bm:operations> ) t1
<bm:data-filters> #WHERE_CLAUSE#
<bm:data-filter enforceOperations="query" expression="t1.amount_tax &lt;&gt;0"/> ]]></bm:query-sql>
<bm:data-filter enforceOperations="query" expression="exists(select 1 from con_contract cc where cc.contract_number=t1.contract_number and cc.contract_status!='CANCEL' and cc.data_class='NORMAL')"/> </bm:operation>
</bm:data-filters> </bm:operations>
<bm:query-fields> <bm:data-filters>
<bm:query-field name="contract_number" queryExpression="t1.contract_number = ${@contract_number}"/> <bm:data-filter enforceOperations="query" expression="t1.amount_tax &lt;&gt;0"/>
<bm:query-field name="bp_name" queryExpression="t1.bp_name = ${@bp_name}"/> <bm:data-filter enforceOperations="query" expression="exists(select 1 from con_contract cc where cc.contract_number=t1.contract_number and cc.contract_status!='CANCEL' and cc.data_class='NORMAL')"/>
<bm:query-field name="journal_date" queryExpression="to_char(t1.journal_date,'yyyy-mm-dd') = ${@journal_date}"/> </bm:data-filters>
<bm:query-field name="invoice_date" queryExpression="to_char(t1.invoice_date,'yyyy-mm-dd') = ${@invoice_date}"/> <bm:query-fields>
<bm:query-field name="vat_6_flag" queryExpression="((${@vat_6_flag}='Y' and t1.vat_rate=0.06) or (${@vat_6_flag}!='Y' and nvl(t1.vat_rate,0)!=0.06))"/> <bm:query-field name="contract_number" queryExpression="t1.contract_number = ${@contract_number}"/>
</bm:query-fields> <bm:query-field name="bp_name" queryExpression="t1.bp_name = ${@bp_name}"/>
</bm:model> <bm:query-field name="journal_date" queryExpression="to_char(t1.journal_date,'yyyy-mm-dd') = ${@journal_date}"/>
<bm:query-field name="invoice_date" queryExpression="to_char(t1.invoice_date,'yyyy-mm-dd') = ${@invoice_date}"/>
<bm:query-field name="vat_6_flag" queryExpression="((${@vat_6_flag}='Y' and t1.vat_rate=0.06) or (${@vat_6_flag}!='Y' and nvl(t1.vat_rate,0)!=0.06))"/>
</bm:query-fields>
</bm:model>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
$Author: ZLF $Author: ZLF
$Date: 2015-1-21 下午3:09:38 $Date: 2015-1-21 下午3:09:38
$Revision: 1.0 $Revision: 1.0
$Purpose: $Purpose:
--> -->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false"> <bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" needAccessControl="false">
<bm:operations> <bm:operations>
<bm:operation name="query"> <bm:operation name="query">
<bm:query-sql><![CDATA[ <bm:query-sql><![CDATA[
SELECT * FROM ( SELECT * FROM (
SELECT h.period_year, SELECT h.period_year,
h.period_num, h.period_num,
h.internal_period_num, h.internal_period_num,
h.journal_date, h.journal_date,
h.sbo_num journal_num, h.sbo_num journal_num,
reference3 contract_number, reference3 contract_number,
reference1 bp_code, reference1 bp_code,
(SELECT BP_NAME (SELECT BP_NAME
FROM hls_bp_master FROM hls_bp_master
WHERE bp_code = reference1 WHERE bp_code = reference1
AND ROWNUM = 1) bp_name, AND ROWNUM = 1) bp_name,
l.journal_header_id, l.journal_header_id,
(SELECT hi.invoice_date (SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N' AND hi.reversed_flag = 'N'
AND (li.cashflow_id = l.cashflow_id OR AND (li.cashflow_id = l.cashflow_id OR
li.ref_n03 = l.journal_header_id) li.ref_n03 = l.journal_header_id)
AND ROWNUM = 1) invoice_date, AND ROWNUM = 1) invoice_date,
l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where ah.contract_id=h.source_id l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where ah.contract_id=h.source_id
and ah.invoice_hd_id=al.invoice_hd_id and ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N' and ah.reversed_flag='N'
and ah.invoice_status='CONFIRM' and ah.invoice_status='CONFIRM'
and al.cf_item = 2 and al.cf_item = 2
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period} AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'),0) amount_tax, and ah.invoice_status = 'CONFIRM'),0) amount_tax,
'首付款' times, '首付款' times,
(select ccc.due_date from con_contract_cashflow ccc where ccc.contract_id=h.source_id (select ccc.due_date from con_contract_cashflow ccc where ccc.contract_id=h.source_id
and ccc.cf_item=2) due_date, and ccc.cf_item=2) due_date,
(select ccc.due_amount from con_contract_cashflow ccc where ccc.contract_id=h.source_id (select ccc.due_amount from con_contract_cashflow ccc where ccc.contract_id=h.source_id
and ccc.cf_item=2) due_amount, and ccc.cf_item=2) due_amount,
(select ccc.due_amount from con_contract_cashflow ccc where ccc.contract_id=h.source_id (select ccc.due_amount from con_contract_cashflow ccc where ccc.contract_id=h.source_id
and ccc.cf_item=2) principal, and ccc.cf_item=2) principal,
null interest, null interest,
l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where ah.contract_id=h.source_id l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where ah.contract_id=h.source_id
and ah.invoice_hd_id=al.invoice_hd_id and ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N' and ah.reversed_flag='N'
and ah.invoice_status='CONFIRM' and ah.invoice_status='CONFIRM'
and al.cf_item = 2 and al.cf_item = 2
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period} AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND ah.vat_interface_status = 'BACK' AND ah.vat_interface_status = 'BACK'
and ah.invoice_status = 'CONFIRM'),0) vat_due_amount, and ah.invoice_status = 'CONFIRM'),0) vat_due_amount,
(select (select
case when nvl(ccc.due_amount-ccc.vat_due_amount,0)<>0 then case when nvl(ccc.due_amount-ccc.vat_due_amount,0)<>0 then
round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2) round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2)
else else
null null
end end
from con_contract_cashflow ccc where ccc.contract_id=h.source_id from con_contract_cashflow ccc where ccc.contract_id=h.source_id
and ccc.cf_item=2) vat_rate, and ccc.cf_item=2) vat_rate,
h.je_transaction_code, h.je_transaction_code,
l.cashflow_id, l.cashflow_id,
'N' fixed_data_flag 'N' fixed_data_flag
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
WHERE h.journal_header_id = l.journal_header_id WHERE h.journal_header_id = l.journal_header_id
and h.sbo_num is not null and h.sbo_num is not null
and h.total_amount_dr!=0 and h.total_amount_dr!=0
and ga.account_id=l.account_id and ga.account_id=l.account_id
and ga.account_code in('2221001020','2221001023') and ga.account_code in('2221001020','2221001023','2221001024')
and h.reversed_flag='N' and h.reversed_flag='N'
and h.internal_period_num<to_number(${@base_period}) and h.internal_period_num<to_number(${@base_period})
AND (h.je_transaction_code= 'LEASE_INCEPT') AND (h.je_transaction_code= 'LEASE_INCEPT')
and exists (select 1 and exists (select 1
from gld_je_template_hds hd from gld_je_template_hds hd
where hd.je_template_hd_id = where hd.je_template_hd_id =
h.je_template_hd_id h.je_template_hd_id
and hd.je_template_code = and hd.je_template_code =
'HL_INCEPT_DOWN_PAYMENT_CF') 'HL_INCEPT_DOWN_PAYMENT_CF')
AND not EXISTS (SELECT 1 AND not EXISTS (SELECT 1
FROM acr_invoice_hd hi, acr_invoice_ln li FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.vat_interface_status = 'BACK' AND hi.vat_interface_status = 'BACK'
and hi.invoice_status='CONFIRM' and hi.invoice_status='CONFIRM'
AND to_char(hi.invoice_date,'yyyymm') < ${@base_period} AND to_char(hi.invoice_date,'yyyymm') < ${@base_period}
AND hi.contract_id=h.source_id AND hi.contract_id=h.source_id
and li.cf_item=2 ) and li.cf_item=2 )
union union
SELECT h.period_year, SELECT h.period_year,
h.period_num, h.period_num,
h.internal_period_num, h.internal_period_num,
h.journal_date, h.journal_date,
h.sbo_num journal_num, h.sbo_num journal_num,
reference3 contract_number, reference3 contract_number,
reference1 bp_code, reference1 bp_code,
(SELECT BP_NAME (SELECT BP_NAME
FROM hls_bp_master FROM hls_bp_master
WHERE bp_code = reference1 WHERE bp_code = reference1
AND ROWNUM = 1) bp_name, AND ROWNUM = 1) bp_name,
l.journal_header_id, l.journal_header_id,
(SELECT hi.invoice_date (SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N' AND hi.reversed_flag = 'N'
AND (li.cashflow_id = l.cashflow_id OR AND (li.cashflow_id = l.cashflow_id OR
li.ref_n03 = l.journal_header_id) li.ref_n03 = l.journal_header_id)
AND ROWNUM = 1) invoice_date, AND ROWNUM = 1) invoice_date,
l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where
ah.invoice_hd_id=al.invoice_hd_id ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N' and ah.reversed_flag='N'
and al.cashflow_id=l.cashflow_id and al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period} AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'),0) amount_tax, and ah.invoice_status = 'CONFIRM'),0) amount_tax,
(select decode(ccc.cf_item, (select decode(ccc.cf_item,
8, 8,
'留购价', '留购价',
to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times, to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times,
(select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date, (select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date,
(select case (select case
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
nvl(ccc.interest, 0) - nvl(ccc.interest, 0) -
nvl((select sum(al.tax_amount) nvl((select sum(al.tax_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period} AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) 0)
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' then when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' then
ccc.due_amount - ccc.due_amount -
nvl((select sum(al.total_amount) nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period} AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) 0)
else else
ccc.due_amount - ccc.due_amount -
nvl((select sum(al.total_amount) nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period} AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) 0)
end end
from con_contract cc, con_contract_cashflow ccc from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id where ccc.cashflow_id = l.cashflow_id
and ccc.contract_id = cc.contract_id) due_amount, and ccc.contract_id = cc.contract_id) due_amount,
(select case (select case
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
0 0
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_amount) nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period} ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) > nvl(ccc.interest,0) then 0) > nvl(ccc.interest,0) then
ccc.due_amount-nvl((select sum(al.total_amount) ccc.due_amount-nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period} ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) 0)
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_amount) nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period} ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) <=nvl(ccc.interest,0) then 0) <=nvl(ccc.interest,0) then
nvl(ccc.principal, 0) nvl(ccc.principal, 0)
else else
ccc.principal ccc.principal
end end
from con_contract cc, con_contract_cashflow ccc from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id where ccc.cashflow_id = l.cashflow_id
and ccc.contract_id = cc.contract_id) principal, and ccc.contract_id = cc.contract_id) principal,
(select case (select case
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
nvl(ccc.interest, 0) - nvl(ccc.interest, 0) -
nvl((select sum(al.tax_amount) nvl((select sum(al.tax_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period} AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) 0)
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_amount) nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period} ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) >nvl(ccc.interest,0) then 0) >nvl(ccc.interest,0) then
0 0
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_amount) nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period} ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) <= nvl(ccc.interest,0) then 0) <= nvl(ccc.interest,0) then
nvl(ccc.interest, 0)-nvl((select sum(al.total_amount) nvl(ccc.interest, 0)-nvl((select sum(al.total_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.invoice_hd_id = al.invoice_hd_id where ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.cashflow_id = l.cashflow_id and al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period} ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0) 0)
else else
ccc.due_amount ccc.due_amount
end end
from con_contract cc, con_contract_cashflow ccc from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id where ccc.cashflow_id = l.cashflow_id
and ccc.contract_id = cc.contract_id) interest, and ccc.contract_id = cc.contract_id) interest,
l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where
ah.invoice_hd_id=al.invoice_hd_id ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N' and ah.reversed_flag='N'
and al.cashflow_id=l.cashflow_id and al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period} AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
and ah.invoice_status = 'CONFIRM'),0) vat_due_amount, and ah.invoice_status = 'CONFIRM'),0) vat_due_amount,
(select (select
case when ccc.cf_item=1 and cc.business_type='LEASEBACK' and nvl(ccc.interest-ccc.vat_interest,0) !=0 then case when ccc.cf_item=1 and cc.business_type='LEASEBACK' and nvl(ccc.interest-ccc.vat_interest,0) !=0 then
round(ccc.vat_interest/(ccc.interest-ccc.vat_interest),2) round(ccc.vat_interest/(ccc.interest-ccc.vat_interest),2)
when ((ccc.cf_item=1 and cc.business_type!='LEASEBACK') or ccc.cf_item!=1 ) and nvl(ccc.due_amount-ccc.vat_due_amount,0) !=0 then when ((ccc.cf_item=1 and cc.business_type!='LEASEBACK') or ccc.cf_item!=1 ) and nvl(ccc.due_amount-ccc.vat_due_amount,0) !=0 then
round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2) round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2)
else else
null null
end end
from from
con_contract cc,con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id con_contract cc,con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id
and cc.contract_id=ccc.contract_id) vat_rate, and cc.contract_id=ccc.contract_id) vat_rate,
h.je_transaction_code, h.je_transaction_code,
l.cashflow_id, l.cashflow_id,
'N' fixed_data_flag 'N' fixed_data_flag
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
WHERE h.journal_header_id = l.journal_header_id WHERE h.journal_header_id = l.journal_header_id
and h.sbo_num is not null and h.sbo_num is not null
and h.total_amount_dr!=0 and h.total_amount_dr!=0
and ga.account_id=l.account_id and ga.account_id=l.account_id
and ga.account_code in('2221001020','2221001023') and ga.account_code in('2221001020','2221001023','2221001024')
and h.reversed_flag='N' and h.reversed_flag='N'
and h.internal_period_num<to_number(${@base_period}) and h.internal_period_num<to_number(${@base_period})
AND (h.je_transaction_code= 'HL_SALES_TAX_ACT_NEW') AND (h.je_transaction_code= 'HL_SALES_TAX_ACT_NEW')
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( (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 AND ( not EXISTS (SELECT 1
FROM acr_invoice_hd hi, acr_invoice_ln li FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.vat_interface_status = 'BACK' AND hi.vat_interface_status = 'BACK'
and hi.invoice_status='CONFIRM' and hi.invoice_status='CONFIRM'
AND to_char(hi.invoice_date,'yyyymm') < ${@base_period} AND to_char(hi.invoice_date,'yyyymm') < ${@base_period}
and li.cashflow_id=l.cashflow_id ) and li.cashflow_id=l.cashflow_id )
or or
--日立返还金额外判断 --日立返还金额外判断
exists( SELECT 1 exists( SELECT 1
FROM con_contract_cashflow ccc FROM con_contract_cashflow ccc
WHERE WHERE
ccc.cashflow_id=l.cashflow_id ccc.cashflow_id=l.cashflow_id
and ccc.cf_item=1 and ccc.cf_item=1
and acr_invoice_pkg.check_rl_flag(ccc.contract_id) = 'Y' and and acr_invoice_pkg.check_rl_flag(ccc.contract_id) = 'Y' and
acr_invoice_pkg.get_rl_amount(ccc.contract_id, acr_invoice_pkg.get_rl_amount(ccc.contract_id,
1, 1,
ccc.times) > 0 ccc.times) > 0
)) ))
union union
SELECT h.period_year, SELECT h.period_year,
h.period_num, h.period_num,
h.internal_period_num, h.internal_period_num,
h.journal_date, h.journal_date,
h.sbo_num journal_num, h.sbo_num journal_num,
reference3 contract_number, reference3 contract_number,
reference1 bp_code, reference1 bp_code,
(SELECT BP_NAME (SELECT BP_NAME
FROM hls_bp_master FROM hls_bp_master
WHERE bp_code = reference1 WHERE bp_code = reference1
AND ROWNUM = 1) bp_name, AND ROWNUM = 1) bp_name,
l.journal_header_id, l.journal_header_id,
(SELECT hi.invoice_date (SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N' AND hi.reversed_flag = 'N'
AND (li.cashflow_id = l.cashflow_id OR AND (li.cashflow_id = l.cashflow_id OR
li.ref_n03 = l.journal_header_id) li.ref_n03 = l.journal_header_id)
AND ROWNUM = 1) invoice_date, AND ROWNUM = 1) invoice_date,
round(l.amount_cr - round(l.amount_cr -
nvl((select sum(al.tax_amount) nvl((select sum(al.tax_amount)
from acr_invoice_hd ah, acr_invoice_ln al from acr_invoice_hd ah, acr_invoice_ln al
where ah.contract_id = h.source_id where ah.contract_id = h.source_id
and ah.invoice_hd_id = al.invoice_hd_id and ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N' and ah.reversed_flag = 'N'
and al.ref_n03 = l.journal_header_id and al.ref_n03 = l.journal_header_id
and al.ref_n04 = l.journal_line_id and al.ref_n04 = l.journal_line_id
and ah.invoice_kind in ('0', '2') and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period} AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'), and ah.invoice_status = 'CONFIRM'),
0),2) amount_tax, 0),2) amount_tax,
'违约金' times, '违约金' times,
h.journal_date due_date, h.journal_date due_date,
case when ghd.je_template_code in('HL_RECEIVABLES_AGENT_REPUR_LB','HL_RECEIVABLES_AGENT_REPUR','HL_GLD_BALANCE_PENALTY') then case when ghd.je_template_code in('HL_RECEIVABLES_AGENT_REPUR_LB','HL_RECEIVABLES_AGENT_REPUR','HL_GLD_BALANCE_PENALTY') then
(select d.amount_cr (select d.amount_cr
from hls_journal_detail d from hls_journal_detail d
where d.journal_header_id = h.journal_header_id where d.journal_header_id = h.journal_header_id
and exists and d.reference3=l.reference3
(select 1 and exists
from gld_accounts g (select 1
where g.account_id = d.account_id from gld_accounts g
and g.account_code in ('6041001000')) where g.account_id = d.account_id
and rownum = 1) and g.account_code in ('6041001000'))
else and rownum = 1)
(select d.amount_dr else
from hls_journal_detail d (select nvl(d.amount_dr,d.amount_cr)
where d.journal_header_id = h.journal_header_id from hls_journal_detail d
and exists where d.journal_header_id = h.journal_header_id
(select 1 and d.reference3=l.reference3
from gld_accounts g and exists
where g.account_id = d.account_id (select 1
and g.account_code in ('1122000001', '1122000002')) from gld_accounts g
and rownum = 1) where g.account_id = d.account_id
end due_amount, and g.account_code in ('1122000001', '1122000002'))
null principal, and rownum = 1)
case when ghd.je_template_code in('HL_RECEIVABLES_AGENT_REPUR_LB','HL_RECEIVABLES_AGENT_REPUR','HL_GLD_BALANCE_PENALTY') then end due_amount,
(select d.amount_cr null principal,
from hls_journal_detail d case when ghd.je_template_code in('HL_RECEIVABLES_AGENT_REPUR_LB','HL_RECEIVABLES_AGENT_REPUR','HL_GLD_BALANCE_PENALTY') then
where d.journal_header_id = h.journal_header_id (select d.amount_cr
and exists from hls_journal_detail d
(select 1 where d.journal_header_id = h.journal_header_id
from gld_accounts g and d.reference3=l.reference3
where g.account_id = d.account_id and exists
and g.account_code in ('6041001000')) (select 1
and rownum = 1) from gld_accounts g
else where g.account_id = d.account_id
(select d.amount_dr and g.account_code in ('6041001000'))
from hls_journal_detail d and rownum = 1)
where d.journal_header_id = h.journal_header_id else
and exists (select nvl(d.amount_dr,d.amount_cr)
(select 1 from hls_journal_detail d
from gld_accounts g where d.journal_header_id = h.journal_header_id
where g.account_id = d.account_id and d.reference3=l.reference3
and g.account_code in ('1122000001', '1122000002')) and exists
and rownum = 1) (select 1
end interest, from gld_accounts g
round(l.amount_cr - where g.account_id = d.account_id
nvl((select sum(al.tax_amount) and g.account_code in ('1122000001', '1122000002'))
from acr_invoice_hd ah, acr_invoice_ln al and rownum = 1)
where ah.contract_id = h.source_id end interest,
and ah.invoice_hd_id = al.invoice_hd_id round(l.amount_cr -
and ah.reversed_flag = 'N' nvl((select sum(al.tax_amount)
and al.ref_n03 = l.journal_header_id from acr_invoice_hd ah, acr_invoice_ln al
and al.ref_n04 = l.journal_line_id where ah.contract_id = h.source_id
and ah.invoice_kind in ('0', '2') and ah.invoice_hd_id = al.invoice_hd_id
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period} and ah.reversed_flag = 'N'
and ah.invoice_status = 'CONFIRM'), and al.ref_n03 = l.journal_header_id
0),2) vat_due_amount, and al.ref_n04 = l.journal_line_id
(select DECODE(CC.BUSINESS_TYPE, 'LEASEBACK', 0.06, 0.13) and ah.invoice_kind in ('0', '2')
from con_contract cc AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
WHERE cc.contract_number = l.reference3 and ah.invoice_status = 'CONFIRM'),
and cc.data_class = 'NORMAL') vat_rate, 0),2) vat_due_amount,
h.je_transaction_code, (select DECODE(CC.BUSINESS_TYPE, 'LEASEBACK', 0.06, 0.13)
l.cashflow_id, from con_contract cc
'N' fixed_data_flag WHERE cc.contract_number = l.reference3
FROM hls_journal_header h, hls_journal_detail l, gld_accounts ga,gld_je_template_hds ghd and cc.data_class = 'NORMAL') vat_rate,
WHERE h.journal_header_id = l.journal_header_id h.je_transaction_code,
and h.je_template_hd_id=ghd.je_template_hd_id l.cashflow_id,
and h.sbo_num is not null 'N' fixed_data_flag
and h.total_amount_dr != 0 FROM hls_journal_header h, hls_journal_detail l, gld_accounts ga,gld_je_template_hds ghd
and ga.account_id = l.account_id WHERE h.journal_header_id = l.journal_header_id
and ga.account_code in ('2221001020', '2221001023') and h.je_template_hd_id=ghd.je_template_hd_id
and h.reversed_flag = 'N' and h.sbo_num is not null
and h.internal_period_num < to_number(${@base_period}) and h.total_amount_dr != 0
And (h.je_transaction_code = and ga.account_id = l.account_id
'HL_CSH_CONSOLIDATION_DALAY' or and ga.account_code in ('2221001020', '2221001023','2221001024')
ghd.je_template_code in and h.reversed_flag = 'N'
('HL_GLD_BALANCE_REPURCHASE','HL_GLD_BALANCE_REPURCHASE_LB','HL_RECEIVABLES_AGENT_REPUR_LB','HL_RECEIVABLES_AGENT_REPUR','HL_GLD_BALANCE_PENALTY','HL_PENALTY_R_ET','HL_PENALTY_R_ET_LB') and h.internal_period_num < to_number(${@base_period})
) And (h.je_transaction_code =
and ((trunc(h.journal_date) <= 'HL_CSH_CONSOLIDATION_DALAY' or
trunc(to_date('2020-01-31', 'yyyy-mm-dd')) and ghd.je_template_code in
h.description = 'MANUAL_IMPORT') or ('HL_GLD_BALANCE_REPURCHASE','HL_GLD_BALANCE_REPURCHASE_LB','HL_RECEIVABLES_AGENT_REPUR_LB','HL_RECEIVABLES_AGENT_REPUR','HL_GLD_BALANCE_PENALTY','HL_PENALTY_R_ET','HL_PENALTY_R_ET_LB')
(trunc(h.journal_date) > trunc(to_date('2020-01-31', 'yyyy-mm-dd')))) )
AND not EXISTS and ((trunc(h.journal_date) <=
(SELECT 1 trunc(to_date('2020-01-31', 'yyyy-mm-dd')) and
FROM acr_invoice_hd hi, acr_invoice_ln li h.description = 'MANUAL_IMPORT') or
WHERE hi.invoice_hd_id = li.invoice_hd_id (trunc(h.journal_date) > trunc(to_date('2020-01-31', 'yyyy-mm-dd'))))
AND hi.vat_interface_status = 'BACK' AND not EXISTS
and hi.invoice_status = 'CONFIRM' (SELECT 1
AND to_char(hi.invoice_date, 'yyyymm') < =${@base_period} FROM acr_invoice_hd hi, acr_invoice_ln li
and li.ref_n03 = l.journal_header_id WHERE hi.invoice_hd_id = li.invoice_hd_id
and li.ref_n04 = l.journal_line_id) AND hi.vat_interface_status = 'BACK'
union and hi.invoice_status = 'CONFIRM'
SELECT h.period_year, AND to_char(hi.invoice_date, 'yyyymm') < =${@base_period}
h.period_num, and li.ref_n03 = l.journal_header_id
h.internal_period_num, and li.ref_n04 = l.journal_line_id)
h.journal_date, union
h.sbo_num journal_num, SELECT h.period_year,
reference3 contract_number, h.period_num,
reference1 bp_code, h.internal_period_num,
(SELECT BP_NAME h.journal_date,
FROM hls_bp_master h.sbo_num journal_num,
WHERE bp_code = reference1 reference3 contract_number,
AND ROWNUM = 1) bp_name, reference1 bp_code,
l.journal_header_id, (SELECT BP_NAME
(SELECT hi.invoice_date FROM hls_bp_master
FROM acr_invoice_hd hi, acr_invoice_ln li WHERE bp_code = reference1
WHERE hi.invoice_hd_id = li.invoice_hd_id AND ROWNUM = 1) bp_name,
AND hi.reversed_flag = 'N' l.journal_header_id,
AND (li.cashflow_id = l.cashflow_id OR (SELECT hi.invoice_date
li.ref_n03 = l.journal_header_id) FROM acr_invoice_hd hi, acr_invoice_ln li
AND ROWNUM = 1) invoice_date, WHERE hi.invoice_hd_id = li.invoice_hd_id
l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where AND hi.reversed_flag = 'N'
ah.invoice_hd_id=al.invoice_hd_id AND (li.cashflow_id = l.cashflow_id OR
and ah.reversed_flag='N' li.ref_n03 = l.journal_header_id)
and al.cashflow_id=l.cashflow_id AND ROWNUM = 1) invoice_date,
and ah.invoice_kind in ('0', '2') l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period} ah.invoice_hd_id=al.invoice_hd_id
and ah.invoice_status = 'CONFIRM'),0) amount_tax, and ah.reversed_flag='N'
(select decode(ccc.cf_item, and al.cashflow_id=l.cashflow_id
8, and ah.invoice_kind in ('0', '2')
'留购价', AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times, and ah.invoice_status = 'CONFIRM'),0) amount_tax,
(select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date, (select decode(ccc.cf_item,
(select 8,
case when ccc.cf_item=200 then '留购价',
ccc.due_amount-nvl((select sum(al.total_amount) from acr_invoice_hd ah,acr_invoice_ln al where to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times,
ah.invoice_hd_id=al.invoice_hd_id (select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date,
and ah.reversed_flag='N' (select
and al.cashflow_id=l.cashflow_id case when ccc.cf_item=200 then
and ah.invoice_kind in ('0', '2') ccc.due_amount-nvl((select sum(al.total_amount) from acr_invoice_hd ah,acr_invoice_ln al where
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period} ah.invoice_hd_id=al.invoice_hd_id
and ah.invoice_status = 'CONFIRM'),0) and ah.reversed_flag='N'
else and al.cashflow_id=l.cashflow_id
ccc.due_amount and ah.invoice_kind in ('0', '2')
end AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_amount, and ah.invoice_status = 'CONFIRM'),0)
(select case when ccc.cf_item=200 then else
ccc.due_amount-nvl((select sum(al.total_amount) from acr_invoice_hd ah,acr_invoice_ln al where ccc.due_amount
ah.invoice_hd_id=al.invoice_hd_id end
and ah.reversed_flag='N' from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_amount,
and al.cashflow_id=l.cashflow_id (select case when ccc.cf_item=200 then
and ah.invoice_kind in ('0', '2') ccc.due_amount-nvl((select sum(al.total_amount) from acr_invoice_hd ah,acr_invoice_ln al where
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period} ah.invoice_hd_id=al.invoice_hd_id
and ah.invoice_status = 'CONFIRM'),0) and ah.reversed_flag='N'
else and al.cashflow_id=l.cashflow_id
0 and ah.invoice_kind in ('0', '2')
end AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) principal, and ah.invoice_status = 'CONFIRM'),0)
(select decode(ccc.cf_item,'200',0,ccc.due_amount) else
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) interest, 0
l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where end
ah.invoice_hd_id=al.invoice_hd_id from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) principal,
and ah.reversed_flag='N' (select decode(ccc.cf_item,'200',0,ccc.due_amount)
and al.cashflow_id=l.cashflow_id from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) interest,
and ah.invoice_kind in ('0', '2') l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where
AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period} ah.invoice_hd_id=al.invoice_hd_id
and ah.invoice_status = 'CONFIRM'),0) vat_due_amount, and ah.reversed_flag='N'
(select and al.cashflow_id=l.cashflow_id
case when nvl(ccc.due_amount-ccc.vat_due_amount,0)!=0 then and ah.invoice_kind in ('0', '2')
round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2) AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period}
else and ah.invoice_status = 'CONFIRM'),0) vat_due_amount,
null (select
end case when nvl(ccc.due_amount-ccc.vat_due_amount,0)!=0 then
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) vat_rate, round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2)
h.je_transaction_code, else
l.cashflow_id, null
'N' fixed_data_flag end
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) vat_rate,
WHERE h.journal_header_id = l.journal_header_id h.je_transaction_code,
and h.sbo_num is not null l.cashflow_id,
and h.total_amount_dr!=0 'N' fixed_data_flag
and ga.account_id=l.account_id FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
and ga.account_code in('2221001020','2221001023') WHERE h.journal_header_id = l.journal_header_id
and h.reversed_flag='N' and h.sbo_num is not null
and h.internal_period_num<to_number(${@base_period}) and h.total_amount_dr!=0
And exists (selEct 1 and ga.account_id=l.account_id
from gld_je_template_hds hd and ga.account_code in('2221001020','2221001023','2221001024')
where hd.je_template_hd_id = and h.reversed_flag='N'
h.je_template_hd_id and h.internal_period_num<to_number(${@base_period})
and hd.je_template_code in And exists (selEct 1
('HL_CON_TAX_ET', from gld_je_template_hds hd
'HL_CON_TAX_ET_N', where hd.je_template_hd_id =
'HL_CON_FIN_ETFEE', h.je_template_hd_id
'HL_CON_FIN_ETFEE_N')) and hd.je_template_code in
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')))) ('HL_CON_TAX_ET',
AND ( not EXISTS (SELECT 1 'HL_CON_TAX_ET_N',
FROM acr_invoice_hd hi, acr_invoice_ln li 'HL_CON_FIN_ETFEE',
WHERE hi.invoice_hd_id = li.invoice_hd_id 'HL_CON_FIN_ETFEE_N'))
AND hi.vat_interface_status = 'BACK' 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 hi.invoice_status='CONFIRM' AND ( not EXISTS (SELECT 1
AND to_char(hi.invoice_date,'yyyymm') <= ${@base_period} FROM acr_invoice_hd hi, acr_invoice_ln li
and li.cashflow_id=l.cashflow_id ) WHERE hi.invoice_hd_id = li.invoice_hd_id
or AND hi.vat_interface_status = 'BACK'
--日立返还金额外判断 and hi.invoice_status='CONFIRM'
exists( SELECT 1 AND to_char(hi.invoice_date,'yyyymm') <= ${@base_period}
FROM con_contract_cashflow ccc and li.cashflow_id=l.cashflow_id )
WHERE or
ccc.cashflow_id=l.cashflow_id --日立返还金额外判断
and ccc.cf_item=200 exists( SELECT 1
and acr_invoice_pkg.check_rl_flag(ccc.contract_id) = 'Y' and FROM con_contract_cashflow ccc
acr_invoice_pkg.get_rl_amount(ccc.contract_id, WHERE
200, ccc.cashflow_id=l.cashflow_id
ccc.times) > 0 and ccc.cf_item=200
)) and acr_invoice_pkg.check_rl_flag(ccc.contract_id) = 'Y' and
union acr_invoice_pkg.get_rl_amount(ccc.contract_id,
SELECT h.period_year, 200,
h.period_num, ccc.times) > 0
h.internal_period_num, ))
h.journal_date, union
h.sbo_num journal_num, SELECT h.period_year,
reference3 contract_number, h.period_num,
reference1 bp_code, h.internal_period_num,
(SELECT BP_NAME h.journal_date,
FROM hls_bp_master h.sbo_num journal_num,
WHERE bp_code = reference1 reference3 contract_number,
AND ROWNUM = 1) bp_name, reference1 bp_code,
l.journal_header_id, (SELECT BP_NAME
(SELECT hi.invoice_date FROM hls_bp_master
FROM acr_invoice_hd hi, acr_invoice_ln li WHERE bp_code = reference1
WHERE hi.invoice_hd_id = li.invoice_hd_id AND ROWNUM = 1) bp_name,
AND hi.reversed_flag = 'N' l.journal_header_id,
AND (li.cashflow_id = l.cashflow_id OR (SELECT hi.invoice_date
li.ref_n03 = l.journal_header_id) FROM acr_invoice_hd hi, acr_invoice_ln li
AND ROWNUM = 1) invoice_date, WHERE hi.invoice_hd_id = li.invoice_hd_id
l.amount_cr amount_tax, AND hi.reversed_flag = 'N'
(select decode(ccc.cf_item, AND (li.cashflow_id = l.cashflow_id OR
8, li.ref_n03 = l.journal_header_id)
'留购价', AND ROWNUM = 1) invoice_date,
'解约回购利息/'||to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times, l.amount_cr amount_tax,
(select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date, (select decode(ccc.cf_item,
(select decode(ccc.cf_item, 8,
250, '留购价',
ccc.interest, '解约回购利息/'||to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times,
ccc.due_amount) (select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date,
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_amount, (select decode(ccc.cf_item,
null principal, 250,
(select decode(ccc.cf_item,250,ccc.interest,ccc.due_amount) ccc.interest,
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) interest, ccc.due_amount)
l.amount_cr vat_due_amount, from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_amount,
(select null principal,
case when ccc.cf_item=250 and nvl(ccc.interest-ccc.vat_interest,0)!=0 then (select decode(ccc.cf_item,250,ccc.interest,ccc.due_amount)
round(ccc.vat_interest/(ccc.interest-ccc.vat_interest),2) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) interest,
when ccc.cf_item!=250 and nvl(ccc.due_amount-ccc.vat_due_amount,0)!=0 then l.amount_cr vat_due_amount,
round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2) (select
else case when ccc.cf_item=250 and nvl(ccc.interest-ccc.vat_interest,0)!=0 then
null round(ccc.vat_interest/(ccc.interest-ccc.vat_interest),2)
end when ccc.cf_item!=250 and nvl(ccc.due_amount-ccc.vat_due_amount,0)!=0 then
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) vat_rate, round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2)
h.je_transaction_code, else
l.cashflow_id, null
'N' fixed_data_flag end
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) vat_rate,
WHERE h.journal_header_id = l.journal_header_id h.je_transaction_code,
and h.sbo_num is not null l.cashflow_id,
and h.total_amount_dr!=0 'N' fixed_data_flag
and ga.account_id=l.account_id FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
and ga.account_code in('2221001020','2221001023') WHERE h.journal_header_id = l.journal_header_id
and h.reversed_flag='N' and h.sbo_num is not null
and h.internal_period_num<to_number(${@base_period}) and h.total_amount_dr!=0
And exists (selEct 1 and ga.account_id=l.account_id
from gld_je_template_hds hd and ga.account_code in('2221001020','2221001023','2221001024')
where hd.je_template_hd_id = and h.reversed_flag='N'
h.je_template_hd_id and h.internal_period_num<to_number(${@base_period})
and hd.je_template_code in And exists (selEct 1
('HL_FIN_INCOME_REPURCHASE', from gld_je_template_hds hd
'HL_FIN_INCOME_REPURCHASE_N', where hd.je_template_hd_id =
'HL_FIN_INCOME_REPURCHASE_ET', h.je_template_hd_id
'HL_CON_FIN_ETREPUR_INT', and hd.je_template_code in
'HL_CON_FIN_ETREPUR_INT_N')) ('HL_FIN_INCOME_REPURCHASE',
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')))) 'HL_FIN_INCOME_REPURCHASE_N',
AND not EXISTS (SELECT 1 'HL_FIN_INCOME_REPURCHASE_ET',
FROM acr_invoice_hd hi, acr_invoice_ln li 'HL_CON_FIN_ETREPUR_INT',
WHERE hi.invoice_hd_id = li.invoice_hd_id 'HL_CON_FIN_ETREPUR_INT_N'))
AND hi.vat_interface_status = 'BACK' 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 hi.invoice_status='CONFIRM' AND not EXISTS (SELECT 1
AND to_char(hi.invoice_date,'yyyymm') < ${@base_period} FROM acr_invoice_hd hi, acr_invoice_ln li
and li.cashflow_id=l.cashflow_id ) WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.vat_interface_status = 'BACK'
union and hi.invoice_status='CONFIRM'
SELECT h.period_year, AND to_char(hi.invoice_date,'yyyymm') < ${@base_period}
h.period_num, and li.cashflow_id=l.cashflow_id )
h.internal_period_num,
h.journal_date, union
h.sbo_num journal_num, SELECT h.period_year,
t.contract_number, h.period_num,
(SELECT bp.bp_code h.internal_period_num,
FROM hls_bp_master bp, hls_journal_detail d h.journal_date,
WHERE bp.bp_code = d.reference1 h.sbo_num journal_num,
and d.journal_header_id = h.journal_header_id t.contract_number,
AND ROWNUM = 1) bp_code, (SELECT bp.bp_code
(SELECT bp.bp_name FROM hls_bp_master bp, hls_journal_detail d
FROM hls_bp_master bp, hls_journal_detail d WHERE bp.bp_code = d.reference1
WHERE bp.bp_code = d.reference1 and d.journal_header_id = h.journal_header_id
and d.journal_header_id = h.journal_header_id AND ROWNUM = 1) bp_code,
AND ROWNUM = 1) bp_name, (SELECT bp.bp_name
h.journal_header_id, FROM hls_bp_master bp, hls_journal_detail d
(SELECT hi.invoice_date WHERE bp.bp_code = d.reference1
FROM acr_invoice_hd hi, acr_invoice_ln li and d.journal_header_id = h.journal_header_id
WHERE hi.invoice_hd_id = li.invoice_hd_id AND ROWNUM = 1) bp_name,
AND hi.reversed_flag = 'N' h.journal_header_id,
AND (li.cashflow_id = t.cashflow_id OR (SELECT hi.invoice_date
li.ref_n03 = h.journal_header_id) FROM acr_invoice_hd hi, acr_invoice_ln li
AND ROWNUM = 1) invoice_date, WHERE hi.invoice_hd_id = li.invoice_hd_id
t.un_bill_vat_principal amount_tax, AND hi.reversed_flag = 'N'
'解约回购本金' || t.times times, AND (li.cashflow_id = t.cashflow_id OR
h.journal_date due_date, li.ref_n03 = h.journal_header_id)
t.un_bill_principal due_amount, AND ROWNUM = 1) invoice_date,
t.un_bill_principal principal, t.un_bill_vat_principal amount_tax,
null interest, '解约回购本金' || t.times times,
t.un_bill_vat_principal vat_due_amount, h.journal_date due_date,
t.tax_type_rate vat_rate, t.un_bill_principal due_amount,
h.je_transaction_code, t.un_bill_principal principal,
t.cashflow_id, null interest,
'N' fixed_data_flag t.un_bill_vat_principal vat_due_amount,
FROM hls_journal_header h, VAT_ACCOUNT_250_PRIN_TMP t t.tax_type_rate vat_rate,
WHERE h.journal_header_id = t.journal_header_id h.je_transaction_code,
and t.session_id=${/session/@session_id} t.cashflow_id,
and nvl(t.un_bill_principal,0)>0 'N' fixed_data_flag
and h.internal_period_num < to_number(${@base_period}) FROM hls_journal_header h, VAT_ACCOUNT_250_PRIN_TMP t
union WHERE h.journal_header_id = t.journal_header_id
SELECT h.period_year, and t.session_id=${/session/@session_id}
h.period_num, and nvl(t.un_bill_principal,0)>0
h.internal_period_num, and h.internal_period_num < to_number(${@base_period})
h.journal_date, union
h.sbo_num journal_num, SELECT h.period_year,
reference3 contract_number, h.period_num,
reference1 bp_code, h.internal_period_num,
(SELECT BP_NAME h.journal_date,
FROM hls_bp_master h.sbo_num journal_num,
WHERE bp_code = reference1 reference3 contract_number,
AND ROWNUM = 1) bp_name, reference1 bp_code,
l.journal_header_id, (SELECT BP_NAME
(SELECT hi.invoice_date FROM hls_bp_master
FROM acr_invoice_hd hi, acr_invoice_ln li WHERE bp_code = reference1
WHERE hi.invoice_hd_id = li.invoice_hd_id AND ROWNUM = 1) bp_name,
AND hi.reversed_flag = 'N' l.journal_header_id,
AND (li.cashflow_id = l.cashflow_id OR (SELECT hi.invoice_date
li.ref_n03 = l.journal_header_id) FROM acr_invoice_hd hi, acr_invoice_ln li
AND ROWNUM = 1) invoice_date, WHERE hi.invoice_hd_id = li.invoice_hd_id
l.amount_cr amount_tax, AND hi.reversed_flag = 'N'
'留购金' times, AND (li.cashflow_id = l.cashflow_id OR
h.journal_date due_date, li.ref_n03 = l.journal_header_id)
to_number(l.reference7) due_amount, AND ROWNUM = 1) invoice_date,
null principal, l.amount_cr amount_tax,
to_number(l.reference7) interest, '留购金' times,
l.amount_cr vat_due_amount, h.journal_date due_date,
case when nvl(l.reference7-abs(l.amount_cr),0)!=0 then to_number(l.reference7) due_amount,
round(abs(l.amount_cr/(l.reference7-abs(l.amount_cr))),2) null principal,
else to_number(l.reference7) interest,
null l.amount_cr vat_due_amount,
end case when nvl(l.reference7-abs(l.amount_cr),0)!=0 then
vat_rate, round(abs(l.amount_cr/(l.reference7-abs(l.amount_cr))),2)
h.je_transaction_code, else
l.cashflow_id, null
'N' fixed_data_flag end
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga vat_rate,
WHERE h.journal_header_id = l.journal_header_id h.je_transaction_code,
and h.sbo_num is not null l.cashflow_id,
and h.total_amount_dr!=0 'N' fixed_data_flag
and ga.account_id=l.account_id FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
and l.line_description like '%留购金%' WHERE h.journal_header_id = l.journal_header_id
and ga.account_code in('2221001020','2221001023') and h.sbo_num is not null
and h.reversed_flag='N' and h.total_amount_dr!=0
and h.internal_period_num<to_number(${@base_period}) and ga.account_id=l.account_id
And exists (selEct 1 and l.line_description like '%留购金%'
from gld_je_template_hds hd and ga.account_code in('2221001020','2221001023','2221001024')
where hd.je_template_hd_id = and h.reversed_flag='N'
h.je_template_hd_id and h.internal_period_num<to_number(${@base_period})
and hd.je_template_code in And exists (selEct 1
('HL_CON_CHANGE_REPURCHASE_VAT')) from gld_je_template_hds hd
where hd.je_template_hd_id =
AND EXISTS (SELECT 1 h.je_template_hd_id
FROM con_contract cc,con_contract_cashflow ccc and hd.je_template_code in
where cc.contract_number=l.reference3 ('HL_CON_CHANGE_REPURCHASE_VAT'))
and cc.data_class='NORMAL'
and cc.contract_id=ccc.contract_id AND EXISTS (SELECT 1
and ccc.cf_item=250 FROM con_contract cc,con_contract_cashflow ccc
and ccc.cf_status='RELEASE' where cc.contract_number=l.reference3
and ccc.cf_direction='INFLOW' and cc.data_class='NORMAL'
and ccc.billing_status!='FULL' ) and cc.contract_id=ccc.contract_id
union and ccc.cf_item=250
SELECT h.period_year, and ccc.cf_status='RELEASE'
h.period_num, and ccc.cf_direction='INFLOW'
h.internal_period_num, and ccc.billing_status!='FULL' )
h.journal_date, union
h.journal_num, SELECT h.period_year,
h.contract_number, h.period_num,
h.bp_code, h.internal_period_num,
(select bp.bp_name from hls_bp_master bp where bp.bp_code=h.bp_code) bp_name, h.journal_date,
null journal_header_id, h.journal_num,
h.invoice_date, h.contract_number,
h.amount_tax, h.bp_code,
h.times, (select bp.bp_name from hls_bp_master bp where bp.bp_code=h.bp_code) bp_name,
h.due_date, null journal_header_id,
h.due_amount, h.invoice_date,
h.principal, h.amount_tax,
h.interest, h.times,
h.vat_due_amount, h.due_date,
h.vat_rate, h.due_amount,
null je_transaction_code, h.principal,
null cashflow_id, h.interest,
'Y' fixed_data_flag h.vat_due_amount,
from hl_cm_rpt555_fixed_data h h.vat_rate,
union null je_transaction_code,
SELECT h.period_year, null cashflow_id,
h.period_num, 'Y' fixed_data_flag
h.internal_period_num, from hl_cm_rpt555_fixed_data h
h.journal_date, union
h.sbo_num journal_num, SELECT h.period_year,
reference3 contract_number, h.period_num,
reference1 bp_code, h.internal_period_num,
(SELECT BP_NAME h.journal_date,
FROM hls_bp_master h.sbo_num journal_num,
WHERE bp_code = reference1 reference3 contract_number,
AND ROWNUM = 1) bp_name, reference1 bp_code,
l.journal_header_id, (SELECT BP_NAME
(SELECT hi.invoice_date FROM hls_bp_master
FROM acr_invoice_hd hi, acr_invoice_ln li WHERE bp_code = reference1
WHERE hi.invoice_hd_id = li.invoice_hd_id AND ROWNUM = 1) bp_name,
AND hi.reversed_flag = 'N' l.journal_header_id,
AND (li.cashflow_id = l.cashflow_id OR (SELECT hi.invoice_date
li.ref_n03 = l.journal_header_id) FROM acr_invoice_hd hi, acr_invoice_ln li
AND ROWNUM = 1) invoice_date, WHERE hi.invoice_hd_id = li.invoice_hd_id
-1*abs(l.amount_cr) amount_tax, AND hi.reversed_flag = 'N'
(select decode(ccc.cf_item, AND (li.cashflow_id = l.cashflow_id OR
8, li.ref_n03 = l.journal_header_id)
'留购价', AND ROWNUM = 1) invoice_date,
to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times, -1*abs(l.amount_cr) amount_tax,
(select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date, (select decode(ccc.cf_item,
8,
-1* (select case '留购价',
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times,
nvl(ccc.interest, 0) (select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date,
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' then
ccc.due_amount -1* (select case
else when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
ccc.due_amount nvl(ccc.interest, 0)
end when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' then
from con_contract cc, con_contract_cashflow ccc ccc.due_amount
where ccc.cashflow_id = l.cashflow_id else
and ccc.contract_id = cc.contract_id) due_amount, ccc.due_amount
-1* (select case end
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then from con_contract cc, con_contract_cashflow ccc
0 where ccc.cashflow_id = l.cashflow_id
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' then and ccc.contract_id = cc.contract_id) due_amount,
nvl(ccc.principal,0) -1* (select case
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
else 0
ccc.principal when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' then
end nvl(ccc.principal,0)
from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id else
and ccc.contract_id = cc.contract_id) principal, ccc.principal
-1*(select case end
when ccc.cf_item = 1 then from con_contract cc, con_contract_cashflow ccc
nvl(ccc.interest, 0) where ccc.cashflow_id = l.cashflow_id
and ccc.contract_id = cc.contract_id) principal,
else -1*(select case
ccc.due_amount when ccc.cf_item = 1 then
end nvl(ccc.interest, 0)
from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id else
and ccc.contract_id = cc.contract_id) interest, ccc.due_amount
-1*abs(l.amount_cr) vat_due_amount, end
(select from con_contract cc, con_contract_cashflow ccc
case when ccc.cf_item=1 and cc.business_type='LEASEBACK' and nvl(ccc.interest-ccc.vat_interest,0) !=0 then where ccc.cashflow_id = l.cashflow_id
round(ccc.vat_interest/(ccc.interest-ccc.vat_interest),2) and ccc.contract_id = cc.contract_id) interest,
-1*abs(l.amount_cr) vat_due_amount,
when ((ccc.cf_item=1 and cc.business_type!='LEASEBACK') or ccc.cf_item!=1 ) and nvl(ccc.due_amount-ccc.vat_due_amount,0) !=0 then (select
round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2) case when ccc.cf_item=1 and cc.business_type='LEASEBACK' and nvl(ccc.interest-ccc.vat_interest,0) !=0 then
else round(ccc.vat_interest/(ccc.interest-ccc.vat_interest),2)
null
end when ((ccc.cf_item=1 and cc.business_type!='LEASEBACK') or ccc.cf_item!=1 ) and nvl(ccc.due_amount-ccc.vat_due_amount,0) !=0 then
from round(ccc.vat_due_amount/(ccc.due_amount-ccc.vat_due_amount),2)
con_contract cc,con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id else
and cc.contract_id=ccc.contract_id) vat_rate, null
h.je_transaction_code, end
l.cashflow_id, from
'Y' fixed_data_flag con_contract cc,con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga and cc.contract_id=ccc.contract_id) vat_rate,
WHERE h.journal_header_id = l.journal_header_id h.je_transaction_code,
and h.sbo_num is not null l.cashflow_id,
and h.total_amount_dr!=0 'Y' fixed_data_flag
and ga.account_id=l.account_id FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
and ga.account_code in('2221001020','2221001023') WHERE h.journal_header_id = l.journal_header_id
and h.reversed_flag='N' and h.sbo_num is not null
and h.internal_period_num <to_number(${@base_period}) and h.total_amount_dr!=0
and exists(select 1 from gld_je_template_hds hd and ga.account_id=l.account_id
where hd.je_template_hd_id=h.je_template_hd_id and ga.account_code in('2221001020','2221001023','2221001024')
and hd.je_template_code in and h.reversed_flag='N'
('HL_CON_VAT_REVERSE_REPURCHASE','HL_VAT_REVERSE_REPURCHASE_LB','HL_CON_VAT_REVERSE_ET','HL_CON_VAT_REVERSE_ET_LB','HL_REPURCHASE_VAT_REVERSE') and h.internal_period_num <to_number(${@base_period})
) and exists(select 1 from gld_je_template_hds hd
) t1 where hd.je_template_hd_id=h.je_template_hd_id
#WHERE_CLAUSE# and hd.je_template_code in
]]></bm:query-sql> ('HL_CON_VAT_REVERSE_REPURCHASE','HL_VAT_REVERSE_REPURCHASE_LB','HL_CON_VAT_REVERSE_ET','HL_CON_VAT_REVERSE_ET_LB','HL_REPURCHASE_VAT_REVERSE')
</bm:operation> )
</bm:operations> ) t1
<bm:data-filters> #WHERE_CLAUSE#
<bm:data-filter enforceOperations="query" expression="(t1.amount_tax > 0 or t1.fixed_data_flag='Y')"/> ]]></bm:query-sql>
<bm:data-filter enforceOperations="query" expression="(exists(select 1 from con_contract cc where cc.contract_number=t1.contract_number and cc.contract_status!='CANCEL' and cc.data_class='NORMAL') or t1.fixed_data_flag='Y')"/> </bm:operation>
</bm:data-filters> </bm:operations>
<bm:query-fields> <bm:data-filters>
<bm:query-field name="contract_number" queryExpression="t1.contract_number = ${@contract_number}"/> <bm:data-filter enforceOperations="query" expression="(t1.amount_tax > 0 or t1.fixed_data_flag='Y')"/>
<bm:query-field name="bp_name" queryExpression="t1.bp_name = ${@bp_name}"/> <bm:data-filter enforceOperations="query" expression="(exists(select 1 from con_contract cc where cc.contract_number=t1.contract_number and cc.contract_status!='CANCEL' and cc.data_class='NORMAL') or t1.fixed_data_flag='Y')"/>
<bm:query-field name="journal_date" queryExpression="to_char(t1.journal_date,'yyyy-mm-dd') = ${@journal_date}"/> </bm:data-filters>
<bm:query-field name="base_period" <bm:query-fields>
queryExpression="to_number(to_char(t1.journal_date,'yyyymm')) &lt; to_number(${@base_period})"/> <bm:query-field name="contract_number" queryExpression="t1.contract_number = ${@contract_number}"/>
<bm:query-field name="invoice_date" queryExpression="to_char(t1.invoice_date,'yyyy-mm-dd') = ${@invoice_date}"/> <bm:query-field name="bp_name" queryExpression="t1.bp_name = ${@bp_name}"/>
<bm:query-field name="vat_6_flag" queryExpression="((${@vat_6_flag}='Y' and t1.vat_rate=0.06) or (${@vat_6_flag}!='Y' and nvl(t1.vat_rate,0)!=0.06))"/> <bm:query-field name="journal_date" queryExpression="to_char(t1.journal_date,'yyyy-mm-dd') = ${@journal_date}"/>
</bm:query-fields> <bm:query-field name="base_period"
</bm:model> queryExpression="to_number(to_char(t1.journal_date,'yyyymm')) &lt; to_number(${@base_period})"/>
<bm:query-field name="invoice_date" queryExpression="to_char(t1.invoice_date,'yyyy-mm-dd') = ${@invoice_date}"/>
<bm:query-field name="vat_6_flag" queryExpression="((${@vat_6_flag}='Y' and t1.vat_rate=0.06) or (${@vat_6_flag}!='Y' and nvl(t1.vat_rate,0)!=0.06))"/>
</bm:query-fields>
</bm:model>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment