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();
196 public $picto =
'generic';
201 public static $can_modify_bookkeeping_sql_cached;
223 global
$conf, $langs;
230 if (isset($this->doc_type)) {
231 $this->doc_type = trim($this->doc_type);
233 if (isset($this->doc_ref)) {
234 $this->doc_ref = trim($this->doc_ref);
236 if (isset($this->fk_doc)) {
237 $this->fk_doc = (int) $this->fk_doc;
239 if (isset($this->fk_docdet)) {
240 $this->fk_docdet = (int) $this->fk_docdet;
242 if (isset($this->thirdparty_code)) {
243 $this->thirdparty_code = trim($this->thirdparty_code);
245 if (isset($this->subledger_account)) {
246 $this->subledger_account = trim($this->subledger_account);
248 if (isset($this->subledger_label)) {
249 $this->subledger_label = trim($this->subledger_label);
251 if (isset($this->numero_compte)) {
252 $this->numero_compte = trim($this->numero_compte);
254 if (isset($this->label_compte)) {
255 $this->label_compte = trim($this->label_compte);
257 if (isset($this->label_operation)) {
258 $this->label_operation = trim($this->label_operation);
260 if (isset($this->debit)) {
261 $this->debit = (float) $this->debit;
263 if (isset($this->credit)) {
264 $this->credit = (float) $this->credit;
266 if (isset($this->montant)) {
267 $this->montant = (float) $this->montant;
269 if (isset($this->amount)) {
270 $this->amount = (float) $this->amount;
272 if (isset($this->sens)) {
273 $this->sens = trim($this->sens);
275 if (isset($this->import_key)) {
276 $this->import_key = trim($this->import_key);
278 if (isset($this->code_journal)) {
279 $this->code_journal = trim($this->code_journal);
281 if (isset($this->journal_label)) {
282 $this->journal_label = trim($this->journal_label);
284 if (isset($this->piece_num)) {
285 $this->piece_num = (int) $this->piece_num;
287 if (empty($this->debit)) {
290 if (empty($this->credit)) {
297 } elseif ($result == 0) {
299 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
301 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
307 if (($this->numero_compte ==
"") || $this->numero_compte ==
'-1' || $this->numero_compte ==
'NotDefined') {
308 $langs->loadLangs(array(
"errors"));
309 if (in_array($this->doc_type, array(
'bank',
'expense_report'))) {
310 $this->errors[] = $langs->trans(
'ErrorFieldAccountNotDefinedForBankLine', $this->fk_docdet, $this->doc_type);
313 $mesg = $this->doc_ref.
', '.$langs->trans(
"AccountAccounting").
': '.($this->numero_compte != -1 ? $this->numero_compte : $langs->trans(
"Unknown"));
314 if ($this->subledger_account && $this->subledger_account != $this->numero_compte) {
315 $mesg .=
', '.$langs->trans(
"SubledgerAccount").
': '.$this->subledger_account;
317 $this->errors[] = $langs->trans(
'ErrorFieldAccountNotDefinedForLine', $mesg);
325 $this->piece_num = 0;
332 $sql =
"SELECT count(*) as nb";
333 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
334 $sql .=
" WHERE doc_type = '".$this->db->escape($this->doc_type).
"'";
335 $sql .=
" AND fk_doc = ".((int) $this->fk_doc);
338 $sql .=
" AND fk_docdet = ".((int) $this->fk_docdet);
340 $sql .=
" AND numero_compte = '".$this->db->escape($this->numero_compte).
"'";
341 $sql .=
" AND label_operation = '".$this->db->escape($this->label_operation).
"'";
342 if (!empty($this->subledger_account)) {
343 $sql .=
" AND subledger_account = '".$this->db->escape($this->subledger_account).
"'";
345 $sql .=
" AND entity = ".$conf->entity;
347 $resql = $this->db->query($sql);
350 $row = $this->db->fetch_object($resql);
353 $sqlnum =
"SELECT piece_num";
354 $sqlnum .=
" FROM ".$this->db->prefix().$this->table_element;
355 $sqlnum .=
" WHERE doc_type = '".$this->db->escape($this->doc_type).
"'";
356 $sqlnum .=
" AND fk_doc = ".((int) $this->fk_doc);
359 $sqlnum .=
" AND fk_docdet = ".((int) $this->fk_docdet);
361 $sqlnum .=
" AND doc_ref = '".$this->db->escape($this->doc_ref).
"'";
362 $sqlnum .=
" AND entity = ".$conf->entity;
364 dol_syslog(get_class($this).
":: create sqlnum=".$sqlnum, LOG_DEBUG);
365 $resqlnum = $this->db->query($sqlnum);
367 $objnum = $this->db->fetch_object($resqlnum);
368 $this->piece_num = $objnum->piece_num;
371 dol_syslog(get_class($this).
"::create this->piece_num=".$this->piece_num, LOG_DEBUG);
372 if (empty($this->piece_num)) {
373 $sqlnum =
"SELECT MAX(piece_num)+1 as maxpiecenum";
374 $sqlnum .=
" FROM ".$this->db->prefix().$this->table_element;
375 $sqlnum .=
" WHERE entity = " . ((int)
$conf->entity);
377 $resqlnum = $this->db->query($sqlnum);
379 $objnum = $this->db->fetch_object($resqlnum);
380 $this->piece_num = $objnum->maxpiecenum;
382 dol_syslog(get_class($this).
":: create now this->piece_num=".$this->piece_num, LOG_DEBUG);
384 if (empty($this->piece_num)) {
385 $this->piece_num = 1;
390 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
" (";
392 $sql .=
", date_lim_reglement";
393 $sql .=
", doc_type";
396 $sql .=
", fk_docdet";
397 $sql .=
", thirdparty_code";
398 $sql .=
", subledger_account";
399 $sql .=
", subledger_label";
400 $sql .=
", numero_compte";
401 $sql .=
", label_compte";
402 $sql .=
", label_operation";
407 $sql .=
", fk_user_author";
408 $sql .=
", date_creation";
409 $sql .=
", code_journal";
410 $sql .=
", journal_label";
411 $sql .=
", piece_num";
413 $sql .=
") VALUES (";
414 $sql .=
"'".$this->db->idate($this->doc_date).
"'";
415 $sql .=
", ".(isDolTms($this->date_lim_reglement) ?
"'".$this->db->idate($this->date_lim_reglement).
"'" :
'NULL');
416 $sql .=
", '".$this->db->escape($this->doc_type).
"'";
417 $sql .=
", '".$this->db->escape($this->doc_ref).
"'";
418 $sql .=
", ".((int) $this->fk_doc);
419 $sql .=
", ".((int) $this->fk_docdet);
420 $sql .=
", ".(!empty($this->thirdparty_code) ? (
"'".$this->db->escape($this->thirdparty_code).
"'") :
"NULL");
421 $sql .=
", ".(!empty($this->subledger_account) ? (
"'".$this->db->escape($this->subledger_account).
"'") :
"NULL");
422 $sql .=
", ".(!empty($this->subledger_label) ? (
"'".$this->db->escape($this->subledger_label).
"'") :
"NULL");
423 $sql .=
", '".$this->db->escape($this->numero_compte).
"'";
424 $sql .=
", ".(!empty($this->label_compte) ? (
"'".$this->db->escape($this->label_compte).
"'") :
"NULL");
425 $sql .=
", '".$this->db->escape($this->label_operation).
"'";
426 $sql .=
", ".((float) $this->debit);
427 $sql .=
", ".((float) $this->credit);
428 $sql .=
", ".((float) $this->montant);
429 $sql .=
", ".(!empty($this->sens) ? (
"'".$this->db->escape($this->sens).
"'") :
"NULL");
430 $sql .=
", '".$this->db->escape($this->fk_user_author).
"'";
431 $sql .=
", '".$this->db->idate($now).
"'";
432 $sql .=
", '".$this->db->escape($this->code_journal).
"'";
433 $sql .=
", ".(!empty($this->journal_label) ? (
"'".$this->db->escape($this->journal_label).
"'") :
"NULL");
434 $sql .=
", ".((int) $this->piece_num);
435 $sql .=
", ".(!isset($this->entity) ?
$conf->entity : $this->entity);
438 $resql = $this->db->query($sql);
440 $id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
448 $this->errors[] =
'Error Create Error '.$result.
' lecture ID';
449 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
454 $this->errors[] =
'Error '.$this->db->lasterror();
455 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
460 $this->error =
'BookkeepingRecordAlreadyExists';
461 dol_syslog(__METHOD__.
' '.$this->error, LOG_WARNING);
466 $this->errors[] =
'Error '.$this->db->lasterror();
467 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
471 if (! $error && ! $notrigger) {
472 $result = $this->
call_trigger(
'BOOKKEEPING_CREATE', $user);
480 $this->db->rollback();
498 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
500 global $db,
$conf, $langs;
501 global $dolibarr_main_authentication, $dolibarr_main_demo;
502 global $menumanager, $hookmanager;
504 if (!empty(
$conf->dol_no_mouse_hover)) {
511 $label =
'<u>'.$langs->trans(
"Transaction").
'</u>';
513 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->piece_num;
515 $url = DOL_URL_ROOT.
'/accountancy/bookkeeping/card.php?piece_num='.$this->piece_num;
517 if ($option !=
'nolink') {
519 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
520 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
521 $add_save_lastsearch_values = 1;
523 if ($add_save_lastsearch_values) {
524 $url .=
'&save_lastsearch_values=1';
529 if (empty($notooltip)) {
531 $label = $langs->trans(
"ShowTransaction");
532 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
534 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
535 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
537 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
540 $linkstart =
'<a href="'.$url.
'"';
541 $linkstart .= $linkclose.
'>';
544 $result .= $linkstart;
546 $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);
548 if ($withpicto != 2) {
549 $result .= $this->piece_num;
555 $hookmanager->initHooks(array($this->element .
'dao'));
556 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
557 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
559 $result = $hookmanager->resPrint;
561 $result .= $hookmanager->resPrint;
576 global
$conf, $langs;
578 $langs->loadLangs(array(
"accountancy",
"bills",
"compta"));
585 if (isset($this->doc_type)) {
586 $this->doc_type = trim($this->doc_type);
588 if (isset($this->doc_ref)) {
589 $this->doc_ref = trim($this->doc_ref);
591 if (isset($this->fk_doc)) {
592 $this->fk_doc = (int) $this->fk_doc;
594 if (isset($this->fk_docdet)) {
595 $this->fk_docdet = (int) $this->fk_docdet;
597 if (isset($this->thirdparty_code)) {
598 $this->thirdparty_code = trim($this->thirdparty_code);
600 if (isset($this->subledger_account)) {
601 $this->subledger_account = trim($this->subledger_account);
603 if (isset($this->subledger_label)) {
604 $this->subledger_label = trim($this->subledger_label);
606 if (isset($this->numero_compte)) {
607 $this->numero_compte = trim($this->numero_compte);
609 if (isset($this->label_compte)) {
610 $this->label_compte = trim($this->label_compte);
612 if (isset($this->label_operation)) {
613 $this->label_operation = trim($this->label_operation);
615 if (isset($this->sens)) {
616 $this->sens = trim($this->sens);
618 if (isset($this->import_key)) {
619 $this->import_key = trim($this->import_key);
621 if (isset($this->code_journal)) {
622 $this->code_journal = trim($this->code_journal);
624 if (isset($this->journal_label)) {
625 $this->journal_label = trim($this->journal_label);
627 if (isset($this->piece_num)) {
628 $this->piece_num = (int) $this->piece_num;
630 if (empty($this->debit)) {
633 if (empty($this->credit)) {
636 if (empty($this->montant)) {
643 } elseif ($result == 0) {
645 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
647 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
652 $this->debit = (float)
price2num($this->debit,
'MT');
653 $this->credit = (float)
price2num($this->credit,
'MT');
654 $this->montant = (float)
price2num($this->montant,
'MT');
659 $this->journal_label = $langs->trans($this->journal_label);
662 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.$mode.
' (';
664 $sql .=
'date_lim_reglement,';
668 $sql .=
'fk_docdet,';
669 $sql .=
'thirdparty_code,';
670 $sql .=
'subledger_account,';
671 $sql .=
'subledger_label,';
672 $sql .=
'numero_compte,';
673 $sql .=
'label_compte,';
674 $sql .=
'label_operation,';
679 $sql .=
'fk_user_author,';
680 $sql .=
'date_creation,';
681 $sql .=
'code_journal,';
682 $sql .=
'journal_label,';
683 $sql .=
'piece_num,';
685 $sql .=
') VALUES (';
686 $sql .=
' '.(isDolTms($this->doc_date) ?
"'".$this->db->idate($this->doc_date).
"'" :
'NULL').
',';
687 $sql .=
' '.(isDolTms($this->date_lim_reglement) ?
"'".$this->db->idate($this->date_lim_reglement).
"'" :
'NULL').
',';
688 $sql .=
' '.(!isset($this->doc_type) ?
'NULL' :
"'".$this->db->escape($this->doc_type).
"'").
',';
689 $sql .=
' '.(!isset($this->doc_ref) ?
'NULL' :
"'".$this->db->escape($this->doc_ref).
"'").
',';
690 $sql .=
' '.(empty($this->fk_doc) ?
'0' : (int) $this->fk_doc).
',';
691 $sql .=
' '.(empty($this->fk_docdet) ?
'0' : (int) $this->fk_docdet).
',';
692 $sql .=
' '.(!isset($this->thirdparty_code) ?
'NULL' :
"'".$this->db->escape($this->thirdparty_code).
"'").
',';
693 $sql .=
' '.(!isset($this->subledger_account) ?
'NULL' :
"'".$this->db->escape($this->subledger_account).
"'").
',';
694 $sql .=
' '.(!isset($this->subledger_label) ?
'NULL' :
"'".$this->db->escape($this->subledger_label).
"'").
',';
695 $sql .=
' '.(!isset($this->numero_compte) ?
'NULL' :
"'".$this->db->escape($this->numero_compte).
"'").
',';
696 $sql .=
' '.(!isset($this->label_compte) ?
'NULL' :
"'".$this->db->escape($this->label_compte).
"'").
',';
697 $sql .=
' '.(!isset($this->label_operation) ?
'NULL' :
"'".$this->db->escape($this->label_operation).
"'").
',';
698 $sql .=
' '.(!isset($this->debit) ?
'NULL' : $this->debit).
',';
699 $sql .=
' '.(!isset($this->credit) ?
'NULL' : $this->credit).
',';
700 $sql .=
' '.(!isset($this->montant) ?
'NULL' : $this->montant).
',';
701 $sql .=
' '.(!isset($this->sens) ?
'NULL' :
"'".$this->db->escape($this->sens).
"'").
',';
702 $sql .=
' '.((int) $user->id).
',';
703 $sql .=
' '.
"'".$this->db->idate($now).
"',";
704 $sql .=
' '.(empty($this->code_journal) ?
'NULL' :
"'".$this->db->escape($this->code_journal).
"'").
',';
705 $sql .=
' '.(empty($this->journal_label) ?
'NULL' :
"'".$this->db->escape($this->journal_label).
"'").
',';
706 $sql .=
' '.(empty($this->piece_num) ?
'NULL' : $this->db->escape($this->piece_num)).
',';
707 $sql .=
' '.(!isset($this->entity) ?
$conf->entity : $this->entity);
712 $resql = $this->db->query($sql);
715 $this->errors[] =
'Error '.$this->db->lasterror();
716 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
720 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element.$mode);
723 $result = $this->
call_trigger(
'BOOKKEEPING_CREATE', $user);
732 $this->db->rollback();
750 public function fetch($id, $ref =
null, $mode =
'')
758 $sql .=
" t.doc_date,";
759 $sql .=
" t.date_lim_reglement,";
760 $sql .=
" t.doc_type,";
761 $sql .=
" t.doc_ref,";
762 $sql .=
" t.fk_doc,";
763 $sql .=
" t.fk_docdet,";
764 $sql .=
" t.thirdparty_code,";
765 $sql .=
" t.subledger_account,";
766 $sql .=
" t.subledger_label,";
767 $sql .=
" t.numero_compte,";
768 $sql .=
" t.label_compte,";
769 $sql .=
" t.label_operation,";
771 $sql .=
" t.credit,";
772 $sql .=
" t.montant as amount,";
774 $sql .=
" t.fk_user_author,";
775 $sql .=
" t.import_key,";
776 $sql .=
" t.code_journal,";
777 $sql .=
" t.journal_label,";
778 $sql .=
" t.piece_num,";
779 $sql .=
" t.date_creation,";
781 if ($mode !=
"_tmp") {
782 $sql .=
" t.date_export,";
784 $sql .=
" t.date_validated as date_validation";
785 $sql .=
' FROM '.$this->db->prefix().$this->table_element.$mode.
' as t';
786 $sql .=
' WHERE 1 = 1';
787 $sql .=
" AND entity = " . ((int)
$conf->entity);
789 $sql .=
" AND t.rowid = ".((int) $ref);
791 $sql .=
" AND t.rowid = ".((int) $id);
794 $resql = $this->db->query($sql);
796 $numrows = $this->db->num_rows($resql);
798 $obj = $this->db->fetch_object($resql);
800 $this->
id = $obj->rowid;
802 $this->doc_date = $this->db->jdate($obj->doc_date);
803 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
804 $this->doc_type = $obj->doc_type;
805 $this->doc_ref = $obj->doc_ref;
806 $this->fk_doc = $obj->fk_doc;
807 $this->fk_docdet = $obj->fk_docdet;
808 $this->thirdparty_code = $obj->thirdparty_code;
809 $this->subledger_account = $obj->subledger_account;
810 $this->subledger_label = $obj->subledger_label;
811 $this->numero_compte = $obj->numero_compte;
812 $this->label_compte = $obj->label_compte;
813 $this->label_operation = $obj->label_operation;
814 $this->debit = $obj->debit;
815 $this->credit = $obj->credit;
816 $this->montant = $obj->amount;
817 $this->amount = $obj->amount;
818 $this->sens = $obj->sens;
819 $this->fk_user_author = $obj->fk_user_author;
820 $this->import_key = $obj->import_key;
821 $this->code_journal = $obj->code_journal;
822 $this->journal_label = $obj->journal_label;
823 $this->piece_num = $obj->piece_num;
824 $this->date_creation = $this->db->jdate($obj->date_creation);
825 $this->date_export = $this->db->jdate($obj->date_export);
826 $this->date_validation = isset($obj->date_validation) ? $this->db->jdate($obj->date_validation) :
'';
828 $this->db->free($resql);
836 $this->errors[] =
'Error '.$this->db->lasterror();
837 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
857 public function fetchAllByAccount($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND', $option = 0, $countonly = 0)
863 $this->lines = array();
868 $sql .=
' COUNT(t.rowid) as nb';
871 $sql .=
" t.doc_date,";
872 $sql .=
" t.doc_type,";
873 $sql .=
" t.doc_ref,";
874 $sql .=
" t.fk_doc,";
875 $sql .=
" t.fk_docdet,";
876 $sql .=
" t.thirdparty_code,";
877 $sql .=
" t.subledger_account,";
878 $sql .=
" t.subledger_label,";
879 $sql .=
" t.numero_compte,";
880 $sql .=
" t.label_compte,";
881 $sql .=
" t.label_operation,";
883 $sql .=
" t.credit,";
884 $sql .=
" t.montant as amount,";
886 $sql .=
" t.multicurrency_amount,";
887 $sql .=
" t.multicurrency_code,";
888 $sql .=
" t.lettering_code,";
889 $sql .=
" t.date_lettering,";
890 $sql .=
" t.fk_user_author,";
891 $sql .=
" t.import_key,";
892 $sql .=
" t.code_journal,";
893 $sql .=
" t.journal_label,";
894 $sql .=
" t.piece_num,";
895 $sql .=
" t.date_creation,";
896 $sql .=
" t.date_export,";
897 $sql .=
" t.date_validated as date_validation,";
898 $sql .=
" t.date_lim_reglement,";
899 $sql .=
" t.import_key";
903 if (count($filter) > 0) {
904 foreach ($filter as $key => $value) {
905 if ($key ==
't.doc_date>=') {
906 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate($value).
"'";
907 } elseif ($key ==
't.doc_date<=') {
908 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate($value).
"'";
909 } elseif ($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.numero_compte>=') {
914 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
915 } elseif ($key ==
't.numero_compte<=') {
916 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
917 } elseif ($key ==
't.subledger_account>=') {
918 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
919 } elseif ($key ==
't.subledger_account<=') {
920 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
921 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
922 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
923 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
924 $sqlwhere[] = $this->db->sanitize($key).
' LIKE \''.$this->db->escape($this->db->escapeforlike($value)).
'%\'';
925 } elseif ($key ==
't.date_creation>=') {
926 $sqlwhere[] =
't.date_creation >= \''.$this->db->idate($value).
'\'';
927 } elseif ($key ==
't.date_creation<=') {
928 $sqlwhere[] =
't.date_creation <= \''.$this->db->idate($value).
'\'';
929 } elseif ($key ==
't.date_export>=') {
930 $sqlwhere[] =
't.date_export >= \''.$this->db->idate($value).
'\'';
931 } elseif ($key ==
't.date_export<=') {
932 $sqlwhere[] =
't.date_export <= \''.$this->db->idate($value).
'\'';
933 } elseif ($key ==
't.date_validated>=') {
934 $sqlwhere[] =
't.date_validated >= \''.$this->db->idate($value).
'\'';
935 } elseif ($key ==
't.date_validated<=') {
936 $sqlwhere[] =
't.date_validated <= \''.$this->db->idate($value).
'\'';
937 } elseif ($key ==
't.date_lim_reglement>=') {
938 $sqlwhere[] =
't.date_lim_reglement>=\''.$this->db->idate($value).
'\'';
939 } elseif ($key ==
't.date_lim_reglement<=') {
940 $sqlwhere[] =
't.date_lim_reglement<=\''.$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 '.$this->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);
1026 $line->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1027 $line->import_key = $obj->import_key;
1029 $this->lines[] = $line;
1034 $this->db->free($resql);
1038 $this->errors[] =
'Error '.$this->db->lasterror();
1039 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1057 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $showAlreadyExportMovements = 1)
1064 $sql .=
' t.rowid,';
1065 $sql .=
" t.doc_date,";
1066 $sql .=
" t.doc_type,";
1067 $sql .=
" t.doc_ref,";
1068 $sql .=
" t.fk_doc,";
1069 $sql .=
" t.fk_docdet,";
1070 $sql .=
" t.thirdparty_code,";
1071 $sql .=
" t.subledger_account,";
1072 $sql .=
" t.subledger_label,";
1073 $sql .=
" t.numero_compte,";
1074 $sql .=
" t.label_compte,";
1075 $sql .=
" t.label_operation,";
1076 $sql .=
" t.debit,";
1077 $sql .=
" t.credit,";
1078 $sql .=
" t.lettering_code,";
1079 $sql .=
" t.date_lettering,";
1080 $sql .=
" t.montant as amount,";
1082 $sql .=
" t.fk_user_author,";
1083 $sql .=
" t.import_key,";
1084 $sql .=
" t.code_journal,";
1085 $sql .=
" t.journal_label,";
1086 $sql .=
" t.piece_num,";
1087 $sql .=
" t.date_creation,";
1088 $sql .=
" t.date_lim_reglement,";
1089 $sql .=
" t.tms as date_modification,";
1090 $sql .=
" t.date_export,";
1091 $sql .=
" t.date_validated as date_validation";
1092 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t';
1094 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
1095 if ($showAlreadyExportMovements == 0) {
1096 $sql .=
" AND t.date_export IS NULL";
1100 if (is_array($filter)) {
1101 dol_syslog(
"You are using a deprecated use of fetchAll. filter parameter mus be an USF string now.", LOG_WARNING);
1102 $sqlwhere = array();
1103 if (count($filter) > 0) {
1104 foreach ($filter as $key => $value) {
1105 if ($key ==
't.doc_date') {
1106 $sqlwhere[] = $this->db->sanitize($key).
' = \''.$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.doc_date<') {
1114 $sqlwhere[] =
"t.doc_date < '".$this->db->idate($value).
"'";
1115 } elseif ($key ==
't.numero_compte>=') {
1116 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1117 } elseif ($key ==
't.numero_compte<=') {
1118 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1119 } elseif ($key ==
't.subledger_account>=') {
1120 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1121 } elseif ($key ==
't.subledger_account<=') {
1122 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1123 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1124 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
1125 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1126 $sqlwhere[] = $this->db->sanitize($key).
' LIKE \''.$this->db->escape($value).
'%\'';
1127 } elseif ($key ==
't.date_creation>=') {
1128 $sqlwhere[] =
't.date_creation >= \''.$this->db->idate($value).
'\'';
1129 } elseif ($key ==
't.date_creation<=') {
1130 $sqlwhere[] =
't.date_creation <= \''.$this->db->idate($value).
'\'';
1131 } elseif ($key ==
't.tms>=') {
1132 $sqlwhere[] =
't.tms >= \''.$this->db->idate($value).
'\'';
1133 } elseif ($key ==
't.tms<=') {
1134 $sqlwhere[] =
't.tms <= \''.$this->db->idate($value).
'\'';
1135 } elseif ($key ==
't.date_export>=') {
1136 $sqlwhere[] =
't.date_export >= \''.$this->db->idate($value).
'\'';
1137 } elseif ($key ==
't.date_export<=') {
1138 $sqlwhere[] =
't.date_export <= \''.$this->db->idate($value).
'\'';
1139 } elseif ($key ==
't.date_validated>=') {
1140 $sqlwhere[] =
't.date_validated >= \''.$this->db->idate($value).
'\'';
1141 } elseif ($key ==
't.date_validated<=') {
1142 $sqlwhere[] =
't.date_validated <= \''.$this->db->idate($value).
'\'';
1143 } elseif ($key ==
't.credit' || $key ==
't.debit') {
1145 } elseif ($key ==
't.code_journal' && !empty($value)) {
1146 if (is_array($value)) {
1147 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1156 if (count($sqlwhere) > 0) {
1157 $sql .=
' AND '.implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1166 if ($errormessage) {
1167 $this->errors[] = $errormessage;
1168 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1172 if (!empty($sortfield)) {
1173 $sql .= $this->db->order($sortfield, $sortorder);
1175 if (!empty($limit)) {
1176 $sql .= $this->db->plimit($limit + 1, $offset);
1178 $this->lines = array();
1180 $resql = $this->db->query($sql);
1182 $num = $this->db->num_rows($resql);
1185 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1188 $line->id = $obj->rowid;
1190 $line->doc_date = $this->db->jdate($obj->doc_date);
1191 $line->doc_type = $obj->doc_type;
1192 $line->doc_ref = $obj->doc_ref;
1193 $line->fk_doc = $obj->fk_doc;
1194 $line->fk_docdet = $obj->fk_docdet;
1195 $line->thirdparty_code = $obj->thirdparty_code;
1196 $line->subledger_account = $obj->subledger_account;
1197 $line->subledger_label = $obj->subledger_label;
1198 $line->numero_compte = $obj->numero_compte;
1199 $line->label_compte = $obj->label_compte;
1200 $line->label_operation = $obj->label_operation;
1201 $line->debit = $obj->debit;
1202 $line->credit = $obj->credit;
1203 $line->montant = $obj->amount;
1204 $line->amount = $obj->amount;
1205 $line->sens = $obj->sens;
1206 $line->lettering_code = $obj->lettering_code;
1207 $line->date_lettering = $obj->date_lettering;
1208 $line->fk_user_author = $obj->fk_user_author;
1209 $line->import_key = $obj->import_key;
1210 $line->code_journal = $obj->code_journal;
1211 $line->journal_label = $obj->journal_label;
1212 $line->piece_num = $obj->piece_num;
1213 $line->date_creation = $this->db->jdate($obj->date_creation);
1214 $line->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1215 $line->date_modification = $this->db->jdate($obj->date_modification);
1216 $line->date_export = $this->db->jdate($obj->date_export);
1217 $line->date_validation = $this->db->jdate($obj->date_validation);
1219 $this->lines[] = $line;
1223 $this->db->free($resql);
1227 $this->errors[] =
'Error '.$this->db->lasterror();
1228 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1245 public function fetchAllBalance($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $option = 0)
1249 $this->lines = array();
1254 $sql .=
" t.numero_compte,";
1255 if (!empty($option)) {
1256 $sql .=
" t.subledger_account,";
1257 $sql .=
" t.subledger_label,";
1259 $sql .=
" SUM(t.debit) as debit,";
1260 $sql .=
" SUM(t.credit) as credit";
1261 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t';
1262 $sql .=
' WHERE entity = ' . ((int)
$conf->entity);
1265 if (is_array($filter)) {
1266 $sqlwhere = array();
1267 if (count($filter) > 0) {
1268 foreach ($filter as $key => $value) {
1269 if ($key ==
't.doc_date') {
1270 $sqlwhere[] = $this->db->sanitize($key).
" = '".$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.doc_date<') {
1278 $sqlwhere[] =
"t.doc_date < '".$this->db->idate($value).
"'";
1279 } elseif ($key ==
't.numero_compte>=') {
1280 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1281 } elseif ($key ==
't.numero_compte<=') {
1282 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1283 } elseif ($key ==
't.subledger_account>=') {
1284 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1285 } elseif ($key ==
't.subledger_account<=') {
1286 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1287 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1288 $sqlwhere[] = $this->db->sanitize($key).
" = ".((int) $value);
1289 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1290 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1291 } elseif ($key ==
't.subledger_label') {
1292 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1293 } elseif ($key ==
't.code_journal' && !empty($value)) {
1294 if (is_array($value)) {
1295 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1299 } elseif ($key ==
't.reconciled_option') {
1300 $sqlwhere[] =
't.lettering_code IS NULL';
1302 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
1306 if (count($sqlwhere) > 0) {
1307 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1316 if ($errormessage) {
1317 $this->errors[] = $errormessage;
1318 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1322 if (!empty($option)) {
1323 $sql .=
" AND t.subledger_account IS NOT NULL";
1324 $sql .=
" AND t.subledger_account <> ''";
1325 $sql .=
" GROUP BY t.numero_compte, t.subledger_account, t.subledger_label";
1326 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
1327 $sortorder =
'ASC'.($sortfield ?
','.$sortfield :
'');
1329 $sql .=
' GROUP BY t.numero_compte';
1330 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
1331 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1334 if (!empty($sortfield)) {
1335 $sql .= $this->db->order($sortfield, $sortorder);
1337 if (!empty($limit)) {
1338 $sql .= $this->db->plimit($limit + 1, $offset);
1342 $resql = $this->db->query($sql);
1345 $num = $this->db->num_rows($resql);
1348 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1351 $line->numero_compte = $obj->numero_compte;
1353 if (!empty($option)) {
1354 $line->subledger_account = $obj->subledger_account;
1355 $line->subledger_label = $obj->subledger_label;
1357 $line->debit = $obj->debit;
1358 $line->credit = $obj->credit;
1360 $this->lines[] = $line;
1364 $this->db->free($resql);
1368 $this->errors[] =
'Error '.$this->db->lasterror();
1369 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1391 if (isset($this->doc_type)) {
1392 $this->doc_type = trim($this->doc_type);
1394 if (isset($this->doc_ref)) {
1395 $this->doc_ref = trim($this->doc_ref);
1397 if (isset($this->fk_doc)) {
1398 $this->fk_doc = (int) $this->fk_doc;
1400 if (isset($this->fk_docdet)) {
1401 $this->fk_docdet = (int) $this->fk_docdet;
1403 if (isset($this->thirdparty_code)) {
1404 $this->thirdparty_code = trim($this->thirdparty_code);
1406 if (isset($this->subledger_account)) {
1407 $this->subledger_account = trim($this->subledger_account);
1409 if (isset($this->subledger_label)) {
1410 $this->subledger_label = trim($this->subledger_label);
1412 if (isset($this->numero_compte)) {
1413 $this->numero_compte = trim($this->numero_compte);
1415 if (isset($this->label_compte)) {
1416 $this->label_compte = trim($this->label_compte);
1418 if (isset($this->label_operation)) {
1419 $this->label_operation = trim($this->label_operation);
1421 if (isset($this->sens)) {
1422 $this->sens = trim($this->sens);
1424 if (isset($this->import_key)) {
1425 $this->import_key = trim($this->import_key);
1427 if (isset($this->code_journal)) {
1428 $this->code_journal = trim($this->code_journal);
1430 if (isset($this->journal_label)) {
1431 $this->journal_label = trim($this->journal_label);
1433 if (isset($this->piece_num)) {
1434 $this->piece_num = (int) $this->piece_num;
1440 } elseif ($result == 0) {
1442 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1444 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1449 $this->debit = (float)
price2num($this->debit,
'MT');
1450 $this->credit = (float)
price2num($this->credit,
'MT');
1451 $this->montant = (float)
price2num($this->montant,
'MT');
1457 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.$mode.
' SET';
1458 $sql .=
' doc_date = '.(isDolTms($this->doc_date) ?
"'".$this->db->idate($this->doc_date).
"'" :
'null').
',';
1459 $sql .=
' doc_type = '.(isset($this->doc_type) ?
"'".$this->db->escape($this->doc_type).
"'" :
"null").
',';
1460 $sql .=
' doc_ref = '.(isset($this->doc_ref) ?
"'".$this->db->escape($this->doc_ref).
"'" :
"null").
',';
1461 $sql .=
' fk_doc = '.(isset($this->fk_doc) ? $this->fk_doc :
"null").
',';
1462 $sql .=
' fk_docdet = '.(isset($this->fk_docdet) ? $this->fk_docdet :
"null").
',';
1463 $sql .=
' thirdparty_code = '.(isset($this->thirdparty_code) ?
"'".$this->db->escape($this->thirdparty_code).
"'" :
"null").
',';
1464 $sql .=
' subledger_account = '.(isset($this->subledger_account) ?
"'".$this->db->escape($this->subledger_account).
"'" :
"null").
',';
1465 $sql .=
' subledger_label = '.(isset($this->subledger_label) ?
"'".$this->db->escape($this->subledger_label).
"'" :
"null").
',';
1466 $sql .=
' numero_compte = '.(isset($this->numero_compte) ?
"'".$this->db->escape($this->numero_compte).
"'" :
"null").
',';
1467 $sql .=
' label_compte = '.(isset($this->label_compte) ?
"'".$this->db->escape($this->label_compte).
"'" :
"null").
',';
1468 $sql .=
' label_operation = '.(isset($this->label_operation) ?
"'".$this->db->escape($this->label_operation).
"'" :
"null").
',';
1469 $sql .=
' debit = '.(isset($this->debit) ? $this->debit :
"null").
',';
1470 $sql .=
' credit = '.(isset($this->credit) ? $this->credit :
"null").
',';
1471 $sql .=
' montant = '.(isset($this->montant) ? $this->montant :
"null").
',';
1472 $sql .=
' sens = '.(isset($this->sens) ?
"'".$this->db->escape($this->sens).
"'" :
"null").
',';
1473 $sql .=
' fk_user_author = '.(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
',';
1474 $sql .=
' import_key = '.(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
',';
1475 $sql .=
' code_journal = '.(isset($this->code_journal) ?
"'".$this->db->escape($this->code_journal).
"'" :
"null").
',';
1476 $sql .=
' journal_label = '.(isset($this->journal_label) ?
"'".$this->db->escape($this->journal_label).
"'" :
"null").
',';
1477 $sql .=
' piece_num = '.(isset($this->piece_num) ? $this->piece_num :
"null");
1478 $sql .=
' WHERE rowid='.((int) $this->
id);
1482 $resql = $this->db->query($sql);
1485 $this->errors[] =
'Error '.$this->db->lasterror();
1486 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1490 if (! $error && ! $notrigger) {
1491 $result = $this->
call_trigger(
'BOOKKEEPING_MODIFY', $user);
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 ".$this->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');
1583 if (! $error && ! $notrigger) {
1584 $result = $this->
call_trigger(
'BOOKKEEPING_DELETE', $user);
1591 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.$mode;
1592 $sql .=
' WHERE rowid='.((int) $this->
id);
1594 $resql = $this->db->query($sql);
1597 $this->errors[] =
'Error '.$this->db->lasterror();
1598 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1604 $this->db->rollback();
1608 $this->db->commit();
1626 if (!isset($sql_filter)) {
1632 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1633 $sql .=
" WHERE import_key = '".$this->db->escape($importkey).
"'";
1634 $sql .= $sql_filter;
1636 $resql = $this->db->query($sql);
1639 $this->errors[] =
"Error ".$this->db->lasterror();
1640 dol_syslog(get_class($this).
"::delete Error ".$this->db->lasterror(), LOG_ERR);
1641 $this->db->rollback();
1645 $this->db->commit();
1660 global
$conf, $langs;
1662 if (empty($delyear) && empty($journal)) {
1663 $this->error =
'ErrorOneFieldRequired';
1666 if (!empty($delmonth) && empty($delyear)) {
1667 $this->error =
'YearRequiredIfMonthDefined';
1672 if (!isset($sql_filter)) {
1680 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1681 $sql .=
" WHERE 1 = 1";
1683 if (!empty($journal)) {
1684 $sql .=
" AND code_journal = '".$this->db->escape($journal).
"'";
1686 $sql .=
" AND entity = " . ((int)
$conf->entity);
1688 $sql .=
" AND date_validated IS NULL";
1689 $sql .= $sql_filter;
1693 $resql = $this->db->query($sql);
1696 $this->errors[] =
"Error ".$this->db->lasterror();
1697 foreach ($this->errors as $errmsg) {
1698 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1699 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1701 $this->db->rollback();
1705 $this->db->commit();
1721 if (!isset($sql_filter)) {
1731 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1732 $sql .=
" WHERE piece_num = ".(int) $piecenum;
1733 $sql .=
" AND date_validated IS NULL";
1734 $sql .=
" AND entity = " . ((int)
$conf->entity);
1735 $sql .= $sql_filter;
1737 $resql = $this->db->query($sql);
1740 $this->errors[] =
"Error ".$this->db->lasterror();
1741 foreach ($this->errors as $errmsg) {
1742 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1743 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1745 $this->db->rollback();
1748 $nbprocessed = $this->db->affected_rows($resql);
1751 $this->db->commit();
1753 return $nbprocessed;
1781 $object->context[
'createfromclone'] =
'createfromclone';
1782 $result =
$object->create($user);
1787 $this->errors =
$object->errors;
1788 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1791 unset(
$object->context[
'createfromclone']);
1795 $this->db->commit();
1799 $this->db->rollback();
1818 $this->doc_date = $now;
1819 $this->doc_type =
'';
1820 $this->doc_ref =
'';
1822 $this->fk_docdet = 0;
1823 $this->thirdparty_code =
'CU001';
1824 $this->subledger_account =
'41100001';
1825 $this->subledger_label =
'My customer company';
1826 $this->numero_compte =
'411';
1827 $this->label_compte =
'Customer';
1828 $this->label_operation =
'Sales of pea';
1829 $this->debit = 99.9;
1830 $this->credit = 0.0;
1831 $this->amount = 0.0;
1833 $this->fk_user_author = $user->id;
1834 $this->import_key =
'20201027';
1835 $this->code_journal =
'VT';
1836 $this->journal_label =
'Journal de vente';
1837 $this->piece_num = 1234;
1838 $this->date_creation = $now;
1854 $sql =
"SELECT piece_num, doc_date, code_journal, journal_label, doc_ref, doc_type,";
1855 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation, date_lim_reglement, import_key";
1857 if ($mode !=
"_tmp") {
1858 $sql .=
", date_export";
1860 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1861 $sql .=
" WHERE piece_num = ".((int) $piecenum);
1862 $sql .=
" AND entity = " . ((int)
$conf->entity);
1865 $result = $this->db->query($sql);
1867 $obj = $this->db->fetch_object($result);
1869 $this->piece_num = $obj->piece_num;
1870 $this->code_journal = $obj->code_journal;
1871 $this->journal_label = $obj->journal_label;
1872 $this->doc_date = $this->db->jdate($obj->doc_date);
1873 $this->doc_ref = $obj->doc_ref;
1874 $this->doc_type = $obj->doc_type;
1875 $this->date_creation = $this->db->jdate($obj->date_creation);
1876 $this->date_modification = $this->db->jdate($obj->date_modification);
1877 if ($mode !=
"_tmp") {
1878 $this->date_export = $this->db->jdate($obj->date_export);
1880 $this->date_validation = $this->db->jdate($obj->date_validation);
1881 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1882 $this->import_key = $obj->import_key;
1884 $this->error =
"Error ".$this->db->lasterror();
1885 dol_syslog(__METHOD__.$this->error, LOG_ERR);
1902 $sql =
"SELECT MAX(piece_num)+1 as max FROM ".$this->db->prefix().$this->table_element.$mode;
1903 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
1905 dol_syslog(get_class($this).
"::getNextNumMvt", LOG_DEBUG);
1907 $result = $this->db->query($sql);
1910 $obj = $this->db->fetch_object($result);
1912 $result = $obj->max;
1914 if (empty($result)) {
1919 $this->error =
"Error ".$this->db->lasterror();
1920 dol_syslog(get_class($this).
"::getNextNumMvt ".$this->error, LOG_ERR);
1936 $sql =
"SELECT rowid, doc_date, doc_type,";
1937 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
1938 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
1939 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, journal_label, piece_num,";
1940 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation";
1942 if ($mode !=
"_tmp") {
1943 $sql .=
", date_export";
1945 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1946 $sql .=
" WHERE piece_num = ".((int) $piecenum);
1947 $sql .=
" AND entity = " . ((int)
$conf->entity);
1950 $result = $this->db->query($sql);
1952 while ($obj = $this->db->fetch_object($result)) {
1955 $line->id = $obj->rowid;
1957 $line->doc_date = $this->db->jdate($obj->doc_date);
1958 $line->doc_type = $obj->doc_type;
1959 $line->doc_ref = $obj->doc_ref;
1960 $line->fk_doc = $obj->fk_doc;
1961 $line->fk_docdet = $obj->fk_docdet;
1962 $line->thirdparty_code = $obj->thirdparty_code;
1963 $line->subledger_account = $obj->subledger_account;
1964 $line->subledger_label = $obj->subledger_label;
1965 $line->numero_compte = $obj->numero_compte;
1966 $line->label_compte = $obj->label_compte;
1967 $line->label_operation = $obj->label_operation;
1968 $line->debit = $obj->debit;
1969 $line->credit = $obj->credit;
1970 $line->montant = $obj->amount;
1971 $line->amount = $obj->amount;
1972 $line->sens = $obj->sens;
1973 $line->code_journal = $obj->code_journal;
1974 $line->journal_label = $obj->journal_label;
1975 $line->piece_num = $obj->piece_num;
1976 $line->date_creation = $obj->date_creation;
1977 $line->date_modification = $obj->date_modification;
1978 if ($mode !=
"_tmp") {
1979 $line->date_export = $obj->date_export;
1981 $line->date_validation = $obj->date_validation;
1983 $this->linesmvt[] = $line;
1986 $this->error =
"Error ".$this->db->lasterror();
1987 dol_syslog(__METHOD__.$this->error, LOG_ERR);
2006 $sql =
"SELECT rowid, doc_date, doc_type,";
2007 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
2008 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
2009 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, piece_num,";
2010 $sql .=
" date_validated as date_validation";
2011 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
2012 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2014 dol_syslog(get_class($this).
"::export_bookkeeping", LOG_DEBUG);
2016 $resql = $this->db->query($sql);
2019 $this->linesexport = array();
2021 $num = $this->db->num_rows($resql);
2022 while ($obj = $this->db->fetch_object($resql)) {
2025 $line->id = $obj->rowid;
2027 $line->doc_date = $this->db->jdate($obj->doc_date);
2028 $line->doc_type = $obj->doc_type;
2029 $line->doc_ref = $obj->doc_ref;
2030 $line->fk_doc = $obj->fk_doc;
2031 $line->fk_docdet = $obj->fk_docdet;
2032 $line->thirdparty_code = $obj->thirdparty_code;
2033 $line->subledger_account = $obj->subledger_account;
2034 $line->subledger_label = $obj->subledger_label;
2035 $line->numero_compte = $obj->numero_compte;
2036 $line->label_compte = $obj->label_compte;
2037 $line->label_operation = $obj->label_operation;
2038 $line->debit = $obj->debit;
2039 $line->credit = $obj->credit;
2040 $line->montant = $obj->amount;
2041 $line->amount = $obj->amount;
2042 $line->sens = $obj->sens;
2043 $line->code_journal = $obj->code_journal;
2044 $line->piece_num = $obj->piece_num;
2045 $line->date_validation = $obj->date_validation;
2047 $this->linesexport[] = $line;
2049 $this->db->free($resql);
2053 $this->error =
"Error ".$this->db->lasterror();
2054 dol_syslog(get_class($this).
"::export_bookkeeping ".$this->error, LOG_ERR);
2074 if (!isset($sql_filter)) {
2080 if ($direction == 0) {
2084 if ($next_piecenum < 0) {
2090 $sql =
'DELETE FROM '.$this->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";
2091 $resql = $this->db->query($sql);
2094 $this->errors[] =
'Error '.$this->db->lasterror();
2095 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2100 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
' (doc_date, doc_type,';
2101 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2102 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2103 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num, date_creation)';
2104 $sql .=
' SELECT doc_date, doc_type,';
2105 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2106 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2107 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.((int) $next_piecenum).
", '".$this->db->idate($now).
"'";
2108 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND numero_compte IS NOT NULL AND entity = ' .((int)
$conf->entity);
2109 $sql .= $sql_filter;
2110 $resql = $this->db->query($sql);
2113 $this->errors[] =
'Error '.$this->db->lasterror();
2114 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2119 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2120 $resql = $this->db->query($sql);
2123 $this->errors[] =
'Error '.$this->db->lasterror();
2124 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2127 } elseif ($direction == 1) {
2129 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2130 $resql = $this->db->query($sql);
2133 $this->errors[] =
'Error '.$this->db->lasterror();
2134 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2139 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
'_tmp (doc_date, doc_type,';
2140 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2141 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2142 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)';
2143 $sql .=
' SELECT doc_date, doc_type,';
2144 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2145 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2146 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num';
2147 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2148 $sql .= $sql_filter;
2149 $resql = $this->db->query($sql);
2152 $this->errors[] =
'Error '.$this->db->lasterror();
2153 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2158 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2159 $sql .= $sql_filter;
2160 $resql = $this->db->query($sql);
2163 $this->errors[] =
'Error '.$this->db->lasterror();
2164 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2169 $this->db->commit();
2172 $this->db->rollback();
2200 public function select_account($selectid, $htmlname =
'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase =
'')
2205 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
2209 $sql =
"SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version";
2210 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as ab";
2211 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as aa ON aa.account_number = ab.numero_compte";
2212 $sql .=
" AND aa.active = 1";
2213 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2214 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2215 $sql .=
" AND ab.entity = " . ((int)
$conf->entity);
2216 $sql .=
" ORDER BY account_number ASC";
2218 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2219 $resql = $this->db->query($sql);
2222 $this->error =
"Error ".$this->db->lasterror();
2223 dol_syslog(get_class($this).
"::select_account ".$this->error, LOG_ERR);
2232 while ($obj = $this->db->fetch_object($resql)) {
2235 $select_value_in = $obj->rowid;
2236 $select_value_out = $obj->rowid;
2238 if ($select_in == 1) {
2239 $select_value_in = $obj->account_number;
2241 if ($select_out == 1) {
2242 $select_value_out = $obj->account_number;
2247 if (($selectid !=
'') && $selectid == $select_value_in) {
2248 $selected = $select_value_out;
2251 $options[$select_value_out] = $label;
2254 $out .=
Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0,
'', 0, 0, 0,
'',
'maxwidth300');
2255 $this->db->free($resql);
2271 $sql =
"SELECT root.rowid, root.account_number, root.label as label,";
2272 $sql .=
" parent.rowid as parent_rowid, parent.account_number as parent_account_number, parent.label as parent_label";
2273 $sql .=
" FROM ".$this->db->prefix().
"accounting_account as aa";
2274 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2275 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2276 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as parent ON aa.account_parent = parent.rowid AND parent.active = 1";
2277 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as root ON parent.account_parent = root.rowid AND root.active = 1";
2278 $sql .=
" WHERE aa.account_number = '".$this->db->escape($account).
"'";
2279 $sql .=
" AND aa.entity = " . ((int)
$conf->entity);
2281 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2282 $resql = $this->db->query($sql);
2285 if ($this->db->num_rows($resql)) {
2286 $obj = $this->db->fetch_object($resql);
2289 $result = array(
'id' => $obj->rowid,
'account_number' => $obj->account_number,
'label' => $obj->label);
2292 $this->error =
"Error ".$this->db->lasterror();
2293 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2312 $sql =
"SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
2313 $sql .=
" FROM ".$this->db->prefix().
"accounting_account as aa ";
2314 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2315 $sql .=
" AND aa.account_number = '".$this->db->escape($account).
"'";
2316 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2317 $sql .=
" AND aa.active = 1";
2318 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
2319 $sql .=
" WHERE aa.entity = " . ((int)
$conf->entity);
2321 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2322 $resql = $this->db->query($sql);
2325 if ($this->db->num_rows($resql)) {
2326 $obj = $this->db->fetch_object($resql);
2328 if (empty($obj->category)) {
2331 return $obj->label.
' ('.$obj->category.
')';
2334 $this->error =
"Error ".$this->db->lasterror();
2335 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2351 $alias = trim($alias);
2352 $alias = !empty($alias) && strpos($alias,
'.') ===
false ? $alias .
"." : $alias;
2354 if (!isset(self::$can_modify_bookkeeping_sql_cached[$alias]) || $force) {
2360 $sql_list = array();
2361 if (!empty(
$conf->cache[
'active_fiscal_period_cached']) && is_array(
$conf->cache[
'active_fiscal_period_cached'])) {
2363 foreach (
$conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2364 $sql_list[$i] =
"(";
2365 $sql_list[$i] .=
"'".$this->db->idate($fiscal_period[
'date_start']) .
"' <= ".$this->db->sanitize($alias).
"doc_date";
2366 if (!empty($fiscal_period[
'date_end'])) {
2367 $sql_list[$i] .=
" AND ";
2368 $sql_list[$i] .= $this->db->sanitize($alias).
"doc_date <= '" . $this->db->idate($fiscal_period[
'date_end']).
"'";
2370 $sql_list[$i] .=
")";
2374 $sqlsanitized = implode(
' OR ', $sql_list);
2375 self::$can_modify_bookkeeping_sql_cached[$alias] = empty($sql_list) ?
"" :
" AND (".$sqlsanitized.
")";
2378 return self::$can_modify_bookkeeping_sql_cached[$alias];
2400 $result = $bookkeeping->fetch($id,
null, $mode);
2405 if (!empty(
$conf->cache[
'closed_fiscal_period_cached']) && is_array(
$conf->cache[
'closed_fiscal_period_cached'])) {
2406 foreach (
$conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2407 if ($fiscal_period[
'date_start'] <= $bookkeeping->doc_date && $bookkeeping->doc_date <= $fiscal_period[
'date_end']) {
2421 $result = $bookkeeping->fetch($id,
null, $mode);
2426 if (!empty(
$conf->cache[
'active_fiscal_period_cached']) && is_array(
$conf->cache[
'active_fiscal_period_cached'])) {
2427 foreach (
$conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2428 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'])) {
2450 $accountingLabelOperation =
'';
2453 $truncThirdpartyName = 16;
2455 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2456 if (!empty($reference)) {
2457 $accountingLabelOperation .=
' - '. $reference;
2459 if (!empty($labelaccount)) {
2460 $accountingLabelOperation .=
' - '. $labelaccount;
2463 $truncThirdpartyName = 32;
2465 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2466 if (!empty($reference)) {
2467 $accountingLabelOperation .=
' - '. $reference;
2470 $truncThirdpartyName = 64;
2472 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2474 dol_syslog(
'label'.$accountingLabelOperation, LOG_ERR);
2476 return $accountingLabelOperation;
2496 if (!empty(
$conf->cache[
'closed_fiscal_period_cached']) && is_array(
$conf->cache[
'closed_fiscal_period_cached'])) {
2497 foreach (
$conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2498 if ($fiscal_period[
'date_start'] <= $date && $date <= $fiscal_period[
'date_end']) {
2511 if (!empty(
$conf->cache[
'active_fiscal_period_cached']) && is_array(
$conf->cache[
'active_fiscal_period_cached'])) {
2512 foreach (
$conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2513 if (!empty($fiscal_period[
'date_start']) && $fiscal_period[
'date_start'] <= $date && (empty($fiscal_period[
'date_end']) || $date <= $fiscal_period[
'date_end'])) {
2534 if ($mode ==
'active') {
2535 if (!isset(
$conf->cache[
'active_fiscal_period_cached']) || $force) {
2536 $sql =
"SELECT date_start, date_end";
2537 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2538 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2539 $sql .=
" AND statut = 0";
2541 $resql = $this->db->query($sql);
2543 $this->errors[] = $this->db->lasterror();
2548 while ($obj = $this->db->fetch_object($resql)) {
2550 'date_start' => $this->db->jdate($obj->date_start),
2551 'date_end' => $this->db->jdate($obj->date_end),
2554 $conf->cache[
'active_fiscal_period_cached'] = $list;
2557 if ($mode ==
'closed') {
2558 if (!isset(
$conf->cache[
'closed_fiscal_period_cached']) || $force) {
2559 $sql =
"SELECT date_start, date_end";
2560 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2561 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2562 $sql .=
" AND statut = 1";
2564 $resql = $this->db->query($sql);
2566 $this->errors[] = $this->db->lasterror();
2571 while ($obj = $this->db->fetch_object($resql)) {
2573 'date_start' => $this->db->jdate($obj->date_start),
2574 'date_end' => $this->db->jdate($obj->date_end),
2577 $conf->cache[
'closed_fiscal_period_cached'] = $list;
2595 $sql =
"SELECT rowid, label, date_start, date_end, statut";
2596 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2597 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2598 if (!empty($filter)) {
2599 $sql .=
" AND (" . $this->db->sanitize($filter, 1, 1, 1) .
')';
2601 $sql .= $this->db->order(
'date_start',
'ASC');
2603 $resql = $this->db->query($sql);
2605 $this->errors[] = $this->db->lasterror();
2609 while ($obj = $this->db->fetch_object($resql)) {
2610 $list[$obj->rowid] = array(
2611 'id' => (
int) $obj->rowid,
2612 'label' => $obj->label,
2613 'date_start' => $this->db->jdate($obj->date_start),
2614 'date_end' => $this->db->jdate($obj->date_end),
2615 'status' => (
int) $obj->statut,
2637 $sql =
"SELECT YEAR(b.doc_date) as year";
2638 for ($i = 1; $i <= 12; $i++) {
2639 $sql .=
", SUM(".$this->db->ifsql(
"MONTH(b.doc_date) = ".((
int) $i),
"1",
"0") .
") AS month".((int) $i);
2641 $sql .=
", COUNT(b.rowid) as total";
2642 $sql .=
" FROM " . $this->db->prefix() . $this->table_element .
" as b";
2643 $sql .=
" WHERE b.doc_date >= '" . $this->db->idate($date_start) .
"'";
2644 $sql .=
" AND b.doc_date <= '" . $this->db->idate($date_end) .
"'";
2645 $sql .=
" AND b.entity IN (" .
getEntity(
'bookkeeping', 0) .
")";
2650 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
'accounting_fiscalyear as af WHERE b.doc_date >= af.date_start AND b.doc_date <= af.date_end AND af.entity = '.((int)
$conf->entity).
" AND af.statut = 1)";
2653 $sql .=
" AND date_validated IS NULL";
2656 $sql .=
" GROUP BY YEAR(b.doc_date)";
2657 $sql .= $this->db->order(
"year",
'ASC');
2660 $resql = $this->db->query($sql);
2662 $this->errors[] = $this->db->lasterror();
2666 while ($obj = $this->db->fetch_object($resql)) {
2667 $total += (int) $obj->total;
2669 'year' => (
int) $obj->year,
2671 'total' => (
int) $obj->total,
2673 for ($i = 1; $i <= 12; $i++) {
2674 $year_list[
'count'][$i] = (int) $obj->{
'month' . $i};
2677 $list[] = $year_list;
2680 $this->db->free($resql);
2702 $sql =
" UPDATE " . $this->db->prefix() . $this->table_element;
2703 $sql .=
" SET date_validated = '" . $this->db->idate($now) .
"'";
2704 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2705 $sql .=
" AND DATE(doc_date) >= '" . $this->db->idate($date_start) .
"'";
2706 $sql .=
" AND DATE(doc_date) <= '" . $this->db->idate($date_end) .
"'";
2707 $sql .=
" AND date_validated IS NULL";
2710 $resql = $this->db->query($sql);
2712 $this->errors[] = $this->db->lasterror();
2732 $income_statement_amount = 0;
2734 if (
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
2735 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
2737 $pcg_type_filter = array();
2738 foreach ($accounting_groups_used_for_income_statement as $item) {
2739 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
2743 $sql .=
" t.numero_compte,";
2744 $sql .=
" aa.pcg_type,";
2745 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as accounting_result";
2746 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
2747 $sql .=
' LEFT JOIN ' . $this->db->prefix() .
'accounting_account as aa ON aa.account_number = t.numero_compte';
2748 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
2749 $sql .=
" AND aa.entity = " . ((int)
$conf->entity);
2750 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM ' . $this->db->prefix() .
'accounting_system WHERE rowid = ' . ((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')) .
')';
2751 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
2752 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) .
"'";
2753 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
2754 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
2756 $resql = $this->db->query($sql);
2758 $this->errors[] =
'Error ' . $this->db->lasterror();
2759 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2761 while ($obj = $this->db->fetch_object($resql)) {
2762 $income_statement_amount += $obj->accounting_result;
2767 return (
string) $income_statement_amount;
2779 public function closeFiscalPeriod($fiscal_period_id, $new_fiscal_period_id, $separate_auxiliary_account =
false, $generate_bookkeeping_records =
true)
2781 global
$conf, $langs, $user;
2784 $fiscal_period_id = max(0, $fiscal_period_id);
2785 if (empty($fiscal_period_id)) {
2786 $langs->load(
'errors');
2787 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2791 $result = $fiscal_period->fetch($fiscal_period_id);
2793 $this->error = $fiscal_period->error;
2794 $this->errors = $fiscal_period->errors;
2796 } elseif (empty($fiscal_period->id)) {
2797 $langs->loadLangs(array(
'errors',
'compta'));
2798 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
2803 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
2804 if (empty($new_fiscal_period_id)) {
2805 $langs->load(
'errors');
2806 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2809 $new_fiscal_period =
new Fiscalyear($this->db);
2810 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
2812 $this->error = $new_fiscal_period->error;
2813 $this->errors = $new_fiscal_period->errors;
2815 } elseif (empty($new_fiscal_period->id)) {
2816 $langs->loadLangs(array(
'errors',
'compta'));
2817 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
2824 $fiscal_period->statut = Fiscalyear::STATUS_CLOSED;
2825 $fiscal_period->status = Fiscalyear::STATUS_CLOSED;
2826 $result = $fiscal_period->update($user);
2828 $this->error = $fiscal_period->error;
2829 $this->errors = $fiscal_period->errors;
2833 if (!$error && !empty($generate_bookkeeping_records)) {
2835 if (empty($journal_id)) {
2836 $langs->loadLangs(array(
'errors',
'accountancy'));
2837 $this->errors[] = $langs->trans(
'ErrorBadParameters') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
2844 $result = $journal->fetch($journal_id);
2846 $this->error = $journal->error;
2847 $this->errors = $journal->errors;
2849 } elseif ($result == 0) {
2850 $langs->loadLangs(array(
'errors',
'accountancy'));
2851 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
2858 if (!$error && is_object($journal)) {
2859 $accounting_groups_used_for_balance_sheet_account = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))),
'strlen');
2860 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
2862 $pcg_type_filter = array();
2863 $tmp = array_merge($accounting_groups_used_for_balance_sheet_account, $accounting_groups_used_for_income_statement);
2864 foreach ($tmp as $item) {
2865 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
2869 $sql .=
" t.numero_compte,";
2870 if ($separate_auxiliary_account) {
2871 $sql .=
" NULLIF(t.subledger_account, '') as subledger_account,";
2873 $sql .=
" aa.pcg_type,";
2874 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as opening_balance";
2875 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
2876 $sql .=
' LEFT JOIN ' . $this->db->prefix() .
'accounting_account as aa ON aa.account_number = t.numero_compte';
2877 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
2878 $sql .=
" AND aa.entity = ". ((int)
$conf->entity);
2879 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM '.$this->db->prefix().
'accounting_system WHERE rowid = '.((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')).
')';
2880 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
2881 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
2882 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
2883 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
2884 if ($separate_auxiliary_account) {
2885 $sql .=
" , NULLIF(t.subledger_account, '')";
2887 $sql .=
' HAVING (SUM(t.credit) - SUM(t.debit)) != 0 ';
2888 $sql .= $this->db->order(
"t.numero_compte",
"ASC");
2890 $resql = $this->db->query($sql);
2892 $this->errors[] =
'Error ' . $this->db->lasterror();
2893 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2898 $income_statement_amount = 0;
2899 while ($obj = $this->db->fetch_object($resql)) {
2900 if (in_array($obj->pcg_type, $accounting_groups_used_for_income_statement)) {
2901 $income_statement_amount += $obj->opening_balance;
2904 $mt = $obj->opening_balance;
2907 $bookkeeping->doc_date = $new_fiscal_period->date_start;
2909 $bookkeeping->date_lim_reglement =
'';
2910 $bookkeeping->doc_ref = $fiscal_period->label;
2912 $bookkeeping->date_creation = $now;
2913 $bookkeeping->doc_type =
'closure';
2914 $bookkeeping->fk_doc = $fiscal_period->id;
2915 $bookkeeping->fk_docdet = 0;
2916 $bookkeeping->thirdparty_code =
'';
2918 if ($separate_auxiliary_account) {
2919 $bookkeeping->subledger_account = $obj->subledger_account;
2921 $sql .=
" subledger_label";
2922 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
2923 $sql .=
" WHERE subledger_account = '" . $this->db->escape($obj->subledger_account) .
"'";
2924 $sql .=
" ORDER BY doc_date DESC";
2926 $result = $this->db->query($sql);
2928 $this->errors[] =
'Error: ' . $this->db->lasterror();
2929 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2932 $objtmp = $this->db->fetch_object($result);
2933 $bookkeeping->subledger_label = $objtmp->subledger_label;
2935 $bookkeeping->subledger_account =
null;
2936 $bookkeeping->subledger_label =
null;
2939 $bookkeeping->numero_compte = $obj->numero_compte;
2941 $accountingaccount->fetch(0, $obj->numero_compte);
2942 $bookkeeping->label_compte = $accountingaccount->label;
2944 $bookkeeping->label_operation = $new_fiscal_period->label;
2945 $bookkeeping->montant = $mt;
2946 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
2947 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
2948 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
2949 $bookkeeping->code_journal = $journal->code;
2950 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
2951 $bookkeeping->fk_user_author = $user->id;
2952 $bookkeeping->entity =
$conf->entity;
2954 $result = $bookkeeping->create($user);
2956 $this->setErrorsFromObject($bookkeeping);
2964 if (!$error && $income_statement_amount != 0) {
2965 $mt = $income_statement_amount;
2967 $accountingaccount->fetch(0,
getDolGlobalString($income_statement_amount < 0 ?
'ACCOUNTING_RESULT_LOSS' :
'ACCOUNTING_RESULT_PROFIT'),
true);
2970 $bookkeeping->doc_date = $new_fiscal_period->date_start;
2972 $bookkeeping->date_lim_reglement =
'';
2973 $bookkeeping->doc_ref = $fiscal_period->label;
2975 $bookkeeping->date_creation = $now;
2976 $bookkeeping->doc_type =
'closure';
2977 $bookkeeping->fk_doc = $fiscal_period->id;
2978 $bookkeeping->fk_docdet = 0;
2979 $bookkeeping->thirdparty_code =
'';
2981 if ($separate_auxiliary_account) {
2982 $bookkeeping->subledger_account = $obj->subledger_account;
2984 $sql .=
" subledger_label";
2985 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
2986 $sql .=
" WHERE subledger_account = '" . $this->db->escape($obj->subledger_account) .
"'";
2987 $sql .=
" ORDER BY doc_date DESC";
2989 $result = $this->db->query($sql);
2991 $this->errors[] =
'Error: ' . $this->db->lasterror();
2992 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2995 $objtmp = $this->db->fetch_object($result);
2996 $bookkeeping->subledger_label = $objtmp->subledger_label;
2998 $bookkeeping->subledger_account =
null;
2999 $bookkeeping->subledger_label =
null;
3002 $bookkeeping->numero_compte = $accountingaccount->account_number;
3003 $bookkeeping->label_compte = $accountingaccount->label;
3005 $bookkeeping->label_operation = $new_fiscal_period->label;
3006 $bookkeeping->montant = $mt;
3007 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
3008 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
3009 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
3010 $bookkeeping->code_journal = $journal->code;
3011 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
3012 $bookkeeping->fk_user_author = $user->id;
3013 $bookkeeping->entity =
$conf->entity;
3015 $result = $bookkeeping->create($user);
3017 $this->setErrorsFromObject($bookkeeping);
3021 $this->db->free($resql);
3027 $this->db->rollback();
3030 $this->db->commit();
3047 global
$conf, $langs, $user;
3050 $fiscal_period_id = max(0, $fiscal_period_id);
3051 if (empty($fiscal_period_id)) {
3052 $langs->load(
'errors');
3053 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3057 $result = $fiscal_period->fetch($fiscal_period_id);
3059 $this->error = $fiscal_period->error;
3060 $this->errors = $fiscal_period->errors;
3062 } elseif (empty($fiscal_period->id)) {
3063 $langs->loadLangs(array(
'errors',
'compta'));
3064 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
3069 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
3070 if (empty($new_fiscal_period_id)) {
3071 $langs->load(
'errors');
3072 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3075 $new_fiscal_period =
new Fiscalyear($this->db);
3076 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
3078 $this->error = $new_fiscal_period->error;
3079 $this->errors = $new_fiscal_period->errors;
3081 } elseif (empty($new_fiscal_period->id)) {
3082 $langs->loadLangs(array(
'errors',
'compta'));
3083 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
3088 $inventory_journal_id = max(0, $inventory_journal_id);
3089 if (empty($inventory_journal_id)) {
3090 $langs->load(
'errors');
3091 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3096 $result = $inventory_journal->fetch($inventory_journal_id);
3098 $this->error = $inventory_journal->error;
3099 $this->errors = $inventory_journal->errors;
3101 } elseif ($result == 0) {
3102 $langs->loadLangs(array(
'errors',
'accountancy'));
3103 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'InventoryJournal');
3110 $sql =
'SELECT t.rowid';
3111 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
3112 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
3113 $sql .=
" AND code_journal = '" . $this->db->escape($inventory_journal->code) .
"'";
3114 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) .
"'";
3115 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
3116 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
3117 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
3119 $resql = $this->db->query($sql);
3121 $this->errors[] =
'Error ' . $this->db->lasterror();
3122 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3127 while ($obj = $this->db->fetch_object($resql)) {
3129 $result = $bookkeeping->fetch($obj->rowid);
3131 $this->error = $inventory_journal->error;
3132 $this->errors = $inventory_journal->errors;
3135 } elseif ($result == 0) {
3136 $langs->loadLangs(array(
'errors',
'accountancy'));
3137 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'LineId') .
': ' . $obj->rowid;
3142 $bookkeeping->id = 0;
3143 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3144 $bookkeeping->doc_ref = $new_fiscal_period->label;
3145 $bookkeeping->date_creation = $now;
3146 $bookkeeping->doc_type =
'accounting_reversal';
3147 $bookkeeping->fk_doc = $new_fiscal_period->id;
3148 $bookkeeping->fk_docdet = 0;
3150 $bookkeeping->montant = -$bookkeeping->montant;
3151 $bookkeeping->sens = ($bookkeeping->montant >= 0) ?
'C' :
'D';
3152 $old_debit = $bookkeeping->debit;
3153 $bookkeeping->debit = $bookkeeping->credit;
3154 $bookkeeping->credit = $old_debit;
3156 $bookkeeping->fk_user_author = $user->id;
3157 $bookkeeping->entity =
$conf->entity;
3159 $result = $bookkeeping->create($user);
3161 $this->error = $bookkeeping->error;
3162 $this->errors = $bookkeeping->errors;
3167 $this->db->free($resql);
3171 $this->db->rollback();
3174 $this->db->commit();
3193 public $doc_date =
null;
3217 public $thirdparty_code;
3222 public $subledger_account;
3227 public $subledger_label;
3232 public $numero_compte;
3237 public $label_compte;
3242 public $label_operation;
3268 public $multicurrency_amount;
3273 public $multicurrency_code;
3283 public $lettering_code;
3288 public $date_lettering;
3293 public $fk_user_author;
3304 public $code_journal;
3309 public $journal_label;
3318 public $date_export;
3323 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)
accountingLabelForOperation($thirdpartyname, $reference, $labelaccount)
Generate label operation when operation is transferred into accounting.
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,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
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...
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.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...