mod_arctic.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  6. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  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/fichinter/mod_arctic.php
  24. * \ingroup fiche intervention
  25. * \brief File with Arctic numbering module for interventions
  26. */
  27. require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
  28. /**
  29. * Class to manage numbering of intervention cards with rule Artic.
  30. */
  31. class mod_arctic extends ModeleNumRefFicheinter
  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 Nom du modele
  44. * @deprecated
  45. * @see $name
  46. */
  47. public $nom = 'arctic';
  48. /**
  49. * @var string model name
  50. */
  51. public $name = 'arctic';
  52. /**
  53. * Returns the description of the numbering model
  54. *
  55. * @param Translate $langs Lang object to use for output
  56. * @return string Descriptive text
  57. */
  58. public function info($langs)
  59. {
  60. global $db, $langs;
  61. $langs->load("bills");
  62. $form = new Form($db);
  63. $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
  64. $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  65. $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
  66. $texte .= '<input type="hidden" name="action" value="updateMask">';
  67. $texte .= '<input type="hidden" name="maskconst" value="FICHINTER_ARTIC_MASK">';
  68. $texte .= '<table class="nobordernopadding" width="100%">';
  69. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("InterventionCard"), $langs->transnoentities("InterventionCard"));
  70. $tooltip .= $langs->trans("GenericMaskCodes2");
  71. $tooltip .= $langs->trans("GenericMaskCodes3");
  72. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("InterventionCard"), $langs->transnoentities("InterventionCard"));
  73. $tooltip .= $langs->trans("GenericMaskCodes5");
  74. // Setting the prefix
  75. $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
  76. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskvalue" value="'.getDolGlobalString("FICHINTER_ARTIC_MASK").'">', $tooltip, 1, 1).'</td>';
  77. $texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button button-edit" name="Button" value="'.$langs->trans("Modify").'"></td>';
  78. $texte .= '</tr>';
  79. $texte .= '</table>';
  80. $texte .= '</form>';
  81. return $texte;
  82. }
  83. /**
  84. * Return an example of numbering
  85. *
  86. * @return string Example
  87. */
  88. public function getExample()
  89. {
  90. global $conf, $langs, $mysoc;
  91. $old_code_client = $mysoc->code_client;
  92. $mysoc->code_client = 'CCCCCCCCCC';
  93. $numExample = $this->getNextValue($mysoc, '');
  94. $mysoc->code_client = $old_code_client;
  95. if (!$numExample) {
  96. $numExample = $langs->trans('NotConfigured');
  97. }
  98. return $numExample;
  99. }
  100. /**
  101. * Return next free value
  102. *
  103. * @param Societe $objsoc Object thirdparty
  104. * @param Object $object Object we need next value for
  105. * @return string Value if KO, <0 if KO
  106. */
  107. public function getNextValue($objsoc = 0, $object = '')
  108. {
  109. global $db, $conf;
  110. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  111. // We define the search criteria of the counter
  112. $mask = getDolGlobalString("FICHINTER_ARTIC_MASK");
  113. if (!$mask) {
  114. $this->error = 'NotConfigured';
  115. return 0;
  116. }
  117. $numFinal = get_next_value($db, $mask, 'fichinter', 'ref', '', $objsoc, $object->datec);
  118. return $numFinal;
  119. }
  120. /**
  121. * Return next free value
  122. *
  123. * @param Societe $objsoc Object third party
  124. * @param Object $objforref Object for number to search
  125. * @return string Next free value
  126. */
  127. public function getNumRef($objsoc, $objforref)
  128. {
  129. return $this->getNextValue($objsoc, $objforref);
  130. }
  131. }