Correction calcul tva

This commit is contained in:
Rodolphe Quiedeville 2003-07-10 17:06:26 +00:00
parent 8f91bf1aa2
commit 4fe0510f50

View File

@ -336,27 +336,38 @@ class Facture
Function updateprice($facid) Function updateprice($facid)
{ {
$sql = "SELECT sum(price*qty) FROM llx_facturedet WHERE fk_facture = $facid;"; $sql = "SELECT price, qty, tva_taux FROM llx_facturedet WHERE fk_facture = $facid;";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
if ($this->db->num_rows() ) $num = $this->db->num_rows();
$i = 0;
$totalht = 0;
$totaltva = 0;
while ($i < $num)
{ {
$row = $this->db->fetch_row(); $obj = $this->db->fetch_object($i);
$totalht = $row[0];
$totalht = $totalht + ($obj->qty * $obj->price);
$totaltva = $totaltva + tva($obj->qty * $obj->price, $obj->tva_taux);
$i++;
} }
$this->db->free();
$tva = tva($totalht); $total = $totalht + $totaltva;
$total = $totalht + $tva;
$sql = "UPDATE llx_facture SET amount = $totalht, tva=$tva, total=$total"; $sql = "UPDATE llx_facture SET amount = $totalht, tva=$totaltva, total=$total";
$sql .= " WHERE rowid = $facid ;"; $sql .= " WHERE rowid = $facid ;";
$result = $this->db->query($sql); $result = $this->db->query($sql);
} }
else
{
print "Error";
}
} }
/* /*
@ -367,14 +378,6 @@ class Facture
Function pdf() Function pdf()
{ {
print "<hr><b>Génération du PDF</b><p>";
$command = "export DBI_DSN=\"".$GLOBALS["DBI"]."\" ";
$command .= " ; ../../scripts/facture-tex.pl --facture=$facid --pdf --ps" ;
$output = system($command);
print "<p>command : $command<br>";
} }
} }