mod_holiday_immaculate.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /* Copyright (C) 2011-2019 Juanjo Menent <jmenent@2byte.es>
  3. * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
  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/holiday/mod_holiday_immaculate.php
  21. * \ingroup contract
  22. * \brief File of class to manage contract numbering rules Magre
  23. */
  24. require_once DOL_DOCUMENT_ROOT.'/core/modules/holiday/modules_holiday.php';
  25. /**
  26. * Class to manage contract numbering rules Magre
  27. */
  28. class mod_holiday_immaculate extends ModelNumRefHolidays
  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 = 'Immaculate';
  45. /**
  46. * @var string model name
  47. */
  48. public $name = 'Immaculate';
  49. /**
  50. * @var int Automatic numbering
  51. */
  52. public $code_auto = 1;
  53. /**
  54. * Return default description of numbering model
  55. *
  56. * @return string text description
  57. */
  58. public function info()
  59. {
  60. global $db, $conf, $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="maskconstholiday" value="HOLIDAY_IMMACULATE_MASK">';
  68. $texte .= '<table class="nobordernopadding" width="100%">';
  69. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Holiday"), $langs->transnoentities("Holiday"));
  70. $tooltip .= $langs->trans("GenericMaskCodes2");
  71. $tooltip .= $langs->trans("GenericMaskCodes3");
  72. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Holiday"), $langs->transnoentities("Holiday"));
  73. $tooltip .= $langs->trans("GenericMaskCodes5");
  74. $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
  75. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskholiday" value="'.getDolGlobalString('HOLIDAY_IMMACULATE_MASK').'">', $tooltip, 1, 1).'</td>';
  76. $texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button button-edit" name="Button"value="'.$langs->trans("Modify").'"></td>';
  77. $texte .= '</tr>';
  78. $texte .= '</table>';
  79. $texte .= '</form>';
  80. return $texte;
  81. }
  82. /**
  83. * Return numbering example
  84. *
  85. * @return string Example
  86. */
  87. public function getExample()
  88. {
  89. global $conf, $langs, $user;
  90. $old_login = $user->login;
  91. $user->login = 'UUUUUUU';
  92. $numExample = $this->getNextValue($user, '');
  93. $user->login = $old_login;
  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 $holiday holiday object
  104. * @return string Value if OK, 0 if KO
  105. */
  106. public function getNextValue($objsoc, $holiday)
  107. {
  108. global $db, $conf;
  109. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  110. $mask = getDolGlobalString('HOLIDAY_IMMACULATE_MASK');
  111. if (!$mask) {
  112. $this->error = 'NotConfigured';
  113. return 0;
  114. }
  115. $numFinal = get_next_value($db, $mask, 'holiday', 'ref', '', $objsoc, $holiday->date_create);
  116. return $numFinal;
  117. }
  118. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  119. /**
  120. * Return next value
  121. *
  122. * @param User $fuser User object
  123. * @param Object $objforref Holiday object
  124. * @return string Value if OK, 0 if KO
  125. */
  126. public function holiday_get_num($fuser, $objforref)
  127. {
  128. // phpcs:enable
  129. return $this->getNextValue($fuser, $objforref);
  130. }
  131. }