Browse Source

报告、项目、合同详情中的发票添加批量导出功能

徐滕 3 tuần trước cách đây
mục cha
commit
f2f7d23a23

+ 19 - 4
jeeplus-modules/jeeplus-finance/src/main/java/com/jeeplus/finance/invoice/mapper/xml/CwFinanceInvoiceMapper.xml

@@ -443,10 +443,15 @@
     </select>
 
     <select id="getIdByProjectId" resultType="string">
-        select
-            invoice_id
+        select distinct cw_fib.invoice_id
         from cw_finance_invoice_base cw_fib
-        where cw_fib.del_flag = '0' and cw_fib.program_id = #{id}
+        where cw_fib.del_flag = '0'
+          and (
+            cw_fib.program_id = #{id}
+            or cw_fib.program_id in (
+                select id from cw_project_report where project_id = #{id}
+            )
+          )
     </select>
 
     <select id="getByIds" resultMap="BaseResultMap">
@@ -480,7 +485,17 @@
         from cw_finance_invoice_base fi
         where (fi.program_id is null or fi.program_id = '')
         and fi.contract_id = #{id}
-        AND fi.del_flag = '0') a
+        AND fi.del_flag = '0'
+        union
+        select distinct
+            cw_fib.invoice_id
+        from cw_finance_invoice_base cw_fib
+        where cw_fib.del_flag = '0'
+        and cw_fib.program_id in (
+            select cpr.id from cw_project_report cpr
+            where cpr.project_id in (select cw_pr.id from cw_project_records cw_pr where cw_pr.contract_id = #{id} and cw_pr.del_flag = '0')
+            and cpr.del_flag = '0'
+        )) a
     </select>
 
     <select id="getIdByClientId" resultType="string">

+ 72 - 2
jeeplus-modules/jeeplus-finance/src/main/java/com/jeeplus/finance/invoice/service/CwFinanceInvoiceService.java

@@ -1200,7 +1200,43 @@ public class CwFinanceInvoiceService extends ServiceImpl<CwFinanceInvoiceMapper,
                 queryWrapper.eq("fi.status", "5"); // 发票申请流程已通过
                 queryWrapper.orderByDesc("fi.create_time");
                 queryWrapper.eq("fi.invalid_status", "0"); // 未作废
-                return cwFinanceInvoiceMapper.getByIds(queryWrapper);
+                List<CwFinanceInvoiceDTO> list = cwFinanceInvoiceMapper.getByIds(queryWrapper);
+
+                // 组装发票明细信息(发票号、开票金额)和 OMS 附件 URL
+                for (CwFinanceInvoiceDTO invoice : list) {
+                    // 1. 查询发票明细,合并展示发票号和开票金额
+                    List<CwFinanceInvoiceDetailDTO> detailList = cwFinanceInvoiceMapper.getFidList(invoice.getId());
+                    if (CollectionUtil.isNotEmpty(detailList)) {
+                        List<String> numbers = new ArrayList<>();
+                        BigDecimal totalAmount = new BigDecimal(0);
+                        for (CwFinanceInvoiceDetailDTO detail : detailList) {
+                            if (StringUtils.isNotBlank(detail.getNumber())) {
+                                numbers.add(detail.getNumber());
+                            }
+                            if (StringUtils.isNotBlank(detail.getAccount())) {
+                                totalAmount = totalAmount.add(new BigDecimal(detail.getAccount()));
+                            }
+                        }
+                        if (!numbers.isEmpty()) {
+                            invoice.setNumber(String.join(", ", numbers));
+                        }
+                        invoice.setAccountDetail(totalAmount.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
+                    }
+
+                    // 2. 查询 OMS 附件 URL
+                    if (StringUtils.isNotBlank(invoice.getStatus()) && "5".equals(invoice.getStatus())) {
+                        List<WorkAttachmentInfo> omsInvoiceFileList = SpringUtil.getBean(IWorkAttachmentApi.class).getByAttachmentIdListAndFlag(Arrays.asList(invoice.getId()));
+                        if (CollectionUtil.isNotEmpty(omsInvoiceFileList)) {
+                            for (WorkAttachmentInfo workattachment : omsInvoiceFileList) {
+                                if (workattachment.getUrl().contains("OMS_invoice")) {
+                                    invoice.setOmsAttachmentUrl(workattachment.getUrl());
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                }
+                return list;
             }
         }
         return new ArrayList<>();
@@ -1286,7 +1322,41 @@ public class CwFinanceInvoiceService extends ServiceImpl<CwFinanceInvoiceMapper,
                 queryWrapper.eq("fi.status", "5"); // 发票申请流程已通过
                 queryWrapper.orderByDesc("fi.create_time");
                 queryWrapper.eq("fi.invalid_status", "0"); // 未作废
-                return cwFinanceInvoiceMapper.getByIds(queryWrapper);
+                List<CwFinanceInvoiceDTO> list = cwFinanceInvoiceMapper.getByIds(queryWrapper);
+
+                // 组装发票明细信息(发票号、开票金额)和 OMS 附件 URL
+                for (CwFinanceInvoiceDTO invoice : list) {
+                    List<CwFinanceInvoiceDetailDTO> detailList = cwFinanceInvoiceMapper.getFidList(invoice.getId());
+                    if (CollectionUtil.isNotEmpty(detailList)) {
+                        List<String> numbers = new ArrayList<>();
+                        BigDecimal totalAmount = new BigDecimal(0);
+                        for (CwFinanceInvoiceDetailDTO detail : detailList) {
+                            if (StringUtils.isNotBlank(detail.getNumber())) {
+                                numbers.add(detail.getNumber());
+                            }
+                            if (StringUtils.isNotBlank(detail.getAccount())) {
+                                totalAmount = totalAmount.add(new BigDecimal(detail.getAccount()));
+                            }
+                        }
+                        if (!numbers.isEmpty()) {
+                            invoice.setNumber(String.join(", ", numbers));
+                        }
+                        invoice.setAccountDetail(totalAmount.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
+                    }
+
+                    if (StringUtils.isNotBlank(invoice.getStatus()) && "5".equals(invoice.getStatus())) {
+                        List<WorkAttachmentInfo> omsInvoiceFileList = SpringUtil.getBean(IWorkAttachmentApi.class).getByAttachmentIdListAndFlag(Arrays.asList(invoice.getId()));
+                        if (CollectionUtil.isNotEmpty(omsInvoiceFileList)) {
+                            for (WorkAttachmentInfo workattachment : omsInvoiceFileList) {
+                                if (workattachment.getUrl().contains("OMS_invoice")) {
+                                    invoice.setOmsAttachmentUrl(workattachment.getUrl());
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                }
+                return list;
             }
         }
         return new ArrayList<>();