dolibarr  16.0.5
mod_member_simple.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2021 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  * or see https://www.gnu.org/
17  */
18 
25 require_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_member.class.php';
26 
27 
32 {
37  public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
38 
39  public $prefix = 'MEM';
40 
44  public $error = '';
45 
51  public $nom = 'Simple';
52 
56  public $name = 'Simple';
57 
58 
64  public function info()
65  {
66  global $langs;
67  return $langs->trans("SimpleNumRefModelDesc", $this->prefix);
68  }
69 
70 
76  public function getExample()
77  {
78  return $this->prefix."0501-0001";
79  }
80 
81 
88  public function canBeActivated()
89  {
90  global $conf, $langs, $db;
91 
92  $coyymm = '';
93  $max = '';
94 
95  $posindice = strlen($this->prefix) + 6;
96  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
97  $sql .= " FROM ".MAIN_DB_PREFIX."adherent";
98  $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
99  $sql .= " AND entity = ".$conf->entity;
100  $resql = $db->query($sql);
101  if ($resql) {
102  $row = $db->fetch_row($resql);
103  if ($row) {
104  $coyymm = substr($row[0], 0, 6);
105  $max = $row[0];
106  }
107  }
108  if (!$coyymm || preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) {
109  return true;
110  } else {
111  $langs->load("errors");
112  $this->error = $langs->trans('ErrorNumRefModel', $max);
113  return false;
114  }
115  }
116 
117 
125  public function getNextValue($objsoc, $object)
126  {
127  global $db, $conf;
128 
129  /*
130  // First, we get the max value
131  $posindice = strlen($this->prefix) + 6;
132  $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
133  $sql .= " FROM ".MAIN_DB_PREFIX."adherent";
134  $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'";
135  $sql .= " AND entity = ".$conf->entity;
136 
137  $resql = $db->query($sql);
138  if ($resql) {
139  $obj = $db->fetch_object($resql);
140  if ($obj) {
141  $max = intval($obj->max);
142  } else {
143  $max = 0;
144  }
145  } else {
146  dol_syslog("mod_member_simple::getNextValue", LOG_DEBUG);
147  return -1;
148  }
149 
150  $date = empty($object->date_c) ? dol_now() : $object->date_c;
151 
152  //$yymm = strftime("%y%m",time());
153  $yymm = strftime("%y%m", $date);
154 
155  if ($max >= (pow(10, 4) - 1)) {
156  $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is
157  } else {
158  $num = sprintf("%04s", $max + 1);
159  }
160 
161  dol_syslog("mod_member_simple::getNextValue return ".$this->prefix.$yymm."-".$num);
162  return $this->prefix.$yymm."-".$num;
163  */
164 
165  // For the moment, the ref of a member is the rowid
166  $sql = "SELECT MAX(rowid) as max";
167  $sql .= " FROM ".MAIN_DB_PREFIX."adherent";
168 
169  $resql = $db->query($sql);
170  if ($resql) {
171  $obj = $db->fetch_object($resql);
172  if ($obj) {
173  $max = intval($obj->max);
174  } else {
175  $max = 0;
176  }
177  } else {
178  dol_syslog("mod_member_simple::getNextValue", LOG_DEBUG);
179  return -1;
180  }
181  return ($max + 1);
182  }
183 }
ModeleNumRefMembers
Classe mere des modeles de numerotation des references de members.
Definition: modules_member.class.php:69
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:88
mod_member_simple
Class to manage the numbering module Simple for member references.
Definition: mod_member_simple.php:31
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
mod_member_simple\getExample
getExample()
Return an example of numbering module values.
Definition: mod_member_simple.php:76
mod_member_simple\info
info()
Return description of numbering module.
Definition: mod_member_simple.php:64
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
mod_member_simple\getNextValue
getNextValue($objsoc, $object)
Return next value.
Definition: mod_member_simple.php:125