|
@@ -1,5 +1,6 @@
|
|
|
package com.dk.mdm.service.mac;
|
|
package com.dk.mdm.service.mac;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.dk.common.exception.BaseBusinessException;
|
|
import com.dk.common.exception.BaseBusinessException;
|
|
|
import com.dk.common.infrastructure.annotaiton.Pagination;
|
|
import com.dk.common.infrastructure.annotaiton.Pagination;
|
|
|
import com.dk.common.infrastructure.constant.Constant;
|
|
import com.dk.common.infrastructure.constant.Constant;
|
|
@@ -7,16 +8,23 @@ import com.dk.common.infrastructure.enums.ErrorCodeEnum;
|
|
|
import com.dk.common.response.ResponseCodeEnum;
|
|
import com.dk.common.response.ResponseCodeEnum;
|
|
|
import com.dk.common.response.ResponseResultUtil;
|
|
import com.dk.common.response.ResponseResultUtil;
|
|
|
import com.dk.common.response.ResponseResultVO;
|
|
import com.dk.common.response.ResponseResultVO;
|
|
|
|
|
+import com.dk.mdm.mapper.ivt.InboundMapper;
|
|
|
|
|
+import com.dk.mdm.mapper.ivt.OutboundMapper;
|
|
|
import com.dk.mdm.mapper.mac.AccountItemMapper;
|
|
import com.dk.mdm.mapper.mac.AccountItemMapper;
|
|
|
import com.dk.mdm.mapper.mst.MoneyAccountItemMapper;
|
|
import com.dk.mdm.mapper.mst.MoneyAccountItemMapper;
|
|
|
|
|
+import com.dk.mdm.model.pojo.ivt.Inbound;
|
|
|
|
|
+import com.dk.mdm.model.pojo.ivt.Outbound;
|
|
|
import com.dk.mdm.model.pojo.mac.Account;
|
|
import com.dk.mdm.model.pojo.mac.Account;
|
|
|
import com.dk.mdm.mapper.mac.AccountMapper;
|
|
import com.dk.mdm.mapper.mac.AccountMapper;
|
|
|
import com.dk.common.service.BaseService;
|
|
import com.dk.common.service.BaseService;
|
|
|
import com.dk.common.mapper.BaseMapper;
|
|
import com.dk.common.mapper.BaseMapper;
|
|
|
|
|
+import com.dk.mdm.model.pojo.mac.AccountItem;
|
|
|
import com.dk.mdm.model.pojo.mst.MoneyAccount;
|
|
import com.dk.mdm.model.pojo.mst.MoneyAccount;
|
|
|
import com.dk.mdm.model.query.mac.AccountItemQuery;
|
|
import com.dk.mdm.model.query.mac.AccountItemQuery;
|
|
|
import com.dk.mdm.model.response.mac.AccountItemResponse;
|
|
import com.dk.mdm.model.response.mac.AccountItemResponse;
|
|
|
import com.dk.mdm.model.response.mac.AccountResponse;
|
|
import com.dk.mdm.model.response.mac.AccountResponse;
|
|
|
|
|
+import com.dk.mdm.service.ivt.inbound.InboundService;
|
|
|
|
|
+import com.dk.mdm.service.ivt.outbound.OutboundService;
|
|
|
import com.dk.mdm.service.mst.MoneyAccountService;
|
|
import com.dk.mdm.service.mst.MoneyAccountService;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -25,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
@Transactional
|
|
@Transactional
|
|
@@ -52,6 +61,17 @@ public class AccountService extends BaseService<Account> {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private MoneyAccountItemMapper moneyAccountItemMapper;
|
|
private MoneyAccountItemMapper moneyAccountItemMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OutboundService outboundService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OutboundMapper outboundMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private InboundService inboundService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private InboundMapper inboundMapper;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @desc : 查看来源单据,总单加明细
|
|
* @desc : 查看来源单据,总单加明细
|
|
@@ -122,7 +142,7 @@ public class AccountService extends BaseService<Account> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @desc : 获取账款总表,没有则新建(客户)
|
|
|
|
|
|
|
+ * @desc : 获取账款总表,没有则新建(供应商)
|
|
|
* @author : 付斌
|
|
* @author : 付斌
|
|
|
* @date : 2024-03-23 16:32
|
|
* @date : 2024-03-23 16:32
|
|
|
*/
|
|
*/
|
|
@@ -173,6 +193,183 @@ public class AccountService extends BaseService<Account> {
|
|
|
moneyAccountUpdate.setBalance(sumAmtInflow).setMacId(macId);
|
|
moneyAccountUpdate.setBalance(sumAmtInflow).setMacId(macId);
|
|
|
moneyAccountService.updateByUuid(moneyAccountUpdate);
|
|
moneyAccountService.updateByUuid(moneyAccountUpdate);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc : 应收记账
|
|
|
|
|
+ * @author : 付斌
|
|
|
|
|
+ * @date : 2024-03-22 11:08
|
|
|
|
|
+ */
|
|
|
|
|
+ public void accReceivable(String invoiceId, String biznisType) {
|
|
|
|
|
+ // 账款明细
|
|
|
|
|
+ AccountItem accountItemInsert = new AccountItem();
|
|
|
|
|
+ // 账务对象Id
|
|
|
|
|
+ String objectId = null;
|
|
|
|
|
+
|
|
|
|
|
+ if ("t_psi_outbound".equals(biznisType)) {
|
|
|
|
|
+ Outbound outbound = outboundMapper.selectByIdForUpdate(invoiceId);
|
|
|
|
|
+ objectId = outbound.getCusId();
|
|
|
|
|
+
|
|
|
|
|
+ // 当前单据已经记账
|
|
|
|
|
+ if (outbound.getReceivableId() != null) {
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.CURRENT_INVOICE_ISACC.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 插入账款明细
|
|
|
|
|
+ accountItemInsert.setAccItemType(Constant.accItemType.YING_SHOU.getName())
|
|
|
|
|
+ .setObjectId(objectId).setOrgId(outbound.getOrgId()).setStaffId(outbound.getStaffId())
|
|
|
|
|
+ .setAccDate(outbound.getOutDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName())
|
|
|
|
|
+ .setAmtShould(outbound.getOutAmt()).setAmtResidue(outbound.getOutAmt())
|
|
|
|
|
+ .setBiznisType(biznisType).setBiznisId(outbound.getOutId()).setBiznisNo(outbound.getOutNo())
|
|
|
|
|
+ .setMakeStaff(outbound.getMakeStaff()).setCpId(outbound.getCpId());
|
|
|
|
|
+ accountItemMapper.insert(accountItemInsert);
|
|
|
|
|
+
|
|
|
|
|
+ // 更新出库单上的账款明细Id
|
|
|
|
|
+ Outbound outboundUpdate = new Outbound();
|
|
|
|
|
+ outboundUpdate.setReceivableId(accountItemInsert.getItemId()).setOutId(invoiceId);
|
|
|
|
|
+ outboundService.updateByUuid(outboundUpdate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 更新账款总表上的总应收账款和总剩余应收
|
|
|
|
|
+ Account accountForUpdate = getCusAccountForUpdate(objectId);
|
|
|
|
|
+ Account accountUpdate = new Account();
|
|
|
|
|
+ accountUpdate.setReceivable(accountForUpdate.getReceivable().add(accountItemInsert.getAmtShould()))
|
|
|
|
|
+ .setReceivableResidue(accountForUpdate.getReceivableResidue().add(accountItemInsert.getAmtShould()))
|
|
|
|
|
+ .setObjectId(objectId);
|
|
|
|
|
+ super.updateByUuid(accountUpdate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc : 应收反记账
|
|
|
|
|
+ * @author : 付斌
|
|
|
|
|
+ * @date : 2024-03-22 11:08
|
|
|
|
|
+ */
|
|
|
|
|
+ public void reverseReceivable(String invoiceId, String biznisType) {
|
|
|
|
|
+ // 更新账款明细应收收款
|
|
|
|
|
+ AccountItem accountItemForUpdate = null;
|
|
|
|
|
+ // 账务对象Id
|
|
|
|
|
+ String objectId = null;
|
|
|
|
|
+
|
|
|
|
|
+ if ("t_psi_outbound".equals(biznisType)) {
|
|
|
|
|
+ Outbound outbound = outboundMapper.selectByIdForUpdate(invoiceId);
|
|
|
|
|
+ objectId = outbound.getCusId();
|
|
|
|
|
+
|
|
|
|
|
+ // 当前单据已经记账
|
|
|
|
|
+ if (outbound.getReceivableId() == null) {
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.CURRENT_INVOICE_ISREVERSE.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ accountItemForUpdate = accountItemMapper.selectByIdForUpdate(outbound.getReceivableId());
|
|
|
|
|
+ // 当前单据已核销
|
|
|
|
|
+ if (accountItemForUpdate.getAmtShould().compareTo(accountItemForUpdate.getAmtResidue()) != 0) {
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.CURRENT_INVOICE_ISHANDLE.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 将出库单上的账款明细Id更为null
|
|
|
|
|
+ LambdaUpdateWrapper<Outbound> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ updateWrapper.set(Outbound::getReceivableId, null).eq(Outbound::getOutId, UUID.fromString(invoiceId));
|
|
|
|
|
+ outboundMapper.update(null, updateWrapper);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 删除账款明细
|
|
|
|
|
+ accountItemMapper.deleteById(accountItemForUpdate.getItemId());
|
|
|
|
|
+
|
|
|
|
|
+ // 更新账款总表上的总应收账款和总剩余应收
|
|
|
|
|
+ Account accountForUpdate = getCusAccountForUpdate(objectId);
|
|
|
|
|
+ Account accountUpdate = new Account();
|
|
|
|
|
+ accountUpdate.setReceivable(accountForUpdate.getReceivable().subtract(accountItemForUpdate.getAmtShould()))
|
|
|
|
|
+ .setReceivableResidue(accountForUpdate.getReceivableResidue().subtract(accountItemForUpdate.getAmtShould()))
|
|
|
|
|
+ .setObjectId(objectId);
|
|
|
|
|
+ super.updateByUuid(accountUpdate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc : 应付记账
|
|
|
|
|
+ * @author : 付斌
|
|
|
|
|
+ * @date : 2024-03-22 11:08
|
|
|
|
|
+ */
|
|
|
|
|
+ public void accPayable(String invoiceId, String biznisType) {
|
|
|
|
|
+ // 账款明细
|
|
|
|
|
+ AccountItem accountItemInsert = new AccountItem();
|
|
|
|
|
+ // 账务对象Id
|
|
|
|
|
+ String objectId = null;
|
|
|
|
|
+
|
|
|
|
|
+ if ("t_psi_inbound".equals(biznisType)) {
|
|
|
|
|
+ Inbound inbound = inboundMapper.selectByIdForUpdate(invoiceId);
|
|
|
|
|
+ objectId = inbound.getSupId();
|
|
|
|
|
+
|
|
|
|
|
+ // 当前单据已经记账
|
|
|
|
|
+ if (inbound.getReceivableId() != null) {
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.CURRENT_INVOICE_ISACC.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 插入账款明细
|
|
|
|
|
+ accountItemInsert.setAccItemType(Constant.accItemType.YING_SHOU.getName())
|
|
|
|
|
+ .setObjectId(objectId).setOrgId(inbound.getOrgId()).setStaffId(inbound.getStaffId())
|
|
|
|
|
+ .setAccDate(inbound.getIntoDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName())
|
|
|
|
|
+ .setAmtShould(inbound.getIntoAmt()).setAmtResidue(inbound.getIntoAmt())
|
|
|
|
|
+ .setBiznisType(biznisType).setBiznisId(inbound.getIntoId()).setBiznisNo(inbound.getIntoNo())
|
|
|
|
|
+ .setMakeStaff(inbound.getMakeStaff()).setCpId(inbound.getCpId());
|
|
|
|
|
+ accountItemMapper.insert(accountItemInsert);
|
|
|
|
|
+
|
|
|
|
|
+ // 更新出库单上的账款明细Id
|
|
|
|
|
+ Inbound inboundUpdate = new Inbound();
|
|
|
|
|
+ inboundUpdate.setReceivableId(accountItemInsert.getItemId()).setIntoId(invoiceId);
|
|
|
|
|
+ inboundService.updateByUuid(inboundUpdate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 更新账款总表上的总应收账款和总剩余应收
|
|
|
|
|
+ Account accountForUpdate = getSupAccountForUpdate(objectId);
|
|
|
|
|
+ Account accountUpdate = new Account();
|
|
|
|
|
+ accountUpdate.setPayable(accountForUpdate.getPayable().add(accountItemInsert.getAmtShould()))
|
|
|
|
|
+ .setPayableResidue(accountForUpdate.getPayableResidue().add(accountItemInsert.getAmtShould()))
|
|
|
|
|
+ .setObjectId(objectId);
|
|
|
|
|
+ super.updateByUuid(accountUpdate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc : 应付反记账
|
|
|
|
|
+ * @author : 付斌
|
|
|
|
|
+ * @date : 2024-03-22 11:08
|
|
|
|
|
+ */
|
|
|
|
|
+ public void reversePayable(String invoiceId, String biznisType) {
|
|
|
|
|
+ // 更新账款明细应收收款
|
|
|
|
|
+ AccountItem accountItemForUpdate = null;
|
|
|
|
|
+ // 账务对象Id
|
|
|
|
|
+ String objectId = null;
|
|
|
|
|
+
|
|
|
|
|
+ if ("t_psi_inbound".equals(biznisType)) {
|
|
|
|
|
+ Inbound inbound = inboundMapper.selectByIdForUpdate(invoiceId);
|
|
|
|
|
+ objectId = inbound.getSupId();
|
|
|
|
|
+
|
|
|
|
|
+ // 当前单据已经记账
|
|
|
|
|
+ if (inbound.getReceivableId() == null) {
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.CURRENT_INVOICE_ISREVERSE.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ accountItemForUpdate = accountItemMapper.selectByIdForUpdate(inbound.getReceivableId());
|
|
|
|
|
+ // 当前单据已核销
|
|
|
|
|
+ if (accountItemForUpdate.getAmtShould().compareTo(accountItemForUpdate.getAmtResidue()) != 0) {
|
|
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.CURRENT_INVOICE_ISHANDLE.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 将出库单上的账款明细Id更为null
|
|
|
|
|
+ LambdaUpdateWrapper<Inbound> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ updateWrapper.set(Inbound::getReceivableId, null).eq(Inbound::getIntoId, UUID.fromString(invoiceId));
|
|
|
|
|
+ inboundMapper.update(null, updateWrapper);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 删除账款明细
|
|
|
|
|
+ accountItemMapper.deleteById(accountItemForUpdate.getItemId());
|
|
|
|
|
+
|
|
|
|
|
+ // 更新账款总表上的总应收账款和总剩余应收
|
|
|
|
|
+ Account accountForUpdate = getSupAccountForUpdate(objectId);
|
|
|
|
|
+ Account accountUpdate = new Account();
|
|
|
|
|
+ accountUpdate.setPayable(accountForUpdate.getPayable().subtract(accountItemForUpdate.getAmtShould()))
|
|
|
|
|
+ .setPayableResidue(accountForUpdate.getPayableResidue().subtract(accountItemForUpdate.getAmtShould()))
|
|
|
|
|
+ .setObjectId(objectId);
|
|
|
|
|
+ super.updateByUuid(accountUpdate);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/********************* 账款部分共通方法 end **********************/
|
|
/********************* 账款部分共通方法 end **********************/
|
|
|
|
|
|
|
|
|
|
|