mod_commande_saphir.php 5.0 KB

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