Gestion du contact facture

This commit is contained in:
Rodolphe Quiedeville 2005-02-16 15:23:06 +00:00
parent d5ab0df63d
commit bd8ef9fd38
2 changed files with 74 additions and 34 deletions

View File

@ -1,5 +1,5 @@
<?PHP
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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 '<tr><td valign="top" width="20%">Contact facture</td>';
print '<td valign="top" colspan="2">';
$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 '<tr><td valign="top" width="20%">Contact facture '.$i.'</td>';
print '<td valign="top" colspan="2">'.$row[1] . " " . $row[2] . " &lt;".$row[3]."&gt;</td></tr>";
print $row[1] . " " . $row[2] . " &lt;".$row[3]."&gt;<br />";
$i++;
}
}
@ -516,8 +519,8 @@ else
{
print $sql;
}
Fin Contacts */
print '</td></tr>';
/* Fin Contacts */
print "</table><br />";
@ -792,16 +795,17 @@ else
{
print_fiche_titre('Ajouter un contact', $mesg);
print "<form action=\"fiche.php?id=$ligne->id\" method=\"post\">\n";
print '<form action="fiche.php?id='.$contrat->id.'" method="post">';
print '<input type="hidden" name="action" value="addcontact">';
print '<table class="border" width="100%" cellspacing="0" cellpadding="4">';
$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 '<tr><td valign="top" width="20%">Contact facture '.$i.'</td>';
print '<td valign="top">'.$row[1] . " " . $row[2] . " &lt;".$row[3]."&gt;";
print '</td><td>';
print '<a href="fiche.php?id='.$ligne->id.'&amp;action=delcontact&amp;contact_id='.$row[0].'">';
print '<a href="fiche.php?id='.$contrat->id.'&amp;action=delcontact&amp;contact_id='.$row[0].'">';
print img_delete();
print "</a></td></tr>";
$i++;
@ -832,7 +836,11 @@ else
print '<tr><td valign="top" width="20%">Contact</td><td valign="top" colspan="2">';
$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 '<select name="contact_id">';
@ -858,7 +866,7 @@ else
print '<p>Contact auquel est envoyé la facture par email</p></td></tr>';
print '<tr><td>&nbsp;</td><td>';
print '<tr><td colspan="3" align="center">';
if ($num > 0)
{
print '<input type="submit" value="Ajouter">';

View File

@ -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);
}
}
?>