31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
41 public $element =
'multicurrency_rate';
46 public $table_element =
'multicurrency_rate';
61 public $rate_indirect;
71 public $fk_multicurrency;
97 public function create(
User $user,
int $fk_multicurrency, $notrigger = 0)
101 dol_syslog(
'CurrencyRate::create', LOG_DEBUG);
104 $this->rate = (float)
price2num($this->rate);
105 if (empty($this->entity) || $this->entity <= 0) {
106 $this->entity =
$conf->entity;
108 $now = empty($this->date_sync) ?
dol_now() : $this->date_sync;
111 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
"(";
113 $sql .=
' rate_indirect,';
114 $sql .=
' date_sync,';
115 $sql .=
' fk_multicurrency,';
117 $sql .=
') VALUES (';
118 $sql .=
' '.((float) $this->rate).
',';
119 $sql .=
' '.((float) $this->rate_indirect).
',';
120 $sql .=
" '".$this->db->idate($now).
"',";
121 $sql .=
" ".((int) $fk_multicurrency).
",";
122 $sql .=
" ".((int) $this->entity);
128 $resql = $this->db->query($sql);
131 $this->errors[] =
'Error '.$this->db->lasterror();
132 dol_syslog(
'CurrencyRate::create '.implode(
',', $this->errors), LOG_ERR);
136 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
137 $this->fk_multicurrency = $fk_multicurrency;
138 $this->date_sync = $now;
140 if (empty($notrigger)) {
141 $result = $this->
call_trigger(
'CURRENCYRATE_CREATE', $user);
149 $this->db->rollback();
169 $sql =
"SELECT cr.rowid, cr.rate, cr.rate_indirect, cr.date_sync, cr.fk_multicurrency, cr.entity";
170 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" AS cr";
171 $sql .=
" WHERE cr.rowid = ".((int) $id);
174 $resql = $this->db->query($sql);
176 $numrows = $this->db->num_rows($resql);
178 $obj = $this->db->fetch_object($resql);
180 $this->
id = $obj->rowid;
181 $this->rate = $obj->rate;
182 $this->rate_indirect = $obj->rate_indirect;
183 $this->date_sync = $this->db->jdate($obj->date_sync);
184 $this->fk_multicurrency = $obj->fk_multicurrency;
185 $this->entity = $obj->entity;
187 $this->db->free($resql);
195 $this->errors[] =
'Error '.$this->db->lasterror();
196 dol_syslog(
'CurrencyRate::fetch '.implode(
',', $this->errors), LOG_ERR);
213 dol_syslog(
'CurrencyRate::update', LOG_DEBUG);
215 $this->rate = (float)
price2num($this->rate);
218 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
219 $sql .=
"SET rate = ".((float) $this->rate);
220 if (!empty($this->date_sync)) {
221 $sql .=
", date_sync = '".$this->db->idate($this->date_sync).
"'";
223 if (!empty($this->fk_multicurrency)) {
224 $sql .=
', fk_multicurrency = '.((int) $this->fk_multicurrency);
226 $sql .=
" WHERE rowid =".((int) $this->
id);
231 $resql = $this->db->query($sql);
234 $this->errors[] =
'Error '.$this->db->lasterror();
235 dol_syslog(
'CurrencyRate::update '.implode(
',', $this->errors), LOG_ERR);
238 if (!$error && empty($notrigger)) {
239 $result = $this->
call_trigger(
'CURRENCYRATE_MODIFY', $user);
247 $this->db->rollback();
264 public function delete(
User $user, $notrigger = 0)
266 dol_syslog(
'CurrencyRate::delete', LOG_DEBUG);
272 if (empty($notrigger)) {
273 $result = $this->
call_trigger(
'CURRENCYRATE_DELETE', $user);
280 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
281 $sql .=
' WHERE rowid='.((int) $this->
id);
284 $resql = $this->db->query($sql);
287 $this->errors[] =
'Error '.$this->db->lasterror();
288 dol_syslog(
'CurrencyRate::delete '.implode(
',', $this->errors), LOG_ERR);
294 $this->db->rollback();
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 ...
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 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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...