37 public $picto =
'generic';
95 if (isset($this->label)) {
96 $this->label = trim($this->label);
100 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_categ (";
103 $sql .=
") VALUES (";
104 $sql .=
" ".(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'");
105 $sql .=
", ".((int) $conf->entity);
110 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
111 $resql = $this->db->query($sql);
114 $this->errors[] =
"Error ".$this->db->lasterror();
118 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"bank_categ");
123 foreach ($this->errors as $errmsg) {
124 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
125 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
127 $this->db->rollback();
149 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_categ as t";
150 $sql .=
" WHERE t.rowid = ".((int) $id);
151 $sql .=
" AND t.entity = ".$conf->entity;
153 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
154 $resql = $this->db->query($sql);
156 if ($this->db->num_rows($resql)) {
157 $obj = $this->db->fetch_object($resql);
159 $this->
id = $obj->rowid;
160 $this->label = $obj->label;
162 $this->db->free($resql);
166 $this->error =
"Error ".$this->db->lasterror();
184 if (isset($this->label)) {
185 $this->label = trim($this->label);
192 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"bank_categ SET";
193 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
194 $sql .=
" WHERE rowid=".((int) $this->
id);
195 $sql .=
" AND entity = ".$conf->entity;
199 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
200 $resql = $this->db->query($sql);
203 $this->errors[] =
"Error ".$this->db->lasterror();
208 foreach ($this->errors as $errmsg) {
209 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
210 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
212 $this->db->rollback();
227 public function delete(
User $user, $notrigger = 0)
236 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
237 $sql .=
" WHERE fk_categorie = ".((int) $this->
id);
239 $resql = $this->db->query($sql);
242 $this->errors[] =
"Error ".$this->db->lasterror();
248 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_class";
249 $sql .=
" WHERE fk_categ = ".((int) $this->
id);
251 $resql = $this->db->query($sql);
254 $this->errors[] =
"Error ".$this->db->lasterror();
260 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_categ";
261 $sql .=
" WHERE rowid=".((int) $this->
id);
263 $resql = $this->db->query($sql);
266 $this->errors[] =
"Error ".$this->db->lasterror();
272 foreach ($this->errors as $errmsg) {
273 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
274 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
276 $this->db->rollback();
305 $object->context[
'createfromclone'] =
'createfromclone';
306 $result =
$object->create($user);
314 unset(
$object->context[
'createfromclone']);
321 $this->db->rollback();
337 $sql =
"SELECT rowid, label FROM ".MAIN_DB_PREFIX.
"bank_categ WHERE entity = ".$conf->entity.
" ORDER BY label";
338 $resql = $this->db->query($sql);
341 while ($obj = $this->db->fetch_object($resql)) {
343 $tmp->id = $obj->rowid;
344 $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.
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.