forked from Wavyzz/dolibarr
Removed deprecated code
This commit is contained in:
@@ -54,6 +54,7 @@ CanceledBy=Canceled by %s
|
|||||||
ClosedBy=Closed by %s
|
ClosedBy=Closed by %s
|
||||||
FileWasRemoved=File was deleted
|
FileWasRemoved=File was deleted
|
||||||
DirWasRemoved=Directory was removed
|
DirWasRemoved=Directory was removed
|
||||||
|
FeatureNotYetAvailableShort=Available in a next version
|
||||||
FeatureNotYetAvailable=Feature not yet available in this version
|
FeatureNotYetAvailable=Feature not yet available in this version
|
||||||
FeatureExperimental=Experimental feature. Not stable in this version
|
FeatureExperimental=Experimental feature. Not stable in this version
|
||||||
FeatureDevelopment=Development feature. Not stable in this version
|
FeatureDevelopment=Development feature. Not stable in this version
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ NumberOfUnit=Number of units
|
|||||||
TotalStock=Total in stock
|
TotalStock=Total in stock
|
||||||
StockTooLow=Stock too low
|
StockTooLow=Stock too low
|
||||||
EnhancedValue=Value
|
EnhancedValue=Value
|
||||||
|
PMPValue=Value
|
||||||
EnhancedValueOfWarehouses=Warehouses value
|
EnhancedValueOfWarehouses=Warehouses value
|
||||||
UserWarehouseAutoCreate=Create a stock automatically when creating a user
|
UserWarehouseAutoCreate=Create a stock automatically when creating a user
|
||||||
QtyDispatched=Quantity dispatched
|
QtyDispatched=Quantity dispatched
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ CanceledBy=Annul
|
|||||||
ClosedBy=Clotur<75> par %s
|
ClosedBy=Clotur<75> par %s
|
||||||
FileWasRemoved=Le fichier a <20>t<EFBFBD> supprim<69>
|
FileWasRemoved=Le fichier a <20>t<EFBFBD> supprim<69>
|
||||||
DirWasRemoved=Le r<>pertoire a <20>t<EFBFBD> supprim<69>
|
DirWasRemoved=Le r<>pertoire a <20>t<EFBFBD> supprim<69>
|
||||||
|
FeatureNotYetAvailableShort=Disponible dans une prochaine version
|
||||||
FeatureNotYetAvailable=Fonctionnalit<69> pas encore disponible dans cette version
|
FeatureNotYetAvailable=Fonctionnalit<69> pas encore disponible dans cette version
|
||||||
FeatureExperimental=Fonctionnalit<69> exp<78>rimentale. Non stable dans cette version
|
FeatureExperimental=Fonctionnalit<69> exp<78>rimentale. Non stable dans cette version
|
||||||
FeatureDevelopment=Fonctionnalit<69> en d<>veloppement. Non stable dans cette version
|
FeatureDevelopment=Fonctionnalit<69> en d<>veloppement. Non stable dans cette version
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ NumberOfUnit=Nombre de pi
|
|||||||
TotalStock=Total en stock
|
TotalStock=Total en stock
|
||||||
StockTooLow=Stock insuffisant
|
StockTooLow=Stock insuffisant
|
||||||
EnhancedValue=Valorisation
|
EnhancedValue=Valorisation
|
||||||
|
PMPValue=Valorisation (PMP)
|
||||||
EnhancedValueOfWarehouses=Valorisation des stocks
|
EnhancedValueOfWarehouses=Valorisation des stocks
|
||||||
UserWarehouseAutoCreate=Cr<43>er un stock automatiquement <20> la cr<63>ation d'un utilisateur
|
UserWarehouseAutoCreate=Cr<43>er un stock automatiquement <20> la cr<63>ation d'un utilisateur
|
||||||
QtyDispatched=Quantit<69> ventil<69>e
|
QtyDispatched=Quantit<69> ventil<69>e
|
||||||
|
|||||||
@@ -265,11 +265,13 @@ else
|
|||||||
// Statut
|
// Statut
|
||||||
print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">'.$entrepot->getLibStatut(4).'</td></tr>';
|
print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">'.$entrepot->getLibStatut(4).'</td></tr>';
|
||||||
|
|
||||||
|
// Nb of products
|
||||||
print '<tr><td valign="top">'.$langs->trans("NumberOfProducts").'</td><td colspan="3">';
|
print '<tr><td valign="top">'.$langs->trans("NumberOfProducts").'</td><td colspan="3">';
|
||||||
print $entrepot->nb_products();
|
$nb=$entrepot->nb_products();
|
||||||
|
print empty($nb)?'0':$nb;
|
||||||
print "</td></tr>";
|
print "</td></tr>";
|
||||||
|
|
||||||
// Dernier mouvement
|
// Last movement
|
||||||
$sql = "SELECT max( ".$db->pdate("m.datem").") as datem";
|
$sql = "SELECT max( ".$db->pdate("m.datem").") as datem";
|
||||||
$sql .= " FROM llx_stock_mouvement as m";
|
$sql .= " FROM llx_stock_mouvement as m";
|
||||||
$sql .= " WHERE m.fk_entrepot = '".$entrepot->id."';";
|
$sql .= " WHERE m.fk_entrepot = '".$entrepot->id."';";
|
||||||
@@ -320,12 +322,14 @@ else
|
|||||||
print_liste_field_titre($langs->trans("Product"),"", "p.ref","&id=".$_GET['id'],"","",$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("Product"),"", "p.ref","&id=".$_GET['id'],"","",$sortfield,$sortorder);
|
||||||
print_liste_field_titre($langs->trans("Label"),"", "p.label","&id=".$_GET['id'],"","",$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("Label"),"", "p.label","&id=".$_GET['id'],"","",$sortfield,$sortorder);
|
||||||
print_liste_field_titre($langs->trans("Units"),"", "ps.reel","&id=".$_GET['id'],"",'align="right"',$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("Units"),"", "ps.reel","&id=".$_GET['id'],"",'align="right"',$sortfield,$sortorder);
|
||||||
|
print_liste_field_titre($langs->trans("PMP"),"", "ps.pmp","&id=".$_GET['id'],"",'align="center"',$sortfield,$sortorder);
|
||||||
if ($user->rights->stock->mouvement->creer) print '<td> </td>';
|
if ($user->rights->stock->mouvement->creer) print '<td> </td>';
|
||||||
if ($user->rights->stock->creer) print '<td> </td>';
|
if ($user->rights->stock->creer) print '<td> </td>';
|
||||||
print "</tr>";
|
print "</tr>";
|
||||||
|
|
||||||
$sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, ps.reel as value ";
|
$sql = "SELECT p.rowid as rowid, p.ref, p.label as produit,";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."product_stock ps, ".MAIN_DB_PREFIX."product p ";
|
$sql.= " ps.reel as value";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock ps, ".MAIN_DB_PREFIX."product p ";
|
||||||
if ($conf->categorie->enabled && !$user->rights->categorie->voir)
|
if ($conf->categorie->enabled && !$user->rights->categorie->voir)
|
||||||
{
|
{
|
||||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
|
||||||
@@ -375,8 +379,11 @@ else
|
|||||||
print img_object($langs->trans("ShowProduct"),"product").' '.$objp->ref;
|
print img_object($langs->trans("ShowProduct"),"product").' '.$objp->ref;
|
||||||
print "</a></td>";
|
print "</a></td>";
|
||||||
print '<td>'.$objp->produit.'</td>';
|
print '<td>'.$objp->produit.'</td>';
|
||||||
|
|
||||||
print '<td align="right">'.$objp->value.'</td>';
|
print '<td align="right">'.$objp->value.'</td>';
|
||||||
|
|
||||||
|
print '<td align="center">'.$langs->trans("FeatureNotYetAvailableShort").'</td>';
|
||||||
|
|
||||||
if ($user->rights->stock->mouvement->creer)
|
if ($user->rights->stock->mouvement->creer)
|
||||||
{
|
{
|
||||||
print '<td align="center"><a href="'.DOL_URL_ROOT.'/product/stock/product.php?dwid='.$entrepot->id.'&id='.$objp->rowid.'&action=transfert">';
|
print '<td align="center"><a href="'.DOL_URL_ROOT.'/product/stock/product.php?dwid='.$entrepot->id.'&id='.$objp->rowid.'&action=transfert">';
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class MouvementStock
|
|||||||
$error = -1;
|
$error = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current value of stock
|
// Test if there is already a record for couple (warehouse / product)
|
||||||
$num = 0;
|
$num = 0;
|
||||||
if ($error == 0)
|
if ($error == 0)
|
||||||
{
|
{
|
||||||
@@ -108,6 +108,8 @@ class MouvementStock
|
|||||||
dolibarr_syslog("MouvementStock::_Create sql=".$sql, LOG_DEBUG);
|
dolibarr_syslog("MouvementStock::_Create sql=".$sql, LOG_DEBUG);
|
||||||
if ($this->db->query($sql))
|
if ($this->db->query($sql))
|
||||||
{
|
{
|
||||||
|
// TODO
|
||||||
|
// Update value of PMP in product_stock
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -117,6 +119,7 @@ class MouvementStock
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if ($error == 0)
|
if ($error == 0)
|
||||||
{
|
{
|
||||||
$valo_mouvement = 0;
|
$valo_mouvement = 0;
|
||||||
@@ -127,6 +130,7 @@ class MouvementStock
|
|||||||
{
|
{
|
||||||
$error = $this->CalculateEntrepotValoPmp($user, $entrepot_id, $valo_mouvement);
|
$error = $this->CalculateEntrepotValoPmp($user, $entrepot_id, $valo_mouvement);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add movement for sub products
|
// Add movement for sub products
|
||||||
@@ -157,7 +161,7 @@ class MouvementStock
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Create movement in databse for all subproducts
|
* \brief Create movement in database for all subproducts
|
||||||
* \return int <0 si ko, 0 si ok
|
* \return int <0 si ko, 0 si ok
|
||||||
*/
|
*/
|
||||||
function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price=0)
|
function _createSubProduct($user, $idProduct, $entrepot_id, $qty, $type, $price=0)
|
||||||
@@ -199,252 +203,43 @@ class MouvementStock
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Cr<43>e un mouvement en base pour toutes les compositions de produits
|
* \brief Cr<43>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)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
dolibarr_syslog("MouvementStock::_createComposition $user->id, $fk_product, $entrepot_id, $qty, $type, $price");
|
|
||||||
$products_compo = array();
|
|
||||||
|
|
||||||
$sql = "SELECT fk_product_composition, qte, etat_stock";
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_composition";
|
|
||||||
$sql.= " WHERE fk_product = $fk_product;";
|
|
||||||
|
|
||||||
$all = $this->db->query($sql);
|
|
||||||
|
|
||||||
if ($all)
|
|
||||||
{
|
|
||||||
while($item = $this->db->fetch_object($all) )
|
|
||||||
{
|
|
||||||
if($item->etat_stock != 0) array_push($products_compo,$item);
|
|
||||||
}
|
|
||||||
$this->db->free($resql);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dolibarr_syslog("MouvementStock::_Create echec update ".$this->error);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($products_compo as $product)
|
|
||||||
{
|
|
||||||
$this->_create($user, $product->fk_product_composition, $entrepot_id, ($qty*$product->qte), $type, $price=0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Calcul ???
|
|
||||||
* \return int <0 si ko, >0 si ok
|
|
||||||
*/
|
*/
|
||||||
function CalculateEntrepotValoPmp($user, $entrepot_id, $valo_mouvement)
|
function _createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, $price=0)
|
||||||
{
|
{
|
||||||
$error = 0;
|
|
||||||
dolibarr_syslog("MouvementStock::CalculateEntrepotValoPmp $user->id, $entrepot_id, $valo_mouvement");
|
|
||||||
|
|
||||||
if ( $valo_mouvement <> 0 )
|
|
||||||
|
dolibarr_syslog("MouvementStock::_createComposition $user->id, $fk_product, $entrepot_id, $qty, $type, $price");
|
||||||
|
$products_compo = array();
|
||||||
|
|
||||||
|
$sql = "SELECT fk_product_composition, qte, etat_stock";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_composition";
|
||||||
|
$sql.= " WHERE fk_product = $fk_product;";
|
||||||
|
|
||||||
|
$all = $this->db->query($sql);
|
||||||
|
|
||||||
|
if ($all)
|
||||||
{
|
{
|
||||||
$entrepot_value_pmp = 0;
|
while($item = $this->db->fetch_object($all) )
|
||||||
|
{
|
||||||
if ($error === 0)
|
if($item->etat_stock != 0) array_push($products_compo,$item);
|
||||||
{
|
}
|
||||||
$sql = "SELECT valo_pmp,".$this->db->pdate("date_calcul")." FROM ".MAIN_DB_PREFIX."entrepot_valorisation";
|
$this->db->free($resql);
|
||||||
$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;
|
|
||||||
dolibarr_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;
|
|
||||||
dolibarr_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;
|
|
||||||
dolibarr_syslog("MouvementStock::CalculateEntrepotValoPmp ERRORSQL[$error]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($error === 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dolibarr_syslog("MouvementStock::CalculateEntrepotValoPmp RETURN IN ERROR[$error]");
|
|
||||||
return $error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return 0;
|
dolibarr_syslog("MouvementStock::_Create echec update ".$this->error);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
foreach($products_compo as $product)
|
||||||
/**
|
|
||||||
* \brief ???
|
|
||||||
* \param mvid int Id du mouvement
|
|
||||||
* \param fk_product int Id produit
|
|
||||||
* \param qty float Quantit<69>
|
|
||||||
* \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;
|
|
||||||
dolibarr_syslog("MouvementStock::CalculateValoPmp $mvid, $fk_product, $qty, $price");
|
|
||||||
|
|
||||||
if ( $qty <> 0 )
|
|
||||||
{
|
{
|
||||||
$price_pmp = 0;
|
$this->_create($user, $product->fk_product_composition, $entrepot_id, ($qty*$product->qte), $type, $price=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
|
|
||||||
{
|
|
||||||
dolibarr_syslog("MouvementStock::CalculateValoPmp ERRORSQL[1] ".$this->error);
|
|
||||||
$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
|
|
||||||
{
|
|
||||||
dolibarr_syslog("MouvementStock::CalculateValoPmp ERRORSQL[2] insert ".$this->error);
|
|
||||||
$error = -17;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($error === 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dolibarr_syslog("MouvementStock::CalculateValoPmp ERROR : $error");
|
|
||||||
return -21;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -489,5 +284,211 @@ 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;
|
||||||
|
dolibarr_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;
|
||||||
|
dolibarr_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;
|
||||||
|
dolibarr_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;
|
||||||
|
dolibarr_syslog("MouvementStock::CalculateEntrepotValoPmp ERRORSQL[$error]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error === 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dolibarr_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<69>
|
||||||
|
* \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;
|
||||||
|
dolibarr_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
|
||||||
|
{
|
||||||
|
dolibarr_syslog("MouvementStock::CalculateValoPmp ERRORSQL[1] ".$this->error);
|
||||||
|
$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
|
||||||
|
{
|
||||||
|
dolibarr_syslog("MouvementStock::CalculateValoPmp ERRORSQL[2] insert ".$this->error);
|
||||||
|
$error = -17;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error === 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dolibarr_syslog("MouvementStock::CalculateValoPmp ERROR : $error");
|
||||||
|
return -21;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -18,11 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\file htdocs/product/stock/valo.php
|
* \file htdocs/product/stock/valo.php
|
||||||
\ingroup stock
|
* \ingroup stock
|
||||||
\brief Page de valorisation des stocks
|
* \brief Page de valorisation des stocks
|
||||||
\version $Id$
|
* \version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require("./pre.inc.php");
|
require("./pre.inc.php");
|
||||||
require_once("./entrepot.class.php");
|
require_once("./entrepot.class.php");
|
||||||
@@ -30,7 +30,7 @@ require_once("./entrepot.class.php");
|
|||||||
$langs->load("stocks");
|
$langs->load("stocks");
|
||||||
|
|
||||||
if (!$user->rights->stock->lire)
|
if (!$user->rights->stock->lire)
|
||||||
accessforbidden();
|
accessforbidden();
|
||||||
|
|
||||||
$sref=isset($_GET["sref"])?$_GET["sref"]:$_POST["sref"];
|
$sref=isset($_GET["sref"])?$_GET["sref"]:$_POST["sref"];
|
||||||
$snom=isset($_GET["snom"])?$_GET["snom"]:$_POST["snom"];
|
$snom=isset($_GET["snom"])?$_GET["snom"]:$_POST["snom"];
|
||||||
@@ -38,8 +38,8 @@ $sall=isset($_GET["sall"])?$_GET["sall"]:$_POST["sall"];
|
|||||||
|
|
||||||
$sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
|
$sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
|
||||||
$sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"];
|
$sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"];
|
||||||
if (! $sortfield) $sortfield="valo";
|
if (! $sortfield) $sortfield="e.label";
|
||||||
if (! $sortorder) $sortorder="DESC";
|
if (! $sortorder) $sortorder="ASC";
|
||||||
$page = $_GET["page"];
|
$page = $_GET["page"];
|
||||||
if ($page < 0) $page = 0;
|
if ($page < 0) $page = 0;
|
||||||
$limit = $conf->liste_limit;
|
$limit = $conf->liste_limit;
|
||||||
@@ -53,16 +53,16 @@ $year = strftime("%Y",time());
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Affichage valorisation par entrepot
|
// Affichage valorisation par entrepot
|
||||||
$sql = "SELECT e.rowid as ref, e.label, e.statut, e.lieu, e.valo_pmp as valo";
|
$sql = "SELECT e.rowid as ref, e.label, e.statut, e.lieu";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
|
$sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
|
||||||
$sql .= " WHERE 1=1";
|
$sql .= " WHERE 1=1";
|
||||||
if ($sref)
|
if ($sref)
|
||||||
{
|
{
|
||||||
$sql .= " AND e.ref like '%".$sref."%'";
|
$sql .= " AND e.ref like '%".$sref."%'";
|
||||||
}
|
}
|
||||||
if ($sall)
|
if ($sall)
|
||||||
{
|
{
|
||||||
$sql .= " AND (e.label like '%".addslashes($sall)."%' OR e.description like '%".addslashes($sall)."%' OR e.lieu like '%".addslashes($sall)."%' OR e.address like '%".addslashes($sall)."%' OR e.ville like '%".addslashes($sall)."%')";
|
$sql .= " AND (e.label like '%".addslashes($sall)."%' OR e.description like '%".addslashes($sall)."%' OR e.lieu like '%".addslashes($sall)."%' OR e.address like '%".addslashes($sall)."%' OR e.ville like '%".addslashes($sall)."%')";
|
||||||
}
|
}
|
||||||
$sql .= " ORDER BY $sortfield $sortorder ";
|
$sql .= " ORDER BY $sortfield $sortorder ";
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
@@ -70,52 +70,55 @@ $sql .= $db->plimit($limit + 1, $offset);
|
|||||||
$result = $db->query($sql) ;
|
$result = $db->query($sql) ;
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$num = $db->num_rows($result);
|
$num = $db->num_rows($result);
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
llxHeader("","",$langs->trans("EnhancedValueOfWarehouses"));
|
llxHeader("","",$langs->trans("EnhancedValueOfWarehouses"));
|
||||||
|
|
||||||
print_barre_liste($langs->trans("EnhancedValueOfWarehouses"), $page, "valo.php", "", $sortfield, $sortorder,'',$num);
|
print_barre_liste($langs->trans("EnhancedValueOfWarehouses"), $page, "valo.php", "", $sortfield, $sortorder,'',$num);
|
||||||
|
|
||||||
print '<table class="noborder" width="100%">';
|
print '<table class="noborder" width="100%">';
|
||||||
print "<tr class=\"liste_titre\">";
|
print "<tr class=\"liste_titre\">";
|
||||||
print_liste_field_titre($langs->trans("Ref"),"valo.php", "e.label","","","",$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("Ref"),"valo.php", "e.label","","","",$sortfield,$sortorder);
|
||||||
print_liste_field_titre($langs->trans("LocationSummary"),"valo.php", "e.lieu","","","",$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("LocationSummary"),"valo.php", "e.lieu","","","",$sortfield,$sortorder);
|
||||||
print_liste_field_titre($langs->trans("EnhancedValue"),"valo.php", "valo",'','','align="right"',$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("PMPValue"),"valo.php", "valo",'','','align="right"',$sortfield,$sortorder);
|
||||||
print_liste_field_titre($langs->trans("Status"),"valo.php", "e.statut",'','','align="right"',$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("Status"),"valo.php", "e.statut",'','','align="right"',$sortfield,$sortorder);
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
|
||||||
if ($num)
|
if ($num)
|
||||||
{
|
|
||||||
$entrepot=new Entrepot($db);
|
|
||||||
$total = 0;
|
|
||||||
$var=false;
|
|
||||||
while ($i < min($num,$limit))
|
|
||||||
{
|
{
|
||||||
$objp = $db->fetch_object($result);
|
$entrepot=new Entrepot($db);
|
||||||
print "<tr $bc[$var]>";
|
$total = 0;
|
||||||
print '<td><a href="fiche.php?id='.$objp->ref.'">'.img_object($langs->trans("ShowWarehouse"),'stock').' '.$objp->label.'</a></td>';
|
$var=false;
|
||||||
print '<td>'.$objp->lieu.'</td>';
|
while ($i < min($num,$limit))
|
||||||
print '<td align="right">'.price($objp->valo).' '.$langs->trans('Currency'.$conf->monnaie).'</td>';
|
{
|
||||||
print '<td align="right">'.$entrepot->LibStatut($objp->statut,5).'</td>';
|
$objp = $db->fetch_object($result);
|
||||||
print "</tr>\n";
|
print "<tr $bc[$var]>";
|
||||||
$total += $objp->valo;
|
print '<td><a href="fiche.php?id='.$objp->ref.'">'.img_object($langs->trans("ShowWarehouse"),'stock').' '.$objp->label.'</a></td>';
|
||||||
$var=!$var;
|
print '<td>'.$objp->lieu.'</td>';
|
||||||
$i++;
|
print '<td align="right">';
|
||||||
|
// This value is real QTY * PMP of products in llx_product_stock for the warehouse
|
||||||
|
print $langs->trans("FeatureNotYetAvailableShort");
|
||||||
|
print '</td>';
|
||||||
|
print '<td align="right">'.$entrepot->LibStatut($objp->statut,5).'</td>';
|
||||||
|
print "</tr>\n";
|
||||||
|
$total += $objp->valo;
|
||||||
|
$var=!$var;
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
print '<tr class="liste_total">';
|
||||||
|
print '<td colspan="2" align="right">'.$langs->trans("Total").'</td>';
|
||||||
|
print '<td align="right">'.price($total).' '.$langs->trans('Currency'.$conf->monnaie).'</td>';
|
||||||
|
print '<td align="right"> </td>';
|
||||||
|
print "</tr>\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
$db->free($result);
|
||||||
|
print "</table>";
|
||||||
|
|
||||||
print '<tr class="liste_total">';
|
print '<br />';
|
||||||
print '<td colspan="2" align="right">'.$langs->trans("Total").'</td>';
|
|
||||||
print '<td align="right">'.price($total).' '.$langs->trans('Currency'.$conf->monnaie).'</td>';
|
|
||||||
print '<td align="right"> </td>';
|
|
||||||
print "</tr>\n";
|
|
||||||
|
|
||||||
}
|
|
||||||
$db->free($result);
|
|
||||||
print "</table>";
|
|
||||||
|
|
||||||
print '<br />';
|
|
||||||
|
|
||||||
$file='entrepot-'.$year.'.png';
|
$file='entrepot-'.$year.'.png';
|
||||||
if (file_exists(DOL_DATA_ROOT.'/entrepot/temp/'.$file))
|
if (file_exists(DOL_DATA_ROOT.'/entrepot/temp/'.$file))
|
||||||
@@ -126,15 +129,15 @@ if ($result)
|
|||||||
|
|
||||||
$file='entrepot-'.($year-1).'.png';
|
$file='entrepot-'.($year-1).'.png';
|
||||||
if (file_exists(DOL_DATA_ROOT.'/entrepot/temp/'.$file))
|
if (file_exists(DOL_DATA_ROOT.'/entrepot/temp/'.$file))
|
||||||
{
|
{
|
||||||
$url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&file='.$file;
|
$url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&file='.$file;
|
||||||
print '<br /><img src="'.$url.'" alt="Valorisation du stock ann<6E>e '.($year-1).'">';
|
print '<br /><img src="'.$url.'" alt="Valorisation du stock ann<6E>e '.($year-1).'">';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_print_error($db);
|
dolibarr_print_error($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|||||||
@@ -13,3 +13,6 @@ insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) v
|
|||||||
insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (71, 'facture_fourn', 'external', 'BILLING', 'Contact fournisseur facturation', 1);
|
insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (71, 'facture_fourn', 'external', 'BILLING', 'Contact fournisseur facturation', 1);
|
||||||
insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (72, 'facture_fourn', 'external', 'SHIPPING', 'Contact fournisseur livraison', 1);
|
insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (72, 'facture_fourn', 'external', 'SHIPPING', 'Contact fournisseur livraison', 1);
|
||||||
insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (73, 'facture_fourn', 'external', 'SERVICE', 'Contact fournisseur prestation', 1);
|
insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (73, 'facture_fourn', 'external', 'SERVICE', 'Contact fournisseur prestation', 1);
|
||||||
|
|
||||||
|
alter table llx_product_stock add column pmp double(24,8) default 0 NOT NULL;
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ create table llx_product_stock
|
|||||||
tms timestamp,
|
tms timestamp,
|
||||||
fk_product integer NOT NULL,
|
fk_product integer NOT NULL,
|
||||||
fk_entrepot integer NOT NULL,
|
fk_entrepot integer NOT NULL,
|
||||||
reel integer -- stock r<>el
|
reel integer -- physical stock
|
||||||
|
pmp double(24,8) default 0 NOT NULL -- PMP value for product in this warehous
|
||||||
)type=innodb;
|
)type=innodb;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user