From c77e0650502bc5169962192f33617bd62aada268 Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Fri, 16 Dec 2022 14:41:45 +0100 Subject: [PATCH 1/2] NEW - Invoice - Show Category of operations --- htdocs/admin/facture.php | 2 +- htdocs/admin/pdf.php | 4 +-- htdocs/admin/pdf_other.php | 24 +++++++++++---- htdocs/core/lib/pdf.lib.php | 4 +-- .../facture/doc/pdf_sponge.modules.php | 29 ++++++++++++++++++- htdocs/langs/en_US/admin.lang | 4 +++ htdocs/langs/en_US/bills.lang | 4 +++ htdocs/master.inc.php | 6 +++- 8 files changed, 65 insertions(+), 12 deletions(-) diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index 10746c794be..bbeb25371b9 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -743,7 +743,7 @@ print load_fiche_titre($langs->trans("OtherOptions"), '', ''); print '
'; print ''; print ''; -print ''; +print ''; print ''; print ''; print "\n"; diff --git a/htdocs/admin/pdf.php b/htdocs/admin/pdf.php index d8cc8d554a2..f5f87877ab7 100644 --- a/htdocs/admin/pdf.php +++ b/htdocs/admin/pdf.php @@ -35,7 +35,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; // Load translation files required by the page -$langs->loadLangs(array('admin', 'languages', 'other', 'companies', 'products', 'members', 'stocks', 'Trips')); +$langs->loadLangs(array('admin', 'companies', 'languages', 'members', 'other', 'products', 'stocks', 'trips')); if (!$user->admin) { accessforbidden(); @@ -276,7 +276,7 @@ print load_fiche_titre($langs->trans("DictionaryPaperFormat"), '', ''); print '
'; print '
'.$langs->trans("Parameter").''.$langs->trans("Parameters").''.$langs->trans("Value").' 
'; -print ''; +print ''; $selected = (isset($conf->global->MAIN_PDF_FORMAT) ? $conf->global->MAIN_PDF_FORMAT : ''); if (empty($selected)) { diff --git a/htdocs/admin/pdf_other.php b/htdocs/admin/pdf_other.php index e5c76a36269..182f8d4e472 100644 --- a/htdocs/admin/pdf_other.php +++ b/htdocs/admin/pdf_other.php @@ -5,6 +5,7 @@ * Copyright (C) 2012-2107 Juanjo Menent * Copyright (C) 2019 Ferran Marcet * Copyright (C) 2021-2022 Anthony Berton + * Copyright (C) 2022 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,7 +36,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; // Load translation files required by the page -$langs->loadLangs(array('admin', 'languages', 'other', 'companies', 'products', 'members', 'stocks', 'Trips')); +$langs->loadLangs(array('admin', 'bills', 'companies', 'languages', 'members', 'other', 'products', 'receptions', 'stocks', 'trips')); if (!$user->admin) { accessforbidden(); @@ -69,6 +70,9 @@ if ($action == 'update') { dolibarr_set_const($db, "INVOICE_ADD_SWISS_QR_CODE", GETPOST("INVOICE_ADD_SWISS_QR_CODE", 'int'), 'chaine', 0, '', $conf->entity); dolibarr_del_const($db, "INVOICE_ADD_ZATCA_QR_CODE", $conf->entity); } + if (GETPOSTISSET('INVOICE_CATEGORY_OF_OPERATION')) { + dolibarr_set_const($db, "INVOICE_CATEGORY_OF_OPERATION", GETPOST("INVOICE_CATEGORY_OF_OPERATION", 'int'), 'chaine', 0, '', $conf->entity); + } if (GETPOSTISSET('INVOICE_SHOW_SHIPPING_ADDRESS')) { dolibarr_set_const($db, "INVOICE_SHOW_SHIPPING_ADDRESS", GETPOST("INVOICE_SHOW_SHIPPING_ADDRESS", 'int'), 'chaine', 0, '', $conf->entity); dolibarr_del_const($db, "INVOICE_SHOW_SHIPPING_ADDRESS", $conf->entity); @@ -135,7 +139,7 @@ if (isModEnabled('facture')) { print '
'; print '
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'.$langs->trans("Parameters").''.$langs->trans("Value").'
'; - print ''; + print ''; print ''; + // Mention category of operations + // French Decret n°2099-1299 2022-10-07 print ''; + + print '
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'.$langs->trans("Parameters").''.$langs->trans("Value").'
'; print $form->textwithpicto($langs->trans("INVOICE_ADD_ZATCA_QR_CODE"), $langs->trans("INVOICE_ADD_ZATCA_QR_CODEMore")); @@ -159,11 +163,21 @@ if (isModEnabled('facture')) { } print '
'; - print $form->textwithpicto($langs->trans("INVOICE_SHOW_SHIPPING_ADDRESS"), $langs->trans("INVOICE_SHOW_SHIPPING_ADDRESSMore")); + print $form->textwithpicto($langs->trans("InvoiceOptionCategoryOfOperations"), $langs->trans('InvoiceOptionCategoryOfOperationsHelp'), 1); print ''; + $arrval = array('0'=>$langs->trans("No"), + '1'=>$langs->trans("InvoiceOptionCategoryOfOperationsYes1"), + '2'=>$langs->trans("InvoiceOptionCategoryOfOperationsYes2") + ); + print $form->selectarray("INVOICE_CATEGORY_OF_OPERATION", $arrval, $conf->global->INVOICE_CATEGORY_OF_OPERATION, 0, 0, 0, '', 0, 0, 0, '', 'minwidth75imp'); + print '
'.$langs->trans("MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING").''; if ($conf->use_javascript_ajax) { - print ajax_constantonoff('INVOICE_SHOW_SHIPPING_ADDRESS'); + print ajax_constantonoff('MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING'); } else { $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); print $form->selectarray("INVOICE_SHOW_SHIPPING_ADDRESS", $arrval, $conf->global->INVOICE_SHOW_SHIPPING_ADDRESS); @@ -181,7 +195,7 @@ if (isModEnabled('reception')) { print '
'; print ''; - print ''; + print ''; print '
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'.$langs->trans("Parameters").''.$langs->trans("Value").'
'; print $langs->trans("RECEPTION_PDF_HIDE_ORDERED"); diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 789a65b93e4..0c628c9d5e8 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -61,9 +61,9 @@ function pdf_admin_prepare_head() // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab complete_head_from_modules($conf, $langs, null, $head, $h, 'pdf_admin'); - if (isModEnabled("propal")) { + if (isModEnabled("propal") || isModEnabled('facture') || isModEnabled('reception')) { $head[$h][0] = DOL_URL_ROOT.'/admin/pdf_other.php'; - $head[$h][1] = $langs->trans("Other"); + $head[$h][1] = $langs->trans("Others"); $head[$h][2] = 'other'; $h++; } diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index 1bea6b0db67..57e333cb759 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -10,6 +10,7 @@ * Copyright (C) 2017 Ferran Marcet * Copyright (C) 2018 Frédéric France * Copyright (C) 2022 Anthony Berton + * Copyright (C) 2022 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1289,6 +1290,16 @@ class pdf_sponge extends ModelePDFFactures $posy = $pdf->GetY(); } + // Show category of operations + if ($conf->global->INVOICE_CATEGORY_OF_OPERATION == 2) { + $nbCategoryOfOperations = 0; + $categoryOfOperations = $outputlangs->trans("MentionCategoryOfOperations") . ': ' . $outputlangs->trans("MentionCategoryOfOperations" . $nbCategoryOfOperations); + $pdf->SetXY($this->marge_gauche, $posy); + $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities($categoryOfOperations), 0, 1); + + $posy = $pdf->GetY() + 1; + } + // Show if Option VAT debit option is on also if transmitter is french // Decret n°2099-1299 2022-10-07 // French mention : "Option pour le paiement de la taxe d'après les débits" @@ -1947,9 +1958,10 @@ class pdf_sponge extends ModelePDFFactures * @param int $hidebottom Hide bottom bar of array * @param string $currency Currency code * @param Translate $outputlangsbis Langs object bis + * @param Facture $object Object to show * @return void */ - protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null) + protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null, $object) { global $conf; @@ -1967,6 +1979,21 @@ class pdf_sponge extends ModelePDFFactures $pdf->SetFont('', '', $default_font_size - 2); if (empty($hidetop)) { + // Show category of operations + if ($conf->global->INVOICE_CATEGORY_OF_OPERATION == 1) { + $nbCategoryOfOperations = 0; + if (count($object->product_type == 0) >= 1) { + $nbCategoryOfOperations = 0; + } elseif (count($object->product_type == 1) >= 1) { + $nbCategoryOfOperations = 1; + } elseif (count($object->product_type == 0) >= 1 && count($object->product_type == 1) >= 1) { + $nbCategoryOfOperations = 2; + } + $categoryOfOperations = $outputlangs->trans("MentionCategoryOfOperations") . ': ' . $outputlangs->trans("MentionCategoryOfOperations" . $nbCategoryOfOperations); + $pdf->SetXY($this->marge_gauche, $tab_top - 4); + $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations); + } + $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency)); if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) { $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency)); diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 62176a37c41..28205d1dcba 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1442,6 +1442,10 @@ SuppliersPayment=Vendor payments SupplierPaymentSetup=Vendor payments setup InvoiceCheckPosteriorDate=Check facture date before validation InvoiceCheckPosteriorDateHelp=Validating an invoice will be forbidden if its date is anterior to the date of last invoice of same type. +InvoiceOptionCategoryOfOperations=Display the mention "category of operations" on the invoice. +InvoiceOptionCategoryOfOperationsHelp=Depending on the situation, the mention will appear in the form:
- Category of operations: Delivery of goods
- Category of operations: Provision of services
- Category of operations: Mixed - Delivery of goods & provision of services +InvoiceOptionCategoryOfOperationsYes1=Yes, below the address block +InvoiceOptionCategoryOfOperationsYes2=Yes, in the lower left-hand corner ##### Proposals ##### PropalSetup=Commercial proposals module setup ProposalsNumberingModules=Commercial proposal numbering models diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index d7c29a82399..183620c72da 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -627,3 +627,7 @@ SendEmailsRemindersOnInvoiceDueDate=Send reminder by email for unpaid invoices MakePaymentAndClassifyPayed=Record payment BulkPaymentNotPossibleForInvoice=Bulk payment is not possible for invoice %s (bad type or status) MentionVATDebitOptionIsOn=Option to pay tax based on debits +MentionCategoryOfOperations=Category of operations +MentionCategoryOfOperations0=Delivery of goods +MentionCategoryOfOperations1=Provision of services +MentionCategoryOfOperations2=Mixed - Delivery of goods & provision of services diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index 03515c9a2e2..aa3cfba0c77 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -215,9 +215,13 @@ if (!defined('NOREQUIREDB') && !defined('NOREQUIRESOC')) { $conf->global->MAIN_INVERT_SENDER_RECIPIENT = 1; } if ($mysoc->country_code == 'FR' && !isset($conf->global->MAIN_PROFID1_IN_ADDRESS)) { - // For FR, default value of option to show profid SIRET is on by default + // For FR, default value of option to show profid SIRET is on by default. Decret n°2099-1299 2022-10-07 $conf->global->MAIN_PROFID1_IN_ADDRESS = 1; } + if ($mysoc->country_code == 'FR' && (!isset($conf->global->INVOICE_CATEGORY_OF_OPERATION) || empty($conf->global->INVOICE_CATEGORY_OF_OPERATION))) { + // For FR, default value of option to show category of operations is on by default. Decret n°2099-1299 2022-10-07 + $conf->global->INVOICE_CATEGORY_OF_OPERATION = 1; + } } From c3dc10f2e5c4d954f2cc8eb51a9d79582ec55cc9 Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Fri, 16 Dec 2022 17:12:23 +0100 Subject: [PATCH 2/2] NEW category of operation in PDF --- htdocs/admin/pdf_other.php | 2 +- .../facture/doc/pdf_sponge.modules.php | 70 +++++++++++++------ htdocs/master.inc.php | 2 +- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/htdocs/admin/pdf_other.php b/htdocs/admin/pdf_other.php index 182f8d4e472..933486b0577 100644 --- a/htdocs/admin/pdf_other.php +++ b/htdocs/admin/pdf_other.php @@ -36,7 +36,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; // Load translation files required by the page -$langs->loadLangs(array('admin', 'bills', 'companies', 'languages', 'members', 'other', 'products', 'receptions', 'stocks', 'trips')); +$langs->loadLangs(array('admin', 'bills', 'companies', 'languages', 'members', 'other', 'products', 'propal', 'receptions', 'stocks', 'trips')); if (!$user->admin) { accessforbidden(); diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index 57e333cb759..adf47af3cce 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -160,6 +160,11 @@ class pdf_sponge extends ModelePDFFactures */ public $cols; + /** + * @var int Category of operation + */ + public $categoryOfOperation = -1; // unknown by default + /** * Constructor @@ -430,12 +435,35 @@ class pdf_sponge extends ModelePDFFactures $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right // Set $this->atleastonediscount if you have at least one discount + // and determine category of operation + $categoryOfOperation = 0; + $nbProduct = 0; + $nbService = 0; for ($i = 0; $i < $nblines; $i++) { if ($object->lines[$i]->remise_percent) { $this->atleastonediscount++; } - } + // determine category of operation + $lineProductType = $object->lines[$i]->product_type; + if ($lineProductType == Product::TYPE_PRODUCT) { + $nbProduct++; + } elseif ($lineProductType == Product::TYPE_SERVICE) { + $nbService++; + } + if ($nbProduct > 0 && $nbService > 0) { + // mixed products and services + $categoryOfOperation = 2; + } + } + // determine category of operation + if ($categoryOfOperation <= 0) { + // only services + if ($nbProduct == 0 && $nbService > 0) { + $categoryOfOperation = 1; + } + } + $this->categoryOfOperation = $categoryOfOperation; // Situation invoice handling if ($object->situation_cycle_ref) { @@ -1242,6 +1270,21 @@ class pdf_sponge extends ModelePDFFactures $posy = $pdf->GetY() + 3; // We need spaces for 2 lines payment conditions } + // Show category of operations + if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 2 && $this->categoryOfOperation >= 0) { + $pdf->SetFont('', 'B', $default_font_size - 2); + $pdf->SetXY($this->marge_gauche, $posy); + $categoryOfOperationTitle = $outputlangs->transnoentities("MentionCategoryOfOperations").' : '; + $pdf->MultiCell($posxval - $this->marge_gauche, 4, $categoryOfOperationTitle, 0, 'L'); + + $pdf->SetFont('', '', $default_font_size - 2); + $pdf->SetXY($posxval, $posy); + $categoryOfOperationLabel = $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation); + $pdf->MultiCell($posxend - $posxval, 4, $categoryOfOperationLabel, 0, 'L'); + + $posy = $pdf->GetY() + 3; // for 2 lines + } + if ($object->type != 2) { // Check a payment mode is defined if (empty($object->mode_reglement_code) @@ -1290,16 +1333,6 @@ class pdf_sponge extends ModelePDFFactures $posy = $pdf->GetY(); } - // Show category of operations - if ($conf->global->INVOICE_CATEGORY_OF_OPERATION == 2) { - $nbCategoryOfOperations = 0; - $categoryOfOperations = $outputlangs->trans("MentionCategoryOfOperations") . ': ' . $outputlangs->trans("MentionCategoryOfOperations" . $nbCategoryOfOperations); - $pdf->SetXY($this->marge_gauche, $posy); - $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities($categoryOfOperations), 0, 1); - - $posy = $pdf->GetY() + 1; - } - // Show if Option VAT debit option is on also if transmitter is french // Decret n°2099-1299 2022-10-07 // French mention : "Option pour le paiement de la taxe d'après les débits" @@ -1958,10 +1991,9 @@ class pdf_sponge extends ModelePDFFactures * @param int $hidebottom Hide bottom bar of array * @param string $currency Currency code * @param Translate $outputlangsbis Langs object bis - * @param Facture $object Object to show * @return void */ - protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null, $object) + protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null) { global $conf; @@ -1980,16 +2012,8 @@ class pdf_sponge extends ModelePDFFactures if (empty($hidetop)) { // Show category of operations - if ($conf->global->INVOICE_CATEGORY_OF_OPERATION == 1) { - $nbCategoryOfOperations = 0; - if (count($object->product_type == 0) >= 1) { - $nbCategoryOfOperations = 0; - } elseif (count($object->product_type == 1) >= 1) { - $nbCategoryOfOperations = 1; - } elseif (count($object->product_type == 0) >= 1 && count($object->product_type == 1) >= 1) { - $nbCategoryOfOperations = 2; - } - $categoryOfOperations = $outputlangs->trans("MentionCategoryOfOperations") . ': ' . $outputlangs->trans("MentionCategoryOfOperations" . $nbCategoryOfOperations); + if (getDolGlobalInt('INVOICE_CATEGORY_OF_OPERATION') == 1 && $this->categoryOfOperation >= 0) { + $categoryOfOperations = $outputlangs->transnoentities("MentionCategoryOfOperations") . ' : ' . $outputlangs->transnoentities("MentionCategoryOfOperations" . $this->categoryOfOperation); $pdf->SetXY($this->marge_gauche, $tab_top - 4); $pdf->MultiCell(($pdf->GetStringWidth($categoryOfOperations)) + 4, 2, $categoryOfOperations); } diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index aa3cfba0c77..8cf649148a6 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -218,7 +218,7 @@ if (!defined('NOREQUIREDB') && !defined('NOREQUIRESOC')) { // For FR, default value of option to show profid SIRET is on by default. Decret n°2099-1299 2022-10-07 $conf->global->MAIN_PROFID1_IN_ADDRESS = 1; } - if ($mysoc->country_code == 'FR' && (!isset($conf->global->INVOICE_CATEGORY_OF_OPERATION) || empty($conf->global->INVOICE_CATEGORY_OF_OPERATION))) { + if ($mysoc->country_code == 'FR' && !isset($conf->global->INVOICE_CATEGORY_OF_OPERATION)) { // For FR, default value of option to show category of operations is on by default. Decret n°2099-1299 2022-10-07 $conf->global->INVOICE_CATEGORY_OF_OPERATION = 1; }