26require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
46 public $errors = array();
51 public $element =
'c_accounting_report';
56 public $table_element =
'c_accounting_report';
107 public function create($user, $notrigger = 0)
109 global
$conf, $langs;
113 if (isset($this->code)) {
114 $this->code = trim($this->code);
116 if (isset($this->label)) {
117 $this->label = trim($this->label);
119 if (isset($this->fk_country)) {
120 $this->fk_country = (int) $this->fk_country;
122 if (isset($this->
active)) {
130 $sql =
"INSERT INTO " . $this->db->prefix() . $this->table_element .
" (";
131 if ($this->rowid > 0) {
136 $sql .=
"fk_country, ";
139 $sql .=
") VALUES (";
140 if ($this->rowid > 0) {
141 $sql .=
" " . ((int) $this->rowid) .
",";
143 $sql .=
" " . (!isset($this->code) ?
"NULL" :
"'" . $this->db->escape($this->code) .
"'") .
",";
144 $sql .=
" " . (!isset($this->label) ?
'NULL' :
"'" . $this->db->escape($this->label) .
"'") .
",";
145 $sql .=
" " . (!isset($this->fk_country) ?
'NULL' : ((int) $this->fk_country)) .
",";
146 $sql .=
" " . (!isset($this->
active) ?
'NULL' : ((int) $this->
active));
147 $sql .=
", " . ((int)
$conf->entity);
152 dol_syslog(get_class($this) .
"::create", LOG_DEBUG);
153 $resql = $this->db->query($sql);
156 $this->errors[] =
"Error " . $this->db->lasterror();
161 foreach ($this->errors as $errmsg) {
162 dol_syslog(get_class($this) .
"::create " . $errmsg, LOG_ERR);
163 $this->error .= ($this->error ?
', ' . $errmsg : $errmsg);
165 $this->db->rollback();
182 public function fetch($id, $code =
'', $label =
'')
188 $sql .=
" t.fk_country,";
190 $sql .=
" FROM " . $this->db->prefix() . $this->table_element .
" as t";
192 $sql .=
" WHERE t.rowid = " . ((int) $id);
194 $sql .=
" WHERE t.entity IN (" .
getEntity(
'c_accounting_report') .
")";
196 $sql .=
" AND t.code = '" . $this->db->escape($code) .
"'";
198 $sql .=
" AND t.label = '" . $this->db->escape($label) .
"'";
202 dol_syslog(get_class($this) .
"::fetch", LOG_DEBUG);
203 $resql = $this->db->query($sql);
205 if ($this->db->num_rows($resql)) {
206 $obj = $this->db->fetch_object($resql);
208 $this->
id = $obj->rowid;
209 $this->code = $obj->code;
210 $this->label = $obj->label;
211 $this->fk_country = $obj->fk_country;
212 $this->
active = $obj->active;
214 $this->db->free($resql);
218 $this->error =
"Error " . $this->db->lasterror();
231 public function update($user =
null, $notrigger = 0)
236 if (isset($this->code)) {
237 $this->code = trim($this->code);
239 if (isset($this->label)) {
240 $this->label = trim($this->label);
242 if (isset($this->fk_country)) {
243 $this->fk_country = (int) $this->fk_country;
245 if (isset($this->
active)) {
254 $sql =
"UPDATE " . $this->db->prefix() . $this->table_element .
" SET";
255 $sql .=
" code=" . (isset($this->code) ?
"'" . $this->db->escape($this->code) .
"'" :
"null") .
",";
256 $sql .=
" label=" . (isset($this->label) ?
"'" . $this->db->escape($this->label) .
"'" :
"null") .
",";
257 $sql .=
" fk_country=" . (isset($this->fk_country) ? ((int) $this->fk_country) :
"null") .
",";
258 $sql .=
" active=" . (isset($this->
active) ? ((int) $this->
active) :
"null");
259 $sql .=
" WHERE rowid=" . ((int) $this->
id);
263 dol_syslog(get_class($this) .
"::update", LOG_DEBUG);
264 $resql = $this->db->query($sql);
267 $this->errors[] =
"Error " . $this->db->lasterror();
272 foreach ($this->errors as $errmsg) {
273 dol_syslog(get_class($this) .
"::update " . $errmsg, LOG_ERR);
274 $this->error .= ($this->error ?
', ' . $errmsg : $errmsg);
276 $this->db->rollback();
292 public function delete($user, $notrigger = 0)
294 global
$conf, $langs;
297 $sql =
"DELETE FROM " . $this->db->prefix() . $this->table_element;
298 $sql .=
" WHERE rowid=" . ((int) $this->
id);
302 dol_syslog(get_class($this) .
"::delete", LOG_DEBUG);
303 $resql = $this->db->query($sql);
306 $this->errors[] =
"Error " . $this->db->lasterror();
311 foreach ($this->errors as $errmsg) {
312 dol_syslog(get_class($this) .
"::delete " . $errmsg, LOG_ERR);
313 $this->error .= ($this->error ?
', ' . $errmsg : $errmsg);
315 $this->db->rollback();
Class to manage reports for accounting categories.
update($user=null, $notrigger=0)
Update object into database.
__construct($db)
Constructor.
create($user, $notrigger=0)
Create object into database.
fetch($id, $code='', $label='')
Load object in memory from database.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.