Gestion de la date d'échéance

This commit is contained in:
Rodolphe Quiedeville 2005-07-20 12:15:20 +00:00
parent 4b3643d964
commit 3b6b574b9e

View File

@ -93,97 +93,98 @@ class FactureFournisseur
$number = sanitize_string(strtoupper($this->number)); $number = sanitize_string(strtoupper($this->number));
$amount = $this->amount; $amount = $this->amount;
$remise = $this->remise; $remise = $this->remise;
$this->db->begin(); $this->db->begin();
if (! $remise) $remise = 0 ; if (! $remise) $remise = 0 ;
$totalht = ($amount - $remise); $totalht = ($amount - $remise);
$tva = tva($totalht); $tva = tva($totalht);
$total = $totalht + $tva; $total = $totalht + $tva;
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn (facnumber, libelle, fk_soc, datec, datef, note, fk_user_author) "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn (facnumber, libelle, fk_soc, datec, datef, note, fk_user_author, date_lim_reglement) ";
$sql .= " VALUES ('".$number."','".addslashes($this->libelle)."',"; $sql .= " VALUES ('".$number."','".addslashes($this->libelle)."',";
$sql .= $this->socid.", now(),".$this->db->idate($this->date).",'".addslashes($this->note)."', ".$user->id.");"; $sql .= $this->socid.", now(),'".$this->db->idate($this->date)."','".addslashes($this->note)."', ".$user->id.",'".$this->db->idate($this->date_echeance)."');";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_fourn"); $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_fourn");
for ($i = 0 ; $i < sizeof($this->lignes) ; $i++) for ($i = 0 ; $i < sizeof($this->lignes) ; $i++)
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn_det (fk_facture_fourn)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn_det (fk_facture_fourn)";
$sql .= " VALUES ($this->id);"; $sql .= " VALUES ($this->id);";
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_fourn_det"); $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_fourn_det");
$this->updateline($idligne, $this->updateline($idligne,
$this->lignes[$i][0], $this->lignes[$i][0],
$this->lignes[$i][1], $this->lignes[$i][1],
$this->lignes[$i][2], $this->lignes[$i][2],
$this->lignes[$i][3]); $this->lignes[$i][3]);
} }
} }
// Mise à jour prix // Mise à jour prix
if ($this->updateprice($this->id) > 0) if ($this->updateprice($this->id) > 0)
{ {
$this->db->commit(); $this->db->commit();
return $this->id; return $this->id;
} }
else { else
$this->error=$langs->trans("FailedToUpdatePrice"); {
$this->db->rollback(); $this->error=$langs->trans("FailedToUpdatePrice");
return -3; $this->db->rollback();
} return -3;
}
} }
else else
{ {
if ($this->db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS) if ($this->db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS)
{ {
$this->error=$langs->trans("ErrorBillRefAlreadyExists"); $this->error=$langs->trans("ErrorBillRefAlreadyExists");
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
} }
} }
/** /**
* \brief Recupére l'objet facture et ses lignes de factures * \brief Recupére l'objet facture et ses lignes de factures
* \param rowid id de la facture a récupérer * \param rowid id de la facture a récupérer
*/ */
function fetch($rowid) function fetch($rowid)
{ {
$sql = "SELECT fk_soc,libelle,facnumber,amount,remise,".$this->db->pdate(datef)."as df"; $sql = "SELECT fk_soc,libelle,facnumber,amount,remise,".$this->db->pdate(datef)."as df";
$sql .= ", total_ht, total_tva, total_ttc, fk_user_author"; $sql .= ", total_ht, total_tva, total_ttc, fk_user_author";
$sql .= ", fk_statut, paye, f.note"; $sql .= ", fk_statut, paye, f.note,".$this->db->pdate(date_lim_reglement)."as de";
$sql .= ", s.nom as socnom, s.idp as socidp"; $sql .= ", s.nom as socnom, s.idp as socidp";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."societe as s"; $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."societe as s";
$sql .= " WHERE f.rowid=$rowid AND f.fk_soc = s.idp ;"; $sql .= " WHERE f.rowid=$rowid AND f.fk_soc = s.idp ;";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
if ($this->db->num_rows()) if ($this->db->num_rows())
{ {
$obj = $this->db->fetch_object(); $obj = $this->db->fetch_object();
$this->id = $rowid; $this->id = $rowid;
$this->datep = $obj->df; $this->datep = $obj->df;
$this->ref = $obj->facnumber; $this->date_echeance = $obj->de;
$this->libelle = $obj->libelle; $this->ref = $obj->facnumber;
$this->libelle = $obj->libelle;
$this->remise = $obj->remise; $this->remise = $obj->remise;
$this->socidp = $obj->fk_soc; $this->socidp = $obj->fk_soc;
$this->total_ht = $obj->total_ht; $this->total_ht = $obj->total_ht;
$this->total_tva = $obj->total_tva; $this->total_tva = $obj->total_tva;