| | |
| | | package com.ruoyi.account.service.impl.purchase; |
| | | |
| | | 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.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.github.xiaoymin.knife4j.core.util.CollectionUtils; |
| | | import com.ruoyi.account.bean.dto.purchase.AccountPurchasePaymentDto; |
| | | import com.ruoyi.account.bean.vo.purchase.AccountPurchasePaymentVo; |
| | | import com.ruoyi.account.mapper.AccountStatementDetailsMapper; |
| | | import com.ruoyi.account.mapper.purchase.AccountPaymentApplicationMapper; |
| | | import com.ruoyi.account.mapper.purchase.AccountPurchasePaymentMapper; |
| | | import com.ruoyi.account.pojo.AccountStatementDetails; |
| | | import com.ruoyi.account.pojo.purchase.AccountPaymentApplication; |
| | | import com.ruoyi.account.pojo.purchase.AccountPurchasePayment; |
| | | import com.ruoyi.account.service.purchase.AccountPurchasePaymentService; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.purchase.dto.SavePaymentDto; |
| | | import com.ruoyi.purchase.mapper.PurchaseLedgerMapper; |
| | | import com.ruoyi.purchase.pojo.PurchaseLedger; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | | import java.util.Random; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private static final DateTimeFormatter CODE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyMMddHHmmss"); |
| | | private final AccountPurchasePaymentMapper accountPurchasePaymentMapper; |
| | | private final AccountStatementDetailsMapper accountStatementDetailsMapper; |
| | | private final AccountPaymentApplicationMapper accountPaymentApplicationMapper; |
| | | private final PurchaseLedgerMapper purchaseLedgerMapper; |
| | | |
| | | @Override |
| | | public IPage<AccountPurchasePaymentVo> listPageAccountPurchasePayment(Page page, AccountPurchasePaymentDto accountPurchasePaymentDto) { |
| | |
| | | public boolean addAccountPurchasePayment(AccountPurchasePayment accountPurchasePayment) { |
| | | if (StringUtils.isEmpty(accountPurchasePayment.getPaymentNumber())) { |
| | | accountPurchasePayment.setPaymentNumber(genAccountPurchasePaymentNo()); |
| | | } |
| | | //校验累计付款金额不能超过申请金额 |
| | | AccountPaymentApplication accountPaymentApplication = accountPaymentApplicationMapper.selectById(accountPurchasePayment.getAccountPaymentApplicationId()); |
| | | List<AccountPurchasePayment> accountPurchasePayments = accountPurchasePaymentMapper.selectList(Wrappers.<AccountPurchasePayment>lambdaQuery().eq(AccountPurchasePayment::getAccountPaymentApplicationId, accountPurchasePayment.getAccountPaymentApplicationId())); |
| | | BigDecimal totalPaymentAmount = accountPurchasePayments.stream().map(AccountPurchasePayment::getPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | if (accountPaymentApplication.getPaymentAmount().compareTo(totalPaymentAmount) < 0) { |
| | | throw new ServiceException("累计付款金额不能超过申请金额"); |
| | | } |
| | | return save(accountPurchasePayment); |
| | | } |
| | |
| | | return removeByIds(ids); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean savePayment(SavePaymentDto 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.getPurchaseContractNumber())) { |
| | | throw new ServiceException("采购合同号不能为空"); |
| | | } |
| | | if (dto.getSupplierId() == null) { |
| | | throw new ServiceException("供应商不能为空"); |
| | | } |
| | | |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectOne(new LambdaQueryWrapper<PurchaseLedger>() |
| | | .eq(PurchaseLedger::getPurchaseContractNumber, dto.getPurchaseContractNumber())); |
| | | if (purchaseLedger == null) { |
| | | throw new ServiceException("采购合同不存在"); |
| | | } |
| | | if (purchaseLedger.getSupplierId() == null || purchaseLedger.getSupplierId().longValue() != dto.getSupplierId().longValue()) { |
| | | throw new ServiceException("供应商与合同不匹配"); |
| | | } |
| | | |
| | | List<Long> stockInRecordIds = accountPurchasePaymentMapper.selectStockInRecordIdsByPurchaseLedgerId(purchaseLedger.getId()); |
| | | if (CollectionUtils.isEmpty(stockInRecordIds)) { |
| | | throw new ServiceException("该合同暂无可付款的采购入库记录"); |
| | | } |
| | | |
| | | AccountPaymentApplication application = new AccountPaymentApplication(); |
| | | application.setSupplierId(dto.getSupplierId().intValue()); |
| | | application.setStockInRecordIds(stockInRecordIds.stream().map(String::valueOf).collect(Collectors.joining(","))); |
| | | application.setInvoiceApplicationNo(genPaymentApplicationNo()); |
| | | application.setPaymentMethod(dto.getPaymentMethod()); |
| | | application.setPaymentContent(dto.getPurchaseContractNumber()); |
| | | application.setApplyDate(dto.getPaymentDate()); |
| | | application.setRemark(dto.getRemark()); |
| | | application.setStatus(1); |
| | | application.setPaymentAmount(dto.getPaymentAmount()); |
| | | accountPaymentApplicationMapper.insert(application); |
| | | |
| | | AccountPurchasePayment payment = new AccountPurchasePayment(); |
| | | payment.setAccountPaymentApplicationId(application.getId()); |
| | | payment.setSupplierId(dto.getSupplierId().intValue()); |
| | | payment.setPaymentDate(dto.getPaymentDate()); |
| | | payment.setPaymentMethod(dto.getPaymentMethod()); |
| | | payment.setPaymentAmount(dto.getPaymentAmount()); |
| | | payment.setPaymentNumber(genAccountPurchasePaymentNo()); |
| | | payment.setRemark(dto.getRemark()); |
| | | return save(payment); |
| | | } |
| | | |
| | | private String genPaymentApplicationNo() { |
| | | return "FK" + LocalDateTime.now().format(CODE_TIME_FORMATTER) + new Random().nextInt(10); |
| | | } |
| | | |
| | | private String genAccountPurchasePaymentNo() { |
| | | return "SK" + LocalDateTime.now().format(CODE_TIME_FORMATTER) + new Random().nextInt(10); |
| | | } |