dolibarr  7.0.0-beta
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@capnetworks.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 {
36  var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
37  var $error = '';
38 
39 
45  function info()
46  {
47  global $conf,$langs;
48 
49  $langs->load("bills");
50 
51  $form = new Form($this->db);
52 
53  $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
54  $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
55  $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
56  $texte.= '<input type="hidden" name="action" value="updateMask">';
57  $texte.= '<input type="hidden" name="maskconstinvoice" value="FACTURE_MERCURE_MASK_INVOICE">';
58  $texte.= '<input type="hidden" name="maskconstreplacement" value="FACTURE_MERCURE_MASK_REPLACEMENT">';
59  $texte.= '<input type="hidden" name="maskconstcredit" value="FACTURE_MERCURE_MASK_CREDIT">';
60  $texte.= '<input type="hidden" name="maskconstdeposit" value="FACTURE_MERCURE_MASK_DEPOSIT">';
61  $texte.= '<table class="nobordernopadding" width="100%">';
62 
63  $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Invoice"),$langs->transnoentities("Invoice"));
64  $tooltip.=$langs->trans("GenericMaskCodes2");
65  $tooltip.=$langs->trans("GenericMaskCodes3");
66  $tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Invoice"),$langs->transnoentities("Invoice"));
67  $tooltip.=$langs->trans("GenericMaskCodes5");
68 
69  // Parametrage du prefix
70  $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceStandard").'):</td>';
71  $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>';
72 
73  $texte.= '<td align="left" rowspan="3">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
74 
75  $texte.= '</tr>';
76 
77  // Parametrage du prefix des replacement
78  $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceReplacement").'):</td>';
79  $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>';
80  $texte.= '</tr>';
81 
82  // Parametrage du prefix des avoirs
83  $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceAvoir").'):</td>';
84  $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>';
85  $texte.= '</tr>';
86 
87  // Parametrage du prefix des acomptes
88  $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("InvoiceDeposit").'):</td>';
89  $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>';
90  $texte.= '</tr>';
91 
92  $texte.= '</table>';
93  $texte.= '</form>';
94 
95  return $texte;
96  }
97 
103  function getExample()
104  {
105  global $conf,$langs,$mysoc;
106 
107  $old_code_client=$mysoc->code_client;
108  $old_code_type=$mysoc->typent_code;
109  $mysoc->code_client='CCCCCCCCCC';
110  $mysoc->typent_code='TTTTTTTTTT';
111  $numExample = $this->getNextValue($mysoc,'');
112  $mysoc->code_client=$old_code_client;
113  $mysoc->typent_code=$old_code_type;
114 
115  if (! $numExample)
116  {
117  $numExample = 'NotConfigured';
118  }
119  return $numExample;
120  }
121 
130  function getNextValue($objsoc,$facture,$mode='next')
131  {
132  global $db,$conf;
133 
134  require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
135 
136  // Get Mask value
137  $mask = '';
138  if (is_object($facture) && $facture->type == 1)
139  {
140  $mask=$conf->global->FACTURE_MERCURE_MASK_REPLACEMENT;
141  if (! $mask)
142  {
143  $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE;
144  }
145  }
146  else if (is_object($facture) && $facture->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT;
147  else if (is_object($facture) && $facture->type == 3) $mask=$conf->global->FACTURE_MERCURE_MASK_DEPOSIT;
148  else $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE;
149  if (! $mask)
150  {
151  $this->error='NotConfigured';
152  return 0;
153  }
154 
155  $where='';
156  //if ($facture->type == 2) $where.= " AND type = 2";
157  //else $where.=" AND type != 2";
158 
159  $numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc,$facture->date,$mode);
160  if (! preg_match('/([0-9])+/',$numFinal)) $this->error = $numFinal;
161 
162  return $numFinal;
163  }
164 
165 
174  function getNumRef($objsoc,$objforref,$mode='next')
175  {
176  return $this->getNextValue($objsoc,$objforref,$mode);
177  }
178 
179 }
info()
Renvoi la description du modele de numerotation.
if(empty($reshook)) $form
View.
Definition: perms.php:103
Class of numbering module Mercure for invoices.
Class to manage generation of HTML components Only common components must be here.
getExample()
Return an example of number value.
Classe mere des modeles de numerotation des references de facture.
get_next_value($db, $mask, $table, $field, $where='', $objsoc='', $date='', $mode='next', $bentityon=true, $objuser=null)
Return last or next value for a mask (according to area we should not reset)
getNumRef($objsoc, $objforref, $mode='next')
Return next free value.
getNextValue($objsoc, $facture, $mode='next')
Return next value.