dolibarr  13.0.2
multicurrency.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2020 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
4  * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
5  * Copyright (C) 2015 RaphaĆ«l Doursenaud <rdoursenaud@gpcsolutions.fr>
6  * Copyright (C) 2016 Pierre-Henry Favre <phf@atm-consulting.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 // Put here all includes required by your class file
29 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
31 
32 
40 {
44  public $element = 'multicurrency';
45 
49  public $table_element = 'multicurrency';
50 
54  public $table_element_line = "multicurrency_rate";
55 
59  public $rates = array();
60 
64  public $id;
65 
69  public $code;
70 
74  public $name;
75 
79  public $entity;
80 
84  public $date_create;
85 
89  public $fk_user;
90 
94  public $rate;
95 
96 
102  public function __construct(DoliDB $db)
103  {
104  $this->db = $db;
105 
106  return 1;
107  }
108 
116  public function create(User $user, $trigger = true)
117  {
118  global $conf, $langs;
119 
120  dol_syslog('MultiCurrency::create', LOG_DEBUG);
121 
122  $error = 0;
123 
124  if (self::checkCodeAlreadyExists($this->code))
125  {
126  $error++;
127  $this->errors[] = $langs->trans('multicurrency_code_already_added');
128  return -1;
129  }
130 
131  if (empty($this->entity) || $this->entity <= 0) $this->entity = $conf->entity;
132  $now = date('Y-m-d H:i:s');
133 
134  // Insert request
135  $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'(';
136  $sql .= ' code,';
137  $sql .= ' name,';
138  $sql .= ' entity,';
139  $sql .= ' date_create,';
140  $sql .= ' fk_user';
141  $sql .= ') VALUES (';
142  $sql .= ' \''.$this->db->escape($this->code).'\',';
143  $sql .= ' \''.$this->db->escape($this->name).'\',';
144  $sql .= ' \''.$this->entity.'\',';
145  $sql .= ' \''.$now.'\',';
146  $sql .= ' \''.$user->id.'\'';
147  $sql .= ')';
148 
149  $this->db->begin();
150 
151  dol_syslog(__METHOD__, LOG_DEBUG);
152  $resql = $this->db->query($sql);
153  if (!$resql) {
154  $error++;
155  $this->errors[] = 'Error '.$this->db->lasterror();
156  dol_syslog('MultiCurrency::create '.join(',', $this->errors), LOG_ERR);
157  }
158 
159  if (!$error) {
160  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
161  $this->date_create = $now;
162  $this->fk_user = $user->id;
163 
164  if ($trigger) {
165  $result = $this->call_trigger('CURRENCY_CREATE', $user);
166  if ($result < 0) $error++;
167  }
168  }
169 
170  if ($error) {
171  $this->db->rollback();
172 
173  return -1 * $error;
174  } else {
175  $this->db->commit();
176 
177  return $this->id;
178  }
179  }
180 
188  public function fetch($id, $code = null)
189  {
190  dol_syslog('MultiCurrency::fetch', LOG_DEBUG);
191 
192  global $conf;
193 
194  $sql = 'SELECT';
195  $sql .= ' 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';
197  if (!empty($code)) $sql .= ' WHERE c.code = \''.$this->db->escape($code).'\' AND c.entity = '.$conf->entity;
198  else $sql .= ' WHERE c.rowid = '.$id;
199 
200  dol_syslog(__METHOD__, LOG_DEBUG);
201  $resql = $this->db->query($sql);
202 
203  if ($resql) {
204  $numrows = $this->db->num_rows($resql);
205  if ($numrows) {
206  $obj = $this->db->fetch_object($resql);
207 
208  $this->id = $obj->rowid;
209  $this->name = $obj->name;
210  $this->code = $obj->code;
211  $this->entity = $obj->entity;
212  $this->date_create = $obj->date_create;
213  $this->fk_user = $obj->fk_user;
214 
215  $this->fetchAllCurrencyRate();
216  $this->getRate();
217  }
218  $this->db->free($resql);
219 
220  if ($numrows) {
221  return 1;
222  } else {
223  return 0;
224  }
225  } else {
226  $this->errors[] = 'Error '.$this->db->lasterror();
227  dol_syslog('MultiCurrency::fetch '.join(',', $this->errors), LOG_ERR);
228 
229  return -1;
230  }
231  }
232 
238  public function fetchAllCurrencyRate()
239  {
240  $sql = 'SELECT cr.rowid';
241  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as cr';
242  $sql .= ' WHERE cr.fk_multicurrency = '.$this->id;
243  $sql .= ' ORDER BY cr.date_sync DESC';
244 
245  $this->rates = array();
246 
247  dol_syslog(__METHOD__, LOG_DEBUG);
248  $resql = $this->db->query($sql);
249  if ($resql) {
250  $num = $this->db->num_rows($resql);
251 
252  while ($obj = $this->db->fetch_object($resql)) {
253  $rate = new CurrencyRate($this->db);
254  $rate->fetch($obj->rowid);
255 
256  $this->rates[] = $rate;
257  }
258  $this->db->free($resql);
259 
260  return $num;
261  } else {
262  $this->errors[] = 'Error '.$this->db->lasterror();
263  dol_syslog('MultiCurrency::fetchAllCurrencyRate '.join(',', $this->errors), LOG_ERR);
264 
265  return -1;
266  }
267  }
268 
276  public function update(User $user, $trigger = true)
277  {
278  $error = 0;
279 
280  dol_syslog('MultiCurrency::update', LOG_DEBUG);
281 
282  // Clean parameters
283  $this->name = trim($this->name);
284  $this->code = trim($this->code);
285 
286  // Check parameters
287  if (empty($this->code)) {
288  $error++;
289  dol_syslog('MultiCurrency::update $this->code can not be empty', LOG_ERR);
290 
291  return -1;
292  }
293 
294  // Update request
295  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET';
296  $sql .= ' name=\''.$this->db->escape($this->name).'\'';
297  $sql .= ' code=\''.$this->db->escape($this->code).'\'';
298  $sql .= ' WHERE rowid='.$this->id;
299 
300  $this->db->begin();
301 
302  $resql = $this->db->query($sql);
303  if (!$resql) {
304  $error++;
305  $this->errors[] = 'Error '.$this->db->lasterror();
306  dol_syslog('MultiCurrency::update '.join(',', $this->errors), LOG_ERR);
307  }
308 
309  if (!$error && $trigger) {
310  $result = $this->call_trigger('CURRENCY_MODIFY', $user);
311  if ($result < 0) $error++;
312  }
313 
314  // Commit or rollback
315  if ($error) {
316  $this->db->rollback();
317 
318  return -1 * $error;
319  } else {
320  $this->db->commit();
321 
322  return 1;
323  }
324  }
325 
332  public function delete($trigger = true)
333  {
334  global $user;
335 
336  dol_syslog('MultiCurrency::delete', LOG_DEBUG);
337 
338  $error = 0;
339 
340  $this->db->begin();
341 
342  if ($trigger) {
343  $result = $this->call_trigger('CURRENCY_DELETE', $user);
344  if ($result < 0) $error++;
345  }
346 
347  if (!$error) {
348  // Delete all rates before
349  if (!$this->deleteRates()) {
350  $error++;
351  $this->errors[] = 'Error '.$this->db->lasterror();
352  dol_syslog('Currency::delete '.join(',', $this->errors), LOG_ERR);
353  }
354 
355  $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
356  $sql .= ' WHERE rowid='.$this->id;
357 
358  dol_syslog(__METHOD__, LOG_DEBUG);
359  $resql = $this->db->query($sql);
360  if (!$resql) {
361  $error++;
362  $this->errors[] = 'Error '.$this->db->lasterror();
363  dol_syslog('MultiCurrency::delete '.join(',', $this->errors), LOG_ERR);
364  }
365  }
366 
367  // Commit or rollback
368  if ($error) {
369  $this->db->rollback();
370 
371  return -1 * $error;
372  } else {
373  $this->db->commit();
374 
375  return 1;
376  }
377  }
378 
384  public function deleteRates()
385  {
386  foreach ($this->rates as &$rate)
387  {
388  if ($rate->delete() <= 0)
389  {
390  return false;
391  }
392  }
393 
394  return true;
395  }
396 
403  public function addRate($rate)
404  {
405  $currencyRate = new CurrencyRate($this->db);
406  $currencyRate->rate = price2num($rate);
407 
408  if ($currencyRate->create($this->id) > 0)
409  {
410  $this->rate = $currencyRate;
411  return 1;
412  } else {
413  $this->rate = null;
414  $this->errors = $currencyRate->errors;
415  return -1;
416  }
417  }
418 
426  public function addRateFromDolibarr($code, $rate)
427  {
428  global $db, $user;
429 
430  $currency = new MultiCurrency($this->db);
431  $currency->code = $code;
432  $currency->name = $code;
433 
434  $sql = 'SELECT label FROM '.MAIN_DB_PREFIX."c_currencies WHERE code_iso = '".$this->db->escape($code)."'";
435 
436  dol_syslog(__METHOD__, LOG_DEBUG);
437  $resql = $db->query($sql);
438  if ($resql && ($line = $db->fetch_object($resql)))
439  {
440  $currency->name = $line->label;
441  }
442 
443  if ($currency->create($user) > 0)
444  {
445  $currency->addRate($rate);
446 
447  if (!empty($line)) return 2;
448  else return 1;
449  }
450 
451  return -1;
452  }
453 
460  public function updateRate($rate)
461  {
462  return $this->addRate($rate);
463  }
464 
470  public function getRate()
471  {
472  $sql = 'SELECT cr.rowid';
473  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as cr';
474  $sql .= ' WHERE cr.fk_multicurrency = '.$this->id;
475  $sql .= ' AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM '.MAIN_DB_PREFIX.$this->table_element_line.' AS cr2 WHERE cr2.fk_multicurrency = '.$this->id.')';
476 
477  dol_syslog(__METHOD__, LOG_DEBUG);
478  $resql = $this->db->query($sql);
479  if ($resql && ($obj = $this->db->fetch_object($resql))) {
480  $this->rate = new CurrencyRate($this->db);
481  return $this->rate->fetch($obj->rowid);
482  }
483  }
484 
493  public static function getIdFromCode($db, $code)
494  {
495  global $conf;
496 
497  $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX."multicurrency WHERE code = '".$db->escape($code)."' AND entity = ".$conf->entity;
498 
499  dol_syslog(__METHOD__, LOG_DEBUG);
500  $resql = $db->query($sql);
501  if ($resql && $obj = $db->fetch_object($resql)) return $obj->rowid;
502  else return 0;
503  }
504 
515  public static function getIdAndTxFromCode($db, $code, $date_document = '')
516  {
517  global $conf;
518 
519  $sql1 = 'SELECT m.rowid, mc.rate FROM '.MAIN_DB_PREFIX.'multicurrency m';
520 
521  $sql1 .= ' LEFT JOIN '.MAIN_DB_PREFIX.'multicurrency_rate mc ON (m.rowid = mc.fk_multicurrency)';
522  $sql1 .= " WHERE m.code = '".$db->escape($code)."'";
523  $sql1 .= " AND m.entity IN (".getEntity('multicurrency').")";
524  $sql2 = '';
525  if (!empty($conf->global->MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE) && !empty($date_document)) { // Use last known rate compared to document date
526  $tmparray = dol_getdate($date_document);
527  $sql2 .= " AND mc.date_sync <= '".$db->idate(dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year'], true))."'";
528  }
529  $sql3 = ' ORDER BY mc.date_sync DESC LIMIT 1';
530 
531  dol_syslog(__METHOD__, LOG_DEBUG);
532  $resql = $db->query($sql1.$sql2.$sql3);
533 
534  if ($resql && $obj = $db->fetch_object($resql)) return array($obj->rowid, $obj->rate);
535  else {
536  if (!empty($conf->global->MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE))
537  {
538  $resql = $db->query($sql1.$sql3);
539  if ($resql && $obj = $db->fetch_object($resql)) return array($obj->rowid, $obj->rate);
540  }
541 
542  return array(0, 1);
543  }
544  }
545 
555  public static function getAmountConversionFromInvoiceRate($fk_facture, $amount, $way = 'dolibarr', $table = 'facture')
556  {
557  $multicurrency_tx = self::getInvoiceRate($fk_facture, $table);
558 
559  if ($multicurrency_tx)
560  {
561  if ($way == 'dolibarr') return price2num($amount * $multicurrency_tx, 'MU');
562  else return price2num($amount / $multicurrency_tx, 'MU');
563  } else return $amount;
564  }
565 
573  public static function getInvoiceRate($fk_facture, $table = 'facture')
574  {
575  global $db;
576 
577  $sql = 'SELECT multicurrency_tx FROM '.MAIN_DB_PREFIX.$table.' WHERE rowid = '.$fk_facture;
578 
579  dol_syslog(__METHOD__, LOG_DEBUG);
580  $resql = $db->query($sql);
581  if ($resql && ($line = $db->fetch_object($resql)))
582  {
583  return $line->multicurrency_tx;
584  }
585 
586  return false;
587  }
588 
596  public static function recalculRates(&$TRate)
597  {
598  global $conf;
599 
600  if ($conf->currency != $conf->global->MULTICURRENCY_APP_SOURCE)
601  {
602  $alternate_source = 'USD'.$conf->currency;
603  if (!empty($TRate->{$alternate_source}))
604  {
605  $coef = $TRate->USDUSD / $TRate->{$alternate_source};
606  foreach ($TRate as $attr => &$rate)
607  {
608  $rate *= $coef;
609  }
610 
611  return 1;
612  }
613 
614  return -1; // Alternate souce not found
615  }
616 
617  return 0; // Nothing to do
618  }
619 
627  public static function syncRates($key, $addifnotfound = 0)
628  {
629  global $conf, $db, $langs;
630 
631  include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
632 
633  $urlendpoint = 'http://apilayer.net/api/live?access_key='.$key;
634  //$urlendpoint.='&format=1';
635  $urlendpoint .= (empty($conf->global->MULTICURRENCY_APP_SOURCE) ? '' : '&source='.$conf->global->MULTICURRENCY_APP_SOURCE);
636 
637  dol_syslog("Call url endpoint ".$urlendpoint);
638 
639  $resget = getURLContent($urlendpoint, 'GET', '', 1, array(), array('http', 'https'), 1);
640 
641  if ($resget['content']) {
642  $response = $resget['content'];
643  $response = json_decode($response);
644 
645  if ($response->success)
646  {
647  $TRate = $response->quotes;
648  $timestamp = $response->timestamp;
649 
650  if (self::recalculRates($TRate) >= 0)
651  {
652  foreach ($TRate as $currency_code => $rate)
653  {
654  $code = substr($currency_code, 3, 3);
655  $obj = new MultiCurrency($db);
656  if ($obj->fetch(null, $code) > 0)
657  {
658  $obj->updateRate($rate);
659  } elseif ($addifnotfound)
660  {
661  self::addRateFromDolibarr($code, $rate);
662  }
663  }
664  }
665 
666  return 1;
667  } else {
668  dol_syslog("Failed to call endpoint ".$response->error->info, LOG_WARNING);
669  setEventMessages($langs->trans('multicurrency_syncronize_error', $response->error->info), null, 'errors');
670 
671  return -1;
672  }
673  }
674  }
675 
682  public static function checkCodeAlreadyExists($code)
683  {
684  global $db;
685 
686  $currency = new MultiCurrency($db);
687  if ($currency->fetch('', $code) > 0) return true;
688  else return false;
689  }
690 }
691 
692 
697 {
701  public $element = 'multicurrency_rate';
702 
706  public $table_element = 'multicurrency_rate';
707 
711  public $id;
712 
716  public $rate;
717 
721  public $date_sync;
722 
726  public $fk_multicurrency;
727 
731  public $entity;
732 
733 
739  public function __construct(DoliDB $db)
740  {
741  $this->db = &$db;
742 
743  return 1;
744  }
745 
753  public function create($fk_multicurrency, $trigger = true)
754  {
755  global $conf, $user;
756 
757  dol_syslog('CurrencyRate::create', LOG_DEBUG);
758 
759  $error = 0;
760  $this->rate = price2num($this->rate);
761  if (empty($this->entity) || $this->entity <= 0) $this->entity = $conf->entity;
762  $now = empty($this->date_sync) ? dol_now() : $this->date_sync;
763 
764  // Insert request
765  $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'(';
766  $sql .= ' rate,';
767  $sql .= ' date_sync,';
768  $sql .= ' fk_multicurrency,';
769  $sql .= ' entity';
770  $sql .= ') VALUES (';
771  $sql .= ' '.$this->rate.',';
772  $sql .= " '".$this->db->idate($now)."',";
773  $sql .= " ".((int) $fk_multicurrency).",";
774  $sql .= " ".((int) $this->entity);
775  $sql .= ')';
776 
777  $this->db->begin();
778 
779  dol_syslog(__METHOD__, LOG_DEBUG);
780  $resql = $this->db->query($sql);
781  if (!$resql) {
782  $error++;
783  $this->errors[] = 'Error '.$this->db->lasterror();
784  dol_syslog('CurrencyRate::create '.join(',', $this->errors), LOG_ERR);
785  }
786 
787  if (!$error) {
788  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
789  $this->fk_multicurrency = $fk_multicurrency;
790  $this->date_sync = $now;
791 
792  if ($trigger) {
793  $result = $this->call_trigger('CURRENCYRATE_CREATE', $user);
794  if ($result < 0) $error++;
795  }
796  }
797 
798  if ($error) {
799  $this->db->rollback();
800 
801  return -1 * $error;
802  } else {
803  $this->db->commit();
804 
805  return $this->id;
806  }
807  }
808 
815  public function fetch($id)
816  {
817  dol_syslog('CurrencyRate::fetch', LOG_DEBUG);
818 
819  $sql = 'SELECT cr.rowid, cr.rate, cr.date_sync, cr.fk_multicurrency, cr.entity';
820  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' AS cr';
821  $sql .= ' WHERE cr.rowid = '.$id;
822 
823  dol_syslog(__METHOD__, LOG_DEBUG);
824  $resql = $this->db->query($sql);
825  if ($resql) {
826  $numrows = $this->db->num_rows($resql);
827  if ($numrows) {
828  $obj = $this->db->fetch_object($resql);
829 
830  $this->id = $obj->rowid;
831  $this->rate = $obj->rate;
832  $this->date_sync = $this->db->jdate($obj->date_sync);
833  $this->fk_multicurrency = $obj->fk_multicurrency;
834  $this->entity = $obj->entity;
835  }
836  $this->db->free($resql);
837 
838  if ($numrows) {
839  return 1;
840  } else {
841  return 0;
842  }
843  } else {
844  $this->errors[] = 'Error '.$this->db->lasterror();
845  dol_syslog('CurrencyRate::fetch '.join(',', $this->errors), LOG_ERR);
846 
847  return -1;
848  }
849  }
850 
857  public function update($trigger = true)
858  {
859  global $user;
860 
861  $error = 0;
862 
863  dol_syslog('CurrencyRate::update', LOG_DEBUG);
864 
865  $this->rate = price2num($this->rate);
866 
867  // Update request
868  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET';
869  $sql .= ' rate='.$this->rate;
870  if (!empty($this->date_sync)) $sql .= ", date_sync='".$this->db->idate($this->date_sync)."'";
871  if (!empty($this->fk_multicurrency)) $sql .= ', fk_multicurrency='.$this->fk_multicurrency;
872  $sql .= ' WHERE rowid='.$this->id;
873 
874  $this->db->begin();
875 
876  dol_syslog(__METHOD__, LOG_DEBUG);
877  $resql = $this->db->query($sql);
878  if (!$resql) {
879  $error++;
880  $this->errors[] = 'Error '.$this->db->lasterror();
881  dol_syslog('CurrencyRate::update '.join(',', $this->errors), LOG_ERR);
882  }
883 
884  if (!$error && $trigger) {
885  $result = $this->call_trigger('CURRENCYRATE_MODIFY', $user);
886  if ($result < 0) $error++;
887  }
888 
889  // Commit or rollback
890  if ($error) {
891  $this->db->rollback();
892 
893  return -1 * $error;
894  } else {
895  $this->db->commit();
896 
897  return 1;
898  }
899  }
900 
907  public function delete($trigger = true)
908  {
909  global $user;
910 
911  dol_syslog('CurrencyRate::delete', LOG_DEBUG);
912 
913  $error = 0;
914 
915  $this->db->begin();
916 
917  if ($trigger) {
918  $result = $this->call_trigger('CURRENCYRATE_DELETE', $user);
919  if ($result < 0) $error++;
920  }
921 
922  if (!$error) {
923  $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
924  $sql .= ' WHERE rowid='.$this->id;
925 
926  dol_syslog(__METHOD__, LOG_DEBUG);
927  $resql = $this->db->query($sql);
928  if (!$resql) {
929  $error++;
930  $this->errors[] = 'Error '.$this->db->lasterror();
931  dol_syslog('CurrencyRate::delete '.join(',', $this->errors), LOG_ERR);
932  }
933  }
934 
935  // Commit or rollback
936  if ($error) {
937  $this->db->rollback();
938 
939  return -1 * $error;
940  } else {
941  $this->db->commit();
942 
943  return 1;
944  }
945  }
946 }
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
if(!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'] country if(!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'] typent code
Definition: list.php:566
getRate()
Fetch CurrencyRate object in $this-&gt;rate.
static getIdAndTxFromCode($db, $code, $date_document= '')
Get id and rate of currency from code.
__construct(DoliDB $db)
Constructor.
fetchAllCurrencyRate()
Load all rates in object from the database.
dol_now($mode= 'auto')
Return date for now.
static recalculRates(&$TRate)
With free account we can&#39;t set source then recalcul all rates to force another source.
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to manage Dolibarr database access.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
getURLContent($url, $postorget= 'GET', $param= '', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0)
Function to get a content from an URL (use proxy if proxy defined).
Definition: geturl.lib.php:38
$conf db
API class for accounts.
Definition: inc.php:54
Class CurrencyRate.
static checkCodeAlreadyExists($code)
Check in database if the current code already exists.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
create(User $user, $trigger=true)
Create object into database.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
static syncRates($key, $addifnotfound=0)
Sync rates from API.
create($fk_multicurrency, $trigger=true)
Create object into database.
updateRate($rate)
Add new entry into llx_multicurrency_rate.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
static getIdFromCode($db, $code)
Get id of currency from code.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
update($trigger=true)
Update object into database.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
static getAmountConversionFromInvoiceRate($fk_facture, $amount, $way= 'dolibarr', $table= 'facture')
Get the conversion of amount with invoice rate.
deleteRates()
Delete rates in database.
fetch($id, $code=null)
Load object in memory from the database.
update(User $user, $trigger=true)
Update object into database.
addRateFromDolibarr($code, $rate)
Try get label of code in llx_currency then add rate.
call_trigger($triggerName, $user)
Call trigger based on this instance.
addRate($rate)
Add a Rate into database.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
Class Currency.
fetch($id)
Load object in memory from the database.
__construct(DoliDB $db)
Constructor.
static getInvoiceRate($fk_facture, $table= 'facture')
Get current invoite rate.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)