From f716a7578acddd7cc31a45e45947ba2b6ce86662 Mon Sep 17 00:00:00 2001 From: bachir souldi Date: Sat, 7 Jan 2023 18:01:28 +0100 Subject: [PATCH] Customize prints for SaleOrder StockMove AccountInvoice --- .../print/InvoicePrintServiceImpl.java | 11 ++++ .../apps/account/web/InvoiceController.java | 56 +++++++++++++++++++ .../print/SaleOrderPrintServiceImpl.java | 8 +++ .../print/StockMovePrintServiceImpl.java | 10 ++++ 4 files changed, 85 insertions(+) diff --git a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/print/InvoicePrintServiceImpl.java b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/print/InvoicePrintServiceImpl.java index e827650d..a4ee8a2a 100644 --- a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/print/InvoicePrintServiceImpl.java +++ b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/service/invoice/print/InvoicePrintServiceImpl.java @@ -23,6 +23,7 @@ import com.axelor.apps.account.db.repo.AccountConfigRepository; import com.axelor.apps.account.db.repo.InvoiceRepository; import com.axelor.apps.account.exception.IExceptionMessage; import com.axelor.apps.account.report.IReport; +import com.axelor.apps.base.service.ConvertNumberToFrenchWordsService; import com.axelor.apps.base.service.app.AppBaseService; import com.axelor.apps.report.engine.ReportSettings; import com.axelor.apps.tool.ModelTool; @@ -220,7 +221,17 @@ public class InvoicePrintServiceImpl implements InvoicePrintService { : partnerLanguageCode; } + + + + String[] arrOfStr = invoice.getInTaxTotal().toString().split("\\."); + + String left = Beans.get(ConvertNumberToFrenchWordsService.class).convert(Long.parseLong(arrOfStr[0])); + String right = Beans.get(ConvertNumberToFrenchWordsService.class).convert(Long.parseLong(arrOfStr[1])); + String number = left+" dinars algériens et "+right+" Cts"; + return reportSetting + .addParam("NumberToWords", number) .addParam("InvoiceId", invoice.getId()) .addParam("Locale", locale) .addParam("ReportType", reportType == null ? 0 : reportType) diff --git a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/web/InvoiceController.java b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/web/InvoiceController.java index a4b40771..04f76117 100644 --- a/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/web/InvoiceController.java +++ b/modules/axelor-open-suite/axelor-account/src/main/java/com/axelor/apps/account/web/InvoiceController.java @@ -24,6 +24,7 @@ import com.axelor.apps.account.db.PaymentCondition; import com.axelor.apps.account.db.PaymentMode; import com.axelor.apps.account.db.PaymentVoucher; import com.axelor.apps.account.db.Journal; +import com.axelor.apps.account.db.repo.AccountConfigRepository; import com.axelor.apps.account.db.repo.InvoiceRepository; import com.axelor.apps.account.exception.IExceptionMessage; import com.axelor.apps.account.service.AccountingSituationService; @@ -71,6 +72,7 @@ import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.HashMap; @@ -1016,6 +1018,60 @@ public class InvoiceController { response.setView(ActionView.define(name).add("html", fileLink).map()); } + public void showInvoice2(ActionRequest request, ActionResponse response) + throws AxelorException { + + Context context = request.getContext(); + + Invoice invoice = Beans.get(InvoiceRepository.class) + .find(Long.parseLong(context.get("id").toString())); + + String name = I18n.get("Invoice"); + String inTaxTotal = invoice.getInTaxTotal().toString(); + String[] arrOfStr = inTaxTotal.split("\\."); + + + String format = context.get("format") != null ? context.get("format").toString() : "pdf"; + Integer reportType = + context.get("reportType") != null + ? Integer.parseInt(context.get("reportType").toString()) + : null; + + Map languageMap = + reportType != null + && (reportType == 1 || reportType == 3) + && context.get("language") != null + ? (Map) request.getContext().get("language") + : null; + String locale = + languageMap != null && languageMap.get("id") != null + ? Beans.get(LanguageRepository.class) + .find(Long.parseLong(languageMap.get("id").toString())) + .getCode() + : null; + + String left = Beans.get(ConvertNumberToFrenchWordsService.class).convert(Long.parseLong(arrOfStr[0])); + String right = Beans.get(ConvertNumberToFrenchWordsService.class).convert(Long.parseLong(arrOfStr[1])); + String number = left+" dinars algériens et "+right+" centimes"; + + String fileLink = + ReportFactory.createReport("invoice.rptdesign", name + "-${date}") + .addParam("NumberToWords", number) + .addParam("InvoiceId", invoice.getId()) + .addParam("Locale", locale) + .addParam("ReportType", reportType == null ? 0 : reportType) + .addParam("HeaderHeight", invoice.getPrintingSettings().getPdfHeaderHeight()) + .addParam("FooterHeight", invoice.getPrintingSettings().getPdfFooterHeight()) + .generate() + .getFileLink(); + + logger.debug("Printing " + name); + + response.setView(ActionView.define(name).add("html", fileLink).map()); + response.setCanClose(true); + + } + /** * set default value for automatic invoice Journal = supplier Purchase Journal diff --git a/modules/axelor-open-suite/axelor-sale/src/main/java/com/axelor/apps/sale/service/saleorder/print/SaleOrderPrintServiceImpl.java b/modules/axelor-open-suite/axelor-sale/src/main/java/com/axelor/apps/sale/service/saleorder/print/SaleOrderPrintServiceImpl.java index aa75b39e..dc8c5145 100644 --- a/modules/axelor-open-suite/axelor-sale/src/main/java/com/axelor/apps/sale/service/saleorder/print/SaleOrderPrintServiceImpl.java +++ b/modules/axelor-open-suite/axelor-sale/src/main/java/com/axelor/apps/sale/service/saleorder/print/SaleOrderPrintServiceImpl.java @@ -18,6 +18,7 @@ package com.axelor.apps.sale.service.saleorder.print; import com.axelor.apps.ReportFactory; +import com.axelor.apps.base.service.ConvertNumberToFrenchWordsService; import com.axelor.apps.base.service.app.AppBaseService; import com.axelor.apps.report.engine.ReportSettings; import com.axelor.apps.sale.db.SaleOrder; @@ -92,8 +93,15 @@ public class SaleOrderPrintServiceImpl implements SaleOrderPrintService { ReportSettings reportSetting = ReportFactory.createReport(IReport.SALES_ORDER, title + " - ${date}"); + + String[] arrOfStr = saleOrder.getInTaxTotal().toString().split("\\."); + + String left = Beans.get(ConvertNumberToFrenchWordsService.class).convert(Long.parseLong(arrOfStr[0])); + String right = Beans.get(ConvertNumberToFrenchWordsService.class).convert(Long.parseLong(arrOfStr[1])); + String number = left+" dinars algériens et "+right+" Cts"; return reportSetting + .addParam("NumberToWords", number) .addParam("SaleOrderId", saleOrder.getId()) .addParam("Locale", locale) .addParam("ProformaInvoice", proforma) diff --git a/modules/axelor-open-suite/axelor-stock/src/main/java/com/axelor/apps/stock/service/stockmove/print/StockMovePrintServiceImpl.java b/modules/axelor-open-suite/axelor-stock/src/main/java/com/axelor/apps/stock/service/stockmove/print/StockMovePrintServiceImpl.java index db9bd32f..dd9e0fd7 100644 --- a/modules/axelor-open-suite/axelor-stock/src/main/java/com/axelor/apps/stock/service/stockmove/print/StockMovePrintServiceImpl.java +++ b/modules/axelor-open-suite/axelor-stock/src/main/java/com/axelor/apps/stock/service/stockmove/print/StockMovePrintServiceImpl.java @@ -18,6 +18,7 @@ package com.axelor.apps.stock.service.stockmove.print; import com.axelor.apps.ReportFactory; +import com.axelor.apps.base.service.ConvertNumberToFrenchWordsService; import com.axelor.apps.base.service.app.AppBaseService; import com.axelor.apps.report.engine.ReportSettings; import com.axelor.apps.stock.db.StockMove; @@ -71,8 +72,17 @@ public class StockMovePrintServiceImpl implements StockMovePrintService { ReportSettings reportSetting = ReportFactory.createReport(IReport.STOCK_MOVE, title + " - ${date}"); + + + String[] exTaxTotal = stockMove.getExTaxTotal().toString().split("\\."); + + String left = Beans.get(ConvertNumberToFrenchWordsService.class).convert(Long.parseLong(exTaxTotal[0])); + String right = Beans.get(ConvertNumberToFrenchWordsService.class).convert(Long.parseLong(exTaxTotal[1])); + String number = left+" dinars algériens et "+right+" Cts"; + return reportSetting .addParam("StockMoveId", stockMove.getId()) + .addParam("NumberToWords", number) .addParam("Locale", locale) .addParam("HeaderHeight", stockMove.getPrintingSettings().getPdfHeaderHeight()) .addParam("FooterHeight", stockMove.getPrintingSettings().getPdfFooterHeight())