Skip to content

Commit

Permalink
Merge pull request #17 from frederic34/dev
Browse files Browse the repository at this point in the history
add format setup
  • Loading branch information
frederic34 authored Feb 3, 2024
2 parents 706f0c7 + f646465 commit 839b0f7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 22 deletions.
56 changes: 39 additions & 17 deletions admin/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
// Load Dolibarr environment
include '../config.php';

global $langs, $user;
global $db, $langs, $user;

// Libraries
require_once DOL_DOCUMENT_ROOT . "/core/lib/admin.lib.php";
//require_once DOL_DOCUMENT_ROOT.'/core/lib/oauth.lib.php';
require_once '../lib/easydocgenerator.lib.php';

// Translations
$langs->loadLangs(["admin", 'oauth', "Easydocgenerator@easydocgenerator"]);
$langs->loadLangs(['admin', 'companies', 'languages', 'members', 'other', 'products', 'stocks', 'trips', 'easydocgenerator@easydocgenerator']);

// Access control
if (!$user->admin) {
Expand All @@ -43,15 +42,30 @@
// Parameters
$action = GETPOST('action', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha');

// Define $urlwithroot
// $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim($dolibarr_main_url_root));
// $urlwithouturlroot = str_replace('http://', 'https://', $urlwithouturlroot);
// This is to use external domain name found into config file
// $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT;
// $urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current
// paper formats
$sql = "SELECT code, label, width, height, unit";
$sql .= " FROM " . $db->prefix() . "c_paper_format";
$sql .= " WHERE active=1";
$paperformats = [];
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num) {
$obj = $db->fetch_object($resql);
$unitKey = $langs->trans('SizeUnit' . $obj->unit);
$paperformats[$obj->code] = $langs->trans('PaperFormat' . strtoupper($obj->code)) . ' - ' . round($obj->width) . 'x' . round($obj->height) . ' ' . ($unitKey == 'SizeUnit' . $obj->unit ? $obj->unit : $unitKey);
$i++;
}
}

$arrayofparameters = [
'EASYDOC_PDF_FORMAT' => [
'css' => 'minwidth500',
'type' => 'selectarray',
'array' => $paperformats,
'default' => dol_getDefaultFormat(),
],
'EASYDOC_PDF_MARGIN_LEFT' => [
'css' => 'minwidth500',
'type' => 'number',
Expand Down Expand Up @@ -184,14 +198,19 @@
print '<tr class="liste_titre"><td class="titlefield">' . $langs->trans("Parameter") . '</td><td>' . $langs->trans("Value") . '</td></tr>';

foreach ($arrayofparameters as $key => $val) {
print '<tr class="oddeven">';
print '<td>';
$tooltiphelp = (($langs->trans($key . 'Tooltip') != $key . 'Tooltip') ? $langs->trans($key . 'Tooltip') : '');
print $form->textwithpicto($langs->trans($key), $tooltiphelp);
$type = empty($val['type']) ? 'text' : $val['type'];
$value = !empty($conf->global->$key) ? $conf->global->$key : (isset($val['default']) ? $val['default'] : '');
print '</td>';
print '<td><input name="' . $key . '" type="' . $type . '" class="flat ' . (empty($val['css']) ? 'minwidth200' : $val['css']) . '" value="' . $value . '"></td>';
print '<tr class="oddeven">';
if ($type == 'selectarray') {
print '<td>' . $langs->trans('EASYDOC_PDF_FORMAT') . '</td>';
print '<td>' . $form->selectarray('EASYDOC_PDF_FORMAT', $val['array'], $value) . '</td>';
} else {
print '<td>';
$tooltiphelp = (($langs->trans($key . 'Tooltip') != $key . 'Tooltip') ? $langs->trans($key . 'Tooltip') : '');
print $form->textwithpicto($langs->trans($key), $tooltiphelp);
print '</td>';
print '<td><input name="' . $key . '" type="' . $type . '" class="flat ' . (empty($val['css']) ? 'minwidth200' : $val['css']) . '" value="' . $value . '"></td>';
}
print '</tr>';
}
print '</table>';
Expand All @@ -214,10 +233,13 @@
$tooltiphelp = (($langs->trans($key . 'Tooltip') != $key . 'Tooltip') ? $langs->trans($key . 'Tooltip') : '');
print $form->textwithpicto($langs->trans($key), $tooltiphelp);
print '</td><td>';
$value = getDolGlobalString('$key', $val['default']);
$value = getDolGlobalString($key, $val['default']);
if (isset($val['type']) && $val['type'] == 'password') {
$value = preg_replace('/./i', '*', $value);
}
if (isset($val['type']) && $val['type'] == 'selectarray') {
$value = $val['array'][$value];
}
print $value;
print '</td></tr>';
}
Expand Down
10 changes: 7 additions & 3 deletions core/modules/facture/doc/doc_easydoc_invoice_html.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,13 @@ 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'));

$mpdf->showWatermarkText = ($object->statut == Commande::STATUS_DRAFT && getDolGlobalString('COMMANDE_DRAFT_WATERMARK'));
// Watermark
$text = getDolGlobalString('FACTURE_DRAFT_WATERMARK');
$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->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;

Expand Down
1 change: 1 addition & 0 deletions langs/fr_FR/easydocgenerator.lang
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ EASYDOC_PDF_MARGIN_TOP=Marge haut sur les PDF
EASYDOC_PDF_MARGIN_BOTTOM=Marge bas sur les PDF
EASYDOC_PDF_MARGIN_HEADER=En-tête sur les PDF
EASYDOC_PDF_MARGIN_FOOTER=Pied de page sur les PDF
EASYDOC_PDF_FORMAT=Format papiers

15 changes: 13 additions & 2 deletions templates/invoice.twig
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,19 @@ table thead th {
{{ trans('VATIntraShort') }}: {{ mysoc.tvanumber }}<br />
</td>
<td width="45%" style="text-align: right;">
<span style="font-weight: bold; font-size: 14pt;"><b>{{ trans('PdfOrderTitle') }}</b></span>
<br /><span style="font-weight: bold; font-size: 10pt;">{{ trans('Ref') }}: {{ object.ref }}</span>
<span style="font-weight: bold; font-size: 14pt;"><b>
{% if object.type == 1 %}
{{ trans('InvoiceReplacement') }}
{% elseif object.type == 2 %}
{{ trans('InvoiceAvoir') }}
{% elseif object.type == 3 %}
{{ trans('InvoiceDeposit') }}
{% elseif object.type == 4 %}
{{ trans('InvoiceProForma') }}
{% else %}
{{ trans('PdfInvoiceTitle') }}
{% endif %}
{{ object.ref }}</span>
<br /><span style="font-weight: bold; font-size: 10pt;">{{ trans('OrderDate') }}: {{ object.date }}</span>
{% if object.ref_customer %}
<br /><span style="font-weight: bold; font-size: 10pt;">{{ trans('RefCustomer') }}: {{ object.ref_customer }}</span>
Expand Down

0 comments on commit 839b0f7

Please sign in to comment.