dolibarr  9.0.0
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@zendsi.com>
4  * Copyright (C) 2018 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 <http://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 
43  public $error;
44 
48  public $errors = array();
49 
53  public $element='c_accounting_category';
54 
58  public $table_element='c_accounting_category';
59 
63  public $id;
64 
68  public $code;
69 
73  public $label;
74 
78  public $range_account;
79 
83  public $sens;
84 
88  public $category_type;
89 
93  public $formula;
94 
98  public $position;
99 
103  public $fk_country;
104 
108  public $active;
109 
113  public $lines_cptbk;
114 
118  public $lines_display;
119 
123  public $sdc;
124 
125 
126 
132  function __construct($db)
133  {
134  $this->db = $db;
135  }
136 
137 
145  function create($user, $notrigger=0)
146  {
147  global $conf, $langs;
148  $error=0;
149 
150  // Clean parameters
151  if (isset($this->code)) $this->code=trim($this->code);
152  if (isset($this->label)) $this->label=trim($this->label);
153  if (isset($this->range_account)) $this->range_account=trim($this->range_account);
154  if (isset($this->sens)) $this->sens=trim($this->sens);
155  if (isset($this->category_type)) $this->category_type=trim($this->category_type);
156  if (isset($this->formula)) $this->formula=trim($this->formula);
157  if (isset($this->position)) $this->position=trim($this->position);
158  if (isset($this->fk_country)) $this->fk_country=trim($this->fk_country);
159  if (isset($this->active)) $this->active=trim($this->active);
160 
161  // Check parameters
162  // Put here code to add control on parameters values
163 
164  // Insert request
165  $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_accounting_category(";
166  if ($this->rowid > 0) $sql.= "rowid, ";
167  $sql.= "code, ";
168  $sql.= "label, ";
169  $sql.= "range_account, ";
170  $sql.= "sens, ";
171  $sql.= "category_type, ";
172  $sql.= "formula, ";
173  $sql.= "position, ";
174  $sql.= "fk_country, ";
175  $sql.= "active, ";
176  $sql.= "entity";
177  $sql.= ") VALUES (";
178  if ($this->rowid > 0) $sql.= " ".$this->rowid.",";
179  $sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").",";
180  $sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").",";
181  $sql.= " ".(! isset($this->range_account)?'NULL':"'".$this->db->escape($this->range_account)."'").",";
182  $sql.= " ".(! isset($this->sens)?'NULL':"'".$this->db->escape($this->sens)."'").",";
183  $sql.= " ".(! isset($this->category_type)?'NULL':"'".$this->db->escape($this->category_type)."'").",";
184  $sql.= " ".(! isset($this->formula)?'NULL':"'".$this->db->escape($this->formula)."'").",";
185  $sql.= " ".(! isset($this->position)?'NULL':$this->db->escape($this->position)).",";
186  $sql.= " ".(! isset($this->fk_country)?'NULL':$this->db->escape($this->fk_country)).",";
187  $sql.= " ".(! isset($this->active)?'NULL':$this->db->escape($this->active));
188  $sql.= ", ".$conf->entity;
189  $sql.= ")";
190 
191  $this->db->begin();
192 
193  dol_syslog(get_class($this)."::create", LOG_DEBUG);
194  $resql=$this->db->query($sql);
195  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
196 
197  if (! $error)
198  {
199  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_accounting_category");
200 
201  // Uncomment this and change MYOBJECT to your own tag if you
202  // want this action call a trigger.
203  //if (! $notrigger)
204  //{
205 
206  // // Call triggers
207  // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
208  // $interface=new Interfaces($this->db);
209  // $result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
210  // if ($result < 0) { $error++; $this->errors=$interface->errors; }
211  // // End call triggers
212  //}
213  }
214 
215  // Commit or rollback
216  if ($error)
217  {
218  foreach($this->errors as $errmsg)
219  {
220  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
221  $this->error.=($this->error?', '.$errmsg:$errmsg);
222  }
223  $this->db->rollback();
224  return -1*$error;
225  }
226  else
227  {
228  $this->db->commit();
229  return $this->id;
230  }
231  }
232 
233 
242  function fetch($id, $code='', $label='')
243  {
244  $sql = "SELECT";
245  $sql.= " t.rowid,";
246  $sql.= " t.code,";
247  $sql.= " t.label,";
248  $sql.= " t.range_account,";
249  $sql.= " t.sens,";
250  $sql.= " t.category_type,";
251  $sql.= " t.formula,";
252  $sql.= " t.position,";
253  $sql.= " t.fk_country,";
254  $sql.= " t.active";
255  $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as t";
256  if ($id) $sql.= " WHERE t.rowid = ".$id;
257  else
258  {
259  $sql.= " WHERE t.entity IN (".getEntity('c_accounting_category').")"; // Dont't use entity if you use rowid
260  if ($code) $sql.= " AND t.code = '".$this->db->escape($code)."'";
261  elseif ($label) $sql.= " AND t.label = '".$this->db->escape($label)."'";
262  }
263 
264  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
265  $resql=$this->db->query($sql);
266  if ($resql)
267  {
268  if ($this->db->num_rows($resql))
269  {
270  $obj = $this->db->fetch_object($resql);
271 
272  $this->id = $obj->rowid;
273  $this->code = $obj->code;
274  $this->label = $obj->label;
275  $this->range_account = $obj->range_account;
276  $this->sens = $obj->sens;
277  $this->category_type = $obj->category_type;
278  $this->formula = $obj->formula;
279  $this->position = $obj->position;
280  $this->fk_country = $obj->fk_country;
281  $this->active = $obj->active;
282  }
283  $this->db->free($resql);
284 
285  return 1;
286  }
287  else
288  {
289  $this->error="Error ".$this->db->lasterror();
290  return -1;
291  }
292  }
293 
294 
302  function update($user=null, $notrigger=0)
303  {
304  global $conf, $langs;
305  $error=0;
306 
307  // Clean parameters
308  if (isset($this->code)) $this->code=trim($this->code);
309  if (isset($this->label)) $this->label=trim($this->label);
310  if (isset($this->range_account)) $this->range_account=trim($this->range_account);
311  if (isset($this->sens)) $this->sens=trim($this->sens);
312  if (isset($this->category_type)) $this->category_type=trim($this->category_type);
313  if (isset($this->formula)) $this->formula=trim($this->formula);
314  if (isset($this->position)) $this->position=trim($this->position);
315  if (isset($this->fk_country)) $this->fk_country=trim($this->fk_country);
316  if (isset($this->active)) $this->active=trim($this->active);
317 
318 
319  // Check parameters
320  // Put here code to add control on parameters values
321 
322  // Update request
323  $sql = "UPDATE ".MAIN_DB_PREFIX."c_accounting_category SET";
324  $sql.= " code=".(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").",";
325  $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
326  $sql.= " range_account=".(isset($this->range_account)?"'".$this->db->escape($this->range_account)."'":"null").",";
327  $sql.= " sens=".(isset($this->sens)?$this->sens:"null").",";
328  $sql.= " category_type=".(isset($this->category_type)?$this->category_type:"null").",";
329  $sql.= " formula=".(isset($this->formula)?"'".$this->db->escape($this->formula)."'":"null").",";
330  $sql.= " position=".(isset($this->position)?$this->position:"null").",";
331  $sql.= " fk_country=".(isset($this->fk_country)?$this->fk_country:"null").",";
332  $sql.= " active=".(isset($this->active)?$this->active:"null")."";
333  $sql.= " WHERE rowid=".$this->id;
334 
335  $this->db->begin();
336 
337  dol_syslog(get_class($this)."::update", LOG_DEBUG);
338  $resql = $this->db->query($sql);
339  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
340 
341  if (! $error)
342  {
343  // Uncomment this and change MYOBJECT to your own tag if you
344  // want this action call a trigger.
345  //if (! $notrigger)
346  //{
347  // // Call triggers
348  // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
349  // $interface=new Interfaces($this->db);
350  // $result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
351  // if ($result < 0) { $error++; $this->errors=$interface->errors; }
352  // // End call triggers
353  //}
354  }
355 
356  // Commit or rollback
357  if ($error)
358  {
359  foreach($this->errors as $errmsg)
360  {
361  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
362  $this->error.=($this->error?', '.$errmsg:$errmsg);
363  }
364  $this->db->rollback();
365  return -1*$error;
366  }
367  else
368  {
369  $this->db->commit();
370  return 1;
371  }
372  }
373 
374 
382  function delete($user, $notrigger=0)
383  {
384  global $conf, $langs;
385  $error=0;
386 
387  $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_accounting_category";
388  $sql.= " WHERE rowid=".$this->id;
389 
390  $this->db->begin();
391 
392  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
393  $resql = $this->db->query($sql);
394  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
395 
396  if (! $error)
397  {
398  // Uncomment this and change MYOBJECT to your own tag if you
399  // want this action call a trigger.
400  //if (! $notrigger)
401  //{
402  // // Call triggers
403  // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
404  // $interface=new Interfaces($this->db);
405  // $result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
406  // if ($result < 0) { $error++; $this->errors=$interface->errors; }
407  // // End call triggers
408  //}
409  }
410 
411  // Commit or rollback
412  if ($error)
413  {
414  foreach($this->errors as $errmsg)
415  {
416  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
417  $this->error.=($this->error?', '.$errmsg:$errmsg);
418  }
419  $this->db->rollback();
420  return -1*$error;
421  }
422  else
423  {
424  $this->db->commit();
425  return 1;
426  }
427  }
428 
429 
436  public function display($id)
437  {
438  global $conf;
439  $sql = "SELECT t.rowid, t.account_number, t.label";
440  $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t";
441  $sql .= " WHERE t.fk_accounting_category = " . $id;
442  $sql .= " AND t.entity = " . $conf->entity;
443 
444  $this->lines_display = array();
445 
446  dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG);
447  $resql = $this->db->query($sql);
448  if ($resql) {
449  $num = $this->db->num_rows($resql);
450  if ($num) {
451  while ( $obj = $this->db->fetch_object($resql) ) {
452  $this->lines_display[] = $obj;
453  }
454  }
455  return $num;
456  } else {
457  $this->error = "Error " . $this->db->lasterror();
458  $this->errors[] = $this->error;
459  dol_syslog(__METHOD__ . " " . implode(',' . $this->errors), LOG_ERR);
460 
461  return - 1;
462  }
463  }
464 
472  public function getCptBK($id)
473  {
474  global $conf;
475 
476  $sql = "SELECT t.numero_compte, t.label_operation, t.doc_ref";
477  $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as t";
478  $sql .= " WHERE t.numero_compte NOT IN (";
479  $sql .= " SELECT t.account_number";
480  $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t";
481  $sql .= " WHERE t.fk_accounting_category = " . $id . " AND t.entity = " . $conf->entity.")";
482  $sql .= " AND t.numero_compte IN (";
483  $sql .= " SELECT DISTINCT aa.account_number";
484  $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
485  $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
486  $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
487  $sql .= " AND aa.active = 1";
488  $sql .= " AND aa.entity = " . $conf->entity . ")";
489  $sql .= " GROUP BY t.numero_compte, t.label_operation, t.doc_ref";
490  $sql .= " ORDER BY t.numero_compte";
491 
492  $this->lines_CptBk = array ();
493 
494  dol_syslog(__METHOD__, LOG_DEBUG);
495  $resql = $this->db->query($sql);
496  if ($resql) {
497  $num = $this->db->num_rows($resql);
498  if ($num) {
499  while ( $obj = $this->db->fetch_object($resql) ) {
500  $this->lines_cptbk[] = $obj;
501  }
502  }
503 
504  return $num;
505  } else {
506  $this->error = "Error " . $this->db->lasterror();
507  $this->errors[] = $this->error;
508  dol_syslog(__METHOD__ . " " . implode(',' . $this->errors), LOG_ERR);
509 
510  return - 1;
511  }
512  }
513 
521  public function getAccountsWithNoCategory($id)
522  {
523  global $conf;
524 
525  $sql = "SELECT aa.account_number as numero_compte, aa.label as label_compte";
526  $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
527  $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
528  $sql .= " WHERE (aa.fk_accounting_category != ".$id." OR aa.fk_accounting_category IS NULL)";
529  $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
530  $sql .= " AND aa.active = 1";
531  $sql .= " AND aa.entity = " . $conf->entity;
532  $sql .= " GROUP BY aa.account_number, aa.label";
533  $sql .= " ORDER BY aa.account_number, aa.label";
534 
535  $this->lines_CptBk = array ();
536 
537  dol_syslog(__METHOD__, LOG_DEBUG);
538  $resql = $this->db->query($sql);
539  if ($resql) {
540  $num = $this->db->num_rows($resql);
541  if ($num) {
542  while ( $obj = $this->db->fetch_object($resql) ) {
543  $this->lines_cptbk[] = $obj;
544  }
545  }
546 
547  return $num;
548  } else {
549  $this->error = "Error " . $this->db->lasterror();
550  $this->errors[] = $this->error;
551  dol_syslog(__METHOD__ . " " . implode(',' . $this->errors), LOG_ERR);
552 
553  return - 1;
554  }
555  }
556 
565  public function updateAccAcc($id_cat, $cpts = array())
566  {
567  global $conf;
568  $error = 0;
569 
570  require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
571 
572  $sql = "SELECT aa.rowid,aa.account_number ";
573  $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa";
574  $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
575  $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
576  $sql .= " AND aa.active = 1";
577  $sql .= " AND aa.entity = " . $conf->entity;
578 
579  $this->db->begin();
580 
581  dol_syslog(__METHOD__, LOG_DEBUG);
582  $resql = $this->db->query($sql);
583  if (! $resql) {
584  $error ++;
585  $this->errors[] = "Error " . $this->db->lasterror();
586  $this->db->rollback();
587  return -1;
588  }
589 
590  while ( $obj = $this->db->fetch_object($resql))
591  {
592  if (array_key_exists(length_accountg($obj->account_number), $cpts))
593  {
594  $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account";
595  $sql .= " SET fk_accounting_category=" . $id_cat;
596  $sql .= " WHERE rowid=".$obj->rowid;
597  dol_syslog(__METHOD__, LOG_DEBUG);
598  $resqlupdate = $this->db->query($sql);
599  if (! $resqlupdate) {
600  $error ++;
601  $this->errors[] = "Error " . $this->db->lasterror();
602  }
603  }
604  }
605 
606  // Commit or rollback
607  if ($error) {
608  foreach ( $this->errors as $errmsg ) {
609  dol_syslog(__METHOD__ . " " . $errmsg, LOG_ERR);
610  $this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
611  }
612  $this->db->rollback();
613 
614  return - 1 * $error;
615  } else {
616  $this->db->commit();
617 
618  return 1;
619  }
620  }
621 
629  public function deleteCptCat($cpt_id)
630  {
631  $error = 0;
632 
633  $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account as aa";
634  $sql .= " SET fk_accounting_category= 0";
635  $sql .= " WHERE aa.rowid= " . $cpt_id;
636  $this->db->begin();
637 
638  dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG);
639  $resql = $this->db->query($sql);
640  if (! $resql) {
641  $error ++;
642  $this->errors[] = "Error " . $this->db->lasterror();
643  }
644 
645  // Commit or rollback
646  if ($error) {
647  foreach ( $this->errors as $errmsg ) {
648  dol_syslog(__METHOD__ . " " . $errmsg, LOG_ERR);
649  $this->error .= ($this->error ? ', ' . $errmsg : $errmsg);
650  }
651  $this->db->rollback();
652 
653  return - 1 * $error;
654  } else {
655  $this->db->commit();
656 
657  return 1;
658  }
659  }
660 
666  public function getCatsCpts()
667  {
668  global $mysoc,$conf;
669 
670  $sql = "";
671 
672  if (empty($mysoc->country_id)) {
673  dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined');
674  exit();
675  }
676 
677  $sql = "SELECT t.rowid, t.account_number, t.label as account_label, cat.code, cat.position, cat.label as name_cat, cat.sens ";
678  $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t, " . MAIN_DB_PREFIX . "c_accounting_category as cat";
679  $sql .= " WHERE t.fk_accounting_category IN ( SELECT c.rowid ";
680  $sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c";
681  $sql .= " WHERE c.active = 1";
682  $sql .= " AND c.entity = " . $conf->entity;
683  $sql .= " AND (c.fk_country = ".$mysoc->country_id." OR c.fk_country = 0)";
684  $sql .= " AND cat.rowid = t.fk_accounting_category";
685  $sql .= " AND t.entity = " . $conf->entity;
686  $sql .= " ORDER BY cat.position ASC";
687 
688  $resql = $this->db->query($sql);
689  if ($resql) {
690  $i = 0;
691  $obj = '';
692  $num = $this->db->num_rows($resql);
693  $data = array ();
694  if ($num) {
695  while ( $obj = $this->db->fetch_object($resql) ) {
696  $name_cat = $obj->name_cat;
697  $data[$name_cat][$i] = array (
698  'id' => $obj->rowid,
699  'code' => $obj->code,
700  'position' => $obj->position,
701  'account_number' => $obj->account_number,
702  'account_label' => $obj->account_label,
703  'sens' => $obj->sens
704  );
705  $i ++;
706  }
707  }
708  return $data;
709  } else {
710  $this->error = "Error " . $this->db->lasterror();
711  dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR);
712 
713  return -1;
714  }
715  }
716 
729  public function getSumDebitCredit($cpt, $date_start, $date_end, $sens, $thirdparty_code='nofilter', $month=0, $year=0)
730  {
731  global $conf;
732 
733  $this->sdc = 0;
734  $this->sdcpermonth = array();
735 
736  $sql = "SELECT SUM(t.debit) as debit, SUM(t.credit) as credit";
737  if (is_array($cpt)) $sql.=", t.numero_compte as accountancy_account";
738  $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as t";
739  //if (in_array($this->db->type, array('mysql', 'mysqli'))) $sql.=' USE INDEX idx_accounting_bookkeeping_doc_date';
740  $sql .= " WHERE t.entity = ".$conf->entity;
741  if (is_array($cpt))
742  {
743  $listofaccount='';
744  foreach($cpt as $cptcursor)
745  {
746  if ($listofaccount) $listofaccount.=",";
747  $listofaccount.="'".$cptcursor."'";
748  }
749  $sql .= " AND t.numero_compte IN (" .$listofaccount. ")";
750  }
751  else
752  {
753  $sql .= " AND t.numero_compte = '" . $this->db->escape($cpt) . "'";
754  }
755  if (! empty($date_start) && ! empty($date_end) && (empty($month) || empty($year))) // If month/year provided, it is stronger than filter date_start/date_end
756  $sql .= " AND (t.doc_date BETWEEN '".$this->db->idate($date_start)."' AND '".$this->db->idate($date_end)."')";
757  if (! empty($month) && ! empty($year)) {
758  $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))."')";
759  }
760  if ($thirdparty_code != 'nofilter')
761  {
762  $sql .= " AND t.thirdparty_code = '".$this->db->escape($thirdparty_code)."'";
763  }
764  if (is_array($cpt)) $sql.=" GROUP BY t.numero_compte";
765  //print $sql;
766 
767  $resql = $this->db->query($sql);
768  if ($resql)
769  {
770  $num = $this->db->num_rows($resql);
771  if ($num)
772  {
773  $obj = $this->db->fetch_object($resql);
774  if ($sens == 1) {
775  $this->sdc = $obj->debit - $obj->credit;
776  } else {
777  $this->sdc = $obj->credit - $obj->debit;
778  }
779  if (is_array($cpt))
780  {
781  $this->sdcperaccount[$obj->accountancy_account] = $this->sdc;
782  }
783  }
784  return $num;
785  } else {
786  $this->error = "Error " . $this->db->lasterror();
787  $this->errors[] = $this->error;
788  dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR);
789  return -1;
790  }
791  }
792 
799  public function getCats($categorytype=-1)
800  {
801  global $conf, $mysoc;
802 
803  if (empty($mysoc->country_id)) {
804  dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined');
805  exit();
806  }
807 
808  $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type";
809  $sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c";
810  $sql .= " WHERE c.active = 1";
811  $sql .= " AND c.entity = " . $conf->entity;
812  if ($categorytype >= 0) $sql.=" AND c.category_type = 1";
813  $sql .= " AND (c.fk_country = ".$mysoc->country_id." OR c.fk_country = 0)";
814  $sql .= " ORDER BY c.position ASC";
815 
816  $resql = $this->db->query($sql);
817  if ($resql) {
818  $i = 0;
819  $obj = '';
820  $num = $this->db->num_rows($resql);
821  $data = array ();
822  if ($num) {
823  while ( $i < $num ) {
824  $obj = $this->db->fetch_object($resql);
825 
826  $data[] = array (
827  'rowid' => $obj->rowid,
828  'code' => $obj->code,
829  'label' => $obj->label,
830  'formula' => $obj->formula,
831  'position' => $obj->position,
832  'category_type' => $obj->category_type
833  );
834  $i++;
835  }
836  }
837  return $data;
838  } else {
839  $this->error = "Error " . $this->db->lasterror();
840  $this->errors[] = $this->error;
841  dol_syslog(__METHOD__ . " " . implode(',', $this->errors), LOG_ERR);
842 
843  return - 1;
844  }
845  }
846 
847 
856  public function getCptsCat($cat_id, $predefinedgroupwhere='')
857  {
858  global $conf, $mysoc;
859  $sql = '';
860 
861  if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
862  dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined');
863  exit();
864  }
865 
866  if (! empty($cat_id))
867  {
868  $sql = "SELECT t.rowid, t.account_number, t.label as account_label";
869  $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t";
870  $sql .= " WHERE t.fk_accounting_category = ".$cat_id;
871  $sql .= " AND t.entity = " . $conf->entity;
872  $sql .= " ORDER BY t.account_number";
873  }
874  else
875  {
876  $sql = "SELECT t.rowid, t.account_number, t.label as account_label";
877  $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t";
878  $sql .= " WHERE ".$predefinedgroupwhere;
879  $sql .= " AND t.entity = " . $conf->entity;
880  $sql .= " ORDER BY t.account_number";
881  }
882  //echo $sql;
883 
884  $resql = $this->db->query($sql);
885  if ($resql) {
886  $i = 0;
887  $obj = '';
888  $num = $this->db->num_rows($resql);
889  $data = array();
890  if ($num) {
891  while ($obj = $this->db->fetch_object($resql))
892  {
893  $data[] = array (
894  'id' => $obj->rowid,
895  'account_number' => $obj->account_number,
896  'account_label' => $obj->account_label,
897  );
898  $i++;
899  }
900  }
901  return $data;
902  } else {
903  $this->error = "Error " . $this->db->lasterror();
904  dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR);
905 
906  return -1;
907  }
908  }
909 }
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
getCats($categorytype=-1)
Return list of personalized groups that are active.
create($user, $notrigger=0)
Create object into database.
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...
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:453
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage categories of an accounting account.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
getCptBK($id)
Function to select accounting category of an accounting account present in chart of accounts...
getCatsCpts()
Function to know all category from accounting account.
updateAccAcc($id_cat, $cpts=array())
Function to add an accounting account in an accounting category.
getCptsCat($cat_id, $predefinedgroupwhere='')
Get all accounting account of a group.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:467
display($id)
Function to select all accounting accounts from an accounting category.
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...
fetch($id, $code='', $label='')
Load object in memory from database.