dolibarr  20.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 
26 require_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 $conf, $langs, $mysoc;
113 
114  $old_code_client = $mysoc->code_client;
115  $mysoc->code_client = 'CCCCCCCCCC';
116  $numExample = $this->getNextValue($mysoc, '');
117  $mysoc->code_client = $old_code_client;
118 
119  if (!$numExample) {
120  $numExample = $langs->trans('NotConfigured');
121  }
122  return $numExample;
123  }
124 
132  public function getNextValue($objsoc, $project)
133  {
134  global $db, $conf;
135 
136  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
137 
138  // We define criterion search counter
139  $mask = getDolGlobalString('PROJECT_UNIVERSAL_MASK');
140 
141  if (!$mask) {
142  $this->error = 'NotConfigured';
143  return 0;
144  }
145 
146  // Get entities
147  $entity = getEntity('projectnumber', 1, $project);
148 
149  $date = (empty($project->date_c) ? dol_now() : $project->date_c);
150  $numFinal = get_next_value($db, $mask, 'projet', 'ref', '', (is_object($objsoc) ? $objsoc : ''), $date, 'next', false, null, $entity);
151 
152  return $numFinal;
153  }
154 }
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.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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.