1<?php 2/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net> 4 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> 5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <https://www.gnu.org/licenses/>. 19 * or see https://www.gnu.org/ 20 */ 21 22 23/** 24 * \file htdocs/core/modules/product/modules_product.class.php 25 * \ingroup contract 26 * \brief File with parent class for generating products to PDF and File of class to manage product numbering 27 */ 28 29 require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php'; 30 31/** 32 * Parent class to manage intervention document templates 33 */ 34abstract class ModelePDFProduct extends CommonDocGenerator 35{ 36 /** 37 * @var string Error code (or message) 38 */ 39 public $error = ''; 40 41 42 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps 43 /** 44 * Return list of active generation modules 45 * 46 * @param DoliDB $db Database handler 47 * @param integer $maxfilenamelength Max length of value to show 48 * @return array List of templates 49 */ 50 public static function liste_modeles($db, $maxfilenamelength = 0) 51 { 52 // phpcs:enable 53 global $conf; 54 55 $type = 'product'; 56 $list = array(); 57 58 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; 59 $list = getListOfModels($db, $type, $maxfilenamelength); 60 return $list; 61 } 62} 63 64/** 65 * Class template for classes of numbering product 66 */ 67abstract class ModeleProductCode 68{ 69 /** 70 * @var string Error code (or message) 71 */ 72 public $error = ''; 73 74 /** Renvoi la description par defaut du modele de numerotation 75 * 76 * @param Translate $langs Object langs 77 * @return string Texte descripif 78 */ 79 public function info($langs) 80 { 81 $langs->load("bills"); 82 return $langs->trans("NoDescription"); 83 } 84 85 /** Renvoi nom module 86 * 87 * @param Translate $langs Object langs 88 * @return string Nom du module 89 */ 90 public function getNom($langs) 91 { 92 return empty($this->name) ? $this->nom : $this->name; 93 } 94 95 96 /** Return an example of numbering 97 * 98 * @param Translate $langs Object langs 99 * @return string Example 100 */ 101 public function getExample($langs) 102 { 103 return $langs->trans("NoExample"); 104 } 105 106 /** 107 * Checks if the numbers already in the database do not 108 * cause conflicts that would prevent this numbering working. 109 * 110 * @return boolean false if conflict, true if ok 111 */ 112 public function canBeActivated() 113 { 114 return true; 115 } 116 117 /** 118 * Return next value available 119 * 120 * @param Product $objproduct Object product 121 * @param int $type Type 122 * @return string Value 123 */ 124 public function getNextValue($objproduct = 0, $type = -1) 125 { 126 global $langs; 127 return $langs->trans("Function_getNextValue_InModuleNotWorking"); 128 } 129 130 131 /** Return version of module 132 * 133 * @return string Version 134 */ 135 public function getVersion() 136 { 137 global $langs; 138 $langs->load("admin"); 139 140 if ($this->version == 'development') { 141 return $langs->trans("VersionDevelopment"); 142 } 143 if ($this->version == 'experimental') { 144 return $langs->trans("VersionExperimental"); 145 } 146 if ($this->version == 'dolibarr') { 147 return DOL_VERSION; 148 } 149 if ($this->version) { 150 return $this->version; 151 } 152 return $langs->trans("NotAvailable"); 153 } 154 155 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps 156 /** 157 * Renvoi la liste des modeles de numérotation 158 * 159 * @param DoliDB $db Database handler 160 * @param integer $maxfilenamelength Max length of value to show 161 * @return array List of numbers 162 */ 163 public static function liste_modeles($db, $maxfilenamelength = 0) 164 { 165 // phpcs:enable 166 $list = array(); 167 $sql = ""; 168 169 $resql = $db->query($sql); 170 if ($resql) { 171 $num = $db->num_rows($resql); 172 $i = 0; 173 while ($i < $num) { 174 $row = $db->fetch_row($resql); 175 $list[$row[0]] = $row[1]; 176 $i++; 177 } 178 } else { 179 return -1; 180 } 181 return $list; 182 } 183 184 /** 185 * Return description of module parameters 186 * 187 * @param Translate $langs Output language 188 * @param Product $product Product object 189 * @param int $type -1=Nothing, 0=Customer, 1=Supplier 190 * @return string HTML translated description 191 */ 192 public function getToolTip($langs, $product, $type) 193 { 194 global $conf; 195 196 $langs->loadLangs(array("admin", "companies")); 197 198 $strikestart = ''; 199 $strikeend = ''; 200 if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) { 201 $strikestart = '<strike>'; 202 $strikeend = '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; 203 } 204 $s = ''; 205 if ($type == -1) { 206 $s .= $langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>'; 207 $s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>'; 208 } elseif ($type == 0) { 209 $s .= $langs->trans("ProductCodeDesc").'<br>'; 210 } elseif ($type == 1) { 211 $s .= $langs->trans("ServiceCodeDesc").'<br>'; 212 } 213 if ($type != -1) { 214 $s .= $langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>'; 215 } 216 $s .= '<br>'; 217 $s .= '<u>'.$langs->trans("ThisIsModuleRules").':</u><br>'; 218 if ($type == 0) { 219 $s .= $langs->trans("RequiredIfProduct").': '.$strikestart; 220 $s .= yn(!$this->code_null, 1, 2).$strikeend; 221 $s .= '<br>'; 222 } elseif ($type == 1) { 223 $s .= $langs->trans("RequiredIfService").': '.$strikestart; 224 $s .= yn(!$this->code_null, 1, 2).$strikeend; 225 $s .= '<br>'; 226 } elseif ($type == -1) { 227 $s .= $langs->trans("Required").': '.$strikestart; 228 $s .= yn(!$this->code_null, 1, 2).$strikeend; 229 $s .= '<br>'; 230 } 231 $s .= $langs->trans("CanBeModifiedIfOk").': '; 232 $s .= yn($this->code_modifiable, 1, 2); 233 $s .= '<br>'; 234 $s .= $langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide, 1, 2).'<br>'; 235 $s .= $langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'<br>'; 236 $s .= '<br>'; 237 if ($type == 0 || $type == -1) { 238 $nextval = $this->getNextValue($product, 0); 239 if (empty($nextval)) { 240 $nextval = $langs->trans("Undefined"); 241 } 242 $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Product").')' : '').': <b>'.$nextval.'</b><br>'; 243 } 244 if ($type == 1 || $type == -1) { 245 $nextval = $this->getNextValue($product, 1); 246 if (empty($nextval)) { 247 $nextval = $langs->trans("Undefined"); 248 } 249 $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Service").')' : '').': <b>'.$nextval.'</b>'; 250 } 251 return $s; 252 } 253 254 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps 255 /** 256 * Check if mask/numbering use prefix 257 * 258 * @return int 0=no, 1=yes 259 */ 260 public function verif_prefixIsUsed() 261 { 262 // phpcs:enable 263 return 0; 264 } 265} 266