diff --git a/htdocs/admin/pdf_other.php b/htdocs/admin/pdf_other.php index 2532fa5403b..ecad0c255e2 100644 --- a/htdocs/admin/pdf_other.php +++ b/htdocs/admin/pdf_other.php @@ -4,7 +4,7 @@ * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2012-2107 Juanjo Menent * Copyright (C) 2019 Ferran Marcet - * Copyright (C) 2021-2022 Anthony Berton + * Copyright (C) 2021-2024 Anthony Berton * Copyright (C) 2022 Alexandre Spangaro * Copyright (C) 2024 Frédéric France * Copyright (C) 2024 Nick Fragoulis @@ -36,6 +36,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; /** * @var Conf $conf @@ -91,6 +93,15 @@ if ($action == 'update') { if (GETPOSTISSET('MAIN_DOCUMENTS_WITH_PICTURE_WIDTH')) { dolibarr_set_const($db, "MAIN_DOCUMENTS_WITH_PICTURE_WIDTH", GETPOSTINT("MAIN_DOCUMENTS_WITH_PICTURE_WIDTH"), 'chaine', 0, '', $conf->entity); } + if (GETPOSTISSET('MAIN_PDF_ADD_TERMSOFSALE_PROPAL')) { + dolibarr_set_const($db, "MAIN_PDF_ADD_TERMSOFSALE_PROPAL", GETPOST("MAIN_PDF_ADD_TERMSOFSALE_PROPAL", 'int'), 'chaine', 0, '', $conf->entity); + } + if (GETPOSTISSET('MAIN_PDF_ADD_TERMSOFSALE_ORDER')) { + dolibarr_set_const($db, "MAIN_PDF_ADD_TERMSOFSALE_ORDER", GETPOST("MAIN_PDF_ADD_TERMSOFSALE_ORDER", 'int'), 'chaine', 0, '', $conf->entity); + } + if (GETPOSTISSET('MAIN_PDF_ADD_TERMSOFSALE_INVOICE')) { + dolibarr_set_const($db, "MAIN_PDF_ADD_TERMSOFSALE_INVOICE", GETPOST("MAIN_PDF_ADD_TERMSOFSALE_INVOICE", 'int'), 'chaine', 0, '', $conf->entity); + } if (GETPOSTISSET('INVOICE_ADD_ZATCA_QR_CODE')) { dolibarr_set_const($db, "INVOICE_ADD_ZATCA_QR_CODE", GETPOSTINT("INVOICE_ADD_ZATCA_QR_CODE"), 'chaine', 0, '', $conf->entity); if (GETPOSTINT('INVOICE_ADD_ZATCA_QR_CODE') == 1) { @@ -116,6 +127,20 @@ if ($action == 'update') { dolibarr_set_const($db, "INVOICE_SHOW_SHIPPING_ADDRESS", GETPOSTINT("INVOICE_SHOW_SHIPPING_ADDRESS"), 'chaine', 0, '', $conf->entity); dolibarr_del_const($db, "INVOICE_SHOW_SHIPPING_ADDRESS", $conf->entity); } + // Terms of sale + if ($_FILES['termsofsale']["name"]) { + if (!preg_match('/(\.pdf)$/i', $_FILES['termsofsale']["name"])) { // Document can be used on a lot of different places. Only pdf can be supported. + $langs->load("errors"); + setEventMessages($langs->trans("ErrorBadFormat"), null, 'errors'); + } else { + $dirforterms = $conf->mycompany->dir_output.'/'; + $original_file = $_FILES['termsofsale']["name"]; + $result = dol_move_uploaded_file($_FILES['termsofsale']["tmp_name"], $dirforterms.$original_file, 1, 0, $_FILES['termsofsale']['error']); + if ($result) { + dolibarr_set_const($db, 'MAIN_INFO_SOCIETE_TERMSOFSALE', $original_file, 'chaine', 0, '', $conf->entity); + } + } + } if (GETPOSTISSET('BARCODE_ON_SHIPPING_PDF')) { dolibarr_set_const($db, "BARCODE_ON_SHIPPING_PDF", GETPOSTINT("BARCODE_ON_SHIPPING_PDF"), 'chaine', 0, '', $conf->entity); @@ -134,6 +159,21 @@ if ($action == 'update') { } +// Terms of sale +if ($action == 'removetermsofsale') { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + $filename = $mysoc->termsofsale; + $file = $conf->mycompany->dir_output.'/'.$filename; + + if ($filename != '') { + dol_delete_file($file); + } + dolibarr_del_const($db, 'MAIN_INFO_SOCIETE_TERMSOFSALE', $conf->entity); + + $mysoc->termsofsale = ''; +} + /* * View @@ -145,6 +185,7 @@ llxHeader('', $langs->trans("Setup"), $wikihelp, '', 0, 0, '', '', '', 'mod-admi $form = new Form($db); $formother = new FormOther($db); $formadmin = new FormAdmin($db); +$formfile = new FormFile($db); print load_fiche_titre($langs->trans("PDF"), '', 'title_setup'); @@ -156,7 +197,7 @@ $tooltiptext = ''; print ''.$form->textwithpicto($langs->trans("PDFOtherDesc"), $tooltiptext)."
\n"; print "
\n"; -print '
'; +print ''; print ''; print ''; @@ -180,6 +221,17 @@ if (isModEnabled('propal')) { print ''; */ + print ''; + print $form->textwithpicto($langs->trans("MAIN_PDF_ADD_TERMSOFSALE_PROPAL"), ''); + print ''; + if ($conf->use_javascript_ajax) { + print ajax_constantonoff('MAIN_PDF_ADD_TERMSOFSALE_PROPAL'); + } else { + $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); + print $form->selectarray("MAIN_PDF_ADD_TERMSOFSALE_PROPAL", $arrval, $conf->global->MAIN_PDF_ADD_TERMSOFSALE_PROPAL); + } + print ''; + print ''; print $form->textwithpicto($langs->trans("MAIN_GENERATE_PROPOSALS_WITH_PICTURE"), $langs->trans("RandomlySelectedIfSeveral")); print ''; @@ -195,6 +247,25 @@ if (isModEnabled('propal')) { print ''; } +if (isModEnabled('order')) { + print load_fiche_titre($langs->trans("Orders"), '', 'bill'); + + print '
'; + print ''; + print ''; + print ''; + print '
'.$langs->trans("Parameters").''.$langs->trans("Value").'
'; + print $form->textwithpicto($langs->trans("MAIN_PDF_ADD_TERMSOFSALE_ORDER"), ''); + print ''; + if ($conf->use_javascript_ajax) { + print ajax_constantonoff('MAIN_PDF_ADD_TERMSOFSALE_ORDER'); + } else { + $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); + print $form->selectarray("MAIN_PDF_ADD_TERMSOFSALE_ORDER", $arrval, $conf->global->MAIN_PDF_ADD_TERMSOFSALE_ORDER); + } + print '
'; + print '
'; +} if (isModEnabled('order')) { $langs->load("orders"); @@ -296,6 +367,16 @@ if (isModEnabled('invoice')) { print ''; print ''; + print ''; print '
'.$langs->trans("Parameters").''.$langs->trans("Value").'
'; + print $form->textwithpicto($langs->trans("MAIN_PDF_ADD_TERMSOFSALE_INVOICE"), ''); + print ''; + if ($conf->use_javascript_ajax) { + print ajax_constantonoff('MAIN_PDF_ADD_TERMSOFSALE_INVOICE'); + } else { + $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); + print $form->selectarray("MAIN_PDF_ADD_TERMSOFSALE_INVOICE", $arrval, $conf->global->MAIN_PDF_ADD_TERMSOFSALE_INVOICE); + } + print '
'; print $form->textwithpicto($langs->trans("INVOICE_ADD_ZATCA_QR_CODE"), $langs->trans("INVOICE_ADD_ZATCA_QR_CODEMore")); print ''; @@ -459,6 +540,36 @@ if (isModEnabled('stocktransfer')) { print ''; } +print load_fiche_titre($langs->trans("Files"), '', 'file'); +print '
'; +print ''; +print ''; + +// Terms of sale +$tooltiptermsofsale = $langs->trans('AvailableFormats').' : pdf'; +$maxfilesizearray = getMaxFileSizeArray(); +$tooltiptermsofsale .= ($maxfilesizearray['maxmin'] > 0) ? '
'.$langs->trans('MaxSize').' : '.$maxfilesizearray['maxmin'].' '.$langs->trans('Kb') : ''; +$documenturl = DOL_URL_ROOT.'/document.php'; +if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) { + $documenturl = $conf->global->DOL_URL_ROOT_DOCUMENT_PHP; +} +$modulepart = 'mycompany'; +$param = ''; + +print ''; +print '
'.$langs->trans("Parameters").''.$langs->trans("Value").'
'; +print '
'; +print ''; + +if (!empty($mysoc->termsofsale)) { + if (file_exists($conf->mycompany->dir_output.'/'.$mysoc->termsofsale)) { + print '
'.$mysoc->termsofsale.''.$formfile->showPreview($mysoc->termsofsale, $modulepart, $mysoc->termsofsale, 0, $param); + print ''; + } +} +print '
'; +print '
'; +print '
'; print '
'; print ''; diff --git a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php index 15ceab5c275..255bacdc977 100644 --- a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php @@ -640,6 +640,27 @@ class pdf_einstein extends ModelePDFCommandes $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod } + // Add terms to sale + if (!empty($mysoc->termsofsale) && getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_ORDER')) { + $termsofsale = $conf->mycompany->dir_output.'/'.$mysoc->termsofsale; + if (!empty($conf->mycompany->multidir_output[$object->entity])) { + $termsofsale = $conf->mycompany->multidir_output[$object->entity].'/'.$mysoc->termsofsale; + } + if (file_exists($termsofsale) && is_readable($termsofsale)) { + $pagecount = $pdf->setSourceFile($termsofsale); + for ($i = 1; $i <= $pagecount; $i++) { + $tplIdx = $pdf->importPage($i); + if ($tplIdx!==false) { + $s = $pdf->getTemplatesize($tplIdx); + $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); + $pdf->useTemplate($tplIdx); + } else { + setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings'); + } + } + } + } + $pdf->Close(); $pdf->Output($file, 'F'); diff --git a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php index 8fabcbc981d..4cef49bc129 100644 --- a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php @@ -7,6 +7,7 @@ * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2015 Marcos García * Copyright (C) 2017 Ferran Marcet + * Copyright (C) 2021-2024 Anthony Berton * Copyright (C) 2018-2024 Frédéric France * Copyright (C) 2024 MDW * Copyright (C) 2024 Nick Fragoulis @@ -860,6 +861,27 @@ class pdf_eratosthene extends ModelePDFCommandes $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod } + // Add terms to sale + if (!empty($mysoc->termsofsale) && getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_ORDER')) { + $termsofsale = $conf->mycompany->dir_output.'/'.$mysoc->termsofsale; + if (!empty($conf->mycompany->multidir_output[$object->entity])) { + $termsofsale = $conf->mycompany->multidir_output[$object->entity].'/'.$mysoc->termsofsale; + } + if (file_exists($termsofsale) && is_readable($termsofsale)) { + $pagecount = $pdf->setSourceFile($termsofsale); + for ($i = 1; $i <= $pagecount; $i++) { + $tplIdx = $pdf->importPage($i); + if ($tplIdx!==false) { + $s = $pdf->getTemplatesize($tplIdx); + $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); + $pdf->useTemplate($tplIdx); + } else { + setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings'); + } + } + } + } + $pdf->Close(); $pdf->Output($file, 'F'); diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index d0deb123c00..b5d7a29c7c6 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -9,7 +9,7 @@ * Copyright (C) 2015 Marcos García * Copyright (C) 2017-2018 Ferran Marcet * Copyright (C) 2018-2024 Frédéric France - * Copyright (C) 2022 Anthony Berton + * Copyright (C) 2022-2024 Anthony Berton * Copyright (C) 2022 Charlene Benke * Copyright (C) 2024 MDW * Copyright (C) 2024 Nick Fragoulis @@ -884,6 +884,26 @@ class pdf_crabe extends ModelePDFFactures $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod } + // Add terms to sale + if (!empty($mysoc->termsofsale) && getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_INVOICE')) { + $termsofsale = $conf->mycompany->dir_output.'/'.$mysoc->termsofsale; + if (!empty($conf->mycompany->multidir_output[$object->entity])) { + $termsofsale = $conf->mycompany->multidir_output[$object->entity].'/'.$mysoc->termsofsale; + } + if (file_exists($termsofsale) && is_readable($termsofsale)) { + $pagecount = $pdf->setSourceFile($termsofsale); + for ($i = 1; $i <= $pagecount; $i++) { + $tplIdx = $pdf->importPage($i); + if ($tplIdx!==false) { + $s = $pdf->getTemplatesize($tplIdx); + $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); + $pdf->useTemplate($tplIdx); + } else { + setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings'); + } + } + } + } if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') { $result = $this->addBottomQRInvoice($pdf, $object, $outputlangs); if (!$result) { diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index a268fd9e24b..30c39d94fb1 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -9,7 +9,7 @@ * Copyright (C) 2015 Marcos García * Copyright (C) 2017 Ferran Marcet * Copyright (C) 2018-2024 Frédéric France - * Copyright (C) 2022 Anthony Berton + * Copyright (C) 2021-2024 Anthony Berton * Copyright (C) 2022-2024 Alexandre Spangaro * Copyright (C) 2024 MDW * Copyright (C) 2024 Nick Fragoulis @@ -1045,10 +1045,31 @@ class pdf_sponge extends ModelePDFFactures if (method_exists($pdf, 'AliasNbPages')) { $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod } + // Add terms to sale + if (!empty($mysoc->termsofsale) && getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_INVOICE')) { + $termsofsale = $conf->mycompany->dir_output.'/'.$mysoc->termsofsale; + if (!empty($conf->mycompany->multidir_output[$object->entity])) { + $termsofsale = $conf->mycompany->multidir_output[$object->entity].'/'.$mysoc->termsofsale; + } + if (file_exists($termsofsale) && is_readable($termsofsale)) { + $pagecount = $pdf->setSourceFile($termsofsale); + for ($i = 1; $i <= $pagecount; $i++) { + $tplIdx = $pdf->importPage($i); + if ($tplIdx!==false) { + $s = $pdf->getTemplatesize($tplIdx); + $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); + $pdf->useTemplate($tplIdx); + } else { + setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings'); + } + } + } + } if (getDolGlobalString('INVOICE_ADD_SWISS_QR_CODE') == 'bottom') { $this->addBottomQRInvoice($pdf, $object, $outputlangs); } + $pdf->Close(); $pdf->Output($file, 'F'); diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index 0a1e4a0088a..40f4951487c 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -9,6 +9,7 @@ * Copyright (C) 2017-2018 Ferran Marcet * Copyright (C) 2018-2024 Frédéric France * Copyright (C) 2019 Pierre Ardoin + * Copyright (C) 2021-2024 Anthony Berton * Copyright (C) 2024 MDW * Copyright (C) 2024 Nick Fragoulis * Copyright (C) 2024 Alexandre Spangaro @@ -764,6 +765,27 @@ class pdf_azur extends ModelePDFPropales $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod } + // Add terms to sale + if (!empty($mysoc->termsofsale) && getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_PROPAL')) { + $termsofsale = $conf->mycompany->dir_output.'/'.$mysoc->termsofsale; + if (!empty($conf->mycompany->multidir_output[$object->entity])) { + $termsofsale = $conf->mycompany->multidir_output[$object->entity].'/'.$mysoc->termsofsale; + } + if (file_exists($termsofsale) && is_readable($termsofsale)) { + $pagecount = $pdf->setSourceFile($termsofsale); + for ($i = 1; $i <= $pagecount; $i++) { + $tplIdx = $pdf->importPage($i); + if ($tplIdx!==false) { + $s = $pdf->getTemplatesize($tplIdx); + $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); + $pdf->useTemplate($tplIdx); + } else { + setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings'); + } + } + } + } + //If propal merge product PDF is active if (getDolGlobalString('PRODUIT_PDF_MERGE_PROPAL')) { require_once DOL_DOCUMENT_ROOT.'/product/class/propalmergepdfproduct.class.php'; diff --git a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php index 8999bc7f807..158a63f7e12 100644 --- a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php @@ -7,6 +7,7 @@ * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2015 Marcos García * Copyright (C) 2017 Ferran Marcet + * Copyright (C) 2021-2024 Anthony Berton * Copyright (C) 2018-2024 Frédéric France * Copyright (C) 2024 MDW * Copyright (C) 2024 Nick Fragoulis @@ -883,6 +884,27 @@ class pdf_cyan extends ModelePDFPropales $pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod } + // Add terms to sale + if (!empty($mysoc->termsofsale) && getDolGlobalInt('MAIN_PDF_ADD_TERMSOFSALE_PROPAL')) { + $termsofsale = $conf->mycompany->dir_output.'/'.$mysoc->termsofsale; + if (!empty($conf->mycompany->multidir_output[$object->entity])) { + $termsofsale = $conf->mycompany->multidir_output[$object->entity].'/'.$mysoc->termsofsale; + } + if (file_exists($termsofsale) && is_readable($termsofsale)) { + $pagecount = $pdf->setSourceFile($termsofsale); + for ($i = 1; $i <= $pagecount; $i++) { + $tplIdx = $pdf->importPage($i); + if ($tplIdx!==false) { + $s = $pdf->getTemplatesize($tplIdx); + $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); + $pdf->useTemplate($tplIdx); + } else { + setEventMessages(null, array($termsofsale.' cannot be added, probably protected PDF'), 'warnings'); + } + } + } + } + //If propal merge product PDF is active if (getDolGlobalString('PRODUIT_PDF_MERGE_PROPAL')) { require_once DOL_DOCUMENT_ROOT.'/product/class/propalmergepdfproduct.class.php'; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index d1593d52f25..9f269081b7f 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -2144,6 +2144,10 @@ MAIN_PDF_NO_RECIPENT_FRAME=Hide borders on recipient address frame MAIN_PDF_HIDE_CUSTOMER_CODE=Hide customer code MAIN_PDF_HIDE_CUSTOMER_ACCOUNTING_CODE=Hide customer accounting code MAIN_PDF_HIDE_SENDER_NAME=Hide sender/company name in address block +TERMSOFSALE=Conditions de vente +MAIN_PDF_ADD_TERMSOFSALE_PROPAL=Add the conditions of sale after the proposal +MAIN_PDF_ADD_TERMSOFSALE_ORDER=Add the conditions of sale after the order +MAIN_PDF_ADD_TERMSOFSALE_INVOICE=Add the conditions of sale after the invoice PROPOSAL_PDF_HIDE_PAYMENTTERM=Hide payments conditions PROPOSAL_PDF_HIDE_PAYMENTMODE=Hide payment mode MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING=Add a hidden markup into the signature area to allow electronic signature tool to reuse it. May be used by external tools or in the future by the online signature feature.