dolibarr 25.0.0-alpha
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-2026 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2026 Lionel Vessiller <lvessiller@open-dsi.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
29
30
37abstract class CommonObjectLine extends CommonObject
38{
42 public $parent_element = '';
43
47 public $fk_parent_attribute = '';
48
53 public $id;
54
61 public $rowid;
62
66 public $picto = 'line';
67
73 public $fk_unit;
74
78 public $date_debut_prevue;
82 public $date_debut_reel;
86 public $date_fin_prevue;
90 public $date_fin_reel;
91
92
96 public $weight;
97
101 public $weight_units; // scale -3, 0, 3, 6
105 public $length;
109 public $length_units; // scale -3, 0, 3, 6
113 public $width;
117 public $width_units; // scale -3, 0, 3, 6
121 public $height;
125 public $height_units; // scale -3, 0, 3, 6
129 public $surface;
133 public $surface_units; // scale -3, 0, 3, 6
137 public $volume;
141 public $volume_units; // scale -3, 0, 3, 6
145 public $multilangs;
146
150 public $product_type;
151
155 public $fk_product;
156
161 public $desc;
162
169 public $description;
170
174 public $product;
175
179 public $product_ref;
180
184 public $product_label;
185
189 public $product_barcode;
190
194 public $product_desc;
195
199 public $product_custom_code;
200
204 public $product_custom_country_code;
205
209 public $product_custom_country_id;
210
214 public $fk_product_type;
215
219 public $qty;
223 public $duree;
227 public $remise_percent;
228
235 public $info_bits;
236
240 public $special_code;
241
246 public $subprice;
247
252 public $subprice_ttc;
253
257 public $tva_tx;
258
262 public $fk_multicurrency;
263
267 public $multicurrency_code;
268
272 public $multicurrency_subprice;
273
277 public $multicurrency_subprice_ttc;
278
282 public $multicurrency_total_ht;
283
287 public $multicurrency_total_tva;
288
292 public $multicurrency_total_localtax1; // not in database
293
297 public $multicurrency_total_localtax2; // not in database
298
302 public $multicurrency_total_ttc;
303
304
310 public function __construct($db)
311 {
312 $this->db = $db;
313 }
314
324 public function getLabelOfUnit($type = 'long', $outputlangs = null, $noentities = 0)
325 {
326 global $langs;
327
328 if (empty($this->fk_unit)) {
329 return '';
330 }
331 if (empty($outputlangs)) {
332 $outputlangs = $langs;
333 }
334
335 $outputlangs->load('products');
336 $label = '';
337
338 $sql = "SELECT code, label, short_label FROM ".$this->db->prefix()."c_units where rowid = ".((int) $this->fk_unit);
339
340 $resql = $this->db->query($sql);
341 if (!$resql) {
342 $this->error = $this->db->error();
343 dol_syslog(get_class($this)."::getLabelOfUnit Error ".$this->error, LOG_ERR);
344 return -1;
345 } elseif ($this->db->num_rows($resql) > 0 && $res = $this->db->fetch_array($resql)) {
346 if ($type == 'short') {
347 if ($noentities) {
348 $label = $outputlangs->transnoentitiesnoconv($res['short_label']);
349 } else {
350 $label = $outputlangs->trans($res['short_label']);
351 }
352 } elseif ($type == 'code') {
353 $label = $res['code'];
354 } else {
355 if ($outputlangs->trans('unit'.$res['code']) == 'unit'.$res['code']) {
356 // No translation available
357 $label = $res['label'];
358 } else {
359 // Return the translated value
360 if ($noentities) {
361 $label = $outputlangs->transnoentitiesnoconv('unit'.$res['code']);
362 } else {
363 $label = $outputlangs->trans('unit'.$res['code']);
364 }
365 }
366 }
367 }
368 $this->db->free($resql);
369
370 return $label;
371 }
372
385 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
386 {
387 return -1; // NOK because nothing done.
388 }
389
398 public function getNomUrl($withpicto = 0)
399 {
400 $parentattribute = $this->fk_parent_attribute;
401
402 /*
403 if ($parentattribute) {
404 return 'Parent #'.$this->$parentattribute.' - Line #'.$this->id;
405 } else {
406 return 'Line #'.$this->id;
407 }
408 */
409
410 $parent_element_properties = getElementProperties($this->parent_element);
411 $parent_classname = $parent_element_properties['classname'];
412 $parent_element = new $parent_classname($this->db);
414 $parentattribute = $this->fk_parent_attribute;
415 if ($parentattribute && method_exists($parent_element, 'fetch')) {
416 $parent_element->fetch($this->$parentattribute); // @phan-suppress-current-line PhanPluginUnknownObjectMethodCall
417 }
418
419 return $parent_element->getNomUrl($withpicto).' - Line #'.$this->id; // @phan-suppress-current-line PhanPluginUnknownObjectMethodCall
420 }
421
430 public function wasEnteredIncludingTax()
431 {
432 return isset($this->subprice_ttc) && (float) $this->subprice_ttc != 0;
433 }
434
442 public function getPriceBaseType()
443 {
444 return $this->wasEnteredIncludingTax() ? 'TTC' : 'HT';
445 }
446}
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
wasEnteredIncludingTax()
Return true if the unit price was originally entered including tax (TTC mode).
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Empty function to prevent errors on call of this function.
getPriceBaseType()
Return the price base type ('TTC' or 'HT') matching how the unit price was entered.
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.