dolibarr  9.0.0
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@inodbox.com>
5  * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2013-2018 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 {
42  public $nom='Elephant';
43 
47  public $name='Elephant';
48 
49  public $code_modifiable; // Code modifiable
50 
51  public $code_modifiable_invalide; // Code modifiable si il est invalide
52 
53  public $code_modifiable_null; // Code modifiables si il est null
54 
55  public $code_null; // Code facultatif
56 
61  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
62 
63  public $code_auto; // Numerotation automatique
64 
65  public $searchcode; // String de recherche
66 
67  public $numbitcounter; // Nombre de chiffres du compteur
68 
69  public $prefixIsRequired; // Le champ prefix du tiers doit etre renseigne quand on utilise {pre}
70 
71 
75  function __construct()
76  {
77  $this->code_null = 0;
78  $this->code_modifiable = 1;
79  $this->code_modifiable_invalide = 1;
80  $this->code_modifiable_null = 1;
81  $this->code_auto = 1;
82  $this->prefixIsRequired = 0;
83  }
84 
85 
91  function info($langs)
92  {
93  global $conf, $mc;
94  global $form;
95 
96  $langs->load("companies");
97 
98  $disabled = ((! empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : '');
99 
100  $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
101  $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
102  $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
103  $texte.= '<input type="hidden" name="action" value="setModuleOptions">';
104  $texte.= '<input type="hidden" name="param1" value="COMPANY_ELEPHANT_MASK_CUSTOMER">';
105  $texte.= '<input type="hidden" name="param2" value="COMPANY_ELEPHANT_MASK_SUPPLIER">';
106  $texte.= '<table class="nobordernopadding" width="100%">';
107 
108  $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("ThirdParty"),$langs->transnoentities("ThirdParty"));
109  //$tooltip.=$langs->trans("GenericMaskCodes2"); Not required for third party numbering
110  $tooltip.=$langs->trans("GenericMaskCodes3");
111  $tooltip.=$langs->trans("GenericMaskCodes4b");
112  $tooltip.=$langs->trans("GenericMaskCodes5");
113 
114  // Parametrage du prefix customers
115  $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("CustomerCodeModel").'):</td>';
116  $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>';
117 
118  $texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"'.$disabled.'></td>';
119 
120  $texte.= '</tr>';
121 
122  // Parametrage du prefix suppliers
123  $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("SupplierCodeModel").'):</td>';
124  $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>';
125  $texte.= '</tr>';
126 
127  $texte.= '</table>';
128  $texte.= '</form>';
129 
130  return $texte;
131  }
132 
133 
142  function getExample($langs,$objsoc=0,$type=-1)
143  {
144  if ($type == 0 || $type == -1)
145  {
146  $examplecust = $this->getNextValue($objsoc,0);
147  if (! $examplecust)
148  {
149  $examplecust = $langs->trans('NotConfigured');
150  }
151  if($examplecust=="ErrorBadMask")
152  {
153  $langs->load("errors");
154  $examplecust=$langs->trans($examplecust);
155  }
156  if($examplecust=="ErrorCantUseRazIfNoYearInMask")
157  {
158  $langs->load("errors");
159  $examplecust=$langs->trans($examplecust);
160  }
161  if($examplecust=="ErrorCantUseRazInStartedYearIfNoYearMonthInMask")
162  {
163  $langs->load("errors");
164  $examplecust=$langs->trans($examplecust);
165  }
166  }
167  if ($type == 1 || $type == -1)
168  {
169  $examplesup = $this->getNextValue($objsoc,1);
170  if (! $examplesup)
171  {
172  $examplesup = $langs->trans('NotConfigured');
173  }
174  if($examplesup=="ErrorBadMask")
175  {
176  $langs->load("errors");
177  $examplesup=$langs->trans($examplesup);
178  }
179  if($examplesup=="ErrorCantUseRazIfNoYearInMask")
180  {
181  $langs->load("errors");
182  $examplesup=$langs->trans($examplesup);
183  }
184  if($examplesup=="ErrorCantUseRazInStartedYearIfNoYearMonthInMask")
185  {
186  $langs->load("errors");
187  $examplesup=$langs->trans($examplesup);
188  }
189  }
190 
191  if ($type == 0) return $examplecust;
192  if ($type == 1) return $examplesup;
193  return $examplecust.'<br>'.$examplesup;
194  }
195 
203  function getNextValue($objsoc=0,$type=-1)
204  {
205  global $db,$conf;
206 
207  require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
208 
209  // Get Mask value
210  $mask = '';
211  if ($type==0) $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER;
212  if ($type==1) $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER;
213  if (! $mask)
214  {
215  $this->error='NotConfigured';
216  return '';
217  }
218 
219  $field='';$where='';
220  if ($type == 0)
221  {
222  $field = 'code_client';
223  //$where = ' AND client in (1,2)';
224  }
225  else if ($type == 1)
226  {
227  $field = 'code_fournisseur';
228  //$where = ' AND fournisseur = 1';
229  }
230  else return -1;
231 
232  $now=dol_now();
233 
234  $numFinal=get_next_value($db,$mask,'societe',$field,$where,'',$now);
235 
236  return $numFinal;
237  }
238 
239 
240  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
247  {
248  // phpcs:enable
249  global $conf;
250 
251  $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER;
252  if (preg_match('/\{pre\}/i',$mask)) return 1;
253 
254  $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER;
255  if (preg_match('/\{pre\}/i',$mask)) return 1;
256 
257  return 0;
258  }
259 
260 
275  function verif($db, &$code, $soc, $type)
276  {
277  global $conf;
278 
279  require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
280 
281  $result=0;
282  $code = strtoupper(trim($code));
283 
284  if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
285  {
286  $result=0;
287  }
288  else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) )
289  {
290  $result=-2;
291  }
292  else
293  {
294  // Get Mask value
295  $mask = '';
296  if ($type==0) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER)?'':$conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER;
297  if ($type==1) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER)?'':$conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER;
298  if (! $mask)
299  {
300  $this->error='NotConfigured';
301  return -5;
302  }
303 
304  $result=check_value($mask,$code);
305  if (is_string($result))
306  {
307  $this->error = $result;
308  return -5;
309  }
310  }
311 
312  dol_syslog("mod_codeclient_elephant::verif type=".$type." result=".$result);
313  return $result;
314  }
315 
316 
317  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
327  function verif_dispo($db, $code, $soc, $type=0)
328  {
329  // phpcs:enable
330  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe";
331  if ($type == 1) $sql.= " WHERE code_fournisseur = '".$code."'";
332  else $sql.= " WHERE code_client = '".$code."'";
333  if ($soc->id > 0) $sql.= " AND rowid <> ".$soc->id;
334 
335  $resql=$db->query($sql);
336  if ($resql)
337  {
338  if ($db->num_rows($resql) == 0)
339  {
340  return 0;
341  }
342  else
343  {
344  return -1;
345  }
346  }
347  else
348  {
349  return -2;
350  }
351  }
352 }
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:1053
Class to manage third party code with elephant rule.
$version
Dolibarr version of the loaded document string.
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.
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.
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)
dol_now($mode='gmt')
Return date for now.
info($langs)
Return description of module.
getNextValue($objsoc=0, $type=-1)
Return next value.
getExample($langs, $objsoc=0, $type=-1)
Return an example of result returned by getNextValue.