32require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
42 public $element =
'multicurrency_rate';
47 public $table_element =
'multicurrency_rate';
72 public $fk_multicurrency;
98 public function create(
User $user,
int $fk_multicurrency, $notrigger = 0)
102 dol_syslog(
'CurrencyRate::create', LOG_DEBUG);
105 $this->rate = (float)
price2num($this->rate);
106 if (empty($this->entity) || $this->entity <= 0) {
107 $this->entity =
$conf->entity;
109 $now = empty($this->date_sync) ?
dol_now() : $this->date_sync;
112 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
"(";
114 $sql .=
' rate_direct,';
115 $sql .=
' date_sync,';
116 $sql .=
' fk_multicurrency,';
118 $sql .=
') VALUES (';
119 $sql .=
' '.((float) $this->rate).
',';
120 $sql .=
' '.((float) $this->rate_direct).
',';
121 $sql .=
" '".$this->db->idate($now).
"',";
122 $sql .=
" ".((int) $fk_multicurrency).
",";
123 $sql .=
" ".((int) $this->entity);
129 $resql = $this->db->query($sql);
132 $this->errors[] =
'Error '.$this->db->lasterror();
133 dol_syslog(
'CurrencyRate::create '.implode(
',', $this->errors), LOG_ERR);
137 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
138 $this->fk_multicurrency = $fk_multicurrency;
139 $this->date_sync = $now;
141 if (empty($notrigger)) {
142 $result = $this->call_trigger(
'CURRENCYRATE_CREATE', $user);
150 $this->db->rollback();
170 $sql =
"SELECT cr.rowid, cr.rate, cr.rate_direct, cr.date_sync, cr.fk_multicurrency, cr.entity";
171 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" AS cr";
172 $sql .=
" WHERE cr.rowid = ".((int) $id);
175 $resql = $this->db->query($sql);
177 $numrows = $this->db->num_rows($resql);
179 $obj = $this->db->fetch_object($resql);
181 $this->
id = $obj->rowid;
182 $this->rate = $obj->rate;
183 $this->rate_direct = $obj->rate_direct;
184 $this->date_sync = $this->db->jdate($obj->date_sync);
185 $this->fk_multicurrency = $obj->fk_multicurrency;
186 $this->entity = $obj->entity;
188 $this->db->free($resql);
196 $this->errors[] =
'Error '.$this->db->lasterror();
197 dol_syslog(
'CurrencyRate::fetch '.implode(
',', $this->errors), LOG_ERR);
214 dol_syslog(
'CurrencyRate::update', LOG_DEBUG);
216 $this->rate = (float)
price2num($this->rate);
219 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
220 $sql .=
"SET rate = ".((float) $this->rate);
221 if (!empty($this->rate_direct)) {
222 $sql .=
", rate_direct = ".((float) $this->rate_direct);
224 if (!empty($this->date_sync)) {
225 $sql .=
", date_sync = '".$this->db->idate($this->date_sync).
"'";
227 if (!empty($this->fk_multicurrency)) {
228 $sql .=
', fk_multicurrency = '.((int) $this->fk_multicurrency);
230 $sql .=
" WHERE rowid =".((int) $this->
id);
235 $resql = $this->db->query($sql);
238 $this->errors[] =
'Error '.$this->db->lasterror();
239 dol_syslog(
'CurrencyRate::update '.implode(
',', $this->errors), LOG_ERR);
242 if (!$error && empty($notrigger)) {
243 $result = $this->call_trigger(
'CURRENCYRATE_MODIFY', $user);
251 $this->db->rollback();
268 public function delete(
User $user, $notrigger = 0)
270 dol_syslog(
'CurrencyRate::delete', LOG_DEBUG);
276 if (empty($notrigger)) {
277 $result = $this->call_trigger(
'CURRENCYRATE_DELETE', $user);
284 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
285 $sql .=
' WHERE rowid='.((int) $this->
id);
288 $resql = $this->db->query($sql);
291 $this->errors[] =
'Error '.$this->db->lasterror();
292 dol_syslog(
'CurrencyRate::delete '.implode(
',', $this->errors), LOG_ERR);
298 $this->db->rollback();
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.
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.