dolibarr 21.0.0-beta
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-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Class
28require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
29
33class AccountancyCategory // extends CommonObject
34{
38 public $db;
39
43 public $error;
44
48 public $errors = array();
49
53 public $element = 'c_accounting_category';
54
58 public $table_element = 'c_accounting_category';
59
64 public $rowid;
65
69 public $id;
70
74 public $code;
75
79 public $label;
80
84 public $range_account;
85
89 public $sens;
90
94 public $category_type;
95
99 public $formula;
100
104 public $position;
105
109 public $fk_country;
110
114 public $active;
115
119 public $lines_cptbk;
120
124 public $lines_display;
125
129 public $sdc;
130
134 public $sdcpermonth;
135
139 public $sdcperaccount;
140
146 public function __construct($db)
147 {
148 $this->db = $db;
149 }
150
151
159 public function create($user, $notrigger = 0)
160 {
161 global $conf, $langs;
162 $error = 0;
163
164 // Clean parameters
165 if (isset($this->code)) {
166 $this->code = trim($this->code);
167 }
168 if (isset($this->label)) {
169 $this->label = trim($this->label);
170 }
171 if (isset($this->range_account)) {
172 $this->range_account = trim($this->range_account);
173 }
174 if (isset($this->sens)) {
175 $this->sens = (int) $this->sens;
176 }
177 if (isset($this->category_type)) {
178 $this->category_type = (int) $this->category_type;
179 }
180 if (isset($this->formula)) {
181 $this->formula = trim($this->formula);
182 }
183 if (isset($this->position)) {
184 $this->position = (int) $this->position;
185 }
186 if (isset($this->fk_country)) {
187 $this->fk_country = (int) $this->fk_country;
188 }
189 if (isset($this->active)) {
190 $this->active = (int) $this->active;
191 }
192
193 // Check parameters
194 // Put here code to add control on parameters values
195
196 // Insert request
197 $sql = "INSERT INTO ".$this->db->prefix().$this->table_element." (";
198 if ($this->rowid > 0) {
199 $sql .= "rowid, ";
200 }
201 $sql .= "code, ";
202 $sql .= "label, ";
203 $sql .= "range_account, ";
204 $sql .= "sens, ";
205 $sql .= "category_type, ";
206 $sql .= "formula, ";
207 $sql .= "position, ";
208 $sql .= "fk_country, ";
209 $sql .= "active, ";
210 $sql .= "entity";
211 $sql .= ") VALUES (";
212 if ($this->rowid > 0) {
213 $sql .= " ".((int) $this->rowid).",";
214 }
215 $sql .= " ".(!isset($this->code) ? "NULL" : "'".$this->db->escape($this->code)."'").",";
216 $sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").",";
217 $sql .= " ".(!isset($this->range_account) ? 'NULL' : "'".$this->db->escape($this->range_account)."'").",";
218 $sql .= " ".(!isset($this->sens) ? 'NULL' : "'".$this->db->escape($this->sens)."'").",";
219 $sql .= " ".(!isset($this->category_type) ? 'NULL' : "'".$this->db->escape($this->category_type)."'").",";
220 $sql .= " ".(!isset($this->formula) ? 'NULL' : "'".$this->db->escape($this->formula)."'").",";
221 $sql .= " ".(!isset($this->position) ? 'NULL' : ((int) $this->position)).",";
222 $sql .= " ".(!isset($this->fk_country) ? 'NULL' : ((int) $this->fk_country)).",";
223 $sql .= " ".(!isset($this->active) ? 'NULL' : ((int) $this->active));
224 $sql .= ", ".((int) $conf->entity);
225 $sql .= ")";
226
227 $this->db->begin();
228
229 dol_syslog(get_class($this)."::create", LOG_DEBUG);
230 $resql = $this->db->query($sql);
231 if (!$resql) {
232 $error++;
233 $this->errors[] = "Error ".$this->db->lasterror();
234 }
235
236 // Commit or rollback
237 if ($error) {
238 foreach ($this->errors as $errmsg) {
239 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
240 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
241 }
242 $this->db->rollback();
243 return -1 * $error;
244 } else {
245 $this->db->commit();
246 return $this->id;
247 }
248 }
249
250
259 public function fetch($id, $code = '', $label = '')
260 {
261 $sql = "SELECT";
262 $sql .= " t.rowid,";
263 $sql .= " t.code,";
264 $sql .= " t.label,";
265 $sql .= " t.range_account,";
266 $sql .= " t.sens,";
267 $sql .= " t.category_type,";
268 $sql .= " t.formula,";
269 $sql .= " t.position,";
270 $sql .= " t.fk_country,";
271 $sql .= " t.active";
272 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
273 if ($id) {
274 $sql .= " WHERE t.rowid = ".((int) $id);
275 } else {
276 $sql .= " WHERE t.entity IN (".getEntity('c_accounting_category').")"; // Don't use entity if you use rowid
277 if ($code) {
278 $sql .= " AND t.code = '".$this->db->escape($code)."'";
279 } elseif ($label) {
280 $sql .= " AND t.label = '".$this->db->escape($label)."'";
281 }
282 }
283
284 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
285 $resql = $this->db->query($sql);
286 if ($resql) {
287 if ($this->db->num_rows($resql)) {
288 $obj = $this->db->fetch_object($resql);
289
290 $this->id = $obj->rowid;
291 $this->code = $obj->code;
292 $this->label = $obj->label;
293 $this->range_account = $obj->range_account;
294 $this->sens = $obj->sens;
295 $this->category_type = $obj->category_type;
296 $this->formula = $obj->formula;
297 $this->position = $obj->position;
298 $this->fk_country = $obj->fk_country;
299 $this->active = $obj->active;
300 }
301 $this->db->free($resql);
302
303 return 1;
304 } else {
305 $this->error = "Error ".$this->db->lasterror();
306 return -1;
307 }
308 }
309
310
318 public function update($user = null, $notrigger = 0)
319 {
320 global $conf, $langs;
321 $error = 0;
322
323 // Clean parameters
324 if (isset($this->code)) {
325 $this->code = trim($this->code);
326 }
327 if (isset($this->label)) {
328 $this->label = trim($this->label);
329 }
330 if (isset($this->range_account)) {
331 $this->range_account = trim($this->range_account);
332 }
333 if (isset($this->sens)) {
334 $this->sens = (int) $this->sens;
335 }
336 if (isset($this->category_type)) {
337 $this->category_type = (int) $this->category_type;
338 }
339 if (isset($this->formula)) {
340 $this->formula = trim($this->formula);
341 }
342 if (isset($this->position)) {
343 $this->position = (int) $this->position;
344 }
345 if (isset($this->fk_country)) {
346 $this->fk_country = (int) $this->fk_country;
347 }
348 if (isset($this->active)) {
349 $this->active = (int) $this->active;
350 }
351
352
353 // Check parameters
354 // Put here code to add control on parameters values
355
356 // Update request
357 $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET";
358 $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").",";
359 $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
360 $sql .= " range_account=".(isset($this->range_account) ? "'".$this->db->escape($this->range_account)."'" : "null").",";
361 $sql .= " sens=".(isset($this->sens) ? ((int) $this->sens) : "null").",";
362 $sql .= " category_type=".(isset($this->category_type) ? ((int) $this->category_type) : "null").",";
363 $sql .= " formula=".(isset($this->formula) ? "'".$this->db->escape($this->formula)."'" : "null").",";
364 $sql .= " position=".(isset($this->position) ? ((int) $this->position) : "null").",";
365 $sql .= " fk_country=".(isset($this->fk_country) ? ((int) $this->fk_country) : "null").",";
366 $sql .= " active=".(isset($this->active) ? ((int) $this->active) : "null");
367 $sql .= " WHERE rowid=".((int) $this->id);
368
369 $this->db->begin();
370
371 dol_syslog(get_class($this)."::update", LOG_DEBUG);
372 $resql = $this->db->query($sql);
373 if (!$resql) {
374 $error++;
375 $this->errors[] = "Error ".$this->db->lasterror();
376 }
377
378 // Commit or rollback
379 if ($error) {
380 foreach ($this->errors as $errmsg) {
381 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
382 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
383 }
384 $this->db->rollback();
385 return -1 * $error;
386 } else {
387 $this->db->commit();
388 return 1;
389 }
390 }
391
392
400 public function delete($user, $notrigger = 0)
401 {
402 global $conf, $langs;
403 $error = 0;
404
405 $sql = "DELETE FROM ".$this->db->prefix().$this->table_element;
406 $sql .= " WHERE rowid=".((int) $this->id);
407
408 $this->db->begin();
409
410 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
411 $resql = $this->db->query($sql);
412 if (!$resql) {
413 $error++;
414 $this->errors[] = "Error ".$this->db->lasterror();
415 }
416
417 // Commit or rollback
418 if ($error) {
419 foreach ($this->errors as $errmsg) {
420 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
421 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
422 }
423 $this->db->rollback();
424 return -1 * $error;
425 } else {
426 $this->db->commit();
427 return 1;
428 }
429 }
430
431
438 public function display($id)
439 {
440 global $conf;
441 $sql = "SELECT t.rowid, t.account_number, t.label";
442 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
443 $sql .= " WHERE t.fk_accounting_category = ".((int) $id);
444 $sql .= " AND t.entity = ".$conf->entity;
445
446 $this->lines_display = array();
447
448 dol_syslog(__METHOD__, LOG_DEBUG);
449 $resql = $this->db->query($sql);
450 if ($resql) {
451 $num = $this->db->num_rows($resql);
452 if ($num) {
453 while ($obj = $this->db->fetch_object($resql)) {
454 $this->lines_display[] = $obj;
455 }
456 }
457 return $num;
458 } else {
459 $this->error = "Error ".$this->db->lasterror();
460 $this->errors[] = $this->error;
461 dol_syslog(__METHOD__." ".implode(',', $this->errors), LOG_ERR);
462
463 return -1;
464 }
465 }
466
473 public function getAccountsWithNoCategory($id)
474 {
475 global $conf;
476
477 $sql = "SELECT aa.account_number as numero_compte, aa.label as label_compte";
478 $sql .= " FROM ".$this->db->prefix()."accounting_account as aa";
479 $sql .= " INNER JOIN ".$this->db->prefix()."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
480 $sql .= " WHERE (aa.fk_accounting_category <> ".((int) $id)." OR aa.fk_accounting_category IS NULL)";
481 $sql .= " AND asy.rowid = ".((int) getDolGlobalInt('CHARTOFACCOUNTS'));
482 $sql .= " AND aa.active = 1";
483 $sql .= " AND aa.entity = ".$conf->entity;
484 $sql .= " GROUP BY aa.account_number, aa.label";
485 $sql .= " ORDER BY aa.account_number, aa.label";
486
487 $this->lines_cptbk = array();
488
489 dol_syslog(__METHOD__, LOG_DEBUG);
490 $resql = $this->db->query($sql);
491 if ($resql) {
492 $num = $this->db->num_rows($resql);
493 if ($num) {
494 while ($obj = $this->db->fetch_object($resql)) {
495 $this->lines_cptbk[] = $obj;
496 }
497 }
498
499 return $num;
500 } else {
501 $this->error = "Error ".$this->db->lasterror();
502 $this->errors[] = $this->error;
503 dol_syslog(__METHOD__." ".implode(',', $this->errors), LOG_ERR);
504
505 return -1;
506 }
507 }
508
517 public function updateAccAcc($id_cat, $cpts = array())
518 {
519 global $conf;
520 $error = 0;
521
522 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
523
524 $sql = "SELECT aa.rowid, aa.account_number";
525 $sql .= " FROM ".$this->db->prefix()."accounting_account as aa";
526 $sql .= " INNER JOIN ".$this->db->prefix()."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
527 $sql .= " AND asy.rowid = ".((int) getDolGlobalInt('CHARTOFACCOUNTS'));
528 $sql .= " AND aa.active = 1";
529 $sql .= " AND aa.entity = ".$conf->entity;
530 $sql .= " ORDER BY LENGTH(aa.account_number) DESC;"; // LENGTH is ok with mysql and postgresql
531
532 $this->db->begin();
533
534 dol_syslog(__METHOD__, LOG_DEBUG);
535 $resql = $this->db->query($sql);
536 if (!$resql) {
537 $error++;
538 $this->errors[] = "Error ".$this->db->lasterror();
539 $this->db->rollback();
540 return -1;
541 }
542
543 $accountincptsadded = array();
544 while ($obj = $this->db->fetch_object($resql)) {
545 $account_number_formated = length_accountg($obj->account_number);
546 if (!empty($accountincptsadded[$account_number_formated])) {
547 continue;
548 }
549
550 if (array_key_exists($account_number_formated, $cpts)) {
551 $accountincptsadded[$account_number_formated] = 1;
552 // We found an account number that is in list $cpts of account to add
553 $sql = "UPDATE ".$this->db->prefix()."accounting_account";
554 $sql .= " SET fk_accounting_category=".((int) $id_cat);
555 $sql .= " WHERE rowid=".((int) $obj->rowid);
556 dol_syslog(__METHOD__, LOG_DEBUG);
557 $resqlupdate = $this->db->query($sql);
558 if (!$resqlupdate) {
559 $error++;
560 $this->errors[] = "Error ".$this->db->lasterror();
561 }
562 }
563 }
564
565 // Commit or rollback
566 if ($error) {
567 foreach ($this->errors as $errmsg) {
568 dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
569 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
570 }
571 $this->db->rollback();
572
573 return -1 * $error;
574 } else {
575 $this->db->commit();
576
577 return 1;
578 }
579 }
580
588 public function deleteCptCat($cpt_id)
589 {
590 $error = 0;
591
592 $sql = "UPDATE ".$this->db->prefix()."accounting_account as aa";
593 $sql .= " SET fk_accounting_category= 0";
594 $sql .= " WHERE aa.rowid = ".((int) $cpt_id);
595 $this->db->begin();
596
597 dol_syslog(__METHOD__, LOG_DEBUG);
598 $resql = $this->db->query($sql);
599 if (!$resql) {
600 $error++;
601 $this->errors[] = "Error ".$this->db->lasterror();
602 }
603
604 // Commit or rollback
605 if ($error) {
606 foreach ($this->errors as $errmsg) {
607 dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
608 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
609 }
610 $this->db->rollback();
611
612 return -1 * $error;
613 } else {
614 $this->db->commit();
615
616 return 1;
617 }
618 }
619
632 public function getSumDebitCredit($cpt, $date_start, $date_end, $sens, $thirdparty_code = 'nofilter', $month = 0, $year = 0)
633 {
634 global $conf;
635
636 $this->sdc = 0;
637 $this->sdcpermonth = array();
638
639 $listofaccount = '';
640
641 if (is_array($cpt)) {
642 foreach ($cpt as $cptcursor) {
643 if (! is_null($cptcursor)) {
644 if ($listofaccount) {
645 $listofaccount .= ",";
646 }
647 $listofaccount .= "'".$cptcursor."'";
648 }
649 }
650 if (empty($listofaccount)) {
651 // List of account is empty, so we do no try sql request, we can say result is empty.
652 return 0;
653 }
654 }
655
656 $sql = "SELECT SUM(t.debit) as debit, SUM(t.credit) as credit";
657 if (is_array($cpt)) {
658 $sql .= ", t.numero_compte as accountancy_account";
659 }
660 $sql .= " FROM ".$this->db->prefix()."accounting_bookkeeping as t";
661 //if (in_array($this->db->type, array('mysql', 'mysqli'))) $sql.=' USE INDEX idx_accounting_bookkeeping_doc_date';
662 $sql .= " WHERE t.entity = ".((int) $conf->entity);
663 if (is_array($cpt)) {
664 $sql .= " AND t.numero_compte IN (".$this->db->sanitize($listofaccount, 1).")";
665 } else {
666 $sql .= " AND t.numero_compte = '".$this->db->escape($cpt)."'";
667 }
668 if (!empty($date_start) && !empty($date_end) && (empty($month) || empty($year))) { // If month/year provided, it is stronger than filter date_start/date_end
669 $sql .= " AND (t.doc_date BETWEEN '".$this->db->idate($date_start)."' AND '".$this->db->idate($date_end)."')";
670 }
671 if (!empty($month) && !empty($year)) {
672 $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))."')";
673 }
674 if ($thirdparty_code != 'nofilter') {
675 $sql .= " AND t.thirdparty_code = '".$this->db->escape($thirdparty_code)."'";
676 }
677 if (is_array($cpt)) {
678 $sql .= " GROUP BY t.numero_compte";
679 }
680
681 $resql = $this->db->query($sql);
682 if ($resql) {
683 $num = $this->db->num_rows($resql);
684 if ($num) {
685 $i = 0;
686 while ($i < $num) {
687 $obj = $this->db->fetch_object($resql);
688 if ($obj) {
689 if ($sens == 1) {
690 $this->sdc = $obj->debit - $obj->credit;
691 } else {
692 $this->sdc = $obj->credit - $obj->debit;
693 }
694 if (is_array($cpt)) {
695 $this->sdcperaccount[$obj->accountancy_account] = $this->sdc;
696 }
697 }
698 $i++;
699 }
700 }
701
702 return $num;
703 } else {
704 $this->error = "Error ".$this->db->lasterror();
705 $this->errors[] = $this->error;
706 dol_syslog(__METHOD__." ".$this->error, LOG_ERR);
707 return -1;
708 }
709 }
710
718 public function getCatsCpts($catid = 0)
719 {
720 global $mysoc, $conf;
721
722 if (empty($mysoc->country_id)) {
723 $this->error = "Error ".$this->db->lasterror();
724 dol_syslog(__METHOD__." ".$this->error, LOG_ERR);
725 return -1;
726 }
727
728 $sql = "SELECT t.rowid, t.account_number, t.label as account_label,";
729 $sql .= " cat.code, cat.position, cat.label as name_cat, cat.sens, cat.category_type, cat.formula";
730 $sql .= " FROM ".$this->db->prefix()."accounting_account as t, ".$this->db->prefix()."c_accounting_category as cat";
731 $sql .= " WHERE t.fk_accounting_category IN (SELECT c.rowid";
732 $sql .= " FROM ".$this->db->prefix().$this->table_element." as c";
733 $sql .= " WHERE c.active = 1";
734 $sql .= " AND c.entity = ".$conf->entity;
735 $sql .= " AND (c.fk_country = ".((int) $mysoc->country_id)." OR c.fk_country = 0)";
736 $sql .= " AND cat.rowid = t.fk_accounting_category";
737 $sql .= " AND t.entity = ".$conf->entity;
738 if ($catid > 0) {
739 $sql .= " AND cat.rowid = ".((int) $catid);
740 }
741 $sql .= " ORDER BY cat.position ASC";
742
743 $resql = $this->db->query($sql);
744 if ($resql) {
745 $obj = '';
746 $num = $this->db->num_rows($resql);
747 $data = array();
748 if ($num) {
749 while ($obj = $this->db->fetch_object($resql)) {
750 $name_cat = $obj->name_cat;
751 $data[$name_cat][$obj->rowid] = array(
752 'id' => $obj->rowid,
753 'code' => $obj->code,
754 'label' => $obj->label,
755 'position' => $obj->position,
756 'category_type' => $obj->category_type,
757 'formula' => $obj->formula,
758 'sens' => $obj->sens,
759 'account_number' => $obj->account_number,
760 'account_label' => $obj->account_label
761 );
762 }
763 }
764 return $data;
765 } else {
766 $this->error = "Error ".$this->db->lasterror();
767 dol_syslog(__METHOD__." ".$this->error, LOG_ERR);
768 return -1;
769 }
770 }
771
782 public function getCats($categorytype = -1, $active = 1, $id_report = 1)
783 {
784 global $conf, $mysoc;
785
786 if (empty($mysoc->country_id)) {
787 dol_print_error(null, 'Call to select_accounting_account with mysoc country not yet defined');
788 exit();
789 }
790
791 $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type, c.sens";
792 $sql .= " FROM ".$this->db->prefix().$this->table_element." as c";
793 $sql .= " WHERE c.active = " . (int) $active;
794 $sql .= " AND c.fk_report=".((int) $id_report);
795 $sql .= " AND c.entity = ".$conf->entity;
796 if ($categorytype >= 0) {
797 $sql .= " AND c.category_type = 1";
798 }
799 $sql .= " AND (c.fk_country = ".((int) $mysoc->country_id)." OR c.fk_country = 0)";
800 $sql .= " ORDER BY c.position ASC";
801
802 $resql = $this->db->query($sql);
803 if ($resql) {
804 $i = 0;
805 $obj = '';
806 $num = $this->db->num_rows($resql);
807 $data = array();
808 if ($num) {
809 while ($i < $num) {
810 $obj = $this->db->fetch_object($resql);
811
812 $data[] = array(
813 'rowid' => $obj->rowid,
814 'code' => $obj->code,
815 'label' => $obj->label,
816 'position' => $obj->position,
817 'category_type' => $obj->category_type,
818 'formula' => $obj->formula,
819 'sens' => $obj->sens,
820 'bc' => $obj->sens
821 );
822 $i++;
823 }
824 }
825 return $data;
826 } else {
827 $this->error = "Error ".$this->db->lasterror();
828 $this->errors[] = $this->error;
829 dol_syslog(__METHOD__." ".implode(',', $this->errors), LOG_ERR);
830
831 return -1;
832 }
833 }
834
835
847 public function getCptsCat($cat_id, $predefinedgroupwhere = '')
848 {
849 global $conf, $mysoc;
850 $sql = '';
851
852 if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
853 dol_print_error(null, 'Call to select_accounting_account with mysoc country not yet defined');
854 exit();
855 }
856
857 $pcgverid = getDolGlobalInt('CHARTOFACCOUNTS');
858 $pcgvercode = dol_getIdFromCode($this->db, (string) $pcgverid, 'accounting_system', 'rowid', 'pcg_version');
859 if (empty($pcgvercode)) {
860 $pcgvercode = $pcgverid;
861 }
862
863 if (!empty($cat_id)) {
864 $sql = "SELECT t.rowid, t.account_number, t.label as account_label";
865 $sql .= " FROM ".$this->db->prefix()."accounting_account as t";
866 $sql .= " WHERE t.fk_accounting_category = ".((int) $cat_id);
867 $sql .= " AND t.entity = ".$conf->entity;
868 $sql .= " AND t.active = 1";
869 $sql .= " AND t.fk_pcg_version = '".$this->db->escape($pcgvercode)."'";
870 $sql .= " ORDER BY t.account_number";
871 } else {
872 $sql = "SELECT t.rowid, t.account_number, t.label as account_label";
873 $sql .= " FROM ".$this->db->prefix()."accounting_account as t";
874 $sql .= " WHERE ".$predefinedgroupwhere;
875 $sql .= " AND t.entity = ".$conf->entity;
876 $sql .= ' AND t.active = 1';
877 $sql .= " AND t.fk_pcg_version = '".$this->db->escape($pcgvercode)."'";
878 $sql .= " ORDER BY t.account_number";
879 }
880
881 $resql = $this->db->query($sql);
882 if ($resql) {
883 $i = 0;
884 $obj = '';
885 $num = $this->db->num_rows($resql);
886 $data = array();
887 if ($num) {
888 while ($obj = $this->db->fetch_object($resql)) {
889 $data[] = array(
890 'id' => $obj->rowid,
891 'account_number' => $obj->account_number,
892 'account_label' => $obj->account_label,
893 );
894 $i++;
895 }
896 }
897 return $data;
898 } else {
899 $this->error = "Error ".$this->db->lasterror();
900 dol_syslog(__METHOD__." ".$this->error, LOG_ERR);
901
902 return -1;
903 }
904 }
905}
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
print $object position
Definition edit.php:204
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).
getCats($categorytype=-1, $active=1, $id_report=1)
Return 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.
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:600
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:619
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79