25require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
45 public $errors = array();
50 public $element =
'c_accounting_report';
55 public $table_element =
'c_accounting_report';
106 public function create($user, $notrigger = 0)
108 global
$conf, $langs;
112 if (isset($this->code)) {
113 $this->code = trim($this->code);
115 if (isset($this->label)) {
116 $this->label = trim($this->label);
118 if (isset($this->fk_country)) {
119 $this->fk_country = (int) $this->fk_country;
121 if (isset($this->active)) {
122 $this->active = (int) $this->active;
129 $sql =
"INSERT INTO " . $this->db->prefix() . $this->table_element .
" (";
130 if ($this->rowid > 0) {
135 $sql .=
"fk_country, ";
138 $sql .=
") VALUES (";
139 if ($this->rowid > 0) {
140 $sql .=
" " . ((int) $this->rowid) .
",";
142 $sql .=
" " . (!isset($this->code) ?
"NULL" :
"'" . $this->db->escape($this->code) .
"'") .
",";
143 $sql .=
" " . (!isset($this->label) ?
'NULL' :
"'" . $this->db->escape($this->label) .
"'") .
",";
144 $sql .=
" " . (!isset($this->fk_country) ?
'NULL' : ((int) $this->fk_country)) .
",";
145 $sql .=
" " . (!isset($this->active) ?
'NULL' : ((int) $this->active));
146 $sql .=
", " . ((int)
$conf->entity);
151 dol_syslog(get_class($this) .
"::create", LOG_DEBUG);
152 $resql = $this->db->query($sql);
155 $this->errors[] =
"Error " . $this->db->lasterror();
160 foreach ($this->errors as $errmsg) {
161 dol_syslog(get_class($this) .
"::create " . $errmsg, LOG_ERR);
162 $this->error .= ($this->error ?
', ' . $errmsg : $errmsg);
164 $this->db->rollback();
181 public function fetch($id, $code =
'', $label =
'')
187 $sql .=
" t.fk_country,";
189 $sql .=
" FROM " . $this->db->prefix() . $this->table_element .
" as t";
191 $sql .=
" WHERE t.rowid = " . ((int) $id);
193 $sql .=
" WHERE t.entity IN (" .
getEntity(
'c_accounting_report') .
")";
195 $sql .=
" AND t.code = '" . $this->db->escape($code) .
"'";
197 $sql .=
" AND t.label = '" . $this->db->escape($label) .
"'";
201 dol_syslog(get_class($this) .
"::fetch", LOG_DEBUG);
202 $resql = $this->db->query($sql);
204 if ($this->db->num_rows($resql)) {
205 $obj = $this->db->fetch_object($resql);
207 $this->
id = $obj->rowid;
208 $this->code = $obj->code;
209 $this->label = $obj->label;
210 $this->fk_country = $obj->fk_country;
211 $this->active = $obj->active;
213 $this->db->free($resql);
217 $this->error =
"Error " . $this->db->lasterror();
230 public function update($user =
null, $notrigger = 0)
232 global
$conf, $langs;
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)) {
246 $this->active = (int) $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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...