* Copyright (C) 2003 Brian Fraval * Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2005 Eric Seigne * * 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$ * */ /** \file htdocs/telephonie/client/new.php \ingroup telephonie \brief Creation d'un nouveau client \version $Revision$ */ require("pre.inc.php"); if (!$user->rights->telephonie->ligne->creer) accessforbidden(); require_once(DOL_DOCUMENT_ROOT.'/contact.class.php'); require_once(DOL_DOCUMENT_ROOT.'/companybankaccount.class.php'); require_once(DOL_DOCUMENT_ROOT."/telephonie/lignetel.class.php"); require_once(DOL_DOCUMENT_ROOT."/telephonie/telephonie.contrat.class.php"); $user->getrights('societe'); $langs->load("companies"); $soc = new Societe($db); $contact = new Contact($db); $rib = new CompanyBankAccount($db, 0); /* * Actions */ if ($_POST["action"] == 'add') { $error = 0; $verif = "ok"; $mesg = ''; $contact->name = $_POST["cnom"]; $contact->firstname = $_POST["cprenom"]; $contact->email = strtolower($_POST["cmail"]); if (strlen(trim($_POST["nom"])) == 0) { $mesg = "Nom de société incorrect"; $verif = "nok"; } if (strlen(trim($_POST["code_client"])) <> 6 && $verif == 'ok') { $mesg = "Code client incorrect"; $verif = "nok"; } if (strlen(trim($_POST["adresse"])) == 0 && $verif == 'ok') { $mesg = "Adresse de société manquante"; $verif = "nok"; } if (strlen(trim($_POST["cp"])) == 0 && $verif == 'ok') { $mesg = "Code postal manquant"; $verif = "nok"; } if (strlen(trim($_POST["ville"])) == 0 && $verif == 'ok') { $mesg = "Ville manquante"; $verif = "nok"; } $rib->code_banque = $_POST["rib_banque"]; $rib->code_guichet = $_POST["rib_guichet"]; $rib->number = $_POST["rib_compte"]; $rib->cle_rib = $_POST["rib_cle"]; $rib->iban_prefix = $_POST["rib_iban"]; $rib->proprio = $_POST["titulaire"]; if ((strlen(trim($_POST["rib_banque"])) + strlen(trim($_POST["rib_guichet"])) + strlen(trim($_POST["rib_compte"])) + strlen(trim($_POST["rib_cle"])))<> 0 && $verif == 'ok') { if (strlen(trim($_POST["rib_banque"])) <> 5 && $verif == 'ok') { $mesg = "Rib code banque incomplet"; $verif = "nok"; } if (strlen(trim($_POST["rib_guichet"])) <> 5 && $verif == 'ok') { $mesg = "Rib code agence incomplet"; $verif = "nok"; } if (strlen(trim($_POST["titulaire"])) == 0 && $verif == 'ok') { $mesg = "Vous devez indiquer le titulaire du compte"; $verif = "nok"; } if ($rib->verif() <> 1 && $verif == 'ok') { $mesg = "Rib incorrect ".$rib->error_message; $verif = "nok"; } } if (strlen(trim($_POST["cmail"])) > 0 && $verif == 'ok') { if (strlen(trim($_POST["cnom"])) == 0 && $verif == 'ok') { $mesg = "Nom de contact manquant"; $verif = "nok"; } if (!ValidEmail(trim($contact->email)) && $verif == 'ok') { $mesg = "Email invalide"; $verif = "nok"; } if (!check_mail(trim($contact->email)) && $verif == 'ok') { $mesg = "Email invalide (domaine invalide)"; $verif = "nok"; } } if (strlen(trim($_POST["cli"])) <> 9 && $verif == 'ok') { $mesg = "Numéro de ligne #1 (0".$_POST["cli"].") incorrect"; $verif = "nok"; } $p = array("1","2","3","4","5"); if (!in_array(substr(trim($_POST["cli"]),0,1), $p) && $verif == 'ok') { $mesg = "Numéro de ligne #1 (0".$_POST["cli"].") incorrect"; $verif = "nok"; } /* Ligne #2 */ if (strlen(trim($_POST["cli2"])) > 0 && $verif == 'ok') { if (strlen(trim($_POST["cli2"])) <> 9 && $verif == 'ok') { $mesg = "Numéro de ligne #2 (0".$_POST["cli2"].") incorrect"; $verif = "nok"; } if (!in_array(substr(trim($_POST["cli2"]),0,1), $p) && $verif == 'ok') { $mesg = "Numéro de ligne #2 (0".$_POST["cli2"].") incorrect"; $verif = "nok"; } } /* Ligne #3 */ if (strlen(trim($_POST["cli3"])) > 0 && $verif == 'ok') { if (strlen(trim($_POST["cli3"])) <> 9 && $verif == 'ok') { $mesg = "Numéro de ligne #3 (0".$_POST["cli3"].") incorrect"; $verif = "nok"; } if (!in_array(substr(trim($_POST["cli3"]),0,1), $p) && $verif == 'ok') { $mesg = "Numéro de ligne #3 (0".$_POST["cli3"].") incorrect"; $verif = "nok"; } } /* Verif Tarif */ if (strlen(trim($_POST["france"])) > 0 && $verif == "ok") { $temporel = ereg_replace(",",".",trim($_POST["france"])); if(! is_numeric($temporel)) { $error = 1030; $verif = "nok"; $mesg .= "Tarif France Invalide"; } else { if ($temporel > 0.04 ) { $error = 1031; $verif = "nok"; $mesg .= "Tarif France Invalide : $temporel > 0.04 !"; } if ($temporel < 0.016 ) { $error = 1031; $verif = "nok"; $mesg .= "Tarif France Invalide : $temporel < 0.016 !"; } } } if (strlen(trim($_POST["mobil"])) > 0 && $verif == "ok") { $temporel = ereg_replace(",",".",trim($_POST["mobil"])); if(! is_numeric($temporel)) { $error++; $verif = "nok"; $mesg .= "Tarif Mobile Invalide"; } else { if ($temporel > 0.40 ) { $error = 1033; $verif = "nok"; $mesg .= "Tarif Mobile Invalide : $temporel > 0.40 !"; } if ($temporel < 0.14 ) { $error = 1034; $verif = "nok"; $mesg .= "Tarif Mobile Invalide : $temporel < 0.14 !"; } } } /* Fin Verif Tarif */ $soc->nom = stripslashes($_POST["nom"]); $soc->adresse = stripslashes($_POST["adresse"]); $soc->cp = stripslashes($_POST["cp"]); $soc->ville = stripslashes($_POST["ville"]); $soc->pays_id = stripslashes($_POST["pays_id"]); $soc->tel = stripslashes($_POST["tel"]); $soc->fax = stripslashes($_POST["fax"]); $soc->url = ereg_replace( "http://", "", $_POST["url"] ); $soc->code_client = $_POST["code_client"]; $soc->code_fournisseur = stripslashes($_POST["code_fournisseur"]); $soc->codeclient_modifiable = stripslashes($_POST["codeclient_modifiable"]); $soc->codefournisseur_modifiable = stripslashes($_POST["codefournisseur_modifiable"]); $soc->client = 1; $soc->fournisseur = 0; if (!$error && $verif == "ok") { $soc->code_client = $_POST["code_client"]."00"; $result = $soc->create($user); if ($result == 0) { $soc->AddPerms(1,1,1,1); $soc->AddPerms(5,1,1,1); $soc->AddPerms(9,1,1,1); $soc->AddPerms(16,1,1,1); $soc->AddPerms($_POST["commercial_sign"],1,0,0); } else { $mesg = nl2br($soc->error) . " (result $result)\n"; $error = 1035; } } if (!$error && $verif == "ok") { $contact->socid = $soc->id; if ( $contact->create($user) > 0) { } else { $error = 1024; } } if ((strlen(trim($_POST["rib_banque"])) + strlen(trim($_POST["rib_guichet"])) + strlen(trim($_POST["rib_compte"])) + strlen(trim($_POST["rib_cle"])))<> 0 && $verif == 'ok' && !$error) { $rib->soc_id = $soc->id; if ( $rib->update($user) > 0) { } else { $error = 1025; } } if (!$error && $verif == "ok") { $contrat = new TelephonieContrat($db); $contrat->client_comm = $soc->id; $contrat->client = $soc->id; $contrat->client_facture = $soc->id; $contrat->commercial_sign = $_POST["commercial_sign"]; if ( $contrat->create($user,'oui',$_POST["mode_paiement"]) == 0) { $contrat->add_contact_facture($contact->id); } else { $error = 1026; } } if(!$error && $verif == "ok") { $contrat->commercial_sign_id = $_POST["commercial_sign"]; $contrat->addpo($_POST["montantpo"], $user); } $ligne = new LigneTel($db); $ligne->contrat = $contrat->id; $ligne->numero = "0".$_POST["cli"]; $ligne->client_comm = $soc->id; $ligne->client = $soc->id; $ligne->client_facture = $soc->id; $ligne->fournisseur = $_POST["fournisseur"]; $ligne->commercial_sign = $_POST["commercial_sign"]; $ligne->commercial_suiv = $_POST["commercial_sign"]; $ligne->concurrent = $_POST["concurrent"]; $ligne->remise = "0"; $ligne->note = $_POST["note"]; if(!$error && $verif == "ok") { if (strlen(trim($_POST["cli"])) == 9) { if ( $ligne->create($user) == 0) { } else { $error = 1027; $mesg.= "Impossible de créer la ligne #1 0".$_POST["cli"]; } } } /* Ligne 2 */ $ligne = new LigneTel($db); $ligne->contrat = $contrat->id; $ligne->numero = "0".$_POST["cli2"]; $ligne->client_comm = $soc->id; $ligne->client = $soc->id; $ligne->client_facture = $soc->id; $ligne->fournisseur = $_POST["fournisseur"]; $ligne->commercial_sign = $_POST["commercial_sign"]; $ligne->commercial_suiv = $_POST["commercial_sign"]; $ligne->concurrent = $_POST["concurrent"]; $ligne->remise = "0"; $ligne->note = $_POST["note"]; if(!$error && $verif == "ok") { if (strlen(trim($_POST["cli2"])) == 9) { if ( $ligne->create($user) == 0) { } else { //$error++; $error = 1028; $mesg.= "Impossible de créer la ligne #2 0".$_POST["cli2"]; } } } /* Ligne 3 */ $ligne = new LigneTel($db); $ligne->contrat = $contrat->id; $ligne->numero = "0".$_POST["cli3"]; $ligne->client_comm = $soc->id; $ligne->client = $soc->id; $ligne->client_facture = $soc->id; $ligne->fournisseur = $_POST["fournisseur"]; $ligne->commercial_sign = $_POST["commercial_sign"]; $ligne->commercial_suiv = $_POST["commercial_sign"]; $ligne->concurrent = $_POST["concurrent"]; $ligne->remise = "0"; $ligne->note = $_POST["note"]; if(!$error && $verif == "ok") { if (strlen(trim($_POST["cli3"])) == 9) { if ( $ligne->create($user) == 0) { } else { //$error++; $error = 1029; $mesg.= "Impossible de créer la ligne #3 0".$_POST["cli3"]; } } } /* DEBUT TARIFS */ if (strlen(trim($_POST["france"])) > 0 && $verif == "ok") { $temporel = ereg_replace(",",".",trim($_POST["france"])); if (!$error) { $db->begin(); $sql = "REPLACE INTO ".MAIN_DB_PREFIX."telephonie_tarif_client"; $sql .= " (fk_tarif, fk_client, temporel, fixe, fk_user) VALUES "; $sql .= " (1293,".$soc->id.",'".$temporel."','0',".$user->id.")"; if (! $db->query($sql) ) { $error++; } $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_tarif_client_log"; $sql .= " (fk_tarif, fk_client, temporel, fixe, fk_user, datec) VALUES "; $sql .= " (1293,".$soc->id.",'".$temporel."','0',".$user->id.",now())"; if (! $db->query($sql) ) { $error++; } if ( $error == 0 ) { $db->commit(); } else { $db->rollback(); $mesg = "Erreur tarifs !"; } } } /* mobiles */ if (strlen(trim($_POST["mobil"])) > 0 && $verif == "ok") { $mobil_ids = array(1289,1290,1291,1292); foreach ($mobil_ids as $mobil_id) { $temporel = ereg_replace(",",".",trim($_POST["mobil"])); if (!$error) { $db->begin(); $sql = "REPLACE INTO ".MAIN_DB_PREFIX."telephonie_tarif_client"; $sql .= " (fk_tarif, fk_client, temporel, fixe, fk_user) VALUES "; $sql .= " (".$mobil_id.",".$soc->id.",'".$temporel."','0',".$user->id.")"; if (! $db->query($sql) ) { $error++; } $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_tarif_client_log"; $sql .= " (fk_tarif, fk_client, temporel, fixe, fk_user, datec) VALUES "; $sql .= " (".$mobil_id.",".$soc->id.",'".$temporel."','0',".$user->id.",now())"; if (! $db->query($sql) ) { $error++; } if ( $error == 0 ) { $db->commit(); } else { $db->rollback(); $mesg = "Erreur tarifs !"; } } } } /* FIN TARIFS */ if (!$error && $verif == "ok") { Header("Location: ".DOL_URL_ROOT."/telephonie/contrat/fiche.php?id=".$contrat->id); } else { $mesg .= $error; } } /** * * */ llxHeader(); $form = new Form($db); if ($user->rights->telephonie->ligne->creer) { dolibarr_fiche_head($head, $hselected, 'Nouveau client'); /* */ if ($mesg) { print '
'; print $mesg; print '
'; } else { } $focus = " onfocus=\"this.className='focus';\" onblur=\"this.className='normal';\" "; print '
'; print ''; print ''; print ''; print '
'; print '
'; print "Société\n"; print ''; print '"; // On positionne pays_id, pays_code et libelle du pays choisi $soc->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:(defined(MAIN_INFO_SOCIETE_PAYS)?MAIN_INFO_SOCIETE_PAYS:''); if ($soc->pays_id) { $sql = "SELECT code, libelle from ".MAIN_DB_PREFIX."c_pays where rowid = ".$soc->pays_id; $resql=$db->query($sql); if ($resql) { $obj = $db->fetch_object($resql); } else { dolibarr_print_error($db); } $soc->pays_code=$obj->code; $soc->pays=$obj->libelle; } print ''; print ''; print ''; print ''; print ''; print "
'.$langs->trans('Name').''; print ''; print "Attention ce formulaire n'est a utiliser uniquement pour les nouveaux clients.
'.$langs->trans('CustomerCode').''; print '00
'.$langs->trans('Address').'
'.$langs->trans('Zip').''; print ' '; print $langs->trans('Town').' 
'.$langs->trans('Phone').''.$langs->trans('Fax').'
\n"; print "

\n"; print '
'; print "Coordonnées bancaires\n"; print ''; print ''; print ''; print ''; print "
Titulaire du compte
RIB'; print ''; print ''; print ''; print ''; print '  IBAN  '; print ''; print '
Règlement'; print ''; print '
\n"; print "

\n"; print '
'; print "Contact\n"; print ''; print ''; print ''; print ''; print "
'.$langs->trans('Name').''.$langs->trans('Firstname').'
'.$langs->trans('Mail').'
\n"; print "

\n"; print '
'; print "Commercial\n"; print ''; print ''; print ''; print ''; 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 ) { while ($row = $db->fetch_row($resql)) { $ff[$row[0]] = $row[1] . " " . $row[2]; } } $db->free(); } $form->select_array("commercial_sign",$ff,$ligne->commercial_sign); print 'PO mensuelle'; print ' euros HT
\n"; print "

\n"; print '
'; print "Lignes téléphoniques à présélectionner\n"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "
Ligne téléphonique #10Si le client a plusieurs lignes vous pourrez les ajouter au contrat ultérieuremnt
Ligne téléphonique #20
Ligne téléphonique #30
Fournisseur'; $ff = array(); $sql = "SELECT rowid, nom FROM ".MAIN_DB_PREFIX."telephonie_fournisseur WHERE commande_active = 1 ORDER BY nom "; $resql = $db->query($sql); if ($resql) { while ($row = $db->fetch_row($resql)) { $ff[$row[0]] = $row[1]; } $db->free($resql); } $def =$ligne->fournisseur?$ligne->fournisseur:TELEPHONIE_FOURNISSEUR_DEFAUT_ID; $form->select_array("fournisseur",$ff,$def); print 'Fournisseur précédent'; $ff = array(); $sql = "SELECT rowid, nom FROM ".MAIN_DB_PREFIX."telephonie_concurrents ORDER BY rowid "; $resql = $db->query( $sql) ; if ($resql) { $num = $db->num_rows($resql); if ( $num > 0 ) { while ($row = $db->fetch_row($resql)) { $ff[$row[0]] = $row[1]; } } $db->free(); } $form->select_array("concurrent",$ff,$ligne->concurrent); print '
\n"; print "

\n"; /* DEBUT TARIFS */ print '
'; print "Tarifs\n"; if ($user->rights->telephonie->tarif->client_modifier) { print ''; print ''; print ''; print "
FranceLaissez vide si tarifs par défaut
MobilesTous réseaux confondus
\n"; } else { print "Vous n'avez pas les droits pour modifier les tarifs"; } print "

\n"; /* FIN TARIFS */ print ''."\n"; print ''."\n"; print "
\n"; } $db->close(); llxFooter('$Date$ - $Revision$'); ?>