diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 797e98245ab..1d80423fb89 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -1463,7 +1463,7 @@ class Form if ($idprof==1 && $soc->pays_code == 'FR') $formlength=9; if ($idprof==2 && $soc->pays_code == 'FR') $formlength=14; if ($idprof==3 && $soc->pays_code == 'FR') $formlength=4; - if ($idprof==4 && $soc->pays_code == 'FR') $formlength=4; + if ($idprof==4 && $soc->pays_code == 'FR') $formlength=12; print ''; } diff --git a/htdocs/soc.php b/htdocs/soc.php index ff8e8c5e253..492f833deab 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -39,7 +39,10 @@ $user->getrights('commercial'); $langs->load("companies"); $langs->load("commercial"); $langs->load("bills"); - + +$socid = isset($_GET["socid"])?$_GET["socid"]:''; + +// Sécurité accés client if (! $user->rights->societe->creer) { if ($_GET["action"] == 'create' || $_POST["action"] == 'create') @@ -47,16 +50,11 @@ if (! $user->rights->societe->creer) accessforbidden(); } } - -$socid = isset($_GET["socid"])?$_GET["socid"]:''; -if (! $socid && ($_REQUEST["action"] != 'create' && $_REQUEST["action"] != 'add')) accessforbidden(); - -// Sécurité accés client if ($user->societe_id > 0) { - $_GET["action"] = ''; - $_POST["action"] = ''; - $socid = $user->societe_id; + $_GET["action"] = ''; + $_POST["action"] = ''; + $socid = $user->societe_id; } // Protection restriction commercial @@ -104,9 +102,10 @@ if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"]) $soc->fax = $_POST["fax"]; $soc->email = $_POST["email"]; $soc->url = $_POST["url"]; - $soc->siren = $_POST["siren"]; - $soc->siret = $_POST["siret"]; - $soc->ape = $_POST["ape"]; + $soc->siren = $_POST["idprof1"]; + $soc->siret = $_POST["idprof2"]; + $soc->ape = $_POST["idprof3"]; + $soc->idprof4 = $_POST["idprof4"]; $soc->prefix_comm = $_POST["prefix_comm"]; $soc->code_client = $_POST["code_client"]; $soc->code_fournisseur = $_POST["code_fournisseur"]; @@ -165,7 +164,10 @@ if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"]) exit; } - $result = $soc->update($socid,$user); + $oldsoc=new Societe($db); + $result=$oldsoc->fetch($socid); + + $result = $soc->update($socid,$user,1,$oldsoc->codeclient_modifiable(),$oldsoc->codefournisseur_modifiable()); if ($result >= 0) { Header("Location: soc.php?socid=".$socid); @@ -262,9 +264,10 @@ if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] || $soc->email=$_POST["email"]; $soc->url=$_POST["url"]; $soc->capital=$_POST["capital"]; - $soc->siren=$_POST["siren"]; - $soc->siret=$_POST["siret"]; - $soc->ape=$_POST["ape"]; + $soc->siren=$_POST["idprof1"]; + $soc->siret=$_POST["idprof2"]; + $soc->ape=$_POST["idprof3"]; + $soc->idprof4=$_POST["idprof4"]; $soc->typent_id=$_POST["typent_id"]; $soc->effectif_id=$_POST["effectif_id"]; @@ -402,10 +405,17 @@ if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] || print '
'.$langs->trans('Capital').'
'.$langs->trans("Currency".$conf->monnaie).'
'; + if ($soc->pays_code == 'FR') + { + $maxlength1=9; + $maxlength2=14; + $maxlength3=4; + $maxlength4=12; + } print '
'.($langs->transcountry("ProfId1",$soc->pays_code) != '-'?$langs->transcountry('ProfId1',$soc->pays_code):'').'
'; if ($soc->pays_id) { - if ($langs->transcountry("ProfId1",$soc->pays_code) != '-') print '
'; + if ($langs->transcountry("ProfId1",$soc->pays_code) != '-') print '
'; else print '
 
'; } else @@ -416,7 +426,7 @@ if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] || print '
'.($langs->transcountry("ProfId2",$soc->pays_code) != '-'?$langs->transcountry('ProfId2',$soc->pays_code):'').'
'; if ($soc->pays_id) { - if ($langs->transcountry("ProfId2",$soc->pays_code) != '-') print '
'; + if ($langs->transcountry("ProfId2",$soc->pays_code) != '-') print '
'; else print '
 
'; } else @@ -428,14 +438,25 @@ if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] || print '
'.($langs->transcountry("ProfId3",$soc->pays_code) != '-'?$langs->transcountry('ProfId3',$soc->pays_code):'').'
'; if ($soc->pays_id) { - if ($langs->transcountry("ProfId3",$soc->pays_code) != '-') print '
'; + if ($langs->transcountry("ProfId3",$soc->pays_code) != '-') print '
'; else print '
 
'; } else { print $countrynotdefined; } - print '
 
'."\n"; + print ''; + print '
'.($langs->transcountry("ProfId4",$soc->pays_code) != '-'?$langs->transcountry('ProfId4',$soc->pays_code):'').'
'; + if ($soc->pays_id) + { + if ($langs->transcountry("ProfId4",$soc->pays_code) != '-') print '
'; + else print '
 
'; + } + else + { + print $countrynotdefined; + } + print ''; // Forme juridique print '
'.$langs->trans('JuridicalStatus').'
'; @@ -553,9 +574,10 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') $soc->email=$_POST["email"]; $soc->url=$_POST["url"]; $soc->capital=$_POST["capital"]; - $soc->siren=$_POST["siren"]; - $soc->siret=$_POST["siret"]; - $soc->ape=$_POST["ape"]; + $soc->siren=$_POST["idprof1"]; + $soc->siret=$_POST["idprof2"]; + $soc->ape=$_POST["idprof3"]; + $soc->idprof4=$_POST["idprof4"]; $soc->typent_id=$_POST["typent_id"]; $soc->effectif_id=$_POST["effectif_id"]; @@ -697,42 +719,41 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') print ''.$langs->trans('Web').''; print ''; - // IdProf1 + // IdProf1 (SIREN pour France) $idprof=$langs->transcountry('ProfId1',$soc->pays_code); if ($idprof!='-') { print ''.$idprof.''; - $form->id_prof(1,$soc,'siren',$soc->siren); + $form->id_prof(1,$soc,'idprof1',$soc->siren); print ''; } else print '  '; - // IdProf2 + // IdProf2 (SIRET pour France) $idprof=$langs->transcountry('ProfId2',$soc->pays_code); if ($idprof!='-') { print ''.$idprof.''; - $form->id_prof(2,$soc,'siret',$soc->siret); + $form->id_prof(2,$soc,'idprof2',$soc->siret); print ''; } else print '  '; print ''; print ''; - // IdProf3 + // IdProf3 (APE pour France) $idprof=$langs->transcountry('ProfId3',$soc->pays_code); if ($idprof!='-') { print ''.$idprof.''; - $form->id_prof(3,$soc,'ape',$soc->ape); + $form->id_prof(3,$soc,'idprof3',$soc->ape); print ''; } else print '  '; - // IdProf4 - // $idprof=$langs->transcountry('ProfId4',$soc->pays_code); - $idprof='-'; // L'identifiant 4 n'est pas encore géré + // IdProf4 (NU pour France) + $idprof=$langs->transcountry('ProfId4',$soc->pays_code); if ($idprof!='-') { print ''.$idprof.''; - $form->id_prof(4,$soc,'rcs',$soc->rcs); + $form->id_prof(4,$soc,'idprof4',$soc->idprof4); print ''; } else print '  '; @@ -873,7 +894,7 @@ else else print ' '; print ''; - // ProfId1 + // ProfId1 (SIREN pour France) $profid=$langs->transcountry('ProfId1',$soc->pays_code); if ($profid!='-') { @@ -887,7 +908,7 @@ else print ''; } else print '  '; - // ProfId2 + // ProfId2 (SIRET pour France) $profid=$langs->transcountry('ProfId2',$soc->pays_code); if ($profid!='-') { @@ -902,7 +923,7 @@ else } else print '  '; - // ProfId3 + // ProfId3 (APE pour France) $profid=$langs->transcountry('ProfId3',$soc->pays_code); if ($profid!='-') { @@ -916,14 +937,13 @@ else print ''; } else print '  '; - // ProfId4 - // $profid=$langs->transcountry('ProfId4',$soc->pays_code); - $profid='-'; // L'identifiant 4 n'est pas encore géré + // ProfId4 (NU pour France) + $profid=$langs->transcountry('ProfId4',$soc->pays_code); if ($profid!='-') { print ''.$profid.''; - print $soc->rcs; - if ($soc->rcs) + print $soc->idprof4; + if ($soc->idprof4) { if ($soc->id_prof_check(4,$soc) > 0) print '   '.$soc->id_prof_url(4,$soc); else print ' ('.$langs->trans("ErrorWrongValue").')'; diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index c77c5fad144..16c18feaeee 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -52,9 +52,12 @@ class Societe var $fax; var $email; var $url; - var $siren; - var $siret; - var $ape; + + // 4 identifiants porfessionnels (leur utilisation depend du pays) + var $siren; // IdProf1 + var $siret; // IdProf2 + var $ape; // IdProf3 + var $idprof4; // IdProf4 var $prefix_comm; @@ -98,7 +101,6 @@ class Societe global $conf; $this->db = $DB; - $this->creation_bit = 0; $this->id = $id; $this->client = 0; @@ -152,9 +154,7 @@ class Societe { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe"); - $this->creation_bit = 1; - - $ret = $this->update($this->id,$user,0); + $ret = $this->update($this->id,$user,0,1,1); // si un commercial crée un client il lui est affecté automatiquement if (!$user->rights->commercial->client->voir) @@ -273,17 +273,19 @@ class Societe } /** - * \brief Mise a jour des paramètres de la sociét - * \param id id societe - * \param user Utilisateur qui demande la mise à jour - * \param call_trigger 0=non, 1=oui - * \return int <0 si ko, >=0 si ok + * \brief Mise a jour des paramètres de la société + * \param id id societe + * \param user Utilisateur qui demande la mise à jour + * \param call_trigger 0=non, 1=oui + * \param allowmodcodeclient Autorise modif code client + * \param allowmodcodefournisseur Autorise modif code fournisseur + * \return int <0 si ko, >=0 si ok */ - function update($id, $user='', $call_trigger=1) + function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0) { global $langs; - dolibarr_syslog("Societe::Update id=".$id." call_trigger=".$call_triger." creation_bit=".$this->creation_bit); + dolibarr_syslog("Societe::Update id=".$id." call_trigger=".$call_triger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur); // Nettoyage des paramètres $this->id=$id; @@ -296,11 +298,16 @@ class Societe $this->pays_id=trim($this->pays_id); $this->tel=trim($this->tel); $this->fax=trim($this->fax); + $this->tel = ereg_replace(" ","",$this->tel); + $this->tel = ereg_replace("\.","",$this->tel); + $this->fax = ereg_replace(" ","",$this->fax); + $this->fax = ereg_replace("\.","",$this->fax); $this->email=trim($this->email); $this->url=trim($this->url); $this->siren=trim($this->siren); $this->siret=trim($this->siret); $this->ape=trim($this->ape); + $this->idprof4=trim($this->idprof4); $this->prefix_comm=trim($this->prefix_comm); $this->tva_assuj=trim($this->tva_assuj); @@ -318,11 +325,6 @@ class Societe { dolibarr_syslog("Societe::Update verify ok"); - $this->tel = ereg_replace(" ","",$this->tel); - $this->tel = ereg_replace("\.","",$this->tel); - $this->fax = ereg_replace(" ","",$this->fax); - $this->fax = ereg_replace("\.","",$this->fax); - $sql = "UPDATE ".MAIN_DB_PREFIX."societe"; $sql.= " SET nom = '" . addslashes($this->nom) ."'"; // Champ obligatoire $sql.= ",datea = now()"; @@ -339,9 +341,10 @@ class Societe $sql .= ",email = ".($this->email?"'".addslashes($this->email)."'":"null"); $sql .= ",url = ".($this->url?"'".addslashes($this->url)."'":"null"); - $sql .= ",siren = '". addslashes($this->siren) ."'"; - $sql .= ",siret = '". addslashes($this->siret) ."'"; - $sql .= ",ape = '". addslashes($this->ape) ."'"; + $sql .= ",siren = '". addslashes($this->siren) ."'"; + $sql .= ",siret = '". addslashes($this->siret) ."'"; + $sql .= ",ape = '". addslashes($this->ape) ."'"; + $sql .= ",idprof4 = '". addslashes($this->idprof4) ."'"; $sql .= ",tva_assuj = ".($this->tva_assuj>=0?"'".$this->tva_assuj."'":"null"); $sql .= ",tva_intra = '" . addslashes($this->tva_intra) ."'"; @@ -359,7 +362,7 @@ class Societe $sql .= ",client = " . $this->client; $sql .= ",fournisseur = " . $this->fournisseur; - if ($this->creation_bit || $this->codeclient_modifiable()) + if ($allowmodcodeclient) { // Attention check_codeclient peut modifier le code suivant le module utilise $this->check_codeclient(); @@ -372,7 +375,7 @@ class Societe $sql .= ", code_compta = ".($this->code_compta?"'".addslashes($this->code_compta)."'":"null"); } - if ($this->creation_bit || $this->codefournisseur_modifiable()) + if ($allowmodcodefournisseur) { // Attention check_codefournisseur peut modifier le code suivant le module utilise $this->check_codefournisseur(); @@ -463,8 +466,9 @@ class Societe if($conf->global->PRODUIT_MULTIPRICES == 1) $sql .= ', s.price_level'; $sql .= ','. $this->db->pdate('s.tms').' as date_update'; - $sql .= ', s.tel, s.fax, s.email, s.url, s.cp, s.ville, s.note, s.siren, client, fournisseur'; - $sql .= ', s.siret, s.capital, s.ape, s.tva_intra, s.rubrique'; + $sql .= ', s.tel, s.fax, s.email, s.url, s.cp, s.ville, s.note, client, fournisseur'; + $sql .= ', s.siren, s.siret, s.ape, s.idprof4'; + $sql .= ', s.capital, s.tva_intra, s.rubrique'; $sql .= ', s.fk_typent as typent_id'; $sql .= ', s.fk_effectif as effectif_id, e.libelle as effectif'; $sql .= ', s.fk_forme_juridique as forme_juridique_code, fj.libelle as forme_juridique'; @@ -519,6 +523,8 @@ class Societe $this->siren = $obj->siren; $this->siret = $obj->siret; $this->ape = $obj->ape; + $this->idprof4 = $obj->idprof4; + $this->capital = $obj->capital; $this->code_client = $obj->code_client; @@ -1419,9 +1425,9 @@ class Societe $mod = new $var; dolibarr_syslog("Societe::codeclient_modifiable code_client=".$this->code_client." module=".$var); - if ($mod->code_modifiable) return 1; if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1; if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1; + if ($mod->code_modifiable) return 1; // A mettre en dernier return 0; } else @@ -1432,7 +1438,7 @@ class Societe /** - * \brief Verifie si un code client est modifiable dans configuration du module de controle des codes + * \brief Verifie si un code fournisseur est modifiable dans configuration du module de controle des codes * \return int 0=Non, 1=Oui */ function codefournisseur_modifiable() @@ -1447,9 +1453,9 @@ class Societe $mod = new $var; dolibarr_syslog("Societe::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$var); - if ($mod->code_modifiable) return 1; if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1; if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1; + if ($mod->code_modifiable) return 1; // A mettre en dernier return 0; } else