Skip to content

Commit 2b2cb69

Browse files
committed
FIX multicurrency compatibility with Multicompany
1 parent 7e80696 commit 2b2cb69

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

htdocs/admin/multicurrency.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@
130130
}
131131
} elseif ($action == 'setapilayer') {
132132
if (GETPOSTISSET('modify_apilayer')) {
133-
dolibarr_set_const($db, 'MULTICURRENCY_APP_ID', GETPOST('MULTICURRENCY_APP_ID', 'alpha'));
134-
dolibarr_set_const($db, 'MULTICURRENCY_APP_SOURCE', GETPOST('MULTICURRENCY_APP_SOURCE', 'alpha'));
135-
//dolibarr_set_const($db, 'MULTICURRENCY_ALTERNATE_SOURCE', GETPOST('MULTICURRENCY_ALTERNATE_SOURCE', 'alpha'));
133+
dolibarr_set_const($db, 'MULTICURRENCY_APP_ID', GETPOST('MULTICURRENCY_APP_ID', 'alpha'), 'chaine', 0, '', $conf->entity);
134+
dolibarr_set_const($db, 'MULTICURRENCY_APP_SOURCE', GETPOST('MULTICURRENCY_APP_SOURCE', 'alpha'), 'chaine', 0, '', $conf->entity);
135+
//dolibarr_set_const($db, 'MULTICURRENCY_ALTERNATE_SOURCE', GETPOST('MULTICURRENCY_ALTERNATE_SOURCE', 'alpha'), 'chaine', 0, '', $conf->entity);
136136
} else {
137137
$multiurrency = new MultiCurrency($db);
138138
$result = $multiurrency->syncRates(getDolGlobalString('MULTICURRENCY_APP_ID'));

htdocs/multicurrency/class/api_multicurrencies.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100,
6565

6666
$sql = "SELECT t.rowid";
6767
$sql .= " FROM ".$this->db->prefix()."multicurrency as t";
68-
$sql .= ' WHERE 1 = 1';
68+
$sql .= " WHERE t.entity IN (".getEntity('multicurrency').")";
6969
// Add sql filters
7070
if ($sqlfilters) {
7171
$errormessage = '';

htdocs/multicurrency/class/multicurrency.class.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,11 @@ public function fetch($id, $code = null)
192192
{
193193
dol_syslog('MultiCurrency::fetch', LOG_DEBUG);
194194

195-
global $conf;
196-
197-
$sql = "SELECT";
198-
$sql .= ' c.rowid, c.name, c.code, c.entity, c.date_create, c.fk_user';
199-
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' AS c';
195+
$sql = "SELECT c.rowid, c.name, c.code, c.entity, c.date_create, c.fk_user";
196+
$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." AS c";
200197
if (!empty($code)) {
201-
$sql .= ' WHERE c.code = \''.$this->db->escape($code).'\' AND c.entity = '.$conf->entity;
198+
$sql .= " WHERE c.code = '".$this->db->escape($code)."'";
199+
$sql .= " AND c.entity IN (".getEntity($this->element).")";
202200
} else {
203201
$sql .= ' WHERE c.rowid = '.((int) $id);
204202
}
@@ -244,9 +242,10 @@ public function fetch($id, $code = null)
244242
public function fetchAllCurrencyRate()
245243
{
246244
$sql = "SELECT cr.rowid";
247-
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as cr';
248-
$sql .= ' WHERE cr.fk_multicurrency = '.((int) $this->id);
249-
$sql .= ' ORDER BY cr.date_sync DESC';
245+
$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element_line." as cr";
246+
$sql .= " WHERE cr.entity IN (".getEntity($this->element).")";
247+
$sql .= " AND cr.fk_multicurrency = ".((int) $this->id);
248+
$sql .= " ORDER BY cr.date_sync DESC";
250249

251250
$this->rates = array();
252251

@@ -482,8 +481,10 @@ public function getRate()
482481
{
483482
$sql = "SELECT cr.rowid";
484483
$sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element_line." as cr";
485-
$sql .= " WHERE cr.fk_multicurrency = ".((int) $this->id);
486-
$sql .= " AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX.$this->table_element_line." AS cr2 WHERE cr2.fk_multicurrency = ".((int) $this->id).")";
484+
$sql .= " WHERE cr.entity IN (".getEntity($this->element).")";
485+
$sql .= " AND cr.fk_multicurrency = ".((int) $this->id);
486+
$sql .= " AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX.$this->table_element_line." AS cr2";
487+
$sql .= " WHERE cr2.entity IN (".getEntity($this->element).") AND cr2.fk_multicurrency = ".((int) $this->id).")";
487488

488489
dol_syslog(__METHOD__, LOG_DEBUG);
489490
$resql = $this->db->query($sql);

htdocs/multicurrency/multicurrency_rate.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@
354354
if ($search_code) {
355355
$sql .= natural_search('m.code', $search_code);
356356
}
357-
$sql .= " WHERE m.code <> '".$db->escape($conf->currency)."'";
357+
$sql .= " WHERE cr.entity IN (".getEntity('multicurrency').")";
358+
$sql .= " AND m.code <> '".$db->escape($conf->currency)."'";
358359

359360
// Add where from hooks
360361
$parameters = array();

0 commit comments

Comments
 (0)