New: Store and show estimated value of stock
This commit is contained in:
parent
0067d360c4
commit
726b3c1d72
@ -21,7 +21,7 @@
|
||||
/**
|
||||
\file htdocs/fourn/fournisseur.product.class.php
|
||||
\ingroup produit
|
||||
\brief Fichier de la classe des produits prédéfinis
|
||||
\brief Fichier de la classe des produits pr<EFBFBD>d<EFBFBD>finis
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
@ -31,7 +31,7 @@ require_once DOL_DOCUMENT_ROOT."/fourn/fournisseur.class.php";
|
||||
|
||||
/**
|
||||
\class Product
|
||||
\brief Classe permettant la gestion des produits prédéfinis
|
||||
\brief Classe permettant la gestion des produits pr<EFBFBD>d<EFBFBD>finis
|
||||
*/
|
||||
class ProductFournisseur extends Product
|
||||
{
|
||||
@ -146,12 +146,12 @@ class ProductFournisseur extends Product
|
||||
function remove_product_fournisseur_price($rowid)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
|
||||
$sql.= " WHERE rowid = ".$rowid;
|
||||
|
||||
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price sql=".$sql);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
@ -162,7 +162,7 @@ class ProductFournisseur extends Product
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pfp.fk_product_fournisseur = pf.rowid";
|
||||
$sql.= " WHERE pfp.rowid IS NULL";
|
||||
$sql.= " AND pf.entity = ".$conf->entity;
|
||||
|
||||
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price sql=".$sql);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
@ -175,7 +175,7 @@ class ProductFournisseur extends Product
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||
$sql.= " WHERE rowid = ".$rowidpf;
|
||||
|
||||
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price sql=".$sql);
|
||||
$resql2 = $this->db->query($sql);
|
||||
if (! $resql2)
|
||||
@ -223,11 +223,11 @@ class ProductFournisseur extends Product
|
||||
{
|
||||
$this->fourn_ref = $ref;
|
||||
|
||||
/* Mise à jour du prix */
|
||||
/* Mise <EFBFBD> jour du prix */
|
||||
|
||||
$this->update_buyprice($qty, $buyprice, $user);
|
||||
|
||||
/* Mise à jour de la référence */
|
||||
/* Mise <EFBFBD> jour de la r<>f<EFBFBD>rence */
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur ";
|
||||
$sql .= " SET ref_fourn = '" . $this->fourn_ref ."'";
|
||||
@ -241,7 +241,7 @@ class ProductFournisseur extends Product
|
||||
/**
|
||||
* \brief Modifie le prix d'achat pour un fournisseur
|
||||
* \param qty Quantite min pour lequel le prix est valide
|
||||
* \param buyprice Prix d'achat pour la quantité min
|
||||
* \param buyprice Prix d'achat pour la quantit<EFBFBD> min
|
||||
* \param user Objet user de l'utilisateur qui modifie
|
||||
* \param price_base_type HT or TTC
|
||||
* \param fourn Supplier
|
||||
@ -255,7 +255,7 @@ class ProductFournisseur extends Product
|
||||
$error=0;
|
||||
$this->db->begin();
|
||||
|
||||
// Supprime prix courant du fournisseur pour cette quantité
|
||||
// Supprime prix courant du fournisseur pour cette quantit<EFBFBD>
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price ";
|
||||
if ($this->product_fourn_price_id)
|
||||
{
|
||||
@ -275,7 +275,7 @@ class ProductFournisseur extends Product
|
||||
}
|
||||
$unitBuyPrice = price2num($buyprice/$qty,'MU');
|
||||
|
||||
// Ajoute prix courant du fournisseur pour cette quantité
|
||||
// Ajoute prix courant du fournisseur pour cette quantit<EFBFBD>
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price";
|
||||
$sql.= " SET datec = ".$this->db->idate(mktime());
|
||||
$sql.= " ,fk_product_fournisseur = ".$this->product_fourn_id;
|
||||
@ -328,18 +328,18 @@ class ProductFournisseur extends Product
|
||||
|
||||
|
||||
/**
|
||||
\brief Modifie le prix d'achat pour un fournisseur par la référecne du produit chez le fournisseur
|
||||
\brief Modifie le prix d'achat pour un fournisseur par la r<EFBFBD>f<EFBFBD>recne du produit chez le fournisseur
|
||||
\param id_fourn Id du fournisseur
|
||||
\param product_fourn_ref Ref du produit chez le fournisseur
|
||||
\param qty Quantite pour lequel le prix est valide
|
||||
\param buyprice Prix d'achat pour la quantité
|
||||
\param buyprice Prix d'achat pour la quantit<EFBFBD>
|
||||
\param user Objet user de l'utilisateur qui modifie
|
||||
\return int <0 si KO, >0 si OK
|
||||
*/
|
||||
function UpdateBuyPriceByFournRef($id_fourn, $product_fourn_ref, $qty, $buyprice, $user, $price_base_type='HT')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
|
||||
$result=0;
|
||||
|
||||
// Recherche id produit pour cette ref et fournisseur
|
||||
@ -353,7 +353,7 @@ class ProductFournisseur extends Product
|
||||
{
|
||||
if ($obj = $this->db->fetch_object($resql))
|
||||
{
|
||||
// Met a jour prix pour la qté
|
||||
// Met a jour prix pour la qt<EFBFBD>
|
||||
$this->id = $obj->fk_product;
|
||||
$result = $this->update_buyprice($id_fourn, $qty, $buyprice, $user, $price_base_type);
|
||||
}
|
||||
@ -364,14 +364,17 @@ class ProductFournisseur extends Product
|
||||
|
||||
|
||||
/**
|
||||
* \brief Charge les informations relatives à un fournisseur
|
||||
* \brief Charge les informations relatives a un fournisseur
|
||||
* \param fournid id du fournisseur
|
||||
* \return int < 0 si erreur, > 0 si ok
|
||||
*/
|
||||
function fetch_fourn_data($fournid)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
|
||||
// Check parameters
|
||||
if (empty($fournid)) return -1;
|
||||
|
||||
$sql = "SELECT rowid, ref_fourn";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur ";
|
||||
$sql.= " WHERE fk_product = ".$this->id;
|
||||
@ -390,13 +393,13 @@ class ProductFournisseur extends Product
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("Product::fetch_fourn_data error=".$this->error, LOG_ERR);
|
||||
dol_syslog("ProductFournisseur::fetch_fourn_data error=".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Charge les informations relatives à un prix de fournisseur
|
||||
* \brief Charge les informations relatives <EFBFBD> un prix de fournisseur
|
||||
* \param rowid id ligne
|
||||
* \return int < 0 if KO, 0 if OK but not found, > 0 if OK
|
||||
*/
|
||||
@ -409,7 +412,7 @@ class ProductFournisseur extends Product
|
||||
$sql.= " WHERE pfp.rowid = ".$rowid;
|
||||
$sql.= " AND pf.rowid = pfp.fk_product_fournisseur";
|
||||
|
||||
dol_syslog("Product::fetch_product_fournisseur_price sql=".$sql, LOG_DEBUG);
|
||||
dol_syslog("ProductFournisseur::fetch_product_fournisseur_price sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql) ;
|
||||
if ($resql)
|
||||
{
|
||||
@ -434,7 +437,7 @@ class ProductFournisseur extends Product
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("Product::fetch_product_fournisseur_price error=".$this->error, LOG_ERR);
|
||||
dol_syslog("ProductFournisseur::fetch_product_fournisseur_price error=".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ IdWarehouse=Id warehouse
|
||||
DescWareHouse=Description warehouse
|
||||
LieuWareHouse=Localisation warehouse
|
||||
WarehousesAndProducts=Warehouses and products
|
||||
AverageUnitPricePMP=Average price
|
||||
EstimatedStockValueForProduct=Estimated value for product's stock
|
||||
EstimatedStockValueInWarehouse=Estimated value in warehouse
|
||||
EstimatedStockValue=Estimated value in stock
|
||||
AverageUnitPricePMPShort=Average input price
|
||||
AverageUnitPricePMP=Average input price
|
||||
EstimatedStockValueShort=Estimated value of stock
|
||||
EstimatedStockValue=Estimated value of stock
|
||||
@ -63,7 +63,7 @@ IdWarehouse=Id entrepôt
|
||||
DescWareHouse=Description entrepôt
|
||||
LieuWareHouse=Lieu entrepôt
|
||||
WarehousesAndProducts=Entrepôts et produits
|
||||
AverageUnitPricePMP=Prix moyen pondéré (PMP)
|
||||
EstimatedStockValueForProduct=Valeur estimée du produit en stock
|
||||
EstimatedStockValueInWarehouse=Valeur estimée dans l'entrepot
|
||||
EstimatedStockValue=Valeur estimée du stock
|
||||
AverageUnitPricePMPShort=Prix moyen pondéré (PMP)
|
||||
AverageUnitPricePMP=Prix moyen pondéré (PMP) d'aquisition
|
||||
EstimatedStockValueShort=Valorisation (PMP)
|
||||
EstimatedStockValue=Valorisation aquisition stock (PMP)
|
||||
@ -1651,6 +1651,7 @@ class Product extends CommonObject
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||
$sql.= " WHERE fk_product = ".$this->id." AND fk_soc = ".$id_fourn." AND ref_fourn = '".$ref_fourn."'";
|
||||
|
||||
dol_syslog("Product::add_fournisseur sql=".$sql);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
@ -1661,6 +1662,7 @@ class Product extends CommonObject
|
||||
$sql .= " (datec, fk_product, fk_soc, ref_fourn, fk_user_author)";
|
||||
$sql .= " VALUES (".$this->db->idate(mktime()).", ".$this->id.", ".$id_fourn.", '".$ref_fourn."', ".$user->id.")";
|
||||
|
||||
dol_syslog("Product::add_fournisseur sql=".$sql);
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
$this->product_fourn_id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_fournisseur");
|
||||
@ -1668,7 +1670,8 @@ class Product extends CommonObject
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("Product::add_fournisseur ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -1689,7 +1692,7 @@ class Product extends CommonObject
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
$this->error=$this->db->lasterror();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,9 +178,9 @@ if ($_GET["id"] || $_GET["ref"])
|
||||
if ($_GET["action"] <> 're-edit')
|
||||
{
|
||||
$product = new ProductFournisseur($db);
|
||||
if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]);
|
||||
if ($_GET["id"]) $result = $product->fetch($_GET["id"]);
|
||||
$product->fetch_fourn_data($_GET["socid"]);
|
||||
$result = $product->fetch($_GET["id"],$_GET["ref"]);
|
||||
$result = $product->fetch_fourn_data($_REQUEST["id_fourn"]);
|
||||
//print 'eeeee'.$_GET["socid"];exit;
|
||||
llxHeader("","",$langs->trans("CardProduct".$product->type));
|
||||
}
|
||||
|
||||
|
||||
@ -92,7 +92,7 @@ if ($_GET["id"])
|
||||
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
|
||||
print $form->showrefnav($entrepot,'id','',1,'rowid','libelle');
|
||||
print '</td>';
|
||||
|
||||
|
||||
print '<tr><td>'.$langs->trans("LocationSummary").'</td><td colspan="3">'.$entrepot->lieu.'</td></tr>';
|
||||
|
||||
// Description
|
||||
@ -127,24 +127,31 @@ if ($_GET["id"])
|
||||
|
||||
print "<div class=\"graph\">\n";
|
||||
$year = strftime("%Y",time());
|
||||
|
||||
|
||||
$file=DOL_DATA_ROOT.'/entrepot/temp/entrepot-'.$entrepot->id.'-'.($year).'.png';
|
||||
|
||||
// TODO Build graph in $file from a table called llx_stock_log
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (file_exists($file))
|
||||
{
|
||||
$url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&file=entrepot-'.$entrepot->id.'-'.$year.'.png';
|
||||
print '<img src="'.$url.'" alt="Valorisation du stock année '.($year).'">';
|
||||
|
||||
print '<img src="'.$url.'" alt="Valorisation du stock annee '.($year).'">';
|
||||
|
||||
if (file_exists(DOL_DATA_ROOT.'/entrepot/temp/entrepot-'.$entrepot->id.'-'.($year-1).'.png'))
|
||||
{
|
||||
$url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&file=entrepot-'.$entrepot->id.'-'.($year-1).'.png';
|
||||
print '<br /><img src="'.$url.'" alt="Valorisation du stock année '.($year-1).'">';
|
||||
print '<br /><img src="'.$url.'" alt="Valorisation du stock annee '.($year-1).'">';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs->load("errors");
|
||||
if ($user->admin) print info_admin($langs->trans("WarningBuildScriptNotRunned",'stock-graph.php'));
|
||||
print $langs->trans("FeatureNotYetAvailable");
|
||||
}
|
||||
|
||||
print "</div>";
|
||||
|
||||
@ -326,8 +326,8 @@ else
|
||||
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("Units"),"", "ps.reel","&id=".$_GET['id'],"",'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("AverageUnitPricePMP"),"", "ps.pmp","&id=".$_GET['id'],"",'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("EstimatedStockValueInWarehouse"),"", "","&id=".$_GET['id'],"",'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("AverageUnitPricePMPShort"),"", "ps.pmp","&id=".$_GET['id'],"",'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("EstimatedStockValueShort"),"", "","&id=".$_GET['id'],"",'align="center"',$sortfield,$sortorder);
|
||||
if ($user->rights->stock->mouvement->creer) print '<td> </td>';
|
||||
if ($user->rights->stock->creer) print '<td> </td>';
|
||||
print "</tr>";
|
||||
|
||||
@ -42,7 +42,7 @@ class MouvementStock
|
||||
* \param user User object
|
||||
* \param fk_product Id of product
|
||||
* \param entrepot_id Id of warehouse
|
||||
* \param qty Qty of movement
|
||||
* \param qty Qty of movement (can be <0 or >0)
|
||||
* \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
|
||||
@ -116,18 +116,21 @@ class MouvementStock
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate new PMP. Price should always be >0 or 0. pmp should always be >0 or 0.
|
||||
// Calculate new PMP.
|
||||
if (! $error)
|
||||
{
|
||||
$newpmp=0;
|
||||
$newpmpwarehouse=0;
|
||||
if ($price > 0)
|
||||
// Note: PMP is calculated on stock input only (type = 3). If type == 3, qty should be > 0.
|
||||
// Note: Price should always be >0 or 0. PMP should be always >0 (calculated on input)
|
||||
if ($type == 3 && $price > 0)
|
||||
{
|
||||
if (($oldqty + $qty) == 0) $newpmp=0;
|
||||
else if ($oldpmp > 0) $newpmp=price2num((($oldqty * $oldpmp) + ($qty * $price)) / ($oldqty + $qty), 'MU');
|
||||
$oldqtytouse=($oldqty >= 0?$oldqty:0);
|
||||
// We make a test on oldpmp>0 to avoid to use normal rule on old data with no pmp field defined
|
||||
if ($oldpmp > 0) $newpmp=price2num((($oldqtytouse * $oldpmp) + ($qty * $price)) / ($oldqtytouse + $qty), 'MU');
|
||||
else $newpmp=$price;
|
||||
if (($oldqtywarehouse + $qty) == 0) $newpmpwarehouse=0;
|
||||
else if ($oldpmpwarehouse > 0) $newpmpwarehouse=price2num((($oldqtywarehouse * $oldpmpwarehouse) + ($qty * $price)) / ($oldqtywarehouse + $qty), 'MU');
|
||||
$oldqtywarehousetouse=($oldqtywarehouse >= 0?$oldqty:0);
|
||||
if ($oldpmpwarehouse > 0) $newpmpwarehouse=price2num((($oldqtywarehousetouse * $oldpmpwarehouse) + ($qty * $price)) / ($oldqtywarehousetouse + $qty), 'MU');
|
||||
else $newpmpwarehouse=$price;
|
||||
}
|
||||
else
|
||||
|
||||
@ -351,8 +351,8 @@ print '</div>';
|
||||
print '<br><table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre"><td width="40%">'.$langs->trans("Warehouse").'</td>';
|
||||
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 '<td align="right">'.$langs->trans("AverageUnitPricePMPShort").'</td>';
|
||||
print '<td align="right">'.$langs->trans("EstimatedStockValueShort").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
$sql = "SELECT e.rowid, e.label, ps.reel, ps.pmp";
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2001-2006 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) 2005-2009 Regis Houssin <regis@dolibarr.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -54,8 +54,9 @@ $year = strftime("%Y",time());
|
||||
*/
|
||||
|
||||
// Affichage valorisation par entrepot
|
||||
$sql = "SELECT e.rowid as ref, e.label, e.statut, e.lieu";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e";
|
||||
$sql = "SELECT e.rowid as ref, e.label, e.statut, e.lieu,";
|
||||
$sql.= " SUM(ps.pmp * ps.reel) as estimatedvalue";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."entrepot as e LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON e.rowid = ps.fk_entrepot";
|
||||
$sql.= " WHERE e.entity = ".$conf->entity;
|
||||
if ($sref)
|
||||
{
|
||||
@ -69,6 +70,7 @@ if ($sall)
|
||||
$sql.= " OR e.address LIKE '%".addslashes($sall)."%'";
|
||||
$sql.= " OR e.ville LIKE '%".addslashes($sall)."%')";
|
||||
}
|
||||
$sql.= " GROUP BY e.rowid, e.label, e.statut, e.lieu";
|
||||
$sql.= " ORDER BY $sortfield $sortorder ";
|
||||
$sql.= $db->plimit($limit + 1, $offset);
|
||||
|
||||
@ -87,7 +89,7 @@ if ($result)
|
||||
print "<tr class=\"liste_titre\">";
|
||||
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("PMPValue"),"valo.php", "valo",'','','align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("EstimatedStockValue"),"valo.php", "valo",'','','align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Status"),"valo.php", "e.statut",'','','align="right"',$sortfield,$sortorder);
|
||||
print "</tr>\n";
|
||||
|
||||
@ -103,12 +105,11 @@ if ($result)
|
||||
print '<td><a href="fiche.php?id='.$objp->ref.'">'.img_object($langs->trans("ShowWarehouse"),'stock').' '.$objp->label.'</a></td>';
|
||||
print '<td>'.$objp->lieu.'</td>';
|
||||
print '<td align="right">';
|
||||
// This value is real QTY * PMP of products in llx_product_stock for the warehouse
|
||||
print $langs->trans("FeatureNotYetAvailableShort");
|
||||
print price(price2num($objp->estimatedvalue,'MT'));
|
||||
print '</td>';
|
||||
print '<td align="right">'.$entrepot->LibStatut($objp->statut,5).'</td>';
|
||||
print "</tr>\n";
|
||||
$total += $objp->valo;
|
||||
$total += price2num($objp->estimatedvalue,'MU');
|
||||
$var=!$var;
|
||||
$i++;
|
||||
}
|
||||
@ -129,14 +130,14 @@ if ($result)
|
||||
if (file_exists(DOL_DATA_ROOT.'/entrepot/temp/'.$file))
|
||||
{
|
||||
$url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&file='.$file;
|
||||
print '<img src="'.$url.'" alt="Valorisation du stock année '.($year).'">';
|
||||
print '<img src="'.$url.'" alt="Valorisation du stock ann<EFBFBD>e '.($year).'">';
|
||||
}
|
||||
|
||||
$file='entrepot-'.($year-1).'.png';
|
||||
if (file_exists(DOL_DATA_ROOT.'/entrepot/temp/'.$file))
|
||||
{
|
||||
$url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&file='.$file;
|
||||
print '<br /><img src="'.$url.'" alt="Valorisation du stock année '.($year-1).'">';
|
||||
print '<br /><img src="'.$url.'" alt="Valorisation du stock ann<EFBFBD>e '.($year-1).'">';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,239 +0,0 @@
|
||||
<?PHP
|
||||
/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2007 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
\file scripts/cron/stock-graph.php
|
||||
\ingroup stock
|
||||
\brief Cr<EFBFBD><EFBFBD> le graph de valorisation du stock
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
// Test si mode CLI
|
||||
$sapi_type = php_sapi_name();
|
||||
$script_file=__FILE__;
|
||||
if (eregi('([^\\\/]+)$',$script_file,$reg)) $script_file=$reg[1];
|
||||
|
||||
if (substr($sapi_type, 0, 3) == 'cgi') {
|
||||
echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer $script_file en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
// Recupere env dolibarr
|
||||
$version='$Revision$';
|
||||
$path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]);
|
||||
|
||||
require_once($path."../../htdocs/master.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."//cron/functions_cron.lib.php");
|
||||
|
||||
print '***** '.$script_file.' ('.$version.') *****'."\n";
|
||||
print '--- start'."\n";
|
||||
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
|
||||
$error=0;
|
||||
|
||||
$verbose = 0;
|
||||
for ($i = 1 ; $i < sizeof($argv) ; $i++)
|
||||
{
|
||||
if ($argv[$i] == "-v")
|
||||
{
|
||||
$verbose = 1;
|
||||
}
|
||||
if ($argv[$i] == "-vv")
|
||||
{
|
||||
$verbose = 2;
|
||||
}
|
||||
if ($argv[$i] == "-vvv")
|
||||
{
|
||||
$verbose = 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$dir = $conf->stock->dir_temp;
|
||||
$result=create_exdir($dir);
|
||||
|
||||
|
||||
$sql = "SELECT distinct(fk_entrepot)";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."entrepot_valorisation";
|
||||
|
||||
$resql = $db->query($sql) ;
|
||||
$entrepots = array();
|
||||
if ($resql)
|
||||
{
|
||||
$i = 0;
|
||||
while ($row = $db->fetch_row($resql))
|
||||
{
|
||||
$entrepots[$row[0]] = $row[0];
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db,$sql);
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$year = strftime('%Y',$now);
|
||||
$day = strftime('%j', $now);
|
||||
for ($i = 0 ; $i < strftime('%j',$now) ; $i++)
|
||||
{
|
||||
foreach ($entrepots as $key => $ent)
|
||||
{
|
||||
$values[$key][$i] = 0;
|
||||
}
|
||||
$values[0][$i] = 0;
|
||||
$legends[$i] = strftime('%b',dol_mktime(12,0,0,1,1,2006) + ($i * 3600 * 24));
|
||||
//print $legends[$i].strftime('%j',$now);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read values
|
||||
*/
|
||||
$sql = "SELECT date_format(date_calcul,'%j'), valo_pmp, fk_entrepot";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."entrepot_valorisation as e";
|
||||
$sql .= " WHERE date_format(date_calcul, '%Y') = '".$year."'";
|
||||
$sql .= " ORDER BY date_calcul ASC";
|
||||
|
||||
$resql = $db->query($sql) ;
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
$i = 0;
|
||||
$last_day = 0;
|
||||
while ($row = $db->fetch_row($resql))
|
||||
{
|
||||
if ($last_day > 0)
|
||||
{
|
||||
for ($j = $last_day + 1 ; $j < $row[0] ; $j++)
|
||||
{
|
||||
foreach ($entrepots as $key => $ent)
|
||||
{
|
||||
$values[$key][$j] = $values[$key][$last_day];
|
||||
}
|
||||
$values[0][$j] = $values[0][$last_day];
|
||||
}
|
||||
}
|
||||
$last_day = $row[0];
|
||||
|
||||
$max_day = $row[0];
|
||||
$values[$row[2]][$row[0]] = $row[1];
|
||||
$values[0][$row[0]] += $row[1];
|
||||
|
||||
$total[$row[2]] += abs($row[1]);
|
||||
$total[0] += abs($row[1]);
|
||||
$i++;
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db,$sql);
|
||||
}
|
||||
|
||||
for ($i = $max_day + 1 ; $i < ($day + 1) ; $i++)
|
||||
{
|
||||
foreach ($entrepots as $key => $ent)
|
||||
{
|
||||
$values[$key][$i] = $values[$key][$max_day];
|
||||
}
|
||||
$values[0][$i] = $values[0][$max_day];
|
||||
}
|
||||
|
||||
|
||||
// PMP = (quantit<69>s en stock x pmp ancien + nouvelles quantit<69>s x prix d'acquisition)/ (anciennes quantit<69>s + nouvelles quantit<69>s)
|
||||
|
||||
/*
|
||||
* For each warehouse
|
||||
*/
|
||||
foreach ($entrepots as $key => $ent)
|
||||
{
|
||||
$file = $dir ."/entrepot-".$key."-".$year.".png";
|
||||
$title = "Valorisation PMP du stock de l'entrep<65>t (euros HT) sur l'ann<6E>e ".$year;
|
||||
|
||||
if ($total[$key] > 0)
|
||||
graph_datas($file, $title, $values[$key], $legends);
|
||||
|
||||
if ($verbose)
|
||||
print "$file\n";
|
||||
}
|
||||
|
||||
/*
|
||||
* For all warehouses
|
||||
*/
|
||||
$file = $dir."/entrepot-".$year.".png";
|
||||
$title = "Valorisation PMP (Prix Moyen Pond<6E>r<EFBFBD>) du stock global (euros HT) sur l'ann<6E>e ".$year;
|
||||
|
||||
if ($total[$key] > 0)
|
||||
graph_datas($file, $title, $values[0], $legends);
|
||||
|
||||
if ($verbose)
|
||||
print "$file\n";
|
||||
|
||||
|
||||
|
||||
/** \brief Build graph
|
||||
* \param file File
|
||||
* \param title Title
|
||||
* \param values Value
|
||||
* \param legends Legend
|
||||
*/
|
||||
function graph_datas($file, $title, $values, $legends)
|
||||
{
|
||||
$width=800;
|
||||
$height=230;
|
||||
|
||||
print "Build graph ".$file."\n";
|
||||
|
||||
$newvalues=array();
|
||||
foreach ($values as $abs=>$ord)
|
||||
{
|
||||
$newvalues[]=array($legends[$abs],$ord);
|
||||
}
|
||||
|
||||
$px = new DolGraph();
|
||||
$px->SetData($newvalues);
|
||||
//$px->SetLegend('');
|
||||
$px->SetMaxValue($px->GetCeilMaxValue());
|
||||
$px->SetMinValue($px->GetFloorMinValue());
|
||||
$px->SetTitle($title);
|
||||
$px->SetWidth($width);
|
||||
$px->SetHeight($height);
|
||||
$px->SetType('lines');
|
||||
$px->setBgColor('default');
|
||||
$px->setBgColorGrid(array(255,255,255));
|
||||
$px->SetHideXGrid(true);
|
||||
$px->SetLabelInterval(31);
|
||||
$px->draw($file);
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
print '--- end ok'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '--- end error code='.$error."\n";
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user