New: Quelques améliorations sur la gestion des stocks.

This commit is contained in:
Laurent Destailleur 2008-03-31 05:56:45 +00:00
parent e4ac9de490
commit 10dfe57420
7 changed files with 222 additions and 184 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003 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) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org> * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be> * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* *
@ -17,13 +17,12 @@
* 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$
*/ */
/** /**
\defgroup produit Module produit \defgroup produit Module produit
\brief Module pour g<EFBFBD>rer le suivi de produits pr<EFBFBD>d<EFBFBD>finis \brief Module pour gerer le suivi de produits predefinis
\version $Id$
*/ */
/** /**

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-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>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -15,13 +15,12 @@
* 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$
*/ */
/** /**
\defgroup stock Module stock \defgroup stock Module stock
\brief Module pour g<EFBFBD>rer la tenue de stocks produits \brief Module pour gerer la tenue de stocks produits
\version $Id$
*/ */
/** /**
@ -88,7 +87,7 @@ class modStock extends DolibarrModules
$this->rights[0][5] = ''; $this->rights[0][5] = '';
$this->rights[1][0] = 1002; $this->rights[1][0] = 1002;
$this->rights[1][1] = 'Cr<EFBFBD>er/Modifier les stocks'; $this->rights[1][1] = 'Creer/Modifier les stocks';
$this->rights[1][2] = 'w'; $this->rights[1][2] = 'w';
$this->rights[1][3] = 0; $this->rights[1][3] = 0;
$this->rights[1][4] = 'creer'; $this->rights[1][4] = 'creer';
@ -109,17 +108,31 @@ class modStock extends DolibarrModules
$this->rights[3][5] = 'lire'; $this->rights[3][5] = 'lire';
$this->rights[4][0] = 1005; $this->rights[4][0] = 1005;
$this->rights[4][1] = 'Cr<EFBFBD>er/modifier mouvements de stocks'; $this->rights[4][1] = 'Creer/modifier mouvements de stocks';
$this->rights[4][2] = 'w'; $this->rights[4][2] = 'w';
$this->rights[4][3] = 0; $this->rights[4][3] = 0;
$this->rights[4][4] = 'mouvement'; $this->rights[4][4] = 'mouvement';
$this->rights[4][5] = 'creer'; $this->rights[4][5] = 'creer';
// Exports
//--------
$r=0;
$r++;
$this->export_code[$r]=$this->rights_class.'_'.$r;
$this->export_label[$r]="ProductsOrServices"; // Translation key (used only if key ExportDataset_xxx_z not found)
$this->export_permission[$r]=array(array("produit","export"));
$this->export_fields_array[$r]=array('p.rowid'=>"Id",'p.ref'=>"Ref",'p.fk_product_type'=>"Type",'p.label'=>"Label",'p.description'=>"Description",'p.note'=>"Note",'p.price'=>"Price",'p.tva_tx'=>'VAT','p.envente'=>"OnSell",'p.duration'=>"Duration",'p.datec'=>'DateCreation','p.tms'=>'DateModification');
$this->export_entities_array[$r]=array('p.rowid'=>"product",'p.ref'=>"product",'p.fk_product_type'=>"product",'p.label'=>"product",'p.description'=>"product",'p.note'=>"product",'p.price'=>"product",'p.tva_tx'=>'product','p.envente'=>"product",'p.duration'=>"product",'p.datec'=>'product','p.tms'=>'product');
$this->export_alias_array[$r]=array('p.rowid'=>"id",'p.ref'=>"ref",'p.fk_product_type'=>"type",'p.label'=>"label",'p.description'=>"description",'p.note'=>"note",'p.price'=>"price",'p.tva_tx'=>'vat','p.envente'=>"onsell",'p.duration'=>"duration",'p.datec'=>'datecreation','p.tms'=>'datemodification');
$this->export_sql_start[$r]='SELECT DISTINCT ';
$this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p';
} }
/** /**
* \brief Fonction appel<EFBFBD>e lors de l'activation du module. Ins<EFBFBD>re en base les constantes, boites, permissions du module. * \brief Fonction appelee lors de l'activation du module. Insere en base les constantes, boites, permissions du module.
* D<EFBFBD>finit <EFBFBD>galement les r<EFBFBD>pertoires de donn<EFBFBD>es <EFBFBD> cr<EFBFBD>er pour ce module. * Definit egalement les repertoires de donnees a creer pour ce module.
*/ */
function init() function init()
{ {

View File

@ -1985,15 +1985,40 @@ class Product extends CommonObject
*/ */
function create_stock($id_entrepot, $nbpiece) function create_stock($id_entrepot, $nbpiece)
{ {
global $user;
$op[0] = "+".trim($nbpiece);
$op[1] = "-".trim($nbpiece);
$mouvement=0; // We add pieces
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_stock "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_stock ";
$sql .= " (fk_product, fk_entrepot, reel)"; $sql .= " (fk_product, fk_entrepot, reel)";
$sql .= " VALUES ($this->id, $id_entrepot, $nbpiece)"; $sql .= " VALUES ($this->id, $id_entrepot, $nbpiece)";
if ($this->db->query($sql) ) dolibarr_syslog("Product::create_stock sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author)";
$sql .= " VALUES (now(), ".$this->id.", ".$id_entrepot.", ".$nbpiece.", 0, ".$user->id.")";
dolibarr_syslog("Product::create_stock sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
$this->db->commit();
return 1; return 1;
} }
else else
{
dolibarr_print_error($this->db);
$this->db->rollback();
return -2;
}
}
else
{ {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
return -1; return -1;
@ -2002,7 +2027,7 @@ class Product extends CommonObject
/** /**
* \brief Ajuste le stock d'un entrep<EFBFBD>t pour le produit <EFBFBD> une valeure donn<EFBFBD>e * \brief Ajuste le stock d'un entrepot pour le produit a une valeure donnee
* \param user utilisateur qui demande l'ajustement * \param user utilisateur qui demande l'ajustement
* \param id_entrepot id de l'entrepot * \param id_entrepot id de l'entrepot
* \param nbpiece nombre de pieces * \param nbpiece nombre de pieces
@ -2012,18 +2037,21 @@ class Product extends CommonObject
{ {
if ($id_entrepot) if ($id_entrepot)
{ {
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."product_stock "; $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."product_stock";
$sql .= " WHERE fk_product = $this->id AND fk_entrepot = $id_entrepot"; $sql .= " WHERE fk_product = ".$this->id." AND fk_entrepot = ".$id_entrepot;
if ($this->db->query($sql) ) $resql=$this->db->query($sql);
if ($resql)
{ {
$row = $this->db->fetch_row(0); $row = $this->db->fetch_object($resql);
if ($row[0] > 0) if ($row->nb > 0)
{ {
// Record already exists, we make an update
return $this->ajust_stock($user, $id_entrepot, $nbpiece, $mouvement); return $this->ajust_stock($user, $id_entrepot, $nbpiece, $mouvement);
} }
else else
{ {
// Record not yet available, we make an insert
return $this->create_stock($id_entrepot, $nbpiece); return $this->create_stock($id_entrepot, $nbpiece);
} }
} }
@ -2048,18 +2076,22 @@ class Product extends CommonObject
$op[0] = "+".trim($nbpiece); $op[0] = "+".trim($nbpiece);
$op[1] = "-".trim($nbpiece); $op[1] = "-".trim($nbpiece);
if ($this->db->begin()) $this->db->begin();
{
$sql = "UPDATE ".MAIN_DB_PREFIX."product_stock"; $sql = "UPDATE ".MAIN_DB_PREFIX."product_stock";
$sql.= " SET reel = reel ".$op[$mouvement]; $sql.= " SET reel = reel ".$op[$mouvement];
$sql .= " WHERE fk_product = $this->id AND fk_entrepot = $id_entrepot"; $sql.= " WHERE fk_product = ".$this->id." AND fk_entrepot = ".$id_entrepot;
if ($this->db->query($sql) ) dolibarr_syslog("Product::ajust_stock sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author)";
$sql .= " VALUES (now(), $this->id, $id_entrepot, ".$op[$mouvement].", 0, $user->id)"; $sql .= " VALUES (now(), ".$this->id.", ".$id_entrepot.", ".$op[$mouvement].", 0, ".$user->id.")";
if ($this->db->query($sql) ) dolibarr_syslog("Product::ajust_stock sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{ {
$this->db->commit(); $this->db->commit();
return 1; return 1;
@ -2078,7 +2110,6 @@ class Product extends CommonObject
return -1; return -1;
} }
} }
}
/** /**
* \brief Augmente ou r<EFBFBD>duit le nombre de piece en commande a expedier * \brief Augmente ou r<EFBFBD>duit le nombre de piece en commande a expedier

View File

@ -16,16 +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$
* $Source$
*/ */
/** /**
\file htdocs/product/stock/entrepot.class.php \file htdocs/product/stock/entrepot.class.php
\ingroup stock \ingroup stock
\brief Fichier de la classe de gestion des entrepots \brief Fichier de la classe de gestion des entrepots
\version $Revision$ \version $Id$
*/ */
@ -71,16 +68,18 @@ class Entrepot
function create($user) function create($user)
{ {
// Si libelle non defini, erreur // Si libelle non defini, erreur
if ($this->libelle == '') { if ($this->libelle == '')
$this->error = "Libellé obligatoire"; {
$this->error = "ErrorFieldRequired";
return 0; return 0;
} }
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."entrepot (datec, fk_user_author)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."entrepot (datec, fk_user_author, label)";
$sql .= " VALUES (now(),".$user->id.")"; $sql .= " VALUES (now(),".$user->id.",'".addslashes($this->libelle)."')";
dolibarr_syslog("Entrepot::create sql=".$sql);
$result=$this->db->query($sql); $result=$this->db->query($sql);
if ($result) if ($result)
{ {
@ -109,10 +108,8 @@ class Entrepot
} }
else else
{ {
$this->error="Failed to insert warehouse"; $this->error=$this->db->error();
dolibarr_syslog("Entrepot::Create return -1"); dolibarr_syslog("Entrepot::Create Error ".$this->db->error());
dolibarr_syslog("Entrepot::Create ".$this->error);
dolibarr_syslog("Entrepot::Create ".$this->db->error());
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }

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-2006 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,16 +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$
* $Source$
*/ */
/** /**
\file htdocs/product/stock/mouvement.php \file htdocs/product/stock/mouvement.php
\ingroup stock \ingroup stock
\brief Page liste des mouvements de stocks \brief Page liste des mouvements de stocks
\version $Revision$ \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
@ -147,14 +144,16 @@ if ($resql)
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
$var=!$var; $var=!$var;
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td>'.dolibarr_print_date($objp->datem).'</td>'; print '<td>'.dolibarr_print_date($objp->datem,'dayhour').'</td>';
print "<td><a href=\"../fiche.php?id=$objp->rowid\">"; print "<td><a href=\"../fiche.php?id=$objp->rowid\">";
print img_object($langs->trans("ShowProduct"),"product").' '.$objp->produit; print img_object($langs->trans("ShowProduct"),"product").' '.$objp->produit;
print "</a></td>\n"; print "</a></td>\n";
print '<td><a href="fiche.php?id='.$objp->entrepot_id.'">'; print '<td><a href="fiche.php?id='.$objp->entrepot_id.'">';
print img_object($langs->trans("ShowWarehouse"),"stock").' '.$objp->stock; print img_object($langs->trans("ShowWarehouse"),"stock").' '.$objp->stock;
print "</a></td>\n"; print "</a></td>\n";
print '<td align="right">'.$objp->value.'</td>'; print '<td align="right">';
if ($objp->value > 0) print '+';
print $objp->value.'</td>';
print "</tr>\n"; print "</tr>\n";
$i++; $i++;
} }

View File

@ -18,16 +18,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$
* $Source$
*/ */
/** /**
\file htdocs/product/stock/product.php \file htdocs/product/stock/product.php
\ingroup product \ingroup product
\brief Page de la fiche stock d'un produit \brief Page de la fiche stock d'un produit
\version $Revision$ \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
@ -45,6 +42,9 @@ if (! $user->rights->produit->lire || ! $product->type == 0 || ! $conf->stock->e
accessforbidden(); accessforbidden();
} }
/**
* Actions
*/
if ($_POST["action"] == "create_stock") if ($_POST["action"] == "create_stock")
{ {
@ -57,7 +57,6 @@ if ($_POST["action"] == "correct_stock" && $_POST["cancel"] <> $langs->trans("Ca
{ {
if (is_numeric($_POST["nbpiece"])) if (is_numeric($_POST["nbpiece"]))
{ {
$product = new Product($db); $product = new Product($db);
$product->id = $_GET["id"]; $product->id = $_GET["id"];
$product->correct_stock($user, $product->correct_stock($user,

View File

@ -90,7 +90,7 @@ if ($result)
{ {
$entrepot=new Entrepot($db); $entrepot=new Entrepot($db);
$total = 0; $total = 0;
$var=True; $var=false;
while ($i < min($num,$limit)) while ($i < min($num,$limit))
{ {
$objp = $db->fetch_object($result); $objp = $db->fetch_object($result);