dolibarr  19.0.0-dev
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  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
30 {
34  public $db;
35 
39  public $error = '';
40 
44  public $errors = array();
45 
49  public $rowid;
50 
54  public $fk_pcg_version;
55 
59  public $pcg_type;
60 
64  public $numero;
65 
69  public $label;
70 
74  public $account_number;
75 
79  public $account_parent;
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, numero, label)";
151  $sql .= " VALUES ('".$this->db->idate($now)."',".((int) $user->id).",'".$this->db->escape($this->numero)."','".$this->db->escape($this->label)."')";
152 
153  dol_syslog(get_class($this)."::create", LOG_DEBUG);
154  $resql = $this->db->query($sql);
155  if ($resql) {
156  $id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_system");
157 
158  if ($id > 0) {
159  $this->rowid = $id;
160  $result = $this->rowid;
161  } else {
162  $result = - 2;
163  $this->error = "AccountancySystem::Create Error $result";
164  dol_syslog($this->error, LOG_ERR);
165  }
166  } else {
167  $result = - 1;
168  $this->error = "AccountancySystem::Create Error $result";
169  dol_syslog($this->error, LOG_ERR);
170  }
171 
172  return $result;
173  }
174 }
$object ref
Definition: info.php:78
Class to manage accountancy systems.
fetch($rowid=0, $ref='')
Load record in memory.
create($user)
Insert accountancy system name into database.
__construct($db)
Constructor.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
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.