dolibarr  9.0.0
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 {
32  public $element='accounting_journal';
33 
37  public $table_element='accounting_journal';
38 
42  public $fk_element = '';
43 
48  public $ismultientitymanaged = 0;
49 
53  public $picto = 'generic';
54 
58  public $rowid;
59 
60  public $code;
61 
65  public $label;
66 
67  public $nature; // 1:various operations, 2:sale, 3:purchase, 4:bank, 5:expense-report, 8:inventory, 9: has-new
68  public $active;
69 
70  public $lines;
71 
77  function __construct($db)
78  {
79  $this->db = $db;
80  }
81 
89  function fetch($rowid = null, $journal_code = null)
90  {
91  global $conf;
92 
93  if ($rowid || $journal_code)
94  {
95  $sql = "SELECT rowid, code, label, nature, active";
96  $sql.= " FROM ".MAIN_DB_PREFIX."accounting_journal";
97  $sql .= " WHERE";
98  if ($rowid) {
99  $sql .= " rowid = " . (int) $rowid;
100  }
101  elseif ($journal_code)
102  {
103  $sql .= " code = '" . $this->db->escape($journal_code) . "'";
104  $sql .= " AND entity = " . $conf->entity;
105  }
106 
107  dol_syslog(get_class($this)."::fetch sql=" . $sql, LOG_DEBUG);
108  $result = $this->db->query($sql);
109  if ($result)
110  {
111  $obj = $this->db->fetch_object($result);
112 
113  if ($obj) {
114  $this->id = $obj->rowid;
115  $this->rowid = $obj->rowid;
116 
117  $this->code = $obj->code;
118  $this->ref = $obj->code;
119  $this->label = $obj->label;
120  $this->nature = $obj->nature;
121  $this->active = $obj->active;
122 
123  return $this->id;
124  } else {
125  return 0;
126  }
127  }
128  else
129  {
130  $this->error = "Error " . $this->db->lasterror();
131  $this->errors[] = "Error " . $this->db->lasterror();
132  }
133  }
134  return -1;
135  }
136 
149  function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
150  {
151  $sql = "SELECT rowid, code, label, nature, active";
152  $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
153  // Manage filter
154  $sqlwhere = array();
155  if (count($filter) > 0) {
156  foreach ( $filter as $key => $value ) {
157  if ($key == 't.code' || $key == 't.label' || $key == 't.nature') {
158  $sqlwhere[] = $key . '\'' . $this->db->escape($value) . '\'';
159  } elseif ($key == 't.rowid' || $key == 't.active') {
160  $sqlwhere[] = $key . '=' . $value;
161  }
162  }
163  }
164  $sql .= ' WHERE 1 = 1';
165  $sql .= " AND entity IN (" . getEntity('accountancy') . ")";
166  if (count($sqlwhere) > 0) {
167  $sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere);
168  }
169 
170  if (! empty($sortfield)) {
171  $sql .= $this->db->order($sortfield, $sortorder);
172  }
173  if (! empty($limit)) {
174  $sql .= ' ' . $this->db->plimit($limit + 1, $offset);
175  }
176  $this->lines = array();
177 
178  dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG);
179  $resql = $this->db->query($sql);
180  if ($resql) {
181  $num = $this->db->num_rows($resql);
182 
183  while ( $obj = $this->db->fetch_object($resql) ) {
184  $line = new self($this->db);
185 
186  $line->id = $obj->rowid;
187  $line->code = $obj->code;
188  $line->label = $obj->label;
189  $line->nature = $obj->nature;
190  $line->active = $obj->active;
191 
192  $this->lines[] = $line;
193  }
194 
195  $this->db->free($resql);
196 
197  return $num;
198  } else {
199  $this->errors[] = 'Error ' . $this->db->lasterror();
200  dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);
201 
202  return - 1;
203  }
204  }
205 
216  function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle='',$notooltip=0)
217  {
218  global $langs, $conf, $user;
219 
220  if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips
221 
222  $result = '';
223 
224  $url = DOL_URL_ROOT . '/accountancy/admin/journals_list.php?id=35';
225 
226  $label = '<u>' . $langs->trans("ShowAccountingJournal") . '</u>';
227  if (! empty($this->code))
228  $label .= '<br><b>'.$langs->trans('Code') . ':</b> ' . $this->code;
229  if (! empty($this->label))
230  $label .= '<br><b>'.$langs->trans('Label') . ':</b> ' . $this->label;
231  if ($moretitle) $label.=' - '.$moretitle;
232 
233  $linkclose='';
234  if (empty($notooltip))
235  {
236  if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
237  {
238  $label=$langs->trans("ShowAccoutingJournal");
239  $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
240  }
241  $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
242  $linkclose.=' class="classfortooltip"';
243  }
244 
245  $linkstart='<a href="'.$url.'"';
246  $linkstart.=$linkclose.'>';
247  $linkend='</a>';
248 
249  if ($nourl)
250  {
251  $linkstart = '';
252  $linkclose = '';
253  $linkend = '';
254  }
255 
256  $label_link = $this->code;
257  if ($withlabel) $label_link .= ' - ' . $this->label;
258 
259  $result .= $linkstart;
260  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);
261  if ($withpicto != 2) $result.= $label_link;
262  $result .= $linkend;
263 
264  return $result;
265  }
266 
273  function getLibType($mode=0)
274  {
275  return $this->LibType($this->nature,$mode);
276  }
277 
278  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
286  function LibType($nature,$mode=0)
287  {
288  // phpcs:enable
289  global $langs;
290 
291  $langs->loadLangs(array("accountancy"));
292 
293  if ($mode == 0)
294  {
295  $prefix='';
296  if ($nature == 9) return $langs->trans('AccountingJournalType9');
297  if ($nature == 5) return $langs->trans('AccountingJournalType5');
298  if ($nature == 4) return $langs->trans('AccountingJournalType4');
299  if ($nature == 3) return $langs->trans('AccountingJournalType3');
300  if ($nature == 2) return $langs->trans('AccountingJournalType2');
301  if ($nature == 1) return $langs->trans('AccountingJournalType1');
302  }
303  if ($mode == 1)
304  {
305  if ($nature == 9) return $langs->trans('AccountingJournalType9');
306  if ($nature == 5) return $langs->trans('AccountingJournalType5');
307  if ($nature == 4) return $langs->trans('AccountingJournalType4');
308  if ($nature == 3) return $langs->trans('AccountingJournalType3');
309  if ($nature == 2) return $langs->trans('AccountingJournalType2');
310  if ($nature == 1) return $langs->trans('AccountingJournalType1');
311  }
312  }
313 }
print $object label
hash of file content (md5_file(dol_osencode($destfull))
Definition: edit.php:153
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:1053
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.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
getLibType($mode=0)
Retourne le libelle du statut d&#39;un user (actif, inactif)
LibType($nature, $mode=0)
Return type of an accounting journal.
fetch($rowid=null, $journal_code=null)
Load an object from database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load object in memory from the database.
Class to manage accounting accounts.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)