diff --git a/htdocs/includes/modules/modProduit.class.php b/htdocs/includes/modules/modProduit.class.php index 8c98361e776..fcb0d0e8333 100644 --- a/htdocs/includes/modules/modProduit.class.php +++ b/htdocs/includes/modules/modProduit.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier * @@ -17,13 +17,12 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ */ /** \defgroup produit Module produit - \brief Module pour g�rer le suivi de produits pr�d�finis + \brief Module pour gerer le suivi de produits predefinis + \version $Id$ */ /** diff --git a/htdocs/includes/modules/modStock.class.php b/htdocs/includes/modules/modStock.class.php index 80c5b044e0e..6c89fef454c 100644 --- a/htdocs/includes/modules/modStock.class.php +++ b/htdocs/includes/modules/modStock.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * * 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 @@ -15,13 +15,12 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ */ /** - \defgroup stock Module stock - \brief Module pour g�rer la tenue de stocks produits + \defgroup stock Module stock + \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[1][0] = 1002; - $this->rights[1][1] = 'Cr�er/Modifier les stocks'; + $this->rights[1][1] = 'Creer/Modifier les stocks'; $this->rights[1][2] = 'w'; $this->rights[1][3] = 0; $this->rights[1][4] = 'creer'; @@ -109,17 +108,31 @@ class modStock extends DolibarrModules $this->rights[3][5] = 'lire'; $this->rights[4][0] = 1005; - $this->rights[4][1] = 'Cr�er/modifier mouvements de stocks'; + $this->rights[4][1] = 'Creer/modifier mouvements de stocks'; $this->rights[4][2] = 'w'; $this->rights[4][3] = 0; $this->rights[4][4] = 'mouvement'; $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�e lors de l'activation du module. Ins�re en base les constantes, boites, permissions du module. - * D�finit �galement les r�pertoires de donn�es � cr�er pour ce module. + * \brief Fonction appelee lors de l'activation du module. Insere en base les constantes, boites, permissions du module. + * Definit egalement les repertoires de donnees a creer pour ce module. */ function init() { diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 6f04897529c..41d3b6da3c8 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -1978,107 +1978,138 @@ class Product extends CommonObject return $langs->trans('Unknown'); } - /** - * \brief Entre un nombre de piece du produit en stock dans un entrep�t - * \param id_entrepot id de l'entrepot - * \param nbpiece nombre de pieces - */ - function create_stock($id_entrepot, $nbpiece) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_stock "; - $sql .= " (fk_product, fk_entrepot, reel)"; - $sql .= " VALUES ($this->id, $id_entrepot, $nbpiece)"; - - if ($this->db->query($sql) ) - { - return 1; - } - else - { - dolibarr_print_error($this->db); - return -1; - } - } - - - /** - * \brief Ajuste le stock d'un entrep�t pour le produit � une valeure donn�e - * \param user utilisateur qui demande l'ajustement - * \param id_entrepot id de l'entrepot - * \param nbpiece nombre de pieces - * \param mouvement 0 = ajout, 1 = suppression - */ - function correct_stock($user, $id_entrepot, $nbpiece, $mouvement) - { - if ($id_entrepot) - { - $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."product_stock "; - $sql .= " WHERE fk_product = $this->id AND fk_entrepot = $id_entrepot"; - - if ($this->db->query($sql) ) - { - $row = $this->db->fetch_row(0); - if ($row[0] > 0) - { - return $this->ajust_stock($user, $id_entrepot, $nbpiece, $mouvement); - } - else - { - return $this->create_stock($id_entrepot, $nbpiece); - } - } - else - { - dolibarr_print_error($this->db); - $this->db->rollback(); - return -1; - } - } - } - - /** - * \brief Augmente ou r�duit la valeur de stock pour le produit - * \param user utilisateur qui demande l'ajustement - * \param id_entrepot id de l'entrepot - * \param nbpiece nombre de pieces - * \param mouvement 0 = ajout, 1 = suppression - */ - function ajust_stock($user, $id_entrepot, $nbpiece, $mouvement) - { - $op[0] = "+" . trim($nbpiece); - $op[1] = "-" . trim($nbpiece); - - if ($this->db->begin()) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."product_stock "; - $sql .= " SET reel = reel ".$op[$mouvement]; - $sql .= " WHERE fk_product = $this->id AND fk_entrepot = $id_entrepot"; + /** + * \brief Entre un nombre de piece du produit en stock dans un entrep�t + * \param id_entrepot id de l'entrepot + * \param nbpiece nombre de pieces + */ + function create_stock($id_entrepot, $nbpiece) + { + global $user; + + $op[0] = "+".trim($nbpiece); + $op[1] = "-".trim($nbpiece); + $mouvement=0; // We add pieces + + $this->db->begin(); - if ($this->db->query($sql) ) - { - $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)"; - - if ($this->db->query($sql) ) - { - $this->db->commit(); - return 1; - } - else - { - dolibarr_print_error($this->db); - $this->db->rollback(); - return -2; - } - } - else - { - dolibarr_print_error($this->db); - $this->db->rollback(); - return -1; - } - } - } + $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_stock "; + $sql .= " (fk_product, fk_entrepot, reel)"; + $sql .= " VALUES ($this->id, $id_entrepot, $nbpiece)"; + + 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; + } + else + { + dolibarr_print_error($this->db); + $this->db->rollback(); + return -2; + } + } + else + { + dolibarr_print_error($this->db); + return -1; + } + } + + + /** + * \brief Ajuste le stock d'un entrepot pour le produit a une valeure donnee + * \param user utilisateur qui demande l'ajustement + * \param id_entrepot id de l'entrepot + * \param nbpiece nombre de pieces + * \param mouvement 0 = ajout, 1 = suppression + */ + function correct_stock($user, $id_entrepot, $nbpiece, $mouvement) + { + if ($id_entrepot) + { + $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."product_stock"; + $sql .= " WHERE fk_product = ".$this->id." AND fk_entrepot = ".$id_entrepot; + + $resql=$this->db->query($sql); + if ($resql) + { + $row = $this->db->fetch_object($resql); + if ($row->nb > 0) + { + // Record already exists, we make an update + return $this->ajust_stock($user, $id_entrepot, $nbpiece, $mouvement); + } + else + { + // Record not yet available, we make an insert + return $this->create_stock($id_entrepot, $nbpiece); + } + } + else + { + dolibarr_print_error($this->db); + $this->db->rollback(); + return -1; + } + } + } + + /** + * \brief Augmente ou r�duit la valeur de stock pour le produit + * \param user utilisateur qui demande l'ajustement + * \param id_entrepot id de l'entrepot + * \param nbpiece nombre de pieces + * \param mouvement 0 = ajout, 1 = suppression + */ + function ajust_stock($user, $id_entrepot, $nbpiece, $mouvement) + { + $op[0] = "+".trim($nbpiece); + $op[1] = "-".trim($nbpiece); + + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."product_stock"; + $sql.= " SET reel = reel ".$op[$mouvement]; + $sql.= " WHERE fk_product = ".$this->id." AND fk_entrepot = ".$id_entrepot; + + 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 .= " VALUES (now(), ".$this->id.", ".$id_entrepot.", ".$op[$mouvement].", 0, ".$user->id.")"; + + dolibarr_syslog("Product::ajust_stock sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return 1; + } + else + { + dolibarr_print_error($this->db); + $this->db->rollback(); + return -2; + } + } + else + { + dolibarr_print_error($this->db); + $this->db->rollback(); + return -1; + } + } /** * \brief Augmente ou r�duit le nombre de piece en commande a expedier diff --git a/htdocs/product/stock/entrepot.class.php b/htdocs/product/stock/entrepot.class.php index 77d50dfbb00..4891fcd6e60 100644 --- a/htdocs/product/stock/entrepot.class.php +++ b/htdocs/product/stock/entrepot.class.php @@ -16,16 +16,13 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - * $Source$ */ /** \file htdocs/product/stock/entrepot.class.php \ingroup stock \brief Fichier de la classe de gestion des entrepots - \version $Revision$ + \version $Id$ */ @@ -64,60 +61,60 @@ class Entrepot $this->statuts[1] = $langs->trans("Opened"); } - /* - * \brief Creation d'un entrepot en base - * \param Objet user qui crée l'entrepot - */ - function create($user) - { - // Si libelle non defini, erreur - if ($this->libelle == '') { - $this->error = "Libellé obligatoire"; - return 0; - } - - $this->db->begin(); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."entrepot (datec, fk_user_author)"; - $sql .= " VALUES (now(),".$user->id.")"; - - $result=$this->db->query($sql); - if ($result) - { - $id = $this->db->last_insert_id(MAIN_DB_PREFIX."entrepot"); - if ($id > 0) - { - $this->id = $id; - - if ( $this->update($id, $user) > 0) - { - $this->db->commit(); - return $id; - } - else - { - dolibarr_syslog("Entrepot::Create return -3"); - $this->db->rollback(); - return -3; - } - } - else { - $this->error="Failed to get insert id"; - dolibarr_syslog("Entrepot::Create return -2"); - return -2; + /* + * \brief Creation d'un entrepot en base + * \param Objet user qui crée l'entrepot + */ + function create($user) + { + // Si libelle non defini, erreur + if ($this->libelle == '') + { + $this->error = "ErrorFieldRequired"; + return 0; + } + + $this->db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."entrepot (datec, fk_user_author, label)"; + $sql .= " VALUES (now(),".$user->id.",'".addslashes($this->libelle)."')"; + + dolibarr_syslog("Entrepot::create sql=".$sql); + $result=$this->db->query($sql); + if ($result) + { + $id = $this->db->last_insert_id(MAIN_DB_PREFIX."entrepot"); + if ($id > 0) + { + $this->id = $id; + + if ( $this->update($id, $user) > 0) + { + $this->db->commit(); + return $id; + } + else + { + dolibarr_syslog("Entrepot::Create return -3"); + $this->db->rollback(); + return -3; + } + } + else { + $this->error="Failed to get insert id"; + dolibarr_syslog("Entrepot::Create return -2"); + return -2; + } + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("Entrepot::Create Error ".$this->db->error()); + $this->db->rollback(); + return -1; + } + } - } - else - { - $this->error="Failed to insert warehouse"; - dolibarr_syslog("Entrepot::Create return -1"); - dolibarr_syslog("Entrepot::Create ".$this->error); - dolibarr_syslog("Entrepot::Create ".$this->db->error()); - $this->db->rollback(); - return -1; - } - - } /* * \brief Mise a jour des information d'un entrepot diff --git a/htdocs/product/stock/mouvement.php b/htdocs/product/stock/mouvement.php index 904fa4fe1ce..58caadcc9d5 100644 --- a/htdocs/product/stock/mouvement.php +++ b/htdocs/product/stock/mouvement.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2006 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2005-2006 Regis Houssin * * 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 * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - * $Source$ */ /** \file htdocs/product/stock/mouvement.php \ingroup stock \brief Page liste des mouvements de stocks - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); @@ -147,14 +144,16 @@ if ($resql) $objp = $db->fetch_object($resql); $var=!$var; print ""; - print ''.dolibarr_print_date($objp->datem).''; + print ''.dolibarr_print_date($objp->datem,'dayhour').''; print "rowid\">"; print img_object($langs->trans("ShowProduct"),"product").' '.$objp->produit; print "\n"; print ''; print img_object($langs->trans("ShowWarehouse"),"stock").' '.$objp->stock; print "\n"; - print ''.$objp->value.''; + print ''; + if ($objp->value > 0) print '+'; + print $objp->value.''; print "\n"; $i++; } diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 6be679e0385..31ee2b2d26d 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -18,16 +18,13 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - * $Source$ */ /** \file htdocs/product/stock/product.php \ingroup product \brief Page de la fiche stock d'un produit - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); @@ -45,6 +42,9 @@ if (! $user->rights->produit->lire || ! $product->type == 0 || ! $conf->stock->e accessforbidden(); } +/** +* Actions +*/ if ($_POST["action"] == "create_stock") { @@ -55,9 +55,8 @@ if ($_POST["action"] == "create_stock") if ($_POST["action"] == "correct_stock" && $_POST["cancel"] <> $langs->trans("Cancel")) { - if (is_numeric($_POST["nbpiece"])) + if (is_numeric($_POST["nbpiece"])) { - $product = new Product($db); $product->id = $_GET["id"]; $product->correct_stock($user, diff --git a/htdocs/product/stock/valo.php b/htdocs/product/stock/valo.php index 302f17b69b3..4c90f755d9b 100644 --- a/htdocs/product/stock/valo.php +++ b/htdocs/product/stock/valo.php @@ -90,7 +90,7 @@ if ($result) { $entrepot=new Entrepot($db); $total = 0; - $var=True; + $var=false; while ($i < min($num,$limit)) { $objp = $db->fetch_object($result);