Prechádzať zdrojové kódy

修改出库记账、反记账

fubin 1 rok pred
rodič
commit
6ef360f9f6

+ 25 - 18
src/main/java/com/dk/mdm/mapper/mac/RecPayMapper.java

@@ -10,57 +10,64 @@ import org.springframework.stereotype.Repository;
 import java.util.List;
 
 /**
-*  收付款单 Mapper
-*/
+ * 收付款单 Mapper
+ */
 @Repository
-public interface RecPayMapper extends BaseMapper<RecPay>{
+public interface RecPayMapper extends BaseMapper<RecPay> {
     /**
-     * @desc   : 根据条件进行查询
+     * @desc : 根据条件进行查询
      * @author : 付斌
-     * @date   : 2024-02-28 10:18
+     * @date : 2024-02-28 10:18
      */
     List<RecPayResponse> selectByCond(RecPayQuery recPayQuery);
 
     /**
-     * @desc   : 根据条件进行查询(数量)
+     * @desc : 根据条件进行查询(数量)
      * @author : 付斌
-     * @date   : 2024-02-28 10:19
+     * @date : 2024-02-28 10:19
      */
     Long countByCond(RecPayQuery recPayQuery);
 
     /**
-     * @desc   : 根据Id进行查询
+     * @desc : 根据Id进行查询
      * @author : 付斌
-     * @date   : 2024-03-03 9:25
+     * @date : 2024-03-03 9:25
      */
     RecPayResponse selectById(@Param("id") String id);
 
     /**
-     * @desc   : 根据BiznisId进行查询
+     * @desc : 根据BiznisId进行查询
      * @author : 付斌
-     * @date   : 2024-03-03 9:25
+     * @date : 2024-03-03 9:25
      */
-    RecPay selectByBiznisIdForUpdate(String id);
+    RecPay selectByBiznisIdForUpdate(@Param("id") String id, @Param("flgOrderHandle") Boolean flgOrderHandle);
 
     /**
-     * @desc   : 根据BiznisId进行查询
+     * @desc : 根据BiznisId进行查询
      * @author : 付斌
-     * @date   : 2024-03-03 9:25
+     * @date : 2024-03-03 9:25
      */
     RecPay selectByBiznisId(String id);
 
     /**
-     * @desc   : 根据条件进行查询
+     * @desc : 根据条件进行查询
      * @author : 付斌
-     * @date   : 2024-02-28 10:18
+     * @date : 2024-02-28 10:18
      */
     List<RecPayResponse> selectPaymentByCond(RecPayQuery recPayQuery);
 
     /**
-     * @desc   : 根据条件进行查询(数量)
+     * @desc : 根据条件进行查询(数量)
      * @author : 付斌
-     * @date   : 2024-02-28 10:19
+     * @date : 2024-02-28 10:19
      */
     Long countPaymentByCond(RecPayQuery recPayQuery);
+
+    /**
+     * @desc : 删除收款单
+     * @author : 付斌
+     * @date : 2024-04-28 9:10
+     */
+    int deleteById(@Param("id") String id);
 }
 

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

@@ -5,7 +5,7 @@
     <!-- 通用设置 -->
     <!-- 通用查询列 -->
     <sql id="Base_Column_List">
-        rp_id, rp_no, rp_type, object_id, org_id, staff_id, sum_amt_rec, sum_amt_pay, sum_should_handle, sum_use_receipt_residue, sum_use_payment_residue, sum_amt_receivable_handle, sum_amt_payable_handle, sum_waive_amt, acc_date, annex_paths, remarks, biznis_type, biznis_id, biznis_no, flg_lock, make_staff, make_time, flg_valid, cp_id
+        rp_id, rp_no, rp_type, object_id, org_id, staff_id, sum_amt_rec, sum_amt_pay, sum_should_handle, sum_use_receipt_residue, sum_use_payment_residue, sum_amt_receivable_handle, sum_amt_payable_handle, sum_waive_amt, acc_date, annex_paths, remarks, biznis_type, biznis_id, biznis_no, flg_order_handle, flg_lock, make_staff, make_time, flg_valid, cp_id
     </sql>
 
     <!-- 通用查询映射结果 -->
@@ -30,6 +30,7 @@
             <result column="biznis_type" property="biznisType"/>
             <result column="biznis_id" property="biznisId" typeHandler="UuidTypeHandler"/>
             <result column="biznis_no" property="biznisNo"/>
+            <result column="flg_order_handle" property="flgOrderHandle"/>
             <result column="flg_lock" property="flgLock"/>
             <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
             <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
@@ -59,6 +60,7 @@
             <result column="biznis_type" property="biznisType"/>
             <result column="biznis_id" property="biznisId" typeHandler="UuidTypeHandler"/>
             <result column="biznis_no" property="biznisNo"/>
+            <result column="flg_order_handle" property="flgOrderHandle"/>
             <result column="flg_lock" property="flgLock"/>
             <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
             <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
@@ -130,6 +132,9 @@
         <if test="biznisNo != null and biznisNo != ''">
             AND t.biznis_no = #{biznisNo}
         </if>
+        <if test="flgOrderHandle != null">
+            AND t.flg_order_handle = #{flgOrderHandle}
+        </if>
         <if test="flgLock != null">
             AND t.flg_lock = #{flgLock}
         </if>
@@ -228,6 +233,7 @@
                t.biznis_type,
                t.biznis_id,
                t.biznis_no,
+               t.flg_order_handle,
                t.flg_lock,
                t.make_staff,
                makestaff.staff_name as "makeStaffName",
@@ -312,6 +318,7 @@
                t.biznis_type,
                t.biznis_id,
                t.biznis_no,
+               t.flg_order_handle,
                t.flg_lock,
                t.make_staff,
                makestaff.staff_name as "makeStaffName",
@@ -344,6 +351,7 @@
         FROM dkic_b.t_mac_rec_pay
         WHERE flg_valid
           and biznis_id = #{id}::uuid
+          and flg_order_handle = #{flgOrderHandle}
         for update
     </select>
 
@@ -388,6 +396,7 @@
             biznis_type,
             biznis_id,
             biznis_no,
+            flg_order_handle,
             flg_lock,
             make_staff,
             make_time,
@@ -418,6 +427,7 @@
                 #{item.biznisType},
                 #{item.biznisId}::uuid,
                 #{item.biznisNo},
+                #{item.flgOrderHandle},
                 #{item.flgLock},
                 #{item.makeStaff}::uuid,
                 #{item.makeTime},
@@ -456,6 +466,7 @@
                t.biznis_type,
                t.biznis_id,
                t.biznis_no,
+               t.flg_order_handle,
                t.flg_lock,
                t.make_staff,
                makestaff.staff_name as "makeStaffName",
@@ -507,4 +518,10 @@
             )
         </if>
     </select>
+
+    <!-- 删除收款单 -->
+    <delete id="deleteById">
+        DELETE FROM dkic_b.t_mac_rec_pay
+        WHERE rp_id = #{id}::uuid;
+    </delete>
 </mapper>

+ 6 - 0
src/main/java/com/dk/mdm/model/pojo/mac/RecPay.java

@@ -189,6 +189,12 @@ public class RecPay extends PageInfo<RecPay> implements Serializable {
     @ApiModelProperty(value = "业务单号")
     private String biznisNo;
 
+    /**
+     * 核销标识(是否是订单的出库的核销单)
+     */
+    @Excel(name = "核销标识(是否是订单的出库的核销单)")
+    @ApiModelProperty(value = "核销标识(是否是订单的出库的核销单)")
+    private Boolean flgOrderHandle;
 
     /**
      * 锁定标识

+ 8 - 0
src/main/java/com/dk/mdm/model/query/mac/RecPayQuery.java

@@ -196,6 +196,14 @@ public class RecPayQuery extends PageInfo<RecPayQuery> implements Serializable {
 
 
     /**
+     * 核销标识(是否是订单的出库的核销单)
+     */
+    @Excel(name = "核销标识(是否是订单的出库的核销单)")
+    @ApiModelProperty(value = "核销标识(是否是订单的出库的核销单)")
+    private Boolean flgOrderHandle;
+
+
+    /**
      * 锁定标识
      */
     @Excel(name = "锁定标识")

+ 8 - 0
src/main/java/com/dk/mdm/model/response/mac/RecPayResponse.java

@@ -193,6 +193,14 @@ public class RecPayResponse extends PageInfo<RecPayResponse> implements Serializ
 
 
     /**
+     * 核销标识(是否是订单的出库的核销单)
+     */
+    @Excel(name = "核销标识(是否是订单的出库的核销单)")
+    @ApiModelProperty(value = "核销标识(是否是订单的出库的核销单)")
+    private Boolean flgOrderHandle;
+
+
+    /**
      * 锁定标识
      */
     @Excel(name = "锁定标识")

+ 8 - 0
src/main/java/com/dk/mdm/model/vo/mac/RecPayVO.java

@@ -194,6 +194,14 @@ public class RecPayVO extends PageInfo<RecPayVO> implements Serializable {
 
 
     /**
+     * 核销标识(是否是订单的出库的核销单)
+     */
+    @Excel(name = "核销标识(是否是订单的出库的核销单)")
+    @ApiModelProperty(value = "核销标识(是否是订单的出库的核销单)")
+    private Boolean flgOrderHandle;
+
+
+    /**
      * 锁定标识
      */
     @Excel(name = "锁定标识")

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

@@ -922,7 +922,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
                         .setOutQty(outboundItemResponse.getOutQty().add(outboundItemVO.getOutingQty()))
                         .setOutAmt(outboundItemResponse.getOutAmt().add(outboundItemVO.getOutingAmt()))
                         .setOutingQty(BigDecimal.ZERO)
-                        .setOutAmt(BigDecimal.ZERO)
+                        .setOutingAmt(BigDecimal.ZERO)
                         .setCostPrice(outboundItemVO.getPriceOut())
                         .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
                 ;

+ 31 - 10
src/main/java/com/dk/mdm/service/mac/AccountService.java

@@ -24,12 +24,14 @@ import com.dk.mdm.model.pojo.sale.Order;
 import com.dk.mdm.model.query.mac.AccountItemQuery;
 import com.dk.mdm.model.response.mac.AccountItemResponse;
 import com.dk.mdm.model.response.mac.AccountResponse;
+import com.dk.mdm.service.common.CommonService;
 import com.dk.mdm.service.mst.MoneyAccountService;
 import org.springframework.stereotype.Service;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -94,6 +96,9 @@ public class AccountService extends BaseService<Account> {
     @Autowired
     private RecPayHandleItemMapper recPayHandleItemMapper;
 
+    @Autowired
+    private CommonService commonService;
+
     /**
      * @desc : 查看来源单据,总单加明细
      * @author : 姜永辉
@@ -357,7 +362,7 @@ public class AccountService extends BaseService<Account> {
                 Order orderForUpdate = orderMapper.selectByIdForUpdate(outbound.getFromId());
                 // 如果当前订单已经全部出库
                 if (orderForUpdate != null && orderForUpdate.getOutQty().compareTo(orderForUpdate.getSumQuantity()) == 0) {
-                    RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderForUpdate.getOrderId());
+                    RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderForUpdate.getOrderId(),false);
                     if (recPayForUpdate != null && recPayForUpdate.getFlgLock()) {
                         // 先把收款单解锁
                         RecPay recPayUpdate = new RecPay();
@@ -385,6 +390,17 @@ public class AccountService extends BaseService<Account> {
                                 new AccountItemQuery().setObjectId(objectId).setOrderId(orderForUpdate.getOrderId()));
 
                         if (accountItemResponseList.size() > 0) {
+                            // 生成核销总单
+                            RecPay recPayHandle = new RecPay();
+                            // 获取单号
+                            Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.RECPAY.getName(), false);
+                            recPayHandle.setRpId(codeMap.get("outId").toString()).setRpNo(codeMap.get("outNote").toString())
+                                    .setRpType(Constant.RpType.SHOU_KUAN.getName()).setObjectId(objectId)
+                                    .setOrgId(recPayForUpdate.getOrgId()).setStaffId(recPayForUpdate.getStaffId()).setAccDate(LocalDate.now())
+                                    .setBiznisType(Constant.InventoryDocCode.ORDER.getTableName()).setBiznisId(recPayForUpdate.getBiznisId()).setBiznisNo(recPayForUpdate.getBiznisNo())
+                                    .setMakeStaff(recPayForUpdate.getMakeStaff()).setCpId(recPayForUpdate.getCpId()).setFlgOrderHandle(true);
+                            recPayMapper.insert(recPayHandle);
+
                             // 记录核销了哪些应收账
                             List<RecPayHandleItem> receivableList = new ArrayList<>();
 
@@ -393,7 +409,7 @@ public class AccountService extends BaseService<Account> {
 
                             for (AccountItemResponse accountItemResponse : accountItemResponseList) {
                                 RecPayHandleItem recPayHandleItem = new RecPayHandleItem();
-                                recPayHandleItem.setRpId(recPayForUpdate.getRpId()).setCpId(recPayForUpdate.getCpId()).setAccDate(recPayForUpdate.getAccDate())
+                                recPayHandleItem.setRpId(recPayHandle.getRpId()).setCpId(recPayHandle.getCpId()).setAccDate(recPayHandle.getAccDate())
                                         .setAccItemId(accountItemResponse.getAccItemId());
                                 // 如果定金比应收金额大
                                 if (lockAmt.compareTo(accountItemResponse.getAmtResidue()) == 1) {
@@ -436,11 +452,11 @@ public class AccountService extends BaseService<Account> {
                             recPayUpdate = new RecPay();
                             recPayUpdate.setSumAmtReceivableHandle(recPayHandleItem.getAmtReceivableHandle())
                                     .setSumShouldHandle(recPayHandleItem.getAmtReceivableHandle())
-                                    .setRpId(recPayForUpdate.getRpId());
+                                    .setRpId(recPayHandle.getRpId());
                             receiptService.updateByUuid(recPayUpdate);
 
                             // 更新总账上
-                            accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
+                            accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
                             accountUpdate = new Account();
                             accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().add(recPayHandleItem.getAmtReceivableHandle()))// 总应收收款金额
                                     .setObjectId(accountForUpdate.getObjectId());
@@ -522,10 +538,11 @@ public class AccountService extends BaseService<Account> {
             // 如果当前出库单对应的订单做了应收收款,则自动作废应收核销,并且锁定金额订单收款(锁定金额)
             // 如果是销售出库
             if (outbound.getOutType().equals(Constant.OutType.SALE.getName())) {
-                RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(outbound.getFromId());
-                if (recPayForUpdate != null) {
+                RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(outbound.getFromId(),false);        // 款
+                RecPay recPayHandleForUpdate = recPayMapper.selectByBiznisIdForUpdate(outbound.getFromId(),true);   // 账
+                if (recPayForUpdate != null && recPayHandleForUpdate != null) {
                     // 查出并锁定所有应收核销明细
-                    List<RecPayHandleItem> recPayHandleItemForUpdateList = recPayHandleItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
+                    List<RecPayHandleItem> recPayHandleItemForUpdateList = recPayHandleItemMapper.selectByZIdForUpdate(recPayHandleForUpdate.getRpId());
                     if (recPayHandleItemForUpdateList.size() > 0) {
                         for (RecPayHandleItem recPayHandleItemForUpdate : recPayHandleItemForUpdateList) {
                             // 更新账款明细应收收款
@@ -541,10 +558,10 @@ public class AccountService extends BaseService<Account> {
                         }
 
                         // 把总帐上的钱加回来
-                        accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
+                        accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
                         accountUpdate = new Account();
-                        accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayForUpdate.getSumAmtReceivableHandle()))// 总应收收款金额
-                                .setObjectId(accountForUpdate.getObjectId());
+                        accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayHandleForUpdate.getSumAmtReceivableHandle()))// 总应收收款金额
+                                .setObjectId(objectId);
                         // 剩余应收 = 总应收账款-总应收收款金额
                         accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
                         // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
@@ -557,6 +574,9 @@ public class AccountService extends BaseService<Account> {
                         }
                         super.updateByUuid(accountUpdate);
 
+                        // 删掉收款核销单
+                        recPayMapper.deleteById(recPayHandleForUpdate.getRpId());
+
                         // 先把收款单锁定
                         RecPay recPayUpdate = new RecPay();
                         recPayUpdate.setFlgLock(true).setRpId(recPayForUpdate.getRpId());
@@ -571,6 +591,7 @@ public class AccountService extends BaseService<Account> {
                         }
 
                         // 钱进到锁定金额中
+                        accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
                         accountUpdate = new Account();
                         accountUpdate.setReceipt(accountForUpdate.getReceipt().subtract(recPayForUpdate.getSumAmtRec()))
                                 .setReceiptResidue(accountForUpdate.getReceiptResidue().subtract(recPayForUpdate.getSumAmtRec()))

+ 2 - 2
src/main/java/com/dk/mdm/service/mac/OtherPayableService.java

@@ -305,7 +305,7 @@ public class OtherPayableService extends BaseService<OtherPayable> {
         }
 
         /*******************************************  应付付款的处理 begin ********************************************/
-        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(otherPayableVO.getPayableId());
+        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(otherPayableVO.getPayableId(), false);
         if(recPayForUpdate != null && recPayForUpdate.getFlgValid()) {
             // 查出并锁定所有应付核销明细
             AccountItem accountItemForUpdate;
@@ -550,7 +550,7 @@ public class OtherPayableService extends BaseService<OtherPayable> {
         // 如果所在月份已结账,则不能作废 todo
 
         /*******************************************  应付付款的处理 begin ********************************************/
-        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(id);
+        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(id, false);
         if(recPayForUpdate != null && recPayForUpdate.getFlgValid()) {
             // 查出并锁定所有应付核销明细
             AccountItem accountItemForUpdate;

+ 2 - 2
src/main/java/com/dk/mdm/service/mac/OtherReceivableService.java

@@ -305,7 +305,7 @@ public class OtherReceivableService extends BaseService<OtherReceivable> {
 
         /***********************************  应收收款的处理 begin ************************************/
         // 如果收款了,先把收款作废掉
-        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(otherReceivableVO.getReceivableId());
+        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(otherReceivableVO.getReceivableId(), false);
         if(recPayForUpdate != null && recPayForUpdate.getFlgValid()){
             // 查出并锁定所有应收核销明细
             AccountItem accountItemForUpdate;
@@ -551,7 +551,7 @@ public class OtherReceivableService extends BaseService<OtherReceivable> {
         // 如果所在月份已结账,则不能作废 todo
 
         /***********************************  应收收款的处理 begin ************************************/
-        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(id);
+        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(id, false);
         if(recPayForUpdate != null && recPayForUpdate.getFlgValid()){
             // 查出并锁定所有应收核销明细
             AccountItem accountItemForUpdate;

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

@@ -171,7 +171,7 @@ public class OrderService extends BaseService<Order> {
         result.put("orderItem", orderItem);
 
         // 收款明细
-        List<RecPayResponse> recPayList = recPayMapper.selectByCond(new RecPayQuery().setBiznisId(id));
+        List<RecPayResponse> recPayList = recPayMapper.selectByCond(new RecPayQuery().setBiznisId(id).setFlgOrderHandle(false));
         if (recPayList != null && recPayList.size() > 0) {
             List<RecPayItemResponse> receiptItem = recPayItemMapper.selectByCond(new RecPayItemQuery().setRpId(recPayList.get(0).getRpId()));
             result.put("receiptItem", receiptItem);
@@ -431,7 +431,7 @@ public class OrderService extends BaseService<Order> {
         // 需要重新计算的资金账户
         List<String> macList = new ArrayList<>();
         // 收款明细
-        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderVO.getOrderId());
+        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderVO.getOrderId(), false);
         if (recPayForUpdate != null) {
             // 将之前的明细全部删除
             List<RecPayItem> recPayItemOriginalList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
@@ -553,7 +553,7 @@ public class OrderService extends BaseService<Order> {
         // 需要重新计算的资金账户
         List<String> macList = new ArrayList<>();
         // 收款明细
-        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(id);
+        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(id, false);
         if (recPayForUpdate != null) {
             // 将之前的明细全部删除
             List<RecPayItem> recPayItemOriginalList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
@@ -601,7 +601,7 @@ public class OrderService extends BaseService<Order> {
         dataInfo.put("dataItem", orderItemResponse);
 
         // 收款明细
-        List<RecPayResponse> recPayList = recPayMapper.selectByCond(new RecPayQuery().setBiznisId(id));
+        List<RecPayResponse> recPayList = recPayMapper.selectByCond(new RecPayQuery().setBiznisId(id).setFlgOrderHandle(false));
         if (recPayList != null && recPayList.size() > 0) {
             List<RecPayItemResponse> receiptItem = recPayItemMapper.selectByCond(new RecPayItemQuery().setRpId(recPayList.get(0).getRpId()));
             dataInfo.put("receiptItem", receiptItem);