mod_codeclient_leopard.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. * or see https://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/modules/societe/mod_codeclient_leopard.php
  21. * \ingroup societe
  22. * \brief Fichier de la classe des gestion leopard des codes clients
  23. */
  24. require_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
  25. /**
  26. * Class to manage numbering of thirdparties code
  27. */
  28. class mod_codeclient_leopard extends ModeleThirdPartyCode
  29. {
  30. /*
  31. * Attention ce module est utilise par defaut si aucun module n'a
  32. * ete definit dans la configuration
  33. *
  34. * Le fonctionnement de celui-ci doit donc rester le plus ouvert possible
  35. */
  36. /**
  37. * @var string model name
  38. */
  39. public $name = 'Leopard';
  40. public $code_modifiable; // Code modifiable
  41. public $code_modifiable_invalide; // Code modifiable si il est invalide
  42. public $code_modifiable_null; // Code modifiables si il est null
  43. public $code_null; // Code facultatif
  44. /**
  45. * Dolibarr version of the loaded document
  46. * @var string
  47. */
  48. public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
  49. /**
  50. * @var int Automatic numbering
  51. */
  52. public $code_auto;
  53. /**
  54. * Constructor
  55. */
  56. public function __construct()
  57. {
  58. $this->code_null = 1;
  59. $this->code_modifiable = 1;
  60. $this->code_modifiable_invalide = 1;
  61. $this->code_modifiable_null = 1;
  62. $this->code_auto = 0;
  63. }
  64. /**
  65. * Return description of module
  66. *
  67. * @param Translate $langs Object langs
  68. * @return string Description of module
  69. */
  70. public function info($langs)
  71. {
  72. $langs->load("companies");
  73. return $langs->trans("LeopardNumRefModelDesc");
  74. }
  75. /**
  76. * Return an example of result returned by getNextValue
  77. *
  78. * @param societe $objsoc Object thirdparty
  79. * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect)
  80. * @return string Return next value
  81. */
  82. public function getNextValue($objsoc = 0, $type = -1)
  83. {
  84. global $langs;
  85. return '';
  86. }
  87. /**
  88. * Check validity of code according to its rules
  89. *
  90. * @param DoliDB $db Database handler
  91. * @param string $code Code to check/correct
  92. * @param Societe $soc Object third party
  93. * @param int $type 0 = customer/prospect , 1 = supplier
  94. * @return int 0 if OK
  95. * -1 ErrorBadCustomerCodeSyntax
  96. * -2 ErrorCustomerCodeRequired
  97. * -3 ErrorCustomerCodeAlreadyUsed
  98. * -4 ErrorPrefixRequired
  99. */
  100. public function verif($db, &$code, $soc, $type)
  101. {
  102. global $conf;
  103. $result = 0;
  104. $code = trim($code);
  105. if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) {
  106. $result = 0;
  107. } elseif (empty($code) && (!$this->code_null || !empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))) {
  108. $result = -2;
  109. }
  110. dol_syslog(get_class($this)."::verif type=".$type." result=".$result);
  111. return $result;
  112. }
  113. }