diff --git a/ChangeLog.md b/ChangeLog.md index 833cc248..b29a41ee 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. # [Unreleased] ## Release 3.29 +- FIX : COMPAT V23 - *02/12/2025* - 3.29.2 - FIX : query sql to order line when create invoice from order - *29/10/2025* - 3.29.1 - FIX : Prevent creating a new situation invoice when all lines have 100% progress- *01/10/2025* - 3.29.1 - NEW : COMPAT 22 - *02/07/2025* - 3.29.0 diff --git a/class/actions_subtotal.class.php b/class/actions_subtotal.class.php index 1b22629b..1bd5cc9a 100644 --- a/class/actions_subtotal.class.php +++ b/class/actions_subtotal.class.php @@ -1,5 +1,19 @@ + + 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + * SPDX-License-Identifier: GPL-3.0-or-later * This file is part of Dolibarr module Subtotal */ @@ -12,6 +26,11 @@ require_once __DIR__ . '/../backport/v19/core/class/commonhookactions.class.php'; +/** + * Class ActionsSubtotal + * + * Hook actions for Subtotal module + */ class ActionsSubtotal extends \subtotal\RetroCompatCommonHookActions { @@ -25,23 +44,28 @@ class ActionsSubtotal extends \subtotal\RetroCompatCommonHookActions */ public $errors = array(); - /** - * @var int Subtotal current level - */ - protected $subtotal_level_cur = 0; + /** + * @var int Subtotal current level + */ + protected $subtotal_level_cur = 0; - /** - * @var bool Show subtotal qty by default - */ - protected $subtotal_show_qty_by_default = false; + /** + * @var bool Show subtotal qty by default + */ + protected $subtotal_show_qty_by_default = false; - /** - * @var bool Determine if sum on subtotal qty is enabled - */ - protected $subtotal_sum_qty_enabled = false; + /** + * @var bool Determine if sum on subtotal qty is enabled + */ + protected $subtotal_sum_qty_enabled = false; - function __construct($db) + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) { global $langs; @@ -51,13 +75,23 @@ function __construct($db) $this->allow_move_block_lines = true; } - function printFieldListSelect($parameters, &$object, &$action, $hookmanager) { + /** + * Print field list select + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @param HookManager $hookmanager Hook manager + * @return int + */ + public function printFieldListSelect($parameters, &$object, &$action, $hookmanager) + { global $type_element, $where; - $contexts = explode(':',$parameters['context']); + $contexts = explode(':', $parameters['context']); - if(in_array('consumptionthirdparty',$contexts) && in_array($type_element, array('propal', 'order', 'invoice', 'supplier_order', 'supplier_invoice', 'supplier_proposal'))) { + if (in_array('consumptionthirdparty', $contexts) && in_array($type_element, array('propal', 'order', 'invoice', 'supplier_order', 'supplier_invoice', 'supplier_proposal'))) { $mod_num = TSubtotal::$module_number; // Not a title (can't use TSubtotal class methods in sql) @@ -66,23 +100,30 @@ function printFieldListSelect($parameters, &$object, &$action, $hookmanager) { $where.= ' AND (d.special_code != '.$mod_num.' OR d.product_type != 9 OR d.qty < 90)'; // Not a free line text (can't use TSubtotal class methods in sql) $where.= ' AND (d.special_code != '.$mod_num.' OR d.product_type != 9 OR d.qty != 50)'; - } return 0; } - function editDictionaryFieldlist($parameters, &$object, &$action, $hookmanager) + /** + * Edit dictionary field list + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @param HookManager $hookmanager Hook manager + * @return int + */ + public function editDictionaryFieldlist($parameters, &$object, &$action, $hookmanager) { global $conf; $dictionnariesTablePrefix = ''; if (intval(DOL_VERSION)< 16) $dictionnariesTablePrefix = MAIN_DB_PREFIX; - if ($parameters['tabname'] == $dictionnariesTablePrefix.'c_subtotal_free_text') - { - $value = TSubtotal::getHtmlDictionnary(); + if ($parameters['tabname'] == $dictionnariesTablePrefix.'c_subtotal_free_text') { + $value = TSubtotal::getHtmlDictionnary(); ?> @@ -107,7 +148,7 @@ function editDictionaryFieldlist($parameters, &$object, &$action, $hookmanager) versionCheck: false }); }); - + } }); @@ -116,16 +157,24 @@ function editDictionaryFieldlist($parameters, &$object, &$action, $hookmanager) return 0; } - function createDictionaryFieldlist($parameters, &$object, &$action, $hookmanager) + /** + * Create dictionary field list + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @param HookManager $hookmanager Hook manager + * @return int + */ + public function createDictionaryFieldlist($parameters, &$object, &$action, $hookmanager) { global $conf; $dictionnariesTablePrefix = ''; if (intval(DOL_VERSION)< 16) $dictionnariesTablePrefix = MAIN_DB_PREFIX; - if ($parameters['tabname'] == $dictionnariesTablePrefix.'c_subtotal_free_text') - { - $value = TSubtotal::getHtmlDictionnary(); + if ($parameters['tabname'] == $dictionnariesTablePrefix.'c_subtotal_free_text') { + $value = TSubtotal::getHtmlDictionnary(); ?> + id] ) ? $_SESSION['subtotal_hideInnerLines_'.$parameters['modulepart']][$object->id] : 0; - $hidedetails = isset( $_SESSION['subtotal_hidedetails_'.$parameters['modulepart']][$object->id] ) ? $_SESSION['subtotal_hidedetails_'.$parameters['modulepart']][$object->id] : 0; + && (in_array('invoicecard', $contextArray) + || in_array('invoicesuppliercard', $contextArray) + || in_array('propalcard', $contextArray) + || in_array('ordercard', $contextArray) + || in_array('ordersuppliercard', $contextArray) + || in_array('invoicereccard', $contextArray)) + ) { + $hideInnerLines = isset($_SESSION['subtotal_hideInnerLines_'.$parameters['modulepart']][$object->id]) ? $_SESSION['subtotal_hideInnerLines_'.$parameters['modulepart']][$object->id] : 0; + $hidedetails = isset($_SESSION['subtotal_hidedetails_'.$parameters['modulepart']][$object->id]) ? $_SESSION['subtotal_hidedetails_'.$parameters['modulepart']][$object->id] : 0; $hidepricesDefaultConf = getDolGlobalString('SUBTOTAL_HIDE_PRICE_DEFAULT_CHECKED')?getDolGlobalString('SUBTOTAL_HIDE_PRICE_DEFAULT_CHECKED') :0; - $hideprices= !empty( $_SESSION['subtotal_hideprices_'.$parameters['modulepart']][$object->id] ) ? $_SESSION['subtotal_hideprices_'.$parameters['modulepart']][$object->id] : $hidepricesDefaultConf; + $hideprices= !empty($_SESSION['subtotal_hideprices_'.$parameters['modulepart']][$object->id]) ? $_SESSION['subtotal_hideprices_'.$parameters['modulepart']][$object->id] : $hidepricesDefaultConf; $var=false; $out = ''; - $out.= ' + $out.= ' '; - $out.= ' + $out.= ' '; - $out.= ' + $out.= ' @@ -604,102 +658,115 @@ function formBuilddocOptions($parameters, &$object) { - if ( + if ( (in_array('propalcard', $contextArray) && getDolGlobalString('SUBTOTAL_PROPAL_ADD_RECAP')) || (in_array('ordercard', $contextArray) && getDolGlobalString('SUBTOTAL_COMMANDE_ADD_RECAP')) - || (in_array('ordersuppliercard', $contextArray) && getDolGlobalString('SUBTOTAL_COMMANDE_ADD_RECAP')) + || (in_array('ordersuppliercard', $contextArray) && getDolGlobalString('SUBTOTAL_COMMANDE_ADD_RECAP')) || (in_array('invoicecard', $contextArray) && getDolGlobalString('SUBTOTAL_INVOICE_ADD_RECAP')) - || (in_array('invoicesuppliercard', $contextArray) && getDolGlobalString('SUBTOTAL_INVOICE_ADD_RECAP')) + || (in_array('invoicesuppliercard', $contextArray) && getDolGlobalString('SUBTOTAL_INVOICE_ADD_RECAP')) || (in_array('invoicereccard', $contextArray) && getDolGlobalString('SUBTOTAL_INVOICE_ADD_RECAP')) - ) - { - $out.= ' + ) { + $out.= ' '; - } + } $this->resprints = $out; - } + } - return 1; + return 1; } - function formEditProductOptions($parameters, &$object, &$action, $hookmanager) - { - - if (in_array('invoicecard',explode(':',$parameters['context']))) - { + /** + * Form edit product options + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @param HookManager $hookmanager Hook manager + * @return int + */ + public function formEditProductOptions($parameters, &$object, &$action, $hookmanager) + { - } + if (in_array('invoicecard', explode(':', $parameters['context']))) { + } - return 0; - } + return 0; + } - function ODTSubstitutionLine(&$parameters, &$object, $action, $hookmanager) { + /** + * ODT substitution line + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @param HookManager $hookmanager Hook manager + * @return int + */ + public function ODTSubstitutionLine(&$parameters, &$object, $action, $hookmanager) + { global $conf; - if($action === 'builddoc' || $action === 'addline' || $action === 'confirm_valid' || $action === 'confirm_paiement') { - + if ($action === 'builddoc' || $action === 'addline' || $action === 'confirm_valid' || $action === 'confirm_paiement') { $line = &$parameters['line']; $object = &$parameters['object']; $substitutionarray = &$parameters['substitutionarray']; - $substitutionarray['line_not_modsubtotal'] = true; - $substitutionarray['line_modsubtotal'] = false; - $substitutionarray['line_modsubtotal_total'] = false; - $substitutionarray['line_modsubtotal_title'] = false; + $substitutionarray['line_not_modsubtotal'] = true; + $substitutionarray['line_modsubtotal'] = false; + $substitutionarray['line_modsubtotal_total'] = false; + $substitutionarray['line_modsubtotal_title'] = false; - if($line->product_type == 9 && $line->special_code == $this->module_number) { + if ($line->product_type == 9 && $line->special_code == $this->module_number) { $substitutionarray['line_modsubtotal'] = 1; - $substitutionarray['line_not_modsubtotal'] = false; + $substitutionarray['line_not_modsubtotal'] = false; $substitutionarray['line_price_ht'] - = $substitutionarray['line_price_vat'] - = $substitutionarray['line_price_ttc'] - = $substitutionarray['line_vatrate'] - = $substitutionarray['line_qty'] - = $substitutionarray['line_up'] - = ''; - - if($line->qty>90) { + = $substitutionarray['line_price_vat'] + = $substitutionarray['line_price_ttc'] + = $substitutionarray['line_vatrate'] + = $substitutionarray['line_qty'] + = $substitutionarray['line_up'] + = ''; + + if ($line->qty>90) { $substitutionarray['line_modsubtotal_total'] = true; //list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1); $TInfo = $this->getTotalLineFromObject($object, $line, '', 1); - $substitutionarray['line_price_ht'] = price($TInfo[0],0,'',1,0,getDolGlobalString('MAIN_MAX_DECIMALS_TOT')); - $substitutionarray['line_price_vat'] = price($TInfo[1],0,'',1,0,getDolGlobalString('MAIN_MAX_DECIMALS_TOT')); - $substitutionarray['line_price_ttc'] = price($TInfo[2],0,'',1,0,getDolGlobalString('MAIN_MAX_DECIMALS_TOT')); + $substitutionarray['line_price_ht'] = price($TInfo[0], 0, '', 1, 0, getDolGlobalString('MAIN_MAX_DECIMALS_TOT')); + $substitutionarray['line_price_vat'] = price($TInfo[1], 0, '', 1, 0, getDolGlobalString('MAIN_MAX_DECIMALS_TOT')); + $substitutionarray['line_price_ttc'] = price($TInfo[2], 0, '', 1, 0, getDolGlobalString('MAIN_MAX_DECIMALS_TOT')); } else { $substitutionarray['line_modsubtotal_title'] = true; } - - - } - else{ + } else { $substitutionarray['line_not_modsubtotal'] = true; $substitutionarray['line_modsubtotal'] = 0; } - } return 0; } /** - * @param array $parameters - * @param CommonObject $object - * @param string $action - * @param HookManager $hookmanager + * Do actions + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @param HookManager $hookmanager Hook manager * @return int|void */ - function doActions($parameters, &$object, $action, $hookmanager) + public function doActions($parameters, &$object, $action, $hookmanager) { global $db, $conf, $langs,$user; $contextArray = array(); @@ -711,20 +778,16 @@ function doActions($parameters, &$object, $action, $hookmanager) $showBlockExtrafields = GETPOST('showBlockExtrafields', 'none'); - if(isset($object->element) && $object->element=='facture') $idvar = 'facid'; + if (isset($object->element) && $object->element=='facture') $idvar = 'facid'; else $idvar = 'id'; - if ($action == 'updateligne' || $action == 'updateline') - { + if ($action == 'updateligne' || $action == 'updateline') { $found = false; $lineid = GETPOST('lineid', 'int'); - foreach ($object->lines as &$line) - { - - if ($line->id == $lineid && TSubtotal::isModSubtotalLine($line)) - { + foreach ($object->lines as &$line) { + if ($line->id == $lineid && TSubtotal::isModSubtotalLine($line)) { $found = true; - if(TSubtotal::isTitle($line) && !empty($showBlockExtrafields)) { + if (TSubtotal::isTitle($line) && !empty($showBlockExtrafields)) { $extrafieldsline = new ExtraFields($db); $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); $extrafieldsline->setOptionalsFromPost($extralabelsline, $line); @@ -737,54 +800,44 @@ function doActions($parameters, &$object, $action, $hookmanager) } } - if ($found) - { + if ($found) { header('Location: '.$_SERVER['PHP_SELF'].'?'.$idvar.'='.$object->id); exit; // Surtout ne pas laisser Dolibarr faire du traitement sur le updateligne sinon ça plante les données de la ligne } - } - else if($action === 'builddoc') { - + } elseif ($action === 'builddoc') { if ( in_array('invoicecard', $contextArray) || in_array('propalcard', $contextArray) || in_array('ordercard', $contextArray) - || in_array('ordersuppliercard', $contextArray) - || in_array('invoicesuppliercard', $contextArray) - || in_array('supplier_proposalcard', $contextArray) - ) - { - if(in_array('invoicecard',$contextArray)) { + || in_array('ordersuppliercard', $contextArray) + || in_array('invoicesuppliercard', $contextArray) + || in_array('supplier_proposalcard', $contextArray) + ) { + if (in_array('invoicecard', $contextArray)) { $sessname = 'subtotal_hideInnerLines_facture'; $sessname2 = 'subtotal_hidedetails_facture'; $sessname3 = 'subtotal_hideprices_facture'; - } - elseif(in_array('invoicesuppliercard',$contextArray)) { - $sessname = 'subtotal_hideInnerLines_facture_fournisseur'; - $sessname2 = 'subtotal_hidedetails_facture_fournisseur'; - $sessname3 = 'subtotal_hideprices_facture_fournisseur'; - } - elseif(in_array('propalcard',$contextArray)) { + } elseif (in_array('invoicesuppliercard', $contextArray)) { + $sessname = 'subtotal_hideInnerLines_facture_fournisseur'; + $sessname2 = 'subtotal_hidedetails_facture_fournisseur'; + $sessname3 = 'subtotal_hideprices_facture_fournisseur'; + } elseif (in_array('propalcard', $contextArray)) { $sessname = 'subtotal_hideInnerLines_propal'; $sessname2 = 'subtotal_hidedetails_propal'; $sessname3 = 'subtotal_hideprices_propal'; - } - elseif(in_array('supplier_proposalcard',$contextArray)) { - $sessname = 'subtotal_hideInnerLines_supplier_proposal'; - $sessname2 = 'subtotal_hidedetails_supplier_proposal'; - $sessname3 = 'subtotal_hideprices_supplier_proposal'; - } - elseif(in_array('ordercard',$contextArray)) { + } elseif (in_array('supplier_proposalcard', $contextArray)) { + $sessname = 'subtotal_hideInnerLines_supplier_proposal'; + $sessname2 = 'subtotal_hidedetails_supplier_proposal'; + $sessname3 = 'subtotal_hideprices_supplier_proposal'; + } elseif (in_array('ordercard', $contextArray)) { $sessname = 'subtotal_hideInnerLines_commande'; $sessname2 = 'subtotal_hidedetails_commande'; $sessname3 = 'subtotal_hideprices_commande'; - } - elseif(in_array('ordersuppliercard',$contextArray)) { - $sessname = 'subtotal_hideInnerLines_commande_fournisseur'; - $sessname2 = 'subtotal_hidedetails_commande_fournisseur'; - $sessname3 = 'subtotal_hideprices_commande_fournisseur'; - } - else { + } elseif (in_array('ordersuppliercard', $contextArray)) { + $sessname = 'subtotal_hideInnerLines_commande_fournisseur'; + $sessname2 = 'subtotal_hidedetails_commande_fournisseur'; + $sessname3 = 'subtotal_hideprices_commande_fournisseur'; + } else { $sessname = 'subtotal_hideInnerLines_unknown'; $sessname2 = 'subtotal_hidedetails_unknown'; $sessname3 = 'subtotal_hideprices_unknown'; @@ -794,7 +847,7 @@ function doActions($parameters, &$object, $action, $hookmanager) $hideInnerLines = GETPOST('hideInnerLines', 'int'); if (!array_key_exists($sessname, $_SESSION) || empty($_SESSION[$sessname]) || !is_array($_SESSION[$sessname]) || !isset($_SESSION[$sessname][$object->id]) || !is_array($_SESSION[$sessname][$object->id])) - $_SESSION[$sessname] = array($object->id => 0); // prevent old system + $_SESSION[$sessname] = array($object->id => 0); // prevent old system $_SESSION[$sessname][$object->id] = $hideInnerLines; $hidedetails= GETPOST('hidedetails', 'int'); @@ -807,87 +860,77 @@ function doActions($parameters, &$object, $action, $hookmanager) $_SESSION[$sessname3] = array($object->id => 0); // prevent old system $_SESSION[$sessname3][$object->id] = $hideprices; - foreach($object->lines as &$line) { + foreach ($object->lines as &$line) { if ($line->product_type == 9 && $line->special_code == $this->module_number) { - - if($line->qty>=90) { - $line->modsubtotal_total = 1; - } - else{ - $line->modsubtotal_title = 1; - } + if ($line->qty>=90) { + $line->modsubtotal_total = 1; + } else { + $line->modsubtotal_title = 1; + } $line->total_ht = $this->getTotalLineFromObject($object, $line, ''); } - } - } - - } - else if($action === 'confirm_delete_all_lines' && GETPOST('confirm', 'none')=='yes') { + } + } + } elseif ($action === 'confirm_delete_all_lines' && GETPOST('confirm', 'none')=='yes') { $error = 0; $Tab = TSubtotal::getLinesFromTitleId($object, GETPOST('lineid', 'int'), true); - foreach($Tab as $line) { - $result = 0; + foreach ($Tab as $line) { + $result = 0; $idLine = $line->id; /** * @var $object Facture */ - if($object->element=='facture') $result = $object->deleteline($idLine); + if ($object->element=='facture') $result = $object->deleteline($idLine); /** * @var $object Facture fournisseur */ - else if($object->element=='invoice_supplier') - { + elseif ($object->element=='invoice_supplier') { $result = $object->deleteline($idLine); - } + } // /** * @var $object Propal */ - else if($object->element=='propal') $result = $object->deleteline($idLine); + elseif ($object->element=='propal') $result = $object->deleteline($idLine); /** * @var $object Propal Fournisseur */ - else if($object->element=='supplier_proposal') $result = $object->deleteline($idLine); + elseif ($object->element=='supplier_proposal') $result = $object->deleteline($idLine); /** * @var $object Commande */ - else if($object->element=='commande') - { + elseif ($object->element=='commande') { $result = $object->deleteline($user, $idLine); - } + } // /** * @var $object Commande fournisseur */ - else if($object->element=='order_supplier') - { - $result = $object->deleteline($idLine); - } + elseif ($object->element=='order_supplier') { + $result = $object->deleteline($idLine); + } // /** * @var $object Facturerec */ - else if($object->element=='facturerec') $result = $object->deleteline($idLine); + elseif ($object->element=='facturerec') $result = $object->deleteline($idLine); /** * @var $object Expedition */ - else if($object->element=='shipping') $result = $object->deleteline($user, $idLine); + elseif ($object->element=='shipping') $result = $object->deleteline($user, $idLine); - if ($result < 0) $error++; + if ($result < 0) $error++; } - if ($error > 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $db->rollback(); - } else { - $db->commit(); - } + if ($error > 0) { + setEventMessages($object->error, $object->errors, 'errors'); + $db->rollback(); + } else { + $db->commit(); + } header('location:?id='.$object->id); exit; - - } - else if ($action == 'duplicate') - { + } elseif ($action == 'duplicate') { $lineid = GETPOST('lineid', 'int'); $nbDuplicate = TSubtotal::duplicateLines($object, $lineid, true); @@ -897,114 +940,127 @@ function doActions($parameters, &$object, $action, $hookmanager) header('Location: ?id='.$object->id); exit; - } - - elseif ((!empty($parameters['currentcontext']) && $parameters['currentcontext'] == 'orderstoinvoice') + } elseif ((!empty($parameters['currentcontext']) && $parameters['currentcontext'] == 'orderstoinvoice') || in_array('orderstoinvoice', $contextArray) || in_array('orderstoinvoicesupplier', $contextArray) || in_array('orderlist', $contextArray) ) { $this->_billOrdersAddCheckBoxForTitleBlocks(); + } else { + // when automatic generate is enabled : keep last selected options from last "builddoc" action (ganerate document manually) + if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { + if (in_array('invoicecard', $contextArray) + || in_array('propalcard', $contextArray) + || in_array('ordercard', $contextArray) + || in_array('ordersuppliercard', $contextArray) + || in_array('invoicesuppliercard', $contextArray) + || in_array('supplier_proposalcard', $contextArray) + ) { + $confirm = GETPOST('confirm', 'alpha'); + + if ($action == 'modif' + || ($action == 'confirm_modif' && $confirm == 'yes') + || ($action == 'confirm_edit' && $confirm == 'yes') + || $action == 'reopen' + || (($action == 'confirm_validate' || $action == 'confirm_valid') && $confirm == 'yes') + ) { + if (in_array('invoicecard', $contextArray)) { + $sessname = 'subtotal_hideInnerLines_facture'; + $sessname2 = 'subtotal_hidedetails_facture'; + $sessname3 = 'subtotal_hideprices_facture'; + } elseif (in_array('invoicesuppliercard', $contextArray)) { + $sessname = 'subtotal_hideInnerLines_facture_fournisseur'; + $sessname2 = 'subtotal_hidedetails_facture_fournisseur'; + $sessname3 = 'subtotal_hideprices_facture_fournisseur'; + } elseif (in_array('propalcard', $contextArray)) { + $sessname = 'subtotal_hideInnerLines_propal'; + $sessname2 = 'subtotal_hidedetails_propal'; + $sessname3 = 'subtotal_hideprices_propal'; + } elseif (in_array('supplier_proposalcard', $contextArray)) { + $sessname = 'subtotal_hideInnerLines_supplier_proposal'; + $sessname2 = 'subtotal_hidedetails_supplier_proposal'; + $sessname3 = 'subtotal_hideprices_supplier_proposal'; + } elseif (in_array('ordercard', $contextArray)) { + $sessname = 'subtotal_hideInnerLines_commande'; + $sessname2 = 'subtotal_hidedetails_commande'; + $sessname3 = 'subtotal_hideprices_commande'; + } elseif (in_array('ordersuppliercard', $contextArray)) { + $sessname = 'subtotal_hideInnerLines_commande_fournisseur'; + $sessname2 = 'subtotal_hidedetails_commande_fournisseur'; + $sessname3 = 'subtotal_hideprices_commande_fournisseur'; + } else { + $sessname = 'subtotal_hideInnerLines_unknown'; + $sessname2 = 'subtotal_hidedetails_unknown'; + $sessname3 = 'subtotal_hideprices_unknown'; + } + + global $hidedetails; // same name as in global card (proposal, order, invoice, ...) + global $hideprices; // used as global value in this module + + if (GETPOSTISSET('hideInnerLines')) { + $hideInnerLines = GETPOST('hideInnerLines', 'int'); + } else { + $hideInnerLines = isset($_SESSION[$sessname][$object->id]) ? $_SESSION[$sessname][$object->id] : 0; + } + $_POST['hideInnerLines'] = $hideInnerLines; + + if (GETPOSTISSET('hidedetails')) { + $hidedetails = GETPOST('hidedetails', 'int'); + } else { + $hidedetails = isset($_SESSION[$sessname2][$object->id]) ? $_SESSION[$sessname2][$object->id] : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0); + } + // no need to set POST value (it's a global value used in global card) + + if (GETPOSTISSET('hideprices')) { + $hideprices = GETPOST('hideprices', 'int'); + } else { + $hidepricesDefaultConf = getDolGlobalString('SUBTOTAL_HIDE_PRICE_DEFAULT_CHECKED') ? getDolGlobalString('SUBTOTAL_HIDE_PRICE_DEFAULT_CHECKED') : 0; + $hideprices = isset($_SESSION[$sessname3][$object->id]) ? $_SESSION[$sessname3][$object->id] : $hidepricesDefaultConf; + } + // no need to set POST value (it's a global value used in this module) + } + } + } } - else { - // when automatic generate is enabled : keep last selected options from last "builddoc" action (ganerate document manually) - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { - if (in_array('invoicecard', $contextArray) - || in_array('propalcard', $contextArray) - || in_array('ordercard', $contextArray) - || in_array('ordersuppliercard', $contextArray) - || in_array('invoicesuppliercard', $contextArray) - || in_array('supplier_proposalcard', $contextArray) - ) { - $confirm = GETPOST('confirm', 'alpha'); - - if ($action == 'modif' - || ($action == 'confirm_modif' && $confirm == 'yes') - || ($action == 'confirm_edit' && $confirm == 'yes') - || $action == 'reopen' - || (($action == 'confirm_validate' || $action == 'confirm_valid') && $confirm == 'yes') - ) { - if (in_array('invoicecard', $contextArray)) { - $sessname = 'subtotal_hideInnerLines_facture'; - $sessname2 = 'subtotal_hidedetails_facture'; - $sessname3 = 'subtotal_hideprices_facture'; - } elseif (in_array('invoicesuppliercard', $contextArray)) { - $sessname = 'subtotal_hideInnerLines_facture_fournisseur'; - $sessname2 = 'subtotal_hidedetails_facture_fournisseur'; - $sessname3 = 'subtotal_hideprices_facture_fournisseur'; - } elseif (in_array('propalcard', $contextArray)) { - $sessname = 'subtotal_hideInnerLines_propal'; - $sessname2 = 'subtotal_hidedetails_propal'; - $sessname3 = 'subtotal_hideprices_propal'; - } elseif (in_array('supplier_proposalcard', $contextArray)) { - $sessname = 'subtotal_hideInnerLines_supplier_proposal'; - $sessname2 = 'subtotal_hidedetails_supplier_proposal'; - $sessname3 = 'subtotal_hideprices_supplier_proposal'; - } elseif (in_array('ordercard', $contextArray)) { - $sessname = 'subtotal_hideInnerLines_commande'; - $sessname2 = 'subtotal_hidedetails_commande'; - $sessname3 = 'subtotal_hideprices_commande'; - } elseif (in_array('ordersuppliercard', $contextArray)) { - $sessname = 'subtotal_hideInnerLines_commande_fournisseur'; - $sessname2 = 'subtotal_hidedetails_commande_fournisseur'; - $sessname3 = 'subtotal_hideprices_commande_fournisseur'; - } else { - $sessname = 'subtotal_hideInnerLines_unknown'; - $sessname2 = 'subtotal_hidedetails_unknown'; - $sessname3 = 'subtotal_hideprices_unknown'; - } - - global $hidedetails; // same name as in global card (proposal, order, invoice, ...) - global $hideprices; // used as global value in this module - - if (GETPOSTISSET('hideInnerLines')) { - $hideInnerLines = GETPOST('hideInnerLines', 'int'); - } else { - $hideInnerLines = isset($_SESSION[$sessname][$object->id]) ? $_SESSION[$sessname][$object->id] : 0; - } - $_POST['hideInnerLines'] = $hideInnerLines; - - if (GETPOSTISSET('hidedetails')) { - $hidedetails = GETPOST('hidedetails', 'int'); - } else { - $hidedetails = isset($_SESSION[$sessname2][$object->id]) ? $_SESSION[$sessname2][$object->id] : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0); - } - // no need to set POST value (it's a global value used in global card) - - if (GETPOSTISSET('hideprices')) { - $hideprices = GETPOST('hideprices', 'int'); - } else { - $hidepricesDefaultConf = getDolGlobalString('SUBTOTAL_HIDE_PRICE_DEFAULT_CHECKED') ? getDolGlobalString('SUBTOTAL_HIDE_PRICE_DEFAULT_CHECKED') : 0; - $hideprices = isset($_SESSION[$sessname3][$object->id]) ? $_SESSION[$sessname3][$object->id] : $hidepricesDefaultConf; - } - // no need to set POST value (it's a global value used in this module) - } - } - } - } - - return 0; + + return 0; } - function formAddObjectLine ($parameters, &$object, &$action, $hookmanager) { + /** + * Form add object line + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @param HookManager $hookmanager Hook manager + * @return int + */ + public function formAddObjectLine($parameters, &$object, &$action, $hookmanager) + { return 0; } - function changeRoundingMode($parameters, &$object, &$action, $hookmanager) + /** + * Change rounding mode + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @param HookManager $hookmanager Hook manager + * @return int + */ + public function changeRoundingMode($parameters, &$object, &$action, $hookmanager) { global $conf; - if (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && !empty($object->table_element_line) && in_array($object->element, array('commande', 'facture', 'propal'))) - { + if (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && !empty($object->table_element_line) && in_array($object->element, array('commande', 'facture', 'propal'))) { if ($object->element == 'commande') $obj = new OrderLine($object->db); if ($object->element == 'propal') $obj = new PropaleLigne($object->db); if ($object->element == 'facture') $obj = new FactureLigne($object->db); - if (!empty($parameters['fk_element'])) - { - - if($obj->fetch($parameters['fk_element'])){ + if (!empty($parameters['fk_element'])) { + if ($obj->fetch($parameters['fk_element'])) { $obj->id= $obj->rowid; if (empty($obj->array_options)) $obj->fetch_optionals(); @@ -1017,27 +1073,34 @@ function changeRoundingMode($parameters, &$object, &$action, $hookmanager) return 0; } - function getArrayOfLineForAGroup(&$object, $lineid) { + /** + * Get array of line for a group + * + * @param CommonObject $object Object + * @param int $lineid Line ID + * @return array + */ + public function getArrayOfLineForAGroup(&$object, $lineid) + { $qty_line = 0; - $qty_end_line = 0; + $qty_end_line = 0; $found = false; $Tab= array(); - foreach($object->lines as $l) { - $lid = (!empty($l->rowid) ? $l->rowid : $l->id); + foreach ($object->lines as $l) { + $lid = (!empty($l->rowid) ? $l->rowid : $l->id); - if($lid == $lineid && $l->qty > 0 && $l->qty < 10) { + if ($lid == $lineid && $l->qty > 0 && $l->qty < 10) { $found = true; $qty_line = $l->qty; - $qty_end_line = 100 - $qty_line; + $qty_end_line = 100 - $qty_line; } - if($found) { - if ($l->special_code == $this->module_number && $lid != $lineid && ($l->qty <= $qty_line || $l->qty >= $qty_end_line)) { - if ($l->qty == $qty_end_line) $Tab[] = $lid; - break; - } - else $Tab[] = $lid; + if ($found) { + if ($l->special_code == $this->module_number && $lid != $lineid && ($l->qty <= $qty_line || $l->qty >= $qty_end_line)) { + if ($l->qty == $qty_end_line) $Tab[] = $lid; + break; + } else $Tab[] = $lid; } } @@ -1045,28 +1108,31 @@ function getArrayOfLineForAGroup(&$object, $lineid) { } - //@TODO change all call to this method with the method in lib !!!! + //@TODO change all call to this method with the method in lib !!!! /** - * @param $object - * @param $line - * @param false $use_level - * @param int $return_all + * Get total line from object + * + * @param CommonObject $object Object + * @param CommonObjectLine $line Line + * @param bool $use_level Use level + * @param int $return_all Return all * @return array|float|int */ - function getTotalLineFromObject(&$object, &$line, $use_level=false, $return_all=0) { + public function getTotalLineFromObject(&$object, &$line, $use_level = false, $return_all = 0) + { global $conf; $rang = $line->rang; $qty_line = $line->qty; $lvl = 0; - if (TSubtotal::isSubtotal($line)) $lvl = TSubtotal::getNiveau($line); + if (TSubtotal::isSubtotal($line)) $lvl = TSubtotal::getNiveau($line); $title_break = TSubtotal::getParentTitleOfLine($object, $rang, $lvl); $total = 0; $total_tva = 0; $total_ttc = 0; - $total_qty = 0; + $total_qty = 0; $TTotal_tva = array(); @@ -1080,91 +1146,87 @@ function getTotalLineFromObject(&$object, &$line, $use_level=false, $return_all= $TLineReverse = array_reverse($object->lines); - foreach($TLineReverse as $l) - { + foreach ($TLineReverse as $l) { $l->total_ttc = doubleval($l->total_ttc); $l->total_ht = doubleval($l->total_ht); //print $l->rang.'>='.$rang.' '.$total.'
'; - if ($l->rang>=$rang) continue; - if (!empty($title_break) && $title_break->id == $l->id) break; - elseif (!TSubtotal::isModSubtotalLine($l)) - { - $total_qty += $l->qty; - // TODO retirer le test avec $builddoc quand Dolibarr affichera le total progression sur la card et pas seulement dans le PDF - if ($builddoc && $object->element == 'facture' && $object->type==Facture::TYPE_SITUATION) - { - if ($l->situation_percent > 0 && !empty($l->total_ht)) - { - $prev_progress = 0; - $progress = 1; - if (method_exists($l, 'get_prev_progress')) - { - $prev_progress = $l->get_prev_progress($object->id); - $progress = ($l->situation_percent - $prev_progress) / 100; - } - - $result = $sign * ($l->total_ht / ($l->situation_percent / 100)) * $progress; - $total+= $result; - // TODO check si les 3 lignes du dessous sont corrects - $total_tva += $sign * ($l->total_tva / ($l->situation_percent / 100)) * $progress; - $TTotal_tva[$l->tva_tx] += $sign * ($l->total_tva / ($l->situation_percent / 100)) * $progress; - $total_ttc += $sign * ($l->total_tva / ($l->total_ttc / 100)) * $progress; - - } - } - else - { - if ($l->product_type != 9) { - $total += $l->total_ht; - $total_tva += $l->total_tva; - - if(! isset($TTotal_tva[$l->tva_tx])) { - $TTotal_tva[$l->tva_tx] = 0; - } - $TTotal_tva[$l->tva_tx] += $l->total_tva; - - $total_ttc += $l->total_ttc; + if ($l->rang>=$rang) continue; + if (!empty($title_break) && $title_break->id == $l->id) break; + elseif (!TSubtotal::isModSubtotalLine($l)) { + $total_qty += $l->qty; + // TODO retirer le test avec $builddoc quand Dolibarr affichera le total progression sur la card et pas seulement dans le PDF + if ($builddoc && $object->element == 'facture' && $object->type==Facture::TYPE_SITUATION) { + if ($l->situation_percent > 0 && !empty($l->total_ht)) { + $prev_progress = 0; + $progress = 1; + if (method_exists($l, 'get_prev_progress')) { + $prev_progress = $l->get_prev_progress($object->id); + $progress = ($l->situation_percent - $prev_progress) / 100; + } + + $result = $sign * ($l->total_ht / ($l->situation_percent / 100)) * $progress; + $total+= $result; + // TODO check si les 3 lignes du dessous sont corrects + $total_tva += $sign * ($l->total_tva / ($l->situation_percent / 100)) * $progress; + $TTotal_tva[$l->tva_tx] += $sign * ($l->total_tva / ($l->situation_percent / 100)) * $progress; + $total_ttc += $sign * ($l->total_tva / ($l->total_ttc / 100)) * $progress; + } + } else { + if ($l->product_type != 9) { + $total += $l->total_ht; + $total_tva += $l->total_tva; + + if (! isset($TTotal_tva[$l->tva_tx])) { + $TTotal_tva[$l->tva_tx] = 0; + } + $TTotal_tva[$l->tva_tx] += $l->total_tva; + + $total_ttc += $l->total_ttc; + } + } } - } - } } if (!$return_all) return $total; else return array($total, $total_tva, $total_ttc, $TTotal_tva, $total_qty); } /** - * @param $pdf TCPDF PDF object - * @param $object CommonObject dolibarr object - * @param $line CommonObjectLine dolibarr object line - * @param $label string - * @param $description string - * @param $posx float horizontal position - * @param $posy float vertical position - * @param $w float width - * @param $h float height + * PDF add total + * + * @param TCPDF $pdf PDF object + * @param CommonObject $object Object + * @param CommonObjectLine $line Line + * @param string $label Label + * @param string $description Description + * @param float $posx Position X + * @param float $posy Position Y + * @param float $w Width + * @param float $h Height + * @return void */ - function pdf_add_total(&$pdf,&$object, &$line, $label, $description,$posx, $posy, $w, $h) { + public function pdfAddTotal(&$pdf, &$object, &$line, $label, $description, $posx, $posy, $w, $h) + { global $conf,$subtotal_last_title_posy,$langs; $subtotalDefaultTopPadding = 1; $subtotalDefaultBottomPadding = 1; $subtotalDefaultLeftPadding = 0.5; $subtotalDefaultRightPadding = 0.5; - $backgroundCellHeightOffset = 0; - $backgroundCellPosYOffset = 0; + $backgroundCellHeightOffset = 0; + $backgroundCellPosYOffset = 0; empty($pdf->page_largeur) ? $pdf->page_largeur = 0 : ''; empty($pdf->marge_droite) ? $pdf->marge_droite = 0 : ''; empty($line->total) ? $line->total = 0 : '' ; empty($pdf->postotalht) ? $pdf->postotalht = 0 : '' ; $fillBackground = false; - if(getDolGlobalString('SUBTOTAL_SUBTOTAL_BACKGROUNDCOLOR') + if (getDolGlobalString('SUBTOTAL_SUBTOTAL_BACKGROUNDCOLOR') && function_exists('colorValidateHex') && colorValidateHex(getDolGlobalString('SUBTOTAL_SUBTOTAL_BACKGROUNDCOLOR')) && function_exists('colorStringToArray') && function_exists('colorIsLight') - ){ + ) { $fillBackground = true; @@ -1172,25 +1234,24 @@ function pdf_add_total(&$pdf,&$object, &$line, $label, $description,$posx, $posy // mais avant d'ajouter une exeption ici verifier si il ne faut pas plutôt effectuer un fix sur le PDF // ex : les "Anciens PDF n'utilisent pas le padding pour les texts contrairement au "nouveaux PDF" c'est pourquoi les nouveaux PDF disposent d'un affichage mieux positionné - if(getDolGlobalString('SUBTOTAL_BACKGROUND_CELL_HEIGHT_OFFSET')){ + if (getDolGlobalString('SUBTOTAL_BACKGROUND_CELL_HEIGHT_OFFSET')) { $backgroundCellHeightOffset = doubleval(getDolGlobalString('SUBTOTAL_BACKGROUND_CELL_HEIGHT_OFFSET')); } - if(getDolGlobalString('SUBTOTAL_BACKGROUND_CELL_POS_Y_OFFSET')){ + if (getDolGlobalString('SUBTOTAL_BACKGROUND_CELL_POS_Y_OFFSET')) { $backgroundCellPosYOffset = doubleval(getDolGlobalString('SUBTOTAL_BACKGROUND_CELL_POS_Y_OFFSET')); } - $backgroundColor = colorStringToArray(getDolGlobalString('SUBTOTAL_SUBTOTAL_BACKGROUNDCOLOR') ,array(233, 233, 233)); + $backgroundColor = colorStringToArray(getDolGlobalString('SUBTOTAL_SUBTOTAL_BACKGROUNDCOLOR'), array(233, 233, 233)); //background color if (!colorIsLight(getDolGlobalString('SUBTOTAL_SUBTOTAL_BACKGROUNDCOLOR'))) { - $pdf->setColor('text', 255,255,255); + $pdf->setColor('text', 255, 255, 255); } } // POUR LES PDF DE TYPE PDF_EVOLUTION (ceux avec les colonnes configurables) $pdfModelUseColSystem = !empty($object->context['subtotalPdfModelInfo']->cols); // justilise une variable au cas ou le test evolue - if($pdfModelUseColSystem){ - + if ($pdfModelUseColSystem) { include_once __DIR__ . '/staticPdf.model.php'; $staticPdfModel = new ModelePDFStatic($object->db); $staticPdfModel->marge_droite = $object->context['subtotalPdfModelInfo']->marge_droite; @@ -1198,67 +1259,64 @@ function pdf_add_total(&$pdf,&$object, &$line, $label, $description,$posx, $posy $staticPdfModel->page_largeur = $object->context['subtotalPdfModelInfo']->page_largeur; $staticPdfModel->page_hauteur = $object->context['subtotalPdfModelInfo']->page_hauteur; $staticPdfModel->cols = $object->context['subtotalPdfModelInfo']->cols; - if ( property_exists($object->context['subtotalPdfModelInfo'], 'defaultTitlesFieldsStyle')){ + if ( property_exists($object->context['subtotalPdfModelInfo'], 'defaultTitlesFieldsStyle')) { $staticPdfModel->defaultTitlesFieldsStyle = $object->context['subtotalPdfModelInfo']->defaultTitlesFieldsStyle; } - if (property_exists($object->context['subtotalPdfModelInfo'], 'defaultContentsFieldsStyle')){ + if (property_exists($object->context['subtotalPdfModelInfo'], 'defaultContentsFieldsStyle')) { $staticPdfModel->defaultContentsFieldsStyle = $object->context['subtotalPdfModelInfo']->defaultContentsFieldsStyle; } $staticPdfModel->prepareArrayColumnField($object, $langs); - if(isset($staticPdfModel->cols['totalexcltax']['content']['padding'][0])){ + if (isset($staticPdfModel->cols['totalexcltax']['content']['padding'][0])) { $subtotalDefaultTopPadding = $staticPdfModel->cols['totalexcltax']['content']['padding'][0]; } - if(isset($staticPdfModel->cols['totalexcltax']['content']['padding'][2])){ + if (isset($staticPdfModel->cols['totalexcltax']['content']['padding'][2])) { $subtotalDefaultBottomPadding = $staticPdfModel->cols['totalexcltax']['content']['padding'][0]; } - if(isset($staticPdfModel->cols['totalincltax']['content']['padding'][0])){ + if (isset($staticPdfModel->cols['totalincltax']['content']['padding'][0])) { $subtotalDefaultTopPadding = $staticPdfModel->cols['totalincltax']['content']['padding'][0]; } - if(isset($staticPdfModel->cols['totalincltax']['content']['padding'][2])){ + if (isset($staticPdfModel->cols['totalincltax']['content']['padding'][2])) { $subtotalDefaultBottomPadding = $staticPdfModel->cols['totalincltax']['content']['padding'][0]; } } $hideInnerLines = GETPOST('hideInnerLines', 'int'); - if (getDolGlobalString('SUBTOTAL_ONE_LINE_IF_HIDE_INNERLINES') && $hideInnerLines && !empty($subtotal_last_title_posy)) - { + if (getDolGlobalString('SUBTOTAL_ONE_LINE_IF_HIDE_INNERLINES') && $hideInnerLines && !empty($subtotal_last_title_posy)) { $posy = $subtotal_last_title_posy; $subtotal_last_title_posy = null; } $hidePriceOnSubtotalLines = GETPOST('hide_price_on_subtotal_lines', 'int'); - if($object->element == 'shipping' || $object->element == 'delivery') - { + if ($object->element == 'shipping' || $object->element == 'delivery') { $hidePriceOnSubtotalLines = 1; } $set_pagebreak_margin = false; - if(method_exists('Closure','bind')) { + if (method_exists('Closure', 'bind')) { $pageBreakOriginalValue = $pdf->AcceptPageBreak(); $sweetsThief = function ($pdf) { - return $pdf->bMargin ; + return $pdf->bMargin ; }; $sweetsThief = Closure::bind($sweetsThief, null, $pdf); $bMargin = $sweetsThief($pdf); - $pdf->SetAutoPageBreak( false ); + $pdf->SetAutoPageBreak(false); $set_pagebreak_margin = true; } - if($line->qty==99) - $pdf->SetFillColor(220,220,220); + if ($line->qty==99) + $pdf->SetFillColor(220, 220, 220); elseif ($line->qty==98) - $pdf->SetFillColor(230,230,230); - else - $pdf->SetFillColor(240,240,240); + $pdf->SetFillColor(230, 230, 230); + else $pdf->SetFillColor(240, 240, 240); $style = 'B'; if (getDolGlobalString('SUBTOTAL_SUBTOTAL_STYLE')) $style = getDolGlobalString('SUBTOTAL_SUBTOTAL_STYLE'); @@ -1269,76 +1327,66 @@ function pdf_add_total(&$pdf,&$object, &$line, $label, $description,$posx, $posy // save curent cell padding $curentCellPaddinds = $pdf->getCellPaddings(); // set cell padding with column content definition for old PDF compatibility - $pdf->setCellPaddings($curentCellPaddinds['L'],$subtotalDefaultTopPadding, $curentCellPaddinds['R'],$subtotalDefaultBottomPadding); + $pdf->setCellPaddings($curentCellPaddinds['L'], $subtotalDefaultTopPadding, $curentCellPaddinds['R'], $subtotalDefaultBottomPadding); $pdf->writeHTMLCell($w, $h, $posx, $posy, $label, 0, 1, false, true, 'R', true); -// var_dump($bMargin); + // var_dump($bMargin); $pageAfter = $pdf->getPage(); //Print background $cell_height = $pdf->getStringHeight($w, $label); // POUR LES PDF DE TYPE PDF_EVOLUTION (ceux avec les colonnes configurables) - if($pdfModelUseColSystem){ + if ($pdfModelUseColSystem) { if ($fillBackground) { $pdf->SetFillColor($backgroundColor[0], $backgroundColor[1], $backgroundColor[2]); } $pdf->SetXY($object->context['subtotalPdfModelInfo']->marge_droite, $posy+$backgroundCellPosYOffset); $pdf->MultiCell($object->context['subtotalPdfModelInfo']->page_largeur - $object->context['subtotalPdfModelInfo']->marge_gauche - $object->context['subtotalPdfModelInfo']->marge_droite, $cell_height, '', 0, '', 1); - } - else{ + } else { $pdf->SetXY($posx, $posy+$backgroundCellPosYOffset); //-1 to take into account the entire height of the row //background color - if ($fillBackground) - { + if ($fillBackground) { $pdf->SetFillColor($backgroundColor[0], $backgroundColor[1], $backgroundColor[2]); $pdf->SetFont('', '', 9); //remove UBI for the background $pdf->MultiCell($pdf->page_largeur - $pdf->marge_droite, $cell_height+$backgroundCellHeightOffset, '', 0, '', 1); //+2 same of SetXY() $pdf->SetXY($posx, $posy); //reset position $pdf->SetFont('', $style, 9); //reset style - } - else { + } else { $pdf->MultiCell($pdf->page_largeur - $pdf->marge_droite, $cell_height, '', 0, '', 1); } } if (!$hidePriceOnSubtotalLines) { - $total_to_print = price($line->total,0,'',1,0,getDolGlobalInt('MAIN_MAX_DECIMALS_TOT')); - if (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS')) - { + $total_to_print = price($line->total, 0, '', 1, 0, getDolGlobalInt('MAIN_MAX_DECIMALS_TOT')); + if (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS')) { $TTitle = TSubtotal::getAllTitleFromLine($line); - foreach ($TTitle as &$line_title) - { - if (!empty($line_title->array_options['options_subtotal_nc'])) - { + foreach ($TTitle as &$line_title) { + if (!empty($line_title->array_options['options_subtotal_nc'])) { $total_to_print = ''; // TODO Gestion "Compris/Non compris", voir si on affiche une annotation du genre "NC" break; } } } - if($total_to_print !== '') { - - if (GETPOST('hideInnerLines', 'int')) - { + if ($total_to_print !== '') { + if (GETPOST('hideInnerLines', 'int')) { // Dans le cas des lignes cachés, le calcul est déjà fait dans la méthode beforePDFCreation et les lignes de sous-totaux sont déjà renseignés -// $line->TTotal_tva -// $line->total_ht -// $line->total_tva -// $line->total -// $line->total_ttc - } - else - { + // $line->TTotal_tva + // $line->total_ht + // $line->total_tva + // $line->total + // $line->total_ttc + } else { // list($total, $total_tva, $total_ttc, $TTotal_tva) = $this->getTotalLineFromObject($object, $line, '', 1); $TInfo = $this->getTotalLineFromObject($object, $line, '', 1); $TTotal_tva = $TInfo[3]; - $total_to_print = price($TInfo[0],0,'',1,0,getDolGlobalInt('MAIN_MAX_DECIMALS_TOT')); + $total_to_print = price($TInfo[0], 0, '', 1, 0, getDolGlobalInt('MAIN_MAX_DECIMALS_TOT')); - $line->total_ht = $TInfo[0]; + $line->total_ht = $TInfo[0]; $line->total = $TInfo[0]; if (!TSubtotal::isModSubtotalLine($line)) $line->total_tva = $TInfo[1]; $line->total_ttc = $TInfo[2]; @@ -1346,21 +1394,18 @@ function pdf_add_total(&$pdf,&$object, &$line, $label, $description,$posx, $posy } $pdf->SetXY($pdf->postotalht, $posy); - if($set_pagebreak_margin) $pdf->SetAutoPageBreak( $pageBreakOriginalValue , $bMargin); + if ($set_pagebreak_margin) $pdf->SetAutoPageBreak($pageBreakOriginalValue, $bMargin); - if($pdfModelUseColSystem){ + if ($pdfModelUseColSystem) { $staticPdfModel->printStdColumnContent($pdf, $posy, 'totalexcltax', $total_to_print); - if(!empty($conf->global->PDF_PROPAL_SHOW_PRICE_INCL_TAX)) - { - $staticPdfModel->printStdColumnContent($pdf, $posy, 'totalincltax', price($line->total_ttc,0,'',1,0,getDolGlobalInt('MAIN_MAX_DECIMALS_TOT'))); + if (!empty($conf->global->PDF_PROPAL_SHOW_PRICE_INCL_TAX)) { + $staticPdfModel->printStdColumnContent($pdf, $posy, 'totalincltax', price($line->total_ttc, 0, '', 1, 0, getDolGlobalInt('MAIN_MAX_DECIMALS_TOT'))); } - } - else{ + } else { $pdf->MultiCell($pdf->page_largeur-$pdf->marge_droite-$pdf->postotalht, 3, $total_to_print, 0, 'R', 0); } - } - else{ - if($set_pagebreak_margin) $pdf->SetAutoPageBreak( $pageBreakOriginalValue , $bMargin); + } else { + if ($set_pagebreak_margin) $pdf->SetAutoPageBreak($pageBreakOriginalValue, $bMargin); } @@ -1369,22 +1414,25 @@ function pdf_add_total(&$pdf,&$object, &$line, $label, $description,$posx, $posy $posy = $posy + $cell_height; $pdf->SetXY($posx, $posy); - $pdf->setColor('text', 0,0,0); - + $pdf->setColor('text', 0, 0, 0); } /** - * @param $pdf TCPDF PDF object - * @param $object CommonObject dolibarr object - * @param $line CommonObjectLine dolibarr object line - * @param $label string - * @param $description string - * @param $posx float horizontal position - * @param $posy float vertical position - * @param $w float width - * @param $h float height + * PDF add title + * + * @param TCPDF $pdf TCPDF PDF object + * @param CommonObject $object CommonObject dolibarr object + * @param CommonObjectLine $line CommonObjectLine dolibarr object line + * @param string $label string + * @param string $description string + * @param float $posx float horizontal position + * @param float $posy float vertical position + * @param float $w float width + * @param float $h float height + * @return void */ - function pdf_add_title(&$pdf,&$object, &$line, $label, $description,$posx, $posy, $w, $h) { + public function pdfAddTitle(&$pdf, &$object, &$line, $label, $description, $posx, $posy, $w, $h) + { global $db,$conf,$subtotal_last_title_posy, $hidedesc; @@ -1394,16 +1442,16 @@ function pdf_add_title(&$pdf,&$object, &$line, $label, $description,$posx, $posy // Manage background color $fillDescBloc = false; $fillBackground = false; - if(getDolGlobalString('SUBTOTAL_TITLE_BACKGROUNDCOLOR') + if (getDolGlobalString('SUBTOTAL_TITLE_BACKGROUNDCOLOR') && function_exists('colorValidateHex') && colorValidateHex(getDolGlobalString('SUBTOTAL_TITLE_BACKGROUNDCOLOR')) && function_exists('colorStringToArray') ) { $fillBackground = true; - $backgroundColor = colorStringToArray( getDolGlobalString('SUBTOTAL_TITLE_BACKGROUNDCOLOR'),array(233, 233, 233)); + $backgroundColor = colorStringToArray(getDolGlobalString('SUBTOTAL_TITLE_BACKGROUNDCOLOR'), array(233, 233, 233)); - if(function_exists('colorIsLight') && !colorIsLight( getDolGlobalString('SUBTOTAL_TITLE_BACKGROUNDCOLOR'))){ - $pdf->setColor('text', 255,255,255); + if (function_exists('colorIsLight') && !colorIsLight(getDolGlobalString('SUBTOTAL_TITLE_BACKGROUNDCOLOR'))) { + $pdf->setColor('text', 255, 255, 255); } $backgroundCellHeightOffset = 0; @@ -1414,19 +1462,19 @@ function pdf_add_title(&$pdf,&$object, &$line, $label, $description,$posx, $posy // ex : les "Anciens PDF n'utilisent pas le padding pour les texts contrairement au "nouveaux PDF" c'est pourquoi les nouveaux PDF disposent d'un affichage mieux positionné - if(getDolGlobalString('SUBTOTAL_TITLE_BACKGROUND_CELL_HEIGHT_OFFSET')){ + if (getDolGlobalString('SUBTOTAL_TITLE_BACKGROUND_CELL_HEIGHT_OFFSET')) { $backgroundCellHeightOffset = doubleval(getDolGlobalString('SUBTOTAL_TITLE_BACKGROUND_CELL_HEIGHT_OFFSET')); } - if(getDolGlobalString('SUBTOTAL_TITLE_BACKGROUND_CELL_POS_Y_OFFSET')){ + if (getDolGlobalString('SUBTOTAL_TITLE_BACKGROUND_CELL_POS_Y_OFFSET')) { $backgroundCellPosYOffset = doubleval(getDolGlobalString('SUBTOTAL_TITLE_BACKGROUND_CELL_POS_Y_OFFSET')); } } -// $pdf->SetTextColor('text', 0, 0, 0); + // $pdf->SetTextColor('text', 0, 0, 0); $subtotal_last_title_posy = $posy; - $pdf->SetXY ($posx, $posy); + $pdf->SetXY($posx, $posy); $hideInnerLines = GETPOST('hideInnerLines', 'int'); @@ -1435,16 +1483,15 @@ function pdf_add_title(&$pdf,&$object, &$line, $label, $description,$posx, $posy $size_title = 9; if (getDolGlobalString('SUBTOTAL_TITLE_SIZE')) $size_title = getDolGlobalString('SUBTOTAL_TITLE_SIZE'); - if($hideInnerLines) { - if($line->qty==1){ + if ($hideInnerLines) { + if ($line->qty==1) { $pdf->SetFont('', $style, $size_title); - }else{ + } else { if (getDolGlobalString('SUBTOTAL_STYLE_TITRES_SI_LIGNES_CACHEES')) $style = getDolGlobalString('SUBTOTAL_STYLE_TITRES_SI_LIGNES_CACHEES'); $pdf->SetFont('', $style, $size_title); } - } - else { - if($line->qty==1)$pdf->SetFont('', $style, $size_title); //TODO if super utile + } else { + if ($line->qty==1)$pdf->SetFont('', $style, $size_title); //TODO if super utile else $pdf->SetFont('', $style, $size_title); } @@ -1452,38 +1499,37 @@ function pdf_add_title(&$pdf,&$object, &$line, $label, $description,$posx, $posy $curentCellPaddinds = $pdf->getCellPaddings(); // set cell padding with column content definition PDF - $pdf->setCellPaddings($curentCellPaddinds['L'],1, $curentCellPaddinds['R'],1); + $pdf->setCellPaddings($curentCellPaddinds['L'], 1, $curentCellPaddinds['R'], 1); $posYBeforeTile = $pdf->GetY(); if ($label === strip_tags($label) && $label === dol_html_entity_decode($label, ENT_QUOTES)) $pdf->MultiCell($w, $h, $label, 0, 'L', $fillDescBloc); // Pas de HTML dans la chaine - else $pdf->writeHTMLCell($w, $h, $posx, $posy, $label, 0, 1, $fillDescBloc, true, 'J',true); // et maintenant avec du HTML + else $pdf->writeHTMLCell($w, $h, $posx, $posy, $label, 0, 1, $fillDescBloc, true, 'J', true); // et maintenant avec du HTML $posYBeforeDesc = $pdf->GetY(); - if($description && !($hidedesc??0)) { - $pdf->setColor('text', 0,0,0); + if ($description && !($hidedesc??0)) { + $pdf->setColor('text', 0, 0, 0); $pdf->SetFont('', '', $size_title-1); - $pdf->writeHTMLCell($w, $h, $posx, $posYBeforeDesc+1, $description, 0, 1, $fillDescBloc, true, 'J',true); + $pdf->writeHTMLCell($w, $h, $posx, $posYBeforeDesc+1, $description, 0, 1, $fillDescBloc, true, 'J', true); } //background color - if ($fillBackground) - { + if ($fillBackground) { $posYAfterDesc = $pdf->GetY(); $cell_height = $pdf->getStringHeight($w, $label) + $backgroundCellHeightOffset; $bgStartX = $posx; $bgW = $pdf->page_largeur - $pdf->marge_droite;// historiquement ce sont ces valeurs, mais elles sont la plupart du temps vide // POUR LES PDF DE TYPE PDF_EVOLUTION (ceux avec les colonnes configurables) - if(!empty($object->context['subtotalPdfModelInfo']->cols)){ + if (!empty($object->context['subtotalPdfModelInfo']->cols)) { $bgStartX = $object->context['subtotalPdfModelInfo']->marge_droite; $bgW = $object->context['subtotalPdfModelInfo']->page_largeur - $object->context['subtotalPdfModelInfo']->marge_gauche - $object->context['subtotalPdfModelInfo']->marge_droite; } $pdf->SetFillColor($backgroundColor[0], $backgroundColor[1], $backgroundColor[2]); $pdf->SetXY($bgStartX, $posy + $backgroundCellPosYOffset); //-2 to take into account the entire height of the row - $pdf->MultiCell($bgW, $cell_height, '', 0, '', 1, 1,'','',true,0, true); //+2 same of SetXY() + $pdf->MultiCell($bgW, $cell_height, '', 0, '', 1, 1, '', '', true, 0, true); //+2 same of SetXY() $posy = $posYAfterDesc; $pdf->SetXY($posx, $posy); //reset position $pdf->SetFont('', $style, $size_title); //reset style @@ -1494,149 +1540,166 @@ function pdf_add_title(&$pdf,&$object, &$line, $label, $description,$posx, $posy $pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']); } - function pdf_writelinedesc_ref($parameters=array(), &$object, &$action='') { - // ultimate PDF hook O_o - - return $this->pdf_writelinedesc($parameters,$object,$action); + /** + * PDF write line desc ref + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @return int + */ + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps + // phpcs:disable Squiz.Functions.MultiLineFunctionDeclaration.ParamDefaultValueNotAtEnd + public function pdf_writelinedesc_ref($parameters = array(), &$object, &$action = '') + { + // ultimate PDF hook O_o + return $this->pdf_writelinedesc($parameters, $object, $action); } - function isModSubtotalLine(&$parameters, &$object) { + /** + * Is mod subtotal line + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @return bool + */ + public function isModSubtotalLine(&$parameters, &$object) + { - if(is_array($parameters)) { + if (is_array($parameters)) { $i = & $parameters['i']; - } - else { - $i = (int)$parameters; + } else { + $i = (int) $parameters; } $line = $object->lines[$i] ??''; - if($object->element == 'shipping' || $object->element == 'delivery') - { + if ($object->element == 'shipping' || $object->element == 'delivery') { dol_include_once('/commande/class/commande.class.php'); $line = new OrderLine($object->db); $line->fetch($object->lines[$i]->fk_elementdet ?? $object->lines[$i]->fk_elementdet); } - if(is_object($line) && property_exists($line, 'special_code') && $line->special_code == $this->module_number && $line->product_type == 9) { + if (is_object($line) && property_exists($line, 'special_code') && $line->special_code == $this->module_number && $line->product_type == 9) { return true; } return false; + } + /** + * Before percent calculation + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @return void + */ + public function beforePercentCalculation($parameters = array(), &$object, &$action = '') + { + if ($object->name == 'sponge' && isset($parameters['object']) && !empty($parameters['object']->lines)) { + foreach ($parameters['object']->lines as $k => $line) { + if (TSubtotal::isModSubtotalLine($line)) { + unset($parameters['object']->lines[$k]); + } + } + } } - /** - * @param array $parameters - * @param Object $object - * @param string $action - * @return void - */ - function beforePercentCalculation ($parameters=array(), &$object, &$action='') { - if($object->name == 'sponge' && isset($parameters['object']) && !empty($parameters['object']->lines)) { - foreach ($parameters['object']->lines as $k => $line) { - if(TSubtotal::isModSubtotalLine($line)) { - unset($parameters['object']->lines[$k]); - } - } - } - } - - /** - * @param array $parameters - * @param Object $object - * @param string $action - * @return int - */ - function pdf_getlineqty($parameters=array(), &$object, &$action='') { + /** + * PDF get line qty + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @return int + */ + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps + // phpcs:disable Squiz.Functions.MultiLineFunctionDeclaration.ParamDefaultValueNotAtEnd + public function pdf_getlineqty($parameters = array(), &$object, &$action = '') + { global $conf,$hideprices, $hidedetails; - $i = intval($parameters['i']); - $line = isset($object->lines[$i]) ? $object->lines[$i] : null ; - - if($this->isModSubtotalLine($parameters,$object) ){ - if ($this->subtotal_sum_qty_enabled === true) { - $line_qty = intval($line->qty); - - if ($line_qty < 50) { - // it's a title level (init level qty) - $subtotal_level = $line_qty; - $this->subtotal_level_cur = $subtotal_level; - TSubtotal::setSubtotalQtyForObject($object, $subtotal_level, 0); - - // not show qty for title lines - $this->resprints = ''; - - return 1; - } elseif ($line_qty > 50) { - // it's a subtotal level (show level qty and reset) - $subtotal_level = 100 - $line_qty; - $level_qty_total = $object->TSubtotalQty[$subtotal_level]; - TSubtotal::setSubtotalQtyForObject($object, $subtotal_level, 0); - - // show quantity sum only if it's a subtotal line (level) - $line_show_qty = TSubtotal::showQtyForObjectLine($line, $this->subtotal_show_qty_by_default); - if ($line_show_qty === false) { - $this->resprints = ''; - } else { - $this->resprints = $level_qty_total; - } - - return 1; - } else { - // not show qty for text line - $this->resprints = ''; - return 1; - } - } - else { - $this->resprints = ' '; - - return 1; - } + $i = intval($parameters['i']); + $line = isset($object->lines[$i]) ? $object->lines[$i] : null ; + + if ($this->isModSubtotalLine($parameters, $object) ) { + if ($this->subtotal_sum_qty_enabled === true) { + $line_qty = intval($line->qty); + + if ($line_qty < 50) { + // it's a title level (init level qty) + $subtotal_level = $line_qty; + $this->subtotal_level_cur = $subtotal_level; + TSubtotal::setSubtotalQtyForObject($object, $subtotal_level, 0); + + // not show qty for title lines + $this->resprints = ''; + + return 1; + } elseif ($line_qty > 50) { + // it's a subtotal level (show level qty and reset) + $subtotal_level = 100 - $line_qty; + $level_qty_total = $object->TSubtotalQty[$subtotal_level]; + TSubtotal::setSubtotalQtyForObject($object, $subtotal_level, 0); + + // show quantity sum only if it's a subtotal line (level) + $line_show_qty = TSubtotal::showQtyForObjectLine($line, $this->subtotal_show_qty_by_default); + if ($line_show_qty === false) { + $this->resprints = ''; + } else { + $this->resprints = $level_qty_total; + } + + return 1; + } else { + // not show qty for text line + $this->resprints = ''; + return 1; + } + } else { + $this->resprints = ' '; + + return 1; + } } else { - if ($this->subtotal_sum_qty_enabled === true) { - - // sum quantities by subtotal level - if ($this->subtotal_level_cur >= 1) { - for ($subtotal_level = 1; $subtotal_level <= $this->subtotal_level_cur; $subtotal_level++) { - TSubtotal::addSubtotalQtyForObject($object, $subtotal_level, $line->qty); - } - } - } - if (!empty($hideprices) && !empty($object->lines[$parameters['i']]) && property_exists($object->lines[$parameters['i']], 'qty')) { - $this->resprints = $object->lines[$parameters['i']]->qty; - return 1; - } elseif (getDolGlobalString('SUBTOTAL_IF_HIDE_PRICES_SHOW_QTY')) { - $hideInnerLines = GETPOST('hideInnerLines', 'int'); - $hidedetails = GETPOST('hidedetails', 'int'); + if ($this->subtotal_sum_qty_enabled === true) { + // sum quantities by subtotal level + if ($this->subtotal_level_cur >= 1) { + for ($subtotal_level = 1; $subtotal_level <= $this->subtotal_level_cur; $subtotal_level++) { + TSubtotal::addSubtotalQtyForObject($object, $subtotal_level, $line->qty); + } + } + } + if (!empty($hideprices) && !empty($object->lines[$parameters['i']]) && property_exists($object->lines[$parameters['i']], 'qty')) { + $this->resprints = $object->lines[$parameters['i']]->qty; + return 1; + } elseif (getDolGlobalString('SUBTOTAL_IF_HIDE_PRICES_SHOW_QTY')) { + $hideInnerLines = GETPOST('hideInnerLines', 'int'); + $hidedetails = GETPOST('hidedetails', 'int'); if (empty($hideInnerLines) && !empty($hidedetails)) { - $this->resprints = $object->lines[$parameters['i']]->qty; - } - } - else if (!empty($hidedetails)) - { + $this->resprints = $object->lines[$parameters['i']]->qty; + } + } elseif (!empty($hidedetails)) { $lineTitle = (!empty($object->lines[$i])) ? TSubtotal::getParentTitleOfLine($object, $object->lines[$i]->rang): ''; if (!($lineTitle && TSubtotal::titleHasTotalLine($object, $lineTitle, true))) { $this->resprints = $object->lines[$parameters['i']]->qty; } } - } + } - if(is_array($parameters)) $i = & $parameters['i']; - else $i = (int)$parameters; + if (is_array($parameters)) $i = & $parameters['i']; + else $i = (int) $parameters; /** Attention, ici on peut ce retrouver avec un objet de type stdClass à cause de l'option cacher le détail des ensembles avec la notion de Non Compris (@see beforePDFCreation()) et dû à l'appel de TSubtotal::hasNcTitle() */ if (empty($object->lines[$i]->id)) return 0; // hideInnerLines => override $object->lines et Dolibarr ne nous permet pas de mettre à jour la variable qui conditionne la boucle sur les lignes (PR faite pour 6.0) - if(empty($object->lines[$i]->array_options)) $object->lines[$i]->fetch_optionals(); + if (empty($object->lines[$i]->array_options)) $object->lines[$i]->fetch_optionals(); - if (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) - { - if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) - { + if (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) { + if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) { $this->resprints = ' '; return 1; } @@ -1645,61 +1708,62 @@ function pdf_getlineqty($parameters=array(), &$object, &$action='') { return 0; } - function pdf_getlinetotalexcltax($parameters=array(), &$object, &$action='') { - global $conf, $hideprices, $hookmanager, $hidedetails, $langs; - - if(is_array($parameters)) $i = & $parameters['i']; - else $i = (int)$parameters; + /** + * PDF get line total excl tax + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @return int + */ + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps + // phpcs:disable Squiz.Functions.MultiLineFunctionDeclaration.ParamDefaultValueNotAtEnd + public function pdf_getlinetotalexcltax($parameters = array(), &$object, &$action = '') + { + global $conf, $hideprices, $hookmanager, $hidedetails, $langs; - if($this->isModSubtotalLine($parameters,$object) ){ + if (is_array($parameters)) $i = & $parameters['i']; + else $i = (int) $parameters; + if ($this->isModSubtotalLine($parameters, $object) ) { $this->resprints = ' '; - return 1; - - } - elseif (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS')) - { - if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC') ))) - { - if (!empty($object->lines[$i]->array_options['options_subtotal_nc'])) - { + return 1; + } elseif (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS')) { + if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) { + if (!empty($object->lines[$i]->array_options['options_subtotal_nc'])) { $this->resprints = ' '; return 1; } $TTitle = TSubtotal::getAllTitleFromLine($object->lines[$i]); - foreach ($TTitle as &$line_title) - { - if (!empty($line_title->array_options['options_subtotal_nc'])) - { + foreach ($TTitle as &$line_title) { + if (!empty($line_title->array_options['options_subtotal_nc'])) { $this->resprints = ' '; return 1; } } - } elseif(in_array('pdf_getlinetotalexcltax', explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC'))) && + } elseif (in_array('pdf_getlinetotalexcltax', explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC'))) && floatval($object->lines[$i]->total_ht) == 0 - ){ + ) { // On affiche le véritable total ht de la ligne sans le comptabilisé $this->resprints = price($object->lines[$i]->qty * $object->lines[$i]->subprice); return 1; } } - // If commenté car : Affichage du total HT des lignes produit en doublon TICKET DA024057 -// if (GETPOST('hideInnerLines', 'int') && !empty(getDolGlobalString('SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES'))){ -// $this->resprints = price($object->lines[$i]->total_ht,0,'',1,0,getDolGlobalString('MAIN_MAX_DECIMALS_TOT')); -// } + // If commenté car : Affichage du total HT des lignes produit en doublon TICKET DA024057 + // if (GETPOST('hideInnerLines', 'int') && !empty(getDolGlobalString('SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES'))){ + // $this->resprints = price($object->lines[$i]->total_ht,0,'',1,0,getDolGlobalString('MAIN_MAX_DECIMALS_TOT')); + // } // Si la gestion C/NC est active et que je suis sur un ligne dont l'extrafield est coché if ( getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) - ) - { + ) { // alors je dois vérifier si la méthode fait partie de la conf qui l'exclue - if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) - { + if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) { $this->resprints = ' '; // currentcontext à modifier celon l'appel @@ -1708,25 +1772,20 @@ function pdf_getlinetotalexcltax($parameters=array(), &$object, &$action='') { } } // Cache le prix pour les lignes standards dolibarr qui sont dans un ensemble - else if (!empty($hideprices)) - { + elseif (!empty($hideprices)) { // Check if a title exist for this line && if the title have subtotal $lineTitle = (!empty($object->lines[$i])) ? TSubtotal::getParentTitleOfLine($object, $object->lines[$i]->rang): ''; - if ($lineTitle && TSubtotal::titleHasTotalLine($object, $lineTitle, true)) - { - + if ($lineTitle && TSubtotal::titleHasTotalLine($object, $lineTitle, true)) { $this->resprints = ' '; // currentcontext à modifier celon l'appel $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinetotalexcltax', 'currentcontext'=>'subtotal_hideprices', 'i' => $i); return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) - } - } - else if (!empty($hidedetails)) - { + } // + } elseif (!empty($hidedetails)) { $lineTitle = (!empty($object->lines[$i])) ? TSubtotal::getParentTitleOfLine($object, $object->lines[$i]->rang): ''; if (!($lineTitle && TSubtotal::titleHasTotalLine($object, $lineTitle, true))) { - $this->resprints = price($object->lines[$i]->total_ht,0,$langs); + $this->resprints = price($object->lines[$i]->total_ht, 0, $langs); $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinetotalexcltax', 'currentcontext' => 'subtotal_hidedetails', 'i' => $i); return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) @@ -1738,28 +1797,28 @@ function pdf_getlinetotalexcltax($parameters=array(), &$object, &$action='') { /** * Remplace le retour de la méthode qui l'appelle par un standard 1 ou autre chose celon le hook + * + * @param CommonObject $object Object + * @param HookManager $hookmanager Hook manager + * @param string $action Action + * @param array $params Parameters + * @param int $defaultReturn Default return value * @return int 1, 0, -1 */ private function callHook(&$object, &$hookmanager, $action, $params, $defaultReturn = 1) { - $reshook=$hookmanager->executeHooks('subtotalHidePrices',$params, $object, $action); - if ($reshook < 0) - { + $reshook=$hookmanager->executeHooks('subtotalHidePrices', $params, $object, $action); + if ($reshook < 0) { $this->error = $hookmanager->error; $this->errors = $hookmanager->errors; return -1; - } - elseif (empty($reshook)) - { - if (property_exists($hookmanager, 'resprints')) $this->resprints .= $hookmanager->resprints; - } - else - { + } elseif (empty($reshook)) { + if (property_exists($hookmanager, 'resprints')) $this->resprints .= $hookmanager->resprints; + } else { $this->resprints = $hookmanager->resprints; // override return (use $this->results['overrideReturn'] or $this->resArray['overrideReturn'] in other module action_xxxx.class.php ) - if(isset($this->results['overrideReturn'])) - { + if (isset($this->results['overrideReturn'])) { return $this->results['overrideReturn']; } } @@ -1767,25 +1826,30 @@ private function callHook(&$object, &$hookmanager, $action, $params, $defaultRet return $defaultReturn; } - function pdf_getlinetotalwithtax($parameters=array(), &$object, &$action='') { + /** + * PDF get line total with tax + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @return int + */ + public function pdf_getlinetotalwithtax($parameters = array(), &$object, &$action = '') + { global $conf; - if($this->isModSubtotalLine($parameters,$object) ){ - + if ($this->isModSubtotalLine($parameters, $object) ) { $this->resprints = ' '; - return 1; - + return 1; } - if(is_array($parameters)) $i = & $parameters['i']; - else $i = (int)$parameters; + if (is_array($parameters)) $i = & $parameters['i']; + else $i = (int) $parameters; - if (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) - { - if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) - { + if (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) { + if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) { $this->resprints = ' '; return 1; } @@ -1794,23 +1858,29 @@ function pdf_getlinetotalwithtax($parameters=array(), &$object, &$action='') { return 0; } - function pdf_getlineunit($parameters=array(), &$object, &$action='') { + /** + * PDF get line unit + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @return int + */ + public function pdf_getlineunit($parameters = array(), &$object, &$action = '') + { global $conf; - if($this->isModSubtotalLine($parameters,$object) ){ + if ($this->isModSubtotalLine($parameters, $object) ) { $this->resprints = ' '; - return 1; - + return 1; } - if(is_array($parameters)) $i = & $parameters['i']; - else $i = (int)$parameters; + if (is_array($parameters)) $i = & $parameters['i']; + else $i = (int) $parameters; - if (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) - { - if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) - { + if (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) { + if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) { $this->resprints = ' '; return 1; } @@ -1819,122 +1889,124 @@ function pdf_getlineunit($parameters=array(), &$object, &$action='') { return 0; } - function pdf_getlineupexcltax($parameters=array(), &$object, &$action='') { - global $conf,$hideprices,$hookmanager, $hidedetails, $langs; + /** + * PDF get line up excl tax + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @return int + */ + public function pdf_getlineupexcltax($parameters = array(), &$object, &$action = '') + { + global $conf,$hideprices,$hookmanager, $hidedetails, $langs; - if(is_array($parameters)) $i = & $parameters['i']; - else $i = (int)$parameters; + if (is_array($parameters)) $i = & $parameters['i']; + else $i = (int) $parameters; - if($this->isModSubtotalLine($parameters,$object) ) { + if ($this->isModSubtotalLine($parameters, $object) ) { $this->resprints = ' '; - $line = $object->lines[$i]; - - // On récupère les montants du bloc pour les afficher dans la ligne de sous-total - if(TSubtotal::isSubtotal($line)) { - $parentTitle = TSubtotal::getParentTitleOfLine($object, $line->rang); + $line = $object->lines[$i]; - if(is_object($parentTitle) && empty($parentTitle->array_options)) $parentTitle->fetch_optionals(); - if(! empty($parentTitle->array_options['options_show_total_ht'])) { - $TTotal = TSubtotal::getTotalBlockFromTitle($object, $parentTitle); - $this->resprints = price($TTotal['total_unit_subprice'],0,'',1,0,getDolGlobalString('MAIN_MAX_DECIMALS_TOT') ); - } - } + // On récupère les montants du bloc pour les afficher dans la ligne de sous-total + if (TSubtotal::isSubtotal($line)) { + $parentTitle = TSubtotal::getParentTitleOfLine($object, $line->rang); + if (is_object($parentTitle) && empty($parentTitle->array_options)) $parentTitle->fetch_optionals(); + if (! empty($parentTitle->array_options['options_show_total_ht'])) { + $TTotal = TSubtotal::getTotalBlockFromTitle($object, $parentTitle); + $this->resprints = price($TTotal['total_unit_subprice'], 0, '', 1, 0, getDolGlobalString('MAIN_MAX_DECIMALS_TOT')); + } + } - return 1; + return 1; } // Si la gestion C/NC est active et que je suis sur un ligne dont l'extrafield est coché if ( getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) - ) - { - // alors je dois vérifier si la méthode fait partie de la conf qui l'exclue - if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) - { - $this->resprints = ' '; - - // currentcontext à modifier celon l'appel - $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlineupexcltax', 'currentcontext'=>'subtotal_hide_nc', 'i' => $i); - return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) - - } + ) { + // alors je dois vérifier si la méthode fait partie de la conf qui l'exclue + if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) { + $this->resprints = ' '; + + // currentcontext à modifier celon l'appel + $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlineupexcltax', 'currentcontext'=>'subtotal_hide_nc', 'i' => $i); + return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) + } } // Cache le prix pour les lignes standards dolibarr qui sont dans un ensemble - else if (!empty($hideprices)) - { - - // Check if a title exist for this line && if the title have subtotal - $lineTitle = (!empty($object->lines[$i])) ? TSubtotal::getParentTitleOfLine($object, $object->lines[$i]->rang): ''; - if ($lineTitle && TSubtotal::titleHasTotalLine($object, $lineTitle, true)) - { - - $this->resprints = ' '; - - // currentcontext à modifier celon l'appel - $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlineupexcltax', 'currentcontext'=>'subtotal_hideprices', 'i' => $i); - return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) - } - } elseif (!empty($hidedetails)) - { + elseif (!empty($hideprices)) { + // Check if a title exist for this line && if the title have subtotal + $lineTitle = (!empty($object->lines[$i])) ? TSubtotal::getParentTitleOfLine($object, $object->lines[$i]->rang): ''; + if ($lineTitle && TSubtotal::titleHasTotalLine($object, $lineTitle, true)) { + $this->resprints = ' '; + + // currentcontext à modifier celon l'appel + $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlineupexcltax', 'currentcontext'=>'subtotal_hideprices', 'i' => $i); + return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) + } + } elseif (!empty($hidedetails)) { $lineTitle = (!empty($object->lines[$i])) ? TSubtotal::getParentTitleOfLine($object, $object->lines[$i]->rang): ''; if (!($lineTitle && TSubtotal::titleHasTotalLine($object, $lineTitle, true))) { - $this->resprints = price($object->lines[$i]->subprice,0,$langs); + $this->resprints = price($object->lines[$i]->subprice, 0, $langs); $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlineupexcltax', 'currentcontext' => 'subtotal_hidedetails', 'i' => $i); return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) - } + } // } return 0; } - function pdf_getlineremisepercent($parameters=array(), &$object, &$action='') { - global $conf,$hideprices,$hookmanager, $hidedetails, $langs; + /** + * PDF get line remise percent + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @return int + */ + public function pdf_getlineremisepercent($parameters = array(), &$object, &$action = '') + { + global $conf,$hideprices,$hookmanager, $hidedetails, $langs; - if(is_array($parameters)) $i = & $parameters['i']; - else $i = (int) $parameters; + if (is_array($parameters)) $i = & $parameters['i']; + else $i = (int) $parameters; - if($this->isModSubtotalLine($parameters,$object) ) { + if ($this->isModSubtotalLine($parameters, $object) ) { $this->resprints = ' '; - $line = $object->lines[$i]; - - // Affichage de la remise - if(TSubtotal::isSubtotal($line)) { - if ($parentTitle = TSubtotal::getParentTitleOfLine($object, $line->rang)) { + $line = $object->lines[$i]; - if(empty($parentTitle->array_options)) $parentTitle->fetch_optionals(); - if(! empty($parentTitle->array_options['options_show_reduc'])) { + // Affichage de la remise + if (TSubtotal::isSubtotal($line)) { + if ($parentTitle = TSubtotal::getParentTitleOfLine($object, $line->rang)) { + if (empty($parentTitle->array_options)) $parentTitle->fetch_optionals(); + if (! empty($parentTitle->array_options['options_show_reduc'])) { $TTotal = TSubtotal::getTotalBlockFromTitle($object, $parentTitle); $this->resprints = price((1-$TTotal['total_ht'] / $TTotal['total_subprice'])*100, 0, '', 1, 2, 2).'%'; } } - } - + } - return 1; - } - elseif (!empty($hideprices) - || (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) - ) - { - if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) - { - // Check if a title exist for this line && if the title have subtotal - $lineTitle = TSubtotal::getParentTitleOfLine($object, $object->lines[$i]->rang); - if ($lineTitle && TSubtotal::titleHasTotalLine($object, $lineTitle, true)) { - $this->resprints = ' '; - return 1; - } - } - } - elseif (!empty($hidedetails)) - { + return 1; + } elseif (!empty($hideprices) + || (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) + ) { + if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) { + // Check if a title exist for this line && if the title have subtotal + $lineTitle = TSubtotal::getParentTitleOfLine($object, $object->lines[$i]->rang); + if ($lineTitle && TSubtotal::titleHasTotalLine($object, $lineTitle, true)) { + $this->resprints = ' '; + return 1; + } + } + } elseif (!empty($hidedetails)) { $lineTitle = (!empty($object->lines[$i])) ? TSubtotal::getParentTitleOfLine($object, $object->lines[$i]->rang): ''; if (!($lineTitle && TSubtotal::titleHasTotalLine($object, $lineTitle, true))) { $this->resprints = dol_print_reduction($object->lines[$i]->remise_percent, $langs); @@ -1945,26 +2017,32 @@ function pdf_getlineremisepercent($parameters=array(), &$object, &$action='') { return 0; } - function pdf_getlineupwithtax($parameters=array(), &$object, &$action='') { + /** + * PDF get line up with tax + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @return int + */ + public function pdf_getlineupwithtax($parameters = array(), &$object, &$action = '') + { global $conf,$hideprices, $hidedetails; - if($this->isModSubtotalLine($parameters,$object) ){ + if ($this->isModSubtotalLine($parameters, $object) ) { $this->resprints = ' '; - return 1; - + return 1; } - if(is_array($parameters)) $i = & $parameters['i']; - else $i = (int)$parameters; + if (is_array($parameters)) $i = & $parameters['i']; + else $i = (int) $parameters; if (!empty($hideprices) || (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) - ) - { - if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) - { + ) { + if (!empty($hideprices) || !in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) { $this->resprints = ' '; return 1; } @@ -1973,22 +2051,30 @@ function pdf_getlineupwithtax($parameters=array(), &$object, &$action='') { return 0; } - function pdf_getlinevatrate($parameters=array(), &$object, &$action='') { - global $conf,$hideprices,$hookmanager, $hidedetails; + /** + * PDF get line vat rate + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @return int + */ + public function pdf_getlinevatrate($parameters = array(), &$object, &$action = '') + { + global $conf,$hideprices,$hookmanager, $hidedetails; -// // Dans le cas des notes de frais report ne pas traiter -// // TODO : peut être faire l'inverse : limiter à certains elements plutot que le faire pour tous ... à voir si un autre PB du genre apparait. -// $TContext = explode(':', $parameters['context']); -// if (in_array('expensereportcard', $TContext)) return 0; + // // Dans le cas des notes de frais report ne pas traiter + // // TODO : peut être faire l'inverse : limiter à certains elements plutot que le faire pour tous ... à voir si un autre PB du genre apparait. + // $TContext = explode(':', $parameters['context']); + // if (in_array('expensereportcard', $TContext)) return 0; - if($this->isModSubtotalLine($parameters,$object) ){ + if ($this->isModSubtotalLine($parameters, $object) ) { $this->resprints = ' '; - return 1; - + return 1; } - if(is_array($parameters)) $i = & $parameters['i']; - else $i = (int)$parameters; + if (is_array($parameters)) $i = & $parameters['i']; + else $i = (int) $parameters; if (empty($object->lines[$i])) return 0; // hideInnerLines => override $object->lines et Dolibarr ne nous permet pas de mettre à jour la variable qui conditionne la boucle sur les lignes (PR faite pour 6.0) @@ -1997,63 +2083,61 @@ function pdf_getlinevatrate($parameters=array(), &$object, &$action='') { if ( getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) - ) - { - // alors je dois vérifier si la méthode fait partie de la conf qui l'exclue - if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) - { - $this->resprints = ' '; - - // currentcontext à modifier celon l'appel - $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinevatrate', 'currentcontext'=>'subtotal_hide_nc', 'i' => $i); - return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) - } + ) { + // alors je dois vérifier si la méthode fait partie de la conf qui l'exclue + if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) { + $this->resprints = ' '; + + // currentcontext à modifier celon l'appel + $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinevatrate', 'currentcontext'=>'subtotal_hide_nc', 'i' => $i); + return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) + } } // Cache le prix pour les lignes standards dolibarr qui sont dans un ensemble - else if (!empty($hideprices)) - { - - // Check if a title exist for this line && if the title have subtotal - $lineTitle = TSubtotal::getParentTitleOfLine($object, $object->lines[$i]->rang); - if ($lineTitle && TSubtotal::titleHasTotalLine($object, $lineTitle, true)) - { - - $this->resprints = ' '; + elseif (!empty($hideprices)) { + // Check if a title exist for this line && if the title have subtotal + $lineTitle = TSubtotal::getParentTitleOfLine($object, $object->lines[$i]->rang); + if ($lineTitle && TSubtotal::titleHasTotalLine($object, $lineTitle, true)) { + $this->resprints = ' '; - // currentcontext à modifier celon l'appel - $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinevatrate', 'currentcontext'=>'subtotal_hideprices', 'i' => $i); - return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) - } - } - elseif (!empty($hidedetails)) - { + // currentcontext à modifier celon l'appel + $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinevatrate', 'currentcontext'=>'subtotal_hideprices', 'i' => $i); + return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) + } + } elseif (!empty($hidedetails)) { $lineTitle = (!empty($object->lines[$i])) ? TSubtotal::getParentTitleOfLine($object, $object->lines[$i]->rang): ''; if (!($lineTitle && TSubtotal::titleHasTotalLine($object, $lineTitle, true))) { $this->resprints = vatrate($object->lines[$i]->tva_tx, true); $params = array('parameters' => $parameters, 'currentmethod' => 'pdf_getlinevatrate', 'currentcontext'=>'subtotal_hidedetails', 'i' => $i); return $this->callHook($object, $hookmanager, $action, $params); // return 1 (qui est la valeur par défaut) OU -1 si erreur OU overrideReturn (contient -1 ou 0 ou 1) - } + } // } return 0; } - function pdf_getlineprogress($parameters=array(), &$object, &$action) { + /** + * PDF get line progress + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @return int + */ + public function pdf_getlineprogress($parameters = array(), &$object, &$action) + { global $conf; - if($this->isModSubtotalLine($parameters,$object) ){ + if ($this->isModSubtotalLine($parameters, $object) ) { $this->resprints = ' '; - return 1; - + return 1; } - if(is_array($parameters)) $i = & $parameters['i']; - else $i = (int)$parameters; + if (is_array($parameters)) $i = & $parameters['i']; + else $i = (int) $parameters; - if (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) - { - if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) - { + if (getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS') && (!empty($object->lines[$i]->array_options['options_subtotal_nc']) || TSubtotal::hasNcTitle($object->lines[$i])) ) { + if (!in_array(__FUNCTION__, explode(',', getDolGlobalString('SUBTOTAL_TFIELD_TO_KEEP_WITH_NC')))) { $this->resprints = ' '; return 1; } @@ -2062,62 +2146,61 @@ function pdf_getlineprogress($parameters=array(), &$object, &$action) { return 0; } - function add_numerotation(&$object) { + /** + * Add numerotation + * + * @param CommonObject $object Object + * @return void + */ + public function addNumerotation(&$object) + { global $conf; - if(getDolGlobalString('SUBTOTAL_USE_NUMEROTATION')) { - + if (getDolGlobalString('SUBTOTAL_USE_NUMEROTATION')) { $TLineTitle = $TTitle = $TLineSubtotal = array(); $prevlevel = 0; dol_include_once('/subtotal/class/subtotal.class.php'); - foreach($object->lines as $k=>&$line) - { - if ($line->id > 0 && $this->isModSubtotalLine($k, $object) && $line->qty <= 10) - { + foreach ($object->lines as $k=>&$line) { + if ($line->id > 0 && $this->isModSubtotalLine($k, $object) && $line->qty <= 10) { $TLineTitle[] = &$line; - } - else if ($line->id > 0 && TSubtotal::isSubtotal($line)) - { + } elseif ($line->id > 0 && TSubtotal::isSubtotal($line)) { $TLineSubtotal[] = &$line; } - } - if (!empty($TLineTitle)) - { + if (!empty($TLineTitle)) { $TTitleNumeroted = $this->formatNumerotation($TLineTitle); $TTitle = $this->getTitlesFlatArray($TTitleNumeroted); - if (!empty($TLineSubtotal)) - { - foreach ($TLineSubtotal as &$stLine) - { + if (!empty($TLineSubtotal)) { + foreach ($TLineSubtotal as &$stLine) { $parentTitle = TSubtotal::getParentTitleOfLine($object, $stLine->rang); - if (!empty($parentTitle) && array_key_exists($parentTitle->id, $TTitle)) - { + if (!empty($parentTitle) && array_key_exists($parentTitle->id, $TTitle)) { $stLine->label = $TTitle[$parentTitle->id]['numerotation'] . ' ' . $stLine->label; } } } } } - } + /** + * Get titles flat array + * + * @param array $TTitleNumeroted Titles numeroted + * @param array $resArray Result array + * @return array + */ private function getTitlesFlatArray($TTitleNumeroted = array(), &$resArray = array()) { - if (is_array($TTitleNumeroted) && !empty($TTitleNumeroted)) - { - foreach ($TTitleNumeroted as $tn) - { + if (is_array($TTitleNumeroted) && !empty($TTitleNumeroted)) { + foreach ($TTitleNumeroted as $tn) { $resArray[$tn['line']->id] = $tn; - if (array_key_exists('children', $tn)) - { + if (array_key_exists('children', $tn)) { $this->getTitlesFlatArray($tn['children'], $resArray); } - } } @@ -2126,13 +2209,14 @@ private function getTitlesFlatArray($TTitleNumeroted = array(), &$resArray = arr /** * TODO ne gère pas encore la numération des lignes "Totaux" - * @param CommonObjectLine[] $TLineTitle - * @param string $line_reference - * @param int $level - * @param int $prefix_num + * + * @param CommonObjectLine[] $TLineTitle Array of title lines + * @param string $line_reference Line reference + * @param int $level Level + * @param int $prefix_num Prefix number * @return array */ - private function formatNumerotation(&$TLineTitle, $line_reference='', $level=1, $prefix_num=0) + private function formatNumerotation(&$TLineTitle, $line_reference = '', $level = 1, $prefix_num = 0) { $TTitle = array(); @@ -2143,13 +2227,11 @@ private function formatNumerotation(&$TLineTitle, $line_reference='', $level=1, 'facture_fourn_det', 'commande_fournisseurdet', ); - foreach ($TLineTitle as $k => &$line) - { + foreach ($TLineTitle as $k => &$line) { if (!empty($line_reference) && $line->rang <= $line_reference->rang) continue; if (!empty($line_reference) && $line->qty <= $line_reference->qty) break; - if ($line->qty == $level) - { + if ($line->qty == $level) { $TTitle[$j]['numerotation'] = ($prefix_num == 0) ? $i : $prefix_num.'.'.$i; //var_dump('Prefix == '.$prefix_num.' // '.$line->desc.' ==> numerotation == '.$TTitle[$j]['numerotation'].' ### '.$line->qty .'=='. $level); if (empty($line->label) && ( @@ -2178,18 +2260,34 @@ private function formatNumerotation(&$TLineTitle, $line_reference='', $level=1, return $TTitle; } - function setDocTVA(&$pdf, &$object) { + /** + * Set doc TVA + * + * @param TCPDF $pdf PDF + * @param CommonObject $object Object + * @return bool + */ + public function setDocTVA(&$pdf, &$object) + { $hidedetails = GETPOST('hidedetails', 'int'); - if(empty($hidedetails)) return false; + if (empty($hidedetails)) return false; // TODO can't add VAT to document without lines... :-/ return true; } - function beforePDFCreation($parameters=array(), &$object, &$action) + /** + * Before PDF creation + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @return void + */ + public function beforePDFCreation($parameters = array(), &$object, &$action = '') { /** * @var $pdf TCPDF @@ -2202,7 +2300,7 @@ function beforePDFCreation($parameters=array(), &$object, &$action) } // for compatibility dolibarr < 15 - if(!empty($object->context)){ $object->context = array(); } + if (!empty($object->context)) { $object->context = array(); } $object->context['subtotalPdfModelInfo'] = new stdClass(); // see defineColumnFiel method in this class $object->context['subtotalPdfModelInfo']->cols = false; @@ -2211,62 +2309,58 @@ function beforePDFCreation($parameters=array(), &$object, &$action) // var_dump($object->lines); dol_include_once('/subtotal/class/subtotal.class.php'); - $i = 0; - if(isset($parameters['i'])) { - $i = $parameters['i']; - } + $i = 0; + if (isset($parameters['i'])) { + $i = $parameters['i']; + } - foreach($parameters as $key=>$value) { + foreach ($parameters as $key=>$value) { ${$key} = $value; } $this->setDocTVA($pdf, $object); - $this->add_numerotation($object); + $this->addNumerotation($object); - foreach($object->lines ?? [] as $k => &$l) { - if(TSubtotal::isSubtotal($l)) { - $parentTitle = TSubtotal::getParentTitleOfLine($object, $l->rang); - if(is_object($parentTitle) && empty($parentTitle->array_options)) $parentTitle->fetch_optionals(); - if(! empty($parentTitle->id) && ! empty($parentTitle->array_options['options_show_reduc'])) { - $l->remise_percent = 100; // Affichage de la réduction sur la ligne de sous-total - } - } + foreach ($object->lines ?? [] as $k => &$l) { + if (TSubtotal::isSubtotal($l)) { + $parentTitle = TSubtotal::getParentTitleOfLine($object, $l->rang); + if (is_object($parentTitle) && empty($parentTitle->array_options)) $parentTitle->fetch_optionals(); + if (! empty($parentTitle->id) && ! empty($parentTitle->array_options['options_show_reduc'])) { + $l->remise_percent = 100; // Affichage de la réduction sur la ligne de sous-total + } + } - // Pas de hook sur les colonnes du PDF expédition, on unset les bonnes variables - if(($object->element == 'shipping' || $object->element == 'delivery') && $this->isModSubtotalLine($k, $object)) - { + // Pas de hook sur les colonnes du PDF expédition, on unset les bonnes variables + if (($object->element == 'shipping' || $object->element == 'delivery') && $this->isModSubtotalLine($k, $object)) { $l->qty = $l->qty_asked; unset($l->qty_asked, $l->qty_shipped, $l->volume, $l->weight); } - } + } $hideInnerLines = GETPOST('hideInnerLines', 'int'); $hidedetails = GETPOST('hidedetails', 'int'); if ($hideInnerLines) { // si c une ligne de titre - $fk_parent_line=0; + $fk_parent_line=0; $TLines =array(); $original_count=count($object->lines); - $TTvas = array(); // tableau de tva + $TTvas = array(); // tableau de tva - foreach($object->lines as $k=>&$line) - { - // to keep compatibility with supplier order and old versions (rowid was replaced with id in fetch lines method) - if ($line->id > 0) { - $line->rowid = $line->id; - } + foreach ($object->lines as $k=>&$line) { + // to keep compatibility with supplier order and old versions (rowid was replaced with id in fetch lines method) + if ($line->id > 0) { + $line->rowid = $line->id; + } - if($line->product_type==9 && $line->rowid>0) - { + if ($line->product_type==9 && $line->rowid>0) { $fk_parent_line = $line->rowid; // Fix tk7201 - si on cache le détail, la TVA est renseigné au niveau du sous-total, l'erreur c'est s'il y a plusieurs sous-totaux pour les même lignes, ça va faire la somme - if(TSubtotal::isSubtotal($line)) - { + if (TSubtotal::isSubtotal($line)) { /*$total = $this->getTotalLineFromObject($object, $line, ''); $line->total_ht = $total; @@ -2282,37 +2376,32 @@ function beforePDFCreation($parameters=array(), &$object, &$action) $line->total = $line->total_ht; $line->total_ttc = $TInfo[2]; -// $TTitle = TSubtotal::getParentTitleOfLine($object, $line->rang); -// $parentTitle = array_shift($TTitle); -// if(! empty($parentTitle->id) && ! empty($parentTitle->array_option['options_show_total_ht'])) { -// exit('la?'); -// $line->remise_percent = 100; // Affichage de la réduction sur la ligne de sous-total -// $line->update(); -// } + // $TTitle = TSubtotal::getParentTitleOfLine($object, $line->rang); + // $parentTitle = array_shift($TTitle); + // if(! empty($parentTitle->id) && ! empty($parentTitle->array_option['options_show_total_ht'])) { + // exit('la?'); + // $line->remise_percent = 100; // Affichage de la réduction sur la ligne de sous-total + // $line->update(); + // } } -// if(TSub) - + // if(TSub) } - if ($hideInnerLines) - { - if(getDolGlobalString('SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES')) - { - if($line->tva_tx != '0.000' && $line->product_type!=9){ - - // on remplit le tableau de tva pour substituer les lignes cachées - if (!empty($TTvas[$line->tva_tx]['total_tva'])) $TTvas[$line->tva_tx]['total_tva'] += $line->total_tva; - if (!empty($TTvas[$line->tva_tx]['total_ht'])) $TTvas[$line->tva_tx]['total_ht'] += $line->total_ht; - if (!empty($TTvas[$line->tva_tx]['total_ttc'])) $TTvas[$line->tva_tx]['total_ttc'] += $line->total_ttc; - } - if($line->product_type==9 && $line->rowid>0) - { - //Cas où je doit cacher les produits et afficher uniquement les sous-totaux avec les titres - // génère des lignes d'affichage des montants HT soumis à tva - $nbtva = count($TTvas); - if(!empty($nbtva)){ - foreach ($TTvas as $tx =>$val){ - $copyL = clone $line; // la variable $coyyL était nommé $l, j' l'ai renommé car probleme de référence d'instance dans le clone + if ($hideInnerLines) { + if (getDolGlobalString('SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES')) { + if ($line->tva_tx != '0.000' && $line->product_type!=9) { + // on remplit le tableau de tva pour substituer les lignes cachées + if (!empty($TTvas[$line->tva_tx]['total_tva'])) $TTvas[$line->tva_tx]['total_tva'] += $line->total_tva; + if (!empty($TTvas[$line->tva_tx]['total_ht'])) $TTvas[$line->tva_tx]['total_ht'] += $line->total_ht; + if (!empty($TTvas[$line->tva_tx]['total_ttc'])) $TTvas[$line->tva_tx]['total_ttc'] += $line->total_ttc; + } + if ($line->product_type==9 && $line->rowid>0) { + //Cas où je doit cacher les produits et afficher uniquement les sous-totaux avec les titres + // génère des lignes d'affichage des montants HT soumis à tva + $nbtva = count($TTvas); + if (!empty($nbtva)) { + foreach ($TTvas as $tx =>$val) { + $copyL = clone $line; // la variable $coyyL était nommé $l, j' l'ai renommé car probleme de référence d'instance dans le clone $copyL->product_type = 1; $copyL->special_code = ''; $copyL->qty = 1; @@ -2322,60 +2411,51 @@ function beforePDFCreation($parameters=array(), &$object, &$action) $copyL->total_tva = $val['total_tva']; $copyL->total = $line->total_ht; $copyL->total_ttc = $val['total_ttc']; - $TLines[] = $copyL; - array_shift($TTvas); - } - } - - // ajoute la ligne de sous-total - $TLines[] = $line; - } - } else { - - if($line->product_type==9 && $line->rowid>0) - { - // ajoute la ligne de sous-total - $TLines[] = $line; - } - } - + $TLines[] = $copyL; + array_shift($TTvas); + } + } - } - elseif ($hidedetails) - { + // ajoute la ligne de sous-total + $TLines[] = $line; + } + } else { + if ($line->product_type==9 && $line->rowid>0) { + // ajoute la ligne de sous-total + $TLines[] = $line; + } + } + } elseif ($hidedetails) { $TLines[] = $line; //Cas où je cache uniquement les prix des produits } if ($line->product_type != 9) { // jusqu'au prochain titre ou total //$line->fk_parent_line = $fk_parent_line; - } /*if($hideTotal) { $line->total = 0; $line->subprice= 0; }*/ - } // cas incongru où il y aurait des produits en dessous du dernier sous-total $nbtva = count($TTvas); - if(!empty($nbtva) && $hideInnerLines && getDolGlobalString('SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES')) - { - foreach ($TTvas as $tx =>$val){ - $l = clone $line; - $l->product_type = 1; - $l->special_code = ''; - $l->qty = 1; - $l->desc = $langs->trans('AmountBeforeTaxesSubjectToVATX%', $langs->transnoentitiesnoconv('VAT'), price($tx)); - $l->tva_tx = $tx; - $l->total_ht = $val['total_ht']; - $l->total_tva = $val['total_tva']; - $l->total = $line->total_ht; - $l->total_ttc = $val['total_ttc']; - $TLines[] = $l; - array_shift($TTvas); - } + if (!empty($nbtva) && $hideInnerLines && getDolGlobalString('SUBTOTAL_REPLACE_WITH_VAT_IF_HIDE_INNERLINES')) { + foreach ($TTvas as $tx =>$val) { + $l = clone $line; + $l->product_type = 1; + $l->special_code = ''; + $l->qty = 1; + $l->desc = $langs->trans('AmountBeforeTaxesSubjectToVATX%', $langs->transnoentitiesnoconv('VAT'), price($tx)); + $l->tva_tx = $tx; + $l->total_ht = $val['total_ht']; + $l->total_tva = $val['total_tva']; + $l->total = $line->total_ht; + $l->total_ttc = $val['total_ttc']; + $TLines[] = $l; + array_shift($TTvas); + } } global $nblignes; @@ -2383,23 +2463,31 @@ function beforePDFCreation($parameters=array(), &$object, &$action) $object->lines = $TLines; - if($i>count($object->lines)) { + if ($i>count($object->lines)) { $this->resprints = ''; return 0; } - } + } return 0; } - function pdf_writelinedesc($parameters=array(), &$object, &$action) + /** + * PDF write line desc + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @return int + */ + public function pdf_writelinedesc($parameters = array(), &$object, &$action = '') { /** * @var $pdf TCPDF */ global $pdf,$conf; - foreach($parameters as $key=>$value) { + foreach ($parameters as $key=>$value) { ${$key} = $value; } @@ -2413,218 +2501,204 @@ function pdf_writelinedesc($parameters=array(), &$object, &$action) $hideInnerLines = GETPOST('hideInnerLines', 'int'); $hidedetails = GETPOST('hidedetails', 'int'); - if($this->isModSubtotalLine($parameters,$object) ){ - + if ($this->isModSubtotalLine($parameters, $object) ) { global $hideprices; - if(!empty($hideprices)) { - foreach($object->lines as &$line) { - if($line->fk_product_type!=9) $line->fk_parent_line = -1; - } + if (!empty($hideprices)) { + foreach ($object->lines as &$line) { + if ($line->fk_product_type!=9) $line->fk_parent_line = -1; } + } $line = &$object->lines[$i]; // Unset on Dolibarr < 20.0 - if($object->element == 'delivery' && ! empty($object->commande->expeditions[$line->fk_elementdet])) unset($object->commande->expeditions[$line->fk_elementdet]); + if ($object->element == 'delivery' && ! empty($object->commande->expeditions[$line->fk_elementdet])) unset($object->commande->expeditions[$line->fk_elementdet]); // Unset on Dolibarr >= 20.0 - if($object->element == 'delivery' && ! empty($object->commande->expeditions[$line->fk_elementdet])) unset($object->commande->expeditions[$line->fk_elementdet]); + if ($object->element == 'delivery' && ! empty($object->commande->expeditions[$line->fk_elementdet])) unset($object->commande->expeditions[$line->fk_elementdet]); $margin = $pdf->getMargins(); - if(!empty($margin) && $line->info_bits>0) { // PAGE BREAK - $pdf->addPage(); - $posy = $margin['top']; - } + if (!empty($margin) && $line->info_bits>0) { // PAGE BREAK + $pdf->addPage(); + $posy = $margin['top']; + } $label = $line->label; $description= !empty($line->desc) ? $outputlangs->convToOutputCharset($line->desc) : $outputlangs->convToOutputCharset($line->description); - if(empty($label)) { - $label = $description; - $description=''; - } + if (empty($label)) { + $label = $description; + $description=''; + } - if($line->qty>90) { + if ($line->qty>90) { if (getDolGlobalString('CONCAT_TITLE_LABEL_IN_SUBTOTAL_LABEL')) { - $label .= ' '.$this->getTitle($object, $line); - } - if(!empty(getDolGlobalString('SUBTOTAL_DISABLE_FIX_TRANSACTION'))) { - /** - * TCPDF::startTransaction() committe la transaction en cours s'il y en a une, - * ce qui peut être problématique. Comme TCPDF::rollbackTransaction() ne fait rien - * si aucune transaction n'est en cours, on peut y faire appel sans problème pour revenir - * à l'état d'origine. - */ - $pdf->rollbackTransaction(true); - $pdf->startTransaction(); - - $pageBefore = $pdf->getPage(); - } - + $label .= ' '.$this->getTitle($object, $line); + } + if (!empty(getDolGlobalString('SUBTOTAL_DISABLE_FIX_TRANSACTION'))) { + /** + * TCPDF::startTransaction() committe la transaction en cours s'il y en a une, + * ce qui peut être problématique. Comme TCPDF::rollbackTransaction() ne fait rien + * si aucune transaction n'est en cours, on peut y faire appel sans problème pour revenir + * à l'état d'origine. + */ + $pdf->rollbackTransaction(true); + $pdf->startTransaction(); + + $pageBefore = $pdf->getPage(); + } - // FIX DA024845 : Le module sous total amène des erreurs dans les sauts de page lorsque l'on arrive tout juste en bas de page. - $heightForFooter = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10) + (getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22); // Height reserved to output the footer (value include bottom margin) - if($pdf->getPageHeight() - $posy - $heightForFooter < 8){ - $pdf->addPage('', '', true); - $posy = $pdf->GetY(); - } + // FIX DA024845 : Le module sous total amène des erreurs dans les sauts de page lorsque l'on arrive tout juste en bas de page. + $heightForFooter = getDolGlobalInt('MAIN_PDF_MARGIN_BOTTOM', 10) + (getDolGlobalInt('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22); // Height reserved to output the footer (value include bottom margin) + if ($pdf->getPageHeight() - $posy - $heightForFooter < 8) { + $pdf->addPage('', '', true); + $posy = $pdf->GetY(); + } - $this->pdf_add_total($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h); - if(!empty(getDolGlobalString('SUBTOTAL_DISABLE_FIX_TRANSACTION'))) { - $pageAfter = $pdf->getPage(); + $this->pdf_add_total($pdf, $object, $line, $label, $description, $posx, $posy, $w, $h); - if($pageAfter > $pageBefore) { - //print "ST $pageAfter>$pageBefore
"; - $pdf->rollbackTransaction(true); - $pdf->addPage('', '', true); - $posy = $pdf->GetY(); - $this->pdf_add_total($pdf, $object, $line, $label, $description, $posx, $posy, $w, $h); - $posy = $pdf->GetY(); - //print 'add ST'.$pdf->getPage().'
'; + if (!empty(getDolGlobalString('SUBTOTAL_DISABLE_FIX_TRANSACTION'))) { + $pageAfter = $pdf->getPage(); - } - else // No pagebreak - { - $pdf->commitTransaction(); - } - } - - // On delivery PDF, we don't want quantities to appear and there are no hooks => setting text color to background color; - if($object->element == 'delivery') + if ($pageAfter > $pageBefore) { + //print "ST $pageAfter>$pageBefore
"; + $pdf->rollbackTransaction(true); + $pdf->addPage('', '', true); + $posy = $pdf->GetY(); + $this->pdf_add_total($pdf, $object, $line, $label, $description, $posx, $posy, $w, $h); + $posy = $pdf->GetY(); + //print 'add ST'.$pdf->getPage().'
'; + } else // No pagebreak { - switch($line->qty) - { - case 99: - $grey = 220; - break; - - case 98: - $grey = 230; - break; - - default: - $grey = 240; - } - - $pdf->SetTextColor($grey, $grey, $grey); + $pdf->commitTransaction(); } - - $posy = $pdf->GetY(); - return 1; } - else if ($line->qty < 10) { - if(!empty(getDolGlobalString('SUBTOTAL_DISABLE_FIX_TRANSACTION'))) { - /** - * TCPDF::startTransaction() committe la transaction en cours s'il y en a une, - * ce qui peut être problématique. Comme TCPDF::rollbackTransaction() ne fait rien - * si aucune transaction n'est en cours, on peut y faire appel sans problème pour revenir - * à l'état d'origine. - */ - $pdf->rollbackTransaction(true); - $pdf->startTransaction(); - - $pageBefore = $pdf->getPage(); - } - $this->pdf_add_title($pdf,$object, $line, $label, $description,$posx, $posy, $w, $h); + // On delivery PDF, we don't want quantities to appear and there are no hooks => setting text color to background color; + if ($object->element == 'delivery') { + switch ($line->qty) { + case 99: + $grey = 220; + break; - if(!empty(getDolGlobalString('SUBTOTAL_DISABLE_FIX_TRANSACTION'))) { - $pageAfter = $pdf->getPage(); + case 98: + $grey = 230; + break; - if($pageAfter > $pageBefore) { - //print "ST $pageAfter>$pageBefore
"; - $pdf->rollbackTransaction(true); - $pdf->addPage('', '', true); - $posy = $pdf->GetY(); - $this->pdf_add_title($pdf, $object, $line, $label, $description, $posx, $posy, $w, $h); - $posy = $pdf->GetY(); - //print 'add ST'.$pdf->getPage().'
'; - - } - else // No pagebreak - { - $pdf->commitTransaction(); - } + default: + $grey = 240; } - if($object->element == 'delivery') - { - $pdf->SetTextColor(255,255,255); - } + $pdf->SetTextColor($grey, $grey, $grey); + } - $posy = $pdf->GetY(); - return 1; - } elseif(!empty($margin)) { + $posy = $pdf->GetY(); + return 1; + } elseif ($line->qty < 10) { + if (!empty(getDolGlobalString('SUBTOTAL_DISABLE_FIX_TRANSACTION'))) { + /** + * TCPDF::startTransaction() committe la transaction en cours s'il y en a une, + * ce qui peut être problématique. Comme TCPDF::rollbackTransaction() ne fait rien + * si aucune transaction n'est en cours, on peut y faire appel sans problème pour revenir + * à l'état d'origine. + */ + $pdf->rollbackTransaction(true); + $pdf->startTransaction(); + + $pageBefore = $pdf->getPage(); + } - $labelproductservice = pdf_getlinedesc($object, $i, $outputlangs, $parameters['hideref'], $parameters['hidedesc'], $parameters['issupplierline']); + $this->pdfAddTitle($pdf, $object, $line, $label, $description, $posx, $posy, $w, $h); - $labelproductservice = preg_replace('/(]*src=")([^"]*)(&)([^"]*")/', '\1\2&\4', $labelproductservice, -1, $nbrep); + if (!empty(getDolGlobalString('SUBTOTAL_DISABLE_FIX_TRANSACTION'))) { + $pageAfter = $pdf->getPage(); - if(!empty(getDolGlobalString('SUBTOTAL_DISABLE_FIX_TRANSACTION'))) { - /** - * TCPDF::startTransaction() committe la transaction en cours s'il y en a une, - * ce qui peut être problématique. Comme TCPDF::rollbackTransaction() ne fait rien - * si aucune transaction n'est en cours, on peut y faire appel sans problème pour revenir - * à l'état d'origine. - */ + if ($pageAfter > $pageBefore) { + //print "ST $pageAfter>$pageBefore
"; $pdf->rollbackTransaction(true); - $pdf->startTransaction(); - - $pageBefore = $pdf->getPage(); + $pdf->addPage('', '', true); + $posy = $pdf->GetY(); + $this->pdfAddTitle($pdf, $object, $line, $label, $description, $posx, $posy, $w, $h); + $posy = $pdf->GetY(); + //print 'add ST'.$pdf->getPage().'
'; + } else // No pagebreak + { + $pdf->commitTransaction(); } + } - $pdf->writeHTMLCell($parameters['w'], $parameters['h'], $parameters['posx'], $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1, false, true, 'J', true); + if ($object->element == 'delivery') { + $pdf->SetTextColor(255, 255, 255); + } - if(!empty(getDolGlobalString('SUBTOTAL_DISABLE_FIX_TRANSACTION'))) { - $pageAfter = $pdf->getPage(); + $posy = $pdf->GetY(); + return 1; + } elseif (!empty($margin)) { + $labelproductservice = pdf_getlinedesc($object, $i, $outputlangs, $parameters['hideref'], $parameters['hidedesc'], $parameters['issupplierline']); + + $labelproductservice = preg_replace('/(]*src=")([^"]*)(&)([^"]*")/', '\1\2&\4', $labelproductservice, -1, $nbrep); + + if (!empty(getDolGlobalString('SUBTOTAL_DISABLE_FIX_TRANSACTION'))) { + /** + * TCPDF::startTransaction() committe la transaction en cours s'il y en a une, + * ce qui peut être problématique. Comme TCPDF::rollbackTransaction() ne fait rien + * si aucune transaction n'est en cours, on peut y faire appel sans problème pour revenir + * à l'état d'origine. + */ + $pdf->rollbackTransaction(true); + $pdf->startTransaction(); + + $pageBefore = $pdf->getPage(); + } - if($pageAfter > $pageBefore) { - //print "ST $pageAfter>$pageBefore
"; - $pdf->rollbackTransaction(true); - $pdf->addPage('', '', true); - $posy = $pdf->GetY(); - $pdf->writeHTMLCell($parameters['w'], $parameters['h'], $parameters['posx'], $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1, false, true, 'J', true); - $posy = $pdf->GetY(); - //print 'add ST'.$pdf->getPage().'
'; + $pdf->writeHTMLCell($parameters['w'], $parameters['h'], $parameters['posx'], $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1, false, true, 'J', true); - } - else // No pagebreak - { - $pdf->commitTransaction(); - } - } + if (!empty(getDolGlobalString('SUBTOTAL_DISABLE_FIX_TRANSACTION'))) { + $pageAfter = $pdf->getPage(); - return 1; + if ($pageAfter > $pageBefore) { + //print "ST $pageAfter>$pageBefore
"; + $pdf->rollbackTransaction(true); + $pdf->addPage('', '', true); + $posy = $pdf->GetY(); + $pdf->writeHTMLCell($parameters['w'], $parameters['h'], $parameters['posx'], $posy, $outputlangs->convToOutputCharset($labelproductservice), 0, 1, false, true, 'J', true); + $posy = $pdf->GetY(); + //print 'add ST'.$pdf->getPage().'
'; + } else // No pagebreak + { + $pdf->commitTransaction(); + } } + return 1; + } + return 0; - } - elseif (empty($object->lines[$parameters['i']])) - { + } elseif (empty($object->lines[$parameters['i']])) { $this->resprints = -1; } - return 0; + return 0; } /** - * Permet de récupérer le titre lié au sous-total + * Get title * + * @param CommonObject $object Object + * @param CommonObjectLine $currentLine Current line * @return string */ - function getTitle(&$object, &$currentLine) + public function getTitle(&$object, &$currentLine) { $res = ''; - foreach ($object->lines as $line) - { + foreach ($object->lines as $line) { if ($line->id == $currentLine->id) break; $qty_search = 100 - $currentLine->qty; - if ($line->product_type == 9 && $line->special_code == $this->module_number && $line->qty == $qty_search) - { + if ($line->product_type == 9 && $line->special_code == $this->module_number && $line->qty == $qty_search) { $res = ($line->label) ? $line->label : (($line->description) ? $line->description : $line->desc); } } @@ -2633,13 +2707,15 @@ function getTitle(&$object, &$currentLine) } /** - * @param $parameters array - * @param $object CommonObject - * @param $action string - * @param $hookmanager HookManager + * Print object line + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @param HookManager $hookmanager Hook manager * @return int */ - function printObjectLine ($parameters, &$object, &$action, $hookmanager) + public function printObjectLine($parameters, &$object, &$action, $hookmanager) { global $conf, $langs, $user, $db, $bc, $usercandelete, $toselect; @@ -2650,144 +2726,124 @@ function printObjectLine ($parameters, &$object, &$action, $hookmanager) $var = &$parameters['var']; - $contexts = explode(':',$parameters['context']); - if($parameters['currentcontext'] === 'paiementcard') return 0; + $contexts = explode(':', $parameters['context']); + if ($parameters['currentcontext'] === 'paiementcard') return 0; $originline = null; - $newToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; + $newToken = function_exists('newToken') ? newToken() : $_SESSION['newtoken']; $createRight = $user->hasRight($object->element, 'creer'); - if($object->element == 'facturerec' ) - { + if ($object->element == 'facturerec' ) { $object->statut = 0; // hack for facture rec $createRight = $user->hasRight('facture', 'creer'); - } - elseif($object->element == 'order_supplier' ) - { - $createRight = $user->hasRight('fournisseur', 'commande', 'creer'); - } - elseif($object->element == 'invoice_supplier' ) - { - $createRight = $user->hasRight('fournisseur', 'facture', 'creer'); - } - elseif($object->element == 'commande' && in_array('ordershipmentcard', $contexts)) - { + } elseif ($object->element == 'order_supplier' ) { + $createRight = $user->hasRight('fournisseur', 'commande', 'creer'); + } elseif ($object->element == 'invoice_supplier' ) { + $createRight = $user->hasRight('fournisseur', 'facture', 'creer'); + } elseif ($object->element == 'commande' && in_array('ordershipmentcard', $contexts)) { // H4cK 4n0nYm0u$-style : $line n'est pas un objet instancié mais provient d'un fetch_object d'une requête SQL $line->id = $line->rowid; $line->product_type = $line->type; - } - elseif($object->element == 'shipping' || $object->element == 'delivery') - { - if(empty($line->origin_line_id) && (! empty($line->fk_elementdet || ! empty($line->fk_elementdet)))) - { + } elseif ($object->element == 'shipping' || $object->element == 'delivery') { + if (empty($line->origin_line_id) && (! empty($line->fk_elementdet || ! empty($line->fk_elementdet)))) { $line->origin_line_id = $line->fk_elementdet ?? $line->fk_elementdet; } $originline = new OrderLine($db); $originline->fetch($line->fk_elementdet ?? $line->fk_elementdet); - foreach(get_object_vars($line) as $property => $value) - { - if(empty($originline->{ $property })) - { + foreach (get_object_vars($line) as $property => $value) { + if (empty($originline->{ $property })) { $originline->{ $property } = $value; } } $line = $originline; } - if($object->element=='facture')$idvar = 'facid'; - else $idvar='id'; - if($line->special_code!=$this->module_number || $line->product_type!=9) { - if ($object->statut == 0 && $createRight && getDolGlobalString('SUBTOTAL_ALLOW_DUPLICATE_LINE') && $object->element !== 'invoice_supplier') - { - if(empty($line->fk_prev_id)) $line->fk_prev_id = null; - if(($object->element != 'shipping' && $object->element != 'delivery')&& !(TSubtotal::isModSubtotalLine($line)) && ( $line->fk_prev_id === null ) && !($action == "editline" && GETPOST('lineid', 'int') == $line->id)) { - echo ''; - - ?> - - element=='facture')$idvar = 'facid'; + else $idvar='id'; + if ($line->special_code!=$this->module_number || $line->product_type!=9) { + if ($object->statut == 0 && $createRight && getDolGlobalString('SUBTOTAL_ALLOW_DUPLICATE_LINE') && $object->element !== 'invoice_supplier') { + if (empty($line->fk_prev_id)) $line->fk_prev_id = null; + if (($object->element != 'shipping' && $object->element != 'delivery')&& !(TSubtotal::isModSubtotalLine($line)) && ( $line->fk_prev_id === null ) && !($action == "editline" && GETPOST('lineid', 'int') == $line->id)) { + echo ''; - if(empty($line->description)) $line->description = $line->desc; + ?> + + description)) $line->description = $line->desc; - $TNonAffectedByMarge = array('order_supplier', 'invoice_supplier', 'supplier_proposal'); - $affectedByMarge = in_array($object->element, $TNonAffectedByMarge) ? 0 : 1; + $TNonAffectedByMarge = array('order_supplier', 'invoice_supplier', 'supplier_proposal'); + $affectedByMarge = in_array($object->element, $TNonAffectedByMarge) ? 0 : 1; $colspan = 5; - if($object->element == 'order_supplier') $colspan = 6; - if($object->element == 'invoice_supplier') $colspan = 7; - if($object->element == 'supplier_proposal') $colspan = 3; + if ($object->element == 'order_supplier') $colspan = 6; + if ($object->element == 'invoice_supplier') $colspan = 7; + if ($object->element == 'supplier_proposal') $colspan = 3; - if(DOL_VERSION > 16.0 && empty(getDolGlobalString('MAIN_NO_INPUT_PRICE_WITH_TAX'))) $colspan++; // Ajout de la colonne PU TTC + if (DOL_VERSION > 16.0 && empty(getDolGlobalString('MAIN_NO_INPUT_PRICE_WITH_TAX'))) $colspan++; // Ajout de la colonne PU TTC - if($object->element == 'facturerec' ) $colspan = 5; + if ($object->element == 'facturerec' ) $colspan = 5; - if(isModEnabled('multicurrency') && ($object->multicurrency_code != $conf->currency)) { + if (isModEnabled('multicurrency') && ($object->multicurrency_code != $conf->currency)) { $colspan++; // Colonne PU Devise } - if($object->element == 'commande' && $object->statut < 3 && isModEnabled('shippableorder')) $colspan++; + if ($object->element == 'commande' && $object->statut < 3 && isModEnabled('shippableorder')) $colspan++; $margins_hidden_by_module = !isModEnabled('affmarges') ? false : !($_SESSION['marginsdisplayed']); - if(isModEnabled('margin') && !$margins_hidden_by_module) $colspan++; - if(isModEnabled('margin') && getDolGlobalString('DISPLAY_MARGIN_RATES') && !$margins_hidden_by_module && $affectedByMarge > 0) $colspan++; - if(isModEnabled('margin') && getDolGlobalString('DISPLAY_MARK_RATES') && !$margins_hidden_by_module && $affectedByMarge > 0) $colspan++; - if($object->element == 'facture' && getDolGlobalString('INVOICE_USE_SITUATION') && $object->type == Facture::TYPE_SITUATION) $colspan++; - if(getDolGlobalString('PRODUCT_USE_UNITS')) $colspan++; + if (isModEnabled('margin') && !$margins_hidden_by_module) $colspan++; + if (isModEnabled('margin') && getDolGlobalString('DISPLAY_MARGIN_RATES') && !$margins_hidden_by_module && $affectedByMarge > 0) $colspan++; + if (isModEnabled('margin') && getDolGlobalString('DISPLAY_MARK_RATES') && !$margins_hidden_by_module && $affectedByMarge > 0) $colspan++; + if ($object->element == 'facture' && getDolGlobalString('INVOICE_USE_SITUATION') && $object->type == Facture::TYPE_SITUATION) $colspan++; + if (getDolGlobalString('PRODUCT_USE_UNITS')) $colspan++; // Compatibility module showprice - if(isModEnabled('showprice')) $colspan++; + if (isModEnabled('showprice')) $colspan++; /* Titre */ // HTML 5 data for js - $data = $this->_getHtmlData($parameters, $object, $action, $hookmanager); - - // Prepare CSS class - $class = ''; - if (!empty(getDolGlobalString('SUBTOTAL_USE_NEW_FORMAT'))) $class .= ' newSubtotal'; - if ($line->qty == 1) $class .= ' subtitleLevel1'; // Title level 1 - elseif ($line->qty == 2) $class .= ' subtitleLevel2'; // Title level 2 - elseif ($line->qty > 2 && $line->qty < 10) $class .= ' subtitleLevel3to9'; // Sub-total level 3 to 9 - elseif ($line->qty == 99) $class .= ' subtotalLevel1'; // Sub-total level 1 - elseif ($line->qty == 98) $class .= ' subtotalLevel2'; // Sub-total level 2 - elseif ($line->qty > 90 && $line->qty < 98) $class .= ' subtotalLevel3to9'; // Sub-total level 3 to 9 - elseif ($line->qty == 50) $class .= ' subtotalText'; // Free text + $data = $this->getHtmlData($parameters, $object, $action, $hookmanager); + + // Prepare CSS class + $class = ''; + if (!empty(getDolGlobalString('SUBTOTAL_USE_NEW_FORMAT'))) $class .= ' newSubtotal'; + if ($line->qty == 1) $class .= ' subtitleLevel1'; // Title level 1 + elseif ($line->qty == 2) $class .= ' subtitleLevel2'; // Title level 2 + elseif ($line->qty > 2 && $line->qty < 10) $class .= ' subtitleLevel3to9'; // Sub-total level 3 to 9 + elseif ($line->qty == 99) $class .= ' subtotalLevel1'; // Sub-total level 1 + elseif ($line->qty == 98) $class .= ' subtotalLevel2'; // Sub-total level 2 + elseif ($line->qty > 90 && $line->qty < 98) $class .= ' subtotalLevel3to9'; // Sub-total level 3 to 9 + elseif ($line->qty == 50) $class .= ' subtotalText'; // Free text ?> rel="subtotal" id="row-id ?>" style="qty==99) print 'background:#adadcf'; // Sub-total level 1 - else if($line->qty==98) print 'background:#ddddff;'; // Sub-total level 2 - else if($line->qty<=97 && $line->qty>=91) print 'background:#eeeeff;'; // Sub-total level 3 to 9 - else if($line->qty==1) print 'background:#adadcf;'; // Title level 1 - else if($line->qty==2) print 'background:#ddddff;'; // Title level 2 - else if($line->qty==50) print ''; // Free text - else print 'background:#eeeeff;'; // Title level 3 to 9 - - // À compléter si on veut plus de nuances de couleurs avec les niveaux 4,5,6,7,8 et 9 - } - else - { - if($line->qty==99) print 'background:#ddffdd'; // Sub-total level 1 - else if($line->qty==98) print 'background:#ddddff;'; // Sub-total level 2 - else if($line->qty==2) print 'background:#eeeeff; '; // Title level 2 - else if($line->qty==50) print ''; // Free text - else print 'background:#eeffee;' ; // Title level 1 and 3 to 9 - } + if (!empty(getDolGlobalString('SUBTOTAL_USE_NEW_FORMAT'))) { + if ($line->qty==99) print 'background:#adadcf'; // Sub-total level 1 + elseif ($line->qty==98) print 'background:#ddddff;'; // Sub-total level 2 + elseif ($line->qty<=97 && $line->qty>=91) print 'background:#eeeeff;'; // Sub-total level 3 to 9 + elseif ($line->qty==1) print 'background:#adadcf;'; // Title level 1 + elseif ($line->qty==2) print 'background:#ddddff;'; // Title level 2 + elseif ($line->qty==50) print ''; // Free text + else print 'background:#eeeeff;'; // Title level 3 to 9 + + // À compléter si on veut plus de nuances de couleurs avec les niveaux 4,5,6,7,8 et 9 + } else { + if ($line->qty==99) print 'background:#ddffdd'; // Sub-total level 1 + elseif ($line->qty==98) print 'background:#ddddff;'; // Sub-total level 2 + elseif ($line->qty==2) print 'background:#eeeeff; '; // Title level 2 + elseif ($line->qty==50) print ''; // Free text + else print 'background:#eeffee;' ; // Title level 1 and 3 to 9 + } ?>;"> - + @@ -2801,195 +2857,176 @@ function printObjectLine ($parameters, &$object, &$action, $hookmanager) if ($object->element == 'invoice_supplier') { $colspan -= 2; } - $line_show_qty = false; - - if(TSubtotal::isSubtotal($line)) { - - /* Total */ - $TSubtotalDatas = $this->getTotalLineFromObject($object, $line, '', 1); - $total_line = $TSubtotalDatas[0]; - $total_qty = $TSubtotalDatas[4]; - if ($show_qty_bu_deault = TSubtotal::showQtyForObject($object)) { - $line_show_qty = TSubtotal::showQtyForObjectLine($line, $show_qty_bu_deault); + $line_show_qty = false; - } - } + if (TSubtotal::isSubtotal($line)) { + /* Total */ + $TSubtotalDatas = $this->getTotalLineFromObject($object, $line, '', 1); + $total_line = $TSubtotalDatas[0]; + $total_qty = $TSubtotalDatas[4]; + if ($show_qty_bu_deault = TSubtotal::showQtyForObject($object)) { + $line_show_qty = TSubtotal::showQtyForObjectLine($line, $show_qty_bu_deault); + } + } ?> id && TSubtotal::isModSubtotalLine($line) ) { - - echo ''; - $params=array('line'=>$line); - $reshook=$hookmanager->executeHooks('formEditProductOptions',$params,$object,$action); - - echo '
'; // Imitation Dolibarr - echo ''; - echo ''; - echo ''; - echo ''; - - $isFreeText=false; - if (TSubtotal::isTitle($line)) - { - $qty_displayed = $line->qty; - print img_picto('', 'subsubtotal@subtotal').''.$qty_displayed.'  '; + if ($action=='editline' && GETPOST('lineid', 'int') == $line->id && TSubtotal::isModSubtotalLine($line) ) { + echo ''; + $params=array('line'=>$line); + $reshook=$hookmanager->executeHooks('formEditProductOptions', $params, $object, $action); + + echo '
'; // Imitation Dolibarr + echo ''; + echo ''; + echo ''; + echo ''; + + $isFreeText=false; + if (TSubtotal::isTitle($line)) { + $qty_displayed = $line->qty; + print img_picto('', 'subsubtotal@subtotal').''.$qty_displayed.'  '; + } elseif (TSubtotal::isSubtotal($line)) { + $qty_displayed = 100 - $line->qty; + print img_picto('', 'subsubtotal2@subtotal').''.$qty_displayed.'  '; + } else { + $isFreeText = true; + } + if ($object->element == 'order_supplier' || $object->element == 'invoice_supplier') { + $line->label = !empty($line->description) ? $line->description : $line->desc; + $line->description = ''; + } + $newlabel = $line->label; + if ($line->label=='' && !$isFreeText) { + if (TSubtotal::isSubtotal($line)) { + $newlabel = $line->description.' '.$this->getTitle($object, $line); + $line->description=''; } - else if (TSubtotal::isSubtotal($line)) - { - $qty_displayed = 100 - $line->qty; - print img_picto('', 'subsubtotal2@subtotal').''.$qty_displayed.'  '; - } - else - { - $isFreeText = true; - } + } - if ($object->element == 'order_supplier' || $object->element == 'invoice_supplier') { - $line->label = !empty($line->description) ? $line->description : $line->desc; - $line->description = ''; - } - $newlabel = $line->label; - if($line->label=='' && !$isFreeText) { - if(TSubtotal::isSubtotal($line)) { - $newlabel = $line->description.' '.$this->getTitle($object, $line); - $line->description=''; - } - } + $readonlyForSituation = ''; + if (empty($line->fk_prev_id)) $line->fk_prev_id = null; + if (!empty($line->fk_prev_id) && $line->fk_prev_id != null) $readonlyForSituation = 'readonly'; - $readonlyForSituation = ''; - if(empty($line->fk_prev_id)) $line->fk_prev_id = null; - if (!empty($line->fk_prev_id) && $line->fk_prev_id != null) $readonlyForSituation = 'readonly'; + if (!$isFreeText) echo ' '; - if (!$isFreeText) echo ' '; + if (getDolGlobalString('SUBTOTAL_USE_NEW_FORMAT') && (TSubtotal::isTitle($line) || TSubtotal::isSubtotal($line)) ) { + $select = ' '; - if (getDolGlobalString('SUBTOTAL_USE_NEW_FORMAT') && (TSubtotal::isTitle($line) || TSubtotal::isSubtotal($line)) ) - { - $select = ' '; + echo $select; + } - echo $select; - } + echo '
'; + if (!getDolGlobalString('SUBTOTAL_HIDE_OPTIONS_BREAK_PAGE_BEFORE')) { + echo '
'; + echo 'info_bits > 0) ? 'checked="checked"' : '') .' /> '; + echo ''; + echo '
'; + } + if (TSubtotal::isTitle($line)&& !getDolGlobalString('SUBTOTAL_HIDE_OPTIONS_TITLE')) { + $form = new Form($db); + echo '
'; + echo ''; + echo ''; + echo '
'; - echo '
'; - if (!getDolGlobalString('SUBTOTAL_HIDE_OPTIONS_BREAK_PAGE_BEFORE')){ + if (getDolGlobalString('INVOICE_USE_SITUATION') && $object->element == 'facture' && $object->type == Facture::TYPE_SITUATION) { echo '
'; - echo 'info_bits > 0) ? 'checked="checked"' : '') .' /> '; - echo ''; + echo ' %'; echo '
'; } - if (TSubtotal::isTitle($line)&& !getDolGlobalString('SUBTOTAL_HIDE_OPTIONS_TITLE')) - { - $form = new Form($db); - echo '
'; - echo ''; - echo ''; - echo '
'; - - if (getDolGlobalString('INVOICE_USE_SITUATION') && $object->element == 'facture' && $object->type == Facture::TYPE_SITUATION) - { - echo '
'; - echo ' %'; - echo '
'; - } - echo '
'; - echo 'array_options['options_show_total_ht']) && $line->array_options['options_show_total_ht'] > 0) ? 'checked="checked"' : '') .' /> '; - echo ''; - echo '
'; - - echo '
'; - echo 'array_options['options_show_reduc']) && $line->array_options['options_show_reduc'] > 0) ? 'checked="checked"' : '') .' /> '; - echo ''; - echo '
'; - } - else if ($isFreeText) echo TSubtotal::getFreeTextHtml($line, (bool) $readonlyForSituation); - - if (TSubtotal::isSubtotal($line) && $show_qty_bu_deault = TSubtotal::showQtyForObject($object)) { - $line_show_qty = TSubtotal::showQtyForObjectLine($line, $show_qty_bu_deault); - echo '
'; - echo ' '; - echo ''; - echo '
'; - } + echo '
'; + echo 'array_options['options_show_total_ht']) && $line->array_options['options_show_total_ht'] > 0) ? 'checked="checked"' : '') .' /> '; + echo ''; + echo '
'; + echo '
'; + echo 'array_options['options_show_reduc']) && $line->array_options['options_show_reduc'] > 0) ? 'checked="checked"' : '') .' /> '; + echo ''; echo '
'; + } elseif ($isFreeText) echo TSubtotal::getFreeTextHtml($line, (bool) $readonlyForSituation); - if (TSubtotal::isTitle($line)) - { - // WYSIWYG editor - require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; - $nbrows = ROWS_2; - $cked_enabled = (getDolGlobalString('FCKEDITOR_ENABLE_DETAILS') ? getDolGlobalString('FCKEDITOR_ENABLE_DETAILS'): 0); - if (getDolGlobalString('MAIN_INPUT_DESC_HEIGHT')) { - $nbrows = getDolGlobalString('MAIN_INPUT_DESC_HEIGHT'); - } - $toolbarname = 'dolibarr_details'; - if (getDolGlobalString('FCKEDITOR_ENABLE_DETAILS_FULL')) { - $toolbarname = 'dolibarr_notes'; - } - $doleditor = new DolEditor('line-description', $line->description, '', 100, $toolbarname, '', - false, true, $cked_enabled, $nbrows, '98%', (bool) $readonlyForSituation); - $doleditor->Create(); - - $TKey = null; - getDolGlobalString('SUBTOTAL_LIST_OF_EXTRAFIELDS_PROPALDET', ''); - getDolGlobalString('SUBTOTAL_LIST_OF_EXTRAFIELDS_COMMANDEDET', ''); - getDolGlobalString('SUBTOTAL_LIST_OF_EXTRAFIELDS_FACTUREDET', ''); - if ($line->element == 'propaldet') $TKey = explode(',', getDolGlobalString('SUBTOTAL_LIST_OF_EXTRAFIELDS_PROPALDET')); - elseif ($line->element == 'commandedet') $TKey = explode(',', getDolGlobalString('SUBTOTAL_LIST_OF_EXTRAFIELDS_COMMANDEDET')); - elseif ($line->element == 'facturedet') $TKey = explode(',', getDolGlobalString('SUBTOTAL_LIST_OF_EXTRAFIELDS_FACTUREDET')); - // TODO ajouter la partie fournisseur - - if (!empty($TKey)) - { - $extrafields = new ExtraFields($this->db); - $extrafields->fetch_name_optionals_label($object->table_element_line); - if(!empty($extrafields->attributes[$line->element]['param'])) { - foreach($extrafields->attributes[$line->element]['param'] as $code => $val) { - if(in_array($code, $TKey) && $extrafields->attributes[$line->element]['list'][$code] > 0) { - echo '
'; - echo ''; - if(floatval(DOL_VERSION) >= 17) echo $extrafields->showInputField($code, $line->array_options['options_'.$code], '', '', 'subtotal_','',0,$object->table_element_line); - else echo $extrafields->showInputField($code, $line->array_options['options_'.$code], '', '', 'subtotal_'); - echo '
'; - } + if (TSubtotal::isSubtotal($line) && $show_qty_bu_deault = TSubtotal::showQtyForObject($object)) { + $line_show_qty = TSubtotal::showQtyForObjectLine($line, $show_qty_bu_deault); + echo '
'; + echo ' '; + echo ''; + echo '
'; + } + + echo '
'; + + if (TSubtotal::isTitle($line)) { + // WYSIWYG editor + require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; + $nbrows = ROWS_2; + $cked_enabled = (getDolGlobalString('FCKEDITOR_ENABLE_DETAILS') ? getDolGlobalString('FCKEDITOR_ENABLE_DETAILS'): 0); + if (getDolGlobalString('MAIN_INPUT_DESC_HEIGHT')) { + $nbrows = getDolGlobalString('MAIN_INPUT_DESC_HEIGHT'); + } + $toolbarname = 'dolibarr_details'; + if (getDolGlobalString('FCKEDITOR_ENABLE_DETAILS_FULL')) { + $toolbarname = 'dolibarr_notes'; + } + $doleditor = new DolEditor('line-description', $line->description, '', 100, $toolbarname, '', + false, true, $cked_enabled, $nbrows, '98%', (bool) $readonlyForSituation); + $doleditor->Create(); + + $TKey = null; + getDolGlobalString('SUBTOTAL_LIST_OF_EXTRAFIELDS_PROPALDET', ''); + getDolGlobalString('SUBTOTAL_LIST_OF_EXTRAFIELDS_COMMANDEDET', ''); + getDolGlobalString('SUBTOTAL_LIST_OF_EXTRAFIELDS_FACTUREDET', ''); + if ($line->element == 'propaldet') $TKey = explode(',', getDolGlobalString('SUBTOTAL_LIST_OF_EXTRAFIELDS_PROPALDET')); + elseif ($line->element == 'commandedet') $TKey = explode(',', getDolGlobalString('SUBTOTAL_LIST_OF_EXTRAFIELDS_COMMANDEDET')); + elseif ($line->element == 'facturedet') $TKey = explode(',', getDolGlobalString('SUBTOTAL_LIST_OF_EXTRAFIELDS_FACTUREDET')); + // TODO ajouter la partie fournisseur + + if (!empty($TKey)) { + $extrafields = new ExtraFields($this->db); + $extrafields->fetch_name_optionals_label($object->table_element_line); + if (!empty($extrafields->attributes[$line->element]['param'])) { + foreach ($extrafields->attributes[$line->element]['param'] as $code => $val) { + if (in_array($code, $TKey) && $extrafields->attributes[$line->element]['list'][$code] > 0) { + echo '
'; + echo ''; + if (floatval(DOL_VERSION) >= 17) echo $extrafields->showInputField($code, $line->array_options['options_'.$code], '', '', 'subtotal_', '', 0, $object->table_element_line); + else echo $extrafields->showInputField($code, $line->array_options['options_'.$code], '', '', 'subtotal_'); + echo '
'; } } } } + } + } else { + if ($line_show_qty) { + $colspan -= 2; + + $style = getDolGlobalString('SUBTOTAL_TITLE_STYLE', ''); + $titleStyleItalic = strpos($style, 'I') === false ? '' : ' font-style: italic;'; + $titleStyleBold = strpos($style, 'B') === false ? '' : ' font-weight:bold;'; + $titleStyleUnderline = strpos($style, 'U') === false ? '' : ' text-decoration: underline;'; + $style = 'text-align:right;'; + echo ''; + echo '' . $langs->trans('Qty') . ' :   ' . price($total_qty, 0, '', 0, 0); + echo ''; + $colspan = 2; } - else { - - if ($line_show_qty) { - $colspan -= 2; - - $style = getDolGlobalString('SUBTOTAL_TITLE_STYLE', ''); - $titleStyleItalic = strpos($style, 'I') === false ? '' : ' font-style: italic;'; - $titleStyleBold = strpos($style, 'B') === false ? '' : ' font-weight:bold;'; - $titleStyleUnderline = strpos($style, 'U') === false ? '' : ' text-decoration: underline;'; - - $style = 'text-align:right;'; - echo ''; - echo '' . $langs->trans('Qty') . ' :   ' . price($total_qty, 0, '', 0, 0); - echo ''; - $colspan = 2; - } - if(TSubtotal::isSubtotal($line) && getDolGlobalString('DISPLAY_MARGIN_ON_SUBTOTALS')) { + if (TSubtotal::isSubtotal($line) && getDolGlobalString('DISPLAY_MARGIN_ON_SUBTOTALS')) { $colspan --; - $style = getDolGlobalString('SUBTOTAL_TITLE_STYLE', ''); + $style = getDolGlobalString('SUBTOTAL_TITLE_STYLE', ''); $titleStyleItalic = strpos($style, 'I') === false ? '' : ' font-style: italic;'; $titleStyleBold = strpos($style, 'B') === false ? '' : ' font-weight:bold;'; $titleStyleUnderline = strpos($style, 'U') === false ? '' : ' text-decoration: underline;'; @@ -3003,21 +3040,21 @@ function printObjectLine ($parameters, &$object, &$action, $hookmanager) echo 'Marge :'; - $parentTitleLine = TSubtotal::getParentTitleOfLine($object, $line->rang); - $productLines = TSubtotal::getLinesFromTitleId($object, $parentTitleLine->id); + $parentTitleLine = TSubtotal::getParentTitleOfLine($object, $line->rang); + $productLines = TSubtotal::getLinesFromTitleId($object, $parentTitleLine->id); $totalCostPrice = 0; - if(!empty($productLines)){ + if (!empty($productLines)) { foreach ($productLines as $l) { $product = new Product($db); $res = $product->fetch($l->fk_product); - if($res) { - $totalCostPrice += $product->cost_price * $l->qty; + if ($res) { + $totalCostPrice += $product->cost_price * $l->qty; } - } + } } - $marge = $total_line - $totalCostPrice; + $marge = $total_line - $totalCostPrice; echo '  '.price($marge); echo ''; @@ -3026,100 +3063,90 @@ function printObjectLine ($parameters, &$object, &$action, $hookmanager) - //SousTotal : - $style = TSubtotal::isFreeText($line) ? '' : 'font-weight:bold;'; - $style.= $line->qty>90 ? 'text-align:right' : ''; - - echo ''; - if (getDolGlobalString('SUBTOTAL_USE_NEW_FORMAT')) - { - if(TSubtotal::isTitle($line)) - { - echo str_repeat('   ', max(floatval($line->qty) - 1, 0)); + //SousTotal : + $style = TSubtotal::isFreeText($line) ? '' : 'font-weight:bold;'; + $style.= $line->qty>90 ? 'text-align:right' : ''; - if (TSubtotal::isTitle($line)) print img_picto('', 'subtotal@subtotal').''.$line->qty.'  '; - else print img_picto('', 'subtotal2@subtotal').''.(100-$line->qty).'  '; - } - } - else - { - if($line->qty<=1) print img_picto('', 'subtotal@subtotal'); - else if($line->qty==2) print img_picto('', 'subsubtotal@subtotal').'     '; - } + echo ''; + if (getDolGlobalString('SUBTOTAL_USE_NEW_FORMAT')) { + if (TSubtotal::isTitle($line)) { + echo str_repeat('   ', max(floatval($line->qty) - 1, 0)); + if (TSubtotal::isTitle($line)) print img_picto('', 'subtotal@subtotal').''.$line->qty.'  '; + else print img_picto('', 'subtotal2@subtotal').''.(100-$line->qty).'  '; + } + } else { + if ($line->qty<=1) print img_picto('', 'subtotal@subtotal'); + elseif ($line->qty==2) print img_picto('', 'subsubtotal@subtotal').'     '; + } - // Get display styles and apply them - $style = ''; - $style = TSubtotal::isFreeText($line) ? getDolGlobalString('SUBTOTAL_TEXT_LINE_STYLE', '') : getDolGlobalString('SUBTOTAL_TITLE_STYLE', ''); - $titleStyleItalic = strpos($style, 'I') === false ? '' : ' font-style: italic;'; - $titleStyleBold = strpos($style, 'B') === false ? '' : ' font-weight:bold;'; - $titleStyleUnderline = strpos($style, 'U') === false ? '' : ' text-decoration: underline;'; - - if (empty($line->label)) { - if ($line->qty >= 91 && $line->qty <= 99 && getDolGlobalString('CONCAT_TITLE_LABEL_IN_SUBTOTAL_LABEL')) print $line->description.' '.''.$this->getTitle($object, $line).''; - else print ''.$line->description.''; - } - else { - if (getDolGlobalString('PRODUIT_DESC_IN_FORM') && !empty($line->description)) { - // on ne veut pas afficher le label et la description si elles sont identiques - $lineLabel = $line->description != $line->label ? $line->label.'
'.dol_htmlentitiesbr($line->description) : $line->label ; - print '' . $lineLabel . '
'; - } - else{ - print ''.$line->label.''; - } + // Get display styles and apply them + $style = ''; + $style = TSubtotal::isFreeText($line) ? getDolGlobalString('SUBTOTAL_TEXT_LINE_STYLE', '') : getDolGlobalString('SUBTOTAL_TITLE_STYLE', ''); + $titleStyleItalic = strpos($style, 'I') === false ? '' : ' font-style: italic;'; + $titleStyleBold = strpos($style, 'B') === false ? '' : ' font-weight:bold;'; + $titleStyleUnderline = strpos($style, 'U') === false ? '' : ' text-decoration: underline;'; - } - if (TSubtotal::isTitle($line)) { - //Folder for expand - $titleAttr = (array_key_exists('options_hideblock', $line->array_options) && $line->array_options['options_hideblock'] == 1) ? $langs->trans("Subtotal_Show") : $langs->trans("Subtotal_Hide"); + if (empty($line->label)) { + if ($line->qty >= 91 && $line->qty <= 99 && getDolGlobalString('CONCAT_TITLE_LABEL_IN_SUBTOTAL_LABEL')) print $line->description.' '.$this->getTitle($object, $line).''; + else print ''.$line->description.''; + } else { + if (getDolGlobalString('PRODUIT_DESC_IN_FORM') && !empty($line->description)) { + // on ne veut pas afficher le label et la description si elles sont identiques + $lineLabel = $line->description != $line->label ? $line->label.'
'.dol_htmlentitiesbr($line->description) : $line->label ; + print '' . $lineLabel . '
'; + } else { + print ''.$line->label.''; + } + } + if (TSubtotal::isTitle($line)) { + //Folder for expand + $titleAttr = (array_key_exists('options_hideblock', $line->array_options) && $line->array_options['options_hideblock'] == 1) ? $langs->trans("Subtotal_Show") : $langs->trans("Subtotal_Hide"); - print ''; + print ''; - // bouton pour ouvrir/fermer le bloc - print ' '; - print ((array_key_exists('options_hideblock', $line->array_options) && $line->array_options['options_hideblock'] == 1) ? img_picto('', 'folder') : img_picto('', 'folder-open')); - print ''; + // bouton pour ouvrir/fermer le bloc + print ' '; + print ((array_key_exists('options_hideblock', $line->array_options) && $line->array_options['options_hideblock'] == 1) ? img_picto('', 'folder') : img_picto('', 'folder-open')); + print ''; - // Bouton pour ouvrir/fermer aussi les enfants - print ' '; - print ((array_key_exists('options_hideblock', $line->array_options) && $line->array_options['options_hideblock'] == 1) ? img_picto('', 'folder') : img_picto('', 'folder-open')); - print ''; + // Bouton pour ouvrir/fermer aussi les enfants + print ' '; + print ((array_key_exists('options_hideblock', $line->array_options) && $line->array_options['options_hideblock'] == 1) ? img_picto('', 'folder') : img_picto('', 'folder-open')); + print ''; - // un span pour contenir des infos comme le nombre de lignes cachées etc... - print ' '; + // un span pour contenir des infos comme le nombre de lignes cachées etc... + print ' '; - print ''; - } + print ''; + } - if($line->qty>90) print ' : '; - if($line->info_bits > 0) echo img_picto($langs->trans('Pagebreak'), 'pagebreak@subtotal'); - } - ?> + if ($line->qty>90) print ' : '; + if ($line->info_bits > 0) echo img_picto($langs->trans('Pagebreak'), 'pagebreak@subtotal'); + } + ?> qty>90) { - - /* Total */ - echo ''.price($total_line).''; - if (isModEnabled('multicurrency') && ($object->multicurrency_code != $conf->currency)) { - echo ' '; - } - } else { - echo ' '; - if (isModEnabled('multicurrency') && ($object->multicurrency_code != $conf->currency)) { - echo ' '; - } + if ($line->qty>90) { + /* Total */ + echo ''.price($total_line).''; + if (isModEnabled('multicurrency') && ($object->multicurrency_code != $conf->currency)) { + echo ' '; + } + } else { + echo ' '; + if (isModEnabled('multicurrency') && ($object->multicurrency_code != $conf->currency)) { + echo ' '; } + } ?> id && TSubtotal::isModSubtotalLine($line) ) { + if ($action=='editline' && GETPOST('lineid', 'int') == $line->id && TSubtotal::isModSubtotalLine($line) ) { ?>
@@ -3133,27 +3160,22 @@ function printObjectLine ($parameters, &$object, &$action, $hookmanager) statut == 0 && $createRight && getDolGlobalString('SUBTOTAL_ALLOW_DUPLICATE_BLOCK') && $object->element !== 'invoice_supplier') - { - if(empty($line->fk_prev_id)) $line->fk_prev_id = null; - if(TSubtotal::isTitle($line) && ( $line->fk_prev_id === null )) { + } else { + if ($object->statut == 0 && $createRight && getDolGlobalString('SUBTOTAL_ALLOW_DUPLICATE_BLOCK') && $object->element !== 'invoice_supplier') { + if (empty($line->fk_prev_id)) $line->fk_prev_id = null; + if (TSubtotal::isTitle($line) && ( $line->fk_prev_id === null )) { echo ''; - echo ''; + echo ''; echo ''; } } - if ($object->statut == 0 && $createRight && getDolGlobalString('SUBTOTAL_ALLOW_EDIT_BLOCK')) - { + if ($object->statut == 0 && $createRight && getDolGlobalString('SUBTOTAL_ALLOW_EDIT_BLOCK')) { echo ''.img_edit().''; } } - } ?> @@ -3163,29 +3185,24 @@ function printObjectLine ($parameters, &$object, &$action, $hookmanager) statut == 0 && $createRight && !empty(getDolGlobalString('SUBTOTAL_ALLOW_REMOVE_BLOCK'))) - { - if(empty($line->fk_prev_id)) $line->fk_prev_id = null; - if (!isset($line->fk_prev_id) || $line->fk_prev_id === null) - { - echo ''.img_delete().''; - } - - if(TSubtotal::isTitle($line) && (!isset($line->fk_prev_id) || (isset($line->fk_prev_id) && ($line->fk_prev_id === null))) ) - { + if ($object->statut == 0 && $createRight && !empty(getDolGlobalString('SUBTOTAL_ALLOW_REMOVE_BLOCK'))) { + if (empty($line->fk_prev_id)) $line->fk_prev_id = null; + if (!isset($line->fk_prev_id) || $line->fk_prev_id === null) { + echo ''.img_delete().''; + } - $img_delete = img_delete($langs->trans('deleteWithAllLines'), ' style="color:#be3535 !important;" class="pictodelete pictodeleteallline"'); + if (TSubtotal::isTitle($line) && (!isset($line->fk_prev_id) || (isset($line->fk_prev_id) && ($line->fk_prev_id === null))) ) { + $img_delete = img_delete($langs->trans('deleteWithAllLines'), ' style="color:#be3535 !important;" class="pictodelete pictodeleteallline"'); - echo ''.$img_delete.''; - } + echo ''.$img_delete.''; } } + } ?> statut == 0 && $createRight && !empty(getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS')) && TSubtotal::isTitle($line) && $action != 'editline' && $action != 'selectlines') - { + if ($object->statut == 0 && $createRight && !empty(getDolGlobalString('SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS')) && TSubtotal::isTitle($line) && $action != 'editline' && $action != 'selectlines') { echo ''; echo 'array_options['options_subtotal_nc']) ? 'checked="checked"' : '').' />'; echo ''; @@ -3202,12 +3219,11 @@ function printObjectLine ($parameters, &$object, &$action, $hookmanager) status == $object::STATUS_DRAFT && $usercandelete && in_array($object->element,$Telement)|| $action == 'selectlines' ) { // dolibarr 8 - + if (!empty(getDolGlobalString('MASSACTION_CARD_ENABLE_SELECTLINES')) && $object->status == $object::STATUS_DRAFT && $usercandelete && in_array($object->element, $Telement)|| $action == 'selectlines' ) { // dolibarr 8 if ($action !== 'editline' && GETPOST('lineid', 'int') !== $line->id) { $checked = ''; - if (!empty($toselect) && in_array($line->id,$toselect)){ + if (!empty($toselect) && in_array($line->id, $toselect)) { $checked = 'checked'; } @@ -3225,8 +3241,7 @@ function printObjectLine ($parameters, &$object, &$action, $hookmanager) // Affichage des extrafields à la Dolibarr (car sinon non affiché sur les titres) - if(TSubtotal::isTitle($line) && getDolGlobalString('SUBTOTAL_ALLOW_EXTRAFIELDS_ON_TITLE')) { - + if (TSubtotal::isTitle($line) && getDolGlobalString('SUBTOTAL_ALLOW_EXTRAFIELDS_ON_TITLE')) { require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; // Extrafields @@ -3234,20 +3249,20 @@ function printObjectLine ($parameters, &$object, &$action, $hookmanager) $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); $colspan+=3; $mode = 'view'; - if($action === 'editline' && $line->rowid == GETPOST('lineid', 'int')) $mode = 'edit'; + if ($action === 'editline' && $line->rowid == GETPOST('lineid', 'int')) $mode = 'edit'; $ex_element = $line->element; $line->element = 'tr_extrafield_title '.$line->element; // Pour pouvoir manipuler ces tr print $line->showOptionals($extrafieldsline, $mode, array('style'=>' style="background:#eeffee;" ','colspan'=>$colspan)); $isExtraSelected = false; - foreach($line->array_options as $option) { - if(!empty($option) && $option != "-1") { + foreach ($line->array_options as $option) { + if (!empty($option) && $option != "-1") { $isExtraSelected = true; break; } } - if($mode === 'edit') { + if ($mode === 'edit') { ?> '; // used also for subtotal.lib.js - if(!getDolGlobalString('SUBTOTAL_DISABLE_SUMMARY')){ + if (!getDolGlobalString('SUBTOTAL_DISABLE_SUMMARY')) { $jsConfig = array( 'langs' => array( 'SubtotalSummaryTitle' => $langs->trans('QuickSummary') @@ -3804,14 +3787,22 @@ function callAjaxUpdateLineNC(set, lineid, subtotal_nc) return 0; } - function afterPDFCreation($parameters, &$pdf, &$action, $hookmanager) + /** + * After PDF creation + * + * @param array $parameters Parameters + * @param TCPDF $pdf PDF + * @param string $action Action + * @param HookManager $hookmanager Hook manager + * @return int + */ + public function afterPDFCreation($parameters, &$pdf, &$action, $hookmanager) { global $conf; $object = $parameters['object']; - if ((getDolGlobalString('SUBTOTAL_PROPAL_ADD_RECAP') && $object->element == 'propal') || (getDolGlobalString('SUBTOTAL_COMMANDE_ADD_RECAP') && $object->element == 'commande') || (getDolGlobalString('SUBTOTAL_INVOICE_ADD_RECAP') && $object->element == 'facture')) - { + if ((getDolGlobalString('SUBTOTAL_PROPAL_ADD_RECAP') && $object->element == 'propal') || (getDolGlobalString('SUBTOTAL_COMMANDE_ADD_RECAP') && $object->element == 'commande') || (getDolGlobalString('SUBTOTAL_INVOICE_ADD_RECAP') && $object->element == 'facture')) { if (GETPOST('subtotal_add_recap', 'none')) { dol_include_once('/subtotal/class/subtotal.class.php'); TSubtotal::addRecapPage($parameters, $pdf); @@ -3821,114 +3812,131 @@ function afterPDFCreation($parameters, &$pdf, &$action, $hookmanager) return 0; } - /** Overloading the getlinetotalremise function : replacing the parent's function with the one below - * @param $parameters array meta datas of the hook (context, etc...) - * @param $object CommonObject the object you want to process (an invoice if you are in invoice module, a propale in propale's module, etc...) - * @param $action string current action (if set). Generally create or edit or null - * @param $hookmanager HookManager current hook manager - * @return void + /** + * Overloading the getlinetotalremise function : replacing the parent's function with the one below + * + * @param array $parameters Meta datas of the hook (context, etc...) + * @param CommonObject $object The object you want to process (an invoice if you are in invoice module, a propale in propale's module, etc...) + * @param string $action Current action (if set). Generally create or edit or null + * @param HookManager $hookmanager Current hook manager + * @return int */ - function getlinetotalremise($parameters, &$object, &$action, $hookmanager) + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps + public function getlinetotalremise($parameters, &$object, &$action, $hookmanager) { - // Si c'est une ligne de sous-total, la méthode pdfGetLineTotalDiscountAmount ne doit rien renvoyer - if (!empty($object->lines[$parameters['i']]) && TSubtotal::isModSubtotalLine($object->lines[$parameters['i']])) { - $this->resprints = ''; - $this->results = []; + // Si c'est une ligne de sous-total, la méthode pdfGetLineTotalDiscountAmount ne doit rien renvoyer + if (!empty($object->lines[$parameters['i']]) && TSubtotal::isModSubtotalLine($object->lines[$parameters['i']])) { + $this->resprints = ''; + $this->results = []; - return 1; - } + return 1; + } - return 0; - } + return 0; + } // HTML 5 data for js - private function _getHtmlData($parameters, &$object, &$action, $hookmanager) + /** + * Get HTML data + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @param HookManager $hookmanager Hook manager + * @return string + */ + private function getHtmlData($parameters, &$object, &$action, $hookmanager) { dol_include_once('/subtotal/class/subtotal.class.php'); - $line = &$parameters['line']; + $line = &$parameters['line']; - $ThtmlData['data-id'] = $line->id; - $ThtmlData['data-product_type'] = $line->product_type; - $ThtmlData['data-qty'] = 0; //$line->qty; - $ThtmlData['data-level'] = TSubtotal::getNiveau($line); + $ThtmlData['data-id'] = $line->id; + $ThtmlData['data-product_type'] = $line->product_type; + $ThtmlData['data-qty'] = 0; //$line->qty; + $ThtmlData['data-level'] = TSubtotal::getNiveau($line); - if(TSubtotal::isTitle($line)){ - $ThtmlData['data-issubtotal'] = 'title'; + if (TSubtotal::isTitle($line)) { + $ThtmlData['data-issubtotal'] = 'title'; $ThtmlData['data-folder-status'] = 'open'; - if(!empty($line->array_options['options_hideblock'])){ + if (!empty($line->array_options['options_hideblock'])) { $ThtmlData['data-folder-status'] = 'closed'; } - }elseif(TSubtotal::isSubtotal($line)){ - $ThtmlData['data-issubtotal'] = 'subtotal'; - } - else{ - $ThtmlData['data-issubtotal'] = 'freetext'; - } - - // Change or add data from hooks - $parameters = array_replace($parameters , array( 'ThtmlData' => $ThtmlData ) ); - - // hook - $reshook = $hookmanager->executeHooks('subtotalLineHtmlData',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - if ($reshook>0) - { - $ThtmlData = $this->results; - } - - return $this->implodeHtmlData($ThtmlData); + } elseif (TSubtotal::isSubtotal($line)) { + $ThtmlData['data-issubtotal'] = 'subtotal'; + } else { + $ThtmlData['data-issubtotal'] = 'freetext'; + } + + // Change or add data from hooks + $parameters = array_replace($parameters, array( 'ThtmlData' => $ThtmlData )); + + // hook + $reshook = $hookmanager->executeHooks('subtotalLineHtmlData', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook>0) { + $ThtmlData = $this->results; + } + return $this->implodeHtmlData($ThtmlData); } - function implodeHtmlData($ThtmlData = array()) + /** + * Implode HTML data + * + * @param array $ThtmlData HTML data + * @return string + */ + public function implodeHtmlData($ThtmlData = array()) { - $data = ''; - foreach($ThtmlData as $k => $h ) - { - if(is_array($h)) - { - $h = json_encode($h); - } - - $data .= $k . '="'.dol_htmlentities($h, ENT_QUOTES).'" '; - } - - return $data; + $data = ''; + foreach ($ThtmlData as $k => $h) { + if (is_array($h)) { + $h = json_encode($h); + } + + $data .= $k . '="'.dol_htmlentities($h, ENT_QUOTES).'" '; + } + + return $data; } - function _ajax_block_order_js($object) + /** + * Ajax block order JS + * + * @param CommonObject $object Object + * @return void + */ + public function ajaxBlockOrderJs($object) { - global $conf,$tagidfortablednd,$filepath,$langs; + global $conf,$tagidfortablednd,$filepath,$langs; - /* - * this part of js is base on dolibarr htdocs/core/tpl/ajaxrow.tpl.php - * for compatibility reasons we don't use tableDnD but jquery sortable - */ - - $id=$object->id; - $nboflines=(isset($object->lines)?count($object->lines):0); - $forcereloadpage=!getDolGlobalString('MAIN_FORCE_RELOAD_PAGE')?0:1; + /* + * this part of js is base on dolibarr htdocs/core/tpl/ajaxrow.tpl.php + * for compatibility reasons we don't use tableDnD but jquery sortable + */ - $id=$object->id; - $fk_element=$object->fk_element; - $table_element_line=$object->table_element_line; - $nboflines=(isset($object->lines)?count($object->lines):(empty($nboflines)?0:$nboflines)); - $tagidfortablednd=(empty($tagidfortablednd)?'tablelines':$tagidfortablednd); - $filepath=(empty($filepath)?'':$filepath); + $id=$object->id; + $nboflines=(isset($object->lines)?count($object->lines):0); + $forcereloadpage=!getDolGlobalString('MAIN_FORCE_RELOAD_PAGE')?0:1; + $id=$object->id; + $fk_element=$object->fk_element; + $table_element_line=$object->table_element_line; + $nboflines=(isset($object->lines)?count($object->lines):(empty($nboflines)?0:$nboflines)); + $tagidfortablednd=(empty($tagidfortablednd)?'tablelines':$tagidfortablednd); + $filepath=(empty($filepath)?'':$filepath); - if (GETPOST('action','aZ09') != 'editline' && $nboflines > 1) - { + if (GETPOST('action', 'aZ09') != 'editline' && $nboflines > 1) { $jsConf = array( 'useOldSplittedTrForLine' => intval(DOL_VERSION) < 16 ? 1 : 0, ); print ''; - ?> + ?> - addline($parameters['TEnt_comm'][$object->order->id], $parameters['line']->id, $parameters['line']->qty); - getDolGlobalString('STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT', $confOld); - } - - } - - } + /** + * Handle expedition title and total + * + * @param array $parameters Parameters + * @param CommonObject $object Object + * @param string $action Action + * @param HookManager $hookmanager Hook manager + * @return void + */ + public function handleExpeditionTitleAndTotal($parameters, &$object, &$action, $hookmanager) + { + global $conf; + //var_dump($parameters['line']); + dol_include_once('subtotal/class/subtotal.class.php'); + $currentcontext = explode(':', $parameters['context']); + + if ( in_array('shippableorderlist', $currentcontext)) { + //var_dump($parameters['line']); + if (TSubtotal::isModSubtotalLine($parameters['line'])) { + $confOld = getDolGlobalString('STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT'); + getDolGlobalString('STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT', 0); + $res = $parameters['shipping']->addline($parameters['TEnt_comm'][$object->order->id], $parameters['line']->id, $parameters['line']->qty); + getDolGlobalString('STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT', $confOld); + } + } + } /** * Overloading the defineColumnField function @@ -4099,18 +4103,20 @@ public function defineColumnField($parameters, &$pdfDoc, &$action, $hookmanager) $parameters['object']->context['subtotalPdfModelInfo']->page_largeur = $pdfDoc->page_largeur; $parameters['object']->context['subtotalPdfModelInfo']->page_hauteur = $pdfDoc->page_hauteur; $parameters['object']->context['subtotalPdfModelInfo']->format = $pdfDoc->format; - if (property_exists($pdfDoc, 'context') && array_key_exists('subtotalPdfModelInfo', $pdfDoc->context) && is_object($pdfDoc->context['subtotalPdfModelInfo'])) { - $parameters['object']->context['subtotalPdfModelInfo']->defaultTitlesFieldsStyle = $pdfDoc->context['subtotalPdfModelInfo']->defaultTitlesFieldsStyle; - $parameters['object']->context['subtotalPdfModelInfo']->defaultContentsFieldsStyle = $pdfDoc->context['subtotalPdfModelInfo']->defaultContentsFieldsStyle; - } + if (property_exists($pdfDoc, 'context') && array_key_exists('subtotalPdfModelInfo', $pdfDoc->context) && is_object($pdfDoc->context['subtotalPdfModelInfo'])) { + $parameters['object']->context['subtotalPdfModelInfo']->defaultTitlesFieldsStyle = $pdfDoc->context['subtotalPdfModelInfo']->defaultTitlesFieldsStyle; + $parameters['object']->context['subtotalPdfModelInfo']->defaultContentsFieldsStyle = $pdfDoc->context['subtotalPdfModelInfo']->defaultContentsFieldsStyle; + } return 0; } /** * Add a checkbox on the bill orders forms (either the old orderstoinvoice or the new mass * action) to create a title block per invoiced order when creating one invoice per client. + * + * @return void */ - private function _billOrdersAddCheckBoxForTitleBlocks() + private function billOrdersAddCheckBoxForTitleBlocks() { global $delayedhtmlcontent, $langs, $conf; @@ -4161,114 +4167,118 @@ private function _billOrdersAddCheckBoxForTitleBlocks() * @param HookManager $hookmanager Hook manager propagated to allow calling another hook * @return int < 0 on error, 0 on success, 1 to replace standard code */ - public function afterCreationOfRecurringInvoice($parameters, &$object, &$action, $hookmanager){ - require_once __DIR__ . '/subtotal.class.php'; - $TSub = new TSubtotal; - $TSub->generateDoc($object); - return 0; - } + public function afterCreationOfRecurringInvoice($parameters, &$object, &$action, $hookmanager) + { + require_once __DIR__ . '/subtotal.class.php'; + $TSub = new TSubtotal; + $TSub->generateDoc($object); + return 0; + } + /** + * Print common footer + * + * @param array $parameters Parameters + * @param CommonObject $objectHook Object hook + * @param string $action Action + * @param HookManager $hookmanager Hook manager + * @return int + */ public function printCommonFooter(&$parameters, &$objectHook, &$action, $hookmanager) { global $langs, $db, $conf; - $contextArray = explode(':',$parameters['context']); + $contextArray = explode(':', $parameters['context']); /**Gestion des dossiers qui permettent de réduire un bloc**/ - if ( - in_array('invoicecard',$contextArray) - || in_array('invoicesuppliercard',$contextArray) - || in_array('propalcard',$contextArray) - || in_array('ordercard',$contextArray) - || in_array('ordersuppliercard',$contextArray) - || in_array('invoicereccard',$contextArray) - ) - { - //On récupère les informations de l'objet actuel - $id = GETPOST('id', 'int'); - if(empty($id)) $id = GETPOST('facid', 'int'); - - //On détermine l'élement concernée en fonction du contexte - $TCurrentContexts = explode('card', $parameters['currentcontext']); - /** - * TODO John le 11/08/2023 : Je trouve bizarre d'utiliser le contexte pour déterminer la class de l'objet alors - * que l'objet est passé en paramètres ça doit être due à de vielle versions de Dolibarr ou une compat avec un module externe... - * Cette methode de chargement d'objet a causée une fatale car la classe de l'objet correspondant au contexte n'était pas chargé ce qui n'est pas logique... - * La logique voudrait que l'on utilise $object->element - * Cependant si on regarde plus loin $object qui est passé en référence dans les paramètres de cette méthode est remplacé quelques lignes plus bas. - */ - if($TCurrentContexts[0] == 'order'){ - $element = 'Commande'; - if(!class_exists($element)){ require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';} - } - elseif($TCurrentContexts[0] == 'invoice'){ - $element = 'Facture'; - if(!class_exists($element)){ require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';} - } - elseif($TCurrentContexts[0] == 'invoicesupplier'){ - $element = 'FactureFournisseur'; - if(!class_exists($element)){ require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';} - } - elseif($TCurrentContexts[0] == 'ordersupplier'){ - $element = 'CommandeFournisseur'; - if(!class_exists($element)){ require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';} - } - elseif($TCurrentContexts[0] == 'invoicerec'){ - $element = 'FactureRec'; - if(!class_exists($element)){ require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture-rec.class.php';} - } - else $element = $TCurrentContexts[0]; - - - if(!class_exists($element)){ - // Pour éviter la fatale sur une page d'un module externe qui utiliserait un nom de context de Dolibarr mais qui - $this->error = $langs->trans('ErrorClassXNotExists', $element); - return -1; - } + if ( + in_array('invoicecard', $contextArray) + || in_array('invoicesuppliercard', $contextArray) + || in_array('propalcard', $contextArray) + || in_array('ordercard', $contextArray) + || in_array('ordersuppliercard', $contextArray) + || in_array('invoicereccard', $contextArray) + ) { + //On récupère les informations de l'objet actuel + $id = GETPOST('id', 'int'); + if (empty($id)) $id = GETPOST('facid', 'int'); + + //On détermine l'élement concernée en fonction du contexte + $TCurrentContexts = explode('card', $parameters['currentcontext']); + /** + * TODO John le 11/08/2023 : Je trouve bizarre d'utiliser le contexte pour déterminer la class de l'objet alors + * que l'objet est passé en paramètres ça doit être due à de vielle versions de Dolibarr ou une compat avec un module externe... + * Cette methode de chargement d'objet a causée une fatale car la classe de l'objet correspondant au contexte n'était pas chargé ce qui n'est pas logique... + * La logique voudrait que l'on utilise $object->element + * Cependant si on regarde plus loin $object qui est passé en référence dans les paramètres de cette méthode est remplacé quelques lignes plus bas. + */ + if ($TCurrentContexts[0] == 'order') { + $element = 'Commande'; + if (!class_exists($element)) { require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';} + } elseif ($TCurrentContexts[0] == 'invoice') { + $element = 'Facture'; + if (!class_exists($element)) { require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';} + } elseif ($TCurrentContexts[0] == 'invoicesupplier') { + $element = 'FactureFournisseur'; + if (!class_exists($element)) { require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';} + } elseif ($TCurrentContexts[0] == 'ordersupplier') { + $element = 'CommandeFournisseur'; + if (!class_exists($element)) { require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';} + } elseif ($TCurrentContexts[0] == 'invoicerec') { + $element = 'FactureRec'; + if (!class_exists($element)) { require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture-rec.class.php';} + } else $element = $TCurrentContexts[0]; + + + if (!class_exists($element)) { + // Pour éviter la fatale sur une page d'un module externe qui utiliserait un nom de context de Dolibarr mais qui + $this->error = $langs->trans('ErrorClassXNotExists', $element); + return -1; + } - $object = new $element($db); - $object->fetch($id); + $object = new $element($db); + $object->fetch($id); - //On récupère tous les titres sous-total - $TLines = TSubtotal::getAllTitleFromDocument($object); + //On récupère tous les titres sous-total + $TLines = TSubtotal::getAllTitleFromDocument($object); - //On définit quels sont les blocs à cacher en fonction des données existantes (hideblock) + //On définit quels sont les blocs à cacher en fonction des données existantes (hideblock) $TBlocksToHide = array(); - if(!empty($TLines)) { - foreach ($TLines as $line) { - if (array_key_exists('options_hideblock', $line->array_options) && $line->array_options['options_hideblock']) $TBlocksToHide[] = $line->id; - } + if (!empty($TLines)) { + foreach ($TLines as $line) { + if (array_key_exists('options_hideblock', $line->array_options) && $line->array_options['options_hideblock']) $TBlocksToHide[] = $line->id; } + } - $hideMode = getDolGlobalString('SUBTOTAL_BLOC_FOLD_MODE', 'default'); - if(!in_array($hideMode, array('default', 'keepTitle'))){ - $hideMode = 'default'; - } + $hideMode = getDolGlobalString('SUBTOTAL_BLOC_FOLD_MODE', 'default'); + if (!in_array($hideMode, array('default', 'keepTitle'))) { + $hideMode = 'default'; + } - $jsConf = array( - 'linesToHide' => $TBlocksToHide, - 'hideFoldersByDefault' => getDolGlobalInt('SUBTOTAL_HIDE_FOLDERS_BY_DEFAULT'), - 'closeMode' => $hideMode, // default, keepTitle - 'interfaceUrl'=> dol_buildpath('/subtotal/script/interface.php', 1), - 'element' => $element, - 'element_id' => $id, - 'img_folder_closed' => img_picto('', 'folder'), - 'img_folder_open' => img_picto('', 'folder-open'), - 'langs' => array( - 'Subtotal_HideAll' => $langs->transnoentities("Subtotal_HideAll"), - 'Subtotal_ShowAll' => $langs->transnoentities("Subtotal_ShowAll"), - 'Subtotal_Hide' => $langs->transnoentities("Subtotal_Hide"), - 'Subtotal_Show' => $langs->transnoentities("Subtotal_Show"), - 'Subtotal_ForceHideAll' => $langs->transnoentities("Subtotal_ForceHideAll"), - 'Subtotal_ForceShowAll' => $langs->transnoentities("Subtotal_ForceShowAll") - ) - ); + $jsConf = array( + 'linesToHide' => $TBlocksToHide, + 'hideFoldersByDefault' => getDolGlobalInt('SUBTOTAL_HIDE_FOLDERS_BY_DEFAULT'), + 'closeMode' => $hideMode, // default, keepTitle + 'interfaceUrl'=> dol_buildpath('/subtotal/script/interface.php', 1), + 'element' => $element, + 'element_id' => $id, + 'img_folder_closed' => img_picto('', 'folder'), + 'img_folder_open' => img_picto('', 'folder-open'), + 'langs' => array( + 'Subtotal_HideAll' => $langs->transnoentities("Subtotal_HideAll"), + 'Subtotal_ShowAll' => $langs->transnoentities("Subtotal_ShowAll"), + 'Subtotal_Hide' => $langs->transnoentities("Subtotal_Hide"), + 'Subtotal_Show' => $langs->transnoentities("Subtotal_Show"), + 'Subtotal_ForceHideAll' => $langs->transnoentities("Subtotal_ForceHideAll"), + 'Subtotal_ForceShowAll' => $langs->transnoentities("Subtotal_ForceShowAll") + ) + ); - print ''; + print ''; - ?> + ?>