Răsfoiți Sursa

修改付款

fubin 2 ani în urmă
părinte
comite
e5a9142fea

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

@@ -63,7 +63,7 @@ public class PaymentController {
      * @date : 2023/1/9 10:48
      */
     @ApiOperation(value = "新建应付付款", notes = "新建应付付款")
-    @PostMapping({"insert_receivable_payment"})
+    @PostMapping({"insert_payable_payment"})
     public ResponseResultVO<?> insertPayablePayment(@RequestBody RecPayVO recPayVO) {
         return paymentService.insertPayablePayment(recPayVO);
     }

+ 1 - 1
src/main/java/com/dk/mdm/mapper/mac/AccountItemMapper.java

@@ -39,6 +39,6 @@ public interface AccountItemMapper extends BaseMapper<AccountItem>{
      * @author : 付斌
      * @date   : 2024-03-09 11:36
      */
-    Map<String, Object> getSumAmtRec(String id);
+    Map<String, Object> getSumAmtRecPay(String id);
 }
 

+ 3 - 4
src/main/java/com/dk/mdm/mapper/mac/AccountItemMapper.xml

@@ -220,8 +220,6 @@
                t.object_id,
                supplier.sup_code       as "supCode",
                supplier.sup_name       as "supName",
-               supplier.contact_phone  as "contactPhone",
-               supplier.return_address as "returnAddress",
                t.org_id,
                tmo.org_name            as "orgName",
                t.staff_id,
@@ -346,8 +344,9 @@
     </insert>
 
     <!-- 查询收款总额 -->
-    <select id="getSumAmtRec" resultType="java.util.Map">
-        SELECT COALESCE(sum(tmai.amt_rec), 0) as "sumAmtRec"
+    <select id="getSumAmtRecPay" resultType="java.util.Map">
+        SELECT COALESCE(sum(tmai.amt_rec), 0) as "sumAmtRec",
+               COALESCE(sum(tmai.amt_pay), 0) as "sumAmtPay"
         FROM dkic_b.t_mac_account_item as tmai
         where tmai.flg_valid
           and tmai.object_id = #{id}::uuid

+ 3 - 0
src/main/java/com/dk/mdm/model/response/mac/AccountItemResponse.java

@@ -255,6 +255,9 @@ public class AccountItemResponse extends PageInfo<AccountItemResponse> implement
     @ApiModelProperty(value = "供应商名称")
     private String supName;
 
+    @ApiModelProperty(value = "本次核销金额")
+    private BigDecimal amtPayableHandle;
+
     private static final long serialVersionUID = 1L;
 
 }

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

@@ -230,6 +230,9 @@ public class RecPayVO extends PageInfo<RecPayVO> implements Serializable {
     @ApiModelProperty(value = "应收冲抵明细")
     private List<RecPayHandleItemVO> receivableList;
 
+    @ApiModelProperty(value = "应付冲抵明细")
+    private List<RecPayHandleItemVO> payableList;
+
     private static final long serialVersionUID = 1L;
 
 }

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

@@ -159,8 +159,8 @@ public class AccountService extends BaseService<Account> {
      */
     public void updateReceipt(String objectId) {
         Account accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
-        Map<String, Object> mapSumAmtRec = accountItemMapper.getSumAmtRec(objectId);
-        BigDecimal sumAmtRec = new BigDecimal(mapSumAmtRec.get("sumAmtRec").toString());
+        Map<String, Object> mapSumAmtRecPay = accountItemMapper.getSumAmtRecPay(objectId);
+        BigDecimal sumAmtRec = new BigDecimal(mapSumAmtRecPay.get("sumAmtRec").toString());
         // 可退金额 = 总收款额-应收应款额+优惠金额
         BigDecimal sumReceiptResidue = sumAmtRec.subtract(accountForUpdate.getReceivableHandle()).add(accountForUpdate.getReceivableWaive());
 
@@ -176,6 +176,29 @@ public class AccountService extends BaseService<Account> {
     }
 
     /**
+     * @desc : 更新总帐上付款类字段
+     * @author : 付斌
+     * @date : 2024-03-22 11:08
+     */
+    public void updatePayment(String objectId) {
+        Account accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
+        Map<String, Object> mapSumAmtRecPay = accountItemMapper.getSumAmtRecPay(objectId);
+        BigDecimal sumAmtPay = new BigDecimal(mapSumAmtRecPay.get("sumAmtPay").toString());
+        // 可退金额 = 总收款额-应收应款额+优惠金额
+        BigDecimal sumPaymentResidue = sumAmtPay.subtract(accountForUpdate.getPayableHandle()).add(accountForUpdate.getPayableWaive());
+
+        // 如果可退金额小于0 ,则提示余额不足
+        if (sumPaymentResidue.compareTo(BigDecimal.ZERO) == -1) {
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
+        }
+
+        // 更新账款总表上的收款总额和可用金额
+        Account accountUpdate = new Account();
+        accountUpdate.setPayment(sumAmtPay).setPaymentResidue(sumPaymentResidue).setObjectId(objectId);
+        super.updateByUuid(accountUpdate);
+    }
+
+    /**
      * @desc : 更新资金账户余额
      * @author : 付斌
      * @date : 2024-03-22 11:08

+ 26 - 26
src/main/java/com/dk/mdm/service/mac/PaymentService.java

@@ -161,9 +161,9 @@ public class PaymentService extends BaseService<RecPay> {
 
                 // 插入账款明细
                 AccountItem accountItem = new AccountItem();
-                accountItem.setAccItemType(Constant.accItemType.SHOU_KUAN.getName())
+                accountItem.setAccItemType(Constant.accItemType.FU_KUAN.getName())
                         .setObjectId(recPayVO.getObjectId()).setOrgId(recPayVO.getOrgId()).setStaffId(recPayVO.getStaffId())
-                        .setAccDate(recPayVO.getAccDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName()).setAmtRec(recPayItem.getAmtRec())
+                        .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);
@@ -176,14 +176,14 @@ public class PaymentService extends BaseService<RecPay> {
                 // 插入资金流水
                 MoneyAccountItem moneyAccountItem = new MoneyAccountItem();
                 moneyAccountItem.setMacId(recPayItem.getMacId()).setFlowType(Constant.FlowType.SHOU_FU_KUAN.getName())
-                        .setInvoiceId(recPayItem.getItemId()).setAmtInflow(recPayItem.getAmtRec()).setAccDate(recPayVO.getAccDate())
+                        .setInvoiceId(recPayItem.getItemId()).setAmtInflow(recPayItem.getAmtPay().negate()).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.getAmtRec()))
+                moneyAccountUpdate.setBalance(moneyAccountForUpdate.getBalance().add(recPayItem.getAmtPay().negate()))
                         .setMacId(moneyAccountForUpdate.getMacId());
                 moneyAccountService.updateByUuid(moneyAccountUpdate);
             }
@@ -193,8 +193,8 @@ public class PaymentService extends BaseService<RecPay> {
         Account accountForUpdate = accountService.getCusAccountForUpdate(recPayVO.getObjectId());
         // 更新账款总表上付款的相关字段
         Account accountUpdate = new Account();
-        accountUpdate.setReceipt(accountForUpdate.getReceipt().add(recPayVO.getSumAmtRec()))// 总付款金额
-                .setReceiptResidue(accountForUpdate.getReceiptResidue().add(recPayVO.getSumAmtRec()))//  可退金额
+        accountUpdate.setPayment(accountForUpdate.getPayment().add(recPayVO.getSumAmtPay()))// 总付款金额
+                .setPaymentResidue(accountForUpdate.getPaymentResidue().add(recPayVO.getSumAmtPay()))//  可退金额
                 .setObjectId(accountForUpdate.getObjectId());
         accountService.updateByUuid(accountUpdate);
         /*********************  付款的处理 end **********************/
@@ -202,8 +202,8 @@ public class PaymentService extends BaseService<RecPay> {
 
         /*********************  应付付款的处理 begin **********************/
         // 应付付款的处理
-        if (recPayVO.getReceivableList() != null && recPayVO.getReceivableList().size() > 0) {
-            for (RecPayHandleItemVO recPayHandleItemVO : recPayVO.getReceivableList()) {
+        if (recPayVO.getPayableList() != null && recPayVO.getPayableList().size() > 0) {
+            for (RecPayHandleItemVO recPayHandleItemVO : recPayVO.getPayableList()) {
                 RecPayHandleItem recPayHandleItem = recPayHandleItemConvert.convertToPo(recPayHandleItemVO);
                 recPayHandleItem.setItemId(null).setRpId(recPay.getRpId()).setCpId(recPay.getCpId()).setAccDate(recPay.getAccDate());
                 recPayHandleItemMapper.insert(recPayHandleItem);
@@ -212,10 +212,10 @@ public class PaymentService extends BaseService<RecPay> {
                 AccountItem accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItem.getAccItemId());
                 AccountItem accountItemUpdate = new AccountItem();
                 // 核销金额,超出剩余应付金额
-                if (accountItemForUpdate.getAmtResidue().compareTo(recPayHandleItem.getAmtReceivableHandle()) == -1) {
+                if (accountItemForUpdate.getAmtResidue().compareTo(recPayHandleItem.getAmtPayableHandle()) == -1) {
                     throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
                 }
-                accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().add(recPayHandleItem.getAmtReceivableHandle()))
+                accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().add(recPayHandleItem.getAmtPayableHandle()))
                         .setAmtWaive(accountItemForUpdate.getAmtWaive().add(recPayHandleItem.getAmtWaive()))
                         .setItemId(recPayHandleItem.getAccItemId());
                 // 剩余金额 = 应付金额-应付付款金额
@@ -224,9 +224,9 @@ public class PaymentService extends BaseService<RecPay> {
             }
 
             // 计算明细的核销金额,优惠金额合计
-            RecPayHandleItemVO recPayHandleItemVO = recPayVO.getReceivableList().stream().reduce((x, y) -> {
+            RecPayHandleItemVO recPayHandleItemVO = recPayVO.getPayableList().stream().reduce((x, y) -> {
                 RecPayHandleItemVO item = new RecPayHandleItemVO();
-                item.setAmtReceivableHandle(x.getAmtReceivableHandle().add(y.getAmtReceivableHandle()));
+                item.setAmtPayableHandle(x.getAmtPayableHandle().add(y.getAmtPayableHandle()));
                 item.setAmtWaive(x.getAmtWaive().add(y.getAmtWaive()));
                 return item;
             }).get();
@@ -234,21 +234,21 @@ public class PaymentService extends BaseService<RecPay> {
             // 更新总账上
             accountForUpdate = accountMapper.selectByIdForUpdate(recPayVO.getObjectId());
             accountUpdate = new Account();
-            accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().add(recPayHandleItemVO.getAmtReceivableHandle()))// 总应付付款金额
-                    .setReceivableWaive(accountForUpdate.getReceivableWaive().add(recPayHandleItemVO.getAmtWaive()))//  总应付优惠金额
+            accountUpdate.setPayableHandle(accountForUpdate.getPayableHandle().add(recPayHandleItemVO.getAmtPayableHandle()))// 总应付付款金额
+                    .setPayableWaive(accountForUpdate.getPayableWaive().add(recPayHandleItemVO.getAmtWaive()))//  总应付优惠金额
                     .setObjectId(accountForUpdate.getObjectId());
             // 剩余应付 = 总应付账款-总应付付款金额
-            accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
+            accountUpdate.setPayableResidue(accountForUpdate.getPayable().subtract(accountUpdate.getPayableHandle()));
             // 可退金额 = 总付款金额-总应付付款金额+总应付优惠金额
-            accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()).add(accountUpdate.getReceivableWaive()));
+            accountUpdate.setPaymentResidue(accountForUpdate.getPayment().subtract(accountUpdate.getPayableHandle()).add(accountUpdate.getPayableWaive()));
 
             // 更新前的最后校验
             // 剩余应付为负数,则不能保存
-            if (accountUpdate.getReceivableResidue().compareTo(BigDecimal.ZERO) == -1) {
+            if (accountUpdate.getPayableResidue().compareTo(BigDecimal.ZERO) == -1) {
                 throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
             }
             // 可用金额为负数,则不能保存
-            if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
+            if (accountUpdate.getPaymentResidue().compareTo(BigDecimal.ZERO) == -1) {
                 throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
             }
             accountService.updateByUuid(accountUpdate);
@@ -277,7 +277,7 @@ public class PaymentService extends BaseService<RecPay> {
             // 更新账款明细应付付款
             accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItemForUpdate.getAccItemId());
             AccountItem accountItemUpdate = new AccountItem();
-            accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().subtract(recPayHandleItemForUpdate.getAmtReceivableHandle()))
+            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()));
@@ -292,21 +292,21 @@ public class PaymentService extends BaseService<RecPay> {
         // 把总帐上的钱加回来
         Account accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
         Account accountUpdate = new Account();
-        accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayForUpdate.getSumAmtReceivableHandle()))// 总应付付款金额
-                .setReceivableWaive(accountForUpdate.getReceivableWaive().subtract(recPayForUpdate.getSumWaiveAmt()))//  总应付优惠金额
+        accountUpdate.setPayableHandle(accountForUpdate.getPayableHandle().subtract(recPayForUpdate.getSumAmtPayableHandle()))// 总应付付款金额
+                .setPayableWaive(accountForUpdate.getPayableWaive().subtract(recPayForUpdate.getSumWaiveAmt()))//  总应付优惠金额
                 .setObjectId(accountForUpdate.getObjectId());
         // 剩余应付 = 总应付账款-总应付付款金额
-        accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
+        accountUpdate.setPayableResidue(accountForUpdate.getPayable().subtract(accountUpdate.getPayableHandle()));
         // 可退金额 = 总付款金额-总应付付款金额+总应付优惠金额
-        accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()).add(accountUpdate.getReceivableWaive()));
+        accountUpdate.setPaymentResidue(accountForUpdate.getPayment().subtract(accountUpdate.getPayableHandle()).add(accountUpdate.getPayableWaive()));
 
         // 更新前的最后校验
         // 剩余应付为负数,则不能保存
-        if (accountUpdate.getReceivableResidue().compareTo(BigDecimal.ZERO) == -1) {
+        if (accountUpdate.getPayableResidue().compareTo(BigDecimal.ZERO) == -1) {
             throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
         }
         // 可用金额为负数,则不能保存
-        if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
+        if (accountUpdate.getPaymentResidue().compareTo(BigDecimal.ZERO) == -1) {
             throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
         }
         accountService.updateByUuid(accountUpdate);
@@ -328,7 +328,7 @@ public class PaymentService extends BaseService<RecPay> {
             }
         }
         // 更新总账表的总付款额和可用额
-        accountService.updateReceipt(recPayForUpdate.getObjectId());
+        accountService.updatePayment(recPayForUpdate.getObjectId());
         // 更新账户余额
         for (String macId : macList) {
             accountService.updateMac(macId);