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

203 lines
6.0 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;
}
2022-12-20 17:00:15 +01:00
2022-12-22 14:36:55 +01:00
/**
2022-12-20 17:00:15 +01:00
* Return clicable link of object (with eventually picto)
*
* @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link)
* @return string HTML Code for Kanban thumb.
*/
public function getKanbanView($option = '')
{
2022-12-22 14:04:22 +01:00
global $langs;
2022-12-20 17:00:15 +01:00
$return = '<div class="box-flex-item box-flex-grow-zero">';
$return .= '<div class="info-box info-box-sm">';
$return .= '<span class="info-box-icon bg-infobox-action">';
$return .= img_picto('', $this->picto);
//$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
$return .= '</span>';
$return .= '<div class="info-box-content">';
$return .= '<span class="info-box-ref">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : '').'</span>';
if (property_exists($this, 'date_delivery')) {
2022-12-22 14:04:22 +01:00
$return .= '<br><span class="info-box-label opacitymedium">'.dol_print_date($this->db->jdate($this->date_delivery), "dayhour").'</span>';
2022-12-20 17:00:15 +01:00
}
if (property_exists($this, 'town') && !empty($this->town)) {
$return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Town").'</span>';
$return .= '<span class="info-box-label "> : '.$this->town.'</span>';
}
if (method_exists($this, 'getLibStatut')) {
$return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(5).'</div>';
}
$return .= '</div>';
$return .= '</div>';
$return .= '</div>';
return $return;
}
2008-02-24 18:56:20 +01:00
}