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 * \file htdocs/core/modules/societe/modules_societe.class.php 24 * \ingroup societe 25 * \brief File with parent class of submodules to manage numbering and document generation 26 */ 27require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php'; 28 29 30/** 31 * Parent class for third parties models of doc generators 32 */ 33abstract class ModeleThirdPartyDoc extends CommonDocGenerator 34{ 35 /** 36 * @var string Error code (or message) 37 */ 38 public $error = ''; 39 40 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps 41 /** 42 * Return list of active generation modules 43 * 44 * @param DoliDB $db Database handler 45 * @param integer $maxfilenamelength Max length of value to show 46 * @return array List of templates 47 */ 48 public static function liste_modeles($db, $maxfilenamelength = 0) 49 { 50 // phpcs:enable 51 global $conf; 52 53 $type = 'company'; 54 $list = array(); 55 56 include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; 57 $list = getListOfModels($db, $type, $maxfilenamelength); 58 59 return $list; 60 } 61} 62 63/** 64 * Parent class for third parties code generators 65 */ 66abstract class ModeleThirdPartyCode 67{ 68 /** 69 * @var string Error code (or message) 70 */ 71 public $error = ''; 72 73 /** 74 * @var array Error code (or message) array 75 */ 76 public $errors; 77 78 79 /** Renvoi la description par defaut du modele de numerotation 80 * 81 * @param Translate $langs Object langs 82 * @return string Texte descripif 83 */ 84 public function info($langs) 85 { 86 $langs->load("bills"); 87 return $langs->trans("NoDescription"); 88 } 89 90 /** Return name of module 91 * 92 * @param Translate $langs Object langs 93 * @return string Nom du module 94 */ 95 public function getNom($langs) 96 { 97 return $this->name; 98 } 99 100 101 /** Return an example of numbering 102 * 103 * @param Translate $langs Object langs 104 * @return string Example 105 */ 106 public function getExample($langs) 107 { 108 $langs->load("bills"); 109 return $langs->trans("NoExample"); 110 } 111 112 /** 113 * Checks if the numbers already in the database do not 114 * cause conflicts that would prevent this numbering working. 115 * 116 * @return boolean false if conflict, true if ok 117 */ 118 public function canBeActivated() 119 { 120 return true; 121 } 122 123 /** 124 * Return next value available 125 * 126 * @param Societe $objsoc Object thirdparty 127 * @param int $type Type 128 * @return string Value 129 */ 130 public function getNextValue($objsoc = 0, $type = -1) 131 { 132 global $langs; 133 return $langs->trans("Function_getNextValue_InModuleNotWorking"); 134 } 135 136 137 /** 138 * Return version of module 139 * 140 * @return string Version 141 */ 142 public function getVersion() 143 { 144 global $langs; 145 $langs->load("admin"); 146 147 if ($this->version == 'development') { 148 return $langs->trans("VersionDevelopment"); 149 } elseif ($this->version == 'experimental') { 150 return $langs->trans("VersionExperimental"); 151 } elseif ($this->version == 'dolibarr') { 152 return DOL_VERSION; 153 } elseif ($this->version) { 154 return $this->version; 155 } else { 156 return $langs->trans("NotAvailable"); 157 } 158 } 159 160 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps 161 /** 162 * Renvoie la liste des modeles de numérotation 163 * 164 * @param DoliDB $db Database handler 165 * @param integer $maxfilenamelength Max length of value to show 166 * @return array|int List of numbers 167 */ 168 public static function liste_modeles($db, $maxfilenamelength = 0) 169 { 170 // phpcs:enable 171 $list = array(); 172 $sql = ""; 173 174 $resql = $db->query($sql); 175 if ($resql) { 176 $num = $db->num_rows($resql); 177 $i = 0; 178 while ($i < $num) { 179 $row = $db->fetch_row($resql); 180 $list[$row[0]] = $row[1]; 181 $i++; 182 } 183 } else { 184 return -1; 185 } 186 return $list; 187 } 188 189 /** 190 * Return description of module parameters 191 * 192 * @param Translate $langs Output language 193 * @param Societe $soc Third party object 194 * @param int $type -1=Nothing, 0=Customer, 1=Supplier 195 * @return string HTML translated description 196 */ 197 public function getToolTip($langs, $soc, $type) 198 { 199 global $conf; 200 201 $langs->loadLangs(array("admin", "companies")); 202 203 $strikestart = ''; 204 $strikeend = ''; 205 if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) { 206 $strikestart = '<strike>'; 207 $strikeend = '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; 208 } 209 210 $s = ''; 211 if ($type == -1) { 212 $s .= $langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>'; 213 } elseif ($type == -1) { 214 $s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>'; 215 } elseif ($type == 0) { 216 $s .= $langs->trans("CustomerCodeDesc").'<br>'; 217 } elseif ($type == 1) { 218 $s .= $langs->trans("SupplierCodeDesc").'<br>'; 219 } 220 if ($type != -1) { 221 $s .= $langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>'; 222 } 223 $s .= '<br>'; 224 $s .= '<u>'.$langs->trans("ThisIsModuleRules").':</u><br>'; 225 if ($type == 0) { 226 $s .= $langs->trans("RequiredIfCustomer").': '.$strikestart; 227 $s .= yn(!$this->code_null, 1, 2).$strikeend; 228 $s .= '<br>'; 229 } elseif ($type == 1) { 230 $s .= $langs->trans("RequiredIfSupplier").': '.$strikestart; 231 $s .= yn(!$this->code_null, 1, 2).$strikeend; 232 $s .= '<br>'; 233 } elseif ($type == -1) { 234 $s .= $langs->trans("Required").': '.$strikestart; 235 $s .= yn(!$this->code_null, 1, 2).$strikeend; 236 $s .= '<br>'; 237 } 238 $s .= $langs->trans("CanBeModifiedIfOk").': '; 239 $s .= yn($this->code_modifiable, 1, 2); 240 $s .= '<br>'; 241 $s .= $langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide, 1, 2).'<br>'; 242 $s .= $langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'<br>'; 243 $s .= '<br>'; 244 if ($type == 0 || $type == -1) { 245 $nextval = $this->getNextValue($soc, 0); 246 if (empty($nextval)) { 247 $nextval = $langs->trans("Undefined"); 248 } 249 $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Customer").')' : '').': <b>'.$nextval.'</b><br>'; 250 } 251 if ($type == 1 || $type == -1) { 252 $nextval = $this->getNextValue($soc, 1); 253 if (empty($nextval)) { 254 $nextval = $langs->trans("Undefined"); 255 } 256 $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Supplier").')' : '').': <b>'.$nextval.'</b>'; 257 } 258 return $s; 259 } 260 261 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps 262 /** 263 * Check if mask/numbering use prefix 264 * 265 * @return int 0=no, 1=yes 266 */ 267 public function verif_prefixIsUsed() 268 { 269 // phpcs:enable 270 return 0; 271 } 272} 273 274 275/** 276 * Parent class for third parties accountancy code generators 277 */ 278abstract class ModeleAccountancyCode 279{ 280 /** 281 * @var string Error code (or message) 282 */ 283 public $error = ''; 284 285 286 /** 287 * Return description of module 288 * 289 * @param Translate $langs Object langs 290 * @return string Description of module 291 */ 292 public function info($langs) 293 { 294 $langs->load("bills"); 295 return $langs->trans("NoDescription"); 296 } 297 298 /** 299 * Return an example of result returned by getNextValue 300 * 301 * @param Translate $langs Object langs 302 * @param societe $objsoc Object thirdparty 303 * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) 304 * @return string Example 305 */ 306 public function getExample($langs, $objsoc = 0, $type = -1) 307 { 308 $langs->load("bills"); 309 return $langs->trans("NoExample"); 310 } 311 312 /** 313 * Checks if the numbers already in the database do not 314 * cause conflicts that would prevent this numbering working. 315 * 316 * @return boolean false if conflict, true if ok 317 */ 318 public function canBeActivated() 319 { 320 return true; 321 } 322 323 /** 324 * Return version of module 325 * 326 * @return string Version 327 */ 328 public function getVersion() 329 { 330 global $langs; 331 $langs->load("admin"); 332 333 if ($this->version == 'development') { 334 return $langs->trans("VersionDevelopment"); 335 } elseif ($this->version == 'experimental') { 336 return $langs->trans("VersionExperimental"); 337 } elseif ($this->version == 'dolibarr') { 338 return DOL_VERSION; 339 } elseif ($this->version) { 340 return $this->version; 341 } else { 342 return $langs->trans("NotAvailable"); 343 } 344 } 345 346 /** 347 * Return description of module parameters 348 * 349 * @param Translate $langs Output language 350 * @param Societe $soc Third party object 351 * @param int $type -1=Nothing, 0=Customer, 1=Supplier 352 * @return string HTML translated description 353 */ 354 public function getToolTip($langs, $soc, $type) 355 { 356 global $conf, $db; 357 358 $langs->load("admin"); 359 360 $s = ''; 361 if ($type == -1) { 362 $s .= $langs->trans("Name").': <b>'.$this->name.'</b><br>'; 363 $s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>'; 364 } 365 //$s.='<br>'; 366 //$s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>'; 367 $s .= '<br>'; 368 if ($type == 0 || $type == -1) { 369 $result = $this->get_code($db, $soc, 'customer'); 370 $nextval = $this->code; 371 if (empty($nextval)) { 372 $nextval = $langs->trans("Undefined"); 373 } 374 $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Customer").')' : '').': <b>'.$nextval.'</b><br>'; 375 } 376 if ($type == 1 || $type == -1) { 377 $result = $this->get_code($db, $soc, 'supplier'); 378 $nextval = $this->code; 379 if (empty($nextval)) { 380 $nextval = $langs->trans("Undefined"); 381 } 382 $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Supplier").')' : '').': <b>'.$nextval.'</b>'; 383 } 384 return $s; 385 } 386 387 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps 388 /** 389 * Set accountancy account code for a third party into this->code 390 * 391 * @param DoliDB $db Database handler 392 * @param Societe $societe Third party object 393 * @param int $type 'customer' or 'supplier' 394 * @return int >=0 if OK, <0 if KO 395 */ 396 public function get_code($db, $societe, $type = '') 397 { 398 // phpcs:enable 399 global $langs; 400 401 return $langs->trans("NotAvailable"); 402 } 403} 404 405 406/** 407 * Create a document onto disk according to template module. 408 * 409 * @param DoliDB $db Database handler 410 * @param Facture $object Object invoice 411 * @param string $message Message (not used, deprecated) 412 * @param string $modele Force template to use ('' to not force) 413 * @param Translate $outputlangs objet lang a utiliser pour traduction 414 * @param int $hidedetails Hide details of lines 415 * @param int $hidedesc Hide description 416 * @param int $hideref Hide ref 417 * @return int <0 if KO, >0 if OK 418 * @deprecated Use the new function generateDocument of Objects class 419 * @see Societe::generateDocument() 420 */ 421function thirdparty_doc_create(DoliDB $db, Societe $object, $message, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0) 422{ 423 dol_syslog(__METHOD__." is deprecated", LOG_WARNING); 424 425 return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref); 426} 427