Explorar o código

Merge branch 'master' of http://47.100.3.209:3000/gdc/yiliangyiyun

ccj %!s(int64=2) %!d(string=hai) anos
pai
achega
1373c38391

+ 47 - 14
winsea-haixin-plugin-yiliangyiyun/src/main/resources/mapper/ContractManagementInfoMapper.xml

@@ -757,7 +757,7 @@
             resultType="com.yh.saas.plugin.yiliangyiyun.entity.ContractManagementInfo">
         SELECT
         '采购' AS type,
-        SUM( IFNULL( sri.proportion, 1 ) * IFNULL( ssrr.amount_ing_receivable, 0 ) ) + SUM( exi.amount_money )- SUM( exi2.amount_money ) AS contractProfit
+        SUM( IFNULL( sri.proportion, 1 ) * IFNULL( ssrr.amount_ing_receivable, 0 ) ) + IFNULL(SUM( exi.amount_money ),0)- IFNULL(SUM( exi2.amount_money ),0) AS contractProfit
         FROM
         contract_management_info cmi
         LEFT JOIN expense_info exi ON exi.contract_id = cmi.id
@@ -778,7 +778,6 @@
         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
@@ -795,7 +794,7 @@
         UNION ALL
         SELECT
         '销售' AS type,
-        SUM( exi.amount_money )- SUM(ssrr.settlement_weight* wo.avg_cost)- SUM( exi2.unallocated_amount ) AS contractProfit
+        IFNULL(SUM( exi.amount_money ),0)- IFNULL(SUM(ssrr.settlement_weight* wo.avg_cost),0)- IFNULL(SUM( exi2.unallocated_amount),0) AS contractProfit
         FROM
         contract_management_info cmi
         LEFT JOIN expense_info exi ON exi.contract_id = cmi.id
@@ -821,7 +820,45 @@
         AND (DATE_FORMAT(cmi.create_date,"%Y%m%d") <=
         DATE_FORMAT(#{endDate},"%Y%m%d"))
         AND cmi.contract_type = '1'
-        AND cmi.agreement_no != '代储合同'
+        AND cmi.agreement_type != '代储合同'
+        UNION ALL
+        SELECT
+        '收购' AS type,
+        SUM( IFNULL( sri.proportion, 1 ) * IFNULL( ssrr.amount_ing_receivable, 0 ) ) + IFNULL(SUM( exi.amount_money),0)- IFNULL(SUM( exi2.amount_money),0) AS contractProfit
+        FROM
+        contract_management_info cmi
+            LEFT JOIN expense_info exi ON exi.contract_id = cmi.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 = cmi.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 = 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'
+            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.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
+        cmi.comp_id =  #{compId}
+        AND cmi.delete_flag = '0'
+        AND (DATE_FORMAT(cmi.create_date,"%Y%m%d") >=
+           DATE_FORMAT(#{startDate},"%Y%m%d"))
+        AND (DATE_FORMAT(cmi.create_date,"%Y%m%d") <=
+           DATE_FORMAT(#{endDate},"%Y%m%d"))
+        AND cmi.contract_type = '3'
+        AND cmi.agreement_type = '收购合同'
         UNION ALL
         SELECT
         '代收' AS type,
@@ -844,6 +881,7 @@
         AND (DATE_FORMAT(cmi.create_date,"%Y%m%d") <=
         DATE_FORMAT(#{endDate},"%Y%m%d"))
         AND cmi.contract_type = '3'
+        AND cmi.agreement_type = '代收合同'
         UNION ALL
         SELECT
         '代储' AS type,
@@ -866,7 +904,7 @@
         AND (DATE_FORMAT(cmi.create_date,"%Y%m%d") <=
         DATE_FORMAT(#{endDate},"%Y%m%d"))
         AND cmi.contract_type = '1'
-        AND cmi.agreement_no = '代储合同'
+        AND cmi.agreement_type = '代储合同'
     </select>
     <!--合同利润表查询-->
     <select id="getContractFormByCondition" parameterType="Map"
@@ -1111,23 +1149,18 @@
           AND ei.comp_id =  #{compId} UNION ALL
         SELECT
             '运费' AS type,
-            SUM( ei1.amount_money )- SUM( ei2.amount_money ) AS profit
+            SUM( ei.amount_money ) AS profit
         FROM
             expense_info ei
-                LEFT JOIN expense_info ei1 ON ei1.id = ei.id
-                AND ei1.delete_flag = 0
-                AND ei1.expenses_type = '1'
-                LEFT JOIN expense_info ei2 ON ei2.id = ei.id
-                AND ei2.delete_flag = 0
-                AND ei2.expenses_type = '2'
         WHERE
             ei.delete_flag = 0
-          AND ei.comp_id =  #{compId}
+            AND ei.expenses_type = '2'
+            AND ei.expense_name = '运费'
+            AND ei.comp_id =  #{compId}
           AND (DATE_FORMAT(ei.create_date,"%Y%m%d") &gt;=
                DATE_FORMAT(#{startDate},"%Y%m%d"))
           AND (DATE_FORMAT(ei.create_date,"%Y%m%d") &lt;=
                DATE_FORMAT(#{endDate},"%Y%m%d"))
-          AND ei.cost_type = '1'
         UNION ALL
         SELECT
             '总利润' AS type,