dolibarr 19.0.3
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
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30require_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
114 public function create(User $user, $trigger = true)
115 {
116 global $conf, $langs;
117
118 dol_syslog('MultiCurrency::create', LOG_DEBUG);
119
120 $error = 0;
121
122 if (self::checkCodeAlreadyExists($this->code)) {
123 $error++;
124 $this->errors[] = $langs->trans('multicurrency_code_already_added');
125 return -1;
126 }
127
128 if (empty($this->entity) || $this->entity <= 0) {
129 $this->entity = $conf->entity;
130 }
131 $now = dol_now();
132
133 // Insert request
134 $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."(";
135 $sql .= ' code,';
136 $sql .= ' name,';
137 $sql .= ' entity,';
138 $sql .= ' date_create,';
139 $sql .= ' fk_user';
140 $sql .= ') VALUES (';
141 $sql .= " '".$this->db->escape($this->code)."',";
142 $sql .= " '".$this->db->escape($this->name)."',";
143 $sql .= " ".((int) $this->entity).",";
144 $sql .= " '".$this->db->idate($now)."',";
145 $sql .= " ".((int) $user->id);
146 $sql .= ')';
147
148 $this->db->begin();
149
150 dol_syslog(__METHOD__, LOG_DEBUG);
151 $resql = $this->db->query($sql);
152 if (!$resql) {
153 $error++;
154 $this->errors[] = 'Error '.$this->db->lasterror();
155 dol_syslog('MultiCurrency::create '.join(',', $this->errors), LOG_ERR);
156 }
157
158 if (!$error) {
159 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
160 $this->date_create = $now;
161 $this->fk_user = $user->id;
162
163 if ($trigger) {
164 $result = $this->call_trigger('CURRENCY_CREATE', $user);
165 if ($result < 0) {
166 $error++;
167 }
168 }
169 }
170
171 if ($error) {
172 $this->db->rollback();
173
174 return -1 * $error;
175 } else {
176 $this->db->commit();
177
178 return $this->id;
179 }
180 }
181
189 public function fetch($id, $code = null)
190 {
191 dol_syslog('MultiCurrency::fetch', LOG_DEBUG);
192
193 global $conf;
194
195 $sql = "SELECT";
196 $sql .= ' c.rowid, c.name, c.code, c.entity, c.date_create, c.fk_user';
197 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' AS c';
198 if (!empty($code)) {
199 $sql .= ' WHERE c.code = \''.$this->db->escape($code).'\' AND c.entity = '.$conf->entity;
200 } else {
201 $sql .= ' WHERE c.rowid = '.((int) $id);
202 }
203
204 dol_syslog(__METHOD__, LOG_DEBUG);
205 $resql = $this->db->query($sql);
206
207 if ($resql) {
208 $numrows = $this->db->num_rows($resql);
209 if ($numrows) {
210 $obj = $this->db->fetch_object($resql);
211
212 $this->id = $obj->rowid;
213 $this->name = $obj->name;
214 $this->code = $obj->code;
215 $this->entity = $obj->entity;
216 $this->date_create = $obj->date_create;
217 $this->fk_user = $obj->fk_user;
218
219 $this->fetchAllCurrencyRate();
220 $this->getRate();
221 }
222 $this->db->free($resql);
223
224 if ($numrows) {
225 return 1;
226 } else {
227 return 0;
228 }
229 } else {
230 $this->errors[] = 'Error '.$this->db->lasterror();
231 dol_syslog('MultiCurrency::fetch '.join(',', $this->errors), LOG_ERR);
232
233 return -1;
234 }
235 }
236
242 public function fetchAllCurrencyRate()
243 {
244 $sql = "SELECT cr.rowid";
245 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as cr';
246 $sql .= ' WHERE cr.fk_multicurrency = '.((int) $this->id);
247 $sql .= ' ORDER BY cr.date_sync DESC';
248
249 $this->rates = array();
250
251 dol_syslog(__METHOD__, LOG_DEBUG);
252 $resql = $this->db->query($sql);
253 if ($resql) {
254 $num = $this->db->num_rows($resql);
255
256 while ($obj = $this->db->fetch_object($resql)) {
257 $rate = new CurrencyRate($this->db);
258 $rate->fetch($obj->rowid);
259
260 $this->rates[] = $rate;
261 }
262 $this->db->free($resql);
263
264 return $num;
265 } else {
266 $this->errors[] = 'Error '.$this->db->lasterror();
267 dol_syslog('MultiCurrency::fetchAllCurrencyRate '.join(',', $this->errors), LOG_ERR);
268
269 return -1;
270 }
271 }
272
280 public function update(User $user, $trigger = true)
281 {
282 $error = 0;
283
284 dol_syslog('MultiCurrency::update', LOG_DEBUG);
285
286 // Clean parameters
287 $this->name = trim($this->name);
288 $this->code = trim($this->code);
289
290 // Check parameters
291 if (empty($this->code)) {
292 $error++;
293 dol_syslog('MultiCurrency::update $this->code can not be empty', LOG_ERR);
294
295 return -1;
296 }
297
298 // Update request
299 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
300 $sql .= " name = '".$this->db->escape($this->name)."',";
301 $sql .= " code = '".$this->db->escape($this->code)."'";
302 $sql .= " WHERE rowid = ".((int) $this->id);
303
304 $this->db->begin();
305
306 $resql = $this->db->query($sql);
307 if (!$resql) {
308 $error++;
309 $this->errors[] = 'Error '.$this->db->lasterror();
310 dol_syslog('MultiCurrency::update '.join(',', $this->errors), LOG_ERR);
311 }
312
313 if (!$error && $trigger) {
314 $result = $this->call_trigger('CURRENCY_MODIFY', $user);
315 if ($result < 0) {
316 $error++;
317 }
318 }
319
320 // Commit or rollback
321 if ($error) {
322 $this->db->rollback();
323
324 return -1 * $error;
325 } else {
326 $this->db->commit();
327
328 return 1;
329 }
330 }
331
339 public function delete($user, $trigger = true)
340 {
341 dol_syslog('MultiCurrency::delete', LOG_DEBUG);
342
343 $error = 0;
344
345 $this->db->begin();
346
347 if ($trigger) {
348 $result = $this->call_trigger('CURRENCY_DELETE', $user);
349 if ($result < 0) {
350 $error++;
351 }
352 }
353
354 if (!$error) {
355 // Delete all rates before
356 if (!$this->deleteRates()) {
357 $error++;
358 $this->errors[] = 'Error '.$this->db->lasterror();
359 dol_syslog('Currency::delete '.join(',', $this->errors), LOG_ERR);
360 }
361
362 $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
363 $sql .= " WHERE rowid = ".((int) $this->id);
364
365 dol_syslog(__METHOD__, LOG_DEBUG);
366 $resql = $this->db->query($sql);
367 if (!$resql) {
368 $error++;
369 $this->errors[] = 'Error '.$this->db->lasterror();
370 dol_syslog('MultiCurrency::delete '.join(',', $this->errors), LOG_ERR);
371 }
372 }
373
374 // Commit or rollback
375 if ($error) {
376 $this->db->rollback();
377
378 return -1 * $error;
379 } else {
380 $this->db->commit();
381
382 return 1;
383 }
384 }
385
391 public function deleteRates()
392 {
393 global $user;
394
395 foreach ($this->rates as &$rate) {
396 if ($rate->delete($user) <= 0) {
397 return false;
398 }
399 }
400
401 return true;
402 }
403
410 public function addRate($rate)
411 {
412 $currencyRate = new CurrencyRate($this->db);
413 $currencyRate->rate = price2num($rate);
414
415 if ($currencyRate->create($this->id) > 0) {
416 $this->rate = $currencyRate;
417 return 1;
418 } else {
419 $this->rate = null;
420 $this->errors = $currencyRate->errors;
421 return -1;
422 }
423 }
424
432 public function addRateFromDolibarr($code, $rate)
433 {
434 global $user;
435
436 $currency = new MultiCurrency($this->db);
437 $currency->code = $code;
438 $currency->name = $code;
439
440 $sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies WHERE code_iso = '".$this->db->escape($code)."'";
441
442 dol_syslog(__METHOD__, LOG_DEBUG);
443 $resql = $this->db->query($sql);
444 if ($resql && ($line = $this->db->fetch_object($resql))) {
445 $currency->name = $line->label;
446 }
447
448 if ($currency->create($user) > 0) {
449 $currency->addRate($rate);
450
451 if (!empty($line)) {
452 return 2;
453 } else {
454 return 1;
455 }
456 }
457
458 return -1;
459 }
460
467 public function updateRate($rate)
468 {
469 return $this->addRate($rate);
470 }
471
477 public function getRate()
478 {
479 $sql = "SELECT cr.rowid";
480 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element_line." as cr";
481 $sql .= " WHERE cr.fk_multicurrency = ".((int) $this->id);
482 $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).")";
483
484 dol_syslog(__METHOD__, LOG_DEBUG);
485 $resql = $this->db->query($sql);
486 if ($resql && ($obj = $this->db->fetch_object($resql))) {
487 $this->rate = new CurrencyRate($this->db);
488 return $this->rate->fetch($obj->rowid);
489 }
490
491 return -1;
492 }
493
502 public static function getIdFromCode($dbs, $code)
503 {
504 global $conf;
505
506 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."multicurrency WHERE code = '".$dbs->escape($code)."' AND entity = ".((int) $conf->entity);
507
508 dol_syslog(__METHOD__, LOG_DEBUG);
509 $resql = $dbs->query($sql);
510 if ($resql && $obj = $dbs->fetch_object($resql)) {
511 return $obj->rowid;
512 } else {
513 return 0;
514 }
515 }
516
527 public static function getIdAndTxFromCode($dbs, $code, $date_document = '')
528 {
529 global $conf;
530
531 $sql1 = "SELECT m.rowid, mc.rate FROM ".MAIN_DB_PREFIX."multicurrency m";
532
533 $sql1 .= ' LEFT JOIN '.MAIN_DB_PREFIX.'multicurrency_rate mc ON (m.rowid = mc.fk_multicurrency)';
534 $sql1 .= " WHERE m.code = '".$dbs->escape($code)."'";
535 $sql1 .= " AND m.entity IN (".getEntity('multicurrency').")";
536 $sql2 = '';
537 if (getDolGlobalString('MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE') && !empty($date_document)) { // Use last known rate compared to document date
538 $tmparray = dol_getdate($date_document);
539 $sql2 .= " AND mc.date_sync <= '".$dbs->idate(dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year'], true))."'";
540 }
541 $sql3 = " ORDER BY mc.date_sync DESC LIMIT 1";
542
543 dol_syslog(__METHOD__, LOG_DEBUG);
544 $resql = $dbs->query($sql1.$sql2.$sql3);
545
546 if ($resql && $obj = $dbs->fetch_object($resql)) {
547 return array($obj->rowid, $obj->rate);
548 } else {
549 if (getDolGlobalString('MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE')) {
550 $resql = $dbs->query($sql1.$sql3);
551 if ($resql && $obj = $dbs->fetch_object($resql)) {
552 return array($obj->rowid, $obj->rate);
553 }
554 }
555
556 return array(0, 1);
557 }
558 }
559
570 public static function getAmountConversionFromInvoiceRate($fk_facture, $amount, $way = 'dolibarr', $table = 'facture', $invoice_rate = null)
571 {
572 if (!is_null($invoice_rate)) {
573 $multicurrency_tx = $invoice_rate;
574 } else {
575 $multicurrency_tx = self::getInvoiceRate($fk_facture, $table);
576 }
577
578 if ($multicurrency_tx) {
579 if ($way == 'dolibarr') {
580 return price2num($amount * $multicurrency_tx, 'MU');
581 } else {
582 return price2num($amount / $multicurrency_tx, 'MU');
583 }
584 } else {
585 return false;
586 }
587 }
588
596 public static function getInvoiceRate($fk_facture, $table = 'facture')
597 {
598 global $db;
599
600 $sql = "SELECT multicurrency_tx FROM ".MAIN_DB_PREFIX.$table." WHERE rowid = ".((int) $fk_facture);
601
602 dol_syslog(__METHOD__, LOG_DEBUG);
603 $resql = $db->query($sql);
604 if ($resql && ($line = $db->fetch_object($resql))) {
605 return $line->multicurrency_tx;
606 }
607
608 return false;
609 }
610
618 public function recalculRates(&$TRate)
619 {
620 global $conf;
621
622 if ($conf->currency != getDolGlobalString('MULTICURRENCY_APP_SOURCE')) {
623 $alternate_source = 'USD'.$conf->currency;
624 if (!empty($TRate->$alternate_source)) {
625 $coef = 1 / $TRate->$alternate_source;
626 foreach ($TRate as $attr => &$rate) {
627 $rate *= $coef;
628 }
629 $TRate->USDUSD = $coef;
630 return 1;
631 }
632
633 return -1; // Alternate souce not found
634 }
635
636 return 0; // Nothing to do
637 }
638
647 public function syncRates($key, $addifnotfound = 0, $mode = "")
648 {
649 global $conf, $db, $langs;
650
651 if (getDolGlobalString('MULTICURRENCY_DISABLE_SYNC_CURRENCYLAYER')) {
652 if ($mode == "cron") {
653 $this->output = $langs->trans('Use of API for currency update is disabled by option MULTICURRENCY_DISABLE_SYNC_CURRENCYLAYER');
654 } else {
655 setEventMessages($langs->trans('Use of API for currency update is disabled by option MULTICURRENCY_DISABLE_SYNC_CURRENCYLAYER'), null, 'errors');
656 }
657 return -1;
658 }
659
660 if (empty($key)) {
661 $key = getDolGlobalString("MULTICURRENCY_APP_ID");
662 }
663
664 include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
665
666 $urlendpoint = 'http://api.currencylayer.com/live?access_key='.$key;
667 $urlendpoint .= '&source=' . (!getDolGlobalString('MULTICURRENCY_APP_SOURCE') ? 'USD' : $conf->global->MULTICURRENCY_APP_SOURCE);
668
669 dol_syslog("Call url endpoint ".$urlendpoint);
670
671 $resget = getURLContent($urlendpoint);
672
673 if ($resget['content']) {
674 $response = $resget['content'];
675 $response = json_decode($response);
676
677 if ($response->success) {
678 $TRate = $response->quotes;
679 //$timestamp = $response->timestamp;
680
681 if ($this->recalculRates($TRate) >= 0) {
682 foreach ($TRate as $currency_code => $rate) {
683 $code = substr($currency_code, 3, 3);
684 $obj = new MultiCurrency($db);
685 if ($obj->fetch(0, $code) > 0) {
686 $obj->updateRate($rate);
687 } elseif ($addifnotfound) {
688 $this->addRateFromDolibarr($code, $rate);
689 }
690 }
691 }
692
693 if ($mode == "cron") {
694 return 0;
695 }
696 return 1;
697 } else {
698 dol_syslog("Failed to call endpoint ".$response->error->info, LOG_WARNING);
699 if ($mode == "cron") {
700 $this->output = $langs->trans('multicurrency_syncronize_error', $response->error->info);
701 } else {
702 setEventMessages($langs->trans('multicurrency_syncronize_error', $response->error->info), null, 'errors');
703 }
704 return -1;
705 }
706 } else {
707 return -1;
708 }
709 }
710
717 public function checkCodeAlreadyExists($code)
718 {
719 $currencytmp = new MultiCurrency($this->db);
720 if ($currencytmp->fetch('', $code) > 0) {
721 return true;
722 } else {
723 return false;
724 }
725 }
726}
727
728
733{
737 public $element = 'multicurrency_rate';
738
742 public $table_element = 'multicurrency_rate';
743
747 public $id;
748
752 public $rate;
753
757 public $rate_indirect;
758
762 public $date_sync;
763
767 public $fk_multicurrency;
768
772 public $entity;
773
774
780 public function __construct(DoliDB $db)
781 {
782 $this->db = $db;
783 }
784
792 public function create($fk_multicurrency, $trigger = true)
793 {
794 global $conf, $user;
795
796 dol_syslog('CurrencyRate::create', LOG_DEBUG);
797
798 $error = 0;
799 $this->rate = price2num($this->rate);
800 if (empty($this->entity) || $this->entity <= 0) {
801 $this->entity = $conf->entity;
802 }
803 $now = empty($this->date_sync) ? dol_now() : $this->date_sync;
804
805 // Insert request
806 $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."(";
807 $sql .= ' rate,';
808 $sql .= ' rate_indirect,';
809 $sql .= ' date_sync,';
810 $sql .= ' fk_multicurrency,';
811 $sql .= ' entity';
812 $sql .= ') VALUES (';
813 $sql .= ' '.((float) $this->rate).',';
814 $sql .= ' '.((float) $this->rate_indirect).',';
815 $sql .= " '".$this->db->idate($now)."',";
816 $sql .= " ".((int) $fk_multicurrency).",";
817 $sql .= " ".((int) $this->entity);
818 $sql .= ')';
819
820 $this->db->begin();
821
822 dol_syslog(__METHOD__, LOG_DEBUG);
823 $resql = $this->db->query($sql);
824 if (!$resql) {
825 $error++;
826 $this->errors[] = 'Error '.$this->db->lasterror();
827 dol_syslog('CurrencyRate::create '.join(',', $this->errors), LOG_ERR);
828 }
829
830 if (!$error) {
831 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
832 $this->fk_multicurrency = $fk_multicurrency;
833 $this->date_sync = $now;
834
835 if ($trigger) {
836 $result = $this->call_trigger('CURRENCYRATE_CREATE', $user);
837 if ($result < 0) {
838 $error++;
839 }
840 }
841 }
842
843 if ($error) {
844 $this->db->rollback();
845
846 return -1 * $error;
847 } else {
848 $this->db->commit();
849
850 return $this->id;
851 }
852 }
853
860 public function fetch($id)
861 {
862 dol_syslog('CurrencyRate::fetch', LOG_DEBUG);
863
864 $sql = "SELECT cr.rowid, cr.rate, cr.rate_indirect, cr.date_sync, cr.fk_multicurrency, cr.entity";
865 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." AS cr";
866 $sql .= " WHERE cr.rowid = ".((int) $id);
867
868 dol_syslog(__METHOD__, LOG_DEBUG);
869 $resql = $this->db->query($sql);
870 if ($resql) {
871 $numrows = $this->db->num_rows($resql);
872 if ($numrows) {
873 $obj = $this->db->fetch_object($resql);
874
875 $this->id = $obj->rowid;
876 $this->rate = $obj->rate;
877 $this->rate_indirect = $obj->rate_indirect;
878 $this->date_sync = $this->db->jdate($obj->date_sync);
879 $this->fk_multicurrency = $obj->fk_multicurrency;
880 $this->entity = $obj->entity;
881 }
882 $this->db->free($resql);
883
884 if ($numrows) {
885 return 1;
886 } else {
887 return 0;
888 }
889 } else {
890 $this->errors[] = 'Error '.$this->db->lasterror();
891 dol_syslog('CurrencyRate::fetch '.join(',', $this->errors), LOG_ERR);
892
893 return -1;
894 }
895 }
896
903 public function update($trigger = true)
904 {
905 global $user;
906
907 $error = 0;
908
909 dol_syslog('CurrencyRate::update', LOG_DEBUG);
910
911 $this->rate = price2num($this->rate);
912
913 // Update request
914 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
915 $sql .= "SET rate = ".((float) $this->rate);
916 if (!empty($this->date_sync)) {
917 $sql .= ", date_sync = '".$this->db->idate($this->date_sync)."'";
918 }
919 if (!empty($this->fk_multicurrency)) {
920 $sql .= ', fk_multicurrency = '.((int) $this->fk_multicurrency);
921 }
922 $sql .= " WHERE rowid =".((int) $this->id);
923
924 $this->db->begin();
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::update '.join(',', $this->errors), LOG_ERR);
932 }
933
934 if (!$error && $trigger) {
935 $result = $this->call_trigger('CURRENCYRATE_MODIFY', $user);
936 if ($result < 0) {
937 $error++;
938 }
939 }
940
941 // Commit or rollback
942 if ($error) {
943 $this->db->rollback();
944
945 return -1 * $error;
946 } else {
947 $this->db->commit();
948
949 return 1;
950 }
951 }
952
960 public function delete($user, $trigger = true)
961 {
962 dol_syslog('CurrencyRate::delete', LOG_DEBUG);
963
964 $error = 0;
965
966 $this->db->begin();
967
968 if ($trigger) {
969 $result = $this->call_trigger('CURRENCYRATE_DELETE', $user);
970 if ($result < 0) {
971 $error++;
972 }
973 }
974
975 if (!$error) {
976 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
977 $sql .= ' WHERE rowid='.((int) $this->id);
978
979 dol_syslog(__METHOD__, LOG_DEBUG);
980 $resql = $this->db->query($sql);
981 if (!$resql) {
982 $error++;
983 $this->errors[] = 'Error '.$this->db->lasterror();
984 dol_syslog('CurrencyRate::delete '.join(',', $this->errors), LOG_ERR);
985 }
986 }
987
988 // Commit or rollback
989 if ($error) {
990 $this->db->rollback();
991
992 return -1 * $error;
993 } else {
994 $this->db->commit();
995
996 return 1;
997 }
998 }
999}
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($trigger=true)
Update object into database.
create($fk_multicurrency, $trigger=true)
Create object into database.
__construct(DoliDB $db)
Constructor.
Class to manage Dolibarr database access.
Class Currency.
fetchAllCurrencyRate()
Load all rates in object from the database.
checkCodeAlreadyExists($code)
Check in database if the current code already exists.
__construct(DoliDB $db)
Constructor.
update(User $user, $trigger=true)
Update object into database.
delete($user, $trigger=true)
Delete object in database.
addRateFromDolibarr($code, $rate)
Try get label of code in llx_currency then add rate.
create(User $user, $trigger=true)
Create object into database.
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).
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:124