New: Store and show estimated value of stock
This commit is contained in:
parent
8c68711e02
commit
0e8e8e2b98
@ -607,6 +607,8 @@ class CommandeFournisseur extends Commande
|
|||||||
*/
|
*/
|
||||||
function refuse($user)
|
function refuse($user)
|
||||||
{
|
{
|
||||||
|
global $conf, $langs;
|
||||||
|
|
||||||
dol_syslog("CommandeFournisseur::Refuse");
|
dol_syslog("CommandeFournisseur::Refuse");
|
||||||
$result = 0;
|
$result = 0;
|
||||||
if ($user->rights->fournisseur->commande->approuver)
|
if ($user->rights->fournisseur->commande->approuver)
|
||||||
@ -615,21 +617,21 @@ class CommandeFournisseur extends Commande
|
|||||||
$sql .= " WHERE rowid = ".$this->id;
|
$sql .= " WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
{
|
{
|
||||||
$result = 0;
|
$result = 0;
|
||||||
$this->log($user, 9, time());
|
$this->log($user, 9, time());
|
||||||
|
|
||||||
$subject = $langs->trans("EMailTextOrderRefused",$this->ref);
|
$subject = $langs->trans("EMailTextOrderRefused",$this->ref);
|
||||||
$message = $langs->trans("Hello").",\n\n";
|
$message = $langs->trans("Hello").",\n\n";
|
||||||
$message .= $langs->trans("EMailTextOrderRefusedBy",$this->ref,$user->fullname);
|
$message .= $langs->trans("EMailTextOrderRefusedBy",$this->ref,$user->fullname);
|
||||||
|
|
||||||
$this->_NotifyCreator($user, $subject, $message);
|
$this->_NotifyCreator($user, $subject, $message);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_syslog("CommandeFournisseur::Refuse Error -1");
|
dol_syslog("CommandeFournisseur::Refuse Error -1");
|
||||||
$result = -1;
|
$result = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -62,4 +62,7 @@ StockUpShort=Stock up
|
|||||||
IdWarehouse=Id warehouse
|
IdWarehouse=Id warehouse
|
||||||
DescWareHouse=Description warehouse
|
DescWareHouse=Description warehouse
|
||||||
LieuWareHouse=Localisation warehouse
|
LieuWareHouse=Localisation warehouse
|
||||||
WarehousesAndProducts=Warehouses and products
|
WarehousesAndProducts=Warehouses and products
|
||||||
|
AverageUnitPricePMP=Average price
|
||||||
|
EstimatedStockValueForProduct=Estimated value for product's stock
|
||||||
|
EstimatedStockValue=Estimated value in stock
|
||||||
@ -62,4 +62,7 @@ StockUpShort=Stock max
|
|||||||
IdWarehouse=Id entrepôt
|
IdWarehouse=Id entrepôt
|
||||||
DescWareHouse=Description entrepôt
|
DescWareHouse=Description entrepôt
|
||||||
LieuWareHouse=Lieu entrepôt
|
LieuWareHouse=Lieu entrepôt
|
||||||
WarehousesAndProducts=Entrepôts et produits
|
WarehousesAndProducts=Entrepôts et produits
|
||||||
|
AverageUnitPricePMP=Prix moyen pondéré (PMP)
|
||||||
|
EstimatedStockValueForProduct=Valeur estimée du produit en stock
|
||||||
|
EstimatedStockValue=Valeur estimée du stock
|
||||||
@ -38,6 +38,8 @@ class Product extends CommonObject
|
|||||||
{
|
{
|
||||||
var $db;
|
var $db;
|
||||||
var $error;
|
var $error;
|
||||||
|
//! Numero de l'erreur
|
||||||
|
var $errno = 0;
|
||||||
var $element='product';
|
var $element='product';
|
||||||
var $table_element='product';
|
var $table_element='product';
|
||||||
|
|
||||||
@ -63,7 +65,12 @@ class Product extends CommonObject
|
|||||||
//! Type 0 for regular product, 1 for service, 2 for assembly kit, 3 for stock kit
|
//! Type 0 for regular product, 1 for service, 2 for assembly kit, 3 for stock kit
|
||||||
var $type;
|
var $type;
|
||||||
var $typestring;
|
var $typestring;
|
||||||
|
|
||||||
|
//! Stock
|
||||||
var $stock_reel;
|
var $stock_reel;
|
||||||
|
//! Stock value (PMP)
|
||||||
|
var $pmp;
|
||||||
|
|
||||||
var $seuil_stock_alerte;
|
var $seuil_stock_alerte;
|
||||||
//! Duree de validite du service
|
//! Duree de validite du service
|
||||||
var $duration_value;
|
var $duration_value;
|
||||||
@ -97,9 +104,6 @@ class Product extends CommonObject
|
|||||||
var $imgWidth;
|
var $imgWidth;
|
||||||
var $imgHeight;
|
var $imgHeight;
|
||||||
|
|
||||||
//! Numero de l'erreur
|
|
||||||
//! Numero d'erreur Plage 0256-0511
|
|
||||||
var $errno = 0;
|
|
||||||
//! Canevas a utiliser si le produit n'est pas un produit generique
|
//! Canevas a utiliser si le produit n'est pas un produit generique
|
||||||
var $canvas;
|
var $canvas;
|
||||||
|
|
||||||
@ -438,9 +442,9 @@ class Product extends CommonObject
|
|||||||
{
|
{
|
||||||
$num = $this->db->num_rows($result);
|
$num = $this->db->num_rows($result);
|
||||||
if ($num != 0)
|
if ($num != 0)
|
||||||
{
|
{
|
||||||
$sqr++;
|
$sqr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT rowid";
|
$sql = "SELECT rowid";
|
||||||
@ -452,9 +456,9 @@ class Product extends CommonObject
|
|||||||
{
|
{
|
||||||
$num = $this->db->num_rows($result);
|
$num = $this->db->num_rows($result);
|
||||||
if ($num != 0)
|
if ($num != 0)
|
||||||
{
|
{
|
||||||
$sqr++;
|
$sqr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -467,9 +471,9 @@ class Product extends CommonObject
|
|||||||
{
|
{
|
||||||
$num = $this->db->num_rows($result);
|
$num = $this->db->num_rows($result);
|
||||||
if ($num != 0)
|
if ($num != 0)
|
||||||
{
|
{
|
||||||
$sqr++;
|
$sqr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -482,9 +486,9 @@ class Product extends CommonObject
|
|||||||
{
|
{
|
||||||
$num = $this->db->num_rows($result);
|
$num = $this->db->num_rows($result);
|
||||||
if ($num != 0)
|
if ($num != 0)
|
||||||
{
|
{
|
||||||
$sqr++;
|
$sqr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sqr == 0)
|
if ($sqr == 0)
|
||||||
@ -875,10 +879,10 @@ class Product extends CommonObject
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Charge le produit/service en memoire
|
* \brief Load a product in memory from database
|
||||||
* \param id Id du produit/service a charger
|
* \param id Id of product/service to load
|
||||||
* \param ref Ref du produit/service a charger
|
* \param ref Ref of product/service to load
|
||||||
* \return int <0 si ko, >0 si ok
|
* \return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function fetch($id='',$ref='')
|
function fetch($id='',$ref='')
|
||||||
{
|
{
|
||||||
@ -898,7 +902,9 @@ class Product extends CommonObject
|
|||||||
$sql = "SELECT rowid, ref, label, description, note, price, price_ttc,";
|
$sql = "SELECT rowid, ref, label, description, note, price, price_ttc,";
|
||||||
$sql.= " price_min, price_min_ttc, price_base_type, tva_tx, envente,";
|
$sql.= " price_min, price_min_ttc, price_base_type, tva_tx, envente,";
|
||||||
$sql.= " fk_product_type, duration, seuil_stock_alerte,canvas,";
|
$sql.= " fk_product_type, duration, seuil_stock_alerte,canvas,";
|
||||||
$sql.= " stock_loc, weight, weight_units, volume, volume_units, barcode, fk_barcode_type, finished";
|
$sql.= " stock_loc, weight, weight_units, volume, volume_units, barcode, fk_barcode_type, finished,";
|
||||||
|
$sql.= " stock, pmp,";
|
||||||
|
$sql.= " import_key";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product";
|
||||||
if ($id) $sql.= " WHERE rowid = '".$id."'";
|
if ($id) $sql.= " WHERE rowid = '".$id."'";
|
||||||
if ($ref) $sql.= " WHERE ref = '".addslashes($ref)."'";
|
if ($ref) $sql.= " WHERE ref = '".addslashes($ref)."'";
|
||||||
@ -936,9 +942,12 @@ class Product extends CommonObject
|
|||||||
$this->barcode = $result["barcode"];
|
$this->barcode = $result["barcode"];
|
||||||
$this->barcode_type = $result["fk_barcode_type"];
|
$this->barcode_type = $result["fk_barcode_type"];
|
||||||
|
|
||||||
$this->next_prev_filter = 'entity = '.$conf->entity;
|
$this->stock_reel = $result["stock"];
|
||||||
|
$this->pmp = $result["pmp"];
|
||||||
|
|
||||||
$this->label_url = '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$this->id.'">'.$this->libelle.'</a>';
|
$this->import_key = $result["import_key"];
|
||||||
|
|
||||||
|
$this->next_prev_filter = 'entity = '.$conf->entity;
|
||||||
|
|
||||||
$this->db->free();
|
$this->db->free();
|
||||||
|
|
||||||
@ -958,10 +967,10 @@ class Product extends CommonObject
|
|||||||
$sql = "SELECT code, libelle, coder";
|
$sql = "SELECT code, libelle, coder";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
|
$sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
|
||||||
$sql.= " WHERE rowid = ".$this->barcode_type;
|
$sql.= " WHERE rowid = ".$this->barcode_type;
|
||||||
$result = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($result)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$result = $this->db->fetch_array();
|
$result = $this->db->fetch_array($resql);
|
||||||
$this->barcode_type_code = $result["code"];
|
$this->barcode_type_code = $result["code"];
|
||||||
$this->barcode_type_label = $result["libelle"];
|
$this->barcode_type_label = $result["libelle"];
|
||||||
$this->barcode_type_coder = $result["coder"];
|
$this->barcode_type_coder = $result["coder"];
|
||||||
@ -985,10 +994,10 @@ class Product extends CommonObject
|
|||||||
$sql.= " where price_level=".$i." and";
|
$sql.= " where price_level=".$i." and";
|
||||||
$sql.= " fk_product = '".$this->id."'";
|
$sql.= " fk_product = '".$this->id."'";
|
||||||
$sql.= " order by date_price DESC limit 1";
|
$sql.= " order by date_price DESC limit 1";
|
||||||
$result = $this->db->query($sql) ;
|
$resql = $this->db->query($sql) ;
|
||||||
if ( $result )
|
if ($resql)
|
||||||
{
|
{
|
||||||
$result = $this->db->fetch_array();
|
$result = $this->db->fetch_array($resql);
|
||||||
|
|
||||||
$this->multiprices[$i]=$result["price"];
|
$this->multiprices[$i]=$result["price"];
|
||||||
$this->multiprices_ttc[$i]=$result["price_ttc"];
|
$this->multiprices_ttc[$i]=$result["price_ttc"];
|
||||||
@ -1034,7 +1043,7 @@ class Product extends CommonObject
|
|||||||
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 = pd.fk_propal";
|
$sql.= " WHERE p.rowid = pd.fk_propal";
|
||||||
$sql.= " AND p.fk_soc = s.rowid";
|
$sql.= " AND p.fk_soc = s.rowid";
|
||||||
$sql.= " AND s.entity = ".$conf->entity;
|
$sql.= " AND s.entity = ".$conf->entity;
|
||||||
$sql.= " AND pd.fk_product = ".$this->id;
|
$sql.= " AND pd.fk_product = ".$this->id;
|
||||||
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||||
//$sql.= " AND pr.fk_statut != 0";
|
//$sql.= " AND pr.fk_statut != 0";
|
||||||
@ -1076,7 +1085,7 @@ class Product extends CommonObject
|
|||||||
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 = cd.fk_commande";
|
$sql.= " WHERE c.rowid = cd.fk_commande";
|
||||||
$sql.= " AND c.fk_soc = s.rowid";
|
$sql.= " AND c.fk_soc = s.rowid";
|
||||||
$sql.= " AND s.entity = ".$conf->entity;
|
$sql.= " AND s.entity = ".$conf->entity;
|
||||||
$sql.= " AND cd.fk_product = ".$this->id;
|
$sql.= " AND cd.fk_product = ".$this->id;
|
||||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||||
if ($socid > 0) $sql.= " AND c.fk_soc = ".$socid;
|
if ($socid > 0) $sql.= " AND c.fk_soc = ".$socid;
|
||||||
@ -1117,7 +1126,7 @@ class Product extends CommonObject
|
|||||||
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 = cd.fk_commande";
|
$sql.= " WHERE c.rowid = cd.fk_commande";
|
||||||
$sql.= " AND c.fk_soc = s.rowid";
|
$sql.= " AND c.fk_soc = s.rowid";
|
||||||
$sql.= " AND s.entity = ".$conf->entity;
|
$sql.= " AND s.entity = ".$conf->entity;
|
||||||
$sql.= " AND cd.fk_product = ".$this->id;
|
$sql.= " AND cd.fk_product = ".$this->id;
|
||||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||||
if ($socid > 0) $sql.= " AND c.fk_soc = ".$socid;
|
if ($socid > 0) $sql.= " AND c.fk_soc = ".$socid;
|
||||||
@ -1159,7 +1168,7 @@ class Product extends CommonObject
|
|||||||
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 e.rowid = ed.fk_expedition";
|
$sql.= " WHERE e.rowid = ed.fk_expedition";
|
||||||
$sql.= " AND e.fk_soc = s.rowid";
|
$sql.= " AND e.fk_soc = s.rowid";
|
||||||
$sql.= " AND s.entity = ".$conf->entity;
|
$sql.= " AND s.entity = ".$conf->entity;
|
||||||
$sql.= " AND ed.fk_origin_line = cd.rowid";
|
$sql.= " AND ed.fk_origin_line = cd.rowid";
|
||||||
$sql.= " AND cd.fk_product = ".$this->id;
|
$sql.= " AND cd.fk_product = ".$this->id;
|
||||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND e.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND e.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||||
@ -1201,7 +1210,7 @@ class Product extends CommonObject
|
|||||||
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 = cd.fk_contrat";
|
$sql.= " WHERE c.rowid = cd.fk_contrat";
|
||||||
$sql.= " AND c.fk_soc = s.rowid";
|
$sql.= " AND c.fk_soc = s.rowid";
|
||||||
$sql.= " AND s.entity = ".$conf->entity;
|
$sql.= " AND s.entity = ".$conf->entity;
|
||||||
$sql.= " AND cd.fk_product = ".$this->id;
|
$sql.= " AND cd.fk_product = ".$this->id;
|
||||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||||
//$sql.= " AND c.statut != 0";
|
//$sql.= " AND c.statut != 0";
|
||||||
@ -1242,7 +1251,7 @@ class Product extends CommonObject
|
|||||||
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 f.rowid = fd.fk_facture";
|
$sql.= " WHERE f.rowid = fd.fk_facture";
|
||||||
$sql.= " AND f.fk_soc = s.rowid";
|
$sql.= " AND f.fk_soc = s.rowid";
|
||||||
$sql.= " AND s.entity = ".$conf->entity;
|
$sql.= " AND s.entity = ".$conf->entity;
|
||||||
$sql.= " AND fd.fk_product = ".$this->id;
|
$sql.= " AND fd.fk_product = ".$this->id;
|
||||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||||
//$sql.= " AND f.fk_statut != 0";
|
//$sql.= " AND f.fk_statut != 0";
|
||||||
@ -1283,7 +1292,7 @@ class Product extends CommonObject
|
|||||||
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 f.rowid = fd.fk_facture_fourn";
|
$sql.= " WHERE f.rowid = fd.fk_facture_fourn";
|
||||||
$sql.= " AND f.fk_soc = s.rowid";
|
$sql.= " AND f.fk_soc = s.rowid";
|
||||||
$sql.= " AND s.entity = ".$conf->entity;
|
$sql.= " AND s.entity = ".$conf->entity;
|
||||||
$sql.= " AND fd.fk_product = ".$this->id;
|
$sql.= " AND fd.fk_product = ".$this->id;
|
||||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND f.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
|
||||||
//$sql.= " AND f.fk_statut != 0";
|
//$sql.= " AND f.fk_statut != 0";
|
||||||
@ -1852,13 +1861,13 @@ class Product extends CommonObject
|
|||||||
<a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$desc_pere[0]."\">".$compl_path.stripslashes($nom_pere)."
|
<a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$desc_pere[0]."\">".$compl_path.stripslashes($nom_pere)."
|
||||||
</a> (".$desc_pere[1].")</td><td align=\"center\"> ".$trueValue."</td><td> </td><td> </td>
|
</a> (".$desc_pere[1].")</td><td align=\"center\"> ".$trueValue."</td><td> </td><td> </td>
|
||||||
<td align=\"center\">".$this->stock_entrepot[1]." ".$img."</td></tr>",
|
<td align=\"center\">".$this->stock_entrepot[1]." ".$img."</td></tr>",
|
||||||
$desc_pere[0],
|
$desc_pere[0],
|
||||||
'fullpath' => $compl_path.$nom_pere);
|
'fullpath' => $compl_path.$nom_pere);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->res[]= array($compl_path.$nom_pere." (".$desc_pere[1].")",
|
$this->res[]= array($compl_path.$nom_pere." (".$desc_pere[1].")",
|
||||||
$desc_pere[0],
|
$desc_pere[0],
|
||||||
'fullpath' => $compl_path.$nom_pere);
|
'fullpath' => $compl_path.$nom_pere);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1909,7 +1918,7 @@ class Product extends CommonObject
|
|||||||
{
|
{
|
||||||
if (is_array($desc_pere)) $this->fetch_prod_arbo($desc_pere,"",$multiply);
|
if (is_array($desc_pere)) $this->fetch_prod_arbo($desc_pere,"",$multiply);
|
||||||
}
|
}
|
||||||
// dol_sort($this->res,);
|
// dol_sort($this->res,);
|
||||||
}
|
}
|
||||||
return $this->res;
|
return $this->res;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,19 +39,32 @@ class MouvementStock
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Add a movement in stock (in one direction only)
|
* \brief Add a movement in stock (in one direction only)
|
||||||
* \param type Direction of movement: 2=output (stock decrease), 3=input (stock increase)
|
* \param user User object
|
||||||
* \return int <0 if KO, >0 if OK
|
* \param fk_product Id of product
|
||||||
|
* \param entrepot_id Id of warehouse
|
||||||
|
* \param qty Qty of movement
|
||||||
|
* \param type Direction of movement: 2=output (stock decrease), 3=input (stock increase)
|
||||||
|
* \param type Unit price HT of product
|
||||||
|
* \return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0)
|
function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$error = 0;
|
$error = 0;
|
||||||
dol_syslog("MouvementStock::_create $user->id, $fk_product, $entrepot_id, qty=$qty, type=$type, $price");
|
dol_syslog("MouvementStock::_create start userid=$user->id, fk_product=$fk_product, warehouse=$entrepot_id, qty=$qty, type=$type, price=$price");
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
if (1 == 1) // Always change stock for current product, change for subproduct done after
|
$product = new Product($this->db);
|
||||||
|
$result=$product->fetch($fk_product);
|
||||||
|
if (! $result > 0)
|
||||||
|
{
|
||||||
|
dol_print_error('',"Failed to fetch product");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (1 == 1) // Always change stock for current product, change for subproduct is done after
|
||||||
{
|
{
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement";
|
||||||
$sql.= " (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author, price)";
|
$sql.= " (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author, price)";
|
||||||
@ -65,98 +78,117 @@ class MouvementStock
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
dol_syslog("MouvementStock::_create ".$this->error, LOG_ERR);
|
dol_syslog("MouvementStock::_create ".$this->error, LOG_ERR);
|
||||||
$error = -1;
|
$error = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Define current values for qty and pmp
|
||||||
|
$oldqty=$product->stock_reel;
|
||||||
|
$oldqtywarehouse=0;
|
||||||
|
$oldpmp=$product->pmp;
|
||||||
|
$oldpmpwarehouse=0;
|
||||||
|
|
||||||
// Test if there is already a record for couple (warehouse / product)
|
// Test if there is already a record for couple (warehouse / product)
|
||||||
$num = 0;
|
$num = 0;
|
||||||
if ($error == 0)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product_stock";
|
$sql = "SELECT rowid, reel, pmp FROM ".MAIN_DB_PREFIX."product_stock";
|
||||||
$sql.= " WHERE fk_entrepot = ".$entrepot_id." AND fk_product = ".$fk_product;
|
$sql.= " WHERE fk_entrepot = ".$entrepot_id." AND fk_product = ".$fk_product;
|
||||||
|
|
||||||
|
dol_syslog("MouvementStock::_create sql=".$sql);
|
||||||
if ($this->db->query($sql))
|
if ($this->db->query($sql))
|
||||||
{
|
{
|
||||||
$num = $this->db->num_rows($resql);
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
if ($obj)
|
||||||
|
{
|
||||||
|
$num = 1;
|
||||||
|
$oldqtywarehouse = $obj->reel;
|
||||||
|
$oldpmpwarehouse = $obj->pmp;
|
||||||
|
}
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
dol_syslog("MouvementStock::_create echec update ".$this->error, LOG_ERR);
|
dol_syslog("MouvementStock::_create echec update ".$this->error, LOG_ERR);
|
||||||
$error = -2;
|
$error = -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate new PMP
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$newpmp=0;
|
||||||
|
$newpmpwarehouse=0;
|
||||||
|
if ($price > 0)
|
||||||
|
{
|
||||||
|
if ($oldqty > 0 && $oldpmp > 0) $newpmp=($oldqty * $oldpmp + $qty * $price) / ($oldqty + $qty);
|
||||||
|
else $newpmp=$price;
|
||||||
|
if ($oldqtywarehouse > 0 && $oldpmpwarehouse > 0) $newpmpwarehouse=($oldqtywarehouse * $oldpmpwarehouse + $qty * $price) / ($oldqtywarehouse + $qty);
|
||||||
|
else $newpmpwarehouse=$price;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$newpmp = $oldpmp;
|
||||||
|
$newpmpwarehouse = $oldpmpwarehouse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update denormalized value of stock in product_stock and product
|
// Update denormalized value of stock in product_stock and product
|
||||||
if ($error == 0)
|
if (! $error)
|
||||||
{
|
{
|
||||||
if ($num > 0)
|
if ($num > 0)
|
||||||
{
|
{
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET reel = reel + ".$qty;
|
$sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET pmp = ".$newpmpwarehouse.", reel = reel + ".$qty;
|
||||||
$sql.= " WHERE fk_entrepot = ".$entrepot_id." AND fk_product = ".$fk_product;
|
$sql.= " WHERE fk_entrepot = ".$entrepot_id." AND fk_product = ".$fk_product;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_stock";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_stock";
|
||||||
$sql.= " (reel, fk_entrepot, fk_product) VALUES ";
|
$sql.= " (pmp, reel, fk_entrepot, fk_product) VALUES ";
|
||||||
$sql.= " (".$qty.",".$entrepot_id.",".$fk_product.")";
|
$sql.= " (".$newpmpwarehouse.", ".$qty.", ".$entrepot_id.", ".$fk_product.")";
|
||||||
}
|
}
|
||||||
|
|
||||||
dol_syslog("MouvementStock::_create sql=".$sql, LOG_DEBUG);
|
dol_syslog("MouvementStock::_create sql=".$sql);
|
||||||
if ($this->db->query($sql))
|
$resql=$this->db->query($sql);
|
||||||
{
|
if (! $resql)
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product SET stock = stock + ".$qty;
|
|
||||||
$sql.= " WHERE rowid = ".$fk_product;
|
|
||||||
|
|
||||||
dol_syslog("MouvementStock::_create sql=".$sql, LOG_DEBUG);
|
|
||||||
if ($this->db->query($sql))
|
|
||||||
{
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
// Update value of PMP in product_stock
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_syslog("MouvementStock::_create ".$this->error, LOG_ERR);
|
|
||||||
$error = -4;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
dol_syslog("MouvementStock::_create ".$this->error, LOG_ERR);
|
dol_syslog("MouvementStock::_create ".$this->error, LOG_ERR);
|
||||||
$error = -3;
|
$error = -3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (! $error)
|
||||||
if ($error == 0)
|
|
||||||
{
|
{
|
||||||
$valo_mouvement = 0;
|
$sql = "UPDATE ".MAIN_DB_PREFIX."product SET pmp = ".$newpmp.", stock = stock + ".$qty;
|
||||||
$error = $this->CalculateValoPmp($mvid, $fk_product, $qty, $price, $valo_mouvement);
|
$sql.= " WHERE rowid = ".$fk_product;
|
||||||
}
|
|
||||||
|
|
||||||
if ($error == 0)
|
dol_syslog("MouvementStock::_create sql=".$sql);
|
||||||
{
|
$resql=$this->db->query($sql);
|
||||||
$error = $this->CalculateEntrepotValoPmp($user, $entrepot_id, $valo_mouvement);
|
if (! $resql)
|
||||||
|
{
|
||||||
|
$this->error=$this->db->lasterror();
|
||||||
|
dol_syslog("MouvementStock::_create ".$this->error, LOG_ERR);
|
||||||
|
$error = -4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add movement for sub products
|
// Add movement for sub products
|
||||||
if ($error == 0 && $conf->global->PRODUIT_SOUSPRODUITS)
|
if (! $error && $conf->global->PRODUIT_SOUSPRODUITS)
|
||||||
{
|
{
|
||||||
$error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, $price=0);
|
$error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0); // pmp is not change for subproduct
|
||||||
}
|
}
|
||||||
|
|
||||||
// composition module
|
// composition module
|
||||||
if ($error == 0 && $qty < 0 && $conf->global->MAIN_MODULE_COMPOSITION)
|
if (! $error && $qty < 0 && $conf->global->MAIN_MODULE_COMPOSITION)
|
||||||
{
|
{
|
||||||
$error = $this->_createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, $price=0);
|
$error = $this->_createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, 0); // pmp is not change for subproduct
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($error == 0)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
@ -164,9 +196,8 @@ class MouvementStock
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
$this->error=$this->db->lasterror();
|
dol_syslog("MouvementStock::_create error code=".$error, LOG_ERR);
|
||||||
dol_syslog("MouvementStock::_create ".$this->error, LOG_ERR);
|
return -6;
|
||||||
return -2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +246,7 @@ class MouvementStock
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Crée un mouvement en base pour toutes les compositions de produits
|
* \brief Cr<EFBFBD>e un mouvement en base pour toutes les compositions de produits
|
||||||
* \return int <0 si ko, 0 si ok
|
* \return int <0 si ko, 0 si ok
|
||||||
*/
|
*/
|
||||||
function _createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, $price=0)
|
function _createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, $price=0)
|
||||||
@ -293,211 +324,5 @@ class MouvementStock
|
|||||||
return $nbSP;
|
return $nbSP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Calcul ???
|
|
||||||
* \return int <0 si ko, >0 si ok
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
function CalculateEntrepotValoPmp($user, $entrepot_id, $valo_mouvement)
|
|
||||||
{
|
|
||||||
$error = 0;
|
|
||||||
dol_syslog("MouvementStock::CalculateEntrepotValoPmp $user->id, $entrepot_id, $valo_mouvement");
|
|
||||||
|
|
||||||
if ( $valo_mouvement <> 0 )
|
|
||||||
{
|
|
||||||
$entrepot_value_pmp = 0;
|
|
||||||
|
|
||||||
if ($error === 0)
|
|
||||||
{
|
|
||||||
$sql = "SELECT valo_pmp,".$this->db->pdate("date_calcul")." FROM ".MAIN_DB_PREFIX."entrepot_valorisation";
|
|
||||||
$sql.= " WHERE fk_entrepot = $entrepot_id ORDER BY date_calcul DESC LIMIT 1;";
|
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
|
||||||
{
|
|
||||||
while ($row = $this->db->fetch_row($resql) )
|
|
||||||
{
|
|
||||||
$entrepot_value_pmp = $row[0];
|
|
||||||
$entrepot_value_date = $row[1];
|
|
||||||
}
|
|
||||||
$this->db->free($resql);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$error = -26;
|
|
||||||
dol_syslog("MouvementStock::CalculateEntrepotValoPmp ERRORSQL[$error]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$new_value = $entrepot_value_pmp + $valo_mouvement;
|
|
||||||
|
|
||||||
$now = time();
|
|
||||||
|
|
||||||
if ($error === 0)
|
|
||||||
{
|
|
||||||
if ( strftime('%Y%m%d',$entrepot_value_date) == strftime('%Y%m%d',$now) )
|
|
||||||
{
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."entrepot_valorisation";
|
|
||||||
$sql.= " SET valo_pmp='".price2num($new_value)."'";
|
|
||||||
$sql.= " WHERE fk_entrepot = $entrepot_id ";
|
|
||||||
$sql.= " AND ".$this->db->pdate("date_calcul")."='".$entrepot_value_date."';";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."entrepot_valorisation";
|
|
||||||
$sql.= " (date_calcul, fk_entrepot, valo_pmp)";
|
|
||||||
$sql.= " VALUES (".$this->db->idate(mktime()).", ".$entrepot_id;
|
|
||||||
$sql.= ",'".price2num($new_value)."')";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$error = -27;
|
|
||||||
dol_syslog("MouvementStock::CalculateEntrepotValoPmp ERRORSQL[$error]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($error === 0)
|
|
||||||
{
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."entrepot";
|
|
||||||
$sql.= " SET valo_pmp='".price2num($new_value)."'";
|
|
||||||
$sql.= " WHERE rowid = $entrepot_id ";
|
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$error = -28;
|
|
||||||
dol_syslog("MouvementStock::CalculateEntrepotValoPmp ERRORSQL[$error]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($error === 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_syslog("MouvementStock::CalculateEntrepotValoPmp RETURN IN ERROR[$error]");
|
|
||||||
return $error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief ???
|
|
||||||
* \param mvid int Id du mouvement
|
|
||||||
* \param fk_product int Id produit
|
|
||||||
* \param qty float Quantit�
|
|
||||||
* \param price float Prix unitaire du produit
|
|
||||||
* \param value_ope float Valeur du mouvement en retour
|
|
||||||
* \return int <0 si ko, 0 si ok
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
function CalculateValoPmp($mvid, $fk_product, $qty, $price=0, &$value_ope)
|
|
||||||
{
|
|
||||||
$error = 0;
|
|
||||||
dol_syslog("MouvementStock::CalculateValoPmp $mvid, $fk_product, $qty, $price");
|
|
||||||
|
|
||||||
if ( $qty <> 0 )
|
|
||||||
{
|
|
||||||
$price_pmp = 0;
|
|
||||||
$qty_stock = 0;
|
|
||||||
$stock_value_pmp = 0;
|
|
||||||
|
|
||||||
if ($error === 0)
|
|
||||||
{
|
|
||||||
$sql = "SELECT price_pmp, qty_stock, valo_pmp FROM ".MAIN_DB_PREFIX."stock_valorisation";
|
|
||||||
$sql.= " WHERE fk_product = $fk_product ORDER BY date_valo DESC LIMIT 1;";
|
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
|
||||||
{
|
|
||||||
while ($row = $this->db->fetch_row($resql) )
|
|
||||||
{
|
|
||||||
$price_pmp = $row[0];
|
|
||||||
$qty_stock = $row[1];
|
|
||||||
$stock_value_pmp = $row[2];
|
|
||||||
}
|
|
||||||
$this->db->free($resql);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_syslog("MouvementStock::CalculateValoPmp ERRORSQL[1] ".$this->error, LOG_ERR);
|
|
||||||
$error = -16;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calcul
|
|
||||||
if ($qty > 0)
|
|
||||||
{
|
|
||||||
// on stock
|
|
||||||
if (($qty + $qty_stock) <> 0)
|
|
||||||
$new_pmp = ( ($qty * $price) + ($qty_stock * $price_pmp ) ) / ($qty + $qty_stock);
|
|
||||||
|
|
||||||
$value_ope = $qty * $price;
|
|
||||||
$new_stock_qty = $qty_stock + $qty;
|
|
||||||
$new_stock_value_pmp = $stock_value_pmp + $value_ope;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// on destock
|
|
||||||
$new_pmp = $price_pmp;
|
|
||||||
$price = $price_pmp;
|
|
||||||
$value_ope = $qty * $price_pmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
$new_stock_qty = $qty_stock + $qty;
|
|
||||||
$new_stock_value_pmp = $stock_value_pmp + $value_ope;
|
|
||||||
|
|
||||||
// Fin calcul
|
|
||||||
if ($error === 0)
|
|
||||||
{
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_valorisation";
|
|
||||||
$sql.= " (date_valo, fk_product, fk_stock_mouvement, qty_ope, price_ope, valo_ope, price_pmp, qty_stock, valo_pmp)";
|
|
||||||
$sql.= " VALUES (".$this->db->idate(mktime()).", $fk_product, $mvid";
|
|
||||||
$sql.= ",'".price2num($qty)."'";
|
|
||||||
$sql.= ",'".price2num($price)."'";
|
|
||||||
$sql.= ",'".price2num($value_ope)."'";
|
|
||||||
$sql.= ",'".price2num($new_pmp)."'";
|
|
||||||
$sql.= ",'".price2num($new_stock_qty)."'";
|
|
||||||
$sql.= ",'".price2num($new_stock_value_pmp)."')";
|
|
||||||
|
|
||||||
if ($this->db->query($sql))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_syslog("MouvementStock::CalculateValoPmp ERRORSQL[2] insert ".$this->error, LOG_ERR);
|
|
||||||
$error = -17;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($error === 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_syslog("MouvementStock::CalculateValoPmp ERROR : $error");
|
|
||||||
return -21;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
||||||
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
|
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
|
||||||
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
|
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
|
||||||
@ -22,8 +22,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \file htdocs/product/stock/product.php
|
* \file htdocs/product/stock/product.php
|
||||||
* \ingroup product
|
* \ingroup product, stock
|
||||||
* \brief Page de la fiche stock d'un produit
|
* \brief Page to list detailed stock of a product
|
||||||
* \version $Id$
|
* \version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -350,9 +350,12 @@ print '</div>';
|
|||||||
*/
|
*/
|
||||||
print '<br><table class="noborder" width="100%">';
|
print '<br><table class="noborder" width="100%">';
|
||||||
print '<tr class="liste_titre"><td width="40%">'.$langs->trans("Warehouse").'</td>';
|
print '<tr class="liste_titre"><td width="40%">'.$langs->trans("Warehouse").'</td>';
|
||||||
print '<td align="right">'.$langs->trans("NumberOfUnit").'</td></tr>';
|
print '<td align="right">'.$langs->trans("NumberOfUnit").'</td>';
|
||||||
|
print '<td align="right">'.$langs->trans("AverageUnitPricePMP").'</td>';
|
||||||
|
print '<td align="right">'.$langs->trans("EstimatedStockValue").'</td>';
|
||||||
|
print '</tr>';
|
||||||
|
|
||||||
$sql = "SELECT e.rowid, e.label, ps.reel";
|
$sql = "SELECT e.rowid, e.label, ps.reel, ps.pmp";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e";
|
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."product_stock as ps";
|
$sql.= ", ".MAIN_DB_PREFIX."product_stock as ps";
|
||||||
$sql.= " WHERE ps.reel != 0";
|
$sql.= " WHERE ps.reel != 0";
|
||||||
@ -362,6 +365,8 @@ $sql.= " AND ps.fk_product = ".$product->id;
|
|||||||
$sql.= " ORDER BY lower(e.label)";
|
$sql.= " ORDER BY lower(e.label)";
|
||||||
|
|
||||||
$entrepotstatic=new Entrepot($db);
|
$entrepotstatic=new Entrepot($db);
|
||||||
|
$total=0;
|
||||||
|
$totalvalue=0;
|
||||||
|
|
||||||
$resql=$db->query($sql);
|
$resql=$db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
@ -376,13 +381,20 @@ if ($resql)
|
|||||||
print '<tr '.$bc[$var].'>';
|
print '<tr '.$bc[$var].'>';
|
||||||
print '<td>'.$entrepotstatic->getNomUrl(1).'</td>';
|
print '<td>'.$entrepotstatic->getNomUrl(1).'</td>';
|
||||||
print '<td align="right">'.$obj->reel.'</td>';
|
print '<td align="right">'.$obj->reel.'</td>';
|
||||||
|
print '<td align="right">'.price2num($obj->pmp,'MU').'</td>';
|
||||||
|
print '<td align="right">'.price(price2num($obj->pmp,'MU')*$obj->reel).'</td>';
|
||||||
print '</tr>'; ;
|
print '</tr>'; ;
|
||||||
$total = $total + $obj->reel;
|
$total = $total + $obj->reel;
|
||||||
|
$totalvalue = $totalvalue + price2num($obj->pmp,'MU')*$obj->reel;
|
||||||
$i++;
|
$i++;
|
||||||
$var=!$var;
|
$var=!$var;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print '<tr class="liste_total"><td align="right" class="liste_total">'.$langs->trans("Total").':</td><td class="liste_total" align="right">'.$total."</td></tr>";
|
print '<tr class="liste_total"><td align="right" class="liste_total">'.$langs->trans("Total").':</td>';
|
||||||
|
print '<td class="liste_total" align="right">'.$total.'</td>';
|
||||||
|
print '<td class="liste_total" align="right"> </td>';
|
||||||
|
print '<td class="liste_total" align="right">'.price($totalvalue).'</td>';
|
||||||
|
print "</tr>";
|
||||||
print "</table>";
|
print "</table>";
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,9 @@
|
|||||||
-- when current version is 2.6.0 or higher.
|
-- when current version is 2.6.0 or higher.
|
||||||
--
|
--
|
||||||
|
|
||||||
|
drop table llx_stock_valorisation;
|
||||||
|
drop table llx_entrepot_valorisation;
|
||||||
|
|
||||||
update llx_actioncomm set datep = datec where datep is null and datec is not null;
|
update llx_actioncomm set datep = datec where datep is null and datec is not null;
|
||||||
|
|
||||||
-- Create new table for import module
|
-- Create new table for import module
|
||||||
|
|||||||
@ -1,29 +0,0 @@
|
|||||||
-- ============================================================================
|
|
||||||
-- Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
|
||||||
--
|
|
||||||
-- 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 2 of the License, or
|
|
||||||
-- (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
|
|
||||||
-- along with this program; if not, write to the Free Software
|
|
||||||
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
--
|
|
||||||
-- $Id$
|
|
||||||
-- ============================================================================
|
|
||||||
|
|
||||||
create table llx_entrepot_valorisation
|
|
||||||
(
|
|
||||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
tms timestamp, -- date technique mise à jour automatiquement
|
|
||||||
date_calcul date, -- date auquel a ete calcule la valeur
|
|
||||||
fk_entrepot integer UNSIGNED NOT NULL,
|
|
||||||
valo_pmp float(12,4) -- valoristaion du stock en PMP
|
|
||||||
)type=innodb;
|
|
||||||
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
-- ============================================================================
|
|
||||||
-- Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
|
||||||
-- Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
||||||
--
|
|
||||||
-- 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 2 of the License, or
|
|
||||||
-- (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
|
|
||||||
-- along with this program; if not, write to the Free Software
|
|
||||||
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
--
|
|
||||||
-- $Id$
|
|
||||||
-- ============================================================================
|
|
||||||
|
|
||||||
|
|
||||||
ALTER TABLE llx_stock_valorisation ADD INDEX idx_stock_valorisation_fk_product (fk_product);
|
|
||||||
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
-- ============================================================================
|
|
||||||
-- Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
|
||||||
--
|
|
||||||
-- 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 2 of the License, or
|
|
||||||
-- (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
|
|
||||||
-- along with this program; if not, write to the Free Software
|
|
||||||
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
--
|
|
||||||
-- $Id$
|
|
||||||
-- ============================================================================
|
|
||||||
|
|
||||||
create table llx_stock_valorisation
|
|
||||||
(
|
|
||||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
tms timestamp, -- date technique mise à jour automatiquement
|
|
||||||
date_valo datetime, -- date de valorisation
|
|
||||||
fk_product integer NOT NULL, -- id du produit concerne par l'operation
|
|
||||||
qty_ope float(9,3), -- quantité de l'operation
|
|
||||||
price_ope float(12,4), -- prix unitaire du produit concerne par l'operation
|
|
||||||
valo_ope float(12,4), -- valorisation de l'operation
|
|
||||||
price_pmp float(12,4), -- valeur PMP de l'operation
|
|
||||||
qty_stock float(9,3) DEFAULT 0, -- qunatite en stock
|
|
||||||
valo_pmp float(12,4), -- valorisation du stock en PMP
|
|
||||||
fk_stock_mouvement integer -- id du mouvement de stock
|
|
||||||
)type=innodb;
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user