mod_expedition_ribera.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  3. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
  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/expedition/mod_expedition_ribera.php
  21. * \ingroup expedition
  22. * \brief File of class to manage expedition numbering rules Ribera
  23. */
  24. require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
  25. /**
  26. * Class to manage expedition numbering rules Ribera
  27. */
  28. class mod_expedition_ribera extends ModelNumRefExpedition
  29. {
  30. /**
  31. * Dolibarr version of the loaded document
  32. * @var string
  33. */
  34. public $version = 'dolibarr';
  35. /**
  36. * @var string Error message
  37. */
  38. public $error = '';
  39. /**
  40. * @var string Nom du modele
  41. * @deprecated
  42. * @see $name
  43. */
  44. public $nom = 'Ribera';
  45. /**
  46. * @var string model name
  47. */
  48. public $name = 'Ribera';
  49. /**
  50. * Return default description of numbering model
  51. *
  52. * @param Translate $langs Lang object to use for output
  53. * @return string Descriptive text
  54. */
  55. public function info($langs)
  56. {
  57. global $langs, $db;
  58. $langs->load("bills");
  59. $form = new Form($db);
  60. $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
  61. $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  62. $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
  63. $texte .= '<input type="hidden" name="action" value="updateMask">';
  64. $texte .= '<input type="hidden" name="maskconstexpedition" value="EXPEDITION_RIBERA_MASK">';
  65. $texte .= '<table class="nobordernopadding" width="100%">';
  66. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Shipment"), $langs->transnoentities("Shipment"));
  67. $tooltip .= $langs->trans("GenericMaskCodes2");
  68. $tooltip .= $langs->trans("GenericMaskCodes3");
  69. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Shipment"), $langs->transnoentities("Shipment"));
  70. $tooltip .= $langs->trans("GenericMaskCodes5");
  71. $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
  72. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskexpedition" value="'.getDolGlobalString('EXPEDITION_RIBERA_MASK').'">', $tooltip, 1, 1).'</td>';
  73. $texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button button-edit" name="Button" value="'.$langs->trans("Modify").'"></td>';
  74. $texte .= '</tr>';
  75. $texte .= '</table>';
  76. $texte .= '</form>';
  77. return $texte;
  78. }
  79. /**
  80. * Return numbering example
  81. *
  82. * @return string Example
  83. */
  84. public function getExample()
  85. {
  86. global $conf, $langs, $mysoc;
  87. $old_code_client = $mysoc->code_client;
  88. $old_code_type = $mysoc->typent_code;
  89. $mysoc->code_client = 'CCCCCCCCCC';
  90. $mysoc->typent_code = 'TTTTTTTTTT';
  91. $numExample = $this->getNextValue($mysoc, '');
  92. $mysoc->code_client = $old_code_client;
  93. $mysoc->typent_code = $old_code_type;
  94. if (!$numExample) {
  95. $numExample = $langs->trans('NotConfigured');
  96. }
  97. return $numExample;
  98. }
  99. /**
  100. * Return next value
  101. *
  102. * @param Societe $objsoc Third party object
  103. * @param Object $shipment Shipment object
  104. * @return string Value if OK, 0 if KO
  105. */
  106. public function getNextValue($objsoc, $shipment)
  107. {
  108. global $db, $conf;
  109. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  110. $mask = getDolGlobalString('EXPEDITION_RIBERA_MASK');
  111. if (empty($mask)) {
  112. $this->error = 'NotConfigured';
  113. return 0;
  114. }
  115. $date = $shipment->date_expedition;
  116. $numFinal = get_next_value($db, $mask, 'expedition', 'ref', '', $objsoc, $date);
  117. return $numFinal;
  118. }
  119. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  120. /**
  121. * Return next free value
  122. *
  123. * @param Societe $objsoc Third party object
  124. * @param Object $objforref Shipment object
  125. * @return string Next free value
  126. */
  127. public function expedition_get_num($objsoc, $objforref)
  128. {
  129. // phpcs:enable
  130. return $this->getNextValue($objsoc, $objforref);
  131. }
  132. }