mod_facture_mercure.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2007 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  6. * Copyright (C) 2013 uanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. * or see https://www.gnu.org/
  22. */
  23. /**
  24. * \file htdocs/core/modules/facture/mod_facture_mercure.php
  25. * \ingroup facture
  26. * \brief File containing class for numbering module Mercure
  27. */
  28. require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
  29. /**
  30. * Class of numbering module Mercure for invoices
  31. */
  32. class mod_facture_mercure extends ModeleNumRefFactures
  33. {
  34. /**
  35. * Dolibarr version of the loaded document
  36. * @var string
  37. */
  38. public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
  39. /**
  40. * @var string Error message
  41. */
  42. public $error = '';
  43. /**
  44. * Returns the description of the numbering model
  45. *
  46. * @param Translate $langs Lang object to use for output
  47. * @return string Descriptive text
  48. */
  49. public function info($langs)
  50. {
  51. global $db, $langs;
  52. $langs->load("bills");
  53. $form = new Form($db);
  54. $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
  55. $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  56. $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
  57. $texte .= '<input type="hidden" name="action" value="updateMask">';
  58. $texte .= '<input type="hidden" name="maskconstinvoice" value="FACTURE_MERCURE_MASK_INVOICE">';
  59. $texte .= '<input type="hidden" name="maskconstreplacement" value="FACTURE_MERCURE_MASK_REPLACEMENT">';
  60. $texte .= '<input type="hidden" name="maskconstcredit" value="FACTURE_MERCURE_MASK_CREDIT">';
  61. $texte .= '<input type="hidden" name="maskconstdeposit" value="FACTURE_MERCURE_MASK_DEPOSIT">';
  62. $texte .= '<table class="nobordernopadding" width="100%">';
  63. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice"));
  64. $tooltip .= $langs->trans("GenericMaskCodes2");
  65. $tooltip .= $langs->trans("GenericMaskCodes3");
  66. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice"));
  67. $tooltip .= $langs->trans("GenericMaskCodes5");
  68. // Setting the prefix
  69. $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").'):</span></td>';
  70. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskinvoice" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_INVOICE").'">', $tooltip, 1, 1).'</td>';
  71. $texte .= '<td class="left" rowspan="3">&nbsp; <input type="submit" class="button button-edit" name="Button"value="'.$langs->trans("Modify").'"></td>';
  72. $texte .= '</tr>';
  73. // Prefix setting of replacement invoices
  74. $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceReplacement").'):</span></td>';
  75. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskreplacement" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_REPLACEMENT").'">', $tooltip, 1, 1).'</td>';
  76. $texte .= '</tr>';
  77. // Prefix setting of credit note
  78. $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):</span></td>';
  79. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskcredit" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_CREDIT").'">', $tooltip, 1, 1).'</td>';
  80. $texte .= '</tr>';
  81. // Prefix setting of deposit
  82. $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):</span></td>';
  83. $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskdeposit" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_DEPOSIT").'">', $tooltip, 1, 1).'</td>';
  84. $texte .= '</tr>';
  85. $texte .= '</table>';
  86. $texte .= '</form>';
  87. return $texte;
  88. }
  89. /**
  90. * Return an example of number value
  91. *
  92. * @return string Example
  93. */
  94. public function getExample()
  95. {
  96. global $mysoc;
  97. $old_code_client = $mysoc->code_client;
  98. $old_code_type = $mysoc->typent_code;
  99. $mysoc->code_client = 'CCCCCCCCCC';
  100. $mysoc->typent_code = 'TTTTTTTTTT';
  101. $numExample = $this->getNextValue($mysoc, '');
  102. $mysoc->code_client = $old_code_client;
  103. $mysoc->typent_code = $old_code_type;
  104. if (!$numExample) {
  105. $numExample = 'NotConfigured';
  106. }
  107. return $numExample;
  108. }
  109. /**
  110. * Return next value
  111. *
  112. * @param Societe $objsoc Object third party
  113. * @param Facture $invoice Object invoice
  114. * @param string $mode 'next' for next value or 'last' for last value
  115. * @return string Value if OK, 0 if KO
  116. */
  117. public function getNextValue($objsoc, $invoice, $mode = 'next')
  118. {
  119. global $db;
  120. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  121. // Get Mask value
  122. $mask = '';
  123. if (is_object($invoice) && $invoice->type == 1) {
  124. $mask = getDolGlobalString('FACTURE_MERCURE_MASK_REPLACEMENT', getDolGlobalString('FACTURE_MERCURE_MASK_INVOICE'));
  125. } elseif (is_object($invoice) && $invoice->type == 2) {
  126. $mask = getDolGlobalString('FACTURE_MERCURE_MASK_CREDIT');
  127. } elseif (is_object($invoice) && $invoice->type == 3) {
  128. $mask = getDolGlobalString('FACTURE_MERCURE_MASK_DEPOSIT');
  129. } else {
  130. $mask = getDolGlobalString('FACTURE_MERCURE_MASK_INVOICE');
  131. }
  132. if (!$mask) {
  133. $this->error = 'NotConfigured';
  134. return 0;
  135. }
  136. $where = '';
  137. //if ($facture->type == 2) $where.= " AND type = 2";
  138. //else $where.=" AND type != 2";
  139. // Get entities
  140. $entity = getEntity('invoicenumber', 1, $invoice);
  141. $numFinal = get_next_value($db, $mask, 'facture', 'ref', $where, $objsoc, $invoice->date, $mode, false, null, $entity);
  142. if (!preg_match('/([0-9])+/', $numFinal)) {
  143. $this->error = $numFinal;
  144. }
  145. return $numFinal;
  146. }
  147. /**
  148. * Return next free value
  149. *
  150. * @param Societe $objsoc Object third party
  151. * @param string $objforref Object for number to search
  152. * @param string $mode 'next' for next value or 'last' for last value
  153. * @return string Next free value
  154. */
  155. public function getNumRef($objsoc, $objforref, $mode = 'next')
  156. {
  157. return $this->getNextValue($objsoc, $objforref, $mode);
  158. }
  159. }