dolibarr 21.0.4
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_subprice_ttc;
253
257 public $multicurrency_total_ht;
258
262 public $multicurrency_total_tva;
263
267 public $multicurrency_total_ttc;
268
269
275 public function __construct($db)
276 {
277 $this->db = $db;
278 }
279
289 public function getLabelOfUnit($type = 'long', $outputlangs = null, $noentities = 0)
290 {
291 global $langs;
292
293 if (empty($this->fk_unit)) {
294 return '';
295 }
296 if (empty($outputlangs)) {
297 $outputlangs = $langs;
298 }
299
300 $outputlangs->load('products');
301 $label = '';
302
303 $sql = "SELECT code, label, short_label FROM ".$this->db->prefix()."c_units where rowid = ".((int) $this->fk_unit);
304
305 $resql = $this->db->query($sql);
306 if (!$resql) {
307 $this->error = $this->db->error();
308 dol_syslog(get_class($this)."::getLabelOfUnit Error ".$this->error, LOG_ERR);
309 return -1;
310 } elseif ($this->db->num_rows($resql) > 0 && $res = $this->db->fetch_array($resql)) {
311 if ($type == 'short') {
312 if ($noentities) {
313 $label = $outputlangs->transnoentitiesnoconv($res['short_label']);
314 } else {
315 $label = $outputlangs->trans($res['short_label']);
316 }
317 } elseif ($type == 'code') {
318 $label = $res['code'];
319 } else {
320 if ($outputlangs->trans('unit'.$res['code']) == 'unit'.$res['code']) {
321 // No translation available
322 $label = $res['label'];
323 } else {
324 // Return the translated value
325 if ($noentities) {
326 $label = $outputlangs->transnoentitiesnoconv('unit'.$res['code']);
327 } else {
328 $label = $outputlangs->trans('unit'.$res['code']);
329 }
330 }
331 }
332 }
333 $this->db->free($resql);
334
335 return $label;
336 }
337
350 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
351 {
352 return -1; // NOK because nothing done.
353 }
354
363 public function getNomUrl($withpicto = 0)
364 {
365 $parentattribute = $this->fk_parent_attribute;
366
367 /*
368 if ($parentattribute) {
369 return 'Parent #'.$this->$parentattribute.' - Line #'.$this->id;
370 } else {
371 return 'Line #'.$this->id;
372 }
373 */
374
375 $parent_element_properties = getElementProperties($this->parent_element);
376 $parent_classname = $parent_element_properties['classname'];
377 $parent_element = new $parent_classname($this->db);
379 $parentattribute = $this->fk_parent_attribute;
380 if ($parentattribute && method_exists($parent_element, 'fetch')) {
381 $parent_element->fetch($this->$parentattribute); // @phan-suppress-current-line PhanPluginUnknownObjectMethodCall
382 }
383
384 return $parent_element->getNomUrl($withpicto).' - Line #'.$this->id; // @phan-suppress-current-line PhanPluginUnknownObjectMethodCall
385 }
386}
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.