Incremente/Decremente les stocks pour les sous-produits

This commit is contained in:
Rodolphe Quiedeville 2007-03-26 11:45:37 +00:00
parent d7dd1c7c92
commit 0fa261ad0c

View File

@ -123,6 +123,11 @@ class MouvementStock
$error = $this->CalculateEntrepotValoPmp($user, $entrepot_id, $valo_mouvement); $error = $this->CalculateEntrepotValoPmp($user, $entrepot_id, $valo_mouvement);
} }
if ($error === 0)
{
$error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, $price=0);
}
if ($error === 0) if ($error === 0)
{ {
$this->db->commit(); $this->db->commit();
@ -137,6 +142,45 @@ class MouvementStock
return -2; return -2;
} }
} }
/**
* \brief Crée un mouvement en base pour tous les sous-produits
* \return int <0 si ko, 0 si ok
*/
function _createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, $price=0)
{
$error = 0;
dolibarr_syslog("MouvementStock::_CreateSubProduct $user->id, $fk_product, $entrepot_id, $qty, $type, $price");
pids = array();
$sql = "SELECT fk_product_subproduct FROM ".MAIN_DB_PREFIX."product_subproduct";
$sql.= " WHERE fk_product = $fk_product;";
if ($this->db->query($sql))
{
while ($row = $this->db->fetch_row($resql) )
{
array_push($row[0]);
}
$this->db->free($resql);
}
else
{
dolibarr_syslog("MouvementStock::_Create echec update ".$this->error);
$error = -2;
}
foreach($pids as $pid)
{
$this->_create($user, $pid, $entrepot_id, $qty, $type, $price=0)
}
return $error;
}
/** /**
* \brief Crée un mouvement en base * \brief Crée un mouvement en base
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok