dolibarr 21.0.0-beta
accountancysystem.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
3 * Copyright (C) 2013-2014 Alexandre Spangaro <aspangaro@open-dsi.fr>
4 * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
5 * Copyright (C) 2023-2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 Alexandre Janniaux <alexandre.janniaux@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
32{
36 public $db;
37
41 public $error = '';
42
46 public $errors = array();
47
51 public $id;
52
58 public $rowid;
59
63 public $pcg_version;
64
69 public $ref;
70
74 public $active;
75
79 public $label;
80
86 public function __construct($db)
87 {
88 $this->db = $db;
89 }
90
91
99 public function fetch($rowid = 0, $ref = '')
100 {
101 global $conf;
102
103 if ($rowid > 0 || $ref) {
104 $sql = "SELECT a.rowid, a.pcg_version, a.label, a.active";
105 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_system as a";
106 $sql .= " WHERE";
107 if ($rowid) {
108 $sql .= " a.rowid = ".((int) $rowid);
109 } elseif ($ref) {
110 $sql .= " a.pcg_version = '".$this->db->escape($ref)."'";
111 }
112
113 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
114 $result = $this->db->query($sql);
115 if ($result) {
116 $obj = $this->db->fetch_object($result);
117
118 if ($obj) {
119 $this->id = $obj->rowid;
120 $this->rowid = $obj->rowid;
121 $this->pcg_version = $obj->pcg_version;
122 $this->ref = $obj->pcg_version;
123 $this->label = $obj->label;
124 $this->active = $obj->active;
125
126 return $this->id;
127 } else {
128 return 0;
129 }
130 } else {
131 $this->error = "Error ".$this->db->lasterror();
132 $this->errors[] = "Error ".$this->db->lasterror();
133 }
134 }
135 return -1;
136 }
137
138
145 public function create($user)
146 {
147 $now = dol_now();
148
149 $sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_system";
150 $sql .= " (date_creation, fk_user_author, label, pcg_version, active)";
151 $sql .= " VALUES ('"
152 . $this->db->idate($now) ."',"
153 . ((int) $user->id) .",'"
154 . $this->db->escape($this->label) ."','"
155 . $this->db->escape($this->pcg_version) ."',"
156 . ((int) $this->active) .")";
157
158 dol_syslog(get_class($this)."::create", LOG_DEBUG);
159 $resql = $this->db->query($sql);
160 if ($resql) {
161 $id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_system");
162
163 if ($id > 0) {
164 $this->id = $id;
165 $this->rowid = $id;
166 $result = $this->rowid;
167 } else {
168 $result = - 2;
169 $this->error = "AccountancySystem::Create Error $result: " . $this->db->lasterror();
170 dol_syslog($this->error, LOG_ERR);
171 }
172 } else {
173 $result = - 1;
174 $this->error = "AccountancySystem::Create Error $result: " . $this->db->lasterror();
175 dol_syslog($this->error, LOG_ERR);
176 }
177
178 return $result;
179 }
180}
$object ref
Definition info.php:89
Class to manage accountancy systems.
fetch($rowid=0, $ref='')
Load record in memory.
create($user)
Insert accountancy system name into database.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79