Skip to content

Commit

Permalink
add log and toher multicurrency bug fix for PgSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
atm-florian committed Jun 30, 2016
1 parent 1740166 commit 542be96
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions htdocs/multicurrency/class/multicurrency.class.php
Expand Up @@ -140,6 +140,7 @@ public function create(User $user, $trigger = true)

$this->db->begin();

dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$error ++;
Expand Down Expand Up @@ -184,9 +185,10 @@ public function fetch($id, $code = null)
$sql = 'SELECT';
$sql .= ' c.rowid, c.name, c.code, c.entity, c.date_create, c.fk_user';
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' AS c';
if (!empty($code)) $sql .= ' WHERE c.code = "'.$this->db->escape($code).'"';
if (!empty($code)) $sql .= ' WHERE c.code = \''.$this->db->escape($code).'\'';
else $sql .= ' WHERE c.rowid = ' . $id;

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

if ($resql) {
Expand Down Expand Up @@ -226,15 +228,14 @@ public function fetch($id, $code = null)
*/
public function fetchAllCurrencyRate()
{
dol_syslog('Currency::fetchAllCurrencyRate', LOG_DEBUG);

$sql = 'SELECT cr.rowid';
$sql.= ' FROM ' . MAIN_DB_PREFIX . $this->table_element_line. ' as cr';
$sql.= ' WHERE cr.fk_multicurrency = '.$this->id;
$sql.= ' ORDER BY cr.date_sync DESC';

$this->rates = array();

dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
Expand Down Expand Up @@ -284,10 +285,11 @@ public function update(User $user, $trigger = true)

// Update request
$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
$sql .= ' name="'.$this->db->escape($this->name).'"';
$sql .= ' code="'.$this->db->escape($this->code).'"';
$sql .= ' name=\''.$this->db->escape($this->name).'\'';
$sql .= ' code=\''.$this->db->escape($this->code).'\'';
$sql .= ' WHERE rowid=' . $this->id;

dol_syslog(__METHOD__,LOG_DEBUG);
$this->db->begin();

$resql = $this->db->query($sql);
Expand Down Expand Up @@ -347,6 +349,7 @@ public function delete($trigger = true)
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
$sql .= ' WHERE rowid=' . $this->id;

dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$error ++;
Expand Down Expand Up @@ -425,7 +428,9 @@ function addRateFromDolibarr($code, $rate)
$currency->code = $code;
$currency->name = $code;

$sql = 'SELECT label FROM '.MAIN_DB_PREFIX.'c_currencies WHERE code_iso = "'.$db->escape($code).'"';
$sql = 'SELECT label FROM '.MAIN_DB_PREFIX.'c_currencies WHERE code_iso = \''.$db->escape($code).'\'';

dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $db->query($sql);
if ($resql && ($line = $db->fetch_object($resql)))
{
Expand Down Expand Up @@ -475,6 +480,7 @@ public function getRate()
$sql.= ' WHERE cr.fk_multicurrency = '.$this->id;
$sql.= ' AND cr.date_sync >= ALL (SELECT cr2.date_sync FROM '.MAIN_DB_PREFIX.$this->table_element_line.' AS cr2 WHERE cr.rowid = cr2.rowid)';

dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql && ($obj = $this->db->fetch_object($resql))) {
$this->rate = new CurrencyRate($this->db);
Expand All @@ -494,6 +500,8 @@ public function getRate()
public static function getIdFromCode(&$db, $code)
{
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'multicurrency WHERE code = \''.$db->escape($code).'\'';

dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $db->query($sql);
if ($resql && $obj = $db->fetch_object($resql)) return $obj->rowid;
else return 0;
Expand All @@ -512,10 +520,11 @@ public static function getIdAndTxFromCode(&$db, $code)
{
$sql = 'SELECT m.rowid, mc.rate FROM '.MAIN_DB_PREFIX.'multicurrency m';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'multicurrency_rate mc ON (m.rowid = mc.fk_multicurrency)';
$sql.= ' WHERE m.code = "'.$db->escape($code).'"';
$sql.= ' WHERE m.code = \''.$db->escape($code).'\'';
$sql.= " AND m.entity IN (".getEntity('multicurrency', 1).")";
$sql.= ' ORDER BY mc.date_sync DESC LIMIT 1';

dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $db->query($sql);
if ($resql && $obj = $db->fetch_object($resql)) return array($obj->rowid, $obj->rate);
else return array(0, 1);
Expand Down Expand Up @@ -556,6 +565,8 @@ public static function getInvoiceRate($fk_facture, $table='facture')
global $db;

$sql = 'SELECT multicurrency_tx FROM '.MAIN_DB_PREFIX.$table.' WHERE rowid = '.$fk_facture;

dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $db->query($sql);
if ($resql && ($line = $db->fetch_object($resql)))
{
Expand Down Expand Up @@ -721,6 +732,7 @@ public function create($fk_multicurrency, $trigger = true)

$this->db->begin();

dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$error ++;
Expand Down Expand Up @@ -765,6 +777,7 @@ public function fetch($id)
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' AS cr';
$sql .= ' WHERE cr.rowid = ' . $id;

dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$numrows = $this->db->num_rows($resql);
Expand Down Expand Up @@ -816,6 +829,7 @@ public function update($trigger = true)

$this->db->begin();

dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$error ++;
Expand Down Expand Up @@ -866,6 +880,7 @@ public function delete($trigger = true)
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
$sql .= ' WHERE rowid='.$this->id;

dol_syslog(__METHOD__,LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$error ++;
Expand Down

0 comments on commit 542be96

Please sign in to comment.