Commit 2fa91e00 authored by 李贺贺's avatar 李贺贺

Merge branch 'feature/月结报表取值逻辑调整' into develop

parents c77bff08 bac0d68b
...@@ -9,211 +9,675 @@ ...@@ -9,211 +9,675 @@
<bm:operations> <bm:operations>
<bm:operation name="query"> <bm:operation name="query">
<bm:query-sql><![CDATA[ <bm:query-sql><![CDATA[
select SELECT
(SELECT m.extra_nam (SELECT m.extra_nam
FROM hls_bp_master m FROM hls_bp_master m
WHERE m.bp_id = ct.bp_id_agent_level1) agent_extra_name, WHERE m.bp_id = ct.bp_id_agent_level1) agent_extra_name,
--代理店简称 --代理店简称
(SELECT m.bp_name (SELECT m.bp_name FROM hls_bp_master m WHERE m.bp_id = ct.bp_id_tenant) AS bp_tenant_name,
FROM hls_bp_master m --承租人名称
WHERE m.bp_id = ct.contract_number,
ct.bp_id_tenant) AS bp_tenant_name, --合同编号
--承租人名称 to_char(ct.lease_start_date, 'yyyy-mm-dd') lease_start_date,
ct.contract_number, --租赁期开始日
--合同编号 (SELECT ccli.modelcd
to_char(ct.lease_start_date, FROM con_contract_lease_item ccli
'yyyy-mm-dd') lease_start_date, WHERE ccli.contract_id = ct.contract_id) modelcd,
--租赁期开始日 --机型
(SELECT ccli.modelcd (SELECT i.machine_number
FROM con_contract_lease_item ccli FROM con_contract_lease_item i
WHERE ccli.contract_id = WHERE i.contract_id = ct.contract_id
ct.contract_id) modelcd, AND i.equipment_type = 'MAIN') machine_number,
--机型 --机号
(SELECT i.machine_number to_char(NVL(ct.int_rate_display, 0) * 100, 'FM99,999,999,990.00') || '%' int_rate_display,
FROM con_contract_lease_item i -- (NVL(ct.int_rate_display, 0) * 100 ||
WHERE i.contract_id = ct.contract_id -- '%') int_rate_display,
AND i.equipment_type = --利率
'MAIN') machine_number, ct.lease_times,
--机号 --租赁期间
to_char(NVL(ct.int_rate_display, 0)*100,'FM99,999,999,990.00')||'%' int_rate_display, (NVL(ct.down_payment_ratio, 0) * 100 || '%') down_payment_ratio,
-- (NVL(ct.int_rate_display, 0) * 100 || --首付比例
-- '%') int_rate_display, ct.lease_item_amount AS lease_item_amount,
--利率 --设备款
ct.lease_times, NVL(ct.residual_value, 0) residual_amount,
--租赁期间 --留购金
(NVL(ct.down_payment_ratio, 0) * 100 || NVL(ct.total_rental, 0) + NVL(ct.down_payment, 0) +
'%') down_payment_ratio, NVL(ct.residual_value, 0) contract_amount,
--首付比例 --合同金额
ct.lease_item_amount as lease_item_amount, NVL(ct.down_payment, 0) down_payment,
--设备款 --首付款
NVL(ct.residual_value, (case when ((CASE
0) residual_amount, WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
--留购金 0
NVL(ct.total_rental, 0) + NVL(ct.down_payment, 0) + ELSE
NVL(ct.residual_value, ((SELECT SUM(ccw.due_amount)
0) contract_amount, FROM con_contract_cashflow ccw
--合同金额 WHERE ccw.contract_id = ct.contract_id
NVL(ct.down_payment, AND ccw.cf_item IN (1, 200, 250)
0) down_payment, AND ccw.cf_status = 'RELEASE') -
--首付款 nvl((SELECT SUM(nvl(cw.write_off_due_amount, 0))
(case when ct.contract_status = 'TERMINATE' FROM csh_transaction cn, csh_write_off cw
then WHERE cw.csh_transaction_id = cn.transaction_id
0 AND cw.cf_item IN (1, 200, 250)
else AND cw.contract_id = ct.contract_id
((select sum(ccw.due_amount) AND NVL(cw.reversed_flag, 'N') = 'N'
from con_contract_cashflow ccw AND trunc(cn.transaction_date) <=
where ccw.contract_id = ct.contract_id trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
and ccw.cf_item in (1, 200)) - 0))
nvl((select sum(nvl(cw.write_off_due_amount, 0)) END)<=0) then 0 else
from csh_transaction cn, csh_write_off cw (CASE
where cw.csh_transaction_id = cn.transaction_id WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
and cw.cf_item in (1, 200) 0
and cw.contract_id = ct.contract_id ELSE
and NVL(cw.reversed_flag, 'N') = 'N' ((SELECT SUM(ccw.due_amount)
and trunc(cn.transaction_date) <= FROM con_contract_cashflow ccw
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))), WHERE ccw.contract_id = ct.contract_id
0)) AND ccw.cf_item IN (1, 200, 250)
end) month_due_amount, AND ccw.cf_status = 'RELEASE') -
--当月末应收款余额(合计) nvl((SELECT SUM(nvl(cw.write_off_due_amount, 0))
(case when ct.contract_status = 'TERMINATE' FROM csh_transaction cn, csh_write_off cw
then WHERE cw.csh_transaction_id = cn.transaction_id
0 AND cw.cf_item IN (1, 200, 250)
else AND cw.contract_id = ct.contract_id
((select sum(ccw.principal) AND NVL(cw.reversed_flag, 'N') = 'N'
from con_contract_cashflow ccw AND trunc(cn.transaction_date) <=
where ccw.contract_id = ct.contract_id trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
and ccw.cf_item in (1, 200)) - 0))
nvl((select sum(nvl(cw.write_off_principal, 0)) END)
from csh_transaction cn, csh_write_off cw end) month_due_amount,
where cw.csh_transaction_id = cn.transaction_id --当月末应收款余额(合计)
and cw.cf_item in (1, 200) (CASE
and cw.contract_id = ct.contract_id WHEN (CASE
and NVL(cw.reversed_flag, 'N') = 'N' WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
and trunc(cn.transaction_date) <= 0
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))), ELSE
0)) ((SELECT SUM(ccw.due_amount)
end) month_due_principal, FROM con_contract_cashflow ccw
--当月末本金余额(合计) WHERE ccw.contract_id = ct.contract_id
(case when ct.contract_status = 'TERMINATE' AND ccw.cf_item IN (1, 200, 250)
then AND ccw.cf_status = 'RELEASE') -
0 nvl((SELECT SUM(nvl(cw.write_off_due_amount, 0))
else FROM csh_transaction cn, csh_write_off cw
((select sum(ccw.interest) WHERE cw.csh_transaction_id = cn.transaction_id
from con_contract_cashflow ccw AND cw.cf_item IN (1, 200, 250)
where ccw.contract_id = ct.contract_id AND cw.contract_id = ct.contract_id
and ccw.cf_item in (1, 200)) - AND NVL(cw.reversed_flag, 'N') = 'N'
nvl((select sum(nvl(cw.write_off_interest, 0)) AND trunc(cn.transaction_date) <=
from csh_transaction cn, csh_write_off cw trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
where cw.csh_transaction_id = cn.transaction_id 0) - nvl((SELECT SUM((nvl(tt.transaction_amount, 0) -
and cw.cf_item in (1, 200) nvl(tt.write_off_amount, 0) -
and cw.contract_id = ct.contract_id nvl(tt.returned_amount, 0)))
and NVL(cw.reversed_flag, 'N') = 'N' FROM csh_transaction tt
and trunc(cn.transaction_date) <= WHERE tt.transaction_type = 'DEPOSIT'
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))), AND tt.deposit_trans_type = 'rent_deposit'
0)) end) month_interest, AND tt.ref_contract_id = ct.contract_id
--当月末利息余额(合计) AND tt.transaction_date <=
(case when ct.contract_status = 'TERMINATE' trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
then 0))
0 END) <= 0 THEN
else 0
((select sum(ccw.due_amount) ELSE
from con_contract_cashflow ccw (CASE
where ccw.contract_id = ct.contract_id WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
and ccw.cf_item in (8)) - 0
nvl((select sum(nvl(cw.write_off_due_amount, 0)) ELSE
from csh_transaction cn, csh_write_off cw ((SELECT SUM(ccw.due_amount)
where cw.csh_transaction_id = cn.transaction_id FROM con_contract_cashflow ccw
and cw.cf_item in (8) WHERE ccw.contract_id = ct.contract_id
and cw.contract_id = ct.contract_id AND ccw.cf_item IN (1, 200, 250)
and NVL(cw.reversed_flag, 'N') = 'N' AND ccw.cf_status = 'RELEASE') -
and trunc(cn.transaction_date) <= nvl((SELECT SUM(nvl(cw.write_off_due_amount, 0))
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))), FROM csh_transaction cn, csh_write_off cw
0)) end) month_residual, WHERE cw.csh_transaction_id = cn.transaction_id
--当月末留购金余额 AND cw.cf_item IN (1, 200, 250)
(case when ct.contract_status = 'TERMINATE' AND cw.contract_id = ct.contract_id
then AND NVL(cw.reversed_flag, 'N') = 'N'
0 AND trunc(cn.transaction_date) <=
else trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
con_contract_pkg.get_business_times(p_contract_id => ct.contract_id, 0) - nvl((SELECT SUM((nvl(tt.transaction_amount, 0) -
p_calc_date => to_date(${@cur_end}, 'yyyy-mm-dd'), nvl(tt.write_off_amount, 0) -
p_contract_inception_date => ct.contract_inception_date) end) business_due_times, nvl(tt.returned_amount, 0)))
--逾期期数 FROM csh_transaction tt
(case when ct.contract_status = 'TERMINATE' WHERE tt.transaction_type = 'DEPOSIT'
then AND tt.deposit_trans_type = 'rent_deposit'
0 AND tt.ref_contract_id = ct.contract_id
else AND tt.transaction_date <=
(nvl((select sum(ccw.due_amount) - sum(nvl((SELECT SUM(nvl(cwo.write_off_due_amount, 0)) trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
FROM csh_write_off cwo, csh_transaction cn 0))
WHERE nvl(cwo.reversed_flag, 'N') = 'N' END)
AND cwo.contract_id = ccw.contract_id END) month_due_amount_after,
AND cwo.times = ccw.times --当月末应收款余额(合计)保证金后
and (case when ((CASE
cwo.csh_transaction_id = cn.transaction_id WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
AND cwo.cf_item = ccw.cf_item 0
and trunc(cn.transaction_date) <= ELSE
trunc(to_date(${@cur_end}, ((SELECT SUM(ccw.principal)
'yyyy-mm-dd'))), FROM con_contract_cashflow ccw
0)) WHERE ccw.contract_id = ct.contract_id
from con_contract_cashflow ccw AND ccw.cf_item IN (1, 200, 250)
where ccw.contract_id = ct.contract_id AND ccw.cf_status = 'RELEASE') -
and ccw.cf_item in (1, 200, 8) nvl((SELECT SUM(nvl(cw.write_off_principal, 0))
and trunc(ccw.due_date) <= trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))), 0) FROM csh_transaction cn, csh_write_off cw
- nvl((select sum((nvl(tt.transaction_amount, 0) - nvl(tt.write_off_amount, 0) - WHERE cw.csh_transaction_id = cn.transaction_id
nvl(tt.returned_amount, 0))) AND cw.cf_item IN (1, 200, 250)
from csh_transaction tt AND cw.contract_id = ct.contract_id
where tt.transaction_type = 'DEPOSIT' AND NVL(cw.reversed_flag, 'N') = 'N'
AND tt.deposit_trans_type = 'rent_deposit' AND trunc(cn.transaction_date) <=
and tt.ref_contract_id = ct.contract_id), trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0)) end) business_due_amount, 0))
--当月末逾期金额(合计) END) <=0) then 0 else
(CASE
(select sum((nvl(tt.transaction_amount, 0) - nvl(tt.write_off_amount, 0) - WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
nvl(tt.returned_amount, 0))) 0
from csh_transaction tt ELSE
where tt.transaction_type = 'DEPOSIT' ((SELECT SUM(ccw.principal)
AND tt.deposit_trans_type = 'rent_deposit' FROM con_contract_cashflow ccw
and tt.ref_contract_id = WHERE ccw.contract_id = ct.contract_id
ct.contract_id) deposit_amount, AND ccw.cf_item IN (1, 200, 250)
--保证金金额 AND ccw.cf_status = 'RELEASE') -
(SELECT v.code_value_name nvl((SELECT SUM(nvl(cw.write_off_principal, 0))
FROM sys_code_values_v v FROM csh_transaction cn, csh_write_off cw
WHERE v.code = 'CON500_CONTRACT_STATUS' WHERE cw.csh_transaction_id = cn.transaction_id
AND v.code_value = AND cw.cf_item IN (1, 200, 250)
ct.contract_status) AS contract_status_n, AND cw.contract_id = ct.contract_id
--合同金额 AND NVL(cw.reversed_flag, 'N') = 'N'
(select to_char(due_date, 'yyyy-mm-dd') AND trunc(cn.transaction_date) <=
from con_contract_cashflow trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
where contract_id = ct.contract_id 0))
and cf_status='RELEASE' END)
and cf_item = end) month_due_principal,
8) residual_date, --当月末本金余额(合计)
-- 合同终了 (CASE
to_char(ct.et_date, WHEN (CASE
'yyyy-mm-dd') terminate_date, WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
ct.is_buyout, 0
(Select v.code_value_name ELSE
From sys_code_values_v v ((SELECT SUM(ccw.principal)
Where v.code = 'YES_OR_NO' FROM con_contract_cashflow ccw
And v.code_enabled_flag = 'Y' WHERE ccw.contract_id = ct.contract_id
And v.code_value_enabled_flag = 'Y' AND ccw.cf_item IN (1, 200, 250)
and v.CODE_VALUE = ct.is_buyout) is_buyout_n, AND ccw.cf_status = 'RELEASE') -
(select sh.large_balance from prj_quotation sh where sh.DOCUMENT_ID = ct.project_id) large_balance, nvl((SELECT SUM(nvl(cw.write_off_principal, 0))
(select v.code_value_name FROM csh_transaction cn, csh_write_off cw
from sys_code_values_v v WHERE cw.csh_transaction_id = cn.transaction_id
where v.code = 'SECONDARY_LEASE' AND cw.cf_item IN (1, 200, 250)
and v.code_value = (select sh.large_balance from prj_quotation sh where sh.DOCUMENT_ID = ct.project_id)) large_balance_n, AND cw.contract_id = ct.contract_id
ct.branch_code, AND NVL(cw.reversed_flag, 'N') = 'N'
(Select v.code_value_name AND trunc(cn.transaction_date) <=
From sys_code_values_v v trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
Where v.code = 'BRANCH_CODE_SZMP' 0) - nvl((SELECT SUM((nvl(tt.transaction_amount, 0) -
And v.code_enabled_flag = 'Y' nvl(tt.write_off_amount, 0) -
And v.code_value_enabled_flag = 'Y' nvl(tt.returned_amount, 0)))
And v.code_value = ct.branch_code) branch_code_n FROM csh_transaction tt
from con_contract ct WHERE tt.transaction_type = 'DEPOSIT'
where ct.contract_status not in ('CANCEL') AND tt.deposit_trans_type = 'rent_deposit'
and ct.data_class = 'NORMAL' AND tt.ref_contract_id = ct.contract_id
order by ct.bp_id_agent_level1 AND tt.transaction_date <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END) <= 0 THEN
0
ELSE
(CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
((SELECT SUM(ccw.principal)
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (1, 200, 250)
AND ccw.cf_status = 'RELEASE') -
nvl((SELECT SUM(nvl(cw.write_off_principal, 0))
FROM csh_transaction cn, csh_write_off cw
WHERE cw.csh_transaction_id = cn.transaction_id
AND cw.cf_item IN (1, 200, 250)
AND cw.contract_id = ct.contract_id
AND NVL(cw.reversed_flag, 'N') = 'N'
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0) - nvl((SELECT SUM((nvl(tt.transaction_amount, 0) -
nvl(tt.write_off_amount, 0) -
nvl(tt.returned_amount, 0)))
FROM csh_transaction tt
WHERE tt.transaction_type = 'DEPOSIT'
AND tt.deposit_trans_type = 'rent_deposit'
AND tt.ref_contract_id = ct.contract_id
AND tt.transaction_date <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END)
END) month_due_principal_after,
--当月末本金余额(合计)保证金后
(case when ((CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
((SELECT SUM(ccw.interest)
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (1, 200, 250)
AND ccw.cf_status = 'RELEASE') -
nvl((SELECT SUM(nvl(cw.write_off_interest, 0))
FROM csh_transaction cn, csh_write_off cw
WHERE cw.csh_transaction_id = cn.transaction_id
AND cw.cf_item IN (1, 200, 250)
AND cw.contract_id = ct.contract_id
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END) <=0) then 0 else
(CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
((SELECT SUM(ccw.interest)
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (1, 200, 250)
AND ccw.cf_status = 'RELEASE') -
nvl((SELECT SUM(nvl(cw.write_off_interest, 0))
FROM csh_transaction cn, csh_write_off cw
WHERE cw.csh_transaction_id = cn.transaction_id
AND cw.cf_item IN (1, 200, 250)
AND cw.contract_id = ct.contract_id
AND NVL(cw.reversed_flag, 'N') = 'N'
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END)
end) month_interest,
--当月末利息余额(合计)
(CASE
WHEN ((SELECT SUM((nvl(tt.transaction_amount, 0) -
nvl(tt.write_off_amount, 0) -
nvl(tt.returned_amount, 0)))
FROM csh_transaction tt
WHERE tt.transaction_type = 'DEPOSIT'
AND tt.deposit_trans_type = 'rent_deposit'
AND tt.ref_contract_id = ct.contract_id
AND tt.transaction_date <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))) - ((CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
((SELECT SUM(ccw.principal)
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (1, 200, 250)
AND ccw.cf_status = 'RELEASE') -
nvl((SELECT SUM(nvl(cw.write_off_principal, 0))
FROM csh_transaction cn, csh_write_off cw
WHERE cw.csh_transaction_id = cn.transaction_id
AND cw.cf_item IN (1, 200, 250)
AND cw.contract_id = ct.contract_id
AND NVL(cw.reversed_flag, 'N') = 'N'
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END))) > 0 THEN
(CASE
WHEN ((CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
((SELECT SUM(ccw.interest)
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (1, 200, 250)
AND ccw.cf_status = 'RELEASE') -
nvl((SELECT SUM(nvl(cw.write_off_interest, 0))
FROM csh_transaction cn, csh_write_off cw
WHERE cw.csh_transaction_id = cn.transaction_id
AND cw.cf_item IN (1, 200, 250)
AND cw.contract_id = ct.contract_id
AND NVL(cw.reversed_flag, 'N') = 'N'
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END) - (SELECT SUM((nvl(tt.transaction_amount, 0) -
nvl(tt.write_off_amount, 0) -
nvl(tt.returned_amount, 0)))
FROM csh_transaction tt
WHERE tt.transaction_type = 'DEPOSIT'
AND tt.deposit_trans_type = 'rent_deposit'
AND tt.ref_contract_id = ct.contract_id
AND tt.transaction_date <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))) - (CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
((SELECT SUM(ccw.principal)
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (1, 200, 250)
AND ccw.cf_status = 'RELEASE') -
nvl((SELECT SUM(nvl(cw.write_off_principal, 0))
FROM csh_transaction cn, csh_write_off cw
WHERE cw.csh_transaction_id = cn.transaction_id
AND cw.cf_item IN (1, 200, 250)
AND cw.contract_id = ct.contract_id
AND NVL(cw.reversed_flag, 'N') = 'N'
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END)) <= 0 THEN
0
ELSE
((CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
((SELECT SUM(ccw.interest)
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (1, 200, 250)
AND ccw.cf_status = 'RELEASE') -
nvl((SELECT SUM(nvl(cw.write_off_interest, 0))
FROM csh_transaction cn, csh_write_off cw
WHERE cw.csh_transaction_id = cn.transaction_id
AND cw.cf_item IN (1, 200, 250)
AND cw.contract_id = ct.contract_id
AND NVL(cw.reversed_flag, 'N') = 'N'
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END) -
(SELECT SUM((nvl(tt.transaction_amount, 0) - nvl(tt.write_off_amount, 0) -
nvl(tt.returned_amount, 0)))
FROM csh_transaction tt
WHERE tt.transaction_type = 'DEPOSIT'
AND tt.deposit_trans_type = 'rent_deposit'
AND tt.ref_contract_id = ct.contract_id
AND tt.transaction_date <= trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))) -
(CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
((SELECT SUM(ccw.principal)
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (1, 200, 250)
AND ccw.cf_status = 'RELEASE') -
nvl((SELECT SUM(nvl(cw.write_off_principal, 0))
FROM csh_transaction cn, csh_write_off cw
WHERE cw.csh_transaction_id = cn.transaction_id
AND cw.cf_item IN (1, 200, 250)
AND cw.contract_id = ct.contract_id
AND NVL(cw.reversed_flag, 'N') = 'N'
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END))
END)
ELSE
(CASE
WHEN (CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
((SELECT SUM(ccw.interest)
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (1, 200, 250)
AND ccw.cf_status = 'RELEASE') -
nvl((SELECT SUM(nvl(cw.write_off_interest, 0))
FROM csh_transaction cn, csh_write_off cw
WHERE cw.csh_transaction_id = cn.transaction_id
AND cw.cf_item IN (1, 200, 250)
AND cw.contract_id = ct.contract_id
AND NVL(cw.reversed_flag, 'N') = 'N'
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END) <= 0 THEN
0
ELSE
(CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
((SELECT SUM(ccw.interest)
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (1, 200, 250)
AND ccw.cf_status = 'RELEASE') -
nvl((SELECT SUM(nvl(cw.write_off_interest, 0))
FROM csh_transaction cn, csh_write_off cw
WHERE cw.csh_transaction_id = cn.transaction_id
AND cw.cf_item IN (1, 200, 250)
AND cw.contract_id = ct.contract_id
AND NVL(cw.reversed_flag, 'N') = 'N'
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END)
END)
END) month_interest_after,
--当月末利息余额(合计)保证金后
(CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
((SELECT SUM(ccw.due_amount)
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (8)
and ccw.cf_status = 'RELEASE') -
nvl((SELECT SUM(nvl(cw.write_off_due_amount, 0))
FROM csh_transaction cn, csh_write_off cw
WHERE cw.csh_transaction_id = cn.transaction_id
AND cw.cf_item IN (8)
AND cw.contract_id = ct.contract_id
AND NVL(cw.reversed_flag, 'N') = 'N'
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END) month_residual,
--当月末留购金余额
(CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
con_contract_pkg.get_business_times(p_contract_id => ct.contract_id,
p_calc_date => to_date(${@cur_end},
'yyyy-mm-dd'),
p_contract_inception_date => ct.contract_inception_date)
END) business_due_times,
--逾期期数
(CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
con_contract_pkg.get_business_times(
p_contract_id => ct.contract_id,
p_calc_date => to_date(${@cur_end}, 'yyyy-mm-dd'),
p_contract_inception_date => ct.contract_inception_date,
p_amount_after => 'Y')
END) business_due_times_after,
--逾期期数(保证金后)
(case when ((CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
(nvl((SELECT SUM(ccw.due_amount) -
SUM(nvl((SELECT SUM(nvl(cwo.write_off_due_amount, 0))
FROM csh_write_off cwo, csh_transaction cn
WHERE nvl(cwo.reversed_flag, 'N') = 'N'
AND cwo.contract_id = ccw.contract_id
AND cwo.times = ccw.times
AND cwo.csh_transaction_id =
cn.transaction_id
AND cwo.cf_item = ccw.cf_item
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end},
'yyyy-mm-dd'))),
0))
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (1, 200, 8, 250)
AND ccw.cf_status = 'RELEASE'
AND trunc(ccw.due_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END)<=0) then 0 else (CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
(nvl((SELECT SUM(ccw.due_amount) -
SUM(nvl((SELECT SUM(nvl(cwo.write_off_due_amount, 0))
FROM csh_write_off cwo, csh_transaction cn
WHERE nvl(cwo.reversed_flag, 'N') = 'N'
AND cwo.contract_id = ccw.contract_id
AND cwo.times = ccw.times
AND cwo.csh_transaction_id =
cn.transaction_id
AND cwo.cf_item = ccw.cf_item
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end},
'yyyy-mm-dd'))),
0))
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (1, 200, 8, 250)
AND ccw.cf_status = 'RELEASE'
AND trunc(ccw.due_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END)
end) business_due_amount,
--当月末逾期金额(合计)
(case when (CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
(nvl((SELECT SUM(ccw.due_amount) -
SUM(nvl((SELECT SUM(nvl(cwo.write_off_due_amount, 0))
FROM csh_write_off cwo, csh_transaction cn
WHERE nvl(cwo.reversed_flag, 'N') = 'N'
AND cwo.contract_id = ccw.contract_id
AND cwo.times = ccw.times
AND cwo.csh_transaction_id = cn.transaction_id
AND cwo.cf_item = ccw.cf_item
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (1, 200, 8, 250)
AND ccw.cf_status = 'RELEASE'
AND trunc(ccw.due_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0) - nvl((SELECT SUM((nvl(tt.transaction_amount, 0) -
nvl(tt.write_off_amount, 0) -
nvl(tt.returned_amount, 0)))
FROM csh_transaction tt
WHERE tt.transaction_type = 'DEPOSIT'
AND tt.deposit_trans_type = 'rent_deposit'
AND tt.ref_contract_id = ct.contract_id
AND tt.transaction_date <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END)<=0 then
0
else
(CASE
WHEN ct.contract_status IN ('TERMINATE', 'REPUR', 'ET') THEN
0
ELSE
(nvl((SELECT SUM(ccw.due_amount) -
SUM(nvl((SELECT SUM(nvl(cwo.write_off_due_amount, 0))
FROM csh_write_off cwo, csh_transaction cn
WHERE nvl(cwo.reversed_flag, 'N') = 'N'
AND cwo.contract_id = ccw.contract_id
AND cwo.times = ccw.times
AND cwo.csh_transaction_id = cn.transaction_id
AND cwo.cf_item = ccw.cf_item
AND trunc(cn.transaction_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
FROM con_contract_cashflow ccw
WHERE ccw.contract_id = ct.contract_id
AND ccw.cf_item IN (1, 200, 8, 250)
AND ccw.cf_status = 'RELEASE'
AND trunc(ccw.due_date) <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0) - nvl((SELECT SUM((nvl(tt.transaction_amount, 0) -
nvl(tt.write_off_amount, 0) -
nvl(tt.returned_amount, 0)))
FROM csh_transaction tt
WHERE tt.transaction_type = 'DEPOSIT'
AND tt.deposit_trans_type = 'rent_deposit'
AND tt.ref_contract_id = ct.contract_id
AND tt.transaction_date <=
trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))),
0))
END)
end) business_due_amount_after,
--当月末逾期金额(合计)保证金后
(SELECT SUM((nvl(tt.transaction_amount, 0) - nvl(tt.write_off_amount, 0) -
nvl(tt.returned_amount, 0)))
FROM csh_transaction tt
WHERE tt.transaction_type = 'DEPOSIT'
AND tt.deposit_trans_type = 'rent_deposit'
AND tt.ref_contract_id = ct.contract_id
AND tt.transaction_date <= trunc(to_date(${@cur_end}, 'yyyy-mm-dd'))) deposit_amount,
--保证金金额
(SELECT v.code_value_name
FROM sys_code_values_v v
WHERE v.code = 'CON500_CONTRACT_STATUS'
AND v.code_value = ct.contract_status) AS contract_status_n,
--合同金额
(SELECT to_char(due_date, 'yyyy-mm-dd')
FROM con_contract_cashflow
WHERE contract_id = ct.contract_id
AND cf_status = 'RELEASE'
AND cf_item = 8) residual_date,
-- 合同终了
(CASE
WHEN ct.contract_status IN ('INCEPT', 'ETING', 'TERMINATE', 'ET') THEN
(SELECT to_char(MAX(cc.last_received_date),'yyyy-mm-dd')
FROM con_contract_cashflow cc
WHERE cc.contract_id = ct.contract_id
AND cf_status = 'RELEASE'
AND cf_item = 8)
WHEN ct.contract_status IN ('REPUR') THEN
(SELECT to_char(MAX(cc.last_received_date),'yyyy-mm-dd')
FROM con_contract_cashflow cc
WHERE cc.contract_id = ct.contract_id
AND cf_status = 'RELEASE'
AND cf_item = 250)
ELSE
''
END) terminate_date,
ct.is_buyout,
(SELECT v.code_value_name
FROM sys_code_values_v v
WHERE v.code = 'YES_OR_NO'
AND v.code_enabled_flag = 'Y'
AND v.code_value_enabled_flag = 'Y'
AND v.CODE_VALUE = ct.is_buyout) is_buyout_n,
(SELECT sh.large_balance
FROM prj_quotation sh
WHERE sh.DOCUMENT_ID = ct.project_id) large_balance,
(SELECT v.code_value_name
FROM sys_code_values_v v
WHERE v.code = 'SECONDARY_LEASE'
AND v.code_value =
(SELECT sh.large_balance
FROM prj_quotation sh
WHERE sh.DOCUMENT_ID = ct.project_id)) large_balance_n,
ct.branch_code,
(SELECT v.code_value_name
FROM sys_code_values_v v
WHERE v.code = 'BRANCH_CODE_SZMP'
AND v.code_enabled_flag = 'Y'
AND v.code_value_enabled_flag = 'Y'
AND v.code_value = ct.branch_code) branch_code_n
FROM con_contract ct
WHERE ct.contract_status NOT IN ('CANCEL')
AND ct.data_class = 'NORMAL'
ORDER BY ct.bp_id_agent_level1
]]></bm:query-sql> ]]></bm:query-sql>
</bm:operation> </bm:operation>
<bm:operation name="update"> <bm:operation name="update">
...@@ -266,11 +730,16 @@ ...@@ -266,11 +730,16 @@
<bm:field name="contract_amount" datatype="java.lang.Double"/> <bm:field name="contract_amount" datatype="java.lang.Double"/>
<bm:field name="down_payment" datatype="java.lang.Double"/> <bm:field name="down_payment" datatype="java.lang.Double"/>
<bm:field name="month_due_amount" datatype="java.lang.Double"/> <bm:field name="month_due_amount" datatype="java.lang.Double"/>
<bm:field name="month_due_amount_after" datatype="java.lang.Double"/>
<bm:field name="month_due_principal" datatype="java.lang.Double"/> <bm:field name="month_due_principal" datatype="java.lang.Double"/>
<bm:field name="month_due_principal_after" datatype="java.lang.Double"/>
<bm:field name="month_interest" datatype="java.lang.Double"/> <bm:field name="month_interest" datatype="java.lang.Double"/>
<bm:field name="month_interest_after" datatype="java.lang.Double"/>
<bm:field name="month_residual" datatype="java.lang.Double"/> <bm:field name="month_residual" datatype="java.lang.Double"/>
<bm:field name="business_due_times" datatype="java.lang.Long"/> <bm:field name="business_due_times" datatype="java.lang.Long"/>
<bm:field name="business_due_times_after" datatype="java.lang.Long"/>
<bm:field name="business_due_amount" datatype="java.lang.Double"/> <bm:field name="business_due_amount" datatype="java.lang.Double"/>
<bm:field name="business_due_amount_after" datatype="java.lang.Double"/>
<bm:field name="deposit_amount" datatype="java.lang.Double"/> <bm:field name="deposit_amount" datatype="java.lang.Double"/>
<bm:field name="contract_status_n"/> <bm:field name="contract_status_n"/>
<bm:field name="residual_date"/> <bm:field name="residual_date"/>
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
/*
if (!Ext.isEmpty(bp_code)&&bp_code!== 'D00010001'&&bp_code!=='D00000009') { if (!Ext.isEmpty(bp_code)&&bp_code!== 'D00010001'&&bp_code!=='D00000009') {
$('con_contract_rental_result_grid').hideColumn('branch_code_n'); $('con_contract_rental_result_grid').hideColumn('branch_code_n');
$('con_contract_rental_result_grid').hideColumn('branch_code'); $('con_contract_rental_result_grid').hideColumn('branch_code');
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
$('con_contract_cashflow_rental_result_grid').hideColumn('large_balance'); $('con_contract_cashflow_rental_result_grid').hideColumn('large_balance');
} }
} }
}); });*/
]]></script> ]]></script>
<a:dataSets> <a:dataSets>
<a:dataSet id="con_contract_rental_result_ds" pageSize="13" autoQuery="true" model="rpt.RPT5012.rpt5012_result_query" queryUrl="${/request/@context_path}/autocrud/rpt.RPT5012.rpt5012_result_query/query?month=${/parameter/@month}&amp;cur_begin=${/parameter/@cur_begin}&amp;cur_end=${/parameter/@cur_end}&amp;before_begin=${/parameter/@before_begin}&amp;before_end=${/parameter/@before_end}" autoPageSize="true"/> <a:dataSet id="con_contract_rental_result_ds" pageSize="13" autoQuery="true" model="rpt.RPT5012.rpt5012_result_query" queryUrl="${/request/@context_path}/autocrud/rpt.RPT5012.rpt5012_result_query/query?month=${/parameter/@month}&amp;cur_begin=${/parameter/@cur_begin}&amp;cur_end=${/parameter/@cur_end}&amp;before_begin=${/parameter/@before_begin}&amp;before_end=${/parameter/@before_end}" autoPageSize="true"/>
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
<!-- </a:screenTopToolbar>--> <!-- </a:screenTopToolbar>-->
<a:tabPanel marginHeight="25" marginWidth="20"> <a:tabPanel marginHeight="25" marginWidth="20">
<a:tabs> <a:tabs>
<a:tab prompt="租金余额表" width="110"> <a:tab prompt="租金余额表(保证金前)" width="150">
<a:grid id="con_contract_rental_result_grid" bindTarget="con_contract_rental_result_ds" marginHeight="115" navBar="true" marginWidth="30"> <a:grid id="con_contract_rental_result_grid" bindTarget="con_contract_rental_result_ds" marginHeight="115" navBar="true" marginWidth="30">
<a:columns> <a:columns>
<a:column name="agent_extra_name" align="center" prompt="代理店" width="120"/> <a:column name="agent_extra_name" align="center" prompt="代理店" width="120"/>
...@@ -110,7 +110,40 @@ ...@@ -110,7 +110,40 @@
</a:columns> </a:columns>
</a:grid> </a:grid>
</a:tab> </a:tab>
<a:tab prompt="回收逾期明细表" width="110"> <a:tab prompt="租金余额表(保证金后)" width="150">
<a:grid id="con_contract_rental_result_after_grid" bindTarget="con_contract_rental_result_ds" marginHeight="115" navBar="true" marginWidth="30">
<a:columns>
<a:column name="agent_extra_name" align="center" prompt="代理店" width="120"/>
<a:column name="bp_tenant_name" align="center" prompt="客户名称" width="120"/>
<a:column name="contract_number" align="center" prompt="合同编号" width="100"/>
<a:column name="lease_start_date" align="center" prompt="租赁期开始日" width="80"/>
<a:column name="branch_code_n" align="center" prompt="分公司" width="100"/>
<a:column name="large_balance_n" align="center" prompt="大额尾款" width="100"/>
<a:column name="is_buyout_n" align="center" prompt="是否买断机" width="100"/>
<a:column name="modelcd" align="center" prompt=" 机型" width="180"/>
<a:column name="machine_number" align="center" prompt="机器号码" width="80"/>
<a:column name="int_rate_display" exportDataFormat="" align="center" prompt="利率" width="80"/>
<a:column name="int_rate_display" align="center" prompt="基准利率" width="80"/>
<a:column name="lease_times" align="center" prompt="租赁期间" width="80"/>
<a:column name="down_payment_ratio" align="center" prompt="首付款比率" width="80"/>
<a:column name="lease_item_amount" align="center" prompt="代理店销售金额" renderer="Leaf.formatMoney" width="80"/>
<a:column name="residual_amount" align="center" prompt="留购价格" renderer="Leaf.formatMoney" width="80"/>
<a:column name="contract_amount" align="center" prompt="合同总金额" renderer="Leaf.formatMoney" width="80"/>
<a:column name="down_payment" align="center" prompt="首付款" renderer="Leaf.formatMoney" width="80"/>
<a:column name="month_due_amount_after" align="center" prompt="当月末应收款余额(合计)" renderer="Leaf.formatMoney" width="80"/>
<a:column name="month_due_principal_after" align="center" prompt="当月末本金余额(合计)" renderer="Leaf.formatMoney" width="80"/>
<a:column name="month_interest_after" align="center" prompt="当月末利息余额(合计)" renderer="Leaf.formatMoney" width="80"/>
<a:column name="month_residual" align="center" prompt="当月末留购金余额" renderer="Leaf.formatMoney" width="80"/>
<a:column name="business_due_times_after" align="center" prompt="逾期期数" width="80"/>
<a:column name="business_due_amount_after" align="center" prompt="当月末逾期金额(合计)" renderer="Leaf.formatMoney" width="80"/>
<a:column name="deposit_amount" align="center" prompt="保证金" renderer="Leaf.formatMoney" width="80"/>
<a:column name="contract_status_n" align="center" prompt="合同状态" width="80"/>
<a:column name="residual_date" align="center" prompt="合同终了" width="80"/>
<a:column name="terminate_date" align="center" prompt="结清年月" width="80"/>
</a:columns>
</a:grid>
</a:tab>
<a:tab prompt="回收逾期明细表(保证金前)" width="180">
<a:grid id="con_contract_cashflow_rental_result_grid" bindTarget="con_contract_cashflow_rental_result_ds" marginHeight="115" navBar="true" marginWidth="30"> <a:grid id="con_contract_cashflow_rental_result_grid" bindTarget="con_contract_cashflow_rental_result_ds" marginHeight="115" navBar="true" marginWidth="30">
<a:columns> <a:columns>
<a:column name="agent_extra_name" align="center" prompt="代理店" width="120"/> <a:column name="agent_extra_name" align="center" prompt="代理店" width="120"/>
......
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