Passed
Branch develop (5cbde9)
by
unknown
26:38
created

ModeleThirdPartyCode::canBeActivated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <[email protected]>
3
 * Copyright (C) 2004-2010 Laurent Destailleur  <[email protected]>
4
 * Copyright (C) 2004      Eric Seigne          <[email protected]>
5
 * Copyright (C) 2005-2012 Regis Houssin        <[email protected]>
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
 * or see http://www.gnu.org/
20
 */
21
22
/**
23
 *	    \file       htdocs/core/modules/societe/modules_societe.class.php
24
 *		\ingroup    societe
25
 *		\brief      File with parent class of submodules to manage numbering and document generation
26
 */
27
require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
28
29
30
/**
31
 *	\class      ModeleThirdPartyDoc
32
 *	\brief      Parent class for third parties models of doc generators
33
 */
34
abstract class ModeleThirdPartyDoc extends CommonDocGenerator
35
{
36
    /**
37
	 * @var string Error code (or message)
38
	 */
39
	public $error='';
40
41
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
42
    /**
43
     *  Return list of active generation modules
44
     *
45
     * 	@param	DoliDB		$db					Database handler
46
     *  @param	integer		$maxfilenamelength  Max length of value to show
47
     * 	@return	array							List of templates
48
     */
49
    public static function liste_modeles($db, $maxfilenamelength = 0)
50
    {
51
        // phpcs:enable
52
        global $conf;
53
54
        $type='company';
55
        $liste=array();
56
57
        include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
58
        $liste = getListOfModels($db, $type, $maxfilenamelength);
59
60
        return $liste;
61
    }
62
}
63
64
/**
65
 *	    \class      ModeleThirdPartyCode
66
 *		\brief  	Parent class for third parties code generators
67
 */
68
abstract class ModeleThirdPartyCode
69
{
70
    /**
71
     * @var string Error code (or message)
72
	 */
73
	public $error='';
74
75
    /**     Renvoi la description par defaut du modele de numerotation
76
     *
77
     *		@param	Translate	$langs		Object langs
78
     *      @return string      			Texte descripif
79
     */
80
    public function info($langs)
81
    {
82
        $langs->load("bills");
83
        return $langs->trans("NoDescription");
84
    }
85
86
    /**     Renvoi nom module
87
     *
88
     *		@param	Translate	$langs		Object langs
89
     *      @return string      			Nom du module
90
     */
91
    public function getNom($langs)
92
    {
93
        return $this->nom;
94
    }
95
96
97
    /**     Renvoi un exemple de numerotation
98
     *
99
     *		@param	Translate	$langs		Object langs
100
     *      @return string      			Example
101
     */
102
    public function getExample($langs)
103
    {
104
        $langs->load("bills");
105
        return $langs->trans("NoExample");
106
    }
107
108
    /**     Test si les numeros deja en vigueur dans la base ne provoquent pas de
109
     *      de conflits qui empechera cette numerotation de fonctionner.
110
     *
111
     *      @return     boolean     false si conflit, true si ok
112
     */
113
    public function canBeActivated()
114
    {
115
        return true;
116
    }
117
118
    /**
119
     *  Return next value available
120
     *
121
     *	@param	Societe		$objsoc		Object thirdparty
122
     *	@param	int			$type		Type
123
     *  @return string      			Value
124
     */
125
    public function getNextValue($objsoc = 0, $type = -1)
126
    {
127
        global $langs;
128
        return $langs->trans("Function_getNextValue_InModuleNotWorking");
129
    }
130
131
132
    /**
133
     *  Return version of module
134
     *
135
     *  @return     string      Version
136
     */
137
    public function getVersion()
138
    {
139
        global $langs;
140
        $langs->load("admin");
141
142
        if ($this->version == 'development') return $langs->trans("VersionDevelopment");
143
        if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
144
        if ($this->version == 'dolibarr') return DOL_VERSION;
145
        if ($this->version) return $this->version;
146
        return $langs->trans("NotAvailable");
147
    }
148
149
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
150
    /**
151
     *  Renvoie la liste des modeles de numérotation
152
     *
153
     *  @param	DoliDB	$db     			Database handler
154
     *  @param  integer	$maxfilenamelength  Max length of value to show
155
     *  @return	array						List of numbers
156
     */
157
    public static function liste_modeles($db, $maxfilenamelength = 0)
158
    {
159
        // phpcs:enable
160
        $liste=array();
161
        $sql ="";
162
163
        $resql = $db->query($sql);
164
        if ($resql)
165
        {
166
            $num = $db->num_rows($resql);
167
            $i = 0;
168
            while ($i < $num)
169
            {
170
                $row = $db->fetch_row($resql);
171
                $liste[$row[0]]=$row[1];
172
                $i++;
173
            }
174
        }
175
        else
176
        {
177
            return -1;
178
        }
179
        return $liste;
180
    }
181
182
    /**
183
     *  Return description of module parameters
184
     *
185
     *  @param	Translate	$langs      Output language
186
     *  @param	Societe		$soc		Third party object
187
     *  @param	int			$type		-1=Nothing, 0=Customer, 1=Supplier
188
     *  @return	string					HTML translated description
189
     */
190
    public function getToolTip($langs, $soc, $type)
191
    {
192
        global $conf;
193
194
        $langs->load("admin");
195
196
        $s='';
197
        if ($type == -1) $s.=$langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>';
198
        if ($type == -1) $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
199
        if ($type == 0)  $s.=$langs->trans("CustomerCodeDesc").'<br>';
200
        if ($type == 1)  $s.=$langs->trans("SupplierCodeDesc").'<br>';
201
        if ($type != -1) $s.=$langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>';
202
        $s.='<br>';
203
        $s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
204
        if ($type == 0)
205
        {
206
            $s.=$langs->trans("RequiredIfCustomer").': ';
207
            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>';
208
            $s.=yn(!$this->code_null, 1, 2);
209
            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
210
            $s.='<br>';
211
        }
212
        if ($type == 1)
213
        {
214
            $s.=$langs->trans("RequiredIfSupplier").': ';
215
            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>';
216
            $s.=yn(!$this->code_null, 1, 2);
217
            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
218
            $s.='<br>';
219
        }
220
        if ($type == -1)
221
        {
222
            $s.=$langs->trans("Required").': ';
223
            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>';
224
            $s.=yn(!$this->code_null, 1, 2);
225
            if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')';
226
            $s.='<br>';
227
        }
228
        $s.=$langs->trans("CanBeModifiedIfOk").': ';
229
        $s.=yn($this->code_modifiable, 1, 2);
230
        $s.='<br>';
231
        $s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide, 1, 2).'<br>';
232
        $s.=$langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'<br>';
233
        $s.='<br>';
234
        if ($type == 0 || $type == -1)
235
        {
236
            $nextval=$this->getNextValue($soc, 0);
237
            if (empty($nextval)) $nextval=$langs->trans("Undefined");
238
            $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Customer").')':'').': <b>'.$nextval.'</b><br>';
239
        }
240
        if ($type == 1 || $type == -1)
241
        {
242
            $nextval=$this->getNextValue($soc, 1);
243
            if (empty($nextval)) $nextval=$langs->trans("Undefined");
244
            $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Supplier").')':'').': <b>'.$nextval.'</b>';
245
        }
246
        return $s;
247
    }
248
249
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
250
	/**
251
	 *   Check if mask/numbering use prefix
252
	 *
253
	 *   @return    int	    0=no, 1=yes
254
     */
255
    public function verif_prefixIsUsed()
256
    {
257
        // phpcs:enable
258
        return 0;
259
    }
260
}
261
262
263
/**
264
 *		\class		ModeleAccountancyCode
265
 *		\brief  	Parent class for third parties accountancy code generators
266
 */
267
abstract class ModeleAccountancyCode
268
{
269
    /**
270
	 * @var string Error code (or message)
271
	 */
272
	public $error='';
273
274
275
    /**
276
     *  Return description of module
277
     *
278
     *  @param	Translate	$langs		Object langs
279
     *  @return string      			Description of module
280
     */
281
    public function info($langs)
282
    {
283
        $langs->load("bills");
284
        return $langs->trans("NoDescription");
285
    }
286
287
    /**
288
     *  Return an example of result returned by getNextValue
289
     *
290
     *  @param	Translate	$langs		Object langs
291
     *  @param	societe		$objsoc		Object thirdparty
292
     *  @param	int			$type		Type of third party (1:customer, 2:supplier, -1:autodetect)
293
     *  @return	string					Example
294
     */
295
    public function getExample($langs, $objsoc = 0, $type = -1)
296
    {
297
        $langs->load("bills");
298
        return $langs->trans("NoExample");
299
    }
300
301
    /**     Test si les numeros deja en vigueur dans la base ne provoquent pas de
302
     *      de conflits qui empechera cette numerotation de fonctionner.
303
     *
304
     *      @return     boolean     false si conflit, true si ok
305
     */
306
    public function canBeActivated()
307
    {
308
        return true;
309
    }
310
311
    /**
312
     *  Return version of module
313
     *
314
     *  @return     string      Version
315
     */
316
    public function getVersion()
317
    {
318
        global $langs;
319
        $langs->load("admin");
320
321
        if ($this->version == 'development') return $langs->trans("VersionDevelopment");
322
        if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
323
        if ($this->version == 'dolibarr') return DOL_VERSION;
324
        if ($this->version) return $this->version;
325
        return $langs->trans("NotAvailable");
326
    }
327
328
    /**
329
     *  Return description of module parameters
330
     *
331
     *  @param	Translate	$langs      Output language
332
     *  @param	Societe		$soc		Third party object
333
     *  @param	int			$type		-1=Nothing, 0=Customer, 1=Supplier
334
     *  @return	string					HTML translated description
335
     */
336
    public function getToolTip($langs, $soc, $type)
337
    {
338
        global $conf,$db;
339
340
        $langs->load("admin");
341
342
        $s='';
343
        if ($type == -1) $s.=$langs->trans("Name").': <b>'.$this->nom.'</b><br>';
344
        if ($type == -1) $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>';
345
        //$s.='<br>';
346
        //$s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>';
347
        $s.='<br>';
348
        if ($type == 0 || $type == -1)
349
        {
350
            $result=$this->get_code($db, $soc, 'customer');
351
            $nextval=$this->code;
352
            if (empty($nextval)) $nextval=$langs->trans("Undefined");
353
            $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Customer").')':'').': <b>'.$nextval.'</b><br>';
354
        }
355
        if ($type == 1 || $type == -1)
356
        {
357
            $result=$this->get_code($db, $soc, 'supplier');
358
            $nextval=$this->code;
359
            if (empty($nextval)) $nextval=$langs->trans("Undefined");
360
            $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Supplier").')':'').': <b>'.$nextval.'</b>';
361
        }
362
        return $s;
363
    }
364
365
    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
366
    /**
367
     *  Set accountancy account code for a third party into this->code
368
     *
369
     *  @param	DoliDB	$db             Database handler
370
     *  @param  Societe	$societe        Third party object
371
     *  @param  int		$type			'customer' or 'supplier'
372
     *  @return	int						>=0 if OK, <0 if KO
373
     */
374
    public function get_code($db, $societe, $type = '')
375
    {
376
        // phpcs:enable
377
        global $langs;
378
379
        return $langs->trans("NotAvailable");
380
    }
381
}
382
383
384
/**
385
 *  Create a document onto disk according to template module.
386
 *
387
 *	@param	DoliDB		$db  			Database handler
388
 *	@param  Facture		$object			Object invoice
389
 *  @param  string      $message        Message (not used, deprecated)
390
 *	@param	string		$modele			Force template to use ('' to not force)
391
 *	@param	Translate	$outputlangs	objet lang a utiliser pour traduction
392
 *  @param  int			$hidedetails    Hide details of lines
393
 *  @param  int			$hidedesc       Hide description
394
 *  @param  int			$hideref        Hide ref
395
 *	@return int        					<0 if KO, >0 if OK
396
 *  @deprecated Use the new function generateDocument of Objects class
397
 *  @see Societe::generateDocument()
398
 */
399
function thirdparty_doc_create(DoliDB $db, Societe $object, $message, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
400
{
401
    dol_syslog(__METHOD__ . " is deprecated", LOG_WARNING);
402
403
    return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
404
}
405