36 public $picto =
'generic';
94 if (isset($this->label)) {
95 $this->label = trim($this->label);
99 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_categ (";
102 $sql .=
") VALUES (";
103 $sql .=
" ".(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'");
104 $sql .=
", ".((int) $conf->entity);
109 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
110 $resql = $this->db->query($sql);
113 $this->errors[] =
"Error ".$this->db->lasterror();
117 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_categ");
122 foreach ($this->errors as $errmsg) {
123 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
124 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
126 $this->db->rollback();
148 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_categ as t";
149 $sql .=
" WHERE t.rowid = ".((int) $id);
150 $sql .=
" AND t.entity = ".$conf->entity;
152 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
153 $resql = $this->db->query($sql);
155 if ($this->db->num_rows($resql)) {
156 $obj = $this->db->fetch_object($resql);
158 $this->
id = $obj->rowid;
159 $this->label = $obj->label;
161 $this->db->free($resql);
165 $this->error =
"Error ".$this->db->lasterror();
183 if (isset($this->label)) {
184 $this->label = trim($this->label);
191 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_categ SET";
192 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
193 $sql .=
" WHERE rowid=".((int) $this->
id);
194 $sql .=
" AND entity = ".$conf->entity;
198 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
199 $resql = $this->db->query($sql);
202 $this->errors[] =
"Error ".$this->db->lasterror();
207 foreach ($this->errors as $errmsg) {
208 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
209 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
211 $this->db->rollback();
226 public function delete(
User $user, $notrigger = 0)
235 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
236 $sql .=
" WHERE fk_categorie = ".((int) $this->
id);
238 $resql = $this->db->query($sql);
241 $this->errors[] =
"Error ".$this->db->lasterror();
247 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_class";
248 $sql .=
" WHERE fk_categ = ".((int) $this->
id);
250 $resql = $this->db->query($sql);
253 $this->errors[] =
"Error ".$this->db->lasterror();
259 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_categ";
260 $sql .=
" WHERE rowid=".((int) $this->
id);
262 $resql = $this->db->query($sql);
265 $this->errors[] =
"Error ".$this->db->lasterror();
271 foreach ($this->errors as $errmsg) {
272 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
273 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
275 $this->db->rollback();
299 $object->fetch($fromid);
304 $object->context[
'createfromclone'] =
'createfromclone';
305 $result = $object->create($user);
309 $this->error = $object->error;
313 unset($object->context[
'createfromclone']);
320 $this->db->rollback();
336 $sql =
"SELECT rowid, label FROM ".MAIN_DB_PREFIX.
"bank_categ WHERE entity = ".$conf->entity.
" ORDER BY label";
337 $resql = $this->db->query($sql);
340 while ($obj = $this->db->fetch_object($resql)) {
342 $tmp->id = $obj->rowid;
343 $tmp->label = $obj->label;
Class to manage bank categories.
create(User $user, $notrigger=0)
Create in database.
update(User $user=null, $notrigger=0)
Update database.
fetch($id)
Load object in memory from database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
__construct(DoliDB $db)
Constructor.
fetchAll()
Returns all bank categories.
initAsSpecimen()
Initialise an instance with random values.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.