Commit bdb19a8a authored by liyuan.chen's avatar liyuan.chen

对账单sql修改

parent 43bb741a
...@@ -21,17 +21,16 @@ ...@@ -21,17 +21,16 @@
cf_item_n, cf_item_n,
times, times,
due_date, due_date,
to_char(due_amount, 'fm999,999,999,990.00') due_amount, to_char(due_amount, 'fm999,999,999,990.00') due_amount,
transaction_date, transaction_date,
write_off_date, write_off_date,
to_char(received_amount, 'fm999,999,999,990.00') received_amount, to_char(received_amount, 'fm999,999,999,990.00') received_amount,
to_char(unreceived_amount, 'fm999,999,999,990.00') unreceived_amount, to_char(unreceived_amount, 'fm999,999,999,990.00') unreceived_amount,
times_9, times_9,
to_char(due_amount_9, 'fm999,999,999,990.00') due_amount_9, to_char(due_amount_9, 'fm999,999,999,990.00') due_amount_9,
to_char(nvl(received_amount_9, 0), 'fm999,999,999,990.00') received_amount_9, to_char(nvl(received_amount_9, 0), 'fm999,999,999,990.00') received_amount_9,
to_char(unreceived_amount_9, 'fm999,999,999,990.00') unreceived_amount_9 to_char(unreceived_amount_9, 'fm999,999,999,990.00') unreceived_amount_9
from From (Select *
(select *
From (Select From (Select
t1.contract_id, t1.contract_id,
t1.cashflow_id, t1.cashflow_id,
...@@ -53,29 +52,30 @@ ...@@ -53,29 +52,30 @@
c.contract_id, c.contract_id,
cwo.cashflow_id, cwo.cashflow_id,
cwo.write_off_id, cwo.write_off_id,
ccc.cf_item, ccc.cf_item,
(Select h.description (Select h.description
From hls_cashflow_item h From hls_cashflow_item h
Where h.cf_item = ccc.cf_item) cf_item_n, Where h.cf_item = ccc.cf_item) cf_item_n,
ccc.times, ccc.times,
to_char(ccc.due_date, 'yyyy-mm-dd') due_date, to_char(ccc.due_date, 'yyyy-mm-dd') due_date,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id = cwo.cashflow_id
And tn.creation_date &lt;= cwo.creation_date), And tn.creation_date <=
cwo.creation_date),
0) + cwo.write_off_due_amount) As due_amount, 0) + cwo.write_off_due_amount) As due_amount,
--收款日 --收款日
to_char(t.transaction_date, &apos;yyyy-mm-dd&apos;) transaction_date, to_char(t.transaction_date, 'yyyy-mm-dd') transaction_date,
to_char(cwo.write_off_date, &apos;yyyy-mm-dd&apos;) write_off_date, to_char(cwo.write_off_date, 'yyyy-mm-dd') write_off_date,
--实收金额 --实收金额
cwo.write_off_due_amount received_amount, cwo.write_off_due_amount received_amount,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id = cwo.cashflow_id
And tn.creation_date &lt;= cwo.creation_date), And tn.creation_date <=
cwo.creation_date),
0)) As unreceived_amount 0)) As unreceived_amount
From con_contract_cashflow ccc, From con_contract_cashflow ccc,
con_contract c, con_contract c,
...@@ -84,9 +84,13 @@ ...@@ -84,9 +84,13 @@
Where cwo.cashflow_id = ccc.cashflow_id Where cwo.cashflow_id = ccc.cashflow_id
And ccc.contract_id = c.contract_id And ccc.contract_id = c.contract_id
And cwo.csh_transaction_id = t.transaction_id And cwo.csh_transaction_id = t.transaction_id
And nvl(cwo.reversed_flag, &apos;N&apos;) = &apos;N&apos; And nvl(cwo.reversed_flag, 'N') = 'N'
And ccc.cf_direction = &apos;INFLOW&apos; And ((ccc.cf_direction = 'INFLOW' And
And ccc.cf_status = &apos;RELEASE&apos; ccc.cf_status = 'RELEASE') Or
(c.contract_status In ('REPURING', 'REPUR') And
ccc.cf_direction = 'NONCASH' And
ccc.cf_status = 'BLOCK' And
nvl(ccc.write_off_flag, 'NOT') != 'NOT'))
And ccc.cf_item Not In (0, 9) And ccc.cf_item Not In (0, 9)
And c.contract_id = #{contractId} And c.contract_id = #{contractId}
Order By ccc.times, Order By ccc.times,
...@@ -102,8 +106,14 @@ ...@@ -102,8 +106,14 @@
Where ccn.contract_id = ccc.contract_id Where ccn.contract_id = ccc.contract_id
And ccn.times = ccc.times And ccn.times = ccc.times
And ccn.cf_item In (1, 250) And ccn.cf_item In (1, 250)
And ccn.cf_direction = &apos;INFLOW&apos; And ((ccn.cf_direction = 'INFLOW' And
And ccn.cf_status = &apos;RELEASE&apos;) As cf_item, ccn.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
ccn.cf_direction = 'NONCASH' And
ccn.cf_status = 'BLOCK' And
nvl(ccn.write_off_flag, 'NOT') !=
'NOT'))) As cf_item,
(Select h.description (Select h.description
From hls_cashflow_item h, From hls_cashflow_item h,
con_contract_cashflow ccn con_contract_cashflow ccn
...@@ -111,26 +121,34 @@ ...@@ -111,26 +121,34 @@
And ccn.contract_id = ccc.contract_id And ccn.contract_id = ccc.contract_id
And ccn.times = ccc.times And ccn.times = ccc.times
And ccn.cf_item In (1, 250) And ccn.cf_item In (1, 250)
And ccn.cf_direction = &apos;INFLOW&apos; And ((ccn.cf_direction = 'INFLOW' And
And ccn.cf_status = &apos;RELEASE&apos;) cf_item_n, ccn.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
ccn.cf_direction = 'NONCASH' And
ccn.cf_status = 'BLOCK' And
nvl(ccn.write_off_flag, 'NOT') !=
'NOT'))) cf_item_n,
ccc.times, ccc.times,
to_char(ccc.due_date, &apos;yyyy-mm-dd&apos;) due_date, to_char(ccc.due_date, 'yyyy-mm-dd') due_date,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id = cwo.cashflow_id
And tn.creation_date &lt;= cwo.creation_date), And tn.creation_date <=
cwo.creation_date),
0) + cwo.write_off_due_amount) As due_amount, 0) + cwo.write_off_due_amount) As due_amount,
--收款日 --收款日
to_char(t.transaction_date, &apos;yyyy-mm-dd&apos;) transaction_date, to_char(t.transaction_date, 'yyyy-mm-dd') transaction_date,
to_char(cwo.write_off_date, &apos;yyyy-mm-dd&apos;) write_off_date, to_char(cwo.write_off_date, 'yyyy-mm-dd') write_off_date,
--实收金额 --实收金额
cwo.write_off_due_amount received_amount, cwo.write_off_due_amount received_amount,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id = cwo.cashflow_id
And tn.creation_date &lt;= cwo.creation_date), And tn.creation_date <=
cwo.creation_date),
0)) As unreceived_amount 0)) As unreceived_amount
From con_contract_cashflow ccc, From con_contract_cashflow ccc,
con_contract c, con_contract c,
...@@ -139,9 +157,13 @@ ...@@ -139,9 +157,13 @@
Where cwo.cashflow_id = ccc.cashflow_id Where cwo.cashflow_id = ccc.cashflow_id
And ccc.contract_id = c.contract_id And ccc.contract_id = c.contract_id
And cwo.csh_transaction_id = t.transaction_id And cwo.csh_transaction_id = t.transaction_id
And nvl(cwo.reversed_flag, &apos;N&apos;) = &apos;N&apos; And nvl(cwo.reversed_flag, 'N') = 'N'
And ccc.cf_direction = &apos;INFLOW&apos; And ((ccc.cf_direction = 'INFLOW' And
And ccc.cf_status = &apos;RELEASE&apos; ccc.cf_status = 'RELEASE') Or
(c.contract_status In ('REPURING', 'REPUR') And
ccc.cf_direction = 'NONCASH' And
ccc.cf_status = 'BLOCK' And
nvl(ccc.write_off_flag, 'NOT') != 'NOT'))
And ccc.cf_item = 9 And ccc.cf_item = 9
And c.contract_id = #{contractId} And c.contract_id = #{contractId}
Order By ccc.times, Order By ccc.times,
...@@ -162,28 +184,44 @@ ...@@ -162,28 +184,44 @@
Where cc2.contract_id = t2.contract_id Where cc2.contract_id = t2.contract_id
And cc2.times = t2.times And cc2.times = t2.times
And cc2.cf_item Not In (0, 9) And cc2.cf_item Not In (0, 9)
And cc2.cf_direction = &apos;INFLOW&apos; And ((cc2.cf_direction = 'INFLOW' And
And cc2.cf_status = &apos;RELEASE&apos; cc2.cf_status = 'RELEASE') Or
(t2.contract_status In
('REPURING', 'REPUR') And
cc2.cf_direction = 'NONCASH' And
cc2.cf_status = 'BLOCK' And
nvl(cc2.write_off_flag, 'NOT') != 'NOT'))
And rownum = 1)) cf_item, And rownum = 1)) cf_item,
nvl(t1.cf_item_n, nvl(t1.cf_item_n,
(Select h.description (Select h.description
From con_contract_cashflow cc2, hls_cashflow_item h From con_contract_cashflow cc2,
hls_cashflow_item h
Where cc2.contract_id = t2.contract_id Where cc2.contract_id = t2.contract_id
And cc2.times = t2.times And cc2.times = t2.times
And cc2.cf_item Not In (0, 9) And cc2.cf_item Not In (0, 9)
And cc2.cf_direction = &apos;INFLOW&apos; And ((cc2.cf_direction = 'INFLOW' And
And cc2.cf_status = &apos;RELEASE&apos; cc2.cf_status = 'RELEASE') Or
(t2.contract_status In
('REPURING', 'REPUR') And
cc2.cf_direction = 'NONCASH' And
cc2.cf_status = 'BLOCK' And
nvl(cc2.write_off_flag, 'NOT') != 'NOT'))
And h.cf_item = cc2.cf_item And h.cf_item = cc2.cf_item
And rownum = 1)) cf_item_n, And rownum = 1)) cf_item_n,
nvl(t1.times, t2.times) As times, nvl(t1.times, t2.times) As times,
nvl(t1.due_date, nvl(t1.due_date,
(Select to_char(cc2.due_date, &apos;yyyy-mm-dd&apos;) (Select to_char(cc2.due_date, 'yyyy-mm-dd')
From con_contract_cashflow cc2 From con_contract_cashflow cc2
Where cc2.contract_id = t2.contract_id Where cc2.contract_id = t2.contract_id
And cc2.times = t2.times And cc2.times = t2.times
And cc2.cf_item Not In (0, 9) And cc2.cf_item Not In (0, 9)
And cc2.cf_direction = &apos;INFLOW&apos; And ((cc2.cf_direction = 'INFLOW' And
And cc2.cf_status = &apos;RELEASE&apos; cc2.cf_status = 'RELEASE') Or
(t2.contract_status In
('REPURING', 'REPUR') And
cc2.cf_direction = 'NONCASH' And
cc2.cf_status = 'BLOCK' And
nvl(cc2.write_off_flag, 'NOT') != 'NOT'))
And rownum = 1)) due_date, And rownum = 1)) due_date,
nvl(t1.due_amount, nvl(t1.due_amount,
(Select cc2.due_amount (Select cc2.due_amount
...@@ -191,17 +229,28 @@ ...@@ -191,17 +229,28 @@
Where cc2.contract_id = t2.contract_id Where cc2.contract_id = t2.contract_id
And cc2.times = t2.times And cc2.times = t2.times
And cc2.cf_item Not In (0, 9) And cc2.cf_item Not In (0, 9)
And cc2.cf_direction = &apos;INFLOW&apos; And ((cc2.cf_direction = 'INFLOW' And
And cc2.cf_status = &apos;RELEASE&apos; cc2.cf_status = 'RELEASE') Or
And rownum = 1) - nvl((Select nvl(Sum(cc2.received_amount), 0) (t2.contract_status In
('REPURING', 'REPUR') And
cc2.cf_direction = 'NONCASH' And
cc2.cf_status = 'BLOCK' And
nvl(cc2.write_off_flag, 'NOT') != 'NOT'))
And rownum = 1) -
nvl((Select nvl(Sum(cc2.received_amount), 0)
From con_contract_cashflow cc2 From con_contract_cashflow cc2
Where cc2.contract_id = t2.contract_id Where cc2.contract_id = t2.contract_id
And cc2.times = t2.times And cc2.times = t2.times
And cc2.cf_item Not In (0, 9) And cc2.cf_item Not In (0, 9)
And cc2.cf_direction = &apos;INFLOW&apos; And ((cc2.cf_direction = 'INFLOW' And
And cc2.cf_status = &apos;RELEASE&apos;), cc2.cf_status = 'RELEASE') Or
(t2.contract_status In
('REPURING', 'REPUR') And
cc2.cf_direction = 'NONCASH' And
cc2.cf_status = 'BLOCK' And
nvl(cc2.write_off_flag, 'NOT') !=
'NOT'))),
0)) As due_amount, 0)) As due_amount,
nvl(t1.transaction_date, t2.transaction_date) transaction_date, nvl(t1.transaction_date, t2.transaction_date) transaction_date,
nvl(t1.write_off_date, t2.write_off_date) write_off_date, nvl(t1.write_off_date, t2.write_off_date) write_off_date,
nvl(t1.received_amount, 0) As received_amount, nvl(t1.received_amount, 0) As received_amount,
...@@ -211,15 +260,27 @@ ...@@ -211,15 +260,27 @@
Where cc2.contract_id = t2.contract_id Where cc2.contract_id = t2.contract_id
And cc2.times = t2.times And cc2.times = t2.times
And cc2.cf_item Not In (0, 9) And cc2.cf_item Not In (0, 9)
And cc2.cf_direction = &apos;INFLOW&apos; And ((cc2.cf_direction = 'INFLOW' And
And cc2.cf_status = &apos;RELEASE&apos; cc2.cf_status = 'RELEASE') Or
And rownum = 1) - nvl((Select nvl(Sum(cc2.received_amount), 0) (t2.contract_status In
('REPURING', 'REPUR') And
cc2.cf_direction = 'NONCASH' And
cc2.cf_status = 'BLOCK' And
nvl(cc2.write_off_flag, 'NOT') != 'NOT'))
And rownum = 1) -
nvl((Select nvl(Sum(cc2.received_amount), 0)
From con_contract_cashflow cc2 From con_contract_cashflow cc2
Where cc2.contract_id = t2.contract_id Where cc2.contract_id = t2.contract_id
And cc2.times = t2.times And cc2.times = t2.times
And cc2.cf_item Not In (0, 9) And cc2.cf_item Not In (0, 9)
And cc2.cf_direction = &apos;INFLOW&apos; And ((cc2.cf_direction = 'INFLOW' And
And cc2.cf_status = &apos;RELEASE&apos;), cc2.cf_status = 'RELEASE') Or
(t2.contract_status In
('REPURING', 'REPUR') And
cc2.cf_direction = 'NONCASH' And
cc2.cf_status = 'BLOCK' And
nvl(cc2.write_off_flag, 'NOT') !=
'NOT'))),
0)) As unreceived_amount, 0)) As unreceived_amount,
t2.times As times_9, t2.times As times_9,
nvl(t2.due_amount, 0) As due_amount_9, nvl(t2.due_amount, 0) As due_amount_9,
...@@ -227,6 +288,7 @@ ...@@ -227,6 +288,7 @@
nvl(t2.unreceived_amount, 0) As unreceived_amount_9 nvl(t2.unreceived_amount, 0) As unreceived_amount_9
From (Select From (Select
c.contract_id, c.contract_id,
c.contract_status,
cwo.cashflow_id, cwo.cashflow_id,
cwo.write_off_id, cwo.write_off_id,
ccc.cf_item, ccc.cf_item,
...@@ -234,23 +296,25 @@ ...@@ -234,23 +296,25 @@
From hls_cashflow_item h From hls_cashflow_item h
Where h.cf_item = ccc.cf_item) cf_item_n, Where h.cf_item = ccc.cf_item) cf_item_n,
ccc.times, ccc.times,
to_char(ccc.due_date, &apos;yyyy-mm-dd&apos;) due_date, to_char(ccc.due_date, 'yyyy-mm-dd') due_date,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id = cwo.cashflow_id
And tn.creation_date &lt;= cwo.creation_date), And tn.creation_date <=
cwo.creation_date),
0) + cwo.write_off_due_amount) As due_amount, 0) + cwo.write_off_due_amount) As due_amount,
--收款日 --收款日
to_char(t.transaction_date, &apos;yyyy-mm-dd&apos;) transaction_date, to_char(t.transaction_date, 'yyyy-mm-dd') transaction_date,
to_char(cwo.write_off_date, &apos;yyyy-mm-dd&apos;) write_off_date, to_char(cwo.write_off_date, 'yyyy-mm-dd') write_off_date,
--实收金额 --实收金额
cwo.write_off_due_amount received_amount, cwo.write_off_due_amount received_amount,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id = cwo.cashflow_id
And tn.creation_date &lt;= cwo.creation_date), And tn.creation_date <=
cwo.creation_date),
0)) As unreceived_amount 0)) As unreceived_amount
From con_contract_cashflow ccc, From con_contract_cashflow ccc,
con_contract c, con_contract c,
...@@ -260,10 +324,14 @@ ...@@ -260,10 +324,14 @@
Where cwo.cashflow_id = ccc.cashflow_id Where cwo.cashflow_id = ccc.cashflow_id
And ccc.contract_id = c.contract_id And ccc.contract_id = c.contract_id
And cwo.csh_transaction_id = t.transaction_id And cwo.csh_transaction_id = t.transaction_id
And nvl(cwo.reversed_flag, &apos;N&apos;) = &apos;N&apos; And nvl(cwo.reversed_flag, 'N') = 'N'
And h.bp_id = c.bp_id_tenant And h.bp_id = c.bp_id_tenant
And ccc.cf_direction = &apos;INFLOW&apos; And ((ccc.cf_direction = 'INFLOW' And
And ccc.cf_status = &apos;RELEASE&apos; ccc.cf_status = 'RELEASE') Or
(c.contract_status In ('REPURING', 'REPUR') And
ccc.cf_direction = 'NONCASH' And
ccc.cf_status = 'BLOCK' And
nvl(ccc.write_off_flag, 'NOT') != 'NOT'))
And ccc.cf_item Not In (0, 9) And ccc.cf_item Not In (0, 9)
And c.contract_id = #{contractId} And c.contract_id = #{contractId}
Order By ccc.times, Order By ccc.times,
...@@ -272,6 +340,7 @@ ...@@ -272,6 +340,7 @@
cwo.write_off_id) t1, cwo.write_off_id) t1,
(Select (Select
c.contract_id, c.contract_id,
c.contract_status,
cwo.cashflow_id, cwo.cashflow_id,
cwo.write_off_id, cwo.write_off_id,
(Select ccn.cf_item (Select ccn.cf_item
...@@ -279,8 +348,14 @@ ...@@ -279,8 +348,14 @@
Where ccn.contract_id = ccc.contract_id Where ccn.contract_id = ccc.contract_id
And ccn.times = ccc.times And ccn.times = ccc.times
And ccn.cf_item In (1, 250) And ccn.cf_item In (1, 250)
And ccn.cf_direction = &apos;INFLOW&apos; And ((ccn.cf_direction = 'INFLOW' And
And ccn.cf_status = &apos;RELEASE&apos;) As cf_item, ccn.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
ccn.cf_direction = 'NONCASH' And
ccn.cf_status = 'BLOCK' And
nvl(ccn.write_off_flag, 'NOT') !=
'NOT'))) As cf_item,
(Select h.description (Select h.description
From hls_cashflow_item h, From hls_cashflow_item h,
con_contract_cashflow ccn con_contract_cashflow ccn
...@@ -288,26 +363,34 @@ ...@@ -288,26 +363,34 @@
And ccn.contract_id = ccc.contract_id And ccn.contract_id = ccc.contract_id
And ccn.times = ccc.times And ccn.times = ccc.times
And ccn.cf_item In (1, 250) And ccn.cf_item In (1, 250)
And ccn.cf_direction = &apos;INFLOW&apos; And ((ccn.cf_direction = 'INFLOW' And
And ccn.cf_status = &apos;RELEASE&apos;) cf_item_n, ccn.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
ccn.cf_direction = 'NONCASH' And
ccn.cf_status = 'BLOCK' And
nvl(ccn.write_off_flag, 'NOT') !=
'NOT'))) cf_item_n,
ccc.times, ccc.times,
to_char(ccc.due_date, &apos;yyyy-mm-dd&apos;) due_date, to_char(ccc.due_date, 'yyyy-mm-dd') due_date,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id = cwo.cashflow_id
And tn.creation_date &lt;= cwo.creation_date), And tn.creation_date <=
cwo.creation_date),
0) + cwo.write_off_due_amount) As due_amount, 0) + cwo.write_off_due_amount) As due_amount,
--收款日 --收款日
to_char(t.transaction_date, &apos;yyyy-mm-dd&apos;) transaction_date, to_char(t.transaction_date, 'yyyy-mm-dd') transaction_date,
to_char(cwo.write_off_date, &apos;yyyy-mm-dd&apos;) write_off_date, to_char(cwo.write_off_date, 'yyyy-mm-dd') write_off_date,
--实收金额 --实收金额
cwo.write_off_due_amount received_amount, cwo.write_off_due_amount received_amount,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id = cwo.cashflow_id
And tn.creation_date &lt;= cwo.creation_date), And tn.creation_date <=
cwo.creation_date),
0)) As unreceived_amount 0)) As unreceived_amount
From con_contract_cashflow ccc, From con_contract_cashflow ccc,
con_contract c, con_contract c,
...@@ -316,9 +399,13 @@ ...@@ -316,9 +399,13 @@
Where cwo.cashflow_id = ccc.cashflow_id Where cwo.cashflow_id = ccc.cashflow_id
And ccc.contract_id = c.contract_id And ccc.contract_id = c.contract_id
And cwo.csh_transaction_id = t.transaction_id And cwo.csh_transaction_id = t.transaction_id
And nvl(cwo.reversed_flag, &apos;N&apos;) = &apos;N&apos; And nvl(cwo.reversed_flag, 'N') = 'N'
And ccc.cf_direction = &apos;INFLOW&apos; And ((ccc.cf_direction = 'INFLOW' And
And ccc.cf_status = &apos;RELEASE&apos; ccc.cf_status = 'RELEASE') Or
(c.contract_status In ('REPURING', 'REPUR') And
ccc.cf_direction = 'NONCASH' And
ccc.cf_status = 'BLOCK' And
nvl(ccc.write_off_flag, 'NOT') != 'NOT'))
And ccc.cf_item = 9 And ccc.cf_item = 9
And c.contract_id = #{contractId} And c.contract_id = #{contractId}
Order By ccc.times, Order By ccc.times,
...@@ -329,7 +416,6 @@ ...@@ -329,7 +416,6 @@
And t1.times (+) = t2.times And t1.times (+) = t2.times
And t1.cf_item (+) = t2.cf_item And t1.cf_item (+) = t2.cf_item
Union Union
Select Select
ccc.contract_id, ccc.contract_id,
ccc.cashflow_id, ccc.cashflow_id,
...@@ -339,63 +425,85 @@ ...@@ -339,63 +425,85 @@
From hls_cashflow_item h From hls_cashflow_item h
Where h.cf_item = ccc.cf_item) cf_item_n, Where h.cf_item = ccc.cf_item) cf_item_n,
ccc.times, ccc.times,
to_char(ccc.due_date, &apos;yyyy-mm-dd&apos;) due_date, to_char(ccc.due_date, 'yyyy-mm-dd') due_date,
ccc.due_amount, ccc.due_amount,
&apos;&apos; transaction_date, '' transaction_date,
&apos;&apos; write_off_date, '' write_off_date,
nvl(ccc.received_amount, 0) received_amount, nvl(ccc.received_amount, 0) received_amount,
(ccc.due_amount - nvl(ccc.received_amount, 0)) unreceived_amount, (ccc.due_amount - nvl(ccc.received_amount, 0)) unreceived_amount,
(Select cc1.times (Select cc1.times
From con_contract_cashflow cc1 From con_contract_cashflow cc1
Where cc1.contract_id = ccc.contract_id Where cc1.contract_id = ccc.contract_id
And cc1.times = ccc.times And cc1.times = ccc.times
And cc1.cf_direction = &apos;INFLOW&apos; And ((cc1.cf_direction = 'INFLOW' And
And cc1.cf_status = &apos;RELEASE&apos; cc1.cf_status = 'RELEASE') Or
(c.contract_status In ('REPURING', 'REPUR') And
cc1.cf_direction = 'NONCASH' And
cc1.cf_status = 'BLOCK' And
nvl(cc1.write_off_flag, 'NOT') != 'NOT'))
And cc1.cf_item = 9) As times_9, And cc1.cf_item = 9) As times_9,
(Select cc1.due_amount (Select cc1.due_amount
From con_contract_cashflow cc1 From con_contract_cashflow cc1
Where cc1.contract_id = ccc.contract_id Where cc1.contract_id = ccc.contract_id
And cc1.times = ccc.times And cc1.times = ccc.times
And cc1.cf_direction = &apos;INFLOW&apos; And ((cc1.cf_direction = 'INFLOW' And
And cc1.cf_status = &apos;RELEASE&apos; cc1.cf_status = 'RELEASE') Or
(c.contract_status In ('REPURING', 'REPUR') And
cc1.cf_direction = 'NONCASH' And
cc1.cf_status = 'BLOCK' And
nvl(cc1.write_off_flag, 'NOT') != 'NOT'))
And cc1.cf_item = 9) As due_amount_9, And cc1.cf_item = 9) As due_amount_9,
(Select nvl(cc1.received_amount, 0) (Select nvl(cc1.received_amount, 0)
From con_contract_cashflow cc1 From con_contract_cashflow cc1
Where cc1.contract_id = ccc.contract_id Where cc1.contract_id = ccc.contract_id
And cc1.times = ccc.times And cc1.times = ccc.times
And cc1.cf_direction = &apos;INFLOW&apos; And ((cc1.cf_direction = 'INFLOW' And
And cc1.cf_status = &apos;RELEASE&apos; cc1.cf_status = 'RELEASE') Or
(c.contract_status In ('REPURING', 'REPUR') And
cc1.cf_direction = 'NONCASH' And
cc1.cf_status = 'BLOCK' And
nvl(cc1.write_off_flag, 'NOT') != 'NOT'))
And cc1.cf_item = 9) As received_amount_9, And cc1.cf_item = 9) As received_amount_9,
(Select cc1.due_amount - nvl(cc1.received_amount, 0) (Select cc1.due_amount - nvl(cc1.received_amount, 0)
From con_contract_cashflow cc1 From con_contract_cashflow cc1
Where cc1.contract_id = ccc.contract_id Where cc1.contract_id = ccc.contract_id
And cc1.times = ccc.times And cc1.times = ccc.times
And cc1.cf_direction = &apos;INFLOW&apos; And ((cc1.cf_direction = 'INFLOW' And
And cc1.cf_status = &apos;RELEASE&apos; cc1.cf_status = 'RELEASE') Or
(c.contract_status In ('REPURING', 'REPUR') And
cc1.cf_direction = 'NONCASH' And
cc1.cf_status = 'BLOCK' And
nvl(cc1.write_off_flag, 'NOT') != 'NOT'))
And cc1.cf_item = 9) unreceived_amount_9 And cc1.cf_item = 9) unreceived_amount_9
From con_contract_cashflow ccc From con_contract_cashflow ccc, con_contract c
Where ccc.contract_id = #{contractId} Where ccc.contract_id = #{contractId}
And ccc.cf_direction = &apos;INFLOW&apos; And ccc.contract_id = c.contract_id
And ccc.cf_status = &apos;RELEASE&apos; And ((ccc.cf_direction = 'INFLOW' And
ccc.cf_status = 'RELEASE') Or
(c.contract_status In ('REPURING', 'REPUR') And
ccc.cf_direction = 'NONCASH' And
ccc.cf_status = 'BLOCK' And
nvl(ccc.write_off_flag, 'NOT') != 'NOT'))
And ccc.cf_item Not In (0, 9) And ccc.cf_item Not In (0, 9)
And ccc.times &gt; And ccc.times >
nvl((Select Max(cc2.times) nvl((Select Max(cc2.times)
From con_contract_cashflow cc2 From con_contract_cashflow cc2
Where cc2.contract_id = ccc.contract_id Where cc2.contract_id = ccc.contract_id
And cc2.cf_item &lt;&gt; 0 And cc2.cf_item != 0
And nvl(cc2.received_amount, 0) &lt;&gt; 0), -1) And nvl(cc2.received_amount, 0) != 0),
-1)
Union Union
Select Select
Null contract_id, Null contract_id,
Null cashflow_id, Null cashflow_id,
Null write_off_id, Null write_off_id,
100 cf_item, 100 cf_item,
&apos;合计&apos; cf_item_n, '合计' cf_item_n,
Null times, Null times,
&apos;&apos; due_date, '' due_date,
Sum(due_amount) due_amount, Sum(due_amount) due_amount,
&apos;&apos; transaction_date, '' transaction_date,
&apos;&apos; write_off_date, '' write_off_date,
Sum(received_amount) received_amount, Sum(received_amount) received_amount,
Sum(unreceived_amount) unreceived_amount, Sum(unreceived_amount) unreceived_amount,
Null times_9, Null times_9,
...@@ -412,30 +520,31 @@ ...@@ -412,30 +520,31 @@
c.contract_id, c.contract_id,
cwo.cashflow_id, cwo.cashflow_id,
cwo.write_off_id, cwo.write_off_id,
ccc.cf_item, ccc.cf_item,
(Select h.description (Select h.description
From hls_cashflow_item h From hls_cashflow_item h
Where h.cf_item = ccc.cf_item) cf_item_n, Where h.cf_item = ccc.cf_item) cf_item_n,
ccc.times, ccc.times,
to_char(ccc.due_date, &apos;yyyy-mm-dd&apos;) due_date, to_char(ccc.due_date, 'yyyy-mm-dd') due_date,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id =
And tn.creation_date &lt;= cwo.cashflow_id
And tn.creation_date <=
cwo.creation_date), cwo.creation_date),
0) + cwo.write_off_due_amount) As due_amount, 0) + cwo.write_off_due_amount) As due_amount,
--收款日 --收款日
to_char(t.transaction_date, &apos;yyyy-mm-dd&apos;) transaction_date, to_char(t.transaction_date, 'yyyy-mm-dd') transaction_date,
to_char(cwo.write_off_date, &apos;yyyy-mm-dd&apos;) write_off_date, to_char(cwo.write_off_date, 'yyyy-mm-dd') write_off_date,
--实收金额 --实收金额
cwo.write_off_due_amount received_amount, cwo.write_off_due_amount received_amount,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id =
And tn.creation_date &lt;= cwo.cashflow_id
And tn.creation_date <=
cwo.creation_date), cwo.creation_date),
0)) As unreceived_amount 0)) As unreceived_amount
From con_contract_cashflow ccc, From con_contract_cashflow ccc,
...@@ -444,10 +553,17 @@ ...@@ -444,10 +553,17 @@
csh_transaction t csh_transaction t
Where cwo.cashflow_id = ccc.cashflow_id Where cwo.cashflow_id = ccc.cashflow_id
And ccc.contract_id = c.contract_id And ccc.contract_id = c.contract_id
And cwo.csh_transaction_id = t.transaction_id And cwo.csh_transaction_id =
And nvl(cwo.reversed_flag, &apos;N&apos;) = &apos;N&apos; t.transaction_id
And ccc.cf_direction = &apos;INFLOW&apos; And nvl(cwo.reversed_flag, 'N') = 'N'
And ccc.cf_status = &apos;RELEASE&apos; And ((ccc.cf_direction = 'INFLOW' And
ccc.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
ccc.cf_direction = 'NONCASH' And
ccc.cf_status = 'BLOCK' And
nvl(ccc.write_off_flag, 'NOT') !=
'NOT'))
And ccc.cf_item Not In (0, 9) And ccc.cf_item Not In (0, 9)
And c.contract_id = #{contractId} And c.contract_id = #{contractId}
Order By ccc.times, Order By ccc.times,
...@@ -458,14 +574,19 @@ ...@@ -458,14 +574,19 @@
c.contract_id, c.contract_id,
cwo.cashflow_id, cwo.cashflow_id,
cwo.write_off_id, cwo.write_off_id,
(Select ccn.cf_item (Select ccn.cf_item
From con_contract_cashflow ccn From con_contract_cashflow ccn
Where ccn.contract_id = ccc.contract_id Where ccn.contract_id = ccc.contract_id
And ccn.times = ccc.times And ccn.times = ccc.times
And ccn.cf_item In (1, 250) And ccn.cf_item In (1, 250)
And ccn.cf_direction = &apos;INFLOW&apos; And ((ccn.cf_direction = 'INFLOW' And
And ccn.cf_status = &apos;RELEASE&apos;) As cf_item, ccn.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
ccn.cf_direction = 'NONCASH' And
ccn.cf_status = 'BLOCK' And
nvl(ccn.write_off_flag, 'NOT') !=
'NOT'))) As cf_item,
(Select h.description (Select h.description
From hls_cashflow_item h, From hls_cashflow_item h,
con_contract_cashflow ccn con_contract_cashflow ccn
...@@ -473,27 +594,35 @@ ...@@ -473,27 +594,35 @@
And ccn.contract_id = ccc.contract_id And ccn.contract_id = ccc.contract_id
And ccn.times = ccc.times And ccn.times = ccc.times
And ccn.cf_item In (1, 250) And ccn.cf_item In (1, 250)
And ccn.cf_direction = &apos;INFLOW&apos; And ((ccn.cf_direction = 'INFLOW' And
And ccn.cf_status = &apos;RELEASE&apos;) cf_item_n, ccn.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
ccn.cf_direction = 'NONCASH' And
ccn.cf_status = 'BLOCK' And
nvl(ccn.write_off_flag, 'NOT') !=
'NOT'))) cf_item_n,
ccc.times, ccc.times,
to_char(ccc.due_date, &apos;yyyy-mm-dd&apos;) due_date, to_char(ccc.due_date, 'yyyy-mm-dd') due_date,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id =
And tn.creation_date &lt;= cwo.cashflow_id
And tn.creation_date <=
cwo.creation_date), cwo.creation_date),
0) + cwo.write_off_due_amount) As due_amount, 0) + cwo.write_off_due_amount) As due_amount,
--收款日 --收款日
to_char(t.transaction_date, &apos;yyyy-mm-dd&apos;) transaction_date, to_char(t.transaction_date, 'yyyy-mm-dd') transaction_date,
to_char(cwo.write_off_date, &apos;yyyy-mm-dd&apos;) write_off_date, to_char(cwo.write_off_date, 'yyyy-mm-dd') write_off_date,
--实收金额 --实收金额
cwo.write_off_due_amount received_amount, cwo.write_off_due_amount received_amount,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id =
And tn.creation_date &lt;= cwo.cashflow_id
And tn.creation_date <=
cwo.creation_date), cwo.creation_date),
0)) As unreceived_amount 0)) As unreceived_amount
From con_contract_cashflow ccc, From con_contract_cashflow ccc,
...@@ -502,10 +631,17 @@ ...@@ -502,10 +631,17 @@
csh_transaction t csh_transaction t
Where cwo.cashflow_id = ccc.cashflow_id Where cwo.cashflow_id = ccc.cashflow_id
And ccc.contract_id = c.contract_id And ccc.contract_id = c.contract_id
And cwo.csh_transaction_id = t.transaction_id And cwo.csh_transaction_id =
And nvl(cwo.reversed_flag, &apos;N&apos;) = &apos;N&apos; t.transaction_id
And ccc.cf_direction = &apos;INFLOW&apos; And nvl(cwo.reversed_flag, 'N') = 'N'
And ccc.cf_status = &apos;RELEASE&apos; And ((ccc.cf_direction = 'INFLOW' And
ccc.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
ccc.cf_direction = 'NONCASH' And
ccc.cf_status = 'BLOCK' And
nvl(ccc.write_off_flag, 'NOT') !=
'NOT'))
And ccc.cf_item = 9 And ccc.cf_item = 9
And c.contract_id = #{contractId} And c.contract_id = #{contractId}
Order By ccc.times, Order By ccc.times,
...@@ -526,28 +662,47 @@ ...@@ -526,28 +662,47 @@
Where cc2.contract_id = t2.contract_id Where cc2.contract_id = t2.contract_id
And cc2.times = t2.times And cc2.times = t2.times
And cc2.cf_item Not In (0, 9) And cc2.cf_item Not In (0, 9)
And cc2.cf_direction = &apos;INFLOW&apos; And ((cc2.cf_direction = 'INFLOW' And
And cc2.cf_status = &apos;RELEASE&apos; cc2.cf_status = 'RELEASE') Or
(t2.contract_status In
('REPURING', 'REPUR') And
cc2.cf_direction = 'NONCASH' And
cc2.cf_status = 'BLOCK' And
nvl(cc2.write_off_flag, 'NOT') !=
'NOT'))
And rownum = 1)) cf_item, And rownum = 1)) cf_item,
nvl(t1.cf_item_n, nvl(t1.cf_item_n,
(Select h.description (Select h.description
From con_contract_cashflow cc2, hls_cashflow_item h From con_contract_cashflow cc2,
hls_cashflow_item h
Where cc2.contract_id = t2.contract_id Where cc2.contract_id = t2.contract_id
And cc2.times = t2.times And cc2.times = t2.times
And cc2.cf_item Not In (0, 9) And cc2.cf_item Not In (0, 9)
And cc2.cf_direction = &apos;INFLOW&apos; And ((cc2.cf_direction = 'INFLOW' And
And cc2.cf_status = &apos;RELEASE&apos; cc2.cf_status = 'RELEASE') Or
(t2.contract_status In
('REPURING', 'REPUR') And
cc2.cf_direction = 'NONCASH' And
cc2.cf_status = 'BLOCK' And
nvl(cc2.write_off_flag, 'NOT') !=
'NOT'))
And h.cf_item = cc2.cf_item And h.cf_item = cc2.cf_item
And rownum = 1)) cf_item_n, And rownum = 1)) cf_item_n,
nvl(t1.times, t2.times) As times, nvl(t1.times, t2.times) As times,
nvl(t1.due_date, nvl(t1.due_date,
(Select to_char(cc2.due_date, &apos;yyyy-mm-dd&apos;) (Select to_char(cc2.due_date, 'yyyy-mm-dd')
From con_contract_cashflow cc2 From con_contract_cashflow cc2
Where cc2.contract_id = t2.contract_id Where cc2.contract_id = t2.contract_id
And cc2.times = t2.times And cc2.times = t2.times
And cc2.cf_item Not In (0, 9) And cc2.cf_item Not In (0, 9)
And cc2.cf_direction = &apos;INFLOW&apos; And ((cc2.cf_direction = 'INFLOW' And
And cc2.cf_status = &apos;RELEASE&apos; cc2.cf_status = 'RELEASE') Or
(t2.contract_status In
('REPURING', 'REPUR') And
cc2.cf_direction = 'NONCASH' And
cc2.cf_status = 'BLOCK' And
nvl(cc2.write_off_flag, 'NOT') !=
'NOT'))
And rownum = 1)) due_date, And rownum = 1)) due_date,
nvl(t1.due_amount, nvl(t1.due_amount,
(Select cc2.due_amount (Select cc2.due_amount
...@@ -555,17 +710,29 @@ ...@@ -555,17 +710,29 @@
Where cc2.contract_id = t2.contract_id Where cc2.contract_id = t2.contract_id
And cc2.times = t2.times And cc2.times = t2.times
And cc2.cf_item Not In (0, 9) And cc2.cf_item Not In (0, 9)
And cc2.cf_direction = &apos;INFLOW&apos; And ((cc2.cf_direction = 'INFLOW' And
And cc2.cf_status = &apos;RELEASE&apos; cc2.cf_status = 'RELEASE') Or
And rownum = 1) - nvl((Select nvl(Sum(cc2.received_amount), 0) (t2.contract_status In
('REPURING', 'REPUR') And
cc2.cf_direction = 'NONCASH' And
cc2.cf_status = 'BLOCK' And
nvl(cc2.write_off_flag, 'NOT') !=
'NOT'))
And rownum = 1) -
nvl((Select nvl(Sum(cc2.received_amount), 0)
From con_contract_cashflow cc2 From con_contract_cashflow cc2
Where cc2.contract_id = t2.contract_id Where cc2.contract_id = t2.contract_id
And cc2.times = t2.times And cc2.times = t2.times
And cc2.cf_item Not In (0, 9) And cc2.cf_item Not In (0, 9)
And cc2.cf_direction = &apos;INFLOW&apos; And ((cc2.cf_direction = 'INFLOW' And
And cc2.cf_status = &apos;RELEASE&apos;), cc2.cf_status = 'RELEASE') Or
(t2.contract_status In
('REPURING', 'REPUR') And
cc2.cf_direction = 'NONCASH' And
cc2.cf_status = 'BLOCK' And
nvl(cc2.write_off_flag, 'NOT') !=
'NOT'))),
0)) As due_amount, 0)) As due_amount,
nvl(t1.transaction_date, t2.transaction_date) transaction_date, nvl(t1.transaction_date, t2.transaction_date) transaction_date,
nvl(t1.write_off_date, t2.write_off_date) write_off_date, nvl(t1.write_off_date, t2.write_off_date) write_off_date,
nvl(t1.received_amount, 0) As received_amount, nvl(t1.received_amount, 0) As received_amount,
...@@ -575,15 +742,28 @@ ...@@ -575,15 +742,28 @@
Where cc2.contract_id = t2.contract_id Where cc2.contract_id = t2.contract_id
And cc2.times = t2.times And cc2.times = t2.times
And cc2.cf_item Not In (0, 9) And cc2.cf_item Not In (0, 9)
And cc2.cf_direction = &apos;INFLOW&apos; And ((cc2.cf_direction = 'INFLOW' And
And cc2.cf_status = &apos;RELEASE&apos; cc2.cf_status = 'RELEASE') Or
And rownum = 1) - nvl((Select nvl(Sum(cc2.received_amount), 0) (t2.contract_status In
('REPURING', 'REPUR') And
cc2.cf_direction = 'NONCASH' And
cc2.cf_status = 'BLOCK' And
nvl(cc2.write_off_flag, 'NOT') !=
'NOT'))
And rownum = 1) -
nvl((Select nvl(Sum(cc2.received_amount), 0)
From con_contract_cashflow cc2 From con_contract_cashflow cc2
Where cc2.contract_id = t2.contract_id Where cc2.contract_id = t2.contract_id
And cc2.times = t2.times And cc2.times = t2.times
And cc2.cf_item Not In (0, 9) And cc2.cf_item Not In (0, 9)
And cc2.cf_direction = &apos;INFLOW&apos; And ((cc2.cf_direction = 'INFLOW' And
And cc2.cf_status = &apos;RELEASE&apos;), cc2.cf_status = 'RELEASE') Or
(t2.contract_status In
('REPURING', 'REPUR') And
cc2.cf_direction = 'NONCASH' And
cc2.cf_status = 'BLOCK' And
nvl(cc2.write_off_flag, 'NOT') !=
'NOT'))),
0)) As unreceived_amount, 0)) As unreceived_amount,
t2.times As times_9, t2.times As times_9,
nvl(t2.due_amount, 0) As due_amount_9, nvl(t2.due_amount, 0) As due_amount_9,
...@@ -591,6 +771,7 @@ ...@@ -591,6 +771,7 @@
nvl(t2.unreceived_amount, 0) As unreceived_amount_9 nvl(t2.unreceived_amount, 0) As unreceived_amount_9
From (Select From (Select
c.contract_id, c.contract_id,
c.contract_status,
cwo.cashflow_id, cwo.cashflow_id,
cwo.write_off_id, cwo.write_off_id,
ccc.cf_item, ccc.cf_item,
...@@ -598,23 +779,27 @@ ...@@ -598,23 +779,27 @@
From hls_cashflow_item h From hls_cashflow_item h
Where h.cf_item = ccc.cf_item) cf_item_n, Where h.cf_item = ccc.cf_item) cf_item_n,
ccc.times, ccc.times,
to_char(ccc.due_date, &apos;yyyy-mm-dd&apos;) due_date, to_char(ccc.due_date, 'yyyy-mm-dd') due_date,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id =
And tn.creation_date &lt;= cwo.creation_date), cwo.cashflow_id
And tn.creation_date <=
cwo.creation_date),
0) + cwo.write_off_due_amount) As due_amount, 0) + cwo.write_off_due_amount) As due_amount,
--收款日 --收款日
to_char(t.transaction_date, &apos;yyyy-mm-dd&apos;) transaction_date, to_char(t.transaction_date, 'yyyy-mm-dd') transaction_date,
to_char(cwo.write_off_date, &apos;yyyy-mm-dd&apos;) write_off_date, to_char(cwo.write_off_date, 'yyyy-mm-dd') write_off_date,
--实收金额 --实收金额
cwo.write_off_due_amount received_amount, cwo.write_off_due_amount received_amount,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id =
And tn.creation_date &lt;= cwo.creation_date), cwo.cashflow_id
And tn.creation_date <=
cwo.creation_date),
0)) As unreceived_amount 0)) As unreceived_amount
From con_contract_cashflow ccc, From con_contract_cashflow ccc,
con_contract c, con_contract c,
...@@ -623,11 +808,18 @@ ...@@ -623,11 +808,18 @@
csh_transaction t csh_transaction t
Where cwo.cashflow_id = ccc.cashflow_id Where cwo.cashflow_id = ccc.cashflow_id
And ccc.contract_id = c.contract_id And ccc.contract_id = c.contract_id
And cwo.csh_transaction_id = t.transaction_id And cwo.csh_transaction_id =
And nvl(cwo.reversed_flag, &apos;N&apos;) = &apos;N&apos; t.transaction_id
And nvl(cwo.reversed_flag, 'N') = 'N'
And h.bp_id = c.bp_id_tenant And h.bp_id = c.bp_id_tenant
And ccc.cf_direction = &apos;INFLOW&apos; And ((ccc.cf_direction = 'INFLOW' And
And ccc.cf_status = &apos;RELEASE&apos; ccc.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
ccc.cf_direction = 'NONCASH' And
ccc.cf_status = 'BLOCK' And
nvl(ccc.write_off_flag, 'NOT') !=
'NOT'))
And ccc.cf_item Not In (0, 9) And ccc.cf_item Not In (0, 9)
And c.contract_id = #{contractId} And c.contract_id = #{contractId}
Order By ccc.times, Order By ccc.times,
...@@ -636,6 +828,7 @@ ...@@ -636,6 +828,7 @@
cwo.write_off_id) t1, cwo.write_off_id) t1,
(Select (Select
c.contract_id, c.contract_id,
c.contract_status,
cwo.cashflow_id, cwo.cashflow_id,
cwo.write_off_id, cwo.write_off_id,
(Select ccn.cf_item (Select ccn.cf_item
...@@ -643,8 +836,14 @@ ...@@ -643,8 +836,14 @@
Where ccn.contract_id = ccc.contract_id Where ccn.contract_id = ccc.contract_id
And ccn.times = ccc.times And ccn.times = ccc.times
And ccn.cf_item In (1, 250) And ccn.cf_item In (1, 250)
And ccn.cf_direction = &apos;INFLOW&apos; And ((ccn.cf_direction = 'INFLOW' And
And ccn.cf_status = &apos;RELEASE&apos;) As cf_item, ccn.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
ccn.cf_direction = 'NONCASH' And
ccn.cf_status = 'BLOCK' And
nvl(ccn.write_off_flag, 'NOT') !=
'NOT'))) As cf_item,
(Select h.description (Select h.description
From hls_cashflow_item h, From hls_cashflow_item h,
con_contract_cashflow ccn con_contract_cashflow ccn
...@@ -652,26 +851,36 @@ ...@@ -652,26 +851,36 @@
And ccn.contract_id = ccc.contract_id And ccn.contract_id = ccc.contract_id
And ccn.times = ccc.times And ccn.times = ccc.times
And ccn.cf_item In (1, 250) And ccn.cf_item In (1, 250)
And ccn.cf_direction = &apos;INFLOW&apos; And ((ccn.cf_direction = 'INFLOW' And
And ccn.cf_status = &apos;RELEASE&apos;) cf_item_n, ccn.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
ccn.cf_direction = 'NONCASH' And
ccn.cf_status = 'BLOCK' And
nvl(ccn.write_off_flag, 'NOT') !=
'NOT'))) cf_item_n,
ccc.times, ccc.times,
to_char(ccc.due_date, &apos;yyyy-mm-dd&apos;) due_date, to_char(ccc.due_date, 'yyyy-mm-dd') due_date,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id =
And tn.creation_date &lt;= cwo.creation_date), cwo.cashflow_id
And tn.creation_date <=
cwo.creation_date),
0) + cwo.write_off_due_amount) As due_amount, 0) + cwo.write_off_due_amount) As due_amount,
--收款日 --收款日
to_char(t.transaction_date, &apos;yyyy-mm-dd&apos;) transaction_date, to_char(t.transaction_date, 'yyyy-mm-dd') transaction_date,
to_char(cwo.write_off_date, &apos;yyyy-mm-dd&apos;) write_off_date, to_char(cwo.write_off_date, 'yyyy-mm-dd') write_off_date,
--实收金额 --实收金额
cwo.write_off_due_amount received_amount, cwo.write_off_due_amount received_amount,
(ccc.due_amount - (ccc.due_amount -
nvl((Select Sum(tn.write_off_due_amount) nvl((Select Sum(tn.write_off_due_amount)
From csh_write_off tn From csh_write_off tn
Where tn.cashflow_id = cwo.cashflow_id Where tn.cashflow_id =
And tn.creation_date &lt;= cwo.creation_date), cwo.cashflow_id
And tn.creation_date <=
cwo.creation_date),
0)) As unreceived_amount 0)) As unreceived_amount
From con_contract_cashflow ccc, From con_contract_cashflow ccc,
con_contract c, con_contract c,
...@@ -679,10 +888,17 @@ ...@@ -679,10 +888,17 @@
csh_transaction t csh_transaction t
Where cwo.cashflow_id = ccc.cashflow_id Where cwo.cashflow_id = ccc.cashflow_id
And ccc.contract_id = c.contract_id And ccc.contract_id = c.contract_id
And cwo.csh_transaction_id = t.transaction_id And cwo.csh_transaction_id =
And nvl(cwo.reversed_flag, &apos;N&apos;) = &apos;N&apos; t.transaction_id
And ccc.cf_direction = &apos;INFLOW&apos; And nvl(cwo.reversed_flag, 'N') = 'N'
And ccc.cf_status = &apos;RELEASE&apos; And ((ccc.cf_direction = 'INFLOW' And
ccc.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
ccc.cf_direction = 'NONCASH' And
ccc.cf_status = 'BLOCK' And
nvl(ccc.write_off_flag, 'NOT') !=
'NOT'))
And ccc.cf_item = 9 And ccc.cf_item = 9
And c.contract_id = #{contractId} And c.contract_id = #{contractId}
Order By ccc.times, Order By ccc.times,
...@@ -693,7 +909,6 @@ ...@@ -693,7 +909,6 @@
And t1.times (+) = t2.times And t1.times (+) = t2.times
And t1.cf_item (+) = t2.cf_item And t1.cf_item (+) = t2.cf_item
Union Union
Select Select
ccc.contract_id, ccc.contract_id,
ccc.cashflow_id, ccc.cashflow_id,
...@@ -703,52 +918,88 @@ ...@@ -703,52 +918,88 @@
From hls_cashflow_item h From hls_cashflow_item h
Where h.cf_item = ccc.cf_item) cf_item_n, Where h.cf_item = ccc.cf_item) cf_item_n,
ccc.times, ccc.times,
to_char(ccc.due_date, &apos;yyyy-mm-dd&apos;) due_date, to_char(ccc.due_date, 'yyyy-mm-dd') due_date,
ccc.due_amount, ccc.due_amount,
&apos;&apos; transaction_date, '' transaction_date,
&apos;&apos; write_off_date, '' write_off_date,
nvl(ccc.received_amount, 0) received_amount, nvl(ccc.received_amount, 0) received_amount,
(ccc.due_amount - nvl(ccc.received_amount, 0)) unreceived_amount, (ccc.due_amount - nvl(ccc.received_amount, 0)) unreceived_amount,
(Select cc1.times (Select cc1.times
From con_contract_cashflow cc1 From con_contract_cashflow cc1
Where cc1.contract_id = ccc.contract_id Where cc1.contract_id = ccc.contract_id
And cc1.times = ccc.times And cc1.times = ccc.times
And cc1.cf_direction = &apos;INFLOW&apos; And ((cc1.cf_direction = 'INFLOW' And
And cc1.cf_status = &apos;RELEASE&apos; cc1.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
cc1.cf_direction = 'NONCASH' And
cc1.cf_status = 'BLOCK' And
nvl(cc1.write_off_flag, 'NOT') !=
'NOT'))
And cc1.cf_item = 9) As times_9, And cc1.cf_item = 9) As times_9,
(Select cc1.due_amount (Select cc1.due_amount
From con_contract_cashflow cc1 From con_contract_cashflow cc1
Where cc1.contract_id = ccc.contract_id Where cc1.contract_id = ccc.contract_id
And cc1.times = ccc.times And cc1.times = ccc.times
And cc1.cf_direction = &apos;INFLOW&apos; And ((cc1.cf_direction = 'INFLOW' And
And cc1.cf_status = &apos;RELEASE&apos; cc1.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
cc1.cf_direction = 'NONCASH' And
cc1.cf_status = 'BLOCK' And
nvl(cc1.write_off_flag, 'NOT') !=
'NOT'))
And cc1.cf_item = 9) As due_amount_9, And cc1.cf_item = 9) As due_amount_9,
(Select nvl(cc1.received_amount, 0) (Select nvl(cc1.received_amount, 0)
From con_contract_cashflow cc1 From con_contract_cashflow cc1
Where cc1.contract_id = ccc.contract_id Where cc1.contract_id = ccc.contract_id
And cc1.times = ccc.times And cc1.times = ccc.times
And cc1.cf_direction = &apos;INFLOW&apos; And ((cc1.cf_direction = 'INFLOW' And
And cc1.cf_status = &apos;RELEASE&apos; cc1.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
cc1.cf_direction = 'NONCASH' And
cc1.cf_status = 'BLOCK' And
nvl(cc1.write_off_flag, 'NOT') !=
'NOT'))
And cc1.cf_item = 9) As received_amount_9, And cc1.cf_item = 9) As received_amount_9,
(Select cc1.due_amount - nvl(cc1.received_amount, 0) (Select cc1.due_amount -
nvl(cc1.received_amount, 0)
From con_contract_cashflow cc1 From con_contract_cashflow cc1
Where cc1.contract_id = ccc.contract_id Where cc1.contract_id = ccc.contract_id
And cc1.times = ccc.times And cc1.times = ccc.times
And cc1.cf_direction = &apos;INFLOW&apos; And ((cc1.cf_direction = 'INFLOW' And
And cc1.cf_status = &apos;RELEASE&apos; cc1.cf_status = 'RELEASE') Or
(c.contract_status In
('REPURING', 'REPUR') And
cc1.cf_direction = 'NONCASH' And
cc1.cf_status = 'BLOCK' And
nvl(cc1.write_off_flag, 'NOT') !=
'NOT'))
And cc1.cf_item = 9) unreceived_amount_9 And cc1.cf_item = 9) unreceived_amount_9
From con_contract_cashflow ccc From con_contract_cashflow ccc, con_contract c
Where ccc.contract_id = #{contractId} Where ccc.contract_id = #{contractId}
And ccc.cf_direction = &apos;INFLOW&apos; And ccc.contract_id = c.contract_id
And ccc.cf_status = &apos;RELEASE&apos; And ((ccc.cf_direction = 'INFLOW' And
ccc.cf_status = 'RELEASE') Or
(c.contract_status In ('REPURING', 'REPUR') And
ccc.cf_direction = 'NONCASH' And
ccc.cf_status = 'BLOCK' And
nvl(ccc.write_off_flag, 'NOT') != 'NOT'))
And ccc.cf_item Not In (0, 9) And ccc.cf_item Not In (0, 9)
And ccc.times &gt; And ccc.times >
nvl((Select Max(cc2.times) nvl((Select Max(cc2.times)
From con_contract_cashflow cc2 From con_contract_cashflow cc2
Where cc2.contract_id = ccc.contract_id Where cc2.contract_id = ccc.contract_id
And cc2.cf_item &lt;&gt; 0 And cc2.cf_item != 0
And nvl(cc2.received_amount, 0) &lt;&gt; 0), -1))) And nvl(cc2.received_amount, 0) != 0),
Order By times, cf_item, due_amount Desc, transaction_date, write_off_date) -1)))
Order By times,
cf_item,
due_amount Desc,
transaction_date,
write_off_date)
</select> </select>
......
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