New: Store and show estimated value of stock

This commit is contained in:
Laurent Destailleur 2009-07-09 22:17:31 +00:00
parent 39b72a5fbe
commit 27c363530d
7 changed files with 61 additions and 68 deletions

View File

@ -280,8 +280,7 @@ class Commande extends CommonObject
$mouvP = new MouvementStock($this->db); $mouvP = new MouvementStock($this->db);
// We decrement stock of product (and sub-products) // 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
// TODO Add price of product in method or '' to update PMP $result=$mouvP->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty, $this->lignes[$i]->subprice);
$result=$mouvP->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
if ($result < 0) { $error++; } if ($result < 0) { $error++; }
} }
} }
@ -386,7 +385,7 @@ class Commande extends CommonObject
$mouvP = new MouvementStock($this->db); $mouvP = new MouvementStock($this->db);
// We increment stock of product (and sub-products) // 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->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty); $result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty, $this->lignes[$i]->subprice);
if ($result < 0) { $error++; } if ($result < 0) { $error++; }
} }
} }
@ -474,7 +473,7 @@ class Commande extends CommonObject
$mouvP = new MouvementStock($this->db); $mouvP = new MouvementStock($this->db);
// We increment stock of product (and sub-products) // 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->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty); $result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty, $this->lignes[$i]->subprice);
if ($result > 0) if ($result > 0)
{ {
@ -1157,12 +1156,12 @@ class Commande extends CommonObject
$ligne->date_start = $this->db->jdate($objp->date_start); $ligne->date_start = $this->db->jdate($objp->date_start);
$ligne->date_end = $this->db->jdate($objp->date_end); $ligne->date_end = $this->db->jdate($objp->date_end);
$this->lignes[$i] = $ligne; $this->lignes[$i] = $ligne; // For backward compatibility
$this->lines[$i] = $line;
$i++; $i++;
} }
$this->db->free($result); $this->db->free($result);
$this->lines = $this->lignes; // For backward compatibility
return 1; return 1;
} }
else else
@ -1244,10 +1243,10 @@ class Commande extends CommonObject
$sql = 'SELECT count(*) FROM '.MAIN_DB_PREFIX.'expedition as e'; $sql = 'SELECT count(*) FROM '.MAIN_DB_PREFIX.'expedition as e';
$sql .=" WHERE e.fk_commande = ".$this->id; $sql .=" WHERE e.fk_commande = ".$this->id;
$result = $this->db->query($sql); $resql = $this->db->query($sql);
if ($result) if ($resql)
{ {
$row = $this->db->fetch_row(0); $row = $this->db->fetch_row($resql);
return $row[0]; return $row[0];
} }
} }
@ -1266,14 +1265,14 @@ class Commande extends CommonObject
$sql.=' AND cd.fk_commande =' .$this->id; $sql.=' AND cd.fk_commande =' .$this->id;
if ($filtre_statut >= 0) $sql.=' AND l.fk_statut = '.$filtre_statut; if ($filtre_statut >= 0) $sql.=' AND l.fk_statut = '.$filtre_statut;
$sql .= ' GROUP BY cd.fk_product '; $sql .= ' GROUP BY cd.fk_product ';
$result = $this->db->query($sql); $resql = $this->db->query($sql);
if ($result) if ($resql)
{ {
$num = $this->db->num_rows(); $num = $this->db->num_rows($resql);
$i = 0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$row = $this->db->fetch_row( $i); $row = $this->db->fetch_row($resql);
$this->livraisons[$row[0]] = $row[1]; $this->livraisons[$row[0]] = $row[1];
$i++; $i++;
} }
@ -2263,10 +2262,10 @@ class CommandeLigne
var $fk_product; // Id produit predefini var $fk_product; // Id produit predefini
var $product_type = 0; // Type 0 = product, 1 = Service var $product_type = 0; // Type 0 = product, 1 = Service
var $qty; // Quantite (exemple 2) var $qty; // Quantity (example 2)
var $tva_tx; // Taux tva produit/service (exemple 19.6) var $tva_tx; // VAT Rate for product/service (example 19.6)
var $subprice; // P.U. HT (exemple 100) var $subprice; // U.P. HT (example 100)
var $remise_percent; // % de la remise ligne (exemple 20%) var $remise_percent; // % for line discount (example 20%)
var $rang = 0; var $rang = 0;
var $marge_tx; var $marge_tx;
var $marque_tx; var $marque_tx;

View File

@ -549,7 +549,7 @@ if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POS
if ($_REQUEST['action'] == 'confirm_validate' && $_REQUEST['confirm'] == 'yes' && $user->rights->commande->valider) if ($_REQUEST['action'] == 'confirm_validate' && $_REQUEST['confirm'] == 'yes' && $user->rights->commande->valider)
{ {
$commande = new Commande($db); $commande = new Commande($db);
$commande->fetch($_GET['id']); $commande->fetch($_GET['id']); // Load order and lines
$result=$commande->valid($user); $result=$commande->valid($user);
if ($result >= 0) if ($result >= 0)
@ -567,14 +567,16 @@ if ($_REQUEST['action'] == 'confirm_validate' && $_REQUEST['confirm'] == 'yes' &
if ($_REQUEST['action'] == 'confirm_close' && $_REQUEST['confirm'] == 'yes' && $user->rights->commande->creer) if ($_REQUEST['action'] == 'confirm_close' && $_REQUEST['confirm'] == 'yes' && $user->rights->commande->creer)
{ {
$commande = new Commande($db); $commande = new Commande($db);
$commande->fetch($_GET['id']); $commande->fetch($_GET['id']); // Load order and lines
$result = $commande->cloture($user); $result = $commande->cloture($user);
} }
if ($_REQUEST['action'] == 'confirm_cancel' && $_REQUEST['confirm'] == 'yes' && $user->rights->commande->valider) if ($_REQUEST['action'] == 'confirm_cancel' && $_REQUEST['confirm'] == 'yes' && $user->rights->commande->valider)
{ {
$commande = new Commande($db); $commande = new Commande($db);
$commande->fetch($_GET['id']); $commande->fetch($_GET['id']); // Load order and lines
$result = $commande->cancel($user); $result = $commande->cancel($user);
} }
@ -584,8 +586,7 @@ if ($_GET['action'] == 'modif' && $user->rights->commande->creer)
* Repasse la commande en mode brouillon * Repasse la commande en mode brouillon
*/ */
$commande = new Commande($db); $commande = new Commande($db);
$commande->fetch($_GET['id']); $commande->fetch($_GET['id']); // Load order and lines
$commande->set_draft($user);
$result = $commande->set_draft($user); $result = $commande->set_draft($user);
if ($result >= 0) if ($result >= 0)

View File

@ -398,7 +398,7 @@ class Expedition extends CommonObject
require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php"; require_once DOL_DOCUMENT_ROOT ."/product/stock/mouvementstock.class.php";
// Loop on each product line to add a stock movement // Loop on each product line to add a stock movement
$sql = "SELECT cd.fk_product, ed.qty, ed.fk_entrepot"; $sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
$sql.= ", ".MAIN_DB_PREFIX."expeditiondet as ed"; $sql.= ", ".MAIN_DB_PREFIX."expeditiondet as ed";
$sql.= " WHERE ed.fk_expedition = ".$this->id; $sql.= " WHERE ed.fk_expedition = ".$this->id;
@ -419,8 +419,7 @@ class Expedition extends CommonObject
$mouvS = new MouvementStock($this->db); $mouvS = new MouvementStock($this->db);
// We decrement stock of product (and sub-products) // We decrement stock of product (and sub-products)
$entrepot_id = "1"; // TODO ajouter possibilité de choisir l'entrepot $entrepot_id = "1"; // TODO ajouter possibilité de choisir l'entrepot
// TODO Add price of product in method or '' to update PMP $result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, $obj->subprice);
$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty);
if ($result < 0) { $error++; } if ($result < 0) { $error++; }
} }

View File

@ -1359,8 +1359,7 @@ class Facture extends CommonObject
$mouvP = new MouvementStock($this->db); $mouvP = new MouvementStock($this->db);
// We decrease stock for product // We decrease stock for product
$entrepot_id = "1"; // TODO ajouter possibilité de choisir l'entrepot $entrepot_id = "1"; // TODO ajouter possibilité de choisir l'entrepot
// TODO Add price of product in method or '' to update PMP $result=$mouvP->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty, $this->lignes[$i]->subprice);
$result=$mouvP->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
if ($result < 0) { $error++; } if ($result < 0) { $error++; }
} }
} }
@ -1455,8 +1454,7 @@ class Facture extends CommonObject
$mouvP = new MouvementStock($this->db); $mouvP = new MouvementStock($this->db);
// We decrease stock for product // We decrease stock for product
$entrepot_id = "1"; // TODO ajouter possibilité de choisir l'entrepot $entrepot_id = "1"; // TODO ajouter possibilité de choisir l'entrepot
// TODO Add price of product in method or '' to update PMP $result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty, $this->lignes[$i]->subprice);
$result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
} }
} }
} }

View File

@ -546,8 +546,7 @@ class CommandeFournisseur extends Commande
$mouvP = new MouvementStock($this->db); $mouvP = new MouvementStock($this->db);
// We decrement stock of product (and sub-products) // 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
// TODO Add price of product in method or '' to update PMP $result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty, $this->lignes[$i]->subprice);
$result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
if ($result < 0) { $error++; } if ($result < 0) { $error++; }
} }
} }
@ -958,34 +957,33 @@ class CommandeFournisseur extends Commande
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) if (! $resql)
{ {
$error = -1; $error = -1;
} }
// Si module stock gere et que expedition faite depuis un entrepot // Si module stock gere et que expedition faite depuis un entrepot
if (!$error && $conf->stock->enabled && $entrepot) if (!$error && $conf->stock->enabled && $entrepot)
{ {
$mouv = new MouvementStock($this->db); $mouv = new MouvementStock($this->db);
// TODO Add price of product in method or '' to update PMP $result=$mouv->reception($user, $product, $entrepot, $qty, $price);
$result=$mouv->reception($user, $product, $entrepot, $qty, $price); if ($result < 0)
if ($result < 0) {
{ $this->error=$this->db->error()." - sql=$sql";
$this->error=$this->db->error()." - sql=$sql"; dol_syslog("CommandeFournisseur::DispatchProduct".$this->error, LOG_ERR);
dol_syslog("CommandeFournisseur::DispatchProduct".$this->error, LOG_ERR); $error = -2;
$error = -2; }
} $i++;
$i++; }
}
if ($error == 0) if ($error == 0)
{ {
$this->db->commit(); $this->db->commit();
return 0; return 0;
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
} }
else else
{ {

View File

@ -458,8 +458,7 @@ class FactureFournisseur extends Facture
$mouvP = new MouvementStock($this->db); $mouvP = new MouvementStock($this->db);
// We increase stock for product // We increase stock for product
$entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot $entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot
// TODO Add price of product in method or '' to update PMP $result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty, $this->lignes[$i]->pu_ht);
$result=$mouvP->reception($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
if ($result < 0) { $error++; } if ($result < 0) { $error++; }
} }
} }

View File

@ -392,7 +392,7 @@ class Livraison extends CommonObject
dol_syslog("livraison.class.php::valid enregistrement des mouvements"); dol_syslog("livraison.class.php::valid enregistrement des mouvements");
$sql = "SELECT cd.fk_product, ld.qty "; $sql = "SELECT cd.fk_product, cd.subprice, ld.qty ";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
$sql.= ", ".MAIN_DB_PREFIX."livraisondet as ld"; $sql.= ", ".MAIN_DB_PREFIX."livraisondet as ld";
$sql.= " WHERE ld.fk_livraison = ".$this->id; $sql.= " WHERE ld.fk_livraison = ".$this->id;
@ -410,8 +410,7 @@ class Livraison extends CommonObject
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$mouvS = new MouvementStock($this->db); $mouvS = new MouvementStock($this->db);
// TODO Add price of product in method or '' to update PMP $result=$mouvS->livraison($user, $obj->fk_product, $this->entrepot_id, $obj->qty, $obj->subprice);
$result=$mouvS->livraison($user, $obj->fk_product, $this->entrepot_id, $obj->qty);
if ($result < 0) if ($result < 0)
{ {
$this->db->rollback(); $this->db->rollback();