mod_stocktransfer_advanced.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. * or see https://www.gnu.org/
  22. */
  23. /**
  24. * \file htdocs/core/modules/stocktransfer/mod_stocktransfer_advanced.php
  25. * \ingroup stocktransfer
  26. * \brief File containing class for advanced numbering model of StockTransfer
  27. */
  28. require_once DOL_DOCUMENT_ROOT . '/core/modules/stocktransfer/modules_stocktransfer.php';
  29. /**
  30. * Class to manage customer Bom numbering rules advanced
  31. */
  32. class mod_stocktransfer_advanced extends ModeleNumRefStockTransfer
  33. {
  34. /**
  35. * Dolibarr version of the loaded document
  36. * @var string
  37. */
  38. public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
  39. /**
  40. * @var string Error message
  41. */
  42. public $error = '';
  43. /**
  44. * @var string name
  45. */
  46. public $name = 'got2be';
  47. /**
  48. * Returns the description of the numbering model
  49. *
  50. * @param Translate $langs Lang object to use for output
  51. * @return string Descriptive text
  52. */
  53. public function info($langs)
  54. {
  55. global $langs, $db;
  56. $langs->load("bills");
  57. $form = new Form($db);
  58. $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
  59. $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  60. $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
  61. $texte .= '<input type="hidden" name="action" value="updateMask">';
  62. $texte .= '<input type="hidden" name="maskconststocktransfer" value="STOCKTRANSFER_STOCKTRANSFER_ADVANCED_MASK">';
  63. $texte .= '<table class="nobordernopadding" width="100%">';
  64. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("StockTransfer"), $langs->transnoentities("StockTransfer"));
  65. $tooltip .= $langs->trans("GenericMaskCodes2");
  66. $tooltip .= $langs->trans("GenericMaskCodes3");
  67. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("StockTransfer"), $langs->transnoentities("StockTransfer"));
  68. $tooltip .= $langs->trans("GenericMaskCodes5");
  69. // Parametrage du prefix
  70. $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
  71. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskStockTransfer" value="'.getDolGlobalString('STOCKTRANSFER_STOCKTRANSFER_ADVANCED_MASK').'">', $tooltip, 1, 1).'</td>';
  72. $texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
  73. $texte .= '</tr>';
  74. $texte .= '</table>';
  75. $texte .= '</form>';
  76. return $texte;
  77. }
  78. /**
  79. * Return an example of numbering
  80. *
  81. * @return string Example
  82. */
  83. public function getExample()
  84. {
  85. global $conf, $db, $langs, $mysoc;
  86. $object = new StockTransfer($db);
  87. $object->initAsSpecimen();
  88. /*$old_code_client = $mysoc->code_client;
  89. $old_code_type = $mysoc->typent_code;
  90. $mysoc->code_client = 'CCCCCCCCCC';
  91. $mysoc->typent_code = 'TTTTTTTTTT';*/
  92. $numExample = $this->getNextValue($object);
  93. /*$mysoc->code_client = $old_code_client;
  94. $mysoc->typent_code = $old_code_type;*/
  95. if (!$numExample) {
  96. $numExample = $langs->trans('NotConfigured');
  97. }
  98. return $numExample;
  99. }
  100. /**
  101. * Return next free value
  102. *
  103. * @param Object $object Object we need next value for
  104. * @return string Value if KO, <0 if KO
  105. */
  106. public function getNextValue($object)
  107. {
  108. global $db, $conf;
  109. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  110. // We get cursor rule
  111. $mask = getDolGlobalString('STOCKTRANSFER_STOCKTRANSFER_ADVANCED_MASK');
  112. if (!$mask) {
  113. $this->error = 'NotConfigured';
  114. return 0;
  115. }
  116. $date = $object->date;
  117. $numFinal = get_next_value($db, $mask, 'stocktransfer_stocktransfer', 'ref', '', null, $date);
  118. return $numFinal;
  119. }
  120. }