dolibarr  18.0.0-alpha
mod_member_simple.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2021 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2022 Frédéric France <frederic.france@netlogic.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  * or see https://www.gnu.org/
18  */
19 
26 require_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_member.class.php';
27 
28 
33 {
38  public $version = 'dolibarr';
39 
45  public $prefix = '';
46 
50  public $error = '';
51 
55  public $name = 'Simple';
56 
60  public $code_auto = 1;
61 
67  public function info()
68  {
69  global $langs;
70  return $langs->trans("SimpleRefNumRefModelDesc");
71  }
72 
73 
79  public function getExample()
80  {
81  return "1";
82  }
83 
84 
91  public function canBeActivated()
92  {
93  global $conf, $langs, $db;
94 
95  $coyymm = '';
96  $max = '';
97 
98  $sql = "SELECT MAX(CAST(ref AS SIGNED)) as max";
99  $sql .= " FROM ".MAIN_DB_PREFIX."adherent";
100  $sql .= " WHERE entity = ".$conf->entity;
101  $resql = $db->query($sql);
102  if ($resql) {
103  $row = $db->fetch_row($resql);
104  if ($row) {
105  $coyymm = substr($row[0], 0, 6);
106  $max = $row[0];
107  }
108  }
109  if (!$coyymm || preg_match('/[0-9][0-9][0-9][0-9]/i', $coyymm)) {
110  return true;
111  } else {
112  $langs->load("errors");
113  $this->error = $langs->trans('ErrorNumRefModel', $max);
114  return false;
115  }
116  }
117 
118 
126  public function getNextValue($objsoc, $object)
127  {
128  global $conf, $db;
129 
130  // the ref of a member is the rowid
131  $sql = "SELECT MAX(CAST(ref AS SIGNED)) as max";
132  $sql .= " FROM ".MAIN_DB_PREFIX."adherent";
133  $sql .= " WHERE entity = ".(int) $conf->entity;
134 
135  $resql = $db->query($sql);
136  if ($resql) {
137  $obj = $db->fetch_object($resql);
138  if ($obj) {
139  $max = intval($obj->max) + 1;
140  } else {
141  $max = 1;
142  }
143  } else {
144  dol_syslog("mod_member_simple::getNextValue", LOG_DEBUG);
145  return -1;
146  }
147  $max = str_pad((string) $max, getDolGlobalInt('MEMBER_MOD_SIMPLE_LPAD'), "0", STR_PAD_LEFT);
148  return $max;
149  }
150 }
$sql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:745
ModeleNumRefMembers
Classe mere des modeles de numerotation des references de members.
Definition: modules_member.class.php:68
mod_member_simple\canBeActivated
canBeActivated()
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
Definition: mod_member_simple.php:91
mod_member_simple
Class to manage the numbering module Simple for member references.
Definition: mod_member_simple.php:32
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1639
mod_member_simple\getExample
getExample()
Return an example of numbering module values.
Definition: mod_member_simple.php:79
mod_member_simple\info
info()
Return description of numbering module.
Definition: mod_member_simple.php:67
mod_member_simple\getNextValue
getNextValue($objsoc, $object)
Return next value.
Definition: mod_member_simple.php:126
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96