dolibarr 23.0.3
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-2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
27require_once DOL_DOCUMENT_ROOT.'/core/modules/member/modules_member.class.php';
28
29
34{
35 // variables inherited from ModeleNumRefMembers class
36 public $name = 'Simple';
37 public $version = 'dolibarr';
38
42 public $position = 30;
43
44 // variables not inherited
45
49 public $prefix = '';
50
54 public function __construct()
55 {
56 $this->code_auto = 1;
57 }
58
65 public function info($langs)
66 {
67 global $langs;
68 return $langs->trans("SimpleRefNumRefModelDesc");
69 }
70
71
77 public function getExample()
78 {
79 return "1";
80 }
81
82
90 public function canBeActivated($object)
91 {
92 global $conf, $langs, $db;
93
94 $coyymm = '';
95 $max = '';
96
97 $sql = "SELECT MAX(CAST(ref AS SIGNED)) as max";
98 $sql .= " FROM ".MAIN_DB_PREFIX."adherent";
99 $sql .= " WHERE entity = ".$conf->entity;
100
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 $sql .= " AND ref <> '(PROV)'";
135
136 $resql = $db->query($sql);
137 if ($resql) {
138 $obj = $db->fetch_object($resql);
139 if ($obj) {
140 $max = intval($obj->max) + 1;
141 } else {
142 $max = 1;
143 }
144 } else {
145 dol_syslog("mod_member_simple::getNextValue", LOG_DEBUG);
146 return -1;
147 }
148 $max = str_pad((string) $max, getDolGlobalInt('MEMBER_MOD_SIMPLE_LPAD'), "0", STR_PAD_LEFT);
149 return $max;
150 }
151}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class mere des modeles de numerotation des references de members.
Class to manage the numbering module Simple for member references.
__construct()
Constructor.
info($langs)
Return description of numbering module.
getNextValue($objsoc, $object)
Return next value.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
getExample()
Return an example of numbering module values.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.