mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Qual: Clean stock increase/decrease code
This commit is contained in:
parent
0b0d672c3a
commit
edd91b7d26
|
|
@ -19,6 +19,8 @@ For users:
|
|||
saved clicks again).
|
||||
- New: Add graph using Jquery Flot.
|
||||
- New: Usage of Jquery Notify to show result or error messages on action.
|
||||
- New: If a service contains subproducts, subrpoducts are decrease when service
|
||||
is decrease.
|
||||
- New: Add status for third parties to disable a third party.
|
||||
- New: Can send interventions cards by email.
|
||||
- New: Add option MAIN_FIRST_TO_UPPER to force upper case of first
|
||||
|
|
|
|||
|
|
@ -238,11 +238,12 @@ class Commande extends CommonObject
|
|||
if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1)
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php");
|
||||
$langs->load("agenda");
|
||||
|
||||
// Loop on each line
|
||||
for ($i = 0 ; $i < sizeof($this->lines) ; $i++)
|
||||
{
|
||||
if ($this->lines[$i]->fk_product > 0 && $this->lines[$i]->product_type == 0)
|
||||
if ($this->lines[$i]->fk_product > 0)
|
||||
{
|
||||
$mouvP = new MouvementStock($this->db);
|
||||
// We decrement stock of product (and sub-products)
|
||||
|
|
@ -345,10 +346,11 @@ class Commande extends CommonObject
|
|||
if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1)
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php");
|
||||
$langs->load("agenda");
|
||||
|
||||
for ($i = 0 ; $i < sizeof($this->lines) ; $i++)
|
||||
{
|
||||
if ($this->lines[$i]->fk_product > 0 && $this->lines[$i]->product_type == 0)
|
||||
if ($this->lines[$i]->fk_product > 0)
|
||||
{
|
||||
$mouvP = new MouvementStock($this->db);
|
||||
// We increment stock of product (and sub-products)
|
||||
|
|
@ -506,8 +508,9 @@ class Commande extends CommonObject
|
|||
if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1)
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php");
|
||||
$langs->load("agenda");
|
||||
|
||||
if ($this->lines[$i]->fk_product > 0 && $this->lines[$i]->product_type == 0)
|
||||
if ($this->lines[$i]->fk_product > 0)
|
||||
{
|
||||
$mouvP = new MouvementStock($this->db);
|
||||
// We increment stock of product (and sub-products)
|
||||
|
|
|
|||
|
|
@ -1542,13 +1542,13 @@ class Facture extends CommonObject
|
|||
if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_BILL)
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php");
|
||||
$langs->load("agenda");
|
||||
|
||||
// Loop on each line
|
||||
for ($i = 0 ; $i < sizeof($this->lines) ; $i++)
|
||||
{
|
||||
if ($this->lines[$i]->fk_product > 0 && $this->lines[$i]->product_type == 0)
|
||||
if ($this->lines[$i]->fk_product > 0)
|
||||
{
|
||||
$langs->load("agenda");
|
||||
$mouvP = new MouvementStock($this->db);
|
||||
// We decrease stock for product
|
||||
$entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot
|
||||
|
|
@ -1653,12 +1653,12 @@ class Facture extends CommonObject
|
|||
if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_BILL)
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php");
|
||||
$langs->load("agenda");
|
||||
|
||||
for ($i = 0 ; $i < sizeof($this->lines) ; $i++)
|
||||
{
|
||||
if ($this->lines[$i]->fk_product && $this->lines[$i]->product_type == 0)
|
||||
if ($this->lines[$i]->fk_product > 0)
|
||||
{
|
||||
$langs->load("agenda");
|
||||
$mouvP = new MouvementStock($this->db);
|
||||
// We decrease stock for product
|
||||
$entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot
|
||||
|
|
|
|||
|
|
@ -382,9 +382,9 @@ class Expedition extends CommonObject
|
|||
}
|
||||
|
||||
/**
|
||||
* \brief Validate object and update stock if option enabled
|
||||
* \param user Objet de l'utilisateur qui valide
|
||||
* \return int
|
||||
* Validate object and update stock if option enabled
|
||||
* @param user Object user that validate
|
||||
* @return int
|
||||
*/
|
||||
function valid($user)
|
||||
{
|
||||
|
|
@ -451,6 +451,7 @@ class Expedition extends CommonObject
|
|||
if (! $error && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php";
|
||||
$langs->load("agenda");
|
||||
|
||||
// Loop on each product line to add a stock movement
|
||||
// TODO possibilite d'expedier a partir d'une propale ou autre origine
|
||||
|
|
@ -471,15 +472,12 @@ class Expedition extends CommonObject
|
|||
dol_syslog("Expedition::valid movement index ".$i);
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
if ($this->lines[$i]->fk_product > 0 && $this->lines[$i]->product_type == 0)
|
||||
{
|
||||
//var_dump($this->lines[$i]);
|
||||
$mouvS = new MouvementStock($this->db);
|
||||
// We decrement stock of product (and sub-products)
|
||||
// We use warehouse selected for each line
|
||||
$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, $obj->subprice);
|
||||
if ($result < 0) { $error++; break; }
|
||||
}
|
||||
//var_dump($this->lines[$i]);
|
||||
$mouvS = new MouvementStock($this->db);
|
||||
// We decrement stock of product (and sub-products)
|
||||
// We use warehouse selected for each line
|
||||
$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, $obj->subprice);
|
||||
if ($result < 0) { $error++; break; }
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -412,17 +412,17 @@ class CommandeFournisseur extends Commande
|
|||
if ($this->db->query($sql))
|
||||
{
|
||||
// If stock is incremented on validate order, we must redecrement it
|
||||
if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 0)
|
||||
if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER)
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php");
|
||||
|
||||
for ($i = 0 ; $i < sizeof($this->lines) ; $i++)
|
||||
{
|
||||
if ($this->lines[$i]->fk_product > 0 && $this->lines[$i]->product_type == 0)
|
||||
if ($this->lines[$i]->fk_product > 0)
|
||||
{
|
||||
$mouvP = new MouvementStock($this->db);
|
||||
// We increment stock of product (and sub-products)
|
||||
$entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot
|
||||
$entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot
|
||||
$result=$mouvP->reception($user, $this->lines[$i]->fk_product, $entrepot_id, $this->lines[$i]->qty, $this->lines[$i]->subprice);
|
||||
if ($result < 0) { $error++; }
|
||||
}
|
||||
|
|
@ -633,11 +633,11 @@ class CommandeFournisseur extends Commande
|
|||
for ($i = 0 ; $i < sizeof($this->lines) ; $i++)
|
||||
{
|
||||
// Product with reference
|
||||
if (!empty($this->lines[$i]->fk_product))
|
||||
if ($this->lines[$i]->fk_product > 0)
|
||||
{
|
||||
$mouvP = new MouvementStock($this->db);
|
||||
// We decrement stock of product (and sub-products)
|
||||
$entrepot_id = "1"; //Todo: ajouter possibilite de choisir l'entrepot
|
||||
$entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot
|
||||
$result=$mouvP->reception($user, $this->lines[$i]->fk_product, $entrepot_id, $this->lines[$i]->qty, $this->lines[$i]->subprice);
|
||||
if ($result < 0) { $error++; }
|
||||
}
|
||||
|
|
@ -1058,9 +1058,8 @@ class CommandeFournisseur extends Commande
|
|||
|
||||
/**
|
||||
* Add a product into a stock warehouse.
|
||||
*
|
||||
* @param $user User object making change
|
||||
* @param $product Product object to dispatch
|
||||
* @param $product Id of product to dispatch
|
||||
* @param $qty Qty to dispatch
|
||||
* @param $entrepot Id of warehouse to add product
|
||||
* @param $price Price for PMP value calculation
|
||||
|
|
@ -1098,16 +1097,19 @@ class CommandeFournisseur extends Commande
|
|||
$error++;
|
||||
}
|
||||
|
||||
// Si module stock gere et que expedition faite depuis un entrepot
|
||||
// Si module stock gere et que incrementation faite depuis un dispatching en stock
|
||||
if (!$error && $entrepot > 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)
|
||||
{
|
||||
$mouv = new MouvementStock($this->db);
|
||||
$result=$mouv->reception($user, $product, $entrepot, $qty, $price, $comment);
|
||||
if ($result < 0)
|
||||
if ($product > 0)
|
||||
{
|
||||
$this->error=$mouv->error;
|
||||
dol_syslog("CommandeFournisseur::DispatchProduct ".$this->error, LOG_ERR);
|
||||
$error++;
|
||||
$result=$mouv->reception($user, $product, $entrepot, $qty, $price, $comment);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error=$mouv->error;
|
||||
dol_syslog("CommandeFournisseur::DispatchProduct ".$this->error, LOG_ERR);
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
|
@ -1369,7 +1371,7 @@ class CommandeFournisseur extends Commande
|
|||
return $result ;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Cree la commande depuis une propale existante
|
||||
* @param user Utilisateur qui cree
|
||||
* @param propale_id id de la propale qui sert de modele
|
||||
|
|
|
|||
|
|
@ -790,12 +790,12 @@ class FactureFournisseur extends Facture
|
|||
if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php");
|
||||
$langs->load("agenda");
|
||||
|
||||
for ($i = 0 ; $i < sizeof($this->lines) ; $i++)
|
||||
{
|
||||
if ($this->lines[$i]->fk_product && $this->lines[$i]->product_type == 0)
|
||||
if ($this->lines[$i]->fk_product > 0)
|
||||
{
|
||||
$langs->load("agenda");
|
||||
$mouvP = new MouvementStock($this->db);
|
||||
// We increase stock for product
|
||||
$entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot
|
||||
|
|
@ -865,12 +865,12 @@ class FactureFournisseur extends Facture
|
|||
if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php");
|
||||
$langs->load("agenda");
|
||||
|
||||
for ($i = 0 ; $i < sizeof($this->lines) ; $i++)
|
||||
{
|
||||
if ($this->lines[$i]->fk_product && $this->lines[$i]->product_type == 0)
|
||||
if ($this->lines[$i]->fk_product > 0)
|
||||
{
|
||||
$langs->load("agenda");
|
||||
$mouvP = new MouvementStock($this->db);
|
||||
// We increase stock for product
|
||||
$entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/* Copyright (C) 2004-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
|
||||
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
|
||||
|
|
@ -312,7 +312,7 @@ if ($id > 0 || ! empty($ref))
|
|||
print '<input type="text" size="60" maxlength="128" name="comment" value="';
|
||||
print $_POST["comment"]?$_POST["comment"]:$langs->trans("DispatchSupplierOrder",$commande->ref);
|
||||
// print ' / '.$commande->ref_supplier; // Not yet available
|
||||
print '" class="flat">';
|
||||
print '" class="flat"><br><br>';
|
||||
|
||||
print '<center><input type="submit" class="button" value="'.$langs->trans("DispatchVerb").'"';
|
||||
if (sizeof($listwarehouses) <= 0) print ' disabled="true"';
|
||||
|
|
|
|||
|
|
@ -309,9 +309,9 @@ class Livraison extends CommonObject
|
|||
}
|
||||
|
||||
/**
|
||||
* \brief Valide l'expedition, et met a jour le stock si stock gere
|
||||
* \param user Objet de l'utilisateur qui valide
|
||||
* \return int
|
||||
* Validate object and update stock if option enabled
|
||||
* @param user Object user that validate
|
||||
* @return int
|
||||
*/
|
||||
function valid($user)
|
||||
{
|
||||
|
|
@ -376,49 +376,6 @@ class Livraison extends CommonObject
|
|||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
// Si module stock gere et que expedition faite depuis un entrepot
|
||||
if ($conf->stock->enabled && $this->entrepot_id && $conf->global->STOCK_CALCULATE_ON_RECEIVING == 1)
|
||||
{
|
||||
|
||||
//Enregistrement d'un mouvement de stock pour chaque produit de l'expedition
|
||||
|
||||
dol_syslog("livraison.class.php::valid enregistrement des mouvements");
|
||||
|
||||
$sql = "SELECT cd.fk_product, cd.subprice, ld.qty ";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."livraisondet as ld";
|
||||
$sql.= " WHERE ld.fk_livraison = ".$this->id;
|
||||
$sql.= " AND cd.rowid = ld.fk_commande_ligne";
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $this->db->num_rows($resql);
|
||||
$i=0;
|
||||
while($i < $num)
|
||||
{
|
||||
dol_syslog("livraison.class.php::valid movement $i");
|
||||
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$mouvS = new MouvementStock($this->db);
|
||||
$entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot
|
||||
$result=$mouvS->livraison($user, $obj->fk_product, $entrepot_id, $obj->qty, $obj->subprice);
|
||||
if ($result < 0) { $error++; break; }
|
||||
$i++;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
$this->error=$this->db->error()." - sql=$sql";
|
||||
dol_syslog("livraison.class.php::valid ".$this->error, LOG_ERR);
|
||||
return -2;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// On efface le repertoire de pdf provisoire
|
||||
$livraisonref = dol_sanitizeFileName($this->ref);
|
||||
if ($conf->expedition->dir_output)
|
||||
|
|
|
|||
|
|
@ -32,24 +32,27 @@
|
|||
*/
|
||||
class MouvementStock
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param DB Database handler
|
||||
*/
|
||||
function MouvementStock($DB)
|
||||
{
|
||||
$this->db = $DB;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Add a movement of stock (in one direction only)
|
||||
* \param user User object
|
||||
* \param fk_product Id of product
|
||||
* \param entrepot_id Id of warehouse
|
||||
* \param qty Qty of movement (can be <0 or >0)
|
||||
* \param type Direction of movement:
|
||||
* Add a movement of stock (in one direction only)
|
||||
* @param user User object
|
||||
* @param fk_product Id of product
|
||||
* @param entrepot_id Id of warehouse
|
||||
* @param qty Qty of movement (can be <0 or >0)
|
||||
* @param type Direction of movement:
|
||||
* 0=input (stock increase after stock transfert), 1=output (stock decrease after stock transfer),
|
||||
* 2=output (stock decrease), 3=input (stock increase)
|
||||
* \param price Unit price HT of product
|
||||
* \param label Label of stock movement
|
||||
* \return int <0 if KO, >0 if OK
|
||||
* @param price Unit price HT of product
|
||||
* @param label Label of stock movement
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function _create($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label='')
|
||||
{
|
||||
|
|
@ -70,7 +73,10 @@ class MouvementStock
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (1 == 1) // Always change stock for current product, change for subproduct is done after
|
||||
$movestock=0;
|
||||
if ($product->type != 1 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) $movestock=1;
|
||||
|
||||
if ($movestock) // Change stock for current product, change for subproduct is done after
|
||||
{
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement";
|
||||
$sql.= " (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author, label, price)";
|
||||
|
|
@ -195,19 +201,20 @@ class MouvementStock
|
|||
}
|
||||
}
|
||||
|
||||
// Add movement for sub products
|
||||
// Add movement for sub products (recursive call)
|
||||
if (! $error && $conf->global->PRODUIT_SOUSPRODUITS)
|
||||
{
|
||||
$error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0, $label); // pmp is not change for subproduct
|
||||
}
|
||||
|
||||
// composition module (this is a non official external module)
|
||||
// Composition module (this is an external module)
|
||||
/* Removed. This code must be provided by module on trigger STOCK_MOVEMENT
|
||||
if (! $error && $qty < 0 && $conf->global->MAIN_MODULE_COMPOSITION)
|
||||
{
|
||||
$error = $this->_createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, 0, $label); // pmp is not change for subproduct
|
||||
}
|
||||
}*/
|
||||
|
||||
if (! $error)
|
||||
if ($movestock && ! $error)
|
||||
{
|
||||
// Appel des triggers
|
||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||
|
|
@ -285,6 +292,7 @@ class MouvementStock
|
|||
* @param label Label of stock movement
|
||||
* @return int <0 if KO, 0 if OK
|
||||
*/
|
||||
/* This function is specific to a module. Should be inside the trigger of module instead of core code.
|
||||
function _createProductComposition($user, $fk_product, $entrepot_id, $qty, $type, $price=0, $label='')
|
||||
{
|
||||
dol_syslog("MouvementStock::_createProductComposition $user->id, $fk_product, $entrepot_id, $qty, $type, $price, $label");
|
||||
|
|
@ -316,7 +324,7 @@ class MouvementStock
|
|||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -333,7 +341,7 @@ class MouvementStock
|
|||
/**
|
||||
* Increase stock for product and subproducts
|
||||
* @param label Label of stock movement
|
||||
* @return int <0 if KO, >0 if OK
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function reception($user, $fk_product, $entrepot_id, $qty, $price=0, $label='')
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user