mod_ticket_universal.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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/ticket/mod_ticket_universal.php
  20. * \ingroup ticket
  21. * \brief Fichier contenant la classe du modele de numerotation de reference de projet Universal
  22. */
  23. require_once DOL_DOCUMENT_ROOT.'/core/modules/ticket/modules_ticket.php';
  24. /**
  25. * Classe du modele de numerotation de reference de projet Universal
  26. */
  27. class mod_ticket_universal extends ModeleNumRefTicket
  28. {
  29. /**
  30. * Dolibarr version of the loaded document
  31. * @var string
  32. */
  33. public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
  34. /**
  35. * @var string Error code (or message)
  36. */
  37. public $error = '';
  38. /**
  39. * @var string Nom du modele
  40. * @deprecated
  41. * @see $name
  42. */
  43. public $nom = 'Universal';
  44. /**
  45. * @var string model name
  46. */
  47. public $name = 'Universal';
  48. /**
  49. * Returns the description of the numbering model
  50. *
  51. * @return string Texte descripif
  52. */
  53. public function info()
  54. {
  55. global $db, $conf, $langs;
  56. // Load translation files required by the page
  57. $langs->loadLangs(array("ticket", "admin"));
  58. $form = new Form($db);
  59. $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
  60. $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  61. $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
  62. $texte .= '<input type="hidden" name="action" value="updateMask">';
  63. $texte .= '<input type="hidden" name="maskconstticket" value="TICKET_UNIVERSAL_MASK">';
  64. $texte .= '<table class="nobordernopadding" width="100%">';
  65. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Ticket"), $langs->transnoentities("Ticket"));
  66. $tooltip .= $langs->trans("GenericMaskCodes2");
  67. $tooltip .= $langs->trans("GenericMaskCodes3");
  68. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Ticket"), $langs->transnoentities("Ticket"));
  69. $tooltip .= $langs->trans("GenericMaskCodes5");
  70. // Parametrage du prefix
  71. $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
  72. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskticket" value="'.getDolGlobalString("TICKET_UNIVERSAL_MASK").'">', $tooltip, 1, 1).'</td>';
  73. $texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button button-edit" name="Button"value="'.$langs->trans("Modify").'"></td>';
  74. $texte .= '</tr>';
  75. $texte .= '</table>';
  76. $texte .= '</form>';
  77. return $texte;
  78. }
  79. /**
  80. * Return an example of numbering
  81. *
  82. * @return string Example
  83. */
  84. public function getExample()
  85. {
  86. global $conf, $langs, $mysoc;
  87. $old_code_client = $mysoc->code_client;
  88. $mysoc->code_client = 'CCCCCCCCCC';
  89. $numExample = $this->getNextValue($mysoc, '');
  90. $mysoc->code_client = $old_code_client;
  91. if (!$numExample) {
  92. $numExample = $langs->trans('NotConfigured');
  93. }
  94. return $numExample;
  95. }
  96. /**
  97. * Return next value
  98. *
  99. * @param Societe $objsoc Object third party
  100. * @param Ticket $ticket Object ticket
  101. * @return string Value if OK, 0 if KO
  102. */
  103. public function getNextValue($objsoc, $ticket)
  104. {
  105. global $db, $conf;
  106. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  107. // On defini critere recherche compteur
  108. $mask = getDolGlobalString("TICKET_UNIVERSAL_MASK");
  109. if (!$mask) {
  110. $this->error = 'NotConfigured';
  111. return 0;
  112. }
  113. // Get entities
  114. $entity = getEntity('ticketnumber', 1, $ticket);
  115. $date = empty($ticket->datec) ? dol_now() : $ticket->datec;
  116. $numFinal = get_next_value($db, $mask, 'ticket', 'ref', '', $objsoc->code_client, $date, 'next', false, null, $entity);
  117. return $numFinal;
  118. }
  119. }