mod_project_universal.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 File containing the Universal project reference numbering model class
  22. */
  23. require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
  24. /**
  25. * Class to manage the numbering module Universal for project references
  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. * @param Translate $langs Lang object to use for output
  56. * @return string Descriptive text
  57. */
  58. public function info($langs)
  59. {
  60. global $langs;
  61. // Load translation files required by the page
  62. $langs->loadLangs(array("projects", "admin"));
  63. $form = new Form($this->db);
  64. $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
  65. $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  66. $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
  67. $texte .= '<input type="hidden" name="action" value="updateMask">';
  68. $texte .= '<input type="hidden" name="maskconstproject" value="PROJECT_UNIVERSAL_MASK">';
  69. $texte .= '<table class="nobordernopadding" width="100%">';
  70. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Project"), $langs->transnoentities("Project"));
  71. $tooltip .= $langs->trans("GenericMaskCodes2");
  72. $tooltip .= $langs->trans("GenericMaskCodes3");
  73. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Project"), $langs->transnoentities("Project"));
  74. $tooltip .= $langs->trans("GenericMaskCodes5");
  75. // Prefix settings
  76. $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
  77. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskproject" value="'.getDolGlobalString('PROJECT_UNIVERSAL_MASK').'">', $tooltip, 1, 1).'</td>';
  78. $texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button button-edit" name="Button"value="'.$langs->trans("Modify").'"></td>';
  79. $texte .= '</tr>';
  80. $texte .= '</table>';
  81. $texte .= '</form>';
  82. return $texte;
  83. }
  84. /**
  85. * Return an example of numbering
  86. *
  87. * @return string Example
  88. */
  89. public function getExample()
  90. {
  91. global $conf, $langs, $mysoc;
  92. $old_code_client = $mysoc->code_client;
  93. $mysoc->code_client = 'CCCCCCCCCC';
  94. $numExample = $this->getNextValue($mysoc, '');
  95. $mysoc->code_client = $old_code_client;
  96. if (!$numExample) {
  97. $numExample = $langs->trans('NotConfigured');
  98. }
  99. return $numExample;
  100. }
  101. /**
  102. * Return next value
  103. *
  104. * @param Societe $objsoc Object third party
  105. * @param Project $project Object project
  106. * @return string Value if OK, 0 if KO
  107. */
  108. public function getNextValue($objsoc, $project)
  109. {
  110. global $db, $conf;
  111. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  112. // We define criterion search counter
  113. $mask = getDolGlobalString('PROJECT_UNIVERSAL_MASK');
  114. if (!$mask) {
  115. $this->error = 'NotConfigured';
  116. return 0;
  117. }
  118. // Get entities
  119. $entity = getEntity('projectnumber', 1, $project);
  120. $date = (empty($project->date_c) ? dol_now() : $project->date_c);
  121. $numFinal = get_next_value($db, $mask, 'projet', 'ref', '', (is_object($objsoc) ? $objsoc : ''), $date, 'next', false, null, $entity);
  122. return $numFinal;
  123. }
  124. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  125. /**
  126. * Return next reference not yet used as a reference
  127. *
  128. * @param Societe $objsoc Object third party
  129. * @param Project $project Object project
  130. * @return string Next not used reference
  131. */
  132. public function project_get_num($objsoc = 0, $project = '')
  133. {
  134. // phpcs:enable
  135. return $this->getNextValue($objsoc, $project);
  136. }
  137. }