Fix: Stock management debug

This commit is contained in:
Laurent Destailleur 2008-05-26 21:27:50 +00:00
parent 3691acd09a
commit b728c133fb
7 changed files with 848 additions and 833 deletions

View File

@ -464,7 +464,7 @@ if ($_GET["id"] > 0)
print "</td></tr></table>"; print "</td></tr></table>";
print '<br>';
show_list_sending_receive('commande',$commande->id); show_list_sending_receive('commande',$commande->id);

View File

@ -301,7 +301,7 @@ class Expedition extends CommonObject
require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php"; require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php";
dolibarr_syslog("expedition.class.php::valid"); dolibarr_syslog("Expedition::valid");
$this->db->begin(); $this->db->begin();
@ -321,6 +321,8 @@ class Expedition extends CommonObject
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
if ($num > 0) if ($num > 0)
{ {
dolibarr_syslog("Expedition::valid already validated", LOG_WARNING);
$this->db->rollback();
return 0; return 0;
} }
} }
@ -329,20 +331,21 @@ class Expedition extends CommonObject
$sql.= " SET ref='".$this->ref."', fk_statut = 1, date_valid = now(), fk_user_valid = ".$user->id; $sql.= " SET ref='".$this->ref."', fk_statut = 1, date_valid = now(), fk_user_valid = ".$user->id;
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
if ($this->db->query($sql) ) dolibarr_syslog("Expedition::valid update expedition sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{ {
// Si module stock géré et que expedition faite depuis un entrepot // If stock increment is done on sending (recommanded choice)
if ($conf->stock->enabled && $this->entrepot_id && $conf->global->STOCK_CALCULATE_ON_SHIPMENT == 1) if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT)
{ {
/* /*
* Enregistrement d'un mouvement de stock pour chaque produit de l'expedition * Enregistrement d'un mouvement de stock pour chaque produit de l'expedition
*/ */
dolibarr_syslog("expedition.class.php::valid enregistrement des mouvements"); $sql = "SELECT cd.fk_product, ed.qty, ed.fk_entrepot";
$sql = "SELECT cd.fk_product, ed.qty ";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."expeditiondet as ed"; $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."expeditiondet as ed";
$sql.= " WHERE ed.fk_expedition = $this->id AND cd.rowid = ed.fk_commande_ligne"; $sql.= " WHERE ed.fk_expedition = $this->id AND cd.rowid = ed.fk_origin_line";
dolibarr_syslog("Expedition::valid select details sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -350,17 +353,17 @@ class Expedition extends CommonObject
$i=0; $i=0;
while($i < $num) while($i < $num)
{ {
dolibarr_syslog("expedition.class.php::valid movment $i"); dolibarr_syslog("Expedition::valid movment nb ".$i);
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$mouvS = new MouvementStock($this->db); $mouvS = new MouvementStock($this->db);
$result=$mouvS->livraison($user, $obj->fk_product, $this->entrepot_id, $obj->qty); $result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty);
if ($result < 0) if ($result < 0)
{ {
$this->db->rollback(); $this->db->rollback();
$this->error=$this->db->error()." - sql=$sql"; $this->error=$this->db->error()." - sql=$sql";
dolibarr_syslog("expedition.class.php::valid ".$this->error); dolibarr_syslog("Expedition::valid ".$this->error);
return -3; return -3;
} }
@ -372,7 +375,7 @@ class Expedition extends CommonObject
{ {
$this->db->rollback(); $this->db->rollback();
$this->error=$this->db->error()." - sql=$sql"; $this->error=$this->db->error()." - sql=$sql";
dolibarr_syslog("expedition.class.php::valid ".$this->error); dolibarr_syslog("Expedition::valid ".$this->error);
return -2; return -2;
} }
} }
@ -388,7 +391,6 @@ class Expedition extends CommonObject
if (!dol_delete_file($file)) if (!dol_delete_file($file))
{ {
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file); $this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
return 0;
} }
} }
if (file_exists($dir)) if (file_exists($dir))
@ -396,7 +398,6 @@ class Expedition extends CommonObject
if (!dol_delete_dir($dir)) if (!dol_delete_dir($dir))
{ {
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir); $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
return 0;
} }
} }
} }
@ -405,15 +406,16 @@ class Expedition extends CommonObject
else else
{ {
$this->db->rollback(); $this->db->rollback();
$this->error=$this->db->error()." - sql=$sql"; $this->error=$this->db->error();
dolibarr_syslog("expedition.class.php::valid ".$this->error); dolibarr_syslog("Expedition::valid ".$this->error);
return -1; return -1;
} }
} }
else else
{ {
$this->db->rollback();
$this->error="Non autorise"; $this->error="Non autorise";
dolibarr_syslog("expedition.class.php::valid ".$this->error); dolibarr_syslog("Expedition::valid ".$this->error);
return -1; return -1;
} }

View File

@ -113,6 +113,7 @@ else
// Check if GD installed // Check if GD installed
if (! function_exists("imagecreate")) if (! function_exists("imagecreate"))
{ {
$langs->load("errors");
print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportGD")."<br>\n"; print '<img src="../theme/eldy/img/warning.png" alt="Error"> '.$langs->trans("ErrorPHPDoesNotSupportGD")."<br>\n";
// $checksok=0; // If image ko, just warning. So check must still be 1 (otherwise no way to install) // $checksok=0; // If image ko, just warning. So check must still be 1 (otherwise no way to install)
} }

View File

@ -38,9 +38,10 @@ 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
OrderDispatch=Order dispatching OrderDispatch=Order dispatching
DeStockReStockOnBill=Decrease/increase stocks on invoices/credit notes DeStockReStockOnBill=Decrease/increase real stocks on invoices/credit notes
DeStockReStockOnValidateOrder=Decrease/increase stocks on orders notes DeStockReStockOnValidateOrder=Decrease/increase real stocks on orders notes
DeStockReStockOnShipment=Decrease/increase stocks on shipment DeStockReStockOnShipment=Decrease/increase real stocks on shipment
StockDiffPhysicTeoric=Reason for difference stock physical and theorical
StockLimitShort=Limit StockLimitShort=Limit
StockLimit=Stock limit for alerts StockLimit=Stock limit for alerts
PhysicalStock=Physical stock PhysicalStock=Physical stock

View File

@ -38,9 +38,10 @@ EnhancedValueOfWarehouses=Valorisation des stocks
UserWarehouseAutoCreate=Créer un stock automatiquement à la création d'un utilisateur UserWarehouseAutoCreate=Créer un stock automatiquement à la création d'un utilisateur
QtyDispatched=Quantité ventilée QtyDispatched=Quantité ventilée
OrderDispatch=Ventilation commande OrderDispatch=Ventilation commande
DeStockReStockOnBill=Décrémente/Incrémente les stocks sur les factures/avoirs DeStockReStockOnBill=Décrémente/Incrémente les stocks réels sur les factures/avoirs
DeStockReStockOnValidateOrder=Décrémente/Incrémente les stocks sur les commandes DeStockReStockOnValidateOrder=Décrémente/Incrémente les stocks réels sur les commandes
DeStockReStockOnShipment=Décrémente/Incrémente les stocks sur les expéditions DeStockReStockOnShipment=Décrémente/Incrémente les stocks réels sur les expéditions
StockDiffPhysicTeoric=Raison écart stock physique-théorique
StockLimitShort=Seuil StockLimitShort=Seuil
StockLimit=Seuil alerte stock StockLimit=Seuil alerte stock
PhysicalStock=Stock physique PhysicalStock=Stock physique

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -16,15 +16,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/ */
/** /**
\file htdocs/product/liste.php \file htdocs/product/reassort.php
\ingroup produit \ingroup produit
\brief Page liste des produits ou services \brief Page liste des produits ou services
\version $Revision$ \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
@ -181,13 +179,18 @@ if ($resql)
print "</div><br />"; print "</div><br />";
} }
print '<form action="reassort.php" method="post" name="formulaire">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="type" value="'.$type.'">';
print '<table class="liste" width="100%">'; print '<table class="liste" width="100%">';
// Lignes des titres // Lignes des titres
print "<tr class=\"liste_titre\">"; print "<tr class=\"liste_titre\">";
print_liste_field_titre($langs->trans("Ref"),"reassort.php", "p.ref","&amp;envente=$envente".(isset($type)?"&amp;type=$type":"")."&fourn_id=$fourn_id&amp;snom=$snom&amp;sref=$sref","","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Ref"),"reassort.php", "p.ref","&amp;envente=$envente".(isset($type)?"&amp;type=$type":"")."&fourn_id=$fourn_id&amp;snom=$snom&amp;sref=$sref","","",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Label"),"reassort.php", "p.label","&envente=$envente&".(isset($type)?"&amp;type=$type":"")."&fourn_id=$fourn_id&amp;snom=$snom&amp;sref=$sref","","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Label"),"reassort.php", "p.label","&envente=$envente&".(isset($type)?"&amp;type=$type":"")."&fourn_id=$fourn_id&amp;snom=$snom&amp;sref=$sref","","",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("TheoreticalStock"),"reassort.php", "stock_theorique","&envente=$envente&".(isset($type)?"&amp;type=$type":"")."&fourn_id=$fourn_id&amp;snom=$snom&amp;sref=$sref","",'align="right"',$sortfield,$sortorder); //print_liste_field_titre($langs->trans("TheoreticalStock"),"reassort.php", "stock_theorique","&envente=$envente&".(isset($type)?"&amp;type=$type":"")."&fourn_id=$fourn_id&amp;snom=$snom&amp;sref=$sref","",'align="right"',$sortfield,$sortorder);
if ($conf->service->enabled && $type == 1) print_liste_field_titre($langs->trans("Duration"),"reassort.php", "p.duration","&envente=$envente&".(isset($type)?"&amp;type=$type":"")."&fourn_id=$fourn_id&amp;snom=$snom&amp;sref=$sref","",'align="center"',$sortfield,$sortorder); if ($conf->service->enabled && $type == 1) print_liste_field_titre($langs->trans("Duration"),"reassort.php", "p.duration","&envente=$envente&".(isset($type)?"&amp;type=$type":"")."&fourn_id=$fourn_id&amp;snom=$snom&amp;sref=$sref","",'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("PhysicalStock"),"reassort.php", "stock_physique","&envente=$envente&".(isset($type)?"&amp;type=$type":"")."&fourn_id=$fourn_id&amp;snom=$snom&amp;sref=$sref","",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("PhysicalStock"),"reassort.php", "stock_physique","&envente=$envente&".(isset($type)?"&amp;type=$type":"")."&fourn_id=$fourn_id&amp;snom=$snom&amp;sref=$sref","",'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("MininumStock"),"reassort.php", "p.seuil_stock_alerte","&envente=$envente&".(isset($type)?"&amp;type=$type":"")."&fourn_id=$fourn_id&amp;snom=$snom&amp;sref=$sref","",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("MininumStock"),"reassort.php", "p.seuil_stock_alerte","&envente=$envente&".(isset($type)?"&amp;type=$type":"")."&fourn_id=$fourn_id&amp;snom=$snom&amp;sref=$sref","",'align="right"',$sortfield,$sortorder);
@ -195,10 +198,6 @@ if ($resql)
print "</tr>\n"; print "</tr>\n";
// Lignes des champs de filtre // Lignes des champs de filtre
print '<form action="reassort.php" method="post" name="formulaire">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="type" value="'.$type.'">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td class="liste_titre">'; print '<td class="liste_titre">';
print '<input class="flat" type="text" name="sref" value="'.$sref.'">'; print '<input class="flat" type="text" name="sref" value="'.$sref.'">';
@ -212,7 +211,7 @@ if ($resql)
print '&nbsp;'; print '&nbsp;';
print '</td>'; print '</td>';
} }
print '<td class="liste_titre" colspan="3">'; print '<td class="liste_titre" colspan="2">';
print '&nbsp;'; print '&nbsp;';
print '</td>'; print '</td>';
print '<td class="liste_titre" align="right">'; print '<td class="liste_titre" align="right">';
@ -220,7 +219,6 @@ if ($resql)
print '<input type="image" class="liste_titre" name="button_removefilter" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/searchclear.png" alt="'.$langs->trans("RemoveFilter").'">'; print '<input type="image" class="liste_titre" name="button_removefilter" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/searchclear.png" alt="'.$langs->trans("RemoveFilter").'">';
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
print '</form>';
$product_static=new Product($db); $product_static=new Product($db);
@ -245,21 +243,12 @@ if ($resql)
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td nowrap="nowrap">'; print '<tr '.$bc[$var].'><td nowrap="nowrap">';
print "<a href=\"fiche.php?id=$objp->rowid\">"; $product_static->ref=$objp->ref;
if ($objp->fk_product_type==1) $product_static->id=$objp->rowid;
{ $product_static->type=$objp->fk_product_type;
print img_object($langs->trans("ShowService"),"service"); print $product_static->getNomUrl(1,'',16);
} //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow"));
else print '</td>';
{
if ( $objp->stock_theorique > $objp->seuil_stock_alerte) {
print img_object($langs->trans("ShowProduct"),"product");
} else {
print img_warning($langs->trans("StockTooLow"));
}
}
print '</a> ';
print '<a href="fiche.php?id='.$objp->rowid.'">'.$objp->ref.'</a></td>';
print '<td>'.$objp->label.'</td>'; print '<td>'.$objp->label.'</td>';
if ($conf->service->enabled && $type == 1) if ($conf->service->enabled && $type == 1)
@ -271,7 +260,7 @@ if ($resql)
else print $objp->duration; else print $objp->duration;
print '</td>'; print '</td>';
} }
print '<td align="right">'.$objp->stock_theorique.'</td>'; //print '<td align="right">'.$objp->stock_theorique.'</td>';
print '<td align="right">'.$objp->stock_physique.'</td>'; print '<td align="right">'.$objp->stock_physique.'</td>';
print '<td align="right">'.$objp->seuil_stock_alerte.'</td>'; print '<td align="right">'.$objp->seuil_stock_alerte.'</td>';
print '<td align="right" nowrap="nowrap">'.$product_static->LibStatut($objp->statut,5).'</td>'; print '<td align="right" nowrap="nowrap">'.$product_static->LibStatut($objp->statut,5).'</td>';
@ -279,6 +268,9 @@ if ($resql)
$i++; $i++;
} }
print "</table>";
print '</form>';
if ($num > $conf->liste_limit) if ($num > $conf->liste_limit)
{ {
if ($sref || $snom || $sall || $_POST["search"]) if ($sref || $snom || $sall || $_POST["search"])
@ -293,8 +285,6 @@ if ($resql)
$db->free($resql); $db->free($resql);
print "</table>";
} }
else else
{ {

View File

@ -142,55 +142,75 @@ if ($_GET["id"] || $_GET["ref"])
print $product->getLibStatut(2); print $product->getLibStatut(2);
print '</td></tr>'; print '</td></tr>';
// Stock // Stock physique
print '<tr><td>'.$langs->trans("StockLimit").'</td>';
print '<td>'.$product->seuil_stock_alerte.'</td>';
print '</tr>';
// Stock
print '<tr><td>'.$langs->trans("PhysicalStock").'</td>'; print '<tr><td>'.$langs->trans("PhysicalStock").'</td>';
if ($product->stock_reel < $product->seuil_stock_alerte) print '<td>'.$product->stock_reel.'</td>';
{
print '<td>'.$product->stock_reel.' '.img_warning().'</td>';
}
else
{
print "<td>".$product->stock_reel.'</td>';
}
print '</tr>'; print '</tr>';
// Stock
print '<tr><td>'.$langs->trans("VirtualStock").'</td>';
print "<td>".$langs->trans("FeatureNotYetAvailable").'</td>';
print '</tr>';
// Nbre de commande clients en cours // Calculating a theorical value of stock if stock increment is done on order
if ($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER)
{
$stock_commande_client=$stock_commande_fournisseur=0;
if ($conf->commande->enabled) if ($conf->commande->enabled)
{ {
$result=$product->load_stats_commande(0,'2'); $result=$product->load_stats_commande(0,'2');
if ($result < 0) dolibarr_print_error($db,$product->error); if ($result < 0) dolibarr_print_error($db,$product->error);
print '<tr><td>'.$langs->trans("CustomersOrdersRunning").'</td>'; $stock_commande_client=$product->stats_commande['qty'];
}
if ($conf->fournisseur->enabled)
{
$result=$product->load_stats_commande_fournisseur(0,'3');
if ($result < 0) dolibarr_print_error($db,$product->error);
$stock_commande_fournisseur=$product->stats_commande_fournisseur['qty'];
}
$product->stock_theorique=$product->stock_reel-$stock_commande_client+$stock_commande_fournisseur;
// Stock theorique
print '<tr><td>'.$langs->trans("VirtualStock").'</td>';
print "<td>".$product->stock_theorique;
if ($product->stock_theorique < $product->seuil_stock_alerte)
{
print ' '.img_warning($langs->trans("StockTooLow"));
}
print '</td>';
print '</tr>';
if ($product->stock_theorique != $product->stock_reel)
{
print '<tr><td>'.$langs->trans("StockDiffPhysicTeoric").'</td>';
print '<td>'; print '<td>';
print $product->stats_commande['qty']; $found=0;
// Nbre de commande clients en cours
if ($conf->commande->enabled)
{
if ($found) print '<br>'; else $found=1;
print $langs->trans("CustomersOrdersRunning").': '.$stock_commande_client;
$result=$product->load_stats_commande(0,'0,1'); $result=$product->load_stats_commande(0,'0,1');
if ($result < 0) dolibarr_print_error($db,$product->error); if ($result < 0) dolibarr_print_error($db,$product->error);
print ' ('.$langs->trans("DraftOrWaitingShipped").': '.$product->stats_commande['qty'].')'; print ' ('.$langs->trans("DraftOrWaitingShipped").': '.$product->stats_commande['qty'].')';
print '</td></tr>';
} }
// Nbre de commande fournisseurs en cours // Nbre de commande fournisseurs en cours
if ($conf->fournisseur->enabled) if ($conf->fournisseur->enabled)
{ {
$result=$product->load_stats_commande_fournisseur(0,'3'); if ($found) print '<br>'; else $found=1;
if ($result < 0) dolibarr_print_error($db,$product->error); print $langs->trans("SuppliersOrdersRunning").': '.$stock_commande_fournisseur;
print '<tr><td>'.$langs->trans("SuppliersOrdersRunning").'</td>';
print '<td>';
print $product->stats_commande_fournisseur['qty'];
$result=$product->load_stats_commande_fournisseur(0,'0,1,2'); $result=$product->load_stats_commande_fournisseur(0,'0,1,2');
if ($result < 0) dolibarr_print_error($db,$product->error); if ($result < 0) dolibarr_print_error($db,$product->error);
print ' ('.$langs->trans("DraftOrWaitingApproved").': '.$product->stats_commande_fournisseur['qty'].')'; print ' ('.$langs->trans("DraftOrWaitingApproved").': '.$product->stats_commande_fournisseur['qty'].')';
}
print '</td></tr>'; print '</td></tr>';
} }
}
// Stock
print '<tr><td>'.$langs->trans("StockLimit").'</td>';
print '<td>'.$product->seuil_stock_alerte.'</td>';
print '</tr>';
print "</table>"; print "</table>";