PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/modules/product/modules_product.class.php

https://bitbucket.org/speedealing/speedealing
PHP | 213 lines | 120 code | 19 blank | 74 comment | 48 complexity | 7451cc460aad42f1b57a4c96c9f65262 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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@capnetworks.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 <http://www.gnu.org/licenses/>.
  19. * or see http://www.gnu.org/
  20. */
  21. /**
  22. * \class ModeleProductCode
  23. * \brief Parent class for product code generators
  24. */
  25. abstract class ModeleProductCode
  26. {
  27. var $error='';
  28. /** Renvoi la description par defaut du modele de numerotation
  29. *
  30. * @param Translate $langs Object langs
  31. * @return string Texte descripif
  32. */
  33. function info($langs)
  34. {
  35. $langs->load("bills");
  36. return $langs->trans("NoDescription");
  37. }
  38. /** Renvoi nom module
  39. *
  40. * @param Translate $langs Object langs
  41. * @return string Nom du module
  42. */
  43. function getNom($langs)
  44. {
  45. return $this->nom;
  46. }
  47. /** Renvoi un exemple de numerotation
  48. *
  49. * @param Translate $langs Object langs
  50. * @return string Example
  51. */
  52. function getExample($langs)
  53. {
  54. $langs->load("bills");
  55. return $langs->trans("NoExample");
  56. }
  57. /** Test si les numeros deja en vigueur dans la base ne provoquent pas de
  58. * de conflits qui empechera cette numerotation de fonctionner.
  59. *
  60. * @return boolean false si conflit, true si ok
  61. */
  62. function canBeActivated()
  63. {
  64. return true;
  65. }
  66. /**
  67. * Return next value available
  68. *
  69. * @param Product $objproduct Object product
  70. * @param int $type Type
  71. * @return string Value
  72. */
  73. function getNextValue($objproduct=0,$type=-1)
  74. {
  75. global $langs;
  76. return $langs->trans("Function_getNextValue_InModuleNotWorking");
  77. }
  78. /** Return version of module
  79. *
  80. * @return string Version
  81. */
  82. function getVersion()
  83. {
  84. global $langs;
  85. $langs->load("admin");
  86. if ($this->version == 'development') return $langs->trans("VersionDevelopment");
  87. if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
  88. if ($this->version == 'dolibarr') return DOL_VERSION;
  89. return $langs->trans("NotAvailable");
  90. }
  91. /**
  92. * Renvoi la liste des modeles de numérotation
  93. *
  94. * @param DoliDB $db Database handler
  95. * @param string $maxfilenamelength Max length of value to show
  96. * @return array List of numbers
  97. */
  98. static function liste_modeles($db,$maxfilenamelength=0)
  99. {
  100. $liste=array();
  101. $sql ="";
  102. $resql = $db->query($sql);
  103. if ($resql)
  104. {
  105. $num = $db->num_rows($resql);
  106. $i = 0;
  107. while ($i < $num)
  108. {
  109. $row = $db->fetch_row($resql);
  110. $liste[$row[0]]=$row[1];
  111. $i++;
  112. }
  113. }
  114. else
  115. {
  116. return -1;
  117. }
  118. return $liste;
  119. }
  120. /**
  121. * Return description of module parameters
  122. *
  123. * @param Translate $langs Output language
  124. * @param Product $product Product object
  125. * @param int $type -1=Nothing, 0=Customer, 1=Supplier
  126. * @return string HTML translated description
  127. */
  128. function getToolTip($langs,$product,$type)
  129. {
  130. global $conf;
  131. $langs->load("admin");
  132. $s='';
  133. if ($type == -1) $s.=$langs->trans("Name").': <b>'.$this->nom.'</b><br>';
  134. if ($type == -1) $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
  135. if ($type == 0) $s.=$langs->trans("ProductCodeDesc").'<br>';
  136. if ($type == 1) $s.=$langs->trans("ServiceCodeDesc").'<br>';
  137. if ($type != -1) $s.=$langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
  138. $s.='<br>';
  139. $s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
  140. if ($type == 0)
  141. {
  142. $s.=$langs->trans("RequiredIfProduct").': ';
  143. if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>';
  144. $s.=yn(!$this->code_null,1,2);
  145. if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
  146. $s.='<br>';
  147. }
  148. if ($type == 1)
  149. {
  150. $s.=$langs->trans("RequiredIfService").': ';
  151. if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>';
  152. $s.=yn(!$this->code_null,1,2);
  153. if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
  154. $s.='<br>';
  155. }
  156. if ($type == -1)
  157. {
  158. $s.=$langs->trans("Required").': ';
  159. if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>';
  160. $s.=yn(!$this->code_null,1,2);
  161. if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')';
  162. $s.='<br>';
  163. }
  164. $s.=$langs->trans("CanBeModifiedIfOk").': ';
  165. $s.=yn($this->code_modifiable,1,2);
  166. $s.='<br>';
  167. $s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide,1,2).'<br>';
  168. $s.=$langs->trans("AutomaticCode").': '.yn($this->code_auto,1,2).'<br>';
  169. $s.='<br>';
  170. if ($type == 0 || $type == -1)
  171. {
  172. $nextval=$this->getNextValue($product,0);
  173. if (empty($nextval)) $nextval=$langs->trans("Undefined");
  174. $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Product").')':'').': <b>'.$nextval.'</b><br>';
  175. }
  176. if ($type == 1 || $type == -1)
  177. {
  178. $nextval=$this->getNextValue($product,1);
  179. if (empty($nextval)) $nextval=$langs->trans("Undefined");
  180. $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Service").')':'').': <b>'.$nextval.'</b>';
  181. }
  182. return $s;
  183. }
  184. /**
  185. * Check if mask/numbering use prefix
  186. *
  187. * @return int 0=no, 1=yes
  188. */
  189. function verif_prefixIsUsed()
  190. {
  191. return 0;
  192. }
  193. }
  194. ?>