dolibarr 23.0.3
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-2025 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024-2025 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
27require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28
29
36abstract class CommonObjectLine extends CommonObject
37{
41 public $parent_element = '';
42
46 public $fk_parent_attribute = '';
47
52 public $id;
53
60 public $rowid;
61
65 public $picto = 'line';
66
72 public $fk_unit;
73
77 public $date_debut_prevue;
81 public $date_debut_reel;
85 public $date_fin_prevue;
89 public $date_fin_reel;
90
91
95 public $weight;
96
100 public $weight_units; // scale -3, 0, 3, 6
104 public $length;
108 public $length_units; // scale -3, 0, 3, 6
112 public $width;
116 public $width_units; // scale -3, 0, 3, 6
120 public $height;
124 public $height_units; // scale -3, 0, 3, 6
128 public $surface;
132 public $surface_units; // scale -3, 0, 3, 6
136 public $volume;
140 public $volume_units; // scale -3, 0, 3, 6
144 public $multilangs;
145
149 public $product_type;
150
154 public $fk_product;
155
160 public $desc;
161
168 public $description;
169
173 public $product;
174
178 public $product_ref;
179
183 public $product_label;
184
188 public $product_barcode;
189
193 public $product_desc;
194
198 public $product_custom_code;
199
203 public $product_custom_country_code;
204
208 public $product_custom_country_id;
209
213 public $fk_product_type;
214
218 public $qty;
222 public $duree;
226 public $remise_percent;
227
234 public $info_bits;
235
239 public $special_code;
240
245 public $subprice;
246
251 public $subprice_ttc;
252
256 public $tva_tx;
257
261 public $fk_multicurrency;
262
266 public $multicurrency_code;
267
271 public $multicurrency_subprice;
272
276 public $multicurrency_subprice_ttc;
277
281 public $multicurrency_total_ht;
282
286 public $multicurrency_total_tva;
287
291 public $multicurrency_total_localtax1; // not in database
292
296 public $multicurrency_total_localtax2; // not in database
297
301 public $multicurrency_total_ttc;
302
303
309 public function __construct($db)
310 {
311 $this->db = $db;
312 }
313
323 public function getLabelOfUnit($type = 'long', $outputlangs = null, $noentities = 0)
324 {
325 global $langs;
326
327 if (empty($this->fk_unit)) {
328 return '';
329 }
330 if (empty($outputlangs)) {
331 $outputlangs = $langs;
332 }
333
334 $outputlangs->load('products');
335 $label = '';
336
337 $sql = "SELECT code, label, short_label FROM ".$this->db->prefix()."c_units where rowid = ".((int) $this->fk_unit);
338
339 $resql = $this->db->query($sql);
340 if (!$resql) {
341 $this->error = $this->db->error();
342 dol_syslog(get_class($this)."::getLabelOfUnit Error ".$this->error, LOG_ERR);
343 return -1;
344 } elseif ($this->db->num_rows($resql) > 0 && $res = $this->db->fetch_array($resql)) {
345 if ($type == 'short') {
346 if ($noentities) {
347 $label = $outputlangs->transnoentitiesnoconv($res['short_label']);
348 } else {
349 $label = $outputlangs->trans($res['short_label']);
350 }
351 } elseif ($type == 'code') {
352 $label = $res['code'];
353 } else {
354 if ($outputlangs->trans('unit'.$res['code']) == 'unit'.$res['code']) {
355 // No translation available
356 $label = $res['label'];
357 } else {
358 // Return the translated value
359 if ($noentities) {
360 $label = $outputlangs->transnoentitiesnoconv('unit'.$res['code']);
361 } else {
362 $label = $outputlangs->trans('unit'.$res['code']);
363 }
364 }
365 }
366 }
367 $this->db->free($resql);
368
369 return $label;
370 }
371
384 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
385 {
386 return -1; // NOK because nothing done.
387 }
388
397 public function getNomUrl($withpicto = 0)
398 {
399 $parentattribute = $this->fk_parent_attribute;
400
401 /*
402 if ($parentattribute) {
403 return 'Parent #'.$this->$parentattribute.' - Line #'.$this->id;
404 } else {
405 return 'Line #'.$this->id;
406 }
407 */
408
409 $parent_element_properties = getElementProperties($this->parent_element);
410 $parent_classname = $parent_element_properties['classname'];
411 $parent_element = new $parent_classname($this->db);
413 $parentattribute = $this->fk_parent_attribute;
414 if ($parentattribute && method_exists($parent_element, 'fetch')) {
415 $parent_element->fetch($this->$parentattribute); // @phan-suppress-current-line PhanPluginUnknownObjectMethodCall
416 }
417
418 return $parent_element->getNomUrl($withpicto).' - Line #'.$this->id; // @phan-suppress-current-line PhanPluginUnknownObjectMethodCall
419 }
420}
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', $outputlangs=null, $noentities=0)
Reads the units dictionary to return the translation code of a unit (if type='code'),...
__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.