| | |
| | | package com.ruoyi.sales.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.basic.pojo.Customer; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log; |
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType; |
| | |
| | | import com.ruoyi.framework.web.page.TableDataInfo; |
| | | import com.ruoyi.sales.dto.*; |
| | | import com.ruoyi.sales.mapper.InvoiceLedgerMapper; |
| | | import com.ruoyi.sales.mapper.ReceiptPaymentMapper; |
| | | import com.ruoyi.sales.pojo.ReceiptPayment; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProcessRoute; |
| | | import com.ruoyi.sales.service.ICommonFileService; |
| | |
| | | @Autowired |
| | | private InvoiceLedgerMapper invoiceLedgerMapper; |
| | | |
| | | @Autowired |
| | | private ReceiptPaymentMapper receiptPaymentMapper; |
| | | |
| | | /** |
| | | * 导入销售台账 |
| | | */ |
| | |
| | | public AjaxResult importData(@RequestParam("file") |
| | | @ApiParam(value = "Excel文件", required = true) |
| | | MultipartFile file) { |
| | | return salesLedgerService.importData(file); |
| | | salesLedgerService.importData(file); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @ApiOperation("导出销售台账模板") |
| | |
| | | * 查询销售台账列表 |
| | | */ |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(Page page, SalesLedgerDto salesLedgerDto) { |
| | | public TableDataInfo list(Page<?> page, SalesLedgerDto salesLedgerDto) { |
| | | startPage(); |
| | | List<SalesLedger> list = salesLedgerService.selectSalesLedgerList(salesLedgerDto); |
| | | // 计算已开票金额/未开票金额(已填写发票金额为准) |
| | |
| | | @Log(title = "销售台账", businessType = BusinessType.EXPORT) |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SalesLedgerDto salesLedgerDto) { |
| | | Page page = new Page(-1, -1); |
| | | Page<?> page = new Page<>(-1, -1); |
| | | IPage<SalesLedger> salesLedgerIPage = listPage(page, salesLedgerDto); |
| | | ExcelUtil<SalesLedger> util = new ExcelUtil<SalesLedger>(SalesLedger.class); |
| | | if (salesLedgerIPage == null) { |
| | |
| | | @Log(title = "导出开票登记列表", businessType = BusinessType.EXPORT) |
| | | @PostMapping("/exportOne") |
| | | public void exportOne(HttpServletResponse response, SalesLedgerDto salesLedgerDto) { |
| | | Page page = new Page(); |
| | | Page<?> page = new Page<>(); |
| | | page.setCurrent(-1); |
| | | page.setSize(-1); |
| | | IPage<SalesLedger> salesLedgerIPage = listPage(page, salesLedgerDto); |
| | |
| | | * 查询销售台账列表 |
| | | */ |
| | | @GetMapping("/listPage") |
| | | public IPage<SalesLedger> listPage(Page page, SalesLedgerDto salesLedgerDto) { |
| | | IPage<SalesLedger> iPage = salesLedgerService.selectSalesLedgerListPage(page, salesLedgerDto); |
| | | |
| | | // 查询结果为空,直接返回 |
| | | if (CollectionUtils.isEmpty(iPage.getRecords())) { |
| | | return iPage; |
| | | } |
| | | |
| | | // 获取当前页所有台账记录的 ID 集合 |
| | | List<Long> salesLedgerIds = iPage.getRecords().stream().map(SalesLedger::getId).collect(Collectors.toList()); |
| | | |
| | | // 查询发票信息的已开票金额 |
| | | List<InvoiceLedgerDto> invoiceLedgerDtoList = invoiceLedgerMapper.invoicedTotal(salesLedgerIds); |
| | | if (CollectionUtils.isEmpty(invoiceLedgerDtoList)) { |
| | | invoiceLedgerDtoList = Collections.emptyList(); |
| | | } |
| | | |
| | | // 转换发票数据, key 为台账ID, value 为该台账的总开票金额 |
| | | Map<Long, BigDecimal> invoiceTotals = invoiceLedgerDtoList.stream() |
| | | .filter(dto -> dto.getSalesLedgerId() != null && dto.getInvoiceTotal() != null) |
| | | .collect(Collectors.toMap( |
| | | dto -> dto.getSalesLedgerId().longValue(), |
| | | InvoiceLedgerDto::getInvoiceTotal, |
| | | BigDecimal::add // 存在重复ID执行累加 |
| | | )); |
| | | |
| | | // 查询回款/付款记录 |
| | | List<ReceiptPayment> receiptPayments = Collections.emptyList(); |
| | | if (!CollectionUtils.isEmpty(salesLedgerIds)) { |
| | | receiptPayments = receiptPaymentMapper.selectList(new LambdaQueryWrapper<ReceiptPayment>() |
| | | .in(ReceiptPayment::getSalesLedgerId, salesLedgerIds)); |
| | | } |
| | | |
| | | // 转换回款数据, key 为台账ID, value 为该台账的总回款金额 |
| | | Map<Long, BigDecimal> receiptTotals = new HashMap<>(); |
| | | if (!CollectionUtils.isEmpty(receiptPayments)) { |
| | | for (ReceiptPayment receiptPayment : receiptPayments) { |
| | | if (receiptPayment.getSalesLedgerId() != null && receiptPayment.getReceiptPaymentAmount() != null) { |
| | | // 如果 key 存在则相加,不存在则放入 |
| | | receiptTotals.merge(receiptPayment.getSalesLedgerId(), receiptPayment.getReceiptPaymentAmount(), BigDecimal::add); |
| | | } |
| | | } |
| | | } |
| | | |
| | | for (SalesLedger salesLedger : iPage.getRecords()) { |
| | | Long ledgerId = salesLedger.getId(); |
| | | // 合同总金额 |
| | | BigDecimal contractAmount = salesLedger.getContractAmount() == null ? BigDecimal.ZERO : salesLedger.getContractAmount(); |
| | | // 开票总额和回款总额 |
| | | BigDecimal invoiceTotal = invoiceTotals.getOrDefault(ledgerId, BigDecimal.ZERO); |
| | | BigDecimal receiptPaymentAmountTotal = receiptTotals.getOrDefault(ledgerId, BigDecimal.ZERO); |
| | | |
| | | // 未开票金额 = 合同金额 - 已开票金额 |
| | | BigDecimal noInvoiceAmountTotal = contractAmount.subtract(invoiceTotal); |
| | | if (noInvoiceAmountTotal.compareTo(BigDecimal.ZERO) < 0) { |
| | | noInvoiceAmountTotal = BigDecimal.ZERO; |
| | | } |
| | | |
| | | // 待回款金额 = 已开票金额 - 已回款金额 |
| | | BigDecimal noReceiptPaymentAmountTotal = invoiceTotal.subtract(receiptPaymentAmountTotal); |
| | | if (noReceiptPaymentAmountTotal.compareTo(BigDecimal.ZERO) < 0) { |
| | | noReceiptPaymentAmountTotal = BigDecimal.ZERO; |
| | | } |
| | | |
| | | salesLedger.setNoInvoiceAmountTotal(noInvoiceAmountTotal); |
| | | salesLedger.setInvoiceTotal(invoiceTotal); |
| | | salesLedger.setReceiptPaymentAmountTotal(receiptPaymentAmountTotal); |
| | | salesLedger.setNoReceiptAmount(noReceiptPaymentAmountTotal); |
| | | |
| | | // 如果已经有过开票或回款操作,则不允许编辑 |
| | | boolean hasInvoiceOperation = invoiceTotal.compareTo(BigDecimal.ZERO) > 0; |
| | | boolean hasReceiptOperation = receiptPaymentAmountTotal.compareTo(BigDecimal.ZERO) > 0; |
| | | salesLedger.setIsEdit(!(hasInvoiceOperation || hasReceiptOperation)); |
| | | } |
| | | |
| | | if (ObjectUtils.isNotEmpty(salesLedgerDto.getStatus())) { |
| | | if (salesLedgerDto.getStatus()) { |
| | | // 清除所有“未开票金额”为 0 的记录 |
| | | iPage.getRecords().removeIf(salesLedger -> |
| | | Objects.equals(salesLedger.getNoInvoiceAmountTotal(), new BigDecimal("0.00"))); |
| | | iPage.setTotal(iPage.getRecords().size()); |
| | | } |
| | | } |
| | | |
| | | return iPage; |
| | | public IPage<SalesLedger> listPage(Page<?> page, SalesLedgerDto salesLedgerDto) { |
| | | return salesLedgerService.selectSalesLedgerListPage(page, salesLedgerDto); |
| | | } |
| | | |
| | | @ApiOperation("查询销售台账消耗物料信息") |
| | |
| | | SalesOrdersDto salesOrdersDto = salesLedgerService.salesOrders(salesLedgerId); |
| | | return AjaxResult.success(salesOrdersDto); |
| | | } |
| | | |
| | | @PostMapping("/salesInvoices") |
| | | @ApiOperation("打印销售发货单") |
| | | public AjaxResult salesInvoices(@RequestBody List<Long> salesLedgerIds) { |
| | | SalesInvoicesDto dto = salesLedgerService.salesInvoices(salesLedgerIds); |
| | | return AjaxResult.success(dto); |
| | | } |
| | | |
| | | @GetMapping("/salesLabel/{salesLedgerId}") |
| | | @ApiOperation("打印订单标签") |
| | | public AjaxResult salesLabel(@PathVariable Long salesLedgerId) { |
| | | List<SalesLabelDto> list = salesLedgerService.salesLabel(salesLedgerId); |
| | | return AjaxResult.success(list); |
| | | } |
| | | |
| | | @PostMapping("/salesStock") |
| | | @ApiOperation("销售台账产品入库") |
| | | public AjaxResult salesStock(@RequestBody SalesProductStockDto dto) { |
| | | salesLedgerService.salesStock(dto); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @GetMapping("/shippedCustomers") |
| | | @ApiOperation("已发货客户名单") |
| | | public AjaxResult shippedCustomers() { |
| | | List<Customer> list = salesLedgerService.shippedCustomers(); |
| | | return AjaxResult.success(list); |
| | | } |
| | | |
| | | @PostMapping("/scanInbound") |
| | | @ApiOperation("销售订单扫码-合格入库") |
| | | public AjaxResult scanInbound(@RequestBody SalesScanInboundDto dto) { |
| | | salesLedgerService.scanInbound(dto); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @PostMapping("/scanInboundUnqualified") |
| | | @ApiOperation("销售订单扫码-不合格入库") |
| | | public AjaxResult scanInboundUnqualified(@RequestBody SalesScanInboundDto dto) { |
| | | salesLedgerService.scanInboundUnqualified(dto); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @PostMapping("/scanOutbound") |
| | | @ApiOperation("销售订单扫码-合格出库") |
| | | public AjaxResult scanOutbound(@RequestBody SalesScanInboundDto dto) { |
| | | salesLedgerService.scanOutbound(dto); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @PostMapping("/scanOutboundUnqualified") |
| | | @ApiOperation("销售订单扫码-不合格出库") |
| | | public AjaxResult scanOutboundUnqualified(@RequestBody SalesScanInboundDto dto) { |
| | | salesLedgerService.scanOutboundUnqualified(dto); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | } |