From 37d2b73de835d446362eeb78837367015d728080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Sat, 3 Feb 2024 21:43:40 +0100 Subject: [PATCH 1/2] add number to words --- composer.json | 4 +- composer.lock | 123 ++++++++++- .../doc/doc_easydoc_order_html.modules.php | 37 +++- .../doc/doc_easydoc_invoice_html.modules.php | 204 ++++++++++++------ lib/easydocgenerator.lib.php | 9 +- 5 files changed, 295 insertions(+), 82 deletions(-) diff --git a/composer.json b/composer.json index 3f51da3..db1725f 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,8 @@ "php": ">=7.4", "mpdf/mpdf": "^8.2", "twig/twig": "^3.0", - "horstoeko/zugferd":"^1" + "horstoeko/zugferd":"^1", + "mpdf/qrcode": "^1.2", + "kwn/number-to-words": "^2.8" } } diff --git a/composer.lock b/composer.lock index f023ef1..16f5b88 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "67f97a6c7c4ffa9758173c1bde19535d", + "content-hash": "a0f6261497dcb719037174d7a06ea281", "packages": [ { "name": "doctrine/annotations", @@ -679,6 +679,59 @@ ], "time": "2023-12-14T15:25:09+00:00" }, + { + "name": "kwn/number-to-words", + "version": "2.8.0", + "source": { + "type": "git", + "url": "https://github.com/kwn/number-to-words.git", + "reference": "cfab3d833713d9b0c61d473b07bf1d45116aa555" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/kwn/number-to-words/zipball/cfab3d833713d9b0c61d473b07bf1d45116aa555", + "reference": "cfab3d833713d9b0c61d473b07bf1d45116aa555", + "shasum": "" + }, + "require": { + "php": ">=7.4" + }, + "require-dev": { + "phpunit/phpunit": "^9.6.7", + "squizlabs/php_codesniffer": "^3.7.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "NumberToWords\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Karol Wnuk", + "email": "k.wnuk@ascetic.pl" + } + ], + "description": "Multi language standalone PHP number to words converter. Fully tested, open for extensions and new languages.", + "keywords": [ + "currency", + "money", + "number", + "numbers", + "string", + "to", + "words" + ], + "support": { + "issues": "https://github.com/kwn/number-to-words/issues", + "source": "https://github.com/kwn/number-to-words/tree/2.8.0" + }, + "time": "2023-12-04T17:56:32+00:00" + }, { "name": "mpdf/mpdf", "version": "v8.2.2", @@ -852,6 +905,74 @@ }, "time": "2023-05-03T06:18:28+00:00" }, + { + "name": "mpdf/qrcode", + "version": "v1.2.0", + "source": { + "type": "git", + "url": "https://github.com/mpdf/qrcode.git", + "reference": "0c09fce8b28707611c3febdd1ca424d40f172184" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mpdf/qrcode/zipball/0c09fce8b28707611c3febdd1ca424d40f172184", + "reference": "0c09fce8b28707611c3febdd1ca424d40f172184", + "shasum": "" + }, + "require": { + "paragonie/random_compat": "^1.4|^2.0|^9.99.99", + "php": "^5.6 || ^7.0 || ^8.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.5", + "squizlabs/php_codesniffer": "^3.4", + "tracy/tracy": "^2.5", + "yoast/phpunit-polyfills": "^1.0" + }, + "suggest": { + "ext-gd": "To output QR codes to PNG files", + "ext-simplexml": "To output QR codes to SVG files" + }, + "type": "library", + "autoload": { + "psr-4": { + "Mpdf\\QrCode\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1-or-later" + ], + "authors": [ + { + "name": "Matěj Humpál", + "role": "maintainer" + }, + { + "name": "Laurent Minguet", + "role": "author" + } + ], + "description": "QR code generator for mPDF", + "keywords": [ + "mpdf", + "pdf", + "php", + "qr", + "qrcode" + ], + "support": { + "issues": "https://github.com/mpdf/qrcode/issues", + "source": "https://github.com/mpdf/qrcode/tree/v1.2.0" + }, + "funding": [ + { + "url": "https://www.paypal.me/mpdf", + "type": "custom" + } + ], + "time": "2022-01-11T09:42:41+00:00" + }, { "name": "myclabs/deep-copy", "version": "1.11.1", diff --git a/core/modules/commande/doc/doc_easydoc_order_html.modules.php b/core/modules/commande/doc/doc_easydoc_order_html.modules.php index c14ca44..fc45fe9 100644 --- a/core/modules/commande/doc/doc_easydoc_order_html.modules.php +++ b/core/modules/commande/doc/doc_easydoc_order_html.modules.php @@ -253,7 +253,6 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails global $action; $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks - require dol_buildpath('easydocgenerator/vendor/autoload.php'); $loader = new \Twig\Loader\FilesystemLoader(dirname($srctemplatepath)); @@ -264,15 +263,28 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails ]); // create twig function which translate with $outpulangs->trans() $function = new \Twig\TwigFunction('trans', function ($value) { - global $outputlangs; + global $outputlangs, $langs; + if (!is_object($outputlangs)) { + $outputlangs = $langs; + } return $outputlangs->trans($value); }); $twig->addFunction($function); - // create twig function which translate with getDolGlobalString( + // create twig function which returns getDolGlobalString( $function = new \Twig\TwigFunction('getDolGlobalString', function ($value, $default = '') { return getDolGlobalString($value, $default); }); $twig->addFunction($function); + // create twig function which return date formatted + $function = new \Twig\TwigFunction('date', function ($time, $format = '') { + return dol_print_date($time, $format); + }); + $twig->addFunction($function); + // create twig function which return price formatted + $function = new \Twig\TwigFunction('price', function ($price) { + return price($price, 0); + }); + $twig->addFunction($function); try { $template = $twig->load(basename($srctemplatepath)); } catch (\Twig\Error\SyntaxError $e) { @@ -426,6 +438,8 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails 'labelpaymentconditions' => $label_payment_conditions, 'currencyinfo' => $outputlangs->trans("AmountInCurrency", $outputlangs->trans("Currency" . $currency)), ]; + // var_dump($substitutions); + $substitutions['debug'] = '
' . print_r($substitutions, true) . '
'; $subtotal_ht = 0; $subtotal_ttc = 0; $linenumber = 1; @@ -461,10 +475,15 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails } // var_dump($substitutions); - - $html = $template->render($substitutions); + try { + $html = $template->render($substitutions); + } catch (Exception $e) { + $this->errors[] = $e->getMessage(); + return -1; + } // print $html; $mpdf = new \Mpdf\Mpdf([ + 'format' => [210, 297], 'margin_left' => getDolGlobalInt('EASYDOC_PDF_MARGIN_LEFT', 10), 'margin_right' => getDolGlobalInt('EASYDOC_PDF_MARGIN_RIGHT', 10), 'margin_top' => getDolGlobalInt('EASYDOC_PDF_MARGIN_TOP', 48), @@ -476,8 +495,12 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails $mpdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); $mpdf->SetCreator('Dolibarr ' . DOL_VERSION); $mpdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); - $mpdf->SetWatermarkText(getDolGlobalString('COMMANDE_DRAFT_WATERMARK')); - + // Watermark + $text = getDolGlobalString('COMMANDE_DRAFT_WATERMARK'); + $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, null); + complete_substitutions_array($substitutionarray, $outputlangs, null); + $text = make_substitutions($text, $substitutionarray, $outputlangs); + $mpdf->SetWatermarkText($text); $mpdf->showWatermarkText = ($object->statut == Commande::STATUS_DRAFT && getDolGlobalString('COMMANDE_DRAFT_WATERMARK')); $mpdf->watermark_font = 'DejaVuSansCondensed'; $mpdf->watermarkTextAlpha = 0.1; diff --git a/core/modules/facture/doc/doc_easydoc_invoice_html.modules.php b/core/modules/facture/doc/doc_easydoc_invoice_html.modules.php index a4d845c..0b4ff81 100644 --- a/core/modules/facture/doc/doc_easydoc_invoice_html.modules.php +++ b/core/modules/facture/doc/doc_easydoc_invoice_html.modules.php @@ -22,7 +22,7 @@ */ /** - * \file htdocs/core/modules/facture/doc/doc_easydoc_order_html.modules.php + * \file htdocs/core/modules/facture/doc/doc_easydoc_invoice_html.modules.php * \ingroup facture * \brief File of class to build PDF documents for invoices */ @@ -218,14 +218,24 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails global $user, $langs, $conf, $mysoc, $hookmanager; if (empty($srctemplatepath)) { - dol_syslog("doc_easydoc_order_html::write_file parameter srctemplatepath empty", LOG_WARNING); + dol_syslog("doc_easydoc_invoice_html::write_file parameter srctemplatepath empty", LOG_WARNING); return -1; } + $object->fetch_thirdparty(); + if (!is_object($outputlangs)) { $outputlangs = $langs; } - $object->fetch_thirdparty(); + $outputlangs->loadLangs(['main', 'dict', 'companies', 'bills', 'products', 'orders', 'deliveries', 'banks']); + + global $outputlangsbis; + $outputlangsbis = null; + if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) { + $outputlangsbis = new Translate('', $conf); + $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')); + $outputlangsbis->loadLangs(array('main', 'dict', 'companies', 'bills', 'products', 'orders', 'deliveries', 'banks')); + } // add linked objects to note_public $linkedObjects = pdf_getLinkedObjects($object, $outputlangs); @@ -240,7 +250,6 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails $outputlangs->charset_output = 'ISO-8859-1'; } - $outputlangs->loadLangs(["main", "dict", "companies", "bills", "products", "orders", "deliveries"]); $currency = !empty($currency) ? $currency : $conf->currency; // Add pdfgeneration hook @@ -263,15 +272,37 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails ]); // create twig function which translate with $outpulangs->trans() $function = new \Twig\TwigFunction('trans', function ($value) { - global $outputlangs; + global $outputlangs, $langs; + if (!is_object($outputlangs)) { + $outputlangs = $langs; + } return $outputlangs->trans($value); }); $twig->addFunction($function); - // create twig function which translate with getDolGlobalString( + // create twig function which translate with $outpulangsbis->trans() + $function = new \Twig\TwigFunction('transbis', function ($value) { + global $outputlangsbis, $langs; + if (!is_object($outputlangsbis)) { + $outputlangsbis = $langs; + } + return $outputlangsbis->trans($value); + }); + $twig->addFunction($function); + // create twig function which returns getDolGlobalString( $function = new \Twig\TwigFunction('getDolGlobalString', function ($value, $default = '') { return getDolGlobalString($value, $default); }); $twig->addFunction($function); + // create twig function which return date formatted + $function = new \Twig\TwigFunction('date', function ($time, $format = '') { + return dol_print_date($time, $format); + }); + $twig->addFunction($function); + // create twig function which return price formatted + $function = new \Twig\TwigFunction('price', function ($price) { + return price($price, 0); + }); + $twig->addFunction($function); try { $template = $twig->load(basename($srctemplatepath)); } catch (\Twig\Error\SyntaxError $e) { @@ -319,7 +350,7 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails $label_payment_conditions = str_replace('__DEPOSIT_PERCENT__', $object->deposit_percent, $label_payment_conditions); } } - // If CUSTOMER contact defined on order, we use it + // If CUSTOMER contact defined on invoice, we use it $usecontact = false; $arrayidcontact = $object->getIdContact('external', 'CUSTOMER'); if (count($arrayidcontact) > 0) { @@ -365,60 +396,23 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails if (!empty($conf->global->$paramfreetext)) { $newfreetext = make_substitutions(getDolGlobalString($paramfreetext), $substitutionarray); } - // todo - // $test = getEachVarObject($object, $outputlangs); - // var_dump($test); - $substitutions = [ - 'mysoc' => [ - 'name' => $mysoc->name, - 'name_alias' => $mysoc->name_alias, - 'address' => $mysoc->address, - 'zip' => $mysoc->zip, - 'town' => $mysoc->town, - 'country' => $mysoc->country, - 'flag' => DOL_DOCUMENT_ROOT . '/theme/common/flags/' . strtolower($flagImage) . '.png', - 'phone' => dol_print_phone($mysoc->phone, $mysoc->country_code, 0, 0, '', ' '), - 'fax' => dol_print_phone($mysoc->fax, $mysoc->country_code, 0, 0, '', ' '), - 'email' => $mysoc->email, - 'idprof1' => $mysoc->idprof1, - 'idprof2' => $mysoc->idprof2, - 'idprof3' => $mysoc->idprof3, - 'idprof4' => $mysoc->idprof4, - 'idprof5' => $mysoc->idprof5, - 'idprof6' => $mysoc->idprof6, - 'capital' => $mysoc->capital, - 'tvanumber' => $mysoc->tva_intra, - ], - 'thirdparty' => [ - 'name' => $object->thirdparty->name, - 'name_alias' => $object->thirdparty->name_alias, - 'address' => $object->thirdparty->address, - 'zip' => $object->thirdparty->zip, - 'town' => $object->thirdparty->town, - 'country' => $object->thirdparty->country, - 'flag' => DOL_DOCUMENT_ROOT . '/theme/common/flags/' . strtolower($object->thirdparty->country_code) . '.png', - 'phone' => dol_print_phone($object->thirdparty->phone, $object->thirdparty->country_code, 0, 0, '', ' '), - 'fax' => dol_print_phone($object->thirdparty->fax, $object->thirdparty->country_code, 0, 0, '', ' '), - 'email' => $object->thirdparty->email, - 'idprof1' => $object->thirdparty->idprof1, - 'idprof2' => $object->thirdparty->idprof2, - 'idprof3' => $object->thirdparty->idprof3, - 'idprof4' => $object->thirdparty->idprof4, - 'idprof5' => $object->thirdparty->idprof5, - 'idprof6' => $object->thirdparty->idprof6, - 'capital' => $object->thirdparty->capital, - 'code_client' => $object->thirdparty->code_client, - ], - 'object' => [ - 'date' => dol_print_date($object->date, "day", false, $outputlangs, true), - 'ref' => $object->ref, - 'note_public' => $object->note_public, - 'note_private' => $object->note_private, - 'total_tva' => price($object->total_tva), - 'total_ht' => price($object->total_ht), - 'total_ttc' => price($object->total_ttc), - 'ref_customer' => $outputlangs->convToOutputCharset($object->ref_client), - ], + // mysoc + $substitutions = getEachVarObject($mysoc, $outputlangs, 1, 'mysoc'); + $substitutions['mysoc']['flag'] = DOL_DOCUMENT_ROOT . '/theme/common/flags/' . strtolower($flagImage) . '.png'; + $substitutions['mysoc']['phone_formatted'] = dol_print_phone($mysoc->phone, $mysoc->country_code, 0, 0, '', ' '); + $substitutions['mysoc']['fax_formatted'] = dol_print_phone($mysoc->fax, $mysoc->country_code, 0, 0, '', ' '); + + // object + $substitutions = array_merge($substitutions, getEachVarObject($object, $outputlangs, 0)); + + // thirdparty + $substitutions = array_merge($substitutions, getEachVarObject($object->thirdparty, $outputlangs, 1, 'thirdparty')); + $substitutions['thirdparty']['flag'] = DOL_DOCUMENT_ROOT . '/theme/common/flags/' . strtolower($object->thirdparty->country_code) . '.png'; + $substitutions['thirdparty']['phone_formatted'] = dol_print_phone($object->thirdparty->phone, $object->thirdparty->country_code, 0, 0, '', ' '); + $substitutions['thirdparty']['fax_formatted'] = dol_print_phone($object->thirdparty->fax, $object->thirdparty->country_code, 0, 0, '', ' '); + + // other + $substitutions = array_merge($substitutions, [ 'logo' => $logo, 'freetext' => $newfreetext, 'lines' => [], @@ -426,8 +420,7 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails 'footerinfo' => getPdfPagefoot($outputlangs, $paramfreetext, $mysoc, $object), 'labelpaymentconditions' => $label_payment_conditions, 'currencyinfo' => $outputlangs->trans("AmountInCurrency", $outputlangs->trans("Currency" . $currency)), - ]; - $substitutions['debug'] = '
' . print_r($substitutions, true) . '
'; + ]); $subtotal_ht = 0; $subtotal_ttc = 0; $linenumber = 1; @@ -461,12 +454,85 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails $linenumber++; } } - + $substitutions['discounts'] = []; + // Loop on each discount available (deposits and credit notes and excess of payment included) + $sql = "SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva, re.amount_ttc, re.multicurrency_amount_ttc,"; + $sql .= " re.description, re.fk_facture_source,"; + $sql .= " f.type, f.datef"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f"; + $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id); + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + $i = 0; + $invoice = new Facture($this->db); + while ($i < $num) { + $obj = $this->db->fetch_object($resql); + if ($obj->type == 2) { + $text = "CreditNote"; + } elseif ($obj->type == 3) { + $text = "Deposit"; + } elseif ($obj->type == 0) { + $text = "ExcessReceived"; + } else { + $text = "UnknownType"; + } + $invoice->fetch($obj->fk_facture_source); + $substitutions['discounts'][] = [ + 'text' => $text, + 'date' => $this->db->jdate($obj->datef), + 'ref' => $invoice->ref, + 'total_ttc' => $obj->amount_ttc, + 'multicurrency_total_ttc' => $obj->multicurrency_amount_ttc, + ]; + $i++; + } + } + $substitutions['payments'] = []; + // Loop on each payment + // TODO Call getListOfPayments instead of hard coded sql + $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num"; + $sql .= ", pf.amount as amount, pf.multicurrency_amount,"; + $sql .= " cp.code, ba.ref as bankref"; + $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON pf.fk_paiement = p.rowid"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "c_paiement AS cp ON p.fk_paiement = cp.id AND cp.entity IN (" . getEntity('c_paiement') . ")"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank as b ON p.fk_bank = b.rowid"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_account as ba ON b.fk_account = ba.rowid"; + $sql .= " WHERE pf.fk_facture = ".((int) $object->id); + $sql .= " ORDER BY p.datep"; + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + $i = 0; + while ($i < $num) { + $obj = $this->db->fetch_object($resql); + $substitutions['payments'][] = [ + 'text' => "PaymentTypeShort".$obj->code, + 'date' => $this->db->jdate($obj->date), + 'num' => $obj->num, + 'total_ttc' => $obj->amount, + 'multicurrency_total_ttc' => $obj->multicurrency_amount, + 'bankref' => $obj->bankref, + ]; + $i++; + } + } // var_dump($substitutions); - - $html = $template->render($substitutions); + $substitutions['debug'] = '
' . print_r($substitutions, true) . '
'; + try { + $html = $template->render($substitutions); + } catch (\Twig\Error\SyntaxError $e) { + $this->errors = $e->getMessage() . ' at line ' . $e->getLine() . ' in file ' . $e->getFile(); + return -1; + } catch (Exception $e) { + $this->errors[] = $e->getMessage(); + return -1; + } // print $html; $mpdf = new \Mpdf\Mpdf([ + 'format' => [210, 297], 'margin_left' => getDolGlobalInt('EASYDOC_PDF_MARGIN_LEFT', 10), 'margin_right' => getDolGlobalInt('EASYDOC_PDF_MARGIN_RIGHT', 10), 'margin_top' => getDolGlobalInt('EASYDOC_PDF_MARGIN_TOP', 48), @@ -483,14 +549,14 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, null); complete_substitutions_array($substitutionarray, $outputlangs, null); $text = make_substitutions($text, $substitutionarray, $outputlangs); - $mpdf->SetWatermarkText($outputlangs->convToOutputCharset($text)); - $mpdf->showWatermarkText = ($object->statut == Commande::STATUS_DRAFT && getDolGlobalString('FACTURE_DRAFT_WATERMARK')); + $mpdf->SetWatermarkText($text); + $mpdf->showWatermarkText = ($object->status == Facture::STATUS_DRAFT && getDolGlobalString('FACTURE_DRAFT_WATERMARK')); $mpdf->watermark_font = 'DejaVuSansCondensed'; $mpdf->watermarkTextAlpha = 0.1; $mpdf->SetDisplayMode('fullpage'); - $mpdf->Bookmark($outputlangs->trans('PdfOrderTitle')); + $mpdf->Bookmark($outputlangs->trans('PdfInvoiceTitle')); $mpdf->WriteHTML($html); $dir = $conf->facture->multidir_output[$object->entity]; diff --git a/lib/easydocgenerator.lib.php b/lib/easydocgenerator.lib.php index e6cdd18..664f44e 100644 --- a/lib/easydocgenerator.lib.php +++ b/lib/easydocgenerator.lib.php @@ -86,9 +86,10 @@ function easydocgeneratorAdminPrepareHead() * @param Object $object Dolibarr Object * @param Translate $outputlangs Language object for output * @param boolean|int $recursive Want to fetch child array or child object. + * @param string $objectname Name of object * @return array Array of substitution key->code */ -function getEachVarObject($object, $outputlangs, $recursive = 1) +function getEachVarObject($object, $outputlangs, $recursive = 1, $objectname = 'object') { $array_other = []; if (!empty($object)) { @@ -98,16 +99,16 @@ function getEachVarObject($object, $outputlangs, $recursive = 1) } if (!empty($value)) { if (!is_array($value) && !is_object($value)) { - $array_other['object'][$key] = $value; + $array_other[$objectname][$key] = $value; } elseif (is_array($value) && $recursive) { $tmparray = getEachVarObject($value, $outputlangs, 0); foreach ($tmparray as $key2 => $value2) { - $array_other['object'][$key . '_' . preg_replace('/^object_/', '', $key2)] = $value2; + $array_other[$objectname][$key] = $value2; } } elseif (is_object($value) && $recursive) { $tmparray = getEachVarObject($value, $outputlangs, 0); foreach ($tmparray as $key2 => $value2) { - $array_other['object'][$key . '_' . preg_replace('/^object_/', '', $key2)] = $value2; + $array_other[$objectname][$key] = $value2; } } } From 791df3132fb179928376d14dc41342dcfaf46755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Sat, 3 Feb 2024 21:45:46 +0100 Subject: [PATCH 2/2] add number to words --- .../facture/doc/doc_easydoc_invoice_html.modules.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/modules/facture/doc/doc_easydoc_invoice_html.modules.php b/core/modules/facture/doc/doc_easydoc_invoice_html.modules.php index 0b4ff81..d8aa77b 100644 --- a/core/modules/facture/doc/doc_easydoc_invoice_html.modules.php +++ b/core/modules/facture/doc/doc_easydoc_invoice_html.modules.php @@ -234,7 +234,7 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE') && $outputlangs->defaultlang != getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) { $outputlangsbis = new Translate('', $conf); $outputlangsbis->setDefaultLang(getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')); - $outputlangsbis->loadLangs(array('main', 'dict', 'companies', 'bills', 'products', 'orders', 'deliveries', 'banks')); + $outputlangsbis->loadLangs(['main', 'dict', 'companies', 'bills', 'products', 'orders', 'deliveries', 'banks']); } // add linked objects to note_public @@ -459,8 +459,8 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails $sql = "SELECT re.rowid, re.amount_ht, re.multicurrency_amount_ht, re.amount_tva, re.multicurrency_amount_tva, re.amount_ttc, re.multicurrency_amount_ttc,"; $sql .= " re.description, re.fk_facture_source,"; $sql .= " f.type, f.datef"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".((int) $object->id); + $sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re, " . MAIN_DB_PREFIX . "facture as f"; + $sql .= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = " . ((int) $object->id); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -494,12 +494,12 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails $sql = "SELECT p.datep as date, p.fk_paiement, p.num_paiement as num"; $sql .= ", pf.amount as amount, pf.multicurrency_amount,"; $sql .= " cp.code, ba.ref as bankref"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf"; + $sql .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as p ON pf.fk_paiement = p.rowid"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "c_paiement AS cp ON p.fk_paiement = cp.id AND cp.entity IN (" . getEntity('c_paiement') . ")"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank as b ON p.fk_bank = b.rowid"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_account as ba ON b.fk_account = ba.rowid"; - $sql .= " WHERE pf.fk_facture = ".((int) $object->id); + $sql .= " WHERE pf.fk_facture = " . ((int) $object->id); $sql .= " ORDER BY p.datep"; $resql = $this->db->query($sql); @@ -509,7 +509,7 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails while ($i < $num) { $obj = $this->db->fetch_object($resql); $substitutions['payments'][] = [ - 'text' => "PaymentTypeShort".$obj->code, + 'text' => "PaymentTypeShort" . $obj->code, 'date' => $this->db->jdate($obj->date), 'num' => $obj->num, 'total_ttc' => $obj->amount,