|
|
@@ -9,25 +9,21 @@ import com.dk.common.response.ResponseCodeEnum;
|
|
|
import com.dk.common.response.ResponseResultUtil;
|
|
|
import com.dk.common.response.ResponseResultVO;
|
|
|
import com.dk.mdm.infrastructure.convert.mac.RecPayConvert;
|
|
|
+import com.dk.mdm.infrastructure.convert.mac.RecPayHandleItemConvert;
|
|
|
import com.dk.mdm.infrastructure.convert.mac.RecPayItemConvert;
|
|
|
-import com.dk.mdm.mapper.mac.AccountItemMapper;
|
|
|
-import com.dk.mdm.mapper.mac.AccountMapper;
|
|
|
-import com.dk.mdm.mapper.mac.RecPayItemMapper;
|
|
|
+import com.dk.mdm.mapper.mac.*;
|
|
|
import com.dk.mdm.mapper.mst.MoneyAccountItemMapper;
|
|
|
import com.dk.mdm.mapper.mst.MoneyAccountMapper;
|
|
|
-import com.dk.mdm.model.pojo.mac.Account;
|
|
|
-import com.dk.mdm.model.pojo.mac.AccountItem;
|
|
|
-import com.dk.mdm.model.pojo.mac.RecPay;
|
|
|
-import com.dk.mdm.mapper.mac.RecPayMapper;
|
|
|
+import com.dk.mdm.model.pojo.mac.*;
|
|
|
import com.dk.common.service.BaseService;
|
|
|
import com.dk.common.mapper.BaseMapper;
|
|
|
-import com.dk.mdm.model.pojo.mac.RecPayItem;
|
|
|
import com.dk.mdm.model.pojo.mst.MoneyAccount;
|
|
|
import com.dk.mdm.model.pojo.mst.MoneyAccountItem;
|
|
|
import com.dk.mdm.model.query.mac.RecPayItemQuery;
|
|
|
import com.dk.mdm.model.query.mac.RecPayQuery;
|
|
|
import com.dk.mdm.model.response.mac.RecPayItemResponse;
|
|
|
import com.dk.mdm.model.response.mac.RecPayResponse;
|
|
|
+import com.dk.mdm.model.vo.mac.RecPayHandleItemVO;
|
|
|
import com.dk.mdm.model.vo.mac.RecPayItemVO;
|
|
|
import com.dk.mdm.model.vo.mac.RecPayVO;
|
|
|
import com.dk.mdm.service.common.CommonService;
|
|
|
@@ -84,6 +80,9 @@ public class RecPayService extends BaseService<RecPay> {
|
|
|
private MoneyAccountItemMapper moneyAccountItemMapper;
|
|
|
|
|
|
@Autowired
|
|
|
+ private RecPayHandleItemMapper recPayHandleItemMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private CommonService commonService;
|
|
|
|
|
|
@Autowired
|
|
|
@@ -92,6 +91,9 @@ public class RecPayService extends BaseService<RecPay> {
|
|
|
@Autowired
|
|
|
private RecPayItemConvert recPayItemConvert;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RecPayHandleItemConvert recPayHandleItemConvert;
|
|
|
+
|
|
|
/**
|
|
|
* @desc : 条件查询
|
|
|
* @author : 付斌
|
|
|
@@ -175,16 +177,7 @@ public class RecPayService extends BaseService<RecPay> {
|
|
|
}
|
|
|
|
|
|
// 插入账款总表
|
|
|
- Account accountForUpdate = accountMapper.selectByIdForUpdate(recPayVO.getObjectId());
|
|
|
-
|
|
|
- // 没有账款对象,需要新建
|
|
|
- if (accountForUpdate == null) {
|
|
|
- accountForUpdate = new Account();
|
|
|
- accountForUpdate.setObjectId(recPayVO.getObjectId()).setObjectType(Constant.ObjectType.CUS.getName());
|
|
|
- accountMapper.insert(accountForUpdate);
|
|
|
- accountForUpdate = accountMapper.selectByIdForUpdate(recPayVO.getObjectId());
|
|
|
- }
|
|
|
-
|
|
|
+ Account accountForUpdate = accountService.getCusAccountForUpdate(recPayVO.getObjectId());
|
|
|
// 更新账款总表上收款的相关字段
|
|
|
Account accountUpdate = new Account();
|
|
|
accountUpdate.setReceipt(accountForUpdate.getReceipt().add(recPayVO.getSumAmtRec()))// 总收款金额
|
|
|
@@ -367,6 +360,7 @@ public class RecPayService extends BaseService<RecPay> {
|
|
|
)
|
|
|
public ResponseResultVO<?> insertReceivableReceipt(RecPayVO recPayVO) {
|
|
|
|
|
|
+ /********************* 收款的处理 begin **********************/
|
|
|
// 获取单号
|
|
|
Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.RECPAY.getName(), false);
|
|
|
recPayVO.setRpId(codeMap.get("outId").toString()).setRpNo(codeMap.get("outNote").toString());
|
|
|
@@ -413,22 +407,70 @@ public class RecPayService extends BaseService<RecPay> {
|
|
|
}
|
|
|
|
|
|
// 插入账款总表
|
|
|
- Account accountForUpdate = accountMapper.selectByIdForUpdate(recPayVO.getObjectId());
|
|
|
-
|
|
|
- // 没有账款对象,需要新建
|
|
|
- if (accountForUpdate == null) {
|
|
|
- accountForUpdate = new Account();
|
|
|
- accountForUpdate.setObjectId(recPayVO.getObjectId()).setObjectType(Constant.ObjectType.CUS.getName());
|
|
|
- accountMapper.insert(accountForUpdate);
|
|
|
- accountForUpdate = accountMapper.selectByIdForUpdate(recPayVO.getObjectId());
|
|
|
- }
|
|
|
-
|
|
|
+ Account accountForUpdate = accountService.getCusAccountForUpdate(recPayVO.getObjectId());
|
|
|
// 更新账款总表上收款的相关字段
|
|
|
Account accountUpdate = new Account();
|
|
|
accountUpdate.setReceipt(accountForUpdate.getReceipt().add(recPayVO.getSumAmtRec()))// 总收款金额
|
|
|
.setReceiptResidue(accountForUpdate.getReceiptResidue().add(recPayVO.getSumAmtRec()))// 可退金额
|
|
|
.setObjectId(accountForUpdate.getObjectId());
|
|
|
accountService.updateByUuid(accountUpdate);
|
|
|
+ /********************* 收款的处理 end **********************/
|
|
|
+
|
|
|
+
|
|
|
+ /********************* 应收收款的处理 begin **********************/
|
|
|
+ // 应收收款的处理
|
|
|
+ if (recPayVO.getReceivableList() != null && recPayVO.getReceivableList().size() > 0) {
|
|
|
+ for (RecPayHandleItemVO recPayHandleItemVO : recPayVO.getReceivableList()) {
|
|
|
+ RecPayHandleItem recPayHandleItem = recPayHandleItemConvert.convertToPo(recPayHandleItemVO);
|
|
|
+ recPayHandleItem.setItemId(null).setRpId(recPay.getRpId()).setCpId(recPay.getCpId()).setAccDate(recPay.getAccDate());
|
|
|
+ recPayHandleItemMapper.insert(recPayHandleItem);
|
|
|
+
|
|
|
+ // 账款明细的核销金额和优惠金额
|
|
|
+ AccountItem accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItem.getAccItemId());
|
|
|
+ AccountItem accountItemUpdate = new AccountItem();
|
|
|
+ // 核销金额加优惠金额,超出应收金额
|
|
|
+ if (accountItemForUpdate.getAmtResidue().compareTo(recPayHandleItem.getAmtReceivableHandle().add(recPayHandleItem.getAmtWaive())) == -1) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
|
|
|
+ }
|
|
|
+ accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().add(recPayHandleItem.getAmtReceivableHandle()))
|
|
|
+ .setAmtWaive(accountItemForUpdate.getAmtWaive().add(recPayHandleItem.getAmtWaive()))
|
|
|
+ .setItemId(recPayHandleItem.getAccItemId());
|
|
|
+ // 剩余金额 = 应收金额-应收收款金额-优惠金额
|
|
|
+ accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()).subtract(accountItemUpdate.getAmtWaive()));
|
|
|
+ accountItemService.updateByUuid(accountItemUpdate);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算明细的核销金额,优惠金额合计
|
|
|
+ RecPayHandleItemVO recPayHandleItemVO = recPayVO.getReceivableList().stream().reduce((x, y) -> {
|
|
|
+ RecPayHandleItemVO item = new RecPayHandleItemVO();
|
|
|
+ item.setAmtReceivableHandle(x.getAmtReceivableHandle().add(y.getAmtReceivableHandle()));
|
|
|
+ item.setAmtWaive(x.getAmtWaive().add(y.getAmtWaive()));
|
|
|
+ return item;
|
|
|
+ }).get();
|
|
|
+
|
|
|
+ // 更新总账上
|
|
|
+ accountForUpdate = accountMapper.selectByIdForUpdate(recPayVO.getObjectId());
|
|
|
+ accountUpdate = new Account();
|
|
|
+ accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().add(recPayHandleItemVO.getAmtReceivableHandle()))// 总应收收款金额
|
|
|
+ .setReceivableWaive(accountForUpdate.getReceivableWaive().add(recPayHandleItemVO.getAmtWaive()))// 总应收优惠金额
|
|
|
+ .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);
|
|
|
+ }
|
|
|
+ /********************* 应收收款的处理 end **********************/
|
|
|
return ResponseResultUtil.success();
|
|
|
}
|
|
|
}
|