dolibarr 20.0.0
mod_project_universal.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2010 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.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
26require_once DOL_DOCUMENT_ROOT.'/core/modules/project/modules_project.php';
27
28
33{
37 public $db;
38
43 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
44
48 public $error = '';
49
55 public $nom = 'Universal';
56
60 public $name = 'Universal';
61
62
69 public function info($langs)
70 {
71 global $langs;
72
73 // Load translation files required by the page
74 $langs->loadLangs(array("projects", "admin"));
75
76 $form = new Form($this->db);
77
78 $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
79 $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
80 $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
81 $texte .= '<input type="hidden" name="action" value="updateMask">';
82 $texte .= '<input type="hidden" name="maskconstproject" value="PROJECT_UNIVERSAL_MASK">';
83 $texte .= '<table class="nobordernopadding" width="100%">';
84
85 $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Project"), $langs->transnoentities("Project"));
86 $tooltip .= $langs->trans("GenericMaskCodes2");
87 $tooltip .= $langs->trans("GenericMaskCodes3");
88 $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Project"), $langs->transnoentities("Project"));
89 $tooltip .= $langs->trans("GenericMaskCodes5");
90 $tooltip .= '<br>'.$langs->trans("GenericMaskCodes5b");
91
92 // Prefix settings
93 $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
94 $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskproject" value="'.getDolGlobalString('PROJECT_UNIVERSAL_MASK').'">', $tooltip, 1, 1).'</td>';
95
96 $texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button button-edit reposition smallpaddingimp" name="Button"value="'.$langs->trans("Modify").'"></td>';
97
98 $texte .= '</tr>';
99
100 $texte .= '</table>';
101 $texte .= '</form>';
102
103 return $texte;
104 }
105
111 public function getExample()
112 {
113 global $conf, $langs, $mysoc;
114
115 $old_code_client = $mysoc->code_client;
116 $mysoc->code_client = 'CCCCCCCCCC';
117 $numExample = $this->getNextValue($mysoc, '');
118 $mysoc->code_client = $old_code_client;
119
120 if (!$numExample) {
121 $numExample = $langs->trans('NotConfigured');
122 }
123 return $numExample;
124 }
125
133 public function getNextValue($objsoc, $project)
134 {
135 global $db, $conf;
136
137 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
138
139 // We define criterion search counter
140 $mask = getDolGlobalString('PROJECT_UNIVERSAL_MASK');
141
142 if (!$mask) {
143 $this->error = 'NotConfigured';
144 return 0;
145 }
146
147 // Get entities
148 $entity = getEntity('projectnumber', 1, $project);
149
150 $date = (empty($project->date_c) ? dol_now() : $project->date_c);
151 $numFinal = get_next_value($db, $mask, 'projet', 'ref', '', (is_object($objsoc) ? $objsoc : ''), $date, 'next', false, null, $entity);
152
153 return $numFinal;
154 }
155}
Class to manage generation of HTML components Only common components must be here.
Class mere des modeles de numerotation des references de projects.
Class to manage the numbering module Universal for project references.
getExample()
Return an example of numbering.
info($langs)
Returns the description of the numbering model.
getNextValue($objsoc, $project)
Return next value.
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='auto')
Return date for now.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.