dolibarr  9.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  *
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 <http://www.gnu.org/licenses/>.
20  * or see http://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  function info()
54  {
55  global $conf, $langs;
56 
57  $langs->load("bills");
58 
59  $form = new Form($this->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="'.$_SESSION['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  // Parametrage du prefix
78  $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").'):</td>';
79  $texte.= '<td align="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 align="left" rowspan="3">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
82 
83  $texte.= '</tr>';
84 
85  // Parametrage du prefix des replacement
86  $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceReplacement").'):</td>';
87  $texte.= '<td align="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  // Parametrage du prefix des avoirs
91  $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):</td>';
92  $texte.= '<td align="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  // Parametrage du prefix des acomptes
96  $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):</td>';
97  $texte.= '<td align="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  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  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  }
154  else if (is_object($invoice) && $invoice->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT;
155  else if (is_object($invoice) && $invoice->type == 3) $mask=$conf->global->FACTURE_MERCURE_MASK_DEPOSIT;
156  else $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE;
157  if (! $mask)
158  {
159  $this->error='NotConfigured';
160  return 0;
161  }
162 
163  $where='';
164  //if ($facture->type == 2) $where.= " AND type = 2";
165  //else $where.=" AND type != 2";
166 
167  // Get entities
168  $entity = getEntity('invoicenumber', 1, $invoice);
169 
170  $numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc,$invoice->date,$mode,false,null,$entity);
171  if (! preg_match('/([0-9])+/',$numFinal)) $this->error = $numFinal;
172 
173  return $numFinal;
174  }
175 
176 
185  function getNumRef($objsoc,$objforref,$mode='next')
186  {
187  return $this->getNextValue($objsoc,$objforref,$mode);
188  }
189 }
$version
Dolibarr version of the loaded document string.
info()
Renvoi la description du modele de numerotation.
Class of numbering module Mercure for invoices.
Class to manage generation of HTML components Only common components must be here.
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)
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
getExample()
Return an example of number value.
getNextValue($objsoc, $invoice, $mode='next')
Return next value.
Classe mere des modeles de numerotation des references de facture.
getNumRef($objsoc, $objforref, $mode='next')
Return next free value.