diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 487d174b2bb..c8b775f40e2 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -1927,6 +1927,44 @@ if ($action == 'create')
}
print '';
+ // Multicurrency
+ if (! empty($conf->multicurrency->enabled))
+ {
+ // Multicurrency code
+ print '
';
print '| ';
@@ -2184,43 +2222,6 @@ if ($action == 'create' && $user->rights->commande->creer)
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 ' | ';
- }
// Other attributes
$cols = 3;
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index 080db4aa64f..bc5a0767aff 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -3289,7 +3289,7 @@ class Commande extends CommonOrder
$sql.= ' l.total_ht, l.total_tva, l.total_ttc, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht, l.localtax1_tx, l.localtax2_tx,';
$sql.= ' l.date_start, l.date_end,';
$sql.= ' l.fk_unit,';
- $sql.= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
+ $sql.= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
$sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, ';
$sql.= ' p.description as product_desc, p.stock as stock_reel,';
$sql.= ' p.entity';
@@ -3342,12 +3342,12 @@ class Commande extends CommonOrder
$this->lines[$i]->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]->fk_multicurrency = $obj->fk_multicurrency;
+ $this->lines[$i]->multicurrency_code = $obj->multicurrency_code;
+ $this->lines[$i]->multicurrency_subprice = $obj->multicurrency_subprice;
+ $this->lines[$i]->multicurrency_total_ht = $obj->multicurrency_total_ht;
+ $this->lines[$i]->multicurrency_total_tva = $obj->multicurrency_total_tva;
+ $this->lines[$i]->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
$i++;
}
@@ -3850,6 +3850,13 @@ class OrderLine extends CommonOrderLine
$sql.= " , fk_parent_line=".(! empty($this->fk_parent_line)?$this->fk_parent_line:"null");
if (! empty($this->rang)) $sql.= ", rang=".$this->rang;
$sql.= " , fk_unit=".(!$this->fk_unit ? 'NULL' : $this->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->rowid;
dol_syslog(get_class($this)."::update", LOG_DEBUG);
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index c933482f98e..8ee26c3f102 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -271,6 +271,16 @@ if (empty($reshook))
dol_print_error($db, $object->error);
}
+ // 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'));
+ }
+
else if ($action == 'setinvoicedate' && $user->rights->facture->creer)
{
$object->fetch($id);
@@ -699,7 +709,9 @@ if (empty($reshook))
$object->remise_percent = $_POST['remise_percent'];
$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');
+
// Proprietes particulieres a facture de remplacement
$object->fk_facture_source = $_POST['fac_replacement'];
$object->type = Facture::TYPE_REPLACEMENT;
@@ -746,7 +758,9 @@ if (empty($reshook))
$object->remise_percent = $_POST['remise_percent'];
$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');
+
// Proprietes particulieres a facture avoir
$object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice : '';
$object->type = Facture::TYPE_CREDIT_NOTE;
@@ -831,7 +845,9 @@ if (empty($reshook))
$object->ref_client = $_POST['ref_client'];
$object->ref_int = $_POST['ref_int'];
$object->modelpdf = $_POST['model'];
-
+ $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
+ $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
+
// Source facture
$object->fac_rec = GETPOST('fac_rec');
@@ -876,6 +892,8 @@ if (empty($reshook))
$object->remise_percent = $_POST['remise_percent'];
$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');
if (GETPOST('type') == Facture::TYPE_SITUATION)
{
@@ -1855,6 +1873,8 @@ if ($action == 'create')
if ($socid > 0)
$res = $soc->fetch($socid);
+ $currency_code = $conf->currency;
+
// Load objectsrc
$remise_absolue = 0;
@@ -1923,6 +1943,12 @@ if ($action == 'create')
$remise_absolue = (! empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(! empty($soc->remise_absolue)?$soc->remise_absolue:0));
$dateinvoice = (empty($dateinvoice)?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$dateinvoice);
+ 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;
+ }
+
// Replicate extrafields
$objectsrc->fetch_optionals($originid);
$object->array_options = $objectsrc->array_options;
@@ -1936,6 +1962,8 @@ if ($action == 'create')
$remise_percent = $soc->remise_percent;
$remise_absolue = 0;
$dateinvoice = (empty($dateinvoice)?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$dateinvoice); // Do not set 0 here (0 for a date is 1970)
+
+ if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) $currency_code = $soc->multicurrency_code;
}
$absolute_discount = $soc->getAvailableDiscounts();
@@ -1958,7 +1986,8 @@ if ($action == 'create')
print '';
print '';
print '';
-
+ if (!empty($currency_tx)) print '';
+
dol_fiche_head('');
print '';
@@ -2337,6 +2366,16 @@ if ($action == 'create')
print $form->selectarray('model', $liste, $conf->global->FACTURE_ADDON_PDF);
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 '';
print '| ' . $langs->trans('NotePublic') . ' | ';
@@ -2419,6 +2458,13 @@ if ($action == 'create')
print ' | ' . $langs->transcountry("AmountLT2", $mysoc->country_code) . ' | ' . price($objectsrc->total_localtax2) . " | ";
}
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
{
@@ -3384,6 +3430,44 @@ else if ($id > 0 || ! empty($ref))
}
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 '| ';
@@ -3498,6 +3582,24 @@ else if ($id > 0 || ! empty($ref))
// Total with tax
print ' | | ' . $langs->trans('AmountTTC') . ' | ' . price($object->total_ttc, 1, '', 1, - 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 ' ';
+ }
+
// Statut
print '| ' . $langs->trans('Status') . ' | ';
print '' . ($object->getLibStatut(4, $totalpaye)) . ' | ';
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 91221118f2a..4042af717c2 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -40,7 +40,7 @@ require_once DOL_DOCUMENT_ROOT ."/core/class/commonobjectline.class.php";
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
-
+dol_include_once('/multicurrency/class/multicurrency.class.php');
/**
* Class to manage invoices
@@ -107,6 +107,14 @@ class Facture extends CommonInvoice
var $specimen;
var $fac_rec;
+
+ // Multicurrency
+ var $fk_multicurrency;
+ var $multicurrency_code;
+ var $multicurrency_tx;
+ var $multicurrency_total_ht;
+ var $multicurrency_total_tva;
+ var $multicurrency_total_ttc;
/**
* @var int Situation cycle reference number
@@ -230,6 +238,16 @@ class Facture extends CommonInvoice
if (! $this->mode_reglement_id) $this->mode_reglement_id = 0;
$this->brouillon = 1;
+ // 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;
+ }
+
dol_syslog(get_class($this)."::create user=".$user->id);
// Check parameters
@@ -301,6 +319,9 @@ class Facture extends CommonInvoice
$sql.= ", fk_cond_reglement, fk_mode_reglement, date_lim_reglement, model_pdf";
$sql.= ", situation_cycle_ref, situation_counter, situation_final";
$sql.= ", fk_incoterms, location_incoterms";
+ $sql.= ", fk_multicurrency";
+ $sql.= ", multicurrency_code";
+ $sql.= ", multicurrency_tx";
$sql.= ")";
$sql.= " VALUES (";
$sql.= "'(PROV)'";
@@ -328,6 +349,9 @@ class Facture extends CommonInvoice
$sql.= ", ".($this->situation_final?$this->situation_final:0);
$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);
@@ -973,6 +997,7 @@ class Facture extends CommonInvoice
$sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet, f.extraparams';
$sql.= ', f.situation_cycle_ref, f.situation_counter, f.situation_final';
$sql.= ', f.fk_account';
+ $sql.= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
$sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
$sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
$sql.= ', f.fk_incoterms, f.location_incoterms';
@@ -1045,6 +1070,14 @@ class Facture 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;
+
if ($this->type == self::TYPE_SITUATION && $fetch_situation)
{
$this->fetchPreviousNextSituationInvoice();
@@ -1104,6 +1137,7 @@ class Facture extends CommonInvoice
$sql.= ' l.date_start as date_start, l.date_end as date_end,';
$sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc, l.fk_code_ventilation, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht,';
$sql.= ' l.fk_unit,';
+ $sql.= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
$sql.= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as l';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
@@ -1163,7 +1197,15 @@ class Facture extends CommonInvoice
$line->situation_percent= $objp->situation_percent;
$line->fk_prev_id = $objp->fk_prev_id;
$line->fk_unit = $objp->fk_unit;
-
+
+ // Multicurrency
+ $line->fk_multicurrency = $objp->fk_multicurrency;
+ $line->multicurrency_code = $objp->multicurrency_code;
+ $line->multicurrency_subprice = $objp->multicurrency_subprice;
+ $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
+ $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
+ $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
+
$this->lines[$i] = $line;
$i++;
@@ -2255,7 +2297,7 @@ class Facture extends CommonInvoice
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty, $mysoc);
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
- $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, $situation_percent);
+ $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, $situation_percent, $this->multicurrency_tx);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
@@ -2264,6 +2306,11 @@ class Facture extends CommonInvoice
$total_localtax2 = $tabprice[10];
$pu_ht = $tabprice[3];
+ // MultiCurrency
+ $multicurrency_total_ht = $tabprice[16];
+ $multicurrency_total_tva = $tabprice[17];
+ $multicurrency_total_ttc = $tabprice[18];
+
// Rank to use
$rangtouse = $rang;
if ($rangtouse == -1)
@@ -2313,7 +2360,15 @@ class Facture extends CommonInvoice
// infos marge
$this->line->fk_fournprice = $fk_fournprice;
$this->line->pa_ht = $pa_ht;
-
+
+ // Multicurrency
+ $this->line->fk_multicurrency = $this->fk_multicurrency;
+ $this->line->multicurrency_code = $this->multicurrency_code;
+ $this->line->multicurrency_subprice = price2num($this->line->subprice * $this->multicurrency_tx);
+ $this->line->multicurrency_total_ht = $multicurrency_total_ht;
+ $this->line->multicurrency_total_tva = $multicurrency_total_tva;
+ $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
+
if (is_array($array_options) && count($array_options)>0) {
$this->line->array_options=$array_options;
}
@@ -2424,7 +2479,7 @@ class Facture extends CommonInvoice
$localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty, $mysoc);
$txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate.
- $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, $situation_percent);
+ $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, $situation_percent, $this->multicurrency_tx);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
@@ -2435,6 +2490,11 @@ class Facture extends CommonInvoice
$pu_tva = $tabprice[4];
$pu_ttc = $tabprice[5];
+ // MultiCurrency
+ $multicurrency_total_ht = $tabprice[16];
+ $multicurrency_total_tva = $tabprice[17];
+ $multicurrency_total_ttc = $tabprice[18];
+
// Old properties: $price, $remise (deprecated)
$price = $pu;
$remise = 0;
@@ -2491,6 +2551,12 @@ class Facture extends CommonInvoice
$this->line->fk_fournprice = $fk_fournprice;
$this->line->pa_ht = $pa_ht;
+ // Multicurrency
+ $this->line->multicurrency_subprice = price2num($this->line->subprice * $this->multicurrency_tx);
+ $this->line->multicurrency_total_ht = $multicurrency_total_ht;
+ $this->line->multicurrency_total_tva = $multicurrency_total_tva;
+ $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
+
if (is_array($array_options) && count($array_options)>0) {
$this->line->array_options=$array_options;
}
@@ -3591,6 +3657,7 @@ class Facture extends CommonInvoice
$sql.= ' l.total_ht, l.total_tva, l.total_ttc, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht,';
$sql.= ' l.date_start, l.date_end,';
$sql.= ' l.fk_unit,';
+ $sql.= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
$sql.= ' p.ref as product_ref, p.fk_product_type, p.label as product_label,';
$sql.= ' p.description as product_desc,';
$sql.= ' p.entity';
@@ -3643,7 +3710,15 @@ class Facture extends CommonInvoice
$this->lines[$i]->marge_tx = $marginInfos[1];
$this->lines[$i]->marque_tx = $marginInfos[2];
$this->lines[$i]->fk_unit = $obj->fk_unit;
-
+
+ // Multicurrency
+ $this->lines[$i]->fk_multicurrency = $obj->fk_multicurrency;
+ $this->lines[$i]->multicurrency_code = $obj->multicurrency_code;
+ $this->lines[$i]->multicurrency_subprice = $obj->multicurrency_subprice;
+ $this->lines[$i]->multicurrency_total_ht = $obj->multicurrency_total_ht;
+ $this->lines[$i]->multicurrency_total_tva = $obj->multicurrency_total_tva;
+ $this->lines[$i]->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
+
$i++;
}
$this->db->free($resql);
@@ -4079,7 +4154,9 @@ class FactureLigne extends CommonInvoiceLine
$sql.= ' rang, special_code, fk_product_fournisseur_price, buy_price_ht,';
$sql.= ' info_bits, total_ht, total_tva, total_ttc, total_localtax1, total_localtax2,';
$sql.= ' situation_percent, fk_prev_id,';
- $sql.= ' fk_unit)';
+ $sql.= ' fk_unit';
+ $sql.= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
+ $sql.= ')';
$sql.= " VALUES (".$this->fk_facture.",";
$sql.= " ".($this->fk_parent_line>0?"'".$this->fk_parent_line."'":"null").",";
$sql.= " ".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
@@ -4111,6 +4188,12 @@ class FactureLigne extends CommonInvoiceLine
$sql .= ", " . $this->situation_percent;
$sql .= ", " . $this->fk_prev_id;
$sql .= ", ".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
+ $sql.= ", ".$this->fk_multicurrency;
+ $sql.= ", '".$this->db->escape($this->multicurrency_code)."'";
+ $sql.= ", ".$this->multicurrency_subprice;
+ $sql.= ", ".$this->multicurrency_total_ht;
+ $sql.= ", ".$this->multicurrency_total_tva;
+ $sql.= ", ".$this->multicurrency_total_ttc;
$sql.= ')';
dol_syslog(get_class($this)."::insert", LOG_DEBUG);
@@ -4284,6 +4367,13 @@ class FactureLigne extends CommonInvoiceLine
if (! empty($this->rang)) $sql.= ", rang=".$this->rang;
$sql .= ", situation_percent=" . $this->situation_percent;
$sql .= ", fk_unit=".(!$this->fk_unit ? 'NULL' : $this->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->rowid;
dol_syslog(get_class($this)."::update", LOG_DEBUG);
diff --git a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php
index 593e4616fd0..cb9f7571858 100644
--- a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php
+++ b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php
@@ -449,8 +449,9 @@ class pdf_einstein extends ModelePDFCommandes
$pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
// Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
- $tvaligne=$object->lines[$i]->total_tva;
-
+ if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
+ else $tvaligne=$object->lines[$i]->total_tva;
+
$localtax1ligne=$object->lines[$i]->total_localtax1;
$localtax2ligne=$object->lines[$i]->total_localtax2;
$localtax1_rate=$object->lines[$i]->localtax1_tx;
@@ -501,11 +502,11 @@ class pdf_einstein extends ModelePDFCommandes
$pdf->setPage($pagenb);
if ($pagenb == 1)
{
- $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
+ $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
}
else
{
- $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
+ $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
}
$this->_pagefoot($pdf,$object,$outputlangs,1);
$pagenb++;
@@ -517,11 +518,11 @@ class pdf_einstein extends ModelePDFCommandes
{
if ($pagenb == 1)
{
- $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
+ $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
}
else
{
- $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
+ $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
}
$this->_pagefoot($pdf,$object,$outputlangs,1);
// New page
@@ -535,12 +536,12 @@ class pdf_einstein extends ModelePDFCommandes
// Show square
if ($pagenb == 1)
{
- $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
+ $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
}
else
{
- $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
+ $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
}
@@ -827,8 +828,9 @@ class pdf_einstein extends ModelePDFCommandes
$pdf->SetXY($col1x, $tab2_top + 0);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
+ $total_ht = ($conf->multicurrency->enabled && $object->mylticurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
$pdf->SetXY($col2x, $tab2_top + 0);
- $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht + (! empty($object->remise)?$object->remise:0), 0, $outputlangs), 0, 'R', 1);
+ $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (! empty($object->remise)?$object->remise:0), 0, $outputlangs), 0, 'R', 1);
// Show VAT by rates and total
$pdf->SetFillColor(248,248,248);
@@ -1006,8 +1008,9 @@ class pdf_einstein extends ModelePDFCommandes
$pdf->SetFillColor(224,224,224);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
+ $total_ttc = ($conf->multicurrency->enabled && $object->multiccurency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
- $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc, 0, $outputlangs), $useborder, 'R', 1);
+ $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
}
}
@@ -1060,7 +1063,7 @@ class pdf_einstein extends ModelePDFCommandes
* @param int $hidebottom Hide bottom bar of array
* @return void
*/
- function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
+ function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
{
global $conf;
@@ -1068,6 +1071,7 @@ class pdf_einstein extends ModelePDFCommandes
$hidebottom=0;
if ($hidetop) $hidetop=-1;
+ $currency = !empty($currency) ? $currency : $conf->currency;
$default_font_size = pdf_getPDFFontSize($outputlangs);
// Amount in (at tab_top - 1)
@@ -1076,7 +1080,7 @@ class pdf_einstein extends ModelePDFCommandes
if (empty($hidetop))
{
- $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$conf->currency));
+ $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php
index e967f6781ea..7df6b8c07cd 100644
--- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php
+++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php
@@ -540,9 +540,11 @@ class pdf_crabe extends ModelePDFFactures
$prev_progress = $object->lines[$i]->get_prev_progress();
if ($prev_progress > 0) // Compute progress from previous situation
{
- $tvaligne = $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
+ if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne = $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
+ else $tvaligne = $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
} else {
- $tvaligne = $object->lines[$i]->total_tva;
+ if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
+ else $tvaligne=$object->lines[$i]->total_tva;
}
$localtax1ligne=$object->lines[$i]->total_localtax1;
$localtax2ligne=$object->lines[$i]->total_localtax2;
@@ -596,11 +598,11 @@ class pdf_crabe extends ModelePDFFactures
$pdf->setPage($pagenb);
if ($pagenb == 1)
{
- $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
+ $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
}
else
{
- $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
+ $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
}
$this->_pagefoot($pdf,$object,$outputlangs,1);
$pagenb++;
@@ -612,11 +614,11 @@ class pdf_crabe extends ModelePDFFactures
{
if ($pagenb == 1)
{
- $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
+ $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
}
else
{
- $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
+ $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
}
$this->_pagefoot($pdf,$object,$outputlangs,1);
// New page
@@ -630,12 +632,12 @@ class pdf_crabe extends ModelePDFFactures
// Show square
if ($pagenb == 1)
{
- $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
+ $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
}
else
{
- $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
+ $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
$bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
}
@@ -1017,8 +1019,10 @@ class pdf_crabe extends ModelePDFFactures
$pdf->SetFillColor(255,255,255);
$pdf->SetXY($col1x, $tab2_top + 0);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
+
+ $total_ht = ($conf->multicurrency->enabled && $object->mylticurrency_tx != 1 ? $object->multicurrency_total_ht : $object->total_ht);
$pdf->SetXY($col2x, $tab2_top + 0);
- $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($object->total_ht + (! empty($object->remise)?$object->remise:0)), 0, $outputlangs), 0, 'R', 1);
+ $pdf->MultiCell($largcol2, $tab2_hl, price($sign * ($total_ht + (! empty($object->remise)?$object->remise:0)), 0, $outputlangs), 0, 'R', 1);
// Show VAT by rates and total
$pdf->SetFillColor(248,248,248);
@@ -1211,8 +1215,9 @@ class pdf_crabe extends ModelePDFFactures
$pdf->SetFillColor(224,224,224);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
+ $total_ttc = ($conf->multicurrency->enabled && $object->multiccurency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
- $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->total_ttc, 0, $outputlangs), $useborder, 'R', 1);
+ $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
}
}
@@ -1285,7 +1290,7 @@ class pdf_crabe extends ModelePDFFactures
* @param int $hidebottom Hide bottom bar of array
* @return void
*/
- function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
+ function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
{
global $conf;
@@ -1293,6 +1298,7 @@ class pdf_crabe extends ModelePDFFactures
$hidebottom=0;
if ($hidetop) $hidetop=-1;
+ $currency = !empty($currency) ? $currency : $conf->currency;
$default_font_size = pdf_getPDFFontSize($outputlangs);
// Amount in (at tab_top - 1)
@@ -1301,7 +1307,7 @@ class pdf_crabe extends ModelePDFFactures
if (empty($hidetop))
{
- $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$conf->currency));
+ $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
$pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
|
|