| | |
| | | package com.ruoyi.account.service.impl.sales; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.sales.dto.SaveReceiptPaymentDto; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Random; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | private final AccountSalesCollectionMapper accountSalesCollectionMapper; |
| | | private final AccountStatementDetailsMapper accountStatementDetailsMapper; |
| | | private final SalesLedgerMapper salesLedgerMapper; |
| | | private static final DateTimeFormatter CODE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyMMddHHmmss"); |
| | | |
| | | |
| | |
| | | return accountSalesCollectionMapper.getOutboundBatchesByCustomer(customerId); |
| | | } |
| | | |
| | | @Override |
| | | public boolean saveReceiptPayment(SaveReceiptPaymentDto dto) { |
| | | if (dto.getPaymentDate() == null) { |
| | | throw new ServiceException("请选择回款日期"); |
| | | } |
| | | if (dto.getPaymentAmount() == null || dto.getPaymentAmount().compareTo(BigDecimal.valueOf(0.01)) < 0) { |
| | | throw new ServiceException("请输入回款金额"); |
| | | } |
| | | if (StringUtils.isEmpty(dto.getSalesContractNo())) { |
| | | throw new ServiceException("销售合同号不能为空"); |
| | | } |
| | | if (dto.getCustomerId() == null) { |
| | | throw new ServiceException("客户不能为空"); |
| | | } |
| | | |
| | | SalesLedger salesLedger = salesLedgerMapper.selectOne(new LambdaQueryWrapper<SalesLedger>() |
| | | .eq(SalesLedger::getSalesContractNo, dto.getSalesContractNo())); |
| | | if (salesLedger == null) { |
| | | throw new ServiceException("销售合同不存在"); |
| | | } |
| | | if (salesLedger.getCustomerId() == null || salesLedger.getCustomerId().longValue() != dto.getCustomerId().longValue()) { |
| | | throw new ServiceException("客户与合同不匹配"); |
| | | } |
| | | |
| | | List<Long> stockOutRecordIds = accountSalesCollectionMapper.selectStockOutRecordIdsBySalesLedgerId(salesLedger.getId()); |
| | | if (CollectionUtils.isEmpty(stockOutRecordIds)) { |
| | | throw new ServiceException("该合同暂无可回款的销售出库记录"); |
| | | } |
| | | |
| | | AccountSalesCollection collection = new AccountSalesCollection(); |
| | | collection.setCustomerId(dto.getCustomerId().intValue()); |
| | | collection.setStockOutRecordIds(stockOutRecordIds.stream().map(String::valueOf).collect(Collectors.joining(","))); |
| | | collection.setCollectionDate(dto.getPaymentDate()); |
| | | collection.setCollectionAmount(dto.getPaymentAmount()); |
| | | collection.setCollectionMethod(dto.getPaymentMethod()); |
| | | collection.setCollectionNumber(genAccountSalesCollectionNo()); |
| | | collection.setRemark(dto.getRemark()); |
| | | return save(collection); |
| | | } |
| | | |
| | | private String genAccountSalesCollectionNo() { |
| | | return "SK" + LocalDateTime.now().format(CODE_TIME_FORMATTER) + new Random().nextInt(10); |
| | | } |