dolibarr  13.0.2
accountingjournal.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
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 <https://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 
47  public $ismultientitymanaged = 0;
48 
52  public $picto = 'generic';
53 
57  public $rowid;
58 
62  public $code;
63 
67  public $label;
68 
72  public $nature;
73 
77  public $active;
78 
82  public $lines;
83 
89  public function __construct($db)
90  {
91  $this->db = $db;
92  }
93 
101  public function fetch($rowid = null, $journal_code = null)
102  {
103  global $conf;
104 
105  if ($rowid || $journal_code)
106  {
107  $sql = "SELECT rowid, code, label, nature, active";
108  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_journal";
109  $sql .= " WHERE";
110  if ($rowid) {
111  $sql .= " rowid = ".((int) $rowid);
112  } elseif ($journal_code)
113  {
114  $sql .= " code = '".$this->db->escape($journal_code)."'";
115  $sql .= " AND entity = ".$conf->entity;
116  }
117 
118  dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
119  $result = $this->db->query($sql);
120  if ($result)
121  {
122  $obj = $this->db->fetch_object($result);
123 
124  if ($obj) {
125  $this->id = $obj->rowid;
126  $this->rowid = $obj->rowid;
127 
128  $this->code = $obj->code;
129  $this->ref = $obj->code;
130  $this->label = $obj->label;
131  $this->nature = $obj->nature;
132  $this->active = $obj->active;
133 
134  return $this->id;
135  } else {
136  return 0;
137  }
138  } else {
139  $this->error = "Error ".$this->db->lasterror();
140  $this->errors[] = "Error ".$this->db->lasterror();
141  }
142  }
143  return -1;
144  }
145 
158  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
159  {
160  $sql = "SELECT rowid, code, label, nature, active";
161  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
162  // Manage filter
163  $sqlwhere = array();
164  if (count($filter) > 0) {
165  foreach ($filter as $key => $value) {
166  if ($key == 't.code' || $key == 't.label' || $key == 't.nature') {
167  $sqlwhere[] = $key.'\''.$this->db->escape($value).'\'';
168  } elseif ($key == 't.rowid' || $key == 't.active') {
169  $sqlwhere[] = $key.'='.$value;
170  }
171  }
172  }
173  $sql .= ' WHERE 1 = 1';
174  $sql .= " AND entity IN (".getEntity('accountancy').")";
175  if (count($sqlwhere) > 0) {
176  $sql .= ' AND '.implode(' '.$filtermode.' ', $sqlwhere);
177  }
178 
179  if (!empty($sortfield)) {
180  $sql .= $this->db->order($sortfield, $sortorder);
181  }
182  if (!empty($limit)) {
183  $sql .= ' '.$this->db->plimit($limit + 1, $offset);
184  }
185  $this->lines = array();
186 
187  dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
188  $resql = $this->db->query($sql);
189  if ($resql) {
190  $num = $this->db->num_rows($resql);
191 
192  while ($obj = $this->db->fetch_object($resql)) {
193  $line = new self($this->db);
194 
195  $line->id = $obj->rowid;
196  $line->code = $obj->code;
197  $line->label = $obj->label;
198  $line->nature = $obj->nature;
199  $line->active = $obj->active;
200 
201  $this->lines[] = $line;
202  }
203 
204  $this->db->free($resql);
205 
206  return $num;
207  } else {
208  $this->errors[] = 'Error '.$this->db->lasterror();
209  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
210 
211  return -1;
212  }
213  }
214 
225  public function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle = '', $notooltip = 0)
226  {
227  global $langs, $conf, $user;
228 
229  if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
230 
231  $result = '';
232 
233  $url = DOL_URL_ROOT.'/accountancy/admin/journals_list.php?id=35';
234 
235  $label = '<u>'.$langs->trans("ShowAccountingJournal").'</u>';
236  if (!empty($this->code))
237  $label .= '<br><b>'.$langs->trans('Code').':</b> '.$this->code;
238  if (!empty($this->label))
239  $label .= '<br><b>'.$langs->trans('Label').':</b> '.$langs->transnoentities($this->label);
240  if ($moretitle) $label .= ' - '.$moretitle;
241 
242  $linkclose = '';
243  if (empty($notooltip))
244  {
245  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
246  {
247  $label = $langs->trans("ShowAccountingJournal");
248  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
249  }
250  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
251  $linkclose .= ' class="classfortooltip"';
252  }
253 
254  $linkstart = '<a href="'.$url.'"';
255  $linkstart .= $linkclose.'>';
256  $linkend = '</a>';
257 
258  if ($nourl)
259  {
260  $linkstart = '';
261  $linkclose = '';
262  $linkend = '';
263  }
264 
265  $label_link = $this->code;
266  if ($withlabel) $label_link .= ' - '.($nourl ? '<span class="opacitymedium">' : '').$langs->transnoentities($this->label).($nourl ? '</span>' : '');
267 
268  $result .= $linkstart;
269  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);
270  if ($withpicto != 2) $result .= $label_link;
271  $result .= $linkend;
272 
273  return $result;
274  }
275 
282  public function getLibType($mode = 0)
283  {
284  return $this->LibType($this->nature, $mode);
285  }
286 
287  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
295  public function LibType($nature, $mode = 0)
296  {
297  // phpcs:enable
298  global $langs;
299 
300  $langs->loadLangs(array("accountancy"));
301 
302  if ($mode == 0)
303  {
304  $prefix = '';
305  if ($nature == 9) return $langs->trans('AccountingJournalType9');
306  elseif ($nature == 5) return $langs->trans('AccountingJournalType5');
307  elseif ($nature == 4) return $langs->trans('AccountingJournalType4');
308  elseif ($nature == 3) return $langs->trans('AccountingJournalType3');
309  elseif ($nature == 2) return $langs->trans('AccountingJournalType2');
310  elseif ($nature == 1) return $langs->trans('AccountingJournalType1');
311  } elseif ($mode == 1)
312  {
313  if ($nature == 9) return $langs->trans('AccountingJournalType9');
314  elseif ($nature == 5) return $langs->trans('AccountingJournalType5');
315  elseif ($nature == 4) return $langs->trans('AccountingJournalType4');
316  elseif ($nature == 3) return $langs->trans('AccountingJournalType3');
317  elseif ($nature == 2) return $langs->trans('AccountingJournalType2');
318  elseif ($nature == 1) return $langs->trans('AccountingJournalType1');
319  }
320  }
321 }
if(!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'] country if(!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'] typent code
Definition: list.php:566
getNomUrl($withpicto=0, $withlabel=0, $nourl=0, $moretitle= '', $notooltip=0)
Return clicable name (with picto eventually)
</td >< tdcolspan="3">< spanclass="opacitymedium"></span ></td ></tr >< trclass="liste_total"> CREANCES DETTES< tdcolspan="3"class="right"></td >< tdcolspan="3"class="right"></td ></tr > CREANCES DETTES RECETTES DEPENSES trips CREANCES DETTES Y m expensereport p date_valid Y m expensereport pe datep $db idate($date_start)."' AND $column < p rowid
$conf db
API class for accounts.
Definition: inc.php:54
__construct($db)
Constructor.
getLibType($mode=0)
Retourne le libelle du statut d&#39;un user (actif, inactif)
fetchAll($sortorder= '', $sortfield= '', $limit=0, $offset=0, array $filter=array(), $filtermode= 'AND')
Load object in memory from the database.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
Class to manage accounting accounts.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)