dolibarr/htdocs/core/class/commonobjectline.class.php

170 lines
4.5 KiB
PHP
Raw Normal View History

2008-02-24 18:56:20 +01:00
<?php
/* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
2008-02-24 18:56:20 +01:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
2008-02-24 18:56:20 +01:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2008-02-24 18:56:20 +01:00
*/
/**
2012-08-05 15:00:24 +02:00
* \file htdocs/core/class/commonobjectline.class.php
* \ingroup core
2020-11-09 11:34:58 +01:00
* \brief File of the superclass of classes of lines of business objects (invoice, contract, proposal, orders, etc. ...)
2011-06-19 16:35:16 +02:00
*/
2008-02-24 18:56:20 +01:00
/**
2012-08-05 15:00:24 +02:00
* Parent class for class inheritance lines of business objects
* This class is useless for the moment so no inherit are done on it
2021-09-23 13:39:48 +02:00
*
* TODO For the moment we use the extends on CommonObject until PHP min is 5.4 so we can use Traits.
2011-06-19 16:35:16 +02:00
*/
abstract class CommonObjectLine extends CommonObject
2008-02-24 18:56:20 +01:00
{
2015-03-23 01:39:12 +01:00
/**
* Id of the line
* @var int
*/
public $id;
/**
* Id of the line
* @var int
2015-04-21 15:49:58 +02:00
* @deprecated Try to use id property as possible (even if field into database is still rowid)
2019-04-04 18:33:12 +02:00
* @see $id
2015-03-23 01:39:12 +01:00
*/
public $rowid;
2022-02-21 19:09:26 +01:00
/**
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
*/
public $picto = 'line';
/**
2015-04-21 15:49:58 +02:00
* Product/service unit code ('km', 'm', 'p', ...)
* @var string
*/
public $fk_unit;
2015-04-21 15:49:58 +02:00
2021-10-21 16:48:04 +02:00
public $date_debut_prevue;
public $date_debut_reel;
public $date_fin_prevue;
public $date_fin_reel;
2022-05-18 13:37:49 +02:00
public $weight;
public $weight_units;
public $width;
public $width_units;
public $height;
public $height_units;
public $length;
public $length_units;
public $surface;
public $surface_units;
public $volume;
public $volume_units;
2022-05-18 23:52:43 +02:00
public $multilangs;
2022-05-19 12:59:29 +02:00
public $product_type; // type in line
2022-05-31 14:20:59 +02:00
public $fk_product; // product id in line (when line is linked to a product)
2022-06-11 21:53:14 +02:00
public $desc;
2022-05-31 14:20:59 +02:00
public $product; // To store full product object after a fetch_product() on a line
2022-05-19 12:59:29 +02:00
public $product_ref; // ref in product table
public $product_label; // label in product table
2022-06-02 20:15:49 +02:00
public $product_barcode; // barcode in product table
2022-05-19 12:59:29 +02:00
public $product_desc; // desc in product table
public $fk_product_type; // type in product table
2022-05-19 12:08:03 +02:00
public $qty;
public $duree;
public $remise_percent;
public $info_bits;
public $special_code;
2022-05-18 23:52:43 +02:00
2008-02-24 18:56:20 +01:00
2020-08-05 12:25:26 +02:00
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
$this->db = $db;
}
/**
2021-09-23 13:39:48 +02:00
* Returns the label, short_label or code found in units dictionary from ->fk_unit.
* A langs->trans() must be called on result to get translated value.
*
* @param string $type Label type ('long', 'short' or 'code'). This can be a translation key.
* @return string|int <0 if KO, label if OK (Example: 'long', 'short' or 'unitCODE')
*/
public function getLabelOfUnit($type = 'long')
{
global $langs;
2021-09-01 16:26:59 +02:00
if (empty($this->fk_unit)) {
return '';
}
$langs->load('products');
$label_type = 'label';
$label_type = 'label';
2021-02-23 22:03:23 +01:00
if ($type == 'short') {
$label_type = 'short_label';
} elseif ($type == 'code') {
$label_type = 'code';
}
2022-01-27 10:19:35 +01:00
$sql = "SELECT ".$label_type.", code from ".$this->db->prefix()."c_units where rowid = ".((int) $this->fk_unit);
$resql = $this->db->query($sql);
if ($resql && $this->db->num_rows($resql) > 0) {
$res = $this->db->fetch_array($resql);
2021-02-23 22:03:23 +01:00
if ($label_type == 'code') {
$label = 'unit'.$res['code'];
} else {
$label = $res[$label_type];
}
$this->db->free($resql);
return $label;
2020-05-21 15:05:19 +02:00
} else {
2021-08-28 00:55:51 +02:00
$this->error = $this->db->lasterror();
2015-04-21 15:49:58 +02:00
dol_syslog(get_class($this)."::getLabelOfUnit Error ".$this->error, LOG_ERR);
return -1;
}
}
2021-10-22 11:55:21 +02:00
/**
* Empty function to prevent errors on call of this function must be overload if usefull
*
* @param string $sortorder Sort Order
* @param string $sortfield Sort field
* @param int $limit offset limit
* @param int $offset offset limit
* @param array $filter filter array
* @param string $filtermode filter mode (AND or OR)
* @return int <0 if KO, >0 if OK
*/
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
{
return 0;
}
2008-02-24 18:56:20 +01:00
}