dolibarr  13.0.2
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>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").'):</td>';
79  $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" 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" value="'.$langs->trans("Modify").'" name="Button"></td>';
82 
83  $texte .= '</tr>';
84 
85  // Prefix setting of replacement invoices
86  $texte .= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceReplacement").'):</td>';
87  $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" 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>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):</td>';
92  $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" 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>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):</td>';
97  $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" 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  {
125  $numExample = 'NotConfigured';
126  }
127  return $numExample;
128  }
129 
138  public function getNextValue($objsoc, $invoice, $mode = 'next')
139  {
140  global $db, $conf;
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  {
148  $mask = $conf->global->FACTURE_MERCURE_MASK_REPLACEMENT;
149  if (!$mask)
150  {
151  $mask = $conf->global->FACTURE_MERCURE_MASK_INVOICE;
152  }
153  } elseif (is_object($invoice) && $invoice->type == 2) $mask = $conf->global->FACTURE_MERCURE_MASK_CREDIT;
154  elseif (is_object($invoice) && $invoice->type == 3) $mask = $conf->global->FACTURE_MERCURE_MASK_DEPOSIT;
155  else $mask = $conf->global->FACTURE_MERCURE_MASK_INVOICE;
156  if (!$mask)
157  {
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)) $this->error = $numFinal;
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 }
getNextValue($objsoc, $invoice, $mode= 'next')
Return next value.
info()
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)
Class of numbering module Mercure for invoices.
Class to manage generation of HTML components Only common components must be here.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
getExample()
Return an example of number value.
Parent class of invoice reference numbering templates.
getNumRef($objsoc, $objforref, $mode= 'next')
Return next free value.