mod_reception_moonstone.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /* Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
  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/reception/mod_reception_moonstone.php
  21. * \ingroup reception
  22. * \brief File of class to manage reception numbering rules Moonstone
  23. */
  24. require_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
  25. /**
  26. * Class to manage reception numbering rules Moonstone
  27. */
  28. class mod_reception_moonstone extends ModelNumRefReception
  29. {
  30. public $version = 'dolibarr';
  31. public $error = '';
  32. public $nom = 'Moonstone';
  33. /**
  34. * Return default description of numbering model
  35. *
  36. * @param Translate $langs Lang object to use for output
  37. * @return string Descriptive text
  38. */
  39. public function info($langs)
  40. {
  41. global $langs, $db;
  42. $langs->load("bills");
  43. $form = new Form($db);
  44. $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
  45. $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  46. $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
  47. $texte .= '<input type="hidden" name="action" value="updateMask">';
  48. $texte .= '<input type="hidden" name="maskconstreception" value="RECEPTION_MOONSTONE_MASK">';
  49. $texte .= '<table class="nobordernopadding" width="100%">';
  50. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Reception"), $langs->transnoentities("Reception"));
  51. $tooltip .= $langs->trans("GenericMaskCodes2");
  52. $tooltip .= $langs->trans("GenericMaskCodes3");
  53. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Reception"), $langs->transnoentities("Reception"));
  54. $tooltip .= $langs->trans("GenericMaskCodes5");
  55. $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
  56. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskreception" value="'.getDolGlobalString("RECEPTION_MOONSTONE_MASK").'">', $tooltip, 1, 1).'</td>';
  57. $texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button button-edit" name="Button" value="'.$langs->trans("Modify").'"></td>';
  58. $texte .= '</tr>';
  59. $texte .= '</table>';
  60. $texte .= '</form>';
  61. return $texte;
  62. }
  63. /**
  64. * Return numbering example
  65. *
  66. * @return string Example
  67. */
  68. public function getExample()
  69. {
  70. global $langs, $mysoc;
  71. $old_code_client = $mysoc->code_client;
  72. $old_code_type = $mysoc->typent_code;
  73. $mysoc->code_client = 'CCCCCCCCCC';
  74. $mysoc->typent_code = 'TTTTTTTTTT';
  75. $numExample = $this->getNextValue($mysoc, null);
  76. $mysoc->code_client = $old_code_client;
  77. $mysoc->typent_code = $old_code_type;
  78. if (!$numExample) {
  79. $numExample = $langs->trans('NotConfigured');
  80. }
  81. return $numExample;
  82. }
  83. /**
  84. * Return next value
  85. *
  86. * @param Societe $objsoc Third party object
  87. * @param Object|null $reception Reception object
  88. * @return string Value if OK, 0 if KO
  89. */
  90. public function getNextValue($objsoc, $reception)
  91. {
  92. global $db;
  93. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  94. $mask = getDolGlobalString("RECEPTION_MOONSTONE_MASK");
  95. if (!$mask) {
  96. $this->error = 'NotConfigured';
  97. return 0;
  98. }
  99. if (!empty($reception)) {
  100. $date = $reception->date_reception;
  101. } else {
  102. $date = dol_now();
  103. }
  104. $numFinal = get_next_value($db, $mask, 'reception', 'ref', '', $objsoc, $date);
  105. return $numFinal;
  106. }
  107. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  108. /**
  109. * Return next free value
  110. *
  111. * @param Societe $objsoc Third party object
  112. * @param Object $objforref Reception object
  113. * @return string Next free value
  114. */
  115. public function reception_get_num($objsoc, $objforref)
  116. {
  117. // phpcs:enable
  118. return $this->getNextValue($objsoc, $objforref);
  119. }
  120. }