fubin 2 rokov pred
rodič
commit
b941e751eb

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

@@ -292,10 +292,10 @@
                tmgs.sku_model                             as "skuModel",
                tmgs.sku_model                             as "skuModel",
                tmgs.sku_name                              as "skuName",
                tmgs.sku_name                              as "skuName",
                t.item_qty                                 as "orderQty",
                t.item_qty                                 as "orderQty",
-               t.item_qty - t.outing_qty                  as "canOutingQty",
-               t.item_qty - t.outing_qty                  as outing_qty,
+               t.item_qty - t.outing_qty - t.out_qty      as "canOutingQty",
+               t.item_qty - t.outing_qty - t.out_qty      as outing_qty,
                t.price_sale                               as "priceOut",
                t.price_sale                               as "priceOut",
-               t.price_sale * (t.item_qty - t.outing_qty) as outing_amt,
+               t.price_sale * (t.item_qty - t.outing_qty - t.out_qty) as outing_amt,
                t.non_std_code,
                t.non_std_code,
                t.remarks,
                t.remarks,
                t.wh_id,
                t.wh_id,

+ 72 - 67
src/main/java/com/dk/mdm/service/mac/AccountService.java

@@ -239,7 +239,7 @@ public class AccountService extends BaseService<Account> {
      * @date : 2024-03-22 11:08
      * @date : 2024-03-22 11:08
      */
      */
     public void updateMac(String macId) {
     public void updateMac(String macId) {
-        if(macId == null){
+        if (macId == null) {
             return;
             return;
         }
         }
         // 查询当前账户流水合计
         // 查询当前账户流水合计
@@ -249,7 +249,7 @@ public class AccountService extends BaseService<Account> {
         // 更新资金账户
         // 更新资金账户
         MoneyAccount moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(macId);
         MoneyAccount moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(macId);
         // 如果账户不允许为负数
         // 如果账户不允许为负数
-        if(!moneyAccountForUpdate.getFlgNegative()) {
+        if (!moneyAccountForUpdate.getFlgNegative()) {
             // 如果余额小于0 ,则提示余额不足
             // 如果余额小于0 ,则提示余额不足
             if (sumAmtInflow.compareTo(BigDecimal.ZERO) == -1) {
             if (sumAmtInflow.compareTo(BigDecimal.ZERO) == -1) {
                 throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
                 throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
@@ -268,7 +268,7 @@ public class AccountService extends BaseService<Account> {
      * @date : 2024-03-22 11:08
      * @date : 2024-03-22 11:08
      */
      */
     public void updateContractAssets(String objectId) {
     public void updateContractAssets(String objectId) {
-        if(objectId == null){
+        if (objectId == null) {
             return;
             return;
         }
         }
         // 更新账款总表上的总应收账款和总剩余应收
         // 更新账款总表上的总应收账款和总剩余应收
@@ -290,7 +290,7 @@ public class AccountService extends BaseService<Account> {
      * @date : 2024-03-22 11:08
      * @date : 2024-03-22 11:08
      */
      */
     public void updatePurEstimate(String objectId) {
     public void updatePurEstimate(String objectId) {
-        if(objectId == null){
+        if (objectId == null) {
             return;
             return;
         }
         }
         // 更新账款总表上的总应收账款和总剩余应收
         // 更新账款总表上的总应收账款和总剩余应收
@@ -353,12 +353,12 @@ public class AccountService extends BaseService<Account> {
 
 
             // 如果当前出库单对应的订单全部出库了,并且订单有收款(锁定金额),则自动做应收核销
             // 如果当前出库单对应的订单全部出库了,并且订单有收款(锁定金额),则自动做应收核销
             // 如果是销售出库
             // 如果是销售出库
-            if(outbound.getOutType().equals(Constant.OutType.SALE.getName())){
+            if (outbound.getOutType().equals(Constant.OutType.SALE.getName())) {
                 Order orderForUpdate = orderMapper.selectByIdForUpdate(outbound.getFromId());
                 Order orderForUpdate = orderMapper.selectByIdForUpdate(outbound.getFromId());
                 // 如果当前订单已经全部出库
                 // 如果当前订单已经全部出库
-                if(orderForUpdate.getOutQty().compareTo(orderForUpdate.getSumQuantity()) == 0){
+                if (orderForUpdate != null && orderForUpdate.getOutQty().compareTo(orderForUpdate.getSumQuantity()) == 0) {
                     RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderForUpdate.getOrderId());
                     RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderForUpdate.getOrderId());
-                    if(recPayForUpdate != null && recPayForUpdate.getFlgLock()){
+                    if (recPayForUpdate != null && recPayForUpdate.getFlgLock()) {
                         // 先把收款单解锁
                         // 先把收款单解锁
                         RecPay recPayUpdate = new RecPay();
                         RecPay recPayUpdate = new RecPay();
                         recPayUpdate.setFlgLock(false).setRpId(recPayForUpdate.getRpId());
                         recPayUpdate.setFlgLock(false).setRpId(recPayForUpdate.getRpId());
@@ -380,10 +380,11 @@ public class AccountService extends BaseService<Account> {
                                 .setObjectId(objectId);
                                 .setObjectId(objectId);
                         super.updateByUuid(accountUpdate);
                         super.updateByUuid(accountUpdate);
 
 
+                        // 查出当前订单需要核销的应收单据
                         List<AccountItemResponse> accountItemResponseList = accountItemMapper.getReceivableAccountItemForUpdate(
                         List<AccountItemResponse> accountItemResponseList = accountItemMapper.getReceivableAccountItemForUpdate(
                                 new AccountItemQuery().setObjectId(objectId).setOrderId(orderForUpdate.getOrderId()));
                                 new AccountItemQuery().setObjectId(objectId).setOrderId(orderForUpdate.getOrderId()));
 
 
-                        if(accountItemResponseList.size() > 0){
+                        if (accountItemResponseList.size() > 0) {
                             // 记录核销了哪些应收账
                             // 记录核销了哪些应收账
                             List<RecPayHandleItem> receivableList = new ArrayList<>();
                             List<RecPayHandleItem> receivableList = new ArrayList<>();
 
 
@@ -395,10 +396,10 @@ public class AccountService extends BaseService<Account> {
                                 recPayHandleItem.setRpId(recPayForUpdate.getRpId()).setCpId(recPayForUpdate.getCpId()).setAccDate(recPayForUpdate.getAccDate())
                                 recPayHandleItem.setRpId(recPayForUpdate.getRpId()).setCpId(recPayForUpdate.getCpId()).setAccDate(recPayForUpdate.getAccDate())
                                         .setAccItemId(accountItemResponse.getAccItemId());
                                         .setAccItemId(accountItemResponse.getAccItemId());
                                 // 如果定金比应收金额大
                                 // 如果定金比应收金额大
-                                if(lockAmt.compareTo(accountItemResponse.getAmtResidue()) == 1){
+                                if (lockAmt.compareTo(accountItemResponse.getAmtResidue()) == 1) {
                                     recPayHandleItem.setAmtReceivableHandle(accountItemResponse.getAmtResidue());
                                     recPayHandleItem.setAmtReceivableHandle(accountItemResponse.getAmtResidue());
                                     lockAmt = lockAmt.subtract(accountItemResponse.getAmtResidue());
                                     lockAmt = lockAmt.subtract(accountItemResponse.getAmtResidue());
-                                }else{
+                                } else {
                                     recPayHandleItem.setAmtReceivableHandle(lockAmt);
                                     recPayHandleItem.setAmtReceivableHandle(lockAmt);
                                     lockAmt = BigDecimal.ZERO;
                                     lockAmt = BigDecimal.ZERO;
                                 }
                                 }
@@ -419,7 +420,7 @@ public class AccountService extends BaseService<Account> {
                                 accountItemService.updateByUuid(accountItemUpdate);
                                 accountItemService.updateByUuid(accountItemUpdate);
 
 
                                 // 如果定金都用完了,跳出循环
                                 // 如果定金都用完了,跳出循环
-                                if(lockAmt.compareTo(BigDecimal.ZERO)==0){
+                                if (lockAmt.compareTo(BigDecimal.ZERO) == 0) {
                                     break;
                                     break;
                                 }
                                 }
                             }
                             }
@@ -503,9 +504,9 @@ public class AccountService extends BaseService<Account> {
      */
      */
     public void reverseReceivable(String invoiceId, String biznisType) {
     public void reverseReceivable(String invoiceId, String biznisType) {
         // 更新账款明细应收收款
         // 更新账款明细应收收款
-        AccountItem accountItemForUpdate = null;
+        AccountItem accountItemForUpdate;
         // 账务对象Id
         // 账务对象Id
-        String objectId = null;
+        String objectId;
 
 
         if ("t_psi_outbound".equals(biznisType)) {
         if ("t_psi_outbound".equals(biznisType)) {
             Outbound outbound = outboundMapper.selectByIdForUpdate(invoiceId);
             Outbound outbound = outboundMapper.selectByIdForUpdate(invoiceId);
@@ -520,60 +521,64 @@ public class AccountService extends BaseService<Account> {
             Account accountUpdate;
             Account accountUpdate;
             // 如果当前出库单对应的订单做了应收收款,则自动作废应收核销,并且锁定金额订单收款(锁定金额)
             // 如果当前出库单对应的订单做了应收收款,则自动作废应收核销,并且锁定金额订单收款(锁定金额)
             // 如果是销售出库
             // 如果是销售出库
-            if(outbound.getOutType().equals(Constant.OutType.SALE.getName())){
+            if (outbound.getOutType().equals(Constant.OutType.SALE.getName())) {
                 RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(outbound.getFromId());
                 RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(outbound.getFromId());
-                // 查出并锁定所有应收核销明细
-                List<RecPayHandleItem> recPayHandleItemForUpdateList = recPayHandleItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
-                for (RecPayHandleItem recPayHandleItemForUpdate : recPayHandleItemForUpdateList) {
-                    // 更新账款明细应收收款
-                    accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItemForUpdate.getAccItemId());
-                    AccountItem accountItemUpdate = new AccountItem();
-                    accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().subtract(recPayHandleItemForUpdate.getAmtReceivableHandle()))
-                            .setItemId(recPayHandleItemForUpdate.getAccItemId());
-                    accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()));
-                    accountItemService.updateByUuid(accountItemUpdate);
-
-                    // 删掉核销明细
-                    recPayHandleItemMapper.deleteById(recPayHandleItemForUpdate.getItemId());
-                }
+                if (recPayForUpdate != null) {
+                    // 查出并锁定所有应收核销明细
+                    List<RecPayHandleItem> recPayHandleItemForUpdateList = recPayHandleItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
+                    if (recPayHandleItemForUpdateList.size() > 0) {
+                        for (RecPayHandleItem recPayHandleItemForUpdate : recPayHandleItemForUpdateList) {
+                            // 更新账款明细应收收款
+                            accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItemForUpdate.getAccItemId());
+                            AccountItem accountItemUpdate = new AccountItem();
+                            accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().subtract(recPayHandleItemForUpdate.getAmtReceivableHandle()))
+                                    .setItemId(recPayHandleItemForUpdate.getAccItemId());
+                            accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()));
+                            accountItemService.updateByUuid(accountItemUpdate);
 
 
-                // 把总帐上的钱加回来
-                accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
-                accountUpdate = new Account();
-                accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayForUpdate.getSumAmtReceivableHandle()))// 总应收收款金额
-                        .setObjectId(accountForUpdate.getObjectId());
-                // 剩余应收 = 总应收账款-总应收收款金额
-                accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
-                // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
-                accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()));
-
-                // 更新前的最后校验
-                // 可用金额为负数,则不能保存
-                if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
-                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
-                }
-                super.updateByUuid(accountUpdate);
-
-                // 先把收款单锁定
-                RecPay recPayUpdate = new RecPay();
-                recPayUpdate.setFlgLock(true).setRpId(recPayForUpdate.getRpId());
-                receiptService.updateByUuid(recPayUpdate);
-
-                // 账款明细解锁
-                List<RecPayItem> recPayItemList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
-                for (RecPayItem recPayItem : recPayItemList) {
-                    AccountItem accountItemUpdate = new AccountItem();
-                    accountItemUpdate.setFlgLock(true).setItemId(recPayItem.getAccItemId());
-                    accountItemService.updateByUuid(accountItemUpdate);
-                }
+                            // 删掉核销明细
+                            recPayHandleItemMapper.deleteById(recPayHandleItemForUpdate.getItemId());
+                        }
+
+                        // 把总帐上的钱加回来
+                        accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
+                        accountUpdate = new Account();
+                        accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayForUpdate.getSumAmtReceivableHandle()))// 总应收收款金额
+                                .setObjectId(accountForUpdate.getObjectId());
+                        // 剩余应收 = 总应收账款-总应收收款金额
+                        accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
+                        // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
+                        accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()));
+
+                        // 更新前的最后校验
+                        // 可用金额为负数,则不能保存
+                        if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
+                            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
+                        }
+                        super.updateByUuid(accountUpdate);
+
+                        // 先把收款单锁定
+                        RecPay recPayUpdate = new RecPay();
+                        recPayUpdate.setFlgLock(true).setRpId(recPayForUpdate.getRpId());
+                        receiptService.updateByUuid(recPayUpdate);
+
+                        // 账款明细解锁
+                        List<RecPayItem> recPayItemList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
+                        for (RecPayItem recPayItem : recPayItemList) {
+                            AccountItem accountItemUpdate = new AccountItem();
+                            accountItemUpdate.setFlgLock(true).setItemId(recPayItem.getAccItemId());
+                            accountItemService.updateByUuid(accountItemUpdate);
+                        }
 
 
-                // 钱进到锁定金额中
-                accountUpdate = new Account();
-                accountUpdate.setReceipt(accountForUpdate.getReceipt().subtract(recPayForUpdate.getSumAmtRec()))
-                        .setReceiptResidue(accountForUpdate.getReceiptResidue().subtract(recPayForUpdate.getSumAmtRec()))
-                        .setReceiptLock(accountForUpdate.getReceiptLock().add(recPayForUpdate.getSumAmtRec()))
-                        .setObjectId(objectId);
-                super.updateByUuid(accountUpdate);
+                        // 钱进到锁定金额中
+                        accountUpdate = new Account();
+                        accountUpdate.setReceipt(accountForUpdate.getReceipt().subtract(recPayForUpdate.getSumAmtRec()))
+                                .setReceiptResidue(accountForUpdate.getReceiptResidue().subtract(recPayForUpdate.getSumAmtRec()))
+                                .setReceiptLock(accountForUpdate.getReceiptLock().add(recPayForUpdate.getSumAmtRec()))
+                                .setObjectId(objectId);
+                        super.updateByUuid(accountUpdate);
+                    }
+                }
             }
             }
 
 
             accountItemForUpdate = accountItemMapper.selectByIdForUpdate(outbound.getReceivableId());
             accountItemForUpdate = accountItemMapper.selectByIdForUpdate(outbound.getReceivableId());
@@ -737,7 +742,7 @@ public class AccountService extends BaseService<Account> {
             LambdaUpdateWrapper<Inbound> updateWrapper = new LambdaUpdateWrapper<>();
             LambdaUpdateWrapper<Inbound> updateWrapper = new LambdaUpdateWrapper<>();
             updateWrapper.set(Inbound::getReceivableId, null).eq(Inbound::getIntoId, UUID.fromString(invoiceId));
             updateWrapper.set(Inbound::getReceivableId, null).eq(Inbound::getIntoId, UUID.fromString(invoiceId));
             inboundMapper.update(null, updateWrapper);
             inboundMapper.update(null, updateWrapper);
-        } 
+        }
         // 其他支出单
         // 其他支出单
         else if ("t_mac_other_payable".equals(biznisType)) {
         else if ("t_mac_other_payable".equals(biznisType)) {
             OtherPayable otherPayable = otherPayableMapper.selectByIdForUpdate(invoiceId);
             OtherPayable otherPayable = otherPayableMapper.selectByIdForUpdate(invoiceId);
@@ -777,8 +782,8 @@ public class AccountService extends BaseService<Account> {
      * @author : 周兴
      * @author : 周兴
      * @date : 2024-04-03 16:32
      * @date : 2024-04-03 16:32
      */
      */
-    public ResponseResultVO<?> getReceivableAccountSum(AccountItemQuery accountItemQuery){
-        Map<String, Object> receivableAccountMap= accountItemMapper.getReceivableAccountSum(accountItemQuery);
+    public ResponseResultVO<?> getReceivableAccountSum(AccountItemQuery accountItemQuery) {
+        Map<String, Object> receivableAccountMap = accountItemMapper.getReceivableAccountSum(accountItemQuery);
         return ResponseResultUtil.success(receivableAccountMap);
         return ResponseResultUtil.success(receivableAccountMap);
     }
     }