|
|
@@ -239,7 +239,7 @@ public class AccountService extends BaseService<Account> {
|
|
|
* @date : 2024-03-22 11:08
|
|
|
*/
|
|
|
public void updateMac(String macId) {
|
|
|
- if(macId == null){
|
|
|
+ if (macId == null) {
|
|
|
return;
|
|
|
}
|
|
|
// 查询当前账户流水合计
|
|
|
@@ -249,7 +249,7 @@ public class AccountService extends BaseService<Account> {
|
|
|
// 更新资金账户
|
|
|
MoneyAccount moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(macId);
|
|
|
// 如果账户不允许为负数
|
|
|
- if(!moneyAccountForUpdate.getFlgNegative()) {
|
|
|
+ if (!moneyAccountForUpdate.getFlgNegative()) {
|
|
|
// 如果余额小于0 ,则提示余额不足
|
|
|
if (sumAmtInflow.compareTo(BigDecimal.ZERO) == -1) {
|
|
|
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
|
|
|
*/
|
|
|
public void updateContractAssets(String objectId) {
|
|
|
- if(objectId == null){
|
|
|
+ if (objectId == null) {
|
|
|
return;
|
|
|
}
|
|
|
// 更新账款总表上的总应收账款和总剩余应收
|
|
|
@@ -290,7 +290,7 @@ public class AccountService extends BaseService<Account> {
|
|
|
* @date : 2024-03-22 11:08
|
|
|
*/
|
|
|
public void updatePurEstimate(String objectId) {
|
|
|
- if(objectId == null){
|
|
|
+ if (objectId == null) {
|
|
|
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());
|
|
|
// 如果当前订单已经全部出库
|
|
|
- if(orderForUpdate.getOutQty().compareTo(orderForUpdate.getSumQuantity()) == 0){
|
|
|
+ if (orderForUpdate != null && orderForUpdate.getOutQty().compareTo(orderForUpdate.getSumQuantity()) == 0) {
|
|
|
RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderForUpdate.getOrderId());
|
|
|
- if(recPayForUpdate != null && recPayForUpdate.getFlgLock()){
|
|
|
+ if (recPayForUpdate != null && recPayForUpdate.getFlgLock()) {
|
|
|
// 先把收款单解锁
|
|
|
RecPay recPayUpdate = new RecPay();
|
|
|
recPayUpdate.setFlgLock(false).setRpId(recPayForUpdate.getRpId());
|
|
|
@@ -380,10 +380,11 @@ public class AccountService extends BaseService<Account> {
|
|
|
.setObjectId(objectId);
|
|
|
super.updateByUuid(accountUpdate);
|
|
|
|
|
|
+ // 查出当前订单需要核销的应收单据
|
|
|
List<AccountItemResponse> accountItemResponseList = accountItemMapper.getReceivableAccountItemForUpdate(
|
|
|
new AccountItemQuery().setObjectId(objectId).setOrderId(orderForUpdate.getOrderId()));
|
|
|
|
|
|
- if(accountItemResponseList.size() > 0){
|
|
|
+ if (accountItemResponseList.size() > 0) {
|
|
|
// 记录核销了哪些应收账
|
|
|
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())
|
|
|
.setAccItemId(accountItemResponse.getAccItemId());
|
|
|
// 如果定金比应收金额大
|
|
|
- if(lockAmt.compareTo(accountItemResponse.getAmtResidue()) == 1){
|
|
|
+ if (lockAmt.compareTo(accountItemResponse.getAmtResidue()) == 1) {
|
|
|
recPayHandleItem.setAmtReceivableHandle(accountItemResponse.getAmtResidue());
|
|
|
lockAmt = lockAmt.subtract(accountItemResponse.getAmtResidue());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
recPayHandleItem.setAmtReceivableHandle(lockAmt);
|
|
|
lockAmt = BigDecimal.ZERO;
|
|
|
}
|
|
|
@@ -419,7 +420,7 @@ public class AccountService extends BaseService<Account> {
|
|
|
accountItemService.updateByUuid(accountItemUpdate);
|
|
|
|
|
|
// 如果定金都用完了,跳出循环
|
|
|
- if(lockAmt.compareTo(BigDecimal.ZERO)==0){
|
|
|
+ if (lockAmt.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -503,9 +504,9 @@ public class AccountService extends BaseService<Account> {
|
|
|
*/
|
|
|
public void reverseReceivable(String invoiceId, String biznisType) {
|
|
|
// 更新账款明细应收收款
|
|
|
- AccountItem accountItemForUpdate = null;
|
|
|
+ AccountItem accountItemForUpdate;
|
|
|
// 账务对象Id
|
|
|
- String objectId = null;
|
|
|
+ String objectId;
|
|
|
|
|
|
if ("t_psi_outbound".equals(biznisType)) {
|
|
|
Outbound outbound = outboundMapper.selectByIdForUpdate(invoiceId);
|
|
|
@@ -520,60 +521,64 @@ public class AccountService extends BaseService<Account> {
|
|
|
Account accountUpdate;
|
|
|
// 如果当前出库单对应的订单做了应收收款,则自动作废应收核销,并且锁定金额订单收款(锁定金额)
|
|
|
// 如果是销售出库
|
|
|
- if(outbound.getOutType().equals(Constant.OutType.SALE.getName())){
|
|
|
+ if (outbound.getOutType().equals(Constant.OutType.SALE.getName())) {
|
|
|
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());
|
|
|
@@ -737,7 +742,7 @@ public class AccountService extends BaseService<Account> {
|
|
|
LambdaUpdateWrapper<Inbound> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
updateWrapper.set(Inbound::getReceivableId, null).eq(Inbound::getIntoId, UUID.fromString(invoiceId));
|
|
|
inboundMapper.update(null, updateWrapper);
|
|
|
- }
|
|
|
+ }
|
|
|
// 其他支出单
|
|
|
else if ("t_mac_other_payable".equals(biznisType)) {
|
|
|
OtherPayable otherPayable = otherPayableMapper.selectByIdForUpdate(invoiceId);
|
|
|
@@ -777,8 +782,8 @@ public class AccountService extends BaseService<Account> {
|
|
|
* @author : 周兴
|
|
|
* @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);
|
|
|
}
|
|
|
|