dolibarr 19.0.3
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-2023 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
27require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
28
32class 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
133 public $sdcpermonth;
134
138 public $sdcperaccount;
139
145 public function __construct($db)
146 {
147 $this->db = $db;
148 }
149
150
158 public function create($user, $notrigger = 0)
159 {
160 global $conf, $langs;
161 $error = 0;
162
163 // Clean parameters
164 if (isset($this->code)) {
165 $this->code = trim($this->code);
166 }
167 if (isset($this->label)) {
168 $this->label = trim($this->label);
169 }
170 if (isset($this->range_account)) {
171 $this->range_account = trim($this->range_account);
172 }
173 if (isset($this->sens)) {
174 $this->sens = (int) $this->sens;
175 }
176 if (isset($this->category_type)) {
177 $this->category_type = (int) $this->category_type;
178 }
179 if (isset($this->formula)) {
180 $this->formula = trim($this->formula);
181 }
182 if (isset($this->position)) {
183 $this->position = (int) $this->position;
184 }
185 if (isset($this->fk_country)) {
186 $this->fk_country = (int) $this->fk_country;
187 }
188 if (isset($this->active)) {
189 $this->active = (int) $this->active;
190 }
191
192 // Check parameters
193 // Put here code to add control on parameters values
194
195 // Insert request
196 $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_accounting_category(";
197 if ($this->rowid > 0) {
198 $sql .= "rowid, ";
199 }
200 $sql .= "code, ";
201 $sql .= "label, ";
202 $sql .= "range_account, ";
203 $sql .= "sens, ";
204 $sql .= "category_type, ";
205 $sql .= "formula, ";
206 $sql .= "position, ";
207 $sql .= "fk_country, ";
208 $sql .= "active, ";
209 $sql .= "entity";
210 $sql .= ") VALUES (";
211 if ($this->rowid > 0) {
212 $sql .= " ".((int) $this->rowid).",";
213 }
214 $sql .= " ".(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").",";
215 $sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").",";
216 $sql .= " ".(!isset($this->range_account) ? 'NULL' : "'".$this->db->escape($this->range_account)."'").",";
217 $sql .= " ".(!isset($this->sens) ? 'NULL' : "'".$this->db->escape($this->sens)."'").",";
218 $sql .= " ".(!isset($this->category_type) ? 'NULL' : "'".$this->db->escape($this->category_type)."'").",";
219 $sql .= " ".(!isset($this->formula) ? 'NULL' : "'".$this->db->escape($this->formula)."'").",";
220 $sql .= " ".(!isset($this->position) ? 'NULL' : ((int) $this->position)).",";
221 $sql .= " ".(!isset($this->fk_country) ? 'NULL' : ((int) $this->fk_country)).",";
222 $sql .= " ".(!isset($this->active) ? 'NULL' : ((int) $this->active));
223 $sql .= ", ".((int) $conf->entity);
224 $sql .= ")";
225
226 $this->db->begin();
227
228 dol_syslog(get_class($this)."::create", LOG_DEBUG);
229 $resql = $this->db->query($sql);
230 if (!$resql) {
231 $error++;
232 $this->errors[] = "Error ".$this->db->lasterror();
233 }
234
235 // Commit or rollback
236 if ($error) {
237 foreach ($this->errors as $errmsg) {
238 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
239 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
240 }
241 $this->db->rollback();
242 return -1 * $error;
243 } else {
244 $this->db->commit();
245 return $this->id;
246 }
247 }
248
249
258 public function fetch($id, $code = '', $label = '')
259 {
260 $sql = "SELECT";
261 $sql .= " t.rowid,";
262 $sql .= " t.code,";
263 $sql .= " t.label,";
264 $sql .= " t.range_account,";
265 $sql .= " t.sens,";
266 $sql .= " t.category_type,";
267 $sql .= " t.formula,";
268 $sql .= " t.position,";
269 $sql .= " t.fk_country,";
270 $sql .= " t.active";
271 $sql .= " FROM ".MAIN_DB_PREFIX."c_accounting_category as t";
272 if ($id) {
273 $sql .= " WHERE t.rowid = ".((int) $id);
274 } else {
275 $sql .= " WHERE t.entity IN (".getEntity('c_accounting_category').")"; // Don't use entity if you use rowid
276 if ($code) {
277 $sql .= " AND t.code = '".$this->db->escape($code)."'";
278 } elseif ($label) {
279 $sql .= " AND t.label = '".$this->db->escape($label)."'";
280 }
281 }
282
283 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
284 $resql = $this->db->query($sql);
285 if ($resql) {
286 if ($this->db->num_rows($resql)) {
287 $obj = $this->db->fetch_object($resql);
288
289 $this->id = $obj->rowid;
290 $this->code = $obj->code;
291 $this->label = $obj->label;
292 $this->range_account = $obj->range_account;
293 $this->sens = $obj->sens;
294 $this->category_type = $obj->category_type;
295 $this->formula = $obj->formula;
296 $this->position = $obj->position;
297 $this->fk_country = $obj->fk_country;
298 $this->active = $obj->active;
299 }
300 $this->db->free($resql);
301
302 return 1;
303 } else {
304 $this->error = "Error ".$this->db->lasterror();
305 return -1;
306 }
307 }
308
309
317 public function update($user = null, $notrigger = 0)
318 {
319 global $conf, $langs;
320 $error = 0;
321
322 // Clean parameters
323 if (isset($this->code)) {
324 $this->code = trim($this->code);
325 }
326 if (isset($this->label)) {
327 $this->label = trim($this->label);
328 }
329 if (isset($this->range_account)) {
330 $this->range_account = trim($this->range_account);
331 }
332 if (isset($this->sens)) {
333 $this->sens = (int) $this->sens;
334 }
335 if (isset($this->category_type)) {
336 $this->category_type = (int) $this->category_type;
337 }
338 if (isset($this->formula)) {
339 $this->formula = trim($this->formula);
340 }
341 if (isset($this->position)) {
342 $this->position = (int) $this->position;
343 }
344 if (isset($this->fk_country)) {
345 $this->fk_country = (int) $this->fk_country;
346 }
347 if (isset($this->active)) {
348 $this->active = (int) $this->active;
349 }
350
351
352 // Check parameters
353 // Put here code to add control on parameters values
354
355 // Update request
356 $sql = "UPDATE ".MAIN_DB_PREFIX."c_accounting_category SET";
357 $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").",";
358 $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
359 $sql .= " range_account=".(isset($this->range_account) ? "'".$this->db->escape($this->range_account)."'" : "null").",";
360 $sql .= " sens=".(isset($this->sens) ? $this->sens : "null").",";
361 $sql .= " category_type=".(isset($this->category_type) ? $this->category_type : "null").",";
362 $sql .= " formula=".(isset($this->formula) ? "'".$this->db->escape($this->formula)."'" : "null").",";
363 $sql .= " position=".(isset($this->position) ? $this->position : "null").",";
364 $sql .= " fk_country=".(isset($this->fk_country) ? $this->fk_country : "null").",";
365 $sql .= " active=".(isset($this->active) ? $this->active : "null");
366 $sql .= " WHERE rowid=".((int) $this->id);
367
368 $this->db->begin();
369
370 dol_syslog(get_class($this)."::update", LOG_DEBUG);
371 $resql = $this->db->query($sql);
372 if (!$resql) {
373 $error++;
374 $this->errors[] = "Error ".$this->db->lasterror();
375 }
376
377 // Commit or rollback
378 if ($error) {
379 foreach ($this->errors as $errmsg) {
380 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
381 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
382 }
383 $this->db->rollback();
384 return -1 * $error;
385 } else {
386 $this->db->commit();
387 return 1;
388 }
389 }
390
391
399 public function delete($user, $notrigger = 0)
400 {
401 global $conf, $langs;
402 $error = 0;
403
404 $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_accounting_category";
405 $sql .= " WHERE rowid=".((int) $this->id);
406
407 $this->db->begin();
408
409 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
410 $resql = $this->db->query($sql);
411 if (!$resql) {
412 $error++;
413 $this->errors[] = "Error ".$this->db->lasterror();
414 }
415
416 // Commit or rollback
417 if ($error) {
418 foreach ($this->errors as $errmsg) {
419 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
420 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
421 }
422 $this->db->rollback();
423 return -1 * $error;
424 } else {
425 $this->db->commit();
426 return 1;
427 }
428 }
429
430
437 public function display($id)
438 {
439 global $conf;
440 $sql = "SELECT t.rowid, t.account_number, t.label";
441 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as t";
442 $sql .= " WHERE t.fk_accounting_category = ".((int) $id);
443 $sql .= " AND t.entity = ".$conf->entity;
444
445 $this->lines_display = array();
446
447 dol_syslog(__METHOD__, LOG_DEBUG);
448 $resql = $this->db->query($sql);
449 if ($resql) {
450 $num = $this->db->num_rows($resql);
451 if ($num) {
452 while ($obj = $this->db->fetch_object($resql)) {
453 $this->lines_display[] = $obj;
454 }
455 }
456 return $num;
457 } else {
458 $this->error = "Error ".$this->db->lasterror();
459 $this->errors[] = $this->error;
460 dol_syslog(__METHOD__." ".implode(',', $this->errors), LOG_ERR);
461
462 return -1;
463 }
464 }
465
472 public function getAccountsWithNoCategory($id)
473 {
474 global $conf;
475
476 $sql = "SELECT aa.account_number as numero_compte, aa.label as label_compte";
477 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
478 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
479 $sql .= " WHERE (aa.fk_accounting_category <> ".((int) $id)." OR aa.fk_accounting_category IS NULL)";
480 $sql .= " AND asy.rowid = ".((int) getDolGlobalInt('CHARTOFACCOUNTS'));
481 $sql .= " AND aa.active = 1";
482 $sql .= " AND aa.entity = ".$conf->entity;
483 $sql .= " GROUP BY aa.account_number, aa.label";
484 $sql .= " ORDER BY aa.account_number, aa.label";
485
486 $this->lines_cptbk = array();
487
488 dol_syslog(__METHOD__, LOG_DEBUG);
489 $resql = $this->db->query($sql);
490 if ($resql) {
491 $num = $this->db->num_rows($resql);
492 if ($num) {
493 while ($obj = $this->db->fetch_object($resql)) {
494 $this->lines_cptbk[] = $obj;
495 }
496 }
497
498 return $num;
499 } else {
500 $this->error = "Error ".$this->db->lasterror();
501 $this->errors[] = $this->error;
502 dol_syslog(__METHOD__." ".implode(',', $this->errors), LOG_ERR);
503
504 return -1;
505 }
506 }
507
516 public function updateAccAcc($id_cat, $cpts = array())
517 {
518 global $conf;
519 $error = 0;
520
521 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
522
523 $sql = "SELECT aa.rowid, aa.account_number";
524 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
525 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
526 $sql .= " AND asy.rowid = ".((int) getDolGlobalInt('CHARTOFACCOUNTS'));
527 $sql .= " AND aa.active = 1";
528 $sql .= " AND aa.entity = ".$conf->entity;
529 $sql .= " ORDER BY LENGTH(aa.account_number) DESC;"; // LENGTH is ok with mysql and postgresql
530
531 $this->db->begin();
532
533 dol_syslog(__METHOD__, LOG_DEBUG);
534 $resql = $this->db->query($sql);
535 if (!$resql) {
536 $error++;
537 $this->errors[] = "Error ".$this->db->lasterror();
538 $this->db->rollback();
539 return -1;
540 }
541
542 $accountincptsadded = array();
543 while ($obj = $this->db->fetch_object($resql)) {
544 $account_number_formated = length_accountg($obj->account_number);
545 if (!empty($accountincptsadded[$account_number_formated])) {
546 continue;
547 }
548
549 if (array_key_exists($account_number_formated, $cpts)) {
550 $accountincptsadded[$account_number_formated] = 1;
551 // We found an account number that is in list $cpts of account to add
552 $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_account";
553 $sql .= " SET fk_accounting_category=".((int) $id_cat);
554 $sql .= " WHERE rowid=".((int) $obj->rowid);
555 dol_syslog(__METHOD__, LOG_DEBUG);
556 $resqlupdate = $this->db->query($sql);
557 if (!$resqlupdate) {
558 $error++;
559 $this->errors[] = "Error ".$this->db->lasterror();
560 }
561 }
562 }
563
564 // Commit or rollback
565 if ($error) {
566 foreach ($this->errors as $errmsg) {
567 dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
568 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
569 }
570 $this->db->rollback();
571
572 return -1 * $error;
573 } else {
574 $this->db->commit();
575
576 return 1;
577 }
578 }
579
587 public function deleteCptCat($cpt_id)
588 {
589 $error = 0;
590
591 $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_account as aa";
592 $sql .= " SET fk_accounting_category= 0";
593 $sql .= " WHERE aa.rowid = ".((int) $cpt_id);
594 $this->db->begin();
595
596 dol_syslog(__METHOD__, LOG_DEBUG);
597 $resql = $this->db->query($sql);
598 if (!$resql) {
599 $error++;
600 $this->errors[] = "Error ".$this->db->lasterror();
601 }
602
603 // Commit or rollback
604 if ($error) {
605 foreach ($this->errors as $errmsg) {
606 dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
607 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
608 }
609 $this->db->rollback();
610
611 return -1 * $error;
612 } else {
613 $this->db->commit();
614
615 return 1;
616 }
617 }
618
631 public function getSumDebitCredit($cpt, $date_start, $date_end, $sens, $thirdparty_code = 'nofilter', $month = 0, $year = 0)
632 {
633 global $conf;
634
635 $this->sdc = 0;
636 $this->sdcpermonth = array();
637
638 if (is_array($cpt)) {
639 $listofaccount = '';
640 foreach ($cpt as $cptcursor) {
641 if (! is_null($cptcursor)) {
642 if ($listofaccount) {
643 $listofaccount .= ",";
644 }
645 $listofaccount .= "'".$cptcursor."'";
646 }
647 }
648 if (empty($listofaccount)) {
649 // List of account is empty, so we do no try sql request, we can say result is empty.
650 return 0;
651 }
652 }
653
654 $sql = "SELECT SUM(t.debit) as debit, SUM(t.credit) as credit";
655 if (is_array($cpt)) {
656 $sql .= ", t.numero_compte as accountancy_account";
657 }
658 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as t";
659 //if (in_array($this->db->type, array('mysql', 'mysqli'))) $sql.=' USE INDEX idx_accounting_bookkeeping_doc_date';
660 $sql .= " WHERE t.entity = ".((int) $conf->entity);
661 if (is_array($cpt)) {
662 $sql .= " AND t.numero_compte IN (".$this->db->sanitize($listofaccount, 1).")";
663 } else {
664 $sql .= " AND t.numero_compte = '".$this->db->escape($cpt)."'";
665 }
666 if (!empty($date_start) && !empty($date_end) && (empty($month) || empty($year))) { // If month/year provided, it is stronger than filter date_start/date_end
667 $sql .= " AND (t.doc_date BETWEEN '".$this->db->idate($date_start)."' AND '".$this->db->idate($date_end)."')";
668 }
669 if (!empty($month) && !empty($year)) {
670 $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))."')";
671 }
672 if ($thirdparty_code != 'nofilter') {
673 $sql .= " AND t.thirdparty_code = '".$this->db->escape($thirdparty_code)."'";
674 }
675 if (is_array($cpt)) {
676 $sql .= " GROUP BY t.numero_compte";
677 }
678
679 $resql = $this->db->query($sql);
680 if ($resql) {
681 $num = $this->db->num_rows($resql);
682 if ($num) {
683 $i = 0;
684 while ($i < $num) {
685 $obj = $this->db->fetch_object($resql);
686 if ($obj) {
687 if ($sens == 1) {
688 $this->sdc = $obj->debit - $obj->credit;
689 } else {
690 $this->sdc = $obj->credit - $obj->debit;
691 }
692 if (is_array($cpt)) {
693 $this->sdcperaccount[$obj->accountancy_account] = $this->sdc;
694 }
695 }
696 $i++;
697 }
698 }
699
700 return $num;
701 } else {
702 $this->error = "Error ".$this->db->lasterror();
703 $this->errors[] = $this->error;
704 dol_syslog(__METHOD__." ".$this->error, LOG_ERR);
705 return -1;
706 }
707 }
708
716 public function getCatsCpts($catid = 0)
717 {
718 global $mysoc, $conf;
719
720 if (empty($mysoc->country_id)) {
721 $this->error = "Error ".$this->db->lasterror();
722 dol_syslog(__METHOD__." ".$this->error, LOG_ERR);
723 return -1;
724 }
725
726 $sql = "SELECT t.rowid, t.account_number, t.label as account_label,";
727 $sql .= " cat.code, cat.position, cat.label as name_cat, cat.sens, cat.category_type, cat.formula";
728 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as t, ".MAIN_DB_PREFIX."c_accounting_category as cat";
729 $sql .= " WHERE t.fk_accounting_category IN (SELECT c.rowid";
730 $sql .= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c";
731 $sql .= " WHERE c.active = 1";
732 $sql .= " AND c.entity = ".$conf->entity;
733 $sql .= " AND (c.fk_country = ".((int) $mysoc->country_id)." OR c.fk_country = 0)";
734 $sql .= " AND cat.rowid = t.fk_accounting_category";
735 $sql .= " AND t.entity = ".$conf->entity;
736 if ($catid > 0) {
737 $sql .= " AND cat.rowid = ".((int) $catid);
738 }
739 $sql .= " ORDER BY cat.position ASC";
740
741 $resql = $this->db->query($sql);
742 if ($resql) {
743 $obj = '';
744 $num = $this->db->num_rows($resql);
745 $data = array();
746 if ($num) {
747 while ($obj = $this->db->fetch_object($resql)) {
748 $name_cat = $obj->name_cat;
749 $data[$name_cat][$obj->rowid] = array(
750 'id' => $obj->rowid,
751 'code' => $obj->code,
752 'label' => $obj->label,
753 'position' => $obj->position,
754 'category_type' => $obj->category_type,
755 'formula' => $obj->formula,
756 'sens' => $obj->sens,
757 'account_number' => $obj->account_number,
758 'account_label' => $obj->account_label
759 );
760 }
761 }
762 return $data;
763 } else {
764 $this->error = "Error ".$this->db->lasterror();
765 dol_syslog(__METHOD__." ".$this->error, LOG_ERR);
766 return -1;
767 }
768 }
769
779 public function getCats($categorytype = -1, $active = 1)
780 {
781 global $conf, $mysoc;
782
783 if (empty($mysoc->country_id)) {
784 dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined');
785 exit();
786 }
787
788 $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type, c.sens";
789 $sql .= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c";
790 $sql .= " WHERE c.active = " . (int) $active;
791 $sql .= " AND c.entity = ".$conf->entity;
792 if ($categorytype >= 0) {
793 $sql .= " AND c.category_type = 1";
794 }
795 $sql .= " AND (c.fk_country = ".((int) $mysoc->country_id)." OR c.fk_country = 0)";
796 $sql .= " ORDER BY c.position ASC";
797
798 $resql = $this->db->query($sql);
799 if ($resql) {
800 $i = 0;
801 $obj = '';
802 $num = $this->db->num_rows($resql);
803 $data = array();
804 if ($num) {
805 while ($i < $num) {
806 $obj = $this->db->fetch_object($resql);
807
808 $data[] = array(
809 'rowid' => $obj->rowid,
810 'code' => $obj->code,
811 'label' => $obj->label,
812 'position' => $obj->position,
813 'category_type' => $obj->category_type,
814 'formula' => $obj->formula,
815 'sens' => $obj->sens,
816 'bc' => $obj->sens
817 );
818 $i++;
819 }
820 }
821 return $data;
822 } else {
823 $this->error = "Error ".$this->db->lasterror();
824 $this->errors[] = $this->error;
825 dol_syslog(__METHOD__." ".implode(',', $this->errors), LOG_ERR);
826
827 return -1;
828 }
829 }
830
831
843 public function getCptsCat($cat_id, $predefinedgroupwhere = '')
844 {
845 global $conf, $mysoc;
846 $sql = '';
847
848 if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
849 dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined');
850 exit();
851 }
852
853 $pcgverid = getDolGlobalInt('CHARTOFACCOUNTS');
854 $pcgvercode = dol_getIdFromCode($this->db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
855 if (empty($pcgvercode)) {
856 $pcgvercode = $pcgverid;
857 }
858
859 if (!empty($cat_id)) {
860 $sql = "SELECT t.rowid, t.account_number, t.label as account_label";
861 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as t";
862 $sql .= " WHERE t.fk_accounting_category = ".((int) $cat_id);
863 $sql .= " AND t.entity = ".$conf->entity;
864 $sql .= " AND t.active = 1";
865 $sql .= " AND t.fk_pcg_version = '".$this->db->escape($pcgvercode)."'";
866 $sql .= " ORDER BY t.account_number";
867 } else {
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 ".$predefinedgroupwhere;
871 $sql .= " AND t.entity = ".$conf->entity;
872 $sql .= ' AND t.active = 1';
873 $sql .= " AND t.fk_pcg_version = '".$this->db->escape($pcgvercode)."'";
874 $sql .= " ORDER BY t.account_number";
875 }
876
877 $resql = $this->db->query($sql);
878 if ($resql) {
879 $i = 0;
880 $obj = '';
881 $num = $this->db->num_rows($resql);
882 $data = array();
883 if ($num) {
884 while ($obj = $this->db->fetch_object($resql)) {
885 $data[] = array(
886 'id' => $obj->rowid,
887 'account_number' => $obj->account_number,
888 'account_label' => $obj->account_label,
889 );
890 $i++;
891 }
892 }
893 return $data;
894 } else {
895 $this->error = "Error ".$this->db->lasterror();
896 dol_syslog(__METHOD__." ".$this->error, LOG_ERR);
897
898 return -1;
899 }
900 }
901}
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
Class to manage categories of an accounting account.
getCptsCat($cat_id, $predefinedgroupwhere='')
Get all accounting account of a given custom group (or a list of custom groups).
update($user=null, $notrigger=0)
Update object into database.
getAccountsWithNoCategory($id)
Function to fill ->lines_cptbk with accounting account (defined in chart of account) and not yet into...
create($user, $notrigger=0)
Create object into database.
getCats($categorytype=-1, $active=1)
Return list of custom groups.
getCatsCpts($catid=0)
Function to get an array of all active custom groups (llx_c_accunting_categories) with their accounts...
fetch($id, $code='', $label='')
Load object in memory from database.
deleteCptCat($cpt_id)
Function to delete an accounting account from an accounting category.
display($id)
Function to select into ->lines_display all accounting accounts for a given custom accounting group.
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.
updateAccAcc($id_cat, $cpts=array())
Function to add an accounting account in an accounting category.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:594
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:613
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
rtl background position
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid
Definition invoice.php:1926