From ce317d60849b228d44e4c9d5258e4a6a62787392 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 2 Feb 2009 02:04:26 +0000 Subject: [PATCH] New: Can create a third party from a member. --- htdocs/adherents/fiche.php | 120 +++++++++-- htdocs/adherents/index.php | 196 +++++++++--------- htdocs/admin/societe.php | 108 +++++----- .../modules/societe/modules_societe.class.php | 40 ++-- htdocs/langs/en_US/members.lang | 4 +- htdocs/langs/en_US/users.lang | 8 +- htdocs/langs/fr_FR/members.lang | 4 +- htdocs/langs/fr_FR/users.lang | 6 +- htdocs/lib/functions.lib.php | 16 +- htdocs/societe.class.php | 87 +++++++- htdocs/user.class.php | 8 +- mysql/migration/2.5.0-2.6.0.sql | 3 + mysql/tables/llx_adherent.key.sql | 3 + 13 files changed, 388 insertions(+), 215 deletions(-) diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index 7323d4ac3e6..0dd51c2f806 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -1,7 +1,7 @@ * Copyright (C) 2002-2003 Jean-Louis Bergamo - * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2004-2009 Laurent Destailleur * * 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 @@ -19,11 +19,11 @@ */ /** - \file htdocs/adherents/fiche.php - \ingroup adherent - \brief Page d'ajout, edition, suppression d'une fiche adherent - \version $Id$ -*/ + * \file htdocs/adherents/fiche.php + * \ingroup adherent + * \brief Page d'ajout, edition, suppression d'une fiche adherent + * \version $Id$ + */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/member.lib.php"); @@ -67,7 +67,7 @@ $typeid=isset($_GET["typeid"])?$_GET["typeid"]:$_POST["typeid"]; * Actions */ -// Create user from a memeber +// Create user from a member if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer) { // Recuperation contact actuel @@ -92,6 +92,30 @@ if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $ } } +// Create third party from a member +if ($_POST["action"] == 'confirm_create_thirdparty' && $_POST["confirm"] == 'yes' && $user->rights->societe->creer) +{ + $adh = new Adherent($db); + $result = $adh->fetch($_GET["rowid"]); + + if ($result > 0) + { + // Creation user + $company = new Societe($db); + $result=$company->create_from_member($adh,$_POST["name"]); + + if ($result < 0) + { + $langs->load("errors"); + $msg=$langs->trans($company->error); + } + } + else + { + $msg=$adh->error; + } +} + if ($_POST["action"] == 'confirm_sendinfo' && $_POST["confirm"] == 'yes') { $adh->id = $rowid; @@ -826,18 +850,41 @@ if ($rowid && $action != 'edit') $formquestion=array( array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login)); - $html->form_confirm($_SERVER["PHP_SELF"]."?rowid=".$adh->id,$langs->trans("CreateDolibarrLogin"),$langs->trans("ConfirmCreateContact"),"confirm_create_user",$formquestion); + $html->form_confirm($_SERVER["PHP_SELF"]."?rowid=".$adh->id,$langs->trans("CreateDolibarrLogin"),$langs->trans("ConfirmCreateLogin"),"confirm_create_user",$formquestion); print '
'; } - // Confirm remove member + // Confirm create third party + if ($_GET["action"] == 'create_thirdparty') + { + $name =$adh->nom; + if ($adh->nom && $adh->prenom) $name.=' '; + $name.=$adh->prenom; + if (! empty($name)) + { + if ($adh->societe) $name.=' ('.$adh->societe.')'; + } + else + { + $name=$adh->societe; + } + + // Create a form array + $formquestion=array( + array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $name)); + + $html->form_confirm($_SERVER["PHP_SELF"]."?rowid=".$adh->id,$langs->trans("CreateDolibarrThirdParty"),$langs->trans("ConfirmCreateThirdParty"),"confirm_create_thirdparty",$formquestion); + print '
'; + } + + // Confirm remove member if ($action == 'delete') { $html->form_confirm("fiche.php?rowid=$rowid",$langs->trans("DeleteMember"),$langs->trans("ConfirmDeleteMember"),"confirm_delete"); print '
'; } - // Confirm validate memeber + // Confirm validate member if ($action == 'valid') { // Cree un tableau formulaire @@ -930,32 +977,32 @@ if ($rowid && $action != 'edit') // Morphy print ''.$langs->trans("Person").''.$adh->getmorphylib().''; - // Tiers - print ''.$langs->trans("Company").''.$adh->societe.' '; + // Company + print ''.$langs->trans("Company").''.$adh->societe.''; - // Adresse - print ''.$langs->trans("Address").''.nl2br($adh->adresse).' '; + // Adresse + print ''.$langs->trans("Address").''.nl2br($adh->adresse).''; // CP / Ville - print ''.$langs->trans("Zip").' / '.$langs->trans("Town").''.$adh->cp.' '.$adh->ville.' '; + print ''.$langs->trans("Zip").' / '.$langs->trans("Town").''.$adh->cp.' '.$adh->ville.''; // Pays print ''.$langs->trans("Country").''.getCountryLabel($adh->pays_id).''; // Tel pro. - print ''.$langs->trans("PhonePro").''.dol_print_phone($adh->phone,$adh->pays_code).''; + print ''.$langs->trans("PhonePro").''.dol_print_phone($adh->phone,$adh->pays_code,0,$adh->fk_soc,1).''; // Tel perso - print ''.$langs->trans("PhonePerso").''.dol_print_phone($adh->phone_perso,$adh->pays_code).''; + print ''.$langs->trans("PhonePerso").''.dol_print_phone($adh->phone_perso,$adh->pays_code,0,$adh->fk_soc,1).''; // Tel mobile - print ''.$langs->trans("PhoneMobile").''.dol_print_phone($adh->phone_mobile,$adh->pays_code).''; + print ''.$langs->trans("PhoneMobile").''.dol_print_phone($adh->phone_mobile,$adh->pays_code,0,$adh->fk_soc,1).''; // EMail - print ''.$langs->trans("EMail").''.dol_print_email($adh->email,0,0,1).' '; + print ''.$langs->trans("EMail").''.dol_print_email($adh->email,0,$adh->fk_soc,1).''; // Date naissance - print ''.$langs->trans("Birthday").''.dolibarr_print_date($adh->naiss,'day').' '; + print ''.$langs->trans("Birthday").''.dolibarr_print_date($adh->naiss,'day').''; // Public print ''.$langs->trans("Public").''.yn($adh->public).''; @@ -975,7 +1022,23 @@ if ($rowid && $action != 'edit') else print $langs->trans("NoDolibarrAccess"); print ''; - + // Third party Dolibarr + if ($conf->societe->enabled) + { + print ''.$langs->trans("ThirdPartyDolibarr").''; + if ($adh->fk_soc) + { + $company=new Societe($db); + $result=$company->fetch($adh->fk_soc); + print $company->getNomUrl(1); + } + else + { + print $langs->trans("NoThirdPartyAssociatedToMember"); + } + print ''; + } + // Other attributs foreach($adho->attribute_label as $key=>$value) { @@ -1069,7 +1132,20 @@ if ($rowid && $action != 'edit') } } - // Supprimer + // Create third party + if ($conf->societe->enabled && ! $adh->fk_soc) + { + if ($user->rights->societe->creer) + { + print ''.$langs->trans("CreateDolibarrThirdParty").''; + } + else + { + print "".$langs->trans("CreateDolibarrThirdParty").""; + } + } + + // Supprimer if ($user->rights->adherent->supprimer) { print "id&action=delete\">".$langs->trans("Delete")."\n"; diff --git a/htdocs/adherents/index.php b/htdocs/adherents/index.php index 5cc0479ad61..475ea4e4dd1 100644 --- a/htdocs/adherents/index.php +++ b/htdocs/adherents/index.php @@ -19,10 +19,10 @@ */ /** - \file htdocs/adherents/index.php - \ingroup adherent - \brief Page accueil module adherents -*/ + * \file htdocs/adherents/index.php + * \ingroup adherent + * \brief Page accueil module adherents + */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/adherents/adherent.class.php"); @@ -42,22 +42,8 @@ print_fiche_titre($langs->trans("MembersArea")); print ''; -print '\n"; if ($conf->global->SOCIETE_CODECOMPTA_ADDON == "$file") - { - print ''; - } + { + print ''; + } else - { - print ''; + { + print ''; - } - print ''; + } + print ''; print "\n"; + } } - } - closedir($handle); + closedir($handle); } print "
'; - - - -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print "\n"; - $var=True; - $Adherents=array(); $AdherentsAValider=array(); $AdherentsResilies=array(); @@ -96,13 +82,14 @@ if ($result) } else { - $Cotisants[$objp->rowid]=0; // Calculé plus loin + $Cotisants[$objp->rowid]=0; // Calcule plus loin } $i++; } $db->free($result); } + # Liste les cotisants a jour $sql = "SELECT count(*) as somme , d.fk_adherent_type"; $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d"; @@ -112,22 +99,59 @@ $sql.= " GROUP BY d.fk_adherent_type"; $result = $db->query($sql); if ($result) { - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $Cotisants[$objp->fk_adherent_type]=$objp->somme; - $i++; - } - $db->free(); - + $num = $db->num_rows($result); + $i = 0; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $Cotisants[$objp->fk_adherent_type]=$objp->somme; + $i++; + } + $db->free(); } + + +print ''; - - -print '"; + $staticmember->id=$obj->rowid; + $staticmember->ref=trim($obj->prenom.' '.$obj->nom); + $statictype->id=$obj->typeid; + $statictype->libelle=$obj->libelle; + print ''; + print ''; + print ''; + print ''; + print ''; + $i++; + } + } + print "
'.$langs->trans("Type").''.$langs->trans("MembersStatusToValid").''.$langs->trans("MenuMembersNotUpToDate").''.$langs->trans("MenuMembersUpToDate").''.$langs->trans("MembersStatusResiliated").'
'; + + +// Formulaire recherche adherent +print '
'; +print ''; +print ''; +print ''; +print ''; +print "\n"; +$var=false; +print ""; +print ''; +print ""; +print ''; +print "
'.$langs->trans("SearchAMember").'
'; +print $langs->trans("Name").':'; +print '
'; +print $langs->trans("Other").':'; +print '
"; + + +print '
'; + + +$var=true; + $SommeA=0; $SommeB=0; $SommeC=0; $SommeD=0; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; + foreach ($AdherentType as $key => $adhtype) { $var=!$var; @@ -152,38 +176,10 @@ print ''; print "
'.$langs->trans("Type").''.$langs->trans("MembersStatusToValid").''.$langs->trans("MenuMembersNotUpToDate").''.$langs->trans("MenuMembersUpToDate").''.$langs->trans("MembersStatusResiliated").'
'.$SommeD.' '.$staticmember->LibStatut(0,$adhtype->c print '
\n"; - -print '
'; - -print '
'; - - -// Formulaire recherche adhérent -print '
'; -print ''; -print ''; -print ''; -print ''; -print "\n"; -$var=false; -print ""; -print ''; -print ""; -print ''; -print "
'.$langs->trans("SearchAMember").'
'; -print $langs->trans("Name").':'; -print '
'; -print $langs->trans("Other").':'; -print '
"; - - -print '
'; +print "
\n"; /* - * Dernières adherent + * Dernieres adherent */ $max=5; @@ -198,33 +194,33 @@ $sql.= $db->plimit($max, 0); $resql=$db->query($sql); if ($resql) { - print ''; - print ''; - print ''; + print '
'.$langs->trans("LastMembersModified",$max).'
'; + print ''; + print ''; - $num = $db->num_rows($resql); - if ($num) - { - $i = 0; - $var = True; - while ($i < $num) - { - $var=!$var; - $obj = $db->fetch_object($resql); - print ""; - $staticmember->id=$obj->rowid; - $staticmember->ref=trim($obj->prenom.' '.$obj->nom); - $statictype->id=$obj->typeid; - $statictype->libelle=$obj->libelle; - print ''; - print ''; - print ''; - print ''; - print ''; - $i++; - } - } - print "
'.$langs->trans("LastMembersModified",$max).'
'.$staticmember->getNomUrl(1).''.$statictype->getNomUrl(1).''.dolibarr_print_date($obj->datem,'dayhour').''.$staticmember->LibStatut($obj->statut,($obj->cotisation=='yes'?1:0),$obj->date_end_subscription,5).'

"; + $num = $db->num_rows($resql); + if ($num) + { + $i = 0; + $var = True; + while ($i < $num) + { + $var=!$var; + $obj = $db->fetch_object($resql); + print "
'.$staticmember->getNomUrl(1).''.$statictype->getNomUrl(1).''.dolibarr_print_date($obj->datem,'dayhour').''.$staticmember->LibStatut($obj->statut,($obj->cotisation=='yes'?1:0),$obj->date_end_subscription,5).'

"; } else { @@ -233,7 +229,7 @@ else -// Tableau résumé par an +// Tableau r�sum� par an $Total=array(); $Number=array(); $tot=0; @@ -249,18 +245,18 @@ if(isset($date_select) && $date_select != '') $result = $db->query($sql); if ($result) { - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $year=dolibarr_print_date($objp->dateadh,"%Y"); - $Total[$year]=(isset($Total[$year])?$Total[$year]:0)+$objp->cotisation; - $Number[$year]=(isset($Number[$year])?$Number[$year]:0)+1; - $tot+=$objp->cotisation; - $numb+=1; - $i++; - } + $num = $db->num_rows($result); + $i = 0; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $year=dolibarr_print_date($objp->dateadh,"%Y"); + $Total[$year]=(isset($Total[$year])?$Total[$year]:0)+$objp->cotisation; + $Number[$year]=(isset($Number[$year])?$Number[$year]:0)+1; + $tot+=$objp->cotisation; + $numb+=1; + $i++; + } } print ''; @@ -275,8 +271,8 @@ $var=true; krsort($Total); foreach ($Total as $key=>$value) { - $var=!$var; - print ""; + $var=!$var; + print ""; print ""; print ""; print ""; diff --git a/htdocs/admin/societe.php b/htdocs/admin/societe.php index e472c6ee26c..daa474d6ca3 100644 --- a/htdocs/admin/societe.php +++ b/htdocs/admin/societe.php @@ -20,11 +20,11 @@ */ /** - \file htdocs/admin/societe.php - \ingroup company - \brief Page d'administration/configuration du module Societe - \version $Id$ -*/ + \file htdocs/admin/societe.php + \ingroup company + \brief Page d'administration/configuration du module Societe + \version $Id$ + */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); @@ -32,7 +32,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); $langs->load("admin"); if (!$user->admin) - accessforbidden(); +accessforbidden(); /* @@ -66,15 +66,15 @@ if ($_GET["action"] == 'setcodecompta') if ($_POST["action"] == 'usesearchtoselectcompany') { - if (dolibarr_set_const($db, "COMPANY_USE_SEARCH_TO_SELECT", $_POST["activate_usesearchtoselectcompany"])) - { - Header("Location: ".$_SERVER["PHP_SELF"]); - exit; - } - else - { - dolibarr_print_error($db); - } + if (dolibarr_set_const($db, "COMPANY_USE_SEARCH_TO_SELECT", $_POST["activate_usesearchtoselectcompany"])) + { + Header("Location: ".$_SERVER["PHP_SELF"]); + exit; + } + else + { + dolibarr_print_error($db); + } } // define constants for tigre model @@ -123,9 +123,9 @@ if ($handle) // Loop on each module find in opened directory while (($file = readdir($handle))!==false) - { - if (substr($file, 0, 15) == 'mod_codeclient_' && substr($file, -3) == 'php') { + if (substr($file, 0, 15) == 'mod_codeclient_' && substr($file, -3) == 'php') + { $file = substr($file, 0, strlen($file)-4); require_once(DOL_DOCUMENT_ROOT ."/includes/modules/societe/".$file.".php"); @@ -143,25 +143,25 @@ if ($handle) print '\n"; if ($conf->global->SOCIETE_CODECLIENT_ADDON == "$file") - { - print "\n"; - } + { + print "\n"; + } else - { - print ''; - } + { + print ''; + } - print ''; + print ''; print ''; + } } - } - closedir($handle); + closedir($handle); } print '
$key".$Number[$key]."".price($value)."'.$modCodeTiers->getExample($langs)."\n"; - print img_tick(); - print "\n"; + print img_tick(); + print "'.$langs->trans("Activate").''.$langs->trans("Activate").''; - $s=$modCodeTiers->getToolTip($langs,$soc,-1); - print $form->textwithhelp('',$s,1); - print ''; + $s=$modCodeTiers->getToolTip($langs,$soc,-1); + print $form->textwithhelp('',$s,1); + print '
'; @@ -188,11 +188,11 @@ $dir = "../includes/modules/societe/"; $handle = opendir($dir); if ($handle) { - $var = true; - while (($file = readdir($handle))!==false) - { - if (substr($file, 0, 15) == 'mod_codecompta_' && substr($file, -3) == 'php') + $var = true; + while (($file = readdir($handle))!==false) { + if (substr($file, 0, 15) == 'mod_codecompta_' && substr($file, -3) == 'php') + { $file = substr($file, 0, strlen($file)-4); require_once(DOL_DOCUMENT_ROOT ."/includes/modules/societe/".$file.".php"); @@ -207,21 +207,21 @@ if ($handle) print '
'.$modCodeCompta->getExample($langs)."'; - print img_tick(); - print ''; + print img_tick(); + print ''.$langs->trans("Activate").''.$langs->trans("Activate").'  
\n"; @@ -245,17 +245,17 @@ print ""; print ''.$langs->trans("UseSearchToSelectCompany").''; if (! $conf->use_javascript_ajax) { - print ''; - print $langs->trans("NotAvailableWhenAjaxDisabled"); - print ""; + print ''; + print $langs->trans("NotAvailableWhenAjaxDisabled"); + print ""; } else { - print ''; - print $html->selectyesno("activate_usesearchtoselectcompany",$conf->global->COMPANY_USE_SEARCH_TO_SELECT,1); - print ''; - print ''; - print ""; + print ''; + print $html->selectyesno("activate_usesearchtoselectcompany",$conf->global->COMPANY_USE_SEARCH_TO_SELECT,1); + print ''; + print ''; + print ""; } print ''; print ''; diff --git a/htdocs/includes/modules/societe/modules_societe.class.php b/htdocs/includes/modules/societe/modules_societe.class.php index ed86614ff1f..1ef0ffe3be5 100644 --- a/htdocs/includes/modules/societe/modules_societe.class.php +++ b/htdocs/includes/modules/societe/modules_societe.class.php @@ -23,21 +23,21 @@ /** \file htdocs/includes/modules/societe/modules_societe.class.php \ingroup societe - \brief Fichier contenant la classe mère de module de generation societes + \brief Fichier contenant la classe m�re de module de generation societes \version $Id$ */ /** \class ModeleThirdPartyCode - \brief Classe mère des modèles de numérotation des codes tiers + \brief Classe m�re des mod�les de num�rotation des codes tiers */ class ModeleThirdPartyCode { var $error=''; - /** \brief Renvoi la description par defaut du modele de numérotation + /** \brief Renvoi la description par defaut du modele de num�rotation * \return string Texte descripif */ function info($langs) @@ -55,7 +55,7 @@ class ModeleThirdPartyCode } - /** \brief Renvoi un exemple de numérotation + /** \brief Renvoi un exemple de num�rotation * \return string Example */ function getExample($langs) @@ -64,8 +64,8 @@ class ModeleThirdPartyCode return $langs->trans("NoExample"); } - /** \brief Test si les numéros déjà en vigueur dans la base ne provoquent pas de - * de conflits qui empechera cette numérotation de fonctionner. + /** \brief Test si les num�ros d�j� en vigueur dans la base ne provoquent pas de + * de conflits qui empechera cette num�rotation de fonctionner. * \return boolean false si conflit, true si ok */ function canBeActivated() @@ -73,7 +73,7 @@ class ModeleThirdPartyCode return true; } - /** \brief Renvoi prochaine valeur attribuée + /** \brief Renvoi prochaine valeur attribu�e * \return string Valeur */ function getNextValue($objsoc=0,$type=-1) @@ -98,7 +98,7 @@ class ModeleThirdPartyCode } /** - * \brief Renvoi la liste des modèles actifs + * \brief Renvoi la liste des mod�les actifs * \param db Handler de base */ function liste_modeles($db) @@ -142,12 +142,12 @@ class ModeleThirdPartyCode if ($type != -1) $s.=$langs->trans("ValidityControledByModule").': '.$this->getNom($langs).'
'; $s.='
'; $s.=''.$langs->trans("ThisIsModuleRules").':
'; - if ($type == 0) $s.=$langs->trans("RequiredIfCustomer").': '.yn(!$this->code_null,1,1).'
'; - if ($type == 1) $s.=$langs->trans("RequiredIfSupplier").': '.yn(!$this->code_null,1,1).'
'; - if ($type == -1) $s.=$langs->trans("Required").': '.yn(!$this->code_null,1,1).'
'; - $s.=$langs->trans("CanBeModifiedIfOk").': '.yn($this->code_modifiable,1,1).'
'; - $s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide,1,1).'
'; - $s.=$langs->trans("AutomaticCode").': '.yn($this->code_auto,1,1).'
'; + if ($type == 0) $s.=$langs->trans("RequiredIfCustomer").': '.yn(!$this->code_null,1,2).'
'; + if ($type == 1) $s.=$langs->trans("RequiredIfSupplier").': '.yn(!$this->code_null,1,2).'
'; + if ($type == -1) $s.=$langs->trans("Required").': '.yn(!$this->code_null,1,2).'
'; + $s.=$langs->trans("CanBeModifiedIfOk").': '.yn($this->code_modifiable,1,2).'
'; + $s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide,1,2).'
'; + $s.=$langs->trans("AutomaticCode").': '.yn($this->code_auto,1,2).'
'; $s.='
'; if ($type == 0 || $type == -1) $s.=$langs->trans("NextValue").': '.$this->getNextValue($soc,0).'
'; if ($type == 1 || $type == -1) $s.=$langs->trans("NextValue").': '.$this->getNextValue($soc,1).''; @@ -164,14 +164,14 @@ class ModeleThirdPartyCode /** \class ModeleAccountancyCode - \brief Classe mère des modèles de numérotation des codes compta + \brief Classe m�re des mod�les de num�rotation des codes compta */ class ModeleAccountancyCode { var $error=''; - /** \brief Renvoi la description par defaut du modele de numérotation + /** \brief Renvoi la description par defaut du modele de num�rotation * \return string Texte descripif */ function info($langs) @@ -180,7 +180,7 @@ class ModeleAccountancyCode return $langs->trans("NoDescription"); } - /** \brief Renvoi un exemple de numérotation + /** \brief Renvoi un exemple de num�rotation * \return string Example */ function getExample($langs) @@ -189,8 +189,8 @@ class ModeleAccountancyCode return $langs->trans("NoExample"); } - /** \brief Test si les numéros déjà en vigueur dans la base ne provoquent pas de - * de conflits qui empechera cette numérotation de fonctionner. + /** \brief Test si les num�ros d�j� en vigueur dans la base ne provoquent pas de + * de conflits qui empechera cette num�rotation de fonctionner. * \return boolean false si conflit, true si ok */ function canBeActivated() @@ -198,7 +198,7 @@ class ModeleAccountancyCode return true; } - /** \brief Renvoi prochaine valeur attribuée + /** \brief Renvoi prochaine valeur attribu�e * \return string Valeur */ function getNextValue($langs) diff --git a/htdocs/langs/en_US/members.lang b/htdocs/langs/en_US/members.lang index f4976942efe..f7c81ece1c7 100644 --- a/htdocs/langs/en_US/members.lang +++ b/htdocs/langs/en_US/members.lang @@ -133,4 +133,6 @@ DescADHERENT_CARD_HEADER_TEXT=Text printed on top of member cards DescADHERENT_CARD_TEXT=Text printed on member cards DescADHERENT_CARD_FOOTER_TEXT=Text printed on bottom of member cards ShowTypeCard=Show type '%s' -HTPasswordExport=htpassword file generation \ No newline at end of file +HTPasswordExport=htpassword file generation +NoThirdPartyAssociatedToMember=No third party associated to this member +ThirdPartyDolibarr=Dolibarr third party \ No newline at end of file diff --git a/htdocs/langs/en_US/users.lang b/htdocs/langs/en_US/users.lang index 04e8783175f..f881b8091e4 100755 --- a/htdocs/langs/en_US/users.lang +++ b/htdocs/langs/en_US/users.lang @@ -70,6 +70,7 @@ UsersToAdd=Users to add to this group GroupsToAdd=Groups to add to this user NoLogin=No login CreateDolibarrLogin=Create Dolibarr account +CreateDolibarrThirdParty=Create third party LoginAccountDisable=Account disabled, put a new login to activate it. LoginAccountDisableInDolibarr=Account disabled in Dolibarr. LoginAccountDisableInLdap=Account disabled in the domain. @@ -94,5 +95,8 @@ UserDeleted=User %s removed NewGroupCreated=Group %s created GroupModified=Group %s modified GroupDeleted=Group %s removed -ConfirmCreateContact=Are you sure yu want to create a Dolibarr account for this contact ? -LoginToCreate=Login to create \ No newline at end of file +ConfirmCreateContact=Are you sure you want to create a Dolibarr account for this contact ? +ConfirmCreateLogin=Are you sure you want to create a Dolibarr account for this member ? +ConfirmCreateThirdParty=Are you sure you want to create a third party for this member ? +LoginToCreate=Login to create +NameToCreate=Name of third party to create \ No newline at end of file diff --git a/htdocs/langs/fr_FR/members.lang b/htdocs/langs/fr_FR/members.lang index 999fe867fbc..9e40fa42f6d 100644 --- a/htdocs/langs/fr_FR/members.lang +++ b/htdocs/langs/fr_FR/members.lang @@ -133,4 +133,6 @@ DescADHERENT_CARD_HEADER_TEXT=Texte imprimé sur le haut des cartes adhérents DescADHERENT_CARD_TEXT=Texte imprimé sur les cartes adhérents DescADHERENT_CARD_FOOTER_TEXT=Texte imprimé sur le bas des cartes adhérents ShowTypeCard=Voir type '%s' -HTPasswordExport=Generation fichier htpassword \ No newline at end of file +HTPasswordExport=Generation fichier htpassword +NoThirdPartyAssociatedToMember=Pas de tiers associé à cet adhérent +ThirdPartyDolibarr=Tiers Dolibarr \ No newline at end of file diff --git a/htdocs/langs/fr_FR/users.lang b/htdocs/langs/fr_FR/users.lang index b62d4cf8255..ff3e2c109dc 100755 --- a/htdocs/langs/fr_FR/users.lang +++ b/htdocs/langs/fr_FR/users.lang @@ -70,6 +70,7 @@ UsersToAdd=Utilisateur à ajouter à ce groupe GroupsToAdd=Groupes à ajouter pour cet utilisateur NoLogin=Pas de login CreateDolibarrLogin=Créer un compte Dolibarr +CreateDolibarrThirdParty=Créer un tiers LoginAccountDisable=Le compte est désactivé, mettre un nouveau login pour l'activer. LoginAccountDisableInDolibarr=Le compte est désactivé sur Dolibarr. LoginAccountDisableInLdap=Le compte est désactivé sur le domaine. @@ -95,4 +96,7 @@ NewGroupCreated=Création groupe %s GroupModified=Modification groupe %s GroupDeleted=Suppression groupe %s ConfirmCreateContact=Etes vous sur de vouloir créer un compte Dolibarr pour ce contact ? -LoginToCreate=Login à créer \ No newline at end of file +ConfirmCreateLogin=Etes vous sur de vouloir créer un compte Dolibarr pour cet adhérent ? +ConfirmCreateThirdParty=Etes vous sur de vouloir créer un tiers pour cet adhérent ? +LoginToCreate=Login à créer +NameToCreate=Nom du tiers à créer \ No newline at end of file diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 1551c13e0bf..3faf6f2fe6e 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -789,11 +789,12 @@ function dol_print_phone($phone,$country="FR",$cid=0,$socid=0,$addlink=0,$separ= $newphone=''.$newphone.''; } - if (($cid || $socid) && $conf->agenda->enabled && $user->rights->agenda->myactions->create) + //if (($cid || $socid) && $conf->agenda->enabled && $user->rights->agenda->myactions->create) + if ($conf->agenda->enabled && $user->rights->agenda->myactions->create) { $type='AC_TEL'; if ($addlink == 'AC_FAX') $type='AC_FAX'; - $link=''.img_object($langs->trans("AddAction"),"calendar").''; + $link=''.img_object($langs->trans("AddAction"),"calendar").''; $newphone='
'.$newphone.'  '.$link.'
'; } } @@ -2265,10 +2266,10 @@ function get_default_npr($societe_vendeuse, $societe_acheteuse, $taux_produit) /** - \brief Renvoie oui ou non dans la langue choisie - \param yesno Variable pour test si oui ou non - \param case 1=Yes/No, 0=yes/no - \param color 0=texte only, 1=Text is format with a color font style + * \brief Renvoie oui ou non dans la langue choisie + * \param yesno Variable pour test si oui ou non + * \param case 1=Yes/No, 0=yes/no + * \param color 0=texte only, 1=Text is formated with a color font style (red or blue), 2=Text is formated with blue color. */ function yn($yesno, $case=1, $color=0) { @@ -2282,7 +2283,8 @@ function yn($yesno, $case=1, $color=0) elseif ($yesno == 0 || strtolower($yesno) == 'no' || strtolower($yesno) == 'false') { $result=($case?$langs->trans("No"):$langs->trans("no")); - $class='error'; + if ($color == 2) $class='ok'; + else $class='error'; } if ($color) return ''.$result.''; return $result; diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index 4668cd4bf6f..2242b792a31 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2003 Brian Fraval * Copyright (C) 2006 Andre Cianfarani @@ -688,7 +688,7 @@ class Societe extends CommonObject { global $user,$langs,$conf; - dolibarr_syslog("Societe::Delete"); + dolibarr_syslog("Societe::Delete", LOG_DEBUG); $sqr = 0; // Check if third party can be deleted @@ -746,6 +746,7 @@ class Societe extends CommonObject // Remove contacts $sql = "DELETE from ".MAIN_DB_PREFIX."socpeople"; $sql.= " WHERE fk_soc = " . $id; + dolibarr_syslog("Societe::Delete sql=".$sql, LOG_DEBUG); if ($this->db->query($sql)) { $sqr++; @@ -756,8 +757,24 @@ class Societe extends CommonObject dolibarr_syslog("Societe::Delete erreur -1 ".$this->error); } + // Update link in member table + $sql = "UPDATE ".MAIN_DB_PREFIX."adherent"; + $sql.= " SET fk_soc = NULL where fk_soc = " . $id; + dolibarr_syslog("Societe::Delete sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql)) + { + $sqr++; + } + else + { + $this->error .= $this->db->lasterror(); + dolibarr_syslog("Societe::Delete erreur -1 ".$this->error); + } + + // Remove ban $sql = "DELETE from ".MAIN_DB_PREFIX."societe_rib"; $sql.= " WHERE fk_soc = " . $id; + dolibarr_syslog("Societe::Delete sql=".$sql, LOG_DEBUG); if ($this->db->query($sql)) { $sqr++; @@ -768,8 +785,10 @@ class Societe extends CommonObject dolibarr_syslog("Societe::Delete erreur -2 ".$this->error); } + // Remove third party $sql = "DELETE from ".MAIN_DB_PREFIX."societe"; $sql.= " WHERE rowid = " . $id; + dolibarr_syslog("Societe::Delete sql=".$sql, LOG_DEBUG); if ($this->db->query($sql)) { $sqr++; @@ -780,7 +799,7 @@ class Societe extends CommonObject dolibarr_syslog("Societe::Delete erreur -3 ".$this->error); } - if ($sqr == 3) + if ($sqr == 4) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); @@ -1935,6 +1954,68 @@ class Societe extends CommonObject print ''; } + + /** + * \brief Cree en base un utilisateur depuis l'objet adherent + * \param member Objet adherent source + * \param login Login to force + * \return int Si erreur <0, si ok renvoie id compte cree + */ + function create_from_member($member,$login='') + { + global $conf,$user,$langs; + + $name=$member->societe; + if (empty($name)) $name=strtolower($member->nom.' '.$member->prenom); + + // Positionne parametres + $this->email = $member->email; + $this->nom = $name; + $this->code_client = -1; + $this->code_fournisseur = -1; + $this->adresse=$member->adresse; + $this->cp=$member->cp; + $this->ville=$member->ville; + $this->pays_code=$member->pays_code; + $this->pays_id=$member->pays_id; + $this->tel=$member->phone; // Prof phone + + $this->db->begin(); + + // Cree et positionne $this->id + $result=$this->create($user); + if ($result >= 0) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."adherent"; + $sql.= " SET fk_soc=".$this->id; + $sql.= " WHERE rowid=".$member->id; + + dolibarr_syslog("Societe::create_from_member sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("Societe::create_from_member - 1 - ".$this->error, LOG_ERR); + + $this->db->rollback(); + return -1; + } + } + else + { + // $this->error deja positionne + dolibarr_syslog("Societe::create_from_member - 2 - ".$this->error, LOG_ERR); + + $this->db->rollback(); + return $result; + } + } + } ?> diff --git a/htdocs/user.class.php b/htdocs/user.class.php index b286308d481..9b991bd911e 100644 --- a/htdocs/user.class.php +++ b/htdocs/user.class.php @@ -868,9 +868,9 @@ class User extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."user"; $sql.= " SET fk_member=".$member->id; $sql.= " WHERE rowid=".$this->id; - $resql=$this->db->query($sql); - + dolibarr_syslog("User::create_from_member sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); if ($resql) { $this->db->commit(); @@ -878,8 +878,8 @@ class User extends CommonObject } else { - $this->error=$this->db->error()." - ".$sql; - dolibarr_syslog("User::create_from_member - ".$this->error, LOG_ERR); + $this->error=$this->db->error(); + dolibarr_syslog("User::create_from_member - 1 - ".$this->error, LOG_ERR); $this->db->rollback(); return -1; diff --git a/mysql/migration/2.5.0-2.6.0.sql b/mysql/migration/2.5.0-2.6.0.sql index f18aac7414f..369473b4564 100644 --- a/mysql/migration/2.5.0-2.6.0.sql +++ b/mysql/migration/2.5.0-2.6.0.sql @@ -41,7 +41,10 @@ ALTER TABLE llx_product drop column stock_commande; ALTER TABLE llx_adherent drop index login; ALTER TABLE llx_adherent ADD UNIQUE INDEX uk_adherent_login (login); + ALTER TABLE llx_adherent add column fk_soc integer NULL after societe; +ALTER TABLE llx_adherent ADD INDEX idx_adherent_fk_soc (fk_soc); +ALTER TABLE llx_adherent ADD CONSTRAINT adherent_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid); ALTER TABLE llx_societe drop column rubrique; diff --git a/mysql/tables/llx_adherent.key.sql b/mysql/tables/llx_adherent.key.sql index 11481993fc5..3fd841adcf8 100644 --- a/mysql/tables/llx_adherent.key.sql +++ b/mysql/tables/llx_adherent.key.sql @@ -20,3 +20,6 @@ ALTER TABLE llx_adherent ADD UNIQUE INDEX uk_adherent_login (login); +ALTER TABLE llx_adherent ADD INDEX idx_adherent_fk_soc (fk_soc); + +ALTER TABLE llx_adherent ADD CONSTRAINT adherent_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);