From beeba1259f983a5f92e6b8137d2fb05389f184b4 Mon Sep 17 00:00:00 2001
From: chenrui <1187576398@qq.com>
Date: 星期二, 27 五月 2025 11:39:43 +0800
Subject: [PATCH] 开票台账功能修改

---
 src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java |  131 ++++++++++++++++++++++++++++++++-----------
 1 files changed, 98 insertions(+), 33 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java
index 89520b4..9ce10fb 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java
@@ -5,17 +5,17 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ruoyi.basic.dto.SupplierManageDto;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.common.vo.FileVo;
 import com.ruoyi.sales.dto.InvoiceLedgerDto;
+import com.ruoyi.sales.dto.InvoiceRegistrationProductDto;
 import com.ruoyi.sales.excel.InvoiceLedgerExcelDto;
 import com.ruoyi.sales.mapper.InvoiceLedgerFileMapper;
 import com.ruoyi.sales.mapper.InvoiceLedgerMapper;
-import com.ruoyi.sales.mapper.ReceiptPaymentMapper;
+import com.ruoyi.sales.mapper.InvoiceRegistrationMapper;
+import com.ruoyi.sales.mapper.InvoiceRegistrationProductMapper;
 import com.ruoyi.sales.pojo.InvoiceLedger;
 import com.ruoyi.sales.pojo.InvoiceLedgerFile;
-import com.ruoyi.sales.pojo.ReceiptPayment;
 import com.ruoyi.sales.service.InvoiceLedgerService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.BeanUtils;
@@ -29,8 +29,10 @@
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.math.BigDecimal;
-import java.util.Collections;
+import java.time.LocalDate;
+import java.time.YearMonth;
 import java.util.List;
+import java.util.Objects;
 import java.util.UUID;
 import java.util.stream.Collectors;
 
@@ -47,36 +49,51 @@
     private InvoiceLedgerFileMapper invoiceLedgerFileMapper;
 
     @Autowired
-    private ReceiptPaymentMapper receiptPaymentMapper;
+    private InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
+
+    @Autowired
+    private InvoiceRegistrationMapper invoiceRegistrationMapper;
 
     /**
      * 寮�绁ㄥ彴璐︽柊澧�
-     * @param invoiceLedgerDto
+     * @param productDto
      * @return
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public int invoiceLedgerSaveOrUpdate(InvoiceLedgerDto invoiceLedgerDto) {
-        InvoiceLedger invoiceLedger = new InvoiceLedger();
-        BeanUtils.copyProperties(invoiceLedgerDto, invoiceLedger);
+    public int invoiceLedgerSaveOrUpdate(InvoiceRegistrationProductDto productDto) {
+        // 鍒ゆ柇鏄惁宸茬粡鏂板寮�绁ㄥ彴璐�
+        QueryWrapper<InvoiceLedger> ledgerQueryWrapper = new QueryWrapper<>();
+        ledgerQueryWrapper.eq("invoice_registration_product_id", productDto.getId());
+        InvoiceLedger invoiceLedger = invoiceLedgerMapper.selectOne(ledgerQueryWrapper);
         int result;
-        if(invoiceLedgerDto.getId() == null){
+        if(ObjectUtils.isEmpty(invoiceLedger)){
+            invoiceLedger = new InvoiceLedger();
+            invoiceLedger.setInvoiceRegistrationProductId(productDto.getId());
+            invoiceLedger.setInvoiceNo(productDto.getInvoiceNo());
+            invoiceLedger.setInvoiceTotal(productDto.getInvoiceTotal());
+            invoiceLedger.setInvoiceDate(productDto.getInvoiceDate());
+            invoiceLedger.setInvoicePerson(productDto.getInvoicePerson());
             result = invoiceLedgerMapper.insert(invoiceLedger);
         }else {
+            invoiceLedger.setInvoiceNo(productDto.getInvoiceNo());
+            invoiceLedger.setInvoiceTotal(productDto.getInvoiceTotal());
+            invoiceLedger.setInvoiceDate(productDto.getInvoiceDate());
+            invoiceLedger.setInvoicePerson(productDto.getInvoicePerson());
             result = invoiceLedgerMapper.updateById(invoiceLedger);
             //鍒犻櫎鎵�鏈夐檮浠跺叧鑱�
             LambdaQueryWrapper<InvoiceLedgerFile> delWrapper = new LambdaQueryWrapper<>();
-            delWrapper.eq(InvoiceLedgerFile::getInvoiceLedgerId, invoiceLedgerDto.getId());
+            delWrapper.eq(InvoiceLedgerFile::getInvoiceLedgerId, invoiceLedger.getId());
             invoiceLedgerFileMapper.delete(delWrapper);
         }
-        List<FileVo> fileList = invoiceLedgerDto.getFileList();
+        List<FileVo> fileList = productDto.getFileList();
         if(CollectionUtils.isNotEmpty(fileList)){
-            fileList.forEach(fileVo -> {
+            for (FileVo fileVo : fileList) {
                 InvoiceLedgerFile invoiceLedgerFile = new InvoiceLedgerFile();
                 BeanUtils.copyProperties(fileVo, invoiceLedgerFile);
                 invoiceLedgerFile.setInvoiceLedgerId(invoiceLedger.getId());
                 invoiceLedgerFileMapper.insert(invoiceLedgerFile);
-            });
+            }
         }
         return result;
     }
@@ -145,13 +162,13 @@
     /**
      * 闄勪欢涓嬭浇
      * @param response
-     * @param invoiceLedgerDto
+     * @param invoiceRegistrationProductDto
      * @return
      */
     @Override
-    public void invoiceLedgerExport(HttpServletResponse response, InvoiceLedgerDto invoiceLedgerDto) {
-        List<InvoiceLedgerDto> invoiceLedgerDtoList = invoiceLedgerMapper.invoiceLedgerList(invoiceLedgerDto);
-        List<InvoiceLedgerExcelDto> invoiceLedgerExcelDtoList = invoiceLedgerDtoList.stream().map(item -> {
+    public void invoiceLedgerExport(HttpServletResponse response, InvoiceRegistrationProductDto invoiceRegistrationProductDto) {
+        List<InvoiceRegistrationProductDto> invoiceRegistrationProductList = invoiceRegistrationProductMapper.invoiceRegistrationProductList(invoiceRegistrationProductDto);
+        List<InvoiceLedgerExcelDto> invoiceLedgerExcelDtoList = invoiceRegistrationProductList.stream().map(item -> {
             InvoiceLedgerExcelDto invoiceLedgerExcelDto = new InvoiceLedgerExcelDto();
             BeanUtils.copyProperties(item, invoiceLedgerExcelDto);
             return invoiceLedgerExcelDto;
@@ -197,11 +214,17 @@
         if(CollectionUtils.isEmpty(invoiceLedgerDto.getFileList())){
             throw new RuntimeException("缂哄皯鏂囦欢淇℃伅");
         }
+        QueryWrapper<InvoiceLedger> ledgerQueryWrapper = new QueryWrapper<>();
+        ledgerQueryWrapper.eq("invoice_registration_product_id", invoiceLedgerDto.getId());
+        InvoiceLedger invoiceLedger = invoiceLedgerMapper.selectOne(ledgerQueryWrapper);
+        if(ObjectUtils.isEmpty(invoiceLedger)){
+            throw new RuntimeException("寮�绁ㄥ彴璐︽湭鐧昏");
+        }
         List<FileVo> fileList = invoiceLedgerDto.getFileList();
         fileList.forEach(fileVo -> {
             InvoiceLedgerFile invoiceLedgerFile = new InvoiceLedgerFile();
             BeanUtils.copyProperties(fileVo, invoiceLedgerFile);
-            invoiceLedgerFile.setInvoiceLedgerId(invoiceLedgerDto.getId());
+            invoiceLedgerFile.setInvoiceLedgerId(invoiceLedger.getId());
             invoiceLedgerFileMapper.insert(invoiceLedgerFile);
         });
     }
@@ -225,21 +248,63 @@
     @Override
     public IPage<InvoiceLedgerDto> invoiceLedgerSalesAccount(Page page, InvoiceLedgerDto invoiceLedgerDto) {
         IPage<InvoiceLedgerDto> invoiceLedgerDtoIPage = invoiceLedgerMapper.invoiceLedgerSalesAccount(page, invoiceLedgerDto);
-        for (InvoiceLedgerDto record : invoiceLedgerDtoIPage.getRecords()) {
-            QueryWrapper<ReceiptPayment> queryWrapper = new QueryWrapper<>();
-            queryWrapper.eq("customer_id", record.getCustomerId());
-            List<ReceiptPayment> receiptPaymentList = receiptPaymentMapper.selectList(queryWrapper);
-            BigDecimal totalAmount = BigDecimal.ZERO;
-            if(!CollectionUtils.isEmpty(receiptPaymentList)){
-                for (ReceiptPayment receiptPayment : receiptPaymentList) {
-                    totalAmount = totalAmount.add(receiptPayment.getInvoiceAmount());
-                }
-            }
-            BigDecimal unReceiptPaymentAmount = record.getInvoiceAmount().subtract(totalAmount);
-            record.setReceiptPaymentAmount(totalAmount);
-            record.setUnReceiptPaymentAmount(unReceiptPaymentAmount);
-        }
         return invoiceLedgerDtoIPage;
     }
 
+    @Override
+    public BigDecimal getInvoiceAmount() {
+        LocalDate now = LocalDate.now();
+        YearMonth currentMonth = YearMonth.from(now);
+
+        // 鍒涘缓LambdaQueryWrapper
+        LambdaQueryWrapper<InvoiceLedger> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.ge(InvoiceLedger::getInvoiceDate, currentMonth.atDay(1).atStartOfDay())  // 澶т簬绛変簬鏈湀绗竴澶�
+                .lt(InvoiceLedger::getInvoiceDate, currentMonth.plusMonths(1).atDay(1).atStartOfDay()); // 灏忎簬涓嬫湀绗竴澶�
+
+        // 鎵ц鏌ヨ骞惰绠楁�诲拰
+        List<InvoiceLedger> invoiceLedgers = invoiceLedgerMapper.selectList(queryWrapper);
+
+        BigDecimal totalContractAmount = invoiceLedgers.stream()
+                .map(InvoiceLedger::getInvoiceTotal)
+                .filter(Objects::nonNull)
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+        return totalContractAmount;
+    }
+
+    /**
+     * 寮�绁ㄧ櫥璁颁骇鍝佸垎椤垫煡璇�
+     * @param page
+     * @param registrationProductDto
+     * @return
+     */
+    @Override
+    public IPage<InvoiceRegistrationProductDto> registrationProductPage(Page page, InvoiceRegistrationProductDto registrationProductDto) {
+        return invoiceRegistrationProductMapper.invoiceRegistrationProductPage(page,registrationProductDto);
+    }
+
+    /**
+     * 浜у搧寮�绁ㄥ彴璐﹁鎯�
+     * @param id
+     * @return
+     */
+    @Override
+    public InvoiceRegistrationProductDto invoiceLedgerProductDetail(Integer id) {
+        InvoiceRegistrationProductDto invoiceRegistrationProductDto = invoiceLedgerMapper.invoiceLedgerProductInfo(id);
+        if(ObjectUtils.isEmpty(invoiceRegistrationProductDto)){
+            throw new RuntimeException("浜у搧寮�绁ㄥ彴璐︽煡鎵惧け璐�");
+        }
+        // 鏌ヨ闄勪欢
+        QueryWrapper<InvoiceLedgerFile> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("invoice_ledger_id", invoiceRegistrationProductDto.getInvoiceLedgerId());
+        List<InvoiceLedgerFile> invoiceLedgerFileList = invoiceLedgerFileMapper.selectList(queryWrapper);
+        List<FileVo> fileList = invoiceLedgerFileList.stream().map(item -> {
+            FileVo fileVo = new FileVo();
+            BeanUtils.copyProperties(item, fileVo);
+            return fileVo;
+        }).collect(Collectors.toList());
+        invoiceRegistrationProductDto.setFileList(fileList);
+        return invoiceRegistrationProductDto;
+    }
+
 }

--
Gitblit v1.9.3