dolibarr  13.0.2
accountancycategory.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2016 Jamal Elbaz <jamelbaz@gmail.pro>
3  * Copyright (C) 2016-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
4  * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
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 
26 // Class
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
28 
32 class AccountancyCategory // extends CommonObject
33 {
37  public $db;
38 
42  public $error;
43 
47  public $errors = array();
48 
52  public $element = 'c_accounting_category';
53 
57  public $table_element = 'c_accounting_category';
58 
63  public $rowid;
64 
68  public $id;
69 
73  public $code;
74 
78  public $label;
79 
83  public $range_account;
84 
88  public $sens;
89 
93  public $category_type;
94 
98  public $formula;
99 
103  public $position;
104 
108  public $fk_country;
109 
113  public $active;
114 
118  public $lines_cptbk;
119 
123  public $lines_display;
124 
128  public $sdc;
129 
130 
131 
137  public function __construct($db)
138  {
139  $this->db = $db;
140  }
141 
142 
150  public function create($user, $notrigger = 0)
151  {
152  global $conf, $langs;
153  $error = 0;
154 
155  // Clean parameters
156  if (isset($this->code)) $this->code = trim($this->code);
157  if (isset($this->label)) $this->label = trim($this->label);
158  if (isset($this->range_account)) $this->range_account = trim($this->range_account);
159  if (isset($this->sens)) $this->sens = (int) $this->sens;
160  if (isset($this->category_type)) $this->category_type = (int) $this->category_type;
161  if (isset($this->formula)) $this->formula = trim($this->formula);
162  if (isset($this->position)) $this->position = (int) $this->position;
163  if (isset($this->fk_country)) $this->fk_country = (int) $this->fk_country;
164  if (isset($this->active)) $this->active = (int) $this->active;
165 
166  // Check parameters
167  // Put here code to add control on parameters values
168 
169  // Insert request
170  $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_accounting_category(";
171  if ($this->rowid > 0) $sql .= "rowid, ";
172  $sql .= "code, ";
173  $sql .= "label, ";
174  $sql .= "range_account, ";
175  $sql .= "sens, ";
176  $sql .= "category_type, ";
177  $sql .= "formula, ";
178  $sql .= "position, ";
179  $sql .= "fk_country, ";
180  $sql .= "active, ";
181  $sql .= "entity";
182  $sql .= ") VALUES (";
183  if ($this->rowid > 0) $sql .= " ".$this->rowid.",";
184  $sql .= " ".(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").",";
185  $sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").",";
186  $sql .= " ".(!isset($this->range_account) ? 'NULL' : "'".$this->db->escape($this->range_account)."'").",";
187  $sql .= " ".(!isset($this->sens) ? 'NULL' : "'".$this->db->escape($this->sens)."'").",";
188  $sql .= " ".(!isset($this->category_type) ? 'NULL' : "'".$this->db->escape($this->category_type)."'").",";
189  $sql .= " ".(!isset($this->formula) ? 'NULL' : "'".$this->db->escape($this->formula)."'").",";
190  $sql .= " ".(!isset($this->position) ? 'NULL' : $this->db->escape($this->position)).",";
191  $sql .= " ".(!isset($this->fk_country) ? 'NULL' : $this->db->escape($this->fk_country)).",";
192  $sql .= " ".(!isset($this->active) ? 'NULL' : $this->db->escape($this->active));
193  $sql .= ", ".$conf->entity;
194  $sql .= ")";
195 
196  $this->db->begin();
197 
198  dol_syslog(get_class($this)."::create", LOG_DEBUG);
199  $resql = $this->db->query($sql);
200  if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
201 
202  // Commit or rollback
203  if ($error)
204  {
205  foreach ($this->errors as $errmsg)
206  {
207  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
208  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
209  }
210  $this->db->rollback();
211  return -1 * $error;
212  } else {
213  $this->db->commit();
214  return $this->id;
215  }
216  }
217 
218 
227  public function fetch($id, $code = '', $label = '')
228  {
229  $sql = "SELECT";
230  $sql .= " t.rowid,";
231  $sql .= " t.code,";
232  $sql .= " t.label,";
233  $sql .= " t.range_account,";
234  $sql .= " t.sens,";
235  $sql .= " t.category_type,";
236  $sql .= " t.formula,";
237  $sql .= " t.position,";
238  $sql .= " t.fk_country,";
239  $sql .= " t.active";
240  $sql .= " FROM ".MAIN_DB_PREFIX."c_accounting_category as t";
241  if ($id) $sql .= " WHERE t.rowid = ".$id;
242  else {
243  $sql .= " WHERE t.entity IN (".getEntity('c_accounting_category').")"; // Dont't use entity if you use rowid
244  if ($code) $sql .= " AND t.code = '".$this->db->escape($code)."'";
245  elseif ($label) $sql .= " AND t.label = '".$this->db->escape($label)."'";
246  }
247 
248  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
249  $resql = $this->db->query($sql);
250  if ($resql)
251  {
252  if ($this->db->num_rows($resql))
253  {
254  $obj = $this->db->fetch_object($resql);
255 
256  $this->id = $obj->rowid;
257  $this->code = $obj->code;
258  $this->label = $obj->label;
259  $this->range_account = $obj->range_account;
260  $this->sens = $obj->sens;
261  $this->category_type = $obj->category_type;
262  $this->formula = $obj->formula;
263  $this->position = $obj->position;
264  $this->fk_country = $obj->fk_country;
265  $this->active = $obj->active;
266  }
267  $this->db->free($resql);
268 
269  return 1;
270  } else {
271  $this->error = "Error ".$this->db->lasterror();
272  return -1;
273  }
274  }
275 
276 
284  public function update($user = null, $notrigger = 0)
285  {
286  global $conf, $langs;
287  $error = 0;
288 
289  // Clean parameters
290  if (isset($this->code)) $this->code = trim($this->code);
291  if (isset($this->label)) $this->label = trim($this->label);
292  if (isset($this->range_account)) $this->range_account = trim($this->range_account);
293  if (isset($this->sens)) $this->sens = (int) $this->sens;
294  if (isset($this->category_type)) $this->category_type = (int) $this->category_type;
295  if (isset($this->formula)) $this->formula = trim($this->formula);
296  if (isset($this->position)) $this->position = (int) $this->position;
297  if (isset($this->fk_country)) $this->fk_country = (int) $this->fk_country;
298  if (isset($this->active)) $this->active = (int) $this->active;
299 
300 
301  // Check parameters
302  // Put here code to add control on parameters values
303 
304  // Update request
305  $sql = "UPDATE ".MAIN_DB_PREFIX."c_accounting_category SET";
306  $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").",";
307  $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
308  $sql .= " range_account=".(isset($this->range_account) ? "'".$this->db->escape($this->range_account)."'" : "null").",";
309  $sql .= " sens=".(isset($this->sens) ? $this->sens : "null").",";
310  $sql .= " category_type=".(isset($this->category_type) ? $this->category_type : "null").",";
311  $sql .= " formula=".(isset($this->formula) ? "'".$this->db->escape($this->formula)."'" : "null").",";
312  $sql .= " position=".(isset($this->position) ? $this->position : "null").",";
313  $sql .= " fk_country=".(isset($this->fk_country) ? $this->fk_country : "null").",";
314  $sql .= " active=".(isset($this->active) ? $this->active : "null")."";
315  $sql .= " WHERE rowid=".$this->id;
316 
317  $this->db->begin();
318 
319  dol_syslog(get_class($this)."::update", LOG_DEBUG);
320  $resql = $this->db->query($sql);
321  if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
322 
323  // Commit or rollback
324  if ($error)
325  {
326  foreach ($this->errors as $errmsg)
327  {
328  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
329  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
330  }
331  $this->db->rollback();
332  return -1 * $error;
333  } else {
334  $this->db->commit();
335  return 1;
336  }
337  }
338 
339 
347  public function delete($user, $notrigger = 0)
348  {
349  global $conf, $langs;
350  $error = 0;
351 
352  $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_accounting_category";
353  $sql .= " WHERE rowid=".$this->id;
354 
355  $this->db->begin();
356 
357  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
358  $resql = $this->db->query($sql);
359  if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
360 
361  // Commit or rollback
362  if ($error)
363  {
364  foreach ($this->errors as $errmsg)
365  {
366  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
367  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
368  }
369  $this->db->rollback();
370  return -1 * $error;
371  } else {
372  $this->db->commit();
373  return 1;
374  }
375  }
376 
377 
384  public function display($id)
385  {
386  global $conf;
387  $sql = "SELECT t.rowid, t.account_number, t.label";
388  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as t";
389  $sql .= " WHERE t.fk_accounting_category = ".$id;
390  $sql .= " AND t.entity = ".$conf->entity;
391 
392  $this->lines_display = array();
393 
394  dol_syslog(__METHOD__." sql=".$sql, LOG_DEBUG);
395  $resql = $this->db->query($sql);
396  if ($resql) {
397  $num = $this->db->num_rows($resql);
398  if ($num) {
399  while ($obj = $this->db->fetch_object($resql)) {
400  $this->lines_display[] = $obj;
401  }
402  }
403  return $num;
404  } else {
405  $this->error = "Error ".$this->db->lasterror();
406  $this->errors[] = $this->error;
407  dol_syslog(__METHOD__." ".implode(','.$this->errors), LOG_ERR);
408 
409  return -1;
410  }
411  }
412 
420  public function getCptBK($id)
421  {
422  global $conf;
423 
424  $sql = "SELECT t.numero_compte, t.label_operation, t.doc_ref";
425  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as t";
426  $sql .= " WHERE t.numero_compte NOT IN (";
427  $sql .= " SELECT t.account_number";
428  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as t";
429  $sql .= " WHERE t.fk_accounting_category = ".$id." AND t.entity = ".$conf->entity.")";
430  $sql .= " AND t.numero_compte IN (";
431  $sql .= " SELECT DISTINCT aa.account_number";
432  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
433  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
434  $sql .= " AND asy.rowid = ".$conf->global->CHARTOFACCOUNTS;
435  $sql .= " AND aa.active = 1";
436  $sql .= " AND aa.entity = ".$conf->entity.")";
437  $sql .= " GROUP BY t.numero_compte, t.label_operation, t.doc_ref";
438  $sql .= " ORDER BY t.numero_compte";
439 
440  $this->lines_CptBk = array();
441 
442  dol_syslog(__METHOD__, LOG_DEBUG);
443  $resql = $this->db->query($sql);
444  if ($resql) {
445  $num = $this->db->num_rows($resql);
446  if ($num) {
447  while ($obj = $this->db->fetch_object($resql)) {
448  $this->lines_cptbk[] = $obj;
449  }
450  }
451 
452  return $num;
453  } else {
454  $this->error = "Error ".$this->db->lasterror();
455  $this->errors[] = $this->error;
456  dol_syslog(__METHOD__." ".implode(','.$this->errors), LOG_ERR);
457 
458  return -1;
459  }
460  }
461 
469  public function getAccountsWithNoCategory($id)
470  {
471  global $conf;
472 
473  $sql = "SELECT aa.account_number as numero_compte, aa.label as label_compte";
474  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
475  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
476  $sql .= " WHERE (aa.fk_accounting_category != ".$id." OR aa.fk_accounting_category IS NULL)";
477  $sql .= " AND asy.rowid = ".$conf->global->CHARTOFACCOUNTS;
478  $sql .= " AND aa.active = 1";
479  $sql .= " AND aa.entity = ".$conf->entity;
480  $sql .= " GROUP BY aa.account_number, aa.label";
481  $sql .= " ORDER BY aa.account_number, aa.label";
482 
483  $this->lines_CptBk = array();
484 
485  dol_syslog(__METHOD__, LOG_DEBUG);
486  $resql = $this->db->query($sql);
487  if ($resql) {
488  $num = $this->db->num_rows($resql);
489  if ($num) {
490  while ($obj = $this->db->fetch_object($resql)) {
491  $this->lines_cptbk[] = $obj;
492  }
493  }
494 
495  return $num;
496  } else {
497  $this->error = "Error ".$this->db->lasterror();
498  $this->errors[] = $this->error;
499  dol_syslog(__METHOD__." ".implode(','.$this->errors), LOG_ERR);
500 
501  return -1;
502  }
503  }
504 
513  public function updateAccAcc($id_cat, $cpts = array())
514  {
515  global $conf;
516  $error = 0;
517 
518  require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
519 
520  $sql = "SELECT aa.rowid, aa.account_number";
521  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
522  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
523  $sql .= " AND asy.rowid = ".$conf->global->CHARTOFACCOUNTS;
524  $sql .= " AND aa.active = 1";
525  $sql .= " AND aa.entity = ".$conf->entity;
526  $sql .= " ORDER BY LENGTH(aa.account_number) DESC;"; // LENGTH is ok with mysql and postgresql
527 
528  $this->db->begin();
529 
530  dol_syslog(__METHOD__, LOG_DEBUG);
531  $resql = $this->db->query($sql);
532  if (!$resql) {
533  $error++;
534  $this->errors[] = "Error ".$this->db->lasterror();
535  $this->db->rollback();
536  return -1;
537  }
538 
539  $accountincptsadded = array();
540  while ($obj = $this->db->fetch_object($resql))
541  {
542  $account_number_formated = length_accountg($obj->account_number);
543  if (!empty($accountincptsadded[$account_number_formated])) continue;
544 
545  if (array_key_exists($account_number_formated, $cpts))
546  {
547  $accountincptsadded[$account_number_formated] = 1;
548  // We found an account number that is in list $cpts of account to add
549  $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_account";
550  $sql .= " SET fk_accounting_category=".$id_cat;
551  $sql .= " WHERE rowid=".$obj->rowid;
552  dol_syslog(__METHOD__, LOG_DEBUG);
553  $resqlupdate = $this->db->query($sql);
554  if (!$resqlupdate) {
555  $error++;
556  $this->errors[] = "Error ".$this->db->lasterror();
557  }
558  }
559  }
560 
561  // Commit or rollback
562  if ($error) {
563  foreach ($this->errors as $errmsg) {
564  dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
565  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
566  }
567  $this->db->rollback();
568 
569  return -1 * $error;
570  } else {
571  $this->db->commit();
572 
573  return 1;
574  }
575  }
576 
584  public function deleteCptCat($cpt_id)
585  {
586  $error = 0;
587 
588  $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_account as aa";
589  $sql .= " SET fk_accounting_category= 0";
590  $sql .= " WHERE aa.rowid= ".$cpt_id;
591  $this->db->begin();
592 
593  dol_syslog(__METHOD__." sql=".$sql, LOG_DEBUG);
594  $resql = $this->db->query($sql);
595  if (!$resql) {
596  $error++;
597  $this->errors[] = "Error ".$this->db->lasterror();
598  }
599 
600  // Commit or rollback
601  if ($error) {
602  foreach ($this->errors as $errmsg) {
603  dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
604  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
605  }
606  $this->db->rollback();
607 
608  return -1 * $error;
609  } else {
610  $this->db->commit();
611 
612  return 1;
613  }
614  }
615 
621  public function getCatsCpts()
622  {
623  global $mysoc, $conf;
624 
625  if (empty($mysoc->country_id)) {
626  dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined');
627  exit();
628  }
629 
630  $sql = "SELECT t.rowid, t.account_number, t.label as account_label, cat.code, cat.position, cat.label as name_cat, cat.sens ";
631  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as t, ".MAIN_DB_PREFIX."c_accounting_category as cat";
632  $sql .= " WHERE t.fk_accounting_category IN ( SELECT c.rowid ";
633  $sql .= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c";
634  $sql .= " WHERE c.active = 1";
635  $sql .= " AND c.entity = ".$conf->entity;
636  $sql .= " AND (c.fk_country = ".$mysoc->country_id." OR c.fk_country = 0)";
637  $sql .= " AND cat.rowid = t.fk_accounting_category";
638  $sql .= " AND t.entity = ".$conf->entity;
639  $sql .= " ORDER BY cat.position ASC";
640 
641  $resql = $this->db->query($sql);
642  if ($resql) {
643  $i = 0;
644  $obj = '';
645  $num = $this->db->num_rows($resql);
646  $data = array();
647  if ($num) {
648  while ($obj = $this->db->fetch_object($resql)) {
649  $name_cat = $obj->name_cat;
650  $data[$name_cat][$i] = array(
651  'id' => $obj->rowid,
652  'code' => $obj->code,
653  'position' => $obj->position,
654  'account_number' => $obj->account_number,
655  'account_label' => $obj->account_label,
656  'sens' => $obj->sens
657  );
658  $i++;
659  }
660  }
661  return $data;
662  } else {
663  $this->error = "Error ".$this->db->lasterror();
664  dol_syslog(__METHOD__." ".$this->error, LOG_ERR);
665 
666  return -1;
667  }
668  }
669 
682  public function getSumDebitCredit($cpt, $date_start, $date_end, $sens, $thirdparty_code = 'nofilter', $month = 0, $year = 0)
683  {
684  global $conf;
685 
686  $this->sdc = 0;
687  $this->sdcpermonth = array();
688 
689  $sql = "SELECT SUM(t.debit) as debit, SUM(t.credit) as credit";
690  if (is_array($cpt)) $sql .= ", t.numero_compte as accountancy_account";
691  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as t";
692  //if (in_array($this->db->type, array('mysql', 'mysqli'))) $sql.=' USE INDEX idx_accounting_bookkeeping_doc_date';
693  $sql .= " WHERE t.entity = ".$conf->entity;
694  if (is_array($cpt))
695  {
696  $listofaccount = '';
697  foreach ($cpt as $cptcursor)
698  {
699  if ($listofaccount) $listofaccount .= ",";
700  $listofaccount .= "'".$cptcursor."'";
701  }
702  $sql .= " AND t.numero_compte IN (".$listofaccount.")";
703  } else {
704  $sql .= " AND t.numero_compte = '".$this->db->escape($cpt)."'";
705  }
706  if (!empty($date_start) && !empty($date_end) && (empty($month) || empty($year))) // If month/year provided, it is stronger than filter date_start/date_end
707  $sql .= " AND (t.doc_date BETWEEN '".$this->db->idate($date_start)."' AND '".$this->db->idate($date_end)."')";
708  if (!empty($month) && !empty($year)) {
709  $sql .= " AND (t.doc_date BETWEEN '".$this->db->idate(dol_get_first_day($year, $month))."' AND '".$this->db->idate(dol_get_last_day($year, $month))."')";
710  }
711  if ($thirdparty_code != 'nofilter')
712  {
713  $sql .= " AND t.thirdparty_code = '".$this->db->escape($thirdparty_code)."'";
714  }
715  if (is_array($cpt)) $sql .= " GROUP BY t.numero_compte";
716  //print $sql;
717 
718  $resql = $this->db->query($sql);
719  if ($resql)
720  {
721  $num = $this->db->num_rows($resql);
722  if ($num)
723  {
724  $obj = $this->db->fetch_object($resql);
725  if ($sens == 1) {
726  $this->sdc = $obj->debit - $obj->credit;
727  } else {
728  $this->sdc = $obj->credit - $obj->debit;
729  }
730  if (is_array($cpt))
731  {
732  $this->sdcperaccount[$obj->accountancy_account] = $this->sdc;
733  }
734  }
735  return $num;
736  } else {
737  $this->error = "Error ".$this->db->lasterror();
738  $this->errors[] = $this->error;
739  dol_syslog(__METHOD__." ".$this->error, LOG_ERR);
740  return -1;
741  }
742  }
743 
750  public function getCats($categorytype = -1)
751  {
752  global $conf, $mysoc;
753 
754  if (empty($mysoc->country_id)) {
755  dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined');
756  exit();
757  }
758 
759  $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type, c.sens";
760  $sql .= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c";
761  $sql .= " WHERE c.active = 1";
762  $sql .= " AND c.entity = ".$conf->entity;
763  if ($categorytype >= 0) $sql .= " AND c.category_type = 1";
764  $sql .= " AND (c.fk_country = ".$mysoc->country_id." OR c.fk_country = 0)";
765  $sql .= " ORDER BY c.position ASC";
766 
767  $resql = $this->db->query($sql);
768  if ($resql) {
769  $i = 0;
770  $obj = '';
771  $num = $this->db->num_rows($resql);
772  $data = array();
773  if ($num) {
774  while ($i < $num) {
775  $obj = $this->db->fetch_object($resql);
776 
777  $data[] = array(
778  'rowid' => $obj->rowid,
779  'code' => $obj->code,
780  'label' => $obj->label,
781  'formula' => $obj->formula,
782  'position' => $obj->position,
783  'category_type' => $obj->category_type,
784  'bc' => $obj->sens
785  );
786  $i++;
787  }
788  }
789  return $data;
790  } else {
791  $this->error = "Error ".$this->db->lasterror();
792  $this->errors[] = $this->error;
793  dol_syslog(__METHOD__." ".implode(',', $this->errors), LOG_ERR);
794 
795  return -1;
796  }
797  }
798 
799 
808  public function getCptsCat($cat_id, $predefinedgroupwhere = '')
809  {
810  global $conf, $mysoc;
811  $sql = '';
812 
813  if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
814  dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined');
815  exit();
816  }
817 
818  if (!empty($cat_id))
819  {
820  $sql = "SELECT t.rowid, t.account_number, t.label as account_label";
821  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as t";
822  $sql .= " WHERE t.fk_accounting_category = ".$cat_id;
823  $sql .= " AND t.entity = ".$conf->entity;
824  $sql .= " ORDER BY t.account_number";
825  } else {
826  $sql = "SELECT t.rowid, t.account_number, t.label as account_label";
827  $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as t";
828  $sql .= " WHERE ".$predefinedgroupwhere;
829  $sql .= " AND t.entity = ".$conf->entity;
830  $sql .= " ORDER BY t.account_number";
831  }
832  //echo $sql;
833 
834  $resql = $this->db->query($sql);
835  if ($resql) {
836  $i = 0;
837  $obj = '';
838  $num = $this->db->num_rows($resql);
839  $data = array();
840  if ($num) {
841  while ($obj = $this->db->fetch_object($resql))
842  {
843  $data[] = array(
844  'id' => $obj->rowid,
845  'account_number' => $obj->account_number,
846  'account_label' => $obj->account_label,
847  );
848  $i++;
849  }
850  }
851  return $data;
852  } else {
853  $this->error = "Error ".$this->db->lasterror();
854  dol_syslog(__METHOD__." ".$this->error, LOG_ERR);
855 
856  return -1;
857  }
858  }
859 }
fetch($id, $code= '', $label= '')
Load object in memory from database.
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
getCats($categorytype=-1)
Return list of personalized groups that are active.
create($user, $notrigger=0)
Create object into database.
getCptsCat($cat_id, $predefinedgroupwhere= '')
Get all accounting account of a group.
</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
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:481
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage categories of an accounting account.
display($id)
Function to select all accounting accounts from an accounting category.
getSumDebitCredit($cpt, $date_start, $date_end, $sens, $thirdparty_code= 'nofilter', $month=0, $year=0)
Function to show result of an accounting account from the ledger with a direction and a period...
getCptBK($id)
Function to select accounting category of an accounting account present in chart of accounts...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getCatsCpts()
Function to know all category from accounting account.
updateAccAcc($id_cat, $cpts=array())
Function to add an accounting account in an accounting category.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:498
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
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
update($user=null, $notrigger=0)
Update object into database.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
deleteCptCat($cpt_id)
Function to delete an accounting account from an accounting category.
getAccountsWithNoCategory($id)
Function to select accounting category of an accounting account present in chart of accounts...