*
* 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 '
';
}
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 '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 '