Currency : when we pay at the same time as we record the sale / purchase , either

the bank is in euro (default currency) or the sale/purchase has the same
currency than the financial ledger
This commit is contained in:
Dany De Bontridder 2018-12-09 23:57:17 +01:00
parent 65393e331c
commit 2134aeffe7
3 changed files with 40 additions and 2 deletions

View file

@ -1607,7 +1607,33 @@ class Acc_Ledger extends jrn_def_sql
return false;
throw new Exception("Valeur invalid ".__FILE__.':'.__LINE__);
}
/**
* When we write a record for the payment at the same time as a sale or a purchase, to have a
* bank saldo reliable , all the bank operation must be in the same currency
* Operation = Currency 1 and Bank = Currency 2 then it must failed , except if currency 2 (of the bank is the
* default currency
* @param string $p_qcode_payment Qcode of the payment card
* @param int $p_currency_id currency id of the sale/purchase operation
* @throws Exception
*/
function check_currency($p_qcode_payment, $p_currency_id)
{
$card=new Fiche($this->db);
$card->get_by_qcode($p_qcode_payment);
if ( $card->id == 0) throw new Exception (_("Fiche invalide"));
$ledger = $card->get_bank_ledger();
if ( $ledger != NULL )
{
$ledger_currency_id=$ledger->get_currency()->get_id();
// if sale and payment are not the same currency and the
if ($ledger_currency_id != 0 && $p_currency_id != $ledger_currency_id )
{
throw new Exception (_("Devise de la banque doit être identique à l'opération"));
}
}
}
/**
* @brief get the date of the last operation
*/

View file

@ -159,7 +159,12 @@ class Acc_Ledger_Purchase extends Acc_Ledger
//------------------------------------------------------
// The "Paid By" check
//------------------------------------------------------
if ($e_mp != 0 ) $this->check_payment($e_mp,${"e_mp_qcode_".$e_mp});
if ($e_mp != 0 ) {
$this->check_payment($e_mp,${"e_mp_qcode_".$e_mp});
// check for the currency , if we use a financial ledger and a card which is a bank account (with his own
// ledger , then the currency of the operation must be the same
$this->check_currency(${"e_mp_qcode_" . $e_mp},$p_currency_code);
}
//----------------------------------------

View file

@ -218,8 +218,15 @@ class Acc_Ledger_Sold extends Acc_Ledger {
if ($e_mp != 0) {
$this->check_payment($e_mp, ${"e_mp_qcode_" . $e_mp});
// check for the currency , if we use a financial ledger and a card which is a bank account (with his own
// ledger , then the currency of the operation must be the same
$this->check_currency(${"e_mp_qcode_" . $e_mp},$p_currency_code);
}
//
// Check payment date
if ( isset ($mp_date) && trim ($mp_date) != "" && isDate($mp_date) == null) {
throw new Exception(_('Date de paiement invalide'),13);