Implementation des remises
This commit is contained in:
parent
9b74128ec3
commit
277357cd44
@ -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 '<input type="hidden" name="amount" value="'.$amount.'">';
|
||||
print '<input type="hidden" name="total" value="'.$obj->total.'">';
|
||||
print '<input type="hidden" name="remise" value="'.$obj->remise.'">';
|
||||
print '<input type="hidden" name="tva" value="'.$obj->tva.'">';
|
||||
$amount = ($obj->price);
|
||||
print '<input type="hidden" name="amount" value="'.$amount.'">'."\n";
|
||||
print '<input type="hidden" name="total" value="'.$obj->total.'">'."\n";
|
||||
print '<input type="hidden" name="remise" value="'.$obj->remise.'">'."\n";
|
||||
print '<input type="hidden" name="remise_percent" value="'.$obj->remise_percent.'">'."\n";
|
||||
print '<input type="hidden" name="tva" value="'.$obj->tva.'">'."\n";
|
||||
print '<input type="hidden" name="propalid" value="'.$propalid.'">';
|
||||
|
||||
print '<tr><td>Proposition</td><td colspan="2">'.$obj->ref.'</td></tr>';
|
||||
@ -498,7 +510,14 @@ else
|
||||
print "<td>Date limite de réglement : " . strftime("%d %B %Y",$fac->date_lim_reglement) ."</td></tr>";
|
||||
print "<tr><td>Auteur</td><td colspan=\"3\">$author->fullname</td>";
|
||||
|
||||
print '<td rowspan="4" valign="top">';
|
||||
if ($fac->remise_percent > 0)
|
||||
{
|
||||
print '<td rowspan="5" valign="top">';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td rowspan="4" valign="top">';
|
||||
}
|
||||
|
||||
$_MONNAIE="euros";
|
||||
|
||||
@ -564,6 +583,14 @@ else
|
||||
print '<tr><td>Montant</td>';
|
||||
print '<td align="right" colspan="2"><b>'.price($fac->total_ht).'</b></td>';
|
||||
print '<td>euros HT</td></tr>';
|
||||
|
||||
if ($fac->remise_percent > 0)
|
||||
{
|
||||
print '<tr><td>Remise</td>';
|
||||
print '<td align="right" colspan="2">'.$fac->remise_percent.'</td>';
|
||||
print '<td>%</td></tr>';
|
||||
}
|
||||
|
||||
print '<tr><td>TVA</td><td align="right" colspan="2">'.price($fac->total_tva).'</td>';
|
||||
print '<td>euros</td></tr>';
|
||||
print '<tr><td>Total</td><td align="right" colspan="2">'.price($fac->total_ttc).'</td>';
|
||||
@ -573,7 +600,18 @@ else
|
||||
print '<tr><td colspan="5">Note : '.nl2br($obj->note)."</td></tr>";
|
||||
}
|
||||
|
||||
print "</table><br>";
|
||||
print "</table><br>";
|
||||
|
||||
if ($fac->brouillon == 1)
|
||||
{
|
||||
print '<form action="facture.php3?facid='.$facid.'" method="post">';
|
||||
print '<input type="hidden" name="action" value="setremise">';
|
||||
print '<table cellpadding="3" cellspacing="0" border="1"><tr><td>Remise</td><td align="right">';
|
||||
print '<input type="text" name="remise" size="3" value="'.$fac->remise_percent.'">%';
|
||||
print '<input type="submit" value="Appliquer">';
|
||||
print '</td></tr></table></form>';
|
||||
}
|
||||
|
||||
/*
|
||||
* Lignes de factures
|
||||
*
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user