mod_ticket_universal.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 File with class to manage the numbering module Universal for Ticket references
  22. */
  23. require_once DOL_DOCUMENT_ROOT.'/core/modules/ticket/modules_ticket.php';
  24. /**
  25. * Class to manage the numbering module Universal for Ticket references
  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. * @param Translate $langs Lang object to use for output
  52. * @return string Descriptive text
  53. */
  54. public function info($langs)
  55. {
  56. global $db, $langs;
  57. // Load translation files required by the page
  58. $langs->loadLangs(array("ticket", "admin"));
  59. $form = new Form($db);
  60. $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
  61. $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  62. $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
  63. $texte .= '<input type="hidden" name="action" value="updateMask">';
  64. $texte .= '<input type="hidden" name="maskconstticket" value="TICKET_UNIVERSAL_MASK">';
  65. $texte .= '<table class="nobordernopadding" width="100%">';
  66. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Ticket"), $langs->transnoentities("Ticket"));
  67. $tooltip .= $langs->trans("GenericMaskCodes2");
  68. $tooltip .= $langs->trans("GenericMaskCodes3");
  69. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Ticket"), $langs->transnoentities("Ticket"));
  70. $tooltip .= $langs->trans("GenericMaskCodes5");
  71. // Prefix settings
  72. $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
  73. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskticket" value="'.getDolGlobalString("TICKET_UNIVERSAL_MASK").'">', $tooltip, 1, 1).'</td>';
  74. $texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button button-edit" name="Button"value="'.$langs->trans("Modify").'"></td>';
  75. $texte .= '</tr>';
  76. $texte .= '</table>';
  77. $texte .= '</form>';
  78. return $texte;
  79. }
  80. /**
  81. * Return an example of numbering
  82. *
  83. * @return string Example
  84. */
  85. public function getExample()
  86. {
  87. global $conf, $langs, $mysoc;
  88. $old_code_client = $mysoc->code_client;
  89. $mysoc->code_client = 'CCCCCCCCCC';
  90. $numExample = $this->getNextValue($mysoc, '');
  91. $mysoc->code_client = $old_code_client;
  92. if (!$numExample) {
  93. $numExample = $langs->trans('NotConfigured');
  94. }
  95. return $numExample;
  96. }
  97. /**
  98. * Return next value
  99. *
  100. * @param Societe $objsoc Object third party
  101. * @param Ticket $ticket Object ticket
  102. * @return string Value if OK, 0 if KO
  103. */
  104. public function getNextValue($objsoc, $ticket)
  105. {
  106. global $db, $conf;
  107. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  108. // We define criterion search counter
  109. $mask = getDolGlobalString("TICKET_UNIVERSAL_MASK");
  110. if (!$mask) {
  111. $this->error = 'NotConfigured';
  112. return 0;
  113. }
  114. // Get entities
  115. $entity = getEntity('ticketnumber', 1, $ticket);
  116. $date = empty($ticket->datec) ? dol_now() : $ticket->datec;
  117. $numFinal = get_next_value($db, $mask, 'ticket', 'ref', '', $objsoc->code_client, $date, 'next', false, null, $entity);
  118. return $numFinal;
  119. }
  120. }