46 public $errors = array();
65 public $table_element =
"c_price_global_variable";
85 public function create($user, $notrigger = 0)
92 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
" (";
93 $sql .=
"code, description, value";
95 $sql .=
" ".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"''").
",";
97 $sql .=
" ".((float) $this->value);
103 $resql = $this->db->query($sql);
106 $this->errors[] =
"Error ".$this->db->lasterror();
110 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
125 foreach ($this->errors as $errmsg) {
127 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
129 $this->db->rollback();
146 $sql =
"SELECT code, description, value";
147 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
148 $sql .=
" WHERE rowid = ".((int) $id);
151 $resql = $this->db->query($sql);
153 $obj = $this->db->fetch_object($resql);
156 $this->code = $obj->code;
158 $this->value = $obj->value;
165 $this->error =
"Error ".$this->db->lasterror();
177 public function update($user =
null, $notrigger = 0)
184 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
185 $sql .=
" code = ".(isset($this->code) ?
"'".$this->db->escape($this->code).
"'" :
"''").
",";
186 $sql .=
" description = ".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"''").
",";
187 $sql .=
" value = ".((float) $this->value);
188 $sql .=
" WHERE rowid = ".((int) $this->
id);
193 $resql = $this->db->query($sql);
196 $this->errors[] =
"Error ".$this->db->lasterror();
215 foreach ($this->errors as $errmsg) {
217 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
219 $this->db->rollback();
236 public function delete($rowid, $user, $notrigger = 0)
255 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
256 $sql .=
" WHERE rowid = ".((int) $rowid);
259 $resql = $this->db->query($sql);
262 $this->errors[] =
"Error ".$this->db->lasterror();
268 foreach ($this->errors as $errmsg) {
270 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
272 $this->db->rollback();
304 if (isset($this->code)) {
305 $this->code = trim($this->code);
312 if (empty($this->value) || !is_numeric($this->value)) {
324 $sql =
"SELECT rowid, code, description, value";
325 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
326 $sql .=
" ORDER BY code";
329 $resql = $this->db->query($sql);
333 while ($record = $this->db->fetch_array($resql)) {
335 $variable_obj->id = $record[
"rowid"];
336 $variable_obj->code = $record[
"code"];
337 $variable_obj->description = $record[
"description"];
338 $variable_obj->value = $record[
"value"];
339 $variable_obj->checkParameters();
340 $retarray[] = $variable_obj;
343 $this->db->free($resql);
346 $this->error = $this->db->error();
Class for accessing price global variables table.
update($user=null, $notrigger=0)
Update object into database.
__construct($db)
Constructor.
listGlobalVariables()
List all price global variables.
checkParameters()
Checks if all parameters are in order.
create($user, $notrigger=0)
Create object into database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetch($id)
Load object in memory from the database.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.