| | |
| | | import com.ruoyi.sales.mapper.InvoiceLedgerMapper; |
| | | import com.ruoyi.sales.mapper.ReceiptPaymentMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.InvoiceLedger; |
| | | import com.ruoyi.sales.pojo.ReceiptPayment; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.sales.service.ReceiptPaymentService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private SalesLedgerMapper salesLedgerMapper; |
| | | |
| | | @Autowired |
| | | private SalesLedgerProductMapper salesLedgerProductMapper; |
| | | @Autowired |
| | | private InvoiceLedgerMapper invoiceLedgerMapper; |
| | | |
| | | /** |
| | | * 回款登记新增 |
| | | * @param receiptPayment |
| | | * @param receiptPaymentList |
| | | * @return |
| | | */ |
| | | @Override |
| | | public int receiptPaymentSaveOrUpdate(ReceiptPayment receiptPayment) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int receiptPaymentSaveOrUpdate(List<ReceiptPayment> receiptPaymentList) { |
| | | for (ReceiptPayment receiptPayment : receiptPaymentList) { |
| | | ReceiptPayment byId = receiptPayment; |
| | | if (!ObjectUtils.isEmpty(receiptPayment.getId())){ |
| | | byId = this.getById(receiptPayment.getId()); |
| | | receiptPayment = this.getById(receiptPayment.getId()); |
| | | } |
| | | InvoiceLedger invoiceLedger = invoiceLedgerMapper.selectById(byId.getInvoiceLedgerId()); |
| | | Page<ReceiptPaymentDto> objectPage = new Page<>(); |
| | | ReceiptPaymentDto receiptPaymentDto = new ReceiptPaymentDto(); |
| | | receiptPaymentDto.setInvoiceLedgerId(invoiceLedger.getId()); |
| | | IPage<ReceiptPaymentDto> receiptPaymentDtoIPage = receiptPaymentMapper.bindInvoiceNoRegPage(objectPage, receiptPaymentDto); |
| | | ReceiptPaymentDto receiptPaymentDto1 = receiptPaymentDtoIPage.getRecords().get(0); |
| | | if (!ObjectUtils.isEmpty(byId.getId())){ |
| | | receiptPaymentDto1.setNoReceiptAmount(receiptPaymentDto1.getNoReceiptAmount().add(byId.getReceiptPaymentAmount())); |
| | | } |
| | | if (receiptPaymentDto1.getNoReceiptAmount().compareTo(receiptPayment.getReceiptPaymentAmount())<0){ |
| | | // InvoiceLedger invoiceLedger = invoiceLedgerMapper.selectById(byId.getInvoiceLedgerId()); |
| | | SalesLedger salesLedger = salesLedgerMapper.selectById(receiptPayment.getSalesLedgerId()); |
| | | if(null==salesLedger) throw new RuntimeException("未找到销售单"); |
| | | // 已回款金额 |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(receiptPayment.getSalesLedgerProductId()); |
| | | if(null==salesLedgerProduct) throw new RuntimeException("未找到销售单产品"); |
| | | if (salesLedgerProduct.getPendingInvoiceTotal().compareTo(receiptPayment.getReceiptPaymentAmount())<0){ |
| | | throw new RuntimeException("本次回款金额不能大于待回款金额"); |
| | | } |
| | | if(null==receiptPayment.getId()){ |
| | | |
| | | return receiptPaymentMapper.insert(receiptPayment); |
| | | salesLedgerProduct.setInvoiceTotal(salesLedgerProduct.getInvoiceTotal().add(receiptPayment.getReceiptPaymentAmount())); |
| | | salesLedgerProduct.setPendingInvoiceTotal(salesLedgerProduct.getTaxInclusiveTotalPrice().subtract(salesLedgerProduct.getInvoiceTotal())); |
| | | receiptPaymentMapper.insert(receiptPayment); |
| | | }else { |
| | | |
| | | return receiptPaymentMapper.updateById(receiptPayment); |
| | | BigDecimal subtract = receiptPayment.getReceiptPaymentAmount().subtract(byId.getReceiptPaymentAmount()); |
| | | salesLedgerProduct.setInvoiceTotal(salesLedgerProduct.getInvoiceTotal().add(subtract)); |
| | | salesLedgerProduct.setPendingInvoiceTotal(salesLedgerProduct.getTaxInclusiveTotalPrice().subtract(salesLedgerProduct.getInvoiceTotal())); |
| | | receiptPaymentMapper.updateById(receiptPayment); |
| | | } |
| | | salesLedgerProductMapper.updateById(salesLedgerProduct); |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | /** |