dolibarr 20.0.0
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 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 * or see https://www.gnu.org/
23 */
24
30require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
31
32
37{
42 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
43
47 public $error = '';
48
49
56 public function info($langs)
57 {
58 global $db, $langs;
59
60 $langs->load("bills");
61
62 $form = new Form($db);
63
64 $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
65 $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
66 $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
67 $texte .= '<input type="hidden" name="action" value="updateMask">';
68 $texte .= '<input type="hidden" name="maskconstinvoice" value="FACTURE_MERCURE_MASK_INVOICE">';
69 $texte .= '<input type="hidden" name="maskconstreplacement" value="FACTURE_MERCURE_MASK_REPLACEMENT">';
70 $texte .= '<input type="hidden" name="maskconstcredit" value="FACTURE_MERCURE_MASK_CREDIT">';
71 $texte .= '<input type="hidden" name="maskconstdeposit" value="FACTURE_MERCURE_MASK_DEPOSIT">';
72 $texte .= '<table class="nobordernopadding" width="100%">';
73
74 $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice"));
75 $tooltip .= $langs->trans("GenericMaskCodes2");
76 $tooltip .= '<br>';
77 $tooltip .= $langs->trans("GenericMaskCodes3");
78 $tooltip .= '<br>';
79 $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice"));
80 $tooltip .= $langs->trans("GenericMaskCodes5");
81 $tooltip .= '<br>'.$langs->trans("GenericMaskCodes5b");
82
83 // Setting the prefix
84 $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").'):</span></td>';
85 $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskinvoice" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_INVOICE").'">', $tooltip, 1, 1, '', 0, 3, 'tooltipstandardmercure').'</td>';
86
87 $texte .= '<td class="left" rowspan="3">&nbsp; <input type="submit" class="button button-edit reposition smallpaddingimp" name="Button"value="'.$langs->trans("Modify").'"></td>';
88
89 $texte .= '</tr>';
90
91 // Prefix setting of credit note
92 $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):</span></td>';
93 $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskcredit" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_CREDIT").'">', $tooltip, 1, 1, '', 0, 3, 'tooltipcreditnotemercure').'</td>';
94 $texte .= '</tr>';
95
96 // Prefix setting of replacement invoices
97 if (!getDolGlobalString('INVOICE_DISABLE_REPLACEMENT')) {
98 $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceReplacement").'):</span></td>';
99 $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskreplacement" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_REPLACEMENT").'">', $tooltip, 1, 1, '', 0, 3, 'tooltipreplacementmercure').'</td>';
100 $texte .= '</tr>';
101 }
102
103 // Prefix setting of deposit
104 $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):</span></td>';
105 $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskdeposit" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_DEPOSIT").'">', $tooltip, 1, 1, '', 0, 3, 'tooltipdownpaymentmercure').'</td>';
106 $texte .= '</tr>';
107
108 $texte .= '</table>';
109 $texte .= '</form>';
110
111 return $texte;
112 }
113
119 public function getExample()
120 {
121 global $mysoc;
122
123 $old_code_client = $mysoc->code_client;
124 $old_code_type = $mysoc->typent_code;
125 $mysoc->code_client = 'CCCCCCCCCC';
126 $mysoc->typent_code = 'TTTTTTTTTT';
127 $numExample = $this->getNextValue($mysoc, '');
128 $mysoc->code_client = $old_code_client;
129 $mysoc->typent_code = $old_code_type;
130
131 if (!$numExample) {
132 $numExample = 'NotConfigured';
133 }
134 return $numExample;
135 }
136
145 public function getNextValue($objsoc, $invoice, $mode = 'next')
146 {
147 global $db;
148
149 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
150
151 // Get Mask value
152 $mask = '';
153 if (is_object($invoice) && $invoice->type == 1) {
154 $mask = getDolGlobalString('FACTURE_MERCURE_MASK_REPLACEMENT', getDolGlobalString('FACTURE_MERCURE_MASK_INVOICE'));
155 } elseif (is_object($invoice) && $invoice->type == 2) {
156 $mask = getDolGlobalString('FACTURE_MERCURE_MASK_CREDIT');
157 } elseif (is_object($invoice) && $invoice->type == 3) {
158 $mask = getDolGlobalString('FACTURE_MERCURE_MASK_DEPOSIT');
159 } else {
160 $mask = getDolGlobalString('FACTURE_MERCURE_MASK_INVOICE');
161 }
162 if (!$mask) {
163 $this->error = 'NotConfigured';
164 return 0;
165 }
166
167 $where = '';
168 //if ($facture->type == 2) $where.= " AND type = 2";
169 //else $where.=" AND type != 2";
170
171 // Get entities
172 $entity = getEntity('invoicenumber', 1, $invoice);
173 $numFinal = get_next_value($db, $mask, 'facture', 'ref', $where, $objsoc, (empty($invoice) ? dol_now() : $invoice->date), $mode, false, null, $entity);
174 if (!preg_match('/([0-9])+/', $numFinal)) {
175 $this->error = $numFinal;
176 }
177
178 return $numFinal;
179 }
180
181
191 public function getNumRef($objsoc, $objforref, $mode = 'next')
192 {
193 return $this->getNextValue($objsoc, $objforref, $mode);
194 }
195}
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.
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.
get_next_value($db, $mask, $table, $field, $where='', $objsoc='', $date='', $mode='next', $bentityon=true, $objuser=null, $forceentity=null)
Return last or next value for a mask (according to area we should not reset)
dol_now($mode='auto')
Return date for now.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.