|
|
@ -1,10 +1,7 @@ |
|
|
|
package com.ruoyi.system.service.impl; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import com.ruoyi.common.exception.BusinessException; |
|
|
@ -152,7 +149,8 @@ public class BaseExpenseConfirmAmountServiceImpl implements IBaseExpenseConfirmA |
|
|
|
for (BaseExpenseAccountChild child: expenseChildren) { |
|
|
|
if(child.getPurchaseCode()!=null&&!child.getPurchaseCode().isEmpty()){ |
|
|
|
// 更新应付账款打款相关信息
|
|
|
|
int rows = updateFinancialPayableInfo(child.getPurchaseCode(),supplierCode,baseExpenseConfirmAmount); |
|
|
|
FinancialAccountsPayable payable = updateFinancialPayableInfo(child.getPurchaseCode(),child,supplierCode,baseExpenseConfirmAmount); |
|
|
|
int rows = accountsPayableMapper.updateFinancialAccountsPayable(payable); |
|
|
|
if(rows<= 0){ |
|
|
|
throw new BusinessException("更新应付账款记录失败!"); |
|
|
|
} |
|
|
@ -161,10 +159,9 @@ public class BaseExpenseConfirmAmountServiceImpl implements IBaseExpenseConfirmA |
|
|
|
if(purchaseOrder == null){ |
|
|
|
throw new BusinessException("关联采购订单"+purchaseOrderCode+"不存在!"); |
|
|
|
} |
|
|
|
BigDecimal paidPrice = child.getAmounts(); |
|
|
|
if(paidPrice.compareTo(purchaseOrder.getRmbSum()) == 0){ |
|
|
|
if(payable.getAccountsPayableStatus().equals("2")){ |
|
|
|
purchaseOrder.setPaymentStatus("4");//已结案
|
|
|
|
}else if(paidPrice.compareTo(purchaseOrder.getRmbSum()) < 0){ |
|
|
|
}else { |
|
|
|
purchaseOrder.setPaymentStatus("1");//部分打款(需要手动结案)
|
|
|
|
} |
|
|
|
purchaseOrder.setUpdateBy(ShiroUtils.getLoginName()); |
|
|
@ -177,7 +174,8 @@ public class BaseExpenseConfirmAmountServiceImpl implements IBaseExpenseConfirmA |
|
|
|
} |
|
|
|
else if(child.getOutsourceCode()!=null&&!child.getOutsourceCode().isEmpty()){ |
|
|
|
// 更新应付账款打款相关信息
|
|
|
|
int rows = updateFinancialPayableInfo(child.getOutsourceCode(),supplierCode,baseExpenseConfirmAmount); |
|
|
|
FinancialAccountsPayable payable = updateFinancialPayableInfo(child.getOutsourceCode(), child,supplierCode,baseExpenseConfirmAmount); |
|
|
|
int rows = accountsPayableMapper.updateFinancialAccountsPayable(payable); |
|
|
|
if(rows<= 0){ |
|
|
|
throw new BusinessException("更新应付账款记录失败!"); |
|
|
|
} |
|
|
@ -186,13 +184,23 @@ public class BaseExpenseConfirmAmountServiceImpl implements IBaseExpenseConfirmA |
|
|
|
tempOutDetail.setOutsourceOrderNo(child.getOutsourceCode()); |
|
|
|
tempOutDetail.setSupplierCode(supplierCode); |
|
|
|
List<OutsourceOrderDetail> outOrderDetails = outOrderDetailMapper.selectOutsourceOrderDetailList(tempOutDetail); |
|
|
|
if(StringUtils.isEmpty(outOrderDetails)){ |
|
|
|
throw new BusinessException("未找到关联委外订单详情信息!"); |
|
|
|
} |
|
|
|
|
|
|
|
if(CollectionUtils.isNotEmpty(outOrderDetails)){ |
|
|
|
for (OutsourceOrderDetail detail: outOrderDetails) { |
|
|
|
detail.setRemitStatus("2"); |
|
|
|
detail.setClosedStatus("0"); |
|
|
|
if(payable.getAccountsPayableStatus().equals("1")){//部分付款
|
|
|
|
detail.setRemitStatus("1"); |
|
|
|
detail.setClosedStatus("1"); |
|
|
|
}else{//全部打款
|
|
|
|
detail.setRemitStatus("2"); |
|
|
|
detail.setClosedStatus("2"); |
|
|
|
} |
|
|
|
outOrderDetailMapper.updateOutsourceOrderDetail(detail); |
|
|
|
updateResult ++; |
|
|
|
} |
|
|
|
|
|
|
|
if(updateResult <= 0){ |
|
|
|
throw new BusinessException("委外订单详情记录更新失败!"); |
|
|
|
} |
|
|
@ -210,37 +218,23 @@ public class BaseExpenseConfirmAmountServiceImpl implements IBaseExpenseConfirmA |
|
|
|
// 更新委外订单打款状态
|
|
|
|
public int updateOutsourceOrderPayableStatus(String outsourceOrderCode){ |
|
|
|
OutsourceOrder outsourceOrder = outsourceOrderMapper.selectOutsourceOrderByNo(outsourceOrderCode); |
|
|
|
OutsourceOrderDetail temp = new OutsourceOrderDetail(); |
|
|
|
temp.setOutsourceOrderNo(outsourceOrderCode); |
|
|
|
List<OutsourceOrderDetail> outsourceOrderDetails = outOrderDetailMapper.selectOutsourceOrderDetailList(temp); |
|
|
|
if(CollectionUtils.isEmpty(outsourceOrderDetails)){ |
|
|
|
throw new BusinessException("委外订单详情记录为空!"); |
|
|
|
FinancialAccountsPayable temp = new FinancialAccountsPayable(); |
|
|
|
temp.setRelevanceCode(outsourceOrderCode); |
|
|
|
List<FinancialAccountsPayable> payableList = accountsPayableMapper.selectFinancialAccountsPayableList(temp); |
|
|
|
if(CollectionUtils.isEmpty(payableList)){ |
|
|
|
throw new BusinessException("未找到应付账款记录!"); |
|
|
|
} |
|
|
|
String isAllPaid = "3"; |
|
|
|
// 获取所有 paymentStatus 的集合
|
|
|
|
Set<String> statuses = outsourceOrderDetails.stream() |
|
|
|
.map(OutsourceOrderDetail::getRemitStatus) |
|
|
|
.collect(Collectors.toSet()); |
|
|
|
|
|
|
|
// 判断状态
|
|
|
|
if (statuses.size() == 1) { |
|
|
|
String singleStatus = statuses.iterator().next(); |
|
|
|
if (singleStatus.equals("0")) { |
|
|
|
isAllPaid = "0"; |
|
|
|
} else if (singleStatus.equals("2")) { |
|
|
|
isAllPaid = "1"; |
|
|
|
boolean allClosed = true; |
|
|
|
//根据应付账款打款信息更新订单状态
|
|
|
|
for (FinancialAccountsPayable payable: payableList) { |
|
|
|
if(!payable.getAccountsPayableStatus().equals("2")){ |
|
|
|
allClosed = false; |
|
|
|
} |
|
|
|
} else if (statuses.size() == 2 && statuses.contains("0") && statuses.contains("2")) { |
|
|
|
isAllPaid = "2"; |
|
|
|
} |
|
|
|
if(isAllPaid.equals("1")){ |
|
|
|
// 订单内供应商全部打款
|
|
|
|
outsourceOrder.setClosedStatus("2"); |
|
|
|
}else if(isAllPaid.equals("0")){ |
|
|
|
// 订单内供应商全未打款
|
|
|
|
outsourceOrder.setClosedStatus("0"); |
|
|
|
}else if(isAllPaid.equals("2")){ |
|
|
|
outsourceOrder.setClosedStatus("1"); |
|
|
|
if(allClosed){ |
|
|
|
outsourceOrder.setClosedStatus("4");//已结案
|
|
|
|
}else{ |
|
|
|
outsourceOrder.setClosedStatus("1");//部分打款
|
|
|
|
} |
|
|
|
OutsourceOrderVO outsourceOrderVO = new OutsourceOrderVO(); |
|
|
|
outsourceOrderVO.setOutsourceOrderId(outsourceOrder.getOutsourceOrderId()); |
|
|
@ -248,35 +242,38 @@ public class BaseExpenseConfirmAmountServiceImpl implements IBaseExpenseConfirmA |
|
|
|
return outsourceOrderMapper.updateOutsourceOrder(outsourceOrderVO); |
|
|
|
} |
|
|
|
// 更新应付账款记录付款相关信息
|
|
|
|
public int updateFinancialPayableInfo(String relatedCode, String supplierCode, BaseExpenseConfirmAmount baseExpenseConfirmAmount){ |
|
|
|
public FinancialAccountsPayable updateFinancialPayableInfo(String relatedCode,BaseExpenseAccountChild child, String supplierCode, BaseExpenseConfirmAmount baseExpenseConfirmAmount){ |
|
|
|
FinancialAccountsPayable temp = new FinancialAccountsPayable(); |
|
|
|
temp.setRelevanceCode(relatedCode); |
|
|
|
temp.setSupplierCode(supplierCode); |
|
|
|
List<FinancialAccountsPayable> payableList = accountsPayableMapper.selectFinancialAccountsPayableList(temp); |
|
|
|
if(CollectionUtils.isEmpty(payableList)){ |
|
|
|
FinancialAccountsPayable accountsPayable = accountsPayableMapper.selectFinancialAccountsPayableByCode(temp); |
|
|
|
if(accountsPayable == null){ |
|
|
|
throw new BusinessException("未找到应付账款记录!"); |
|
|
|
} |
|
|
|
FinancialAccountsPayable accountsPayable = payableList.get(0); |
|
|
|
BigDecimal paidPrice = baseExpenseConfirmAmount.getAmount(); |
|
|
|
BigDecimal paidPrice = child.getAmounts(); |
|
|
|
int insertResult = insertFinancialPayableRecord(accountsPayable.getAccountsPayableCode(),relatedCode,baseExpenseConfirmAmount); |
|
|
|
if(insertResult <= 0){ |
|
|
|
throw new BusinessException("插入应付账款付款记录失败!"); |
|
|
|
} |
|
|
|
accountsPayable.setPaidPrice(paidPrice); |
|
|
|
accountsPayable.setActualPaidPrice(paidPrice); |
|
|
|
/*更新实付金额*/ |
|
|
|
BigDecimal actualPaidPrice = Optional.ofNullable(accountsPayable.getActualPaidPrice()).orElse(BigDecimal.ZERO); |
|
|
|
actualPaidPrice = actualPaidPrice.add(paidPrice); |
|
|
|
accountsPayable.setPaidPrice(actualPaidPrice); |
|
|
|
accountsPayable.setActualPaidPrice(actualPaidPrice); |
|
|
|
/*更新未付金额*/ |
|
|
|
BigDecimal shoudPay = accountsPayable.getPriceIncludesTax(); |
|
|
|
accountsPayable.setUnpaidPrice(shoudPay.subtract(paidPrice)); |
|
|
|
if(paidPrice.compareTo(shoudPay) == 0 ){ |
|
|
|
/*更新付款结案状态*/ |
|
|
|
if(actualPaidPrice.compareTo(shoudPay) >= 0 ){ |
|
|
|
accountsPayable.setAccountsPayableStatus("2");//已结案
|
|
|
|
}else if(paidPrice.compareTo(shoudPay) < 0){ |
|
|
|
}else if(actualPaidPrice.compareTo(shoudPay) < 0){ |
|
|
|
accountsPayable.setAccountsPayableStatus("1");//部分打款(需要手动结案)
|
|
|
|
} |
|
|
|
accountsPayable.setPaidTime(baseExpenseConfirmAmount.getExpenseDate()); |
|
|
|
accountsPayable.setOperatorPeople(ShiroUtils.getLoginName()); |
|
|
|
accountsPayable.setUpdateBy(ShiroUtils.getLoginName()); |
|
|
|
accountsPayable.setUpdateTime(DateUtils.getNowDate()); |
|
|
|
int rows = accountsPayableMapper.updateFinancialAccountsPayable(accountsPayable); |
|
|
|
return rows; |
|
|
|
return accountsPayable; |
|
|
|
} |
|
|
|
// 新建应付账款付款记录
|
|
|
|
public int insertFinancialPayableRecord(String accountsPayableCode, String relatedCode, BaseExpenseConfirmAmount baseExpenseConfirmAmount){ |
|
|
@ -285,7 +282,7 @@ public class BaseExpenseConfirmAmountServiceImpl implements IBaseExpenseConfirmA |
|
|
|
payableRecords.setRelevanceCode(relatedCode); |
|
|
|
payableRecords.setPaidPrice(baseExpenseConfirmAmount.getAmount()); |
|
|
|
payableRecords.setPaidTime(baseExpenseConfirmAmount.getExpenseDate()); |
|
|
|
payableRecords.setOperatorPeople(baseExpenseConfirmAmount.getFullName()); |
|
|
|
payableRecords.setOperatorPeople(ShiroUtils.getLoginName()); |
|
|
|
payableRecords.setCreateBy(ShiroUtils.getLoginName()); |
|
|
|
payableRecords.setCreateTime(DateUtils.getNowDate()); |
|
|
|
int rows = payableRecordsMapper.insertFinancialPayableRecords(payableRecords); |
|
|
|