From 54b4a361edcd928c595161c82461c713cc8046da Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Wed, 24 Aug 2005 07:45:31 +0000 Subject: [PATCH] Nouveau fichier --- htdocs/telephonie/client/new.php | 451 +++++++++++++++++++++++++++++++ 1 file changed, 451 insertions(+) create mode 100644 htdocs/telephonie/client/new.php diff --git a/htdocs/telephonie/client/new.php b/htdocs/telephonie/client/new.php new file mode 100644 index 00000000000..268395cba9c --- /dev/null +++ b/htdocs/telephonie/client/new.php @@ -0,0 +1,451 @@ + + * 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 = ''; + + 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"]; + + + 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 ($rib->verif() <> 1 && $verif == 'ok') + { + $mesg = "Rib incorrect ".$rib->error_message; + $verif = "nok"; + } + } + + if (strlen(trim($_POST["cmail"])) > 0 && $verif == 'ok') + { + if (!ValidEmail(trim($_POST["cmail"])) && $verif == 'ok') + { + $mesg = "Email invalide"; + $verif = "nok"; + } + + if (!check_mail(trim($_POST["cmail"])) && $verif == 'ok') + { + $mesg = "Email invalide (domaine invalide)"; + $verif = "nok"; + } + } + + + if (strlen(trim($_POST["cli"])) <> 9 && $verif == 'ok') + { + $mesg = "Numéro de ligne incorrecte"; + $verif = "nok"; + } + + $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) + { + + } + else + { + $error++; + } + } + + $contact->name = $_POST["cnom"]; + $contact->firstname = $_POST["cprenom"]; + $contact->email = $_POST["cmail"]; + + if (!$error && $verif == "ok") + { + $contact->socid = $soc->id; + + if ( $contact->create($user) > 0) + { + + } + else + { + $error++; + } + } + + 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) == 0) + { + $contrat->add_contact_facture($contact->id); + } + else + { + $error++; + } + } + + 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++; + $msg.= "Impossible de créer la ligne"; + } + } + } + + if (!$error && $verif == "ok") + { + Header("Location: ".DOL_URL_ROOT."/telephonie/contrat/fiche.php?id=".$contrat->id); + } + +} + +/** + * + * + */ + +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 + { + print "

Attention ce formulaire n'est a utiliser uniquement pour les nouveaux clients. Il créé automatiquement un client, ses informations bancaires, son contrat (en mode paiement prélèvement) et la première ligne téléphonie, si il y a plusieurs ligne il suffit de les ajouter au contrat ultérieurement

"; + } + + $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 ''; + + print "
'.$langs->trans('Name').''; + print '
'.$langs->trans('CustomerCode').''; + + print '00
'.$langs->trans('Address').'
'.$langs->trans('Zip').''; + print ' '; + + print $langs->trans('Town').' 
'.$langs->trans('Phone').''.$langs->trans('Fax').'
RIB'; + print ''; + print ''; + print ''; + print ''; + print '  IBAN  '; + 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 "Ligne téléphonique à présélectionner\n"; + + print ''; + + print ''; + print ''; + + print ''; + + print ''; + + print "
Ligne téléphonique #10Si le client a plusieurs lignes vous pourrez les ajouter au contrat ultérieuremnt
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); + } + $form->select_array("fournisseur",$ff,$ligne->fournisseur); + 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"; + + print ''."\n"; + + print ''."\n"; + print "
\n"; +} + + +$db->close(); + + +llxFooter('$Date$ - $Revision$'); +?> +