From 64e91fa25b1ccfdb8ba510293fcf0582be0dec01 Mon Sep 17 00:00:00 2001 From: Cristian Torres Date: Wed, 27 Mar 2019 17:09:59 -0600 Subject: [PATCH 1/4] [CHANGE] Making State available in .odt templates... ...making use of the same strategy when loading Country info from single attribute. Previously attempted on PR #10463 which has been closed This also relates to #7428 --- htdocs/admin/company.php | 12 +++++++++++- htdocs/societe/class/societe.class.php | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index 949038b4413..1a5f963a46a 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -74,11 +74,21 @@ if ( ($action == 'update' && ! GETPOST("cancel",'alpha')) activateModulesRequiredByCountry($mysoc->country_code); } + $tmparray=getState(GETPOST('state_id','int'),'all',$db,$langs,0); + if (! empty($tmparray['id'])) + { + $mysoc->state_id =$tmparray['id']; + $mysoc->state_code =$tmparray['code']; + $mysoc->state_label=$tmparray['label']; + + $s=$mysoc->state_id.':'.$mysoc->state_code.':'.$mysoc->state_label; + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_STATE", $s,'chaine',0,'',$conf->entity); + } + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM", GETPOST("nom",'nohtml'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_ADDRESS", GETPOST("MAIN_INFO_SOCIETE_ADDRESS",'nohtml'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_TOWN", GETPOST("MAIN_INFO_SOCIETE_TOWN",'nohtml'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_ZIP", GETPOST("MAIN_INFO_SOCIETE_ZIP",'alpha'),'chaine',0,'',$conf->entity); - dolibarr_set_const($db, "MAIN_INFO_SOCIETE_STATE", GETPOST("state_id",'alpha'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_REGION", GETPOST("region_code",'alpha'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_MONNAIE", GETPOST("currency",'aZ09'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_TEL", GETPOST("tel",'alpha'),'chaine',0,'',$conf->entity); diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 38d07e8e4db..ba268b0b269 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3310,6 +3310,31 @@ class Societe extends CommonObject $this->country=$country_label; if (is_object($langs)) $this->country=($langs->trans('Country'.$country_code)!='Country'.$country_code)?$langs->trans('Country'.$country_code):$country_label; + //TODO This could be replicated for region but function `getRegion` didn't exist, so I didn't added it. + // We define state_id, state_code and state + $state_id=$state_code=$state_label=''; + if (! empty($conf->global->MAIN_INFO_SOCIETE_STATE)) + { + $tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_STATE); + $state_id=$tmp[0]; + if (! empty($tmp[1])) // If $conf->global->MAIN_INFO_SOCIETE_STATE is "id:code:label" + { + $state_code=$tmp[1]; + $state_label=$tmp[2]; + } + else // For backward compatibility + { + dol_syslog("Your state setup use an old syntax. Reedit it using setup area.", LOG_ERR); + include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; + $state_code=getState($state_id,2,$this->db); // This need a SQL request, but it's the old feature that should not be used anymore + $state_label=getState($state_id,0,$this->db); // This need a SQL request, but it's the old feature that should not be used anymore + } + } + $this->state_id=$state_id; + $this->state_code=$state_code; + $this->state=$state_label; + if (is_object($langs)) $this->state=($langs->trans('State'.$state_code)!='State'.$state_code)?$langs->trans('State'.$state_code):$state_label; + $this->phone=empty($conf->global->MAIN_INFO_SOCIETE_TEL)?'':$conf->global->MAIN_INFO_SOCIETE_TEL; $this->fax=empty($conf->global->MAIN_INFO_SOCIETE_FAX)?'':$conf->global->MAIN_INFO_SOCIETE_FAX; $this->url=empty($conf->global->MAIN_INFO_SOCIETE_WEB)?'':$conf->global->MAIN_INFO_SOCIETE_WEB; From e60020140d01d3a17b4ca467641c083c410854fa Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 20 Jun 2019 04:11:10 +0200 Subject: [PATCH 2/4] Update societe.class.php --- htdocs/societe/class/societe.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 6419eb11420..44b38856b90 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3455,7 +3455,7 @@ class Societe extends CommonObject } else // For backward compatibility { - dol_syslog("Your country setup use an old syntax. Reedit it using setup area.", LOG_ERR); + dol_syslog("Your country setup use an old syntax. Reedit it using setup area.", LOG_WARNING); include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; $country_code=getCountry($country_id, 2, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore $country_label=getCountry($country_id, 0, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore From 3afa4175dbed20ce889ea1b750771b276f1fe228 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 22 Jun 2019 11:22:04 +0200 Subject: [PATCH 3/4] Update company.php --- htdocs/admin/company.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index f707f531f9d..9778a4aa610 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -86,7 +86,9 @@ if ( ($action == 'update' && ! GETPOST("cancel", 'alpha')) dolibarr_set_const($db, "MAIN_INFO_SOCIETE_STATE", $s,'chaine', 0, '', $conf->entity); } - dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM", GETPOST("nom",'nohtml'),'chaine',0,'',$conf->entity); + $db->begin(); + + dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOM", GETPOST("nom",'nohtml'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_ADDRESS", GETPOST("MAIN_INFO_SOCIETE_ADDRESS",'nohtml'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_TOWN", GETPOST("MAIN_INFO_SOCIETE_TOWN",'nohtml'),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_INFO_SOCIETE_ZIP", GETPOST("MAIN_INFO_SOCIETE_ZIP",'alpha'),'chaine',0,'',$conf->entity); From e9a8eb19bb521dd84e8ae7fa2a82409da3067bf3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 22 Jun 2019 11:24:21 +0200 Subject: [PATCH 4/4] Update company.php --- htdocs/admin/company.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index 9778a4aa610..2728448f031 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -75,7 +75,7 @@ if ( ($action == 'update' && ! GETPOST("cancel", 'alpha')) activateModulesRequiredByCountry($mysoc->country_code); } - $tmparray=getState(GETPOST('state_id','int'),'all',$db,$langs,0); + $tmparray=getState(GETPOST('state_id','int'), 'all', $db, $langs, 0); if (! empty($tmparray['id'])) { $mysoc->state_id =$tmparray['id'];