38 public $picto =
'generic';
96 if (isset($this->label)) {
97 $this->label = trim($this->label);
101 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"category_bank (";
104 $sql .=
") VALUES (";
105 $sql .=
" ".(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'");
106 $sql .=
", ".((int) $conf->entity);
111 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
112 $resql = $this->db->query($sql);
115 $this->errors[] =
"Error ".$this->db->lasterror();
119 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"category_bank");
124 foreach ($this->errors as $errmsg) {
125 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
126 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
128 $this->db->rollback();
150 $sql .=
" FROM ".MAIN_DB_PREFIX.
"category_bank as t";
151 $sql .=
" WHERE t.rowid = ".((int) $id);
152 $sql .=
" AND t.entity = ".$conf->entity;
154 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
155 $resql = $this->db->query($sql);
157 if ($this->db->num_rows($resql)) {
158 $obj = $this->db->fetch_object($resql);
160 $this->
id = $obj->rowid;
161 $this->label = $obj->label;
163 $this->db->free($resql);
167 $this->error =
"Error ".$this->db->lasterror();
179 public function update($user =
null, $notrigger = 0)
185 if (isset($this->label)) {
186 $this->label = trim($this->label);
193 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"category_bank SET";
194 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
195 $sql .=
" WHERE rowid=".((int) $this->
id);
196 $sql .=
" AND entity = ".$conf->entity;
200 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
201 $resql = $this->db->query($sql);
204 $this->errors[] =
"Error ".$this->db->lasterror();
209 foreach ($this->errors as $errmsg) {
210 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
211 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
213 $this->db->rollback();
228 public function delete(
User $user, $notrigger = 0)
237 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
238 $sql .=
" WHERE fk_categorie = ".((int) $this->
id);
240 $resql = $this->db->query($sql);
243 $this->errors[] =
"Error ".$this->db->lasterror();
249 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"category_bankline";
250 $sql .=
" WHERE fk_categ = ".((int) $this->
id);
252 $resql = $this->db->query($sql);
255 $this->errors[] =
"Error ".$this->db->lasterror();
261 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"category_bank";
262 $sql .=
" WHERE rowid=".((int) $this->
id);
264 $resql = $this->db->query($sql);
267 $this->errors[] =
"Error ".$this->db->lasterror();
273 foreach ($this->errors as $errmsg) {
274 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
275 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
277 $this->db->rollback();
306 $object->context[
'createfromclone'] =
'createfromclone';
307 $result =
$object->create($user);
315 unset(
$object->context[
'createfromclone']);
322 $this->db->rollback();
338 $sql =
"SELECT rowid, label FROM ".MAIN_DB_PREFIX.
"category_bank WHERE entity = ".$conf->entity.
" ORDER BY label";
339 $resql = $this->db->query($sql);
342 while ($obj = $this->db->fetch_object($resql)) {
344 $tmp->id = $obj->rowid;
345 $tmp->label = $obj->label;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage bank categories.
create(User $user, $notrigger=0)
Create in database.
fetch($id)
Load object in memory from database.
update($user=null, $notrigger=0)
Update 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.