dolibarr 21.0.0-beta
commonobjectline.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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 <https://www.gnu.org/licenses/>.
19 */
20
34abstract class CommonObjectLine extends CommonObject
35{
39 public $parent_element = '';
40
44 public $fk_parent_attribute = '';
45
50 public $id;
51
58 public $rowid;
59
63 public $picto = 'line';
64
70 public $fk_unit;
71
75 public $date_debut_prevue;
79 public $date_debut_reel;
83 public $date_fin_prevue;
87 public $date_fin_reel;
88
89
93 public $weight;
94
98 public $weight_units; // scale -3, 0, 3, 6
102 public $length;
106 public $length_units; // scale -3, 0, 3, 6
110 public $width;
114 public $width_units; // scale -3, 0, 3, 6
118 public $height;
122 public $height_units; // scale -3, 0, 3, 6
126 public $surface;
130 public $surface_units; // scale -3, 0, 3, 6
134 public $volume;
138 public $volume_units; // scale -3, 0, 3, 6
142 public $multilangs;
143
147 public $product_type;
148
152 public $fk_product;
153
158 public $desc;
159
166 public $description;
167
171 public $product;
172
176 public $product_ref;
177
181 public $product_label;
182
186 public $product_barcode;
187
191 public $product_desc;
192
196 public $fk_product_type;
197
201 public $qty;
205 public $duree;
209 public $remise_percent;
210
217 public $info_bits;
218
222 public $special_code;
223
228 public $subprice;
232 public $tva_tx;
233
237 public $fk_multicurrency;
238
242 public $multicurrency_code;
243
247 public $multicurrency_subprice;
248
252 public $multicurrency_total_ht;
253
257 public $multicurrency_total_tva;
258
262 public $multicurrency_total_ttc;
263
264
270 public function __construct($db)
271 {
272 $this->db = $db;
273 }
274
282 public function getLabelOfUnit($type = 'long')
283 {
284 global $langs;
285
286 if (empty($this->fk_unit)) {
287 return '';
288 }
289
290 $langs->load('products');
291
292 $label_type = 'label';
293 if ($type == 'short') {
294 $label_type = 'short_label';
295 } elseif ($type == 'code') {
296 $label_type = 'code';
297 }
298
299 $sql = "SELECT ".$label_type.", code from ".$this->db->prefix()."c_units where rowid = ".((int) $this->fk_unit);
300
301 $resql = $this->db->query($sql);
302 if ($resql && $this->db->num_rows($resql) > 0 && $res = $this->db->fetch_array($resql)) {
303 if ($label_type == 'code') {
304 $label = 'unit'.$res['code'];
305 } else {
306 $label = $res[$label_type];
307 }
308 $this->db->free($resql);
309 return $label;
310 } else {
311 $this->error = $this->db->lasterror();
312 dol_syslog(get_class($this)."::getLabelOfUnit Error ".$this->error, LOG_ERR);
313 return -1;
314 }
315 }
316
329 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
330 {
331 return -1; // NOK because nothing done.
332 }
333
342 public function getNomUrl($withpicto = 0)
343 {
344 $parentattribute = $this->fk_parent_attribute;
345
346 /*
347 if ($parentattribute) {
348 return 'Parent #'.$this->$parentattribute.' - Line #'.$this->id;
349 } else {
350 return 'Line #'.$this->id;
351 }
352 */
353
354 $parent_element_properties = getElementProperties($this->parent_element);
355 $parent_classname = $parent_element_properties['classname'];
356 $parent_element = new $parent_classname($this->db);
358 $parentattribute = $this->fk_parent_attribute;
359 if ($parentattribute && method_exists($parent_element, 'fetch')) {
360 $parent_element->fetch($this->$parentattribute); // @phan-suppress-current-line PhanPluginUnknownObjectMethodCall
361 }
362
363 return $parent_element->getNomUrl($withpicto).' - Line #'.$this->id; // @phan-suppress-current-line PhanPluginUnknownObjectMethodCall
364 }
365}
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Empty function to prevent errors on call of this function.
getLabelOfUnit($type='long')
Returns the label, short_label or code found in units dictionary from ->fk_unit.
__construct($db)
Constructor.
getElementProperties($elementType)
Get an array with properties of an element.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.