Modif calcul_price, désormais on utilise la meme fonction pour
calculer le prix d'une propale et d'une facture
This commit is contained in:
parent
77188fb1f4
commit
4adcb5bbc0
@ -81,7 +81,7 @@ class Propal
|
|||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->update_price($this->id);
|
$this->update_price();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ class Propal
|
|||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->update_price($this->id) > 0)
|
if ($this->update_price() > 0)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ class Propal
|
|||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->update_price($this->id);
|
$this->update_price();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -208,7 +208,7 @@ class Propal
|
|||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$this->update_price($this->id);
|
$this->update_price();
|
||||||
/*
|
/*
|
||||||
* Affectation au projet
|
* Affectation au projet
|
||||||
*/
|
*/
|
||||||
@ -234,26 +234,14 @@ class Propal
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Function update_price($rowid)
|
Function update_price()
|
||||||
{
|
{
|
||||||
$totalht=0;
|
include_once DOL_DOCUMENT_ROOT . "/lib/price.lib.php";
|
||||||
$totaltva=0;
|
|
||||||
$totalttc=0;
|
|
||||||
$total_remise=0;
|
|
||||||
$t = 0;
|
|
||||||
/*
|
|
||||||
* Remise
|
|
||||||
*/
|
|
||||||
$sql = "SELECT remise_percent FROM llx_propal WHERE rowid = $rowid";
|
|
||||||
if ( $this->db->query($sql) )
|
|
||||||
{
|
|
||||||
$remise_percent = $this->db->result(0, 0);
|
|
||||||
$this->db->free();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Total des produits a ajouter
|
* Liste des produits a ajouter
|
||||||
*/
|
*/
|
||||||
$sql = "SELECT price, qty, tva_tx FROM llx_propaldet WHERE fk_propal = $rowid";
|
$sql = "SELECT price, qty, tva_tx FROM llx_propaldet WHERE fk_propal = $this->id";
|
||||||
if ( $this->db->query($sql) )
|
if ( $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
$num = $this->db->num_rows();
|
$num = $this->db->num_rows();
|
||||||
@ -262,37 +250,27 @@ class Propal
|
|||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object($i);
|
$obj = $this->db->fetch_object($i);
|
||||||
|
$products[$i][0] = $obj->price;
|
||||||
$lprice = ($obj->qty * $obj->price);
|
$products[$i][1] = $obj->qty;
|
||||||
|
$products[$i][2] = $obj->tva_tx;
|
||||||
if ($remise_percent > 0)
|
|
||||||
{
|
|
||||||
$ligne_remise = ($lprice * $remise_percent / 100);
|
|
||||||
$total_remise = $total_remise + $ligne_remise;
|
|
||||||
$lprice = $lprice - $ligne_remise;
|
|
||||||
}
|
|
||||||
|
|
||||||
$totalht = $totalht + $lprice;
|
|
||||||
|
|
||||||
$ligne_tva = ($lprice * ($obj->tva_tx / 100));
|
|
||||||
|
|
||||||
$totaltva = $totaltva + $ligne_tva;
|
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
$calculs = calcul_price($products, $this->remise_percent);
|
||||||
|
|
||||||
$this->db->free();
|
$totalht = $calculs[0];
|
||||||
|
$totaltva = $calculs[1];
|
||||||
|
$totalttc = $calculs[2];
|
||||||
|
$total_remise = $calculs[3];
|
||||||
|
|
||||||
/*
|
$this->remise = $total_remise;
|
||||||
* Calcul TVA
|
$this->total_ht = $totalht;
|
||||||
*/
|
$this->total_tva = $totaltva;
|
||||||
$totaltva = round($totaltva, 2);
|
$this->total_ttc = $totalttc;
|
||||||
$totalht = round($totalht, 2);
|
|
||||||
$totalttc = $totalht + $totaltva;
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$sql = "UPDATE llx_propal set price=$totalht, tva=$totaltva, total=$totalttc, remise=$total_remise WHERE rowid = $rowid";
|
$sql = "UPDATE llx_propal set price=$totalht, tva=$totaltva, total=$totalttc, remise=$total_remise WHERE rowid = $this->id";
|
||||||
if ( $this->db->query($sql) )
|
if ( $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
@ -303,10 +281,6 @@ class Propal
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
@ -465,12 +439,15 @@ class Propal
|
|||||||
if ($user->rights->propale->creer)
|
if ($user->rights->propale->creer)
|
||||||
{
|
{
|
||||||
|
|
||||||
$sql = "UPDATE llx_propal SET remise_percent = ".ereg_replace(",",".",$remise);
|
$remise = ereg_replace(",",".",$remise);
|
||||||
|
|
||||||
|
$sql = "UPDATE llx_propal SET remise_percent = ".$remise;
|
||||||
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
{
|
{
|
||||||
$this->update_price($this->id);
|
$this->remise_percent = $remise;
|
||||||
|
$this->update_price();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user