From 7f81488c38ac6305fdfead5e850498649f8c4dd3 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Tue, 23 Sep 2003 17:50:20 +0000 Subject: [PATCH] Mise en place des remises par lignes --- htdocs/comm/addpropal.php | 7 +- htdocs/comm/propal.php | 63 ++++--- htdocs/compta/facture.php | 166 +++++++++--------- htdocs/facture.class.php | 44 +++-- .../modules/facture/pluton/pluton.modules.php | 2 +- htdocs/main.inc.php | 2 +- htdocs/propal.class.php | 57 +++--- 7 files changed, 193 insertions(+), 148 deletions(-) diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php index e079cea3a35..608749dea83 100644 --- a/htdocs/comm/addpropal.php +++ b/htdocs/comm/addpropal.php @@ -179,7 +179,7 @@ if ($action == 'create') while ($i < $num) { $objp = $db->fetch_object( $i); - $opt .= "\n"; + $opt .= "\n"; $i++; } } @@ -193,11 +193,12 @@ if ($action == 'create') print_titre("Services/Produits"); print ''; - + print ''; for ($i = 1 ; $i <= PROPALE_NEW_FORM_NB_PRODUCT ; $i++) { print ''; - print ''; + print ''; + print ''; } print "
ProduitQuan.Remise
%
"; diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 44c228587e1..7e4c26d3347 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -92,8 +92,9 @@ if ($action == 'add') { $xid = "idprod".$i; $xqty = "qty".$i; + $xremise = "remise".$i; - $propal->add_product($$xid,$$xqty); + $propal->add_product($$xid,$$xqty,$$xremise); } $id = $propal->create(); @@ -146,7 +147,7 @@ if ($HTTP_POST_VARS["action"] == 'addligne' && $user->rights->propale->creer) { $propal = new Propal($db); $propal->fetch($propalid); - $propal->insert_product($HTTP_POST_VARS["idprod"], $HTTP_POST_VARS["qty"]); + $propal->insert_product($HTTP_POST_VARS["idprod"], $HTTP_POST_VARS["qty"], $HTTP_POST_VARS["remise"]); } } @@ -292,8 +293,8 @@ if ($propalid) /* * */ - print 'Remise'.price($propal->remise).' euros'; - print ' '.price($propal->remise_percent).' %'; + print 'Remise'.$propal->remise_percent.' %'; + print ' '.price($propal->remise).' euros'; /* * */ @@ -329,15 +330,6 @@ if ($propalid) * * */ - if ($propal->brouillon == 1) - { - print '
'; - print ''; - print '
Remise'; - print '%'; - print ''; - print '
'; - } /* * Produits @@ -347,14 +339,14 @@ if ($propalid) print ''; print ""; print ""; - print ''; + print ''; if ($propal->statut == 0) { print ""; } print "\n"; - $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.tva_tx"; + $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.tva_tx, pt.remise_percent, pt.subprice"; $sql .= " FROM llx_propaldet as pt, llx_product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = $propalid"; $result = $db->query($sql); @@ -370,11 +362,12 @@ if ($propalid) $objp = $db->fetch_object( $i); $var=!$var; print ""; - print "\n"; + print "\n"; print ''; - print ""; print ''; print "\n"; + print ''; + print ''; if ($obj->statut == 0 && $user->rights->propale->creer) { print ''; @@ -389,11 +382,10 @@ if ($propalid) } } - $sql = "SELECT pt.rowid, pt.description, pt.price, pt.qty, pt.tva_tx"; + $sql = "SELECT pt.rowid, pt.description, pt.price, pt.qty, pt.tva_tx, pt.remise_percent"; $sql .= " FROM llx_propaldet as pt WHERE pt.fk_propal = $propalid AND pt.fk_product = 0"; - $result = $db->query($sql); - if ($result) + if ($db->query($sql)) { $num = $db->num_rows(); $i = 0; @@ -403,9 +395,10 @@ if ($propalid) $var=!$var; print "\n"; print ''; - print ""; print ''; print "\n"; + print ''; + print ""; if ($obj->statut == 0 && $user->rights->propale->creer) { print ''; @@ -432,7 +425,7 @@ if ($propalid) while ($i < $num) { $objp = $db->fetch_object( $i); - $opt .= "\n"; + $opt .= "\n"; $i++; } } @@ -444,7 +437,7 @@ if ($propalid) } /* - * Produits génériques + * Produits * */ $var=!$var; @@ -453,17 +446,25 @@ if ($propalid) print ''; print ''; print ''; - print ''; print ''; + print ''; + print ''; print ''; print ''; + /* + * Produits génériques + * + */ $var=!$var; print ''; print ''; - print ""; + print ""; print ''; + print ''; + print ''; print ''; print "\n"; print ''; @@ -473,12 +474,22 @@ if ($propalid) print "
RéfProduitPrixTvaQté.TvaQté.RemiseP.U. 
[$objp->ref][$objp->ref]'.$objp->product.'".price($objp->price)."'.$objp->tva_tx.' %".$objp->qty."'.$objp->remise_percent.' %'.price($objp->subprice).'Supprimer
 '.$objp->description.'".price($objp->price)."'.$objp->tva_tx.' %".$objp->qty."'.$objp->remise_percent.' %".price($objp->price)."Supprimer
 '; + print ''; print $html->select_tva("np_tva_tx") . ' %
 
  % 
"; + if ($propal->brouillon == 1) + { + print '
'; + print ''; + print '
Remise'; + print '%'; + print ''; + print '
'; + } + /* * Actions */ if ($obj->statut < 2) { - print "

"; + print "
"; if ($obj->statut == 0) { diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 0c1cd3c1324..73b8b6002d1 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -85,10 +85,11 @@ if ($HTTP_POST_VARS["action"] == 'add') { $result = $facture->addline($facid, addslashes($prop->lignes[$i]->libelle), - $prop->lignes[$i]->price, + $prop->lignes[$i]->subprice, $prop->lignes[$i]->qty, $prop->lignes[$i]->tva_tx, - $prop->lignes[$i]->product_id); + $prop->lignes[$i]->product_id, + $prop->lignes[$i]->remise_percent); } } else @@ -154,7 +155,9 @@ if ($action == 'valid' && $user->rights->facture->valider) { $fac = new Facture($db); $fac->fetch($facid); - $result = $fac->set_valid($facid, $user); + $soc = new Societe($db); + $soc->fetch($fac->socidp); + $result = $fac->set_valid($facid, $user, $soc); if ($result) { facture_pdf_create($db, $facid); @@ -184,7 +187,9 @@ if ($action == 'addligne' && $user->rights->facture->creer) $HTTP_POST_VARS["desc"], $HTTP_POST_VARS["pu"], $HTTP_POST_VARS["qty"], - $HTTP_POST_VARS["tva_tx"]); + $HTTP_POST_VARS["tva_tx"], + "NULL", + $HTTP_POST_VARS["remise_percent"]); } if ($action == 'updateligne' && $user->rights->facture->creer) @@ -194,7 +199,8 @@ if ($action == 'updateligne' && $user->rights->facture->creer) $result = $fac->updateline($rowid, $HTTP_POST_VARS["desc"], $HTTP_POST_VARS["price"], - $HTTP_POST_VARS["qty"]); + $HTTP_POST_VARS["qty"], + $HTTP_POST_VARS["remise_percent"]); } if ($action == 'deleteline' && $user->rights->facture->creer) @@ -327,8 +333,6 @@ if ($action == 'create') $soc = new Societe($db); $soc->fetch($obj->idp); - $numfa = facture_get_num($soc); // définit dans includes/modules/facture - print ''; print ''; print '' ."\n"; @@ -349,8 +353,8 @@ if ($action == 'create') print_date_select(time()); print ""; - print ""; - + print ""; + print ''; print ""; - print ''; - print ''; + print ''; + print ''; print ''; - print ''; + print ''; + print ''; print ''; print "\n"; } @@ -660,7 +665,15 @@ else } print ''; print ''; - print '\n"; + if ($objp->remise_percent > 0) + { + print '\n"; + } + else + { + print ''; + } + print '\n"; if ($fac->statut == 0) { print ''; @@ -678,9 +691,10 @@ else print ''; print ''; print ""; - print ''; + print ''; print ''; - print ''; + print ''; + print ''; print ''; print '' . "\n"; print "\n"; @@ -707,19 +721,21 @@ else print ""; // echo '
Numéro :
Numéro :Provisoire
Conditions de réglement :"; $sql = "SELECT rowid, libelle FROM llx_cond_reglement ORDER BY sortorder"; $result = $db->query($sql); @@ -624,8 +628,8 @@ else * */ - $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux"; - $sql .= " FROM llx_facturedet as l WHERE l.fk_facture = $facid"; + $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux, l.remise_percent, l.subprice"; + $sql .= " FROM llx_facturedet as l WHERE l.fk_facture = $facid ORDER BY l.rowid"; $result = $db->query($sql); if ($result) @@ -637,10 +641,11 @@ else if ($num) { print "
DescriptionTva TxDescriptionTvaQuantitéMontantRemiseP.U.  
'.$objp->tva_taux.' %'.$objp->qty.''.price($objp->price)."'.$objp->remise_percent." % '.price($objp->subprice)."del
 %
'; print ""; - print ''; - print ''; + print ''; + print ''; print ''; - print ''; + print ''; + print ''; print ''; print ''; print "\n"; print ''; - print ''; + print ''; print ''; - print ''; + print ''; + print ''; print ''; print ''; @@ -811,83 +827,65 @@ else * Documents générés * */ - - print "
DescriptionTva TxDescriptionTvaQuantitéMontantRemiseP.U.  
'; print $html->select_tva("tva_tx"); print ' %
"; - print_titre("Documents"); - print ''; - $file = FAC_OUTPUTDIR . "/" . $fac->ref . "/" . $fac->ref . ".pdf"; if (file_exists($file)) { + print "
"; + print_titre("Documents"); + print ''; + print ""; print ''; print ''; print ''; print ''; - } - - $file = FAC_OUTPUTDIR . "/" . $fac->ref . "/" . $fac->ref . ".ps"; - - if (file_exists($file)) - { - print ""; - print ''; - print ''; - print ''; - print ''; + + print "
Facture PDFref."/".$fac->ref.'.pdf">'.$fac->ref.'.pdf'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
Facture Postscriptref."/".$fac->ref.'.ps">'.$fac->ref.'.ps'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
\n"; + print '
'; + print_titre("Actions"); + /* + * Liste des actions + * + */ + $sql = "SELECT ".$db->pdate("a.datea")." as da, a.note"; + $sql .= " FROM llx_actioncomm as a WHERE a.fk_soc = $fac->socidp AND a.fk_action in (9,10) AND a.fk_facture = $facid"; - - } - - print "
\n"; - print '
'; - print_titre("Actions"); - /* - * Liste des actions - * - */ - $sql = "SELECT ".$db->pdate("a.datea")." as da, a.note"; - $sql .= " FROM llx_actioncomm as a WHERE a.fk_soc = $fac->socidp AND a.fk_action in (9,10) AND a.fk_facture = $facid"; - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows(); - if ($num) + $result = $db->query($sql); + if ($result) { - $i = 0; $total = 0; - print ''; - print ""; - print ""; - print ""; - print "\n"; - - $var=True; - while ($i < $num) + $num = $db->num_rows(); + if ($num) { - $objp = $db->fetch_object( $i); - $var=!$var; - print ""; - print "\n"; - print ''; - print ""; - $i++; + $i = 0; $total = 0; + print '
DateAction
".strftime("%d %B %Y",$objp->da)."'.stripslashes($objp->note).'
'; + print "\n"; + + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object( $i); + $var=!$var; + print ""; + print "\n"; + print ''; + print ""; + $i++; + } + print "
DateAction
".strftime("%d %B %Y",$objp->da)."'.stripslashes($objp->note).'
"; } - print "
"; } + else + { + print $db->error(); + } + + /* + * + * + */ + print ""; } - else - { - print $db->error(); - } - - /* - * - * - */ - print ""; - /* * * diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 0ea00e4ed12..04f374130cb 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -118,6 +118,9 @@ class Facture { $this->id = $this->db->last_insert_id(); + $sql = "UPDATE llx_facture SET facnumber='(PROV".$this->id.")' WHERE rowid=".$this->id; + $this->db->query($sql); + if ($this->id && $this->propalid) { $sql = "INSERT INTO llx_fa_pr (fk_facture, fk_propal) VALUES (".$this->id.",".$this->propalid.")"; @@ -342,13 +345,15 @@ class Facture * Valide la facture * */ - Function set_valid($rowid, $user) + Function set_valid($rowid, $user, $soc) { if ($this->brouillon) { $action_notify = 2; // ne pas modifier cette valeur - $sql = "UPDATE llx_facture set fk_statut = 1, fk_user_valid = $user->id WHERE rowid = $rowid ;"; + $numfa = facture_get_num($soc); // définit dans includes/modules/facture + + $sql = "UPDATE llx_facture set facnumber='$numfa', fk_statut = 1, fk_user_valid = $user->id WHERE rowid = $rowid ;"; $result = $this->db->query( $sql); /* @@ -411,10 +416,10 @@ class Facture } } /** - * Supprime une ligne de la facture + * Ajoute une ligne de facture * */ - Function addline($facid, $desc, $pu, $qty, $txtva, $fk_product='NULL') + Function addline($facid, $desc, $pu, $qty, $txtva, $fk_product='NULL', $remise_percent=0) { if ($this->brouillon) { @@ -422,10 +427,17 @@ class Facture { $qty=1; } + $remise = 0; + $price = round(ereg_replace(",",".",$pu), 2); + $subprice = $price; + if (trim(strlen($remise_percent)) > 0) + { + $remise = round(($pu * $remise_percent / 100), 2); + $price = $pu - $remise; + } - $pu = round(ereg_replace(",",".",$pu), 2); - $sql = "INSERT INTO llx_facturedet (fk_facture,description,price,qty,tva_taux, fk_product)"; - $sql .= " VALUES ($facid, '$desc', $pu, $qty, $txtva, $fk_product) ;"; + $sql = "INSERT INTO llx_facturedet (fk_facture,description,price,qty,tva_taux, fk_product, remise_percent, subprice, remise)"; + $sql .= " VALUES ($facid, '$desc', $price, $qty, $txtva, $fk_product, $remise_percent, $subprice, $remise) ;"; if ( $this->db->query( $sql) ) { @@ -442,7 +454,7 @@ class Facture * Mets à jour une ligne de facture * */ - Function updateline($rowid, $desc, $pu, $qty) + Function updateline($rowid, $desc, $pu, $qty, $remise_percent=0) { if ($this->brouillon) { @@ -450,8 +462,20 @@ class Facture { $qty=1; } - $pu = round(ereg_replace(",",".",$pu), 2); - $sql = "UPDATE llx_facturedet set description='$desc',price=$pu,qty=$qty WHERE rowid = $rowid ;"; + $remise = 0; + $price = round(ereg_replace(",",".",$pu), 2); + $subprice = $price; + if (trim(strlen($remise_percent)) > 0) + { + $remise = round(($pu * $remise_percent / 100), 2); + $price = $pu - $remise; + } + else + { + $remise_percent=0; + } + + $sql = "UPDATE llx_facturedet set description='$desc',price=$price,subprice=$subprice,remise=$remise,remise_percent=$remise_percent,qty=$qty WHERE rowid = $rowid ;"; $result = $this->db->query( $sql); $this->updateprice($this->id); diff --git a/htdocs/includes/modules/facture/pluton/pluton.modules.php b/htdocs/includes/modules/facture/pluton/pluton.modules.php index 630b37b33c6..a5d9aafc791 100644 --- a/htdocs/includes/modules/facture/pluton/pluton.modules.php +++ b/htdocs/includes/modules/facture/pluton/pluton.modules.php @@ -25,7 +25,7 @@ function facture_get_num($objsoc=0) { global $db; - $sql = "SELECT count(*) FROM llx_facture"; + $sql = "SELECT count(*) FROM llx_facture WHERE fk_statut > 0"; if ( $db->query($sql) ) { diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 9430277ff98..91e4fb575d5 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -20,7 +20,7 @@ * $Source$ * */ -define('DOL_VERSION','1.0.1'); +define('DOL_VERSION','1.1.0'); if (! include ("conf/conf.php")) { diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 2a0ba170998..e2c1bc3e3b5 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -50,7 +50,7 @@ class Propal * * */ - Function add_product($idproduct, $qty) + Function add_product($idproduct, $qty, $remise_percent=0) { if ($idproduct > 0) { @@ -61,22 +61,30 @@ class Propal $qty = 1 ; } $this->products_qty[$i] = $qty; + $this->products_remise_percent[$i] = $remise_percent; } } /* * * */ - Function insert_product($idproduct, $qty) + Function insert_product($idproduct, $qty, $remise_percent=0) { if ($this->statut == 0) { $prod = new Product($this->db, $idproduct); if ($prod->fetch($idproduct) > 0) { + $price = $prod->price; + $subprice = $prod->price; + if ($remise_percent > 0) + { + $remise = round(($prod->price * $remise_percent / 100), 2); + $price = $prod->price - $remise; + } - $sql = "INSERT INTO llx_propaldet (fk_propal, fk_product, qty, price, tva_tx, description) VALUES "; - $sql .= " (".$this->id.",". $idproduct.",". $qty.",". $prod->price.",".$prod->tva_tx.",'".addslashes($prod->label)."') ; "; + $sql = "INSERT INTO llx_propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES "; + $sql .= " (".$this->id.",". $idproduct.",". $qty.",". $price.",".$prod->tva_tx.",'".addslashes($prod->label)."',$remise_percent, $subprice)"; if ($this->db->query($sql) ) { @@ -197,13 +205,12 @@ class Propal $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() .'
'; - } + //$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);"; + + $this->insert_product($this->products[$i], + $this->products_qty[$i], + $this->products_remise_percent[$i]); } /* * @@ -328,9 +335,9 @@ class Propal * Lignes */ - $sql = "SELECT d.qty, p.description, p.ref, p.price, d.tva_tx, p.rowid, p.label"; + $sql = "SELECT p.rowid, p.label, p.description, p.ref, d.price, d.tva_tx, d.qty, d.remise_percent, d.subprice"; $sql .= " FROM llx_propaldet as d, llx_product as p"; - $sql .= " WHERE d.fk_propal = ".$this->id ." AND d.fk_product = p.rowid"; + $sql .= " WHERE d.fk_propal = ".$this->id ." AND d.fk_product = p.rowid ORDER by d.rowid ASC"; $result = $this->db->query($sql); if ($result) @@ -340,16 +347,20 @@ class Propal while ($i < $num) { - $objp = $this->db->fetch_object($i); - $ligne = new PropaleLigne(); - $ligne->libelle = stripslashes($objp->label); - $ligne->desc = stripslashes($objp->description); - $ligne->qty = $objp->qty; - $ligne->ref = $objp->ref; - $ligne->tva_tx = $objp->tva_tx; - $ligne->price = $objp->price; - $ligne->product_id = $objp->rowid; - $this->lignes[$i] = $ligne; + $objp = $this->db->fetch_object($i); + + $ligne = new PropaleLigne(); + $ligne->libelle = stripslashes($objp->label); + $ligne->desc = stripslashes($objp->description); + $ligne->qty = $objp->qty; + $ligne->ref = $objp->ref; + $ligne->tva_tx = $objp->tva_tx; + $ligne->subprice = $objp->subprice; + $ligne->remise_percent = $objp->remise_percent; + $ligne->price = $objp->price; + $ligne->product_id = $objp->rowid; + + $this->lignes[$i] = $ligne; $i++; }