diff --git a/htdocs/compta/facture.php3 b/htdocs/compta/facture.php3 index ae9367a2e84..a2e20149f80 100644 --- a/htdocs/compta/facture.php3 +++ b/htdocs/compta/facture.php3 @@ -105,6 +105,15 @@ if ($action == 'payed' && $user->rights->facture->paiement) $result = $fac->set_payed($facid); } +if ($HTTP_POST_VARS["action"] == 'setremise' && $user->rights->facture->creer) +{ + $fac = new Facture($db); + $fac->fetch($facid); + + $fac->set_remise($user, $HTTP_POST_VARS["remise"]); +} + + if ($action == 'addligne' && $user->rights->facture->creer) { $fac = new Facture($db); @@ -156,6 +165,7 @@ if ($HTTP_POST_VARS["action"] == 'add') { $facture->amount = $HTTP_POST_VARS["amount"]; $facture->remise = $HTTP_POST_VARS["remise"]; + $facture->remise_percent = $HTTP_POST_VARS["remise_percent"]; $facture->add_product($HTTP_POST_VARS["idprod1"],$HTTP_POST_VARS["qty1"]); $facture->add_product($HTTP_POST_VARS["idprod2"],$HTTP_POST_VARS["qty2"]); @@ -166,6 +176,7 @@ if ($HTTP_POST_VARS["action"] == 'add') } else { + $facture->remise_percent = $HTTP_POST_VARS["remise_percent"]; $facture->amount = $HTTP_POST_VARS["amount"]; $facture->remise = $remise; $facture->propalid = $HTTP_POST_VARS["propalid"]; @@ -291,7 +302,7 @@ if ($action == 'create') if ($propalid) { - $sql = "SELECT s.nom, s.prefix_comm, s.idp, p.price, p.remise, p.tva, p.total, p.ref, ".$db->pdate("p.datep")." as dp, c.id as statut, c.label as lst"; + $sql = "SELECT s.nom, s.prefix_comm, s.idp, p.price, p.remise, p.remise_percent, p.tva, p.total, p.ref, ".$db->pdate("p.datep")." as dp, c.id as statut, c.label as lst"; $sql .= " FROM llx_societe as s, llx_propal as p, c_propalst as c"; $sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id"; $sql .= " AND p.rowid = $propalid"; @@ -364,11 +375,12 @@ if ($action == 'create') if ($propalid) { - $amount = ($obj->price - $obj->remise); - print ''; - print ''; - print ''; - print ''; + $amount = ($obj->price); + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; print ''; print 'Proposition'.$obj->ref.''; @@ -498,7 +510,14 @@ else print "Date limite de réglement : " . strftime("%d %B %Y",$fac->date_lim_reglement) .""; print "Auteur$author->fullname"; - print ''; + if ($fac->remise_percent > 0) + { + print ''; + } + else + { + print ''; + } $_MONNAIE="euros"; @@ -564,6 +583,14 @@ else print 'Montant'; print ''.price($fac->total_ht).''; print 'euros HT'; + + if ($fac->remise_percent > 0) + { + print 'Remise'; + print ''.$fac->remise_percent.''; + print '%'; + } + print 'TVA'.price($fac->total_tva).''; print 'euros'; print 'Total'.price($fac->total_ttc).''; @@ -573,7 +600,18 @@ else print 'Note : '.nl2br($obj->note).""; } - print "
"; + print "
"; + + if ($fac->brouillon == 1) + { + print '
'; + print ''; + print '
Remise'; + print '%'; + print ''; + print '
'; + } + /* * Lignes de factures * diff --git a/htdocs/facture.class.php3 b/htdocs/facture.class.php3 index 51f6882348d..5d9fa5893c0 100644 --- a/htdocs/facture.class.php3 +++ b/htdocs/facture.class.php3 @@ -57,6 +57,7 @@ class Facture $this->db_table = "llx_facture"; $this->amount = 0; $this->remise = 0; + $this->remise_percent = 0; $this->tva = 0; $this->total = 0; $this->propalid = 0; @@ -112,8 +113,8 @@ class Facture $tva = tva($totalht); $total = $totalht + $tva; - $sql = "INSERT INTO $this->db_table (facnumber, fk_soc, datec, amount, remise, tva, total, datef, note, fk_user_author,fk_projet, fk_cond_reglement, date_lim_reglement) "; - $sql .= " VALUES ('$number', $socid, now(), $totalht, $remise, $tva, $total,".$this->db->idate($this->date).",'$this->note',$user->id, $this->projetid, $this->cond_reglement,".$this->db->idate($datelim).")"; + $sql = "INSERT INTO $this->db_table (facnumber, fk_soc, datec, amount, remise, remise_percent, tva, total, datef, note, fk_user_author,fk_projet, fk_cond_reglement, date_lim_reglement) "; + $sql .= " VALUES ('$number', $socid, now(), $totalht, $remise, $this->remise_percent, $tva, $total,".$this->db->idate($this->date).",'$this->note',$user->id, $this->projetid, $this->cond_reglement,".$this->db->idate($datelim).")"; if ( $this->db->query($sql) ) { $this->id = $this->db->last_insert_id(); @@ -158,7 +159,7 @@ class Facture Function fetch($rowid) { - $sql = "SELECT f.fk_soc,f.facnumber,f.amount,f.tva,f.total,f.remise,".$this->db->pdate("f.datef")."as df,f.fk_projet,".$this->db->pdate("f.date_lim_reglement")." as dlr, c.libelle, f.note, f.paye, f.fk_statut"; + $sql = "SELECT f.fk_soc,f.facnumber,f.amount,f.tva,f.total,f.remise,f.remise_percent,".$this->db->pdate("f.datef")."as df,f.fk_projet,".$this->db->pdate("f.date_lim_reglement")." as dlr, c.libelle, f.note, f.paye, f.fk_statut"; $sql .= " FROM llx_facture as f, llx_cond_reglement as c"; $sql .= " WHERE f.rowid=$rowid AND c.rowid = f.fk_cond_reglement"; @@ -177,6 +178,7 @@ class Facture $this->total_ttc = $obj->total; $this->paye = $obj->paye; $this->remise = $obj->remise; + $this->remise_percent = $obj->remise_percent; $this->socidp = $obj->fk_soc; $this->statut = $obj->fk_statut; $this->date_lim_reglement = $obj->dlr; @@ -456,12 +458,22 @@ class Facture $i = 0; $totalht = 0; $totaltva = 0; + $totalremise = 0; while ($i < $num) { $obj = $this->db->fetch_object($i); - $totalht = $totalht + ($obj->qty * $obj->price); - $totaltva = $totaltva + tva($obj->qty * $obj->price, $obj->tva_taux); + $lprice = $obj->qty * $obj->price; + + if ($this->remise_percent > 0) + { + $lremise = ($lprice * $this->remise_percent / 100); + $total_remise = $total_remise + $lremise; + $lprice = $lprice - $lremise; + } + + $totalht = $totalht + $lprice; + $totaltva = $totaltva + tva($lprice, $obj->tva_taux); $i++; } $this->db->free(); @@ -483,6 +495,33 @@ class Facture * * */ + Function set_remise($user, $remise) + { + if ($user->rights->facture->creer) + { + + $this->remise_percent = $remise ; + + $sql = "UPDATE llx_facture SET remise_percent = ".ereg_replace(",",".",$remise); + $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;"; + + if ($this->db->query($sql) ) + { + $this->updateprice($this->id); + return 1; + } + else + { + print $this->db->error() . ' in ' . $sql; + return 0; + } + } + } + /* + * + * + * + */ Function send_relance($destinataire, $replytoname, $replytomail, $user) { $soc = new Societe($this->db, $this->socidp);