dolibarr  7.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@zendsi.com>
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 <http://www.gnu.org/licenses/>.
18  */
19 
30 {
31  var $db;
32  var $error;
33  var $rowid;
34  var $fk_pcg_version;
35  var $pcg_type;
36  var $pcg_subtype;
37  var $label;
38  var $account_number;
39  var $account_parent;
40 
46  function __construct($db) {
47  $this->db = $db;
48  }
49 
50 
58  function fetch($rowid = 0, $ref = '')
59  {
60  global $conf;
61 
62  if ($rowid > 0 || $ref)
63  {
64  $sql = "SELECT a.pcg_version, a.label, a.active";
65  $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_system as a";
66  $sql .= " WHERE";
67  if ($rowid) {
68  $sql .= " a.rowid = '" . $rowid . "'";
69  } elseif ($ref) {
70  $sql .= " a.pcg_version = '" . $ref . "'";
71  }
72 
73  dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG);
74  $result = $this->db->query($sql);
75  if ($result) {
76  $obj = $this->db->fetch_object($result);
77 
78  if ($obj) {
79  $this->id = $obj->rowid;
80  $this->rowid = $obj->rowid;
81  $this->pcg_version = $obj->pcg_version;
82  $this->ref = $obj->pcg_version;
83  $this->label = $obj->label;
84  $this->active = $obj->active;
85 
86  return $this->id;
87  } else {
88  return 0;
89  }
90  } else {
91  $this->error = "Error " . $this->db->lasterror();
92  $this->errors[] = "Error " . $this->db->lasterror();
93  }
94  }
95  return - 1;
96  }
97 
98 
105  function create($user) {
106  $now = dol_now();
107 
108  $sql = "INSERT INTO " . MAIN_DB_PREFIX . "accounting_system";
109  $sql .= " (date_creation, fk_user_author, numero, label)";
110  $sql .= " VALUES ('" . $this->db->idate($now) . "'," . $user->id . ",'" . $this->db->escape($this->numero) . "','" . $this->db->escape($this->label) . "')";
111 
112  dol_syslog(get_class($this) . "::create sql=" . $sql, LOG_DEBUG);
113  $resql = $this->db->query($sql);
114  if ($resql) {
115  $id = $this->db->last_insert_id(MAIN_DB_PREFIX . "accounting_system");
116 
117  if ($id > 0) {
118  $this->rowid = $id;
119  $result = $this->rowid;
120  } else {
121  $result = - 2;
122  $this->error = "AccountancySystem::Create Erreur $result";
123  dol_syslog($this->error, LOG_ERR);
124  }
125  } else {
126  $result = - 1;
127  $this->error = "AccountancySystem::Create Erreur $result";
128  dol_syslog($this->error, LOG_ERR);
129  }
130 
131  return $result;
132  }
133 }
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
__construct($db)
Constructor.
dol_now($mode='gmt')
Return date for now.
Class to manage accountancy systems.
create($user)
Insert accountancy system name into database.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
fetch($rowid=0, $ref= '')
Load record in memory.