dolibarr 20.0.0
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Put here all includes required by your class file
31require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
33
34
42{
46 public $element = 'multicurrency';
47
51 public $table_element = 'multicurrency';
52
56 public $table_element_line = "multicurrency_rate";
57
61 public $rates = array();
62
66 public $id;
67
71 public $code;
72
76 public $name;
77
81 public $entity;
82
86 public $date_create;
87
91 public $fk_user;
92
96 public $rate;
97
98
104 public function __construct(DoliDB $db)
105 {
106 $this->db = $db;
107 }
108
116 public function create(User $user, $notrigger = 0)
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 $error++;
126 $this->errors[] = $langs->trans('multicurrency_code_already_added');
127 return -1;
128 }
129
130 if (empty($this->entity) || $this->entity <= 0) {
131 $this->entity = $conf->entity;
132 }
133 $now = dol_now();
134
135 // Insert request
136 $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."(";
137 $sql .= ' code,';
138 $sql .= ' name,';
139 $sql .= ' entity,';
140 $sql .= ' date_create,';
141 $sql .= ' fk_user';
142 $sql .= ') VALUES (';
143 $sql .= " '".$this->db->escape($this->code)."',";
144 $sql .= " '".$this->db->escape($this->name)."',";
145 $sql .= " ".((int) $this->entity).",";
146 $sql .= " '".$this->db->idate($now)."',";
147 $sql .= " ".((int) $user->id);
148 $sql .= ')';
149
150 $this->db->begin();
151
152 dol_syslog(__METHOD__, LOG_DEBUG);
153 $resql = $this->db->query($sql);
154 if (!$resql) {
155 $error++;
156 $this->errors[] = 'Error '.$this->db->lasterror();
157 dol_syslog('MultiCurrency::create '.implode(',', $this->errors), LOG_ERR);
158 }
159
160 if (!$error) {
161 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
162 $this->date_create = $now;
163 $this->fk_user = $user->id;
164
165 if (empty($notrigger)) {
166 $result = $this->call_trigger('CURRENCY_CREATE', $user);
167 if ($result < 0) {
168 $error++;
169 }
170 }
171 }
172
173 if ($error) {
174 $this->db->rollback();
175
176 return -1 * $error;
177 } else {
178 $this->db->commit();
179
180 return $this->id;
181 }
182 }
183
191 public function fetch($id, $code = null)
192 {
193 dol_syslog('MultiCurrency::fetch', LOG_DEBUG);
194
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';
200 if (!empty($code)) {
201 $sql .= ' WHERE c.code = \''.$this->db->escape($code).'\' AND c.entity = '.$conf->entity;
202 } else {
203 $sql .= ' WHERE c.rowid = '.((int) $id);
204 }
205
206 dol_syslog(__METHOD__, LOG_DEBUG);
207 $resql = $this->db->query($sql);
208
209 if ($resql) {
210 $numrows = $this->db->num_rows($resql);
211 if ($numrows) {
212 $obj = $this->db->fetch_object($resql);
213
214 $this->id = $obj->rowid;
215 $this->name = $obj->name;
216 $this->code = $obj->code;
217 $this->entity = $obj->entity;
218 $this->date_create = $obj->date_create;
219 $this->fk_user = $obj->fk_user;
220
221 $this->fetchAllCurrencyRate();
222 $this->getRate();
223 }
224 $this->db->free($resql);
225
226 if ($numrows) {
227 return 1;
228 } else {
229 return 0;
230 }
231 } else {
232 $this->errors[] = 'Error '.$this->db->lasterror();
233 dol_syslog('MultiCurrency::fetch '.implode(',', $this->errors), LOG_ERR);
234
235 return -1;
236 }
237 }
238
244 public function fetchAllCurrencyRate()
245 {
246 $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';
250
251 $this->rates = array();
252
253 dol_syslog(__METHOD__, LOG_DEBUG);
254 $resql = $this->db->query($sql);
255 if ($resql) {
256 $num = $this->db->num_rows($resql);
257
258 while ($obj = $this->db->fetch_object($resql)) {
259 $rate = new CurrencyRate($this->db);
260 $rate->fetch($obj->rowid);
261
262 $this->rates[] = $rate;
263 }
264 $this->db->free($resql);
265
266 return $num;
267 } else {
268 $this->errors[] = 'Error '.$this->db->lasterror();
269 dol_syslog('MultiCurrency::fetchAllCurrencyRate '.implode(',', $this->errors), LOG_ERR);
270
271 return -1;
272 }
273 }
274
282 public function update(User $user, $notrigger = 0)
283 {
284 $error = 0;
285
286 dol_syslog('MultiCurrency::update', LOG_DEBUG);
287
288 // Clean parameters
289 $this->name = trim($this->name);
290 $this->code = trim($this->code);
291
292 // Check parameters
293 if (empty($this->code)) {
294 $error++;
295 dol_syslog('MultiCurrency::update $this->code can not be empty', LOG_ERR);
296
297 return -1;
298 }
299
300 // Update request
301 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
302 $sql .= " name = '".$this->db->escape($this->name)."',";
303 $sql .= " code = '".$this->db->escape($this->code)."'";
304 $sql .= " WHERE rowid = ".((int) $this->id);
305
306 $this->db->begin();
307
308 $resql = $this->db->query($sql);
309 if (!$resql) {
310 $error++;
311 $this->errors[] = 'Error '.$this->db->lasterror();
312 dol_syslog('MultiCurrency::update '.implode(',', $this->errors), LOG_ERR);
313 }
314
315 if (!$error && empty($notrigger)) {
316 $result = $this->call_trigger('CURRENCY_MODIFY', $user);
317 if ($result < 0) {
318 $error++;
319 }
320 }
321
322 // Commit or rollback
323 if ($error) {
324 $this->db->rollback();
325
326 return -1 * $error;
327 } else {
328 $this->db->commit();
329
330 return 1;
331 }
332 }
333
341 public function delete(User $user, $notrigger = 0)
342 {
343 dol_syslog('MultiCurrency::delete', LOG_DEBUG);
344
345 $error = 0;
346
347 $this->db->begin();
348
349 if (empty($notrigger)) {
350 $result = $this->call_trigger('CURRENCY_DELETE', $user);
351 if ($result < 0) {
352 $error++;
353 }
354 }
355
356 if (!$error) {
357 // Delete all rates before
358 if (!$this->deleteRates()) {
359 $error++;
360 $this->errors[] = 'Error '.$this->db->lasterror();
361 dol_syslog('Currency::delete '.implode(',', $this->errors), LOG_ERR);
362 }
363
364 $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
365 $sql .= " WHERE rowid = ".((int) $this->id);
366
367 dol_syslog(__METHOD__, LOG_DEBUG);
368 $resql = $this->db->query($sql);
369 if (!$resql) {
370 $error++;
371 $this->errors[] = 'Error '.$this->db->lasterror();
372 dol_syslog('MultiCurrency::delete '.implode(',', $this->errors), LOG_ERR);
373 }
374 }
375
376 // Commit or rollback
377 if ($error) {
378 $this->db->rollback();
379
380 return -1 * $error;
381 } else {
382 $this->db->commit();
383
384 return 1;
385 }
386 }
387
393 public function deleteRates()
394 {
395 global $user;
396
397 foreach ($this->rates as &$rate) {
398 if ($rate->delete($user) <= 0) {
399 return false;
400 }
401 }
402
403 return true;
404 }
405
412 public function addRate($rate)
413 {
414 global $user;
415
416 $currencyRate = new CurrencyRate($this->db);
417 $currencyRate->rate = (float) price2num($rate);
418
419 if ($currencyRate->create($user, $this->id) > 0) {
420 $this->rate = $currencyRate;
421 return 1;
422 } else {
423 $this->rate = null;
424 $this->errors = $currencyRate->errors;
425 return -1;
426 }
427 }
428
436 public function addRateFromDolibarr($code, $rate)
437 {
438 global $user;
439
440 $currency = new MultiCurrency($this->db);
441 $currency->code = $code;
442 $currency->name = $code;
443
444 $sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies WHERE code_iso = '".$this->db->escape($code)."'";
445
446 dol_syslog(__METHOD__, LOG_DEBUG);
447 $resql = $this->db->query($sql);
448 if ($resql && ($line = $this->db->fetch_object($resql))) {
449 $currency->name = $line->label;
450 }
451
452 if ($currency->create($user) > 0) {
453 $currency->addRate($rate);
454
455 if (!empty($line)) {
456 return 2;
457 } else {
458 return 1;
459 }
460 }
461
462 return -1;
463 }
464
471 public function updateRate($rate)
472 {
473 return $this->addRate($rate);
474 }
475
481 public function getRate()
482 {
483 $sql = "SELECT cr.rowid";
484 $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).")";
487
488 dol_syslog(__METHOD__, LOG_DEBUG);
489 $resql = $this->db->query($sql);
490 if ($resql && ($obj = $this->db->fetch_object($resql))) {
491 $this->rate = new CurrencyRate($this->db);
492 return $this->rate->fetch($obj->rowid);
493 }
494
495 return -1;
496 }
497
506 public static function getIdFromCode($dbs, $code)
507 {
508 global $conf;
509
510 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."multicurrency WHERE code = '".$dbs->escape($code)."' AND entity = ".((int) $conf->entity);
511
512 dol_syslog(__METHOD__, LOG_DEBUG);
513 $resql = $dbs->query($sql);
514 if ($resql && $obj = $dbs->fetch_object($resql)) {
515 return $obj->rowid;
516 } else {
517 return 0;
518 }
519 }
520
531 public static function getIdAndTxFromCode($dbs, $code, $date_document = '')
532 {
533 global $conf;
534
535 $sql1 = "SELECT m.rowid, mc.rate FROM ".MAIN_DB_PREFIX."multicurrency m";
536
537 $sql1 .= ' LEFT JOIN '.MAIN_DB_PREFIX.'multicurrency_rate mc ON (m.rowid = mc.fk_multicurrency)';
538 $sql1 .= " WHERE m.code = '".$dbs->escape($code)."'";
539 $sql1 .= " AND m.entity IN (".getEntity('multicurrency').")";
540 $sql2 = '';
541 if (getDolGlobalString('MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE') && !empty($date_document)) { // Use last known rate compared to document date
542 $tmparray = dol_getdate($date_document);
543 $sql2 .= " AND mc.date_sync <= '".$dbs->idate(dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year'], true))."'";
544 }
545 $sql3 = " ORDER BY mc.date_sync DESC LIMIT 1";
546
547 dol_syslog(__METHOD__, LOG_DEBUG);
548 $resql = $dbs->query($sql1.$sql2.$sql3);
549
550 if ($resql && $obj = $dbs->fetch_object($resql)) {
551 return array($obj->rowid, $obj->rate);
552 } else {
553 if (getDolGlobalString('MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE')) {
554 $resql = $dbs->query($sql1.$sql3);
555 if ($resql && $obj = $dbs->fetch_object($resql)) {
556 return array($obj->rowid, $obj->rate);
557 }
558 }
559
560 return array(0, 1);
561 }
562 }
563
574 public static function getAmountConversionFromInvoiceRate($fk_facture, $amount, $way = 'dolibarr', $table = 'facture', $invoice_rate = null)
575 {
576 if (!is_null($invoice_rate)) {
577 $multicurrency_tx = $invoice_rate;
578 } else {
579 $multicurrency_tx = self::getInvoiceRate($fk_facture, $table);
580 }
581
582 if ($multicurrency_tx) {
583 if ($way == 'dolibarr') {
584 return (float) price2num($amount * $multicurrency_tx, 'MU');
585 } else {
586 return (float) price2num($amount / $multicurrency_tx, 'MU');
587 }
588 } else {
589 return false;
590 }
591 }
592
600 public static function getInvoiceRate($fk_facture, $table = 'facture')
601 {
602 global $db;
603
604 $sql = "SELECT multicurrency_tx FROM ".MAIN_DB_PREFIX.$table." WHERE rowid = ".((int) $fk_facture);
605
606 dol_syslog(__METHOD__, LOG_DEBUG);
607 $resql = $db->query($sql);
608 if ($resql && ($line = $db->fetch_object($resql))) {
609 return $line->multicurrency_tx;
610 }
611
612 return false;
613 }
614
622 public function recalculRates(&$TRate)
623 {
624 global $conf;
625
626 if ($conf->currency != getDolGlobalString('MULTICURRENCY_APP_SOURCE')) {
627 $alternate_source = 'USD'.$conf->currency;
628 if (!empty($TRate->$alternate_source)) {
629 $coef = 1 / $TRate->$alternate_source;
630 foreach ($TRate as $attr => &$rate) {
631 $rate *= $coef;
632 }
633 $TRate->USDUSD = $coef;
634 return 1;
635 }
636
637 return -1; // Alternate source not found
638 }
639
640 return 0; // Nothing to do
641 }
642
651 public function syncRates($key, $addifnotfound = 0, $mode = "")
652 {
653 global $conf, $db, $langs;
654
655 if (getDolGlobalString('MULTICURRENCY_DISABLE_SYNC_CURRENCYLAYER')) {
656 if ($mode == "cron") {
657 $this->output = $langs->trans('Use of API for currency update is disabled by option MULTICURRENCY_DISABLE_SYNC_CURRENCYLAYER');
658 } else {
659 setEventMessages($langs->trans('Use of API for currency update is disabled by option MULTICURRENCY_DISABLE_SYNC_CURRENCYLAYER'), null, 'errors');
660 }
661 return -1;
662 }
663
664 if (empty($key)) {
665 $key = getDolGlobalString("MULTICURRENCY_APP_ID");
666 }
667
668 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
669
670 $urlendpoint = 'http://api.currencylayer.com/live?access_key='.$key;
671 $urlendpoint .= '&source=' . (!getDolGlobalString('MULTICURRENCY_APP_SOURCE') ? 'USD' : $conf->global->MULTICURRENCY_APP_SOURCE);
672
673 dol_syslog("Call url endpoint ".$urlendpoint);
674
675 $resget = getURLContent($urlendpoint);
676
677 if ($resget['content']) {
678 $response = $resget['content'];
679 $response = json_decode($response);
680
681 if ($response->success) {
682 $TRate = $response->quotes;
683 //$timestamp = $response->timestamp;
684
685 if ($this->recalculRates($TRate) >= 0) {
686 foreach ($TRate as $currency_code => $rate) {
687 $code = substr($currency_code, 3, 3);
688 $obj = new MultiCurrency($db);
689 if ($obj->fetch(0, $code) > 0) {
690 $obj->updateRate($rate);
691 } elseif ($addifnotfound) {
692 $this->addRateFromDolibarr($code, $rate);
693 }
694 }
695 }
696
697 if ($mode == "cron") {
698 return 0;
699 }
700 return 1;
701 } else {
702 dol_syslog("Failed to call endpoint ".$response->error->info, LOG_WARNING);
703 if ($mode == "cron") {
704 $this->output = $langs->trans('multicurrency_syncronize_error', $response->error->info);
705 } else {
706 setEventMessages($langs->trans('multicurrency_syncronize_error', $response->error->info), null, 'errors');
707 }
708 return -1;
709 }
710 } else {
711 return -1;
712 }
713 }
714
721 public function checkCodeAlreadyExists($code)
722 {
723 $currencytmp = new MultiCurrency($this->db);
724 if ($currencytmp->fetch('', $code) > 0) {
725 return true;
726 } else {
727 return false;
728 }
729 }
730}
731
732
737{
741 public $element = 'multicurrency_rate';
742
746 public $table_element = 'multicurrency_rate';
747
751 public $id;
752
756 public $rate;
757
761 public $rate_indirect;
762
766 public $date_sync;
767
771 public $fk_multicurrency;
772
776 public $entity;
777
778
784 public function __construct(DoliDB $db)
785 {
786 $this->db = $db;
787 }
788
797 public function create(User $user, int $fk_multicurrency, $notrigger = 0)
798 {
799 global $conf;
800
801 dol_syslog('CurrencyRate::create', LOG_DEBUG);
802
803 $error = 0;
804 $this->rate = (float) price2num($this->rate);
805 if (empty($this->entity) || $this->entity <= 0) {
806 $this->entity = $conf->entity;
807 }
808 $now = empty($this->date_sync) ? dol_now() : $this->date_sync;
809
810 // Insert request
811 $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."(";
812 $sql .= ' rate,';
813 $sql .= ' rate_indirect,';
814 $sql .= ' date_sync,';
815 $sql .= ' fk_multicurrency,';
816 $sql .= ' entity';
817 $sql .= ') VALUES (';
818 $sql .= ' '.((float) $this->rate).',';
819 $sql .= ' '.((float) $this->rate_indirect).',';
820 $sql .= " '".$this->db->idate($now)."',";
821 $sql .= " ".((int) $fk_multicurrency).",";
822 $sql .= " ".((int) $this->entity);
823 $sql .= ')';
824
825 $this->db->begin();
826
827 dol_syslog(__METHOD__, LOG_DEBUG);
828 $resql = $this->db->query($sql);
829 if (!$resql) {
830 $error++;
831 $this->errors[] = 'Error '.$this->db->lasterror();
832 dol_syslog('CurrencyRate::create '.implode(',', $this->errors), LOG_ERR);
833 }
834
835 if (!$error) {
836 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
837 $this->fk_multicurrency = $fk_multicurrency;
838 $this->date_sync = $now;
839
840 if (empty($notrigger)) {
841 $result = $this->call_trigger('CURRENCYRATE_CREATE', $user);
842 if ($result < 0) {
843 $error++;
844 }
845 }
846 }
847
848 if ($error) {
849 $this->db->rollback();
850
851 return -1 * $error;
852 } else {
853 $this->db->commit();
854
855 return $this->id;
856 }
857 }
858
865 public function fetch($id)
866 {
867 dol_syslog('CurrencyRate::fetch', LOG_DEBUG);
868
869 $sql = "SELECT cr.rowid, cr.rate, cr.rate_indirect, cr.date_sync, cr.fk_multicurrency, cr.entity";
870 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." AS cr";
871 $sql .= " WHERE cr.rowid = ".((int) $id);
872
873 dol_syslog(__METHOD__, LOG_DEBUG);
874 $resql = $this->db->query($sql);
875 if ($resql) {
876 $numrows = $this->db->num_rows($resql);
877 if ($numrows) {
878 $obj = $this->db->fetch_object($resql);
879
880 $this->id = $obj->rowid;
881 $this->rate = $obj->rate;
882 $this->rate_indirect = $obj->rate_indirect;
883 $this->date_sync = $this->db->jdate($obj->date_sync);
884 $this->fk_multicurrency = $obj->fk_multicurrency;
885 $this->entity = $obj->entity;
886 }
887 $this->db->free($resql);
888
889 if ($numrows) {
890 return 1;
891 } else {
892 return 0;
893 }
894 } else {
895 $this->errors[] = 'Error '.$this->db->lasterror();
896 dol_syslog('CurrencyRate::fetch '.implode(',', $this->errors), LOG_ERR);
897
898 return -1;
899 }
900 }
901
909 public function update(User $user, $notrigger = 0)
910 {
911 $error = 0;
912
913 dol_syslog('CurrencyRate::update', LOG_DEBUG);
914
915 $this->rate = (float) price2num($this->rate);
916
917 // Update request
918 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
919 $sql .= "SET rate = ".((float) $this->rate);
920 if (!empty($this->date_sync)) {
921 $sql .= ", date_sync = '".$this->db->idate($this->date_sync)."'";
922 }
923 if (!empty($this->fk_multicurrency)) {
924 $sql .= ', fk_multicurrency = '.((int) $this->fk_multicurrency);
925 }
926 $sql .= " WHERE rowid =".((int) $this->id);
927
928 $this->db->begin();
929
930 dol_syslog(__METHOD__, LOG_DEBUG);
931 $resql = $this->db->query($sql);
932 if (!$resql) {
933 $error++;
934 $this->errors[] = 'Error '.$this->db->lasterror();
935 dol_syslog('CurrencyRate::update '.implode(',', $this->errors), LOG_ERR);
936 }
937
938 if (!$error && empty($notrigger)) {
939 $result = $this->call_trigger('CURRENCYRATE_MODIFY', $user);
940 if ($result < 0) {
941 $error++;
942 }
943 }
944
945 // Commit or rollback
946 if ($error) {
947 $this->db->rollback();
948
949 return -1 * $error;
950 } else {
951 $this->db->commit();
952
953 return 1;
954 }
955 }
956
964 public function delete(User $user, $notrigger = 0)
965 {
966 dol_syslog('CurrencyRate::delete', LOG_DEBUG);
967
968 $error = 0;
969
970 $this->db->begin();
971
972 if (empty($notrigger)) {
973 $result = $this->call_trigger('CURRENCYRATE_DELETE', $user);
974 if ($result < 0) {
975 $error++;
976 }
977 }
978
979 if (!$error) {
980 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
981 $sql .= ' WHERE rowid='.((int) $this->id);
982
983 dol_syslog(__METHOD__, LOG_DEBUG);
984 $resql = $this->db->query($sql);
985 if (!$resql) {
986 $error++;
987 $this->errors[] = 'Error '.$this->db->lasterror();
988 dol_syslog('CurrencyRate::delete '.implode(',', $this->errors), LOG_ERR);
989 }
990 }
991
992 // Commit or rollback
993 if ($error) {
994 $this->db->rollback();
995
996 return -1 * $error;
997 } else {
998 $this->db->commit();
999
1000 return 1;
1001 }
1002 }
1003}
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class CurrencyRate.
fetch($id)
Load object in memory from the database.
update(User $user, $notrigger=0)
Update object into database.
create(User $user, int $fk_multicurrency, $notrigger=0)
Create object into database.
__construct(DoliDB $db)
Constructor.
Class to manage Dolibarr database access.
Class Currency.
delete(User $user, $notrigger=0)
Delete object in database.
update(User $user, $notrigger=0)
Update object into database.
fetchAllCurrencyRate()
Load all rates in object from the database.
checkCodeAlreadyExists($code)
Check in database if the current code already exists.
__construct(DoliDB $db)
Constructor.
create(User $user, $notrigger=0)
Create object into database.
addRateFromDolibarr($code, $rate)
Try get label of code in llx_currency then add rate.
recalculRates(&$TRate)
With free account we can't set source then recalcul all rates to force another source.
fetch($id, $code=null)
Load object in memory from the database.
Class to manage Dolibarr users.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_now($mode='auto')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).
a disabled
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:140