From 923952fb250222a379ab83f219caf2dc1c5bebc0 Mon Sep 17 00:00:00 2001 From: phf Date: Fri, 3 Jun 2016 23:36:58 +0200 Subject: [PATCH 1/4] Fix conf useful has been commented --- htdocs/admin/multicurrency.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/admin/multicurrency.php b/htdocs/admin/multicurrency.php index bd49265436d..e47b2c9068e 100644 --- a/htdocs/admin/multicurrency.php +++ b/htdocs/admin/multicurrency.php @@ -264,7 +264,6 @@ print '' print ''; print ''; -/* This property seems not used in code, so i comment it $var=!$var; print ''; print ''.$langs->transnoentitiesnoconv("multicurrency_appCurrencySource").''; @@ -290,7 +289,7 @@ print ''; print ''; print ''; -*/ + print ''; print '
'; From e3a5af6ad4884fc8c39d1a8cbc91a7c3c30e0f72 Mon Sep 17 00:00:00 2001 From: phf Date: Sat, 4 Jun 2016 00:42:01 +0200 Subject: [PATCH 2/4] Fix clean multicurrency admin --- htdocs/admin/multicurrency.php | 132 ++++++++++-------- .../class/multicurrency.class.php | 24 +++- 2 files changed, 94 insertions(+), 62 deletions(-) diff --git a/htdocs/admin/multicurrency.php b/htdocs/admin/multicurrency.php index e47b2c9068e..74804b01344 100644 --- a/htdocs/admin/multicurrency.php +++ b/htdocs/admin/multicurrency.php @@ -77,20 +77,20 @@ if (preg_match('/del_(.*)/',$action,$reg)) if ($action == 'add_currency') { - $code = GETPOST('code', 'alpha'); - $name = GETPOST('name', 'alpha'); - $rate = GETPOST('rate', 'alpha'); + $langs->loadCacheCurrencies(''); + $code = GETPOST('code', 'alpha'); + $rate = GETPOST('rate', 'alpha'); $currency = new MultiCurrency($db); $currency->code = $code; - $currency->name = $name; + $currency->name = !empty($langs->cache_currencies[$code]['label']) ? $langs->cache_currencies[$code]['label'].' ('.$langs->getCurrencySymbol($code).')' : $code; if ($currency->create($user) > 0) { if ($currency->addRate($rate)) setEventMessages($langs->trans('RecordSaved'), array()); else setEventMessages($langs->trans('ErrorAddRateFail'), array(), 'errors'); } - else setEventMessages($langs->trans('ErrorAddCurrencyFail'), array()); + else setEventMessages($langs->trans('ErrorAddCurrencyFail'), $currency->errors, 'errors'); } elseif ($action == 'update_currency') { @@ -182,6 +182,7 @@ print ''.$langs->trans("Parameters").''."\n"; print ' '; print ''.$langs->trans("Value").''."\n"; +/* TODO uncomment when the functionality will integrated $var=!$var; print ''; print ''.$langs->transnoentitiesnoconv("multicurrency_useRateOnInvoiceDate").''; @@ -194,6 +195,7 @@ print $form->selectyesno("MULTICURRENCY_USE_RATE_ON_INVOICE_DATE",$conf->global- print ''; print ''; print ''; +*/ $var=!$var; print ''; @@ -208,6 +210,7 @@ print '' print ''; print ''; +/* TODO uncomment when the functionality will integrated $var=!$var; print ''; print ''.$langs->transnoentitiesnoconv("multicurrency_buyPriceInCurrency").''; @@ -220,7 +223,9 @@ print $form->selectyesno("MULTICURRENCY_BUY_PRICE_IN_CURRENCY",$conf->global->MU print ''; print ''; print ''; +*/ +/* TODO uncomment when the functionality will integrated $var=!$var; print ''; print ''.$langs->transnoentitiesnoconv("multicurrency_modifyRateApplication").''; @@ -236,64 +241,68 @@ print ''; print ''; print '
'; +*/ -$var=false; -print ''; -print ''; -print ''."\n"; -print ''; -print ''; +if (!empty($conf->global->MAIN_MULTICURRENCY_ALLOW_SYNCHRONIZATION)) +{ + $var=false; + print '
'.$langs->trans("CurrencyLayerAccount").' '; -print '
'; -print ''; -print ''; -print $langs->trans("Value").' '; -print '
'; -print '
'; + print ''; + print ''."\n"; + print ''; + print ''; + + + $var=!$var; + print ''; + print ''; + print ''; + print ''; + + $var=!$var; + print ''; + print ''; + print ''; + print ''; + + $var=!$var; + print ''; + print ''; + print ''; + print ''; + + print '
'.$langs->trans("CurrencyLayerAccount").' '; + print '
'; + print ''; + print ''; + print $langs->trans("Value").' '; + print '
'; + print '
'.$langs->transnoentitiesnoconv("multicurrency_appId").' '; + print '
'; + print ''; + print ''; + print ' '; + print ''; + print '
'; + print '
'.$langs->transnoentitiesnoconv("multicurrency_appCurrencySource").' '; + print '
'; + print ''; + print ''; + print ' '; // Default: USD + print ''; + print '
'; + print '
'.$langs->transnoentitiesnoconv("multicurrency_alternateCurrencySource").' '; + print '
'; + print ''; + print ''; + print ' '; // Example: EUR + print ''; + print '
'; + print '
'; + print '
'; +} -$var=!$var; -print ''; -print ''.$langs->transnoentitiesnoconv("multicurrency_appId").''; -print ' '; -print ''; -print '
'; -print ''; -print ''; -print ' '; -print ''; -print '
'; -print ''; - -$var=!$var; -print ''; -print ''.$langs->transnoentitiesnoconv("multicurrency_appCurrencySource").''; -print ' '; -print ''; -print '
'; -print ''; -print ''; -print ' '; // Default: USD -print ''; -print '
'; -print ''; - -$var=!$var; -print ''; -print ''.$langs->transnoentitiesnoconv("multicurrency_alternateCurrencySource").''; -print ' '; -print ''; -print '
'; -print ''; -print ''; -print ' '; // Example: EUR -print ''; -print '
'; -print ''; - - -print ''; -print '
'; - print ''; print ''; @@ -306,7 +315,8 @@ print ''; print ''; print ''; print ''; -print ''; +//print ''; +print ''; print ''; print ''; print ''; } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 64d1538578b..5a8c0440a81 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3812,7 +3812,7 @@ class Form print ''; print '
- - '.$form->selectCurrency('', 'code').' '; print ' '; diff --git a/htdocs/multicurrency/class/multicurrency.class.php b/htdocs/multicurrency/class/multicurrency.class.php index b4baa550ce7..76238e31906 100644 --- a/htdocs/multicurrency/class/multicurrency.class.php +++ b/htdocs/multicurrency/class/multicurrency.class.php @@ -107,12 +107,19 @@ class MultiCurrency extends CommonObject */ public function create(User $user, $trigger = true) { - global $conf; + global $conf,$langs; dol_syslog('Currency::create', LOG_DEBUG); $error = 0; + if (self::checkCodeAlreadyExists($this->code)) + { + $error++; + $this->errors[] = $langs->trans('multicurrency_code_already_added'); + return -1; + } + if (empty($this->entity) || $this->entity <= 0) $this->entity = $conf->entity; $now=date('Y-m-d H:i:s'); @@ -616,6 +623,21 @@ class MultiCurrency extends CommonObject } } } + + /** + * Check in database if the current code already exists + * + * @param string $code current code to search + * @return true if exists, false if not exists + */ + public static function checkCodeAlreadyExists($code) + { + global $db; + + $currency = new MultiCurrency($db); + if ($currency->fetch('', $code) > 0) return true; + else return false; + } } /** From 495ce2463dd3dcf61aa27d02ede9c8d5e67ae75e Mon Sep 17 00:00:00 2001 From: phf Date: Sat, 4 Jun 2016 01:13:23 +0200 Subject: [PATCH 3/4] Fix switch currency on document do not get the associate rate --- htdocs/comm/propal/card.php | 2 +- htdocs/core/class/html.form.class.php | 4 ++-- htdocs/multicurrency/class/multicurrency.class.php | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 82988dfcb0d..f3ebd32fe95 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -1433,7 +1433,7 @@ if ($action == 'create') print ''.fieldLabel('Currency','multicurrency_code').''; $currency_code = (!empty($soc->multicurrency_code) ? $soc->multicurrency_code : ($object->multicurrency_code ? $object->multicurrency_code : $conf->currency)); - print $form->selectMultiCurrency($currency_code, 'multicurrency_code', 1); + print $form->selectMultiCurrency($currency_code, 'multicurrency_code', 0); print '
'; print ''; print ''; print '
'; - print $this->selectMultiCurrency($selected, $htmlname, 1); + print $this->selectMultiCurrency($selected, $htmlname, 0); print '
'; @@ -4091,7 +4091,7 @@ class Form $out=''; $out.= '' print ''; print ''; +*/ + print ''; print '
'; -*/ if (!empty($conf->global->MAIN_MULTICURRENCY_ALLOW_SYNCHRONIZATION)) { $var=false; print ''; print ''; - print ''."\n"; + print ''."\n"; print ''; print '
'.$langs->trans("CurrencyLayerAccount").''.$form->textwithpicto($langs->trans("CurrencyLayerAccount"), $langs->trans("CurrencyLayerAccount_help_to_synchronize")).' '; print '
'; @@ -306,7 +307,7 @@ if (!empty($conf->global->MAIN_MULTICURRENCY_ALLOW_SYNCHRONIZATION)) print ''; print ''; -print ''."\n"; +print ''."\n"; print ''; print ''."\n"; @@ -315,7 +316,6 @@ print ''; print ''; print ''; print ''; -//print ''; print ''; print ''; print '
'.$langs->trans("Currencies").''.$form->textwithpicto($langs->trans("CurrenciesUsed"), $langs->transnoentitiesnoconv("CurrenciesUsed_help_to_add")).' '.$langs->trans("Rate").'
- '.$form->selectCurrency('', 'code').' '; diff --git a/htdocs/langs/en_US/multicurrency.lang b/htdocs/langs/en_US/multicurrency.lang new file mode 100644 index 00000000000..b37355372a1 --- /dev/null +++ b/htdocs/langs/en_US/multicurrency.lang @@ -0,0 +1,17 @@ +# ADMIN +RecordSaved=Currency rate added +RecordDeleted=Currency rate deleted +ErrorAddRateFail=Error in added rate +ErrorAddCurrencyFail=Error in added currency +ErrorDeleteCurrencyFail=Error delete fail +multicurrency_syncronize_error=Error in synchronization +multicurrency_useOriginTx=Use the origin rate +CurrencyLayerAccount=CurrencyLayer API +CurrencyLayerAccount_help_to_synchronize=You sould create an account on their website to use this functionnality
Get your API key
If you use a free account you can't change the currency source (USD by default)
But if your main currency isn't USD you can use the alternate currency source to force you main currency

You are limited at 1000 synchronizations per month +multicurrency_appId=API key +multicurrency_appCurrencySource=Currency source +multicurrency_alternateCurrencySource= Alternate currency souce +CurrenciesUsed=Currencies used +CurrenciesUsed_help_to_add=Add the differents currencies and rates you need to use on you proposals, orders, etc. +Rate=Rate +rate=rate \ No newline at end of file