1<?php
2/* Copyright (C) 2014 Laurent Destailleur  <eldy@users.sourceforge.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 * or see https://www.gnu.org/
17 */
18
19/**
20 *   \file       htdocs/core/modules/barcode/modules_barcode.class.php
21 *   \ingroup    barcode
22 *   \brief      File with parent classes for barcode document modules and numbering modules
23 */
24require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
25
26
27/**
28 *	Parent class for barcode document models
29 */
30abstract class ModeleBarCode
31{
32	/**
33	 * @var string Error code (or message)
34	 */
35	public $error = '';
36
37
38	/**
39	 * Return if a model can be used or not
40	 *
41	 * @return		boolean     true if model can be used
42	 */
43	public function isEnabled()
44	{
45		return true;
46	}
47}
48
49
50/**
51 *	Parent class for barcode numbering models
52 */
53abstract class ModeleNumRefBarCode
54{
55	/**
56	 * @var string Error code (or message)
57	 */
58	public $error = '';
59
60	/**     Return default description of numbering model
61	 *
62	 *		@param	Translate	$langs		Object langs
63	 *      @return string      			Descriptive text
64	 */
65	public function info($langs)
66	{
67		$langs->load("bills");
68		return $langs->trans("NoDescription");
69	}
70
71	/**     Return model name
72	 *
73	 *		@param	Translate	$langs		Object langs
74	 *      @return string      			Model name
75	 */
76	public function getNom($langs)
77	{
78		return empty($this->name) ? $this->nom : $this->name;
79	}
80
81	/**     Return a numbering example
82	 *
83	 *		@param	Translate	$langs		Object langs
84	 *      @return string      			Example
85	 */
86	public function getExample($langs)
87	{
88		$langs->load("bills");
89		return $langs->trans("NoExample");
90	}
91
92	/**
93	 *  Return next value available
94	 *
95	 *	@param	Product		$objproduct	Object Product
96	 *	@param	string		$type		Type of barcode (EAN, ISBN, ...)
97	 *  @return string      			Value
98	 */
99	public function getNextValue($objproduct, $type = '')
100	{
101		global $langs;
102		return $langs->trans("Function_getNextValue_InModuleNotWorking");
103	}
104
105	/**     Return version of module
106	 *
107	 *      @return     string      Version
108	 */
109	public function getVersion()
110	{
111		global $langs;
112		$langs->load("admin");
113
114		if ($this->version == 'development') {
115			return $langs->trans("VersionDevelopment");
116		}
117		if ($this->version == 'experimental') {
118			return $langs->trans("VersionExperimental");
119		}
120		if ($this->version == 'dolibarr') {
121			return DOL_VERSION;
122		}
123		if ($this->version) {
124			return $this->version;
125		}
126		return $langs->trans("NotAvailable");
127	}
128
129	/**
130	 *      Return description of module parameters
131	 *
132	 *      @param	Translate	$langs      Output language
133	 *		@param	Societe		$soc		Third party object
134	 *		@param	int			$type		-1=Nothing, 0=Product, 1=Service
135	 *		@return	string					HTML translated description
136	 */
137	public function getToolTip($langs, $soc, $type)
138	{
139		global $conf;
140
141		$langs->loadLangs(array("admin", "companies"));
142
143		$s = '';
144		$s .= $langs->trans("Name").': <b>'.$this->name.'</b><br>';
145		$s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
146		if ($type != -1) {
147			$s .= $langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
148		}
149		$s .= '<br>';
150		$s .= '<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
151		if ($type == 0) {
152			$s .= $langs->trans("RequiredIfProduct").': ';
153			if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
154				$s .= '<strike>';
155			}
156			$s .= yn(!$this->code_null, 1, 2);
157			if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
158				$s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
159			}
160			$s .= '<br>';
161		}
162		if ($type == 1) {
163			$s .= $langs->trans("RequiredIfService").': ';
164			if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
165				$s .= '<strike>';
166			}
167			$s .= yn(!$this->code_null, 1, 2);
168			if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
169				$s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
170			}
171			$s .= '<br>';
172		}
173		if ($type == -1) {
174			$s .= $langs->trans("Required").': ';
175			if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
176				$s .= '<strike>';
177			}
178			$s .= yn(!$this->code_null, 1, 2);
179			if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) {
180				$s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
181			}
182			$s .= '<br>';
183		}
184		/*$s.=$langs->trans("CanBeModifiedIfOk").': ';
185		$s.=yn($this->code_modifiable,1,2);
186		$s.='<br>';
187		$s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide,1,2).'<br>';
188		*/
189		$s .= $langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'<br>';
190		$s .= '<br>';
191
192		$nextval = $this->getNextValue($soc, '');
193		if (empty($nextval)) {
194			$nextval = $langs->trans("Undefined");
195		}
196		$s .= $langs->trans("NextValue").': <b>'.$nextval.'</b><br>';
197
198		return $s;
199	}
200}
201