调整收付款问题

This commit is contained in:
2026-08-31 16:11:34 +08:00
parent 35309b32ae
commit d1ef6eb97b
3 changed files with 23 additions and 12 deletions
@@ -82,9 +82,11 @@ public class InvoiceApplicationController extends BladeController {
@Operation(summary = "可开票正式结算单")
public R<IPage<Map<String, Object>>> settlementCandidates(Query query,
@RequestParam(required = false) String keyword,
@RequestParam(required = false) String contractCategory) {
@RequestParam(required = false) String contractCategory,
@RequestParam(defaultValue = "receivable") String settlementType,
@RequestParam(defaultValue = "unreceived") String invoiceStatus) {
return R.data(invoiceApplicationService.settlementCandidates(
Condition.getPage(query), keyword, contractCategory));
Condition.getPage(query), keyword, contractCategory, settlementType, invoiceStatus));
}
@GetMapping("/settlement-details")
@@ -44,7 +44,8 @@ import java.util.Map;
public interface IInvoiceApplicationService extends BaseService<InvoiceApplication> {
IPage<InvoiceApplicationVO> selectPage(IPage<InvoiceApplication> page, InvoiceApplicationVO query);
InvoiceApplicationVO detail(Long id);
IPage<Map<String, Object>> settlementCandidates(IPage<?> page, String keyword, String contractCategory);
IPage<Map<String, Object>> settlementCandidates(IPage<?> page, String keyword, String contractCategory,
String settlementType, String invoiceStatus);
List<FormalSettlementDetail> settlementDetails(String settlementIds);
Map<String, Object> receiverInformation(String settlementIds);
Long saveDraft(InvoiceApplicationSaveRequest request);
@@ -147,7 +147,9 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
@Override
public IPage<Map<String, Object>> settlementCandidates(IPage<?> page, String keyword,
String contractCategory) {
String contractCategory, String settlementType, String invoiceStatus) {
String candidateSettlementType = Func.isEmpty(settlementType) ? "receivable" : settlementType;
String candidateInvoiceStatus = Func.isEmpty(invoiceStatus) ? "unreceived" : invoiceStatus;
List<Long> contractIds = Func.isEmpty(contractCategory) ? List.of()
: contractManageMapper.selectList(Wrappers.<ContractManage>lambdaQuery()
.select(ContractManage::getId)
@@ -158,7 +160,8 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
return new Page<>(page.getCurrent(), page.getSize(), 0);
}
List<FormalSettlement> settlements = formalSettlementMapper.selectList(Wrappers.<FormalSettlement>lambdaQuery()
.eq(FormalSettlement::getSettlementType, "payable")
.eq(FormalSettlement::getSettlementType, candidateSettlementType)
.eq(FormalSettlement::getInvoiceStatus, candidateInvoiceStatus)
.eq(FormalSettlement::getApprovalStatus, APPROVED)
.eq(FormalSettlement::getStatus, 1)
.in(Func.isNotEmpty(contractCategory), FormalSettlement::getContractId, contractIds)
@@ -243,13 +246,15 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
List<FormalSettlement> settlements = distinctIds(settlementIds).stream().map(this::availableSettlement).toList();
assertCompatible(settlements);
FormalSettlement first = settlements.get(0);
CustomerArchive customer = findCustomer(first.getPayeeName());
String customerName = "receivable".equals(first.getSettlementType())
? first.getPayerName() : first.getPayeeName();
CustomerArchive customer = findCustomer(customerName);
List<CustomerInvoiceInfo> invoiceInfos = customer == null ? List.of() : activeInvoiceInfos(customer.getId());
Map<String, Object> result = new LinkedHashMap<>();
result.put("issuerName", first.getPayeeName());
result.put("receiverName", first.getPayerName());
result.put("customer", customer);
// 应结算单的票方(payeeName)是客商,受票方信息和部门邮箱均来源于该客商发票信息
// 应结算单的票方(payerName)是客商;历史应付申请仍按开票方(payeeName)读取客商资料
result.put("invoices", invoiceInfos);
result.put("invoiceInfos", invoiceInfos);
result.put("departmentEmails", invoiceInfoEmails(invoiceInfos));
@@ -274,6 +279,10 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
.collect(Collectors.toMap(InvoiceApplicationSaveRequest.SettlementRow::getSettlementId,
Function.identity(), (first, duplicate) -> first, LinkedHashMap::new)).values().stream().toList();
List<FormalSettlement> settlements = requestedRows.stream().map(row -> availableSettlement(row.getSettlementId())).toList();
if (settlements.stream().anyMatch(settlement -> !"receivable".equals(settlement.getSettlementType())
|| (creating && !"unreceived".equals(settlement.getInvoiceStatus())))) {
throw new ServiceException("只能选择审批通过、未作废、未收票的应收正式结算单");
}
assertCompatible(settlements);
FormalSettlement first = settlements.get(0);
Map<Long, FormalSettlement> settlementMap = settlements.stream()
@@ -292,8 +301,8 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
if (lineTotal.compareTo(BigDecimal.ZERO) <= 0) {
throw new ServiceException("本次开票金额必须大于0");
}
CustomerArchive customer = findCustomer(first.getPayeeName());
if (customer == null) throw new ServiceException("未找到正式结算单票方对应的客商档案");
CustomerArchive customer = findCustomer(first.getPayerName());
if (customer == null) throw new ServiceException("未找到正式结算单票方对应的客商档案");
List<CustomerInvoiceInfo> invoiceInfos = activeInvoiceInfos(customer.getId());
CustomerInvoiceInfo invoiceInfo = invoiceInfos.stream()
.filter(item -> Objects.equals(item.getId(), request.getReceiverInvoiceInfoId()))
@@ -475,9 +484,8 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
if (id == null) throw new ServiceException("正式结算单不能为空");
FormalSettlement settlement = formalSettlementMapper.selectById(id);
if (settlement == null || Objects.equals(settlement.getIsDeleted(), 1)) throw new ServiceException("正式结算单不存在");
if (!Objects.equals(settlement.getStatus(), 1) || !APPROVED.equals(settlement.getApprovalStatus())
|| !"payable".equals(settlement.getSettlementType())) {
throw new ServiceException("只能选择审批通过、未作废的应付正式结算单");
if (!Objects.equals(settlement.getStatus(), 1) || !APPROVED.equals(settlement.getApprovalStatus())) {
throw new ServiceException("只能选择审批通过、未作废的正式结算单");
}
return settlement;
}