dolibarr  13.0.2
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  * Copyright (C) 2020 Frédéric France <frederic.france@netlogic.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  * or see https://www.gnu.org/
22  */
23 
30 require_once DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php';
31 
32 
37 {
41  public $name = 'Elephant';
42 
46  public $code_modifiable;
47 
51  public $code_modifiable_invalide;
52 
56  public $code_modifiable_null;
57 
61  public $code_null;
62 
67  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
68 
72  public $code_auto;
73 
77  public $searchcode;
78 
82  public $numbitcounter;
83 
87  public $prefixIsRequired;
88 
89 
93  public function __construct()
94  {
95  $this->code_null = 0;
96  $this->code_modifiable = 1;
97  $this->code_modifiable_invalide = 1;
98  $this->code_modifiable_null = 1;
99  $this->code_auto = 1;
100  $this->prefixIsRequired = 0;
101  }
102 
103 
110  public function info($langs)
111  {
112  global $conf, $mc;
113  global $form;
114 
115  $langs->load("companies");
116 
117  $disabled = ((!empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : '');
118 
119  $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
120  $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
121  $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
122  $texte .= '<input type="hidden" name="action" value="setModuleOptions">';
123  $texte .= '<input type="hidden" name="param1" value="COMPANY_ELEPHANT_MASK_CUSTOMER">';
124  $texte .= '<input type="hidden" name="param2" value="COMPANY_ELEPHANT_MASK_SUPPLIER">';
125  $texte .= '<table class="nobordernopadding" width="100%">';
126 
127  $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("ThirdParty"), $langs->transnoentities("ThirdParty"));
128  //$tooltip.=$langs->trans("GenericMaskCodes2"); Not required for third party numbering
129  $tooltip .= $langs->trans("GenericMaskCodes3");
130  $tooltip .= $langs->trans("GenericMaskCodes4b");
131  $tooltip .= $langs->trans("GenericMaskCodes5");
132 
133  // Parametrage du prefix customers
134  $texte .= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("CustomerCodeModel").'):</td>';
135  $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="'.$conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER.'"'.$disabled.'>', $tooltip, 1, 1).'</td>';
136 
137  $texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"'.$disabled.'></td>';
138 
139  $texte .= '</tr>';
140 
141  // Parametrage du prefix suppliers
142  $texte .= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("SupplierCodeModel").'):</td>';
143  $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value2" value="'.$conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER.'"'.$disabled.'>', $tooltip, 1, 1).'</td>';
144  $texte .= '</tr>';
145 
146  $texte .= '</table>';
147  $texte .= '</form>';
148 
149  return $texte;
150  }
151 
152 
161  public function getExample($langs, $objsoc = 0, $type = -1)
162  {
163  $examplecust = '';
164  $examplesup = '';
165  $errmsg = array(
166  "ErrorBadMask",
167  "ErrorCantUseRazIfNoYearInMask",
168  "ErrorCantUseRazInStartedYearIfNoYearMonthInMask",
169  );
170  if ($type != 1) {
171  $examplecust = $this->getNextValue($objsoc, 0);
172  if (!$examplecust) {
173  $examplecust = $langs->trans('NotConfigured');
174  }
175  if (in_array($examplecust, $errmsg)) {
176  $langs->load("errors");
177  $examplecust = $langs->trans($examplecust);
178  }
179  }
180  if ($type != 0) {
181  $examplesup = $this->getNextValue($objsoc, 1);
182  if (!$examplesup) {
183  $examplesup = $langs->trans('NotConfigured');
184  }
185  if (in_array($examplesup, $errmsg)) {
186  $langs->load("errors");
187  $examplesup = $langs->trans($examplesup);
188  }
189  }
190 
191  if ($type == 0) {
192  return $examplecust;
193  } elseif ($type == 1) {
194  return $examplesup;
195  } else {
196  return $examplecust.'<br>'.$examplesup;
197  }
198  }
199 
207  public function getNextValue($objsoc = 0, $type = -1)
208  {
209  global $db, $conf;
210 
211  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
212 
213  // Get Mask value
214  $mask = '';
215  if ($type == 0) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER) ? '' : $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER;
216  if ($type == 1) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER) ? '' : $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER;
217  if (!$mask)
218  {
219  $this->error = 'NotConfigured';
220  return '';
221  }
222 
223  $field = ''; $where = '';
224  if ($type == 0)
225  {
226  $field = 'code_client';
227  //$where = ' AND client in (1,2)';
228  } elseif ($type == 1)
229  {
230  $field = 'code_fournisseur';
231  //$where = ' AND fournisseur = 1';
232  } else return -1;
233 
234  $now = dol_now();
235 
236  $numFinal = get_next_value($db, $mask, 'societe', $field, $where, '', $now);
237 
238  return $numFinal;
239  }
240 
241 
242  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
248  public function verif_prefixIsUsed()
249  {
250  // phpcs:enable
251  global $conf;
252 
253  $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER;
254  if (preg_match('/\{pre\}/i', $mask)) return 1;
255 
256  $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER;
257  if (preg_match('/\{pre\}/i', $mask)) return 1;
258 
259  return 0;
260  }
261 
262 
278  public function verif($db, &$code, $soc, $type)
279  {
280  global $conf;
281 
282  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
283 
284  $result = 0;
285  $code = strtoupper(trim($code));
286 
287  if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
288  {
289  $result = 0;
290  } elseif (empty($code) && (!$this->code_null || !empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)))
291  {
292  $result = -2;
293  } else {
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  $result = check_value($mask, $code);
304  if (is_string($result))
305  {
306  $this->error = $result;
307  return -6;
308  }
309  }
310 
311  dol_syslog("mod_codeclient_elephant::verif type=".$type." result=".$result);
312  return $result;
313  }
314 
315 
316  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
326  public function verif_dispo($db, $code, $soc, $type = 0)
327  {
328  // phpcs:enable
329  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe";
330  if ($type == 1) $sql .= " WHERE code_fournisseur = '".$db->escape($code)."'";
331  else $sql .= " WHERE code_client = '".$db->escape($code)."'";
332  if ($soc->id > 0) $sql .= " AND rowid <> ".$soc->id;
333 
334  $resql = $db->query($sql);
335  if ($resql)
336  {
337  if ($db->num_rows($resql) == 0)
338  {
339  return 0;
340  } else {
341  return -1;
342  }
343  } else {
344  return -2;
345  }
346  }
347 }
Class to manage third party code with elephant rule.
verif($db, &$code, $soc, $type)
Check validity of code according to its rules.
dol_now($mode= 'auto')
Return date for now.
verif_dispo($db, $code, $soc, $type=0)
Renvoi si un code est pris ou non (par autre tiers)
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)
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= '', $logcontext=null)
Write log message into outputs.
info($langs)
Return description of module.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
getNextValue($objsoc=0, $type=-1)
Return next value.
getExample($langs, $objsoc=0, $type=-1)
Return an example of result returned by getNextValue.