38 public $picto =
'generic';
93 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
95 $catTypeID = $cats->getMapId()[Categorie::TYPE_BANK_LINE];
100 if (isset($this->label)) {
101 $this->label = trim($this->label);
105 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie (";
109 $sql .=
") VALUES (";
110 $sql .=
" ".(!isset($this->label) ?
'NULL' :
"'".$this->db->escape($this->label).
"'");
111 $sql .=
", ".((int) $conf->entity);
112 $sql .=
", ".((int) $catTypeID);
117 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
118 $resql = $this->db->query($sql);
121 $this->errors[] =
"Error ".$this->db->lasterror();
125 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"categorie");
130 foreach ($this->errors as $errmsg) {
131 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
132 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
134 $this->db->rollback();
153 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
155 $catTypeID = $cats->getMapId()[Categorie::TYPE_BANK_LINE];
160 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as t";
161 $sql .=
" WHERE t.rowid = ".((int) $id);
162 $sql .=
" AND t.entity = ".$conf->entity.
" AND t.type = " . ((int) $catTypeID);
164 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
165 $resql = $this->db->query($sql);
167 if ($this->db->num_rows($resql)) {
168 $obj = $this->db->fetch_object($resql);
170 $this->
id = $obj->rowid;
171 $this->label = $obj->label;
173 $this->db->free($resql);
177 $this->error =
"Error ".$this->db->lasterror();
189 public function update($user =
null, $notrigger = 0)
195 if (isset($this->label)) {
196 $this->label = trim($this->label);
203 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"categorie SET";
204 $sql .=
" label=".(isset($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
205 $sql .=
" WHERE rowid=".((int) $this->
id);
206 $sql .=
" AND entity = ".$conf->entity;
210 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
211 $resql = $this->db->query($sql);
214 $this->errors[] =
"Error ".$this->db->lasterror();
219 foreach ($this->errors as $errmsg) {
220 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
221 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
223 $this->db->rollback();
238 public function delete(
User $user, $notrigger = 0)
247 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_account";
248 $sql .=
" WHERE fk_categorie = ".((int) $this->
id);
250 $resql = $this->db->query($sql);
253 $this->errors[] =
"Error ".$this->db->lasterror();
259 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"category_bankline";
260 $sql .=
" WHERE fk_categ = ".((int) $this->
id);
262 $resql = $this->db->query($sql);
265 $this->errors[] =
"Error ".$this->db->lasterror();
271 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie";
272 $sql .=
" WHERE rowid=".((int) $this->
id);
274 $resql = $this->db->query($sql);
277 $this->errors[] =
"Error ".$this->db->lasterror();
283 foreach ($this->errors as $errmsg) {
284 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
285 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
287 $this->db->rollback();
316 $object->context[
'createfromclone'] =
'createfromclone';
317 $result =
$object->create($user);
325 unset(
$object->context[
'createfromclone']);
332 $this->db->rollback();
346 include_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
348 $catTypeID = $cats->getMapId()[Categorie::TYPE_BANK_LINE];
352 $sql =
"SELECT rowid, label FROM ".MAIN_DB_PREFIX.
"categorie WHERE entity = ".$conf->entity.
" AND type = ".((int) $catTypeID).
" ORDER BY label";
353 $resql = $this->db->query($sql);
356 while ($obj = $this->db->fetch_object($resql)) {
358 $tmp->id = $obj->rowid;
359 $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 categories.
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.