Laurent Destailleur 2 سال پیش
والد
کامیت
770a160b8b

+ 11 - 4
htdocs/admin/multicurrency.php

@@ -76,10 +76,15 @@ if ($action == 'add_currency') {
 	$currency->code = $code;
 	$currency->name = !empty($langs->cache_currencies[$code]['label']) ? $langs->cache_currencies[$code]['label'].' ('.$langs->getCurrencySymbol($code).')' : $code;
 
+	if (empty($currency->code) || $currency->code == '-1') {
+		setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Currency")), null, 'errors');
+		$error++;
+	}
 	if (empty($rate)) {
 		setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Rate")), null, 'errors');
 		$error++;
 	}
+
 	if (!$error) {
 		if ($currency->create($user) > 0) {
 			if ($currency->addRate($rate)) {
@@ -296,7 +301,7 @@ print '<table class="noborder centpercent nomarginbottom">';
 
 print '<tr class="liste_titre">';
 print '<td>'.$form->textwithpicto($langs->trans("CurrenciesUsed"), $langs->transnoentitiesnoconv("CurrenciesUsed_help_to_add")).'</td>'."\n";
-print '<td class="center">'.$langs->trans("Rate").'</td>'."\n";
+print '<td class="right">'.$langs->trans("Rate").' / '.$langs->getCurrencySymbol($conf->currency).'</td>'."\n";
 print '</tr>';
 
 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
@@ -304,17 +309,19 @@ print '<input type="hidden" name="token" value="'.newToken().'">';
 print '<input type="hidden" name="action" value="add_currency">';
 
 print '<tr class="oddeven">';
-print '<td>'.$form->selectCurrency('', 'code', 1).'</td>';
+print '<td>'.$form->selectCurrency('', 'code', 1, '1').'</td>';
 print '<td class="right">';
 print '<input type="text" name="rate" value="" class="width75 right" placeholder="'.$langs->trans('Rate').'" />&nbsp;';
-print '<input type="submit" class="button button-add small" value="'.$langs->trans("Add").'">';
+print '<input type="submit" class="button button-add smallpaddingimp" value="'.$langs->trans("Add").'">';
 print '</td>';
 print '</tr>';
 
 print '</form>';
 
 print '<tr class="oddeven">';
-print '<td>'.$conf->currency.$form->textwithpicto(' ', $langs->trans("BaseCurrency")).'</td>';
+print '<td>'.$conf->currency;
+print ' ('.$langs->getCurrencySymbol($conf->currency).')';
+print $form->textwithpicto(' ', $langs->trans("BaseCurrency")).'</td>';
 print '<td class="right">1</td>';
 print '</tr>';
 

+ 1 - 1
htdocs/core/class/conf.class.php

@@ -51,7 +51,7 @@ class Conf
 	public $use_javascript_ajax;
 	//! To store if javascript/ajax is enabked
 	public $disable_compute;
-	//! Used to store current currency (ISO code like 'USD', 'EUR', ...)
+	//! Used to store current currency (ISO code like 'USD', 'EUR', ...). To get the currency symbol: $langs->getCurrencySymbol($this->currency)
 	public $currency;
 
 	//! Used to store current css (from theme)

+ 8 - 4
htdocs/core/class/html.form.class.php

@@ -5848,12 +5848,13 @@ class Form
 	/**
 	 *  Retourne la liste des devises, dans la langue de l'utilisateur
 	 *
-	 *  @param	string	$selected    preselected currency code
-	 *  @param  string	$htmlname    name of HTML select list
-	 *  @param  string  $mode        0 = Add currency symbol into label, 1 = Add 3 letter iso code
+	 *  @param	string	$selected   preselected currency code
+	 *  @param  string	$htmlname   name of HTML select list
+	 *  @param  string  $mode       0 = Add currency symbol into label, 1 = Add 3 letter iso code
+	 *  @param	string	$useempty	'1'=Allow empty value
 	 * 	@return	string
 	 */
-	public function selectCurrency($selected = '', $htmlname = 'currency_id', $mode = 0)
+	public function selectCurrency($selected = '', $htmlname = 'currency_id', $mode = 0, $useempty = '')
 	{
 		global $conf, $langs, $user;
 
@@ -5866,6 +5867,9 @@ class Form
 		}
 
 		$out .= '<select class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'" id="'.$htmlname.'">';
+		if ($useempty) {
+			$out .= '<option value="-1" selected></option>';
+		}
 		foreach ($langs->cache_currencies as $code_iso => $currency) {
 			$labeltoshow = $currency['label'];
 			if ($mode == 1) {

+ 2 - 1
htdocs/core/lib/functions.lib.php

@@ -5383,7 +5383,8 @@ function print_fleche_navigation($page, $file, $options = '', $nextpage = 0, $be
 		print '</li>';
 	}
 	if ((int) $limit > 0 && empty($hideselectlimit)) {
-		$pagesizechoices = '10:10,15:15,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000,5000:5000,25000:25000';
+		$pagesizechoices = '10:10,15:15,20:20,30:30,40:40,50:50,100:100,250:250,500:500,1000:1000';
+		$pagesizechoices .= ',5000:5000,10000:10000,20000:20000';
 		//$pagesizechoices.=',0:'.$langs->trans("All");     // Not yet supported
 		//$pagesizechoices.=',2:2';
 		if (!empty($conf->global->MAIN_PAGESIZE_CHOICES)) {

+ 1 - 1
htdocs/core/modules/modMultiCurrency.class.php

@@ -286,7 +286,7 @@ class modMultiCurrency extends DolibarrModules
 
 		$multicurrency = new MultiCurrency($this->db);
 
-		if (!$multicurrency->checkCodeAlreadyExists($conf->currency)) {
+		if (! $multicurrency->checkCodeAlreadyExists($conf->currency)) {
 			$langs->loadCacheCurrencies('');
 
 			$multicurrency->code = $conf->currency;

+ 20 - 7
htdocs/multicurrency/multicurrency_rate.php

@@ -66,7 +66,7 @@ $offset = $limit * $page;
 $pageprev = $page - 1;
 $pagenext = $page + 1;
 if (!$sortfield) $sortfield = "cr.date_sync";
-if (!$sortorder) $sortorder = "ASC";
+if (!$sortorder) $sortorder = "DESC";
 
 
 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
@@ -106,13 +106,27 @@ if (!$user->admin || empty($conf->multicurrency->enabled)) {
 	accessforbidden();
 }
 
+$error = 0;
+
 
 /*
  * Actions
  */
 
 if ($action == "create") {
-	if (!empty($rateinput)) {
+	if (empty($multicurrency_code) || $multicurrency_code == '-1') {
+		setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Currency")), null, "errors");
+		$error++;
+	}
+	if ($rateinput === '0') {
+		setEventMessages($langs->trans('NoEmptyRate'), null, "errors");
+		$error++;
+	} elseif (empty($rateinput)) {
+		setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Rate")), null, "errors");
+		$error++;
+	}
+
+	if (!$error) {
 		$currencyRate_static = new CurrencyRate($db);
 		$currency_static = new MultiCurrency($db);
 		$fk_currency = $currency_static->getIdFromCode($db, $multicurrency_code);
@@ -129,8 +143,6 @@ if ($action == "create") {
 			dol_syslog("currencyRate:createRate", LOG_WARNING);
 			setEventMessages($currencyRate_static->error, $currencyRate_static->errors, 'errors');
 		}
-	} else {
-		setEventMessages($langs->trans('NoEmptyRate'), null, "errors");
 	}
 }
 
@@ -261,7 +273,7 @@ if (!in_array($action, array("updateRate", "deleteRate"))) {
 	print '<td> '.$langs->trans('Currency').'</td>';
 	print '<td>'.$form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code', 'alpha') : $multicurrency_code), 'multicurrency_code', 1, " code != '".$db->escape($conf->currency)."'", true).'</td>';
 
-	print ' <td>'.$langs->trans('Rate').'</td>';
+	print ' <td>'.$langs->trans('Rate').' / '.$langs->getCurrencySymbol($conf->currency).'</td>';
 	print ' <td><input type="text" min="0" step="any" class="maxwidth75" name="rateinput" value="'.dol_escape_htmltag($rateinput).'"></td>';
 
 	print '<td>';
@@ -280,7 +292,7 @@ if (!in_array($action, array("updateRate", "deleteRate"))) {
 
 
 
-$sql = 'SELECT cr.rowid, cr.date_sync, cr.rate, cr.entity, m.code, m.name ';
+$sql = 'SELECT cr.rowid, cr.date_sync, cr.rate, cr.entity, m.code, m.name';
 // Add fields from hooks
 $parameters = array();
 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
@@ -496,7 +508,8 @@ if ($resql) {
 			// code
 			if (! empty($arrayfields['m.code']['checked'])) {
 				print '<td class="tdoverflowmax200">';
-				print $obj->code." ".$obj->name;
+				print $obj->code;
+				print ' - <span class="opacitymedium">'.$obj->name.'</span>';
 				print "</td>\n";
 
 				if (! $i) $totalarray['nbfield']++;