30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/fiscalyear.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
44 public $element =
'accountingbookkeeping';
49 public $table_element =
'accounting_bookkeeping';
59 public $lines = array();
74 public $date_lim_reglement;
99 public $thirdparty_code;
104 public $subledger_account;
109 public $subledger_label;
114 public $numero_compte;
119 public $label_compte;
124 public $label_operation;
156 public $fk_user_author;
166 public $code_journal;
171 public $journal_label;
181 public $linesmvt = array();
186 public $linesexport = array();
191 public $date_validation;
201 public $picto =
'generic';
206 public static $can_modify_bookkeeping_sql_cached;
228 global $conf, $langs;
235 if (isset($this->doc_type)) {
236 $this->doc_type = trim($this->doc_type);
238 if (isset($this->doc_ref)) {
239 $this->doc_ref = trim($this->doc_ref);
241 if (isset($this->fk_doc)) {
242 $this->fk_doc = (int) $this->fk_doc;
244 if (isset($this->fk_docdet)) {
245 $this->fk_docdet = (int) $this->fk_docdet;
247 if (isset($this->thirdparty_code)) {
248 $this->thirdparty_code = trim($this->thirdparty_code);
250 if (isset($this->subledger_account)) {
251 $this->subledger_account = trim($this->subledger_account);
253 if (isset($this->subledger_label)) {
254 $this->subledger_label = trim($this->subledger_label);
256 if (isset($this->numero_compte)) {
257 $this->numero_compte = trim($this->numero_compte);
259 if (isset($this->label_compte)) {
260 $this->label_compte = trim($this->label_compte);
262 if (isset($this->label_operation)) {
263 $this->label_operation = trim($this->label_operation);
265 if (isset($this->debit)) {
266 $this->debit = (float) $this->debit;
268 if (isset($this->credit)) {
269 $this->credit = (float) $this->credit;
271 if (isset($this->montant)) {
272 $this->montant = (float) $this->montant;
274 if (isset($this->amount)) {
275 $this->amount = (float) $this->amount;
277 if (isset($this->sens)) {
278 $this->sens = trim($this->sens);
280 if (isset($this->import_key)) {
281 $this->import_key = trim($this->import_key);
283 if (isset($this->code_journal)) {
284 $this->code_journal = trim($this->code_journal);
286 if (isset($this->journal_label)) {
287 $this->journal_label = trim($this->journal_label);
289 if (isset($this->piece_num)) {
290 $this->piece_num = (int) $this->piece_num;
292 if (empty($this->debit)) {
295 if (empty($this->credit)) {
302 } elseif ($result == 0) {
304 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
306 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
312 if (($this->numero_compte ==
"") || $this->numero_compte ==
'-1' || $this->numero_compte ==
'NotDefined') {
313 $langs->loadLangs(array(
"errors"));
314 if (in_array($this->doc_type, array(
'bank',
'expense_report'))) {
315 $this->errors[] = $langs->trans(
'ErrorFieldAccountNotDefinedForBankLine', $this->fk_docdet, $this->doc_type);
318 $mesg = $this->doc_ref.
', '.$langs->trans(
"AccountAccounting").
': '.($this->numero_compte != -1 ? $this->numero_compte : $langs->trans(
"Unknown"));
319 if ($this->subledger_account && $this->subledger_account != $this->numero_compte) {
320 $mesg .=
', '.$langs->trans(
"SubledgerAccount").
': '.$this->subledger_account;
322 $this->errors[] = $langs->trans(
'ErrorFieldAccountNotDefinedForLine', $mesg);
330 $this->piece_num = 0;
337 $sql =
"SELECT count(*) as nb";
338 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
339 $sql .=
" WHERE doc_type = '".$this->db->escape($this->doc_type).
"'";
340 $sql .=
" AND fk_doc = ".((int) $this->fk_doc);
343 $sql .=
" AND fk_docdet = ".((int) $this->fk_docdet);
345 $sql .=
" AND numero_compte = '".$this->db->escape($this->numero_compte).
"'";
346 $sql .=
" AND label_operation = '".$this->db->escape($this->label_operation).
"'";
347 if (!empty($this->subledger_account)) {
348 $sql .=
" AND subledger_account = '".$this->db->escape($this->subledger_account).
"'";
350 $sql .=
" AND entity = ".$conf->entity;
352 $resql = $this->db->query($sql);
355 $row = $this->db->fetch_object($resql);
358 $sqlnum =
"SELECT piece_num";
359 $sqlnum .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
360 $sqlnum .=
" WHERE doc_type = '".$this->db->escape($this->doc_type).
"'";
361 $sqlnum .=
" AND fk_doc = ".((int) $this->fk_doc);
364 $sqlnum .=
" AND fk_docdet = ".((int) $this->fk_docdet);
366 $sqlnum .=
" AND doc_ref = '".$this->db->escape($this->doc_ref).
"'";
367 $sqlnum .=
" AND entity = ".$conf->entity;
369 dol_syslog(get_class($this).
":: create sqlnum=".$sqlnum, LOG_DEBUG);
370 $resqlnum = $this->db->query($sqlnum);
372 $num = $this->db->num_rows($resqlnum);
374 $objnum = $this->db->fetch_object($resqlnum);
375 $this->piece_num = $objnum->piece_num;
377 $this->piece_num = 0;
381 dol_syslog(get_class($this).
"::create this->piece_num=".$this->piece_num, LOG_DEBUG);
382 if (empty($this->piece_num)) {
383 $sqlnum =
"SELECT MAX(piece_num)+1 as maxpiecenum";
384 $sqlnum .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
385 $sqlnum .=
" WHERE entity = " . ((int) $conf->entity);
387 $resqlnum = $this->db->query($sqlnum);
389 $objnum = $this->db->fetch_object($resqlnum);
390 $this->piece_num = $objnum->maxpiecenum;
392 dol_syslog(get_class($this).
":: create now this->piece_num=".$this->piece_num, LOG_DEBUG);
394 if (empty($this->piece_num)) {
395 $this->piece_num = 1;
400 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
" (";
402 $sql .=
", date_lim_reglement";
403 $sql .=
", doc_type";
406 $sql .=
", fk_docdet";
407 $sql .=
", thirdparty_code";
408 $sql .=
", subledger_account";
409 $sql .=
", subledger_label";
410 $sql .=
", numero_compte";
411 $sql .=
", label_compte";
412 $sql .=
", label_operation";
417 $sql .=
", fk_user_author";
418 $sql .=
", date_creation";
419 $sql .=
", code_journal";
420 $sql .=
", journal_label";
421 $sql .=
", piece_num";
423 $sql .=
") VALUES (";
424 $sql .=
"'".$this->db->idate($this->doc_date).
"'";
425 $sql .=
", ".(!isset($this->date_lim_reglement) ||
dol_strlen($this->date_lim_reglement) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_lim_reglement).
"'");
426 $sql .=
", '".$this->db->escape($this->doc_type).
"'";
427 $sql .=
", '".$this->db->escape($this->doc_ref).
"'";
428 $sql .=
", ".((int) $this->fk_doc);
429 $sql .=
", ".((int) $this->fk_docdet);
430 $sql .=
", ".(!empty($this->thirdparty_code) ? (
"'".$this->db->escape($this->thirdparty_code).
"'") :
"NULL");
431 $sql .=
", ".(!empty($this->subledger_account) ? (
"'".$this->db->escape($this->subledger_account).
"'") :
"NULL");
432 $sql .=
", ".(!empty($this->subledger_label) ? (
"'".$this->db->escape($this->subledger_label).
"'") :
"NULL");
433 $sql .=
", '".$this->db->escape($this->numero_compte).
"'";
434 $sql .=
", ".(!empty($this->label_compte) ? (
"'".$this->db->escape($this->label_compte).
"'") :
"NULL");
435 $sql .=
", '".$this->db->escape($this->label_operation).
"'";
436 $sql .=
", ".((float) $this->debit);
437 $sql .=
", ".((float) $this->credit);
438 $sql .=
", ".((float) $this->montant);
439 $sql .=
", ".(!empty($this->sens) ? (
"'".$this->db->escape($this->sens).
"'") :
"NULL");
440 $sql .=
", '".$this->db->escape($this->fk_user_author).
"'";
441 $sql .=
", '".$this->db->idate($now).
"'";
442 $sql .=
", '".$this->db->escape($this->code_journal).
"'";
443 $sql .=
", ".(!empty($this->journal_label) ? (
"'".$this->db->escape($this->journal_label).
"'") :
"NULL");
444 $sql .=
", ".((int) $this->piece_num);
445 $sql .=
", ".(!isset($this->entity) ? $conf->entity : $this->entity);
448 $resql = $this->db->query($sql);
450 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
458 $this->errors[] =
'Error Create Error '.$result.
' lecture ID';
459 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
464 $this->errors[] =
'Error '.$this->db->lasterror();
465 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
470 $this->error =
'BookkeepingRecordAlreadyExists';
471 dol_syslog(__METHOD__.
' '.$this->error, LOG_WARNING);
476 $this->errors[] =
'Error '.$this->db->lasterror();
477 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
492 $this->db->rollback();
510 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
512 global $db, $conf, $langs;
513 global $dolibarr_main_authentication, $dolibarr_main_demo;
514 global $menumanager, $hookmanager;
516 if (!empty($conf->dol_no_mouse_hover)) {
523 $label =
'<u>'.$langs->trans(
"Transaction").
'</u>';
525 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->piece_num;
527 $url = DOL_URL_ROOT.
'/accountancy/bookkeeping/card.php?piece_num='.$this->piece_num;
529 if ($option !=
'nolink') {
531 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
532 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
533 $add_save_lastsearch_values = 1;
535 if ($add_save_lastsearch_values) {
536 $url .=
'&save_lastsearch_values=1';
541 if (empty($notooltip)) {
543 $label = $langs->trans(
"ShowTransaction");
544 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
546 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
547 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
549 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
552 $linkstart =
'<a href="'.$url.
'"';
553 $linkstart .= $linkclose.
'>';
556 $result .= $linkstart;
558 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
560 if ($withpicto != 2) {
561 $result .= $this->piece_num;
567 $hookmanager->initHooks(array($this->element .
'dao'));
568 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
569 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
571 $result = $hookmanager->resPrint;
573 $result .= $hookmanager->resPrint;
588 global $conf, $langs;
590 $langs->loadLangs(array(
"accountancy",
"bills",
"compta"));
597 if (isset($this->doc_type)) {
598 $this->doc_type = trim($this->doc_type);
600 if (isset($this->doc_ref)) {
601 $this->doc_ref = trim($this->doc_ref);
603 if (isset($this->fk_doc)) {
604 $this->fk_doc = (int) $this->fk_doc;
606 if (isset($this->fk_docdet)) {
607 $this->fk_docdet = (int) $this->fk_docdet;
609 if (isset($this->thirdparty_code)) {
610 $this->thirdparty_code = trim($this->thirdparty_code);
612 if (isset($this->subledger_account)) {
613 $this->subledger_account = trim($this->subledger_account);
615 if (isset($this->subledger_label)) {
616 $this->subledger_label = trim($this->subledger_label);
618 if (isset($this->numero_compte)) {
619 $this->numero_compte = trim($this->numero_compte);
621 if (isset($this->label_compte)) {
622 $this->label_compte = trim($this->label_compte);
624 if (isset($this->label_operation)) {
625 $this->label_operation = trim($this->label_operation);
627 if (isset($this->sens)) {
628 $this->sens = trim($this->sens);
630 if (isset($this->import_key)) {
631 $this->import_key = trim($this->import_key);
633 if (isset($this->code_journal)) {
634 $this->code_journal = trim($this->code_journal);
636 if (isset($this->journal_label)) {
637 $this->journal_label = trim($this->journal_label);
639 if (isset($this->piece_num)) {
640 $this->piece_num = (int) $this->piece_num;
642 if (empty($this->debit)) {
645 if (empty($this->credit)) {
648 if (empty($this->montant)) {
655 } elseif ($result == 0) {
657 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
659 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
664 $this->debit = (float)
price2num($this->debit,
'MT');
665 $this->credit = (float)
price2num($this->credit,
'MT');
666 $this->montant = (float)
price2num($this->montant,
'MT');
671 $this->journal_label = $langs->trans($this->journal_label);
674 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.$mode.
' (';
676 $sql .=
'date_lim_reglement,';
680 $sql .=
'fk_docdet,';
681 $sql .=
'thirdparty_code,';
682 $sql .=
'subledger_account,';
683 $sql .=
'subledger_label,';
684 $sql .=
'numero_compte,';
685 $sql .=
'label_compte,';
686 $sql .=
'label_operation,';
691 $sql .=
'fk_user_author,';
692 $sql .=
'date_creation,';
693 $sql .=
'code_journal,';
694 $sql .=
'journal_label,';
695 $sql .=
'piece_num,';
697 $sql .=
') VALUES (';
698 $sql .=
' '.(!isset($this->doc_date) ||
dol_strlen($this->doc_date) == 0 ?
'NULL' :
"'".$this->db->idate($this->doc_date).
"'").
',';
699 $sql .=
' '.(!isset($this->date_lim_reglement) ||
dol_strlen($this->date_lim_reglement) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_lim_reglement).
"'").
',';
700 $sql .=
' '.(!isset($this->doc_type) ?
'NULL' :
"'".$this->db->escape($this->doc_type).
"'").
',';
701 $sql .=
' '.(!isset($this->doc_ref) ?
'NULL' :
"'".$this->db->escape($this->doc_ref).
"'").
',';
702 $sql .=
' '.(empty($this->fk_doc) ?
'0' : (int) $this->fk_doc).
',';
703 $sql .=
' '.(empty($this->fk_docdet) ?
'0' : (int) $this->fk_docdet).
',';
704 $sql .=
' '.(!isset($this->thirdparty_code) ?
'NULL' :
"'".$this->db->escape($this->thirdparty_code).
"'").
',';
705 $sql .=
' '.(!isset($this->subledger_account) ?
'NULL' :
"'".$this->db->escape($this->subledger_account).
"'").
',';
706 $sql .=
' '.(!isset($this->subledger_label) ?
'NULL' :
"'".$this->db->escape($this->subledger_label).
"'").
',';
707 $sql .=
' '.(!isset($this->numero_compte) ?
'NULL' :
"'".$this->db->escape($this->numero_compte).
"'").
',';
708 $sql .=
' '.(!isset($this->label_compte) ?
'NULL' :
"'".$this->db->escape($this->label_compte).
"'").
',';
709 $sql .=
' '.(!isset($this->label_operation) ?
'NULL' :
"'".$this->db->escape($this->label_operation).
"'").
',';
710 $sql .=
' '.(!isset($this->debit) ?
'NULL' : $this->debit).
',';
711 $sql .=
' '.(!isset($this->credit) ?
'NULL' : $this->credit).
',';
712 $sql .=
' '.(!isset($this->montant) ?
'NULL' : $this->montant).
',';
713 $sql .=
' '.(!isset($this->sens) ?
'NULL' :
"'".$this->db->escape($this->sens).
"'").
',';
714 $sql .=
' '.((int) $user->id).
',';
715 $sql .=
' '.
"'".$this->db->idate($now).
"',";
716 $sql .=
' '.(empty($this->code_journal) ?
'NULL' :
"'".$this->db->escape($this->code_journal).
"'").
',';
717 $sql .=
' '.(empty($this->journal_label) ?
'NULL' :
"'".$this->db->escape($this->journal_label).
"'").
',';
718 $sql .=
' '.(empty($this->piece_num) ?
'NULL' : $this->db->escape($this->piece_num)).
',';
719 $sql .=
' '.(!isset($this->entity) ? $conf->entity : $this->entity);
724 $resql = $this->db->query($sql);
727 $this->errors[] =
'Error '.$this->db->lasterror();
728 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
732 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element.$mode);
737 $this->db->rollback();
755 public function fetch($id, $ref =
null, $mode =
'')
763 $sql .=
" t.doc_date,";
764 $sql .=
" t.date_lim_reglement,";
765 $sql .=
" t.doc_type,";
766 $sql .=
" t.doc_ref,";
767 $sql .=
" t.fk_doc,";
768 $sql .=
" t.fk_docdet,";
769 $sql .=
" t.thirdparty_code,";
770 $sql .=
" t.subledger_account,";
771 $sql .=
" t.subledger_label,";
772 $sql .=
" t.numero_compte,";
773 $sql .=
" t.label_compte,";
774 $sql .=
" t.label_operation,";
776 $sql .=
" t.credit,";
777 $sql .=
" t.montant as amount,";
779 $sql .=
" t.fk_user_author,";
780 $sql .=
" t.import_key,";
781 $sql .=
" t.code_journal,";
782 $sql .=
" t.journal_label,";
783 $sql .=
" t.piece_num,";
784 $sql .=
" t.date_creation,";
786 if ($mode !=
"_tmp") {
787 $sql .=
" t.date_export,";
789 $sql .=
" t.date_validated as date_validation";
790 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.$mode.
' as t';
791 $sql .=
' WHERE 1 = 1';
792 $sql .=
" AND entity = " . ((int) $conf->entity);
794 $sql .=
" AND t.rowid = ".((int) $ref);
796 $sql .=
" AND t.rowid = ".((int) $id);
799 $resql = $this->db->query($sql);
801 $numrows = $this->db->num_rows($resql);
803 $obj = $this->db->fetch_object($resql);
805 $this->
id = $obj->rowid;
807 $this->doc_date = $this->db->jdate($obj->doc_date);
808 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
809 $this->doc_type = $obj->doc_type;
810 $this->doc_ref = $obj->doc_ref;
811 $this->fk_doc = $obj->fk_doc;
812 $this->fk_docdet = $obj->fk_docdet;
813 $this->thirdparty_code = $obj->thirdparty_code;
814 $this->subledger_account = $obj->subledger_account;
815 $this->subledger_label = $obj->subledger_label;
816 $this->numero_compte = $obj->numero_compte;
817 $this->label_compte = $obj->label_compte;
818 $this->label_operation = $obj->label_operation;
819 $this->debit = $obj->debit;
820 $this->credit = $obj->credit;
821 $this->montant = $obj->amount;
822 $this->amount = $obj->amount;
823 $this->sens = $obj->sens;
824 $this->fk_user_author = $obj->fk_user_author;
825 $this->import_key = $obj->import_key;
826 $this->code_journal = $obj->code_journal;
827 $this->journal_label = $obj->journal_label;
828 $this->piece_num = $obj->piece_num;
829 $this->date_creation = $this->db->jdate($obj->date_creation);
830 $this->date_export = $this->db->jdate($obj->date_export);
831 $this->date_validation = isset($obj->date_validation) ? $this->db->jdate($obj->date_validation) :
'';
833 $this->db->free($resql);
841 $this->errors[] =
'Error '.$this->db->lasterror();
842 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
862 public function fetchAllByAccount($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND', $option = 0, $countonly = 0)
868 $this->lines = array();
873 $sql .=
' COUNT(t.rowid) as nb';
876 $sql .=
" t.doc_date,";
877 $sql .=
" t.doc_type,";
878 $sql .=
" t.doc_ref,";
879 $sql .=
" t.fk_doc,";
880 $sql .=
" t.fk_docdet,";
881 $sql .=
" t.thirdparty_code,";
882 $sql .=
" t.subledger_account,";
883 $sql .=
" t.subledger_label,";
884 $sql .=
" t.numero_compte,";
885 $sql .=
" t.label_compte,";
886 $sql .=
" t.label_operation,";
888 $sql .=
" t.credit,";
889 $sql .=
" t.montant as amount,";
891 $sql .=
" t.multicurrency_amount,";
892 $sql .=
" t.multicurrency_code,";
893 $sql .=
" t.lettering_code,";
894 $sql .=
" t.date_lettering,";
895 $sql .=
" t.fk_user_author,";
896 $sql .=
" t.import_key,";
897 $sql .=
" t.code_journal,";
898 $sql .=
" t.journal_label,";
899 $sql .=
" t.piece_num,";
900 $sql .=
" t.date_creation,";
901 $sql .=
" t.date_export,";
902 $sql .=
" t.date_validated as date_validation,";
903 $sql .=
" t.import_key";
907 if (count($filter) > 0) {
908 foreach ($filter as $key => $value) {
909 if ($key ==
't.doc_date>=') {
910 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate($value).
"'";
911 } elseif ($key ==
't.doc_date<=') {
912 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate($value).
"'";
913 } elseif ($key ==
't.doc_date>') {
914 $sqlwhere[] =
"t.doc_date > '".$this->db->idate($value).
"'";
915 } elseif ($key ==
't.doc_date<') {
916 $sqlwhere[] =
"t.doc_date < '".$this->db->idate($value).
"'";
917 } elseif ($key ==
't.numero_compte>=') {
918 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
919 } elseif ($key ==
't.numero_compte<=') {
920 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
921 } elseif ($key ==
't.subledger_account>=') {
922 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
923 } elseif ($key ==
't.subledger_account<=') {
924 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
925 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
926 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
927 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
928 $sqlwhere[] = $this->db->sanitize($key).
' LIKE \''.$this->db->escape($this->db->escapeforlike($value)).
'%\'';
929 } elseif ($key ==
't.date_creation>=') {
930 $sqlwhere[] =
't.date_creation >= \''.$this->db->idate($value).
'\'';
931 } elseif ($key ==
't.date_creation<=') {
932 $sqlwhere[] =
't.date_creation <= \''.$this->db->idate($value).
'\'';
933 } elseif ($key ==
't.date_export>=') {
934 $sqlwhere[] =
't.date_export >= \''.$this->db->idate($value).
'\'';
935 } elseif ($key ==
't.date_export<=') {
936 $sqlwhere[] =
't.date_export <= \''.$this->db->idate($value).
'\'';
937 } elseif ($key ==
't.date_validated>=') {
938 $sqlwhere[] =
't.date_validated >= \''.$this->db->idate($value).
'\'';
939 } elseif ($key ==
't.date_validated<=') {
940 $sqlwhere[] =
't.date_validated <= \''.$this->db->idate($value).
'\'';
941 } elseif ($key ==
't.credit' || $key ==
't.debit') {
943 } elseif ($key ==
't.reconciled_option') {
944 $sqlwhere[] =
't.lettering_code IS NULL';
945 } elseif ($key ==
't.code_journal' && !empty($value)) {
946 if (is_array($value)) {
947 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
951 } elseif ($key ==
't.search_accounting_code_in' && !empty($value)) {
952 $sqlwhere[] =
't.numero_compte IN ('.$this->db->sanitize($value, 1).
')';
958 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
959 $sql .=
' WHERE entity = ' . ((int) $conf->entity);
960 if (count($sqlwhere) > 0) {
961 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
964 if (!empty($option)) {
965 $sql .=
" AND t.subledger_account IS NOT NULL";
966 $sql .=
" AND t.subledger_account <> ''";
967 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
968 $sortorder =
'ASC'.($sortfield ?
','.$sortfield :
'');
970 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
971 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
975 $sql .= $this->db->order($sortfield, $sortorder);
976 if (!empty($limit)) {
977 $sql .= $this->db->plimit($limit + 1, $offset);
981 $resql = $this->db->query($sql);
984 $obj = $this->db->fetch_object($resql);
989 $num = $this->db->num_rows($resql);
992 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
995 $line->id = $obj->rowid;
997 $line->doc_date = $this->db->jdate($obj->doc_date);
998 $line->doc_type = $obj->doc_type;
999 $line->doc_ref = $obj->doc_ref;
1000 $line->fk_doc = $obj->fk_doc;
1001 $line->fk_docdet = $obj->fk_docdet;
1002 $line->thirdparty_code = $obj->thirdparty_code;
1003 $line->subledger_account = $obj->subledger_account;
1004 $line->subledger_label = $obj->subledger_label;
1005 $line->numero_compte = $obj->numero_compte;
1006 $line->label_compte = $obj->label_compte;
1007 $line->label_operation = $obj->label_operation;
1008 $line->debit = $obj->debit;
1009 $line->credit = $obj->credit;
1010 $line->montant = $obj->amount;
1011 $line->amount = $obj->amount;
1012 $line->sens = $obj->sens;
1013 $line->multicurrency_amount = $obj->multicurrency_amount;
1014 $line->multicurrency_code = $obj->multicurrency_code;
1015 $line->lettering_code = $obj->lettering_code;
1016 $line->date_lettering = $obj->date_lettering;
1017 $line->fk_user_author = $obj->fk_user_author;
1018 $line->import_key = $obj->import_key;
1019 $line->code_journal = $obj->code_journal;
1020 $line->journal_label = $obj->journal_label;
1021 $line->piece_num = $obj->piece_num;
1022 $line->date_creation = $this->db->jdate($obj->date_creation);
1023 $line->date_export = $this->db->jdate($obj->date_export);
1024 $line->date_validation = $this->db->jdate($obj->date_validation);
1025 $line->import_key = $obj->import_key;
1027 $this->lines[] = $line;
1032 $this->db->free($resql);
1036 $this->errors[] =
'Error '.$this->db->lasterror();
1037 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1055 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $showAlreadyExportMovements = 1)
1062 $sql .=
' t.rowid,';
1063 $sql .=
" t.doc_date,";
1064 $sql .=
" t.doc_type,";
1065 $sql .=
" t.doc_ref,";
1066 $sql .=
" t.fk_doc,";
1067 $sql .=
" t.fk_docdet,";
1068 $sql .=
" t.thirdparty_code,";
1069 $sql .=
" t.subledger_account,";
1070 $sql .=
" t.subledger_label,";
1071 $sql .=
" t.numero_compte,";
1072 $sql .=
" t.label_compte,";
1073 $sql .=
" t.label_operation,";
1074 $sql .=
" t.debit,";
1075 $sql .=
" t.credit,";
1076 $sql .=
" t.lettering_code,";
1077 $sql .=
" t.date_lettering,";
1078 $sql .=
" t.montant as amount,";
1080 $sql .=
" t.fk_user_author,";
1081 $sql .=
" t.import_key,";
1082 $sql .=
" t.code_journal,";
1083 $sql .=
" t.journal_label,";
1084 $sql .=
" t.piece_num,";
1085 $sql .=
" t.date_creation,";
1086 $sql .=
" t.date_lim_reglement,";
1087 $sql .=
" t.tms as date_modification,";
1088 $sql .=
" t.date_export,";
1089 $sql .=
" t.date_validated as date_validation";
1090 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1092 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
1093 if ($showAlreadyExportMovements == 0) {
1094 $sql .=
" AND t.date_export IS NULL";
1098 if (is_array($filter)) {
1099 dol_syslog(
"You are using a deprecated use of fetchAll. filter parameter mus be an USF string now.", LOG_WARNING);
1100 $sqlwhere = array();
1101 if (count($filter) > 0) {
1102 foreach ($filter as $key => $value) {
1103 if ($key ==
't.doc_date') {
1104 $sqlwhere[] = $this->db->sanitize($key).
' = \''.$this->db->idate($value).
'\'';
1105 } elseif ($key ==
't.doc_date>=') {
1106 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate($value).
"'";
1107 } elseif ($key ==
't.doc_date<=') {
1108 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate($value).
"'";
1109 } elseif ($key ==
't.doc_date>') {
1110 $sqlwhere[] =
"t.doc_date > '".$this->db->idate($value).
"'";
1111 } elseif ($key ==
't.doc_date<') {
1112 $sqlwhere[] =
"t.doc_date < '".$this->db->idate($value).
"'";
1113 } elseif ($key ==
't.numero_compte>=') {
1114 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1115 } elseif ($key ==
't.numero_compte<=') {
1116 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1117 } elseif ($key ==
't.subledger_account>=') {
1118 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1119 } elseif ($key ==
't.subledger_account<=') {
1120 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1121 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1122 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
1123 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1124 $sqlwhere[] = $this->db->sanitize($key).
' LIKE \''.$this->db->escape($value).
'%\'';
1125 } elseif ($key ==
't.date_creation>=') {
1126 $sqlwhere[] =
't.date_creation >= \''.$this->db->idate($value).
'\'';
1127 } elseif ($key ==
't.date_creation<=') {
1128 $sqlwhere[] =
't.date_creation <= \''.$this->db->idate($value).
'\'';
1129 } elseif ($key ==
't.tms>=') {
1130 $sqlwhere[] =
't.tms >= \''.$this->db->idate($value).
'\'';
1131 } elseif ($key ==
't.tms<=') {
1132 $sqlwhere[] =
't.tms <= \''.$this->db->idate($value).
'\'';
1133 } elseif ($key ==
't.date_export>=') {
1134 $sqlwhere[] =
't.date_export >= \''.$this->db->idate($value).
'\'';
1135 } elseif ($key ==
't.date_export<=') {
1136 $sqlwhere[] =
't.date_export <= \''.$this->db->idate($value).
'\'';
1137 } elseif ($key ==
't.date_validated>=') {
1138 $sqlwhere[] =
't.date_validated >= \''.$this->db->idate($value).
'\'';
1139 } elseif ($key ==
't.date_validated<=') {
1140 $sqlwhere[] =
't.date_validated <= \''.$this->db->idate($value).
'\'';
1141 } elseif ($key ==
't.credit' || $key ==
't.debit') {
1143 } elseif ($key ==
't.code_journal' && !empty($value)) {
1144 if (is_array($value)) {
1145 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1154 if (count($sqlwhere) > 0) {
1155 $sql .=
' AND '.implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1164 if ($errormessage) {
1165 $this->errors[] = $errormessage;
1166 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1170 if (!empty($sortfield)) {
1171 $sql .= $this->db->order($sortfield, $sortorder);
1173 if (!empty($limit)) {
1174 $sql .= $this->db->plimit($limit + 1, $offset);
1176 $this->lines = array();
1178 $resql = $this->db->query($sql);
1180 $num = $this->db->num_rows($resql);
1183 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1186 $line->id = $obj->rowid;
1188 $line->doc_date = $this->db->jdate($obj->doc_date);
1189 $line->doc_type = $obj->doc_type;
1190 $line->doc_ref = $obj->doc_ref;
1191 $line->fk_doc = $obj->fk_doc;
1192 $line->fk_docdet = $obj->fk_docdet;
1193 $line->thirdparty_code = $obj->thirdparty_code;
1194 $line->subledger_account = $obj->subledger_account;
1195 $line->subledger_label = $obj->subledger_label;
1196 $line->numero_compte = $obj->numero_compte;
1197 $line->label_compte = $obj->label_compte;
1198 $line->label_operation = $obj->label_operation;
1199 $line->debit = $obj->debit;
1200 $line->credit = $obj->credit;
1201 $line->montant = $obj->amount;
1202 $line->amount = $obj->amount;
1203 $line->sens = $obj->sens;
1204 $line->lettering_code = $obj->lettering_code;
1205 $line->date_lettering = $obj->date_lettering;
1206 $line->fk_user_author = $obj->fk_user_author;
1207 $line->import_key = $obj->import_key;
1208 $line->code_journal = $obj->code_journal;
1209 $line->journal_label = $obj->journal_label;
1210 $line->piece_num = $obj->piece_num;
1211 $line->date_creation = $this->db->jdate($obj->date_creation);
1212 $line->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1213 $line->date_modification = $this->db->jdate($obj->date_modification);
1214 $line->date_export = $this->db->jdate($obj->date_export);
1215 $line->date_validation = $this->db->jdate($obj->date_validation);
1217 $this->lines[] = $line;
1221 $this->db->free($resql);
1225 $this->errors[] =
'Error '.$this->db->lasterror();
1226 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1243 public function fetchAllBalance($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $option = 0)
1247 $this->lines = array();
1252 $sql .=
" t.numero_compte,";
1253 if (!empty($option)) {
1254 $sql .=
" t.subledger_account,";
1255 $sql .=
" t.subledger_label,";
1257 $sql .=
" SUM(t.debit) as debit,";
1258 $sql .=
" SUM(t.credit) as credit";
1259 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1260 $sql .=
' WHERE entity = ' . ((int) $conf->entity);
1263 if (is_array($filter)) {
1264 $sqlwhere = array();
1265 if (count($filter) > 0) {
1266 foreach ($filter as $key => $value) {
1267 if ($key ==
't.doc_date') {
1268 $sqlwhere[] = $this->db->sanitize($key).
" = '".$this->db->idate($value).
"'";
1269 } elseif ($key ==
't.doc_date>=') {
1270 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate($value).
"'";
1271 } elseif ($key ==
't.doc_date<=') {
1272 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate($value).
"'";
1273 } elseif ($key ==
't.doc_date>') {
1274 $sqlwhere[] =
"t.doc_date > '".$this->db->idate($value).
"'";
1275 } elseif ($key ==
't.doc_date<') {
1276 $sqlwhere[] =
"t.doc_date < '".$this->db->idate($value).
"'";
1277 } elseif ($key ==
't.numero_compte>=') {
1278 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1279 } elseif ($key ==
't.numero_compte<=') {
1280 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1281 } elseif ($key ==
't.subledger_account>=') {
1282 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1283 } elseif ($key ==
't.subledger_account<=') {
1284 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1285 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1286 $sqlwhere[] = $this->db->sanitize($key).
" = ".((int) $value);
1287 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1288 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1289 } elseif ($key ==
't.subledger_label') {
1290 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1291 } elseif ($key ==
't.code_journal' && !empty($value)) {
1292 if (is_array($value)) {
1293 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1297 } elseif ($key ==
't.reconciled_option') {
1298 $sqlwhere[] =
't.lettering_code IS NULL';
1300 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
1304 if (count($sqlwhere) > 0) {
1305 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1314 if ($errormessage) {
1315 $this->errors[] = $errormessage;
1316 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1320 if (!empty($option)) {
1321 $sql .=
" AND t.subledger_account IS NOT NULL";
1322 $sql .=
" AND t.subledger_account <> ''";
1323 $sql .=
" GROUP BY t.numero_compte, t.subledger_account, t.subledger_label";
1324 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
1325 $sortorder =
'ASC'.($sortfield ?
','.$sortfield :
'');
1327 $sql .=
' GROUP BY t.numero_compte';
1328 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
1329 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1332 if (!empty($sortfield)) {
1333 $sql .= $this->db->order($sortfield, $sortorder);
1335 if (!empty($limit)) {
1336 $sql .= $this->db->plimit($limit + 1, $offset);
1340 $resql = $this->db->query($sql);
1343 $num = $this->db->num_rows($resql);
1346 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1349 $line->numero_compte = $obj->numero_compte;
1351 if (!empty($option)) {
1352 $line->subledger_account = $obj->subledger_account;
1353 $line->subledger_label = $obj->subledger_label;
1355 $line->debit = $obj->debit;
1356 $line->credit = $obj->credit;
1358 $this->lines[] = $line;
1362 $this->db->free($resql);
1366 $this->errors[] =
'Error '.$this->db->lasterror();
1367 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1389 if (isset($this->doc_type)) {
1390 $this->doc_type = trim($this->doc_type);
1392 if (isset($this->doc_ref)) {
1393 $this->doc_ref = trim($this->doc_ref);
1395 if (isset($this->fk_doc)) {
1396 $this->fk_doc = (int) $this->fk_doc;
1398 if (isset($this->fk_docdet)) {
1399 $this->fk_docdet = (int) $this->fk_docdet;
1401 if (isset($this->thirdparty_code)) {
1402 $this->thirdparty_code = trim($this->thirdparty_code);
1404 if (isset($this->subledger_account)) {
1405 $this->subledger_account = trim($this->subledger_account);
1407 if (isset($this->subledger_label)) {
1408 $this->subledger_label = trim($this->subledger_label);
1410 if (isset($this->numero_compte)) {
1411 $this->numero_compte = trim($this->numero_compte);
1413 if (isset($this->label_compte)) {
1414 $this->label_compte = trim($this->label_compte);
1416 if (isset($this->label_operation)) {
1417 $this->label_operation = trim($this->label_operation);
1419 if (isset($this->sens)) {
1420 $this->sens = trim($this->sens);
1422 if (isset($this->import_key)) {
1423 $this->import_key = trim($this->import_key);
1425 if (isset($this->code_journal)) {
1426 $this->code_journal = trim($this->code_journal);
1428 if (isset($this->journal_label)) {
1429 $this->journal_label = trim($this->journal_label);
1431 if (isset($this->piece_num)) {
1432 $this->piece_num = (int) $this->piece_num;
1438 } elseif ($result == 0) {
1440 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1442 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1447 $this->debit = (float)
price2num($this->debit,
'MT');
1448 $this->credit = (float)
price2num($this->credit,
'MT');
1449 $this->montant = (float)
price2num($this->montant,
'MT');
1455 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.$mode.
' SET';
1456 $sql .=
' doc_date = '.(!isset($this->doc_date) ||
dol_strlen($this->doc_date) != 0 ?
"'".$this->db->idate($this->doc_date).
"'" :
'null').
',';
1457 $sql .=
' doc_type = '.(isset($this->doc_type) ?
"'".$this->db->escape($this->doc_type).
"'" :
"null").
',';
1458 $sql .=
' doc_ref = '.(isset($this->doc_ref) ?
"'".$this->db->escape($this->doc_ref).
"'" :
"null").
',';
1459 $sql .=
' fk_doc = '.(isset($this->fk_doc) ? $this->fk_doc :
"null").
',';
1460 $sql .=
' fk_docdet = '.(isset($this->fk_docdet) ? $this->fk_docdet :
"null").
',';
1461 $sql .=
' thirdparty_code = '.(isset($this->thirdparty_code) ?
"'".$this->db->escape($this->thirdparty_code).
"'" :
"null").
',';
1462 $sql .=
' subledger_account = '.(isset($this->subledger_account) ?
"'".$this->db->escape($this->subledger_account).
"'" :
"null").
',';
1463 $sql .=
' subledger_label = '.(isset($this->subledger_label) ?
"'".$this->db->escape($this->subledger_label).
"'" :
"null").
',';
1464 $sql .=
' numero_compte = '.(isset($this->numero_compte) ?
"'".$this->db->escape($this->numero_compte).
"'" :
"null").
',';
1465 $sql .=
' label_compte = '.(isset($this->label_compte) ?
"'".$this->db->escape($this->label_compte).
"'" :
"null").
',';
1466 $sql .=
' label_operation = '.(isset($this->label_operation) ?
"'".$this->db->escape($this->label_operation).
"'" :
"null").
',';
1467 $sql .=
' debit = '.(isset($this->debit) ? $this->debit :
"null").
',';
1468 $sql .=
' credit = '.(isset($this->credit) ? $this->credit :
"null").
',';
1469 $sql .=
' montant = '.(isset($this->montant) ? $this->montant :
"null").
',';
1470 $sql .=
' sens = '.(isset($this->sens) ?
"'".$this->db->escape($this->sens).
"'" :
"null").
',';
1471 $sql .=
' fk_user_author = '.(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
',';
1472 $sql .=
' import_key = '.(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
',';
1473 $sql .=
' code_journal = '.(isset($this->code_journal) ?
"'".$this->db->escape($this->code_journal).
"'" :
"null").
',';
1474 $sql .=
' journal_label = '.(isset($this->journal_label) ?
"'".$this->db->escape($this->journal_label).
"'" :
"null").
',';
1475 $sql .=
' piece_num = '.(isset($this->piece_num) ? $this->piece_num :
"null");
1476 $sql .=
' WHERE rowid='.((int) $this->
id);
1480 $resql = $this->db->query($sql);
1483 $this->errors[] =
'Error '.$this->db->lasterror();
1484 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1499 $this->db->rollback();
1503 $this->db->commit();
1518 public function updateByMvt($piece_num =
'', $field =
'', $value =
'', $mode =
'')
1523 if (!isset($sql_filter)) {
1529 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.$mode;
1530 $sql .=
" SET ".$this->db->sanitize($field).
" = ".(is_numeric($value) ? ((float) $value) :
"'".$this->db->escape($value).
"'");
1531 $sql .=
" WHERE piece_num = ".((int) $piece_num);
1532 $sql .= $sql_filter;
1534 $resql = $this->db->query($sql);
1538 $this->errors[] =
'Error '.$this->db->lasterror();
1539 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1542 $this->db->rollback();
1546 $this->db->commit();
1560 public function delete(
User $user, $notrigger = 0, $mode =
'')
1569 } elseif ($result == 0) {
1571 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1573 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1593 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.$mode;
1594 $sql .=
' WHERE rowid='.((int) $this->
id);
1596 $resql = $this->db->query($sql);
1599 $this->errors[] =
'Error '.$this->db->lasterror();
1600 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1606 $this->db->rollback();
1610 $this->db->commit();
1628 if (!isset($sql_filter)) {
1634 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1635 $sql .=
" WHERE import_key = '".$this->db->escape($importkey).
"'";
1636 $sql .= $sql_filter;
1638 $resql = $this->db->query($sql);
1641 $this->errors[] =
"Error ".$this->db->lasterror();
1642 dol_syslog(get_class($this).
"::delete Error ".$this->db->lasterror(), LOG_ERR);
1643 $this->db->rollback();
1647 $this->db->commit();
1662 global $conf, $langs;
1664 if (empty($delyear) && empty($journal)) {
1665 $this->error =
'ErrorOneFieldRequired';
1668 if (!empty($delmonth) && empty($delyear)) {
1669 $this->error =
'YearRequiredIfMonthDefined';
1674 if (!isset($sql_filter)) {
1682 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1683 $sql .=
" WHERE 1 = 1";
1685 if (!empty($journal)) {
1686 $sql .=
" AND code_journal = '".$this->db->escape($journal).
"'";
1688 $sql .=
" AND entity = " . ((int) $conf->entity);
1690 $sql .=
" AND date_validated IS NULL";
1691 $sql .= $sql_filter;
1695 $resql = $this->db->query($sql);
1698 $this->errors[] =
"Error ".$this->db->lasterror();
1699 foreach ($this->errors as $errmsg) {
1700 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1701 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1703 $this->db->rollback();
1707 $this->db->commit();
1723 if (!isset($sql_filter)) {
1733 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1734 $sql .=
" WHERE piece_num = ".(int) $piecenum;
1735 $sql .=
" AND date_validated IS NULL";
1736 $sql .=
" AND entity = " . ((int) $conf->entity);
1737 $sql .= $sql_filter;
1739 $resql = $this->db->query($sql);
1742 $this->errors[] =
"Error ".$this->db->lasterror();
1743 foreach ($this->errors as $errmsg) {
1744 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1745 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1747 $this->db->rollback();
1750 $nbprocessed = $this->db->affected_rows($resql);
1753 $this->db->commit();
1755 return $nbprocessed;
1783 $object->context[
'createfromclone'] =
'createfromclone';
1784 $result =
$object->create($user);
1789 $this->errors =
$object->errors;
1790 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1793 unset(
$object->context[
'createfromclone']);
1797 $this->db->commit();
1801 $this->db->rollback();
1820 $this->doc_date = $now;
1821 $this->doc_type =
'';
1822 $this->doc_ref =
'';
1824 $this->fk_docdet = 0;
1825 $this->thirdparty_code =
'CU001';
1826 $this->subledger_account =
'41100001';
1827 $this->subledger_label =
'My customer company';
1828 $this->numero_compte =
'411';
1829 $this->label_compte =
'Customer';
1830 $this->label_operation =
'Sales of pea';
1831 $this->debit = 99.9;
1832 $this->credit = 0.0;
1833 $this->amount = 0.0;
1835 $this->fk_user_author = $user->id;
1836 $this->import_key =
'20201027';
1837 $this->code_journal =
'VT';
1838 $this->journal_label =
'Journal de vente';
1839 $this->piece_num = 1234;
1840 $this->date_creation = $now;
1856 $sql =
"SELECT piece_num, doc_date, code_journal, journal_label, doc_ref, doc_type,";
1857 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation, import_key";
1859 if ($mode !=
"_tmp") {
1860 $sql .=
", date_export";
1862 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1863 $sql .=
" WHERE piece_num = ".((int) $piecenum);
1864 $sql .=
" AND entity = " . ((int) $conf->entity);
1867 $result = $this->db->query($sql);
1869 $obj = $this->db->fetch_object($result);
1871 $this->piece_num = $obj->piece_num;
1872 $this->code_journal = $obj->code_journal;
1873 $this->journal_label = $obj->journal_label;
1874 $this->doc_date = $this->db->jdate($obj->doc_date);
1875 $this->doc_ref = $obj->doc_ref;
1876 $this->doc_type = $obj->doc_type;
1877 $this->date_creation = $this->db->jdate($obj->date_creation);
1878 $this->date_modification = $this->db->jdate($obj->date_modification);
1879 if ($mode !=
"_tmp") {
1880 $this->date_export = $this->db->jdate($obj->date_export);
1882 $this->date_validation = $this->db->jdate($obj->date_validation);
1883 $this->import_key = $obj->import_key;
1885 $this->error =
"Error ".$this->db->lasterror();
1886 dol_syslog(__METHOD__.$this->error, LOG_ERR);
1903 $sql =
"SELECT MAX(piece_num)+1 as max FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1904 $sql .=
" WHERE entity = " . ((int) $conf->entity);
1906 dol_syslog(get_class($this).
"::getNextNumMvt", LOG_DEBUG);
1908 $result = $this->db->query($sql);
1911 $obj = $this->db->fetch_object($result);
1913 $result = $obj->max;
1915 if (empty($result)) {
1920 $this->error =
"Error ".$this->db->lasterror();
1921 dol_syslog(get_class($this).
"::getNextNumMvt ".$this->error, LOG_ERR);
1937 $sql =
"SELECT rowid, doc_date, doc_type,";
1938 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
1939 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
1940 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, journal_label, piece_num,";
1941 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation";
1943 if ($mode !=
"_tmp") {
1944 $sql .=
", date_export";
1946 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1947 $sql .=
" WHERE piece_num = ".((int) $piecenum);
1948 $sql .=
" AND entity = " . ((int) $conf->entity);
1951 $result = $this->db->query($sql);
1953 while ($obj = $this->db->fetch_object($result)) {
1956 $line->id = $obj->rowid;
1958 $line->doc_date = $this->db->jdate($obj->doc_date);
1959 $line->doc_type = $obj->doc_type;
1960 $line->doc_ref = $obj->doc_ref;
1961 $line->fk_doc = $obj->fk_doc;
1962 $line->fk_docdet = $obj->fk_docdet;
1963 $line->thirdparty_code = $obj->thirdparty_code;
1964 $line->subledger_account = $obj->subledger_account;
1965 $line->subledger_label = $obj->subledger_label;
1966 $line->numero_compte = $obj->numero_compte;
1967 $line->label_compte = $obj->label_compte;
1968 $line->label_operation = $obj->label_operation;
1969 $line->debit = $obj->debit;
1970 $line->credit = $obj->credit;
1971 $line->montant = $obj->amount;
1972 $line->amount = $obj->amount;
1973 $line->sens = $obj->sens;
1974 $line->code_journal = $obj->code_journal;
1975 $line->journal_label = $obj->journal_label;
1976 $line->piece_num = $obj->piece_num;
1977 $line->date_creation = $obj->date_creation;
1978 $line->date_modification = $obj->date_modification;
1979 if ($mode !=
"_tmp") {
1980 $line->date_export = $obj->date_export;
1982 $line->date_validation = $obj->date_validation;
1984 $this->linesmvt[] = $line;
1987 $this->error =
"Error ".$this->db->lasterror();
1988 dol_syslog(__METHOD__.$this->error, LOG_ERR);
2007 $sql =
"SELECT rowid, doc_date, doc_type,";
2008 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
2009 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
2010 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, piece_num,";
2011 $sql .=
" date_validated as date_validation";
2012 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
2013 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2015 dol_syslog(get_class($this).
"::export_bookkeeping", LOG_DEBUG);
2017 $resql = $this->db->query($sql);
2020 $this->linesexport = array();
2022 $num = $this->db->num_rows($resql);
2023 while ($obj = $this->db->fetch_object($resql)) {
2026 $line->id = $obj->rowid;
2028 $line->doc_date = $this->db->jdate($obj->doc_date);
2029 $line->doc_type = $obj->doc_type;
2030 $line->doc_ref = $obj->doc_ref;
2031 $line->fk_doc = $obj->fk_doc;
2032 $line->fk_docdet = $obj->fk_docdet;
2033 $line->thirdparty_code = $obj->thirdparty_code;
2034 $line->subledger_account = $obj->subledger_account;
2035 $line->subledger_label = $obj->subledger_label;
2036 $line->numero_compte = $obj->numero_compte;
2037 $line->label_compte = $obj->label_compte;
2038 $line->label_operation = $obj->label_operation;
2039 $line->debit = $obj->debit;
2040 $line->credit = $obj->credit;
2041 $line->montant = $obj->amount;
2042 $line->amount = $obj->amount;
2043 $line->sens = $obj->sens;
2044 $line->code_journal = $obj->code_journal;
2045 $line->piece_num = $obj->piece_num;
2046 $line->date_validation = $obj->date_validation;
2048 $this->linesexport[] = $line;
2050 $this->db->free($resql);
2054 $this->error =
"Error ".$this->db->lasterror();
2055 dol_syslog(get_class($this).
"::export_bookkeeping ".$this->error, LOG_ERR);
2075 if (!isset($sql_filter)) {
2081 if ($direction == 0) {
2085 if ($next_piecenum < 0) {
2091 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity).
" AND numero_compte IS NULL AND debit = 0 AND credit = 0";
2092 $resql = $this->db->query($sql);
2095 $this->errors[] =
'Error '.$this->db->lasterror();
2096 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2101 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
' (doc_date, doc_type,';
2102 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2103 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2104 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num, date_creation)';
2105 $sql .=
' SELECT doc_date, doc_type,';
2106 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2107 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2108 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.((int) $next_piecenum).
", '".$this->db->idate($now).
"'";
2109 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND numero_compte IS NOT NULL AND entity = ' .((int) $conf->entity);
2110 $sql .= $sql_filter;
2111 $resql = $this->db->query($sql);
2114 $this->errors[] =
'Error '.$this->db->lasterror();
2115 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2120 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2121 $resql = $this->db->query($sql);
2124 $this->errors[] =
'Error '.$this->db->lasterror();
2125 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2128 } elseif ($direction == 1) {
2130 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2131 $resql = $this->db->query($sql);
2134 $this->errors[] =
'Error '.$this->db->lasterror();
2135 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2140 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'_tmp (doc_date, doc_type,';
2141 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2142 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2143 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)';
2144 $sql .=
' SELECT doc_date, doc_type,';
2145 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2146 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2147 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num';
2148 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2149 $sql .= $sql_filter;
2150 $resql = $this->db->query($sql);
2153 $this->errors[] =
'Error '.$this->db->lasterror();
2154 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2159 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2160 $sql .= $sql_filter;
2161 $resql = $this->db->query($sql);
2164 $this->errors[] =
'Error '.$this->db->lasterror();
2165 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2170 $this->db->commit();
2173 $this->db->rollback();
2201 public function select_account($selectid, $htmlname =
'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase =
'')
2206 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
2210 $sql =
"SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version";
2211 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab";
2212 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.account_number = ab.numero_compte";
2213 $sql .=
" AND aa.active = 1";
2214 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2215 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2216 $sql .=
" AND ab.entity = " . ((int) $conf->entity);
2217 $sql .=
" ORDER BY account_number ASC";
2219 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2220 $resql = $this->db->query($sql);
2223 $this->error =
"Error ".$this->db->lasterror();
2224 dol_syslog(get_class($this).
"::select_account ".$this->error, LOG_ERR);
2233 while ($obj = $this->db->fetch_object($resql)) {
2236 $select_value_in = $obj->rowid;
2237 $select_value_out = $obj->rowid;
2239 if ($select_in == 1) {
2240 $select_value_in = $obj->account_number;
2242 if ($select_out == 1) {
2243 $select_value_out = $obj->account_number;
2248 if (($selectid !=
'') && $selectid == $select_value_in) {
2249 $selected = $select_value_out;
2252 $options[$select_value_out] = $label;
2255 $out .=
Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0,
'', 0, 0, 0,
'',
'maxwidth300');
2256 $this->db->free($resql);
2272 $sql =
"SELECT root.rowid, root.account_number, root.label as label,";
2273 $sql .=
" parent.rowid as parent_rowid, parent.account_number as parent_account_number, parent.label as parent_label";
2274 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_account as aa";
2275 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2276 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2277 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as parent ON aa.account_parent = parent.rowid AND parent.active = 1";
2278 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as root ON parent.account_parent = root.rowid AND root.active = 1";
2279 $sql .=
" WHERE aa.account_number = '".$this->db->escape($account).
"'";
2280 $sql .=
" AND aa.entity = " . ((int) $conf->entity);
2282 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2283 $resql = $this->db->query($sql);
2286 if ($this->db->num_rows($resql)) {
2287 $obj = $this->db->fetch_object($resql);
2290 $result = array(
'id' => $obj->rowid,
'account_number' => $obj->account_number,
'label' => $obj->label);
2293 $this->error =
"Error ".$this->db->lasterror();
2294 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2313 $sql =
"SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
2314 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_account as aa ";
2315 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2316 $sql .=
" AND aa.account_number = '".$this->db->escape($account).
"'";
2317 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2318 $sql .=
" AND aa.active = 1";
2319 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
2320 $sql .=
" WHERE aa.entity = " . ((int) $conf->entity);
2322 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2323 $resql = $this->db->query($sql);
2326 if ($this->db->num_rows($resql)) {
2327 $obj = $this->db->fetch_object($resql);
2329 if (empty($obj->category)) {
2332 return $obj->label.
' ('.$obj->category.
')';
2335 $this->error =
"Error ".$this->db->lasterror();
2336 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2352 $alias = trim($alias);
2353 $alias = !empty($alias) && strpos($alias,
'.') < 0 ? $alias .
"." : $alias;
2355 if (!isset(self::$can_modify_bookkeeping_sql_cached[$alias]) || $force) {
2361 $sql_list = array();
2362 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2364 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2365 $sql_list[$i] =
"(";
2366 $sql_list[$i] .=
"'".$this->db->idate($fiscal_period[
'date_start']) .
"' <= ".$this->db->sanitize($alias).
"doc_date";
2367 if (!empty($fiscal_period[
'date_end'])) {
2368 $sql_list[$i] .=
" AND ";
2369 $sql_list[$i] .= $this->db->sanitize($alias).
"doc_date <= '" . $this->db->idate($fiscal_period[
'date_end']).
"'";
2371 $sql_list[$i] .=
")";
2375 $sqlsanitized = implode(
' OR ', $sql_list);
2376 self::$can_modify_bookkeeping_sql_cached[$alias] = empty($sql_list) ?
"" :
" AND (".$sqlsanitized.
")";
2379 return self::$can_modify_bookkeeping_sql_cached[$alias];
2401 $result = $bookkeeping->fetch($id,
null, $mode);
2406 if (!empty($conf->cache[
'closed_fiscal_period_cached']) && is_array($conf->cache[
'closed_fiscal_period_cached'])) {
2407 foreach ($conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2408 if ($fiscal_period[
'date_start'] <= $bookkeeping->doc_date && $bookkeeping->doc_date <= $fiscal_period[
'date_end']) {
2422 $result = $bookkeeping->fetch($id,
null, $mode);
2427 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2428 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2429 if (!empty($fiscal_period[
'date_start']) && $fiscal_period[
'date_start'] <= $bookkeeping->doc_date && (empty($fiscal_period[
'date_end']) || $bookkeeping->doc_date <= $fiscal_period[
'date_end'])) {
2456 if (!empty($conf->cache[
'closed_fiscal_period_cached']) && is_array($conf->cache[
'closed_fiscal_period_cached'])) {
2457 foreach ($conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2458 if ($fiscal_period[
'date_start'] <= $date && $date <= $fiscal_period[
'date_end']) {
2471 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2472 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2473 if (!empty($fiscal_period[
'date_start']) && $fiscal_period[
'date_start'] <= $date && (empty($fiscal_period[
'date_end']) || $date <= $fiscal_period[
'date_end'])) {
2494 if ($mode ==
'active') {
2495 if (!isset($conf->cache[
'active_fiscal_period_cached']) || $force) {
2496 $sql =
"SELECT date_start, date_end";
2497 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2498 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2499 $sql .=
" AND statut = 0";
2501 $resql = $this->db->query($sql);
2503 $this->errors[] = $this->db->lasterror();
2508 while ($obj = $this->db->fetch_object($resql)) {
2510 'date_start' => $this->db->jdate($obj->date_start),
2511 'date_end' => $this->db->jdate($obj->date_end),
2514 $conf->cache[
'active_fiscal_period_cached'] = $list;
2517 if ($mode ==
'closed') {
2518 if (!isset($conf->cache[
'closed_fiscal_period_cached']) || $force) {
2519 $sql =
"SELECT date_start, date_end";
2520 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2521 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2522 $sql .=
" AND statut = 1";
2524 $resql = $this->db->query($sql);
2526 $this->errors[] = $this->db->lasterror();
2531 while ($obj = $this->db->fetch_object($resql)) {
2533 'date_start' => $this->db->jdate($obj->date_start),
2534 'date_end' => $this->db->jdate($obj->date_end),
2537 $conf->cache[
'closed_fiscal_period_cached'] = $list;
2555 $sql =
"SELECT rowid, label, date_start, date_end, statut";
2556 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2557 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2558 if (!empty($filter)) {
2559 $sql .=
" AND (" . $this->db->sanitize($filter, 1, 1, 1) .
')';
2561 $sql .= $this->db->order(
'date_start',
'ASC');
2563 $resql = $this->db->query($sql);
2565 $this->errors[] = $this->db->lasterror();
2569 while ($obj = $this->db->fetch_object($resql)) {
2570 $list[$obj->rowid] = array(
2571 'id' => (
int) $obj->rowid,
2572 'label' => $obj->label,
2573 'date_start' => $this->db->jdate($obj->date_start),
2574 'date_end' => $this->db->jdate($obj->date_end),
2575 'status' => (
int) $obj->statut,
2594 $sql =
"SELECT YEAR(b.doc_date) as year";
2595 for ($i = 1; $i <= 12; $i++) {
2596 $sql .=
", SUM(".$this->db->ifsql(
"MONTH(b.doc_date) = ".((
int) $i),
"1",
"0") .
") AS month".((int) $i);
2598 $sql .=
", COUNT(b.rowid) as total";
2599 $sql .=
" FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping as b";
2600 $sql .=
" WHERE b.doc_date >= '" . $this->db->idate($date_start) .
"'";
2601 $sql .=
" AND b.doc_date <= '" . $this->db->idate($date_end) .
"'";
2602 $sql .=
" AND b.entity IN (" .
getEntity(
'bookkeeping', 0) .
")";
2608 $sql .=
" AND b.doc_date BETWEEN 0 AND 0";
2611 $sql .=
" AND date_validated IS NULL";
2614 $sql .=
" GROUP BY YEAR(b.doc_date)";
2615 $sql .= $this->db->order(
"year",
'ASC');
2618 $resql = $this->db->query($sql);
2620 $this->errors[] = $this->db->lasterror();
2624 while ($obj = $this->db->fetch_object($resql)) {
2625 $total += (int) $obj->total;
2627 'year' => (
int) $obj->year,
2629 'total' => (
int) $obj->total,
2631 for ($i = 1; $i <= 12; $i++) {
2632 $year_list[
'count'][$i] = (int) $obj->{
'month' . $i};
2635 $list[] = $year_list;
2638 $this->db->free($resql);
2660 $sql =
" UPDATE " . MAIN_DB_PREFIX .
"accounting_bookkeeping";
2661 $sql .=
" SET date_validated = '" . $this->db->idate($now) .
"'";
2662 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2663 $sql .=
" AND DATE(doc_date) >= '" . $this->db->idate($date_start) .
"'";
2664 $sql .=
" AND DATE(doc_date) <= '" . $this->db->idate($date_end) .
"'";
2665 $sql .=
" AND date_validated IS NULL";
2668 $resql = $this->db->query($sql);
2670 $this->errors[] = $this->db->lasterror();
2690 $income_statement_amount = 0;
2692 if (
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
2693 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
2695 $pcg_type_filter = array();
2696 foreach ($accounting_groups_used_for_income_statement as $item) {
2697 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
2701 $sql .=
" t.numero_compte,";
2702 $sql .=
" aa.pcg_type,";
2703 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as accounting_result";
2704 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
2705 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'accounting_account as aa ON aa.account_number = t.numero_compte';
2706 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
2707 $sql .=
" AND aa.entity = " . ((int) $conf->entity);
2708 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX .
'accounting_system WHERE rowid = ' . ((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')) .
')';
2709 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
2710 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) .
"'";
2711 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
2712 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
2714 $resql = $this->db->query($sql);
2716 $this->errors[] =
'Error ' . $this->db->lasterror();
2717 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2719 while ($obj = $this->db->fetch_object($resql)) {
2720 $income_statement_amount += $obj->accounting_result;
2725 return (
string) $income_statement_amount;
2737 public function closeFiscalPeriod($fiscal_period_id, $new_fiscal_period_id, $separate_auxiliary_account =
false, $generate_bookkeeping_records =
true)
2739 global $conf, $langs, $user;
2742 $fiscal_period_id = max(0, $fiscal_period_id);
2743 if (empty($fiscal_period_id)) {
2744 $langs->load(
'errors');
2745 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2749 $result = $fiscal_period->fetch($fiscal_period_id);
2751 $this->error = $fiscal_period->error;
2752 $this->errors = $fiscal_period->errors;
2754 } elseif (empty($fiscal_period->id)) {
2755 $langs->loadLangs(array(
'errors',
'compta'));
2756 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
2761 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
2762 if (empty($new_fiscal_period_id)) {
2763 $langs->load(
'errors');
2764 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2767 $new_fiscal_period =
new Fiscalyear($this->db);
2768 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
2770 $this->error = $new_fiscal_period->error;
2771 $this->errors = $new_fiscal_period->errors;
2773 } elseif (empty($new_fiscal_period->id)) {
2774 $langs->loadLangs(array(
'errors',
'compta'));
2775 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
2782 $fiscal_period->statut = Fiscalyear::STATUS_CLOSED;
2783 $fiscal_period->status = Fiscalyear::STATUS_CLOSED;
2784 $result = $fiscal_period->update($user);
2786 $this->error = $fiscal_period->error;
2787 $this->errors = $fiscal_period->errors;
2791 if (!$error && !empty($generate_bookkeeping_records)) {
2793 if (empty($journal_id)) {
2794 $langs->loadLangs(array(
'errors',
'accountancy'));
2795 $this->errors[] = $langs->trans(
'ErrorBadParameters') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
2802 $result = $journal->fetch($journal_id);
2804 $this->error = $journal->error;
2805 $this->errors = $journal->errors;
2807 } elseif ($result == 0) {
2808 $langs->loadLangs(array(
'errors',
'accountancy'));
2809 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
2815 $accounting_groups_used_for_balance_sheet_account = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))),
'strlen');
2816 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
2818 $pcg_type_filter = array();
2819 $tmp = array_merge($accounting_groups_used_for_balance_sheet_account, $accounting_groups_used_for_income_statement);
2820 foreach ($tmp as $item) {
2821 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
2825 $sql .=
" t.numero_compte,";
2826 if ($separate_auxiliary_account) {
2827 $sql .=
" NULLIF(t.subledger_account, '') as subledger_account,";
2829 $sql .=
" aa.pcg_type,";
2830 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as opening_balance";
2831 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
2832 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'accounting_account as aa ON aa.account_number = t.numero_compte';
2833 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
2834 $sql .=
" AND aa.entity = ". ((int) $conf->entity);
2835 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM '.MAIN_DB_PREFIX.
'accounting_system WHERE rowid = '.((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')).
')';
2836 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
2837 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
2838 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
2839 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
2840 if ($separate_auxiliary_account) {
2841 $sql .=
" , NULLIF(t.subledger_account, '')";
2843 $sql .=
' HAVING (SUM(t.credit) - SUM(t.debit)) != 0 ';
2844 $sql .= $this->db->order(
"t.numero_compte",
"ASC");
2846 $resql = $this->db->query($sql);
2848 $this->errors[] =
'Error ' . $this->db->lasterror();
2849 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2854 $income_statement_amount = 0;
2855 while ($obj = $this->db->fetch_object($resql)) {
2856 if (in_array($obj->pcg_type, $accounting_groups_used_for_income_statement)) {
2857 $income_statement_amount += $obj->opening_balance;
2860 $mt = $obj->opening_balance;
2863 $bookkeeping->doc_date = $new_fiscal_period->date_start;
2865 $bookkeeping->date_lim_reglement =
'';
2866 $bookkeeping->doc_ref = $fiscal_period->label;
2868 $bookkeeping->date_creation = $now;
2869 $bookkeeping->doc_type =
'closure';
2870 $bookkeeping->fk_doc = $fiscal_period->id;
2871 $bookkeeping->fk_docdet = 0;
2872 $bookkeeping->thirdparty_code =
'';
2874 if ($separate_auxiliary_account) {
2875 $bookkeeping->subledger_account = $obj->subledger_account;
2877 $sql .=
" subledger_label";
2878 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
2879 $sql .=
" WHERE subledger_account = '" . $this->db->escape($obj->subledger_account) .
"'";
2880 $sql .=
" ORDER BY doc_date DESC";
2882 $result = $this->db->query($sql);
2884 $this->errors[] =
'Error: ' . $this->db->lasterror();
2885 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2888 $objtmp = $this->db->fetch_object($result);
2889 $bookkeeping->subledger_label = $objtmp->subledger_label;
2891 $bookkeeping->subledger_account =
null;
2892 $bookkeeping->subledger_label =
null;
2895 $bookkeeping->numero_compte = $obj->numero_compte;
2897 $accountingaccount->fetch(
'', $obj->numero_compte);
2898 $bookkeeping->label_compte = $accountingaccount->label;
2900 $bookkeeping->label_operation = $new_fiscal_period->label;
2901 $bookkeeping->montant = $mt;
2902 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
2903 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
2904 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
2905 $bookkeeping->code_journal = $journal->code;
2906 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
2907 $bookkeeping->fk_user_author = $user->id;
2908 $bookkeeping->entity = $conf->entity;
2910 $result = $bookkeeping->create($user);
2912 $this->error = $bookkeeping->error;
2913 $this->errors = $bookkeeping->errors;
2921 if (!$error && $income_statement_amount != 0) {
2922 $mt = $income_statement_amount;
2924 $accountingaccount->fetch(
null,
getDolGlobalString($income_statement_amount < 0 ?
'ACCOUNTING_RESULT_LOSS' :
'ACCOUNTING_RESULT_PROFIT'),
true);
2927 $bookkeeping->doc_date = $new_fiscal_period->date_start;
2929 $bookkeeping->date_lim_reglement =
'';
2930 $bookkeeping->doc_ref = $fiscal_period->label;
2932 $bookkeeping->date_creation = $now;
2933 $bookkeeping->doc_type =
'closure';
2934 $bookkeeping->fk_doc = $fiscal_period->id;
2935 $bookkeeping->fk_docdet = 0;
2936 $bookkeeping->thirdparty_code =
'';
2938 if ($separate_auxiliary_account) {
2939 $bookkeeping->subledger_account = $obj->subledger_account;
2941 $sql .=
" subledger_label";
2942 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
2943 $sql .=
" WHERE subledger_account = '" . $this->db->escape($obj->subledger_account) .
"'";
2944 $sql .=
" ORDER BY doc_date DESC";
2946 $result = $this->db->query($sql);
2948 $this->errors[] =
'Error: ' . $this->db->lasterror();
2949 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2952 $objtmp = $this->db->fetch_object($result);
2953 $bookkeeping->subledger_label = $objtmp->subledger_label;
2955 $bookkeeping->subledger_account =
null;
2956 $bookkeeping->subledger_label =
null;
2959 $bookkeeping->numero_compte = $accountingaccount->account_number;
2960 $bookkeeping->label_compte = $accountingaccount->label;
2962 $bookkeeping->label_operation = $new_fiscal_period->label;
2963 $bookkeeping->montant = $mt;
2964 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
2965 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
2966 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
2967 $bookkeeping->code_journal = $journal->code;
2968 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
2969 $bookkeeping->fk_user_author = $user->id;
2970 $bookkeeping->entity = $conf->entity;
2972 $result = $bookkeeping->create($user);
2974 $this->error = $bookkeeping->error;
2975 $this->errors = $bookkeeping->errors;
2979 $this->db->free($resql);
2985 $this->db->rollback();
2988 $this->db->commit();
3005 global $conf, $langs, $user;
3008 $fiscal_period_id = max(0, $fiscal_period_id);
3009 if (empty($fiscal_period_id)) {
3010 $langs->load(
'errors');
3011 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3015 $result = $fiscal_period->fetch($fiscal_period_id);
3017 $this->error = $fiscal_period->error;
3018 $this->errors = $fiscal_period->errors;
3020 } elseif (empty($fiscal_period->id)) {
3021 $langs->loadLangs(array(
'errors',
'compta'));
3022 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
3027 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
3028 if (empty($new_fiscal_period_id)) {
3029 $langs->load(
'errors');
3030 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3033 $new_fiscal_period =
new Fiscalyear($this->db);
3034 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
3036 $this->error = $new_fiscal_period->error;
3037 $this->errors = $new_fiscal_period->errors;
3039 } elseif (empty($new_fiscal_period->id)) {
3040 $langs->loadLangs(array(
'errors',
'compta'));
3041 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
3046 $inventory_journal_id = max(0, $inventory_journal_id);
3047 if (empty($inventory_journal_id)) {
3048 $langs->load(
'errors');
3049 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3054 $result = $inventory_journal->fetch($inventory_journal_id);
3056 $this->error = $inventory_journal->error;
3057 $this->errors = $inventory_journal->errors;
3059 } elseif ($result == 0) {
3060 $langs->loadLangs(array(
'errors',
'accountancy'));
3061 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'InventoryJournal');
3068 $sql =
'SELECT t.rowid';
3069 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
3070 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
3071 $sql .=
" AND code_journal = '" . $this->db->escape($inventory_journal->code) .
"'";
3072 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) .
"'";
3073 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
3074 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
3075 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
3077 $resql = $this->db->query($sql);
3079 $this->errors[] =
'Error ' . $this->db->lasterror();
3080 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3085 while ($obj = $this->db->fetch_object($resql)) {
3087 $result = $bookkeeping->fetch($obj->rowid);
3089 $this->error = $inventory_journal->error;
3090 $this->errors = $inventory_journal->errors;
3093 } elseif ($result == 0) {
3094 $langs->loadLangs(array(
'errors',
'accountancy'));
3095 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'LineId') .
': ' . $obj->rowid;
3100 $bookkeeping->id = 0;
3101 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3102 $bookkeeping->doc_ref = $new_fiscal_period->label;
3103 $bookkeeping->date_creation = $now;
3104 $bookkeeping->doc_type =
'accounting_reversal';
3105 $bookkeeping->fk_doc = $new_fiscal_period->id;
3106 $bookkeeping->fk_docdet = 0;
3108 $bookkeeping->montant = -$bookkeeping->montant;
3109 $bookkeeping->sens = ($bookkeeping->montant >= 0) ?
'C' :
'D';
3110 $old_debit = $bookkeeping->debit;
3111 $bookkeeping->debit = $bookkeeping->credit;
3112 $bookkeeping->credit = $old_debit;
3114 $bookkeeping->fk_user_author = $user->id;
3115 $bookkeeping->entity = $conf->entity;
3117 $result = $bookkeeping->create($user);
3119 $this->error = $bookkeeping->error;
3120 $this->errors = $bookkeeping->errors;
3125 $this->db->free($resql);
3129 $this->db->rollback();
3132 $this->db->commit();
3148 public $doc_date =
null;
3162 public $thirdparty_code;
3163 public $subledger_account;
3164 public $subledger_label;
3165 public $numero_compte;
3166 public $label_compte;
3167 public $label_operation;
3185 public $multicurrency_amount;
3190 public $multicurrency_code;
3196 public $lettering_code;
3197 public $date_lettering;
3202 public $fk_user_author;
3205 public $code_journal;
3206 public $journal_label;
3215 public $date_creation;
3220 public $date_modification;
3225 public $date_export;
3230 public $date_validation;
3235 public $date_lim_reglement;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Class to manage accounting accounts.
Class to manage accounting journals.
Class to manage Ledger (General Ledger and Subledger)
closeFiscalPeriod($fiscal_period_id, $new_fiscal_period_id, $separate_auxiliary_account=false, $generate_bookkeeping_records=true)
Close fiscal period.
getCountByMonthForFiscalPeriod($date_start, $date_end)
Get list of count by month into the fiscal period.
fetchAllBalance($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND', $option=0)
Load object in memory from the database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
select_account($selectid, $htmlname='account', $showempty=0, $event=array(), $select_in=0, $select_out=0, $aabase='')
Return list of accounts with label by chart of accounts.
getNextNumMvt($mode='')
Return next movement number.
get_compte_desc($account=null)
Description of accounting account.
__construct(DoliDB $db)
Constructor.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
deleteByImportkey($importkey, $mode='')
Delete bookkeeping by importkey.
getRootAccount($account=null)
Return id and description of a root accounting account.
transformTransaction($direction=0, $piece_num='')
Transform transaction.
insertAccountingReversal($fiscal_period_id, $inventory_journal_id, $new_fiscal_period_id, $date_start, $date_end)
Insert accounting reversal into the inventory journal of the new fiscal period.
fetchPerMvt($piecenum, $mode='')
Load an accounting document into memory from database.
create(User $user, $notrigger=0)
Create object into database.
updateByMvt($piece_num='', $field='', $value='', $mode='')
Update accounting movement.
createStd(User $user, $notrigger=0, $mode='')
Create object into database.
update(User $user, $notrigger=0, $mode='')
Update object into database.
deleteMvtNum($piecenum, $mode='')
Delete bookkeeping by piece number.
getFiscalPeriods($filter='')
Get list of fiscal period ordered by start date.
validBookkeepingDate($date)
Is the bookkeeping date valid (on an open period or not on a closed period) ?
deleteByYearAndJournal($delyear=0, $journal='', $mode='', $delmonth=0)
Delete bookkeeping by year.
loadFiscalPeriods($force=false, $mode='active')
Load list of active fiscal period.
fetchAllByAccount($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND', $option=0, $countonly=0)
Load object in memory from the database in ->lines.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
getCanModifyBookkeepingSQL($alias='', $force=false)
Get SQL string for check if the bookkeeping can be modified or deleted ? (cached)
fetch($id, $ref=null, $mode='')
Load object in memory from the database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND', $showAlreadyExportMovements=1)
Load object in memory from the database.
accountingResult($date_start, $date_end)
Define accounting result.
canModifyBookkeeping($id, $mode='')
Is the bookkeeping can be modified or deleted ?
fetchAllPerMvt($piecenum, $mode='')
Load all accounting lines related to a given transaction ID $piecenum.
validateMovementForFiscalPeriod($date_start, $date_end)
Validate all movement between the specified dates.
export_bookkeeping($model='ebp')
Export bookkeeping.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class to manage fiscal year.
Class to manage Dolibarr users.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.