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') return $langs->trans("VersionDevelopment");
115		if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
116		if ($this->version == 'dolibarr') return DOL_VERSION;
117		if ($this->version) return $this->version;
118		return $langs->trans("NotAvailable");
119	}
120
121	/**
122	 *      Return description of module parameters
123	 *
124	 *      @param	Translate	$langs      Output language
125	 *		@param	Societe		$soc		Third party object
126	 *		@param	int			$type		-1=Nothing, 0=Product, 1=Service
127	 *		@return	string					HTML translated description
128	 */
129	public function getToolTip($langs, $soc, $type)
130	{
131		global $conf;
132
133		$langs->load("admin");
134
135		$s = '';
136		$s .= $langs->trans("Name").': <b>'.$this->name.'</b><br>';
137		$s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
138		if ($type != -1) $s .= $langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
139		$s .= '<br>';
140		$s .= '<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
141		if ($type == 0)
142		{
143			$s .= $langs->trans("RequiredIfProduct").': ';
144			if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
145			$s .= yn(!$this->code_null, 1, 2);
146			if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
147			$s .= '<br>';
148		}
149		if ($type == 1)
150		{
151			$s .= $langs->trans("RequiredIfService").': ';
152			if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
153			$s .= yn(!$this->code_null, 1, 2);
154			if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
155			$s .= '<br>';
156		}
157		if ($type == -1)
158		{
159			$s .= $langs->trans("Required").': ';
160			if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>';
161			$s .= yn(!$this->code_null, 1, 2);
162			if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
163			$s .= '<br>';
164		}
165		/*$s.=$langs->trans("CanBeModifiedIfOk").': ';
166        $s.=yn($this->code_modifiable,1,2);
167        $s.='<br>';
168        $s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide,1,2).'<br>';
169        */
170		$s .= $langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'<br>';
171		$s .= '<br>';
172
173		$nextval = $this->getNextValue($soc, '');
174		if (empty($nextval)) $nextval = $langs->trans("Undefined");
175		$s .= $langs->trans("NextValue").': <b>'.$nextval.'</b><br>';
176
177		return $s;
178	}
179}
180