diff --git a/htdocs/telephonie/contrat/services.php b/htdocs/telephonie/contrat/services.php index dc9405db759..3d48d0d7ed3 100644 --- a/htdocs/telephonie/contrat/services.php +++ b/htdocs/telephonie/contrat/services.php @@ -35,12 +35,12 @@ if ($_POST["action"] == 'addservice') } } -if ($_POST["action"] == 'rmservice') +if ($_GET["action"] == 'rmservice') { $contrat = new TelephonieContrat($db); $contrat->id= $_GET["id"]; - if ( $contrat->remove_service($user, $_POST["service_id"]) == 0) + if ( $contrat->remove_service($user, $_GET["service_id"]) == 0) { Header("Location: services.php?id=".$contrat->id); } @@ -189,7 +189,7 @@ if ($cancel == $langs->trans("Cancel")) print ''; - $sql = "SELECT s.libelle, s.statut, s.rowid as serid, s.montant"; + $sql = "SELECT s.libelle, s.statut, cs.rowid as serid, s.montant, cs.montant as montant_fac"; $sql .= ", cs.rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_contrat_service as cs"; $sql .= " , ".MAIN_DB_PREFIX."telephonie_service as s"; @@ -208,8 +208,9 @@ if ($cancel == $langs->trans("Cancel")) $ligne = new LigneTel($db); print ''; - print ''; - print "\n"; + print ''; + print ''; + print "\n"; while ($i < $numlignes) { @@ -223,6 +224,7 @@ if ($cancel == $langs->trans("Cancel")) print ''.$obj->libelle."\n"; + print '\n"; print '\n"; print '
ServiceMontant 
Montant FacturéMontant du service 
'.price($obj->montant_fac)." euros HT'.price($obj->montant)." euros HT'; diff --git a/htdocs/telephonie/telephonie.contrat.class.php b/htdocs/telephonie/telephonie.contrat.class.php index b10be9975b6..560d22b43bf 100644 --- a/htdocs/telephonie/telephonie.contrat.class.php +++ b/htdocs/telephonie/telephonie.contrat.class.php @@ -274,13 +274,36 @@ class TelephonieContrat { */ function add_service($user, $sid) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_contrat_service"; - $sql .= " (fk_contrat, fk_service, fk_user_creat, date_creat) "; - $sql .= " VALUES ($this->id, $sid, $user->id, now() )"; - - if ($this->db->query($sql) ) + $result = 0; + + $sql = "SELECT montant FROM ".MAIN_DB_PREFIX."telephonie_service"; + $sql .= " WHERE rowid=".$sid; + + $resql = $this->db->query( $sql); + + if ($resql) { - return 0 ; + $row = $this->db->fetch_row($resql); + $montant = $row[0]; + } + else + { + $result = -1; + } + + + if ($result == 0) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_contrat_service"; + $sql .= " (fk_contrat, fk_service, fk_user_creat, date_creat, montant) "; + $sql .= " VALUES ($this->id, $sid, $user->id, now(),".$montant.")"; + + $resql = $this->db->query( $sql); + + if ($resql) + { + return 0 ; + } } } /* @@ -290,8 +313,8 @@ class TelephonieContrat { function remove_service($user, $sid) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_contrat_service"; - $sql .= " (fk_contrat, fk_service, fk_user_creat, date_creat) "; - $sql .= " VALUES ($this->id, $sid, $user->id, now() )"; + $sql .= " WHERE fk_contrat = ".$this->id; + $sql .= " AND rowid = ".$sid; if ($this->db->query($sql) ) {