mod_project_universal.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /* Copyright (C) 2010 Regis Houssin <regis.houssin@inodbox.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. * or see https://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/modules/project/mod_project_universal.php
  20. * \ingroup project
  21. * \brief Fichier contenant la classe du modele de numerotation de reference de projet Universal
  22. */
  23. require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
  24. /**
  25. * Classe du modele de numerotation de reference de projet Universal
  26. */
  27. class mod_project_universal extends ModeleNumRefProjects
  28. {
  29. /**
  30. * @var DoliDB $db
  31. */
  32. public $db;
  33. /**
  34. * Dolibarr version of the loaded document
  35. * @var string
  36. */
  37. public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
  38. /**
  39. * @var string Error code (or message)
  40. */
  41. public $error = '';
  42. /**
  43. * @var string Nom du modele
  44. * @deprecated
  45. * @see $name
  46. */
  47. public $nom = 'Universal';
  48. /**
  49. * @var string model name
  50. */
  51. public $name = 'Universal';
  52. /**
  53. * Returns the description of the numbering model
  54. *
  55. * @return string Texte descripif
  56. */
  57. public function info()
  58. {
  59. global $conf, $langs;
  60. // Load translation files required by the page
  61. $langs->loadLangs(array("projects", "admin"));
  62. $form = new Form($this->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="maskconstproject" value="PROJECT_UNIVERSAL_MASK">';
  68. $texte .= '<table class="nobordernopadding" width="100%">';
  69. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Project"), $langs->transnoentities("Project"));
  70. $tooltip .= $langs->trans("GenericMaskCodes2");
  71. $tooltip .= $langs->trans("GenericMaskCodes3");
  72. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Project"), $langs->transnoentities("Project"));
  73. $tooltip .= $langs->trans("GenericMaskCodes5");
  74. // Parametrage du prefix
  75. $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
  76. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskproject" value="'.$conf->global->PROJECT_UNIVERSAL_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 value
  102. *
  103. * @param Societe $objsoc Object third party
  104. * @param Project $project Object project
  105. * @return string Value if OK, 0 if KO
  106. */
  107. public function getNextValue($objsoc, $project)
  108. {
  109. global $db, $conf;
  110. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  111. // On defini critere recherche compteur
  112. $mask = $conf->global->PROJECT_UNIVERSAL_MASK;
  113. if (!$mask) {
  114. $this->error = 'NotConfigured';
  115. return 0;
  116. }
  117. // Get entities
  118. $entity = getEntity('projectnumber', 1, $project);
  119. $date = (empty($project->date_c) ? dol_now() : $project->date_c);
  120. $numFinal = get_next_value($db, $mask, 'projet', 'ref', '', (is_object($objsoc) ? $objsoc : ''), $date, 'next', false, null, $entity);
  121. return $numFinal;
  122. }
  123. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  124. /**
  125. * Return next reference not yet used as a reference
  126. *
  127. * @param Societe $objsoc Object third party
  128. * @param Project $project Object project
  129. * @return string Next not used reference
  130. */
  131. public function project_get_num($objsoc = 0, $project = '')
  132. {
  133. // phpcs:enable
  134. return $this->getNextValue($objsoc, $project);
  135. }
  136. }