Преглед изворни кода

Merge branch 'master' of http://s.dev01.dkiboss.com:9001/iBOSS-2.0-Mini/iboss-server-mdm

liuyao пре 1 година
родитељ
комит
3b73614d4b
20 измењених фајлова са 999 додато и 202 уклоњено
  1. 36 1
      src/main/java/com/dk/mdm/controller/mac/ReceiptController.java
  2. 12 0
      src/main/java/com/dk/mdm/controller/pur/PurchaseController.java
  3. 3 3
      src/main/java/com/dk/mdm/controller/sale/OrderController.java
  4. 142 9
      src/main/java/com/dk/mdm/mapper/ivt/InboundItemMapper.xml
  5. 143 119
      src/main/java/com/dk/mdm/mapper/mac/AccountItemMapper.xml
  6. 3 1
      src/main/java/com/dk/mdm/mapper/mac/RecPayMapper.xml
  7. 3 0
      src/main/java/com/dk/mdm/mapper/mst/SupplierMapper.xml
  8. 1 0
      src/main/java/com/dk/mdm/mapper/sale/OrderItemMapper.xml
  9. 1 0
      src/main/java/com/dk/mdm/model/query/ivt/InboundItemQuery.java
  10. 3 0
      src/main/java/com/dk/mdm/model/query/mst/SupplierQuery.java
  11. 3 0
      src/main/java/com/dk/mdm/model/vo/ivt/InOutRecordVO.java
  12. 1 1
      src/main/java/com/dk/mdm/model/vo/pur/PurchaseItemVO.java
  13. 10 13
      src/main/java/com/dk/mdm/service/ivt/inbound/InboundPurchaseReturnService.java
  14. 261 13
      src/main/java/com/dk/mdm/service/ivt/inbound/InboundPurchaseService.java
  15. 2 9
      src/main/java/com/dk/mdm/service/ivt/inventory/InventoryService.java
  16. 3 4
      src/main/java/com/dk/mdm/service/ivt/outbound/OutboundSaleOrderService.java
  17. 41 16
      src/main/java/com/dk/mdm/service/ivt/outbound/OutboundSaleReturnService.java
  18. 262 6
      src/main/java/com/dk/mdm/service/mac/ReceiptService.java
  19. 65 6
      src/main/java/com/dk/mdm/service/pur/PurchaseService.java
  20. 4 1
      src/main/java/com/dk/mdm/service/sale/OrderService.java

+ 36 - 1
src/main/java/com/dk/mdm/controller/mac/ReceiptController.java

@@ -174,9 +174,44 @@ public class ReceiptController {
      * @author : 于继渤
      * @date : 2024/7/5 10:48
      */
-    @ApiOperation(value = "新建客户收款", notes = "新建客户收款")
+    @ApiOperation(value = "新建供应商收款", notes = "新建供应商收款")
     @PostMapping({"insert_sup_receipt"})
     public ResponseResultVO<?> insertSupReceipt(@RequestBody RecPayVO recPayVO) {
         return receiptService.insertSupReceipt(recPayVO);
     }
+
+    /**
+     * @desc : 新建供应商退款
+     * @author : 于继渤
+     * @date :  2024/7/5 10:48
+     */
+    @ApiOperation(value = "新建供应商退款", notes = "新建供应商退款")
+    @PostMapping({"insert_sup_refund"})
+    public ResponseResultVO<?> insertSupRefund(@RequestBody RecPayVO recPayVO) {
+        return receiptService.insertSupRefund(recPayVO);
+    }
+
+    /**
+     * @desc : 编辑供应商收款/退款
+     * @author : 于继渤
+     * @date :  2024/7/5 10:48
+     */
+    @ApiOperation(value = "编辑供应商收款/退款", notes = "编辑供应商收款/退款")
+    @PostMapping({"update_sup_receipt"})
+    public ResponseResultVO<?> updateSupReceipt(@RequestBody RecPayVO recPayVO) {
+        return receiptService.updateSupReceipt(recPayVO);
+    }
+
+
+
+    /**
+     * @desc : 作废
+     * @author : 于继渤
+     * @date : 2024-03-08 16:36
+     */
+    @ApiOperation(value = "作废", notes = "作废")
+    @PostMapping({"invalid_sup/{id}"})
+    public ResponseResultVO<?> invalidSup(@PathVariable String id) {
+        return receiptService.invalidSup(id);
+    }
 }

+ 12 - 0
src/main/java/com/dk/mdm/controller/pur/PurchaseController.java

@@ -135,4 +135,16 @@ public class PurchaseController{
     public ResponseResultVO<PageList> selectTrackReport(@RequestBody Map<String, Object> param) {
         return purchaseService.selectTrackReport(param);
     }
+
+    /**
+     * @desc   : 一键作废
+     * @date   : 2024/7/6 9:30
+     * @author : 寇珊珊
+     */
+    @ApiOperation(value = "作废", notes = "作废")
+    @PostMapping({"one_key_invalid/{id}"})
+    public ResponseResultVO<?> oneKeyInvalid(@PathVariable String id) {
+        return purchaseService.oneKeyInvalid(id);
+    }
+
 }

+ 3 - 3
src/main/java/com/dk/mdm/controller/sale/OrderController.java

@@ -177,9 +177,9 @@ public class OrderController {
 
 
     /**
-     * @desc : 作废
-     * @author : 付斌
-     * @date : 2024-03-08 16:36
+     * @desc   : 一键作废
+     * @date   : 2024/7/6 9:30
+     * @author : 寇珊珊
      */
     @ApiOperation(value = "作废", notes = "作废")
     @PostMapping({"one_key_invalid/{id}"})

+ 142 - 9
src/main/java/com/dk/mdm/mapper/ivt/InboundItemMapper.xml

@@ -815,6 +815,10 @@
                 AND tpii.into_status =
                 any(#{intoStatusList, typeHandler= StringListTypeHandler})
             </if>
+            <if test="skuIdFlag !=null and skuIdFlag == true">
+                AND tpii.sku_id is null
+            </if>
+
             <if test="searchText !=null">
                 AND  (tpii.sku_model LIKE concat('%',my_ex.likequery(#{searchText}), '%')
                 OR   tpii.sku_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
@@ -897,6 +901,9 @@
             <if test="intoDateEnd != null">
                 AND tpo.out_date &lt; #{intoDateEnd}::timestamp with time zone + interval '1 day'
             </if>
+            <if test="skuIdFlag !=null and skuIdFlag == true">
+                AND tpoi.sku_id is null
+            </if>
             <if test="searchText !=null">
                 AND  (tpii.sku_model LIKE concat('%',my_ex.likequery(#{searchText}), '%')
                 OR   tpii.sku_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
@@ -920,20 +927,60 @@
     </select>
 
     <select id="countByCondList" resultType="Long">
-        SELECT COUNT
-        ( 1 )
-        FROM (
-        SELECT COUNT
-        ( 1 )
+        SELECT COUNT(1) from
+        (
+        SELECT
+        tpii.sku_model AS "skuModel",
+        tpii.sku_name AS "skuName",
+        tpii.sku_id AS "skuId",
+        tpii.cost_price AS "costPrice",
+        tpii.cost_amt AS "costAmt",
+        tmgs.brand_id AS "brandId",
+        tmgs.sku_images AS "skuImages",
+        tmgb.brand_name AS "brandName",
+        tmgb.short_name AS "shortName",
+        json_agg (
+        json_build_object (
+        'itemId',
+        tpii.item_id,
+        'intoId',
+        tpii.into_id,
+        'outId',
+        NULL,
+        'invId',
+        tpii.inv_id,
+        'fromId',
+        tpii.from_id,
+        'fromItemId',
+        tpii.from_item_id,
+        'skuModel',
+        tpii.sku_model,
+        'skuName',
+        tpii.sku_name,
+        'skuId',
+        tpii.sku_id,
+        'intoQty',
+        tpii.into_qty,
+        'costPrice',
+        tpii.cost_price,
+        'costAmt',
+        tpii.cost_amt,
+        'brandId',
+        tmgs.brand_id,
+        'fromItemId',
+        tpii.from_item_id
+        )
+        ) AS "itemList"
         FROM
         dkic_b.t_psi_inbound_item tpii
         LEFT JOIN dkic_b.t_psi_inbound tpi ON tpi.into_id = tpii.into_id
         LEFT JOIN dkic_b.t_mst_goods_sku tmgs ON tmgs.sku_id = tpii.sku_id
-        left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
+        LEFT JOIN dkic_b.t_mst_goods_brand tmgb ON tmgb.brand_id = tmgs.brand_id
         <where>
             tpii.cost_price = 0
             AND tpii.into_qty != 0
-            AND tpii.sku_model is not null
+            AND tpii.sku_model IS NOT NULL
+            AND tpii.into_type != '入库类型-采退入库'
             <if test="intoId != null and intoId != ''">
                 AND tpii.into_id = #{intoId}::uuid
             </if>
@@ -955,11 +1002,14 @@
             <if test="staffName !=null">
                 AND tmss.staff_name  LIKE concat('%',my_ex.likequery(#{staffName}),'%')
             </if>
-
             <if test="intoStatusList != null and intoStatusList.size()>0">
                 AND tpii.into_status =
                 any(#{intoStatusList, typeHandler= StringListTypeHandler})
             </if>
+            <if test="skuIdFlag !=null and skuIdFlag == true">
+                AND tpii.sku_id is null
+            </if>
+
             <if test="searchText !=null">
                 AND  (tpii.sku_model LIKE concat('%',my_ex.likequery(#{searchText}), '%')
                 OR   tpii.sku_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
@@ -975,9 +1025,92 @@
         tmgs.brand_id,
         tmgs.sku_images,
         tmgb.brand_name,
-        tmgb.short_name ) AS "a"
+        tmgb.short_name
 
+        UNION ALL
+        SELECT
+        tpoi.sku_model AS "skuModel",
+        tpoi.sku_name AS "skuName",
+        tpoi.sku_id AS "skuId",
+        tpoi.cost_price AS "costPrice",
+        tpoi.cost_amt AS "costAmt",
+        tmgs.brand_id AS "brandId",
+        tmgs.sku_images AS "skuImages",
+        tmgb.brand_name AS "brandName",
+        tmgb.short_name AS "shortName",
+        json_agg (
+        json_build_object (
+        'itemId',
+        tpoi.item_id,
+        'intoId',
+        NULL,
+        'outId',
+        tpoi.out_id,
+        'invId',
+        tpoi.inv_id,
+        'fromId',
+        tpoi.from_id,
+        'fromItemId',
+        tpoi.from_item_id,
+        'skuModel',
+        tpoi.sku_model,
+        'skuName',
+        tpoi.sku_name,
+        'skuId',
+        tpoi.sku_id,
+        'intoQty',
+        tpoi.out_qty,
+        'costPrice',
+        tpoi.cost_price,
+        'costAmt',
+        tpoi.cost_amt,
+        'brandId',
+        tmgs.brand_id,
+        'fromItemId',
+        tpoi.from_item_id
+        )
+        ) AS "itemList"
+        FROM
+        dkic_b.t_psi_outbound_item tpoi
+        LEFT JOIN dkic_b.t_psi_outbound tpo ON tpo.out_id = tpoi.out_id
+        LEFT JOIN dkic_b.t_mst_goods_sku tmgs ON tmgs.sku_id = tpoi.sku_id
+        LEFT JOIN dkic_b.t_mst_goods_brand tmgb ON tmgb.brand_id = tmgs.brand_id
 
+        <where>
+            tpoi.cost_price = 0
+            AND tpoi.out_qty != 0
+            AND tpoi.sku_model IS NOT NULL
+            <if test="outId != null and outId != ''">
+                AND tpoi.out_id = #{outId}::uuid
+            </if>
+            <if test="cpId != null">
+                AND tpoi.cp_id = #{cpId}
+            </if>
+            <if test="intoDateStart != null">
+                AND tpo.out_date &gt;= #{intoDateStart}::timestamp with time zone
+            </if>
+            <if test="intoDateEnd != null">
+                AND tpo.out_date &lt; #{intoDateEnd}::timestamp with time zone + interval '1 day'
+            </if>
+            <if test="skuIdFlag !=null and skuIdFlag == true">
+                AND tpoi.sku_id is null
+            </if>
+            <if test="searchText !=null">
+                AND  (tpii.sku_model LIKE concat('%',my_ex.likequery(#{searchText}), '%')
+                OR   tpii.sku_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
+                )
+            </if>
+        </where>
+        GROUP BY
+        tpoi.sku_model,
+        tpoi.sku_name,
+        tpoi.sku_id,
+        tpoi.cost_price,
+        tpoi.cost_amt,
+        tmgs.brand_id,
+        tmgs.sku_images,
+        tmgb.brand_name,
+        tmgb.short_name) AS "a"
     </select>
 
 </mapper>

+ 143 - 119
src/main/java/com/dk/mdm/mapper/mac/AccountItemMapper.xml

@@ -5,7 +5,8 @@
     <!-- 通用设置 -->
     <!-- 通用查询列 -->
     <sql id="Base_Column_List">
-        item_id, acc_item_type, object_id, org_id, staff_id, biznis_type, biznis_id, biznis_no, acc_date, rec_status, amt_rec, amt_pay, amt_should, amt_handle, amt_waive, amt_residue, flg_lock, remarks, make_staff, make_time, flg_valid, cp_id
+        item_id
+        , acc_item_type, object_id, org_id, staff_id, biznis_type, biznis_id, biznis_no, acc_date, rec_status, amt_rec, amt_pay, amt_should, amt_handle, amt_waive, amt_residue, flg_lock, remarks, make_staff, make_time, flg_valid, cp_id
     </sql>
 
     <!-- 通用查询映射结果 -->
@@ -180,93 +181,114 @@
     <select id="getReceivableAccountSum" resultType="Map">
         select
 
-            (SELECT SUM ( tpo.fact_amt - tpo.return_amt) AS receivable
-            FROM
-            dkic_b.t_psi_order tpo
-            WHERE
-            tpo.flg_valid
-            AND tpo.cp_id = #{cpId}
-            AND (
-            tpo.make_staff = #{staffId}::uuid
-            OR EXISTS ( SELECT 1 FROM dkic_b.t_mst_staff_purview tmsp WHERE tmsp.staff_id = tpo.make_staff AND
-            tmsp.purview_code = 'PU10000003' )
-            )
-            <!--开始日期-->
-            <if test="accDateStart != null">
-                AND tpo.make_time &gt;= #{accDateStart,typeHandler=TimestampTypeHandler}
-            </if>
-            <!--截止日期-->
-            <if test="accDateEnd != null">
-                AND tpo.make_time &lt;= #{accDateEnd,typeHandler=TimestampTypeHandler}
-            </if>
-            ),
-            (SELECT SUM ( tmrp.sum_amt_rec) AS receipt
-            FROM   dkic_b.t_mac_rec_pay tmrp
-            WHERE
-                 tmrp.flg_valid
-            AND tmrp.cp_id = #{cpId}
-            AND (
-            tmrp.make_staff = #{staffId}::uuid
-            OR EXISTS ( SELECT 1 FROM dkic_b.t_mst_staff_purview tmsp WHERE tmsp.staff_id = tmrp.make_staff AND
-            tmsp.purview_code = 'PU10000003' )
-            )
-            <!--开始日期-->
-            <if test="accDateStart != null">
-                AND tmrp.acc_date &gt;= #{accDateStart,typeHandler=TimestampTypeHandler}
-            </if>
-            <!--截止日期-->
-            <if test="accDateEnd != null">
-                AND tmrp.acc_date &lt;= #{accDateEnd,typeHandler=TimestampTypeHandler}
-            </if>
-            )
+        (SELECT SUM ( tpo.fact_amt) AS receivable
+        FROM
+        dkic_b.t_psi_order tpo
+        WHERE
+        tpo.flg_valid
+        AND tpo.cp_id = #{cpId}
+        AND (
+        tpo.make_staff = #{staffId}::uuid
+        OR EXISTS ( SELECT 1 FROM dkic_b.t_mst_staff_purview tmsp WHERE tmsp.staff_id = tpo.make_staff AND
+        tmsp.purview_code = 'PU10000003' )
+        )
+        <!--开始日期-->
+        <if test="accDateStart != null">
+            AND tpo.make_time &gt;= #{accDateStart,typeHandler=TimestampTypeHandler}
+        </if>
+        <!--截止日期-->
+        <if test="accDateEnd != null">
+            AND tpo.make_time &lt;= #{accDateEnd,typeHandler=TimestampTypeHandler}
+        </if>
+        ),
+        (SELECT SUM ( tpo.fact_amt) AS returnAmt
+        FROM
+        dkic_b.t_psi_outbound tpo
+        WHERE
+        tpo.flg_valid
+        AND tpo.out_type = '出库类型-销退回库'
+        AND tpo.cp_id = #{cpId}
+        AND (
+        tpo.make_staff = #{staffId}::uuid
+        OR EXISTS ( SELECT 1 FROM dkic_b.t_mst_staff_purview tmsp WHERE tmsp.staff_id = tpo.make_staff AND
+        tmsp.purview_code = 'PU10000003' )
+        )
+        <!--开始日期-->
+        <if test="accDateStart != null">
+            AND tpo.out_date &gt;= #{accDateStart,typeHandler=TimestampTypeHandler}
+        </if>
+        <!--截止日期-->
+        <if test="accDateEnd != null">
+            AND tpo.out_date &lt;= #{accDateEnd,typeHandler=TimestampTypeHandler}
+        </if>
+        ),
+        (SELECT SUM ( tmrp.sum_amt_rec) AS receipt
+        FROM dkic_b.t_mac_rec_pay tmrp
+        WHERE
+        tmrp.flg_valid
+        AND tmrp.cp_id = #{cpId}
+        AND (
+        tmrp.make_staff = #{staffId}::uuid
+        OR EXISTS ( SELECT 1 FROM dkic_b.t_mst_staff_purview tmsp WHERE tmsp.staff_id = tmrp.make_staff AND
+        tmsp.purview_code = 'PU10000003' )
+        )
+        <!--开始日期-->
+        <if test="accDateStart != null">
+            AND tmrp.acc_date &gt;= #{accDateStart,typeHandler=TimestampTypeHandler}
+        </if>
+        <!--截止日期-->
+        <if test="accDateEnd != null">
+            AND tmrp.acc_date &lt;= #{accDateEnd,typeHandler=TimestampTypeHandler}
+        </if>
+        )
 
     </select>
 
     <!-- 查询应收账款明细 -->
     <select id="getReceivableAccountItem" resultMap="BaseResultMapResponse">
         SELECT t.item_id,
-               t.item_id        as "accItemId",
-               t.acc_item_type,
-               t.object_id,
-               tmc.cus_code     as "cusCode",
-               tmc.cus_name     as "cusName",
-               tmc.cus_phone    as "cusPhone",
-               tmc.address_full as "addressFull",
-               t.org_id,
-               tmo.org_name     as "orgName",
-               t.staff_id,
-               tms.staff_name   as "staffName",
-               t.biznis_type,
-               t.biznis_id,
-               t.biznis_no,
-               t.acc_date,
-               t.rec_status,
-               sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "recStatusName",
-               coalesce(sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}), '其他收入') as "biznisTypeName",
-               t.amt_rec,
-               t.amt_pay,
-               t.amt_should,
-               t.amt_handle,
-               t.amt_waive,
-               t.amt_residue    as "amtNotHandle",
-               t.amt_residue    as "amtReceivableHandle",
-               t.amt_residue,
-               t.remarks,
-               t.make_staff,
-               t.make_time,
-               t.flg_valid,
-               t.cp_id
+        t.item_id as "accItemId",
+        t.acc_item_type,
+        t.object_id,
+        tmc.cus_code as "cusCode",
+        tmc.cus_name as "cusName",
+        tmc.cus_phone as "cusPhone",
+        tmc.address_full as "addressFull",
+        t.org_id,
+        tmo.org_name as "orgName",
+        t.staff_id,
+        tms.staff_name as "staffName",
+        t.biznis_type,
+        t.biznis_id,
+        t.biznis_no,
+        t.acc_date,
+        t.rec_status,
+        sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "recStatusName",
+        coalesce(sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}), '其他收入') as "biznisTypeName",
+        t.amt_rec,
+        t.amt_pay,
+        t.amt_should,
+        t.amt_handle,
+        t.amt_waive,
+        t.amt_residue as "amtNotHandle",
+        t.amt_residue as "amtReceivableHandle",
+        t.amt_residue,
+        t.remarks,
+        t.make_staff,
+        t.make_time,
+        t.flg_valid,
+        t.cp_id
         FROM dkic_b.t_mac_account_item as t
-                 left join dkic_b.t_psi_outbound as tpo on tpo.out_id = t.biznis_id and t.biznis_type = 't_psi_outbound'
-                 LEFT JOIN sys.t_data_kind tdk2 ON tdk2.kind_code = tpo.out_type
-                 left join dkic_b.t_mac_other_receivable as tmor
-                           on tmor.receivable_id = t.biznis_id and t.biznis_type = 't_mac_other_receivable'
-                 left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.object_id
-                 left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
-                 left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
-                 left join sys.t_data_kind as tdk1 on t.rec_status = tdk1.kind_code
+        left join dkic_b.t_psi_outbound as tpo on tpo.out_id = t.biznis_id and t.biznis_type = 't_psi_outbound'
+        LEFT JOIN sys.t_data_kind tdk2 ON tdk2.kind_code = tpo.out_type
+        left join dkic_b.t_mac_other_receivable as tmor
+        on tmor.receivable_id = t.biznis_id and t.biznis_type = 't_mac_other_receivable'
+        left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.object_id
+        left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
+        left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
+        left join sys.t_data_kind as tdk1 on t.rec_status = tdk1.kind_code
         where t.flg_valid
-          and t.acc_item_type = '账款类型-应收'
+        and t.acc_item_type = '账款类型-应收'
         and t.amt_residue <![CDATA[ <> ]]> 0
         <include refid="Condition"/>
         order by t.acc_date
@@ -278,45 +300,45 @@
     <!-- 查询应付账款明细 -->
     <select id="getPayableAccountItem" resultMap="BaseResultMapResponse">
         SELECT t.item_id,
-               t.item_id         as "accItemId",
-               t.acc_item_type,
-               t.object_id,
-               supplier.sup_code as "supCode",
-               supplier.sup_name as "supName",
-               t.org_id,
-               tmo.org_name      as "orgName",
-               t.staff_id,
-               tms.staff_name    as "staffName",
-               t.biznis_type,
-               t.biznis_id,
-               t.biznis_no,
-               t.acc_date,
-               t.rec_status,
-               sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "recStatusName",
-               sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}) as "biznisTypeName",
-               t.amt_rec,
-               t.amt_pay,
-               t.amt_should,
-               t.amt_handle,
-               t.amt_waive,
-               t.amt_residue,
-               t.amt_residue     as "amtNotHandle",
-               t.amt_residue     as "amtPayableHandle",
-               t.remarks,
-               t.make_staff,
-               t.make_time,
-               t.flg_valid,
-               t.cp_id
+        t.item_id as "accItemId",
+        t.acc_item_type,
+        t.object_id,
+        supplier.sup_code as "supCode",
+        supplier.sup_name as "supName",
+        t.org_id,
+        tmo.org_name as "orgName",
+        t.staff_id,
+        tms.staff_name as "staffName",
+        t.biznis_type,
+        t.biznis_id,
+        t.biznis_no,
+        t.acc_date,
+        t.rec_status,
+        sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "recStatusName",
+        sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}) as "biznisTypeName",
+        t.amt_rec,
+        t.amt_pay,
+        t.amt_should,
+        t.amt_handle,
+        t.amt_waive,
+        t.amt_residue,
+        t.amt_residue as "amtNotHandle",
+        t.amt_residue as "amtPayableHandle",
+        t.remarks,
+        t.make_staff,
+        t.make_time,
+        t.flg_valid,
+        t.cp_id
         FROM dkic_b.t_mac_account_item as t
-                 left join dkic_b.t_psi_inbound as tpi on tpi.into_id = t.biznis_id and t.biznis_type = 't_psi_inbound'
-                 LEFT JOIN sys.t_data_kind tdk2 ON tdk2.kind_code = tpi.into_type
-                 left join dkic_b.t_mst_supplier supplier on supplier.sup_id = t.object_id
-                 left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
-                 left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
-                 left join sys.t_data_kind as tdk1 on t.rec_status = tdk1.kind_code
+        left join dkic_b.t_psi_inbound as tpi on tpi.into_id = t.biznis_id and t.biznis_type = 't_psi_inbound'
+        LEFT JOIN sys.t_data_kind tdk2 ON tdk2.kind_code = tpi.into_type
+        left join dkic_b.t_mst_supplier supplier on supplier.sup_id = t.object_id
+        left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
+        left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
+        left join sys.t_data_kind as tdk1 on t.rec_status = tdk1.kind_code
         where t.flg_valid
-          and t.acc_item_type = '账款类型-应付'
-          and t.amt_residue <![CDATA[<>]]> 0
+        and t.acc_item_type = '账款类型-应付'
+        and t.amt_residue <![CDATA[<>]]> 0
         <include refid="Condition"/>
         order by t.acc_date
         <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
@@ -351,14 +373,16 @@
                t.flg_valid,
                t.cp_id
         FROM dkic_b.t_mac_account_item as t
-                 inner join dkic_b.t_psi_outbound as tpo on tpo.out_id = t.biznis_id and t.biznis_type = 't_psi_outbound'
+                 inner join dkic_b.t_psi_outbound as tpo
+                            on tpo.out_id = t.biznis_id and t.biznis_type = 't_psi_outbound'
         where t.flg_valid
           and t.acc_item_type = '账款类型-应收'
           and t.amt_residue <![CDATA[<>]]> 0
           AND t.object_id = #{objectId}::uuid
           AND tpo.from_id = #{orderId}::uuid
         order by t.acc_date
-            for update
+            for
+        update
     </select>
 
     <!-- 根据主键查询表t_mac_account_item的一行数据 -->

+ 3 - 1
src/main/java/com/dk/mdm/mapper/mac/RecPayMapper.xml

@@ -550,7 +550,9 @@
                t.flg_valid,
                t.cp_id,
                tma.receivable_residue,
-               tma.receipt_residue
+               tma.receipt_residue,
+               tma.payable_residue,
+               tma.payment_residue
         from dkic_b.t_mac_rec_pay as t
                  left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.object_id
                  left join dkic_b.t_mst_supplier tmsp on tmsp.sup_id = t.object_id

+ 3 - 0
src/main/java/com/dk/mdm/mapper/mst/SupplierMapper.xml

@@ -119,6 +119,9 @@ op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user,return_
             <if test="supType != null and supType != ''">
                 AND msl.sup_type = #{supType}
             </if>
+            <if test="supTypeList != null and supTypeList.size() >0">
+                AND msl.sup_type = any(#{supTypeList, typeHandler=StringListTypeHandler})
+            </if>
             <if test="contactName != null and contactName != ''">
                 AND msl.contact_name = #{contactName}
             </if>

+ 1 - 0
src/main/java/com/dk/mdm/mapper/sale/OrderItemMapper.xml

@@ -449,6 +449,7 @@
                0                                                    as out_qty,
                0                                                    as out_amt,
                t.non_std_code,
+               t.sup_id,
                tpobi.remarks,
                t.wh_id,
                tmw.wh_name

+ 1 - 0
src/main/java/com/dk/mdm/model/query/ivt/InboundItemQuery.java

@@ -337,6 +337,7 @@ public class InboundItemQuery extends PageInfo<InboundItemQuery>  {
     @ApiModelProperty(value = "品牌ID")
     private String brandId;
 
+    private Boolean skuIdFlag;
     private static final long serialVersionUID = 1L;
 
 }

+ 3 - 0
src/main/java/com/dk/mdm/model/query/mst/SupplierQuery.java

@@ -155,6 +155,9 @@ import java.time.LocalDateTime;
 
 
 
+        @ApiModelProperty(value = "供应商类别")
+        @TableField(typeHandler = StringListTypeHandler.class)
+        private List<String> supTypeList;
 
 
 

+ 3 - 0
src/main/java/com/dk/mdm/model/vo/ivt/InOutRecordVO.java

@@ -244,6 +244,9 @@ public class InOutRecordVO  {
     @ApiModelProperty(value = "原非标号")
     private String nonStdCodePri;
 
+    @ApiModelProperty(value = "成本金额---出库用")
+    private BigDecimal costAmt;
+
 
 
 

+ 1 - 1
src/main/java/com/dk/mdm/model/vo/pur/PurchaseItemVO.java

@@ -41,7 +41,7 @@ public class PurchaseItemVO extends PageInfo<PurchaseItemVO> implements Serializ
     /**
      * 明细ID
      */
-    @TableId(value = "item_id", type = IdType.AUTO)
+//    @TableId(value = "item_id", type = IdType.AUTO)
     @ApiModelProperty(value = "明细ID")
     @TableField(typeHandler = UuidTypeHandler.class)
     private String itemId;

+ 10 - 13
src/main/java/com/dk/mdm/service/ivt/inbound/InboundPurchaseReturnService.java

@@ -14,10 +14,7 @@ import com.dk.common.service.BaseService;
 import com.dk.mdm.infrastructure.convert.ivt.InboundConvert;
 import com.dk.mdm.infrastructure.convert.ivt.InboundItemConvert;
 import com.dk.mdm.mapper.common.CommonMapper;
-import com.dk.mdm.mapper.ivt.InboundItemMapper;
-import com.dk.mdm.mapper.ivt.InboundMapper;
-import com.dk.mdm.mapper.ivt.IntoReturnItemMapper;
-import com.dk.mdm.mapper.ivt.IntoReturnMapper;
+import com.dk.mdm.mapper.ivt.*;
 import com.dk.mdm.model.pojo.ivt.Inbound;
 import com.dk.mdm.model.pojo.ivt.InboundItem;
 import com.dk.mdm.model.pojo.ivt.IntoReturn;
@@ -26,10 +23,10 @@ import com.dk.mdm.model.pojo.pur.Purchase;
 import com.dk.mdm.model.pojo.pur.PurchaseItem;
 import com.dk.mdm.model.query.ivt.InboundItemQuery;
 import com.dk.mdm.model.query.ivt.InboundQuery;
-import com.dk.mdm.model.response.ivt.InboundItemResponse;
-import com.dk.mdm.model.response.ivt.InboundResponse;
-import com.dk.mdm.model.response.ivt.IntoReturnItemResponse;
-import com.dk.mdm.model.response.ivt.IntoReturnResponse;
+import com.dk.mdm.model.query.ivt.InventoryQuery;
+import com.dk.mdm.model.response.ivt.*;
+import com.dk.mdm.model.response.pur.PurchaseItemResponse;
+import com.dk.mdm.model.response.pur.PurchaseResponse;
 import com.dk.mdm.model.vo.ivt.InboundItemVO;
 import com.dk.mdm.model.vo.ivt.InboundVO;
 import com.dk.mdm.model.vo.ivt.OutboundItemVO;
@@ -45,6 +42,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 
 /**
@@ -514,8 +512,8 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
                 //region 将库存需要的参数赋值
                 inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
                 inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_RETURN.getValue());
-                inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate());
-                inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
+                inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty());
+                inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt());
                 //endregion
 
                 //赋值 赋值明细  防止作废的单据查不到明细 故注掉下面代码
@@ -781,8 +779,8 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
             //region 将库存需要的参数赋值
             inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
             inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_RETURN.getValue());
-            inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate());
-            inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
+            inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty());
+            inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt());
             //endregion
 
             //region修改入库明细信息
@@ -807,7 +805,6 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
         }
         //endregion
 
-
         //region   调用库存
         Map<String, Object> map = new HashMap<>();
         map.put("delIntoDetail", inboundItemResponseList);

+ 261 - 13
src/main/java/com/dk/mdm/service/ivt/inbound/InboundPurchaseService.java

@@ -17,20 +17,28 @@ import com.dk.mdm.infrastructure.convert.ivt.InboundItemConvert;
 import com.dk.mdm.mapper.common.CommonMapper;
 import com.dk.mdm.mapper.ivt.InboundItemMapper;
 import com.dk.mdm.mapper.ivt.InboundMapper;
+import com.dk.mdm.mapper.ivt.InventoryMapper;
 import com.dk.mdm.mapper.pur.PurchaseItemMapper;
 import com.dk.mdm.mapper.pur.PurchaseMapper;
 import com.dk.mdm.model.pojo.ivt.Inbound;
 import com.dk.mdm.model.pojo.ivt.InboundItem;
+import com.dk.mdm.model.pojo.ivt.Outbound;
+import com.dk.mdm.model.pojo.ivt.OutboundItem;
 import com.dk.mdm.model.pojo.pur.Purchase;
 import com.dk.mdm.model.pojo.pur.PurchaseItem;
+import com.dk.mdm.model.pojo.sale.OrderItem;
 import com.dk.mdm.model.query.ivt.InboundItemQuery;
 import com.dk.mdm.model.query.ivt.InboundQuery;
-import com.dk.mdm.model.response.ivt.InboundItemResponse;
-import com.dk.mdm.model.response.ivt.InboundResponse;
+import com.dk.mdm.model.query.ivt.InventoryQuery;
+import com.dk.mdm.model.query.ivt.OutboundItemQuery;
+import com.dk.mdm.model.response.ivt.*;
 import com.dk.mdm.model.response.pur.PurchaseItemResponse;
 import com.dk.mdm.model.response.pur.PurchaseResponse;
+import com.dk.mdm.model.response.sale.OrderItemResponse;
 import com.dk.mdm.model.vo.ivt.InboundItemVO;
 import com.dk.mdm.model.vo.ivt.InboundVO;
+import com.dk.mdm.model.vo.ivt.OutboundItemVO;
+import com.dk.mdm.model.vo.ivt.OutboundVO;
 import com.dk.mdm.service.common.CommonService;
 import com.dk.mdm.service.ivt.inventory.InventoryService;
 import com.dk.mdm.service.mac.AccountService;
@@ -44,6 +52,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 
 /**
@@ -89,6 +98,8 @@ public class InboundPurchaseService extends BaseService<Inbound> {
     @Autowired
     private AccountService accountService;
 
+    @Autowired
+    private InventoryMapper inventoryMapper;
 
     /**
      * @desc : 条件查询
@@ -119,8 +130,8 @@ public class InboundPurchaseService extends BaseService<Inbound> {
     }
 
     /**
-     * @desc   : 查询入库价
-     * @date   : 2024/7/1 11:29
+     * @desc : 查询入库价
+     * @date : 2024/7/1 11:29
      * @author : 寇珊珊
      */
     @Transactional(rollbackFor = {Exception.class})
@@ -153,7 +164,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
         //region  查询当前入库明细中是否存在未空或者0的入库价,如果存在去库存流水差最近一条有价格的数据赋值到当前明细
         Boolean priceIntoFlag = false;
         for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
-            if(inboundItemVO.getCostPrice() == null || inboundItemVO.getCostPrice().compareTo(BigDecimal.ZERO)==0){
+            if (inboundItemVO.getCostPrice() == null || inboundItemVO.getCostPrice().compareTo(BigDecimal.ZERO) == 0) {
                 priceIntoFlag = true;
                 //查询库存批次最近一条入库价
                 InboundItemResponse inboundItemResponse = this.selectPriceInto(inboundItemVO);
@@ -164,7 +175,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
                 inboundItemVO.setCostAmt(inboundItemResponse != null ? inboundItemResponse.getCostPrice().multiply(inboundItemVO.getIntoingQty()).setScale(2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
             }
         }
-        if(priceIntoFlag){
+        if (priceIntoFlag) {
             BigDecimal intoingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
             inboundVO.setIntoingAmt(intoingAmt);
         }
@@ -194,7 +205,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
             //已入库
             inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
             //入库日期
-            inboundVO.setIntoDate( inboundVO.getIntoDate()==null ? LocalDate.now() : inboundVO.getIntoDate() );
+            inboundVO.setIntoDate(inboundVO.getIntoDate() == null ? LocalDate.now() : inboundVO.getIntoDate());
         } else {
             //入库中
             inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
@@ -567,8 +578,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
                 map.put("delIntoDetail", inboundVO.getDeleteItemList());
                 inventoryService.operatingInventoryInformation(map);
                 //endregion
-            }
-            else{
+            } else {
                 throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FLG_HANDLE_SETTING_NOT_ENABLED_INTO.getMessage());
             }
             //endregion
@@ -712,8 +722,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
                     }
                 }
                 //endregion
-            }
-            else{
+            } else {
                 throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FLG_HANDLE_SETTING_NOT_ENABLED_INTO.getMessage());
             }
             //endregion
@@ -975,7 +984,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
                 inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
                 inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
                 //编辑之前的数
-                if(inboundItemResponse.getIntoQty().compareTo(BigDecimal.ZERO)>0) {
+                if (inboundItemResponse.getIntoQty().compareTo(BigDecimal.ZERO) > 0) {
                     inboundItemVO.setQtyBeforeUpdate(inboundItemResponse.getIntoQty());
                     inboundItemVO.setAmtBeforeUpdate(inboundItemResponse.getIntoAmt());
                 }
@@ -1014,7 +1023,7 @@ public class InboundPurchaseService extends BaseService<Inbound> {
             //endregion
 
             //region 采购明细
-            if(inboundItemVO.getFromItemId()!=null){
+            if (inboundItemVO.getFromItemId() != null) {
                 //根据id查询
                 PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
                 //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
@@ -1273,6 +1282,245 @@ public class InboundPurchaseService extends BaseService<Inbound> {
         return ResponseResultUtil.success();
     }
 
+    /*****************************************查库存*****************************************/
+
+    /**
+     * @desc   : 校验库存是否存在和库存量是否足够本次退货作废
+     * @date   : 2024/7/6 10:52
+     * @author : 寇珊珊
+     */
+    @Transactional(
+            rollbackFor = {Exception.class}
+    )
+    public void checkInventoryExist(List<InboundItemResponse> inboundItemResponseList) {
+        for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
+            //存在标识
+            //根据sku,仓库,非标号查询
+            InventoryResponse inventoryResponse = null;
+            if (inboundItemResponse.getSkuId() != null) {
+                inventoryResponse = inventoryMapper.selectByOther(new InventoryQuery()
+                        .setSkuId(inboundItemResponse.getSkuId())
+                        .setWhId(inboundItemResponse.getWhId())
+                        .setNonStdCode(inboundItemResponse.getNonStdCode()));
+            }
+            //库存不存在
+            if (inventoryResponse == null) {
+                //当前出库商品中在库存中不存在
+                throw new BaseBusinessException(ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getCode(),
+                        ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getMessage());
+            }
+            //判断库存中的数量是否足够本次采购退货作废(采购退货作废等于出库)
+            if (inventoryResponse.getInvQty().compareTo(inboundItemResponse.getIntoQty()) < 0) {
+                //当前库存数量不足,不允许采购退货作废操作
+                throw new BaseBusinessException(ErrorCodeEnum.INSUFFICIENT_INVENTORY_NOT_ALLOW_PURCHASE_RETURN.getCode(),
+                        ErrorCodeEnum.INSUFFICIENT_INVENTORY_NOT_ALLOW_PURCHASE_RETURN.getMessage());
+            }
+        }
+    }
+    /*****************************************先判断库存*****************************************/
+
+    /**
+     * @desc : 一键作废
+     * @date : 2024/7/6 11:03
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public ResponseResultVO<?> oneKeyPurchaseInboundRepeal(String orderId) {
+        List<InboundItemResponse> InboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().setFromId(orderId));
+        if (InboundItemResponses != null && InboundItemResponses.size() > 0) {
+            Map<String, List<InboundItemResponse>> inboundItemMap = InboundItemResponses.stream().collect(Collectors.groupingBy(InboundItemResponse::getIntoId));
+            for (String str : inboundItemMap.keySet()) {
+                //region  查询总单  查询明细
+                //根据id查询 此条入库单的数据还未更改前的数据
+                InboundResponse inboundResponse = inboundMapper.selectById(str);
+                //根据总单id查询
+                List<InboundItemResponse> inboundItemResponseList = inboundItemMapper.selectByCond(new InboundItemQuery().setOutId(inboundResponse.getIntoId()));
+                //endregion
+
+                //region 已入库状态作废
+                if (Constant.IntoStatus.YIRUKU.getName().equals(inboundResponse.getIntoStatus())) {
+
+                    //region  查询当前订单下的入库单的库存是否足够允许作废
+                    this.checkInventoryExist(inboundItemResponseList);
+                    //endregion
+
+                    //region 退账
+                    if (inboundResponse.getReceivableId() != null) {
+                        accountService.reversePayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
+                    }
+                    //endregion
+
+                    //region 修改明细
+                    for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
+
+                        //region 将库存需要的参数赋值
+                        inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
+                        inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
+                        inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate());
+                        inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
+                        //endregion
+
+                        //region  编辑明细  赋值 赋值明细  防止作废的单据查不到明细 故注掉下面代码
+//                InboundItem inboundItem = new InboundItem();
+//                inboundItem.setItemId(inboundItemResponse.getItemId());
+//                inboundItem.setFlgValid(false);
+//                //修改
+//                inboundItemMapper.update(inboundItem,
+//                        new UpdateWrapper<InboundItem>().lambda()
+//                                .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+//                );
+                        //endregion
+
+                        //region  销售明细
+                        if (inboundItemResponse.getFromItemId() != null) {
+                            //根据id查询
+                            PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
+                            PurchaseItem purchaseItem = new PurchaseItem();
+                            purchaseItem.setItemId(inboundItemResponse.getFromItemId());
+                            purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate());
+                            purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
+                            //入库状态
+                            String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty(),
+                                    purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty());
+                            purchaseItem.setIntoStatus(intoStatus);
+                            int countRow = purchaseItemMapper.updateById(purchaseItem);
+                            //数量超出
+                            if (countRow == 0) {
+                                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                            }
+                        }
+                        //endregion
+                    }
+                    //endregion
+
+                    //region  修改入库总单
+                    Inbound inbound = new Inbound();
+                    inbound.setIntoId(inboundResponse.getIntoId());
+                    inbound.setFlgValid(false);
+                    //修改
+                    inboundMapper.update(inbound,
+                            new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
+                    );
+                    //endregion
+
+                    //region 修改销售总单
+                    if (inboundResponse.getFromId() != null) {
+                        //根据id查询
+                        PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundResponse.getFromId());
+                        Purchase purchase = new Purchase();
+                        purchase.setPurId(inboundResponse.getFromId());
+                        purchase.setIntoQty(inboundResponse.getIntoQty().negate());
+                        purchase.setIntoAmt(inboundResponse.getIntoAmt().negate());
+                        //入库状态
+                        String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty(),
+                                purchaseResponse.getIntoQty().add(purchase.getIntoQty()), purchaseResponse.getSumQuantity());
+                        purchase.setIntoStatus(intoStatus);
+                        //修改
+                        int countRow = purchaseMapper.updateById(purchase);
+                        //数量超出
+                        if (countRow == 0) {
+                            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                        }
+                    }
+                    //endregion
+
+                    //region  入账
+                    if (inboundResponse.getReceivableId() != null) {
+                        accountService.accPayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
+                    }
+                    //endregion
+
+                    //region   调用库存
+                    Map<String, Object> map = new HashMap<>();
+                    map.put("delIntoDetail", inboundItemResponseList);
+                    inventoryService.operatingInventoryInformation(map);
+                    //endregion
+                }
+                //endregion
+
+                //region 出库中、待出库状态作废
+                if (Constant.IntoStatus.DAIRUKU.getName().equals(inboundResponse.getIntoStatus()) ||
+                        Constant.IntoStatus.RUKUZHONG.getName().equals(inboundResponse.getIntoStatus())) {
+
+                    //region 修改明细
+                    for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
+                        //region 编辑明细 赋值
+                        InboundItem inboundItem = new InboundItem();
+                        inboundItem.setItemId(inboundItemResponse.getItemId());
+                        inboundItem.setIntoingQty(BigDecimal.ZERO);
+                        inboundItem.setIntoingAmt(BigDecimal.ZERO);
+//                inboundItem.setFlgValid(false);
+                        //修改
+                        inboundItemMapper.update(inboundItem,
+                                new UpdateWrapper<InboundItem>().lambda()
+                                        .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+                        );
+                        //endregion
+
+                        //region  销售明细
+                        if (inboundItemResponse.getFromItemId() != null) {
+                            //根据id查询
+                            PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
+                            PurchaseItem purchaseItem = new PurchaseItem();
+                            purchaseItem.setItemId(inboundItemResponse.getFromItemId());
+                            purchaseItem.setIntoingQty(inboundItemResponse.getIntoingQty().negate());
+                            purchaseItem.setIntoingAmt(inboundItemResponse.getIntoingAmt().negate());
+                            //入库状态
+                            String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
+                                    purchaseItemResponse.getIntoQty(), purchaseItemResponse.getItemQty());
+                            purchaseItem.setIntoStatus(intoStatus);
+                            int countRow = purchaseItemMapper.updateById(purchaseItem);
+                            //数量超出
+                            if (countRow == 0) {
+                                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                            }
+                        }
+                        //endregion
+                    }
+                    //endregion
+
+                    //region  修改入库总单
+                    Inbound inbound = new Inbound();
+                    inbound.setIntoId(inboundResponse.getIntoId());
+                    inbound.setIntoingQty(BigDecimal.ZERO);
+                    inbound.setIntoAmt(BigDecimal.ZERO);
+                    inbound.setFlgValid(false);
+                    //修改
+                    inboundMapper.update(inbound,
+                            new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
+                    );
+                    //endregion
+
+                    //region 修改销售总单
+                    if (inboundResponse.getFromId() != null) {
+                        //根据id查询
+                        PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundResponse.getFromId());
+                        Purchase purchase = new Purchase();
+                        purchase.setPurId(inboundResponse.getFromId());
+                        purchase.setIntoingQty(inboundResponse.getIntoingQty().negate());
+                        purchase.setIntoingAmt(inboundResponse.getIntoingAmt().negate());
+                        //入库状态
+                        String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
+                                purchaseResponse.getIntoQty(), purchaseResponse.getSumQuantity());
+                        purchase.setIntoStatus(intoStatus);
+                        //修改
+                        int countRow = purchaseMapper.updateById(purchase);
+                        //数量超出
+                        if (countRow == 0) {
+                            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                        }
+                    }
+
+                    //endregion
+                }
+                //endregion
+            }
+        }
+        return ResponseResultUtil.success();
+    }
+
+
+
     /**
      * @desc : 入库状态通用(目前本页面)
      * @date : 2024/3/9 8:59

+ 2 - 9
src/main/java/com/dk/mdm/service/ivt/inventory/InventoryService.java

@@ -193,9 +193,9 @@ public class InventoryService extends BaseService<Inventory> {
                 //入库数量
                 inOutRecordVO.setIntoQty(inOutRecordVO.getOutQty());
                 //入库价
-                inOutRecordVO.setPriceInto(inOutRecordVO.getPriceOut());
+                inOutRecordVO.setPriceInto(inOutRecordVO.getCostPrice());
                 //入库金额
-                inOutRecordVO.setIntoAmt(inOutRecordVO.getOutAmt());
+                inOutRecordVO.setIntoAmt(inOutRecordVO.getCostAmt());
             }
             //endregion
             //入库日期
@@ -277,13 +277,6 @@ public class InventoryService extends BaseService<Inventory> {
     )
     public ResponseResultVO<?> operatingInventoryInformation(Map<String, Object> map) {
 
-        //region  todo 这里可能会用到 返回的map
-        List<InOutRecordVO> intoReturnList = new ArrayList<>();
-        List<InOutRecordVO> deleteIntoList = new ArrayList<>();
-        List<InOutRecordVO> outReturnList = new ArrayList<>();
-        List<InOutRecordVO> deleteOutList = new ArrayList<>();
-        //endregion
-
         // region 库存接收类型对应  和  新建还是删除标识
         String inventoryDocCode = null;
         Boolean addOrEditFlag = true;

+ 3 - 4
src/main/java/com/dk/mdm/service/ivt/outbound/OutboundSaleOrderService.java

@@ -523,7 +523,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
 
             //region 销售明细
             if (outboundItemVO.getFromItemId() != null) {
-                //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+                //赋值 (这里重写了更新方法,数量在更新方法中有数据库数量+本次数量)
                 OrderItem orderItem = new OrderItem();
                 orderItem.setItemId(outboundItemVO.getFromItemId());
                 //根据id查询
@@ -1817,8 +1817,8 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
             //region 将库存需要的参数赋值
             outboundItemResponse.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
             outboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
-            outboundItemResponse.setOutQty(outboundItemResponse.getOutQty().negate());
-            outboundItemResponse.setOutQty(outboundItemResponse.getOutQty().negate());
+            outboundItemResponse.setOutQty(outboundItemResponse.getOutQty());
+            outboundItemResponse.setOutQty(outboundItemResponse.getOutQty());
             //endregion
 
             outboundItem
@@ -1904,7 +1904,6 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
         }
     }
 
-
     /**
      * @desc   : 销售出库一键作废
      * @date   : 2024/7/1 13:29

+ 41 - 16
src/main/java/com/dk/mdm/service/ivt/outbound/OutboundSaleReturnService.java

@@ -124,12 +124,14 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
         Map<String, List<OutboundItemVO>> outboundItemVOListOutPri = outboundVO.getItemList().stream().collect(Collectors.groupingBy(OutboundItemVO::getSOutId));
         for (String str : outboundItemVOListOutPri.keySet()) {
             List<OutboundItemVO> outboundItemList = outboundItemVOListOutPri.get(str);
+
             //region 汇总退货数量 金额
             BigDecimal returnSumQty = outboundItemList.stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
             BigDecimal returnSumAmt = outboundItemList.stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
             BigDecimal returnIngSumQty = outboundItemList.stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
             BigDecimal returnIngSumAmt = outboundItemList.stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
             //endregion
+
             //查询原单
             OutboundResponse outboundResponse = outboundMapper.selectById(str);
             //校验数据
@@ -154,6 +156,7 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
         Map<String, List<OutboundItemVO>> outboundItemVOListOrderPri = outboundVO.getItemList().stream().collect(Collectors.groupingBy(OutboundItemVO::getSOrderId));
         for (String str : outboundItemVOListOrderPri.keySet()) {
             List<OutboundItemVO> outboundItemList = outboundItemVOListOrderPri.get(str);
+
             //region 汇总退货数量 金额
             BigDecimal returnSumQty = outboundItemList.stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
             BigDecimal returnSumAmt = outboundItemList.stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
@@ -161,6 +164,7 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
             BigDecimal returnIngSumAmt = outboundItemList.stream().map(OutboundItemVO::getOutingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
 
             //endregion
+
             //查询原单
             OrderResponse orderResponse = orderMapper.selectById(str);
             //校验数据
@@ -248,6 +252,7 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
      */
     @Transactional(rollbackFor = {Exception.class})
     public void rollBackTotalAndDetail(List<OutboundItemVO> deleteItemList) {
+        //注意:销售退货生成的出库单 数据是负数的,销售退货上游单据销售订单和销售出库的退货相应字段是正数,所以下面的代码 不用取负数
         if (deleteItemList.size() > 0 ) {
             if(deleteItemList.get(0).getSOutId() != null ) {
                 //出库单
@@ -261,15 +266,23 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
                     //总单
                     Outbound outboundPri = new Outbound();
                     outboundPri.setOutId(outId);
-                    outboundPri.setReturnQty((delOutQty.add(delOutingQty)).negate());
-                    outboundPri.setReturnAmt(delOutAmt.add(delOutingAmt).negate());
+                    outboundPri.setReturnQty((delOutQty.add(delOutingQty)));
+                    outboundPri.setReturnAmt((delOutAmt.add(delOutingAmt)));
                     outboundMapper.updateReturnMessage(outboundPri);
                     //明细
                     for (OutboundItemVO outboundItemVO : outboundItemVOList) {
                         OutboundItem outboundItemPri = new OutboundItem();
-                        outboundItemPri.setItemId(outboundItemVO.getItemId());
-                        outboundItemPri.setReturnQty(outboundItemVO.getOutingQty());
-                        outboundItemPri.setReturnAmt(outboundItemVO.getOutingAmt());
+                        outboundItemPri.setItemId(outboundItemVO.getSOutItemId());
+                        //已出库
+                        if (Constant.OutStatus.YICHUKU.getName().equals(outboundItemVO.getOutStatus())) {
+                            outboundItemPri.setReturnQty(outboundItemVO.getOutQty());
+                            outboundItemPri.setReturnAmt(outboundItemVO.getOutAmt());
+                        }
+                        //出库中
+                        else if(Constant.OutStatus.CHUKUZHONG.getName().equals(outboundItemVO.getOutStatus())){
+                            outboundItemPri.setReturnQty(outboundItemVO.getOutingQty());
+                            outboundItemPri.setReturnAmt(outboundItemVO.getOutingAmt());
+                        }
                         outboundItemMapper.updateReturnMessage(outboundItemPri);
                     }
                 }
@@ -286,15 +299,23 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
                     //总单
                     Order orderPri = new Order();
                     orderPri.setOrderId(orderId);
-                    orderPri.setReturnQty((delOutQty.add(delOutingQty)).negate());
-                    orderPri.setReturnAmt(delOutAmt.add(delOutingAmt).negate());
+                    orderPri.setReturnQty((delOutQty.add(delOutingQty)));
+                    orderPri.setReturnAmt((delOutAmt.add(delOutingAmt)));
                     orderMapper.updateReturnMessage(orderPri);
                     //明细
                     for (OutboundItemVO outboundItemVO : outboundItemVOList) {
                         OrderItem orderItemPri = new OrderItem();
-                        orderItemPri.setItemId(outboundItemVO.getItemId());
-                        orderItemPri.setReturnQty(outboundItemVO.getOutingQty());
-                        orderItemPri.setReturnAmt(outboundItemVO.getOutingAmt());
+                        orderItemPri.setItemId(outboundItemVO.getSOrderItemId());
+                        //已出库
+                        if (Constant.OutStatus.YICHUKU.getName().equals(outboundItemVO.getOutStatus())) {
+                            orderItemPri.setReturnQty(outboundItemVO.getOutQty());
+                            orderItemPri.setReturnAmt(outboundItemVO.getOutAmt());
+                        }
+                        //出库中
+                        else if(Constant.OutStatus.CHUKUZHONG.getName().equals(outboundItemVO.getOutStatus())){
+                            orderItemPri.setReturnQty(outboundItemVO.getOutingQty());
+                            orderItemPri.setReturnAmt(outboundItemVO.getOutingAmt());
+                        }
                         orderItemMapper.updateReturnMessage(orderItemPri);
                     }
                 }
@@ -848,8 +869,8 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
                 //region 将库存需要的参数赋值
                 outboundItemResponse.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
                 outboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.SALE_RETURN.getValue());
-                outboundItemResponse.setOutQty(outboundItemResponse.getOutQty().negate());
-                outboundItemResponse.setOutAmt(outboundItemResponse.getOutAmt().negate());
+                outboundItemResponse.setOutQty(outboundItemResponse.getOutQty());
+                outboundItemResponse.setOutAmt(outboundItemResponse.getOutAmt());
                 //endregion
 
 //                //region 赋值明细  防止作废的单据查不到明细 故注掉下面代码
@@ -877,8 +898,12 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
 
             //region  修改库存
             Map<String, Object> map = new HashMap<>();
-            map.put("delOutDetail", outboundItemResponseList);
-            inventoryService.operatingInventoryInformation(map);
+            // 过滤掉外协
+            List<OutboundItemResponse> goodsList = outboundItemResponseList.stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
+            if(goodsList != null && goodsList.size() > 0){
+                map.put("delOutDetail", goodsList);
+                inventoryService.operatingInventoryInformation(map);
+            }
             //endregion
         }
         //endregion
@@ -1163,8 +1188,8 @@ public class OutboundSaleReturnService extends BaseService<Outbound> {
             //region 将库存需要的参数赋值
             outboundItemResponse.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
             outboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.SALE_RETURN.getValue());
-            outboundItemResponse.setOutQty(outboundItemResponse.getOutQty().negate());
-            outboundItemResponse.setOutAmt(outboundItemResponse.getOutAmt().negate());
+            outboundItemResponse.setOutQty(outboundItemResponse.getOutQty());
+            outboundItemResponse.setOutAmt(outboundItemResponse.getOutAmt());
             outboundItemResponse.setAddOrEditFlag(false);
             //endregion
         }

+ 262 - 6
src/main/java/com/dk/mdm/service/mac/ReceiptService.java

@@ -672,9 +672,9 @@ public class ReceiptService extends BaseService<RecPay> {
 //            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
 //        }
         // 可用金额为负数,则不能保存
-        if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
-            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
-        }
+//        if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
+//            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
+//        }
         accountService.updateByUuid(accountUpdate);
 
         // 将之前的明细全部删除
@@ -807,13 +807,269 @@ public class ReceiptService extends BaseService<RecPay> {
         }
 
         // 插入账款总表
-        Account accountForUpdate = accountService.getCusAccountForUpdate(recPayVO.getObjectId());
+        Account accountForUpdate = accountService.getSupAccountForUpdate(recPayVO.getObjectId());
         // 更新账款总表上收款的相关字段
         Account accountUpdate = new Account();
-        accountUpdate.setReceipt(accountForUpdate.getReceipt().add(recPayVO.getSumAmtPay()))// 总收款金额
-                .setReceiptResidue(accountForUpdate.getReceiptResidue().add(recPayVO.getSumAmtPay()))//  可退金额
+        accountUpdate.setPayment(accountForUpdate.getPayment().add(recPayVO.getSumAmtPay()))// 总收款金额
+                .setPaymentResidue(accountForUpdate.getPaymentResidue().add(recPayVO.getSumAmtPay()))//  可退金额
+                .setObjectId(accountForUpdate.getObjectId());
+        accountService.updateByUuid(accountUpdate);
+        return ResponseResultUtil.success();
+    }
+
+
+
+    /**
+     * @desc : 新建供应商退款
+     * @author : 于继渤
+     * @date :  2024/7/5 10:48
+     */
+    @Transactional(
+            rollbackFor = {Exception.class}
+    )
+    public ResponseResultVO<?> insertSupRefund(RecPayVO recPayVO) {
+
+        // 查总账,看可退金额是否满足
+        Account accountForUpdate = accountMapper.selectByIdForUpdate(recPayVO.getObjectId());
+        // 获取单号
+        Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.RECPAY.getName(), false);
+        recPayVO.setRpId(codeMap.get("outId").toString()).setRpNo(codeMap.get("outNote").toString());
+        // 转化实体
+        RecPay recPay = recPayConvert.convertToPo(recPayVO);
+        // 总单保存
+        super.insert(recPay);
+
+        // 明细保存
+        if (recPayVO.getItemList() != null && recPayVO.getItemList().size() > 0) {
+            for (RecPayItemVO recPayItemVO : recPayVO.getItemList()) {
+                RecPayItem recPayItem = recPayItemConvert.convertToPo(recPayItemVO);
+                recPayItem.setRpId(recPay.getRpId()).setCpId(recPay.getCpId()).setMakeStaff(recPay.getMakeStaff()).setAccDate(recPay.getAccDate());
+                recPayItemMapper.insert(recPayItem);
+
+                // 插入账款明细
+                AccountItem accountItem = new AccountItem();
+                accountItem.setAccItemType(Constant.accItemType.SHOU_KUAN.getName())
+                        .setObjectId(recPayVO.getObjectId()).setOrgId(recPayVO.getOrgId()).setStaffId(recPayVO.getStaffId())
+                        .setAccDate(recPayVO.getAccDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName()).setAmtPay(recPayItem.getAmtPay())
+                        .setBiznisType("t_mac_rec_pay_item").setBiznisId(recPayItem.getItemId()).setBiznisNo(recPayVO.getRpNo())
+                        .setMakeStaff(recPayVO.getMakeStaff()).setCpId(recPayVO.getCpId());
+                accountItemMapper.insert(accountItem);
+
+                // 更新收款单上的账款明细Id
+                RecPayItem recPayItemUpdate = new RecPayItem();
+                recPayItemUpdate.setAccItemId(accountItem.getItemId()).setItemId(recPayItem.getItemId());
+                recPayItemService.updateByUuid(recPayItemUpdate);
+
+                // 插入资金流水
+                MoneyAccountItem moneyAccountItem = new MoneyAccountItem();
+                moneyAccountItem.setMacId(recPayItem.getMacId()).setFlowType(Constant.FlowType.SHOU_FU_KUAN.getName())
+                        .setInvoiceId(recPayItem.getItemId()).setAmtInflow(recPayItem.getAmtPay()).setAccDate(recPayVO.getAccDate())
+                        .setMakeStaff(recPayItem.getMakeStaff()).setCpId(recPayItem.getCpId());
+                moneyAccountItemMapper.insert(moneyAccountItem);
+
+                // 更新资金账户
+                MoneyAccount moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(recPayItem.getMacId());
+                MoneyAccount moneyAccountUpdate = new MoneyAccount();
+                moneyAccountUpdate.setBalance(moneyAccountForUpdate.getBalance().add(recPayItem.getAmtPay()))
+                        .setMacId(moneyAccountForUpdate.getMacId());
+
+                // 如果账户不允许为负数
+                if (!moneyAccountForUpdate.getFlgNegative()) {
+                    // 如果余额小于0 ,则提示余额不足
+                    if (moneyAccountUpdate.getBalance().compareTo(BigDecimal.ZERO) == -1) {
+                        throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
+                    }
+                }
+                moneyAccountService.updateByUuid(moneyAccountUpdate);
+            }
+        }
+
+        // 更新账款总表上收款的相关字段
+        Account accountUpdate = new Account();
+        // 新建
+        if(accountForUpdate == null ){
+            // TODO 退货新客户插入的问题
+        }else{
+            // 说明已经存在
+            accountUpdate.setPayment(accountForUpdate.getPayment().add(recPayVO.getSumAmtPay()))// 总收款金额
+                    .setPaymentResidue(accountForUpdate.getPaymentResidue().add(recPayVO.getSumAmtPay()))//  可退金额
+                    .setObjectId(accountForUpdate.getObjectId());
+            accountService.updateByUuid(accountUpdate);
+        }
+
+        return ResponseResultUtil.success();
+    }
+
+    /**
+     * @desc : 编辑供应商收款/退款
+     * @author : 于继渤
+     * @date : 2023/1/9 10:49
+     */
+    @Transactional(
+            rollbackFor = {Exception.class}
+    )
+    public ResponseResultVO<?> updateSupReceipt(RecPayVO recPayVO) {
+        RecPay recPayForUpdate = recPayMapper.selectByIdForUpdate(recPayVO.getRpId());
+        // 并发校验
+        if (!recPayForUpdate.getFlgValid()) {
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
+        }
+
+        // 将之前的明细全部删除
+        List<RecPayItem> recPayItemOriginalList = recPayItemMapper.selectByZIdForUpdate(recPayVO.getRpId());
+        // 需要重新计算的资金账户
+        List<String> macList = new ArrayList<>();
+        for (RecPayItem recPayItem : recPayItemOriginalList) {
+            // 删除收付款明细
+//            recPayItemMapper.deleteById(recPayItem.getItemId());
+            //            改为更新false
+            RecPayItem recPayItemNew = new RecPayItem();
+            recPayItemNew.setItemId(recPayItem.getItemId()).setFlgValid(false);
+            recPayItemService.updateByUuid(recPayItemNew);
+            // 删除账款明细
+            accountItemMapper.deleteById(recPayItem.getAccItemId());
+            // 删除账户流水
+            moneyAccountItemMapper.deleteByInvoiceId(recPayItem.getItemId());
+
+            if (!macList.contains(recPayItem.getMacId())) {
+                macList.add(recPayItem.getMacId());
+            }
+        }
+
+        // 新增明细
+        for (RecPayItemVO recPayItemVO : recPayVO.getItemList()) {
+            RecPayItem recPayItem = recPayItemConvert.convertToPo(recPayItemVO);
+            recPayItem.setItemId(null).setRpId(recPayVO.getRpId()).setCpId(recPayVO.getCpId());
+            recPayItemMapper.insert(recPayItem);
+
+            // 插入账款明细
+            AccountItem accountItem = new AccountItem();
+            accountItem.setAccItemType(Constant.accItemType.SHOU_KUAN.getName())
+                    .setObjectId(recPayVO.getObjectId()).setOrgId(recPayVO.getOrgId()).setStaffId(recPayVO.getStaffId())
+                    .setAccDate(recPayVO.getAccDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName()).setAmtPay(recPayItem.getAmtPay())
+                    .setBiznisType("t_mac_rec_pay_item").setBiznisId(recPayItem.getItemId()).setBiznisNo(recPayVO.getRpNo())
+                    .setMakeStaff(recPayVO.getMakeStaff()).setCpId(recPayVO.getCpId());
+            accountItemMapper.insert(accountItem);
+
+            // 更新收款单上的账款明细Id
+            RecPayItem recPayItemUpdate = new RecPayItem();
+            recPayItemUpdate.setAccItemId(accountItem.getItemId()).setItemId(recPayItem.getItemId());
+            recPayItemService.updateByUuid(recPayItemUpdate);
+
+            // 插入资金流水
+            MoneyAccountItem moneyAccountItem = new MoneyAccountItem();
+            moneyAccountItem.setMacId(recPayItem.getMacId()).setFlowType(Constant.FlowType.SHOU_FU_KUAN.getName())
+                    .setInvoiceId(recPayItem.getItemId()).setAmtInflow(recPayItem.getAmtPay()).setAccDate(recPayVO.getAccDate())
+                    .setMakeStaff(recPayItem.getMakeStaff()).setCpId(recPayItem.getCpId());
+            moneyAccountItemMapper.insert(moneyAccountItem);
+
+            if (!macList.contains(recPayItem.getMacId())) {
+                macList.add(recPayItem.getMacId());
+            }
+        }
+
+        // 更新总账表的总收款额和可用额
+        accountService.updatePayment(recPayVO.getObjectId());
+        // 更新账户余额
+        for (String macId : macList) {
+            accountService.updateMac(macId);
+        }
+
+        // 更新收款单总表
+        RecPay recPay = recPayConvert.convertToPo(recPayVO);
+        return ResponseResultUtil.success(super.updateByUuid(recPay));
+    }
+
+
+
+    /**
+     * @desc : 作废
+     * @author : 于继渤
+     * @date : 2024-03-08 16:38
+     */
+    public ResponseResultVO<?> invalidSup(String id) {
+        RecPay recPayForUpdate = recPayMapper.selectByIdForUpdate(id);
+        // 并发校验
+        if (!recPayForUpdate.getFlgValid()) {
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
+        }
+        // 240624 问完付斌后
+//        if(recPayForUpdate.getBiznisId() != null){
+//            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVOICE_FORBID_EDIT.getMessage());
+//        }
+        // 如果所在月份已结账,则不能作废 todo
+
+        // 查出并锁定所有应收核销明细
+        AccountItem accountItemForUpdate;
+        List<RecPayHandleItem> recPayHandleItemForUpdateList = recPayHandleItemMapper.selectByZIdForUpdate(id);
+        for (RecPayHandleItem recPayHandleItemForUpdate : recPayHandleItemForUpdateList) {
+            // 更新账款明细应收收款
+            accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItemForUpdate.getAccItemId());
+            AccountItem accountItemUpdate = new AccountItem();
+            accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().subtract(recPayHandleItemForUpdate.getAmtPayableHandle()))
+                    .setAmtWaive(accountItemForUpdate.getAmtWaive().subtract(recPayHandleItemForUpdate.getAmtWaive()))
+                    .setItemId(recPayHandleItemForUpdate.getAccItemId());
+            accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()).subtract(accountItemUpdate.getAmtWaive()));
+            accountItemService.updateByUuid(accountItemUpdate);
+
+            // 将核销明细有效标识置为false
+            RecPayHandleItem recPayHandleItemUpdate = new RecPayHandleItem();
+            recPayHandleItemUpdate.setFlgValid(false).setItemId(recPayHandleItemForUpdate.getItemId());
+            recPayHandleItemService.updateByUuid(recPayHandleItemUpdate);
+        }
+
+        // 把总帐上的钱加回来
+        Account accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
+        Account accountUpdate = new Account();
+        accountUpdate.setPayableHandle(accountForUpdate.getPayableHandle().subtract(recPayForUpdate.getSumAmtPayableHandle()))// 总应收收款金额
+                .setPayableWaive(accountForUpdate.getPayableWaive().subtract(recPayForUpdate.getSumWaiveAmt()))//  总应收优惠金额
                 .setObjectId(accountForUpdate.getObjectId());
+        // 剩余应收 = 总应收账款-总应收收款金额
+        accountUpdate.setPaymentResidue(accountForUpdate.getPayable().subtract(accountUpdate.getPayableHandle()));
+        // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
+        accountUpdate.setPaymentResidue(accountForUpdate.getPayment().subtract(accountUpdate.getPayableHandle()).add(accountUpdate.getPayableWaive()));
+
+        // 更新前的最后校验
+        // 剩余应收为负数,则不能保存
+//        if (accountUpdate.getReceivableResidue().compareTo(BigDecimal.ZERO) == -1) {
+//            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
+//        }
+        // 可用金额为负数,则不能保存
+        if (accountUpdate.getPaymentResidue().compareTo(BigDecimal.ZERO) == -1) {
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
+        }
         accountService.updateByUuid(accountUpdate);
+
+        // 将之前的明细全部删除
+        List<RecPayItem> recPayItemOriginalList = recPayItemMapper.selectByZIdForUpdate(id);
+        // 需要重新计算的资金账户
+        List<String> macList = new ArrayList<>();
+        for (RecPayItem recPayItem : recPayItemOriginalList) {
+            // 删除收付款明细
+//            recPayItemMapper.deleteById(recPayItem.getItemId());
+//            改为更新false
+            RecPayItem recPayItemNew = new RecPayItem();
+            recPayItemNew.setItemId(recPayItem.getItemId()).setFlgValid(false);
+            recPayItemService.updateByUuid(recPayItemNew);
+            // 删除账款明细
+            accountItemMapper.deleteById(recPayItem.getAccItemId());
+            // 删除账户流水
+            moneyAccountItemMapper.deleteByInvoiceId(recPayItem.getItemId());
+
+            if (!macList.contains(recPayItem.getMacId())) {
+                macList.add(recPayItem.getMacId());
+            }
+        }
+        // 更新总账表的总收款额和可用额
+        accountService.updatePayment(recPayForUpdate.getObjectId());
+        // 更新账户余额
+        for (String macId : macList) {
+            accountService.updateMac(macId);
+        }
+        // 作废
+        RecPay recPayUpdate = new RecPay();
+        recPayUpdate.setFlgValid(false).setRpId(id);
+        super.updateByUuid(recPayUpdate);
         return ResponseResultUtil.success();
     }
 

+ 65 - 6
src/main/java/com/dk/mdm/service/pur/PurchaseService.java

@@ -15,6 +15,9 @@ import com.dk.mdm.infrastructure.convert.ivt.InboundItemConvert;
 import com.dk.mdm.infrastructure.convert.pur.PurChaseConvert;
 import com.dk.mdm.infrastructure.convert.pur.PurChaseItemConvert;
 import com.dk.mdm.mapper.common.CommonMapper;
+import com.dk.mdm.mapper.ivt.InboundItemMapper;
+import com.dk.mdm.mapper.ivt.InboundMapper;
+import com.dk.mdm.mapper.ivt.InventoryMapper;
 import com.dk.mdm.mapper.mst.GoodsSkuMapper;
 import com.dk.mdm.mapper.pur.PurchaseItemMapper;
 import com.dk.mdm.model.pojo.mst.GoodsSku;
@@ -24,17 +27,24 @@ import com.dk.common.service.BaseService;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.mdm.model.pojo.pur.PurchaseItem;
 import com.dk.mdm.model.pojo.sale.Order;
+import com.dk.mdm.model.query.ivt.InboundItemQuery;
+import com.dk.mdm.model.query.ivt.InventoryQuery;
 import com.dk.mdm.model.query.pur.PurchaseItemQuery;
 import com.dk.mdm.model.query.pur.PurchaseQuery;
+import com.dk.mdm.model.response.ivt.InboundItemResponse;
+import com.dk.mdm.model.response.ivt.InventoryResponse;
 import com.dk.mdm.model.response.mst.GoodsSkuResponse;
 import com.dk.mdm.model.response.pur.PurchaseItemResponse;
 import com.dk.mdm.model.response.pur.PurchaseResponse;
 import com.dk.mdm.model.vo.ivt.InboundItemVO;
 import com.dk.mdm.model.vo.ivt.InboundVO;
+import com.dk.mdm.model.vo.ivt.OutboundItemVO;
+import com.dk.mdm.model.vo.ivt.OutboundVO;
 import com.dk.mdm.model.vo.pur.PurchaseItemVO;
 import com.dk.mdm.model.vo.pur.PurchaseVO;
 import com.dk.mdm.service.common.CommonService;
 import com.dk.mdm.service.ivt.inbound.InboundItemService;
+import com.dk.mdm.service.ivt.inbound.InboundPurchaseReturnService;
 import com.dk.mdm.service.ivt.inbound.InboundPurchaseService;
 import com.dk.mdm.service.ivt.inbound.InboundService;
 import org.springframework.stereotype.Service;
@@ -99,6 +109,9 @@ public class PurchaseService extends BaseService<Purchase> {
     @Autowired
     private InboundPurchaseService inboundPurchaseService;
 
+    @Autowired
+    private InboundItemMapper inboundItemMapper;
+
     /**
      * @desc : 条件查询
      * @author : 常皓宁
@@ -157,8 +170,6 @@ public class PurchaseService extends BaseService<Purchase> {
         purchasevo.setMakeTime(LocalDateTime.now());
         // 单据类型
         purchasevo.setPurType(Constant.DocumentType.PUR_CHASE.getName());
-        // 入库状态
-        purchasevo.setIntoStatus(Constant.IntoStatus.DAIRUKU.getName());
         // 订单状态
         purchasevo.setPurStatus(Constant.OrderStatus.STATUS_DEAL.getName());
         // 获取单号
@@ -167,20 +178,21 @@ public class PurchaseService extends BaseService<Purchase> {
         purchasevo.setPurNo(codeMap.get("outNote").toString());
         Purchase purchase = purChaseConvert.convertToPo(purchasevo);
         super.insert(purchase);
+        purchasevo.setPurId(purchase.getPurId());
         //endregion
         //region 设置采购订单明细信息并新建
 //        List<PurchaseItemVO> purchaseItemVOList = purchasevo.getPurchaseItemVOList().stream().filter(it -> it.getItemId() == null).collect(Collectors.toList());
-        List<PurchaseItemVO> purchaseItemVOList = purchasevo.getPurchaseItemVOList();
+//        List<PurchaseItemVO> purchaseItemVOList = purchasevo.getPurchaseItemVOList();
         // 商品顺序
-        for (PurchaseItemVO purchaseItemVO : purchaseItemVOList) {
+        for (PurchaseItemVO purchaseItemVO : purchasevo.getPurchaseItemVOList()) {
             PurchaseItem purchaseItem = purchaseItemConvert.convertToPo(purchaseItemVO);
             purchaseItem.setPurId(purchase.getPurId());
             purchaseItem.setItemIndex(purchaseItemVO.getItemIndex());
-            purchaseItem.setIntoStatus(Constant.IntoStatus.DAIRUKU.getName());
             purchaseItem.setCpId(purchase.getCpId());
-            purchaseItem.setItemId(null);
+//            purchaseItem.setItemId(null);
             purchaseItem.setPriceDiscount(purchaseItemVO.getPriceDiscount());
             purchaseItemMapper.insert(purchaseItem);
+            purchaseItemVO.setItemId(purchaseItem.getItemId());
         }
         //endregion
 
@@ -195,6 +207,8 @@ public class PurchaseService extends BaseService<Purchase> {
                 //endregion
 
                 //region 赋值 采购订单明细和入库单明细不一致的字段要单独set
+                //id制空,这里的id经过转换以后是采购订单明细的id
+                inboundItemVO.setItemId(null);
                 //来源id
                 inboundItemVO.setFromId(purchasevo.getPurId());
                 //来源明细id
@@ -243,6 +257,10 @@ public class PurchaseService extends BaseService<Purchase> {
 
             //region 总单
             InboundVO inboundVO = inboundConvert.convertPurchaseVOToInboundVO(purchasevo);
+            //入库中数量
+            inboundVO.setIntoingQty(purchasevo.getSumQuantity());
+            //已入库数量
+            inboundVO.setIntoingAmt(purchasevo.getSumAmount());
             inboundVO.setItemList(inboundItemVOList);
             //endregion
             //新建采购入库单
@@ -503,4 +521,45 @@ public class PurchaseService extends BaseService<Purchase> {
         data.setList(dataList);
         return ResponseResultUtil.success(data);
     }
+
+    /**
+     * @desc   : 一键作废
+     * @date   : 2024/7/6 9:17
+     * @author : 寇珊珊
+     */
+    public ResponseResultVO<?> oneKeyInvalid(String id) {
+        //region  查询当前订单下是否有退货单
+        List<InboundItemResponse> inboundItemReturnResponses = inboundItemMapper.selectByCond(new InboundItemQuery()
+                .setFromId(id)
+                .setFlgValid(true)
+                .setIntoType(Constant.IntoType.PURRETURN_RETURN.getName()));
+        if (inboundItemReturnResponses != null && inboundItemReturnResponses.size() > 0) {
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ORDER_IS_EXISTS_RETURN_ORDERS.getMessage());
+        }
+        //endregion
+
+        //锁表
+        Purchase purForUpdate = purchaseMapper.selectByIdForUpdate(id);
+        // 并发校验
+        if (!purForUpdate.getFlgValid()) {
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
+        }
+
+        // 如果入库中数量或已入库数量不是0,不能作废
+        if (purForUpdate.getIntoQty().compareTo(BigDecimal.ZERO) != 0 || purForUpdate.getIntoingQty().compareTo(BigDecimal.ZERO) != 0) {
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISEXISTS_AFTER_OPERATE.getMessage());
+        }
+        // 作废
+        Purchase purUpdate = new Purchase();
+        purUpdate.setFlgValid(false).setPurId(id);
+        super.update(purUpdate, new UpdateWrapper<Purchase>().lambda().eq(Purchase::getPurId,
+                UUID.fromString(purUpdate.getPurId ())));
+
+
+        //region 作废出库单
+        inboundPurchaseService.oneKeyPurchaseInboundRepeal(id);
+        //endregion
+
+        return  ResponseResultUtil.success();
+    }
 }

+ 4 - 1
src/main/java/com/dk/mdm/service/sale/OrderService.java

@@ -1102,7 +1102,10 @@ public class OrderService extends BaseService<Order> {
      */
     public ResponseResultVO<?> oneKeyInvalid(String id) {
         //region  查询当前订单下是否存在有效的退货单
-        List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setFromId(id).setFlgValid(true));
+        List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery()
+                .setFromId(id)
+                .setFlgValid(true)
+                .setOutType(Constant.OutType.SALE_RETURN.getName()) );
         if (outboundItemResponseList != null && outboundItemResponseList.size() > 0) {
             throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ORDER_IS_EXISTS_RETURN_ORDERS.getMessage());
         }