amount_state_unid, to_char(start_guarantee_date, 'yyyy-MM-dd') as start_guarantee_date, to_char(end_guarantee_date, 'yyyy-MM-dd') as end_guarantee_date,
amount_state_unid, to_char(start_guarantee_date, 'yyyy-MM-dd') as start_guarantee_date, to_char(end_guarantee_date, 'yyyy-MM-dd') as end_guarantee_date,
(select cast(sum(receipt_amount) as decimal(18,2)) from tb_receipt where tb_receipt.contract_unid = tb_contract.contract_unid) as total_receipt_amount ,
to_char(sign_date,'yyyy') as year, to_char(sign_date,'MM') as month,
to_char(sign_date,'yyyy') as year, to_char(sign_date,'MM') as month,
(cast(contract_amount as decimal(18,2))-(select cast(total_reback_view."sum" as decimal(18,2)) from total_reback_view where total_reback_view.contract_unid=tb_contract.contract_unid)-cast(CASE WHEN deduct_amount IS NULL THEN 0 ELSE deduct_amount end as decimal(18,2))-cast(CASE WHEN stop_amount IS NULL THEN 0 ELSE stop_amount END as decimal(18,2))
(cast(contract_amount as decimal(18,2))-(select cast(total_reback_view."sum" as decimal(18,2)) from total_reback_view where total_reback_view.contract_unid=tb_contract.contract_unid)-cast(CASE WHEN deduct_amount IS NULL THEN 0 ELSE deduct_amount end as decimal(18,2))-cast(CASE WHEN stop_amount IS NULL THEN 0 ELSE stop_amount END as decimal(18,2))
-cast(CASE WHEN exemptions_amount IS NULL THEN 0 ELSE exemptions_amount END as decimal(18,2))-cast(CASE WHEN bad_amount IS NULL THEN 0 ELSE bad_amount END as decimal(18,2))) as contract_remain,(select cast(total_reback_view.sum as decimal(18,2)) from total_reback_view where total_reback_view.contract_unid=tb_contract.contract_unid) as total_reback_amount,
-cast(CASE WHEN exemptions_amount IS NULL THEN 0 ELSE exemptions_amount END as decimal(18,2))-cast(CASE WHEN bad_amount IS NULL THEN 0 ELSE bad_amount END as decimal(18,2))) as contract_remain,(select cast(total_reback_view.sum as decimal(18,2)) from total_reback_view where total_reback_view.contract_unid=tb_contract.contract_unid) as total_reback_amount,