Mets a jour les infos de stock des produits

This commit is contained in:
Rodolphe Quiedeville 2006-12-01 21:35:44 +00:00
parent 0b9d9ed8ef
commit 2b4d773f66

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2006 Regis Houssin <regis.houssin@cap-networks.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
@ -29,9 +29,9 @@
\version $Revision$
*/
require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php");
require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php");
require_once(DOL_DOCUMENT_ROOT."/product.class.php");
require_once(DOL_DOCUMENT_ROOT ."/contact.class.php");
require_once(DOL_DOCUMENT_ROOT."/contact.class.php");
/**
@ -1189,7 +1189,23 @@ class Commande extends CommonObject
{
if ($this->statut == 0)
{
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE rowid = $idligne";
$sql = "SELECT fk_product, qty";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet";
$sql.= " WHERE rowid = '$idligne';";
$result = $this->db->query($sql);
if ($result)
{
while ($obj = $this->db->fetch_object($result))
{
$product = new Product($this->db);
$product->id = $obj->fk_product;
$product->ajust_stock_commande($obj->qty, 1);
}
$this->db->free($result);
}
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE rowid = '$idligne';";
if ($this->db->query($sql) )
{
$this->update_price();
@ -1304,17 +1320,17 @@ class Commande extends CommonObject
// Anciens indicateurs
$this->amount_ht += $obj->price * $obj->qty;
$this->total_remise += 0; // Plus de remise globale (toute remise est sur une ligne)
/* \deprecated car simplifie par les 3 indicateurs total_ht, total_tva et total_ttc sur lignes
/* \deprecated car simplifie par les 3 indicateurs total_ht, total_tva et total_ttc sur lignes
$products[$i][0] = $obj->price;
$products[$i][1] = $obj->qty;
$products[$i][2] = $obj->tva_tx;
*/
*/
$i++;
}
$this->db->free($result);
}
/* \deprecated car simplifie par les 3 indicateurs total_ht, total_tva et total_ttc sur lignes
/* \deprecated car simplifie par les 3 indicateurs total_ht, total_tva et total_ttc sur lignes
$calculs = calcul_price($products, $this->remise_percent, $this->remise_absolue);
$this->total_remise = $calculs[3];
$this->amount_ht = $calculs[4];
@ -1677,6 +1693,10 @@ class Commande extends CommonObject
$price = price2num($price);
$subprice = price2num($subprice);
$LigneOld = new CommandeLigne($this->db);
$LigneOld->fetch($rowid);
// Mise a jour ligne en base
$sql = "UPDATE ".MAIN_DB_PREFIX."commandedet SET";
$sql.= " description='".addslashes($desc)."'";
@ -1701,6 +1721,17 @@ class Commande extends CommonObject
{
// Mise a jour info denormalisees au niveau facture
$this->update_price($this->id);
if ($LigneOld->qty <> $qty && $LigneOld->produit_id)
{
$delta = $qty - $LigneOld->qty;
$op = ($delta > 0) ? 0 : 1;
$product = new Product($this->db);
$product->id = $LigneOld->produit_id;
$product->ajust_stock_commande(abs($delta), $op);
}
$this->db->commit();
return $result;
}
@ -2212,6 +2243,14 @@ class CommandeLigne
dolibarr_syslog("CommandeLigne.class.php::insert sql=$sql");
if ($this->fk_product)
{
$product = new Product($this->db);
$product->id = $this->fk_product;
$product->ajust_stock_commande($this->qty, 0);
}
$resql=$this->db->query($sql);
if ($resql)
{
@ -2259,7 +2298,6 @@ class CommandeLigne
return -2;
}
}
}
?>