mod_facture_mercure.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. * @return string Texte descripif
  47. */
  48. public function info()
  49. {
  50. global $db, $langs;
  51. $langs->load("bills");
  52. $form = new Form($db);
  53. $texte = $langs->trans('GenericNumRefModelDesc') . "<br>\n";
  54. $texte .= '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
  55. $texte .= '<input type="hidden" name="token" value="' . newToken() . '">';
  56. $texte .= '<input type="hidden" name="action" value="updateMask">';
  57. $texte .= '<input type="hidden" name="maskconstinvoice" value="FACTURE_MERCURE_MASK_INVOICE">';
  58. $texte .= '<input type="hidden" name="maskconstreceipt" value="FACTURE_MERCURE_MASK_RECEIPT">';
  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="maskconstreceiptcredit" value="FACTURE_MERCURE_MASK_RECEIPT_CREDIT">';
  62. $texte .= '<input type="hidden" name="maskconstdeposit" value="FACTURE_MERCURE_MASK_DEPOSIT">';
  63. $texte .= '<table class="nobordernopadding" width="100%">';
  64. $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice"));
  65. $tooltip .= $langs->trans("GenericMaskCodes2");
  66. $tooltip .= $langs->trans("GenericMaskCodes3");
  67. $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice"));
  68. $tooltip .= $langs->trans("GenericMaskCodes5");
  69. // Setting the prefix
  70. $texte .= '<tr><td><span class="opacitymedium">' . $langs->trans("Mask") . ' (' . $langs->trans("InvoiceStandard") . '):</span></td>';
  71. $texte .= '<td class="right">' . $form->textwithpicto('<input type="text" class="flat minwidth175" name="maskinvoice" value="' . getDolGlobalString("FACTURE_MERCURE_MASK_INVOICE") . '">', $tooltip, 1, 1) . '</td>';
  72. $texte .= '<td class="left" rowspan="3">&nbsp; <input type="submit" class="button button-edit" name="Button"value="' . $langs->trans("Modify") . '"></td>';
  73. $texte .= '</tr>';
  74. // RECEIPT
  75. $texte .= '<tr><td><span class="opacitymedium">' . $langs->trans("Mask") . ' (' . $langs->trans("ReceiptStandard") . '):</span></td>';
  76. $texte .= '<td class="right">' . $form->textwithpicto('<input type="text" class="flat minwidth175" name="maskreceipt" value="' . getDolGlobalString("FACTURE_MERCURE_MASK_RECEIPT") . '">', $tooltip, 1, 1) . '</td>';
  77. $texte .= '</tr>';
  78. // Prefix setting of replacement invoices
  79. $texte .= '<tr><td><span class="opacitymedium">' . $langs->trans("Mask") . ' (' . $langs->trans("InvoiceReplacement") . '):</span></td>';
  80. $texte .= '<td class="right">' . $form->textwithpicto('<input type="text" class="flat minwidth175" name="maskreplacement" value="' . getDolGlobalString("FACTURE_MERCURE_MASK_REPLACEMENT") . '">', $tooltip, 1, 1) . '</td>';
  81. $texte .= '</tr>';
  82. // Prefix setting of credit note
  83. $texte .= '<tr><td><span class="opacitymedium">' . $langs->trans("Mask") . ' (' . $langs->trans("InvoiceAvoir") . '):</span></td>';
  84. $texte .= '<td class="right">' . $form->textwithpicto('<input type="text" class="flat minwidth175" name="maskcredit" value="' . getDolGlobalString("FACTURE_MERCURE_MASK_CREDIT") . '">', $tooltip, 1, 1) . '</td>';
  85. $texte .= '</tr>';
  86. // RECEIPT CREDIT NOTE
  87. $texte .= '<tr><td><span class="opacitymedium">' . $langs->trans("Mask") . ' (' . $langs->trans("ReceiptInvoiceAvoir") . '):</span></td>';
  88. $texte .= '<td class="right">' . $form->textwithpicto('<input type="text" class="flat minwidth175" name="maskreceiptcredit" value="' . getDolGlobalString("FACTURE_MERCURE_MASK_RECEIPT_CREDIT") . '">', $tooltip, 1, 1) . '</td>';
  89. $texte .= '</tr>';
  90. // Prefix setting of deposit
  91. $texte .= '<tr><td><span class="opacitymedium">' . $langs->trans("Mask") . ' (' . $langs->trans("InvoiceDeposit") . '):</span></td>';
  92. $texte .= '<td class="right">' . $form->textwithpicto('<input type="text" class="flat minwidth175" name="maskdeposit" value="' . getDolGlobalString("FACTURE_MERCURE_MASK_DEPOSIT") . '">', $tooltip, 1, 1) . '</td>';
  93. $texte .= '</tr>';
  94. $texte .= '</table>';
  95. $texte .= '</form>';
  96. return $texte;
  97. }
  98. /**
  99. * Return an example of number value
  100. *
  101. * @return string Example
  102. */
  103. public function getExample()
  104. {
  105. global $conf, $langs, $mysoc;
  106. $old_code_client = $mysoc->code_client;
  107. $old_code_type = $mysoc->typent_code;
  108. $mysoc->code_client = 'CCCCCCCCCC';
  109. $mysoc->typent_code = 'TTTTTTTTTT';
  110. $numExample = $this->getNextValue($mysoc, '');
  111. $mysoc->code_client = $old_code_client;
  112. $mysoc->typent_code = $old_code_type;
  113. if (!$numExample) {
  114. $numExample = 'NotConfigured';
  115. }
  116. return $numExample;
  117. }
  118. /**
  119. * Return next value
  120. *
  121. * @param Societe $objsoc Object third party
  122. * @param Facture $invoice Object invoice
  123. * @param string $mode 'next' for next value or 'last' for last value
  124. * @return string Value if OK, 0 if KO
  125. */
  126. public function getNextValue($objsoc, $invoice, $mode = 'next')
  127. {
  128. global $db;
  129. require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
  130. // Get Mask value
  131. $mask = '';
  132. if (is_object($invoice) && $invoice->type == 1) {
  133. $mask = getDolGlobalString('FACTURE_MERCURE_MASK_REPLACEMENT', getDolGlobalString('FACTURE_MERCURE_MASK_INVOICE'));
  134. } elseif (is_object($invoice) && $invoice->type == 2) {
  135. $mask = getDolGlobalString('FACTURE_MERCURE_MASK_CREDIT');
  136. } elseif (is_object($invoice) && $invoice->type == 7) {
  137. $mask = getDolGlobalString('FACTURE_MERCURE_MASK_RECEIPT');
  138. } elseif (is_object($invoice) && $invoice->type == 8) {
  139. $mask = getDolGlobalString('FACTURE_MERCURE_MASK_RECEIPT_CREDIT');
  140. } elseif (is_object($invoice) && $invoice->type == 3) {
  141. $mask = getDolGlobalString('FACTURE_MERCURE_MASK_DEPOSIT');
  142. } else {
  143. $mask = getDolGlobalString('FACTURE_MERCURE_MASK_INVOICE');
  144. }
  145. if (!$mask) {
  146. $this->error = 'NotConfigured';
  147. return 0;
  148. }
  149. $where = '';
  150. //if ($facture->type == 2) $where.= " AND type = 2";
  151. //else $where.=" AND type != 2";
  152. // Get entities
  153. $entity = getEntity('invoicenumber', 1, $invoice);
  154. $numFinal = get_next_value($db, $mask, 'facture', 'ref', $where, $objsoc, $invoice->date, $mode, false, null, $entity);
  155. if (!preg_match('/([0-9])+/', $numFinal)) {
  156. $this->error = $numFinal;
  157. }
  158. return $numFinal;
  159. }
  160. /**
  161. * Return next free value
  162. *
  163. * @param Societe $objsoc Object third party
  164. * @param string $objforref Object for number to search
  165. * @param string $mode 'next' for next value or 'last' for last value
  166. * @return string Next free value
  167. */
  168. public function getNumRef($objsoc, $objforref, $mode = 'next')
  169. {
  170. return $this->getNextValue($objsoc, $objforref, $mode);
  171. }
  172. }