* * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ * $Source$ * */ require "./pre.inc.php"; require_once DOL_DOCUMENT_ROOT."/telephonie/dolibarrmail.class.php"; $mesg = ''; if ($_POST["action"] == 'add' && $user->rights->telephonie->ligne->creer) { $contrat = new TelephonieContrat($db); $contrat->client_comm = $_POST["client_comm"]; $contrat->client = $_POST["client"]; $contrat->client_facture = $_POST["client_facture"]; $contrat->commercial_sign = $_POST["commercial_sign"]; $contrat->note = $_POST["note"]; if ( $contrat->create($user) == 0) { $soc = new Societe($db); $soc->id = $_POST["client_comm"]; $soc->AddPerms($user->id,1,1,1); $soc->AddPerms($_POST["commercial_sign"],1,1,1); Header("Location: fiche.php?id=".$contrat->id); } else { $_GET["action"] = 'create'; } } if ($_POST["action"] == 'update' && $_POST["cancel"] <> $langs->trans("Cancel") && $user->rights->telephonie->ligne->creer) { $contrat = new TelephonieContrat($db); $contrat->id = $_GET["id"]; $contrat->client = $_POST["client"]; $contrat->client_facture = $_POST["client_facture"]; $contrat->fournisseur = $_POST["fournisseur"]; $contrat->commercial = $_POST["commercial"]; $contrat->concurrent = $_POST["concurrent"]; $contrat->note = $_POST["note"]; $contrat->mode_paiement = $_POST["mode_paiement"]; $contrat->grille_tarif_id = $_POST["grille_tarif_id"]; $contrat->commercial_suiv_id = $_POST["commercial_suiv"]; if ( $contrat->update($user) == 0) { $action = ''; $mesg = 'Fiche mise à jour'; Header("Location: fiche.php?id=".$contrat->id); } else { $action = 're-edit'; $mesg = 'Fiche non mise à jour !' . "
" . $entrepot->mesg_error; } } if ($_POST["action"] == 'addcontact' && $user->rights->telephonie->ligne->creer) { $contrat = new TelephonieContrat($db); $contrat->id = $_GET["id"]; if ( $contrat->add_contact_facture($_POST["contact_id"]) ) { Header("Location: fiche.php?id=".$contrat->id); } } if ($_POST["action"] == 'addpo' && $user->rights->telephonie->ligne->creer) { $contrat = new TelephonieContrat($db); $contrat->fetch($_GET["id"]); $contrat->addpo($_POST["montant"], $user); Header("Location: fiche.php?id=".$contrat->id); } if ($_GET["action"] == 'delcontact' && $user->rights->telephonie->ligne->creer) { $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' && $user->rights->telephonie->ligne->creer) { $contrat = new TelephonieContrat($db); $contrat->id = $_GET["id"]; $contrat->delete() ; Header("Location: index.php"); } llxHeader("","","Fiche Contrat"); if ($cancel == $langs->trans("Cancel")) { $action = ''; } /* * Création en 2 étape * */ if ($_GET["action"] == 'create' && $user->rights->telephonie->ligne->creer) { $form = new Form($db); print_titre("Nouveau contrat"); if (is_object($ligne)) { // La création a échouée print $ligne->error_message; } else { $ligne = new LigneTel($db); } print '
'; print ''; print ''; print ''; print ''."\n"; print '
Client'; $ff = array(); $sql = "SELECT rowid, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1 AND (parent = 0 OR parent IS NULL) ORDER BY nom "; if ( $db->query( $sql) ) { $num = $db->num_rows(); if ( $num > 0 ) { $i = 0; while ($i < $num) { $row = $db->fetch_row($i); $ff[$row[0]] = $row[1] . " (".$row[2].")"; $i++; } } $db->free(); } $form->select_array("client_comm",$ff,$ligne->client_comm); print '
 
'."\n"; print '
'; } elseif ($_GET["action"] == 'create_line' && $_GET["client_comm"] > 0 && $user->rights->telephonie->ligne->creer) { $form = new Form($db); print_titre("Nouveau contrat"); if (is_object($ligne)) { // La création a échouée print $ligne->error_message; } else { $ligne = new LigneTel($db); } $socc = new Societe($db); $socc->fetch($_GET["client_comm"]); if ( $socc->id > 0) { if (strlen($socc->code_client) == 0) { print ''; print ''; print ''; print '
Client'; print ''.$socc->nom.''; print '
Code client'; print $socc->code_client; print '


'; print 'Impossible de créer un contrat pour cette société, vous devez au préalablement lui affecter un code client.'; } elseif (strlen($socc->code_client) > 0 && $socc->check_codeclient() <> 0) { print ''; print ''; print ''; print '
Client'; print ''.$socc->nom.''; print '
Code client'; print $socc->code_client; print '


'; print 'Le code client de cette société est incorrect, vous devez lui affecter un code client correct.'; } else { print "
\n"; print ''; print ''."\n"; print ''; print ''; print ''; print ''; print ''; /* * Commercial */ print ''; print ''."\n"; print ''."\n"; print '
Client'; print $socc->nom; print '
Code client'; print $socc->code_client; print '
Client (Agence/Filiale)'; $ff = array(); $sql = "SELECT rowid, nom, ville FROM ".MAIN_DB_PREFIX."societe"; $sql .= " WHERE client=1"; $sql .= " AND (rowid = ".$socc->id." OR parent = ".$socc->id.")"; $sql .= " ORDER BY nom "; if ( $db->query( $sql) ) { $num = $db->num_rows(); if ( $num > 0 ) { $i = 0; while ($i < $num) { $row = $db->fetch_row(); $ff[$row[0]] = $row[1] . " (".$row[2].")"; $i++; } } $db->free(); } else { print $sql; } $form->select_array("client",$ff,$ligne->client); print '
Client à facturer'; $ff = array(); $sql = "SELECT rowid, nom, ville FROM ".MAIN_DB_PREFIX."societe WHERE client=1"; $sql .= " AND (rowid = ".$socc->id." OR parent = ".$socc->id.")"; $sql .= " ORDER BY nom "; if ( $db->query( $sql) ) { $num = $db->num_rows(); if ( $num > 0 ) { $i = 0; while ($i < $num) { $row = $db->fetch_row(); $ff[$row[0]] = $row[1] . " (".$row[2].")"; $i++; } } $db->free(); } $form->select_array("client_facture",$ff,$ligne->client_facture); print '
Commercial Signature'; $ff = array(); $sql = "SELECT u.rowid, u.firstname, u.name"; $sql .= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."usergroup_user as ug"; $sql .= " WHERE u.rowid = ug.fk_user"; $sql .= " AND ug.fk_usergroup = '".TELEPHONIE_GROUPE_COMMERCIAUX_ID."'"; $sql .= " ORDER BY name "; if ( $db->query( $sql) ) { $num = $db->num_rows(); if ( $num > 0 ) { $i = 0; while ($i < $num) { $row = $db->fetch_row($i); $ff[$row[0]] = $row[1] . " " . $row[2]; $i++; } } $db->free(); } $form->select_array("commercial_sign",$ff,$ligne->commercial); print '
Note'."\n"; print '
 
'."\n"; print '
'; /* * Contrats existants */ $sql = "SELECT c.rowid, c.ref, s.rowid as socid, s.nom "; $sql .= ", sf.rowid as sfidp, sf.nom as sfnom"; $sql .= ", sa.rowid as saidp, sa.nom as sanom"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= " , ".MAIN_DB_PREFIX."societe as sf"; $sql .= " , ".MAIN_DB_PREFIX."societe as sa"; $sql .= " , ".MAIN_DB_PREFIX."telephonie_contrat as c"; $sql .= " WHERE c.fk_client_comm = s.rowid"; $sql .= " AND c.fk_soc = sa.rowid"; $sql .= " AND c.fk_soc_facture = sf.rowid"; $sql .= " AND s.rowid = ".$_GET["client_comm"]; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; if ($num > 0) { print"
\n\n"; print_titre("Contrats existants"); print '
'; print ''; print ''; print ''; print "\n"; $var=True; while ($i < $num) { $obj = $db->fetch_object(); $var=!$var; print "\n"; print ''; print ''; print ''; print "\n"; $i++; } print "
RéfClientClient (Agence/Filiale)Client facturé
"; print ''; print img_file(); print ' '; print ''.$obj->ref."'.stripslashes($obj->nom).''.stripslashes($obj->sanom).''.stripslashes($obj->sfnom).'
"; } $db->free(); } else { print $db->error() . ' ' . $sql; } } } else { print "Erreur"; } } else { /* Consultation */ if ($_GET["id"]) { if ($_GET["action"] <> 're-edit') { $contrat = new TelephonieContrat($db); if ($contrat->fetch($_GET["id"]) == 0) { $result = 1; } } if ($result == 1) { $client_comm = new TelephonieClient($db); $client_comm->fetch($contrat->client_comm_id, $user); } if (!$client_comm->perm_read) { print "Lecture non authorisée"; } if ( $result && $client_comm->perm_read) { $contrat->log_consult($user,'r'); if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') { $h=0; $head[$h][0] = DOL_URL_ROOT."/telephonie/contrat/fiche.php?id=".$contrat->id; $head[$h][1] = $langs->trans("Contrat"); $hselected = $h; $h++; $nser = $contrat->count_associated_services(); $head[$h][0] = DOL_URL_ROOT."/telephonie/contrat/services.php?id=".$contrat->id; if ($nser > 0) { $head[$h][1] = $langs->trans("Services")." (".$nser.")"; } else { $head[$h][1] = $langs->trans("Services"); } $h++; /* * Mise en place de l'interface greffon */ if($conf->global->TELEPHONIE_CONTRAT_PLUGIN) { require_once DOL_DOCUMENT_ROOT.'/telephonie/contrat/modules/'.$conf->global->TELEPHONIE_CONTRAT_PLUGIN.'.php'; $var = $conf->global->TELEPHONIE_CONTRAT_PLUGIN; $plugin = new $var; if($plugin->tabs($head,$h)) $h++; else dolibarr_syslog("$var::tabs error"); } $head[$h][0] = DOL_URL_ROOT."/telephonie/contrat/stats.php?id=".$contrat->id; $head[$h][1] = $langs->trans("Stats"); $h++; $head[$h][0] = DOL_URL_ROOT."/telephonie/contrat/info.php?id=".$contrat->id; $head[$h][1] = $langs->trans("Infos"); $h++; $contrat->load_previous_next_id(); $previous_ref = $contrat->ref_previous?''.img_previous().'':''; $next_ref = $contrat->ref_next?''.img_next().'':''; dolibarr_fiche_head($head, $hselected, 'Contrat : '.$contrat->ref); //print_fiche_titre('Fiche Contrat', $mesg); print ''; print '
Fiche Contrat'.$product->ref.''; print ''.$previous_ref.''.$next_ref.'

'; print ''; //$client_comm = new Societe($db); //$client_comm->fetch($contrat->client_comm_id); print ''; print ''; print ''; if ($contrat->client_id <> $contrat->client_comm_id) { $client = new Societe($db, $contrat->client_id); $client->fetch($contrat->client_id); print ''; } $client_facture = new Societe($db); $client_facture->fetch($contrat->client_facture_id); print ''; $commercial = new User($db, $contrat->commercial_sign_id); $commercial->fetch(); print ''; print ''; print ''; $commercial_suiv = new User($db, $contrat->commercial_suiv_id); $commercial_suiv->fetch(); print ''; print ''; /* Prise d'ordre */ print ''; $po = $contrat->priseordre_totale(); print ''; /* print ''; */ /* Contacts */ print ''; print ''; /* Fin Contacts */ print "
Référence'.$contrat->ref.'Facturé : '.$contrat->facturable.''; print ' '; print $contrat->statuts[$contrat->statut].'
Client'; print ''; print $client_comm->nom.''.$client_comm->code_client; print '
Client (Agence/Filiale)'; print $client->nom.'
'; print $client->cp . " " .$client->ville; print '
'.$client->code_client; print '
Client Facturé'; print ''; print $client_facture->nom.'
'; print $client_facture->cp . " " .$client_facture->ville; print '
'.$client_facture->code_client; print ''; if ($contrat->mode_paiement == 'pre') { print 'RIB : '.$client_facture->display_rib(); } else { print 'Paiement par virement'; } print '
Commercial Signature'.$commercial->fullname.'Grille tarif'.$contrat->grille_tarif_nom.'
Commercial Suivi'.$commercial_suiv->fullname.'
Prise d\'ordre mensuelle'.$po.' euros HT
Statut'; print ' '; print $contrat->statuts[$contrat->statut]; print '
Contact facture'; $sql = "SELECT c.rowid, c.name, c.firstname, c.email "; $sql .= "FROM ".MAIN_DB_PREFIX."socpeople as c"; $sql .= ",".MAIN_DB_PREFIX."telephonie_contrat_contact_facture as cf"; $sql .= " WHERE c.rowid = cf.fk_contact AND cf.fk_contrat = ".$contrat->id." ORDER BY name "; if ( $db->query( $sql) ) { $num = $db->num_rows(); if ( $num > 0 ) { $i = 0; while ($i < $num) { $row = $db->fetch_row($i); print $row[1] . " " . $row[2] . " <".$row[3].">
"; $i++; } } $db->free(); } else { print $sql; } print '

"; /* Lignes */ print ''; $sql = "SELECT l.ligne, l.statut, l.rowid, l.remise, l.techno, f.nom as fournisseur"; $sql .= ", ss.code_client, ss.nom as agence, l.support"; $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne as l"; $sql .= " , ".MAIN_DB_PREFIX."societe as ss"; $sql .= " , ".MAIN_DB_PREFIX."telephonie_fournisseur as f"; $sql .= " WHERE l.fk_fournisseur = f.rowid"; $sql .= " AND l.fk_soc = ss.rowid "; $sql .= " AND l.fk_contrat = ".$contrat->id; $sql .= " ORDER BY l.statut ASC, l.ligne ASC"; if ( $db->query( $sql) ) { $numlignes = $db->num_rows(); if ( $numlignes > 0 ) { $i = 0; $ligne = new LigneTel($db); print ''; if ($user->rights->telephonie->fournisseur->lire) print ''; print "\n"; while ($i < $numlignes) { $obj = $db->fetch_object($i); $var=!$var; print "\n"; print '\n"; print '\n"; print '\n"; if ($user->rights->telephonie->fournisseur->lire) { print "\n"; } print "\n"; $i++; } } $db->free(); } else { print $db->error(); print $sql; } print "
Ligne'; print 'Agence/FilialeStatutSupport'; print 'Fournisseur
"; print ' '; print ''; print img_file(); print ' '; print ''.dolibarr_print_phone($obj->ligne)."'.$obj->code_client." ".$obj->agence."'.$ligne->statuts[$obj->statut]."'.$obj->support."".$obj->fournisseur." - \n"; print $obj->techno."

"; /* Liens xDSL */ require_once DOL_DOCUMENT_ROOT.'/telephonie/adsl/ligneadsl.class.php'; $sql = "SELECT l.rowid, l.numero_ligne, l.statut, t.intitule"; $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_adsl_ligne as l"; $sql .= " , ".MAIN_DB_PREFIX."telephonie_adsl_type as t"; $sql .= " WHERE l.fk_contrat=".$contrat->id; $sql .= " AND t.rowid = l.fk_type"; $sql .= " ORDER BY l.statut ASC;"; $resql = $db->query($sql); if ( $resql ) { $numlignes = $db->num_rows($resql); if ( $numlignes > 0 ) { $i = 0; $ligne = new LigneAdsl($db); print ''; print ''; print "\n"; while ($i < $numlignes) { $obj = $db->fetch_object($i); $var=!$var; print "\n"; print '\n"; print '\n"; print "\n"; $i++; } print "
Liens xDSL'; print 'Numero supportStatut
"; print ' '; print ''; print img_file(); print ' '; print ''.stripslashes($obj->intitule)."'.$obj->numero_ligne."'.$ligne->statuts[$obj->statut]."
"; } $db->free($resql); } else { print $db->error(); print $sql; } } /* * Edition * * * */ if ($_GET["action"] == 'edit' || $action == 're-edit') { $h=0; $head[$h][0] = DOL_URL_ROOT."/telephonie/contrat/fiche.php?id=".$contrat->id; $head[$h][1] = $langs->trans("Contrat"); $hselected = $h; $h++; dolibarr_fiche_head($head, $hselected, 'Contrat : '.$contrat->ref); print_fiche_titre('Edition du contrat', $mesg); print '
'; print ''; print ''; print ''; print ''; $client_comm = new Societe($db, $contrat->client_comm_id); $client_comm->fetch($contrat->client_comm_id); print ''; print ''; print ''; /* * */ print ''; print ''; /* * Commercial */ $commercial = new User($db, $contrat->commercial_sign_id); $commercial->fetch(); print ''; print ''; print "\n".''; /* * */ print "\n".''; /* * * */ print '"; print ''; print '
Référence'.$contrat->ref.'Facturé : '.$contrat->facturable.'
Client'; print ''; print $client_comm->nom.''.$client_comm->code_client; print '
Client (Agence/Filiale)'; print '
Client à facturer'."\n"; print '
Mode de réglement'; if ($user->rights->telephonie->contrat->paiement) { print ''; } else { print ''; if ($contrat->mode_paiement == 'pre') { print 'Prélèvement'; } else { print 'Virement'; } } print '
Commercial Signature'.$commercial->fullname.'
Commercial Suivi'; print '
Grille de tarif'; print '
Note'; print '
'; print 'Annuler
'."\n"; print '
'."\n"; } /* * Contact * * */ if ($_GET["action"] == 'contact') { print_fiche_titre('Ajouter un contact', $mesg); print '
'; print ''; print ''; $sql = "SELECT c.rowid, c.name, c.firstname, c.email "; $sql .= "FROM ".MAIN_DB_PREFIX."socpeople as c"; $sql .= ",".MAIN_DB_PREFIX."telephonie_contrat_contact_facture as cf"; $sql .= " WHERE c.rowid = cf.fk_contact "; $sql .= " AND cf.fk_contrat = ".$contrat->id." ORDER BY name "; if ( $db->query( $sql) ) { $num = $db->num_rows(); if ( $num > 0 ) { $i = 0; while ($i < $num) { $row = $db->fetch_row($i); print ''; print '"; $i++; } } $db->free(); } else { print $sql; } print ''; print ''; print '
Contact facture '.$i.''.$row[1] . " " . $row[2] . " <".$row[3].">"; print ''; print ''; print img_delete(); print "
Contact'; $sql = "SELECT rowid, 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 ''; } else { print $sql; } print '

Contact auquel est envoyé la facture par email

'; if ($num > 0) { print ''; } print 'Annuler
'; print '
'; } /* * Prise d'ordre * * */ if ($_GET["action"] == 'po' && $po == 0) { print_fiche_titre('Ajouter une prise d\'ordre mensuelle'); print '
'; print ''; print ''; print ''; print ''; print ''; print '
Montant mensuel'; print ' euros HT
'; print ''; print 'Annuler
'; print '
'; } /* * */ print ''; /* ************************************************************************** */ /* */ /* Barre d'action */ /* */ /* ************************************************************************** */ print "\n
\n
\n"; if ($_GET["action"] == '') { if ($user->rights->telephonie->ligne->creer && $contrat->statut <> 6) { print 'Nouveau lien xDSL'; print 'Nouvelle ligne'; } if ($user->rights->telephonie->ligne->creer && $contrat->statut <> 6) { print "id\">".$langs->trans("Contact").""; } if ($user->rights->telephonie->ligne->creer && $po == 0 && $contrat->statut <> 6) { print "id\">Ajouter une prise d'ordre"; } if ($user->rights->telephonie->ligne->creer && $contrat->statut <> 6) { print "id\">".$langs->trans("Modify").""; } if ($user->rights->telephonie->ligne->creer && $numlignes == 0 && $contrat->statut <> 6) { print "id\">".$langs->trans("Delete").""; } } print "
"; } } else { print "Error"; } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>