Fix: compatibility with multicompany
Conflicts: htdocs/product/class/product.class.php
This commit is contained in:
parent
1d5db424a1
commit
1f98a23587
@ -139,6 +139,8 @@ class Product extends CommonObject
|
|||||||
//! Contains detail of stock of product into each warehouse
|
//! Contains detail of stock of product into each warehouse
|
||||||
var $stock_warehouse=array();
|
var $stock_warehouse=array();
|
||||||
|
|
||||||
|
var $oldcopy;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -404,6 +406,8 @@ class Product extends CommonObject
|
|||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
// Verification parametres
|
// Verification parametres
|
||||||
if (! $this->libelle) $this->libelle = 'MISSING LABEL';
|
if (! $this->libelle) $this->libelle = 'MISSING LABEL';
|
||||||
|
|
||||||
@ -505,7 +509,35 @@ class Product extends CommonObject
|
|||||||
// Fin appel triggers
|
// Fin appel triggers
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref))
|
||||||
|
{
|
||||||
|
// We remove directory
|
||||||
|
if ($conf->product->dir_output)
|
||||||
|
{
|
||||||
|
$olddir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->oldcopy->ref);
|
||||||
|
$newdir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->ref);
|
||||||
|
if (file_exists($olddir))
|
||||||
|
{
|
||||||
|
$res=@dol_move($olddir, $newdir);
|
||||||
|
if (! $res)
|
||||||
|
{
|
||||||
|
$this->error='ErrorFailToMoveDir';
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
return -$error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -603,6 +635,25 @@ class Product extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
// We remove directory
|
||||||
|
$ref = dol_sanitizeFileName($this->ref);
|
||||||
|
if ($conf->product->dir_output)
|
||||||
|
{
|
||||||
|
$dir = $conf->product->dir_output . "/" . $ref;
|
||||||
|
if (file_exists($dir))
|
||||||
|
{
|
||||||
|
$res=@dol_delete_dir_recursive($dir);
|
||||||
|
if (! $res)
|
||||||
|
{
|
||||||
|
$this->error='ErrorFailToDeleteDir';
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($error)
|
if ($error)
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
@ -2368,9 +2419,12 @@ class Product extends CommonObject
|
|||||||
{
|
{
|
||||||
$this->stock_reel = 0;
|
$this->stock_reel = 0;
|
||||||
|
|
||||||
$sql = "SELECT reel, fk_entrepot, pmp";
|
$sql = "SELECT ps.reel, ps.fk_entrepot, ps.pmp";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
|
||||||
$sql.= " WHERE fk_product = '".$this->id."'";
|
$sql.= ", ".MAIN_DB_PREFIX."entrepot as w";
|
||||||
|
$sql.= " WHERE w.entity = (".getEntity('warehouse', 1).")";
|
||||||
|
$sql.= " AND w.rowid = ps.fk_entrepot";
|
||||||
|
$sql.= " AND ps.fk_product = ".$this->id;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::load_stock sql=".$sql);
|
dol_syslog(get_class($this)."::load_stock sql=".$sql);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
|
|||||||
@ -76,6 +76,8 @@ class Entrepot extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function create($user)
|
function create($user)
|
||||||
{
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
// Si libelle non defini, erreur
|
// Si libelle non defini, erreur
|
||||||
if ($this->libelle == '')
|
if ($this->libelle == '')
|
||||||
{
|
{
|
||||||
@ -87,8 +89,8 @@ class Entrepot extends CommonObject
|
|||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."entrepot (datec, fk_user_author, label)";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."entrepot (entity, datec, fk_user_author, label)";
|
||||||
$sql .= " VALUES ('".$this->db->idate($now)."',".$user->id.",'".$this->db->escape($this->libelle)."')";
|
$sql .= " VALUES (".$conf->entity.",'".$this->db->idate($now)."',".$user->id.",'".$this->db->escape($this->libelle)."')";
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::create sql=".$sql);
|
dol_syslog(get_class($this)."::create sql=".$sql);
|
||||||
$result=$this->db->query($sql);
|
$result=$this->db->query($sql);
|
||||||
@ -99,7 +101,7 @@ class Entrepot extends CommonObject
|
|||||||
{
|
{
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
|
|
||||||
if ( $this->update($id, $user) > 0)
|
if ($this->update($id, $user) > 0)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $id;
|
return $id;
|
||||||
@ -184,7 +186,6 @@ class Entrepot extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function delete($user)
|
function delete($user)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."stock_mouvement";
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."stock_mouvement";
|
||||||
@ -338,7 +339,8 @@ class Entrepot extends CommonObject
|
|||||||
|
|
||||||
$sql = "SELECT rowid, label";
|
$sql = "SELECT rowid, label";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot";
|
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot";
|
||||||
$sql.= " WHERE statut = ".$status;
|
$sql.= " WHERE entity IN (".getEntity('warehouse', 1).")";
|
||||||
|
$sql.= " AND statut = ".$status;
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
@ -363,13 +365,13 @@ class Entrepot extends CommonObject
|
|||||||
*/
|
*/
|
||||||
function nb_products()
|
function nb_products()
|
||||||
{
|
{
|
||||||
global $conf,$user;
|
|
||||||
|
|
||||||
$ret=array();
|
$ret=array();
|
||||||
|
|
||||||
$sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * ps.pmp) as value";
|
$sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * ps.pmp) as value";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product as p";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
|
||||||
$sql .= " WHERE ps.fk_entrepot = ".$this->id." AND ps.fk_product=p.rowid";
|
$sql.= ", ".MAIN_DB_PREFIX."product as p";
|
||||||
|
$sql.= " WHERE ps.fk_entrepot = ".$this->id;
|
||||||
|
$sql.= " AND ps.fk_product = p.rowid";
|
||||||
|
|
||||||
//print $sql;
|
//print $sql;
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
|
|||||||
@ -43,7 +43,7 @@ if (isset($_GET["id"]) || isset($_GET["ref"]))
|
|||||||
}
|
}
|
||||||
$fieldid = isset($_GET["ref"])?'ref':'rowid';
|
$fieldid = isset($_GET["ref"])?'ref':'rowid';
|
||||||
if ($user->societe_id) $socid=$user->societe_id;
|
if ($user->societe_id) $socid=$user->societe_id;
|
||||||
$result=restrictedArea($user,'produit&stock',$id,'product','','',$fieldid);
|
$result=restrictedArea($user,'produit&stock',$id,'product&product','','',$fieldid);
|
||||||
|
|
||||||
$mesg = '';
|
$mesg = '';
|
||||||
|
|
||||||
@ -214,6 +214,7 @@ if ($_GET["id"] || $_GET["ref"])
|
|||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
// Real stock
|
// Real stock
|
||||||
|
$product->load_stock();
|
||||||
print '<tr><td>'.$langs->trans("PhysicalStock").'</td>';
|
print '<tr><td>'.$langs->trans("PhysicalStock").'</td>';
|
||||||
print '<td>'.$product->stock_reel;
|
print '<td>'.$product->stock_reel;
|
||||||
if ($product->seuil_stock_alerte && ($product->stock_reel < $product->seuil_stock_alerte)) print ' '.img_warning($langs->trans("StockTooLow"));
|
if ($product->seuil_stock_alerte && ($product->stock_reel < $product->seuil_stock_alerte)) print ' '.img_warning($langs->trans("StockTooLow"));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user