|
@@ -192,6 +192,25 @@ public class InvoiceContractServiceImpl extends ServiceImpl<InvoiceContractMappe
|
|
|
if(contractTemplate==null){
|
|
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"合同模板不存在");
|
|
|
}
|
|
|
+ ContractTemplateDO template1 = null;
|
|
|
+ ContractTemplateDO template2 = null;
|
|
|
+ if("F2".equals(contractTemplate.getContractTypeCode())){
|
|
|
+ //发票购销合同需添加附件
|
|
|
+ template1 = contractTemplateService.getOne(Wrappers.<ContractTemplateDO>lambdaQuery().eq(ContractTemplateDO::getContractTypeCode,"F2-1").eq(ContractTemplateDO::getClientCode,maxInvoice.getClientCode()));
|
|
|
+ if(template1==null){
|
|
|
+ template1 = contractTemplateService.getOne(Wrappers.<ContractTemplateDO>lambdaQuery().eq(ContractTemplateDO::getContractTypeCode,"F2-1"));
|
|
|
+ }
|
|
|
+ if(template1==null){
|
|
|
+ throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"发票明细附件模板不存在");
|
|
|
+ }
|
|
|
+ template2 = contractTemplateService.getOne(Wrappers.<ContractTemplateDO>lambdaQuery().eq(ContractTemplateDO::getContractTypeCode,"F2-2").eq(ContractTemplateDO::getClientCode,maxInvoice.getClientCode()));
|
|
|
+ if(template2==null){
|
|
|
+ template2 = contractTemplateService.getOne(Wrappers.<ContractTemplateDO>lambdaQuery().eq(ContractTemplateDO::getContractTypeCode,"F2-2"));
|
|
|
+ }
|
|
|
+ if(template2==null){
|
|
|
+ throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"借贷项附件模板不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
invoiceContract.setContractTemplateId(contractTemplate.getId());
|
|
|
invoiceContract.setContractTemplateName(contractTemplate.getContractName());
|
|
|
|
|
@@ -221,11 +240,25 @@ public class InvoiceContractServiceImpl extends ServiceImpl<InvoiceContractMappe
|
|
|
}
|
|
|
invoiceContract.setFrameworkAgreementId(frameworkAgreementId);
|
|
|
|
|
|
+ Map<String,Object> param = buildContractParam(invoiceContract,invoiceDetails,company,clientDO,frameworkAgreementNo,invoiceList);
|
|
|
String htmlContent = contractTemplate.getContractContent();
|
|
|
htmlContent = htmlInit(htmlContent);
|
|
|
- Map<String,Object> param = buildContractParam(invoiceContract,invoiceDetails,company,clientDO,frameworkAgreementNo);
|
|
|
htmlContent = HtmlToFileConverter.authHtmlToPdf(htmlContent, param);
|
|
|
- String fileUrl = htmlToFileConverter.htmlToWord(htmlContent,"invoiceContract/"+invoiceContract.getContractNo(),"fpht-");
|
|
|
+ String fileUrl = null;
|
|
|
+ if("F2".equals(contractTemplate.getContractTypeCode())){
|
|
|
+ //销购发票需要拼接附件
|
|
|
+ List<String> htmlContents = new ArrayList<>();
|
|
|
+ htmlContents.add(htmlContent);
|
|
|
+ htmlContents.add(generateAttachmentHtml(template1,param));
|
|
|
+ if(false){
|
|
|
+ generateAttachmentHtml(template2,param);
|
|
|
+ }
|
|
|
+ fileUrl = htmlToFileConverter.htmlToWord(htmlContents,"invoiceContract/"+invoiceContract.getContractNo(),"fpht-");
|
|
|
+ htmlContent = StringUtils.join(htmlContents,"<div style='break-after: page;'></div><div class='page-break'>")+"</div>";
|
|
|
+ }else{
|
|
|
+ fileUrl = htmlToFileConverter.htmlToWord(htmlContent,"invoiceContract/"+invoiceContract.getContractNo(),"fpht-");
|
|
|
+ }
|
|
|
+
|
|
|
invoiceContract.setGeneratedTime(LocalDateTime.now());
|
|
|
invoiceContract.setContractHtml(htmlContent);
|
|
|
invoiceContract.setContractFileUrl(fileUrl);
|
|
@@ -242,6 +275,22 @@ public class InvoiceContractServiceImpl extends ServiceImpl<InvoiceContractMappe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private String generateAttachmentHtml(ContractTemplateDO template,Map<String,Object> param)throws Exception {
|
|
|
+ if("F2-1".equals(template.getContractTypeCode())){
|
|
|
+ String htmlContent = "";
|
|
|
+ htmlContent = invoiceListHtmlInit(template.getContractContent());
|
|
|
+ htmlContent = HtmlToFileConverter.authHtmlToPdf(htmlContent, param);
|
|
|
+ return htmlContent;
|
|
|
+ }
|
|
|
+ if("F2-2".equals(template.getContractTypeCode())){
|
|
|
+ String htmlContent = "";
|
|
|
+ htmlContent = loanItemHtmlInit(template.getContractContent());
|
|
|
+ htmlContent = HtmlToFileConverter.authHtmlToPdf(htmlContent, param);
|
|
|
+ return htmlContent;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void cancellation(InvoiceContractDO invoiceContract,List<InvoiceDO> invoiceList) {
|
|
@@ -255,7 +304,7 @@ public class InvoiceContractServiceImpl extends ServiceImpl<InvoiceContractMappe
|
|
|
|
|
|
}
|
|
|
|
|
|
- private Map<String, Object> buildContractParam(InvoiceContractDO invoiceContract, Map<String, List<InvoiceDetailsDO>> invoiceDetails, CompanyDO companyDO, ClientDO clientDO,String frameworkAgreementNo) {
|
|
|
+ private Map<String, Object> buildContractParam(InvoiceContractDO invoiceContract, Map<String, List<InvoiceDetailsDO>> invoiceDetails, CompanyDO companyDO, ClientDO clientDO,String frameworkAgreementNo,List<InvoiceDO> invoiceList) {
|
|
|
Map<String,Object> param = new HashMap<>();
|
|
|
//订单信息
|
|
|
param.put("购方名称", StringUtils.nvl(invoiceContract.getGfmc(), ""));
|
|
@@ -347,6 +396,21 @@ public class InvoiceContractServiceImpl extends ServiceImpl<InvoiceContractMappe
|
|
|
}
|
|
|
param.put("invoiceDetails",details);
|
|
|
|
|
|
+
|
|
|
+ List<Map<String,Object>> invoices = new ArrayList<>();
|
|
|
+ for(int i=0;i<invoiceList.size();i++){
|
|
|
+ InvoiceDO invoiceDO = invoiceList.get(i);
|
|
|
+ Map<String,Object> data = new HashMap<>();
|
|
|
+ data.put("序号",i+1);
|
|
|
+ data.put("明细合同编号", StringUtils.nvl(invoiceDO.getDdh(),""));
|
|
|
+ data.put("明细发票号码", StringUtils.nvl(invoiceDO.getFphm(),""));
|
|
|
+ data.put("明细金额", StringUtils.nvl(MoneyUtil.toSeparator(invoiceDO.getJshj()),""));
|
|
|
+ data.put("明细开票日期", StringUtils.nvl(invoiceDO.getKprq(),""));
|
|
|
+ invoices.add(data);
|
|
|
+ }
|
|
|
+ param.put("invoiceList",invoices);
|
|
|
+
|
|
|
+
|
|
|
//产品合计
|
|
|
param.put("数量合计",MoneyUtil.toSeparator(quantityTotal.toString()));
|
|
|
param.put("不含税总金额合计", StringUtils.nvl(MoneyUtil.toSeparator(noTaxAmountSum.toString()), ""));
|
|
@@ -429,6 +493,73 @@ public class InvoiceContractServiceImpl extends ServiceImpl<InvoiceContractMappe
|
|
|
return htmlContent;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private String invoiceListHtmlInit(String htmlContent) {
|
|
|
+ htmlContent= htmlContent.replaceAll("\\$\\{序号}","\\$\\{invoice.序号}");
|
|
|
+ htmlContent= htmlContent.replaceAll("\\$\\{明细合同编号}","\\$\\{invoice.明细合同编号}");
|
|
|
+ htmlContent= htmlContent.replaceAll("\\$\\{明细发票号码}","\\$\\{invoice.明细发票号码}");
|
|
|
+ htmlContent= htmlContent.replaceAll("\\$\\{明细金额}","\\$\\{invoice.明细金额}");
|
|
|
+ htmlContent= htmlContent.replaceAll("\\$\\{明细开票日期}","\\$\\{invoice.明细开票日期}");
|
|
|
+
|
|
|
+
|
|
|
+// htmlContent = addWatermark(htmlContent);
|
|
|
+ Document doc = Jsoup.parse(htmlContent);
|
|
|
+ Elements tdElements = doc.select("td");
|
|
|
+ for (Element cell : tdElements) {
|
|
|
+ String text = cell.text(); // 获取td元素及其所有子元素的文本内容
|
|
|
+ if (text.startsWith("${invoice.")) {
|
|
|
+ Element tr = cell.parent(); // 获取单元格的父元素
|
|
|
+ if (tr.tagName().equals("tr")) { // 确保父元素是tr
|
|
|
+ Element trr = tr.parent(); // 获取单元格的父元素
|
|
|
+ if(!trr.tagName().equals("list")) {
|
|
|
+ // 创建<#list></#list>元素
|
|
|
+ tr.wrap("<list>");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ htmlContent = doc.html();
|
|
|
+ htmlContent = htmlContent.replaceAll("<list>","<#list invoiceList as invoice>");
|
|
|
+ htmlContent = htmlContent.replaceAll("</list>","</#list>");
|
|
|
+ return htmlContent;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String loanItemHtmlInit(String htmlContent) {
|
|
|
+ htmlContent= htmlContent.replaceAll("\\$\\{序号}","\\$\\{item.序号}");
|
|
|
+ htmlContent= htmlContent.replaceAll("\\$\\{借贷项发票号码}","\\$\\{item.借贷项发票号码}");
|
|
|
+ htmlContent= htmlContent.replaceAll("\\$\\{借贷项金额}","\\$\\{item.借贷项金额}");
|
|
|
+ htmlContent= htmlContent.replaceAll("\\$\\{借贷项类型}","\\$\\{item.借贷项类型}");
|
|
|
+
|
|
|
+// htmlContent= htmlContent.replaceAll("\\$\\{数量合计}","\\$\\{invoiceDetail.数量合计}");
|
|
|
+// htmlContent= htmlContent.replaceAll("\\$\\{不含税总金额合计}","\\$\\{invoiceDetail.不含税总金额合计}");
|
|
|
+// htmlContent= htmlContent.replaceAll("\\$\\{含税金额合计}","\\$\\{invoiceDetail.含税金额合计}");
|
|
|
+// htmlContent= htmlContent.replaceAll("\\$\\{合计金额大写}","\\$\\{invoiceDetail.合计金额大写}");
|
|
|
+
|
|
|
+// htmlContent = addWatermark(htmlContent);
|
|
|
+ Document doc = Jsoup.parse(htmlContent);
|
|
|
+ Elements tdElements = doc.select("td");
|
|
|
+ for (Element cell : tdElements) {
|
|
|
+ String text = cell.text(); // 获取td元素及其所有子元素的文本内容
|
|
|
+ if (text.startsWith("${item.")) {
|
|
|
+ Element tr = cell.parent(); // 获取单元格的父元素
|
|
|
+ if (tr.tagName().equals("tr")) { // 确保父元素是tr
|
|
|
+ Element trr = tr.parent(); // 获取单元格的父元素
|
|
|
+ if(!trr.tagName().equals("list")) {
|
|
|
+ // 创建<#list></#list>元素
|
|
|
+ tr.wrap("<list>");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ htmlContent = doc.html();
|
|
|
+ htmlContent = htmlContent.replaceAll("<list>","<#list loanItem as item>");
|
|
|
+ htmlContent = htmlContent.replaceAll("</list>","</#list>");
|
|
|
+ return htmlContent;
|
|
|
+ }
|
|
|
+
|
|
|
public static String sequenceCode(Integer maxNum, Long count) { // 如生成001这种,maxNum为1000 0001的话maxNum则为10000,count则是我们从数据库中查询的总数
|
|
|
|
|
|
String strNum = String.valueOf(maxNum + count);
|