|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* Copyright (C) 2006-2008 Laurent Destailleur <[email protected]> |
|
4
|
|
|
* Copyright (C) 2012 Cedric Salvador <[email protected]> |
|
5
|
|
|
* Copyright (C) 2024 MDW <[email protected]> |
|
6
|
|
|
* Copyright (C) 2024 Frédéric France <[email protected]> |
|
7
|
|
|
* Copyright (C) 2024 Rafael San José <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU General Public License as published by |
|
11
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
12
|
|
|
* (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU General Public License |
|
20
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace Dolibarr\Core\Base; |
|
24
|
|
|
|
|
25
|
|
|
use Dolibarr\Core\Base\CommonObject; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* \file htdocs/core/class/commonobjectline.class.php |
|
29
|
|
|
* \ingroup core |
|
30
|
|
|
* \brief File of the superclass of classes of lines of business objects (invoice, contract, proposal, orders, etc. ...) |
|
31
|
|
|
*/ |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Parent class for class inheritance lines of business objects |
|
36
|
|
|
* This class is useless for the moment so no inherit are done on it |
|
37
|
|
|
* |
|
38
|
|
|
* TODO For the moment we use the extends on CommonObject until PHP min is 5.4 so we can use Traits. |
|
39
|
|
|
*/ |
|
40
|
|
|
abstract class CommonObjectLine extends CommonObject |
|
41
|
|
|
{ |
|
42
|
|
|
/** |
|
43
|
|
|
* @var string ID to identify parent CommonObject type (element name) |
|
44
|
|
|
*/ |
|
45
|
|
|
public $parent_element = ''; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var string Attribute related to parent CommonObject rowid (many2one) |
|
49
|
|
|
*/ |
|
50
|
|
|
public $fk_parent_attribute = ''; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Id of the line |
|
54
|
|
|
* @var int |
|
55
|
|
|
*/ |
|
56
|
|
|
public $id; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Id of the line |
|
60
|
|
|
* @var int |
|
61
|
|
|
* @deprecated Try to use id property as possible (even if field into database is still rowid) |
|
62
|
|
|
* @see $id |
|
63
|
|
|
*/ |
|
64
|
|
|
public $rowid; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png |
|
68
|
|
|
*/ |
|
69
|
|
|
public $picto = 'line'; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @var int|null ID of the unit of measurement (rowid in llx_c_units table) |
|
73
|
|
|
* @see measuringUnitString() |
|
74
|
|
|
* @see getLabelOfUnit() |
|
75
|
|
|
*/ |
|
76
|
|
|
public $fk_unit; |
|
77
|
|
|
|
|
78
|
|
|
public $date_debut_prevue; |
|
79
|
|
|
public $date_debut_reel; |
|
80
|
|
|
public $date_fin_prevue; |
|
81
|
|
|
public $date_fin_reel; |
|
82
|
|
|
|
|
83
|
|
|
public $weight; |
|
84
|
|
|
public $weight_units; |
|
85
|
|
|
public $width; |
|
86
|
|
|
public $width_units; |
|
87
|
|
|
public $height; |
|
88
|
|
|
public $height_units; |
|
89
|
|
|
public $length; |
|
90
|
|
|
public $length_units; |
|
91
|
|
|
public $surface; |
|
92
|
|
|
public $surface_units; |
|
93
|
|
|
public $volume; |
|
94
|
|
|
public $volume_units; |
|
95
|
|
|
|
|
96
|
|
|
public $multilangs; |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @var int type in line |
|
100
|
|
|
*/ |
|
101
|
|
|
public $product_type; |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @var int product id in line (when line is linked to a product or service) |
|
105
|
|
|
*/ |
|
106
|
|
|
public $fk_product; |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Description of the line |
|
110
|
|
|
* @var string |
|
111
|
|
|
*/ |
|
112
|
|
|
public $desc; |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Description of the line |
|
116
|
|
|
* @var string |
|
117
|
|
|
* @deprecated |
|
118
|
|
|
* @see $desc |
|
119
|
|
|
*/ |
|
120
|
|
|
public $description; |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @var Product Object product to store full product object after a fetch_product() on a line |
|
|
|
|
|
|
124
|
|
|
*/ |
|
125
|
|
|
public $product; |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @var string reference in product table |
|
129
|
|
|
*/ |
|
130
|
|
|
public $product_ref; |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @var string label in product table |
|
134
|
|
|
*/ |
|
135
|
|
|
public $product_label; |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @var string barcode in product table |
|
139
|
|
|
*/ |
|
140
|
|
|
public $product_barcode; |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @var string description in product table |
|
144
|
|
|
*/ |
|
145
|
|
|
public $product_desc; |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @var int type in product table |
|
149
|
|
|
*/ |
|
150
|
|
|
public $fk_product_type; |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @var float Quantity |
|
154
|
|
|
*/ |
|
155
|
|
|
public $qty; |
|
156
|
|
|
public $duree; |
|
157
|
|
|
public $remise_percent; |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* List of cumulative options: |
|
161
|
|
|
* Bit 0: 0 for common VAT - 1 if VAT french NPR |
|
162
|
|
|
* Bit 1: 0 si ligne normal - 1 si bit discount (link to line into llx_remise_except) |
|
163
|
|
|
* @var int |
|
164
|
|
|
*/ |
|
165
|
|
|
public $info_bits; |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @var int special code |
|
169
|
|
|
*/ |
|
170
|
|
|
public $special_code; |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Unit price before taxes |
|
174
|
|
|
* @var float |
|
175
|
|
|
*/ |
|
176
|
|
|
public $subprice; |
|
177
|
|
|
public $tva_tx; |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @var int multicurrency id |
|
181
|
|
|
*/ |
|
182
|
|
|
public $fk_multicurrency; |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @var string Multicurrency code |
|
186
|
|
|
*/ |
|
187
|
|
|
public $multicurrency_code; |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* @var float Multicurrency subprice |
|
191
|
|
|
*/ |
|
192
|
|
|
public $multicurrency_subprice; |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @var float Multicurrency total without tax |
|
196
|
|
|
*/ |
|
197
|
|
|
public $multicurrency_total_ht; |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @var float Multicurrency total vat |
|
201
|
|
|
*/ |
|
202
|
|
|
public $multicurrency_total_tva; |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @var float Multicurrency total with tax |
|
206
|
|
|
*/ |
|
207
|
|
|
public $multicurrency_total_ttc; |
|
208
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* Constructor |
|
212
|
|
|
* |
|
213
|
|
|
* @param DoliDB $db Database handler |
|
|
|
|
|
|
214
|
|
|
*/ |
|
215
|
|
|
public function __construct($db) |
|
216
|
|
|
{ |
|
217
|
|
|
$this->db = $db; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* Returns the label, short_label or code found in units dictionary from ->fk_unit. |
|
222
|
|
|
* A langs->trans() must be called on result to get translated value. |
|
223
|
|
|
* |
|
224
|
|
|
* @param string $type Label type ('long', 'short' or 'code'). This can be a translation key. |
|
225
|
|
|
* @return string|int Return integer <0 if KO, label if OK (Example: 'long', 'short' or 'unitCODE') |
|
226
|
|
|
*/ |
|
227
|
|
|
public function getLabelOfUnit($type = 'long') |
|
228
|
|
|
{ |
|
229
|
|
|
global $langs; |
|
230
|
|
|
|
|
231
|
|
|
if (empty($this->fk_unit)) { |
|
232
|
|
|
return ''; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
$langs->load('products'); |
|
236
|
|
|
|
|
237
|
|
|
$label_type = 'label'; |
|
238
|
|
|
if ($type == 'short') { |
|
239
|
|
|
$label_type = 'short_label'; |
|
240
|
|
|
} elseif ($type == 'code') { |
|
241
|
|
|
$label_type = 'code'; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
$sql = "SELECT " . $label_type . ", code from " . $this->db->prefix() . "c_units where rowid = " . ((int) $this->fk_unit); |
|
245
|
|
|
|
|
246
|
|
|
$resql = $this->db->query($sql); |
|
247
|
|
|
if ($resql && $this->db->num_rows($resql) > 0 && $res = $this->db->fetch_array($resql)) { |
|
248
|
|
|
if ($label_type == 'code') { |
|
249
|
|
|
$label = 'unit' . $res['code']; |
|
250
|
|
|
} else { |
|
251
|
|
|
$label = $res[$label_type]; |
|
252
|
|
|
} |
|
253
|
|
|
$this->db->free($resql); |
|
254
|
|
|
return $label; |
|
255
|
|
|
} else { |
|
256
|
|
|
$this->error = $this->db->lasterror(); |
|
257
|
|
|
dol_syslog(get_class($this) . "::getLabelOfUnit Error " . $this->error, LOG_ERR); |
|
258
|
|
|
return -1; |
|
259
|
|
|
} |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* Empty function to prevent errors on call of this function. Must be overload if useful |
|
264
|
|
|
* |
|
265
|
|
|
* @param string $sortorder Sort Order |
|
266
|
|
|
* @param string $sortfield Sort field |
|
267
|
|
|
* @param int $limit Limit the number of lines returned |
|
268
|
|
|
* @param int $offset Offset |
|
269
|
|
|
* @param string|array $filter Filter as an Universal Search string. |
|
270
|
|
|
* Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' |
|
271
|
|
|
* @param string $filtermode No more used |
|
272
|
|
|
* @return array|int int <0 if KO, array of pages if OK |
|
273
|
|
|
*/ |
|
274
|
|
|
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') |
|
275
|
|
|
{ |
|
276
|
|
|
return 0; |
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
|