From 6559c4fbc27d65221ae9c558d2c1c2f4f4e63553 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 4 Nov 2005 20:24:40 +0000 Subject: [PATCH] =?UTF-8?q?New:=20Possibilit=E9=20de=20modifier=20la=20dat?= =?UTF-8?q?e=20de=20fin=20de=20validit=E9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/facture.class.php | 19 ++--- htdocs/propal.class.php | 154 ++++++++++++++++++++++++--------------- 2 files changed, 105 insertions(+), 68 deletions(-) diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 481ae3173d4..dd6ca58844b 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -955,7 +955,7 @@ class Facture } /** - * \brief Ajoute une ligne de facture (associé à aucun produit/service prédéfini) + * \brief Ajoute une ligne de facture (associé à un produit/service prédéfini ou non) * \param facid id de la facture * \param desc description de la ligne * \param pu prix unitaire @@ -973,6 +973,8 @@ class Facture if ($this->brouillon) { // Nettoyage paramètres + $remise_percent=price2num($remise_percent); + $qty=price2num($qty); if (strlen(trim($qty))==0) $qty=1; if ($fk_product && ! $pu) @@ -982,12 +984,11 @@ class Facture $pu=$prod->price; $txtva=$prod->tva_tx; } - $_price = $pu; + $price = $pu; $subprice = $pu; + // Calcul remise et nouveau prix $remise = 0; - $remise_percent = trim($remise_percent); - if ($this->socidp) { $soc = new Societe($this->db); @@ -1001,11 +1002,11 @@ class Facture if ($remise_percent > 0) { - $remise = ($pu * $remise_percent / 100); - $_price = ($pu - $remise); + $remise = round(($pu * $remise_percent / 100),2); + $price = ($pu - $remise); } - // Lecture du rang max de la facture + // Stockage du rang max de la facture dans rangmax $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.'facturedet'; $sql .= ' WHERE fk_facture ='.$facid; $resql = $this->db->query($sql); @@ -1016,12 +1017,12 @@ class Facture } // Formatage des prix - $_price = price2num($_price); + $price = price2num($price); $subprice = price2num($subprice); $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facturedet '; $sql.= ' (fk_facture, description, price, qty, tva_taux, fk_product, remise_percent, subprice, remise, date_start, date_end, fk_code_ventilation, rang)'; - $sql.= " VALUES ($facid, '".addslashes($desc)."','$_price','$qty','$txtva',"; + $sql.= " VALUES ($facid, '".addslashes($desc)."','$price','$qty','$txtva',"; if ($fk_product) { $sql.= "'$fk_product',"; } else { $sql.='0,'; } $sql.= " '$remise_percent','$subprice','$remise',"; diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 2343fdf22f3..dfb26bca5b6 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -55,6 +55,7 @@ class Propal var $note; var $price; var $status; + var $fin_validite; var $labelstatut=array(); var $labelstatut_short=array(); @@ -138,37 +139,43 @@ class Propal $remise_percent=price2num($remise_percent); $qty=price2num($qty); - $prod = new Product($this->db, $idproduct); - if ($prod->fetch($idproduct) > 0) + if ($idproduct) { - $price = price2num($prod->price); - $subprice = price2num($prod->price); - - if ($remise_percent > 0) + $prod = new Product($this->db, $idproduct); + if ($prod->fetch($idproduct) > 0) { - $remise = round(($prod->price * $remise_percent / 100), 2); - $price = $prod->price - $remise; - } - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES "; - $sql .= " (".$this->id.",". $idproduct.",'". $qty."','". $price."','".$prod->tva_tx."','".addslashes($p_desc?$p_desc:$prod->label)."','".ereg_replace(",",".",$remise_percent)."','".ereg_replace(",",".",$subprice)."')"; - - if ($this->db->query($sql) ) - { - $this->update_price(); - return 1; + $txtva = $prod->tva_tx; + $price = price2num($prod->price); + $subprice = price2num($prod->price); + + // Calcul remise et nouveau prix + $remise = 0; + if ($remise_percent > 0) + { + $remise = round(($prod->price * $remise_percent / 100), 2); + $price = $prod->price - $remise; + } + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES "; + $sql .= " (".$this->id.",". $idproduct.",'". $qty."','". $price."','".$txtva."','".addslashes($p_desc?$p_desc:$prod->label)."','".ereg_replace(",",".",$remise_percent)."','".ereg_replace(",",".",$subprice)."')"; + + if ($this->db->query($sql) ) + { + $this->update_price(); + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; + } } else { $this->error=$this->db->error(); - return -1; + return -2; } } - else - { - $this->error=$this->db->error(); - return -2; - } } else { @@ -192,13 +199,12 @@ class Propal dolibarr_syslog("propal.class.php::insert_product_generic $p_desc, $p_price, $p_qty, $p_tva_tx, $remise_percent"); if ($this->statut == 0) { - if (strlen(trim($p_qty)) == 0) - { - $p_qty = 1; - } - - $p_price = ereg_replace(",",".",$p_price); - + // Nettoyage paramètres + $remise_percent=price2num($remise_percent); + $p_qty=price2num($p_qty); + if (strlen(trim($p_qty))==0) $p_qty=1; + $p_price = price2num($p_price); + $price = $p_price; $subprice = $p_price; @@ -211,7 +217,6 @@ class Propal $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES "; $sql .= " (".$this->id.", 0,'". $p_qty."','". ereg_replace(",",".",$price)."','".$p_tva_tx."','".addslashes($p_desc)."','$remise_percent', '".ereg_replace(",",".",$subprice)."') ; "; - if ($this->db->query($sql) ) { @@ -629,40 +634,71 @@ class Propal } } - /** - * \brief Définit une remise globale sur la proposition - * - * - */ - - function set_remise($user, $remise) - { - if ($user->rights->propale->creer) - { - $remise = ereg_replace(",",".",$remise); - - $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise; - $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;"; - - if ($this->db->query($sql) ) - { - $this->remise_percent = $remise; - $this->update_price(); - return 1; - } - else - { - dolibarr_syslog("Propal::set_remise Erreur SQL"); - } - } - } + + /** + * \brief Définit une remise globale sur la proposition + * \param user Objet utilisateur qui modifie + * \param remise Montant remise + * \return int <0 si ko, >0 si ok + */ + function set_echeance($user, $date_fin_validite) + { + if ($user->rights->propale->creer) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fin_validite = ".$this->db->idate($date_fin_validite); + $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; + + if ($this->db->query($sql) ) + { + $this->fin_validite = $date_fin_validite; + return 1; + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("Propal::set_echeance Erreur SQL"); + return -1; + } + } + } + + + /** + * \brief Définit une remise globale sur la proposition + * \param user Objet utilisateur qui modifie + * \param remise Montant remise + * \return int <0 si ko, >0 si ok + */ + function set_remise($user, $remise) + { + if ($user->rights->propale->creer) + { + $remise = price2num($remise); + + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise; + $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; + + if ($this->db->query($sql) ) + { + $this->remise_percent = $remise; + $this->update_price(); + return 1; + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("Propal::set_remise Erreur SQL"); + return -1; + } + } + } + /* * * * */ - function set_project($user, $project_id) { if ($user->rights->propale->creer)