From ca9e4071779be325d8535d4fe38687a297dccf8b Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Fri, 27 Jun 2003 12:27:37 +0000 Subject: [PATCH] Gestion de la tva par ligne --- htdocs/propal.class.php3 | 116 +++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 52 deletions(-) diff --git a/htdocs/propal.class.php3 b/htdocs/propal.class.php3 index b28d83cc52f..668240dc303 100644 --- a/htdocs/propal.class.php3 +++ b/htdocs/propal.class.php3 @@ -42,7 +42,7 @@ class Propal $this->db = $DB ; $this->socidp = $soc_idp; $this->products = array(); - } + } /* * * @@ -72,8 +72,8 @@ class Propal $prod = new Product($this->db, $idproduct); $prod->fetch($idproduct); - $sql = "INSERT INTO llx_propaldet (fk_propal, fk_product, qty, price) VALUES "; - $sql .= " (".$this->id.",". $idproduct.",". $qty.", $prod->price) ; "; + $sql = "INSERT INTO llx_propaldet (fk_propal, fk_product, qty, price, tva_tx) VALUES "; + $sql .= " (".$this->id.",". $idproduct.",". $qty.",". $prod->price.",".$prod->tva_tx.") ; "; if ($this->db->query($sql) ) { @@ -127,58 +127,69 @@ class Propal * * */ - Function create() { - /* - * Insertion dans la base - */ - $sql = "INSERT INTO llx_propal (fk_soc, fk_soc_contact, price, remise, tva, total, datep, datec, ref, fk_user_author, note) "; - $sql .= " VALUES ($this->socidp, $this->contactid, 0, $this->remise, 0,0, $this->datep, now(), '$this->ref', $this->author, '$this->note')"; - $sqlok = 0; + Function create() + { + /* + * Insertion dans la base + */ + $sql = "INSERT INTO llx_propal (fk_soc, fk_soc_contact, price, remise, tva, total, datep, datec, ref, fk_user_author, note) "; + $sql .= " VALUES ($this->socidp, $this->contactid, 0, $this->remise, 0,0, $this->datep, now(), '$this->ref', $this->author, '$this->note')"; + $sqlok = 0; - if ( $this->db->query($sql) ) { + if ( $this->db->query($sql) ) + { - $this->id = $this->db->last_insert_id(); - - $sql = "SELECT rowid FROM llx_propal WHERE ref='$this->ref';"; - if ( $this->db->query($sql) ) { - /* - * Insertion du detail des produits dans la base - */ - if ( $this->db->num_rows() ) { - $propalid = $this->db->result( 0, 0); - $this->db->free(); - - for ($i = 0 ; $i < sizeof($this->products) ; $i++) { - $prod = new Product($this->db, $this->products[$i]); - $prod->fetch($this->products[$i]); - - $sql = "INSERT INTO llx_propaldet (fk_propal, fk_product, qty, price) VALUES "; - $sql .= " ($propalid,". $this->products[$i].",". $this->products_qty[$i].", $prod->price) ; "; - - if (! $this->db->query($sql) ) { - print $sql . '
' . $this->db->error() .'
'; + $this->id = $this->db->last_insert_id(); + + $sql = "SELECT rowid FROM llx_propal WHERE ref='$this->ref';"; + if ( $this->db->query($sql) ) + { + /* + * Insertion du detail des produits dans la base + */ + if ( $this->db->num_rows() ) + { + $propalid = $this->db->result( 0, 0); + $this->db->free(); + + for ($i = 0 ; $i < sizeof($this->products) ; $i++) + { + $prod = new Product($this->db, $this->products[$i]); + $prod->fetch($this->products[$i]); + + $sql = "INSERT INTO llx_propaldet (fk_propal, fk_product, qty, price, tva_tx) VALUES "; + $sql .= " ($propalid,".$this->products[$i].",".$this->products_qty[$i].",$prod->price,$prod->tva_tx);"; + + if (! $this->db->query($sql) ) + { + print $sql . '
' . $this->db->error() .'
'; + } + } + /* + * + */ + $this->update_price($this->id); + /* + * Affectation au projet + */ + if ($this->projetidp) + { + $sql = "UPDATE llx_propal SET fk_projet=$this->projetidp WHERE ref='$this->ref';"; + $this->db->query($sql); + } + } } - } - /* - * - */ - $this->update_price($this->id); - /* - * Affectation au projet - */ - if ($this->projetidp) { - $sql = "UPDATE llx_propal SET fk_projet=$this->projetidp WHERE ref='$this->ref';"; - $this->db->query($sql); - } - } - } else { - print $this->db->error() . '
'.$sql; - } - } else { - print $this->db->error() . '
'.$sql; + else + { + print $this->db->error() . '
'.$sql; + } + } + else + { + print $this->db->error() . '
'.$sql; + } + return $this->id; } - return $this->id; - } /* * * @@ -253,7 +264,7 @@ class Propal * Lignes */ - $sql = "SELECT d.qty, p.description, p.ref, p.price"; + $sql = "SELECT d.qty, p.description, p.ref, p.price, d.tva_tx"; $sql .= " FROM llx_propaldet as d, llx_product as p"; $sql .= " WHERE d.fk_propal = ".$this->id ." AND d.fk_product = p.rowid"; @@ -270,6 +281,7 @@ class Propal $ligne->desc = stripslashes($objp->description); $ligne->qty = $objp->qty; $ligne->ref = $objp->ref; + $ligne->tva_tx = $objp->tva_tx; $ligne->price = $objp->price; $this->lignes[$i] = $ligne; $i++;