Skip to content

Commit

Permalink
Merge pull request #18 from frederic34/dev
Browse files Browse the repository at this point in the history
add number to words
  • Loading branch information
frederic34 authored Feb 3, 2024
2 parents f95a907 + 791df31 commit 0230a80
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 82 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
123 changes: 122 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 30 additions & 7 deletions core/modules/commande/doc/doc_easydoc_order_html.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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) {
Expand Down Expand Up @@ -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'] = '<pre>' . print_r($substitutions, true) . '</pre>';
$subtotal_ht = 0;
$subtotal_ttc = 0;
$linenumber = 1;
Expand Down Expand Up @@ -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),
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 0230a80

Please sign in to comment.