mod_propale_saphir.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2007 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. * or see https://www.gnu.org/
  20. */
  21. /**
  22. * \file htdocs/core/modules/propale/mod_propale_saphir.php
  23. * \ingroup propale
  24. * \brief File that contains the numbering module rules Saphir
  25. */
  26. require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
  27. /**
  28. * Class of file that contains the numbering module rules Saphir
  29. */
  30. class mod_propale_saphir extends ModeleNumRefPropales
  31. {
  32. /**
  33. * Dolibarr version of the loaded document
  34. * @var string
  35. */
  36. public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
  37. /**
  38. * @var string Error code (or message)
  39. */
  40. public $error = '';
  41. /**
  42. * @var string Nom du modele
  43. * @deprecated
  44. * @see $name
  45. */
  46. public $nom = 'Saphir';
  47. /**
  48. * @var string model name
  49. */
  50. public $name = 'Saphir';
  51. /**
  52. * Return description of module
  53. *
  54. * @param Translate $langs Lang object to use for output
  55. * @return string Descriptive text
  56. */
  57. public function info($langs)
  58. {
  59. global $conf, $langs, $db;
  60. $langs->load("bills");
  61. $form = new Form($db);
  62. $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
  63. $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  64. $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
  65. $texte .= '<input type="hidden" name="action" value="updateMask">';
  66. $texte .= '<input type="hidden" name="maskconstpropal" value="PROPALE_SAPHIR_MASK">';
  67. $texte .= '<table class="nobordernopadding" width="100%">';
  68. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Proposal"), $langs->transnoentities("Proposal"));
  69. $tooltip .= $langs->trans("GenericMaskCodes2");
  70. $tooltip .= $langs->trans("GenericMaskCodes3");
  71. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Proposal"), $langs->transnoentities("Proposal"));
  72. $tooltip .= $langs->trans("GenericMaskCodes5");
  73. // Parametrage du prefix
  74. $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
  75. $mask = empty($conf->global->PROPALE_SAPHIR_MASK) ? '' : $conf->global->PROPALE_SAPHIR_MASK;
  76. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskpropal" value="'.$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. $old_code_type = $mysoc->typent_code;
  93. $mysoc->code_client = 'CCCCCCCCCC';
  94. $mysoc->typent_code = 'TTTTTTTTTT';
  95. $numExample = $this->getNextValue($mysoc, '');
  96. $mysoc->code_client = $old_code_client;
  97. $mysoc->typent_code = $old_code_type;
  98. if (!$numExample) {
  99. $numExample = 'NotConfigured';
  100. }
  101. return $numExample;
  102. }
  103. /**
  104. * Return next value
  105. *
  106. * @param Societe $objsoc Object third party
  107. * @param Propal $propal Object commercial proposal
  108. * @return string Value if OK, 0 if KO
  109. */
  110. public function getNextValue($objsoc, $propal)
  111. {
  112. global $db, $conf;
  113. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  114. // On defini critere recherche compteur
  115. $mask = empty($conf->global->PROPALE_SAPHIR_MASK) ? '' : $conf->global->PROPALE_SAPHIR_MASK;
  116. if (!$mask) {
  117. $this->error = 'NotConfigured';
  118. return 0;
  119. }
  120. // Get entities
  121. $entity = getEntity('proposalnumber', 1, $propal);
  122. $date = empty($propal->date) ? dol_now() : $propal->date;
  123. $numFinal = get_next_value($db, $mask, 'propal', 'ref', '', $objsoc, $date, 'next', false, null, $entity);
  124. return $numFinal;
  125. }
  126. }