dolibarr  7.0.0-beta
mod_codeclient_elephant.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2007-2012 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
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 
29 require_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
30 
31 
36 {
37  var $nom='Elephant'; // Nom du modele
38  var $name='Elephant'; // Nom du modele
39  var $code_modifiable; // Code modifiable
40  var $code_modifiable_invalide; // Code modifiable si il est invalide
41  var $code_modifiable_null; // Code modifiables si il est null
42  var $code_null; // Code facultatif
43  var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
44  var $code_auto; // Numerotation automatique
45 
46  var $searchcode; // String de recherche
47  var $numbitcounter; // Nombre de chiffres du compteur
48  var $prefixIsRequired; // Le champ prefix du tiers doit etre renseigne quand on utilise {pre}
49 
50 
54  function __construct()
55  {
56  $this->code_null = 0;
57  $this->code_modifiable = 1;
58  $this->code_modifiable_invalide = 1;
59  $this->code_modifiable_null = 1;
60  $this->code_auto = 1;
61  $this->prefixIsRequired = 0;
62  }
63 
64 
70  function info($langs)
71  {
72  global $conf, $mc;
73  global $form;
74 
75  $langs->load("companies");
76 
77  $disabled = ((! empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : '');
78 
79  $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
80  $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
81  $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
82  $texte.= '<input type="hidden" name="action" value="setModuleOptions">';
83  $texte.= '<input type="hidden" name="param1" value="COMPANY_ELEPHANT_MASK_CUSTOMER">';
84  $texte.= '<input type="hidden" name="param2" value="COMPANY_ELEPHANT_MASK_SUPPLIER">';
85  $texte.= '<table class="nobordernopadding" width="100%">';
86 
87  $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("ThirdParty"),$langs->transnoentities("ThirdParty"));
88  //$tooltip.=$langs->trans("GenericMaskCodes2"); Not required for third party numbering
89  $tooltip.=$langs->trans("GenericMaskCodes3");
90  $tooltip.=$langs->trans("GenericMaskCodes4b");
91  $tooltip.=$langs->trans("GenericMaskCodes5");
92 
93  // Parametrage du prefix customers
94  $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("CustomerCodeModel").'):</td>';
95  $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="'.$conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER.'"'.$disabled.'>',$tooltip,1,1).'</td>';
96 
97  $texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"'.$disabled.'></td>';
98 
99  $texte.= '</tr>';
100 
101  // Parametrage du prefix suppliers
102  $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("SupplierCodeModel").'):</td>';
103  $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value2" value="'.$conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER.'"'.$disabled.'>',$tooltip,1,1).'</td>';
104  $texte.= '</tr>';
105 
106  $texte.= '</table>';
107  $texte.= '</form>';
108 
109  return $texte;
110  }
111 
112 
121  function getExample($langs,$objsoc=0,$type=-1)
122  {
123  if ($type == 0 || $type == -1)
124  {
125  $examplecust = $this->getNextValue($objsoc,0);
126  if (! $examplecust)
127  {
128  $examplecust = $langs->trans('NotConfigured');
129  }
130  if($examplecust=="ErrorBadMask")
131  {
132  $langs->load("errors");
133  $examplecust=$langs->trans($examplecust);
134  }
135  if($examplecust=="ErrorCantUseRazIfNoYearInMask")
136  {
137  $langs->load("errors");
138  $examplecust=$langs->trans($examplecust);
139  }
140  if($examplecust=="ErrorCantUseRazInStartedYearIfNoYearMonthInMask")
141  {
142  $langs->load("errors");
143  $examplecust=$langs->trans($examplecust);
144  }
145  }
146  if ($type == 1 || $type == -1)
147  {
148  $examplesup = $this->getNextValue($objsoc,1);
149  if (! $examplesup)
150  {
151  $examplesup = $langs->trans('NotConfigured');
152  }
153  if($examplesup=="ErrorBadMask")
154  {
155  $langs->load("errors");
156  $examplesup=$langs->trans($examplesup);
157  }
158  if($examplesup=="ErrorCantUseRazIfNoYearInMask")
159  {
160  $langs->load("errors");
161  $examplesup=$langs->trans($examplesup);
162  }
163  if($examplesup=="ErrorCantUseRazInStartedYearIfNoYearMonthInMask")
164  {
165  $langs->load("errors");
166  $examplesup=$langs->trans($examplesup);
167  }
168  }
169 
170  if ($type == 0) return $examplecust;
171  if ($type == 1) return $examplesup;
172  return $examplecust.'<br>'.$examplesup;
173  }
174 
182  function getNextValue($objsoc=0,$type=-1)
183  {
184  global $db,$conf;
185 
186  require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
187 
188  // Get Mask value
189  $mask = '';
190  if ($type==0) $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER;
191  if ($type==1) $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER;
192  if (! $mask)
193  {
194  $this->error='NotConfigured';
195  return '';
196  }
197 
198  $field='';$where='';
199  if ($type == 0)
200  {
201  $field = 'code_client';
202  //$where = ' AND client in (1,2)';
203  }
204  else if ($type == 1)
205  {
206  $field = 'code_fournisseur';
207  //$where = ' AND fournisseur = 1';
208  }
209  else return -1;
210 
211  $now=dol_now();
212 
213  $numFinal=get_next_value($db,$mask,'societe',$field,$where,'',$now);
214 
215  return $numFinal;
216  }
217 
218 
225  {
226  global $conf;
227 
228  $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER;
229  if (preg_match('/\{pre\}/i',$mask)) return 1;
230 
231  $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER;
232  if (preg_match('/\{pre\}/i',$mask)) return 1;
233 
234  return 0;
235  }
236 
237 
252  function verif($db, &$code, $soc, $type)
253  {
254  global $conf;
255 
256  require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
257 
258  $result=0;
259  $code = strtoupper(trim($code));
260 
261  if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
262  {
263  $result=0;
264  }
265  else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) )
266  {
267  $result=-2;
268  }
269  else
270  {
271  // Get Mask value
272  $mask = '';
273  if ($type==0) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER)?'':$conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER;
274  if ($type==1) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER)?'':$conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER;
275  if (! $mask)
276  {
277  $this->error='NotConfigured';
278  return -5;
279  }
280 
281  $result=check_value($mask,$code);
282  if (is_string($result))
283  {
284  $this->error = $result;
285  return -5;
286  }
287  }
288 
289  dol_syslog("mod_codeclient_elephant::verif type=".$type." result=".$result);
290  return $result;
291  }
292 
293 
303  function verif_dispo($db, $code, $soc, $type=0)
304  {
305  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe";
306  if ($type == 1) $sql.= " WHERE code_fournisseur = '".$code."'";
307  else $sql.= " WHERE code_client = '".$code."'";
308  if ($soc->id > 0) $sql.= " AND rowid <> ".$soc->id;
309 
310  $resql=$db->query($sql);
311  if ($resql)
312  {
313  if ($db->num_rows($resql) == 0)
314  {
315  return 0;
316  }
317  else
318  {
319  return -1;
320  }
321  }
322  else
323  {
324  return -2;
325  }
326 
327  }
328 
329 }
330 
Class to manage third party code with elephant rule.
verif($db, &$code, $soc, $type)
Check validity of code according to its rules.
verif_dispo($db, $code, $soc, $type=0)
Renvoi si un code est pris ou non (par autre tiers)
verif_prefixIsUsed()
Check if mask/numbering use prefix.
if(empty($reshook)) $form
View.
Definition: perms.php:103
check_value($mask, $value)
Check value.
Parent class for third parties code generators.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dol_now($mode='gmt')
Return date for now.
info($langs)
Return description of module.
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)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
getNextValue($objsoc=0, $type=-1)
Return next value.
getExample($langs, $objsoc=0, $type=-1)
Return an example of result returned by getNextValue.