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

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

parents c77bff08 bac0d68b
......@@ -9,211 +9,675 @@
<bm:operations>
<bm:operation name="query">
<bm:query-sql><![CDATA[
select
SELECT
(SELECT m.extra_nam
FROM hls_bp_master m
WHERE m.bp_id = ct.bp_id_agent_level1) agent_extra_name,
--代理店简称
(SELECT m.bp_name
FROM hls_bp_master m
WHERE m.bp_id =
ct.bp_id_tenant) AS bp_tenant_name,
--承租人名称
ct.contract_number,
--合同编号
to_char(ct.lease_start_date,
'yyyy-mm-dd') lease_start_date,
--租赁期开始日
(SELECT ccli.modelcd
FROM con_contract_lease_item ccli
WHERE ccli.contract_id =
ct.contract_id) modelcd,
--机型
(SELECT i.machine_number
FROM con_contract_lease_item i
WHERE i.contract_id = ct.contract_id
AND i.equipment_type =
'MAIN') machine_number,
--机号
to_char(NVL(ct.int_rate_display, 0)*100,'FM99,999,999,990.00')||'%' int_rate_display,
-- (NVL(ct.int_rate_display, 0) * 100 ||
-- '%') int_rate_display,
--利率
ct.lease_times,
--租赁期间
(NVL(ct.down_payment_ratio, 0) * 100 ||
'%') down_payment_ratio,
--首付比例
ct.lease_item_amount as lease_item_amount,
--设备款
NVL(ct.residual_value,
0) residual_amount,
--留购金
NVL(ct.total_rental, 0) + NVL(ct.down_payment, 0) +
NVL(ct.residual_value,
0) contract_amount,
--合同金额
NVL(ct.down_payment,
0) down_payment,
--首付款
(case when ct.contract_status = 'TERMINATE'
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 (1, 200)) -
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 (1, 200)
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_due_amount,
--当月末应收款余额(合计)
(case when ct.contract_status = 'TERMINATE'
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)) -
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)
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_due_principal,
--当月末本金余额(合计)
(case when ct.contract_status = 'TERMINATE'
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)) -
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)
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_interest,
--当月末利息余额(合计)
(case when ct.contract_status = 'TERMINATE'
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)) -
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 = 'TERMINATE'
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 = 'TERMINATE'
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)
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),
0)) end) business_due_amount,
--当月末逾期金额(合计)
(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) 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,
-- 合同终了
to_char(ct.et_date,
'yyyy-mm-dd') 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
(SELECT m.extra_nam
FROM hls_bp_master m
WHERE m.bp_id = ct.bp_id_agent_level1) agent_extra_name,
--代理店简称
(SELECT m.bp_name FROM hls_bp_master m WHERE m.bp_id = ct.bp_id_tenant) AS bp_tenant_name,
--承租人名称
ct.contract_number,
--合同编号
to_char(ct.lease_start_date, 'yyyy-mm-dd') lease_start_date,
--租赁期开始日
(SELECT ccli.modelcd
FROM con_contract_lease_item ccli
WHERE ccli.contract_id = ct.contract_id) modelcd,
--机型
(SELECT i.machine_number
FROM con_contract_lease_item i
WHERE i.contract_id = ct.contract_id
AND i.equipment_type = 'MAIN') machine_number,
--机号
to_char(NVL(ct.int_rate_display, 0) * 100, 'FM99,999,999,990.00') || '%' int_rate_display,
-- (NVL(ct.int_rate_display, 0) * 100 ||
-- '%') int_rate_display,
--利率
ct.lease_times,
--租赁期间
(NVL(ct.down_payment_ratio, 0) * 100 || '%') down_payment_ratio,
--首付比例
ct.lease_item_amount AS lease_item_amount,
--设备款
NVL(ct.residual_value, 0) residual_amount,
--留购金
NVL(ct.total_rental, 0) + NVL(ct.down_payment, 0) +
NVL(ct.residual_value, 0) contract_amount,
--合同金额
NVL(ct.down_payment, 0) down_payment,
--首付款
(case when ((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 (1, 200, 250)
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 (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.due_amount)
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_due_amount, 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_due_amount,
--当月末应收款余额(合计)
(CASE
WHEN (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 (1, 200, 250)
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 (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) <= 0 THEN
0
ELSE
(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 (1, 200, 250)
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 (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_amount_after,
--当月末应收款余额(合计)保证金后
(case when ((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.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) month_due_principal,
--当月末本金余额(合计)
(CASE
WHEN (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) <= 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:operation>
<bm:operation name="update">
......@@ -266,11 +730,16 @@
<bm:field name="contract_amount" 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_after" 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_after" 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_after" datatype="java.lang.Long"/>
<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="contract_status_n"/>
<bm:field name="residual_date"/>
......
......@@ -41,7 +41,7 @@
/*
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');
......@@ -64,7 +64,7 @@
$('con_contract_cashflow_rental_result_grid').hideColumn('large_balance');
}
}
});
});*/
]]></script>
<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"/>
......@@ -77,7 +77,7 @@
<!-- </a:screenTopToolbar>-->
<a:tabPanel marginHeight="25" marginWidth="20">
<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:columns>
<a:column name="agent_extra_name" align="center" prompt="代理店" width="120"/>
......@@ -110,7 +110,40 @@
</a:columns>
</a:grid>
</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:columns>
<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