diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index f7295f04894..1084a0deb2f 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -117,7 +117,7 @@ class Commande extends CommonObject $CommLigne->tva_tx = $propal->lignes[$i]->tva_tx; $CommLigne->qty = $propal->lignes[$i]->qty; $CommLigne->remise_percent = $propal->lignes[$i]->remise_percent; - $CommLigne->fk_product = $propal->lignes[$i]->product_id; + $CommLigne->fk_product = $propal->lignes[$i]->fk_product; $this->lines[$i] = $CommLigne; } @@ -1984,30 +1984,18 @@ class CommandeLigne * \brief Mise a jour de l'objet ligne de commande en base * \return int <0 si ko, >0 si ok */ - function update() + function update_total() { $this->db->begin(); // Mise a jour ligne en base $sql = "UPDATE ".MAIN_DB_PREFIX."commandedet SET"; - $sql.= " description='".addslashes($this->desc)."'"; - $sql.= ",price='".price2num($this->price)."'"; - $sql.= ",subprice='".price2num($this->subprice)."'"; - $sql.= ",remise='".price2num($this->remise)."'"; - $sql.= ",remise_percent='".price2num($this->remise_percent)."'"; - if ($fk_remise_except) $sql.= ",fk_remise_except=".$this->fk_remise_except; - else $sql.= ",fk_remise_except=null"; - $sql.= ",tva_tx='".price2num($this->tva_tx)."'"; - $sql.= ",qty='".price2num($this->qty)."'"; - $sql.= ",rang='".$this->rang."'"; - $sql.= ",coef='".$this->coef."'"; - $sql.= ",info_bits='".$this->info_bits."'"; - $sql.= ",total_ht='".price2num($this->total_ht)."'"; + $sql.= " total_ht='".price2num($this->total_ht)."'"; $sql.= ",total_tva='".price2num($this->total_tva)."'"; $sql.= ",total_ttc='".price2num($this->total_ttc)."'"; $sql.= " WHERE rowid = ".$this->rowid; - dolibarr_syslog("CommandeLigne.class.php::update sql=$sql"); + dolibarr_syslog("CommandeLigne.class.php::update_total sql=$sql"); $resql=$this->db->query($sql); if ($resql) @@ -2018,7 +2006,7 @@ class CommandeLigne else { $this->error=$this->db->error(); - dolibarr_syslog("CommandeLigne.class.php::update Error ".$this->error); + dolibarr_syslog("CommandeLigne.class.php::update_total Error ".$this->error); $this->db->rollback(); return -2; } diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index f8fc118d86d..1cf3f27cd8b 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -256,7 +256,7 @@ if ($_POST['action'] == 'add') $prop->lignes[$i]->subprice, $prop->lignes[$i]->qty, $prop->lignes[$i]->tva_tx, - $prop->lignes[$i]->product_id, + $prop->lignes[$i]->fk_product, $prop->lignes[$i]->remise_percent); } } @@ -339,7 +339,7 @@ if ($_POST['action'] == 'add') $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, - $lines[$i]->product_id, + $lines[$i]->fk_product, $lines[$i]->remise_percent, $date_start, $date_end); diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php index a4410cc94c0..8b1afb3d95a 100644 --- a/htdocs/contrat/contrat.class.php +++ b/htdocs/contrat/contrat.class.php @@ -364,7 +364,7 @@ class Contrat extends CommonObject $ligne->statut = $objp->statut; $ligne->remise_percent = $objp->remise_percent; $ligne->price = $objp->price; - $ligne->product_id = $objp->rowid; + $ligne->fk_product = $objp->rowid; $ligne->date_debut_prevue = $objp->date_ouverture_prevue; $ligne->date_debut_reel = $objp->date_ouverture; @@ -412,7 +412,7 @@ class Contrat extends CommonObject $ligne->subprice = $objp->subprice; $ligne->remise_percent = $objp->remise_percent; $ligne->price = $objp->price; - $ligne->product_id = 0; + $ligne->fk_product = 0; $ligne->date_debut_prevue = $objp->date_ouverture_prevue; $ligne->date_debut_reel = $objp->date_ouverture; @@ -1096,7 +1096,7 @@ class ContratLigne var $subprice; var $remise_percent; var $price; - var $product_id; + var $fk_product; var $statut; var $date_debut_prevue; diff --git a/htdocs/expedition/commande.php b/htdocs/expedition/commande.php index 9dc5e2647dd..5c8b4c94140 100644 --- a/htdocs/expedition/commande.php +++ b/htdocs/expedition/commande.php @@ -471,7 +471,7 @@ if ($_GET["id"] > 0) { if ($value > 0) { - $sql = "SELECT e.rowid as entrepot_id, e.label as entrepot, ps.reel, p.label, p.ref, p.rowid as product_id"; + $sql = "SELECT e.rowid as entrepot_id, e.label as entrepot, ps.reel, p.label, p.ref, p.rowid as fk_product"; $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e, ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product as p"; $sql .= " WHERE e.rowid = ps.fk_entrepot AND ps.fk_product = p.rowid AND ps.fk_product = $key"; $sql .= " AND e.statut = 1 AND reel < $value"; @@ -488,7 +488,7 @@ if ($_GET["id"] > 0) $obja = $db->fetch_object($resql); print ""; print ''; - print ''.img_object($langs->trans("ShowProduct"),"product").' '.$obja->ref.' - '.$obja->label; + print ''.img_object($langs->trans("ShowProduct"),"product").' '.$obja->ref.' - '.$obja->label; print ''.$obja->entrepot.''; print 'Stock : '.$obja->reel.'' .img_warning($langs->trans("Alert")).''; print "\n"; diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php index 4507af3d48a..839a99f90d8 100644 --- a/htdocs/expedition/expedition.class.php +++ b/htdocs/expedition/expedition.class.php @@ -165,7 +165,7 @@ class Expedition extends CommonObject { if ($this->commande->lignes[$j]->id == $commande_ligne_id) { - $idprod = $this->commande->lignes[$j]->product_id; + $idprod = $this->commande->lignes[$j]->fk_product; } $j++; } @@ -250,7 +250,7 @@ class Expedition extends CommonObject $ligne->commande_ligne_id = $objp->fk_commande_ligne; $ligne->product_desc = $objp->description; // Description ligne $ligne->qty_commande = $objp->qtycom; - $ligne->product_id = $objp->fk_product; + $ligne->fk_product = $objp->fk_product; $ligne->libelle = $objp->label; // Label produit $ligne->ref = $objp->ref; @@ -571,7 +571,7 @@ class Expedition extends CommonObject $ligne = new ExpeditionLigne(); $obj = $this->db->fetch_object($resql); - $ligne->product_id = $obj->fk_product; + $ligne->fk_product = $obj->fk_product; $ligne->qty_commande = $obj->qtycom; $ligne->qty_expedition = $obj->qtyexp; $ligne->description = stripslashes($obj->description); @@ -588,20 +588,22 @@ class Expedition extends CommonObject class ExpeditionLigne { - // From llx_expeditiondet - var $qty; - var $qty_expedition; - var $product_id; + var $db; - // From llx_commandedet - var $qty_commande; - var $libelle; // Label produit - var $product_desc; // Description produit - var $ref; + // From llx_expeditiondet + var $qty; + var $qty_expedition; + var $fk_product; + + // From llx_commandedet + var $qty_commande; + var $libelle; // Label produit + var $product_desc; // Description produit + var $ref; - function ExpeditionLigne() + function ExpeditionLigne($DB) { - + $this->db=$DB; } } diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index 695ec52da8e..d31ad85308c 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -250,13 +250,13 @@ if ($_GET["action"] == 'create') $ligne = $commande->lignes[$i]; $var=!$var; print "\n"; - if ($ligne->product_id > 0) + if ($ligne->fk_product > 0) { $product = new Product($db); - $product->fetch($ligne->product_id); + $product->fetch($ligne->fk_product); print ''; - print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; + print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; if ($ligne->description) print nl2br($ligne->description); print ''; } @@ -270,7 +270,7 @@ if ($_GET["action"] == 'create') * */ print ''; - $quantite_livree = $commande->expeditions[$ligne->product_id]; + $quantite_livree = $commande->expeditions[$ligne->fk_product]; print $quantite_livree;; print ''; diff --git a/htdocs/expedition/mods/pdf/pdf_expedition_dorade.modules.php b/htdocs/expedition/mods/pdf/pdf_expedition_dorade.modules.php index ae8711a9552..6f52f9de5cc 100644 --- a/htdocs/expedition/mods/pdf/pdf_expedition_dorade.modules.php +++ b/htdocs/expedition/mods/pdf/pdf_expedition_dorade.modules.php @@ -115,7 +115,7 @@ Class pdf_expedition_dorade extends ModelePdfExpedition { $a = $this->pdf->tableau_top + 14 + ($i * 16); - $this->pdf->i25(8, ($a - 2), "000000".$this->expe->lignes[$i]->product_id, 1, 8); + $this->pdf->i25(8, ($a - 2), "000000".$this->expe->lignes[$i]->fk_product, 1, 8); $this->pdf->Text(40, $a, $this->expe->lignes[$i]->description); diff --git a/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php b/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php index d0a9191847d..a91f935f319 100644 --- a/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php +++ b/htdocs/expedition/mods/pdf/pdf_expedition_merou.modules.php @@ -132,7 +132,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition for ($i = 0 ; $i < $nblignes ; $i++){ //Generation du produit $Prod = new Product($this->db); - $Prod->fetch($Produits[$i]->product_id); + $Prod->fetch($Produits[$i]->fk_product); //Creation des cases à cocher $pdf->rect(10+3, $curY+1, 3, 3); $pdf->rect(20+3, $curY+1, 3, 3); diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index ccd02b2bb6f..4c6fe314962 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -2104,9 +2104,8 @@ class FactureLigne // From llx_facturedet var $rowid; - var $fk_facture; var $desc; // Description ligne - var $product_id; // Id produit prédéfini + var $fk_facture; // Id produit prédéfini var $qty; // Quantité (exemple 2) var $subprice; // P.U. HT (exemple 100) @@ -2300,6 +2299,38 @@ class FactureLigne return -2; } } + + /** + * \brief Mise a jour en base des champs total_xxx de ligne de facture + * \return int <0 si ko, >0 si ok + */ + function update_total() + { + $this->db->begin(); + + // Mise a jour ligne en base + $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet SET"; + $sql.= " total_ht='".price2num($this->total_ht)."'"; + $sql.= ",total_tva='".price2num($this->total_tva)."'"; + $sql.= ",total_ttc='".price2num($this->total_ttc)."'"; + $sql.= " WHERE rowid = ".$this->rowid; + + dolibarr_syslog("FactureLigne::update_total sql=$sql"); + + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("FactureLigne::update_total Error ".$this->error); + $this->db->rollback(); + return -2; + } + } } ?> diff --git a/htdocs/fourn/commande/modules/pdf/pdf_muscadet.modules.php b/htdocs/fourn/commande/modules/pdf/pdf_muscadet.modules.php index d925422c284..1bb34496258 100644 --- a/htdocs/fourn/commande/modules/pdf/pdf_muscadet.modules.php +++ b/htdocs/fourn/commande/modules/pdf/pdf_muscadet.modules.php @@ -207,11 +207,11 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $libelleproduitservice.=$com->lignes[$i]->desc; } // Si ligne associée à un code produit - if ($com->lignes[$i]->product_id) + if ($com->lignes[$i]->fk_product) { $prodser = new Product($this->db); - $prodser->fetch($com->lignes[$i]->product_id); + $prodser->fetch($com->lignes[$i]->fk_product); if ($prodser->ref) { $libelleproduitservice=$langs->trans("Product")." ".$prodser->ref." - ".$libelleproduitservice; diff --git a/htdocs/fourn/fournisseur.class.php b/htdocs/fourn/fournisseur.class.php index a21ee737511..45180a72066 100644 --- a/htdocs/fourn/fournisseur.class.php +++ b/htdocs/fourn/fournisseur.class.php @@ -131,7 +131,7 @@ class Fournisseur extends Societe } - function ProductCommande($user, $product_id) + function ProductCommande($user, $fk_product) { include_once(DOL_DOCUMENT_ROOT."/fourn/fournisseur.commande.class.php"); include_once(DOL_DOCUMENT_ROOT."/product.class.php"); @@ -158,7 +158,7 @@ class Fournisseur extends Societe if ($idc > 0) { $prod = new Product($this->db); - $prod->fetch($product_id); + $prod->fetch($fk_product); $prod->fetch_fourn_data($this->id); $commf->fetch($idc); diff --git a/htdocs/fourn/fournisseur.commande.class.php b/htdocs/fourn/fournisseur.commande.class.php index 204f7aaae12..11493e41d75 100644 --- a/htdocs/fourn/fournisseur.commande.class.php +++ b/htdocs/fourn/fournisseur.commande.class.php @@ -133,7 +133,7 @@ class CommandeFournisseur extends Commande $ligne->subprice = $objp->subprice; $ligne->remise_percent = $objp->remise_percent; $ligne->price = $objp->price; - $ligne->product_id = $objp->fk_product; + $ligne->fk_product = $objp->fk_product; $ligne->libelle = $objp->label; // Label produit $ligne->product_desc = $objp->product_desc; // Description produit @@ -1014,7 +1014,7 @@ class CommandeFournisseurLigne extends CommandeLigne var $subprice; var $remise_percent; var $price; - var $product_id; + var $fk_product; var $desc; // Description ligne // From llx_product diff --git a/htdocs/includes/modules/propale/pdf_propale_azur.modules.php b/htdocs/includes/modules/propale/pdf_propale_azur.modules.php index 227f4a547bb..2942c17b2c1 100644 --- a/htdocs/includes/modules/propale/pdf_propale_azur.modules.php +++ b/htdocs/includes/modules/propale/pdf_propale_azur.modules.php @@ -232,11 +232,11 @@ class pdf_propale_azur extends ModelePDFPropales $libelleproduitservice.=$propale->lignes[$i]->desc; } // Si ligne associée à un code produit - if ($propale->lignes[$i]->product_id) + if ($propale->lignes[$i]->fk_product) { $prodser = new Product($this->db); - $prodser->fetch($propale->lignes[$i]->product_id); + $prodser->fetch($propale->lignes[$i]->fk_product); if ($prodser->ref) { $prefix_prodserv = ""; diff --git a/htdocs/livraison/fiche.php b/htdocs/livraison/fiche.php index 2f1e27d5393..c1ff83cb90d 100644 --- a/htdocs/livraison/fiche.php +++ b/htdocs/livraison/fiche.php @@ -268,13 +268,13 @@ if ($_GET["action"] == 'create') $ligne = $commande->lignes[$i]; $var=!$var; print "\n"; - if ($ligne->product_id > 0) + if ($ligne->fk_product > 0) { $product = new Product($db); - $product->fetch($ligne->product_id); + $product->fetch($ligne->fk_product); print ''; - print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; + print ''.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.' - '.$product->libelle; if ($ligne->description) print nl2br($ligne->description); print ''; } @@ -288,7 +288,7 @@ if ($_GET["action"] == 'create') * */ print ''; - $quantite_livree = $commande->livraisons[$ligne->product_id]; + $quantite_livree = $commande->livraisons[$ligne->fk_product]; print $quantite_livree;; print ''; diff --git a/htdocs/livraison/livraison.class.php b/htdocs/livraison/livraison.class.php index 510025a70ae..baca52931fe 100644 --- a/htdocs/livraison/livraison.class.php +++ b/htdocs/livraison/livraison.class.php @@ -173,7 +173,7 @@ class Livraison extends CommonObject { if ($this->commande->lignes[$j]->id == $commande_ligne_id) { - $idprod = $this->commande->lignes[$j]->product_id; + $idprod = $this->commande->lignes[$j]->fk_product; } $j++; } @@ -427,7 +427,7 @@ class Livraison extends CommonObject $LivraisonLigne->libelle = $expedition->lignes[$i]->libelle; $LivraisonLigne->description = $expedition->lignes[$i]->product_desc; $LivraisonLigne->qty = $expedition->lignes[$i]->qty_commande; - $LivraisonLigne->product_id = $expedition->lignes[$i]->product_id; + $LivraisonLigne->fk_product = $expedition->lignes[$i]->fk_product; $LivraisonLigne->ref = $expedition->lignes[$i]->ref; $this->lignes[$i] = $LivraisonLigne; } @@ -585,7 +585,7 @@ class Livraison extends CommonObject $obj = $this->db->fetch_object($resql); - $ligne->product_id = $obj->fk_product; + $ligne->fk_product = $obj->fk_product; $ligne->qty_commande = $obj->qtycom; $ligne->qty_livre = $obj->qtyliv; $ligne->ref = $obj->ref; diff --git a/htdocs/livraison/mods/pdf/pdf_typhon.modules.php b/htdocs/livraison/mods/pdf/pdf_typhon.modules.php index ecf529c1eee..9a3e928802d 100644 --- a/htdocs/livraison/mods/pdf/pdf_typhon.modules.php +++ b/htdocs/livraison/mods/pdf/pdf_typhon.modules.php @@ -208,11 +208,11 @@ class pdf_typhon extends ModelePDFDeliveryOrder $libelleproduitservice.=$lignesdelivery[$i]->description; } // Si ligne associée à un code produit - if ($lignesdelivery[$i]->product_id) + if ($lignesdelivery[$i]->fk_product) { $prodser = new Product($this->db); - $prodser->fetch($lignesdelivery[$i]->product_id); + $prodser->fetch($lignesdelivery[$i]->fk_product); if ($prodser->ref) { $libelleproduitservice=$langs->trans("Product")." ".$prodser->ref." - ".$libelleproduitservice; diff --git a/htdocs/product/stock/mouvementstock.class.php b/htdocs/product/stock/mouvementstock.class.php index 8f2882264a9..0a793dda519 100644 --- a/htdocs/product/stock/mouvementstock.class.php +++ b/htdocs/product/stock/mouvementstock.class.php @@ -44,20 +44,20 @@ class MouvementStock * \brief Crée un mouvement en base * \return int <0 si ko, >0 si ok */ - function _create($user, $product_id, $entrepot_id, $qty, $type) + function _create($user, $fk_product, $entrepot_id, $qty, $type) { - dolibarr_syslog("mouvementstock.class.php::create $user, $product_id, $entrepot_id, $qty, $type"); + dolibarr_syslog("mouvementstock.class.php::create $user, $fk_product, $entrepot_id, $qty, $type"); $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author)"; - $sql .= " VALUES (now(), $product_id, $entrepot_id, $qty, $type, $user->id)"; + $sql .= " VALUES (now(), $fk_product, $entrepot_id, $qty, $type, $user->id)"; if ($this->db->query($sql)) { $sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET reel = reel + $qty"; - $sql.= " WHERE fk_entrepot = $entrepot_id AND fk_product = $product_id"; + $sql.= " WHERE fk_entrepot = $entrepot_id AND fk_product = $fk_product"; if ($this->db->query($sql)) { @@ -87,10 +87,10 @@ class MouvementStock * * */ - function livraison($user, $product_id, $entrepot_id, $qty) + function livraison($user, $fk_product, $entrepot_id, $qty) { - return $this->_create($user, $product_id, $entrepot_id, (0 - $qty), 2); + return $this->_create($user, $fk_product, $entrepot_id, (0 - $qty), 2); } diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 1a10222754b..bf943cc62e6 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -862,15 +862,15 @@ class Propal extends CommonObject $ligne->coef = $objp->coef; $ligne->rang = $objp->rang; - $ligne->product_id = $objp->fk_product; + $ligne->fk_product = $objp->fk_product; $ligne->libelle = $objp->label; // Label produit $ligne->product_desc = $objp->product_desc; // Description produit $ligne->ref = $objp->ref; $this->lignes[$i] = $ligne; - //dolibarr_syslog("1 ".$ligne->product_id); - //print "xx $i ".$this->lignes[$i]->product_id; + //dolibarr_syslog("1 ".$ligne->fk_product); + //print "xx $i ".$this->lignes[$i]->fk_product; $i++; } $this->db->free($result); @@ -1922,7 +1922,7 @@ class Propal extends CommonObject $price, $ligne->qty, $tva_tx, - $ligne->product_id, + $ligne->fk_product, $ligne->remise_percent ); @@ -2065,7 +2065,7 @@ class PropaleLigne var $rowid; var $fk_propal; var $desc; // Description ligne - var $product_id; // Id produit prédéfini + var $fk_product; // Id produit prédéfini var $qty; var $tva_tx; @@ -2239,7 +2239,39 @@ class PropaleLigne return -2; } } - + + /** + * \brief Mise a jour an base des champs total_xxx de ligne de propale + * \return int <0 si ko, >0 si ok + */ + function update_total() + { + $this->db->begin(); + + // Mise a jour ligne en base + $sql = "UPDATE ".MAIN_DB_PREFIX."propaldet SET"; + $sql.= " total_ht='".price2num($this->total_ht)."'"; + $sql.= ",total_tva='".price2num($this->total_tva)."'"; + $sql.= ",total_ttc='".price2num($this->total_ttc)."'"; + $sql.= " WHERE rowid = ".$this->rowid; + + dolibarr_syslog("PropaleLigne::update_total sql=$sql"); + + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("PropaleLigne::update_total Error ".$this->error); + $this->db->rollback(); + return -2; + } + } + } ?>