modules_barcode.class.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. /* Copyright (C) 2014 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. * or see https://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/modules/barcode/modules_barcode.class.php
  20. * \ingroup barcode
  21. * \brief File with parent classes for barcode document modules and numbering modules
  22. */
  23. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  24. /**
  25. * Parent class for barcode document models
  26. */
  27. abstract class ModeleBarCode
  28. {
  29. /**
  30. * @var string Error code (or message)
  31. */
  32. public $error = '';
  33. /**
  34. * Return if a model can be used or not
  35. *
  36. * @return boolean true if model can be used
  37. */
  38. public function isEnabled()
  39. {
  40. return true;
  41. }
  42. }
  43. /**
  44. * Parent class for barcode numbering models
  45. */
  46. abstract class ModeleNumRefBarCode
  47. {
  48. /**
  49. * @var string Error code (or message)
  50. */
  51. public $error = '';
  52. /** Return default description of numbering model
  53. *
  54. * @param Translate $langs Object langs
  55. * @return string Descriptive text
  56. */
  57. public function info($langs)
  58. {
  59. $langs->load("bills");
  60. return $langs->trans("NoDescription");
  61. }
  62. /** Return model name
  63. *
  64. * @param Translate $langs Object langs
  65. * @return string Model name
  66. */
  67. public function getNom($langs)
  68. {
  69. return empty($this->name) ? get_class($this) : $this->name;
  70. }
  71. /** Return a numbering example
  72. *
  73. * @param Translate $langs Object langs
  74. * @return string Example
  75. */
  76. public function getExample($langs)
  77. {
  78. $langs->load("bills");
  79. return $langs->trans("NoExample");
  80. }
  81. /**
  82. * Return next value available
  83. *
  84. * @param Product $objproduct Object Product
  85. * @param string $type Type of barcode (EAN, ISBN, ...)
  86. * @return string Value
  87. */
  88. public function getNextValue($objproduct, $type = '')
  89. {
  90. global $langs;
  91. return $langs->trans("Function_getNextValue_InModuleNotWorking");
  92. }
  93. /** Return version of module
  94. *
  95. * @return string Version
  96. */
  97. public function getVersion()
  98. {
  99. global $langs;
  100. $langs->load("admin");
  101. if ($this->version == 'development') {
  102. return $langs->trans("VersionDevelopment");
  103. }
  104. if ($this->version == 'experimental') {
  105. return $langs->trans("VersionExperimental");
  106. }
  107. if ($this->version == 'dolibarr') {
  108. return DOL_VERSION;
  109. }
  110. if ($this->version) {
  111. return $this->version;
  112. }
  113. return $langs->trans("NotAvailable");
  114. }
  115. /**
  116. * Return description of module parameters
  117. *
  118. * @param Translate $langs Output language
  119. * @param Societe $soc Third party object
  120. * @param int $type -1=Nothing, 0=Product, 1=Service
  121. * @return string HTML translated description
  122. */
  123. public function getToolTip($langs, $soc, $type)
  124. {
  125. global $conf;
  126. $langs->loadLangs(array("admin", "companies"));
  127. $s = '';
  128. $s .= $langs->trans("Name").': <b>'.$this->name.'</b><br>';
  129. $s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
  130. if ($type != -1) {
  131. $s .= $langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
  132. }
  133. $s .= '<br>';
  134. $s .= '<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
  135. if ($type == 0) {
  136. $s .= $langs->trans("RequiredIfProduct").': ';
  137. if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
  138. $s .= '<strike>';
  139. }
  140. $s .= yn(!$this->code_null, 1, 2);
  141. if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
  142. $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
  143. }
  144. $s .= '<br>';
  145. }
  146. if ($type == 1) {
  147. $s .= $langs->trans("RequiredIfService").': ';
  148. if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
  149. $s .= '<strike>';
  150. }
  151. $s .= yn(!$this->code_null, 1, 2);
  152. if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
  153. $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
  154. }
  155. $s .= '<br>';
  156. }
  157. if ($type == -1) {
  158. $s .= $langs->trans("Required").': ';
  159. if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
  160. $s .= '<strike>';
  161. }
  162. $s .= yn(!$this->code_null, 1, 2);
  163. if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
  164. $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
  165. }
  166. $s .= '<br>';
  167. }
  168. /*$s.=$langs->trans("CanBeModifiedIfOk").': ';
  169. $s.=yn($this->code_modifiable,1,2);
  170. $s.='<br>';
  171. $s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide,1,2).'<br>';
  172. */
  173. $s .= $langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'<br>';
  174. $s .= '<br>';
  175. $nextval = $this->getNextValue($soc, '');
  176. if (empty($nextval)) {
  177. $nextval = $langs->trans("Undefined");
  178. }
  179. $s .= $langs->trans("NextValue").': <b>'.$nextval.'</b><br>';
  180. return $s;
  181. }
  182. }