dolibarr  17.0.4
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 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 
29 require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
30 
31 
36 {
41  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
42 
46  public $error = '';
47 
48 
54  public function info()
55  {
56  global $db, $langs;
57 
58  $langs->load("bills");
59 
60  $form = new Form($db);
61 
62  $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
63  $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
64  $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
65  $texte .= '<input type="hidden" name="action" value="updateMask">';
66  $texte .= '<input type="hidden" name="maskconstinvoice" value="FACTURE_MERCURE_MASK_INVOICE">';
67  $texte .= '<input type="hidden" name="maskconstreplacement" value="FACTURE_MERCURE_MASK_REPLACEMENT">';
68  $texte .= '<input type="hidden" name="maskconstcredit" value="FACTURE_MERCURE_MASK_CREDIT">';
69  $texte .= '<input type="hidden" name="maskconstdeposit" value="FACTURE_MERCURE_MASK_DEPOSIT">';
70  $texte .= '<table class="nobordernopadding" width="100%">';
71 
72  $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice"));
73  $tooltip .= $langs->trans("GenericMaskCodes2");
74  $tooltip .= $langs->trans("GenericMaskCodes3");
75  $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice"));
76  $tooltip .= $langs->trans("GenericMaskCodes5");
77 
78  // Setting the prefix
79  $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").'):</span></td>';
80  $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskinvoice" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_INVOICE").'">', $tooltip, 1, 1).'</td>';
81 
82  $texte .= '<td class="left" rowspan="3">&nbsp; <input type="submit" class="button button-edit" name="Button"value="'.$langs->trans("Modify").'"></td>';
83 
84  $texte .= '</tr>';
85 
86  // Prefix setting of replacement invoices
87  $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceReplacement").'):</span></td>';
88  $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskreplacement" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_REPLACEMENT").'">', $tooltip, 1, 1).'</td>';
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).'</td>';
94  $texte .= '</tr>';
95 
96  // Prefix setting of deposit
97  $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):</span></td>';
98  $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskdeposit" value="'.getDolGlobalString("FACTURE_MERCURE_MASK_DEPOSIT").'">', $tooltip, 1, 1).'</td>';
99  $texte .= '</tr>';
100 
101  $texte .= '</table>';
102  $texte .= '</form>';
103 
104  return $texte;
105  }
106 
112  public function getExample()
113  {
114  global $conf, $langs, $mysoc;
115 
116  $old_code_client = $mysoc->code_client;
117  $old_code_type = $mysoc->typent_code;
118  $mysoc->code_client = 'CCCCCCCCCC';
119  $mysoc->typent_code = 'TTTTTTTTTT';
120  $numExample = $this->getNextValue($mysoc, '');
121  $mysoc->code_client = $old_code_client;
122  $mysoc->typent_code = $old_code_type;
123 
124  if (!$numExample) {
125  $numExample = 'NotConfigured';
126  }
127  return $numExample;
128  }
129 
138  public function getNextValue($objsoc, $invoice, $mode = 'next')
139  {
140  global $db;
141 
142  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
143 
144  // Get Mask value
145  $mask = '';
146  if (is_object($invoice) && $invoice->type == 1) {
147  $mask = getDolGlobalString('FACTURE_MERCURE_MASK_REPLACEMENT', getDolGlobalString('FACTURE_MERCURE_MASK_INVOICE'));
148  } elseif (is_object($invoice) && $invoice->type == 2) {
149  $mask = getDolGlobalString('FACTURE_MERCURE_MASK_CREDIT');
150  } elseif (is_object($invoice) && $invoice->type == 3) {
151  $mask = getDolGlobalString('FACTURE_MERCURE_MASK_DEPOSIT');
152  } else {
153  $mask = getDolGlobalString('FACTURE_MERCURE_MASK_INVOICE');
154  }
155  if (!$mask) {
156  $this->error = 'NotConfigured';
157  return 0;
158  }
159 
160  $where = '';
161  //if ($facture->type == 2) $where.= " AND type = 2";
162  //else $where.=" AND type != 2";
163 
164  // Get entities
165  $entity = getEntity('invoicenumber', 1, $invoice);
166 
167  $numFinal = get_next_value($db, $mask, 'facture', 'ref', $where, $objsoc, $invoice->date, $mode, false, null, $entity);
168  if (!preg_match('/([0-9])+/', $numFinal)) {
169  $this->error = $numFinal;
170  }
171 
172  return $numFinal;
173  }
174 
175 
184  public function getNumRef($objsoc, $objforref, $mode = 'next')
185  {
186  return $this->getNextValue($objsoc, $objforref, $mode);
187  }
188 }
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.
info()
Returns the description of the numbering model.
getNextValue($objsoc, $invoice, $mode='next')
Return next value.
getExample()
Return an example of number value.
getNumRef($objsoc, $objforref, $mode='next')
Return next free value.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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)
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.