mod_asset_advanced.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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-2022 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/asset/mod_asset_advanced.php
  24. * \ingroup asset
  25. * \brief File containing class for advanced numbering model of Asset
  26. */
  27. require_once DOL_DOCUMENT_ROOT.'/core/modules/asset/modules_asset.php';
  28. /**
  29. * Class to manage customer Bom numbering rules advanced
  30. */
  31. class mod_asset_advanced extends ModeleNumRefAsset
  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 = 'advanced';
  46. /**
  47. * Returns the description of the numbering model
  48. *
  49. * @param Translate $langs Lang object to use for output
  50. * @return string Descriptive text
  51. */
  52. public function info($langs)
  53. {
  54. global $langs, $db;
  55. $langs->load("bills");
  56. $form = new Form($db);
  57. $text = $langs->trans('GenericNumRefModelDesc')."<br>\n";
  58. $text .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  59. $text .= '<input type="hidden" name="token" value="'.newToken().'">';
  60. $text .= '<input type="hidden" name="action" value="updateMask">';
  61. $text .= '<input type="hidden" name="maskconst" value="ASSET_ADVANCED_MASK">';
  62. $text .= '<table class="nobordernopadding" width="100%">';
  63. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Asset"), $langs->transnoentities("Asset"));
  64. $tooltip .= $langs->trans("GenericMaskCodes2");
  65. $tooltip .= $langs->trans("GenericMaskCodes3");
  66. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Asset"), $langs->transnoentities("Asset"));
  67. $tooltip .= $langs->trans("GenericMaskCodes5");
  68. // Parametrage du prefix
  69. $text .= '<tr><td>'.$langs->trans("Mask").':</td>';
  70. $text .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="mask" value="'.getDolGlobalString('ASSET_ADVANCED_MASK').'">', $tooltip, 1, 1).'</td>';
  71. $text .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button button-edit" name="Button"value="'.$langs->trans("Modify").'"></td>';
  72. $text .= '</tr>';
  73. $text .= '</table>';
  74. $text .= '</form>';
  75. return $text;
  76. }
  77. /**
  78. * Return an example of numbering
  79. *
  80. * @return string Example
  81. */
  82. public function getExample()
  83. {
  84. global $conf, $db, $langs, $mysoc;
  85. $object = new Asset($db);
  86. $object->initAsSpecimen();
  87. $numExample = $this->getNextValue($object);
  88. if (!$numExample) {
  89. $numExample = $langs->trans('NotConfigured');
  90. }
  91. return $numExample;
  92. }
  93. /**
  94. * Return next free value
  95. *
  96. * @param Asset $object Object we need next value for
  97. * @return string Value if KO, <0 if KO
  98. */
  99. public function getNextValue($object)
  100. {
  101. global $db, $conf;
  102. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  103. // We get cursor rule
  104. $mask = getDolGlobalString('ASSET_ADVANCED_MASK');
  105. if (!$mask) {
  106. $this->error = 'NotConfigured';
  107. return 0;
  108. }
  109. $date = $object->date;
  110. $numFinal = get_next_value($db, $mask, 'asset', 'ref', '', null, $date);
  111. return $numFinal;
  112. }
  113. }