diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php
index 2b71daf8bed..ffcda28d5b3 100644
--- a/htdocs/admin/stock.php
+++ b/htdocs/admin/stock.php
@@ -39,6 +39,11 @@ if (!$user->admin)
if ($_POST["action"] == 'stock_userstock')
{
dolibarr_set_const($db, "STOCK_USERSTOCK", $_POST["stock_userstock"]);
+ //On désactive l'autocréation si l'option "stock personnel" est désactivée
+ if ($_POST["stock_userstock"] == 0)
+ {
+ dolibarr_set_const($db, "STOCK_USERSTOCK_AUTOCREATE", 0);
+ }
Header("Location: stock.php");
exit;
}
@@ -51,6 +56,36 @@ elseif ($_POST["action"] == 'stock_userstock_autocreate')
elseif ($_POST["action"] == 'stock_bill')
{
dolibarr_set_const($db, "STOCK_CALCULATE_ON_BILL", $_POST["stock_bill"]);
+ //Si activée on désactive la décrémentation du stock à la validation de commande et/ou à l'expédition
+ if ($_POST["stock_bill"] == 1)
+ {
+ dolibarr_set_const($db, "STOCK_CALCULATE_ON_VALIDATE_ORDER", 0);
+ dolibarr_set_const($db, "STOCK_CALCULATE_ON_SHIPMENT", 0);
+ }
+ Header("Location: stock.php");
+ exit;
+}
+elseif ($_POST["action"] == 'stock_validateorder')
+{
+ dolibarr_set_const($db, "STOCK_CALCULATE_ON_VALIDATE_ORDER", $_POST["stock_validateorder"]);
+ //Si activée on désactive la décrémentation du stock à la facturation et/ou à l'expédition
+ if ($_POST["stock_validateorder"] == 1)
+ {
+ dolibarr_set_const($db, "STOCK_CALCULATE_ON_BILL", 0);
+ dolibarr_set_const($db, "STOCK_CALCULATE_ON_SHIPMENT", 0);
+ }
+ Header("Location: stock.php");
+ exit;
+}
+elseif ($_POST["action"] == 'stock_shipment')
+{
+ dolibarr_set_const($db, "STOCK_CALCULATE_ON_SHIPMENT", $_POST["stock_shipment"]);
+ //Si activée on désactive la décrémentation du stock à la facturation et/ou à la validation de commande
+ if ($_POST["stock_shipment"] == 1)
+ {
+ dolibarr_set_const($db, "STOCK_CALCULATE_ON_BILL", 0);
+ dolibarr_set_const($db, "STOCK_CALCULATE_ON_VALIDATE_ORDER", 0);
+ }
Header("Location: stock.php");
exit;
}
@@ -102,8 +137,8 @@ if ($conf->global->STOCK_USERSTOCK == 1)
print "\n";
print "\n";
}
-$var=!$var;
+$var=!$var;
print "
";
print '| '.$langs->trans("DeStockReStockOnBill").' | ';
print '';
@@ -113,6 +148,26 @@ print $html->selectyesno("stock_bill",$conf->global->STOCK_CALCULATE_ON_BILL,1);
print '';
print "\n | \n
\n";
+$var=!$var;
+print "";
+print '| '.$langs->trans("DeStockReStockOnValidateOrder").' | ';
+print '';
+print "\n | \n
\n";
+
+$var=!$var;
+print "";
+print '| '.$langs->trans("DeStockReStockOnShipment").' | ';
+print '';
+print "\n | \n
\n";
+
print '';
$db->close();
diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php
index 0f0f3f41e7f..89b8d1e63ac 100644
--- a/htdocs/commande/commande.class.php
+++ b/htdocs/commande/commande.class.php
@@ -258,6 +258,36 @@ class Commande extends CommonObject
}
}
}
+
+ //Si activé on décrémente le produit principal et ses composants à la validation de commande
+ if($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1)
+ {
+ require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
+
+ for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
+ {
+ if ($conf->global->PRODUIT_SOUSPRODUITS == 1)
+ {
+ $prod = new Product($this->db, $this->lignes[$i]->fk_product);
+ $prod -> get_sousproduits_arbo ();
+ $prods_arbo = $prod->get_each_prod();
+ if(sizeof($prods_arbo) > 0)
+ {
+ foreach($prods_arbo as $key => $value)
+ {
+ // on décompte le stock de tous les sousproduits
+ $mouvS = new MouvementStock($this->db);
+ $entrepot_id = "1"; //Todo: ajouter possibilité de choisir l'entrepot
+ $result=$mouvS->livraison($user, $value[1], $entrepot_id, $value[0]);
+ }
+ }
+ }
+ $mouvP = new MouvementStock($this->db);
+ // on décompte le stock du produit principal
+ $entrepot_id = "1"; //Todo: ajouter possibilité de choisir l'entrepot
+ $result=$mouvP->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
+ }
+ }
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
@@ -284,20 +314,50 @@ class Commande extends CommonObject
*
*
*/
- function set_draft($userid)
+ function set_draft($user)
{
+ global $conf;
+
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_statut = 0";
-
$sql .= " WHERE rowid = $this->id;";
- if ($this->db->query($sql) )
- {
- return 1;
- }
+ if ($this->db->query($sql))
+ {
+ //Si activé on incrémente le produit principal et ses composants à l'édition de la commande
+ if($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1)
+ {
+ require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
+
+ for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
+ {
+ if ($conf->global->PRODUIT_SOUSPRODUITS == 1)
+ {
+ $prod = new Product($this->db, $this->lignes[$i]->fk_product);
+ $prod -> get_sousproduits_arbo ();
+ $prods_arbo = $prod->get_each_prod();
+ if(sizeof($prods_arbo) > 0)
+ {
+ foreach($prods_arbo as $key => $value)
+ {
+ // on décompte le stock de tous les sousproduits
+ $mouvS = new MouvementStock($this->db);
+ $entrepot_id = "1"; //Todo: ajouter possibilité de choisir l'entrepot
+ $result=$mouvS->reception($user, $value[1], $entrepot_id, $value[0]);
+ }
+ }
+ }
+ $mouvP = new MouvementStock($this->db);
+ // on décompte le stock du produit principal
+ $entrepot_id = "1"; //Todo: ajouter possibilité de choisir l'entrepot
+ $result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
+ }
+ }
+ return 1;
+ }
else
- {
- dolibarr_print_error($this->db);
- }
+ {
+ dolibarr_print_error($this->db);
+ }
}
/**
@@ -309,68 +369,97 @@ class Commande extends CommonObject
{
global $conf;
if ($user->rights->commande->valider)
- {
- $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
- $sql.= ' SET fk_statut = 3,';
- $sql.= ' fk_user_cloture = '.$user->id.',';
- $sql.= ' date_cloture = now()';
- $sql.= " WHERE rowid = $this->id AND fk_statut > 0 ;";
+ {
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
+ $sql.= ' SET fk_statut = 3,';
+ $sql.= ' fk_user_cloture = '.$user->id.',';
+ $sql.= ' date_cloture = now()';
+ $sql.= " WHERE rowid = $this->id AND fk_statut > 0 ;";
- if ($this->db->query($sql) )
- {
- if($conf->stock->enabled && $conf->global->PRODUIT_SOUSPRODUITS == 1)
- {
- require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
- for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
+ if ($this->db->query($sql))
+ {
+ if($conf->stock->enabled && $conf->global->PRODUIT_SOUSPRODUITS == 1 && $conf->global->STOCK_CALCULATE_ON_SHIPMENT == 1)
+ {
+ require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
+ for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{
$prod = new Product($this->db, $this->lignes[$i]->fk_product);
$prod -> get_sousproduits_arbo ();
$prods_arbo = $prod->get_each_prod();
if(sizeof($prods_arbo) > 0)
- {
- foreach($prods_arbo as $key => $value)
- {
- // on décompte le stock de tous les sousproduits
- $mouvS = new MouvementStock($this->db);
- $entrepot_id = "1";
- $result=$mouvS->livraison($user, $value[1], $entrepot_id, $value[0]);
-
- }
- }
+ {
+ foreach($prods_arbo as $key => $value)
+ {
+ // on décompte le stock de tous les sousproduits
+ $mouvS = new MouvementStock($this->db);
+ $entrepot_id = "1";
+ $result=$mouvS->livraison($user, $value[1], $entrepot_id, $value[0]);
+ }
+ }
// on décompte pas le stock du produit principal, ça serait fait manuellement avec l'expédition
// $result=$mouvS->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
}
-
- }
- return 1;
- }
+ }
+ return 1;
+ }
else
- {
- dolibarr_print_error($this->db);
- return -1;
- }
- }
- }
+ {
+ dolibarr_print_error($this->db);
+ return -1;
+ }
+ }
+}
+
/**
* Annule la commande
*
*/
function cancel($user)
{
+ global $conf;
if ($user->rights->commande->valider)
- {
- $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET fk_statut = -1';
- $sql .= " WHERE rowid = $this->id AND fk_statut = 1 ;";
+ {
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET fk_statut = -1';
+ $sql .= " WHERE rowid = $this->id AND fk_statut = 1 ;";
- if ($this->db->query($sql) )
- {
- return 1;
- }
- else
- {
- dolibarr_print_error($this->db);
- }
- }
+ if ($this->db->query($sql) )
+ {
+ //Si activé on incrémente le produit principal et ses composants à l'édition de la commande
+ if($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1)
+ {
+ require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
+
+ for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
+ {
+ if ($conf->global->PRODUIT_SOUSPRODUITS == 1)
+ {
+ $prod = new Product($this->db, $this->lignes[$i]->fk_product);
+ $prod -> get_sousproduits_arbo ();
+ $prods_arbo = $prod->get_each_prod();
+ if(sizeof($prods_arbo) > 0)
+ {
+ foreach($prods_arbo as $key => $value)
+ {
+ // on décompte le stock de tous les sousproduits
+ $mouvS = new MouvementStock($this->db);
+ $entrepot_id = "1"; //Todo: ajouter possibilité de choisir l'entrepot
+ $result=$mouvS->reception($user, $value[1], $entrepot_id, $value[0]);
+ }
+ }
+ }
+ $mouvP = new MouvementStock($this->db);
+ // on décompte le stock du produit principal
+ $entrepot_id = "1"; //Todo: ajouter possibilité de choisir l'entrepot
+ $result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
+ }
+ }
+ return 1;
+ }
+ else
+ {
+ dolibarr_print_error($this->db);
+ }
+ }
}
/**
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 51c85e19ca9..1aa973a8273 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -442,7 +442,7 @@ if ($_GET['action'] == 'modif' && $user->rights->commande->creer)
*/
$commande = new Commande($db);
$commande->fetch($_GET['id']);
- $commande->set_draft($user->id);
+ $commande->set_draft($user);
}
/*
diff --git a/htdocs/commande/liste.php b/htdocs/commande/liste.php
index b4b64f4fe67..f9f05d29d04 100644
--- a/htdocs/commande/liste.php
+++ b/htdocs/commande/liste.php
@@ -119,10 +119,10 @@ if (!empty($sref_client))
{
$sql .= ' AND c.ref_client like \'%'.addslashes($sref_client).'%\'';
}
-// on ne liste pas les commandes classer facturées, elles apparaissent tout de même avec la recherche
+// on ne liste pas les commandes classer facturées et annulées, elles apparaissent tout de même avec la recherche
if ($conf->global->COMMANDE_HIDE_TREATED && (!$sref && !$sref_client && !$snom && !$sall && (!strlen($_POST['sf_ref']) > 0)))
{
- $sql .= ' AND c.facture = 0';
+ $sql .= ' AND c.facture = 0 AND c.fk_statut >= 0';
}
$sql .= ' ORDER BY '.$sortfield.' '.$sortorder;
diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php
index c01e8aad24b..0d02f606357 100644
--- a/htdocs/expedition/expedition.class.php
+++ b/htdocs/expedition/expedition.class.php
@@ -324,7 +324,7 @@ class Expedition extends CommonObject
if ($this->db->query($sql) )
{
// Si module stock géré et que expedition faite depuis un entrepot
- if ($conf->stock->enabled && $this->entrepot_id)
+ if ($conf->stock->enabled && $this->entrepot_id && $conf->global->STOCK_CALCULATE_ON_SHIPMENT == 1)
{
/*
* Enregistrement d'un mouvement de stock pour chaque produit de l'expedition
diff --git a/htdocs/includes/modules/modCommande.class.php b/htdocs/includes/modules/modCommande.class.php
index e68b6bd584f..d453a61f70c 100644
--- a/htdocs/includes/modules/modCommande.class.php
+++ b/htdocs/includes/modules/modCommande.class.php
@@ -163,9 +163,9 @@ class modCommande extends DolibarrModules
$r++;
$this->export_code[$r]=$this->id.'_'.$r;
$this->export_label[$r]='Commandes clients et lignes de commande';
- $this->export_fields_array[$r]=array('s.idp'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','s.fk_pays'=>'Country','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','c.rowid'=>"Id",'c.ref'=>"Ref",'c.ref_client'=>"RefClient",'c.fk_soc'=>"IdCompany",'c.date_creation'=>"DateCreation",'c.date_commande'=>"DateOrder",'c.amount_ht'=>"Amount",'c.remise_percent'=>"GlobalDiscount",'c.total_ht'=>"TotalHT",'c.total_ttc'=>"TotalTTC",'c.facture'=>"OrderShortStatusInvoicee",'c.fk_statut'=>'Status','c.note'=>"Note",'p.ref'=>'RefProduct','p.label'=>'Label','cd.rowid'=>'LineId','cd.description'=>"LineDescription",'cd.total_ht'=>"TotalHT",'cd.tva_tx'=>"LineVATRate",'cd.qty'=>"LineQty");
- $this->export_entities_array[$r]=array('s.idp'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.siret'=>'company','c.rowid'=>"order",'c.ref'=>"order",'c.ref_client'=>"order",'c.fk_soc'=>"order",'c.date_creation'=>"order",'c.date_commande'=>"order",'c.amount_ht'=>"order",'c.remise_percent'=>"order",'c.total_ht'=>"order",'c.total_ttc'=>"order",'c.facture'=>"order",'c.fk_statut'=>'order','c.note'=>"order",'p.ref'=>'product','p.label'=>'product','cd.rowid'=>'order_line','cd.description'=>"order_line",'cd.total_ht'=>"order_line",'cd.tva_tx'=>"order_line",'cd.qty'=>"order_line");
- $this->export_alias_array[$r]=array('s.idp'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.cp'=>'soc_zip','s.ville'=>'soc_ville','s.fk_pays'=>'soc_pays','s.tel'=>'soc_tel','s.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','c.rowid'=>"orderid",'c.ref'=>"ref",'c.ref_client'=>"refclient",'c.fk_soc'=>"fk_soc",'c.date_creation'=>"datecreation",'c.date_commande'=>"dateorder",'c.amount_ht'=>"amount",'c.remise_percent'=>"globaldiscount",'c.total_ht'=>"totalht",'c.total_ttc'=>"totalttc",'c.facture'=>"invoicee",'c.fk_statut'=>'status','c.note'=>"note",'p.ref'=>'refproduct','p.label'=>'label','cd.rowid'=>'lineid','cd.description'=>"linedescription",'cd.total_ht'=>"totalht",'cd.tva_tx'=>"linevatrate",'cd.qty'=>"lineqty");
+ $this->export_fields_array[$r]=array('s.idp'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.cp'=>'Zip','s.ville'=>'Town','s.fk_pays'=>'Country','s.tel'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','c.rowid'=>"Id",'c.ref'=>"Ref",'c.ref_client'=>"RefClient",'c.fk_soc'=>"IdCompany",'c.date_creation'=>"DateCreation",'c.date_commande'=>"DateOrder",'c.amount_ht'=>"Amount",'c.remise_percent'=>"GlobalDiscount",'c.total_ht'=>"TotalHT",'c.total_ttc'=>"TotalTTC",'c.facture'=>"OrderShortStatusInvoicee",'c.fk_statut'=>'Status','c.note'=>"Note",'c.date_livraison'=>'DateDelivery','p.ref'=>'RefProduct','p.label'=>'Label','cd.rowid'=>'LineId','cd.description'=>"LineDescription",'cd.total_ht'=>"LineTotalHT",'cd.tva_tx'=>"LineVATRate",'cd.qty'=>"LineQty");
+ $this->export_entities_array[$r]=array('s.idp'=>"company",'s.nom'=>'company','s.address'=>'company','s.cp'=>'company','s.ville'=>'company','s.fk_pays'=>'company','s.tel'=>'company','s.siren'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.siret'=>'company','c.rowid'=>"order",'c.ref'=>"order",'c.ref_client'=>"order",'c.fk_soc'=>"order",'c.date_creation'=>"order",'c.date_commande'=>"order",'c.amount_ht'=>"order",'c.remise_percent'=>"order",'c.total_ht'=>"order",'c.total_ttc'=>"order",'c.facture'=>"order",'c.fk_statut'=>'order','c.note'=>"order",'c.date_livraison'=>"order",'p.ref'=>'product','p.label'=>'product','cd.rowid'=>'order_line','cd.description'=>"order_line",'cd.total_ht'=>"order_line",'cd.tva_tx'=>"order_line",'cd.qty'=>"order_line");
+ $this->export_alias_array[$r]=array('s.idp'=>"socid",'s.nom'=>'soc_name','s.address'=>'soc_adres','s.cp'=>'soc_zip','s.ville'=>'soc_ville','s.fk_pays'=>'soc_pays','s.tel'=>'soc_tel','s.siren'=>'soc_siren','s.siret'=>'soc_siret','s.ape'=>'soc_ape','s.idprof4'=>'soc_idprof4','c.rowid'=>"orderid",'c.ref'=>"ref",'c.ref_client'=>"refclient",'c.fk_soc'=>"fk_soc",'c.date_creation'=>"datecreation",'c.date_commande'=>"dateorder",'c.amount_ht'=>"amount",'c.remise_percent'=>"globaldiscount",'c.total_ht'=>"totalht",'c.total_ttc'=>"totalttc",'c.facture'=>"invoicee",'c.fk_statut'=>'status','c.note'=>"note",'c.date_livraison'=>'datedelivery','p.ref'=>'refproduct','p.label'=>'label','cd.rowid'=>'lineid','cd.description'=>"linedescription",'cd.total_ht'=>"linetotalht",'cd.tva_tx'=>"linevatrate",'cd.qty'=>"lineqty");
$this->export_sql[$r]="select distinct ";
$i=0;
foreach ($this->export_alias_array[$r] as $key => $value)
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 17e99f86a11..034f87df89f 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -490,7 +490,7 @@ HideTreadedPropal=Hide the treated commercial proposals in the list
OrdersSetup=Orders' management setup
OrdersNumberingModules=Orders numbering modules
OrdersModelModule=Order documents models
-HideTreadedOrders=Hide the treated orders in the list
+HideTreadedOrders=Hide the treated or canceled orders in the list
ValidOrderAfterPropalClosed=To validate the order after proposal closer, makes it possible not to step by the provisional order
##### Fiche inter #####
FicheinterNumberingModules=Intervention numbering modules
diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang
index 68ef9113d55..7c31bcb7bc2 100644
--- a/htdocs/langs/en_US/stocks.lang
+++ b/htdocs/langs/en_US/stocks.lang
@@ -37,6 +37,8 @@ EnhancedValueOfWarehouses=Warehouses value
UserWarehouseAutoCreate=Create a stock automatically when creating a user
QtyDispatched=Quantity dispatched
OrderDispatch=Order dispatching
-DeStockReStockOnBill=Decrease/increase stocks on invoices/credit notes (incompatible with stock decrease on sending/receiving)
+DeStockReStockOnBill=Decrease/increase stocks on invoices/credit notes
+DeStockReStockOnValidateOrder=Decrease/increase stocks on orders notes
+DeStockReStockOnShipment=Decrease/increase stocks on shipment
StockAvailable=Available stock
StockInstant=Real stock
diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang
index 3a4ca6cd985..9a45cdf8a6a 100644
--- a/htdocs/langs/fr_FR/admin.lang
+++ b/htdocs/langs/fr_FR/admin.lang
@@ -489,7 +489,7 @@ HideTreadedPropal=Cacher les propositions commerciales trait
OrdersSetup=Configuration du module Commandes
OrdersNumberingModules=Modules de numérotation des commandes
OrdersModelModule=Modèles de document des commandes
-HideTreadedOrders=Cacher les commandes traitées de la liste
+HideTreadedOrders=Cacher les commandes traitées ou annulées de la liste
ValidOrderAfterPropalClosed=Valider la commande après la clôture de la propale, permet de ne pas passer par la commande provisoire
##### Fiche inter #####
FicheinterNumberingModules=Modules de numérotation des fiches interventions
diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang
index f150a63738f..e912e238a5f 100644
--- a/htdocs/langs/fr_FR/stocks.lang
+++ b/htdocs/langs/fr_FR/stocks.lang
@@ -37,6 +37,8 @@ EnhancedValueOfWarehouses=Valorisation des stocks
UserWarehouseAutoCreate=Créer un stock automatiquement à la création d'un utilisateur
QtyDispatched=Quantité ventilée
OrderDispatch=Ventilation commande
-DeStockReStockOnBill=Décrémente/Incrémente les stocks sur les factures/avoirs (incompatibles avec le destockage sur les expéditions)
+DeStockReStockOnBill=Décrémente/Incrémente les stocks sur les factures/avoirs
+DeStockReStockOnValidateOrder=Décrémente/Incrémente les stocks sur les commandes
+DeStockReStockOnShipment=Décrémente/Incrémente les stocks sur les expéditions
StockAvailable=Stock disponible
StockInstant=Stock actuel
\ No newline at end of file
diff --git a/htdocs/livraison/livraison.class.php b/htdocs/livraison/livraison.class.php
index 0eae2a5c5dc..fb35e356f46 100644
--- a/htdocs/livraison/livraison.class.php
+++ b/htdocs/livraison/livraison.class.php
@@ -307,7 +307,7 @@ class Livraison extends CommonObject
if ($resql)
{
// Si module stock géré et que expedition faite depuis un entrepot
- if (!$conf->expedition->enabled && $conf->stock->enabled && $this->entrepot_id)
+ if (!$conf->expedition->enabled && $conf->stock->enabled && $this->entrepot_id && $conf->global->STOCK_CALCULATE_ON_SHIPMENT == 1)
{
//Enregistrement d'un mouvement de stock pour chaque produit de l'expedition
diff --git a/htdocs/product/stock/mouvementstock.class.php b/htdocs/product/stock/mouvementstock.class.php
index 29d09985170..42e95051ad1 100644
--- a/htdocs/product/stock/mouvementstock.class.php
+++ b/htdocs/product/stock/mouvementstock.class.php
@@ -53,52 +53,52 @@ class MouvementStock
$this->db->begin();
$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 (now(), $fk_product, $entrepot_id, $qty, $type, $user->id";
- $sql.= ",'".ereg_replace(",",".",$price)."');";
+ $sql.= ",'".ereg_replace(",",".",$price)."');";
if ($resql = $this->db->query($sql))
- {
- $mvid = $this->db->last_insert_id($resql);
- }
+ {
+ $mvid = $this->db->last_insert_id($resql);
+ }
else
- {
- dolibarr_syslog("MouvementStock::_Create echec insert ".$this->error);
- $error = -1;
- }
+ {
+ dolibarr_syslog("MouvementStock::_Create echec insert ".$this->error);
+ $error = -1;
+ }
- $num = 0;
+ $num = 0;
- if ($error === 0)
- {
+ if ($error === 0)
+ {
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product_stock";
$sql.= " WHERE fk_entrepot = $entrepot_id AND fk_product = $fk_product";
if ($this->db->query($sql))
{
- $num = $this->db->num_rows($resql);
- $this->db->free($resql);
+ $num = $this->db->num_rows($resql);
+ $this->db->free($resql);
}
else
{
- dolibarr_syslog("MouvementStock::_Create echec update ".$this->error);
- $error = -2;
+ dolibarr_syslog("MouvementStock::_Create echec update ".$this->error);
+ $error = -2;
}
- }
+ }
- if ($error === 0)
- {
- if ($num > 0)
+ if ($error === 0)
{
- $sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET reel = reel + $qty";
- $sql.= " WHERE fk_entrepot = $entrepot_id AND fk_product = $fk_product";
- }
- else
- {
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_stock";
- $sql.= " (reel, fk_entrepot, fk_product) VALUES ";
- $sql.= " ($qty,$entrepot_id,$fk_product);";
- }
+ if ($num > 0)
+ {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET reel = reel + $qty";
+ $sql.= " WHERE fk_entrepot = $entrepot_id AND fk_product = $fk_product";
+ }
+ else
+ {
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_stock";
+ $sql.= " (reel, fk_entrepot, fk_product) VALUES ";
+ $sql.= " ($qty,$entrepot_id,$fk_product);";
+ }
if ($this->db->query($sql))
{
@@ -106,10 +106,10 @@ class MouvementStock
}
else
{
- dolibarr_syslog("MouvementStock::_Create echec update ".$this->error);
- $error = -3;
+ dolibarr_syslog("MouvementStock::_Create echec update ".$this->error);
+ $error = -3;
}
- }
+ }
if ($error === 0)