mod_delivery_saphir.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2007 Regis Houssin <regis.houssin@inodbox.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. * or see https://www.gnu.org/
  19. */
  20. /**
  21. * \file htdocs/core/modules/delivery/mod_delivery_saphir.php
  22. * \ingroup expedition
  23. * \brief Fichier contenant la classe du modele de numerotation de reference de livraison Saphir
  24. */
  25. require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/modules_delivery.php';
  26. /**
  27. * \class mod_delivery_saphir
  28. * \brief Classe du modele de numerotation de reference de livraison Saphir
  29. */
  30. class mod_delivery_saphir extends ModeleNumRefDeliveryOrder
  31. {
  32. /**
  33. * Dolibarr version of the loaded document
  34. * @var string
  35. */
  36. public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
  37. /**
  38. * @var string Error message
  39. */
  40. public $error = '';
  41. /**
  42. * @var string Nom du modele
  43. * @deprecated
  44. * @see $name
  45. */
  46. public $nom = 'Saphir';
  47. /**
  48. * @var string model name
  49. */
  50. public $name = 'Saphir';
  51. /**
  52. * Returns the description of the numbering model
  53. *
  54. * @param Translate $langs Lang object to use for output
  55. * @return string Descriptive text
  56. */
  57. public function info($langs)
  58. {
  59. global $langs, $db;
  60. $langs->load("bills");
  61. $form = new Form($db);
  62. $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
  63. $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  64. $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
  65. $texte .= '<input type="hidden" name="action" value="updateMask">';
  66. $texte .= '<input type="hidden" name="maskconstdelivery" value="DELIVERY_SAPHIR_MASK">';
  67. $texte .= '<table class="nobordernopadding" width="100%">';
  68. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Delivery"), $langs->transnoentities("Delivery"));
  69. $tooltip .= $langs->trans("GenericMaskCodes2");
  70. $tooltip .= $langs->trans("GenericMaskCodes3");
  71. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Delivery"), $langs->transnoentities("Delivery"));
  72. $tooltip .= $langs->trans("GenericMaskCodes5");
  73. // Parametrage du prefix
  74. $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
  75. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskdelivery" value="'.getDolGlobalString('DELIVERY_SAPHIR_MASK').'">', $tooltip, 1, 1).'</td>';
  76. $texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button button-edit" name="Button"value="'.$langs->trans("Modify").'"></td>';
  77. $texte .= '</tr>';
  78. $texte .= '</table>';
  79. $texte .= '</form>';
  80. return $texte;
  81. }
  82. /**
  83. * Return an example of number
  84. *
  85. * @return string Example
  86. */
  87. public function getExample()
  88. {
  89. global $conf, $langs, $mysoc;
  90. $old_code_client = $mysoc->code_client;
  91. $mysoc->code_client = 'CCCCCCCCCC';
  92. $numExample = $this->getNextValue($mysoc, '');
  93. $mysoc->code_client = $old_code_client;
  94. if (!$numExample) {
  95. $numExample = $langs->trans('NotConfigured');
  96. }
  97. return $numExample;
  98. }
  99. /**
  100. * Return next value
  101. *
  102. * @param Societe $objsoc Object third party
  103. * @param Object $object Object delivery
  104. * @return string Value if OK, 0 if KO
  105. */
  106. public function getNextValue($objsoc, $object)
  107. {
  108. global $db, $conf;
  109. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  110. // On defini critere recherche compteur
  111. $mask = getDolGlobalString('DELIVERY_SAPHIR_MASK');
  112. if (!$mask) {
  113. $this->error = 'NotConfigured';
  114. return 0;
  115. }
  116. $numFinal = get_next_value($db, $mask, 'delivery', 'ref', '', $objsoc, $object->delivery_date);
  117. return $numFinal;
  118. }
  119. /**
  120. * Return next free value
  121. *
  122. * @param Societe $objsoc Object third party
  123. * @param string $objforref Object for number to search
  124. * @return string Next free value
  125. */
  126. public function getNumRef($objsoc, $objforref)
  127. {
  128. return $this->getNextValue($objsoc, $objforref);
  129. }
  130. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  131. /**
  132. * Return next free ref
  133. *
  134. * @param Societe $objsoc Object thirdparty
  135. * @param Object $object Objet livraison
  136. * @return string Descriptive text
  137. */
  138. public function delivery_get_num($objsoc = 0, $object = '')
  139. {
  140. // phpcs:enable
  141. return $this->getNextValue($objsoc, $object);
  142. }
  143. }