From bd8ef9fd3853edf783cd0e32c4097e13b05fa98b Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Wed, 16 Feb 2005 15:23:06 +0000 Subject: [PATCH] Gestion du contact facture --- htdocs/telephonie/contrat/fiche.php | 68 +++++++++++-------- .../telephonie/telephonie.contrat.class.php | 40 +++++++++-- 2 files changed, 74 insertions(+), 34 deletions(-) diff --git a/htdocs/telephonie/contrat/fiche.php b/htdocs/telephonie/contrat/fiche.php index 2ec9947d273..cae2f91a996 100644 --- a/htdocs/telephonie/contrat/fiche.php +++ b/htdocs/telephonie/contrat/fiche.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2004-2005 Rodolphe Quiedeville * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -84,16 +84,29 @@ if ($_POST["action"] == 'update' && $_POST["cancel"] <> $langs->trans("Cancel")) if ($_POST["action"] == 'addcontact') { - $ligne = new LigneTel($db); - $ligne->id = $_GET["id"]; + $contrat = new TelephonieContrat($db); + $contrat->id = $_GET["id"]; - if ( $ligne->add_contact($_POST["contact_id"]) ) + if ( $contrat->add_contact_facture($_POST["contact_id"]) ) { - Header("Location: fiche.php?id=".$ligne->id); + Header("Location: fiche.php?id=".$contrat->id); } } +if ($_GET["action"] == 'delcontact') +{ + $contrat = new TelephonieContrat($db); + $contrat->id = $_GET["id"]; + + if ( $contrat->del_contact_facture($_GET["contact_id"]) ) + { + Header("Location: fiche.php?id=".$contrat->id); + } +} + + + if ($_GET["action"] == 'delete') { $contrat = new TelephonieContrat($db); @@ -104,17 +117,6 @@ if ($_GET["action"] == 'delete') } -if ($_GET["action"] == 'delcontact') -{ - $ligne = new LigneTel($db); - $ligne->id = $_GET["id"]; - - if ( $ligne->del_contact($_GET["contact_id"]) ) - { - Header("Location: fiche.php?id=".$ligne->id); - } -} - llxHeader("","","Fiche Contrat"); @@ -488,11 +490,13 @@ else */ - /* Contacts - + /* Contacts */ + print 'Contact facture'; + print ''; + $sql = "SELECT c.idp, c.name, c.firstname, c.email "; $sql .= "FROM ".MAIN_DB_PREFIX."socpeople as c"; - $sql .= ",".MAIN_DB_PREFIX."telephonie_contact_facture as cf"; + $sql .= ",".MAIN_DB_PREFIX."telephonie_contrat_contact_facture as cf"; $sql .= " WHERE c.idp = cf.fk_contact AND cf.fk_contrat = ".$contrat->id." ORDER BY name "; if ( $db->query( $sql) ) { @@ -504,8 +508,7 @@ else { $row = $db->fetch_row($i); - print 'Contact facture '.$i.''; - print ''.$row[1] . " " . $row[2] . " <".$row[3].">"; + print $row[1] . " " . $row[2] . " <".$row[3].">
"; $i++; } } @@ -516,8 +519,8 @@ else { print $sql; } - - Fin Contacts */ + print ''; + /* Fin Contacts */ print "
"; @@ -792,16 +795,17 @@ else { print_fiche_titre('Ajouter un contact', $mesg); - print "
id\" method=\"post\">\n"; + print ''; print ''; print ''; - $sql = "SELECT c.idp, c.name, c.firstname, c.email "; $sql .= "FROM ".MAIN_DB_PREFIX."socpeople as c"; - $sql .= ",".MAIN_DB_PREFIX."telephonie_contact_facture as cf"; - $sql .= " WHERE c.idp = cf.fk_contact AND cf.fk_ligne = ".$ligne->id." ORDER BY name "; + $sql .= ",".MAIN_DB_PREFIX."telephonie_contrat_contact_facture as cf"; + $sql .= " WHERE c.idp = cf.fk_contact "; + $sql .= " AND cf.fk_contrat = ".$contrat->id." ORDER BY name "; + if ( $db->query( $sql) ) { $num = $db->num_rows(); @@ -815,7 +819,7 @@ else print ''; print '"; $i++; @@ -832,7 +836,11 @@ else print ''; - print '
Contact facture '.$i.''.$row[1] . " " . $row[2] . " <".$row[3].">"; print ''; - print ''; + print ''; print img_delete(); print "
Contact'; - $sql = "SELECT idp, name, firstname, email FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$ligne->client_facture_id." ORDER BY name "; + $sql = "SELECT idp, name, firstname, email "; + $sql .= " FROM ".MAIN_DB_PREFIX."socpeople "; + $sql .= " WHERE fk_soc in (".$contrat->client_facture_id.",".$contrat->client_id.")"; + $sql .= " ORDER BY name "; + if ( $db->query( $sql) ) { print '
 '; + print '
'; if ($num > 0) { print ''; diff --git a/htdocs/telephonie/telephonie.contrat.class.php b/htdocs/telephonie/telephonie.contrat.class.php index 7ee4d03e972..419b58698aa 100644 --- a/htdocs/telephonie/telephonie.contrat.class.php +++ b/htdocs/telephonie/telephonie.contrat.class.php @@ -47,7 +47,7 @@ class TelephonieContrat { * Creation du contrat * Le commercial qui fait le suivi est par defaut le commercial qui a signe */ - function create($user) + function create($user, $isfacturable='oui', $mode_paiement='pre') { $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_contrat"; $sql .= " (ref, fk_soc, fk_client_comm, fk_soc_facture, note"; @@ -64,6 +64,8 @@ class TelephonieContrat { $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_contrat"; $sql .= " SET ref='".substr("00000000".$this->id,-8)."'"; + $sql .= " , isfacturable = '".$isfacturable."'"; + $sql .= " , mode_paiement = '".$mode_paiement."'"; $sql .= " WHERE rowid=".$this->id; $this->db->query($sql); @@ -97,8 +99,7 @@ class TelephonieContrat { $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_contrat"; $sql .= " SET "; - $sql .= " fk_client_comm = ".$this->client_comm; - $sql .= ", fk_soc = ".$this->client ; + $sql .= " fk_soc = ".$this->client ; $sql .= ", fk_soc_facture = ".$this->client_facture; $sql .= ", fk_commercial_suiv = ".$this->commercial_suiv_id; $sql .= ", mode_paiement = '".$this->mode_paiement."'"; @@ -118,7 +119,10 @@ class TelephonieContrat { { $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_societe_ligne"; $sql .= " SET "; - $sql .= " mode_paiement = '".$this->mode_paiement."'"; + $sql .= " fk_soc = ".$this->client ; + $sql .= ", fk_soc_facture = ".$this->client_facture; + $sql .= ", fk_commercial_suiv = ".$this->commercial_suiv_id; + $sql .= ", mode_paiement = '".$this->mode_paiement."'"; $sql .= " WHERE fk_contrat = ".$this->id; @@ -224,6 +228,34 @@ class TelephonieContrat { $this->db->query($sql); } + /* + * + * + * + */ + function add_contact_facture($cid) + { + + $this->del_contact_facture($cid); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_contrat_contact_facture"; + $sql .= " (fk_contrat, fk_contact) "; + $sql .= " VALUES ($this->id, $cid )"; + + $this->db->query($sql); + } + /* + * + * + */ + function del_contact_facture($cid) + { + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_contrat_contact_facture"; + $sql .= " WHERE fk_contrat=".$this->id." AND fk_contact=".$cid; + + return $this->db->query($sql); + } } ?>