diff --git a/htdocs/compta/bank/transfer.php b/htdocs/compta/bank/transfer.php index c52ec66a71b76..7805ac6f36a4c 100644 --- a/htdocs/compta/bank/transfer.php +++ b/htdocs/compta/bank/transfer.php @@ -69,6 +69,15 @@ */ $parameters = array('socid' => $socid); +$dateo = array(); +$label = array(); +$amount = array(); +$amountto = array(); +$accountfrom = array(); +$accountto = array(); +$type = array(); +$number = array(); +$tabnum = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); @@ -77,16 +86,6 @@ $langs->load('errors'); $i = 1; - $dateo = array(); - $label = array(); - $amount = array(); - $amountto = array(); - $accountfrom = array(); - $accountto = array(); - $type = array(); - $number = array(); - $tabnum = array(); - while ($i < $MAXLINESFORTRANSFERT) { $dateo[$i] = dol_mktime(12, 0, 0, GETPOSTINT($i.'_month'), GETPOSTINT($i.'_day'), GETPOSTINT($i.'_year')); $label[$i] = GETPOST($i.'_label', 'alpha'); @@ -141,6 +140,9 @@ $tmpaccountto = new Account($db); $tmpaccountto->fetch(GETPOSTINT($n.'_account_to')); + $amount_main_currency_from = null; + $amount_main_currency_to = null; + if ($tmpaccountto->currency_code == $tmpaccountfrom->currency_code) { $amountto[$n] = $amount[$n]; } else { @@ -149,6 +151,15 @@ setEventMessages($langs->trans("ErrorFieldRequired", '#'.$n.' '.$langs->transnoentities("AmountToOthercurrency")), null, 'errors'); } } + + if ($tmpaccountfrom->currency_code != $conf->currency && $tmpaccountto->currency_code == $conf->currency) { + $amount_main_currency_from = (float) price2num(-1 * (float) $amountto[$n]); + } + + if ($tmpaccountto->currency_code != $conf->currency && $tmpaccountfrom->currency_code == $conf->currency) { + $amount_main_currency_to = (float) price2num((float) $amount[$n]); + } + if ($amountto[$n] < 0) { $error++; setEventMessages($langs->trans("AmountMustBePositive").' #'.$n, null, 'errors'); @@ -174,13 +185,13 @@ } if (!$error) { - $bank_line_id_from = $tmpaccountfrom->addline($dateo[$n], $typefrom, $label[$n], (float) price2num(-1 * (float) $amount[$n]), $number[$n], 0, $user); + $bank_line_id_from = $tmpaccountfrom->addline($dateo[$n], $typefrom, $label[$n], (float) price2num(-1 * (float) $amount[$n]), '', 0, $user, '', '', '', null, '', $amount_main_currency_from); } if (!($bank_line_id_from > 0)) { $error++; } if (!$error) { - $bank_line_id_to = $tmpaccountto->addline($dateo[$n], $typeto, $label[$n], (float) $amountto[$n], $number[$n], 0, $user); + $bank_line_id_to = $tmpaccountto->addline($dateo[$n], $typeto, $label[$n], (float) price2num((float) $amountto[$n]), '', 0, $user, '', '', '', null, '', $amount_main_currency_to); } if (!($bank_line_id_to > 0)) { $error++; @@ -351,7 +362,7 @@ function init_page(i) { // Date print ''; - print $form->selectDate((!empty($dateo[$i]) ? $dateo[$i] : ''), $i.'_', 0, 0, 0, 'add'); + print $form->selectDate((!empty($dateo[$i] ?? null) ? $dateo[$i] : ''), $i.'_', 0, 0, 0, 'add'); print "\n"; // Cheque Number