27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
47 public $errors = array();
52 public $element =
'c_accounting_category';
57 public $table_element =
'c_accounting_category';
83 public $range_account;
93 public $category_type;
123 public $lines_display;
150 public function create($user, $notrigger = 0)
152 global $conf, $langs;
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;
170 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"c_accounting_category(";
171 if ($this->
rowid > 0) $sql .=
"rowid, ";
174 $sql .=
"range_account, ";
176 $sql .=
"category_type, ";
178 $sql .=
"position, ";
179 $sql .=
"fk_country, ";
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;
198 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
200 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
205 foreach ($this->errors as $errmsg)
207 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
208 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
210 $this->
db->rollback();
227 public function fetch($id, $code =
'', $label =
'')
233 $sql .=
" t.range_account,";
235 $sql .=
" t.category_type,";
236 $sql .=
" t.formula,";
237 $sql .=
" t.position,";
238 $sql .=
" t.fk_country,";
240 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_accounting_category as t";
241 if ($id) $sql .=
" WHERE t.rowid = ".$id;
243 $sql .=
" WHERE t.entity IN (".getEntity(
'c_accounting_category').
")";
244 if ($code) $sql .=
" AND t.code = '".$this->db->escape($code).
"'";
245 elseif ($label) $sql .=
" AND t.label = '".$this->db->escape($label).
"'";
248 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
254 $obj = $this->
db->fetch_object(
$resql);
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;
271 $this->error =
"Error ".$this->db->lasterror();
284 public function update($user = null, $notrigger = 0)
286 global $conf, $langs;
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;
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;
319 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
321 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
326 foreach ($this->errors as $errmsg)
328 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
329 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
331 $this->
db->rollback();
347 public function delete($user, $notrigger = 0)
349 global $conf, $langs;
352 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"c_accounting_category";
353 $sql .=
" WHERE rowid=".$this->id;
357 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
359 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
364 foreach ($this->errors as $errmsg)
366 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
367 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
369 $this->
db->rollback();
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;
392 $this->lines_display = array();
394 dol_syslog(__METHOD__.
" sql=".$sql, LOG_DEBUG);
399 while ($obj = $this->
db->fetch_object(
$resql)) {
400 $this->lines_display[] = $obj;
405 $this->error =
"Error ".$this->db->lasterror();
406 $this->errors[] = $this->error;
407 dol_syslog(__METHOD__.
" ".implode(
','.$this->errors), LOG_ERR);
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";
440 $this->lines_CptBk = array();
447 while ($obj = $this->
db->fetch_object(
$resql)) {
448 $this->lines_cptbk[] = $obj;
454 $this->error =
"Error ".$this->db->lasterror();
455 $this->errors[] = $this->error;
456 dol_syslog(__METHOD__.
" ".implode(
','.$this->errors), LOG_ERR);
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";
483 $this->lines_CptBk = array();
490 while ($obj = $this->
db->fetch_object(
$resql)) {
491 $this->lines_cptbk[] = $obj;
497 $this->error =
"Error ".$this->db->lasterror();
498 $this->errors[] = $this->error;
499 dol_syslog(__METHOD__.
" ".implode(
','.$this->errors), LOG_ERR);
518 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
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;";
534 $this->errors[] =
"Error ".$this->db->lasterror();
535 $this->
db->rollback();
539 $accountincptsadded = array();
540 while ($obj = $this->
db->fetch_object(
$resql))
543 if (!empty($accountincptsadded[$account_number_formated]))
continue;
545 if (array_key_exists($account_number_formated, $cpts))
547 $accountincptsadded[$account_number_formated] = 1;
549 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"accounting_account";
550 $sql .=
" SET fk_accounting_category=".$id_cat;
551 $sql .=
" WHERE rowid=".$obj->rowid;
553 $resqlupdate = $this->
db->query($sql);
556 $this->errors[] =
"Error ".$this->db->lasterror();
563 foreach ($this->errors as $errmsg) {
565 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
567 $this->
db->rollback();
588 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"accounting_account as aa";
589 $sql .=
" SET fk_accounting_category= 0";
590 $sql .=
" WHERE aa.rowid= ".$cpt_id;
593 dol_syslog(__METHOD__.
" sql=".$sql, LOG_DEBUG);
597 $this->errors[] =
"Error ".$this->db->lasterror();
602 foreach ($this->errors as $errmsg) {
604 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
606 $this->
db->rollback();
623 global $mysoc, $conf;
625 if (empty($mysoc->country_id)) {
626 dol_print_error(
'',
'Call to select_accounting_account with mysoc country not yet defined');
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";
648 while ($obj = $this->
db->fetch_object(
$resql)) {
649 $name_cat = $obj->name_cat;
650 $data[$name_cat][$i] = array(
652 'code' => $obj->code,
653 'position' => $obj->position,
654 'account_number' => $obj->account_number,
655 'account_label' => $obj->account_label,
663 $this->error =
"Error ".$this->db->lasterror();
664 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
682 public function getSumDebitCredit($cpt, $date_start, $date_end, $sens, $thirdparty_code =
'nofilter', $month = 0, $year = 0)
687 $this->sdcpermonth = array();
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";
693 $sql .=
" WHERE t.entity = ".$conf->entity;
697 foreach ($cpt as $cptcursor)
699 if ($listofaccount) $listofaccount .=
",";
700 $listofaccount .=
"'".$cptcursor.
"'";
702 $sql .=
" AND t.numero_compte IN (".$listofaccount.
")";
704 $sql .=
" AND t.numero_compte = '".$this->db->escape($cpt).
"'";
706 if (!empty($date_start) && !empty($date_end) && (empty($month) || empty($year)))
707 $sql .=
" AND (t.doc_date BETWEEN '".$this->db->idate($date_start).
"' AND '".$this->
db->idate($date_end).
"')";
708 if (!empty($month) && !empty($year)) {
711 if ($thirdparty_code !=
'nofilter')
713 $sql .=
" AND t.thirdparty_code = '".$this->db->escape($thirdparty_code).
"'";
715 if (is_array($cpt)) $sql .=
" GROUP BY t.numero_compte";
724 $obj = $this->
db->fetch_object(
$resql);
726 $this->sdc = $obj->debit - $obj->credit;
728 $this->sdc = $obj->credit - $obj->debit;
732 $this->sdcperaccount[$obj->accountancy_account] = $this->sdc;
737 $this->error =
"Error ".$this->db->lasterror();
738 $this->errors[] = $this->error;
739 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
752 global $conf, $mysoc;
754 if (empty($mysoc->country_id)) {
755 dol_print_error(
'',
'Call to select_accounting_account with mysoc country not yet defined');
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";
775 $obj = $this->
db->fetch_object(
$resql);
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,
791 $this->error =
"Error ".$this->db->lasterror();
792 $this->errors[] = $this->error;
793 dol_syslog(__METHOD__.
" ".implode(
',', $this->errors), LOG_ERR);
808 public function getCptsCat($cat_id, $predefinedgroupwhere =
'')
810 global $conf, $mysoc;
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');
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";
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";
841 while ($obj = $this->
db->fetch_object(
$resql))
845 'account_number' => $obj->account_number,
846 'account_label' => $obj->account_label,
853 $this->error =
"Error ".$this->db->lasterror();
854 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
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
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.
$conf db
API class for accounts.
Class to manage categories of an accounting account.
__construct($db)
Constructor.
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.
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.
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...