37 public $element =
'accounting_account';
42 public $table_element =
'accounting_account';
47 public $picto =
'billr';
53 public $ismultientitymanaged = 1;
59 public $restrictiononfksoc = 1;
86 public $fk_pcg_version;
96 public $account_number;
101 public $account_parent;
106 public $account_category;
126 public $fk_user_author;
131 public $fk_user_modif;
141 public $reconcilable;
153 $this->next_prev_filter =
'fk_pcg_version IN (SELECT pcg_version FROM '.MAIN_DB_PREFIX.
'accounting_system WHERE rowid='.$conf->global->CHARTOFACCOUNTS.
')';
165 public function fetch($rowid = null, $account_number = null, $limittocurrentchart = 0, $limittoachartaccount =
'')
169 if ($rowid || $account_number) {
170 $sql =
"SELECT a.rowid as rowid, a.datec, a.tms, a.fk_pcg_version, a.pcg_type, a.account_number, a.account_parent, a.label, a.labelshort, a.fk_accounting_category, a.fk_user_author, a.fk_user_modif, a.active, a.reconcilable";
171 $sql .=
", ca.label as category_label";
172 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_account as a";
173 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_accounting_category as ca ON a.fk_accounting_category = ca.rowid";
176 $sql .=
" a.rowid = ".(int) $rowid;
177 } elseif ($account_number) {
178 $sql .=
" a.account_number = '".$this->db->escape($account_number).
"'";
179 $sql .=
" AND a.entity = ".$conf->entity;
181 if (!empty($limittocurrentchart)) {
182 $sql .=
' AND a.fk_pcg_version IN (SELECT pcg_version FROM '.MAIN_DB_PREFIX.
'accounting_system WHERE rowid='.$this->
db->escape($conf->global->CHARTOFACCOUNTS).
')';
184 if (!empty($limittoachartaccount)) {
185 $sql .=
" AND a.fk_pcg_version = '".$this->db->escape($limittoachartaccount).
"'";
188 dol_syslog(get_class($this).
"::fetch sql=".$sql, LOG_DEBUG);
189 $result = $this->
db->query($sql);
191 $obj = $this->
db->fetch_object($result);
194 $this->
id = $obj->rowid;
195 $this->
rowid = $obj->rowid;
196 $this->ref = $obj->account_number;
197 $this->datec = $obj->datec;
198 $this->tms = $obj->tms;
199 $this->fk_pcg_version = $obj->fk_pcg_version;
200 $this->pcg_type = $obj->pcg_type;
201 $this->account_number = $obj->account_number;
202 $this->account_parent = $obj->account_parent;
203 $this->label = $obj->label;
204 $this->labelshort = $obj->labelshort;
205 $this->account_category = $obj->fk_accounting_category;
206 $this->account_category_label = $obj->category_label;
207 $this->fk_user_author = $obj->fk_user_author;
208 $this->fk_user_modif = $obj->fk_user_modif;
209 $this->active = $obj->active;
210 $this->status = $obj->active;
211 $this->reconcilable = $obj->reconcilable;
218 $this->error =
"Error ".$this->db->lasterror();
219 $this->errors[] =
"Error ".$this->db->lasterror();
232 public function create($user, $notrigger = 0)
239 if (isset($this->fk_pcg_version))
240 $this->fk_pcg_version = trim($this->fk_pcg_version);
241 if (isset($this->pcg_type))
242 $this->pcg_type = trim($this->pcg_type);
243 if (isset($this->account_number))
244 $this->account_number = trim($this->account_number);
245 if (isset($this->label))
246 $this->label = trim($this->label);
247 if (isset($this->labelshort))
248 $this->labelshort = trim($this->labelshort);
250 if (empty($this->pcg_type) || $this->pcg_type ==
'-1')
252 $this->pcg_type =
'XXXXXX';
258 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"accounting_account(";
261 $sql .=
", fk_pcg_version";
262 $sql .=
", pcg_type";
263 $sql .=
", account_number";
264 $sql .=
", account_parent";
266 $sql .=
", labelshort";
267 $sql .=
", fk_accounting_category";
268 $sql .=
", fk_user_author";
270 $sql .=
", reconcilable";
271 $sql .=
") VALUES (";
272 $sql .=
" '".$this->db->idate($now).
"'";
273 $sql .=
", ".$conf->entity;
274 $sql .=
", ".(empty($this->fk_pcg_version) ?
'NULL' :
"'".$this->db->escape($this->fk_pcg_version).
"'");
275 $sql .=
", ".(empty($this->pcg_type) ?
'NULL' :
"'".$this->db->escape($this->pcg_type).
"'");
276 $sql .=
", ".(empty($this->account_number) ?
'NULL' :
"'".$this->db->escape($this->account_number).
"'");
277 $sql .=
", ".(empty($this->account_parent) ? 0 : (int) $this->account_parent);
278 $sql .=
", ".(empty($this->label) ?
"''" :
"'".$this->db->escape($this->label).
"'");
279 $sql .=
", ".(empty($this->labelshort) ?
"''" :
"'".$this->db->escape($this->labelshort).
"'");
280 $sql .=
", ".(empty($this->account_category) ? 0 : (int) $this->account_category);
281 $sql .=
", ".$user->id;
282 $sql .=
", ".(int) $this->active;
283 $sql .=
", ".(int) $this->reconcilable;
288 dol_syslog(get_class($this).
"::create sql=".$sql, LOG_DEBUG);
292 $this->errors[] =
"Error ".$this->db->lasterror();
296 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"accounting_account");
311 foreach ($this->errors as $errmsg) {
312 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
313 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
315 $this->
db->rollback();
332 if (empty($this->pcg_type) || $this->pcg_type ==
'-1')
334 $this->pcg_type =
'XXXXXX';
339 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"accounting_account ";
340 $sql .=
" SET fk_pcg_version = ".($this->fk_pcg_version ?
"'".$this->db->escape($this->fk_pcg_version).
"'" :
"null");
341 $sql .=
" , pcg_type = ".($this->pcg_type ?
"'".$this->db->escape($this->pcg_type).
"'" :
"null");
342 $sql .=
" , account_number = '".$this->db->escape($this->account_number).
"'";
343 $sql .=
" , account_parent = ".(int) $this->account_parent;
344 $sql .=
" , label = ".($this->label ?
"'".$this->db->escape($this->label).
"'" :
"''");
345 $sql .=
" , labelshort = ".($this->labelshort ?
"'".$this->db->escape($this->labelshort).
"'" :
"''");
346 $sql .=
" , fk_accounting_category = ".(empty($this->account_category) ? 0 : (int) $this->account_category);
347 $sql .=
" , fk_user_modif = ".$user->id;
348 $sql .=
" , active = ".(int) $this->active;
349 $sql .=
" , reconcilable = ".(int) $this->reconcilable;
350 $sql .=
" WHERE rowid = ".$this->id;
352 dol_syslog(get_class($this).
"::update sql=".$sql, LOG_DEBUG);
353 $result = $this->
db->query($sql);
358 $this->error = $this->
db->lasterror();
359 $this->
db->rollback();
373 $sql =
"(SELECT fk_code_ventilation FROM ".MAIN_DB_PREFIX.
"facturedet";
374 $sql .=
" WHERE fk_code_ventilation=".$this->id.
")";
376 $sql .=
" (SELECT fk_code_ventilation FROM ".MAIN_DB_PREFIX.
"facture_fourn_det";
377 $sql .=
" WHERE fk_code_ventilation=".$this->id.
")";
379 dol_syslog(get_class($this).
"::checkUsage sql=".$sql, LOG_DEBUG);
385 $this->error = $langs->trans(
'ErrorAccountancyCodeIsAlreadyUse');
391 $this->error = $this->
db->lasterror();
403 public function delete($user, $notrigger = 0)
413 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"accounting_account";
414 $sql .=
" WHERE rowid=".$this->id;
416 dol_syslog(get_class($this).
"::delete sql=".$sql);
420 $this->errors[] =
"Error ".$this->db->lasterror();
426 foreach ($this->errors as $errmsg) {
427 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
428 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
430 $this->
db->rollback();
454 public function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1, $withcompletelabel = 0, $option =
'')
456 global $langs, $conf;
457 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
459 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
463 $url =
''; $labelurl =
'';
464 if (empty($option) || $option ==
'ledger') {
465 $url = DOL_URL_ROOT.
'/accountancy/bookkeeping/listbyaccount.php?search_accountancy_code_start='.urlencode($this->account_number).
'&search_accountancy_code_end='.urlencode($this->account_number);
466 $labelurl = $langs->trans(
"ShowAccountingAccountInLedger");
467 } elseif ($option ==
'journals') {
468 $url = DOL_URL_ROOT.
'/accountancy/bookkeeping/list.php?search_accountancy_code_start='.urlencode($this->account_number).
'&search_accountancy_code_end='.urlencode($this->account_number);
469 $labelurl = $langs->trans(
"ShowAccountingAccountInJournals");
470 } elseif ($option ==
'accountcard') {
471 $url = DOL_URL_ROOT.
'/accountancy/admin/card.php?id='.urlencode($this->
id);
472 $labelurl = $langs->trans(
"ShowAccountingAccount");
476 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
477 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
478 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
483 if (empty($this->labelshort) || $withcompletelabel == 1)
485 $labeltoshow = $this->label;
487 $labeltoshow = $this->labelshort;
490 $label =
'<u>'.$labelurl.
'</u>';
491 if (!empty($this->account_number))
492 $label .=
'<br><b>'.$langs->trans(
'AccountAccounting').
':</b> '.
length_accountg($this->account_number);
493 if (!empty($labeltoshow))
494 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$labeltoshow;
495 if ($moretitle) $label .=
' - '.$moretitle;
498 if (empty($notooltip))
500 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
503 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
505 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
506 $linkclose .=
' class="classfortooltip"';
509 $linkstart =
'<a href="'.$url.
'"';
510 $linkstart .= $linkclose.
'>';
521 if ($withlabel) $label_link .=
' - '.($nourl ?
'<span class="opacitymedium">' :
'').$labeltoshow.($nourl ?
'</span>' :
'');
523 if ($withpicto) $result .= ($linkstart.img_object(($notooltip ?
'' : $label), $picto, ($notooltip ?
'' :
'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).$linkend);
524 if ($withpicto && $withpicto != 2) $result .=
' ';
525 if ($withpicto != 2) $result .= $linkstart.$label_link.$linkend;
537 $sql =
'SELECT a.rowid, a.datec, a.fk_user_author, a.fk_user_modif, a.tms';
538 $sql .=
' FROM '.MAIN_DB_PREFIX.
'accounting_account as a';
539 $sql .=
' WHERE a.rowid = '.$id;
541 dol_syslog(get_class($this).
'::info sql='.$sql);
542 $result = $this->
db->query($sql);
545 if ($this->
db->num_rows($result)) {
546 $obj = $this->
db->fetch_object($result);
547 $this->
id = $obj->rowid;
548 if ($obj->fk_user_author) {
549 $cuser =
new User($this->
db);
550 $cuser->fetch($obj->fk_user_author);
551 $this->user_creation = $cuser;
553 if ($obj->fk_user_modif) {
554 $muser =
new User($this->
db);
555 $muser->fetch($obj->fk_user_modif);
556 $this->user_modification = $muser;
558 $this->date_creation = $this->
db->jdate($obj->datec);
559 $this->date_modification = $this->
db->jdate($obj->tms);
561 $this->
db->free($result);
578 $fieldtouse =
'active';
581 $fieldtouse =
'reconcilable';
587 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"accounting_account ";
588 $sql .=
"SET ".$fieldtouse.
" = '0'";
589 $sql .=
" WHERE rowid = ".$this->db->escape($id);
591 dol_syslog(get_class($this).
"::accountDeactivate ".$fieldtouse.
" sql=".$sql, LOG_DEBUG);
592 $result = $this->
db->query($sql);
598 $this->error = $this->
db->lasterror();
599 $this->
db->rollback();
620 $fieldtouse =
'active';
622 $fieldtouse =
'reconcilable';
625 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"accounting_account";
626 $sql .=
" SET ".$fieldtouse.
" = '1'";
627 $sql .=
" WHERE rowid = ".$this->db->escape($id);
629 dol_syslog(get_class($this).
"::account_activate ".$fieldtouse.
" sql=".$sql, LOG_DEBUG);
630 $result = $this->
db->query($sql);
635 $this->error = $this->
db->lasterror();
636 $this->
db->rollback();
650 return $this->
LibStatut($this->status, $mode);
665 $langs->loadLangs(array(
"users"));
669 if ($status == 1)
return $langs->trans(
'Enabled');
670 elseif ($status == 0)
return $langs->trans(
'Disabled');
671 } elseif ($mode == 1)
673 if ($status == 1)
return $langs->trans(
'Enabled');
674 elseif ($status == 0)
return $langs->trans(
'Disabled');
675 } elseif ($mode == 2)
677 if ($status == 1)
return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
678 elseif ($status == 0)
return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
679 } elseif ($mode == 3)
681 if ($status == 1)
return img_picto($langs->trans(
'Enabled'),
'statut4');
682 elseif ($status == 0)
return img_picto($langs->trans(
'Disabled'),
'statut5');
683 } elseif ($mode == 4)
685 if ($status == 1)
return img_picto($langs->trans(
'Enabled'),
'statut4').
' '.$langs->trans(
'Enabled');
686 elseif ($status == 0)
return img_picto($langs->trans(
'Disabled'),
'statut5').
' '.$langs->trans(
'Disabled');
687 } elseif ($mode == 5)
689 if ($status == 1)
return $langs->trans(
'Enabled').
' '.
img_picto($langs->trans(
'Enabled'),
'statut4');
690 elseif ($status == 0)
return $langs->trans(
'Disabled').
' '.
img_picto($langs->trans(
'Disabled'),
'statut5');
__construct($db)
Constructor.
info($id)
Information on record.
getNomUrl($withpicto=0, $withlabel=0, $nourl=0, $moretitle= '', $notooltip=0, $save_lastsearch_value=-1, $withcompletelabel=0, $option= '')
Return clicable name (with picto eventually)
</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_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
$conf db
API class for accounts.
create($user, $notrigger=0)
Insert new accounting account in chart of accounts.
account_activate($id, $mode=0)
Account activated.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
update($user)
Update record.
checkUsage()
Check usage of accounting code.
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
getLibStatut($mode=0)
Retourne le libelle du statut d'un user (actif, inactif)
print $_SERVER["PHP_SELF"]
Edit parameters.
accountDeactivate($id, $mode=0)
Deactivate an account (for status active or status reconcilable)
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...
fetch($rowid=null, $account_number=null, $limittocurrentchart=0, $limittoachartaccount= '')
Load record in memory.
Class to manage accounting accounts.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)