dolibarr 24.0.0-beta
modules_barcode.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2014 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 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
26require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
27require_once DOL_DOCUMENT_ROOT.'/core/class/commonnumrefgenerator.class.php';
28
29
35abstract class ModeleBarCode
36{
40 public $error = '';
41
42
48 public function isEnabled()
49 {
50 return true;
51 }
52
53
60 abstract public function info($langs);
61
62
73 public function writeBarCode($code, $encoding, $readable = 'Y', $scale = 1, $nooutputiferror = 0)
74 {
75 return -1; // Error by default, this method must be implemented by the driver
76 }
77
88 public function buildBarCode($code, $encoding, $readable = 'Y', $scale = 1, $nooutputiferror = 0)
89 {
90 return 1;
91 }
92
99 abstract public function encodingIsSupported($encoding);
100}
101
102
109{
110 // variables inherited from CommonNumRefGenerator
114 public $code_null;
115
116
124 public function getNextValue($objcommon = null, $type = '')
125 {
126 global $langs;
127 return $langs->trans("Function_getNextValue_InModuleNotWorking");
128 }
129
130
138 abstract public function getExample($langs = null, $object = null);
139
140
149 public function getToolTip($langs, $soc, $type)
150 {
151 $langs->loadLangs(array("admin", "companies"));
152
153 $s = '';
154 $s .= $langs->trans("Name").': <b>'.$this->name.'</b><br>';
155 $s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
156 if ($type != -1) {
157 $s .= $langs->trans("ValidityControledByModule").': <b>'.$this->getName($langs).'</b><br>';
158 }
159 $s .= '<br>';
160 $s .= '<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
161 if ($type == 0) {
162 $s .= $langs->trans("RequiredIfProduct").': ';
163 if (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) {
164 $s .= '<strike>';
165 }
166 $s .= yn($this->code_null ? 0 : 1, 1, 2);
167 if (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) {
168 $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
169 }
170 $s .= '<br>';
171 }
172 if ($type == 1) {
173 $s .= $langs->trans("RequiredIfService").': ';
174 if (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) {
175 $s .= '<strike>';
176 }
177 $s .= yn($this->code_null ? 0 : 1, 1, 2);
178 if (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) {
179 $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
180 }
181 $s .= '<br>';
182 }
183 if ($type == -1) {
184 $s .= $langs->trans("Required").': ';
185 if (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) {
186 $s .= '<strike>';
187 }
188 $s .= yn($this->code_null ? 0 : 1, 1, 2);
189 if (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) {
190 $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
191 }
192 $s .= '<br>';
193 }
194 /*$s.=$langs->trans("CanBeModifiedIfOk").': ';
195 $s.=yn($this->code_modifiable,1,2);
196 $s.='<br>';
197 $s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide,1,2).'<br>';
198 */
199 $s .= $langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'<br>';
200 $s .= '<br>';
201
202 $nextval = $this->getNextValue($soc, '');
203 if (empty($nextval)) {
204 $nextval = $langs->trans("Undefined");
205 }
206 $s .= $langs->trans("NextValue").': <b>'.$nextval.'</b><br>';
207
208 return $s;
209 }
210
211
227 abstract public function verif($db, &$code, $object, $thirdparty_type, $type);
228}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Parent class for number ref generators.
getVersion()
Returns version of numbering module.
getName($langs)
Return model name.
isEnabled()
Return if a model can be used or not.
writeBarCode($code, $encoding, $readable='Y', $scale=1, $nooutputiferror=0)
Save an image file on disk (with no output)
buildBarCode($code, $encoding, $readable='Y', $scale=1, $nooutputiferror=0)
Return an image file on the fly (no need to write on disk) with the HTTP content-type of image.
info($langs)
Return description.
encodingIsSupported($encoding)
Return true if encoding is supported.
verif($db, &$code, $object, $thirdparty_type, $type)
Check validity of code according to its rules.
getToolTip($langs, $soc, $type)
Return description of module parameters.
getNextValue($objcommon=null, $type='')
Return next value available.
getExample($langs=null, $object=null)
Return an example of result returned by getNextValue.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:133