dolibarr 23.0.3
mod_facture_mercure.php
Go to the documentation of this file.
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 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
8 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024 Nick Fragoulis
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 * or see https://www.gnu.org/
25 */
26
32require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
33
34
39{
43 public $name = 'Mercure';
44
48 public $position = 50;
49
54 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
55
59 public $error = '';
60
61
68 public function info($langs)
69 {
70 global $db, $langs;
71
72 $langs->load("bills");
73
74 $form = new Form($db);
75
76 $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
77 $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
78 $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
79 $texte .= '<input type="hidden" name="action" value="updateMask">';
80 $texte .= '<input type="hidden" name="maskconstinvoice" value="FACTURE_MERCURE_MASK_INVOICE">';
81 $texte .= '<input type="hidden" name="maskconstreplacement" value="FACTURE_MERCURE_MASK_REPLACEMENT">';
82 $texte .= '<input type="hidden" name="maskconstcredit" value="FACTURE_MERCURE_MASK_CREDIT">';
83 $texte .= '<input type="hidden" name="maskconstdeposit" value="FACTURE_MERCURE_MASK_DEPOSIT">';
84 $texte .= '<input type="hidden" name="page_y" value="">';
85
86 $texte .= '<table class="nobordernopadding centpercent">';
87
88 $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice"));
89 $tooltip .= $langs->trans("GenericMaskCodes1");
90 $tooltip .= '<br>';
91 $tooltip .= $langs->trans("GenericMaskCodes2");
92 $tooltip .= '<br>';
93 $tooltip .= $langs->trans("GenericMaskCodes3");
94 $tooltip .= '<br>';
95 $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice"));
96 $tooltip .= $langs->trans("GenericMaskCodes5");
97 $tooltip .= '<br>'.$langs->trans("GenericMaskCodes5b");
98
99 // Setting the prefix
100 $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").'):</span></td>';
101 $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskinvoice" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_INVOICE").'">', $tooltip, 1, 'help', '', 0, 3, 'tooltipstandardmercure').'</td>';
102
103 $texte .= '<td class="left" rowspan="3">&nbsp; <input type="submit" class="button button-edit reposition smallpaddingimp" name="Button" value="'.$langs->trans("Save").'"></td>';
104
105 $texte .= '</tr>';
106
107 // Prefix setting of credit note
108 $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):</span></td>';
109 $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskcredit" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_CREDIT").'">', $tooltip, 1, 'help', '', 0, 3, 'tooltipcreditnotemercure').'</td>';
110 $texte .= '</tr>';
111
112 // Prefix setting of replacement invoices
113 if (!getDolGlobalString('INVOICE_DISABLE_REPLACEMENT')) {
114 $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceReplacement").'):</span></td>';
115 $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskreplacement" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_REPLACEMENT").'">', $tooltip, 1, 'help', '', 0, 3, 'tooltipreplacementmercure').'</td>';
116 $texte .= '</tr>';
117 }
118
119 // Prefix setting of deposit
120 if (!getDolGlobalString('INVOICE_DISABLE_DEPOSIT')) {
121 $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):</span></td>';
122 $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskdeposit" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_DEPOSIT").'">', $tooltip, 1, 'help', '', 0, 3, 'tooltipdownpaymentmercure').'</td>';
123 $texte .= '</tr>';
124 }
125
126 $texte .= '</table>';
127 $texte .= '</form>';
128
129 return $texte;
130 }
131
137 public function getExample()
138 {
139 global $mysoc;
140
141 $old_code_client = $mysoc->code_client;
142 $old_code_type = $mysoc->typent_code;
143 $mysoc->code_client = 'CCCCCCCCCC';
144 $mysoc->typent_code = 'TTTTTTTTTT';
145 $numExample = $this->getNextValue($mysoc, null);
146 $mysoc->code_client = $old_code_client;
147 $mysoc->typent_code = $old_code_type;
148
149 if (!$numExample) {
150 $numExample = 'NotConfigured';
151 }
152 return $numExample;
153 }
154
163 public function getNextValue($objsoc, $invoice, $mode = 'next')
164 {
165 global $db;
166
167 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
168
169 // Get Mask value
170 $mask = '';
171 if (is_object($invoice) && $invoice->type == 1) {
172 $mask = getDolGlobalString('FACTURE_MERCURE_MASK_REPLACEMENT', getDolGlobalString('FACTURE_MERCURE_MASK_INVOICE'));
173 } elseif (is_object($invoice) && $invoice->type == 2) {
174 $mask = getDolGlobalString('FACTURE_MERCURE_MASK_CREDIT');
175 } elseif (is_object($invoice) && $invoice->type == 3 && !getDolGlobalString('INVOICE_DISABLE_DEPOSIT')) {
176 $mask = getDolGlobalString('FACTURE_MERCURE_MASK_DEPOSIT');
177 } else {
178 $mask = getDolGlobalString('FACTURE_MERCURE_MASK_INVOICE');
179 }
180 if (!$mask) {
181 $this->error = 'NotConfigured';
182 return 0;
183 }
184
185 $where = '';
186 //if ($facture->type == 2) $where.= " AND type = 2";
187 //else $where.=" AND type != 2";
188
189 // Get entities
190 $entity = getEntity('invoicenumber', 1, $invoice);
191
192 $numFinal = get_next_value($db, $mask, 'facture', 'ref', $where, $objsoc, (empty($invoice) ? dol_now() : $invoice->date), $mode, false, null, $entity);
193 if (!preg_match('/([0-9])+/', $numFinal)) {
194 $this->error = $numFinal;
195 }
196
197 return $numFinal;
198 }
199
200
210 public function getNumRef($objsoc, $objforref, $mode = 'next')
211 {
212 return $this->getNextValue($objsoc, $objforref, $mode);
213 }
214}
Class to manage generation of HTML components Only common components must be here.
Parent class of invoice reference numbering templates.
Class of numbering module Mercure for invoices.
getNextValue($objsoc, $invoice, $mode='next')
Return next value not used or last value used.
getExample()
Return an example of number value.
getNumRef($objsoc, $objforref, $mode='next')
Return next free value.
info($langs)
Returns the description of the numbering model.
global $mysoc
get_next_value($db, $mask, $table, $field, $where='', $objsoc='', $date='', $mode='next', $bentityon=true, $objuser=null, $forceentity=null, $objbookkeeping=null)
Return last or next value for a mask (according to area we should not reset)
dol_now($mode='gmt')
Return date for now.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.