|
|
@@ -479,4 +479,82 @@ public class RecPayService extends BaseService<RecPay> {
|
|
|
/********************* 应收收款的处理 end **********************/
|
|
|
return ResponseResultUtil.success();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 作废
|
|
|
+ * @author : 付斌
|
|
|
+ * @date : 2024-03-08 16:38
|
|
|
+ */
|
|
|
+ public ResponseResultVO<?> invalid(String id) {
|
|
|
+ RecPay recPayForUpdate = recPayMapper.selectByIdForUpdate(id);
|
|
|
+ // 并发校验
|
|
|
+ if (!recPayForUpdate.getFlgValid()) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.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.getAmtReceivableHandle()))
|
|
|
+ .setAmtWaive(accountItemForUpdate.getAmtWaive().subtract(recPayHandleItemForUpdate.getAmtWaive()))
|
|
|
+ .setItemId(recPayHandleItemForUpdate.getAccItemId());
|
|
|
+ accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()).subtract(accountItemUpdate.getAmtWaive()));
|
|
|
+ accountItemService.updateByUuid(accountItemUpdate);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 把总帐上的钱加回来 todo
|
|
|
+ Account accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
|
|
|
+ Account accountUpdate = new Account();
|
|
|
+ accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayForUpdate.getSumAmtReceivableHandle()))// 总应收收款金额
|
|
|
+ .setReceivableWaive(accountForUpdate.getReceivableWaive().subtract(recPayForUpdate.getSumWaiveAmt()))// 总应收优惠金额
|
|
|
+ .setObjectId(accountForUpdate.getObjectId());
|
|
|
+ // 剩余应收 = 总应收账款-总应收收款金额-总应收优惠金额
|
|
|
+ accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()).subtract(accountUpdate.getReceivableWaive()));
|
|
|
+ // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
|
|
|
+ accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()).add(accountUpdate.getReceivableWaive()));
|
|
|
+
|
|
|
+ // 更新前的最后校验
|
|
|
+ // 剩余应收为负数,则不能保存
|
|
|
+ if (accountUpdate.getReceivableResidue().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) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_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());
|
|
|
+ // 删除账款明细
|
|
|
+ accountItemMapper.deleteById(recPayItem.getAccItemId());
|
|
|
+ // 删除账户流水
|
|
|
+ moneyAccountItemMapper.deleteByInvoiceId(recPayItem.getItemId());
|
|
|
+
|
|
|
+ if (!macList.contains(recPayItem.getMacId())) {
|
|
|
+ macList.add(recPayItem.getMacId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 更新总账表的总收款额和可用额
|
|
|
+ accountService.updateReceipt(recPayForUpdate.getObjectId());
|
|
|
+ // 更新账户余额
|
|
|
+ for (String macId : macList) {
|
|
|
+ accountService.updateMac(macId);
|
|
|
+ }
|
|
|
+ // 作废
|
|
|
+ RecPay recPayUpdate = new RecPay();
|
|
|
+ recPayUpdate.setFlgValid(false).setRpId(id);
|
|
|
+ super.updateByUuid(recPayUpdate);
|
|
|
+ return ResponseResultUtil.success();
|
|
|
+ }
|
|
|
}
|