|
|
@@ -24,12 +24,14 @@ import com.dk.mdm.model.pojo.sale.Order;
|
|
|
import com.dk.mdm.model.query.mac.AccountItemQuery;
|
|
|
import com.dk.mdm.model.response.mac.AccountItemResponse;
|
|
|
import com.dk.mdm.model.response.mac.AccountResponse;
|
|
|
+import com.dk.mdm.service.common.CommonService;
|
|
|
import com.dk.mdm.service.mst.MoneyAccountService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -94,6 +96,9 @@ public class AccountService extends BaseService<Account> {
|
|
|
@Autowired
|
|
|
private RecPayHandleItemMapper recPayHandleItemMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CommonService commonService;
|
|
|
+
|
|
|
/**
|
|
|
* @desc : 查看来源单据,总单加明细
|
|
|
* @author : 姜永辉
|
|
|
@@ -357,7 +362,7 @@ public class AccountService extends BaseService<Account> {
|
|
|
Order orderForUpdate = orderMapper.selectByIdForUpdate(outbound.getFromId());
|
|
|
// 如果当前订单已经全部出库
|
|
|
if (orderForUpdate != null && orderForUpdate.getOutQty().compareTo(orderForUpdate.getSumQuantity()) == 0) {
|
|
|
- RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderForUpdate.getOrderId());
|
|
|
+ RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderForUpdate.getOrderId(),false);
|
|
|
if (recPayForUpdate != null && recPayForUpdate.getFlgLock()) {
|
|
|
// 先把收款单解锁
|
|
|
RecPay recPayUpdate = new RecPay();
|
|
|
@@ -385,6 +390,17 @@ public class AccountService extends BaseService<Account> {
|
|
|
new AccountItemQuery().setObjectId(objectId).setOrderId(orderForUpdate.getOrderId()));
|
|
|
|
|
|
if (accountItemResponseList.size() > 0) {
|
|
|
+ // 生成核销总单
|
|
|
+ RecPay recPayHandle = new RecPay();
|
|
|
+ // 获取单号
|
|
|
+ Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.RECPAY.getName(), false);
|
|
|
+ recPayHandle.setRpId(codeMap.get("outId").toString()).setRpNo(codeMap.get("outNote").toString())
|
|
|
+ .setRpType(Constant.RpType.SHOU_KUAN.getName()).setObjectId(objectId)
|
|
|
+ .setOrgId(recPayForUpdate.getOrgId()).setStaffId(recPayForUpdate.getStaffId()).setAccDate(LocalDate.now())
|
|
|
+ .setBiznisType(Constant.InventoryDocCode.ORDER.getTableName()).setBiznisId(recPayForUpdate.getBiznisId()).setBiznisNo(recPayForUpdate.getBiznisNo())
|
|
|
+ .setMakeStaff(recPayForUpdate.getMakeStaff()).setCpId(recPayForUpdate.getCpId()).setFlgOrderHandle(true);
|
|
|
+ recPayMapper.insert(recPayHandle);
|
|
|
+
|
|
|
// 记录核销了哪些应收账
|
|
|
List<RecPayHandleItem> receivableList = new ArrayList<>();
|
|
|
|
|
|
@@ -393,7 +409,7 @@ public class AccountService extends BaseService<Account> {
|
|
|
|
|
|
for (AccountItemResponse accountItemResponse : accountItemResponseList) {
|
|
|
RecPayHandleItem recPayHandleItem = new RecPayHandleItem();
|
|
|
- recPayHandleItem.setRpId(recPayForUpdate.getRpId()).setCpId(recPayForUpdate.getCpId()).setAccDate(recPayForUpdate.getAccDate())
|
|
|
+ recPayHandleItem.setRpId(recPayHandle.getRpId()).setCpId(recPayHandle.getCpId()).setAccDate(recPayHandle.getAccDate())
|
|
|
.setAccItemId(accountItemResponse.getAccItemId());
|
|
|
// 如果定金比应收金额大
|
|
|
if (lockAmt.compareTo(accountItemResponse.getAmtResidue()) == 1) {
|
|
|
@@ -436,11 +452,11 @@ public class AccountService extends BaseService<Account> {
|
|
|
recPayUpdate = new RecPay();
|
|
|
recPayUpdate.setSumAmtReceivableHandle(recPayHandleItem.getAmtReceivableHandle())
|
|
|
.setSumShouldHandle(recPayHandleItem.getAmtReceivableHandle())
|
|
|
- .setRpId(recPayForUpdate.getRpId());
|
|
|
+ .setRpId(recPayHandle.getRpId());
|
|
|
receiptService.updateByUuid(recPayUpdate);
|
|
|
|
|
|
// 更新总账上
|
|
|
- accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
|
|
|
+ accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
|
|
|
accountUpdate = new Account();
|
|
|
accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().add(recPayHandleItem.getAmtReceivableHandle()))// 总应收收款金额
|
|
|
.setObjectId(accountForUpdate.getObjectId());
|
|
|
@@ -522,10 +538,11 @@ public class AccountService extends BaseService<Account> {
|
|
|
// 如果当前出库单对应的订单做了应收收款,则自动作废应收核销,并且锁定金额订单收款(锁定金额)
|
|
|
// 如果是销售出库
|
|
|
if (outbound.getOutType().equals(Constant.OutType.SALE.getName())) {
|
|
|
- RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(outbound.getFromId());
|
|
|
- if (recPayForUpdate != null) {
|
|
|
+ RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(outbound.getFromId(),false); // 款
|
|
|
+ RecPay recPayHandleForUpdate = recPayMapper.selectByBiznisIdForUpdate(outbound.getFromId(),true); // 账
|
|
|
+ if (recPayForUpdate != null && recPayHandleForUpdate != null) {
|
|
|
// 查出并锁定所有应收核销明细
|
|
|
- List<RecPayHandleItem> recPayHandleItemForUpdateList = recPayHandleItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
|
|
|
+ List<RecPayHandleItem> recPayHandleItemForUpdateList = recPayHandleItemMapper.selectByZIdForUpdate(recPayHandleForUpdate.getRpId());
|
|
|
if (recPayHandleItemForUpdateList.size() > 0) {
|
|
|
for (RecPayHandleItem recPayHandleItemForUpdate : recPayHandleItemForUpdateList) {
|
|
|
// 更新账款明细应收收款
|
|
|
@@ -541,10 +558,10 @@ public class AccountService extends BaseService<Account> {
|
|
|
}
|
|
|
|
|
|
// 把总帐上的钱加回来
|
|
|
- accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
|
|
|
+ accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
|
|
|
accountUpdate = new Account();
|
|
|
- accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayForUpdate.getSumAmtReceivableHandle()))// 总应收收款金额
|
|
|
- .setObjectId(accountForUpdate.getObjectId());
|
|
|
+ accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayHandleForUpdate.getSumAmtReceivableHandle()))// 总应收收款金额
|
|
|
+ .setObjectId(objectId);
|
|
|
// 剩余应收 = 总应收账款-总应收收款金额
|
|
|
accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
|
|
|
// 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
|
|
|
@@ -557,6 +574,9 @@ public class AccountService extends BaseService<Account> {
|
|
|
}
|
|
|
super.updateByUuid(accountUpdate);
|
|
|
|
|
|
+ // 删掉收款核销单
|
|
|
+ recPayMapper.deleteById(recPayHandleForUpdate.getRpId());
|
|
|
+
|
|
|
// 先把收款单锁定
|
|
|
RecPay recPayUpdate = new RecPay();
|
|
|
recPayUpdate.setFlgLock(true).setRpId(recPayForUpdate.getRpId());
|
|
|
@@ -571,6 +591,7 @@ public class AccountService extends BaseService<Account> {
|
|
|
}
|
|
|
|
|
|
// 钱进到锁定金额中
|
|
|
+ accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
|
|
|
accountUpdate = new Account();
|
|
|
accountUpdate.setReceipt(accountForUpdate.getReceipt().subtract(recPayForUpdate.getSumAmtRec()))
|
|
|
.setReceiptResidue(accountForUpdate.getReceiptResidue().subtract(recPayForUpdate.getSumAmtRec()))
|