|
@@ -13,7 +13,7 @@
|
|
|
* Copyright (C) 2014-2016 Philippe Grand <philippe.grand@atoo-net.com>
|
|
|
* Copyright (C) 2014 Ion agorria <ion@agorria.com>
|
|
|
* Copyright (C) 2016-2017 Ferran Marcet <fmarcet@2byte.es>
|
|
|
- * Copyright (C) 2017 Gustavo Novaro
|
|
|
+ * Copyright (C) 2017 Gustavo Novaro
|
|
|
*
|
|
|
* 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
|
|
@@ -67,7 +67,7 @@ class Product extends CommonObject
|
|
|
* @var string
|
|
|
*/
|
|
|
public $label;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Product descripion
|
|
|
* @var string
|
|
@@ -79,37 +79,37 @@ class Product extends CommonObject
|
|
|
* @var int
|
|
|
*/
|
|
|
public $type = self::TYPE_PRODUCT;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Selling price
|
|
|
* @var float
|
|
|
*/
|
|
|
public $price; // Price net
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Price with tax
|
|
|
* @var float
|
|
|
*/
|
|
|
public $price_ttc;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Minimum price net
|
|
|
* @var float
|
|
|
*/
|
|
|
public $price_min;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Minimum price with tax
|
|
|
* @var float
|
|
|
*/
|
|
|
public $price_min_ttc;
|
|
|
-
|
|
|
+
|
|
|
/*
|
|
|
* Base price ('TTC' for price including tax or 'HT' for net price)
|
|
|
* @var float
|
|
|
*/
|
|
|
public $price_base_type;
|
|
|
-
|
|
|
+
|
|
|
//! Arrays for multiprices
|
|
|
public $multiprices=array();
|
|
|
public $multiprices_ttc=array();
|
|
@@ -118,88 +118,88 @@ class Product extends CommonObject
|
|
|
public $multiprices_min_ttc=array();
|
|
|
public $multiprices_tva_tx=array();
|
|
|
public $multiprices_recuperableonly=array();
|
|
|
-
|
|
|
+
|
|
|
//! Price by quantity arrays
|
|
|
public $price_by_qty;
|
|
|
public $prices_by_qty=array();
|
|
|
public $prices_by_qty_id=array();
|
|
|
public $prices_by_qty_list=array();
|
|
|
-
|
|
|
+
|
|
|
//! Default VAT code for product (link to code into llx_c_tva but without foreign keys)
|
|
|
public $default_vat_code;
|
|
|
-
|
|
|
+
|
|
|
//! Default VAT rate of product
|
|
|
public $tva_tx;
|
|
|
-
|
|
|
+
|
|
|
//! French VAT NPR (0 or 1)
|
|
|
public $tva_npr=0;
|
|
|
-
|
|
|
+
|
|
|
//! Other local taxes
|
|
|
public $localtax1_tx;
|
|
|
public $localtax2_tx;
|
|
|
public $localtax1_type;
|
|
|
public $localtax2_type;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Stock real
|
|
|
* @var int
|
|
|
*/
|
|
|
public $stock_reel = 0;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Stock virtual
|
|
|
* @var int
|
|
|
*/
|
|
|
public $stock_theorique;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Cost price
|
|
|
* @var float
|
|
|
*/
|
|
|
public $cost_price;
|
|
|
-
|
|
|
+
|
|
|
//! Average price value for product entry into stock (PMP)
|
|
|
public $pmp;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Stock alert
|
|
|
* @var int
|
|
|
*/
|
|
|
public $seuil_stock_alerte;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Ask for replenishment when $desiredstock < $stock_reel
|
|
|
*/
|
|
|
public $desiredstock;
|
|
|
-
|
|
|
+
|
|
|
/*
|
|
|
* Service expiration
|
|
|
*/
|
|
|
public $duration_value;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Exoiration unit
|
|
|
*/
|
|
|
public $duration_unit;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Status indicates whether the product is on sale '1' or not '0'
|
|
|
* @var int
|
|
|
*/
|
|
|
public $status;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Status indicate whether the product is available for purchase '1' or not '0'
|
|
|
* @var int
|
|
|
*/
|
|
|
public $status_buy;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Status indicates whether the product is a finished product '1' or a raw material '0'
|
|
|
* @var int
|
|
|
*/
|
|
|
public $finished;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* We must manage lot/batch number, sell-by date and so on : '1':yes '0':no
|
|
|
* @var int
|
|
@@ -234,10 +234,10 @@ class Product extends CommonObject
|
|
|
/**
|
|
|
* Main barcode
|
|
|
* barcode value
|
|
|
- * @var
|
|
|
+ * @var
|
|
|
*/
|
|
|
public $barcode;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Additional barcodes (Some products have different barcodes according to the country of origin of manufacture)
|
|
|
* @var array
|
|
@@ -282,7 +282,7 @@ class Product extends CommonObject
|
|
|
public $fourn_pu;
|
|
|
|
|
|
public $fourn_price_base_type;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @deprecated
|
|
|
* @see ref_supplier
|
|
@@ -302,7 +302,7 @@ class Product extends CommonObject
|
|
|
*/
|
|
|
public $price_autogen = 0;
|
|
|
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Regular product
|
|
|
*/
|
|
@@ -320,7 +320,7 @@ class Product extends CommonObject
|
|
|
*/
|
|
|
const TYPE_STOCKKIT = 3;
|
|
|
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Constructor
|
|
|
*
|
|
@@ -394,7 +394,7 @@ class Product extends CommonObject
|
|
|
if (empty($this->localtax2_tx)) $this->localtax2_tx = 0;
|
|
|
if (empty($this->localtax1_type)) $this->localtax1_type = '0';
|
|
|
if (empty($this->localtax2_type)) $this->localtax2_type = '0';
|
|
|
-
|
|
|
+
|
|
|
if (empty($this->price)) $this->price = 0;
|
|
|
if (empty($this->price_min)) $this->price_min = 0;
|
|
|
|
|
@@ -408,28 +408,28 @@ class Product extends CommonObject
|
|
|
$price_ttc=0;
|
|
|
$price_min_ht=0;
|
|
|
$price_min_ttc=0;
|
|
|
-
|
|
|
+
|
|
|
//
|
|
|
if ($this->price_base_type == 'TTC' && $this->price_ttc > 0)
|
|
|
{
|
|
|
$price_ttc = price2num($this->price_ttc,'MU');
|
|
|
$price_ht = price2num($this->price_ttc / (1 + ($this->tva_tx / 100)),'MU');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//
|
|
|
if ($this->price_base_type != 'TTC' && $this->price > 0)
|
|
|
{
|
|
|
$price_ht = price2num($this->price,'MU');
|
|
|
$price_ttc = price2num($this->price * (1 + ($this->tva_tx / 100)),'MU');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//
|
|
|
if (($this->price_min_ttc > 0) && ($this->price_base_type == 'TTC'))
|
|
|
{
|
|
|
$price_min_ttc = price2num($this->price_min_ttc,'MU');
|
|
|
$price_min_ht = price2num($this->price_min_ttc / (1 + ($this->tva_tx / 100)),'MU');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//
|
|
|
if (($this->price_min > 0) && ($this->price_base_type != 'TTC'))
|
|
|
{
|
|
@@ -449,7 +449,7 @@ class Product extends CommonObject
|
|
|
$this->error='ErrorMandatoryParametersNotProvided';
|
|
|
return -1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (empty($this->ref))
|
|
|
{
|
|
|
// Load object modCodeProduct
|
|
@@ -468,7 +468,7 @@ class Product extends CommonObject
|
|
|
}
|
|
|
unset($modCodeProduct);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (empty($this->ref))
|
|
|
{
|
|
|
$this->error='ProductModuleNotSetupForAutoRef';
|
|
@@ -752,7 +752,7 @@ class Product extends CommonObject
|
|
|
$this->volume = $this->surface * $this->height;
|
|
|
$this->volume_units = $this->surface_units + $this->height_units;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$this->surface = price2num($this->surface);
|
|
|
$this->surface_units = trim($this->surface_units);
|
|
|
$this->volume = price2num($this->volume);
|
|
@@ -792,7 +792,7 @@ class Product extends CommonObject
|
|
|
$org->fetch($this->id);
|
|
|
$this->oldcopy=$org;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Test if batch management is activated on existing product
|
|
|
// If yes, we create missing entries into product_batch
|
|
|
if ($this->hasbatch() && !$this->oldcopy->hasbatch())
|
|
@@ -808,7 +808,7 @@ class Product extends CommonObject
|
|
|
$qty_batch = 0;
|
|
|
foreach ($ObjW->detail_batch as $detail) // Each lines of detail in product_batch of the current $ObjW = product_stock
|
|
|
{
|
|
|
- if ($detail->batch == $valueforundefinedlot || $detail->batch == 'Undefined')
|
|
|
+ if ($detail->batch == $valueforundefinedlot || $detail->batch == 'Undefined')
|
|
|
{
|
|
|
// We discard this line, we will create it later
|
|
|
$sqlclean="DELETE FROM ".MAIN_DB_PREFIX."product_batch WHERE batch in('Undefined', '".$valueforundefinedlot."') AND fk_product_stock = ".$ObjW->id;
|
|
@@ -820,7 +820,7 @@ class Product extends CommonObject
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$qty_batch += $detail->qty;
|
|
|
}
|
|
|
// Quantities in batch details are not same as stock quantity,
|
|
@@ -828,7 +828,7 @@ class Product extends CommonObject
|
|
|
if ($ObjW->real <> $qty_batch)
|
|
|
{
|
|
|
$ObjBatch = new Productbatch($this->db);
|
|
|
- $ObjBatch->batch = $valueforundefinedlot;
|
|
|
+ $ObjBatch->batch = $valueforundefinedlot;
|
|
|
$ObjBatch->qty = ($ObjW->real - $qty_batch);
|
|
|
$ObjBatch->fk_product_stock = $ObjW->id;
|
|
|
|
|
@@ -855,7 +855,7 @@ class Product extends CommonObject
|
|
|
$sql.= ", localtax2_tx = " . $this->localtax2_tx;
|
|
|
$sql.= ", localtax1_type = " . ($this->localtax1_type!=''?"'".$this->localtax1_type."'":"'0'");
|
|
|
$sql.= ", localtax2_type = " . ($this->localtax2_type!=''?"'".$this->localtax2_type."'":"'0'");
|
|
|
-
|
|
|
+
|
|
|
$sql.= ", barcode = ". (empty($this->barcode)?"null":"'".$this->db->escape($this->barcode)."'");
|
|
|
$sql.= ", fk_barcode_type = ". (empty($this->barcode_type)?"null":$this->db->escape($this->barcode_type));
|
|
|
|
|
@@ -1056,8 +1056,8 @@ class Product extends CommonObject
|
|
|
if ($result < 0) { $error++; }
|
|
|
// End call triggers
|
|
|
}
|
|
|
-
|
|
|
- // Delete from product_batch on product delete
|
|
|
+
|
|
|
+ // Delete from product_batch on product delete
|
|
|
if (! $error)
|
|
|
{
|
|
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX.'product_batch';
|
|
@@ -1072,7 +1072,7 @@ class Product extends CommonObject
|
|
|
$this->errors[] = $this->db->lasterror();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Delete all child tables
|
|
|
if (! $error)
|
|
|
{
|
|
@@ -1190,7 +1190,7 @@ class Product extends CommonObject
|
|
|
function setMultiLangs($user)
|
|
|
{
|
|
|
global $conf, $langs;
|
|
|
-
|
|
|
+
|
|
|
$langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2);
|
|
|
$current_lang = $langs->getDefaultLang();
|
|
|
|
|
@@ -1509,7 +1509,7 @@ class Product extends CommonObject
|
|
|
$sql.= " WHERE pfp.rowid = ".$prodfournprice;
|
|
|
if ($qty > 0) $sql.= " AND pfp.quantity <= ".$qty;
|
|
|
$sql.= " ORDER BY pfp.quantity DESC";
|
|
|
-
|
|
|
+
|
|
|
dol_syslog(get_class($this)."::get_buyprice first search by prodfournprice/qty", LOG_DEBUG);
|
|
|
$resql = $this->db->query($sql);
|
|
|
if ($resql)
|
|
@@ -1641,7 +1641,7 @@ class Product extends CommonObject
|
|
|
|
|
|
// If multiprices are enabled, then we check if the current product is subject to price autogeneration
|
|
|
// Price will be modified ONLY when the first one is the one that is being modified
|
|
|
- if (!empty($conf->global->PRODUIT_MULTIPRICES) && !$ignore_autogen && $this->price_autogen && ($level == 1))
|
|
|
+ if (!empty($conf->global->PRODUIT_MULTIPRICES) && !$ignore_autogen && $this->price_autogen && ($level == 1))
|
|
|
{
|
|
|
return $this->generateMultiprices($user, $newprice, $newpricebase, $newvat, $newnpr, $newpsq);
|
|
|
}
|
|
@@ -1709,7 +1709,7 @@ class Product extends CommonObject
|
|
|
}
|
|
|
if (empty($localtax1)) $localtax1=0; // If = '' then = 0
|
|
|
if (empty($localtax2)) $localtax2=0; // If = '' then = 0
|
|
|
-
|
|
|
+
|
|
|
$this->db->begin();
|
|
|
|
|
|
// Ne pas mettre de quote sur les numeriques decimaux.
|
|
@@ -1755,7 +1755,7 @@ class Product extends CommonObject
|
|
|
$this->localtax2_tx = $localtax2;
|
|
|
$this->localtax1_type = $localtaxtype1;
|
|
|
$this->localtax2_type = $localtaxtype2;
|
|
|
-
|
|
|
+
|
|
|
// Price by quantity
|
|
|
$this->price_by_qty = $newpsq;
|
|
|
|
|
@@ -1857,7 +1857,7 @@ class Product extends CommonObject
|
|
|
$this->url = $obj->url;
|
|
|
$this->note_private = $obj->note_private;
|
|
|
$this->note = $obj->note_private; // deprecated
|
|
|
-
|
|
|
+
|
|
|
$this->type = $obj->fk_product_type;
|
|
|
$this->status = $obj->tosell;
|
|
|
$this->status_buy = $obj->tobuy;
|
|
@@ -1881,7 +1881,7 @@ class Product extends CommonObject
|
|
|
$this->localtax2_tx = $obj->localtax2_tx;
|
|
|
$this->localtax1_type = $obj->localtax1_type;
|
|
|
$this->localtax2_type = $obj->localtax2_type;
|
|
|
-
|
|
|
+
|
|
|
$this->finished = $obj->finished;
|
|
|
$this->duration = $obj->duration;
|
|
|
$this->duration_value = substr($obj->duration,0,dol_strlen($obj->duration)-1);
|
|
@@ -1933,7 +1933,7 @@ class Product extends CommonObject
|
|
|
|
|
|
// multilangs
|
|
|
if (! empty($conf->global->MAIN_MULTILANGS)) $this->getMultiLangs();
|
|
|
-
|
|
|
+
|
|
|
// Load multiprices array
|
|
|
if (! empty($conf->global->PRODUIT_MULTIPRICES))
|
|
|
{
|
|
@@ -2166,29 +2166,29 @@ class Product extends CommonObject
|
|
|
$this->stats_commande['rows']=$obj->nb_rows;
|
|
|
$this->stats_commande['qty']=$obj->qty?$obj->qty:0;
|
|
|
|
|
|
- // if it's a virtual product, maybe it is in order by extension
|
|
|
+ // if it's a virtual product, maybe it is in order by extension
|
|
|
if (! empty($conf->global->ORDER_ADD_ORDERS_WITH_PARENT_PROD_IF_INCDEC))
|
|
|
- {
|
|
|
+ {
|
|
|
$TFather = $this->getFather();
|
|
|
if (is_array($TFather) && !empty($TFather)) {
|
|
|
foreach($TFather as &$fatherData) {
|
|
|
$pFather = new Product($this->db);
|
|
|
- $pFather->id = $fatherData['id'];
|
|
|
+ $pFather->id = $fatherData['id'];
|
|
|
$qtyCoef = $fatherData['qty'];
|
|
|
-
|
|
|
+
|
|
|
if ($fatherData['incdec']) {
|
|
|
$pFather->load_stats_commande($socid, $filtrestatut);
|
|
|
-
|
|
|
+
|
|
|
$this->stats_commande['customers']+=$pFather->stats_commande['customers'];
|
|
|
$this->stats_commande['nb']+=$pFather->stats_commande['nb'];
|
|
|
$this->stats_commande['rows']+=$pFather->stats_commande['rows'];
|
|
|
$this->stats_commande['qty']+=$pFather->stats_commande['qty'] * $qtyCoef;
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return 1;
|
|
|
}
|
|
|
else
|
|
@@ -2483,7 +2483,7 @@ class Product extends CommonObject
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- if (empty($year))
|
|
|
+ if (empty($year))
|
|
|
{
|
|
|
$year = strftime('%Y',time());
|
|
|
$month = strftime('%m',time());
|
|
@@ -2607,7 +2607,7 @@ class Product extends CommonObject
|
|
|
$sql = "SELECT sum(d.qty), date_format(p.datep, '%Y%m')";
|
|
|
if ($mode == 'bynumber') $sql.= ", count(DISTINCT p.rowid)";
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."propaldet as d, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."societe as s";
|
|
|
- if ($filteronproducttype >= 0) $sql.=", ".MAIN_DB_PREFIX."product as prod";
|
|
|
+ if ($filteronproducttype >= 0) $sql.=", ".MAIN_DB_PREFIX."product as prod";
|
|
|
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
|
|
$sql.= " WHERE p.rowid = d.fk_propal";
|
|
|
if ($this->id > 0) $sql.= " AND d.fk_product =".$this->id;
|
|
@@ -2642,7 +2642,7 @@ class Product extends CommonObject
|
|
|
$sql = "SELECT sum(d.qty), date_format(p.date_valid, '%Y%m')";
|
|
|
if ($mode == 'bynumber') $sql.= ", count(DISTINCT p.rowid)";
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposaldet as d, ".MAIN_DB_PREFIX."supplier_proposal as p, ".MAIN_DB_PREFIX."societe as s";
|
|
|
- if ($filteronproducttype >= 0) $sql.=", ".MAIN_DB_PREFIX."product as prod";
|
|
|
+ if ($filteronproducttype >= 0) $sql.=", ".MAIN_DB_PREFIX."product as prod";
|
|
|
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
|
|
$sql.= " WHERE p.rowid = d.fk_supplier_proposal";
|
|
|
if ($this->id > 0) $sql.= " AND d.fk_product =".$this->id;
|
|
@@ -2658,7 +2658,7 @@ class Product extends CommonObject
|
|
|
|
|
|
return $this->_get_stats($sql,$mode, $year);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Return nb of units or orders in which product is included
|
|
|
*
|
|
@@ -2710,7 +2710,7 @@ class Product extends CommonObject
|
|
|
$sql = "SELECT sum(d.qty), date_format(c.date_commande, '%Y%m')";
|
|
|
if ($mode == 'bynumber') $sql.= ", count(DISTINCT c.rowid)";
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as d, ".MAIN_DB_PREFIX."commande_fournisseur as c, ".MAIN_DB_PREFIX."societe as s";
|
|
|
- if ($filteronproducttype >= 0) $sql.=", ".MAIN_DB_PREFIX."product as p";
|
|
|
+ if ($filteronproducttype >= 0) $sql.=", ".MAIN_DB_PREFIX."product as p";
|
|
|
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
|
|
$sql.= " WHERE c.rowid = d.fk_commande";
|
|
|
if ($this->id > 0) $sql.= " AND d.fk_product =".$this->id;
|
|
@@ -2900,7 +2900,7 @@ class Product extends CommonObject
|
|
|
$now=dol_now();
|
|
|
|
|
|
dol_syslog(get_class($this)."::add_fournisseur id_fourn = ".$id_fourn." ref_fourn=".$ref_fourn." quantity=".$quantity, LOG_DEBUG);
|
|
|
-
|
|
|
+
|
|
|
if ($ref_fourn)
|
|
|
{
|
|
|
$sql = "SELECT rowid, fk_product";
|
|
@@ -3289,7 +3289,7 @@ class Product extends CommonObject
|
|
|
function getChildsArbo($id, $firstlevelonly=0, $level=1)
|
|
|
{
|
|
|
global $alreadyfound;
|
|
|
-
|
|
|
+
|
|
|
$sql = "SELECT p.rowid, p.label as label, pa.qty as qty, pa.fk_product_fils as id, p.fk_product_type, pa.incdec";
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
|
|
|
$sql.= ", ".MAIN_DB_PREFIX."product_association as pa";
|
|
@@ -3298,18 +3298,18 @@ class Product extends CommonObject
|
|
|
$sql.= " AND pa.fk_product_fils != ".$id; // This should not happens, it is to avoid infinite loop if it happens
|
|
|
|
|
|
dol_syslog(get_class($this).'::getChildsArbo id='.$id.' level='.$level, LOG_DEBUG);
|
|
|
-
|
|
|
+
|
|
|
if ($level == 1) $alreadyfound=array($id=>1); // We init array of found object to start of tree, so if we found it later (should not happened), we stop immediatly
|
|
|
// Protection against infinite loop
|
|
|
if ($level > 30) return array();
|
|
|
-
|
|
|
+
|
|
|
$res = $this->db->query($sql);
|
|
|
if ($res)
|
|
|
{
|
|
|
$prods = array();
|
|
|
while ($rec = $this->db->fetch_array($res))
|
|
|
{
|
|
|
- if (! empty($alreadyfound[$rec['rowid']]))
|
|
|
+ if (! empty($alreadyfound[$rec['rowid']]))
|
|
|
{
|
|
|
dol_syslog(get_class($this).'::getChildsArbo the product id='.$rec['rowid'].' was already found at a higher level in tree. We discard to avoid infinite loop', LOG_WARNING);
|
|
|
continue;
|
|
@@ -3379,7 +3379,7 @@ class Product extends CommonObject
|
|
|
$result='';
|
|
|
$newref=$this->ref;
|
|
|
if ($maxlength) $newref=dol_trunc($newref,$maxlength,'middle');
|
|
|
-
|
|
|
+
|
|
|
if ($this->type == Product::TYPE_PRODUCT) $label = '<u>' . $langs->trans("ShowProduct") . '</u>';
|
|
|
if ($this->type == Product::TYPE_SERVICE) $label = '<u>' . $langs->trans("ShowService") . '</u>';
|
|
|
if (! empty($this->ref))
|
|
@@ -3402,13 +3402,13 @@ class Product extends CommonObject
|
|
|
{
|
|
|
//
|
|
|
}
|
|
|
- if (! empty($this->entity))
|
|
|
+ if (! empty($this->entity))
|
|
|
{
|
|
|
$tmpphoto = $this->show_photos($conf->product->multidir_output[$this->entity],1,1,0,0,0,80);
|
|
|
- if ($this->nbphoto > 0) $label .= '<br>' . $tmpphoto;
|
|
|
+ if ($this->nbphoto > 0) $label .= '<br>' . $tmpphoto;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
$linkclose='';
|
|
|
if (empty($notooltip))
|
|
|
{
|
|
@@ -3420,7 +3420,7 @@ class Product extends CommonObject
|
|
|
|
|
|
$linkclose.= ' title="'.dol_escape_htmltag($label, 1, 1).'"';
|
|
|
$linkclose.=' class="classfortooltip"';
|
|
|
-
|
|
|
+
|
|
|
if (! is_object($hookmanager))
|
|
|
{
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
|
|
@@ -3445,7 +3445,7 @@ class Product extends CommonObject
|
|
|
$linkstart = '<a href="'.$url.'"';
|
|
|
$linkstart.=$linkclose.'>';
|
|
|
$linkend='</a>';
|
|
|
-
|
|
|
+
|
|
|
if ($withpicto) {
|
|
|
if ($this->type == Product::TYPE_PRODUCT) $result.=($linkstart.img_object(($notooltip?'':$label), 'product', ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend.' ');
|
|
|
if ($this->type == Product::TYPE_SERVICE) $result.=($linkstart.img_object(($notooltip?'':$label), 'service', ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend.' ');
|
|
@@ -3523,7 +3523,7 @@ class Product extends CommonObject
|
|
|
function LibStatut($status,$mode=0,$type=0)
|
|
|
{
|
|
|
global $conf, $langs;
|
|
|
-
|
|
|
+
|
|
|
$langs->load('products');
|
|
|
if (! empty($conf->productbatch->enabled)) $langs->load("productbatch");
|
|
|
|
|
@@ -3630,7 +3630,7 @@ class Product extends CommonObject
|
|
|
$this->db->begin();
|
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php';
|
|
|
-
|
|
|
+
|
|
|
$op[0] = "+".trim($nbpiece);
|
|
|
$op[1] = "-".trim($nbpiece);
|
|
|
|
|
@@ -3704,14 +3704,14 @@ class Product extends CommonObject
|
|
|
|
|
|
/**
|
|
|
* Load information about stock of a product into ->stock_reel, ->stock_warehouse[] (including stock_warehouse[idwarehouse]->detail_batch for batch products)
|
|
|
- * This function need a lot of load. If you use it on list, use a cache to execute it once for each product id.
|
|
|
+ * This function need a lot of load. If you use it on list, use a cache to execute it once for each product id.
|
|
|
* If ENTREPOT_EXTRA_STATUS set, filtering on warehouse status possible.
|
|
|
*
|
|
|
- * @param string $option '' = Load all stock info, also from closed and internal warehouses,
|
|
|
- * 'nobatch' = Do not load batch information,
|
|
|
+ * @param string $option '' = Load all stock info, also from closed and internal warehouses,
|
|
|
+ * 'nobatch' = Do not load batch information,
|
|
|
* 'novirtual' = Do not load virtual stock,
|
|
|
* 'warehouseopen' = Load stock from open warehouses only,
|
|
|
- * 'warehouseclosed' = Load stock from closed warehouses only,
|
|
|
+ * 'warehouseclosed' = Load stock from closed warehouses only,
|
|
|
* 'warehouseinternal' = Load stock from warehouses for internal correction/transfer only
|
|
|
* @return int < 0 if KO, > 0 if OK
|
|
|
* @see load_virtual_stock, getBatchInfo
|
|
@@ -3719,26 +3719,26 @@ class Product extends CommonObject
|
|
|
function load_stock($option='')
|
|
|
{
|
|
|
global $conf;
|
|
|
-
|
|
|
+
|
|
|
$this->stock_reel = 0;
|
|
|
$this->stock_warehouse = array();
|
|
|
$this->stock_theorique = 0;
|
|
|
|
|
|
$warehouseStatus = array();
|
|
|
|
|
|
- if (preg_match('/warehouseclosed/', $option))
|
|
|
+ if (preg_match('/warehouseclosed/', $option))
|
|
|
{
|
|
|
$warehouseStatus[] = Entrepot::STATUS_CLOSED;
|
|
|
}
|
|
|
- if (preg_match('/warehouseopen/', $option))
|
|
|
+ if (preg_match('/warehouseopen/', $option))
|
|
|
{
|
|
|
$warehouseStatus[] = Entrepot::STATUS_OPEN_ALL;
|
|
|
}
|
|
|
- if (preg_match('/warehouseinternal/', $option))
|
|
|
+ if (preg_match('/warehouseinternal/', $option))
|
|
|
{
|
|
|
$warehouseStatus[] = Entrepot::STATUS_OPEN_INTERNAL;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$sql = "SELECT ps.rowid, ps.reel, ps.fk_entrepot";
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
|
|
|
$sql.= ", ".MAIN_DB_PREFIX."entrepot as w";
|
|
@@ -3768,7 +3768,7 @@ class Product extends CommonObject
|
|
|
}
|
|
|
$this->db->free($result);
|
|
|
|
|
|
- if (! preg_match('/novirtual/', $option))
|
|
|
+ if (! preg_match('/novirtual/', $option))
|
|
|
{
|
|
|
$this->load_virtual_stock(); // This also load stats_commande_fournisseur, ...
|
|
|
}
|
|
@@ -3784,7 +3784,7 @@ class Product extends CommonObject
|
|
|
|
|
|
/**
|
|
|
* Load value ->stock_theorique of a product. Property this->id must be defined.
|
|
|
- * This function need a lot of load. If you use it on list, use a cache to execute it one for each product id.
|
|
|
+ * This function need a lot of load. If you use it on list, use a cache to execute it one for each product id.
|
|
|
*
|
|
|
* @return int < 0 if KO, > 0 if OK
|
|
|
* @see load_stock, getBatchInfo
|
|
@@ -3932,7 +3932,7 @@ class Product extends CommonObject
|
|
|
{
|
|
|
include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
|
|
|
include_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php';
|
|
|
-
|
|
|
+
|
|
|
global $conf;
|
|
|
|
|
|
$dir = $sdir;
|
|
@@ -3982,7 +3982,7 @@ class Product extends CommonObject
|
|
|
|
|
|
$sortfield='position_name';
|
|
|
$sortorder='asc';
|
|
|
-
|
|
|
+
|
|
|
$dir = $sdir . '/';
|
|
|
$pdir = '/';
|
|
|
$dir .= get_exdir(0,0,0,0,$this,'product').$this->ref.'/';
|
|
@@ -4002,7 +4002,7 @@ class Product extends CommonObject
|
|
|
$relativedir = preg_replace('/^[\\/]/','',$relativedir);
|
|
|
$relativedir = preg_replace('/[\\/]$/','',$relativedir);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$dirthumb = $dir.'thumbs/';
|
|
|
$pdirthumb = $pdir.'thumbs/';
|
|
|
|
|
@@ -4010,7 +4010,7 @@ class Product extends CommonObject
|
|
|
$nbphoto=0;
|
|
|
|
|
|
$filearray=dol_dir_list($dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
|
|
|
-
|
|
|
+
|
|
|
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs
|
|
|
{
|
|
|
$filearrayold=dol_dir_list($dirold,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
|
|
@@ -4018,10 +4018,10 @@ class Product extends CommonObject
|
|
|
}
|
|
|
|
|
|
$filearrayindatabase = dol_dir_list_in_database($relativedir, '', null, 'name', SORT_ASC);
|
|
|
-
|
|
|
+
|
|
|
//var_dump($filearray);
|
|
|
//var_dump($filearrayindatabase);
|
|
|
-
|
|
|
+
|
|
|
// Complete filearray with properties found into $filearrayindatabase
|
|
|
foreach($filearray as $key => $val)
|
|
|
{
|
|
@@ -4042,19 +4042,19 @@ class Product extends CommonObject
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (count($filearray))
|
|
|
{
|
|
|
if ($sortfield && $sortorder)
|
|
|
{
|
|
|
$filearray=dol_sort_array($filearray, $sortfield, $sortorder);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
foreach($filearray as $key => $val)
|
|
|
{
|
|
|
$photo='';
|
|
|
$file = $val['name'];
|
|
|
-
|
|
|
+
|
|
|
//if (! utf8_check($file)) $file=utf8_encode($file); // To be sure file is stored in UTF8 in memory
|
|
|
|
|
|
//if (dol_is_file($dir.$file) && image_format_supported($file) >= 0)
|
|
@@ -4069,7 +4069,7 @@ class Product extends CommonObject
|
|
|
// Find name of thumb file
|
|
|
$photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small'));
|
|
|
if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette='';
|
|
|
-
|
|
|
+
|
|
|
// Get filesize of original file
|
|
|
$imgarray=dol_getImageSize($dir.$photo);
|
|
|
|
|
@@ -4083,9 +4083,9 @@ class Product extends CommonObject
|
|
|
else if ($nbbyrow < 0) $return .= '<div class="inline-block">';
|
|
|
|
|
|
$return.= "\n";
|
|
|
-
|
|
|
+
|
|
|
$relativefile=preg_replace('/^\//', '', $pdir.$photo);
|
|
|
- if (empty($nolink))
|
|
|
+ if (empty($nolink))
|
|
|
{
|
|
|
$urladvanced=getAdvancedPreviewUrl('product', $relativefile, 0, 'entity='.$this->entity);
|
|
|
if ($urladvanced) $return.='<a href="'.$urladvanced.'">';
|
|
@@ -4096,7 +4096,7 @@ class Product extends CommonObject
|
|
|
// Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine
|
|
|
$alt=$langs->transnoentitiesnoconv('File').': '.$relativefile;
|
|
|
$alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
|
|
|
-
|
|
|
+
|
|
|
if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight)
|
|
|
{
|
|
|
$return.= '<!-- Show thumb -->';
|
|
@@ -4195,7 +4195,7 @@ class Product extends CommonObject
|
|
|
{
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
|
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
|
|
|
-
|
|
|
+
|
|
|
$nbphoto=0;
|
|
|
$tabobj=array();
|
|
|
|
|
@@ -4249,7 +4249,7 @@ class Product extends CommonObject
|
|
|
{
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
|
|
|
-
|
|
|
+
|
|
|
$dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine
|
|
|
$dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette
|
|
|
$filename = preg_replace('/'.preg_quote($dir,'/').'/i','',$file); // Nom du fichier
|
|
@@ -4295,14 +4295,21 @@ class Product extends CommonObject
|
|
|
*/
|
|
|
function load_state_board()
|
|
|
{
|
|
|
- global $conf, $user;
|
|
|
+ global $conf, $user, $hookmanager;
|
|
|
|
|
|
$this->nb=array();
|
|
|
|
|
|
$sql = "SELECT count(p.rowid) as nb, fk_product_type";
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
|
|
|
$sql.= ' WHERE p.entity IN ('.getEntity($this->element, 1).')';
|
|
|
- $sql.= ' GROUP BY fk_product_type';
|
|
|
+ // Add where from hooks
|
|
|
+ if (is_object($hookmanager))
|
|
|
+ {
|
|
|
+ $parameters=array();
|
|
|
+ $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
|
|
|
+ $sql.=$hookmanager->resPrint;
|
|
|
+ }
|
|
|
+ $sql.= ' GROUP BY fk_product_type';
|
|
|
|
|
|
$resql=$this->db->query($sql);
|
|
|
if ($resql)
|
|
@@ -4401,7 +4408,7 @@ class Product extends CommonObject
|
|
|
$this->note='This is a comment (private)';
|
|
|
$this->date_creation = $now;
|
|
|
$this->date_modification = $now;
|
|
|
-
|
|
|
+
|
|
|
$this->weight = 4;
|
|
|
$this->weight_unit = 1;
|
|
|
|
|
@@ -4411,12 +4418,12 @@ class Product extends CommonObject
|
|
|
$this->width_unit = 0;
|
|
|
$this->height = null;
|
|
|
$this->height_unit = null;
|
|
|
-
|
|
|
+
|
|
|
$this->surface = 30;
|
|
|
$this->surface_unit = 0;
|
|
|
$this->volume = 300;
|
|
|
$this->volume_unit = 0;
|
|
|
-
|
|
|
+
|
|
|
$this->barcode=-1; // Create barcode automatically
|
|
|
}
|
|
|
|
|
@@ -4647,7 +4654,7 @@ class Product extends CommonObject
|
|
|
return $user->rights->service;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Load information for tab info
|
|
|
*
|
|
@@ -4695,5 +4702,5 @@ class Product extends CommonObject
|
|
|
dol_print_error($this->db);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|