|
@@ -315,15 +315,126 @@
|
|
|
m.buyer,
|
|
|
m.signing_date as signingDate,
|
|
|
m.status,
|
|
|
- ci.inventory as inventory,
|
|
|
+ SUM(wo.surplus_weight) as surplus,
|
|
|
+ IFNULL(SUM( IFNULL( sri.proportion, 1 ) * IFNULL( ssrr.amount_ing_receivable, 0 ) ) + SUM( exi.amount_money )- SUM( exi2.amount_money ),0) AS profit,
|
|
|
m.approve_status as approveStatus,
|
|
|
m.agreement_type as agreementType
|
|
|
FROM contract_management_info m
|
|
|
- LEFT JOIN contract_cost_info c on m.id = c.contract_id
|
|
|
- LEFT JOIN contract_inventory_distribution ci on m.id = ci.contract_id
|
|
|
+ LEFT JOIN warehousing_order wo on wo.contract_no = m.contract_no and wo.comp_id=m.comp_id and wo.delete_flag = '0'
|
|
|
+ LEFT JOIN expense_info exi ON exi.contract_id = m.id
|
|
|
+ AND exi.expenses_type = '1'
|
|
|
+ AND exi.expenses_purpose = '1'
|
|
|
+ AND exi.delete_flag = '0'
|
|
|
+ LEFT JOIN expense_info exi2 ON exi2.contract_id = m.id
|
|
|
+ AND exi2.expenses_type = '2'
|
|
|
+ AND exi2.expenses_purpose = '1'
|
|
|
+ AND exi2.delete_flag = '0'
|
|
|
+ LEFT JOIN warehousing_order war ON war.contract_no = m.contract_no
|
|
|
+ AND war.comp_id = m.comp_id
|
|
|
+ AND war.delete_flag = '0'
|
|
|
+ LEFT JOIN source_relation_info sri ON sri.source_id = war.id
|
|
|
+ AND sri.delete_flag = '0'
|
|
|
+ LEFT JOIN in_out_warehouse_task iowt ON iowt.id = sri.task_id
|
|
|
+ AND iowt.in_out_flag = 1
|
|
|
+ AND iowt.in_out_type_key = 1
|
|
|
+ AND iowt.delete_flag = '0'
|
|
|
+ LEFT JOIN warehouse_in_out_info wioi ON wioi.in_out_task_no = iowt.in_out_task_no
|
|
|
+ and wioi.car_no = sri.car_no
|
|
|
+ AND wioi.delete_flag = 0
|
|
|
+ AND wioi.status_flag = 3
|
|
|
+ LEFT JOIN stock_sale_receipt_report ssrr ON ssrr.contract_no = iowt.contract_no
|
|
|
+ AND ssrr.warehouse_record_id = wioi.id
|
|
|
+ and ssrr.delete_flag = 0
|
|
|
+ WHERE
|
|
|
+ m.comp_id = #{compId}
|
|
|
+ AND m.delete_flag = '0'
|
|
|
+ and m.contract_type='2'
|
|
|
+ <if test="searchTypeCon != null and searchTypeCon != ''">
|
|
|
+ <!--执行中-->
|
|
|
+ <if test="searchTypeCon == 1">
|
|
|
+ AND (m.status_flag == '1' or approve_status='待决策人审核')
|
|
|
+ </if>
|
|
|
+ <!--已完成-->
|
|
|
+ <if test="searchTypeCon == 2">
|
|
|
+ AND m.status_flag = '3'
|
|
|
+ </if>
|
|
|
+ <!--发运结束-->
|
|
|
+ <if test="searchTypeCon == 3">
|
|
|
+ AND m.status_flag = '2'
|
|
|
+ </if>
|
|
|
+ <!--待执行-->
|
|
|
+ <if test="searchTypeCon == 4">
|
|
|
+ AND m.status_flag = '0'
|
|
|
+ </if>
|
|
|
+ </if>
|
|
|
+ <if test="searchContractType != null and searchContractType != ''">
|
|
|
+ <!--销售合同-->
|
|
|
+ <if test="searchContractType == 1">
|
|
|
+ AND m.contract_type = '1'
|
|
|
+ </if>
|
|
|
+ <!--采购合同-->
|
|
|
+ <if test="searchContractType == 2">
|
|
|
+ AND m.contract_type = '2'
|
|
|
+ </if>
|
|
|
+ <!--代收合同-->
|
|
|
+ <if test="searchContractType == 3">
|
|
|
+ AND m.contract_type = '3'
|
|
|
+ AND m.agreement_type = '代收合同'
|
|
|
+ </if>
|
|
|
+ <!--代储合同-->
|
|
|
+ <if test="searchContractType == 4">
|
|
|
+ AND m.contract_type = '1'
|
|
|
+ AND m.agreement_type = '代储合同'
|
|
|
+ </if>
|
|
|
+ </if>
|
|
|
+ <if test="startDate != null">
|
|
|
+ AND (DATE_FORMAT(m.signing_date,"%Y%m%d") >=
|
|
|
+ DATE_FORMAT(#{startDate},"%Y%m%d"))
|
|
|
+ </if>
|
|
|
+ <if test="endDate != null">
|
|
|
+ AND (DATE_FORMAT(m.signing_date,"%Y%m%d") <=
|
|
|
+ DATE_FORMAT(#{endDate},"%Y%m%d"))
|
|
|
+ </if>
|
|
|
+ <if test="searchKeyWord != null and searchKeyWord != ''">
|
|
|
+ AND (lower(m.contract_no) like lower(CONCAT('%',#{searchKeyWord},'%'))
|
|
|
+ OR lower( m.buyer) like lower(CONCAT('%',#{searchKeyWord},'%'))
|
|
|
+ OR lower( m.seller) like lower(CONCAT('%',#{searchKeyWord},'%')))
|
|
|
+ </if>
|
|
|
+ GROUP BY m.contract_no
|
|
|
+ UNION ALL
|
|
|
+ SELECT
|
|
|
+ m.id,
|
|
|
+ m.comp_id as compId,
|
|
|
+ m.contract_no as contractNo,
|
|
|
+ m.contract_type as contractType,
|
|
|
+ m.seller,
|
|
|
+ m.buyer,
|
|
|
+ m.signing_date as signingDate,
|
|
|
+ m.status,
|
|
|
+ '' as surplus,
|
|
|
+ IFNULL(SUM( exi.amount_money )- SUM(ssrr.settlement_weight* wo.avg_cost)- SUM( exi2.unallocated_amount ) ,0)AS profit,
|
|
|
+ m.approve_status as approveStatus,
|
|
|
+ m.agreement_type as agreementType
|
|
|
+ FROM contract_management_info m
|
|
|
+ LEFT JOIN expense_info exi ON exi.contract_id = m.id
|
|
|
+ AND exi.expenses_type = '1'
|
|
|
+ AND exi.expenses_purpose = '1'
|
|
|
+ AND exi.delete_flag = '0'
|
|
|
+ LEFT JOIN expense_info exi2 ON exi2.contract_id = m.id
|
|
|
+ AND exi2.expenses_type = '2'
|
|
|
+ AND exi2.expenses_purpose = '1'
|
|
|
+ AND exi2.delete_flag = '0'
|
|
|
+ LEFT JOIN stock_sale_receipt_report ssrr ON ssrr.contract_no = m.contract_no
|
|
|
+ and ssrr.delete_flag = 0
|
|
|
+ LEFT JOIN warehouse_in_out_info wioi ON wioi.id = ssrr.warehouse_record_id
|
|
|
+ AND wioi.delete_flag = '0'
|
|
|
+ LEFT JOIN in_out_warehouse_task iowt ON iowt.in_out_task_no=wioi.in_out_task_no and iowt.delete_flag='0'
|
|
|
+ LEFT JOIN source_relation_info sri on sri.task_id=iowt.id and sri.delete_flag='0'
|
|
|
+ LEFT JOIN warehousing_order wo on wo.id=sri.source_id and wo.delete_flag='0'
|
|
|
WHERE
|
|
|
m.comp_id = #{compId}
|
|
|
AND m.delete_flag = '0'
|
|
|
+ and m.contract_type='1'
|
|
|
<if test="searchTypeCon != null and searchTypeCon != ''">
|
|
|
<!--执行中-->
|
|
|
<if test="searchTypeCon == 1">
|
|
@@ -353,7 +464,88 @@
|
|
|
</if>
|
|
|
<!--代收合同-->
|
|
|
<if test="searchContractType == 3">
|
|
|
+ AND m.contract_type = '3'
|
|
|
+ AND m.agreement_type = '代收合同'
|
|
|
+ </if>
|
|
|
+ <!--代储合同-->
|
|
|
+ <if test="searchContractType == 4">
|
|
|
+ AND m.contract_type = '1'
|
|
|
+ AND m.agreement_type = '代储合同'
|
|
|
+ </if>
|
|
|
+ </if>
|
|
|
+ <if test="startDate != null">
|
|
|
+ AND (DATE_FORMAT(m.signing_date,"%Y%m%d") >=
|
|
|
+ DATE_FORMAT(#{startDate},"%Y%m%d"))
|
|
|
+ </if>
|
|
|
+ <if test="endDate != null">
|
|
|
+ AND (DATE_FORMAT(m.signing_date,"%Y%m%d") <=
|
|
|
+ DATE_FORMAT(#{endDate},"%Y%m%d"))
|
|
|
+ </if>
|
|
|
+ <if test="searchKeyWord != null and searchKeyWord != ''">
|
|
|
+ AND (lower(m.contract_no) like lower(CONCAT('%',#{searchKeyWord},'%'))
|
|
|
+ OR lower( m.buyer) like lower(CONCAT('%',#{searchKeyWord},'%'))
|
|
|
+ OR lower( m.seller) like lower(CONCAT('%',#{searchKeyWord},'%')))
|
|
|
+ </if>
|
|
|
+ GROUP BY m.contract_no
|
|
|
+ UNION ALL
|
|
|
+ SELECT
|
|
|
+ m.id,
|
|
|
+ m.comp_id as compId,
|
|
|
+ m.contract_no as contractNo,
|
|
|
+ m.contract_type as contractType,
|
|
|
+ m.seller,
|
|
|
+ m.buyer,
|
|
|
+ m.signing_date as signingDate,
|
|
|
+ m.status,
|
|
|
+ SUM(wo.surplus_weight) as surplus,
|
|
|
+ SUM( exi.amount_money )- SUM( exi2.unallocated_amount ) AS profit,
|
|
|
+ m.approve_status as approveStatus,
|
|
|
+ m.agreement_type as agreementType
|
|
|
+ FROM contract_management_info m
|
|
|
+ LEFT JOIN warehousing_order wo on wo.contract_no = m.contract_no and wo.comp_id=m.comp_id and wo.delete_flag = '0'
|
|
|
+ LEFT JOIN expense_info exi ON exi.contract_id = m.id
|
|
|
+ AND exi.expenses_type = '1'
|
|
|
+ AND exi.expenses_purpose = '1'
|
|
|
+ AND exi.delete_flag = '0'
|
|
|
+ LEFT JOIN expense_info exi2 ON exi2.contract_id = m.id
|
|
|
+ AND exi2.expenses_type = '2'
|
|
|
+ AND exi2.expenses_purpose = '1'
|
|
|
+ AND exi2.delete_flag = '0'
|
|
|
+ WHERE
|
|
|
+ m.comp_id = #{compId}
|
|
|
+ AND m.delete_flag = '0'
|
|
|
+ and m.agreement_type!='销售合同'
|
|
|
+ and m.agreement_type!='采购合同'
|
|
|
+ <if test="searchTypeCon != null and searchTypeCon != ''">
|
|
|
+ <!--执行中-->
|
|
|
+ <if test="searchTypeCon == 1">
|
|
|
+ AND (m.status_flag == '1' or approve_status='待决策人审核')
|
|
|
+ </if>
|
|
|
+ <!--已完成-->
|
|
|
+ <if test="searchTypeCon == 2">
|
|
|
+ AND m.status_flag = '3'
|
|
|
+ </if>
|
|
|
+ <!--发运结束-->
|
|
|
+ <if test="searchTypeCon == 3">
|
|
|
+ AND m.status_flag = '2'
|
|
|
+ </if>
|
|
|
+ <!--待执行-->
|
|
|
+ <if test="searchTypeCon == 4">
|
|
|
+ AND m.status_flag = '0'
|
|
|
+ </if>
|
|
|
+ </if>
|
|
|
+ <if test="searchContractType != null and searchContractType != ''">
|
|
|
+ <!--销售合同-->
|
|
|
+ <if test="searchContractType == 1">
|
|
|
+ AND m.contract_type = '1'
|
|
|
+ </if>
|
|
|
+ <!--采购合同-->
|
|
|
+ <if test="searchContractType == 2">
|
|
|
AND m.contract_type = '2'
|
|
|
+ </if>
|
|
|
+ <!--代收合同-->
|
|
|
+ <if test="searchContractType == 3">
|
|
|
+ AND m.contract_type = '3'
|
|
|
AND m.agreement_type = '代收合同'
|
|
|
</if>
|
|
|
<!--代储合同-->
|
|
@@ -375,7 +567,9 @@
|
|
|
OR lower( m.buyer) like lower(CONCAT('%',#{searchKeyWord},'%'))
|
|
|
OR lower( m.seller) like lower(CONCAT('%',#{searchKeyWord},'%')))
|
|
|
</if>
|
|
|
- ORDER BY m.signing_date
|
|
|
+ GROUP BY m.contract_no
|
|
|
+ ORDER BY
|
|
|
+ signingDate desc
|
|
|
<if test="currentPage != null and currentPage != ''">
|
|
|
LIMIT ${startRecord}, ${pageSize}
|
|
|
</if>
|