From 87e01db551e8dbd7abff9b0e40611014fd26319f Mon Sep 17 00:00:00 2001 From: walid seghier Date: Tue, 11 Oct 2022 14:58:32 +0100 Subject: [PATCH] Invoice payment :: cheque printing PDF --- .../apps/account/web/InvoiceController.java | 37 ++ .../main/resources/domains/InvoicePayment.xml | 3 + .../src/main/resources/reports/ASB.rptdesign | 386 ++++++++++++++++++ .../src/main/resources/reports/BDL.rptdesign | 386 ++++++++++++++++++ .../src/main/resources/reports/BNA.rptdesign | 386 ++++++++++++++++++ .../src/main/resources/reports/CPA.rptdesign | 386 ++++++++++++++++++ .../src/main/resources/reports/SGA.rptdesign | 386 ++++++++++++++++++ .../src/main/resources/views/Selects.xml | 8 + .../axelor/apps/base/module/BaseModule.java | 3 + .../ConvertNumberToFrenchWordsService.java | 26 ++ ...ConvertNumberToFrenchWordsServiceImpl.java | 217 ++++++++++ 11 files changed, 2224 insertions(+) create mode 100644 modules/axelor-open-suite/axelor-account/src/main/resources/reports/ASB.rptdesign create mode 100644 modules/axelor-open-suite/axelor-account/src/main/resources/reports/BDL.rptdesign create mode 100644 modules/axelor-open-suite/axelor-account/src/main/resources/reports/BNA.rptdesign create mode 100644 modules/axelor-open-suite/axelor-account/src/main/resources/reports/CPA.rptdesign create mode 100644 modules/axelor-open-suite/axelor-account/src/main/resources/reports/SGA.rptdesign create mode 100644 modules/axelor-open-suite/axelor-base/src/main/java/com/axelor/apps/base/service/ConvertNumberToFrenchWordsService.java create mode 100644 modules/axelor-open-suite/axelor-base/src/main/java/com/axelor/apps/base/service/ConvertNumberToFrenchWordsServiceImpl.java 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 ddd080b..b8a9443 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 @@ -59,6 +59,8 @@ import com.axelor.meta.schema.actions.ActionView.ActionViewBuilder; import com.axelor.rpc.ActionRequest; import com.axelor.rpc.ActionResponse; import com.axelor.rpc.Context; +import com.axelor.apps.base.service.ConvertNumberToFrenchWordsService; +import com.axelor.apps.ReportFactory; import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.inject.Singleton; @@ -68,6 +70,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.HashMap; import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; @@ -952,4 +955,38 @@ public class InvoiceController { } response.setAttr("partner", "domain", domain); } + + public void printInvoicePayment(ActionRequest request, ActionResponse response) + throws AxelorException { + + InvoicePayment invoicePayment = request.getContext().asType(InvoicePayment.class); + + String name = I18n.get("Payment voucher"); + String AmountToPay = invoicePayment.getAmount().toString(); + String[] arrOfStr = AmountToPay.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+" centimes"; + String chequeModelBank = request.getContext().get("chequeModelBank").toString(); + + Map Report = new HashMap(); + Report.put("CPA", "CPA.rptdesign"); + Report.put("ASB", "ASB.rptdesign"); + Report.put("BDL", "BDL.rptdesign"); + Report.put("SGA", "SGA.rptdesign"); + Report.put("BNA", "BNA.rptdesign"); + + String fileLink = + ReportFactory.createReport(Report.get(chequeModelBank), name + "-${date}") + .addParam("PaymentVoucherId", invoicePayment.getId()) + .addParam("NumberToWords", number) + .addParam("Wilaya", request.getContext().get("wilaya")) + .generate() + .getFileLink(); + + logger.debug("Printing " + name); + + response.setView(ActionView.define(name).add("html", fileLink).map()); + } } diff --git a/modules/axelor-open-suite/axelor-account/src/main/resources/domains/InvoicePayment.xml b/modules/axelor-open-suite/axelor-account/src/main/resources/domains/InvoicePayment.xml index 38591c4..2e108b6 100644 --- a/modules/axelor-open-suite/axelor-account/src/main/resources/domains/InvoicePayment.xml +++ b/modules/axelor-open-suite/axelor-account/src/main/resources/domains/InvoicePayment.xml @@ -32,6 +32,9 @@ + + + diff --git a/modules/axelor-open-suite/axelor-account/src/main/resources/reports/ASB.rptdesign b/modules/axelor-open-suite/axelor-account/src/main/resources/reports/ASB.rptdesign new file mode 100644 index 0000000..00af465 --- /dev/null +++ b/modules/axelor-open-suite/axelor-account/src/main/resources/reports/ASB.rptdesign @@ -0,0 +1,386 @@ + + + Eclipse BIRT Designer Version 4.8.0.v201806261756 + + + odaURL + 209 + params["DBName"].value + + + odaUser + 209 + params["UserName"].value + + + odaPassword + 209 + params["Password"].value + + + queryText + 3740 + + + queryTimeOut + 3740 + + + rowFetchSize + 3740 + + + in + /templates/blank_report.gif + auto layout + ltr + 96 + + + true + static + true + decimal + true + + simple + false + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + false + string + true + + fr + + + simple + false + text-box + + Unformatted + + + + false + static + string + true + + simple + text-box + + Unformatted + + + + static + string + true + + simple + text-box + + Unformatted + + + + + + + + disabledMetadataBidiFormatStr + + + disabledContentBidiFormatStr + + + contentBidiFormatStr + ILYNN + + + metadataBidiFormatStr + ILYNN + + + org.postgresql.Driver + jdbc:postgresql://localhost:5432/ + + + + + + + amount + measure + amount + amount + + + name + dimension + name + name + + + date + dimension + date + date + + + + + param_1 + PaymentVoucherId + + decimal + -5 + 1 + true + false + + + + + + 1 + amount + decimal + + + 2 + name + string + + + 3 + date + date + + + + Data Source + + + 1 + amount + amount + decimal + 2 + + + 2 + name + name + string + 12 + + + 3 + date + date + date + 91 + + + + + + + + + + + + + 0.16666666666666666in + 0.15625in + 0cm + 3cm + + + + + 12pt + black + none + none + none + none + 1.6979166666666667in + 8.145833333333334in + AccountInvoicePayment + + + amount + amount + dataSetRow["amount"] + decimal + + + name + name + dataSetRow["name"] + string + + + date + date + dataSetRow["date"] + date + + + + 2.75in + + + 1.7395833333333333in + + + 1.125in + + + 2.53125in + + + 0.3125in + + + + + + 14px + right + html + row["amount"]]]> + + + + + 0.4895833333333333in + + 4 + 1 + none + none + none + none + + html + params["NumberToWords"]]]> + + + + + 0.3125in + + 4 + 1 + + html + row["name"]]]> + + + + + + + 2 + 1 + + right + html + params["Wilaya"]]]> + + + + + 12pt + right + html + row["date"]]]> + + + + + + diff --git a/modules/axelor-open-suite/axelor-account/src/main/resources/reports/BDL.rptdesign b/modules/axelor-open-suite/axelor-account/src/main/resources/reports/BDL.rptdesign new file mode 100644 index 0000000..00af465 --- /dev/null +++ b/modules/axelor-open-suite/axelor-account/src/main/resources/reports/BDL.rptdesign @@ -0,0 +1,386 @@ + + + Eclipse BIRT Designer Version 4.8.0.v201806261756 + + + odaURL + 209 + params["DBName"].value + + + odaUser + 209 + params["UserName"].value + + + odaPassword + 209 + params["Password"].value + + + queryText + 3740 + + + queryTimeOut + 3740 + + + rowFetchSize + 3740 + + + in + /templates/blank_report.gif + auto layout + ltr + 96 + + + true + static + true + decimal + true + + simple + false + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + false + string + true + + fr + + + simple + false + text-box + + Unformatted + + + + false + static + string + true + + simple + text-box + + Unformatted + + + + static + string + true + + simple + text-box + + Unformatted + + + + + + + + disabledMetadataBidiFormatStr + + + disabledContentBidiFormatStr + + + contentBidiFormatStr + ILYNN + + + metadataBidiFormatStr + ILYNN + + + org.postgresql.Driver + jdbc:postgresql://localhost:5432/ + + + + + + + amount + measure + amount + amount + + + name + dimension + name + name + + + date + dimension + date + date + + + + + param_1 + PaymentVoucherId + + decimal + -5 + 1 + true + false + + + + + + 1 + amount + decimal + + + 2 + name + string + + + 3 + date + date + + + + Data Source + + + 1 + amount + amount + decimal + 2 + + + 2 + name + name + string + 12 + + + 3 + date + date + date + 91 + + + + + + + + + + + + + 0.16666666666666666in + 0.15625in + 0cm + 3cm + + + + + 12pt + black + none + none + none + none + 1.6979166666666667in + 8.145833333333334in + AccountInvoicePayment + + + amount + amount + dataSetRow["amount"] + decimal + + + name + name + dataSetRow["name"] + string + + + date + date + dataSetRow["date"] + date + + + + 2.75in + + + 1.7395833333333333in + + + 1.125in + + + 2.53125in + + + 0.3125in + + + + + + 14px + right + html + row["amount"]]]> + + + + + 0.4895833333333333in + + 4 + 1 + none + none + none + none + + html + params["NumberToWords"]]]> + + + + + 0.3125in + + 4 + 1 + + html + row["name"]]]> + + + + + + + 2 + 1 + + right + html + params["Wilaya"]]]> + + + + + 12pt + right + html + row["date"]]]> + + + + + + diff --git a/modules/axelor-open-suite/axelor-account/src/main/resources/reports/BNA.rptdesign b/modules/axelor-open-suite/axelor-account/src/main/resources/reports/BNA.rptdesign new file mode 100644 index 0000000..00af465 --- /dev/null +++ b/modules/axelor-open-suite/axelor-account/src/main/resources/reports/BNA.rptdesign @@ -0,0 +1,386 @@ + + + Eclipse BIRT Designer Version 4.8.0.v201806261756 + + + odaURL + 209 + params["DBName"].value + + + odaUser + 209 + params["UserName"].value + + + odaPassword + 209 + params["Password"].value + + + queryText + 3740 + + + queryTimeOut + 3740 + + + rowFetchSize + 3740 + + + in + /templates/blank_report.gif + auto layout + ltr + 96 + + + true + static + true + decimal + true + + simple + false + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + false + string + true + + fr + + + simple + false + text-box + + Unformatted + + + + false + static + string + true + + simple + text-box + + Unformatted + + + + static + string + true + + simple + text-box + + Unformatted + + + + + + + + disabledMetadataBidiFormatStr + + + disabledContentBidiFormatStr + + + contentBidiFormatStr + ILYNN + + + metadataBidiFormatStr + ILYNN + + + org.postgresql.Driver + jdbc:postgresql://localhost:5432/ + + + + + + + amount + measure + amount + amount + + + name + dimension + name + name + + + date + dimension + date + date + + + + + param_1 + PaymentVoucherId + + decimal + -5 + 1 + true + false + + + + + + 1 + amount + decimal + + + 2 + name + string + + + 3 + date + date + + + + Data Source + + + 1 + amount + amount + decimal + 2 + + + 2 + name + name + string + 12 + + + 3 + date + date + date + 91 + + + + + + + + + + + + + 0.16666666666666666in + 0.15625in + 0cm + 3cm + + + + + 12pt + black + none + none + none + none + 1.6979166666666667in + 8.145833333333334in + AccountInvoicePayment + + + amount + amount + dataSetRow["amount"] + decimal + + + name + name + dataSetRow["name"] + string + + + date + date + dataSetRow["date"] + date + + + + 2.75in + + + 1.7395833333333333in + + + 1.125in + + + 2.53125in + + + 0.3125in + + + + + + 14px + right + html + row["amount"]]]> + + + + + 0.4895833333333333in + + 4 + 1 + none + none + none + none + + html + params["NumberToWords"]]]> + + + + + 0.3125in + + 4 + 1 + + html + row["name"]]]> + + + + + + + 2 + 1 + + right + html + params["Wilaya"]]]> + + + + + 12pt + right + html + row["date"]]]> + + + + + + diff --git a/modules/axelor-open-suite/axelor-account/src/main/resources/reports/CPA.rptdesign b/modules/axelor-open-suite/axelor-account/src/main/resources/reports/CPA.rptdesign new file mode 100644 index 0000000..00af465 --- /dev/null +++ b/modules/axelor-open-suite/axelor-account/src/main/resources/reports/CPA.rptdesign @@ -0,0 +1,386 @@ + + + Eclipse BIRT Designer Version 4.8.0.v201806261756 + + + odaURL + 209 + params["DBName"].value + + + odaUser + 209 + params["UserName"].value + + + odaPassword + 209 + params["Password"].value + + + queryText + 3740 + + + queryTimeOut + 3740 + + + rowFetchSize + 3740 + + + in + /templates/blank_report.gif + auto layout + ltr + 96 + + + true + static + true + decimal + true + + simple + false + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + false + string + true + + fr + + + simple + false + text-box + + Unformatted + + + + false + static + string + true + + simple + text-box + + Unformatted + + + + static + string + true + + simple + text-box + + Unformatted + + + + + + + + disabledMetadataBidiFormatStr + + + disabledContentBidiFormatStr + + + contentBidiFormatStr + ILYNN + + + metadataBidiFormatStr + ILYNN + + + org.postgresql.Driver + jdbc:postgresql://localhost:5432/ + + + + + + + amount + measure + amount + amount + + + name + dimension + name + name + + + date + dimension + date + date + + + + + param_1 + PaymentVoucherId + + decimal + -5 + 1 + true + false + + + + + + 1 + amount + decimal + + + 2 + name + string + + + 3 + date + date + + + + Data Source + + + 1 + amount + amount + decimal + 2 + + + 2 + name + name + string + 12 + + + 3 + date + date + date + 91 + + + + + + + + + + + + + 0.16666666666666666in + 0.15625in + 0cm + 3cm + + + + + 12pt + black + none + none + none + none + 1.6979166666666667in + 8.145833333333334in + AccountInvoicePayment + + + amount + amount + dataSetRow["amount"] + decimal + + + name + name + dataSetRow["name"] + string + + + date + date + dataSetRow["date"] + date + + + + 2.75in + + + 1.7395833333333333in + + + 1.125in + + + 2.53125in + + + 0.3125in + + + + + + 14px + right + html + row["amount"]]]> + + + + + 0.4895833333333333in + + 4 + 1 + none + none + none + none + + html + params["NumberToWords"]]]> + + + + + 0.3125in + + 4 + 1 + + html + row["name"]]]> + + + + + + + 2 + 1 + + right + html + params["Wilaya"]]]> + + + + + 12pt + right + html + row["date"]]]> + + + + + + diff --git a/modules/axelor-open-suite/axelor-account/src/main/resources/reports/SGA.rptdesign b/modules/axelor-open-suite/axelor-account/src/main/resources/reports/SGA.rptdesign new file mode 100644 index 0000000..00af465 --- /dev/null +++ b/modules/axelor-open-suite/axelor-account/src/main/resources/reports/SGA.rptdesign @@ -0,0 +1,386 @@ + + + Eclipse BIRT Designer Version 4.8.0.v201806261756 + + + odaURL + 209 + params["DBName"].value + + + odaUser + 209 + params["UserName"].value + + + odaPassword + 209 + params["Password"].value + + + queryText + 3740 + + + queryTimeOut + 3740 + + + rowFetchSize + 3740 + + + in + /templates/blank_report.gif + auto layout + ltr + 96 + + + true + static + true + decimal + true + + simple + false + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + string + true + + simple + text-box + + Unformatted + + + + true + static + false + string + true + + fr + + + simple + false + text-box + + Unformatted + + + + false + static + string + true + + simple + text-box + + Unformatted + + + + static + string + true + + simple + text-box + + Unformatted + + + + + + + + disabledMetadataBidiFormatStr + + + disabledContentBidiFormatStr + + + contentBidiFormatStr + ILYNN + + + metadataBidiFormatStr + ILYNN + + + org.postgresql.Driver + jdbc:postgresql://localhost:5432/ + + + + + + + amount + measure + amount + amount + + + name + dimension + name + name + + + date + dimension + date + date + + + + + param_1 + PaymentVoucherId + + decimal + -5 + 1 + true + false + + + + + + 1 + amount + decimal + + + 2 + name + string + + + 3 + date + date + + + + Data Source + + + 1 + amount + amount + decimal + 2 + + + 2 + name + name + string + 12 + + + 3 + date + date + date + 91 + + + + + + + + + + + + + 0.16666666666666666in + 0.15625in + 0cm + 3cm + + + + + 12pt + black + none + none + none + none + 1.6979166666666667in + 8.145833333333334in + AccountInvoicePayment + + + amount + amount + dataSetRow["amount"] + decimal + + + name + name + dataSetRow["name"] + string + + + date + date + dataSetRow["date"] + date + + + + 2.75in + + + 1.7395833333333333in + + + 1.125in + + + 2.53125in + + + 0.3125in + + + + + + 14px + right + html + row["amount"]]]> + + + + + 0.4895833333333333in + + 4 + 1 + none + none + none + none + + html + params["NumberToWords"]]]> + + + + + 0.3125in + + 4 + 1 + + html + row["name"]]]> + + + + + + + 2 + 1 + + right + html + params["Wilaya"]]]> + + + + + 12pt + right + html + row["date"]]]> + + + + + + diff --git a/modules/axelor-open-suite/axelor-account/src/main/resources/views/Selects.xml b/modules/axelor-open-suite/axelor-account/src/main/resources/views/Selects.xml index 43d2511..03885fe 100644 --- a/modules/axelor-open-suite/axelor-account/src/main/resources/views/Selects.xml +++ b/modules/axelor-open-suite/axelor-account/src/main/resources/views/Selects.xml @@ -434,5 +434,13 @@ + + + + + + + + diff --git a/modules/axelor-open-suite/axelor-base/src/main/java/com/axelor/apps/base/module/BaseModule.java b/modules/axelor-open-suite/axelor-base/src/main/java/com/axelor/apps/base/module/BaseModule.java index 56ed36a..b7e017d 100644 --- a/modules/axelor-open-suite/axelor-base/src/main/java/com/axelor/apps/base/module/BaseModule.java +++ b/modules/axelor-open-suite/axelor-base/src/main/java/com/axelor/apps/base/module/BaseModule.java @@ -128,11 +128,14 @@ import com.axelor.auth.db.repo.UserRepository; import com.axelor.base.service.ical.ICalendarEventService; import com.axelor.base.service.ical.ICalendarEventServiceImpl; import com.axelor.team.db.repo.TeamTaskRepository; +import com.axelor.apps.base.service.ConvertNumberToFrenchWordsService; +import com.axelor.apps.base.service.ConvertNumberToFrenchWordsServiceImpl; public class BaseModule extends AxelorModule { @Override protected void configure() { + bind(ConvertNumberToFrenchWordsService.class).to(ConvertNumberToFrenchWordsServiceImpl.class); bind(SophalService.class).to(SophalServiceImpl.class); bind(AddressService.class).to(AddressServiceImpl.class); bind(AdvancedExportService.class).to(AdvancedExportServiceImpl.class); diff --git a/modules/axelor-open-suite/axelor-base/src/main/java/com/axelor/apps/base/service/ConvertNumberToFrenchWordsService.java b/modules/axelor-open-suite/axelor-base/src/main/java/com/axelor/apps/base/service/ConvertNumberToFrenchWordsService.java new file mode 100644 index 0000000..d2eacfc --- /dev/null +++ b/modules/axelor-open-suite/axelor-base/src/main/java/com/axelor/apps/base/service/ConvertNumberToFrenchWordsService.java @@ -0,0 +1,26 @@ +/* + * Axelor Business Solutions + * + * Copyright (C) 2020 Axelor (). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package com.axelor.apps.base.service; + + + +public interface ConvertNumberToFrenchWordsService { + + public String convert(long number); +} + diff --git a/modules/axelor-open-suite/axelor-base/src/main/java/com/axelor/apps/base/service/ConvertNumberToFrenchWordsServiceImpl.java b/modules/axelor-open-suite/axelor-base/src/main/java/com/axelor/apps/base/service/ConvertNumberToFrenchWordsServiceImpl.java new file mode 100644 index 0000000..6aa5e85 --- /dev/null +++ b/modules/axelor-open-suite/axelor-base/src/main/java/com/axelor/apps/base/service/ConvertNumberToFrenchWordsServiceImpl.java @@ -0,0 +1,217 @@ +/* + * Axelor Business Solutions + * + * Copyright (C) 2020 Axelor (). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package com.axelor.apps.base.service; + +import java.text.DecimalFormat; + +public class ConvertNumberToFrenchWordsServiceImpl implements ConvertNumberToFrenchWordsService { + + private final String[] dizaineNames = { "", // + "", // + "vingt", // + "trente", // + "quarante", // + "cinquante", // + "soixante", // + "soixante", // + "quatre-vingt", // + "quatre-vingt" // + }; + + private final String[] uniteNames1 = { "", // + "un", // + "deux", // + "trois", // + "quatre", // + "cinq", // + "six", // + "sept", // + "huit", // + "neuf", // + "dix", // + "onze", // + "douze", // + "treize", // + "quatorze", // + "quinze", // + "seize", // + "dix-sept", // + "dix-huit", // + "dix-neuf" // + }; + + private final String[] uniteNames2 = { "", // + "", // + "deux", // + "trois", // + "quatre", // + "cinq", // + "six", // + "sept", // + "huit", // + "neuf", // + "dix" // + }; + + + + private String convertZeroToHundred(int number) { + + int laDizaine = number / 10; + int lUnite = number % 10; + String resultat = ""; + + switch (laDizaine) { + case 1: + case 7: + case 9: + lUnite = lUnite + 10; + break; + default: + } + + String laLiaison = ""; + if (laDizaine > 1) { + laLiaison = "-"; + } + switch (lUnite) { + case 0: + laLiaison = ""; + break; + case 1: + if (laDizaine == 8) { + laLiaison = "-"; + } else { + laLiaison = " et "; + } + break; + case 11: + if (laDizaine == 7) { + laLiaison = " et "; + } + break; + default: + } + + // dizaines en lettres + switch (laDizaine) { + case 0: + resultat = uniteNames1[lUnite]; + break; + case 8: + if (lUnite == 0) { + resultat = dizaineNames[laDizaine]; + } else { + resultat = dizaineNames[laDizaine] + laLiaison + uniteNames1[lUnite]; + } + break; + default: + resultat = dizaineNames[laDizaine] + laLiaison + uniteNames1[lUnite]; + } + return resultat; + } + + private String convertLessThanOneThousand(int number) { + + int lesCentaines = number / 100; + int leReste = number % 100; + String sReste = convertZeroToHundred(leReste); + + String resultat; + switch (lesCentaines) { + case 0: + resultat = sReste; + break; + case 1: + if (leReste > 0) { + resultat = "cent " + sReste; + } else { + resultat = "cent"; + } + break; + default: + if (leReste > 0) { + resultat = uniteNames2[lesCentaines] + " cent " + sReste; + } else { + resultat = uniteNames2[lesCentaines] + " cents"; + } + } + return resultat; + } + + public String convert(long number) { + if (number == 0) { + return "zero"; + } + + String snumber = Long.toString(number); + String mask = "000000000000"; + DecimalFormat df = new DecimalFormat(mask); + snumber = df.format(number); + + int lesMilliards = Integer.parseInt(snumber.substring(0, 3)); + int lesMillions = Integer.parseInt(snumber.substring(3, 6)); + int lesCentMille = Integer.parseInt(snumber.substring(6, 9)); + int lesMille = Integer.parseInt(snumber.substring(9, 12)); + + String tradMilliards; + switch (lesMilliards) { + case 0: + tradMilliards = ""; + break; + case 1: + tradMilliards = convertLessThanOneThousand(lesMilliards) + " milliard "; + break; + default: + tradMilliards = convertLessThanOneThousand(lesMilliards) + " milliards "; + } + String resultat = tradMilliards; + + String tradMillions; + switch (lesMillions) { + case 0: + tradMillions = ""; + break; + case 1: + tradMillions = convertLessThanOneThousand(lesMillions) + " million "; + break; + default: + tradMillions = convertLessThanOneThousand(lesMillions) + " millions "; + } + resultat = resultat + tradMillions; + + String tradCentMille; + switch (lesCentMille) { + case 0: + tradCentMille = ""; + break; + case 1: + tradCentMille = "mille "; + break; + default: + tradCentMille = convertLessThanOneThousand(lesCentMille) + " mille "; + } + resultat = resultat + tradCentMille; + + String tradMille; + tradMille = convertLessThanOneThousand(lesMille); + resultat = resultat + tradMille; + + return resultat; + } +}