';
@@ -745,10 +751,10 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
if (!empty($conf->use_javascript_ajax)) {
print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmount' data-rowname='".$namef."' data-value='".($sign * (float) $multicurrency_remaintopay)."'");
}
- print '';
+ print '';
print '';
} else {
- print '';
+ print '';
print '';
}
}
diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php
index 3230ce19918..93a2a9abf8a 100644
--- a/htdocs/compta/paiement/class/paiement.class.php
+++ b/htdocs/compta/paiement/class/paiement.class.php
@@ -98,10 +98,15 @@ class Paiement extends CommonObject
public $amount;
/**
- * @var float Total amount of payment (in the currency of the bank account)
+ * @var float Total amount of payment (in the currency of the invoice/bank account)
*/
public $multicurrency_amount;
+ /**
+ * @var string The currency of the total of payment (so the currency of the invoice/bank account)
+ */
+ public $multicurrency_currency;
+
/**
* @var array array: invoice ID => amount for that invoice (in the main currency)
*/
@@ -290,8 +295,9 @@ class Paiement extends CommonObject
/**
* Create payment of invoices into database.
- * Use this->amounts to have list of invoices for the payment.
+ * It uses this->amounts and ->multicurrency_amounts to get the list of detail of payment for each invoices for the payment.
* For payment of a customer invoice, amounts are positive, for payment of credit note, amounts are negative
+ * This will set also ->amount and ->multicurrency_amount at end.
*
* @param User $user Object user
* @param int $closepaidinvoices 1=Also close paid invoices to paid, 0=Do nothing more
@@ -321,9 +327,10 @@ class Paiement extends CommonObject
}
$currencyofpayment = '';
+ $currencyofinvoices = '';
$currencytxofpayment = '';
- foreach ($amounts as $key => $value) { // How payment is dispatched
+ foreach ($amounts as $key => $value) { // How payment is dispatched. $key is ID of invoice
if (empty($value)) {
continue;
}
@@ -335,18 +342,35 @@ class Paiement extends CommonObject
$this->error = $langs->trans('FailedToFoundTheConversionRateForInvoice');
return -1;
}
- if (empty($currencyofpayment)) {
- $currencyofpayment = isset($this->multicurrency_code[$key]) ? $this->multicurrency_code[$key] : "";
- } elseif ($currencyofpayment != $this->multicurrency_code[$key]) {
+
+ // Set the currency of the invoice
+ $currencyofinvoiceforthisline = empty($this->multicurrency_code[$key]) ? $conf->currency : $this->multicurrency_code[$key];
+ // If a payment was enter into section of foreign currency of invoice, we want to pay in the currency if invoice
+ $currencyofpaymentforthisline = empty($this->multicurrency_amounts[$key]) ? $conf->currency : $this->multicurrency_code[$key];
+
+ //var_dump("Invoice ID: ".$key.", amount in company cur:".$this->amounts[$key]." amount in invoice cur:".$this->multicurrency_amounts[$key]." => currencyofinvoice= ".$currencyofinvoiceforthisline." - currencyofpaymentforthisline =".$currencyofpaymentforthisline);
+
+ if (empty($currencyofinvoices)) {
+ $currencyofinvoices = $currencyofinvoiceforthisline;
+ } elseif ($currencyofinvoices != $currencyofinvoiceforthisline) {
// If we have invoices with different currencies in the payment, we stop here
$this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
return -1;
}
+
+ if (empty($currencyofpayment)) {
+ $currencyofpayment = $currencyofpaymentforthisline;
+ } elseif ($currencyofpayment != $currencyofpaymentforthisline) {
+ // If we have invoices with different currencies in the payment, we stop here
+ $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
+ return -1;
+ }
+
if (empty($currencytxofpayment)) {
$currencytxofpayment = isset($this->multicurrency_tx[$key]) ? $this->multicurrency_tx[$key] : "";
}
- $totalamount_converted += $value_converted;
+ $totalamount_converted += $value_converted; // Total in currency of the invoice
$amounts_to_update[$key] = price2num($value_converted, 'MT');
$newvalue = price2num($value, 'MT');
@@ -355,6 +379,9 @@ class Paiement extends CommonObject
if (!empty($newvalue)) {
$atleastonepaymentnotnull++;
}
+
+ //var_dump('currencytxofpayment = '.$currencytxofpayment." totalamount_converted =".$totalamount_converted);
+ //print ' ';
}
if (empty($currencyofpayment)) { // Should not happen. For the case the multicurrency_code was not saved into invoices
@@ -367,14 +394,24 @@ class Paiement extends CommonObject
$bankaccount = new Account($this->db);
$bankaccount->fetch($this->fk_account);
$bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
- if ($currencyofpayment != $bankcurrencycode && $currencyofpayment != $conf->currency && $bankcurrencycode != $conf->currency) {
- $langs->load("errors");
- $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
- return -1;
+
+ if ($bankcurrencycode != $conf->currency) {
+ // If we try to pay on a bank with a different currency
+ if ($bankcurrencycode != $currencyofinvoices && $currencyofinvoices != $conf->currency) {
+ $langs->load("errors");
+ $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofinvoices, $bankcurrencycode);
+ return -1;
+ }
+ if ($bankcurrencycode != $currencyofpayment && $currencyofpayment != $conf->currency) {
+ $langs->load("errors");
+ $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
+ return -1;
+ }
+ } else {
+ // No problem in this case
}
}
-
$totalamount = (float) price2num($totalamount);
$totalamount_converted = (float) price2num($totalamount_converted);
@@ -603,9 +640,12 @@ class Paiement extends CommonObject
}
if (!$error) {
+ // Set some properties that may be used by other process after calling the create
$this->amount = $total;
$this->total = $total; // deprecated
$this->multicurrency_amount = $mtotal;
+ $this->multicurrency_currency = $currencyofinvoices;
+
$this->db->commit();
return $this->id;
} else {
@@ -626,8 +666,6 @@ class Paiement extends CommonObject
*/
public function delete($user, $notrigger = 0)
{
- $error = 0;
-
$bank_line_id = $this->bank_line;
$this->db->begin();
@@ -730,6 +768,9 @@ class Paiement extends CommonObject
$error = 0;
$bank_line_id = 0;
+ // Note: ->amount (amount in company currency) ant multicurrency_amount (amount in )was set by the ->create beforecalling this.
+ // The create had also checked that currency of payment is same than currency of bank account
+
if (isModEnabled("bank")) {
if ($accountid <= 0) {
$this->error = 'Bad value for parameter accountid='.$accountid;
@@ -759,9 +800,20 @@ class Paiement extends CommonObject
$totalamount = $this->total; // For backward compatibility
}
- // if dolibarr currency != bank currency then we received an amount in customer currency (currently I don't manage the case : my currency is USD, the customer currency is EUR and he paid me in GBP. Seems no sense for me)
- if (isModEnabled('multicurrency') && $conf->currency != $acc->currency_code) {
- $totalamount = $this->multicurrency_amount; // We will insert into llx_bank.amount in foreign currency
+ // this->amount is amount of payment in company currency
+ // this->multicurrency_amount of payment in other currency
+ // this->multicurrency_currency is the currency of the payment (may be same than the company one)
+ if ($this->multicurrency_currency == $conf->currency) {
+ if ($this->amount != $this->multicurrency_amount) {
+ // Add protection, should not happen
+ $error++;
+ $this->error = 'Payment in same currency than company but this->amount != this->multicurrency_amount';
+ }
+ }
+
+ // if company currency != bank currency, then we received an amount in customer currency (currently I don't manage the case : my currency is USD, the customer currency is EUR and he paid me in GBP. Seems no sense for me)
+ if ($conf->currency != $acc->currency_code) {
+ $totalamount = $this->multicurrency_amount; // We will insert into llx_bank.amount in foreign currency of invoice
$totalamount_main_currency = $this->amount; // We will also save the amount in main currency into column llx_bank.amount_main_currency
}
diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang
index bcff62c8c80..94e55f82eda 100644
--- a/htdocs/langs/en_US/errors.lang
+++ b/htdocs/langs/en_US/errors.lang
@@ -344,6 +344,7 @@ ErrorStartHourIsNull=Start date field cannot be empty
ErrorTooManyLinesToProcessPleaseUseAMoreSelectiveFilter=Too many lines to process. Please use a more selective filter.
ErrorEmptyValueForQty=Quantity cannot be zero.
ErrorQtyOrderedLessQtyShipped = The quantity ordered cannot be less than the quantity shipped.
+ErrorVariousPaymentOnBankAccountWithADifferentCurrencyNotYetSupported=Error, creating a various payment on a bank account with a currency different than the currency of the company is not yet supported.
# Warnings
WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup.
WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user.