dolibarr  16.0.5
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 $rowid;
45 
49  public $fk_pcg_version;
50 
54  public $pcg_type;
55 
59  public $numero;
60 
64  public $label;
65 
69  public $account_number;
70 
74  public $account_parent;
75 
81  public function __construct($db)
82  {
83  $this->db = $db;
84  }
85 
86 
94  public function fetch($rowid = 0, $ref = '')
95  {
96  global $conf;
97 
98  if ($rowid > 0 || $ref) {
99  $sql = "SELECT a.rowid, a.pcg_version, a.label, a.active";
100  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_system as a";
101  $sql .= " WHERE";
102  if ($rowid) {
103  $sql .= " a.rowid = ".((int) $rowid);
104  } elseif ($ref) {
105  $sql .= " a.pcg_version = '".$this->db->escape($ref)."'";
106  }
107 
108  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
109  $result = $this->db->query($sql);
110  if ($result) {
111  $obj = $this->db->fetch_object($result);
112 
113  if ($obj) {
114  $this->id = $obj->rowid;
115  $this->rowid = $obj->rowid;
116  $this->pcg_version = $obj->pcg_version;
117  $this->ref = $obj->pcg_version;
118  $this->label = $obj->label;
119  $this->active = $obj->active;
120 
121  return $this->id;
122  } else {
123  return 0;
124  }
125  } else {
126  $this->error = "Error ".$this->db->lasterror();
127  $this->errors[] = "Error ".$this->db->lasterror();
128  }
129  }
130  return -1;
131  }
132 
133 
140  public function create($user)
141  {
142  $now = dol_now();
143 
144  $sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_system";
145  $sql .= " (date_creation, fk_user_author, numero, label)";
146  $sql .= " VALUES ('".$this->db->idate($now)."',".((int) $user->id).",'".$this->db->escape($this->numero)."','".$this->db->escape($this->label)."')";
147 
148  dol_syslog(get_class($this)."::create", LOG_DEBUG);
149  $resql = $this->db->query($sql);
150  if ($resql) {
151  $id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_system");
152 
153  if ($id > 0) {
154  $this->rowid = $id;
155  $result = $this->rowid;
156  } else {
157  $result = - 2;
158  $this->error = "AccountancySystem::Create Error $result";
159  dol_syslog($this->error, LOG_ERR);
160  }
161  } else {
162  $result = - 1;
163  $this->error = "AccountancySystem::Create Error $result";
164  dol_syslog($this->error, LOG_ERR);
165  }
166 
167  return $result;
168  }
169 }
db
$conf db
API class for accounts.
Definition: inc.php:41
AccountancySystem\__construct
__construct($db)
Constructor.
Definition: accountancysystem.class.php:81
AccountancySystem\fetch
fetch($rowid=0, $ref='')
Load record in memory.
Definition: accountancysystem.class.php:94
ref
$object ref
Definition: info.php:77
rowid
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
Definition: email_expire_services_to_representatives.php:79
AccountancySystem\create
create($user)
Insert accountancy system name into database.
Definition: accountancysystem.class.php:140
AccountancySystem
Class to manage accountancy systems.
Definition: accountancysystem.class.php:29
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742