dolibarr 19.0.4
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 Frédéric France <frederic.france@netlogic.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
31{
35 public $db;
36
40 public $error = '';
41
45 public $errors = array();
46
50 public $id;
51
57 public $rowid;
58
62 public $fk_pcg_version;
63
67 public $pcg_version;
68
72 public $ref;
73
77 public $active;
78
82 public $pcg_type;
83
87 public $numero;
88
92 public $label;
93
97 public $account_number;
98
102 public $account_parent;
103
109 public function __construct($db)
110 {
111 $this->db = $db;
112 }
113
114
122 public function fetch($rowid = 0, $ref = '')
123 {
124 global $conf;
125
126 if ($rowid > 0 || $ref) {
127 $sql = "SELECT a.rowid, a.pcg_version, a.label, a.active";
128 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_system as a";
129 $sql .= " WHERE";
130 if ($rowid) {
131 $sql .= " a.rowid = ".((int) $rowid);
132 } elseif ($ref) {
133 $sql .= " a.pcg_version = '".$this->db->escape($ref)."'";
134 }
135
136 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
137 $result = $this->db->query($sql);
138 if ($result) {
139 $obj = $this->db->fetch_object($result);
140
141 if ($obj) {
142 $this->id = $obj->rowid;
143 $this->rowid = $obj->rowid;
144 $this->pcg_version = $obj->pcg_version;
145 $this->ref = $obj->pcg_version;
146 $this->label = $obj->label;
147 $this->active = $obj->active;
148
149 return $this->id;
150 } else {
151 return 0;
152 }
153 } else {
154 $this->error = "Error ".$this->db->lasterror();
155 $this->errors[] = "Error ".$this->db->lasterror();
156 }
157 }
158 return -1;
159 }
160
161
168 public function create($user)
169 {
170 $now = dol_now();
171
172 $sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_system";
173 $sql .= " (date_creation, fk_user_author, numero, label)";
174 $sql .= " VALUES ('".$this->db->idate($now)."',".((int) $user->id).",'".$this->db->escape($this->numero)."','".$this->db->escape($this->label)."')";
175
176 dol_syslog(get_class($this)."::create", LOG_DEBUG);
177 $resql = $this->db->query($sql);
178 if ($resql) {
179 $id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_system");
180
181 if ($id > 0) {
182 $this->id = $id;
183 $this->rowid = $id;
184 $result = $this->rowid;
185 } else {
186 $result = - 2;
187 $this->error = "AccountancySystem::Create Error $result";
188 dol_syslog($this->error, LOG_ERR);
189 }
190 } else {
191 $result = - 1;
192 $this->error = "AccountancySystem::Create Error $result";
193 dol_syslog($this->error, LOG_ERR);
194 }
195
196 return $result;
197 }
198}
$object ref
Definition info.php:79
Class to manage accountancy systems.
fetch($rowid=0, $ref='')
Load record in memory.
create($user)
Insert accountancy system name into database.
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.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid
Definition invoice.php:1926