From 8bf14096bdfb18236a2ff16c74ce361c486db0b5 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Mon, 9 Feb 2004 14:41:41 +0000 Subject: [PATCH] Gestion des paiements sur multiple facture --- htdocs/paiement.class.php | 170 ++++++++++++++++++++++++++++++++++---- 1 file changed, 154 insertions(+), 16 deletions(-) diff --git a/htdocs/paiement.class.php b/htdocs/paiement.class.php index 0e82bc07812..d036f5a89f6 100644 --- a/htdocs/paiement.class.php +++ b/htdocs/paiement.class.php @@ -41,33 +41,125 @@ class Paiement { $this->db = $DB ; } + /* + * + * + */ + Function fetch($id) + { + $sql = "SELECT p.rowid,".$this->db->pdate("p.datep")." as dp, p.amount"; + $sql .=", c.libelle as paiement_type, p.num_paiement"; + $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."c_paiement as c"; + $sql .= " WHERE p.fk_paiement = c.id"; + $sql .=" AND p.rowid = ".$id; + + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows()) + { + $obj = $this->db->fetch_object($result , 0); + + $this->id = $obj->rowid; + $this->date = $obj->dp; + $this->numero = $obj->num_paiement; + $this->montant = $obj->amount; + $this->note = $obj->note; + $this->type_libelle = $obj->paiement_type; + } + $this->db->free(); + + // + // Factures concernées + // TODO déplacer dans une autre table l'info pour permettre le paiement + // Sur plusieurs factures + // + $sql = "SELECT p.rowid,".$this->db->pdate("p.datep")." as dp, p.amount"; + $sql .=", c.libelle as paiement_type, p.num_paiement"; + $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."c_paiement as c"; + $sql .= " WHERE p.fk_paiement = c.id"; + $sql .=" AND p.rowid = ".$id; + + $result = $this->db->query($sql); + + if ($result) + { + if ($this->db->num_rows()) + { + $obj = $this->db->fetch_object($result , 0); + } + } + + } + else + { + print $this->db->error(); + } + } /* * * * */ - Function create() + Function create($pid, $user) { /* * Insertion dans la base */ - - $this->amount = ereg_replace(",",".",$this->amount); + if (strlen(trim($this->amount))) + { + $this->amount = ereg_replace(",",".",$this->amount); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (fk_facture, datec, datep, amount, author, fk_paiement, num_paiement, note)"; - $sql .= " VALUES ($this->facid, now(), $this->datepaye,$this->amount,'$this->author', $this->paiementid, '$this->num_paiement', '$this->note')"; - - $result = $this->db->query($sql); - - if ($result) - { - $this->id = $this->db->last_insert_id(); - return $this->id; - } - else - { + if ($pid > 0) + { + $sql = "INSERT INTO llx_paiement_facture (fk_facture, fk_paiement, amount)"; + $sql .= " VALUES ($this->facid, $pid, $this->amount)"; + + $result = $this->db->query($sql); + + $sql = "UPDATE llx_paiement SET amount = amount + ".$this->amount; + $result = $this->db->query($sql); + + return $pid; + } + else + { + + $sql = "INSERT INTO llx_paiement (fk_facture, datec, datep, amount, author, fk_paiement, num_paiement, note, fk_user_creat)"; + $sql .= " VALUES ($this->facid, now(), $this->datepaye,$this->amount,'$this->author', $this->paiementid, '$this->num_paiement', '$this->note', $user->id)"; + + $result = $this->db->query($sql); + + if ($result) + { + $this->id = $this->db->last_insert_id(); + + $sql = "INSERT INTO llx_paiement_facture (fk_facture, fk_paiement, amount)"; + $sql .= " VALUES ($this->facid, ".$this->id.", $this->amount)"; + + $result = $this->db->query($sql); + + $sql = "UPDATE llx_paiement SET amount = amount + ".$this->amount; + $result = $this->db->query($sql); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (fk_facture, datec, datep, amount, author, fk_paiement, num_paiement, note)"; + $sql .= " VALUES ($this->facid, now(), $this->datepaye,$this->amount,'$this->author', $this->paiementid, '$this->num_paiement', '$this->note')"; + + $result = $this->db->query($sql); + + if ($result) + { + $this->id = $this->db->last_insert_id(); + return $this->id; + + } + else + { print $this->db->error() ."
".$sql; - } + } + } + } } /* * @@ -115,6 +207,11 @@ class Paiement if ($result) { + + $sql = "DELETE FROM llx_paiement_facture WHERE fk_paiement.rowid = ".$this->id; + + $result = $this->db->query($sql); + return 1; } else @@ -130,5 +227,46 @@ class Paiement return 0; } } + /* + * Information sur l'objet + * + */ + Function info($id) + { + $sql = "SELECT c.rowid, ".$this->db->pdate("datec")." as datec, fk_user_creat, fk_user_modif"; + $sql .= ", ".$this->db->pdate("tms")." as tms"; + $sql .= " FROM ".MAIN_DB_PREFIX."paiement as c"; + $sql .= " WHERE c.rowid = $id"; + + if ($this->db->query($sql)) + { + if ($this->db->num_rows()) + { + $obj = $this->db->fetch_object($result , 0); + + $this->id = $obj->idp; + + $cuser = new User($this->db, $obj->fk_user_creat); + $cuser->fetch(); + + $this->user_creation = $cuser; + + $muser = new User($this->db, $obj->fk_user_modif); + $muser->fetch(); + + $this->user_modification = $muser; + + $this->date_creation = $obj->datec; + $this->date_modification = $obj->tms; + + } + $this->db->free(); + + } + else + { + print $this->db->error(); + } + } } ?>