From 135c3e49877d269ef8e9633885ae07c3cb86383d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Sep 2005 23:23:31 +0000 Subject: [PATCH] =?UTF-8?q?Les=20listes=20d=E9roulantes=20formes=20juridiq?= =?UTF-8?q?ues,=20d=E9partements,=20les=20identifiants=20soci=E9t=E9=20(si?= =?UTF-8?q?ren,=20siret,=20naf)=20s'affichent=20en=20fonction=20du=20pays?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/langs/en_US/admin.lang | 2 - htdocs/langs/en_US/companies.lang | 1 + htdocs/langs/en_US/main.lang | 1 + htdocs/langs/fr_FR/admin.lang | 2 - htdocs/langs/fr_FR/companies.lang | 1 + htdocs/langs/fr_FR/main.lang | 1 + htdocs/soc.php | 393 +++++++++++++++++++----------- htdocs/societe.class.php | 340 ++++++++++++-------------- 8 files changed, 415 insertions(+), 326 deletions(-) diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index babaa6cdc0c..38d8fd57d9a 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -35,8 +35,6 @@ ActiveOn=Activated on SourceFile=Source file TriggersAvailable=Triggers available TriggersDesc=Triggers are components that modify, once activated, the behaviour of Dolibarr workflow. They add new actions, activated on Dolibarr events (new company creation, invoice validation, ...). -SeeAbove=See above -ErrorSetACountryFirst=Set the country first ModuleFamilyCrm=Customer Ressource Management (CRM) ModuleFamilyProducts=Products Management ModuleFamilyHr=Human Ressource Management diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang index 5c797bc4476..a7c195618a9 100644 --- a/htdocs/langs/en_US/companies.lang +++ b/htdocs/langs/en_US/companies.lang @@ -2,6 +2,7 @@ ErrorBadEMail=EMail %s is wrong ErrorCompanyNameAlreadyExists=Company name %s already exists. Choose another one. ErrorPrefixAlreadyExists=Prefix %s already exists. Choose another one. +ErrorSetACountryFirst=Set the country first ConfirmDeleteCompany=Are you sure you want to delete this company and all inherited informations ? MenuNewCompany=New company MenuNewCustomer=New customer diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 9fe1fb547e0..809dd4b9d4c 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -21,6 +21,7 @@ ErrorWrongHostParameter=Wrong host parameter ErrorYourCountryIsNotDefined=Your country is not defined. Go to Home-Setup-Edit and post again the form. ErrorRecordIsUsedByChild=Failed to delete this record. This record is used by at least on child records. ErrorWrongValue=Wrong value +SeeAbove=See above HomeArea=Home area LastAccess=Last access RequestedUrl=Requested Url diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 2cd259fc175..24800ea43c7 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -35,8 +35,6 @@ ActiveOn=Active sur SourceFile=Fichier source TriggersAvailable=Triggers disponibles TriggersDesc=Les triggers sont des composants qui, une fois activés, modifient le comportement du workflow de Dolibarr. Ils réalisent des actions suplémentaires, déclenchées par les événements Dolibarr (création société, validation facture, clôture contrat...). -SeeAbove=Voir ci-dessus -ErrorSetACountryFirst=Définissez d'abord le pays ModuleFamilyCrm=Gestion client (CRM) ModuleFamilyProducts=Gestion produits ModuleFamilyHr=Ressources humaines diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang index 8ce4c0c228b..0da3d735fa5 100644 --- a/htdocs/langs/fr_FR/companies.lang +++ b/htdocs/langs/fr_FR/companies.lang @@ -2,6 +2,7 @@ ErrorBadEMail=e-mail %s invalide ErrorCompanyNameAlreadyExists=Le nom de société %s existe déjà. Veuillez en choisir un autre. ErrorPrefixAlreadyExists=Le préfixe %s existe déjà. Veuillez en choisir un autre. +ErrorSetACountryFirst=Définissez d'abord le pays ConfirmDeleteCompany=Êtes-vous sûr de vouloir supprimer cette société et toutes les informations qui en dépendent ? MenuNewCompany=Nouvelle société MenuNewCustomer=Nouveau client diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 2f92e0d0534..0892516460b 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -21,6 +21,7 @@ ErrorWrongHostParameter=Mauvais param ErrorYourCountryIsNotDefined=Votre pays n'est pas défini. Aller dans Configuration-Général-Editer et resoumettez le formulaire. ErrorRecordIsUsedByChild=Impossible de supprimer cet enregistrement. Ce dernier est utilisé en tant que père par au moins un enregistrement fils. ErrorWrongValue=Valeur incorrecte +SeeAbove=Voir ci-dessus HomeArea=Espace accueil LastAccess=Dernière connexion RequestedUrl=Url sollicitée diff --git a/htdocs/soc.php b/htdocs/soc.php index 1fb379f9d64..dd4edc88507 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -2,7 +2,7 @@ /* Copyright (C) 2001-2005 Rodolphe Quiedeville * Copyright (C) 2003 Brian Fraval * Copyright (C) 2004-2005 Laurent Destailleur - * Copyright (C) 2005 Eric Seigne + * 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 @@ -46,15 +46,10 @@ if ($user->societe_id > 0) $soc = new Societe($db); -$step=$_POST["step"]; -if ($_POST["createnextstep"]) { $step++; $_GET["action"]="create"; } -if ($_POST["createpreviousstep"]) { $step--; $_GET["action"]="create"; } -if (! $step) $step++; - /* * Actions */ -if (($_POST["action"] == 'add' && (! defined("COMPANY_CREATE_TWO_STEPS") || $step == 2)) or $_POST["action"] == 'update') +if ($_POST["action"] == 'add' or $_POST["action"] == 'update') { $soc->nom = stripslashes($_POST["nom"]); $soc->adresse = stripslashes($_POST["adresse"]); @@ -90,7 +85,7 @@ if (($_POST["action"] == 'add' && (! defined("COMPANY_CREATE_TWO_STEPS") || $ste { $soc->id = $_GET["socid"]; // doublon sur le prefix comm - $no_reload = 1; + $reload = 0; $mesg = $soc->error; //"Erreur, le prefix '".$soc->prefix_comm."' existe déjà vous devez en choisir un autre"; $_GET["action"]= "edit"; } @@ -134,7 +129,7 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user- } else { - $no_reload = 1; + $reload = 0; $_GET["action"]=''; } } @@ -147,6 +142,8 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user- llxHeader(); $form = new Form($db); +$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; + if ($_GET["action"] == 'create' || $_POST["action"] == 'create') { @@ -159,33 +156,31 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'create') if ($_GET["type"]=='f') { $soc->fournisseur=1; } if ($_GET["type"]=='c') { $soc->client=1; } if ($_GET["type"]=='p') { $soc->client=2; } - if ($_POST["nom"]) { $soc->nom=$_POST["nom"]; } - - print_titre($langs->trans("NewCompany")); - print "
\n"; - - if ($soc->error) + if ($_POST["nom"]) { - print '
'; - print nl2br($soc->error); - print '
'; + $soc->nom=$_POST["nom"]; + $soc->prefix_comm=$_POST["prefix_comm"]; + $soc->client=$_POST["client"]; + $soc->code_client=$_POST["code_client"]; + $soc->fournisseur=$_POST["fournisseur"]; + $soc->code_fournisseur=$_POST["code_fournisseur"]; + $soc->adresse=$_POST["adresse"]; + $soc->zip=$_POST["zip"]; + $soc->ville=$_POST["ville"]; + $soc->departement_id=$_POST["departement_id"]; + $soc->tel=$_POST["tel"]; + $soc->fax=$_POST["fax"]; + $soc->url=$_POST["url"]; + $soc->capital=$_POST["capital"]; + $soc->siren=$_POST["siren"]; + $soc->siret=$_POST["siret"]; + $soc->ape=$_POST["ape"]; + $soc->typent_id=$_POST["typent_id"]; + $soc->effectif_id=$_POST["effectif_id"]; + $soc->tva_intra_code=$_POST["tva_intra_code"]; + $soc->tva_intra_num=$_POST["tva_intra_num"]; } - - if ($conf->global->MAIN_AUTO_FILLTOWNFROMZIP) - { - include("./soc.js.php"); - } - - print '
'; - - print ''; - print ''; - - print ''; - - 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) @@ -204,115 +199,165 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'create') $soc->pays=$obj->libelle; } - if ($step==1 && defined("COMPANY_CREATE_TWO_STEPS")) + print_titre($langs->trans("NewCompany")); + print "
\n"; + + if ($soc->error) { - print ''; - - print ''; - print ''; - print ''."\n"; - + print '
'; + print nl2br($soc->error); + print '
'; } - if ($step==2 || ! defined("COMPANY_CREATE_TWO_STEPS")) { - - // Client / Prospect - print ''; - print ''; - - // Fournisseur - print ''; - print ''; - print ''; - - - if (defined("COMPANY_CREATE_TWO_STEPS")) - { - print ''; - } - else - { - print ''; - } - - print ''; - print ''; - - print ''; - - print ''; - print ''; - - print ''; - - print ''; - print ''; - - print ''; - - print ''; - print ''; - print ''; - - print ''; - - print ''; - - print ''; - print ''; - - print ''; - - print ''."\n"; + if ($conf->global->MAIN_AUTO_FILLTOWNFROMZIP) + { + include("./soc.js.php"); } + + print ' + + '; + + print ''; + + print ''; + print ''; + print ''; + + print '
'.$langs->trans('Name').''.$langs->trans('Prefix').'
'.$langs->trans('Country').''; - $form->select_pays($soc->pays_id); - print '
'.$langs->trans('ProspectCustomer').''.$langs->trans('CustomerCode').''; - print ''; - print '
'.$langs->trans('Supplier').''; - $form->selectyesnonum("fournisseur",$soc->fournisseur); - print ''.$langs->trans('SupplierCode').''; - print ''; - print '
'.$langs->trans('Country').''; - print $soc->pays; - print ''; - print '
'.$langs->trans('Country').''; - $form->select_pays($soc->pays_id); - print '
'.$langs->trans('Address').'
'.$langs->trans('Zip').'global->MAIN_AUTO_FILLTOWNFROMZIP) print ' onChange="PopupPostalCode(cp.value,ville)"'; - print '>'; - if ($conf->global->MAIN_AUTO_FILLTOWNFROMZIP) print ' '; - print ''.$langs->trans('Town').'
'.$langs->trans('State').''; - $form->select_departement($soc->departement_id,(defined("COMPANY_CREATE_TWO_STEPS")?$soc->pays_code:0)); - print '
'.$langs->trans('Phone').''.$langs->trans('Fax').'
'.$langs->trans('Web').'
'.$langs->transcountry('ProfId1',$soc->pays_code).''.$langs->transcountry('ProfId2',$soc->pays_code).'
'.$langs->transcountry('ProfId3',$soc->pays_code).' 
'.$langs->trans('Capital').' '.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('JuridicalStatus').''; - $form->select_forme_juridique($soc->forme_juridique_code,(defined("COMPANY_CREATE_TWO_STEPS")?$soc->pays_code:0)); - print '
'.$langs->trans("Type").''; - $form->select_array("typent_id",$soc->typent_array(), $soc->typent_id); - print ''.$langs->trans("Staff").''; - $form->select_array("effectif_id",$soc->effectif_array(), $soc->effectif_id); - print '
'.$langs->trans('VATIntraShort').''; - - print ''; - print ''; - print ' '.$langs->trans("VATIntraCheckableOnEUSite"); - print '
'; - if (defined("COMPANY_CREATE_TWO_STEPS")) - { - print '     '; - } - print '
'; + + print ''; + print ''; + + // Client / Prospect + print ''; + print ''; + + // Fournisseur + print ''; + print ''; + print ''; + + print ''; + + print ''; + print ''; + + print ''; + + print ''; + + print ''; + print ''; + + print ''; + + print ''; + + print ''; + print ''; + print ''; + + print ''; + + print ''; + print ''; + + print ''; + + print ''."\n"; print '
'.$langs->trans('Name').''.$langs->trans('Prefix').'
'.$langs->trans('ProspectCustomer').''.$langs->trans('CustomerCode').''; + print ''; + print '
'.$langs->trans('Supplier').''; + $form->selectyesnonum("fournisseur",$soc->fournisseur); + print ''.$langs->trans('SupplierCode').''; + print ''; + print '
'.$langs->trans('Address').'
'.$langs->trans('Zip').'global->MAIN_AUTO_FILLTOWNFROMZIP) print ' onChange="PopupPostalCode(cp.value,ville)"'; + print '>'; + if ($conf->global->MAIN_AUTO_FILLTOWNFROMZIP) print ' '; + print ''.$langs->trans('Town').'
'.$langs->trans('Country').''; + $form->select_pays($soc->pays_id,'pays_id',' onChange="save_refresh()"'); + print '
'.$langs->trans('State').''; + if ($soc->pays_id) + { + $form->select_departement($soc->departement_id,$soc->pays_code); + } + else + { + print $countrynotdefined; + } + print '
'.$langs->trans('Phone').''.$langs->trans('Fax').'
'.$langs->trans('Web').'
'.$langs->trans('Capital').' '.$langs->trans("Currency".$conf->monnaie).'
'.($langs->transcountry("ProfId1",$soc->pays_code) != '-'?$langs->transcountry('ProfId1',$soc->pays_code):'').''; + if ($soc->pays_id) + { + if ($langs->transcountry("ProfId1",$soc->pays_code) != '-') print ''; + else print ' '; + } + else + { + print $countrynotdefined; + } + 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 ''; + else print ' '; + } + else + { + print $countrynotdefined; + } + 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 ''; + else print ' '; + } + else + { + print $countrynotdefined; + } + print ' 
'.$langs->trans('JuridicalStatus').''; + if ($soc->pays_id) + { + $form->select_forme_juridique($soc->forme_juridique_code,$soc->pays_code); + } + else + { + print $countrynotdefined; + } + print '
'.$langs->trans("Type").''; + $form->select_array("typent_id",$soc->typent_array(), $soc->typent_id); + print ''.$langs->trans("Staff").''; + $form->select_array("effectif_id",$soc->effectif_array(), $soc->effectif_id); + print '
'.$langs->trans('VATIntraShort').''; + + print ''; + print ''; + print ' '.$langs->trans("VATIntraCheckableOnEUSite"); + print '
'; + print '
'."\n"; print '
'."\n"; } } -elseif ($_GET["action"] == 'edit') +elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') { /* * Fiche societe en mode edition @@ -328,12 +373,68 @@ elseif ($_GET["action"] == 'edit') include("./soc.js.php"); } - if ($no_reload <> 1) + print ' + + '; + + if ($reload || ! $_POST["nom"]) { $soc = new Societe($db); $soc->id = $_GET["socid"]; $soc->fetch($_GET["socid"]); } + else + { + $soc->id=$_POST["socid"]; + $soc->nom=$_POST["nom"]; + $soc->prefix_comm=$_POST["prefix_comm"]; + $soc->client=$_POST["client"]; + $soc->code_client=$_POST["code_client"]; + $soc->fournisseur=$_POST["fournisseur"]; + $soc->code_fournisseur=$_POST["code_fournisseur"]; + $soc->adresse=$_POST["adresse"]; + $soc->zip=$_POST["zip"]; + $soc->ville=$_POST["ville"]; + $soc->pays_id=$_POST["pays_id"]?$_POST["pays_id"]:(defined(MAIN_INFO_SOCIETE_PAYS)?MAIN_INFO_SOCIETE_PAYS:''); + $soc->departement_id=$_POST["departement_id"]; + $soc->tel=$_POST["tel"]; + $soc->fax=$_POST["fax"]; + $soc->url=$_POST["url"]; + $soc->capital=$_POST["capital"]; + $soc->siren=$_POST["siren"]; + $soc->siret=$_POST["siret"]; + $soc->ape=$_POST["ape"]; + $soc->typent_id=$_POST["typent_id"]; + $soc->effectif_id=$_POST["effectif_id"]; + $soc->tva_intra_code=$_POST["tva_intra_code"]; + $soc->tva_intra_num=$_POST["tva_intra_num"]; + + // On positionne pays_id, pays_code et libelle du pays choisi + 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=$langs->trans("Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->libelle; + } + } if ($soc->error) { @@ -344,6 +445,7 @@ elseif ($_GET["action"] == 'edit') print '
'; print ''; + print ''; print ''; print ''; @@ -400,12 +502,12 @@ elseif ($_GET["action"] == 'edit') print ''.$langs->trans('Town').''; - print ''.$langs->trans('State').''; - $form->select_departement($soc->departement_id,0); + print ''.$langs->trans('Country').''; + $form->select_pays($soc->pays_id,'pays_id',' onChange="save_refresh()"'); print ''; - print ''.$langs->trans('Country').''; - $form->select_pays($soc->pays_id); + print ''.$langs->trans('State').''; + $form->select_departement($soc->departement_id,$soc->pays_code); print ''; print ''.$langs->trans('Phone').''; @@ -464,7 +566,7 @@ elseif ($_GET["action"] == 'edit') print ''.$langs->trans("Capital").' '.$langs->trans("Currency".$conf->monnaie).''; print ''.$langs->trans('JuridicalStatus').''; - $form->select_forme_juridique($soc->forme_juridique_code,0); + $form->select_forme_juridique($soc->forme_juridique_code,$soc->pays_code); print ''; print ''.$langs->trans("Type").''; @@ -486,11 +588,13 @@ else * Fiche société en mode visu */ - if ($no_reload <> 1) + $soc = new Societe($db); + $soc->id = $_GET["socid"]; + $result=$soc->fetch($_GET["socid"]); + if ($result < 0) { - $soc = new Societe($db); - $soc->id = $_GET["socid"]; - $soc->fetch($_GET["socid"]); + dolibarr_print_error($db,$soc->error); + exit; } $h=0; @@ -586,6 +690,9 @@ else print ''.$langs->trans('Town').''.$soc->ville.""; print ''.$langs->trans('Country').''.$soc->pays.''; + print ''; + + print ''.$langs->trans('State').''.$soc->departement.''; print ''.$langs->trans('Phone').''.dolibarr_print_phone($soc->tel).''; print ''.$langs->trans('Fax').''.dolibarr_print_phone($soc->fax).''; diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index 60178362287..3e467e1d3be 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -236,189 +236,170 @@ class Societe { return $result; } - /** - * \brief Mise a jour des paramètres de la société - * \param id id societe - * \param user Utilisateur qui demande la mise à jour - * \return 0 si ok, < 0 si erreur - */ - - function update($id, $user='') - { - global $langs; + /** + * \brief Mise a jour des paramètres de la sociét + * \param id id societe + * \param user Utilisateur qui demande la mise à jour + * \return 0 si ok, < 0 si erreur + */ + function update($id, $user='') + { + global $langs; - dolibarr_syslog("Societe::Update"); - - $this->id=$id; - $this->capital=trim($this->capital); - $this->nom=trim($this->nom); - $this->adresse=trim($this->adresse); - $this->cp=trim($this->cp); - $this->ville=trim($this->ville); - $this->departement_id=trim($this->departement_id); - $this->pays_id=trim($this->pays_id); - $this->tel=trim($this->tel); - $this->fax=trim($this->fax); - $this->url=trim($this->url); - $this->siren=trim($this->siren); - $this->siret=trim($this->siret); - $this->ape=trim($this->ape); - $this->prefix_comm=trim($this->prefix_comm); - $this->tva_intra=trim($this->tva_intra); - $this->capital=trim($this->capital); - $this->effectif_id=trim($this->effectif_id); - $this->forme_juridique_code=trim($this->forme_juridique_code); + dolibarr_syslog("Societe::Update"); - $result = $this->verify(); - - if ($result == 0) - { - dolibarr_syslog("Societe::Update verify ok"); - - if (strlen($this->capital) == 0) - { - $this->capital = 0; - } - - $this->tel = ereg_replace(" ","",$this->tel); - $this->tel = ereg_replace("\.","",$this->tel); - $this->fax = ereg_replace(" ","",$this->fax); - $this->fax = ereg_replace("\.","",$this->fax); - - /* - * \todo simpliste pour l'instant mais remplit 95% des cas à améliorer - */ - if ($this->departement_id == -1 && $this->pays_id == 1) - { - if (strlen($this->cp) == 5) - { - $depid = departement_rowid($this->db, substr($this->cp,0,2), $this->pays_id); - if ($depid > 0) - { - $this->departement_id = $depid; - } - } - } - - /* - * Supression des if (trim(valeur)) pour construire la requete - * sinon il est impossible de vider les champs - */ - - $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; - $sql .= " SET nom = '" . addslashes($this->nom) ."'"; // Champ obligatoire - - $sql .= ",address = '" . addslashes($this->adresse) ."'"; - - if ($this->cp) - { $sql .= ",cp = '" . $this->cp ."'"; } - - if ($this->ville) - { $sql .= ",ville = '" . addslashes($this->ville) ."'"; } - - if ($this->departement_id) - { $sql .= ",fk_departement = '" . $this->departement_id ."'"; } - - if ($this->pays_id) - { $sql .= ",fk_pays = '" . $this->pays_id ."'"; } - - $sql .= ",tel = ".($this->tel?"'".$this->tel."'":"null"); - $sql .= ",fax = ".($this->fax?"'".$this->fax."'":"null"); - $sql .= ",url = ".($this->url?"'".$this->url."'":"null"); - - $sql .= ",siren = '". $this->siren ."'"; - $sql .= ",siret = '". $this->siret ."'"; - $sql .= ",ape = '". $this->ape ."'"; - - $sql .= ",tva_intra = '" . $this->tva_intra ."'"; - $sql .= ",capital = '" . $this->capital ."'"; - - if ($this->prefix_comm) $sql .= ",prefix_comm = '" . $this->prefix_comm ."'"; - - if ($this->effectif_id) $sql .= ",fk_effectif = '" . $this->effectif_id ."'"; - - if ($this->typent_id) $sql .= ",fk_typent = '" . $this->typent_id ."'"; - - if ($this->forme_juridique_code) $sql .= ",fk_forme_juridique = '".$this->forme_juridique_code."'"; - - $sql .= ",client = " . $this->client; - $sql .= ",fournisseur = " . $this->fournisseur; - - if ($this->creation_bit || $this->codeclient_modifiable) - { - // Attention check_codeclient peut modifier le code - // suivant le module utilisé - - $this->check_codeclient(); - - $sql .= ", code_client = ".($this->code_client?"'".$this->code_client."'":"null"); - - // Attention check_codecompta_client peut modifier le code - // suivant le module utilisé - - $this->check_codecompta_client(); - - $sql .= ", code_compta = ".($this->code_compta?"'".$this->code_compta."'":"null"); - } - - if ($this->creation_bit || $this->codefournisseur_modifiable) - { - // Attention check_codefournisseur peut modifier le code - // suivant le module utilisé - - $this->check_codefournisseur(); - - $sql .= ", code_fournisseur = ".($this->code_fournisseur?"'".$this->code_fournisseur."'":"null"); - - // Attention check_codecompta_fournisseur peut modifier le code - // suivant le module utilisé - - $this->check_codecompta_fournisseur(); - - $sql .= ", code_compta_fournisseur = ".($this->code_compta_fournisseur?"'".$this->code_compta_fournisseur."'":"null"); - } - - - - if ($user) $sql .= ",fk_user_modif = '".$user->id."'"; - - $sql .= " WHERE idp = '" . $id ."'"; - - if ($this->db->query($sql)) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); - $interface=new Interfaces($this->db); - $interface->run_triggers('COMPANY_MODIFY',$this,$user,$lang,$conf); - // Fin appel triggers - - $result = 0; - } - else - { - if ($this->db->errno() == DB_ERROR_RECORD_ALREADY_EXISTS) - { - // Doublon - $this->error = $langs->trans("ErrorPrefixAlreadyExists",$this->prefix_comm); - $result = -1; - } - else - { - dolibarr_syslog("Societe::Update echec sql=$sql"); - $result = -2; - } - } - } - - return $result; - - } + $this->id=$id; + $this->capital=trim($this->capital); + $this->nom=trim($this->nom); + $this->adresse=trim($this->adresse); + $this->cp=trim($this->cp); + $this->ville=trim($this->ville); + $this->departement_id=trim($this->departement_id); + $this->pays_id=trim($this->pays_id); + $this->tel=trim($this->tel); + $this->fax=trim($this->fax); + $this->url=trim($this->url); + $this->siren=trim($this->siren); + $this->siret=trim($this->siret); + $this->ape=trim($this->ape); + $this->prefix_comm=trim($this->prefix_comm); + $this->tva_intra=trim($this->tva_intra); + $this->capital=trim($this->capital); + $this->effectif_id=trim($this->effectif_id); + $this->forme_juridique_code=trim($this->forme_juridique_code); + + $result = $this->verify(); + + if ($result == 0) + { + dolibarr_syslog("Societe::Update verify ok"); + + if (strlen($this->capital) == 0) + { + $this->capital = 0; + } + + $this->tel = ereg_replace(" ","",$this->tel); + $this->tel = ereg_replace("\.","",$this->tel); + $this->fax = ereg_replace(" ","",$this->fax); + $this->fax = ereg_replace("\.","",$this->fax); + + /* + * Supression des if (trim(valeur)) pour construire la requete + * sinon il est impossible de vider les champs + */ + + $sql = "UPDATE ".MAIN_DB_PREFIX."societe "; + $sql .= " SET nom = '" . addslashes($this->nom) ."'"; // Champ obligatoire + + $sql .= ",address = '" . addslashes($this->adresse) ."'"; + + if ($this->cp) + { $sql .= ",cp = '" . $this->cp ."'"; } + + if ($this->ville) + { $sql .= ",ville = '" . addslashes($this->ville) ."'"; } + + $sql .= ",fk_departement = '" . ($this->departement_id?$this->departement_id:'0') ."'"; + $sql .= ",fk_pays = '" . ($this->pays_id?$this->pays_id:'0') ."'"; + + $sql .= ",tel = ".($this->tel?"'".$this->tel."'":"null"); + $sql .= ",fax = ".($this->fax?"'".$this->fax."'":"null"); + $sql .= ",url = ".($this->url?"'".$this->url."'":"null"); + + $sql .= ",siren = '". $this->siren ."'"; + $sql .= ",siret = '". $this->siret ."'"; + $sql .= ",ape = '". $this->ape ."'"; + + $sql .= ",tva_intra = '" . $this->tva_intra ."'"; + $sql .= ",capital = '" . $this->capital ."'"; + + if ($this->prefix_comm) $sql .= ",prefix_comm = '" . $this->prefix_comm ."'"; + + if ($this->effectif_id) $sql .= ",fk_effectif = '" . $this->effectif_id ."'"; + + if ($this->typent_id) $sql .= ",fk_typent = '" . $this->typent_id ."'"; + + if ($this->forme_juridique_code) $sql .= ",fk_forme_juridique = '".$this->forme_juridique_code."'"; + + $sql .= ",client = " . $this->client; + $sql .= ",fournisseur = " . $this->fournisseur; + + if ($this->creation_bit || $this->codeclient_modifiable) + { + // Attention check_codeclient peut modifier le code + // suivant le module utilis + + $this->check_codeclient(); + + $sql .= ", code_client = ".($this->code_client?"'".$this->code_client."'":"null"); + + // Attention check_codecompta_client peut modifier le code + // suivant le module utilis + + $this->check_codecompta_client(); + + $sql .= ", code_compta = ".($this->code_compta?"'".$this->code_compta."'":"null"); + } + + if ($this->creation_bit || $this->codefournisseur_modifiable) + { + // Attention check_codefournisseur peut modifier le code + // suivant le module utilis + + $this->check_codefournisseur(); + + $sql .= ", code_fournisseur = ".($this->code_fournisseur?"'".$this->code_fournisseur."'":"null"); + + // Attention check_codecompta_fournisseur peut modifier le code + // suivant le module utilis + + $this->check_codecompta_fournisseur(); + + $sql .= ", code_compta_fournisseur = ".($this->code_compta_fournisseur?"'".$this->code_compta_fournisseur."'":"null"); + } + + + + if ($user) $sql .= ",fk_user_modif = '".$user->id."'"; + + $sql .= " WHERE idp = '" . $id ."'"; + + if ($this->db->query($sql)) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $interface->run_triggers('COMPANY_MODIFY',$this,$user,$lang,$conf); + // Fin appel triggers + + $result = 0; + } + else + { + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + // Doublon + $this->error = $langs->trans("ErrorPrefixAlreadyExists",$this->prefix_comm); + $result = -1; + } + else + { + dolibarr_syslog("Societe::Update echec sql=$sql"); + $result = -2; + } + } + } + + return $result; + + } /** * \brief Charge depuis la base l'objet societe * \param socid Id de la société à charger en mémoire * \param user Objet de l'utilisateur - * \return int >0 si ok, <0 si erreur + * \return int >0 si ok, <0 si ko */ function fetch($socid, $user=0) { @@ -460,14 +441,13 @@ class Societe { $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql .= ", ".MAIN_DB_PREFIX."c_effectif as e"; $sql .= ", ".MAIN_DB_PREFIX."c_pays as p"; - $sql .= ", ".MAIN_DB_PREFIX."c_departements as d"; $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st"; $sql .= ", ".MAIN_DB_PREFIX."c_forme_juridique as fj"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON s.fk_departement = d.rowid"; $sql .= " WHERE s.idp = ".$socid; $sql .= " AND s.fk_stcomm = st.id"; $sql .= " AND s.fk_effectif = e.id"; $sql .= " AND s.fk_pays = p.rowid"; - $sql .= " AND s.fk_departement = d.rowid"; $sql .= " AND s.fk_forme_juridique = fj.code"; $resql=$this->db->query($sql); @@ -568,7 +548,8 @@ class Societe { } else { - dolibarr_syslog("Erreur Societe::Fetch aucune societe avec id=".$this->id); + dolibarr_syslog("Erreur Societe::Fetch aucune societe avec id=".$this->id." - ".$sql); + $this->error="Erreur Societe::Fetch aucune societe avec id=".$this->id." - ".$sql; $result = -2; } @@ -578,6 +559,7 @@ class Societe { { dolibarr_syslog("Erreur Societe::Fetch echec sql=$sql"); dolibarr_syslog("Erreur Societe::Fetch ".$this->db->error()); + $this->error=$this->db->error(); $result = -3; }