Add stock information in products list.

This commit is contained in:
Laurent Destailleur 2009-02-06 06:26:45 +00:00
parent c2c79eff01
commit f7c956454a
12 changed files with 338 additions and 272 deletions

View File

@ -74,7 +74,7 @@ class modProduit extends DolibarrModules
// Config pages // Config pages
$this->config_page_url = array("produit.php"); $this->config_page_url = array("produit.php");
$this->langfiles = array("products","companies"); $this->langfiles = array("products","companies","stocks");
// Constantes // Constantes
$this->const = array(); $this->const = array();
@ -140,9 +140,9 @@ class modProduit extends DolibarrModules
$this->export_code[$r]=$this->rights_class.'_'.$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_label[$r]="ProductsOrServices"; // Translation key (used only if key ExportDataset_xxx_z not found)
$this->export_permission[$r]=array(array("produit","export")); $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_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','p.stock'=>'Stock','p.pmp'=>'PMPValue');
$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_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','p.stock'=>'product','p.pmp'=>'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_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','p.stock'=>'stock','p.pmp'=>'pmp');
$this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_start[$r]='SELECT DISTINCT ';
$this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p'; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'product as p';

View File

@ -195,6 +195,10 @@ if (isset($_POST['action']) && $_POST['action'] == 'upgrade')
migrate_module_menus($db,$langs,$conf); migrate_module_menus($db,$langs,$conf);
// Script pour V2.5 -> V2.6
migrate_stocks($db,$langs,$conf);
// On commit dans tous les cas. // On commit dans tous les cas.
// La procedure etant concue pour pouvoir passer plusieurs fois quelquesoit la situation. // La procedure etant concue pour pouvoir passer plusieurs fois quelquesoit la situation.
$db->commit(); $db->commit();
@ -1887,6 +1891,76 @@ function migrate_detail_livraison($db,$langs,$conf)
print '</td></tr>'; print '</td></tr>';
} }
/*
* Migration du champ stock dans produits
*/
function migrate_stocks($db,$langs,$conf)
{
print '<tr><td colspan="4">';
print '<br>';
print '<b>'.$langs->trans('MigrationStockDetail')."</b><br>\n";
$error = 0;
$db->begin();
$sql = "SELECT SUM(reel) as total, fk_product";
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
$sql.= " GROUP BY fk_product";
$resql = $db->query($sql);
if ($resql)
{
$i = 0;
$num = $db->num_rows($resql);
if ($num)
{
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$sql = "UPDATE ".MAIN_DB_PREFIX."product SET";
$sql.= " stock = '".$obj->total."'";
$sql.= " WHERE rowid=".$obj->fk_product;
$resql2=$db->query($sql);
if ($resql2)
{
}
else
{
$error++;
dolibarr_print_error($db);
}
print ". ";
$i++;
}
}
if ($error == 0)
{
$db->commit();
}
else
{
$db->rollback();
}
}
else
{
dolibarr_print_error($db);
$db->rollback();
}
print '</td></tr>';
}
/* A faire egalement: Modif statut paye et fk_facture des factures payes completement /* A faire egalement: Modif statut paye et fk_facture des factures payes completement
On recherche facture incorrecte: On recherche facture incorrecte:

View File

@ -186,3 +186,5 @@ MigrationShipmentOrderMatching=Sendings receipt update
MigrationDeliveryOrderMatching=Delivery receipt update MigrationDeliveryOrderMatching=Delivery receipt update
MigrationDeliveryDetail=Delivery update MigrationDeliveryDetail=Delivery update
# Migration stock
MigrationStockDetail=Update stock value of products

View File

@ -35,7 +35,8 @@ 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 PMPValue=Weighted average price
PMPValueShort=WAP
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

View File

@ -187,3 +187,7 @@ MigrationShipmentOrderMatching=Mise a jour bon expedition
MigrationDeliveryOrderMatching=Mise a jour bon reception MigrationDeliveryOrderMatching=Mise a jour bon reception
MigrationDeliveryDetail=Mise a jour bon reception MigrationDeliveryDetail=Mise a jour bon reception
# Migration stock
MigrationStockDetail=Mise a jour valeur en stock des produits

View File

@ -36,6 +36,7 @@ TotalStock=Total en stock
StockTooLow=Stock insuffisant StockTooLow=Stock insuffisant
EnhancedValue=Valorisation EnhancedValue=Valorisation
PMPValue=Valorisation (PMP) PMPValue=Valorisation (PMP)
PMPValueShort=PMP
EnhancedValueOfWarehouses=Valorisation des stocks 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

View File

@ -121,7 +121,7 @@ if ($action == '' && !$cancel) {
print "\n</div><br>\n"; print "\n</div><br>\n";
$id_entrepot = OSC_ENTREPOT; $id_entrepot = OSC_ENTREPOT;
$id = $product->create_stock($id_entrepot,$osc_prod->osc_stock); $id = $product->create_stock($user, $id_entrepot,$osc_prod->osc_stock);
// if ($id > 0) exit; // if ($id > 0) exit;
} }
else else

View File

@ -940,6 +940,7 @@ class Product extends CommonObject
$this->barcode_type = $result["fk_barcode_type"]; $this->barcode_type = $result["fk_barcode_type"];
$this->stock_in_command = 0; // TODO $this->stock_in_command = 0; // TODO
$this->stock_in_propal = 0; // TODO
$this->label_url = '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$this->id.'">'.$this->libelle.'</a>'; $this->label_url = '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$this->id.'">'.$this->libelle.'</a>';
@ -2110,68 +2111,25 @@ class Product extends CommonObject
return ''; return '';
} }
/**
* \brief Entre un nombre de piece du produit en stock dans un entrep<EFBFBD>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();
$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 (".$this->db->idate(mktime()).", ".$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 * \brief Ajuste le stock d'un entrepot pour le produit d'un delta donne
* \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
* \param mouvement 0 = ajout, 1 = suppression * \param mouvement 0 = ajout, 1 = suppression
* \return int <0 if KO, >0 if OK
*/ */
function correct_stock($user, $id_entrepot, $nbpiece, $mouvement) function correct_stock($user, $id_entrepot, $nbpiece, $mouvement)
{ {
if ($id_entrepot) if ($id_entrepot)
{ {
$this->db->begin();
$sql = "SELECT count(*) as nb 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;
dol_syslog("Product::correct_stock sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -2179,14 +2137,20 @@ class Product extends CommonObject
if ($row->nb > 0) if ($row->nb > 0)
{ {
// Record already exists, we make an update // Record already exists, we make an update
return $this->ajust_stock($user, $id_entrepot, $nbpiece, $mouvement); $result=$this->ajust_stock($user, $id_entrepot, $nbpiece, $mouvement);
} }
else else
{ {
// Record not yet available, we make an insert // Record not yet available, we make an insert
return $this->create_stock($id_entrepot, $nbpiece); $result=$this->create_stock($user, $id_entrepot, $nbpiece, $mouvement);
} }
} }
if ($result >= 0)
{
$this->db->commit();
return 1;
}
else else
{ {
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
@ -2201,51 +2165,47 @@ class Product extends CommonObject
* \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
* \param mouvement 0 = ajout, 1 = suppression * \param movement 0 = ajout, 1 = suppression
* \return int <0 if KO, >0 if OK
* \remarks Called by correct_stock * \remarks Called by correct_stock
*/ */
function ajust_stock($user, $id_entrepot, $nbpiece, $mouvement) function ajust_stock($user, $id_entrepot, $nbpiece, $movement)
{ {
require_once(DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php");
$op[0] = "+".trim($nbpiece); $op[0] = "+".trim($nbpiece);
$op[1] = "-".trim($nbpiece); $op[1] = "-".trim($nbpiece);
$this->db->begin(); $movementstock=new MouvementStock($this->db);
$result=$movementstock->_create($user,$this->id,$id_entrepot,$op[$movement],0,0);
$sql = "UPDATE ".MAIN_DB_PREFIX."product_stock"; return $result;
$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 (".$this->db->idate(mktime()).", ".$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 Charge les informations en stock du produit * \brief Entre un nombre de piece du produit en stock dans un entrepot
* \param user utilisateur qui demande l'ajustement
* \param id_entrepot id de l'entrepot
* \param nbpiece nombre de pieces
* \param movement 0 = ajout, 1 = suppression
* \return int <0 if KO, >0 if OK
* \remarks Called by correct_stock
*/
function create_stock($user, $id_entrepot, $nbpiece, $movement=0)
{
require_once(DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php");
$op[0] = "+".trim($nbpiece);
$op[1] = "-".trim($nbpiece);
$movementstock=new MouvementStock($this->db);
$result=$movementstock->_create($user,$this->id,$id_entrepot,$op[$movement],0,0);
return $result;
}
/**
* \brief Charge les informations en stock du produit dans stock_entrepot[] et stock_reel
* \return int < 0 si erreur, > 0 si ok * \return int < 0 si erreur, > 0 si ok
*/ */
function load_stock() function load_stock()
@ -2255,6 +2215,8 @@ class Product extends CommonObject
$sql = "SELECT reel, fk_entrepot"; $sql = "SELECT reel, fk_entrepot";
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock"; $sql.= " FROM ".MAIN_DB_PREFIX."product_stock";
$sql.= " WHERE fk_product = '".$this->id."'"; $sql.= " WHERE fk_product = '".$this->id."'";
dol_syslog("Product::load_stock sql=".$sql);
$result = $this->db->query($sql) ; $result = $this->db->query($sql) ;
if ($result) if ($result)
{ {
@ -2288,11 +2250,11 @@ class Product extends CommonObject
/** /**
* \brief D<EFBFBD>place fichier upload<EFBFBD> sous le nom $files dans le r<EFBFBD>pertoire sdir * \brief Deplace fichier uploade sous le nom $files dans le repertoire sdir
* \param sdir R<EFBFBD>pertoire destination finale * \param sdir Repertoire destination finale
* \param $file Nom du fichier upload<EFBFBD> * \param $file Nom du fichier uploade
* \param maxWidth Largeur maximum que dois faire la miniature (160 par d<EFBFBD>faut) * \param maxWidth Largeur maximum que dois faire la miniature (160 par defaut)
* \param maxHeight Hauteur maximum que dois faire la miniature (120 par d<EFBFBD>faut) * \param maxHeight Hauteur maximum que dois faire la miniature (120 par defaut)
*/ */
function add_photo($sdir, $file, $maxWidth = 160, $maxHeight = 120) function add_photo($sdir, $file, $maxWidth = 160, $maxHeight = 120)
{ {
@ -2301,7 +2263,7 @@ class Product extends CommonObject
if (! file_exists($dir)) if (! file_exists($dir))
{ {
dolibarr_syslog("Product Create $dir"); dol_syslog("Product Create $dir");
create_exdir($dir); create_exdir($dir);
} }
@ -2350,7 +2312,7 @@ class Product extends CommonObject
if (! file_exists($dir)) if (! file_exists($dir))
{ {
dolibarr_syslog("Product Create $dir"); dol_syslog("Product Create $dir");
create_exdir($dir); create_exdir($dir);
} }
@ -2553,7 +2515,7 @@ class Product extends CommonObject
} }
/** /**
* \brief R<EFBFBD>cup<EFBFBD>re la taille de l'image * \brief Recupere la taille de l'image
* \param file Chemin de l'image * \param file Chemin de l'image
*/ */
function get_image_size($file) function get_image_size($file)
@ -2603,7 +2565,7 @@ class Product extends CommonObject
} }
/** /**
* \brief Mise <EFBFBD> jour du code barre * \brief Mise a jour du code barre
* \param user Utilisateur qui fait la modification * \param user Utilisateur qui fait la modification
*/ */
function update_barcode($user) function update_barcode($user)
@ -2612,7 +2574,7 @@ class Product extends CommonObject
$sql .= " SET barcode = '".$this->barcode."'"; $sql .= " SET barcode = '".$this->barcode."'";
$sql .= " WHERE rowid = ".$this->id; $sql .= " WHERE rowid = ".$this->id;
dolibarr_syslog("Product::update_barcode sql=".$sql); dol_syslog("Product::update_barcode sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -2626,7 +2588,7 @@ class Product extends CommonObject
} }
/** /**
* \brief Mise <EFBFBD> jour du type de code barre * \brief Mise a jour du type de code barre
* \param user Utilisateur qui fait la modification * \param user Utilisateur qui fait la modification
*/ */
function update_barcode_type($user) function update_barcode_type($user)
@ -2635,7 +2597,7 @@ class Product extends CommonObject
$sql .= " SET fk_barcode_type = '".$this->barcode_type."'"; $sql .= " SET fk_barcode_type = '".$this->barcode_type."'";
$sql .= " WHERE rowid = ".$this->id; $sql .= " WHERE rowid = ".$this->id;
dolibarr_syslog("Product::update_barcode_type sql=".$sql); dol_syslog("Product::update_barcode_type sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {

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) 2005 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2005-2009 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
@ -38,7 +38,7 @@ class MouvementStock
} }
/** /**
* \brief Add a mouvement in stock (in one direction only) * \brief Add a movement in stock (in one direction only)
* \param type Direction of movement: 2=output (stock decrease), 3=input (stock increase) * \param type Direction of movement: 2=output (stock decrease), 3=input (stock increase)
* \return int <0 if KO, >0 if OK * \return int <0 if KO, >0 if OK
*/ */
@ -47,17 +47,15 @@ class MouvementStock
global $conf; global $conf;
$error = 0; $error = 0;
dolibarr_syslog("MouvementStock::_Create $user->id, $fk_product, $entrepot_id, qty=$qty, type=$type, $price"); dolibarr_syslog("MouvementStock::_create $user->id, $fk_product, $entrepot_id, qty=$qty, type=$type, $price");
$this->db->begin(); $this->db->begin();
// $nbOfSubproduct=$this->nbOfSubProdcuts(); if (1 == 1) // Always change stock for current product, change for subproduct done after
if (1 == 1) // Always change stock for current product
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement";
$sql.= " (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author, price)"; $sql.= " (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author, price)";
$sql.= " VALUES (".$this->db->idate(mktime()).", ".$fk_product.", ".$entrepot_id.", ".$qty.", ".$type.", ".$user->id; $sql.= " VALUES (".$this->db->idate(gmmktime()).", ".$fk_product.", ".$entrepot_id.", ".$qty.", ".$type.", ".$user->id;
$sql.= ",'".price2num($price)."')"; $sql.= ",'".price2num($price)."')";
dolibarr_syslog("MouvementStock::_create sql=".$sql, LOG_DEBUG); dolibarr_syslog("MouvementStock::_create sql=".$sql, LOG_DEBUG);
@ -67,7 +65,7 @@ class MouvementStock
} }
else else
{ {
dolibarr_syslog("MouvementStock::_Create ".$this->error); dolibarr_syslog("MouvementStock::_create ".$this->error);
$error = -1; $error = -1;
} }
@ -85,12 +83,12 @@ class MouvementStock
} }
else else
{ {
dolibarr_syslog("MouvementStock::_Create echec update ".$this->error); dolibarr_syslog("MouvementStock::_create echec update ".$this->error);
$error = -2; $error = -2;
} }
} }
// Update value // Update denormalized value of stock in product_stock and product
if ($error == 0) if ($error == 0)
{ {
if ($num > 0) if ($num > 0)
@ -105,16 +103,29 @@ class MouvementStock
$sql.= " (".$qty.",".$entrepot_id.",".$fk_product.")"; $sql.= " (".$qty.",".$entrepot_id.",".$fk_product.")";
} }
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))
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."product SET stock = stock + ".$qty;
$sql.= " WHERE rowid = ".$fk_product;
dolibarr_syslog("MouvementStock::_create sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql))
{
// TODO // TODO
// Update value of PMP in product_stock // Update value of PMP in product_stock
}
else
{
dolibarr_syslog("MouvementStock::_create ".$this->error, LOG_ERR);
$error = -4;
}
} }
else else
{ {
dolibarr_syslog("MouvementStock::_Create ".$this->error, LOG_ERR); dolibarr_syslog("MouvementStock::_create ".$this->error, LOG_ERR);
$error = -3; $error = -3;
} }
} }
@ -153,8 +164,8 @@ class MouvementStock
else else
{ {
$this->db->rollback(); $this->db->rollback();
$this->error=$this->db->error(); $this->error=$this->db->lasterror();
dolibarr_syslog("MouvementStock::_Create ".$this->error); dolibarr_syslog("MouvementStock::_create ".$this->error);
return -2; return -2;
} }
} }
@ -209,8 +220,6 @@ class MouvementStock
*/ */
function _createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, $price=0) function _createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, $price=0)
{ {
dolibarr_syslog("MouvementStock::_createComposition $user->id, $fk_product, $entrepot_id, $qty, $type, $price"); dolibarr_syslog("MouvementStock::_createComposition $user->id, $fk_product, $entrepot_id, $qty, $type, $price");
$products_compo = array(); $products_compo = array();

View File

@ -52,7 +52,7 @@ if ($_POST["action"] == "create_stock" && ! $_POST["cancel"])
{ {
$product = new Product($db); $product = new Product($db);
$product->id = $_GET["id"]; $product->id = $_GET["id"];
$product->create_stock($_POST["id_entrepot"], $_POST["nbpiece"]); $product->create_stock($user, $_POST["id_entrepot"], $_POST["nbpiece"]);
} }
if ($_POST["action"] == "correct_stock" && ! $_POST["cancel"]) if ($_POST["action"] == "correct_stock" && ! $_POST["cancel"])
@ -74,19 +74,30 @@ if ($_POST["action"] == "transfert_stock" && ! $_POST["cancel"])
{ {
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, $db->begin();
$result1=$product->correct_stock($user,
$_POST["id_entrepot_source"], $_POST["id_entrepot_source"],
$_POST["nbpiece"], $_POST["nbpiece"],
1); 1);
$product->correct_stock($user, $result2=$product->correct_stock($user,
$_POST["id_entrepot_destination"], $_POST["id_entrepot_destination"],
$_POST["nbpiece"], $_POST["nbpiece"],
0); 0);
if ($result1 >= 0 && $result2 >= 0)
{
$db->commit();
}
else
{
$mesg=$product->error;
$db->rollback();
}
} }
} }
} }
@ -336,7 +347,7 @@ print '<tr class="liste_titre"><td width="40%">'.$langs->trans("Warehouse").'</t
print '<td align="right">'.$langs->trans("NumberOfUnit").'</td></tr>'; print '<td align="right">'.$langs->trans("NumberOfUnit").'</td></tr>';
$sql = "SELECT e.rowid, e.label, ps.reel FROM ".MAIN_DB_PREFIX."entrepot as e, ".MAIN_DB_PREFIX."product_stock as ps"; $sql = "SELECT e.rowid, e.label, ps.reel FROM ".MAIN_DB_PREFIX."entrepot as e, ".MAIN_DB_PREFIX."product_stock as ps";
$sql .= " WHERE ps.fk_entrepot = e.rowid AND ps.fk_product = ".$product->id; $sql .= " WHERE ps.reel != 0 AND ps.fk_entrepot = e.rowid AND ps.fk_product = ".$product->id;
$sql .= " ORDER BY lower(e.label)"; $sql .= " ORDER BY lower(e.label)";
$entrepotstatic=new Entrepot($db); $entrepotstatic=new Entrepot($db);

View File

@ -38,6 +38,7 @@ ALTER TABLE llx_categorie ADD INDEX idx_categorie_type (type);
ALTER TABLE llx_product drop column stock_propale; ALTER TABLE llx_product drop column stock_propale;
ALTER TABLE llx_product drop column stock_commande; ALTER TABLE llx_product drop column stock_commande;
ALTER TABLE llx_product add column stock integer after import_key;
ALTER TABLE llx_adherent drop index login; ALTER TABLE llx_adherent drop index login;
ALTER TABLE llx_adherent ADD UNIQUE INDEX uk_adherent_login (login); ALTER TABLE llx_adherent ADD UNIQUE INDEX uk_adherent_login (login);

View File

@ -47,6 +47,7 @@ create table llx_product
weight_units tinyint DEFAULT NULL, weight_units tinyint DEFAULT NULL,
volume float DEFAULT NULL, volume float DEFAULT NULL,
volume_units tinyint DEFAULT NULL, volume_units tinyint DEFAULT NULL,
stock integer, -- physical stock
pmp double(24,8) default 0 NOT NULL; pmp double(24,8) default 0 NOT NULL;
canvas varchar(15) DEFAULT '', canvas varchar(15) DEFAULT '',
finished tinyint DEFAULT NULL, finished tinyint DEFAULT NULL,