Ajout calcul de la remise

This commit is contained in:
Rodolphe Quiedeville 2003-09-05 19:37:20 +00:00
parent 1965feaf20
commit 16b2f85f29

View File

@ -227,17 +227,17 @@ class Propal
$totalht=0; $totalht=0;
$totaltva=0; $totaltva=0;
$totalttc=0; $totalttc=0;
$total_remise=0;
/* /*
* Remise * Remise
*/ */
$sql = "SELECT remise FROM llx_propal WHERE rowid = $rowid"; $sql = "SELECT remise_percent FROM llx_propal WHERE rowid = $rowid";
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
{ {
$remise = $this->db->result(0, 0); $remise_percent = $this->db->result(0, 0);
$this->db->free(); $this->db->free();
/* /*
* Total des produits a ajouter * Total des produits a ajouter
*/ */
@ -251,22 +251,30 @@ class Propal
{ {
$obj = $this->db->fetch_object($i); $obj = $this->db->fetch_object($i);
$totalht = $totalht + ($obj->qty * $obj->price); $lprice = ($obj->qty * $obj->price);
$totaltva = $totaltva + (tva(($obj->qty * $obj->price), $obj->tva_tx));
if ($remise_percent > 0)
{
$lremise = ($lprice * $remise_percent / 100);
$total_remise = $total_remise + $lremise;
$lprice = $lprice - $lremise;
}
$totalht = $totalht + $lprice;
$totaltva = $totaltva + (tva(($lprice), $obj->tva_tx));
$i++; $i++;
} }
$this->db->free(); $this->db->free();
/* /*
* Calcul TVA, Remise * Calcul TVA
*/ */
$totalht = $totalht - $this->remise;
$totalttc = $totalht + $totaltva; $totalttc = $totalht + $totaltva;
/* /*
* *
*/ */
$sql = "UPDATE llx_propal set price=$totalht, tva=$totaltva, total=$totalttc WHERE rowid = $rowid"; $sql = "UPDATE llx_propal set price=$totalht, tva=$totaltva, total=$totalttc, remise=$total_remise WHERE rowid = $rowid";
if (! $this->db->query($sql) ) if (! $this->db->query($sql) )
{ {
print "Erreur mise à jour du prix<p>".$sql; print "Erreur mise à jour du prix<p>".$sql;
@ -284,7 +292,7 @@ class Propal
Function fetch($rowid) Function fetch($rowid)
{ {
$sql = "SELECT ref,total,price,remise,tva,fk_soc,fk_soc_contact,".$this->db->pdate(datep)."as dp, model_pdf "; $sql = "SELECT ref,total,price,remise,tva,fk_soc,fk_soc_contact,".$this->db->pdate(datep)."as dp, model_pdf, note, fk_statut, remise_percent";
$sql .= " FROM llx_propal WHERE rowid=$rowid;"; $sql .= " FROM llx_propal WHERE rowid=$rowid;";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
@ -299,6 +307,7 @@ class Propal
$this->ref = $obj->ref; $this->ref = $obj->ref;
$this->price = $obj->price; $this->price = $obj->price;
$this->remise = $obj->remise; $this->remise = $obj->remise;
$this->remise_percent = $obj->remise_percent;
$this->total = $obj->total; $this->total = $obj->total;
$this->total_ht = $obj->price; $this->total_ht = $obj->price;
$this->total_tva = $obj->tva; $this->total_tva = $obj->tva;
@ -306,6 +315,13 @@ class Propal
$this->socidp = $obj->fk_soc; $this->socidp = $obj->fk_soc;
$this->contactid = $obj->fk_soc_contact; $this->contactid = $obj->fk_soc_contact;
$this->modelpdf = $obj->model_pdf; $this->modelpdf = $obj->model_pdf;
$this->note = $obj->note;
if ($obj->fk_statut == 0)
{
$this->brouillon = 1;
}
$this->lignes = array(); $this->lignes = array();
$this->db->free(); $this->db->free();
@ -416,6 +432,31 @@ class Propal
} }
} }
} }
/*
*
*
*
*/
Function set_remise($user, $remise)
{
if ($user->rights->propale->valider)
{
$sql = "UPDATE llx_propal SET remise_percent = ".ereg_replace(",",".",$remise);
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
if ($this->db->query($sql) )
{
$this->update_price($this->id);
return 1;
}
else
{
print $this->db->error() . ' in ' . $sql;
}
}
}
/* /*
* *
* *