dolibarr  16.0.5
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  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  * or see https://www.gnu.org/
21  */
22 
28 require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
29 
30 
35 {
40  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
41 
45  public $error = '';
46 
47 
53  public function info()
54  {
55  global $db, $conf, $langs;
56 
57  $langs->load("bills");
58 
59  $form = new Form($db);
60 
61  $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
62  $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
63  $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
64  $texte .= '<input type="hidden" name="action" value="updateMask">';
65  $texte .= '<input type="hidden" name="maskconstinvoice" value="FACTURE_MERCURE_MASK_INVOICE">';
66  $texte .= '<input type="hidden" name="maskconstreplacement" value="FACTURE_MERCURE_MASK_REPLACEMENT">';
67  $texte .= '<input type="hidden" name="maskconstcredit" value="FACTURE_MERCURE_MASK_CREDIT">';
68  $texte .= '<input type="hidden" name="maskconstdeposit" value="FACTURE_MERCURE_MASK_DEPOSIT">';
69  $texte .= '<table class="nobordernopadding" width="100%">';
70 
71  $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice"));
72  $tooltip .= $langs->trans("GenericMaskCodes2");
73  $tooltip .= $langs->trans("GenericMaskCodes3");
74  $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Invoice"), $langs->transnoentities("Invoice"));
75  $tooltip .= $langs->trans("GenericMaskCodes5");
76 
77  // Setting the prefix
78  $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").'):</span></td>';
79  $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskinvoice" value="'.$conf->global->FACTURE_MERCURE_MASK_INVOICE.'">', $tooltip, 1, 1).'</td>';
80 
81  $texte .= '<td class="left" rowspan="3">&nbsp; <input type="submit" class="button button-edit" name="Button"value="'.$langs->trans("Modify").'"></td>';
82 
83  $texte .= '</tr>';
84 
85  // Prefix setting of replacement invoices
86  $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceReplacement").'):</span></td>';
87  $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskreplacement" value="'.$conf->global->FACTURE_MERCURE_MASK_REPLACEMENT.'">', $tooltip, 1, 1).'</td>';
88  $texte .= '</tr>';
89 
90  // Prefix setting of credit note
91  $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):</span></td>';
92  $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskcredit" value="'.$conf->global->FACTURE_MERCURE_MASK_CREDIT.'">', $tooltip, 1, 1).'</td>';
93  $texte .= '</tr>';
94 
95  // Prefix setting of deposit
96  $texte .= '<tr><td><span class="opacitymedium">'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):</span></td>';
97  $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskdeposit" value="'.$conf->global->FACTURE_MERCURE_MASK_DEPOSIT.'">', $tooltip, 1, 1).'</td>';
98  $texte .= '</tr>';
99 
100  $texte .= '</table>';
101  $texte .= '</form>';
102 
103  return $texte;
104  }
105 
111  public function getExample()
112  {
113  global $conf, $langs, $mysoc;
114 
115  $old_code_client = $mysoc->code_client;
116  $old_code_type = $mysoc->typent_code;
117  $mysoc->code_client = 'CCCCCCCCCC';
118  $mysoc->typent_code = 'TTTTTTTTTT';
119  $numExample = $this->getNextValue($mysoc, '');
120  $mysoc->code_client = $old_code_client;
121  $mysoc->typent_code = $old_code_type;
122 
123  if (!$numExample) {
124  $numExample = 'NotConfigured';
125  }
126  return $numExample;
127  }
128 
137  public function getNextValue($objsoc, $invoice, $mode = 'next')
138  {
139  global $db, $conf;
140 
141  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
142 
143  // Get Mask value
144  $mask = '';
145  if (is_object($invoice) && $invoice->type == 1) {
146  $mask = $conf->global->FACTURE_MERCURE_MASK_REPLACEMENT;
147  if (!$mask) {
148  $mask = $conf->global->FACTURE_MERCURE_MASK_INVOICE;
149  }
150  } elseif (is_object($invoice) && $invoice->type == 2) {
151  $mask = $conf->global->FACTURE_MERCURE_MASK_CREDIT;
152  } elseif (is_object($invoice) && $invoice->type == 3) {
153  $mask = $conf->global->FACTURE_MERCURE_MASK_DEPOSIT;
154  } else {
155  $mask = $conf->global->FACTURE_MERCURE_MASK_INVOICE;
156  }
157  if (!$mask) {
158  $this->error = 'NotConfigured';
159  return 0;
160  }
161 
162  $where = '';
163  //if ($facture->type == 2) $where.= " AND type = 2";
164  //else $where.=" AND type != 2";
165 
166  // Get entities
167  $entity = getEntity('invoicenumber', 1, $invoice);
168 
169  $numFinal = get_next_value($db, $mask, 'facture', 'ref', $where, $objsoc, $invoice->date, $mode, false, null, $entity);
170  if (!preg_match('/([0-9])+/', $numFinal)) {
171  $this->error = $numFinal;
172  }
173 
174  return $numFinal;
175  }
176 
177 
186  public function getNumRef($objsoc, $objforref, $mode = 'next')
187  {
188  return $this->getNextValue($objsoc, $objforref, $mode);
189  }
190 }
mod_facture_mercure\info
info()
Returns the description of the numbering model.
Definition: mod_facture_mercure.php:53
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
getEntity
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Definition: functions.lib.php:148
ModeleNumRefFactures
Parent class of invoice reference numbering templates.
Definition: modules_facture.php:79
mod_facture_mercure\getNextValue
getNextValue($objsoc, $invoice, $mode='next')
Return next value.
Definition: mod_facture_mercure.php:137
mod_facture_mercure
Class of numbering module Mercure for invoices.
Definition: mod_facture_mercure.php:34
get_next_value
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)
Definition: functions2.lib.php:970
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
mod_facture_mercure\getExample
getExample()
Return an example of number value.
Definition: mod_facture_mercure.php:111
mod_facture_mercure\getNumRef
getNumRef($objsoc, $objforref, $mode='next')
Return next free value.
Definition: mod_facture_mercure.php:186