Fix: Do not touch stock for service lines

This commit is contained in:
Laurent Destailleur 2008-06-17 18:03:36 +00:00
parent 67f11311cc
commit 7afa1f7067
3 changed files with 1068 additions and 1059 deletions

View File

@ -538,13 +538,13 @@ class Facture extends CommonObject
$sql.= ' l.remise, l.remise_percent, l.fk_remise_except, l.subprice,'; $sql.= ' l.remise, l.remise_percent, l.fk_remise_except, l.subprice,';
$sql.= ' '.$this->db->pdate('l.date_start').' as date_start,'.$this->db->pdate('l.date_end').' as date_end,'; $sql.= ' '.$this->db->pdate('l.date_start').' as date_start,'.$this->db->pdate('l.date_end').' as date_end,';
$sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc, l.fk_code_ventilation, l.fk_export_compta,'; $sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc, l.fk_code_ventilation, l.fk_export_compta,';
$sql.= ' p.label as label, p.description as product_desc'; $sql.= ' p.fk_product_type as fk_product_type, p.label as label, p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as l'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as l';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
$sql.= ' WHERE l.fk_facture = '.$this->id; $sql.= ' WHERE l.fk_facture = '.$this->id;
$sql.= ' ORDER BY l.rang'; $sql.= ' ORDER BY l.rang';
dolibarr_syslog('Facture::fetch_lines', LOG_DEBUG); dolibarr_syslog('Facture::fetch_lines sql='.$sql, LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
@ -554,10 +554,12 @@ class Facture extends CommonObject
{ {
$objp = $this->db->fetch_object($result); $objp = $this->db->fetch_object($result);
$faclig = new FactureLigne($this->db); $faclig = new FactureLigne($this->db);
$faclig->rowid = $objp->rowid; $faclig->rowid = $objp->rowid;
$faclig->desc = $objp->description; // Description ligne $faclig->desc = $objp->description; // Description ligne
$faclig->libelle = $objp->label; // Label produit $faclig->libelle = $objp->label; // Label produit
$faclig->product_desc = $objp->product_desc; // Description produit $faclig->product_desc = $objp->product_desc; // Description produit
$faclig->product_type = $objp->fk_product_type;
$faclig->qty = $objp->qty; $faclig->qty = $objp->qty;
$faclig->subprice = $objp->subprice; $faclig->subprice = $objp->subprice;
$faclig->tva_tx = $objp->tva_taux; $faclig->tva_tx = $objp->tva_taux;
@ -1009,6 +1011,7 @@ class Facture extends CommonObject
$this->db->begin(); $this->db->begin();
$this->fetch_client(); $this->fetch_client();
$this->fetch_lines();
// Verification paramètres // Verification paramètres
if ($this->type == 1) // si facture de remplacement if ($this->type == 1) // si facture de remplacement
@ -1121,8 +1124,6 @@ class Facture extends CommonObject
// On vérifie si la facture était une provisoire // On vérifie si la facture était une provisoire
if (! $error && $facref == 'PROV') if (! $error && $facref == 'PROV')
{ {
$this->fetch_lines();
// La vérif qu'une remise n'est pas utilisée 2 fois est faite au moment de l'insertion de ligne // La vérif qu'une remise n'est pas utilisée 2 fois est faite au moment de l'insertion de ligne
// On met a jour table des ventes // On met a jour table des ventes
@ -1151,6 +1152,11 @@ class Facture extends CommonObject
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{ {
if ($this->lignes[$i]->fk_product && $this->lignes[$i]->product_type == 0)
{
dolibarr_syslog("Facture::set_valid() correct stock for ".$this->lignes[$i]->rowid);
// It's a product
if ($conf->global->PRODUIT_SOUSPRODUITS) if ($conf->global->PRODUIT_SOUSPRODUITS)
{ {
$prod = new Product($this->db, $this->lignes[$i]->fk_product); $prod = new Product($this->db, $this->lignes[$i]->fk_product);
@ -1173,6 +1179,7 @@ class Facture extends CommonObject
$result=$mouvP->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty); $result=$mouvP->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
} }
} }
}
$this->ref = $numfa; $this->ref = $numfa;

View File

@ -149,7 +149,7 @@ class Product extends CommonObject
} }
/** /**
\brief Ins<EFBFBD>re le produit en base \brief Insert product in database
\param user Utilisateur qui effectue l'insertion \param user Utilisateur qui effectue l'insertion
\return int id du produit ou numero d'erreur < 0 \return int id du produit ou numero d'erreur < 0
*/ */
@ -236,7 +236,7 @@ class Product extends CommonObject
} }
else else
{ {
$this->_setErrNo("Create",260); $this->_setErrNo("Create",260,$this->error);
} }
} }
else else
@ -277,7 +277,7 @@ class Product extends CommonObject
else else
{ {
$this->db->rollback(); $this->db->rollback();
dolibarr_syslog("Product::Create ROLLBACK ERRNO (".$this->errno.")"); $this->_setErrNo("Create",265);
return -1; return -1;
} }
} }
@ -295,11 +295,12 @@ class Product extends CommonObject
\brief Positionne le numero d'erreur \brief Positionne le numero d'erreur
\param func Nom de la fonction \param func Nom de la fonction
\param num Numero de l'erreur \param num Numero de l'erreur
\param error string
*/ */
function _setErrNo($func, $num) function _setErrNo($func, $num, $error='')
{ {
$this->errno = $num; $this->errno = $num;
dolibarr_syslog("Product::".$func." - ".get_class($this) ." ERRNO (".$this->errno.")"); dolibarr_syslog(get_class($this)."::".$func." - ERRNO(".$this->errno.")".($error?' - '.$error:''), LOG_ERR);
} }
/** /**
@ -344,9 +345,9 @@ class Product extends CommonObject
$sql .= ",tva_tx = " . $this->tva_tx; $sql .= ",tva_tx = " . $this->tva_tx;
$sql .= ",envente = " . $this->status; $sql .= ",envente = " . $this->status;
$sql .= ",weight = " . ($this->weight!='' ? "'".$this->weight."'" : 'null'); $sql .= ",weight = " . ($this->weight!='' ? "'".$this->weight."'" : 'null');
$sql .= ",weight_units = '" . $this->weight_units."'"; $sql .= ",weight_units = " . ($this->weight_units!='' ? "'".$this->weight_units."'": 'null');
$sql .= ",volume = " . ($this->volume!='' ? "'".$this->volume."'" : 'null'); $sql .= ",volume = " . ($this->volume!='' ? "'".$this->volume."'" : 'null');
$sql .= ",volume_units = '" . $this->volume_units."'"; $sql .= ",volume_units = " . ($this->volume_units!='' ? "'".$this->volume_units."'" : 'null');
$sql .= ",seuil_stock_alerte = '" . $this->seuil_stock_alerte."'"; $sql .= ",seuil_stock_alerte = '" . $this->seuil_stock_alerte."'";
$sql .= ",description = '" . addslashes($this->description) ."'"; $sql .= ",description = '" . addslashes($this->description) ."'";
$sql .= ",stock_loc = '" . addslashes($this->stock_loc) ."'"; $sql .= ",stock_loc = '" . addslashes($this->stock_loc) ."'";
@ -355,7 +356,8 @@ class Product extends CommonObject
$sql .= " WHERE rowid = " . $id; $sql .= " WHERE rowid = " . $id;
dolibarr_syslog("Product::update sql=".$sql); dolibarr_syslog("Product::update sql=".$sql);
if ( $this->db->query($sql) ) $resql=$this->db->query($sql);
if ($resql)
{ {
// Multilangs // Multilangs
if($conf->global->MAIN_MULTILANGS) if($conf->global->MAIN_MULTILANGS)

View File

@ -114,12 +114,12 @@ if ($_POST["action"] == 'add' && $user->rights->produit->creer)
if ($id > 0) if ($id > 0)
{ {
Header("Location: fiche.php?id=$id"); Header("Location: fiche.php?id=".$id);
exit; exit;
} }
else else
{ {
$mesg='<div class="error">'.$langs->trans($product->error()).'</div>'; $mesg='<div class="error">'.$langs->trans($product->error).'</div>';
$_GET["action"] = "create"; $_GET["action"] = "create";
$_GET["canvas"] = $product->canvas; $_GET["canvas"] = $product->canvas;
$_GET["type"] = $_POST["type"]; $_GET["type"] = $_POST["type"];