diff --git a/htdocs/telephonie/client/new.php b/htdocs/telephonie/client/new.php index 4d7f4cfa665..84019938210 100644 --- a/htdocs/telephonie/client/new.php +++ b/htdocs/telephonie/client/new.php @@ -151,9 +151,107 @@ if ($_POST["action"] == 'add') if (strlen(trim($_POST["cli"])) <> 9 && $verif == 'ok') { - $mesg = "Numéro de ligne incorrecte"; + $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++; + $verif = "nok"; + $mesg .= "Tarif France Invalide"; + } + else + { + if ($temporel > 0.04 ) + { + $error++; + $verif = "nok"; + $mesg .= "Tarif France Invalide : $temporel > 0.04 !"; + } + + if ($temporel < 0.016 ) + { + $error++; + $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++; + $verif = "nok"; + $mesg .= "Tarif Mobile Invalide : $temporel > 0.40 !"; + } + if ($temporel < 0.16 ) + { + $error++; + $verif = "nok"; + $mesg .= "Tarif Mobile Invalide : $temporel < 0.16 !"; + } + } + } + + /* Fin Verif Tarif */ $soc->nom = stripslashes($_POST["nom"]); $soc->adresse = stripslashes($_POST["adresse"]); @@ -261,7 +359,6 @@ if ($_POST["action"] == 'add') { if (strlen(trim($_POST["cli"])) == 9) { - if ( $ligne->create($user) == 0) { @@ -270,11 +367,158 @@ if ($_POST["action"] == 'add') else { $error++; - $msg.= "Impossible de créer la ligne"; + $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++; + $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++; + $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); @@ -307,7 +551,7 @@ if ($user->rights->telephonie->ligne->creer) } 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';\" "; @@ -324,9 +568,11 @@ if ($user->rights->telephonie->ligne->creer) print ''; - print ''; + print $focus .' value="'.$soc->nom.'">"; // 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:''); @@ -390,8 +636,8 @@ if ($user->rights->telephonie->ligne->creer) print "Contact\n"; print '
'.$langs->trans('Name').''; + print '
'.$langs->trans('Name').''; print '
'; + + print "Attention ce formulaire n'est a utiliser uniquement pour les nouveaux clients.
'; - print ''; - print ''; + print ''; + print ''; print ''; print "
'.$langs->trans('Name').'
'.$langs->trans('Firstname').'
'.$langs->trans('Name').''.$langs->trans('Firstname').'
'.$langs->trans('Mail').'
\n"; @@ -433,13 +679,17 @@ if ($user->rights->telephonie->ligne->creer) print "
\n"; print '
'; - print "Ligne téléphonique à présélectionner\n"; + 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 "; @@ -456,9 +706,9 @@ if ($user->rights->telephonie->ligne->creer) $def =$ligne->fournisseur?$ligne->fournisseur:TELEPHONIE_FOURNISSEUR_DEFAUT_ID; $form->select_array("fournisseur",$ff,$def); - print '
Fournisseur précédent'; + print 'Fournisseur précédent'; $ff = array(); $sql = "SELECT rowid, nom FROM ".MAIN_DB_PREFIX."telephonie_concurrents ORDER BY rowid "; $resql = $db->query( $sql) ; @@ -481,6 +731,28 @@ if ($user->rights->telephonie->ligne->creer) 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";