dolibarr 21.0.0-alpha
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
91 // Prefix settings
92 $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
93 $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskproject" value="'.getDolGlobalString('PROJECT_UNIVERSAL_MASK').'">', $tooltip, 1, 1).'</td>';
94
95 $texte .= '<td class="left" rowspan="2">&nbsp; <input type="submit" class="button button-edit reposition smallpaddingimp" name="Button"value="'.$langs->trans("Modify").'"></td>';
96
97 $texte .= '</tr>';
98
99 $texte .= '</table>';
100 $texte .= '</form>';
101
102 return $texte;
103 }
104
110 public function getExample()
111 {
112 global $db, $langs;
113
114 require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
115 require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
116
117 $project = new Project($db);
118 $project->initAsSpecimen();
119 $thirdparty = new Societe($db);
120 $thirdparty->initAsSpecimen();
121
122 $numExample = $this->getNextValue($thirdparty, $project);
123
124 if (!$numExample) {
125 $numExample = $langs->trans('NotConfigured');
126 }
127
128 return $numExample;
129 }
130
138 public function getNextValue($objsoc, $project)
139 {
140 global $db, $langs;
141
142 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
143
144 // We define criterion search counter
145 $mask = getDolGlobalString('PROJECT_UNIVERSAL_MASK');
146
147 if (!$mask) {
148 $this->error = $langs->trans('NotConfigured');
149 return 0;
150 }
151
152 // Get entities
153 $entity = getEntity('projectnumber', 1, $project);
154
155 $date = (empty($project->date_c) ? dol_now() : $project->date_c);
156 $numFinal = get_next_value($db, $mask, 'projet', 'ref', '', (is_object($objsoc) ? $objsoc : ''), $date, 'next', false, null, $entity);
157
158 return $numFinal;
159 }
160}
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 projects.
Class to manage third parties objects (customers, suppliers, prospects...)
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.