Commit 51bf8ca7 authored by 王炜's avatar 王炜

增值税台账-日立返还金调整

parent 49238652
...@@ -29,122 +29,430 @@ SELECT h.period_year, ...@@ -29,122 +29,430 @@ SELECT h.period_year,
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,
decode(reference6, NULL, 0, NVL(round(l.amount_cr,2),0)) amount_tax, 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
DECODE(h.je_transaction_code, and ah.invoice_hd_id=al.invoice_hd_id
'HL_CSH_CONSOLIDATION_DALAY', and ah.reversed_flag='N'
'违约金', and ah.invoice_status='CONFIRM'
'HL_SALES_TAX_ACT_NEW', and al.cf_item = 2
(SELECT DECODE(cf_item, and ah.invoice_kind in ('0', '2')
2, AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
'首付款', and ah.invoice_status = 'CONFIRM'),0) amount_tax,
'首付款' times,
(select ccc.due_date from con_contract_cashflow ccc where ccc.contract_id=h.source_id
and ccc.cf_item=2) due_date,
(select ccc.due_amount from con_contract_cashflow ccc where ccc.contract_id=h.source_id
and ccc.cf_item=2) due_amount,
(select ccc.due_amount from con_contract_cashflow ccc where ccc.contract_id=h.source_id
and ccc.cf_item=2) principal,
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
and ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N'
and ah.invoice_status='CONFIRM'
and al.cf_item = 2
AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period}
and ah.invoice_kind in ('0', '2')
AND ah.vat_interface_status = 'BACK'
and ah.invoice_status = 'CONFIRM'),0) vat_due_amount,
(select round(ccc.vat_due_amount/ccc.net_due_amount,2) from con_contract_cashflow ccc where ccc.contract_id=h.source_id
and ccc.cf_item=2) vat_rate,
h.je_transaction_code,
l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
WHERE h.journal_header_id = l.journal_header_id
and h.sbo_num is not null
and h.total_amount_dr!=0
and ga.account_id=l.account_id
and ga.account_code in('2221001020','2221001023')
and h.reversed_flag='N'
and h.internal_period_num=to_number(${@base_period})
AND (h.je_transaction_code= 'LEASE_INCEPT')
and exists (select 1
from gld_je_template_hds hd
where hd.je_template_hd_id =
h.je_template_hd_id
and hd.je_template_code =
'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'))))
union
SELECT h.period_year,
h.period_num,
h.internal_period_num,
h.journal_date,
h.sbo_num journal_num,
reference3 contract_number,
reference1 bp_code,
(SELECT BP_NAME
FROM hls_bp_master
WHERE bp_code = reference1
AND ROWNUM = 1) bp_name,
l.journal_header_id,
(SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N'
AND (li.cashflow_id = l.cashflow_id OR
li.ref_n03 = l.journal_header_id)
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
and ah.reversed_flag='N'
and al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
and ah.invoice_status = 'CONFIRM'),0) amount_tax,
(select decode(ccc.cf_item,
8, 8,
'留购价', '留购价',
1, to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times,
times, (select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date,
200,
'提前结清款', (select case
250, when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
'回购款', nvl(ccc.interest, 0) -
0, nvl((select sum(al.tax_amount)
'设备款') from acr_invoice_hd ah, acr_invoice_ln al
FROM con_contract_cashflow where ah.invoice_hd_id = al.invoice_hd_id
WHERE cashflow_id = l.cashflow_id), and ah.reversed_flag = 'N'
'CON_REPURCHASE', and al.cashflow_id = l.cashflow_id
'违约金') times, and ah.invoice_kind in ('0', '2')
DECODE(h.je_transaction_code, AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
'HL_CSH_CONSOLIDATION_DALAY', and ah.invoice_status = 'CONFIRM'),
h.journal_date, 0)
'HL_SALES_TAX_ACT_NEW', when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' then
(SELECT due_date ccc.due_amount -
FROM con_contract_cashflow nvl((select sum(al.total_amount)
WHERE cashflow_id = l.cashflow_id), from acr_invoice_hd ah, acr_invoice_ln al
'CON_REPURCHASE', where ah.invoice_hd_id = al.invoice_hd_id
h.journal_date) due_date, and ah.reversed_flag = 'N'
DECODE(h.je_transaction_code, and al.cashflow_id = l.cashflow_id
'HL_CSH_CONSOLIDATION_DALAY', and ah.invoice_kind in ('0', '2')
decode(reference6, NULL, l.amount_dr, 0), AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
'HL_SALES_TAX_ACT_NEW', and ah.invoice_status = 'CONFIRM'),
(SELECT due_amount 0)
FROM con_contract_cashflow else
WHERE cashflow_id = l.cashflow_id), ccc.due_amount -
decode(reference6, NULL, l.amount_dr, 0), nvl((select sum(al.total_amount)
'CON_REPURCHASE', from acr_invoice_hd ah, acr_invoice_ln al
decode(reference6, NULL, l.amount_dr, 0)) due_amount, where ah.invoice_hd_id = al.invoice_hd_id
(SELECT principal and ah.reversed_flag = 'N'
FROM con_contract_cashflow and al.cashflow_id = l.cashflow_id
WHERE cashflow_id = l.cashflow_id) principal, and ah.invoice_kind in ('0', '2')
DECODE(h.je_transaction_code, AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
'HL_CSH_CONSOLIDATION_DALAY', and ah.invoice_status = 'CONFIRM'),
decode(reference6, NULL, l.amount_dr, 0), 0)
'HL_SALES_TAX_ACT_NEW', end
(SELECT decode(cf_item, 8, due_amount, interest) from con_contract cc, con_contract_cashflow ccc
FROM con_contract_cashflow where ccc.cashflow_id = l.cashflow_id
WHERE cashflow_id = l.cashflow_id), and ccc.contract_id = cc.contract_id) due_amount,
'CON_REPURCHASE', (select case
decode(reference6, NULL, l.amount_dr, 0) when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
) interest, 0
DECODE(h.je_transaction_code, when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
'HL_CSH_CONSOLIDATION_DALAY', nvl((select sum(al.total_amount)
decode(reference6, NULL, 0, NVL(l.amount_cr,0)), from acr_invoice_hd ah, acr_invoice_ln al
'HL_SALES_TAX_ACT_NEW', where ah.invoice_hd_id = al.invoice_hd_id
(SELECT vat_due_amount and ah.reversed_flag = 'N'
FROM con_contract_cashflow and al.cashflow_id = l.cashflow_id
WHERE cashflow_id = l.cashflow_id), and ah.invoice_kind in ('0', '2')
'CON_REPURCHASE', AND to_char(ah.invoice_date, 'yyyymm') <=
decode(reference6, NULL, 0, NVL(l.amount_cr,0))) vat_due_amount, ${@base_period}
nvl(ROUND((DECODE(h.je_transaction_code, and ah.invoice_status = 'CONFIRM'),
'HL_CSH_CONSOLIDATION_DALAY', 0) > nvl(ccc.interest,0) then
l.amount_cr/(l.reference7-l.amount_cr), ccc.due_amount-nvl((select sum(al.total_amount)
'HL_SALES_TAX_ACT_NEW', from acr_invoice_hd ah, acr_invoice_ln al
(SELECT vat_due_amount/(due_amount-vat_due_amount) where ah.invoice_hd_id = al.invoice_hd_id
FROM con_contract_cashflow and ah.reversed_flag = 'N'
WHERE cashflow_id = l.cashflow_id), and al.cashflow_id = l.cashflow_id
l.amount_cr/(l.reference7-l.amount_cr), and ah.invoice_kind in ('0', '2')
'CON_REPURCHASE', AND to_char(ah.invoice_date, 'yyyymm') <=
l.amount_cr/(l.reference7-l.amount_cr))),2) * 100,0)|| '%' vat_rate, ${@base_period}
and ah.invoice_status = 'CONFIRM'),
0)
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period}
and ah.invoice_status = 'CONFIRM'),
0) <=nvl(ccc.interest,0) then
nvl(ccc.principal, 0)
else
ccc.principal
end
from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id
and ccc.contract_id = cc.contract_id) principal,
(select case
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
nvl(ccc.interest, 0) -
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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'),
0)
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period}
and ah.invoice_status = 'CONFIRM'),
0) >nvl(ccc.interest,0) then
0
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period}
and ah.invoice_status = 'CONFIRM'),
0) <= nvl(ccc.interest,0) then
nvl(ccc.interest, 0)-nvl((select sum(al.total_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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period}
and ah.invoice_status = 'CONFIRM'),
0)
else
ccc.due_amount
end
from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id
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
ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N'
and al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'),0) vat_due_amount,
(select
DECODE( ccc.cf_item,1,
decode(cc.business_type,'LEASEBACK',
round(ccc.vat_interest/ccc.net_interest,2),
round(ccc.vat_due_amount/ccc.net_due_amount,2)), round(ccc.vat_due_amount/ccc.net_due_amount,2))
from
con_contract cc,con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id
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 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')
and h.reversed_flag='N' and h.reversed_flag='N'
AND ((h.je_transaction_code IN and h.internal_period_num=to_number(${@base_period})
('HL_SALES_TAX_ACT_NEW', 'HL_CSH_CONSOLIDATION_DALAY') AND (h.je_transaction_code= 'HL_SALES_TAX_ACT_NEW')
)or(h.je_transaction_code = 'CON_REPURCHASE' and
instr(h.description, '调平') > 0))
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 union
SELECT h.period_year,
h.period_num,
h.internal_period_num,
h.journal_date,
h.sbo_num journal_num,
reference3 contract_number,
reference1 bp_code,
(SELECT BP_NAME
FROM hls_bp_master
WHERE bp_code = reference1
AND ROWNUM = 1) bp_name,
l.journal_header_id,
(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.vat_interface_status = 'BACK' AND hi.reversed_flag = 'N'
AND to_char(hi.invoice_date,'yyyymm') <= ${@base_period}
AND (li.cashflow_id = l.cashflow_id OR AND (li.cashflow_id = l.cashflow_id OR
li.ref_n04 = l.journal_line_id)) li.ref_n03 = l.journal_header_id)
UNION AND ROWNUM = 1) invoice_date,
select vl.* round(l.amount_cr -
from ET_VAT_JOURNAL_LV vl nvl((select sum(al.tax_amount)
where not EXISTS from acr_invoice_hd ah, acr_invoice_ln al
(SELECT 1 where ah.contract_id = h.source_id
and ah.invoice_hd_id = al.invoice_hd_id
and ah.reversed_flag = 'N'
and al.ref_n03 = l.journal_header_id
and al.ref_n04 = l.journal_line_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') < =${@base_period}
and ah.invoice_status = 'CONFIRM'),
0),2) amount_tax,
'违约金' times,
h.journal_date due_date,
(select d.amount_dr
from hls_journal_detail d
where d.journal_header_id = h.journal_header_id
and exists
(select 1
from gld_accounts g
where g.account_id = d.account_id
and g.account_code in ('1122000001', '1122000002'))
and rownum = 1) due_amount,
null principal,
(select d.amount_dr
from hls_journal_detail d
where d.journal_header_id = h.journal_header_id
and exists
(select 1
from gld_accounts g
where g.account_id = d.account_id
and g.account_code in ('1122000001', '1122000002'))
and rownum = 1) interest,
round(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.reversed_flag = 'N'
and al.ref_n03 = l.journal_header_id
and al.ref_n04 = l.journal_line_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') < =${@base_period}
and ah.invoice_status = 'CONFIRM'),
0),2) vat_due_amount,
(select DECODE(CC.BUSINESS_TYPE, 'LEASEBACK', 0.06, 0.13)
from con_contract cc
WHERE cc.contract_number = l.reference3
and cc.data_class = 'NORMAL') vat_rate,
h.je_transaction_code,
l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l, gld_accounts ga
WHERE h.journal_header_id = l.journal_header_id
and h.sbo_num is not null
and h.total_amount_dr != 0
and ga.account_id = l.account_id
and ga.account_code in ('2221001020', '2221001023')
and h.reversed_flag = 'N'
and h.internal_period_num = to_number(${@base_period})
And (h.je_transaction_code =
'HL_CSH_CONSOLIDATION_DALAY' or
(h.je_transaction_code =
'CON_REPURCHASE' and exists
(select 1
from gld_je_template_hds ga
where ga.je_template_hd_id =
h.je_template_hd_id
and ga.je_template_code =
'HL_GLD_BALANCE_REPURCHASE')))
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 to_char(hi.invoice_date, 'yyyymm') <= ${@base_period} and hi.invoice_status = 'CONFIRM'
AND (li.cashflow_id = vl.cashflow_id)) AND to_char(hi.invoice_date, 'yyyymm') < =${@base_period}
UNION and li.ref_n03 = l.journal_header_id
select rl.* and li.ref_n04 = l.journal_line_id)
from REPURSE_VAT_JOURNAL_LV rl union
where not EXISTS SELECT h.period_year,
(SELECT 1 h.period_num,
h.internal_period_num,
h.journal_date,
h.sbo_num journal_num,
reference3 contract_number,
reference1 bp_code,
(SELECT BP_NAME
FROM hls_bp_master
WHERE bp_code = reference1
AND ROWNUM = 1) bp_name,
l.journal_header_id,
(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.vat_interface_status = 'BACK' AND hi.reversed_flag = 'N'
AND to_char(hi.invoice_date, 'yyyymm') <= ${@base_period} AND (li.cashflow_id = l.cashflow_id OR
AND (li.cashflow_id = rl.cashflow_id)) li.ref_n03 = l.journal_header_id)
AND ROWNUM = 1) invoice_date,
UNION 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 al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
and ah.invoice_status = 'CONFIRM'),0) amount_tax,
(select decode(ccc.cf_item,
8,
'留购价',
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
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
ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N'
and al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
and ah.invoice_status = 'CONFIRM'),0)
else
ccc.due_amount
end
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_amount,
(select 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
ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N'
and al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
and ah.invoice_status = 'CONFIRM'),0)
else
0
end
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) principal,
(select decode(ccc.cf_item,'200',0,ccc.due_amount)
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) interest,
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 al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'),0) vat_due_amount,
(select
round(ccc.vat_due_amount/ccc.net_due_amount,2)
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) vat_rate,
h.je_transaction_code,
l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
WHERE h.journal_header_id = l.journal_header_id
and h.sbo_num is not null
and h.total_amount_dr!=0
and ga.account_id=l.account_id
and ga.account_code in('2221001020','2221001023')
and h.reversed_flag='N'
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
and hd.je_template_code in
('HL_CON_TAX_ET',
'HL_CON_TAX_ET_N',
'HL_CON_FIN_ETFEE',
'HL_CON_FIN_ETFEE_N'))
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
SELECT h.period_year, SELECT h.period_year,
h.period_num, h.period_num,
h.internal_period_num, h.internal_period_num,
...@@ -161,81 +469,219 @@ SELECT h.period_year, ...@@ -161,81 +469,219 @@ SELECT h.period_year,
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 hi.vat_interface_status = 'BACK' AND (li.cashflow_id = l.cashflow_id OR
AND li.cf_item = 2 li.ref_n03 = l.journal_header_id)
and hi.contract_id = l.source_doc_id
AND ROWNUM = 1) invoice_date, AND ROWNUM = 1) invoice_date,
round(l.amount_dr,2) amount_tax, l.amount_cr amount_tax,
'首付款' times, (select decode(ccc.cf_item,
8,
(SELECT due_date '留购价',
FROM con_contract_cashflow '解约回购利息/'||to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times,
WHERE contract_id = l.source_doc_id (select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date,
AND cf_item = 2 (select decode(ccc.cf_item,
AND ROWNUM = 1) due_date, 250,
ccc.interest,
(SELECT due_amount ccc.due_amount)
FROM con_contract_cashflow from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_amount,
WHERE contract_id = l.source_doc_id null principal,
AND cf_item = 2 (select decode(ccc.cf_item,250,ccc.interest,ccc.due_amount)
AND ROWNUM = 1) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) interest,
due_amount, l.amount_cr vat_due_amount,
(select
(SELECT due_amount decode(ccc.cf_item,250,round(ccc.vat_interest/ccc.net_interest,2),
FROM con_contract_cashflow round(ccc.vat_due_amount/ccc.net_due_amount,2))
WHERE contract_id = l.source_doc_id from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) vat_rate,
AND cf_item = 2
AND ROWNUM = 1) principal,
(SELECT interest
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1) interest,
(SELECT vat_due_amount
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1) vat_due_amount,
NVL(ROUND(
(SELECT vat_due_amount/net_due_amount
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1),
2) * 100,
0) || '%' vat_rate,
h.je_transaction_code, h.je_transaction_code,
l.cashflow_id l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l 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 ga.account_id=l.account_id
and ga.account_code in('2221001020','2221001023')
and h.reversed_flag='N' and h.reversed_flag='N'
AND h.je_transaction_code = 'LEASE_INCEPT' and h.internal_period_num=to_number(${@base_period})
AND l.je_template_ln_id = 8797 AND not EXISTS (SELECT 1
and( (trunc(h.journal_date)<=trunc(to_date('2020-01-31','yyyy-mm-dd')) and h.description='MANUAL_IMPORT')or(trunc(h.journal_date)>trunc(to_date('2020-01-31','yyyy-mm-dd'))))
AND not EXISTS
(SELECT 1
FROM acr_invoice_hd hi, acr_invoice_ln li 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 to_char(hi.invoice_date,'yyyymm') <= ${@base_period} and hi.invoice_status='CONFIRM'
AND ((hi.contract_id = l.source_doc_id AND li.cf_item IN (2)))) AND to_char(hi.invoice_date,'yyyymm') < =${@base_period}
and li.cashflow_id=l.cashflow_id )
And exists (selEct 1
from gld_je_template_hds hd
where hd.je_template_hd_id =
h.je_template_hd_id
and hd.je_template_code in
('HL_FIN_INCOME_REPURCHASE',
'HL_FIN_INCOME_REPURCHASE_N'))
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
SELECT h.period_year,
h.period_num,
h.internal_period_num,
h.journal_date,
h.sbo_num journal_num,
reference3 contract_number,
reference1 bp_code,
(SELECT BP_NAME
FROM hls_bp_master
WHERE bp_code = reference1
AND ROWNUM = 1) bp_name,
l.journal_header_id,
(SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N'
AND (li.cashflow_id = l.cashflow_id OR
li.ref_n03 = l.journal_header_id)
AND ROWNUM = 1) invoice_date,
nvl((select sum(ccc.vat_principal) FROM con_contract cc,con_contract_cashflow ccc
where cc.contract_number=l.reference3
and cc.data_class='NORMAL'
and ccc.cf_item=250
and ccc.contract_id=cc.contract_id
and ccc.cf_status='RELEASE'
and ccc.cf_direction='INFLOW'
and ccc.billing_status!='FULL'
),0) amount_tax,
'解约回购本金' times,
h.journal_date due_date,
nvl((select sum(ccc.principal) FROM con_contract cc,con_contract_cashflow ccc
where cc.contract_number=l.reference3
and cc.data_class='NORMAL'
and ccc.contract_id=cc.contract_id
and ccc.cf_item=250
and ccc.cf_status='RELEASE'
and ccc.cf_direction='INFLOW'
),0) due_amount,
nvl((select sum(ccc.principal) FROM con_contract cc,con_contract_cashflow ccc
where cc.contract_number=l.reference3
and cc.data_class='NORMAL'
and ccc.contract_id=cc.contract_id
and ccc.cf_item=250
and ccc.cf_status='RELEASE'
and ccc.cf_direction='INFLOW'
),0) principal,
null interest,
nvl((select sum(ccc.vat_principal) FROM con_contract cc,con_contract_cashflow ccc
where cc.contract_number=l.reference3
and cc.data_class='NORMAL'
and ccc.cf_item=250
and ccc.contract_id=cc.contract_id
and ccc.cf_status='RELEASE'
and ccc.cf_direction='INFLOW'
and ccc.billing_status!='FULL'
),0) vat_due_amount,
(select round(ccc.vat_principal/ccc.net_principal,2)
FROM con_contract cc,con_contract_cashflow ccc
where cc.contract_number=l.reference3
and cc.data_class='NORMAL'
and ccc.cf_item=250
and ccc.cf_status='RELEASE'
and ccc.cf_direction='INFLOW'
and ccc.billing_status='FULL'
and ccc.principal>0
and rownum=1
) vat_rate,
h.je_transaction_code,
l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
WHERE h.journal_header_id = l.journal_header_id
and h.sbo_num is not null
and h.total_amount_dr!=0
and ga.account_id=l.account_id
and l.line_description like '%本金%'
and ga.account_code in('2221001020','2221001023')
and h.reversed_flag='N'
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
and hd.je_template_code in
('HL_CON_CHANGE_REPURCHASE_VAT'))
AND EXISTS (SELECT 1
FROM con_contract cc,con_contract_cashflow ccc
where cc.contract_number=l.reference3
and cc.data_class='NORMAL'
and ccc.cf_item=250
and cc.contract_id=ccc.contract_id
and ccc.cf_status='RELEASE'
and ccc.cf_direction='INFLOW'
and ccc.billing_status!='FULL' )
union
SELECT h.period_year,
h.period_num,
h.internal_period_num,
h.journal_date,
h.sbo_num journal_num,
reference3 contract_number,
reference1 bp_code,
(SELECT BP_NAME
FROM hls_bp_master
WHERE bp_code = reference1
AND ROWNUM = 1) bp_name,
l.journal_header_id,
(SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N'
AND (li.cashflow_id = l.cashflow_id OR
li.ref_n03 = l.journal_header_id)
AND ROWNUM = 1) invoice_date,
l.amount_cr amount_tax,
'留购金' times,
h.journal_date due_date,
to_number(l.reference7) due_amount,
null principal,
to_number(l.reference7) interest,
l.amount_cr vat_due_amount,
round( l.amount_cr/(l.reference7-l.amount_cr),2) vat_rate,
h.je_transaction_code,
l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
WHERE h.journal_header_id = l.journal_header_id
and h.sbo_num is not null
and h.total_amount_dr!=0
and ga.account_id=l.account_id
and l.line_description like '%留购金%'
and ga.account_code in('2221001020','2221001023')
and h.reversed_flag='N'
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
and hd.je_template_code in
('HL_CON_CHANGE_REPURCHASE_VAT'))
AND EXISTS (SELECT 1
FROM con_contract cc,con_contract_cashflow ccc
where cc.contract_number=l.reference3
and cc.data_class='NORMAL'
and cc.contract_id=ccc.contract_id
and ccc.cf_item=250
and ccc.cf_status='RELEASE'
and ccc.cf_direction='INFLOW'
and ccc.billing_status!='FULL' )
) t1 ) t1
#WHERE_CLAUSE# #WHERE_CLAUSE#
]]></bm:query-sql> ]]></bm:query-sql>
</bm:operation> </bm:operation>
</bm:operations> </bm:operations>
<bm:data-filters> <bm:data-filters>
<bm:data-filter enforceOperations="query" expression="to_char(t1.journal_date,'yyyymm') = ${@base_period}"/> <bm:data-filter enforceOperations="query" expression="t1.amount_tax &lt;&gt;0"/>
<bm:data-filter enforceOperations="query" expression="t1.amount_tax > 0"/> <bm:data-filter enforceOperations="query" expression="exists(select 1 from con_contract cc where cc.contract_number=t1.contract_number and cc.data_class='NORMAL')"/>
</bm:data-filters> </bm:data-filters>
<bm:query-fields> <bm:query-fields>
<bm:query-field name="contract_number" queryExpression="t1.contract_number = ${@contract_number}"/> <bm:query-field name="contract_number" queryExpression="t1.contract_number = ${@contract_number}"/>
<bm:query-field name="bp_name" queryExpression="t1.bp_name = ${@bp_name}"/> <bm:query-field name="bp_name" queryExpression="t1.bp_name = ${@bp_name}"/>
<bm:query-field name="journal_date" queryExpression="to_char(t1.journal_date,'yyyy-mm-dd') = ${@journal_date}"/> <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="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:query-fields>
</bm:model> </bm:model>
...@@ -29,122 +29,372 @@ SELECT h.period_year, ...@@ -29,122 +29,372 @@ SELECT h.period_year,
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,
decode(reference6, NULL, 0, NVL(round(l.amount_cr,2),0)) amount_tax, 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
DECODE(h.je_transaction_code, and ah.invoice_hd_id=al.invoice_hd_id
'HL_CSH_CONSOLIDATION_DALAY', and ah.reversed_flag='N'
'违约金', and ah.invoice_status='CONFIRM'
'HL_SALES_TAX_ACT_NEW', and al.cf_item = 2
(SELECT DECODE(cf_item, and ah.invoice_kind in ('0', '2')
2, AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period}
'首付款', and ah.invoice_status = 'CONFIRM'),0) amount_tax,
8, '首付款' times,
'留购价', (select ccc.due_date from con_contract_cashflow ccc where ccc.contract_id=h.source_id
1, and ccc.cf_item=2) due_date,
times, (select ccc.due_amount from con_contract_cashflow ccc where ccc.contract_id=h.source_id
200, and ccc.cf_item=2) due_amount,
'提前结清款', (select ccc.due_amount from con_contract_cashflow ccc where ccc.contract_id=h.source_id
250, and ccc.cf_item=2) principal,
'回购款', null interest,
0, 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
FROM con_contract_cashflow and ah.reversed_flag='N'
WHERE cashflow_id = l.cashflow_id), and ah.invoice_status='CONFIRM'
'CON_REPURCHASE', and al.cf_item = 2
'违约金') times, AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
DECODE(h.je_transaction_code, and ah.invoice_kind in ('0', '2')
'HL_CSH_CONSOLIDATION_DALAY', AND ah.vat_interface_status = 'BACK'
h.journal_date, and ah.invoice_status = 'CONFIRM'),0) vat_due_amount,
'HL_SALES_TAX_ACT_NEW', (select round(ccc.vat_due_amount/ccc.net_due_amount,2) from con_contract_cashflow ccc where ccc.contract_id=h.source_id
(SELECT due_date and ccc.cf_item=2) vat_rate,
FROM con_contract_cashflow
WHERE cashflow_id = l.cashflow_id),
'CON_REPURCHASE',
h.journal_date) due_date,
DECODE(h.je_transaction_code,
'HL_CSH_CONSOLIDATION_DALAY',
decode(reference6, NULL, l.amount_dr, 0),
'HL_SALES_TAX_ACT_NEW',
(SELECT due_amount
FROM con_contract_cashflow
WHERE cashflow_id = l.cashflow_id),
decode(reference6, NULL, l.amount_dr, 0),
'CON_REPURCHASE',
decode(reference6, NULL, l.amount_dr, 0)) due_amount,
(SELECT principal
FROM con_contract_cashflow
WHERE cashflow_id = l.cashflow_id) principal,
DECODE(h.je_transaction_code,
'HL_CSH_CONSOLIDATION_DALAY',
decode(reference6, NULL, l.amount_dr, 0),
'HL_SALES_TAX_ACT_NEW',
(SELECT decode(cf_item, 8, due_amount, interest)
FROM con_contract_cashflow
WHERE cashflow_id = l.cashflow_id),
'CON_REPURCHASE',
decode(reference6, NULL, l.amount_dr, 0)
) interest,
DECODE(h.je_transaction_code,
'HL_CSH_CONSOLIDATION_DALAY',
decode(reference6, NULL, 0, NVL(l.amount_cr,0)),
'HL_SALES_TAX_ACT_NEW',
(SELECT vat_due_amount
FROM con_contract_cashflow
WHERE cashflow_id = l.cashflow_id),
'CON_REPURCHASE',
decode(reference6, NULL, 0, NVL(l.amount_cr,0))) vat_due_amount,
nvl(ROUND((DECODE(h.je_transaction_code,
'HL_CSH_CONSOLIDATION_DALAY',
l.amount_cr/(l.reference7-l.amount_cr),
'HL_SALES_TAX_ACT_NEW',
(SELECT vat_due_amount/(due_amount-vat_due_amount)
FROM con_contract_cashflow
WHERE cashflow_id = l.cashflow_id),
l.amount_cr/(l.reference7-l.amount_cr),
'CON_REPURCHASE',
l.amount_cr/(l.reference7-l.amount_cr))),2) * 100,0)|| '%' 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 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')
and h.reversed_flag='N' and h.reversed_flag='N'
AND ((h.je_transaction_code IN and h.internal_period_num<to_number(${@base_period})
('HL_SALES_TAX_ACT_NEW', 'HL_CSH_CONSOLIDATION_DALAY') AND (h.je_transaction_code= 'LEASE_INCEPT')
)or(h.je_transaction_code = 'CON_REPURCHASE' and and exists (select 1
instr(h.description, '调平') > 0)) from gld_je_template_hds hd
where hd.je_template_hd_id =
h.je_template_hd_id
and hd.je_template_code =
'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'))))
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 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 li.cf_item=2 )
union
SELECT h.period_year,
h.period_num,
h.internal_period_num,
h.journal_date,
h.sbo_num journal_num,
reference3 contract_number,
reference1 bp_code,
(SELECT BP_NAME
FROM hls_bp_master
WHERE bp_code = reference1
AND ROWNUM = 1) bp_name,
l.journal_header_id,
(SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N'
AND (li.cashflow_id = l.cashflow_id OR AND (li.cashflow_id = l.cashflow_id OR
li.ref_n04 = l.journal_line_id)) li.ref_n03 = l.journal_header_id)
UNION AND ROWNUM = 1) invoice_date,
select vl.* l.amount_cr-nvl((select sum(al.tax_amount) from acr_invoice_hd ah,acr_invoice_ln al where
from ET_VAT_JOURNAL_LV vl ah.invoice_hd_id=al.invoice_hd_id
where not EXISTS and ah.reversed_flag='N'
(SELECT 1 and al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'),0) amount_tax,
(select decode(ccc.cf_item,
8,
'留购价',
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 case
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
nvl(ccc.interest, 0) -
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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'),
0)
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' then
ccc.due_amount -
nvl((select sum(al.total_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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'),
0)
else
ccc.due_amount -
nvl((select sum(al.total_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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'),
0)
end
from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id
and ccc.contract_id = cc.contract_id) due_amount,
(select case
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
0
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period}
and ah.invoice_status = 'CONFIRM'),
0) > nvl(ccc.interest,0) then
ccc.due_amount-nvl((select sum(al.total_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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period}
and ah.invoice_status = 'CONFIRM'),
0)
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period}
and ah.invoice_status = 'CONFIRM'),
0) <=nvl(ccc.interest,0) then
nvl(ccc.principal, 0)
else
ccc.principal
end
from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id
and ccc.contract_id = cc.contract_id) principal,
(select case
when ccc.cf_item = 1 and cc.business_type = 'LEASEBACK' then
nvl(ccc.interest, 0) -
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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'),
0)
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period}
and ah.invoice_status = 'CONFIRM'),
0) >nvl(ccc.interest,0) then
0
when ccc.cf_item = 1 and cc.business_type != 'LEASEBACK' and
nvl((select sum(al.total_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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period}
and ah.invoice_status = 'CONFIRM'),
0) <= nvl(ccc.interest,0) then
nvl(ccc.interest, 0)-nvl((select sum(al.total_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 al.cashflow_id = l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <=
${@base_period}
and ah.invoice_status = 'CONFIRM'),
0)
else
ccc.due_amount
end
from con_contract cc, con_contract_cashflow ccc
where ccc.cashflow_id = l.cashflow_id
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
ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N'
and al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
and ah.invoice_status = 'CONFIRM'),0) vat_due_amount,
(select
DECODE( ccc.cf_item,1,
decode(cc.business_type,'LEASEBACK',
round(ccc.vat_interest/ccc.net_interest,2),
round(ccc.vat_due_amount/ccc.net_due_amount,2)), round(ccc.vat_due_amount/ccc.net_due_amount,2))
from
con_contract cc,con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id
and cc.contract_id=ccc.contract_id) vat_rate,
h.je_transaction_code,
l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
WHERE h.journal_header_id = l.journal_header_id
and h.sbo_num is not null
and h.total_amount_dr!=0
and ga.account_id=l.account_id
and ga.account_code in('2221001020','2221001023')
and h.reversed_flag='N'
and h.internal_period_num<to_number(${@base_period})
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 ( 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 to_char(hi.invoice_date, 'yyyymm') < ${@base_period} and hi.invoice_status='CONFIRM'
AND (li.cashflow_id = vl.cashflow_id)) AND to_char(hi.invoice_date,'yyyymm') < ${@base_period}
UNION and li.cashflow_id=l.cashflow_id )
select rl.* or
from REPURSE_VAT_JOURNAL_LV rl --日立返还金额外判断
where not EXISTS exists( SELECT 1
FROM con_contract_cashflow ccc
WHERE
ccc.cashflow_id=l.cashflow_id
and ccc.cf_item=1
and acr_invoice_pkg.check_rl_flag(ccc.contract_id) = 'Y' and
acr_invoice_pkg.get_rl_amount(ccc.contract_id,
1,
ccc.times) > 0
))
union
SELECT h.period_year,
h.period_num,
h.internal_period_num,
h.journal_date,
h.sbo_num journal_num,
reference3 contract_number,
reference1 bp_code,
(SELECT BP_NAME
FROM hls_bp_master
WHERE bp_code = reference1
AND ROWNUM = 1) bp_name,
l.journal_header_id,
(SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N'
AND (li.cashflow_id = l.cashflow_id OR
li.ref_n03 = l.journal_header_id)
AND ROWNUM = 1) invoice_date,
round(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.reversed_flag = 'N'
and al.ref_n03 = l.journal_header_id
and al.ref_n04 = l.journal_line_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'),
0),2) amount_tax,
'违约金' times,
h.journal_date due_date,
(select d.amount_dr
from hls_journal_detail d
where d.journal_header_id = h.journal_header_id
and exists
(select 1
from gld_accounts g
where g.account_id = d.account_id
and g.account_code in ('1122000001', '1122000002'))
and rownum = 1) due_amount,
null principal,
(select d.amount_dr
from hls_journal_detail d
where d.journal_header_id = h.journal_header_id
and exists
(select 1
from gld_accounts g
where g.account_id = d.account_id
and g.account_code in ('1122000001', '1122000002'))
and rownum = 1) interest,
round(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.reversed_flag = 'N'
and al.ref_n03 = l.journal_header_id
and al.ref_n04 = l.journal_line_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date, 'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'),
0),2) vat_due_amount,
(select DECODE(CC.BUSINESS_TYPE, 'LEASEBACK', 0.06, 0.13)
from con_contract cc
WHERE cc.contract_number = l.reference3
and cc.data_class = 'NORMAL') vat_rate,
h.je_transaction_code,
l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l, gld_accounts ga
WHERE h.journal_header_id = l.journal_header_id
and h.sbo_num is not null
and h.total_amount_dr != 0
and ga.account_id = l.account_id
and ga.account_code in ('2221001020', '2221001023')
and h.reversed_flag = 'N'
and h.internal_period_num < to_number(${@base_period})
And (h.je_transaction_code =
'HL_CSH_CONSOLIDATION_DALAY' or
(h.je_transaction_code =
'CON_REPURCHASE' and exists
(select 1
from gld_je_template_hds ga
where ga.je_template_hd_id =
h.je_template_hd_id
and ga.je_template_code =
'HL_GLD_BALANCE_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'))))
AND not EXISTS
(SELECT 1 (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 to_char(hi.invoice_date, 'yyyymm') < ${@base_period} AND to_char(hi.invoice_date, 'yyyymm') < ${@base_period}
AND (li.cashflow_id = rl.cashflow_id)) and li.ref_n03 = l.journal_header_id
and li.ref_n04 = l.journal_line_id)
UNION union
SELECT h.period_year, SELECT h.period_year,
h.period_num, h.period_num,
h.internal_period_num, h.internal_period_num,
...@@ -161,76 +411,320 @@ SELECT h.period_year, ...@@ -161,76 +411,320 @@ SELECT h.period_year,
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
li.ref_n03 = l.journal_header_id)
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
and ah.reversed_flag='N'
and al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
and ah.invoice_status = 'CONFIRM'),0) amount_tax,
(select decode(ccc.cf_item,
8,
'留购价',
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
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
ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N'
and al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
and ah.invoice_status = 'CONFIRM'),0)
else
ccc.due_amount
end
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_amount,
(select 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
ah.invoice_hd_id=al.invoice_hd_id
and ah.reversed_flag='N'
and al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') < =${@base_period}
and ah.invoice_status = 'CONFIRM'),0)
else
0
end
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) principal,
(select decode(ccc.cf_item,'200',0,ccc.due_amount)
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) interest,
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 al.cashflow_id=l.cashflow_id
and ah.invoice_kind in ('0', '2')
AND to_char(ah.invoice_date,'yyyymm') <= ${@base_period}
and ah.invoice_status = 'CONFIRM'),0) vat_due_amount,
(select
round(ccc.vat_due_amount/ccc.net_due_amount,2)
from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) vat_rate,
h.je_transaction_code,
l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
WHERE h.journal_header_id = l.journal_header_id
and h.sbo_num is not null
and h.total_amount_dr!=0
and ga.account_id=l.account_id
and ga.account_code in('2221001020','2221001023')
and h.reversed_flag='N'
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
and hd.je_template_code in
('HL_CON_TAX_ET',
'HL_CON_TAX_ET_N',
'HL_CON_FIN_ETFEE',
'HL_CON_FIN_ETFEE_N'))
and( (trunc(h.journal_date)<=trunc(to_date('2020-01-31','yyyy-mm-dd')) and h.description='MANUAL_IMPORT')or(trunc(h.journal_date)>trunc(to_date('2020-01-31','yyyy-mm-dd'))))
AND ( not EXISTS (SELECT 1
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.vat_interface_status = 'BACK' AND hi.vat_interface_status = 'BACK'
AND li.cf_item = 2 and hi.invoice_status='CONFIRM'
and hi.contract_id = l.source_doc_id AND to_char(hi.invoice_date,'yyyymm') < ${@base_period}
and li.cashflow_id=l.cashflow_id )
or
--日立返还金额外判断
exists( SELECT 1
FROM con_contract_cashflow ccc
WHERE
ccc.cashflow_id=l.cashflow_id
and ccc.cf_item=200
and acr_invoice_pkg.check_rl_flag(ccc.contract_id) = 'Y' and
acr_invoice_pkg.get_rl_amount(ccc.contract_id,
200,
ccc.times) > 0
))
union
SELECT h.period_year,
h.period_num,
h.internal_period_num,
h.journal_date,
h.sbo_num journal_num,
reference3 contract_number,
reference1 bp_code,
(SELECT BP_NAME
FROM hls_bp_master
WHERE bp_code = reference1
AND ROWNUM = 1) bp_name,
l.journal_header_id,
(SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N'
AND (li.cashflow_id = l.cashflow_id OR
li.ref_n03 = l.journal_header_id)
AND ROWNUM = 1) invoice_date, AND ROWNUM = 1) invoice_date,
round(l.amount_dr,2) amount_tax, l.amount_cr amount_tax,
'首付款' times, (select decode(ccc.cf_item,
8,
(SELECT due_date '留购价',
FROM con_contract_cashflow '解约回购利息/'||to_char(ccc.times)) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) times,
WHERE contract_id = l.source_doc_id (select ccc.due_date from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_date,
AND cf_item = 2 (select decode(ccc.cf_item,
AND ROWNUM = 1) due_date, 250,
ccc.interest,
(SELECT due_amount ccc.due_amount)
FROM con_contract_cashflow from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) due_amount,
WHERE contract_id = l.source_doc_id null principal,
AND cf_item = 2 (select decode(ccc.cf_item,250,ccc.interest,ccc.due_amount)
AND ROWNUM = 1) from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) interest,
due_amount, l.amount_cr vat_due_amount,
(select
(SELECT due_amount decode(ccc.cf_item,250,round(ccc.vat_interest/ccc.net_interest,2),
FROM con_contract_cashflow round(ccc.vat_due_amount/ccc.net_due_amount,2))
WHERE contract_id = l.source_doc_id from con_contract_cashflow ccc where ccc.cashflow_id=l.cashflow_id) vat_rate,
AND cf_item = 2
AND ROWNUM = 1) principal,
(SELECT interest
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1) interest,
(SELECT vat_due_amount
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1) vat_due_amount,
NVL(ROUND(
(SELECT vat_due_amount/net_due_amount
FROM con_contract_cashflow
WHERE contract_id = l.source_doc_id
AND cf_item = 2
AND ROWNUM = 1),
2) * 100,
0) || '%' vat_rate,
h.je_transaction_code, h.je_transaction_code,
l.cashflow_id l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l 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 ga.account_id=l.account_id
and ga.account_code in('2221001020','2221001023')
and h.reversed_flag='N' and h.reversed_flag='N'
AND h.je_transaction_code = 'LEASE_INCEPT' and h.internal_period_num<to_number(${@base_period})
AND l.je_template_ln_id = 8797 And exists (selEct 1
from gld_je_template_hds hd
where hd.je_template_hd_id =
h.je_template_hd_id
and hd.je_template_code in
('HL_FIN_INCOME_REPURCHASE',
'HL_FIN_INCOME_REPURCHASE_N'))
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 AND not EXISTS (SELECT 1
(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 to_char(hi.invoice_date,'yyyymm') < ${@base_period} AND to_char(hi.invoice_date,'yyyymm') < ${@base_period}
AND ((hi.contract_id = l.source_doc_id AND li.cf_item IN (2)))) and li.cashflow_id=l.cashflow_id )
union
SELECT h.period_year,
h.period_num,
h.internal_period_num,
h.journal_date,
h.sbo_num journal_num,
reference3 contract_number,
reference1 bp_code,
(SELECT BP_NAME
FROM hls_bp_master
WHERE bp_code = reference1
AND ROWNUM = 1) bp_name,
l.journal_header_id,
(SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N'
AND (li.cashflow_id = l.cashflow_id OR
li.ref_n03 = l.journal_header_id)
AND ROWNUM = 1) invoice_date,
nvl((select sum(ccc.vat_principal) FROM con_contract cc,con_contract_cashflow ccc
where cc.contract_number=l.reference3
and cc.data_class='NORMAL'
and ccc.cf_item=250
and ccc.contract_id=cc.contract_id
and ccc.cf_status='RELEASE'
and ccc.cf_direction='INFLOW'
and ccc.billing_status!='FULL'
),0) amount_tax,
'解约回购本金' times,
h.journal_date due_date,
nvl((select sum(ccc.principal) FROM con_contract cc,con_contract_cashflow ccc
where cc.contract_number=l.reference3
and cc.data_class='NORMAL'
and ccc.contract_id=cc.contract_id
and ccc.cf_item=250
and ccc.cf_status='RELEASE'
and ccc.cf_direction='INFLOW'
),0) due_amount,
nvl((select sum(ccc.principal) FROM con_contract cc,con_contract_cashflow ccc
where cc.contract_number=l.reference3
and cc.data_class='NORMAL'
and ccc.contract_id=cc.contract_id
and ccc.cf_item=250
and ccc.cf_status='RELEASE'
and ccc.cf_direction='INFLOW'
),0) principal,
null interest,
nvl((select sum(ccc.vat_principal) FROM con_contract cc,con_contract_cashflow ccc
where cc.contract_number=l.reference3
and cc.data_class='NORMAL'
and ccc.cf_item=250
and ccc.contract_id=cc.contract_id
and ccc.cf_status='RELEASE'
and ccc.cf_direction='INFLOW'
and ccc.billing_status!='FULL'
),0) vat_due_amount,
(select round(ccc.vat_principal/ccc.net_principal,2)
FROM con_contract cc,con_contract_cashflow ccc
where cc.contract_number=l.reference3
and cc.data_class='NORMAL'
and ccc.cf_item=250
and ccc.cf_status='RELEASE'
and ccc.cf_direction='INFLOW'
and ccc.billing_status='FULL'
and ccc.principal>0
and rownum=1
) vat_rate,
h.je_transaction_code,
l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
WHERE h.journal_header_id = l.journal_header_id
and h.sbo_num is not null
and h.total_amount_dr!=0
and ga.account_id=l.account_id
and l.line_description like '%本金%'
and ga.account_code in('2221001020','2221001023')
and h.reversed_flag='N'
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
and hd.je_template_code in
('HL_CON_CHANGE_REPURCHASE_VAT'))
AND EXISTS (SELECT 1
FROM con_contract cc,con_contract_cashflow ccc
where cc.contract_number=l.reference3
and cc.data_class='NORMAL'
and ccc.cf_item=250
and cc.contract_id=ccc.contract_id
and ccc.cf_status='RELEASE'
and ccc.cf_direction='INFLOW'
and ccc.billing_status!='FULL' )
union
SELECT h.period_year,
h.period_num,
h.internal_period_num,
h.journal_date,
h.sbo_num journal_num,
reference3 contract_number,
reference1 bp_code,
(SELECT BP_NAME
FROM hls_bp_master
WHERE bp_code = reference1
AND ROWNUM = 1) bp_name,
l.journal_header_id,
(SELECT hi.invoice_date
FROM acr_invoice_hd hi, acr_invoice_ln li
WHERE hi.invoice_hd_id = li.invoice_hd_id
AND hi.reversed_flag = 'N'
AND (li.cashflow_id = l.cashflow_id OR
li.ref_n03 = l.journal_header_id)
AND ROWNUM = 1) invoice_date,
l.amount_cr amount_tax,
'留购金' times,
h.journal_date due_date,
to_number(l.reference7) due_amount,
null principal,
to_number(l.reference7) interest,
l.amount_cr vat_due_amount,
round( l.amount_cr/(l.reference7-l.amount_cr),2) vat_rate,
h.je_transaction_code,
l.cashflow_id
FROM hls_journal_header h, hls_journal_detail l,gld_accounts ga
WHERE h.journal_header_id = l.journal_header_id
and h.sbo_num is not null
and h.total_amount_dr!=0
and ga.account_id=l.account_id
and l.line_description like '%留购金%'
and ga.account_code in('2221001020','2221001023')
and h.reversed_flag='N'
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
and hd.je_template_code in
('HL_CON_CHANGE_REPURCHASE_VAT'))
AND EXISTS (SELECT 1
FROM con_contract cc,con_contract_cashflow ccc
where cc.contract_number=l.reference3
and cc.data_class='NORMAL'
and cc.contract_id=ccc.contract_id
and ccc.cf_item=250
and ccc.cf_status='RELEASE'
and ccc.cf_direction='INFLOW'
and ccc.billing_status!='FULL' )
) t1 ) t1
#WHERE_CLAUSE# #WHERE_CLAUSE#
]]></bm:query-sql> ]]></bm:query-sql>
</bm:operation> </bm:operation>
</bm:operations> </bm:operations>
<bm:data-filters> <bm:data-filters>
<bm:data-filter enforceOperations="query"
expression="t1.journal_date &lt;= add_months(last_day(to_date(${@base_period},'yyyymm')),-1)"/>
<bm:data-filter enforceOperations="query" expression="t1.amount_tax > 0"/> <bm:data-filter enforceOperations="query" expression="t1.amount_tax > 0"/>
<bm:data-filter enforceOperations="query" expression="exists(select 1 from con_contract cc where cc.contract_number=t1.contract_number and cc.data_class='NORMAL')"/>
</bm:data-filters> </bm:data-filters>
<bm:query-fields> <bm:query-fields>
<bm:query-field name="contract_number" queryExpression="t1.contract_number = ${@contract_number}"/> <bm:query-field name="contract_number" queryExpression="t1.contract_number = ${@contract_number}"/>
...@@ -239,5 +733,6 @@ SELECT h.period_year, ...@@ -239,5 +733,6 @@ SELECT h.period_year,
<bm:query-field name="base_period" <bm:query-field name="base_period"
queryExpression="to_number(to_char(t1.journal_date,'yyyymm')) &lt; to_number(${@base_period})"/> 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="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:query-fields>
</bm:model> </bm:model>
...@@ -39,18 +39,20 @@ ...@@ -39,18 +39,20 @@
t.created_by, t.created_by,
t.creation_date, t.creation_date,
t.last_updated_by, t.last_updated_by,
t.last_update_date t.last_update_date,
t.tax_type_rate
FROM vat_account_tmp t FROM vat_account_tmp t
WHERE t.session_id=${/session/@session_id} WHERE t.session_id=${/session/@session_id}
) t1 ) t1
#WHERE_CLAUSE# #WHERE_CLAUSE#
order by invoice_hd_id,due_date ASC,invoice_number asc --order by invoice_hd_id,due_date ASC,invoice_line_id asc
order by invoice_hd_id, invoice_number asc, due_date ASC
]]></bm:query-sql> ]]></bm:query-sql>
</bm:operation> </bm:operation>
<bm:operation name="update"> <bm:operation name="update">
<bm:update-sql><![CDATA[ <bm:update-sql><![CDATA[
BEGIN BEGIN
acr_invoice_pkg.vat_account_data_process(p_base_period => ${@base_period}, hl_cm_vat_report_pkg.vat_account_data_process(p_base_period => ${@base_period},
p_session_id => ${/session/@session_id}, p_session_id => ${/session/@session_id},
p_user_id => ${/session/@user_id} ); p_user_id => ${/session/@user_id} );
END; END;
...@@ -58,14 +60,14 @@ ...@@ -58,14 +60,14 @@
</bm:operation> </bm:operation>
</bm:operations> </bm:operations>
<bm:data-filters> <bm:data-filters>
<!-- <bm:data-filter enforceOperations="query" expression="to_char(t1.invoice_date,'yyyymm') = ${@base_period}"/>--> <!-- <bm:data-filter enforceOperations="query" expression="to_char(t1.invoice_date,'yyyymm') = ${@base_period}"/>-->
</bm:data-filters> </bm:data-filters>
<bm:query-fields> <bm:query-fields>
<bm:query-field name="contract_number" queryExpression="t1.contract_number = ${@contract_number}"/> <bm:query-field name="contract_number" queryExpression="t1.contract_number = ${@contract_number}"/>
<bm:query-field name="bp_name" queryExpression="t1.bp_name = ${@bp_name}"/> <bm:query-field name="bp_name" queryExpression="t1.bp_name = ${@bp_name}"/>
<!-- <bm:query-field name="journal_date" queryExpression="to_char(t1.journal_date,'yyyy-mm-dd') = ${@journal_date}"/>--> <!-- <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="invoice_date" queryExpression="to_char(t1.invoice_date,'yyyy-mm-dd') = ${@invoice_date}"/>
<bm:query-field name="invoice_kind" queryExpression="t1.invoice_kind = ${@invoice_kind}"/> <bm:query-field name="invoice_kind" queryExpression="t1.invoice_kind = ${@invoice_kind}"/>
<bm:query-field name="vat_6_flag" queryExpression="((${@vat_6_flag}='Y' and t1.tax_type_rate=0.06) or(${@vat_6_flag}!='Y' and t1.tax_type_rate!=0.06))"/>
</bm:query-fields> </bm:query-fields>
</bm:model> </bm:model>
var override_queryfields = [
{
name: 'contract_number',
queryexpression: "t1.contract_number = ${@contract_number}"
},
{
name: 'bp_name',
queryexpression: "t1.bp_name = ${@bp_name}"
},
{
name: 'journal_date',
queryexpression: "to_char(t1.journal_date,'yyyy-mm-dd') = ${@journal_date}"
},
{
name: 'base_period',
queryexpression: "to_char(t1.journal_date,'yyyymm') < ${@base_period}"
}
];
var add_datafilters = [{
name: 'base_period',
expression: "t1.journal_date <= add_months(last_day(to_date(${@base_period},'yyyymm')),-1) and (t1.invoice_date is null or t1.invoice_date >= TRUNC(to_date(${@base_period},'yyyymm'),'dd'))"
}];
override();
add_datafilter();
\ No newline at end of file
var override_queryfields = [
{
name: 'contract_number',
queryexpression: "t1.contract_number = ${@contract_number}"
},
{
name: 'bp_name',
queryexpression: "t1.bp_name = ${@bp_name}"
},
{
name: 'journal_date',
queryexpression: "to_char(t1.journal_date,'yyyy-mm-dd') = ${@journal_date}"
},
{
name: 'base_period',
queryexpression: "to_char(t1.journal_date,'yyyymm') = ${@base_period}"
}
];
var add_datafilters = [{
name: 'base_period',
expression: " to_char(t1.journal_date,'yyyymm') = ${@base_period} and (t1.invoice_date is null or to_char(t1.invoice_date,'yyyymm') < ${@base_period})"
}];
override();
add_datafilter();
\ No newline at end of file
var override_queryfields = [
{
name: 'invoice_kind',
queryexpression: "t1.invoice_kind = ${@invoice_kind}"
},
{
name: 'contract_number',
queryexpression: "t1.contract_number = ${@contract_number}"
},
{
name: 'bp_name',
queryexpression: "t1.bp_name = ${@bp_name}"
},
{
name: 'journal_date',
queryexpression: "to_char(t1.je_date,'yyyy-mm-dd') = ${@journal_date}"
},
{
name: 'invoice_date',
queryexpression: "to_char(t1.invoice_date,'yyyy-mm-dd') = ${@invoice_date}"
},
{
name: 'base_period',
queryexpression: "to_char(t1.je_date,'yyyymm') <= ${@base_period}"
}
];
var add_datafilters = [{
name: 'base_period',
expression: "to_char(t1.invoice_date,'yyyymm') = ${@base_period}"
}];
override();
add_datafilter();
\ No newline at end of file
...@@ -15,19 +15,33 @@ ...@@ -15,19 +15,33 @@
//查询数据 //查询数据
window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() { window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
var form_ds_id = '${/parameter/@layout_code}_F_QUERY__ds'; var form_ds_id = '${/parameter/@layout_code}_F_QUERY__ds';
//var grid_ds_id_before = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_BEFORE_RESULT', 'con_contract');
// var grid_ds_id_current = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_CURRENT_RESULT', 'con_contract');
var grid_ds_id_total = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_SUM_RESULT', 'con_contract');
var grid_vat_6_ds_id_total = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_SUM_RESULT_6', 'con_contract');
var grid_ds_id_before = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_BEFORE_RESULT', 'con_contract'); var grid_ds_id_before = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_BEFORE_RESULT', 'con_contract');
var grid_ds_id_before_6 = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_BEFORE_RESULT_6', 'con_contract');
var grid_ds_id_current = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_CURRENT_RESULT', 'con_contract'); var grid_ds_id_current = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_CURRENT_RESULT', 'con_contract');
var grid_ds_id_total = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_SUM_RESULT', 'con_contract'); var grid_ds_id_current_6 = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'G_CURRENT_RESULT_6', 'con_contract');
$(grid_ds_id_before).setQueryUrl('${/request/@context_path}/autocrud/rpt.RPT555.con_je_vat_query/query');
$(grid_ds_id_current).setQueryUrl('${/request/@context_path}/autocrud/rpt.RPT555.con_je_vat_current_query/query'); $(grid_ds_id_before).setQueryUrl('${/request/@context_path}/autocrud/rpt.RPT555.con_je_vat_query/query?vat_6_flag=N');
$(grid_ds_id_before_6).setQueryUrl('${/request/@context_path}/autocrud/rpt.RPT555.con_je_vat_query/query?vat_6_flag=Y');
$(grid_ds_id_current).setQueryUrl('${/request/@context_path}/autocrud/rpt.RPT555.con_je_vat_current_query/query?vat_6_flag=N');
$(grid_ds_id_current_6).setQueryUrl('${/request/@context_path}/autocrud/rpt.RPT555.con_je_vat_current_query/query?vat_6_flag=Y');
//先进行数据的处理 //先进行数据的处理
$(grid_ds_id_total).setQueryUrl('${/request/@context_path}/autocrud/rpt.RPT555.con_je_vat_total_query/query'); $(grid_ds_id_total).setQueryUrl('${/request/@context_path}/autocrud/rpt.RPT555.con_je_vat_total_query/query?vat_6_flag=N');
$(grid_vat_6_ds_id_total).setQueryUrl('${/request/@context_path}/autocrud/rpt.RPT555.con_je_vat_total_query/query?vat_6_flag=Y');
var detail_mask = Ext.getBody(); var detail_mask = Ext.getBody();
$(grid_ds_id_before).setQueryDataSet($(form_ds_id)); // $(grid_ds_id_before).setQueryDataSet($(form_ds_id));
$(grid_ds_id_current).setQueryDataSet($(form_ds_id)); // $(grid_ds_id_current).setQueryDataSet($(form_ds_id));
$(grid_ds_id_total).setQueryDataSet($(form_ds_id)); $(grid_ds_id_total).setQueryDataSet($(form_ds_id));
$(grid_ds_id_total).setQueryParameter('vat_6_flag','N');
$(grid_vat_6_ds_id_total).setQueryDataSet($(form_ds_id));
$(grid_vat_6_ds_id_total).setQueryParameter('vat_6_flag','Y');
$(grid_ds_id_before).query(); $(grid_ds_id_before).query();
$(grid_ds_id_before_6).query();
$(grid_ds_id_current).query(); $(grid_ds_id_current).query();
$(grid_ds_id_current_6).query();
Leaf.Masker.mask(detail_mask, '正在保存中。。。'); Leaf.Masker.mask(detail_mask, '正在保存中。。。');
Leaf.request({ Leaf.request({
url: $('process_vat_account_data_link').getUrl(), url: $('process_vat_account_data_link').getUrl(),
...@@ -36,8 +50,9 @@ ...@@ -36,8 +50,9 @@
tmp_date: new Date() tmp_date: new Date()
}, },
success: function () { success: function () {
Leaf.Masker.unmask(detail_mask);
$(grid_ds_id_total).query(); $(grid_ds_id_total).query();
$(grid_vat_6_ds_id_total).query();
Leaf.Masker.unmask(detail_mask);
}, },
failure: function () { failure: function () {
Leaf.Masker.unmask(detail_mask); Leaf.Masker.unmask(detail_mask);
......
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