1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <[email protected]> |
4
|
|
|
* Copyright (C) 2004-2010 Laurent Destailleur <[email protected]> |
5
|
|
|
* Copyright (C) 2004 Eric Seigne <[email protected]> |
6
|
|
|
* Copyright (C) 2005-2012 Regis Houssin <[email protected]> |
7
|
|
|
* Copyright (C) 2024 Frédéric France <[email protected]> |
8
|
|
|
* Copyright (C) 2024 MDW <[email protected]> |
9
|
|
|
* Copyright (C) 2024 Rafael San José <[email protected]> |
10
|
|
|
* |
11
|
|
|
* This program is free software; you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU General Public License as published by |
13
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
14
|
|
|
* (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU General Public License |
22
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
23
|
|
|
* or see https://www.gnu.org/ |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace Dolibarr\Code\Societe\Classes; |
27
|
|
|
|
28
|
|
|
use Dolibarr\Code\Core\Classes\CommonNumRefGenerator; |
29
|
|
|
use Dolibarr\Code\Core\Classes\Translate; |
30
|
|
|
use DoliDB; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* \file htdocs/core/modules/societe/modules_societe.class.php |
34
|
|
|
* \ingroup societe |
35
|
|
|
* \brief File with parent class of submodules to manage numbering and document generation |
36
|
|
|
*/ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Parent class for third parties code generators |
40
|
|
|
*/ |
41
|
|
|
abstract class ModeleThirdPartyCode extends CommonNumRefGenerator |
42
|
|
|
{ |
43
|
|
|
/** |
44
|
|
|
* Constructor |
45
|
|
|
* |
46
|
|
|
* @param DoliDB $db Database object |
47
|
|
|
*/ |
48
|
|
|
abstract public function __construct($db); |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Renvoie la liste des modeles de numérotation |
52
|
|
|
* |
53
|
|
|
* @param DoliDB $dbs Database handler |
54
|
|
|
* @param integer $maxfilenamelength Max length of value to show |
55
|
|
|
* @return array|int List of numbers |
56
|
|
|
*/ |
57
|
|
|
public static function liste_modeles($dbs, $maxfilenamelength = 0) |
58
|
|
|
{ |
59
|
|
|
// phpcs:enable |
60
|
|
|
$list = array(); |
61
|
|
|
$sql = ""; |
62
|
|
|
|
63
|
|
|
$resql = $dbs->query($sql); |
64
|
|
|
if ($resql) { |
65
|
|
|
$num = $dbs->num_rows($resql); |
66
|
|
|
$i = 0; |
67
|
|
|
while ($i < $num) { |
68
|
|
|
$row = $dbs->fetch_row($resql); |
69
|
|
|
$list[$row[0]] = $row[1]; |
70
|
|
|
$i++; |
71
|
|
|
} |
72
|
|
|
} else { |
73
|
|
|
return -1; |
74
|
|
|
} |
75
|
|
|
return $list; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Return description of module parameters |
83
|
|
|
* |
84
|
|
|
* @param Translate $langs Output language |
85
|
|
|
* @param Societe $soc Third party object |
86
|
|
|
* @param int $type -1=Nothing, 0=Customer, 1=Supplier |
87
|
|
|
* @return string HTML translated description |
88
|
|
|
*/ |
89
|
|
|
public function getToolTip($langs, $soc, $type) |
90
|
|
|
{ |
91
|
|
|
global $conf; |
92
|
|
|
|
93
|
|
|
$langs->loadLangs(array("admin", "companies")); |
94
|
|
|
|
95
|
|
|
$strikestart = ''; |
96
|
|
|
$strikeend = ''; |
97
|
|
|
if (getDolGlobalString('MAIN_COMPANY_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) { |
98
|
|
|
$strikestart = '<strike>'; |
99
|
|
|
$strikeend = '</strike> ' . yn(1, 1, 2) . ' (' . $langs->trans("ForcedToByAModule", $langs->transnoentities("yes")) . ')'; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$s = ''; |
103
|
|
|
if ($type == -1) { |
104
|
|
|
$s .= $langs->trans("Name") . ': <b>' . $this->getName($langs) . '</b><br>'; |
105
|
|
|
} elseif ($type == 0) { |
106
|
|
|
$s .= $langs->trans("CustomerCodeDesc") . '<br>'; |
107
|
|
|
} elseif ($type == 1) { |
108
|
|
|
$s .= $langs->trans("SupplierCodeDesc") . '<br>'; |
109
|
|
|
} |
110
|
|
|
if ($type != -1) { |
111
|
|
|
$s .= $langs->trans("ValidityControledByModule") . ': <b>' . $this->getName($langs) . '</b><br>'; |
112
|
|
|
} |
113
|
|
|
$s .= '<br>'; |
114
|
|
|
$s .= '<u>' . $langs->trans("ThisIsModuleRules") . ':</u><br>'; |
115
|
|
|
if ($type == 0) { |
116
|
|
|
$s .= $langs->trans("RequiredIfCustomer") . ': ' . $strikestart; |
117
|
|
|
$s .= yn(!$this->code_null, 1, 2) . $strikeend; |
118
|
|
|
$s .= '<br>'; |
119
|
|
|
} elseif ($type == 1) { |
120
|
|
|
$s .= $langs->trans("RequiredIfSupplier") . ': ' . $strikestart; |
121
|
|
|
$s .= yn(!$this->code_null, 1, 2) . $strikeend; |
122
|
|
|
$s .= '<br>'; |
123
|
|
|
} elseif ($type == -1) { |
124
|
|
|
$s .= $langs->trans("Required") . ': ' . $strikestart; |
125
|
|
|
$s .= yn(!$this->code_null, 1, 2) . $strikeend; |
126
|
|
|
$s .= '<br>'; |
127
|
|
|
} |
128
|
|
|
$s .= $langs->trans("CanBeModifiedIfOk") . ': '; |
129
|
|
|
$s .= yn($this->code_modifiable, 1, 2); |
130
|
|
|
$s .= '<br>'; |
131
|
|
|
$s .= $langs->trans("CanBeModifiedIfKo") . ': ' . yn($this->code_modifiable_invalide, 1, 2) . '<br>'; |
132
|
|
|
$s .= $langs->trans("AutomaticCode") . ': ' . yn($this->code_auto, 1, 2) . '<br>'; |
133
|
|
|
$s .= '<br>'; |
134
|
|
|
if ($type == 0 || $type == -1) { |
135
|
|
|
$nextval = $this->getNextValue($soc, 0); |
136
|
|
|
if (empty($nextval)) { |
137
|
|
|
$nextval = $langs->trans("Undefined"); |
138
|
|
|
} |
139
|
|
|
$s .= $langs->trans("NextValue") . ($type == -1 ? ' (' . $langs->trans("Customer") . ')' : '') . ': <b>' . $nextval . '</b><br>'; |
140
|
|
|
} |
141
|
|
|
if ($type == 1 || $type == -1) { |
142
|
|
|
$nextval = $this->getNextValue($soc, 1); |
143
|
|
|
if (empty($nextval)) { |
144
|
|
|
$nextval = $langs->trans("Undefined"); |
145
|
|
|
} |
146
|
|
|
$s .= $langs->trans("NextValue") . ($type == -1 ? ' (' . $langs->trans("Supplier") . ')' : '') . ': <b>' . $nextval . '</b>'; |
147
|
|
|
} |
148
|
|
|
return $s; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Return next value available |
153
|
|
|
* |
154
|
|
|
* @param Societe|string $objsoc Object thirdparty |
155
|
|
|
* @param int $type Type |
156
|
|
|
* @return string Value |
157
|
|
|
*/ |
158
|
|
|
public function getNextValue($objsoc = '', $type = -1) |
159
|
|
|
{ |
160
|
|
|
global $langs; |
161
|
|
|
return $langs->trans("Function_getNextValue_InModuleNotWorking"); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Check if mask/numbering use prefix |
168
|
|
|
* |
169
|
|
|
* @return int 0=no, 1=yes |
170
|
|
|
*/ |
171
|
|
|
public function verif_prefixIsUsed() |
172
|
|
|
{ |
173
|
|
|
// phpcs:enable |
174
|
|
|
return 0; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|