dolibarr  7.0.0-beta
accountingjournal.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
28 {
29  public $element='accounting_journal';
30  public $table_element='accounting_journal';
31  public $fk_element = '';
32  public $ismultientitymanaged = 0; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
33  public $picto = 'generic';
34 
35  var $rowid;
36 
37  public $code;
38  public $label;
39  public $nature; // 0:various operations, 1:sale, 2:purchase, 3:bank, 4:expense-report, 9: has-new
40  public $active;
41 
42  public $lines;
43 
49  function __construct($db) {
50  $this->db = $db;
51  }
52 
60  function fetch($rowid = null, $journal_code = null)
61  {
62  if ($rowid || $journal_code)
63  {
64  $sql = "SELECT rowid, code, label, nature, active";
65  $sql.= " FROM ".MAIN_DB_PREFIX."accounting_journal";
66  $sql .= " WHERE";
67  if ($rowid) {
68  $sql .= " rowid = " . (int) $rowid;
69  } elseif ($journal_code) {
70  $sql .= " code = '" . $this->db->escape($journal_code) . "'";
71  }
72 
73  dol_syslog(get_class($this)."::fetch sql=" . $sql, LOG_DEBUG);
74  $result = $this->db->query($sql);
75  if ($result)
76  {
77  $obj = $this->db->fetch_object($result);
78 
79  if ($obj) {
80  $this->id = $obj->rowid;
81  $this->rowid = $obj->rowid;
82 
83  $this->code = $obj->code;
84  $this->ref = $obj->code;
85  $this->label = $obj->label;
86  $this->nature = $obj->nature;
87  $this->active = $obj->active;
88 
89  return $this->id;
90  } else {
91  return 0;
92  }
93  }
94  else
95  {
96  $this->error = "Error " . $this->db->lasterror();
97  $this->errors[] = "Error " . $this->db->lasterror();
98  }
99  }
100  return -1;
101  }
102 
115  function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') {
116  $sql = "SELECT rowid, code, label, nature, active";
117  $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
118  // Manage filter
119  $sqlwhere = array();
120  if (count($filter) > 0) {
121  foreach ( $filter as $key => $value ) {
122  if ($key == 't.code' || $key == 't.label' || $key == 't.nature') {
123  $sqlwhere[] = $key . '\'' . $this->db->escape($value) . '\'';
124  } elseif ($key == 't.rowid' || $key == 't.active') {
125  $sqlwhere[] = $key . '=' . $value;
126  }
127  }
128  }
129  $sql .= ' WHERE 1 = 1';
130  $sql .= " AND entity IN (" . getEntity('accountancy') . ")";
131  if (count($sqlwhere) > 0) {
132  $sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere);
133  }
134 
135  if (! empty($sortfield)) {
136  $sql .= $this->db->order($sortfield, $sortorder);
137  }
138  if (! empty($limit)) {
139  $sql .= ' ' . $this->db->plimit($limit + 1, $offset);
140  }
141  $this->lines = array();
142 
143  dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG);
144  $resql = $this->db->query($sql);
145  if ($resql) {
146  $num = $this->db->num_rows($resql);
147 
148  while ( $obj = $this->db->fetch_object($resql) ) {
149  $line = new self($this->db);
150 
151  $line->id = $obj->rowid;
152  $line->code = $obj->code;
153  $line->label = $obj->label;
154  $line->nature = $obj->nature;
155  $line->active = $obj->active;
156 
157  $this->lines[] = $line;
158  }
159 
160  $this->db->free($resql);
161 
162  return $num;
163  } else {
164  $this->errors[] = 'Error ' . $this->db->lasterror();
165  dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
166 
167  return - 1;
168  }
169  }
170 
181  function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle='',$notooltip=0)
182  {
183  global $langs, $conf, $user;
184 
185  if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
186 
187  $result = '';
188 
189  $url = DOL_URL_ROOT . '/accountancy/admin/journals_list.php?id=35';
190 
191  $label = '<u>' . $langs->trans("ShowAccountingJournal") . '</u>';
192  if (! empty($this->code))
193  $label .= '<br><b>'.$langs->trans('Code') . ':</b> ' . $this->code;
194  if (! empty($this->label))
195  $label .= '<br><b>'.$langs->trans('Label') . ':</b> ' . $this->label;
196  if ($moretitle) $label.=' - '.$moretitle;
197 
198  $linkclose='';
199  if (empty($notooltip))
200  {
201  if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
202  {
203  $label=$langs->trans("ShowAccoutingJournal");
204  $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
205  }
206  $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
207  $linkclose.=' class="classfortooltip"';
208  }
209 
210  $linkstart='<a href="'.$url.'"';
211  $linkstart.=$linkclose.'>';
212  $linkend='</a>';
213 
214  if ($nourl)
215  {
216  $linkstart = '';
217  $linkclose = '';
218  $linkend = '';
219  }
220 
221  $label_link = $this->code;
222  if ($withlabel) $label_link .= ' - ' . $this->label;
223 
224  $result .= $linkstart;
225  if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
226  if ($withpicto != 2) $result.= $label_link;
227  $result .= $linkend;
228 
229  return $result;
230  }
231 
238  function getLibType($mode=0)
239  {
240  return $this->LibType($this->nature,$mode);
241  }
242 
250  function LibType($nature,$mode=0)
251  {
252  global $langs;
253 
254  $langs->load("accountancy");
255 
256  if ($mode == 0)
257  {
258  $prefix='';
259  if ($nature == 9) return $langs->trans('AccountingJournalType9');
260  if ($nature == 5) return $langs->trans('AccountingJournalType5');
261  if ($nature == 4) return $langs->trans('AccountingJournalType4');
262  if ($nature == 3) return $langs->trans('AccountingJournalType3');
263  if ($nature == 2) return $langs->trans('AccountingJournalType2');
264  if ($nature == 1) return $langs->trans('AccountingJournalType1');
265  }
266  if ($mode == 1)
267  {
268  if ($nature == 9) return $langs->trans('AccountingJournalType9');
269  if ($nature == 5) return $langs->trans('AccountingJournalType5');
270  if ($nature == 4) return $langs->trans('AccountingJournalType4');
271  if ($nature == 3) return $langs->trans('AccountingJournalType3');
272  if ($nature == 2) return $langs->trans('AccountingJournalType2');
273  if ($nature == 1) return $langs->trans('AccountingJournalType1');
274  }
275  }
276 }
getNomUrl($withpicto=0, $withlabel=0, $nourl=0, $moretitle='', $notooltip=0)
Return clicable name (with picto eventually)
__construct($db)
Constructor.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
getLibType($mode=0)
Retourne le libelle du statut d'un user (actif, inactif)
fetchAll($sortorder= '', $sortfield= '', $limit=0, $offset=0, array $filter=array(), $filtermode= 'AND')
Load object in memory from the database.
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
LibType($nature, $mode=0)
Return type of an accounting journal.
fetch($rowid=null, $journal_code=null)
Load an object from 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
Class to manage accounting accounts.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)