mod_chequereceipt_thyme.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
  3. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. * or see https://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/modules/cheque/mod_chequereceipt_thyme.php
  21. * \ingroup cheque
  22. * \brief File containing class for numbering module Thyme
  23. */
  24. require_once DOL_DOCUMENT_ROOT.'/core/modules/cheque/modules_chequereceipts.php';
  25. /**
  26. * Class to manage cheque receipts numbering rules Thyme
  27. */
  28. class mod_chequereceipt_thyme extends ModeleNumRefChequeReceipts
  29. {
  30. /**
  31. * Dolibarr version of the loaded document
  32. * @var string
  33. */
  34. public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
  35. /**
  36. * @var string Error message
  37. */
  38. public $error = '';
  39. public $name = 'Thyme';
  40. /**
  41. * Returns the description of the numbering model
  42. *
  43. * @param Translate $langs Lang object to use for output
  44. * @return string Descriptive text
  45. */
  46. public function info($langs)
  47. {
  48. global $conf, $langs, $db;
  49. $langs->load("bills");
  50. $form = new Form($db);
  51. $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
  52. $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  53. $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
  54. $texte .= '<input type="hidden" name="action" value="updateMask">';
  55. $texte .= '<input type="hidden" name="maskconstchequereceipts" value="CHEQUERECEIPTS_THYME_MASK">';
  56. $texte .= '<table class="nobordernopadding" width="100%">';
  57. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("CheckReceiptShort"), $langs->transnoentities("CheckReceiptShort"));
  58. $tooltip .= $langs->trans("GenericMaskCodes2");
  59. $tooltip .= $langs->trans("GenericMaskCodes3");
  60. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("CheckReceiptShort"), $langs->transnoentities("CheckReceiptShort"));
  61. $tooltip .= $langs->trans("GenericMaskCodes5");
  62. // Parametrage du prefix
  63. $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
  64. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskchequereceipts" value="'.$conf->global->CHEQUERECEIPTS_THYME_MASK.'">', $tooltip, 1, 1).'</td>';
  65. $texte .= '<td class="left" rowspan="2">&nbsp;<input type="submit" class="button button-edit" name="Button"value="'.$langs->trans("Modify").'"></td>';
  66. $texte .= '</tr>';
  67. $texte .= '</table>';
  68. $texte .= '</form>';
  69. return $texte;
  70. }
  71. /**
  72. * Return an example of numbering
  73. *
  74. * @return string Example
  75. */
  76. public function getExample()
  77. {
  78. global $conf, $langs, $mysoc;
  79. $old_code_client = $mysoc->code_client;
  80. $mysoc->code_client = 'CCCCCCCCCC';
  81. $numExample = $this->getNextValue($mysoc, '');
  82. $mysoc->code_client = $old_code_client;
  83. if (!$numExample) {
  84. $numExample = $langs->trans('NotConfigured');
  85. }
  86. return $numExample;
  87. }
  88. /**
  89. * Return next free value
  90. *
  91. * @param Societe $objsoc Object thirdparty
  92. * @param Object $object Object we need next value for
  93. * @return string Value if KO, <0 if KO
  94. */
  95. public function getNextValue($objsoc, $object)
  96. {
  97. global $db, $conf;
  98. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  99. // We get cursor rule
  100. $mask = $conf->global->CHEQUERECEIPTS_THYME_MASK;
  101. if (!$mask) {
  102. $this->error = 'NotConfigured';
  103. return 0;
  104. }
  105. $numFinal = get_next_value($db, $mask, 'bordereau_cheque', 'ref', '', $objsoc, $object->date_bordereau);
  106. return $numFinal;
  107. }
  108. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  109. /**
  110. * Return next free value
  111. *
  112. * @param Societe $objsoc Object third party
  113. * @param string $objforref Object for number to search
  114. * @return string Next free value
  115. */
  116. public function chequereceipt_get_num($objsoc, $objforref)
  117. {
  118. // phpcs:enable
  119. return $this->getNextValue($objsoc, $objforref);
  120. }
  121. }