diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 8fd43f3d5c8..0b34c42cbad 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -4030,6 +4030,14 @@ class FactureLigne extends CommonInvoiceLine
*/
public $fk_prev_id;
+ // Multicurrency
+ var $fk_multicurrency;
+ var $multicurrency_code;
+ var $multicurrency_subprice;
+ var $multicurrency_total_ht;
+ var $multicurrency_total_tva;
+ var $multicurrency_total_ttc;
+
/**
* Load invoice line from database
*
diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php
index 7b6c7dd2f5b..daf43ec9d64 100644
--- a/htdocs/compta/paiement/class/paiement.class.php
+++ b/htdocs/compta/paiement/class/paiement.class.php
@@ -150,7 +150,7 @@ class Paiement extends CommonObject
global $conf, $langs;
$error = 0;
- $way = $this->getWay();
+ $way = $this->getWay();
$now=dol_now();
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 24216072cd7..32670098ec3 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -1499,7 +1499,7 @@ abstract class CommonObject
$this->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, $line->ref_fourn);
break;
case 'order_supplier':
- $r = $this->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit);
+ $this->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit);
break;
default:
dol_syslog(get_class($this).'::setMulticurrencyRate no updateline defined', LOG_DEBUG);
diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index 52c35040d2b..a6bfef7427b 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -31,7 +31,7 @@
*/
include_once DOL_DOCUMENT_ROOT.'/core/class/commoninvoice.class.php';
-
+require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
/**
* Class to manage suppliers invoices
@@ -118,6 +118,14 @@ class FactureFournisseur extends CommonInvoice
var $extraparams=array();
+ // Multicurrency
+ var $fk_multicurrency;
+ var $multicurrency_code;
+ var $multicurrency_tx;
+ var $multicurrency_total_ht;
+ var $multicurrency_total_tva;
+ var $multicurrency_total_ttc;
+
/**
* Constructor
*
@@ -162,6 +170,16 @@ class FactureFournisseur extends CommonInvoice
$amount = $this->amount;
$remise = $this->remise;
+ // Multicurrency (test on $this->multicurrency_tx because we sould take the default rate only if not using origin rate)
+ if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency,$this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code);
+ else $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
+ if (empty($this->fk_multicurrency))
+ {
+ $this->multicurrency_code = $conf->currency;
+ $this->fk_multicurrency = 0;
+ $this->multicurrency_tx = 1;
+ }
+
$this->db->begin();
if (! $remise) $remise = 0 ;
@@ -184,6 +202,9 @@ class FactureFournisseur extends CommonInvoice
$sql.= ", fk_user_author";
$sql.= ", date_lim_reglement";
$sql.= ", fk_incoterms, location_incoterms";
+ $sql.= ", fk_multicurrency";
+ $sql.= ", multicurrency_code";
+ $sql.= ", multicurrency_tx";
$sql.= ")";
$sql.= " VALUES (";
$sql.= "'(PROV)'";
@@ -203,6 +224,9 @@ class FactureFournisseur extends CommonInvoice
$sql.= $this->date_echeance!=''?"'".$this->db->idate($this->date_echeance)."'":"null";
$sql.= ", ".(int) $this->fk_incoterms;
$sql.= ", '".$this->db->escape($this->location_incoterms)."'";
+ $sql.= ", ".(int) $this->fk_multicurrency;
+ $sql.= ", '".$this->db->escape($this->multicurrency_code)."'";
+ $sql.= ", ".(double) $this->multicurrency_tx;
$sql.= ")";
dol_syslog(get_class($this)."::create", LOG_DEBUG);
@@ -375,7 +399,8 @@ class FactureFournisseur extends CommonInvoice
$sql.= " p.code as mode_reglement_code, p.libelle as mode_reglement_libelle,";
$sql.= ' s.nom as socnom, s.rowid as socid,';
$sql.= ' t.fk_incoterms, t.location_incoterms,';
- $sql.= " i.libelle as libelle_incoterms";
+ $sql.= " i.libelle as libelle_incoterms,";
+ $sql.= ' t.fk_multicurrency, t.multicurrency_code, t.multicurrency_tx, t.multicurrency_total_ht, t.multicurrency_total_tva, t.multicurrency_total_ttc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as t';
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON (t.fk_soc = s.rowid)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON (t.fk_cond_reglement = cr.rowid)";
@@ -445,6 +470,14 @@ class FactureFournisseur extends CommonInvoice
$this->location_incoterms = $obj->location_incoterms;
$this->libelle_incoterms = $obj->libelle_incoterms;
+ // Multicurrency
+ $this->fk_multicurrency = $obj->fk_multicurrency;
+ $this->multicurrency_code = $obj->multicurrency_code;
+ $this->multicurrency_tx = $obj->multicurrency_tx;
+ $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
+ $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
+ $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
+
$this->extraparams = (array) json_decode($obj->extraparams, true);
$this->socid = $obj->socid;
@@ -496,6 +529,7 @@ class FactureFournisseur extends CommonInvoice
$sql.= ', f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 ';
$sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line, f.fk_unit';
$sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc';
+ $sql.= ', f.fk_multicurrency, f.multicurrency_code, f.multicurrency_subprice, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det as f';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON f.fk_product = p.rowid';
$sql.= ' WHERE fk_facture_fourn='.$this->id;
@@ -547,6 +581,14 @@ class FactureFournisseur extends CommonInvoice
$line->rang = $obj->rang;
$line->fk_unit = $obj->fk_unit;
+ // Multicurrency
+ $line->fk_multicurrency = $obj->fk_multicurrency;
+ $line->multicurrency_code = $obj->multicurrency_code;
+ $line->multicurrency_subprice = $obj->multicurrency_subprice;
+ $line->multicurrency_total_ht = $obj->multicurrency_total_ht;
+ $line->multicurrency_total_tva = $obj->multicurrency_total_tva;
+ $line->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
+
$this->lines[$i] = $line;
$i++;
@@ -1271,7 +1313,7 @@ class FactureFournisseur extends CommonInvoice
$localtaxes_type=getLocalTaxesFromRate($vatrate,0,$mysoc, $this->thirdparty);
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
- $tabprice = calcul_price_total($qty, $pu, $remise_percent, $vatrate, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type);
+ $tabprice = calcul_price_total($qty, $pu, $remise_percent, $vatrate, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
$total_ttc = $tabprice[2];
@@ -1280,6 +1322,12 @@ class FactureFournisseur extends CommonInvoice
$pu_ttc = $tabprice[5];
$total_localtax1 = $tabprice[9];
$total_localtax2 = $tabprice[10];
+
+ // MultiCurrency
+ $multicurrency_total_ht = $tabprice[16];
+ $multicurrency_total_tva = $tabprice[17];
+ $multicurrency_total_ttc = $tabprice[18];
+
if (empty($info_bits)) $info_bits=0;
if ($idproduct)
@@ -1321,6 +1369,12 @@ class FactureFournisseur extends CommonInvoice
$line->fk_unit = $fk_unit;
$line->array_options = $array_options;
+ // Multicurrency
+ $line->multicurrency_subprice = price2num($line->subprice * $this->multicurrency_tx);
+ $line->multicurrency_total_ht = $multicurrency_total_ht;
+ $line->multicurrency_total_tva = $multicurrency_total_tva;
+ $line->multicurrency_total_ttc = $multicurrency_total_ttc;
+
$res = $line->update($notrigger);
if ($res < 1) {
@@ -1971,6 +2025,13 @@ class SupplierInvoiceLine extends CommonObjectLine
public $localtax1_type;
public $localtax2_type;
+ // Multicurrency
+ var $fk_multicurrency;
+ var $multicurrency_code;
+ var $multicurrency_subprice;
+ var $multicurrency_total_ht;
+ var $multicurrency_total_tva;
+ var $multicurrency_total_ttc;
/**
* Constructor
@@ -2163,6 +2224,13 @@ class SupplierInvoiceLine extends CommonObjectLine
$sql.= ", product_type = ".$this->product_type;
$sql.= ", info_bits = ".$this->info_bits;
$sql.= ", fk_unit = ".$fk_unit;
+
+ // Multicurrency
+ $sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice)."";
+ $sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht)."";
+ $sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva)."";
+ $sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc)."";
+
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::update", LOG_DEBUG);
diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php
index bb84f8ca917..940de150765 100644
--- a/htdocs/fourn/class/paiementfourn.class.php
+++ b/htdocs/fourn/class/paiementfourn.class.php
@@ -27,6 +27,7 @@
*/
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
+require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
/**
* Class to manage payments for supplier invoices
@@ -134,29 +135,58 @@ class PaiementFourn extends Paiement
global $langs,$conf;
$error = 0;
+ $way = $this->getWay();
// Clean parameters
- $this->total = 0;
- foreach ($this->amounts as $key => $value)
+ $totalamount = 0;
+ $totalamount_converted = 0;
+
+ if ($way == 'dolibarr')
{
- $newvalue = price2num($value, 'MT');
- $this->amounts[$key] = $newvalue;
- $this->total += $newvalue;
+ $amounts = &$this->amounts;
+ $amounts_to_update = &$this->multicurrency_amounts;
}
- $this->total = price2num($this->total);
-
+ else
+ {
+ $amounts = &$this->multicurrency_amounts;
+ $amounts_to_update = &$this->amounts;
+ }
+
+ foreach ($amounts as $key => $value)
+ {
+ $value_converted = Multicurrency::getAmountConversionFromInvoiceRate($key, $value, $way, 'facture_fourn');
+ $totalamount_converted += $value_converted;
+ $amounts_to_update[$key] = price2num($value_converted, 'MT');
+
+ $newvalue = price2num($value,'MT');
+ $amounts[$key] = $newvalue;
+ $totalamount += $newvalue;
+ }
+ $totalamount = price2num($totalamount);
+ $totalamount_converted = price2num($totalamount_converted);
$this->db->begin();
- if ($this->total <> 0) // On accepte les montants negatifs
+ if ($totalamount <> 0) // On accepte les montants negatifs
{
$ref = $this->getNextNumRef('');
$now=dol_now();
-
+
+ if ($way == 'dolibarr')
+ {
+ $total = $totalamount;
+ $mtotal = $totalamount_converted; // Maybe use price2num with MT for the converted value
+ }
+ else
+ {
+ $total = $totalamount_converted; // Maybe use price2num with MT for the converted value
+ $mtotal = $totalamount;
+ }
+
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn (';
- $sql.= 'ref, entity, datec, datep, amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
+ $sql.= 'ref, entity, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
$sql.= " VALUES ('".$this->db->escape($ref)."', ".$conf->entity.", '".$this->db->idate($now)."',";
- $sql.= " '".$this->db->idate($this->datepaye)."', '".$this->total."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.", 0)";
+ $sql.= " '".$this->db->idate($this->datepaye)."', '".$total."', '".$mtotal."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.", 0)";
dol_syslog("PaiementFourn::create", LOG_DEBUG);
$resql = $this->db->query($sql);
@@ -171,8 +201,8 @@ class PaiementFourn extends Paiement
if (is_numeric($amount) && $amount <> 0)
{
$amount = price2num($amount);
- $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount)';
- $sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\')';
+ $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount, multicurrency_amount)';
+ $sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\', \''.$this->multicurrency_amounts[$key].'\')';
$resql=$this->db->query($sql);
if ($resql)
{
@@ -229,8 +259,11 @@ class PaiementFourn extends Paiement
$error++;
}
- if ($this->total <> 0 && $error == 0) // On accepte les montants negatifs
+ if ($totalamount <> 0 && $error == 0) // On accepte les montants negatifs
{
+ $this->amount=$total;
+ $this->total=$total;
+ $this->multicurrency_amount=$mtotal;
$this->db->commit();
dol_syslog('PaiementFourn::Create Ok Total = '.$this->total);
return $this->id;
@@ -625,4 +658,29 @@ class PaiementFourn extends Paiement
return "";
}
}
+
+ /**
+ * get the right way of payment
+ *
+ * @return string 'dolibarr' if standard comportment or paid in dolibarr currency, 'customer' if payment received from multicurrency inputs
+ */
+ function getWay()
+ {
+ global $conf;
+
+ $way = 'dolibarr';
+ if (!empty($conf->multicurrency->enabled))
+ {
+ foreach ($this->multicurrency_amounts as $value)
+ {
+ if (!empty($value)) // one value found then payment is in invoice currency
+ {
+ $way = 'customer';
+ break;
+ }
+ }
+ }
+
+ return $way;
+ }
}
diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php
index 518f09b5316..73def71adc1 100644
--- a/htdocs/fourn/facture/card.php
+++ b/htdocs/fourn/facture/card.php
@@ -261,6 +261,16 @@ if (empty($reshook))
{
$result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
}
+
+ // Multicurrency Code
+ else if ($action == 'setmulticurrencycode' && $user->rights->facture->creer) {
+ $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
+ }
+
+ // Multicurrency rate
+ else if ($action == 'setmulticurrencyrate' && $user->rights->facture->creer) {
+ $result = $object->setMulticurrencyRate(GETPOST('multicurrency_tx', 'int'));
+ }
// bank account
else if ($action == 'setbankaccount' && $user->rights->fournisseur->facture->creer) {
@@ -368,6 +378,8 @@ if (empty($reshook))
$object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
$object->fk_incoterms = GETPOST('incoterm_id', 'int');
$object->location_incoterms = GETPOST('location_incoterms', 'alpha');
+ $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
+ $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
// Auto calculation of date due if not filled by user
if(empty($object->date_echeance)) $object->date_echeance = $object->calculate_date_lim_reglement();
@@ -1257,13 +1269,16 @@ if ($action == 'create')
dol_htmloutput_events();
+ $currency_code = $conf->currency;
+
$societe='';
if (GETPOST('socid') > 0)
{
$societe=new Societe($db);
$societe->fetch(GETPOST('socid','int'));
+ if (!empty($conf->multicurrency->enabled) && !empty($societe->multicurrency_code)) $currency_code = $societe->multicurrency_code;
}
-
+
if (GETPOST('origin') && GETPOST('originid'))
{
// Parse element/subelement (ex: project_task)
@@ -1308,6 +1323,12 @@ if ($action == 'create')
$remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0));
$dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:'';
+ if (!empty($conf->multicurrency->enabled))
+ {
+ if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code;
+ if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx;
+ }
+
$datetmp=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']);
$dateinvoice=($datetmp==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$datetmp);
$datetmp=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']);
@@ -1323,6 +1344,8 @@ if ($action == 'create')
$dateinvoice=($datetmp==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$datetmp);
$datetmp=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']);
$datedue=($datetmp==''?-1:$datetmp);
+
+ if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) $currency_code = $soc->multicurrency_code;
}
@@ -1331,7 +1354,8 @@ if ($action == 'create')
print '';
print '';
print '';
-
+ if (!empty($currency_tx)) print '';
+
dol_fiche_head();
print '
';
@@ -1490,6 +1514,16 @@ if ($action == 'create')
$form->select_comptes($fk_account, 'fk_account', 0, '', 1);
print '';
+ // Multicurrency
+ if (! empty($conf->multicurrency->enabled))
+ {
+ print '';
+ print '| '.fieldLabel('Currency','multicurrency_code').' | ';
+ print '';
+ print $form->selectMultiCurrency($currency_code, 'multicurrency_code');
+ print ' |
';
+ }
+
// Public note
print '| '.$langs->trans('NotePublic').' | ';
print '';
@@ -1555,6 +1589,13 @@ if ($action == 'create')
}
}
print ' |
| '.$langs->trans('TotalTTC').' | '.price($objectsrc->total_ttc)." |
";
+
+ if (!empty($conf->multicurrency->enabled))
+ {
+ print '| ' . $langs->trans('MulticurrencyTotalHT') . ' | ' . price($objectsrc->multicurrency_total_ht) . ' |
';
+ print '| ' . $langs->trans('MulticurrencyTotalVAT') . ' | ' . price($objectsrc->multicurrency_total_tva) . " |
";
+ print '| ' . $langs->trans('MulticurrencyTotalTTC') . ' | ' . price($objectsrc->multicurrency_total_ttc) . " |
";
+ }
}
else
{
@@ -1968,6 +2009,44 @@ else
}
print '';
+ // Multicurrency
+ if (! empty($conf->multicurrency->enabled))
+ {
+ // Multicurrency code
+ print '';
+ print '| ';
+ print '';
+ print ' | ';
+ if ($action == 'editmulticurrencycode') {
+ $form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, 'multicurrency_code');
+ } else {
+ $form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, 'none');
+ }
+ print ' |
';
+
+ // Multicurrency rate
+ print '';
+ print '| ';
+ print '';
+ print ' | ';
+ if ($action == 'editmulticurrencyrate') {
+ $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'multicurrency_tx');
+ } else {
+ $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'none');
+ }
+ print ' |
';
+ }
+
// Bank Account
print '';
print '| ';
@@ -2019,6 +2098,24 @@ else
}
print ' | | '.$langs->trans('AmountTTC').' | '.price($object->total_ttc,1,$langs,0,-1,-1,$conf->currency).' | ';
+ if (!empty($conf->multicurrency->enabled))
+ {
+ // Multicurrency Amount HT
+ print '| ' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . ' | ';
+ print '' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ' | ';
+ print ' ';
+
+ // Multicurrency Amount VAT
+ print '| ' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . ' | ';
+ print '' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ' | ';
+ print ' ';
+
+ // Multicurrency Amount TTC
+ print '| ' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . ' | ';
+ print '' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ' | ';
+ print ' ';
+ }
+
// Project
if (! empty($conf->projet->enabled))
{
diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php
index 124693ed6da..dd9d8fae87f 100644
--- a/htdocs/fourn/facture/paiement.php
+++ b/htdocs/fourn/facture/paiement.php
@@ -65,7 +65,12 @@ if (! $sortorder) $sortorder="DESC";
if (! $sortfield) $sortfield="p.rowid";
$optioncss = GETPOST('optioncss','alpha');
-$amounts = array();
+$amounts = array();array();
+$amountsresttopay=array();
+$addwarning=0;
+
+$multicurrency_amounts=array();
+$multicurrency_amountsresttopay=array();
// Security check
if ($user->societe_id > 0)
@@ -144,6 +149,34 @@ if (empty($reshook))
$formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]);
}
+ elseif (substr($key,0,21) == 'multicurrency_amount_')
+ {
+ $cursorfacid = substr($key,21);
+ $multicurrency_amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
+ $multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid];
+ if (! empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++;
+ $result=$tmpinvoice->fetch($cursorfacid);
+ if ($result <= 0) dol_print_error($db);
+ $multicurrency_amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement(1));
+ if ($multicurrency_amounts[$cursorfacid])
+ {
+ // Check amount
+ if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid])))
+ {
+ $addwarning=1;
+ $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier");
+ }
+ // Check date
+ if ($datepaye && ($datepaye < $tmpinvoice->date))
+ {
+ $langs->load("errors");
+ //$error++;
+ setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
+ }
+ }
+
+ $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => GETPOST($key, 'int'));
+ }
}
// Check parameters
@@ -163,7 +196,7 @@ if (empty($reshook))
}
}
- if (empty($totalpayment) && empty($atleastonepaymentnotnull))
+ if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull))
{
setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), null, 'errors');
$error++;
@@ -174,6 +207,13 @@ if (empty($reshook))
setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), null, 'errors');
$error++;
}
+
+ // Check if payments in both currency
+ if ($totalpayment > 0 && $multicurrency_totalpayment > 0)
+ {
+ setEventMessages($langs->transnoentities('ErrorPaymentInBothCurrency'), null, 'errors');
+ $error++;
+ }
}
/*
@@ -206,6 +246,7 @@ if (empty($reshook))
$paiement = new PaiementFourn($db);
$paiement->datepaye = $datepaye;
$paiement->amounts = $amounts; // Array of amounts
+ $paiement->multicurrency_amounts = $multicurrency_amounts;
$paiement->paiementid = $_POST['paiementid'];
$paiement->num_paiement = $_POST['num_paiement'];
$paiement->note = $_POST['comment'];
@@ -344,8 +385,8 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
/*
* Autres factures impayees
*/
- $sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.datef as df';
- $sql.= ', SUM(pf.amount) as am';
+ $sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef as df';
+ $sql.= ', SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
$sql.= " WHERE f.entity = ".$conf->entity;
@@ -378,9 +419,13 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print ''.$langs->trans('RefSupplier').' | ';
print ''.$langs->trans('Date').' | ';
print ''.$langs->trans('AmountTTC').' | ';
+ if (!empty($conf->multicurrency->enabled)) print ''.$langs->trans('MulticurrencyAmountTTC').' | ';
print ''.$langs->trans('AlreadyPaid').' | ';
+ if (!empty($conf->multicurrency->enabled)) print ''.$langs->trans('MulticurrencyAlreadyPaid').' | ';
print ''.$langs->trans('RemainderToPay').' | ';
+ if (!empty($conf->multicurrency->enabled)) print ''.$langs->trans('MulticurrencyRemainderToPay').' | ';
print ''.$langs->trans('PaymentAmount').' | ';
+ if (!empty($conf->multicurrency->enabled)) print ''.$langs->trans('MulticurrencyPaymentAmount').' | ';
print '';
$var=True;
@@ -408,14 +453,39 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print '!!! | ';
}
print ''.price($objp->total_ttc).' | ';
+
+ // Multicurrency
+ if (!empty($conf->multicurrency->enabled)) print ''.price($objp->multicurrency_total_ttc).' | ';
+
print ''.price($objp->am).' | ';
+
+ // Multicurrency
+ if (!empty($conf->multicurrency->enabled)) print ''.price($objp->multicurrency_am).' | ';
+
print ''.price($objp->total_ttc - $objp->am).' | ';
+
+ // Multicurrency
+ if (!empty($conf->multicurrency->enabled)) print ''.price($objp->multicurrency_total_ttc - $objp->multicurrency_am).' | ';
+
print '';
$namef = 'amount_'.$objp->facid;
if(!empty($conf->global->FAC_AUTO_FILLJS))
print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($objp->total_ttc - $objp->am)."'");
print '';
- print " | \n";
+ print "";
+
+ // Multicurrency
+ if (!empty($conf->multicurrency->enabled))
+ {
+ print '';
+ $namef = 'multicurrency_amount_'.$objp->facid;
+ if(!empty($conf->global->FAC_AUTO_FILLJS))
+ print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($objp->multicurrency_total_ttc - $objp->multicurrency_am)."'");
+ print '';
+ print " | ";
+ }
+
+ print "\n";
$total+=$objp->total_ht;
$total_ttc+=$objp->total_ttc;
$totalrecu+=$objp->am;
@@ -427,7 +497,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
print '';
print '| '.$langs->trans('TotalTTC').': | ';
print ''.price($total_ttc).' | ';
+ if (!empty($conf->multicurrency->enabled)) print ' | ';
print ''.price($totalrecu).' | ';
+ if (!empty($conf->multicurrency->enabled)) print ' | ';
print ''.price($total_ttc - $totalrecu).' | ';
print ' | ';
print " \n";
@@ -455,7 +527,11 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
$preselectedchoice=$addwarning?'no':'yes';
print ' ';
- $text=$langs->trans('ConfirmSupplierPayment',$totalpayment,$langs->trans("Currency".$conf->currency));
+ if (!empty($totalpayment)) $text=$langs->trans('ConfirmSupplierPayment',$totalpayment,$langs->trans("Currency".$conf->currency));
+ if (!empty($multicurrency_totalpayment))
+ {
+ $text.=' '.$langs->trans('ConfirmSupplierPayment',$multicurrency_totalpayment,$langs->trans("paymentInInvoiceCurrency"));
+ }
if (GETPOST('closepaidinvoices'))
{
$text.=' '.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed");
diff --git a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql
index 963a0040dfe..4596288fcd7 100644
--- a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql
+++ b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql
@@ -281,6 +281,7 @@ ALTER TABLE llx_contratdet ADD COLUMN multicurrency_total_ttc double(24,8) DEFAU
ALTER TABLE llx_paiement ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0;
ALTER TABLE llx_paiement_facture ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0;
+ALTER TABLE llx_paiementfourn ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0;
ALTER TABLE llx_paiementfourn_facturefourn ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0;
ALTER TABLE llx_societe_remise_except ADD COLUMN multicurrency_amount_ht double(24,8) NOT NULL;
diff --git a/htdocs/install/mysql/tables/llx_paiementfourn.sql b/htdocs/install/mysql/tables/llx_paiementfourn.sql
index cbcc93d9b0f..aba54627a09 100644
--- a/htdocs/install/mysql/tables/llx_paiementfourn.sql
+++ b/htdocs/install/mysql/tables/llx_paiementfourn.sql
@@ -26,6 +26,7 @@ create table llx_paiementfourn
datec datetime, -- date de creation de l'enregistrement
datep datetime, -- date de paiement
amount real DEFAULT 0, -- montant
+ multicurrency_amount double(24,8) DEFAULT 0, -- multicurrency amount
fk_user_author integer, -- auteur
fk_paiement integer NOT NULL, -- moyen de paiement
num_paiement varchar(50), -- numero de paiement (cheque)
|