Fix several problem with hook printFieldListWhere

This commit is contained in:
Laurent Destailleur 2017-06-09 11:02:34 +02:00
parent bec6ad9fb3
commit 02781b41ca
4 changed files with 91 additions and 63 deletions

View File

@ -53,7 +53,7 @@ class box_produits extends ModeleBoxes
*/ */
function loadBox($max=5) function loadBox($max=5)
{ {
global $user, $langs, $db, $conf; global $user, $langs, $db, $conf, $hookmanager;
$this->max=$max; $this->max=$max;
@ -69,6 +69,13 @@ class box_produits extends ModeleBoxes
$sql.= ' WHERE p.entity IN ('.getEntity($productstatic->element, 1).')'; $sql.= ' WHERE p.entity IN ('.getEntity($productstatic->element, 1).')';
if (empty($user->rights->produit->lire)) $sql.=' AND p.fk_product_type != 0'; if (empty($user->rights->produit->lire)) $sql.=' AND p.fk_product_type != 0';
if (empty($user->rights->service->lire)) $sql.=' AND p.fk_product_type != 1'; if (empty($user->rights->service->lire)) $sql.=' AND p.fk_product_type != 1';
// 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.= $db->order('p.datec', 'DESC'); $sql.= $db->order('p.datec', 'DESC');
$sql.= $db->plimit($max, 0); $sql.= $db->plimit($max, 0);

View File

@ -55,7 +55,7 @@ class box_produits_alerte_stock extends ModeleBoxes
*/ */
function loadBox($max=5) function loadBox($max=5)
{ {
global $user, $langs, $db, $conf; global $user, $langs, $db, $conf, $hookmanager;
$this->max=$max; $this->max=$max;
@ -74,7 +74,14 @@ class box_produits_alerte_stock extends ModeleBoxes
$sql.= " AND p.tosell = 1 AND p.seuil_stock_alerte > 0"; $sql.= " AND p.tosell = 1 AND p.seuil_stock_alerte > 0";
if (empty($user->rights->produit->lire)) $sql.=' AND p.fk_product_type != 0'; if (empty($user->rights->produit->lire)) $sql.=' AND p.fk_product_type != 0';
if (empty($user->rights->service->lire)) $sql.=' AND p.fk_product_type != 1'; if (empty($user->rights->service->lire)) $sql.=' AND p.fk_product_type != 1';
$sql.= " GROUP BY p.rowid, p.ref, p.label, p.price, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.seuil_stock_alerte, p.entity"; // 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 p.rowid, p.ref, p.label, p.price, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.seuil_stock_alerte, p.entity";
$sql.= " HAVING SUM(".$db->ifsql("s.reel IS NULL","0","s.reel").") < p.seuil_stock_alerte"; $sql.= " HAVING SUM(".$db->ifsql("s.reel IS NULL","0","s.reel").") < p.seuil_stock_alerte";
$sql.= $db->order('p.seuil_stock_alerte', 'DESC'); $sql.= $db->order('p.seuil_stock_alerte', 'DESC');
$sql.= $db->plimit($max, 0); $sql.= $db->plimit($max, 0);

View File

@ -108,7 +108,7 @@ class Product extends CommonObject
var $localtax2_tx; var $localtax2_tx;
var $localtax1_type; var $localtax1_type;
var $localtax2_type; var $localtax2_type;
//! Stock real //! Stock real
var $stock_reel; var $stock_reel;
//! Stock virtual //! Stock virtual
@ -196,7 +196,7 @@ class Product extends CommonObject
public $fourn_pu; public $fourn_pu;
public $fourn_price_base_type; public $fourn_price_base_type;
/** /**
* @deprecated * @deprecated
* @see ref_supplier * @see ref_supplier
@ -306,7 +306,7 @@ class Product extends CommonObject
if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; if (empty($this->localtax2_tx)) $this->localtax2_tx = 0;
if (empty($this->localtax1_type)) $this->localtax1_type = '0'; if (empty($this->localtax1_type)) $this->localtax1_type = '0';
if (empty($this->localtax2_type)) $this->localtax2_type = '0'; if (empty($this->localtax2_type)) $this->localtax2_type = '0';
if (empty($this->price)) $this->price = 0; if (empty($this->price)) $this->price = 0;
if (empty($this->price_min)) $this->price_min = 0; if (empty($this->price_min)) $this->price_min = 0;
@ -675,7 +675,7 @@ class Product extends CommonObject
$org->fetch($this->id); $org->fetch($this->id);
$this->oldcopy=$org; $this->oldcopy=$org;
} }
// Test if batch management is activated on existing product // Test if batch management is activated on existing product
// If yes, we create missing entries into product_batch // If yes, we create missing entries into product_batch
if ($this->hasbatch() && !$this->oldcopy->hasbatch()) if ($this->hasbatch() && !$this->oldcopy->hasbatch())
@ -691,7 +691,7 @@ class Product extends CommonObject
$qty_batch = 0; $qty_batch = 0;
foreach ($ObjW->detail_batch as $detail) // Each lines of detail in product_batch of the current $ObjW = product_stock 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 // 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; $sqlclean="DELETE FROM ".MAIN_DB_PREFIX."product_batch WHERE batch in('Undefined', '".$valueforundefinedlot."') AND fk_product_stock = ".$ObjW->id;
@ -703,7 +703,7 @@ class Product extends CommonObject
} }
continue; continue;
} }
$qty_batch += $detail->qty; $qty_batch += $detail->qty;
} }
// Quantities in batch details are not same as stock quantity, // Quantities in batch details are not same as stock quantity,
@ -711,7 +711,7 @@ class Product extends CommonObject
if ($ObjW->real <> $qty_batch) if ($ObjW->real <> $qty_batch)
{ {
$ObjBatch = new Productbatch($this->db); $ObjBatch = new Productbatch($this->db);
$ObjBatch->batch = $valueforundefinedlot; $ObjBatch->batch = $valueforundefinedlot;
$ObjBatch->qty = ($ObjW->real - $qty_batch); $ObjBatch->qty = ($ObjW->real - $qty_batch);
$ObjBatch->fk_product_stock = $ObjW->id; $ObjBatch->fk_product_stock = $ObjW->id;
@ -738,7 +738,7 @@ class Product extends CommonObject
$sql.= ", localtax2_tx = " . $this->localtax2_tx; $sql.= ", localtax2_tx = " . $this->localtax2_tx;
$sql.= ", localtax1_type = " . ($this->localtax1_type!=''?"'".$this->localtax1_type."'":"'0'"); $sql.= ", localtax1_type = " . ($this->localtax1_type!=''?"'".$this->localtax1_type."'":"'0'");
$sql.= ", localtax2_type = " . ($this->localtax2_type!=''?"'".$this->localtax2_type."'":"'0'"); $sql.= ", localtax2_type = " . ($this->localtax2_type!=''?"'".$this->localtax2_type."'":"'0'");
$sql.= ", barcode = ". (empty($this->barcode)?"null":"'".$this->db->escape($this->barcode)."'"); $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)); $sql.= ", fk_barcode_type = ". (empty($this->barcode_type)?"null":$this->db->escape($this->barcode_type));
@ -924,8 +924,8 @@ class Product extends CommonObject
if ($result < 0) { $error++; } if ($result < 0) { $error++; }
// End call triggers // End call triggers
} }
// Delete from product_batch on product delete // Delete from product_batch on product delete
if (! $error) if (! $error)
{ {
$sql = "DELETE FROM ".MAIN_DB_PREFIX.'product_batch'; $sql = "DELETE FROM ".MAIN_DB_PREFIX.'product_batch';
@ -940,7 +940,7 @@ class Product extends CommonObject
$this->errors[] = $this->db->lasterror(); $this->errors[] = $this->db->lasterror();
} }
} }
// Delete all child tables // Delete all child tables
if (! $error) if (! $error)
{ {
@ -1038,7 +1038,7 @@ class Product extends CommonObject
function setMultiLangs($user) function setMultiLangs($user)
{ {
global $conf, $langs; global $conf, $langs;
$langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2); $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2);
$current_lang = $langs->getDefaultLang(); $current_lang = $langs->getDefaultLang();
@ -1357,7 +1357,7 @@ class Product extends CommonObject
$sql.= " WHERE pfp.rowid = ".$prodfournprice; $sql.= " WHERE pfp.rowid = ".$prodfournprice;
if ($qty > 0) $sql.= " AND pfp.quantity <= ".$qty; if ($qty > 0) $sql.= " AND pfp.quantity <= ".$qty;
$sql.= " ORDER BY pfp.quantity DESC"; $sql.= " ORDER BY pfp.quantity DESC";
dol_syslog(get_class($this)."::get_buyprice first search by prodfournprice/qty", LOG_DEBUG); dol_syslog(get_class($this)."::get_buyprice first search by prodfournprice/qty", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
@ -1487,7 +1487,7 @@ class Product extends CommonObject
// If multiprices are enabled, then we check if the current product is subject to price autogeneration // 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 // 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); return $this->generateMultiprices($user, $newprice, $newpricebase, $newvat, $newnpr, $newpsq);
} }
@ -1555,7 +1555,7 @@ class Product extends CommonObject
} }
if (empty($localtax1)) $localtax1=0; // If = '' then = 0 if (empty($localtax1)) $localtax1=0; // If = '' then = 0
if (empty($localtax2)) $localtax2=0; // If = '' then = 0 if (empty($localtax2)) $localtax2=0; // If = '' then = 0
$this->db->begin(); $this->db->begin();
// Ne pas mettre de quote sur les numeriques decimaux. // Ne pas mettre de quote sur les numeriques decimaux.
@ -1601,7 +1601,7 @@ class Product extends CommonObject
$this->localtax2_tx = $localtax2; $this->localtax2_tx = $localtax2;
$this->localtax1_type = $localtaxtype1; $this->localtax1_type = $localtaxtype1;
$this->localtax2_type = $localtaxtype2; $this->localtax2_type = $localtaxtype2;
// Price by quantity // Price by quantity
$this->price_by_qty = $newpsq; $this->price_by_qty = $newpsq;
@ -1702,7 +1702,7 @@ class Product extends CommonObject
$this->url = $obj->url; $this->url = $obj->url;
$this->note_private = $obj->note_private; $this->note_private = $obj->note_private;
$this->note = $obj->note_private; // deprecated $this->note = $obj->note_private; // deprecated
$this->type = $obj->fk_product_type; $this->type = $obj->fk_product_type;
$this->status = $obj->tosell; $this->status = $obj->tosell;
$this->status_buy = $obj->tobuy; $this->status_buy = $obj->tobuy;
@ -1726,7 +1726,7 @@ class Product extends CommonObject
$this->localtax2_tx = $obj->localtax2_tx; $this->localtax2_tx = $obj->localtax2_tx;
$this->localtax1_type = $obj->localtax1_type; $this->localtax1_type = $obj->localtax1_type;
$this->localtax2_type = $obj->localtax2_type; $this->localtax2_type = $obj->localtax2_type;
$this->finished = $obj->finished; $this->finished = $obj->finished;
$this->duration = $obj->duration; $this->duration = $obj->duration;
$this->duration_value = substr($obj->duration,0,dol_strlen($obj->duration)-1); $this->duration_value = substr($obj->duration,0,dol_strlen($obj->duration)-1);
@ -1773,7 +1773,7 @@ class Product extends CommonObject
// multilangs // multilangs
if (! empty($conf->global->MAIN_MULTILANGS)) $this->getMultiLangs(); if (! empty($conf->global->MAIN_MULTILANGS)) $this->getMultiLangs();
// Load multiprices array // Load multiprices array
if (! empty($conf->global->PRODUIT_MULTIPRICES)) if (! empty($conf->global->PRODUIT_MULTIPRICES))
{ {
@ -2006,29 +2006,29 @@ class Product extends CommonObject
$this->stats_commande['rows']=$obj->nb_rows; $this->stats_commande['rows']=$obj->nb_rows;
$this->stats_commande['qty']=$obj->qty?$obj->qty:0; $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)) if (! empty($conf->global->ORDER_ADD_ORDERS_WITH_PARENT_PROD_IF_INCDEC))
{ {
$TFather = $this->getFather(); $TFather = $this->getFather();
if (is_array($TFather) && !empty($TFather)) { if (is_array($TFather) && !empty($TFather)) {
foreach($TFather as &$fatherData) { foreach($TFather as &$fatherData) {
$pFather = new Product($this->db); $pFather = new Product($this->db);
$pFather->id = $fatherData['id']; $pFather->id = $fatherData['id'];
$qtyCoef = $fatherData['qty']; $qtyCoef = $fatherData['qty'];
if ($fatherData['incdec']) { if ($fatherData['incdec']) {
$pFather->load_stats_commande($socid, $filtrestatut); $pFather->load_stats_commande($socid, $filtrestatut);
$this->stats_commande['customers']+=$pFather->stats_commande['customers']; $this->stats_commande['customers']+=$pFather->stats_commande['customers'];
$this->stats_commande['nb']+=$pFather->stats_commande['nb']; $this->stats_commande['nb']+=$pFather->stats_commande['nb'];
$this->stats_commande['rows']+=$pFather->stats_commande['rows']; $this->stats_commande['rows']+=$pFather->stats_commande['rows'];
$this->stats_commande['qty']+=$pFather->stats_commande['qty'] * $qtyCoef; $this->stats_commande['qty']+=$pFather->stats_commande['qty'] * $qtyCoef;
} }
} }
} }
} }
return 1; return 1;
} }
else else
@ -2432,7 +2432,7 @@ class Product extends CommonObject
$sql = "SELECT sum(d.qty), date_format(p.datep, '%Y%m')"; $sql = "SELECT sum(d.qty), date_format(p.datep, '%Y%m')";
if ($mode == 'bynumber') $sql.= ", count(DISTINCT p.rowid)"; 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"; $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"; if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE p.rowid = d.fk_propal"; $sql.= " WHERE p.rowid = d.fk_propal";
if ($this->id > 0) $sql.= " AND d.fk_product =".$this->id; if ($this->id > 0) $sql.= " AND d.fk_product =".$this->id;
@ -2464,7 +2464,7 @@ class Product extends CommonObject
$sql = "SELECT sum(d.qty), date_format(p.date_valid, '%Y%m')"; $sql = "SELECT sum(d.qty), date_format(p.date_valid, '%Y%m')";
if ($mode == 'bynumber') $sql.= ", count(DISTINCT p.rowid)"; 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"; $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"; if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE p.rowid = d.fk_supplier_proposal"; $sql.= " WHERE p.rowid = d.fk_supplier_proposal";
if ($this->id > 0) $sql.= " AND d.fk_product =".$this->id; if ($this->id > 0) $sql.= " AND d.fk_product =".$this->id;
@ -2479,7 +2479,7 @@ class Product extends CommonObject
return $this->_get_stats($sql,$mode); return $this->_get_stats($sql,$mode);
} }
/** /**
* Return nb of units or orders in which product is included * Return nb of units or orders in which product is included
* *
@ -2526,7 +2526,7 @@ class Product extends CommonObject
$sql = "SELECT sum(d.qty), date_format(c.date_commande, '%Y%m')"; $sql = "SELECT sum(d.qty), date_format(c.date_commande, '%Y%m')";
if ($mode == 'bynumber') $sql.= ", count(DISTINCT c.rowid)"; 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"; $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"; if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE c.rowid = d.fk_commande"; $sql.= " WHERE c.rowid = d.fk_commande";
if ($this->id > 0) $sql.= " AND d.fk_product =".$this->id; if ($this->id > 0) $sql.= " AND d.fk_product =".$this->id;
@ -2715,7 +2715,7 @@ class Product extends CommonObject
$now=dol_now(); $now=dol_now();
dol_syslog(get_class($this)."::add_fournisseur id_fourn = ".$id_fourn." ref_fourn=".$ref_fourn." quantity=".$quantity, LOG_DEBUG); dol_syslog(get_class($this)."::add_fournisseur id_fourn = ".$id_fourn." ref_fourn=".$ref_fourn." quantity=".$quantity, LOG_DEBUG);
if ($ref_fourn) if ($ref_fourn)
{ {
$sql = "SELECT rowid, fk_product"; $sql = "SELECT rowid, fk_product";
@ -3104,7 +3104,7 @@ class Product extends CommonObject
function getChildsArbo($id, $firstlevelonly=0, $level=1) function getChildsArbo($id, $firstlevelonly=0, $level=1)
{ {
global $alreadyfound; 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 = "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.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= ", ".MAIN_DB_PREFIX."product_association as pa"; $sql.= ", ".MAIN_DB_PREFIX."product_association as pa";
@ -3113,18 +3113,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 $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); 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 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 // Protection against infinite loop
if ($level > 30) return array(); if ($level > 30) return array();
$res = $this->db->query($sql); $res = $this->db->query($sql);
if ($res) if ($res)
{ {
$prods = array(); $prods = array();
while ($rec = $this->db->fetch_array($res)) 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); 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; continue;
@ -3194,7 +3194,7 @@ class Product extends CommonObject
$result=''; $result='';
$newref=$this->ref; $newref=$this->ref;
if ($maxlength) $newref=dol_trunc($newref,$maxlength,'middle'); 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_PRODUCT) $label = '<u>' . $langs->trans("ShowProduct") . '</u>';
if ($this->type == Product::TYPE_SERVICE) $label = '<u>' . $langs->trans("ShowService") . '</u>'; if ($this->type == Product::TYPE_SERVICE) $label = '<u>' . $langs->trans("ShowService") . '</u>';
if (! empty($this->ref)) if (! empty($this->ref))
@ -3217,13 +3217,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); $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=''; $linkclose='';
if (empty($notooltip)) if (empty($notooltip))
{ {
@ -3235,7 +3235,7 @@ class Product extends CommonObject
$linkclose.= ' title="'.dol_escape_htmltag($label, 1, 1).'"'; $linkclose.= ' title="'.dol_escape_htmltag($label, 1, 1).'"';
$linkclose.=' class="classfortooltip"'; $linkclose.=' class="classfortooltip"';
if (! is_object($hookmanager)) if (! is_object($hookmanager))
{ {
include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
@ -3260,7 +3260,7 @@ class Product extends CommonObject
$linkstart = '<a href="'.$url.'"'; $linkstart = '<a href="'.$url.'"';
$linkstart.=$linkclose.'>'; $linkstart.=$linkclose.'>';
$linkend='</a>'; $linkend='</a>';
if ($withpicto) { 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_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.' '); if ($this->type == Product::TYPE_SERVICE) $result.=($linkstart.img_object(($notooltip?'':$label), 'service', ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend.' ');
@ -3303,7 +3303,7 @@ class Product extends CommonObject
function LibStatut($status,$mode=0,$type=0) function LibStatut($status,$mode=0,$type=0)
{ {
global $conf, $langs; global $conf, $langs;
$langs->load('products'); $langs->load('products');
if (! empty($conf->productbatch->enabled)) $langs->load("productbatch"); if (! empty($conf->productbatch->enabled)) $langs->load("productbatch");
@ -3473,14 +3473,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) * 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 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.
* If ENTREPOT_EXTRA_STATUS set, filtering on warehouse status possible. * If ENTREPOT_EXTRA_STATUS set, filtering on warehouse status possible.
* *
* @param string $option '' = Load all stock info, also from closed and internal warehouses, * @param string $option '' = Load all stock info, also from closed and internal warehouses,
* 'nobatch' = Do not load batch information, * 'nobatch' = Do not load batch information,
* 'novirtual' = Do not load virtual stock, * 'novirtual' = Do not load virtual stock,
* 'warehouseopen' = Load stock from open warehouses, * 'warehouseopen' = Load stock from open warehouses,
* 'warehouseclosed' = Load stock from closed warehouses, * 'warehouseclosed' = Load stock from closed warehouses,
* 'warehouseinternal' = Load stock from warehouses for internal correct/transfer only * 'warehouseinternal' = Load stock from warehouses for internal correct/transfer only
* @return int < 0 if KO, > 0 if OK * @return int < 0 if KO, > 0 if OK
* @see load_virtual_stock, getBatchInfo * @see load_virtual_stock, getBatchInfo
@ -3488,26 +3488,26 @@ class Product extends CommonObject
function load_stock($option='') function load_stock($option='')
{ {
global $conf; global $conf;
$this->stock_reel = 0; $this->stock_reel = 0;
$this->stock_warehouse = array(); $this->stock_warehouse = array();
$this->stock_theorique = 0; $this->stock_theorique = 0;
$warehouseStatus = array(); $warehouseStatus = array();
if (preg_match('/warehouseclosed/', $option)) if (preg_match('/warehouseclosed/', $option))
{ {
$warehouseStatus[] = Entrepot::STATUS_CLOSED; $warehouseStatus[] = Entrepot::STATUS_CLOSED;
} }
if (preg_match('/warehouseopen/', $option)) if (preg_match('/warehouseopen/', $option))
{ {
$warehouseStatus[] = Entrepot::STATUS_OPEN_ALL; $warehouseStatus[] = Entrepot::STATUS_OPEN_ALL;
} }
if (preg_match('/warehouseinternal/', $option)) if (preg_match('/warehouseinternal/', $option))
{ {
$warehouseStatus[] = Entrepot::STATUS_OPEN_INTERNAL; $warehouseStatus[] = Entrepot::STATUS_OPEN_INTERNAL;
} }
$sql = "SELECT ps.rowid, ps.reel, ps.fk_entrepot"; $sql = "SELECT ps.rowid, ps.reel, ps.fk_entrepot";
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; $sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
$sql.= ", ".MAIN_DB_PREFIX."entrepot as w"; $sql.= ", ".MAIN_DB_PREFIX."entrepot as w";
@ -3537,7 +3537,7 @@ class Product extends CommonObject
} }
$this->db->free($result); $this->db->free($result);
if (! preg_match('/novirtual/', $option)) if (! preg_match('/novirtual/', $option))
{ {
$this->load_virtual_stock(); // This also load stats_commande_fournisseur, ... $this->load_virtual_stock(); // This also load stats_commande_fournisseur, ...
} }
@ -3553,7 +3553,7 @@ class Product extends CommonObject
/** /**
* Load value ->stock_theorique of a product. Property this->id must be defined. * 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 * @return int < 0 if KO, > 0 if OK
* @see load_stock, getBatchInfo * @see load_stock, getBatchInfo
@ -3790,7 +3790,7 @@ class Product extends CommonObject
// Find name of thumb file // Find name of thumb file
$photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small')); $photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small'));
if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette='';
// Get filesize of original file // Get filesize of original file
$imgarray=dol_getImageSize($dir.$photo); $imgarray=dol_getImageSize($dir.$photo);
@ -3804,9 +3804,9 @@ class Product extends CommonObject
else if ($nbbyrow < 0) $return .= '<div class="inline-block">'; else if ($nbbyrow < 0) $return .= '<div class="inline-block">';
$return.= "\n"; $return.= "\n";
$relativefile=preg_replace('/^\//', '', $pdir.$photo); $relativefile=preg_replace('/^\//', '', $pdir.$photo);
if (empty($nolink)) if (empty($nolink))
{ {
$urladvanced=getAdvancedPreviewUrl('product', $relativefile); $urladvanced=getAdvancedPreviewUrl('product', $relativefile);
if ($urladvanced) $return.='<a href="'.$urladvanced.'">'; if ($urladvanced) $return.='<a href="'.$urladvanced.'">';
@ -3817,7 +3817,7 @@ class Product extends CommonObject
// Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine // 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('File').': '.$relativefile;
$alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height']; $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight)
{ {
$return.= '<!-- Show thumb -->'; $return.= '<!-- Show thumb -->';
@ -4017,7 +4017,7 @@ class Product extends CommonObject
*/ */
function load_state_board() function load_state_board()
{ {
global $conf, $user; global $conf, $user, $hookmanager;
$this->nb=array(); $this->nb=array();
@ -4025,6 +4025,13 @@ class Product extends CommonObject
$sql.= " FROM ".MAIN_DB_PREFIX."product as p"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= ' WHERE p.entity IN ('.getEntity($this->element, 1).')'; $sql.= ' WHERE p.entity IN ('.getEntity($this->element, 1).')';
$sql.= " AND p.fk_product_type <> 1"; $sql.= " AND p.fk_product_type <> 1";
// 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;
}
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -4350,7 +4357,7 @@ class Product extends CommonObject
return $user->rights->service; return $user->rights->service;
} }
} }
/** /**
* Load information for tab info * Load information for tab info
* *

View File

@ -56,7 +56,7 @@ class Service extends CommonObject
*/ */
function load_state_board() function load_state_board()
{ {
global $conf, $user; global $conf, $user, $hookmanager;
$this->nb=array(); $this->nb=array();
@ -64,6 +64,13 @@ class Service extends CommonObject
$sql.= " FROM ".MAIN_DB_PREFIX."product as p"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')'; $sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')';
$sql.= " AND p.fk_product_type = 1"; $sql.= " AND p.fk_product_type = 1";
// 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;
}
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)