Fix: bug #16894 overview: Problème avec les lignes produits libre de propal vers commande

This commit is contained in:
Laurent Destailleur 2006-06-20 21:53:00 +00:00
parent 17379431d3
commit e39a795a8d
3 changed files with 66 additions and 72 deletions

View File

@ -72,6 +72,7 @@ $NBLINES=4;
$form=new Form($db); $form=new Form($db);
/******************************************************************************/ /******************************************************************************/
/* Actions */ /* Actions */
/******************************************************************************/ /******************************************************************************/

View File

@ -61,6 +61,8 @@ class Commande extends CommonObject
var $date_livraison; // Date livraison souhaitée var $date_livraison; // Date livraison souhaitée
var $remise_percent; var $remise_percent;
var $remise_absolue; var $remise_absolue;
var $lines = array();
// Pour board // Pour board
var $nbtodo; var $nbtodo;
@ -97,6 +99,8 @@ class Commande extends CommonObject
*/ */
function create_from_propale($user, $propale_id) function create_from_propale($user, $propale_id)
{ {
dolibarr_syslog("Commande.class.php::create_from_propale propale_id=$propale_id");
$propal = new Propal($this->db); $propal = new Propal($this->db);
$propal->fetch($propale_id); $propal->fetch($propale_id);
@ -107,20 +111,14 @@ class Commande extends CommonObject
{ {
$CommLigne = new CommandeLigne($this->db); $CommLigne = new CommandeLigne($this->db);
$CommLigne->libelle = $propal->lignes[$i]->libelle; $CommLigne->libelle = $propal->lignes[$i]->libelle;
$CommLigne->description = $propal->lignes[$i]->desc; $CommLigne->desc = $propal->lignes[$i]->desc;
$CommLigne->price = $propal->lignes[$i]->subprice; $CommLigne->price = $propal->lignes[$i]->price;
$CommLigne->subprice = $propal->lignes[$i]->subprice; $CommLigne->subprice = $propal->lignes[$i]->subprice;
$CommLigne->tva_tx = $propal->lignes[$i]->tva_tx; $CommLigne->tva_tx = $propal->lignes[$i]->tva_tx;
$CommLigne->qty = $propal->lignes[$i]->qty; $CommLigne->qty = $propal->lignes[$i]->qty;
$CommLigne->remise_percent = $propal->lignes[$i]->remise_percent; $CommLigne->remise_percent = $propal->lignes[$i]->remise_percent;
$CommLigne->product_id = $propal->lignes[$i]->product_id; $CommLigne->fk_product = $propal->lignes[$i]->product_id;
$this->lines[$i] = $CommLigne; $this->lines[$i] = $CommLigne;
// \todo La methode create doit utiliser le tableau products plutot que lines
// ce qui permettrait de virer ces lignes
$this->products[$i]=$propal->lignes[$i]->product_id;
$this->products_qty[$i]=$propal->lignes[$i]->qty;
$this->products_remise_percent[$i]=$propal->lignes[$i]->remise_percent;
} }
$this->socidp = $propal->socidp; $this->socidp = $propal->socidp;
@ -276,7 +274,7 @@ class Commande extends CommonObject
require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/stock/mouvementstock.class.php");
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{ {
$prod = new Product($this->db, $this->lignes[$i]->product_id); $prod = new Product($this->db, $this->lignes[$i]->fk_product);
$prod -> get_sousproduits_arbo (); $prod -> get_sousproduits_arbo ();
$prods_arbo = $prod->get_each_prod(); $prods_arbo = $prod->get_each_prod();
if(sizeof($prods_arbo) > 0) if(sizeof($prods_arbo) > 0)
@ -291,7 +289,7 @@ class Commande extends CommonObject
} }
} }
// on décompte pas le stock du produit principal, ça serait fait manuellement avec l'expédition // on décompte pas le stock du produit principal, ça serait fait manuellement avec l'expédition
// $result=$mouvS->livraison($user, $this->lignes[$i]->product_id, $entrepot_id, $this->lignes[$i]->qty); // $result=$mouvS->livraison($user, $this->lignes[$i]->fk_product, $entrepot_id, $this->lignes[$i]->qty);
} }
} }
@ -368,7 +366,7 @@ class Commande extends CommonObject
$sql.= ' '.$this->db->idate($this->date_commande).','; $sql.= ' '.$this->db->idate($this->date_commande).',';
$sql.= ' '.$this->source.', '; $sql.= ' '.$this->source.', ';
$sql.= " '".addslashes($this->note)."', "; $sql.= " '".addslashes($this->note)."', ";
$sql.= " '".addslashes($this->ref_client)."', '".$this->modelpdf.'\', \''.$this->cond_reglement_id.'\', \''.$this->mode_reglement_id.'\','; $sql.= " '".addslashes($this->ref_client)."', '".$this->modelpdf."', '".$this->cond_reglement_id."', '".$this->mode_reglement_id."',";
$sql.= ' '.($this->date_livraison?$this->db->idate($this->date_livraison):'null').','; $sql.= ' '.($this->date_livraison?$this->db->idate($this->date_livraison):'null').',';
$sql.= " '".$this->adresse_livraison_id."',"; $sql.= " '".$this->adresse_livraison_id."',";
$sql.= " '".$this->remise_absolue."',"; $sql.= " '".$this->remise_absolue."',";
@ -386,34 +384,23 @@ class Commande extends CommonObject
/* /*
* Insertion des produits dans la base * Insertion des produits dans la base
*/ */
for ($i = 0 ; $i < sizeof($this->products) ; $i++) for ($i = 0 ; $i < sizeof($this->lines) ; $i++)
{ {
$prod = new Product($this->db, $this->products[$i]); $resql = $this->addline(
if ($prod->fetch($this->products[$i])) $this->id,
$this->lines[$i]->desc,
$this->lines[$i]->price,
$this->lines[$i]->qty,
$this->lines[$i]->tva_tx,
$this->lines[$i]->fk_product,
$this->lines[$i]->remise_percent
);
if ($resql < 0)
{ {
$tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx); $this->error=$this->db->error;
// multiprix dolibarr_print_error($this->db);
if($conf->global->PRODUIT_MULTIPRICES == 1) break;
$price = $prod->multiprices[$soc->price_level];
else
$price = $prod->price;
$resql = $this->addline(
$this->id,
$prod->description,
$price,
$this->products_qty[$i],
$tva_tx,
$this->products[$i],
$this->products_remise_percent[$i]
);
if ($resql < 0)
{
$this->error=$this->db->error;
dolibarr_print_error($this->db);
break;
}
} }
} }
@ -464,7 +451,7 @@ class Commande extends CommonObject
*/ */
function addline($commandeid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0) function addline($commandeid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
{ {
dolibarr_syslog("commande.class.php::addline this->id=$this->id, $commandeid, $desc, $pu, $qty, $txtva, $fk_product, $remise_percent"); dolibarr_syslog("Commande.class.php::addline this->id=$this->id, $commandeid, $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
if ($this->statut == 0) if ($this->statut == 0)
@ -566,16 +553,19 @@ class Commande extends CommonObject
function add_product($idproduct, $qty, $remise_percent=0) function add_product($idproduct, $qty, $remise_percent=0)
{ {
global $conf; global $conf;
if (!$qty) $qty = 1 ;
if ($idproduct > 0) if ($idproduct > 0)
{ {
$i = sizeof($this->products); $ligne=new CommandeLigne($this->db);
$this->products[$i] = $idproduct; $ligne->fk_product=$idproduct;
if (!$qty) $ligne->qty=$qty;
{ $ligne->remise_percent=$remise_percent;
$qty = 1 ;
} $i = sizeof($this->lines);
$this->products_qty[$i] = $qty; $this->lines[$i] = $ligne;
$this->products_remise_percent[$i] = $remise_percent;
/** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS À LA COMMANDE /** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS À LA COMMANDE
if($conf->global->PRODUIT_SOUSPRODUITS == 1) if($conf->global->PRODUIT_SOUSPRODUITS == 1)
{ {
@ -866,14 +856,15 @@ class Commande extends CommonObject
/** /**
* \brief Reinitialise le tableau lignes * \brief Reinitialise le tableau lignes
* \param only_product Ne renvoie que ligne liées à des produits physiques * \param only_product Ne renvoie que ligne liées à des produits physiques prédéfinis
* \return array Tableau de CommandeLigne * \return array Tableau de CommandeLigne
*/ */
function fetch_lignes($only_product=0) function fetch_lignes($only_product=0)
{ {
$this->lignes = array(); $this->lignes = array();
$sql = 'SELECT l.fk_product, l.fk_commande, l.description, l.price, l.qty, l.rowid, l.tva_tx,'; $sql = 'SELECT l.rowid, l.fk_product, l.fk_commande, l.description, l.price, l.qty, l.tva_tx,';
$sql.= ' l.remise_percent, l.subprice, l.rang, l.coef, l.label'; $sql.= ' l.remise_percent, l.subprice, l.rang, l.coef, l.label,';
$sql.= ' p.ref as product_ref, p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l'; $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (p.rowid = l.fk_product)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (p.rowid = l.fk_product)';
$sql.= ' WHERE l.fk_commande = '.$this->id; $sql.= ' WHERE l.fk_commande = '.$this->id;
@ -900,16 +891,14 @@ class Commande extends CommonObject
$ligne->subprice = $objp->subprice; $ligne->subprice = $objp->subprice;
$ligne->remise_percent = $objp->remise_percent; $ligne->remise_percent = $objp->remise_percent;
$ligne->price = $objp->price; $ligne->price = $objp->price;
$ligne->product_id = $objp->fk_product; $ligne->fk_product = $objp->fk_product;
$ligne->coef = $objp->coef; $ligne->coef = $objp->coef;
$ligne->rang = $objp->rang; $ligne->rang = $objp->rang;
$ligne->libelle = $objp->label; // Label ligne $ligne->libelle = $objp->label; // Label produit
$ligne->product_desc = $objp->product_desc; // Description produit $ligne->product_desc = $objp->product_desc; // Description produit
$ligne->ref = $objp->product_ref; $ligne->ref = $objp->product_ref;
$this->lignes[$i] = $ligne; $this->lignes[$i] = $ligne;
$i++; $i++;
} }
@ -1125,6 +1114,9 @@ class Commande extends CommonObject
$sql = "SELECT price, qty, tva_tx, total_ht, total_tva, total_ttc"; $sql = "SELECT price, qty, tva_tx, total_ht, total_tva, total_ttc";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet"; $sql.= " FROM ".MAIN_DB_PREFIX."commandedet";
$sql.= " WHERE fk_commande = ".$this->id; $sql.= " WHERE fk_commande = ".$this->id;
dolibarr_syslog("Commande.class.php::update_price this->id=".$this->id);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
@ -1826,25 +1818,25 @@ class Commande extends CommonObject
class CommandeLigne class CommandeLigne
{ {
var $db; var $db;
var $error; var $error;
// From llx_commandedet // From llx_commandedet
var $rowid; var $rowid;
var $fk_facture; var $fk_facture;
var $desc; // Description ligne var $desc; // Description ligne
var $product_id; // Id produit prédéfini
var $label;
var $qty; var $qty;
var $tva_tx; var $tva_tx;
var $subprice; var $subprice;
var $remise; var $remise;
var $remise_percent; var $remise_percent;
var $price; var $price;
var $rang; var $rang;
var $coef; var $coef;
var $fk_product; // Id produit prédéfini
var $info_bits; // Bit 0: 0 si TVA normal - 1 si TVA NPR var $info_bits; // Bit 0: 0 si TVA normal - 1 si TVA NPR
var $total_ht; // Total HT de la ligne toute quantité et incluant la remise ligne var $total_ht; // Total HT de la ligne toute quantité et incluant la remise ligne
var $total_tva; // Total TVA de la ligne toute quantité et incluant la remise ligne var $total_tva; // Total TVA de la ligne toute quantité et incluant la remise ligne
@ -1934,7 +1926,7 @@ class CommandeLigne
$sql.= " '".price2num($this->qty)."',"; $sql.= " '".price2num($this->qty)."',";
$sql.= " '".price2num($this->tva_tx)."',"; $sql.= " '".price2num($this->tva_tx)."',";
if ($this->fk_product) { $sql.= "'".$this->fk_product."',"; } if ($this->fk_product) { $sql.= "'".$this->fk_product."',"; }
else { $sql.='0,'; } else { $sql.='null,'; }
$sql.= " '".price2num($this->remise_percent)."',"; $sql.= " '".price2num($this->remise_percent)."',";
$sql.= " '".price2num($this->subprice)."',"; $sql.= " '".price2num($this->subprice)."',";
$sql.= " '".price2num($this->remise)."',"; $sql.= " '".price2num($this->remise)."',";
@ -1949,7 +1941,7 @@ class CommandeLigne
$sql.= " '".price2num($this->total_ttc)."'"; $sql.= " '".price2num($this->total_ttc)."'";
$sql.= ')'; $sql.= ')';
dolibarr_syslog("CommandeLigne::insert sql=$sql"); dolibarr_syslog("CommandeLigne.class.php::insert sql=$sql");
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -1960,7 +1952,7 @@ class CommandeLigne
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
dolibarr_syslog("CommandeLigne::insert Error ".$this->error); dolibarr_syslog("CommandeLigne.class.php::insert Error ".$this->error);
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
@ -1994,7 +1986,7 @@ class CommandeLigne
$sql.= ",total_ttc='".price2num($this->total_ttc)."'"; $sql.= ",total_ttc='".price2num($this->total_ttc)."'";
$sql.= " WHERE rowid = ".$this->rowid; $sql.= " WHERE rowid = ".$this->rowid;
dolibarr_syslog("CommandeLigne::update sql=$sql"); dolibarr_syslog("CommandeLigne.class.php::update sql=$sql");
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -2005,7 +1997,7 @@ class CommandeLigne
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
dolibarr_syslog("CommandeLigne::update Error ".$this->error); dolibarr_syslog("CommandeLigne.class.php::update Error ".$this->error);
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }

View File

@ -830,7 +830,7 @@ class Propal extends CommonObject
* Lignes propales liées à un produit ou non * Lignes propales liées à un produit ou non
*/ */
$sql = "SELECT d.description, d.price, d.tva_tx, d.qty, d.remise_percent, d.subprice, d.fk_product,"; $sql = "SELECT d.description, d.price, d.tva_tx, d.qty, d.remise_percent, d.subprice, d.fk_product,";
$sql.= " d.total_ht, d.total_tva, d.total_ttc,"; $sql.= " d.total_ht, d.total_tva, d.total_ttc, d.coef, d.rang,";
$sql.= " p.ref, p.label, p.description as product_desc"; $sql.= " p.ref, p.label, p.description as product_desc";
$sql.= " FROM ".MAIN_DB_PREFIX."propaldet as d"; $sql.= " FROM ".MAIN_DB_PREFIX."propaldet as d";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid";
@ -859,17 +859,18 @@ class Propal extends CommonObject
$ligne->total_ht = $objp->total_ht; $ligne->total_ht = $objp->total_ht;
$ligne->total_tva = $objp->total_tva; $ligne->total_tva = $objp->total_tva;
$ligne->total_ttc = $objp->total_ttc; $ligne->total_ttc = $objp->total_ttc;
$ligne->coef = $objp->coef;
$ligne->rang = $objp->rang;
$ligne->product_id = $objp->fk_product; $ligne->product_id = $objp->fk_product;
$ligne->coef = $objp->coef;
$ligne->libelle = $objp->label; // Label produit $ligne->libelle = $objp->label; // Label produit
$ligne->product_desc = $objp->product_desc; // Description produit $ligne->product_desc = $objp->product_desc; // Description produit
$ligne->ref = $objp->ref; $ligne->ref = $objp->ref;
$this->lignes[$i] = $ligne; $this->lignes[$i] = $ligne;
//dolibarr_syslog("1 ".$ligne->desc); //dolibarr_syslog("1 ".$ligne->product_id);
//print "xx $i ".$this->lignes[$i]->libelle; //print "xx $i ".$this->lignes[$i]->product_id;
$i++; $i++;
} }
$this->db->free($result); $this->db->free($result);
@ -1211,7 +1212,7 @@ class Propal extends CommonObject
$this->db->begin(); $this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."propal"; $sql = "UPDATE ".MAIN_DB_PREFIX."propal";
$sql.= " SET fk_statut = $statut, note = '".addslashes($note)."', date_cloture=now(), fk_user_cloture=".$user->id; $sql.= " SET fk_statut = ".$statut.", note = '".addslashes($note)."', date_cloture=now(), fk_user_cloture=".$user->id;
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);