Ajout sécurités

This commit is contained in:
Rodolphe Quiedeville 2003-08-04 18:08:24 +00:00
parent b6bdc1b4f7
commit 9601acab85

View File

@ -137,7 +137,7 @@ class Facture
Function fetch($rowid) 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"; $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 .= " FROM llx_facture as f, llx_cond_reglement as c"; $sql .= " FROM llx_facture as f, llx_cond_reglement as c";
$sql .= " WHERE f.rowid=$rowid AND c.rowid = f.fk_cond_reglement"; $sql .= " WHERE f.rowid=$rowid AND c.rowid = f.fk_cond_reglement";
@ -147,21 +147,28 @@ class Facture
{ {
$obj = $this->db->fetch_object(0); $obj = $this->db->fetch_object(0);
$this->id = $rowid; $this->id = $rowid;
$this->datep = $obj->dp; $this->datep = $obj->dp;
$this->date = $obj->df; $this->date = $obj->df;
$this->ref = $obj->facnumber; $this->ref = $obj->facnumber;
$this->total_ht = $obj->amount; $this->total_ht = $obj->amount;
$this->total_tva = $obj->tva; $this->total_tva = $obj->tva;
$this->total_ttc = $obj->total; $this->total_ttc = $obj->total;
$this->paye = $obj->paye; $this->paye = $obj->paye;
$this->remise = $obj->remise; $this->remise = $obj->remise;
$this->socidp = $obj->fk_soc; $this->socidp = $obj->fk_soc;
$this->statut = $obj->fk_statut;
$this->date_lim_reglement = $obj->dlr; $this->date_lim_reglement = $obj->dlr;
$this->cond_reglement = $obj->libelle; $this->cond_reglement = $obj->libelle;
$this->projetid = $obj->fk_projet; $this->projetid = $obj->fk_projet;
$this->note = stripslashes($obj->note); $this->note = stripslashes($obj->note);
$this->lignes = array(); $this->lignes = array();
if ($this->statut == 0)
{
$this->brouillon = 1;
}
$this->db->free(); $this->db->free();
/* /*
@ -298,51 +305,54 @@ class Facture
*/ */
Function set_valid($rowid, $user) Function set_valid($rowid, $user)
{ {
$action_notify = 2; // ne pas modifier cette valeur if ($this->brouillon)
$sql = "UPDATE llx_facture set fk_statut = 1, fk_user_valid = $user->id WHERE rowid = $rowid ;";
$result = $this->db->query( $sql);
/*
* Notify
*
*/
$filepdf = FAC_OUTPUTDIR . "/" . $this->ref . "/" . $this->ref . ".pdf";
$mesg = "La facture ".$this->ref." a été validée.\n";
$notify = New Notify($this->db);
$notify->send($action_notify, $this->socidp, $mesg, "facture", $rowid, $filepdf);
/*
* Update Stats
*
*/
$sql = "SELECT fk_product FROM llx_facturedet WHERE fk_facture = ".$this->id;
$sql .= " AND fk_product IS NOT NULL";
$result = $this->db->query($sql);
if ($result)
{ {
$num = $this->db->num_rows(); $action_notify = 2; // ne pas modifier cette valeur
$i = 0;
while ($i < $num) $sql = "UPDATE llx_facture set fk_statut = 1, fk_user_valid = $user->id WHERE rowid = $rowid ;";
$result = $this->db->query( $sql);
/*
* Notify
*
*/
$filepdf = FAC_OUTPUTDIR . "/" . $this->ref . "/" . $this->ref . ".pdf";
$mesg = "La facture ".$this->ref." a été validée.\n";
$notify = New Notify($this->db);
$notify->send($action_notify, $this->socidp, $mesg, "facture", $rowid, $filepdf);
/*
* Update Stats
*
*/
$sql = "SELECT fk_product FROM llx_facturedet WHERE fk_facture = ".$this->id;
$sql .= " AND fk_product IS NOT NULL";
$result = $this->db->query($sql);
if ($result)
{ {
$obj = $this->db->fetch_object($i); $num = $this->db->num_rows();
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($i);
$sql = "UPDATE llx_product SET nbvente=nbvente+1 WHERE rowid = ".$obj->fk_product; $sql = "UPDATE llx_product SET nbvente=nbvente+1 WHERE rowid = ".$obj->fk_product;
$db2 = $this->db->clone(); $db2 = $this->db->clone();
$result = $db2->query($sql); $result = $db2->query($sql);
$i++; $i++;
}
} }
} /*
/* * Contrats
* Contrats */
*/ $contrat = new Contrat($this->db);
$contrat = new Contrat($this->db); $contrat->create_from_facture($this->id, $user, $this->socidp);
$contrat->create_from_facture($this->id, $user, $this->socidp);
return $result; return $result;
}
} }
/* /*
* *
@ -350,12 +360,15 @@ class Facture
*/ */
Function addline($facid, $desc, $pu, $qty, $txtva, $fk_product='NULL') Function addline($facid, $desc, $pu, $qty, $txtva, $fk_product='NULL')
{ {
$sql = "INSERT INTO llx_facturedet (fk_facture,description,price,qty,tva_taux, fk_product)"; if ($this->brouillon)
$sql .= " VALUES ($facid, '$desc', $pu, $qty, $txtva, $fk_product) ;";
if ( $this->db->query( $sql) )
{ {
$this->updateprice($facid); $sql = "INSERT INTO llx_facturedet (fk_facture,description,price,qty,tva_taux, fk_product)";
$sql .= " VALUES ($facid, '$desc', $pu, $qty, $txtva, $fk_product) ;";
if ( $this->db->query( $sql) )
{
$this->updateprice($facid);
}
} }
} }
/* /*
@ -364,10 +377,13 @@ class Facture
*/ */
Function updateline($rowid, $desc, $pu, $qty) Function updateline($rowid, $desc, $pu, $qty)
{ {
$sql = "UPDATE llx_facturedet set description='$desc',price=$pu,qty=$qty WHERE rowid = $rowid ;"; if ($this->brouillon)
$result = $this->db->query( $sql); {
$sql = "UPDATE llx_facturedet set description='$desc',price=$pu,qty=$qty WHERE rowid = $rowid ;";
$result = $this->db->query( $sql);
$this->updateprice($this->id); $this->updateprice($this->id);
}
} }
/* /*
* *
@ -375,10 +391,13 @@ class Facture
*/ */
Function deleteline($rowid) Function deleteline($rowid)
{ {
$sql = "DELETE FROM llx_facturedet WHERE rowid = $rowid;"; if ($this->brouillon)
$result = $this->db->query( $sql); {
$sql = "DELETE FROM llx_facturedet WHERE rowid = $rowid;";
$result = $this->db->query( $sql);
$this->updateprice($this->id); $this->updateprice($this->id);
}
} }
/* /*
* *