zhangyuewww 2 年之前
父节点
当前提交
72e82c0312

+ 33 - 17
winsea-haixin-plugin-yiliangyiyun/src/main/resources/mapper/ContractManagementInfoMapper.xml

@@ -316,20 +316,14 @@
         m.signing_date as signingDate,
         m.status,
         SUM(war.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 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
+        (
+        SELECT
+        SUM(
+        IFNULL( sri.proportion, 1 ) * IFNULL( ssrr.amount_ing_receivable, 0 ))
+        FROM
+        contract_management_info cmi
+        LEFT JOIN warehousing_order war ON war.contract_no = cmi.contract_no
+        AND war.comp_id = cmi.comp_id
         AND war.delete_flag = '0'
         LEFT JOIN source_relation_info sri ON sri.source_id = war.id
         AND sri.delete_flag = '0'
@@ -338,12 +332,34 @@
         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
+        AND ssrr.delete_flag = 0
+        WHERE
+        cmi.id = m.id
+        ) + (
+        SELECT
+        SUM( exi.amount_money )
+        FROM
+        expense_info exi
+        WHERE
+        exi.contract_id = m.id
+        AND exi.expenses_type = '1'
+        AND exi.expenses_purpose = '1'
+        AND exi.delete_flag = '0'
+        )- SUM( exi2.amount_money ) AS profit,
+        m.approve_status as approveStatus,
+        m.agreement_type as agreementType
+        FROM contract_management_info m
+        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'
         WHERE
         m.comp_id = #{compId}
         AND m.delete_flag = '0'
@@ -599,7 +615,7 @@
         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.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