dolibarr  18.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  *
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  $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 '.join(',', $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 ($trigger) {
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 '.join(',', $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 '.join(',', $this->errors), LOG_ERR);
270 
271  return -1;
272  }
273  }
274 
282  public function update(User $user, $trigger = true)
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 '.join(',', $this->errors), LOG_ERR);
313  }
314 
315  if (!$error && $trigger) {
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 
340  public function delete($trigger = true)
341  {
342  global $user;
343 
344  dol_syslog('MultiCurrency::delete', LOG_DEBUG);
345 
346  $error = 0;
347 
348  $this->db->begin();
349 
350  if ($trigger) {
351  $result = $this->call_trigger('CURRENCY_DELETE', $user);
352  if ($result < 0) {
353  $error++;
354  }
355  }
356 
357  if (!$error) {
358  // Delete all rates before
359  if (!$this->deleteRates()) {
360  $error++;
361  $this->errors[] = 'Error '.$this->db->lasterror();
362  dol_syslog('Currency::delete '.join(',', $this->errors), LOG_ERR);
363  }
364 
365  $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
366  $sql .= " WHERE rowid = ".((int) $this->id);
367 
368  dol_syslog(__METHOD__, LOG_DEBUG);
369  $resql = $this->db->query($sql);
370  if (!$resql) {
371  $error++;
372  $this->errors[] = 'Error '.$this->db->lasterror();
373  dol_syslog('MultiCurrency::delete '.join(',', $this->errors), LOG_ERR);
374  }
375  }
376 
377  // Commit or rollback
378  if ($error) {
379  $this->db->rollback();
380 
381  return -1 * $error;
382  } else {
383  $this->db->commit();
384 
385  return 1;
386  }
387  }
388 
394  public function deleteRates()
395  {
396  foreach ($this->rates as &$rate) {
397  if ($rate->delete() <= 0) {
398  return false;
399  }
400  }
401 
402  return true;
403  }
404 
411  public function addRate($rate)
412  {
413  $currencyRate = new CurrencyRate($this->db);
414  $currencyRate->rate = price2num($rate);
415 
416  if ($currencyRate->create($this->id) > 0) {
417  $this->rate = $currencyRate;
418  return 1;
419  } else {
420  $this->rate = null;
421  $this->errors = $currencyRate->errors;
422  return -1;
423  }
424  }
425 
433  public function addRateFromDolibarr($code, $rate)
434  {
435  global $user;
436 
437  $currency = new MultiCurrency($this->db);
438  $currency->code = $code;
439  $currency->name = $code;
440 
441  $sql = "SELECT label FROM ".MAIN_DB_PREFIX."c_currencies WHERE code_iso = '".$this->db->escape($code)."'";
442 
443  dol_syslog(__METHOD__, LOG_DEBUG);
444  $resql = $this->db->query($sql);
445  if ($resql && ($line = $this->db->fetch_object($resql))) {
446  $currency->name = $line->label;
447  }
448 
449  if ($currency->create($user) > 0) {
450  $currency->addRate($rate);
451 
452  if (!empty($line)) {
453  return 2;
454  } else {
455  return 1;
456  }
457  }
458 
459  return -1;
460  }
461 
468  public function updateRate($rate)
469  {
470  return $this->addRate($rate);
471  }
472 
478  public function getRate()
479  {
480  $sql = "SELECT cr.rowid";
481  $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element_line." as cr";
482  $sql .= " WHERE cr.fk_multicurrency = ".((int) $this->id);
483  $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 
485  dol_syslog(__METHOD__, LOG_DEBUG);
486  $resql = $this->db->query($sql);
487  if ($resql && ($obj = $this->db->fetch_object($resql))) {
488  $this->rate = new CurrencyRate($this->db);
489  return $this->rate->fetch($obj->rowid);
490  }
491 
492  return -1;
493  }
494 
503  public static function getIdFromCode($dbs, $code)
504  {
505  global $conf;
506 
507  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."multicurrency WHERE code = '".$dbs->escape($code)."' AND entity = ".((int) $conf->entity);
508 
509  dol_syslog(__METHOD__, LOG_DEBUG);
510  $resql = $dbs->query($sql);
511  if ($resql && $obj = $dbs->fetch_object($resql)) {
512  return $obj->rowid;
513  } else {
514  return 0;
515  }
516  }
517 
528  public static function getIdAndTxFromCode($dbs, $code, $date_document = '')
529  {
530  global $conf;
531 
532  $sql1 = "SELECT m.rowid, mc.rate FROM ".MAIN_DB_PREFIX."multicurrency m";
533 
534  $sql1 .= ' LEFT JOIN '.MAIN_DB_PREFIX.'multicurrency_rate mc ON (m.rowid = mc.fk_multicurrency)';
535  $sql1 .= " WHERE m.code = '".$dbs->escape($code)."'";
536  $sql1 .= " AND m.entity IN (".getEntity('multicurrency').")";
537  $sql2 = '';
538  if (!empty($conf->global->MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE) && !empty($date_document)) { // Use last known rate compared to document date
539  $tmparray = dol_getdate($date_document);
540  $sql2 .= " AND mc.date_sync <= '".$dbs->idate(dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year'], true))."'";
541  }
542  $sql3 = " ORDER BY mc.date_sync DESC LIMIT 1";
543 
544  dol_syslog(__METHOD__, LOG_DEBUG);
545  $resql = $dbs->query($sql1.$sql2.$sql3);
546 
547  if ($resql && $obj = $dbs->fetch_object($resql)) {
548  return array($obj->rowid, $obj->rate);
549  } else {
550  if (!empty($conf->global->MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE)) {
551  $resql = $dbs->query($sql1.$sql3);
552  if ($resql && $obj = $dbs->fetch_object($resql)) {
553  return array($obj->rowid, $obj->rate);
554  }
555  }
556 
557  return array(0, 1);
558  }
559  }
560 
571  public static function getAmountConversionFromInvoiceRate($fk_facture, $amount, $way = 'dolibarr', $table = 'facture', $invoice_rate = null)
572  {
573  if (!is_null($invoice_rate)) {
574  $multicurrency_tx = $invoice_rate;
575  } else {
576  $multicurrency_tx = self::getInvoiceRate($fk_facture, $table);
577  }
578 
579  if ($multicurrency_tx) {
580  if ($way == 'dolibarr') {
581  return price2num($amount * $multicurrency_tx, 'MU');
582  } else {
583  return price2num($amount / $multicurrency_tx, 'MU');
584  }
585  } else {
586  return false;
587  }
588  }
589 
597  public static function getInvoiceRate($fk_facture, $table = 'facture')
598  {
599  global $db;
600 
601  $sql = "SELECT multicurrency_tx FROM ".MAIN_DB_PREFIX.$table." WHERE rowid = ".((int) $fk_facture);
602 
603  dol_syslog(__METHOD__, LOG_DEBUG);
604  $resql = $db->query($sql);
605  if ($resql && ($line = $db->fetch_object($resql))) {
606  return $line->multicurrency_tx;
607  }
608 
609  return false;
610  }
611 
619  public function recalculRates(&$TRate)
620  {
621  global $conf;
622 
623  if ($conf->currency != getDolGlobalString('MULTICURRENCY_APP_SOURCE')) {
624  $alternate_source = 'USD'.$conf->currency;
625  if (!empty($TRate->$alternate_source)) {
626  $coef = $TRate->USDUSD / $TRate->$alternate_source;
627  foreach ($TRate as $attr => &$rate) {
628  $rate *= $coef;
629  }
630 
631  return 1;
632  }
633 
634  return -1; // Alternate souce not found
635  }
636 
637  return 0; // Nothing to do
638  }
639 
647  public function syncRates($key, $addifnotfound = 0)
648  {
649  global $conf, $db, $langs;
650 
651  include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
652 
653  $urlendpoint = 'http://api.currencylayer.com/live?access_key='.$key;
654  $urlendpoint .= '&source=' . (empty($conf->global->MULTICURRENCY_APP_SOURCE) ? 'USD' : $conf->global->MULTICURRENCY_APP_SOURCE);
655 
656  dol_syslog("Call url endpoint ".$urlendpoint);
657 
658  $resget = getURLContent($urlendpoint);
659 
660  if ($resget['content']) {
661  $response = $resget['content'];
662  $response = json_decode($response);
663 
664  if ($response->success) {
665  $TRate = $response->quotes;
666  //$timestamp = $response->timestamp;
667 
668  if ($this->recalculRates($TRate) >= 0) {
669  foreach ($TRate as $currency_code => $rate) {
670  $code = substr($currency_code, 3, 3);
671  $obj = new MultiCurrency($db);
672  if ($obj->fetch(0, $code) > 0) {
673  $obj->updateRate($rate);
674  } elseif ($addifnotfound) {
675  $this->addRateFromDolibarr($code, $rate);
676  }
677  }
678  }
679 
680  return 1;
681  } else {
682  dol_syslog("Failed to call endpoint ".$response->error->info, LOG_WARNING);
683  setEventMessages($langs->trans('multicurrency_syncronize_error', $response->error->info), null, 'errors');
684 
685  return -1;
686  }
687  } else {
688  return -1;
689  }
690  }
691 
698  public function checkCodeAlreadyExists($code)
699  {
700  $currencytmp = new MultiCurrency($this->db);
701  if ($currencytmp->fetch('', $code) > 0) {
702  return true;
703  } else {
704  return false;
705  }
706  }
707 }
708 
709 
714 {
718  public $element = 'multicurrency_rate';
719 
723  public $table_element = 'multicurrency_rate';
724 
728  public $id;
729 
733  public $rate;
734 
738  public $date_sync;
739 
743  public $fk_multicurrency;
744 
748  public $entity;
749 
750 
756  public function __construct(DoliDB $db)
757  {
758  $this->db = $db;
759 
760  return 1;
761  }
762 
770  public function create($fk_multicurrency, $trigger = true)
771  {
772  global $conf, $user;
773 
774  dol_syslog('CurrencyRate::create', LOG_DEBUG);
775 
776  $error = 0;
777  $this->rate = price2num($this->rate);
778  if (empty($this->entity) || $this->entity <= 0) {
779  $this->entity = $conf->entity;
780  }
781  $now = empty($this->date_sync) ? dol_now() : $this->date_sync;
782 
783  // Insert request
784  $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."(";
785  $sql .= ' rate,';
786  $sql .= ' date_sync,';
787  $sql .= ' fk_multicurrency,';
788  $sql .= ' entity';
789  $sql .= ') VALUES (';
790  $sql .= ' '.((float) $this->rate).',';
791  $sql .= " '".$this->db->idate($now)."',";
792  $sql .= " ".((int) $fk_multicurrency).",";
793  $sql .= " ".((int) $this->entity);
794  $sql .= ')';
795 
796  $this->db->begin();
797 
798  dol_syslog(__METHOD__, LOG_DEBUG);
799  $resql = $this->db->query($sql);
800  if (!$resql) {
801  $error++;
802  $this->errors[] = 'Error '.$this->db->lasterror();
803  dol_syslog('CurrencyRate::create '.join(',', $this->errors), LOG_ERR);
804  }
805 
806  if (!$error) {
807  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
808  $this->fk_multicurrency = $fk_multicurrency;
809  $this->date_sync = $now;
810 
811  if ($trigger) {
812  $result = $this->call_trigger('CURRENCYRATE_CREATE', $user);
813  if ($result < 0) {
814  $error++;
815  }
816  }
817  }
818 
819  if ($error) {
820  $this->db->rollback();
821 
822  return -1 * $error;
823  } else {
824  $this->db->commit();
825 
826  return $this->id;
827  }
828  }
829 
836  public function fetch($id)
837  {
838  dol_syslog('CurrencyRate::fetch', LOG_DEBUG);
839 
840  $sql = "SELECT cr.rowid, cr.rate, cr.date_sync, cr.fk_multicurrency, cr.entity";
841  $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." AS cr";
842  $sql .= " WHERE cr.rowid = ".((int) $id);
843 
844  dol_syslog(__METHOD__, LOG_DEBUG);
845  $resql = $this->db->query($sql);
846  if ($resql) {
847  $numrows = $this->db->num_rows($resql);
848  if ($numrows) {
849  $obj = $this->db->fetch_object($resql);
850 
851  $this->id = $obj->rowid;
852  $this->rate = $obj->rate;
853  $this->date_sync = $this->db->jdate($obj->date_sync);
854  $this->fk_multicurrency = $obj->fk_multicurrency;
855  $this->entity = $obj->entity;
856  }
857  $this->db->free($resql);
858 
859  if ($numrows) {
860  return 1;
861  } else {
862  return 0;
863  }
864  } else {
865  $this->errors[] = 'Error '.$this->db->lasterror();
866  dol_syslog('CurrencyRate::fetch '.join(',', $this->errors), LOG_ERR);
867 
868  return -1;
869  }
870  }
871 
878  public function update($trigger = true)
879  {
880  global $user;
881 
882  $error = 0;
883 
884  dol_syslog('CurrencyRate::update', LOG_DEBUG);
885 
886  $this->rate = price2num($this->rate);
887 
888  // Update request
889  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
890  $sql .= "SET rate = ".((float) $this->rate);
891  if (!empty($this->date_sync)) {
892  $sql .= ", date_sync = '".$this->db->idate($this->date_sync)."'";
893  }
894  if (!empty($this->fk_multicurrency)) {
895  $sql .= ', fk_multicurrency = '.((int) $this->fk_multicurrency);
896  }
897  $sql .= " WHERE rowid =".((int) $this->id);
898 
899  $this->db->begin();
900 
901  dol_syslog(__METHOD__, LOG_DEBUG);
902  $resql = $this->db->query($sql);
903  if (!$resql) {
904  $error++;
905  $this->errors[] = 'Error '.$this->db->lasterror();
906  dol_syslog('CurrencyRate::update '.join(',', $this->errors), LOG_ERR);
907  }
908 
909  if (!$error && $trigger) {
910  $result = $this->call_trigger('CURRENCYRATE_MODIFY', $user);
911  if ($result < 0) {
912  $error++;
913  }
914  }
915 
916  // Commit or rollback
917  if ($error) {
918  $this->db->rollback();
919 
920  return -1 * $error;
921  } else {
922  $this->db->commit();
923 
924  return 1;
925  }
926  }
927 
934  public function delete($trigger = true)
935  {
936  global $user;
937 
938  dol_syslog('CurrencyRate::delete', LOG_DEBUG);
939 
940  $error = 0;
941 
942  $this->db->begin();
943 
944  if ($trigger) {
945  $result = $this->call_trigger('CURRENCYRATE_DELETE', $user);
946  if ($result < 0) {
947  $error++;
948  }
949  }
950 
951  if (!$error) {
952  $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
953  $sql .= ' WHERE rowid='.((int) $this->id);
954 
955  dol_syslog(__METHOD__, LOG_DEBUG);
956  $resql = $this->db->query($sql);
957  if (!$resql) {
958  $error++;
959  $this->errors[] = 'Error '.$this->db->lasterror();
960  dol_syslog('CurrencyRate::delete '.join(',', $this->errors), LOG_ERR);
961  }
962  }
963 
964  // Commit or rollback
965  if ($error) {
966  $this->db->rollback();
967 
968  return -1 * $error;
969  } else {
970  $this->db->commit();
971 
972  return 1;
973  }
974  }
975 }
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($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.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
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.
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).
Definition: geturl.lib.php:41
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:123
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge,...