Skip to content

Commit

Permalink
Merge pull request #10932 from tony13tv/patch-6
Browse files Browse the repository at this point in the history
[CHANGE] Make State available in .odt templates...
  • Loading branch information
eldy committed Jun 22, 2019
2 parents 681dbc3 + e9a8eb1 commit 9644b9c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
40 changes: 25 additions & 15 deletions htdocs/admin/company.php
Expand Up @@ -75,21 +75,31 @@
activateModulesRequiredByCountry($mysoc->country_code);
}

$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);
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);
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_FAX", GETPOST("fax", 'alpha'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_MAIL", GETPOST("mail", 'alpha'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_WEB", GETPOST("web", 'alpha'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOTE", GETPOST("note", 'none'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_GENCOD", GETPOST("barcode", 'alpha'), 'chaine', 0, '', $conf->entity);
$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);
}

$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);
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);
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_FAX", GETPOST("fax",'alpha'),'chaine',0,'',$conf->entity);
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_MAIL", GETPOST("mail",'alpha'),'chaine',0,'',$conf->entity);
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_WEB", GETPOST("web",'alpha'),'chaine',0,'',$conf->entity);
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_NOTE", GETPOST("note",'none'),'chaine',0,'',$conf->entity);
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_GENCOD", GETPOST("barcode",'alpha'),'chaine',0,'',$conf->entity);

$varforimage='logo'; $dirforimage=$conf->mycompany->dir_output.'/logos/';
if ($_FILES[$varforimage]["tmp_name"])
Expand Down
27 changes: 26 additions & 1 deletion htdocs/societe/class/societe.class.php
Expand Up @@ -3459,7 +3459,7 @@ public function setMysoc(Conf $conf)
}
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
Expand All @@ -3470,6 +3470,31 @@ public function setMysoc(Conf $conf)
$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;
Expand Down

0 comments on commit 9644b9c

Please sign in to comment.