(select total_reback_view.sum from total_reback_view where total_reback_view.contract_unid=tb_contract.contract_unid) as total_reback_amount,
(contract_amount-(select total_reback_view.sum from total_reback_view where total_reback_view.contract_unid=tb_contract.contract_unid)-deduct_amount-stop_amount-exemptions_amount-bad_amount) as contract_remain,
(select total_recv_amount_view.total_recv_amount from total_recv_amount_view where tb_contract.contract_unid=total_recv_amount_view.contract_unid) as total_receive_amount ,
((select total_recv_amount_view.total_recv_amount from total_recv_amount_view where tb_contract.contract_unid=total_recv_amount_view.contract_unid)-(select total_reback_view.sum from total_reback_view where total_reback_view.contract_unid=tb_contract.contract_unid)-deduct_amount-stop_amount-exemptions_amount-bad_amount) as total_amount_remain ,
(select over_days_view.over_days from over_days_view where over_days_view.contract_unid=tb_contract.contract_unid) as over_days
from tb_contract where 1=1
<iftest="salesperson_name__like !=null and salesperson_name__like !=''">
salesperson_unid like #{salesperson_name__like}
and
salesperson_unid like #{salesperson_name__like}
</if>
<iftest="project_name__like !=null and project_name__like !=''">
and
project_unid like #{project_name__like}
and
</if>
<iftest="customer_name__like !=null and customer_name__like !=''">
and
customer_unid like #{customer_name__like}
and
</if>
<iftest="province !=null and province !=''">
and
province=#{province}
and
</if>
<iftest="city !=null and city !=''">
city=#{city}
and
city=#{city}
</if>
<iftest="county !=null and county !=''">
county=#{county}
and
county=#{county}
</if>
<iftest="guarantee_period !=null">
and
guarantee_period=#{guarantee_period}
and
</if>
<iftest="year !=null and year !=''">
to_char(sign_date,"yyyy")=#{year}
and
to_char(sign_date,"yyyy")=#{year}
</if>
<iftest="month !=null and month!=''">
and
to_char(sign_date,"MM")=#{month}
and
</if>
<iftest="product_line_type !=null and product_line_type !=''">
product_line_type=#{product_line_type}
and
product_line_type=#{product_line_type}
</if>
<iftest="contract_state !=null and contract_state!=''">
and
contract_state=#{contract_state}
and
</if>
<iftest="contract_type !=null and contract_type !=''">
contract_type=#{contract_type}
and
contract_type=#{contract_type}
</if>
<iftest="is_archive !=null">
is_archive=#{is_archive}
and
is_archive=#{is_archive}
</if>
<iftest="acceptanc_type !=null and acceptanc_type !=''">
contract_unid in (select tb_project_acceptanc.contract_unid from tb_project_acceptanc where tb_project_acceptanc.acceptanc_type=#{acceptanc_type})
and
contract_unid in (select tb_project_acceptanc.contract_unid from tb_project_acceptanc where tb_project_acceptanc.acceptanc_type=#{acceptanc_type})
</if>
<iftest="confirm_income_amount !=null">
confirm_income_amount=#{confirm_income_amount}
and
confirm_income_amount=#{confirm_income_amount}
</if>
<iftest="amount_state_unid !=null">
amount_state_unid=#{amount_state_unid}
and
amount_state_unid=#{amount_state_unid}
</if>
<iftest="start_date != null and end_date !=null">
#{start_date} <![CDATA[<=]]> sign_date and sign_date <![CDATA[<=]]> #{end_date}
and
#{start_date} <![CDATA[<=]]> sign_date and sign_date <![CDATA[<=]]> #{end_date}
</if>
<iftest="amount_point !=null">
and
contract_amount <![CDATA[>=]]> #{amount_point}
and
</if>
<iftest="overdays_point !=null">
and
<!--逾期天数-->contract_unid in (select over_days_view.contract_unid from over_days_view where over_days <![CDATA[>=]]> #{overdays_point})
</if>
<!--应收款余额-->
<iftest="leave_amount_point !=null">
<!--应收款余额-->and
contract_unid in (select receive_amount_view.contract_unid from receive_amount_view where receive_amount_view.leave_amount_point <![CDATA[>=]]> #{leave_amount_point})