| | |
| | | PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(paymentRegistration.getPurchaseLedgerId()); |
| | | SalesLedger salesLedger = salesLedgerMapper.selectOne(new QueryWrapper<SalesLedger>(). |
| | | eq("sales_contract_no", purchaseLedger.getSalesContractNo())); |
| | | if (salesLedger == null) { |
| | | throw new RuntimeException("关联销售合同号不存在"); |
| | | // if (salesLedger == null) { |
| | | // throw new RuntimeException("关联销售合同号不存在"); |
| | | // } |
| | | if (salesLedger != null) { |
| | | paymentRegistration.setSaleLedgerId(salesLedger.getId()); |
| | | } |
| | | |
| | | paymentRegistration.setSaleLedgerId(salesLedger.getId()); |
| | | paymentRegistration.setSupplierId(purchaseLedger.getSupplierId()); |
| | | |
| | | TicketRegistration tr = ticketRegistrationMapper.selectOne(new LambdaQueryWrapper<TicketRegistration>().eq(TicketRegistration::getId, paymentRegistration.getTicketRegistrationId())); |
| | |
| | | } |
| | | |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | Integer tenantId = loginUser.getTenantId(); |
| | | paymentRegistration.setTenantId(tenantId.longValue()); |
| | | Long tenantId = loginUser.getTenantId(); |
| | | paymentRegistration.setTenantId(tenantId); |
| | | paymentRegistration.setRegistrantId(loginUser.getUserId()); |
| | | paymentRegistration.setCreateTime(DateUtils.getNowDate()); |
| | | paymentRegistration.setUpdateTime(DateUtils.getNowDate()); |
| | |
| | | */ |
| | | @Override |
| | | public int updatePaymentRegistration(PaymentRegistration paymentRegistration) { |
| | | TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId()); |
| | | PaymentRegistration paymentRegistration1 = paymentRegistrationMapper.selectById(paymentRegistration.getId()); |
| | | |
| | | TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId()==null?paymentRegistration1.getTicketRegistrationId():paymentRegistration.getTicketRegistrationId()); |
| | | |
| | | List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper.selectList(new QueryWrapper<PaymentRegistration>() |
| | | .eq("ticket_registration_id", paymentRegistration.getTicketRegistrationId()).ne("id", paymentRegistration.getId())); |
| | |
| | | new QueryWrapper<SalesLedgerProduct>().eq("sales_ledger_id", id).eq("type",2) |
| | | ).stream()) |
| | | .collect(Collectors.toList()); |
| | | payableAmount = salesLedgerProducts.stream() |
| | | .map(SalesLedgerProduct::getTaxInclusiveTotalPrice) |
| | | .filter(Objects::nonNull) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | // payableAmount = salesLedgerProducts.stream() |
| | | // .map(SalesLedgerProduct::getTaxInclusiveTotalPrice) |
| | | // .filter(Objects::nonNull) |
| | | // .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | // 来票金额计算 |
| | | List<TicketRegistration> ticketRegistrations = purchaseLedgers.stream() |
| | |
| | | .map(PaymentRegistration::getCurrentPaymentAmount) |
| | | .filter(Objects::nonNull) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | |
| | | // 核心过滤逻辑:当paymentAmount和invoiceAmount同时为0时,跳过该记录 |
| | | if (BigDecimal.ZERO.compareTo(paymentAmount) == 0 && BigDecimal.ZERO.compareTo(invoiceAmount) == 0) { |
| | | continue; // 跳过当前供应商,不加入结果集 |
| | | } |
| | | |
| | | // 详情分页处理 |
| | | detailPageNum = detailPageNum != null ? detailPageNum : 1; |
| | |
| | | detailPagination.put("pageSize", detailPageSize); |
| | | detailPagination.put("pages", (int) Math.ceil((double) totalDetails / detailPageSize)); |
| | | |
| | | // 应付金额逻辑不采用合同金额改成 发票金额减付款金额 |
| | | payableAmount = invoiceAmount.subtract(paymentAmount); |
| | | res.put("invoiceAmount", invoiceAmount); |
| | | res.put("payableAmount", payableAmount); |
| | | res.put("paymentAmount", paymentAmount); |
| | |
| | | result.add(res); |
| | | } |
| | | |
| | | // 修正总条数:过滤后需要重新计算总条数 |
| | | resultPage.setTotal(result.size()); |
| | | resultPage.setRecords(result); |
| | | return resultPage; |
| | | } |
| | |
| | | public List<PaymentHistoryRecordVo> getPaymentRecordList(Long supplierId) { |
| | | List<PaymentHistoryRecordVo> paymentRecordList = paymentRegistrationMapper.getPaymentRecordList(supplierId); |
| | | List<PaymentHistoryRecordVo> result = new ArrayList<>(); |
| | | List<PaymentHistoryRecordVo> newResult = new ArrayList<>(); |
| | | // 应付总金额金额计算 |
| | | BigDecimal amountTotal = BigDecimal.ZERO; |
| | | if(CollectionUtils.isNotEmpty(paymentRecordList)) { |
| | |
| | | Collectors.toList() |
| | | ) |
| | | ); |
| | | BigDecimal amountDateTotal = BigDecimal.ZERO; |
| | | for (LocalDate localDate : dateListMap.keySet()) { |
| | | BigDecimal currentPaymentAmount = BigDecimal.ZERO; |
| | | BigDecimal invoiceAmount = BigDecimal.ZERO; |
| | |
| | | paymentHistoryRecordVo.setHappenTime(localDate); |
| | | paymentHistoryRecordVo.setCurrentPaymentAmount(currentPaymentAmount); |
| | | paymentHistoryRecordVo.setInvoiceAmount(invoiceAmount); |
| | | amountTotal = amountTotal.add(currentDateTotal); |
| | | amountTotal = paymentHistoryRecordVo.getInvoiceAmount().subtract(paymentHistoryRecordVo.getCurrentPaymentAmount()); |
| | | paymentHistoryRecordVo.setPayableAmount(amountTotal); |
| | | result.add(paymentHistoryRecordVo); |
| | | } |
| | | |
| | | |
| | | for (int i = 0; i < result.size(); i++) { |
| | | PaymentHistoryRecordVo paymentHistoryRecordVo = result.get(i); |
| | | if (i == 0) { |
| | | paymentHistoryRecordVo.setPayableAmount(paymentHistoryRecordVo.getInvoiceAmount().subtract(paymentHistoryRecordVo.getCurrentPaymentAmount())); |
| | | }else { |
| | | PaymentHistoryRecordVo paymentHistoryRecordVo1 = result.get(i-1); |
| | | paymentHistoryRecordVo.setPayableAmount(paymentHistoryRecordVo1.getPayableAmount() |
| | | .add(paymentHistoryRecordVo.getInvoiceAmount()).subtract(paymentHistoryRecordVo.getCurrentPaymentAmount())); |
| | | } |
| | | newResult.add(paymentHistoryRecordVo); |
| | | } |
| | | } |
| | | return result; |
| | | return newResult; |
| | | } |
| | | |
| | | /** |
| | |
| | | return paymentRegistrationMapper.paymentHistoryListPage(page, paymentRegistrationDto); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean delete(Long[] ids) { |
| | | for (Long id : ids) { |
| | | List<ProductRecord> productRecords = productRecordMapper.selectList(new QueryWrapper<ProductRecord>().lambda().eq(ProductRecord::getTicketRegistrationId, id)); |
| | | for (ProductRecord productRecord : productRecords) { |
| | | SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(productRecord.getSaleLedgerProjectId()); |
| | | salesLedgerProduct.setTicketsNum(salesLedgerProduct.getTicketsNum().subtract(productRecord.getTicketsNum())); |
| | | salesLedgerProduct.setTicketsAmount(salesLedgerProduct.getTicketsAmount().subtract(productRecord.getTicketsAmount())); |
| | | salesLedgerProduct.setFutureTickets(salesLedgerProduct.getFutureTickets().add(productRecord.getTicketsNum())); |
| | | salesLedgerProduct.setFutureTicketsAmount(salesLedgerProduct.getFutureTicketsAmount().add(productRecord.getTicketsAmount())); |
| | | salesLedgerProductMapper.updateById(salesLedgerProduct); |
| | | } |
| | | ticketRegistrationMapper.delete(new QueryWrapper<TicketRegistration>().lambda().eq(TicketRegistration::getId, id)); |
| | | productRecordMapper.delete(new QueryWrapper<ProductRecord>().lambda().eq(ProductRecord::getTicketRegistrationId, id)); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public int delPaymentRegistration(Long id) { |
| | | // PaymentRegistration paymentRegistration = paymentRegistrationMapper.selectById(id); |
| | | // TicketRegistration ticketRegistration = ticketRegistrationMapper.selectById(paymentRegistration.getTicketRegistrationId()); |
| | | // if (ticketRegistration != null) { |
| | | // ticketRegistration.setPaymentAmountTotal(ticketRegistration.getPaymentAmountTotal().subtract(paymentRegistration.getCurrentPaymentAmount())); |
| | | // ticketRegistration.setUnPaymentAmountTotal(ticketRegistration.getUnPaymentAmountTotal().add(paymentRegistration.getCurrentPaymentAmount())); |
| | | // ticketRegistrationMapper.updateById(ticketRegistration); |
| | | // } |
| | | |
| | | return paymentRegistrationMapper.deleteById(id); |
| | | } |
| | | |
| | | // 批量查询采购台账(当月) |
| | | private Map<Long, List<PurchaseLedger>> batchQueryPurchaseLedgers(List<Long> supplierIds, LocalDate startDate, LocalDate endDate) { |
| | | LambdaQueryWrapper<PurchaseLedger> query = new LambdaQueryWrapper<>(); |