29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/fiscalyear.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
43 public $element =
'accountingbookkeeping';
48 public $table_element =
'accounting_bookkeeping';
58 public $lines = array();
73 public $date_lim_reglement;
98 public $thirdparty_code;
103 public $subledger_account;
108 public $subledger_label;
113 public $numero_compte;
118 public $label_compte;
123 public $label_operation;
155 public $fk_user_author;
165 public $code_journal;
170 public $journal_label;
180 public $linesmvt = array();
185 public $linesexport = array();
190 public $date_validation;
200 public $picto =
'generic';
205 public static $can_modify_bookkeeping_sql_cached;
227 global $conf, $langs;
234 if (isset($this->doc_type)) {
235 $this->doc_type = trim($this->doc_type);
237 if (isset($this->doc_ref)) {
238 $this->doc_ref = trim($this->doc_ref);
240 if (isset($this->fk_doc)) {
241 $this->fk_doc = (int) $this->fk_doc;
243 if (isset($this->fk_docdet)) {
244 $this->fk_docdet = (int) $this->fk_docdet;
246 if (isset($this->thirdparty_code)) {
247 $this->thirdparty_code = trim($this->thirdparty_code);
249 if (isset($this->subledger_account)) {
250 $this->subledger_account = trim($this->subledger_account);
252 if (isset($this->subledger_label)) {
253 $this->subledger_label = trim($this->subledger_label);
255 if (isset($this->numero_compte)) {
256 $this->numero_compte = trim($this->numero_compte);
258 if (isset($this->label_compte)) {
259 $this->label_compte = trim($this->label_compte);
261 if (isset($this->label_operation)) {
262 $this->label_operation = trim($this->label_operation);
264 if (isset($this->debit)) {
265 $this->debit = (float) $this->debit;
267 if (isset($this->credit)) {
268 $this->credit = (float) $this->credit;
270 if (isset($this->montant)) {
271 $this->montant = (float) $this->montant;
273 if (isset($this->amount)) {
274 $this->amount = (float) $this->amount;
276 if (isset($this->sens)) {
277 $this->sens = trim($this->sens);
279 if (isset($this->import_key)) {
280 $this->import_key = trim($this->import_key);
282 if (isset($this->code_journal)) {
283 $this->code_journal = trim($this->code_journal);
285 if (isset($this->journal_label)) {
286 $this->journal_label = trim($this->journal_label);
288 if (isset($this->piece_num)) {
289 $this->piece_num = (int) $this->piece_num;
291 if (empty($this->debit)) {
294 if (empty($this->credit)) {
301 } elseif ($result == 0) {
303 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
305 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
311 if (($this->numero_compte ==
"") || $this->numero_compte ==
'-1' || $this->numero_compte ==
'NotDefined') {
312 $langs->loadLangs(array(
"errors"));
313 if (in_array($this->doc_type, array(
'bank',
'expense_report'))) {
314 $this->errors[] = $langs->trans(
'ErrorFieldAccountNotDefinedForBankLine', $this->fk_docdet, $this->doc_type);
317 $mesg = $this->doc_ref.
', '.$langs->trans(
"AccountAccounting").
': '.($this->numero_compte != -1 ? $this->numero_compte : $langs->trans(
"Unknown"));
318 if ($this->subledger_account && $this->subledger_account != $this->numero_compte) {
319 $mesg .=
', '.$langs->trans(
"SubledgerAccount").
': '.$this->subledger_account;
321 $this->errors[] = $langs->trans(
'ErrorFieldAccountNotDefinedForLine', $mesg);
329 $this->piece_num = 0;
336 $sql =
"SELECT count(*) as nb";
337 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
338 $sql .=
" WHERE doc_type = '".$this->db->escape($this->doc_type).
"'";
339 $sql .=
" AND fk_doc = ".((int) $this->fk_doc);
342 $sql .=
" AND fk_docdet = ".((int) $this->fk_docdet);
344 $sql .=
" AND numero_compte = '".$this->db->escape($this->numero_compte).
"'";
345 $sql .=
" AND label_operation = '".$this->db->escape($this->label_operation).
"'";
346 $sql .=
" AND entity = ".$conf->entity;
348 $resql = $this->db->query($sql);
351 $row = $this->db->fetch_object($resql);
354 $sqlnum =
"SELECT piece_num";
355 $sqlnum .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
356 $sqlnum .=
" WHERE doc_type = '".$this->db->escape($this->doc_type).
"'";
357 $sqlnum .=
" AND fk_doc = ".((int) $this->fk_doc);
360 $sqlnum .=
" AND fk_docdet = ".((int) $this->fk_docdet);
362 $sqlnum .=
" AND doc_ref = '".$this->db->escape($this->doc_ref).
"'";
363 $sqlnum .=
" AND entity = ".$conf->entity;
365 dol_syslog(get_class($this).
":: create sqlnum=".$sqlnum, LOG_DEBUG);
366 $resqlnum = $this->db->query($sqlnum);
368 $objnum = $this->db->fetch_object($resqlnum);
369 $this->piece_num = $objnum->piece_num;
372 dol_syslog(get_class($this).
"::create this->piece_num=".$this->piece_num, LOG_DEBUG);
373 if (empty($this->piece_num)) {
374 $sqlnum =
"SELECT MAX(piece_num)+1 as maxpiecenum";
375 $sqlnum .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
376 $sqlnum .=
" WHERE entity = " . ((int) $conf->entity);
378 $resqlnum = $this->db->query($sqlnum);
380 $objnum = $this->db->fetch_object($resqlnum);
381 $this->piece_num = $objnum->maxpiecenum;
383 dol_syslog(get_class($this).
":: create now this->piece_num=".$this->piece_num, LOG_DEBUG);
385 if (empty($this->piece_num)) {
386 $this->piece_num = 1;
391 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
" (";
393 $sql .=
", date_lim_reglement";
394 $sql .=
", doc_type";
397 $sql .=
", fk_docdet";
398 $sql .=
", thirdparty_code";
399 $sql .=
", subledger_account";
400 $sql .=
", subledger_label";
401 $sql .=
", numero_compte";
402 $sql .=
", label_compte";
403 $sql .=
", label_operation";
408 $sql .=
", fk_user_author";
409 $sql .=
", date_creation";
410 $sql .=
", code_journal";
411 $sql .=
", journal_label";
412 $sql .=
", piece_num";
414 $sql .=
") VALUES (";
415 $sql .=
"'".$this->db->idate($this->doc_date).
"'";
416 $sql .=
", ".(!isset($this->date_lim_reglement) ||
dol_strlen($this->date_lim_reglement) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_lim_reglement).
"'");
417 $sql .=
", '".$this->db->escape($this->doc_type).
"'";
418 $sql .=
", '".$this->db->escape($this->doc_ref).
"'";
419 $sql .=
", ".((int) $this->fk_doc);
420 $sql .=
", ".((int) $this->fk_docdet);
421 $sql .=
", ".(!empty($this->thirdparty_code) ? (
"'".$this->db->escape($this->thirdparty_code).
"'") :
"NULL");
422 $sql .=
", ".(!empty($this->subledger_account) ? (
"'".$this->db->escape($this->subledger_account).
"'") :
"NULL");
423 $sql .=
", ".(!empty($this->subledger_label) ? (
"'".$this->db->escape($this->subledger_label).
"'") :
"NULL");
424 $sql .=
", '".$this->db->escape($this->numero_compte).
"'";
425 $sql .=
", ".(!empty($this->label_compte) ? (
"'".$this->db->escape($this->label_compte).
"'") :
"NULL");
426 $sql .=
", '".$this->db->escape($this->label_operation).
"'";
427 $sql .=
", ".((float) $this->debit);
428 $sql .=
", ".((float) $this->credit);
429 $sql .=
", ".((float) $this->montant);
430 $sql .=
", ".(!empty($this->sens) ? (
"'".$this->db->escape($this->sens).
"'") :
"NULL");
431 $sql .=
", '".$this->db->escape($this->fk_user_author).
"'";
432 $sql .=
", '".$this->db->idate($now).
"'";
433 $sql .=
", '".$this->db->escape($this->code_journal).
"'";
434 $sql .=
", ".(!empty($this->journal_label) ? (
"'".$this->db->escape($this->journal_label).
"'") :
"NULL");
435 $sql .=
", ".((int) $this->piece_num);
436 $sql .=
", ".(!isset($this->entity) ? $conf->entity : $this->entity);
439 $resql = $this->db->query($sql);
441 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
449 $this->errors[] =
'Error Create Error '.$result.
' lecture ID';
450 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
455 $this->errors[] =
'Error '.$this->db->lasterror();
456 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
461 $this->error =
'BookkeepingRecordAlreadyExists';
462 dol_syslog(__METHOD__.
' '.$this->error, LOG_WARNING);
467 $this->errors[] =
'Error '.$this->db->lasterror();
468 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
483 $this->db->rollback();
501 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
503 global $db, $conf, $langs;
504 global $dolibarr_main_authentication, $dolibarr_main_demo;
505 global $menumanager, $hookmanager;
507 if (!empty($conf->dol_no_mouse_hover)) {
514 $label =
'<u>'.$langs->trans(
"Transaction").
'</u>';
516 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->piece_num;
518 $url = DOL_URL_ROOT.
'/accountancy/bookkeeping/card.php?piece_num='.$this->piece_num;
520 if ($option !=
'nolink') {
522 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
523 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
524 $add_save_lastsearch_values = 1;
526 if ($add_save_lastsearch_values) {
527 $url .=
'&save_lastsearch_values=1';
532 if (empty($notooltip)) {
534 $label = $langs->trans(
"ShowTransaction");
535 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
537 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
538 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
540 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
543 $linkstart =
'<a href="'.$url.
'"';
544 $linkstart .= $linkclose.
'>';
547 $result .= $linkstart;
549 $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);
551 if ($withpicto != 2) {
552 $result .= $this->piece_num;
558 $hookmanager->initHooks(array($this->element .
'dao'));
559 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
560 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
562 $result = $hookmanager->resPrint;
564 $result .= $hookmanager->resPrint;
579 global $conf, $langs;
581 $langs->loadLangs(array(
"accountancy",
"bills",
"compta"));
588 if (isset($this->doc_type)) {
589 $this->doc_type = trim($this->doc_type);
591 if (isset($this->doc_ref)) {
592 $this->doc_ref = trim($this->doc_ref);
594 if (isset($this->fk_doc)) {
595 $this->fk_doc = (int) $this->fk_doc;
597 if (isset($this->fk_docdet)) {
598 $this->fk_docdet = (int) $this->fk_docdet;
600 if (isset($this->thirdparty_code)) {
601 $this->thirdparty_code = trim($this->thirdparty_code);
603 if (isset($this->subledger_account)) {
604 $this->subledger_account = trim($this->subledger_account);
606 if (isset($this->subledger_label)) {
607 $this->subledger_label = trim($this->subledger_label);
609 if (isset($this->numero_compte)) {
610 $this->numero_compte = trim($this->numero_compte);
612 if (isset($this->label_compte)) {
613 $this->label_compte = trim($this->label_compte);
615 if (isset($this->label_operation)) {
616 $this->label_operation = trim($this->label_operation);
618 if (isset($this->sens)) {
619 $this->sens = trim($this->sens);
621 if (isset($this->import_key)) {
622 $this->import_key = trim($this->import_key);
624 if (isset($this->code_journal)) {
625 $this->code_journal = trim($this->code_journal);
627 if (isset($this->journal_label)) {
628 $this->journal_label = trim($this->journal_label);
630 if (isset($this->piece_num)) {
631 $this->piece_num = (int) $this->piece_num;
633 if (empty($this->debit)) {
636 if (empty($this->credit)) {
639 if (empty($this->montant)) {
646 } elseif ($result == 0) {
648 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
650 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
655 $this->debit = (float)
price2num($this->debit,
'MT');
656 $this->credit = (float)
price2num($this->credit,
'MT');
657 $this->montant = (float)
price2num($this->montant,
'MT');
662 $this->journal_label = $langs->trans($this->journal_label);
665 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.$mode.
' (';
667 $sql .=
'date_lim_reglement,';
671 $sql .=
'fk_docdet,';
672 $sql .=
'thirdparty_code,';
673 $sql .=
'subledger_account,';
674 $sql .=
'subledger_label,';
675 $sql .=
'numero_compte,';
676 $sql .=
'label_compte,';
677 $sql .=
'label_operation,';
682 $sql .=
'fk_user_author,';
683 $sql .=
'date_creation,';
684 $sql .=
'code_journal,';
685 $sql .=
'journal_label,';
686 $sql .=
'piece_num,';
688 $sql .=
') VALUES (';
689 $sql .=
' '.(!isset($this->doc_date) ||
dol_strlen($this->doc_date) == 0 ?
'NULL' :
"'".$this->db->idate($this->doc_date).
"'").
',';
690 $sql .=
' '.(!isset($this->date_lim_reglement) ||
dol_strlen($this->date_lim_reglement) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_lim_reglement).
"'").
',';
691 $sql .=
' '.(!isset($this->doc_type) ?
'NULL' :
"'".$this->db->escape($this->doc_type).
"'").
',';
692 $sql .=
' '.(!isset($this->doc_ref) ?
'NULL' :
"'".$this->db->escape($this->doc_ref).
"'").
',';
693 $sql .=
' '.(empty($this->fk_doc) ?
'0' : (int) $this->fk_doc).
',';
694 $sql .=
' '.(empty($this->fk_docdet) ?
'0' : (int) $this->fk_docdet).
',';
695 $sql .=
' '.(!isset($this->thirdparty_code) ?
'NULL' :
"'".$this->db->escape($this->thirdparty_code).
"'").
',';
696 $sql .=
' '.(!isset($this->subledger_account) ?
'NULL' :
"'".$this->db->escape($this->subledger_account).
"'").
',';
697 $sql .=
' '.(!isset($this->subledger_label) ?
'NULL' :
"'".$this->db->escape($this->subledger_label).
"'").
',';
698 $sql .=
' '.(!isset($this->numero_compte) ?
'NULL' :
"'".$this->db->escape($this->numero_compte).
"'").
',';
699 $sql .=
' '.(!isset($this->label_compte) ?
'NULL' :
"'".$this->db->escape($this->label_compte).
"'").
',';
700 $sql .=
' '.(!isset($this->label_operation) ?
'NULL' :
"'".$this->db->escape($this->label_operation).
"'").
',';
701 $sql .=
' '.(!isset($this->debit) ?
'NULL' : $this->debit).
',';
702 $sql .=
' '.(!isset($this->credit) ?
'NULL' : $this->credit).
',';
703 $sql .=
' '.(!isset($this->montant) ?
'NULL' : $this->montant).
',';
704 $sql .=
' '.(!isset($this->sens) ?
'NULL' :
"'".$this->db->escape($this->sens).
"'").
',';
705 $sql .=
' '.((int) $user->id).
',';
706 $sql .=
' '.
"'".$this->db->idate($now).
"',";
707 $sql .=
' '.(empty($this->code_journal) ?
'NULL' :
"'".$this->db->escape($this->code_journal).
"'").
',';
708 $sql .=
' '.(empty($this->journal_label) ?
'NULL' :
"'".$this->db->escape($this->journal_label).
"'").
',';
709 $sql .=
' '.(empty($this->piece_num) ?
'NULL' : $this->db->escape($this->piece_num)).
',';
710 $sql .=
' '.(!isset($this->entity) ? $conf->entity : $this->entity);
715 $resql = $this->db->query($sql);
718 $this->errors[] =
'Error '.$this->db->lasterror();
719 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
723 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element.$mode);
728 $this->db->rollback();
746 public function fetch($id, $ref =
null, $mode =
'')
754 $sql .=
" t.doc_date,";
755 $sql .=
" t.date_lim_reglement,";
756 $sql .=
" t.doc_type,";
757 $sql .=
" t.doc_ref,";
758 $sql .=
" t.fk_doc,";
759 $sql .=
" t.fk_docdet,";
760 $sql .=
" t.thirdparty_code,";
761 $sql .=
" t.subledger_account,";
762 $sql .=
" t.subledger_label,";
763 $sql .=
" t.numero_compte,";
764 $sql .=
" t.label_compte,";
765 $sql .=
" t.label_operation,";
767 $sql .=
" t.credit,";
768 $sql .=
" t.montant as amount,";
770 $sql .=
" t.fk_user_author,";
771 $sql .=
" t.import_key,";
772 $sql .=
" t.code_journal,";
773 $sql .=
" t.journal_label,";
774 $sql .=
" t.piece_num,";
775 $sql .=
" t.date_creation,";
777 if ($mode !=
"_tmp") {
778 $sql .=
" t.date_export,";
780 $sql .=
" t.date_validated as date_validation";
781 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.$mode.
' as t';
782 $sql .=
' WHERE 1 = 1';
783 $sql .=
" AND entity = " . ((int) $conf->entity);
785 $sql .=
" AND t.rowid = ".((int) $ref);
787 $sql .=
" AND t.rowid = ".((int) $id);
790 $resql = $this->db->query($sql);
792 $numrows = $this->db->num_rows($resql);
794 $obj = $this->db->fetch_object($resql);
796 $this->
id = $obj->rowid;
798 $this->doc_date = $this->db->jdate($obj->doc_date);
799 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
800 $this->doc_type = $obj->doc_type;
801 $this->doc_ref = $obj->doc_ref;
802 $this->fk_doc = $obj->fk_doc;
803 $this->fk_docdet = $obj->fk_docdet;
804 $this->thirdparty_code = $obj->thirdparty_code;
805 $this->subledger_account = $obj->subledger_account;
806 $this->subledger_label = $obj->subledger_label;
807 $this->numero_compte = $obj->numero_compte;
808 $this->label_compte = $obj->label_compte;
809 $this->label_operation = $obj->label_operation;
810 $this->debit = $obj->debit;
811 $this->credit = $obj->credit;
812 $this->montant = $obj->amount;
813 $this->amount = $obj->amount;
814 $this->sens = $obj->sens;
815 $this->fk_user_author = $obj->fk_user_author;
816 $this->import_key = $obj->import_key;
817 $this->code_journal = $obj->code_journal;
818 $this->journal_label = $obj->journal_label;
819 $this->piece_num = $obj->piece_num;
820 $this->date_creation = $this->db->jdate($obj->date_creation);
821 $this->date_export = $this->db->jdate($obj->date_export);
822 $this->date_validation = isset($obj->date_validation) ? $this->db->jdate($obj->date_validation) :
'';
824 $this->db->free($resql);
832 $this->errors[] =
'Error '.$this->db->lasterror();
833 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
853 public function fetchAllByAccount($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND', $option = 0, $countonly = 0)
859 $this->lines = array();
864 $sql .=
' COUNT(t.rowid) as nb';
867 $sql .=
" t.doc_date,";
868 $sql .=
" t.doc_type,";
869 $sql .=
" t.doc_ref,";
870 $sql .=
" t.fk_doc,";
871 $sql .=
" t.fk_docdet,";
872 $sql .=
" t.thirdparty_code,";
873 $sql .=
" t.subledger_account,";
874 $sql .=
" t.subledger_label,";
875 $sql .=
" t.numero_compte,";
876 $sql .=
" t.label_compte,";
877 $sql .=
" t.label_operation,";
879 $sql .=
" t.credit,";
880 $sql .=
" t.montant as amount,";
882 $sql .=
" t.multicurrency_amount,";
883 $sql .=
" t.multicurrency_code,";
884 $sql .=
" t.lettering_code,";
885 $sql .=
" t.date_lettering,";
886 $sql .=
" t.fk_user_author,";
887 $sql .=
" t.import_key,";
888 $sql .=
" t.code_journal,";
889 $sql .=
" t.journal_label,";
890 $sql .=
" t.piece_num,";
891 $sql .=
" t.date_creation,";
892 $sql .=
" t.date_export,";
893 $sql .=
" t.date_validated as date_validation,";
894 $sql .=
" t.import_key";
898 if (count($filter) > 0) {
899 foreach ($filter as $key => $value) {
900 if ($key ==
't.doc_date>=') {
901 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate($value).
"'";
902 } elseif ($key ==
't.doc_date<=') {
903 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate($value).
"'";
904 } elseif ($key ==
't.doc_date>') {
905 $sqlwhere[] =
"t.doc_date > '".$this->db->idate($value).
"'";
906 } elseif ($key ==
't.doc_date<') {
907 $sqlwhere[] =
"t.doc_date < '".$this->db->idate($value).
"'";
908 } elseif ($key ==
't.numero_compte>=') {
909 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
910 } elseif ($key ==
't.numero_compte<=') {
911 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
912 } elseif ($key ==
't.subledger_account>=') {
913 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
914 } elseif ($key ==
't.subledger_account<=') {
915 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
916 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
917 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
918 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
919 $sqlwhere[] = $this->db->sanitize($key).
' LIKE \''.$this->db->escape($this->db->escapeforlike($value)).
'%\'';
920 } elseif ($key ==
't.date_creation>=') {
921 $sqlwhere[] =
't.date_creation >= \''.$this->db->idate($value).
'\'';
922 } elseif ($key ==
't.date_creation<=') {
923 $sqlwhere[] =
't.date_creation <= \''.$this->db->idate($value).
'\'';
924 } elseif ($key ==
't.date_export>=') {
925 $sqlwhere[] =
't.date_export >= \''.$this->db->idate($value).
'\'';
926 } elseif ($key ==
't.date_export<=') {
927 $sqlwhere[] =
't.date_export <= \''.$this->db->idate($value).
'\'';
928 } elseif ($key ==
't.date_validated>=') {
929 $sqlwhere[] =
't.date_validated >= \''.$this->db->idate($value).
'\'';
930 } elseif ($key ==
't.date_validated<=') {
931 $sqlwhere[] =
't.date_validated <= \''.$this->db->idate($value).
'\'';
932 } elseif ($key ==
't.credit' || $key ==
't.debit') {
934 } elseif ($key ==
't.reconciled_option') {
935 $sqlwhere[] =
't.lettering_code IS NULL';
936 } elseif ($key ==
't.code_journal' && !empty($value)) {
937 if (is_array($value)) {
938 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
942 } elseif ($key ==
't.search_accounting_code_in' && !empty($value)) {
943 $sqlwhere[] =
't.numero_compte IN ('.$this->db->sanitize($value, 1).
')';
949 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
950 $sql .=
' WHERE entity = ' . ((int) $conf->entity);
951 if (count($sqlwhere) > 0) {
952 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
955 if (!empty($option)) {
956 $sql .=
" AND t.subledger_account IS NOT NULL";
957 $sql .=
" AND t.subledger_account <> ''";
958 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
959 $sortorder =
'ASC'.($sortfield ?
','.$sortfield :
'');
961 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
962 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
966 $sql .= $this->db->order($sortfield, $sortorder);
967 if (!empty($limit)) {
968 $sql .= $this->db->plimit($limit + 1, $offset);
972 $resql = $this->db->query($sql);
975 $obj = $this->db->fetch_object($resql);
980 $num = $this->db->num_rows($resql);
983 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
986 $line->id = $obj->rowid;
988 $line->doc_date = $this->db->jdate($obj->doc_date);
989 $line->doc_type = $obj->doc_type;
990 $line->doc_ref = $obj->doc_ref;
991 $line->fk_doc = $obj->fk_doc;
992 $line->fk_docdet = $obj->fk_docdet;
993 $line->thirdparty_code = $obj->thirdparty_code;
994 $line->subledger_account = $obj->subledger_account;
995 $line->subledger_label = $obj->subledger_label;
996 $line->numero_compte = $obj->numero_compte;
997 $line->label_compte = $obj->label_compte;
998 $line->label_operation = $obj->label_operation;
999 $line->debit = $obj->debit;
1000 $line->credit = $obj->credit;
1001 $line->montant = $obj->amount;
1002 $line->amount = $obj->amount;
1003 $line->sens = $obj->sens;
1004 $line->multicurrency_amount = $obj->multicurrency_amount;
1005 $line->multicurrency_code = $obj->multicurrency_code;
1006 $line->lettering_code = $obj->lettering_code;
1007 $line->date_lettering = $obj->date_lettering;
1008 $line->fk_user_author = $obj->fk_user_author;
1009 $line->import_key = $obj->import_key;
1010 $line->code_journal = $obj->code_journal;
1011 $line->journal_label = $obj->journal_label;
1012 $line->piece_num = $obj->piece_num;
1013 $line->date_creation = $this->db->jdate($obj->date_creation);
1014 $line->date_export = $this->db->jdate($obj->date_export);
1015 $line->date_validation = $this->db->jdate($obj->date_validation);
1016 $line->import_key = $obj->import_key;
1018 $this->lines[] = $line;
1023 $this->db->free($resql);
1027 $this->errors[] =
'Error '.$this->db->lasterror();
1028 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1046 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $showAlreadyExportMovements = 1)
1053 $sql .=
' t.rowid,';
1054 $sql .=
" t.doc_date,";
1055 $sql .=
" t.doc_type,";
1056 $sql .=
" t.doc_ref,";
1057 $sql .=
" t.fk_doc,";
1058 $sql .=
" t.fk_docdet,";
1059 $sql .=
" t.thirdparty_code,";
1060 $sql .=
" t.subledger_account,";
1061 $sql .=
" t.subledger_label,";
1062 $sql .=
" t.numero_compte,";
1063 $sql .=
" t.label_compte,";
1064 $sql .=
" t.label_operation,";
1065 $sql .=
" t.debit,";
1066 $sql .=
" t.credit,";
1067 $sql .=
" t.lettering_code,";
1068 $sql .=
" t.date_lettering,";
1069 $sql .=
" t.montant as amount,";
1071 $sql .=
" t.fk_user_author,";
1072 $sql .=
" t.import_key,";
1073 $sql .=
" t.code_journal,";
1074 $sql .=
" t.journal_label,";
1075 $sql .=
" t.piece_num,";
1076 $sql .=
" t.date_creation,";
1077 $sql .=
" t.date_lim_reglement,";
1078 $sql .=
" t.tms as date_modification,";
1079 $sql .=
" t.date_export,";
1080 $sql .=
" t.date_validated as date_validation";
1081 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1083 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
1084 if ($showAlreadyExportMovements == 0) {
1085 $sql .=
" AND t.date_export IS NULL";
1089 if (is_array($filter)) {
1090 dol_syslog(
"You are using a deprecated use of fetchAll. filter parameter mus be an USF string now.", LOG_WARNING);
1091 $sqlwhere = array();
1092 if (count($filter) > 0) {
1093 foreach ($filter as $key => $value) {
1094 if ($key ==
't.doc_date') {
1095 $sqlwhere[] = $this->db->sanitize($key).
' = \''.$this->db->idate($value).
'\'';
1096 } elseif ($key ==
't.doc_date>=') {
1097 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate($value).
"'";
1098 } elseif ($key ==
't.doc_date<=') {
1099 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate($value).
"'";
1100 } elseif ($key ==
't.doc_date>') {
1101 $sqlwhere[] =
"t.doc_date > '".$this->db->idate($value).
"'";
1102 } elseif ($key ==
't.doc_date<') {
1103 $sqlwhere[] =
"t.doc_date < '".$this->db->idate($value).
"'";
1104 } elseif ($key ==
't.numero_compte>=') {
1105 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1106 } elseif ($key ==
't.numero_compte<=') {
1107 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1108 } elseif ($key ==
't.subledger_account>=') {
1109 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1110 } elseif ($key ==
't.subledger_account<=') {
1111 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1112 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1113 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
1114 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1115 $sqlwhere[] = $this->db->sanitize($key).
' LIKE \''.$this->db->escape($value).
'%\'';
1116 } elseif ($key ==
't.date_creation>=') {
1117 $sqlwhere[] =
't.date_creation >= \''.$this->db->idate($value).
'\'';
1118 } elseif ($key ==
't.date_creation<=') {
1119 $sqlwhere[] =
't.date_creation <= \''.$this->db->idate($value).
'\'';
1120 } elseif ($key ==
't.tms>=') {
1121 $sqlwhere[] =
't.tms >= \''.$this->db->idate($value).
'\'';
1122 } elseif ($key ==
't.tms<=') {
1123 $sqlwhere[] =
't.tms <= \''.$this->db->idate($value).
'\'';
1124 } elseif ($key ==
't.date_export>=') {
1125 $sqlwhere[] =
't.date_export >= \''.$this->db->idate($value).
'\'';
1126 } elseif ($key ==
't.date_export<=') {
1127 $sqlwhere[] =
't.date_export <= \''.$this->db->idate($value).
'\'';
1128 } elseif ($key ==
't.date_validated>=') {
1129 $sqlwhere[] =
't.date_validated >= \''.$this->db->idate($value).
'\'';
1130 } elseif ($key ==
't.date_validated<=') {
1131 $sqlwhere[] =
't.date_validated <= \''.$this->db->idate($value).
'\'';
1132 } elseif ($key ==
't.credit' || $key ==
't.debit') {
1134 } elseif ($key ==
't.code_journal' && !empty($value)) {
1135 if (is_array($value)) {
1136 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1145 if (count($sqlwhere) > 0) {
1146 $sql .=
' AND '.implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1155 if ($errormessage) {
1156 $this->errors[] = $errormessage;
1157 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1161 if (!empty($sortfield)) {
1162 $sql .= $this->db->order($sortfield, $sortorder);
1164 if (!empty($limit)) {
1165 $sql .= $this->db->plimit($limit + 1, $offset);
1167 $this->lines = array();
1169 $resql = $this->db->query($sql);
1171 $num = $this->db->num_rows($resql);
1174 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1177 $line->id = $obj->rowid;
1179 $line->doc_date = $this->db->jdate($obj->doc_date);
1180 $line->doc_type = $obj->doc_type;
1181 $line->doc_ref = $obj->doc_ref;
1182 $line->fk_doc = $obj->fk_doc;
1183 $line->fk_docdet = $obj->fk_docdet;
1184 $line->thirdparty_code = $obj->thirdparty_code;
1185 $line->subledger_account = $obj->subledger_account;
1186 $line->subledger_label = $obj->subledger_label;
1187 $line->numero_compte = $obj->numero_compte;
1188 $line->label_compte = $obj->label_compte;
1189 $line->label_operation = $obj->label_operation;
1190 $line->debit = $obj->debit;
1191 $line->credit = $obj->credit;
1192 $line->montant = $obj->amount;
1193 $line->amount = $obj->amount;
1194 $line->sens = $obj->sens;
1195 $line->lettering_code = $obj->lettering_code;
1196 $line->date_lettering = $obj->date_lettering;
1197 $line->fk_user_author = $obj->fk_user_author;
1198 $line->import_key = $obj->import_key;
1199 $line->code_journal = $obj->code_journal;
1200 $line->journal_label = $obj->journal_label;
1201 $line->piece_num = $obj->piece_num;
1202 $line->date_creation = $this->db->jdate($obj->date_creation);
1203 $line->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1204 $line->date_modification = $this->db->jdate($obj->date_modification);
1205 $line->date_export = $this->db->jdate($obj->date_export);
1206 $line->date_validation = $this->db->jdate($obj->date_validation);
1208 $this->lines[] = $line;
1212 $this->db->free($resql);
1216 $this->errors[] =
'Error '.$this->db->lasterror();
1217 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1234 public function fetchAllBalance($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $option = 0)
1238 $this->lines = array();
1243 $sql .=
" t.numero_compte,";
1244 if (!empty($option)) {
1245 $sql .=
" t.subledger_account,";
1246 $sql .=
" t.subledger_label,";
1248 $sql .=
" SUM(t.debit) as debit,";
1249 $sql .=
" SUM(t.credit) as credit";
1250 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1251 $sql .=
' WHERE entity = ' . ((int) $conf->entity);
1254 if (is_array($filter)) {
1255 $sqlwhere = array();
1256 if (count($filter) > 0) {
1257 foreach ($filter as $key => $value) {
1258 if ($key ==
't.doc_date') {
1259 $sqlwhere[] = $this->db->sanitize($key).
" = '".$this->db->idate($value).
"'";
1260 } elseif ($key ==
't.doc_date>=') {
1261 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate($value).
"'";
1262 } elseif ($key ==
't.doc_date<=') {
1263 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate($value).
"'";
1264 } elseif ($key ==
't.doc_date>') {
1265 $sqlwhere[] =
"t.doc_date > '".$this->db->idate($value).
"'";
1266 } elseif ($key ==
't.doc_date<') {
1267 $sqlwhere[] =
"t.doc_date < '".$this->db->idate($value).
"'";
1268 } elseif ($key ==
't.numero_compte>=') {
1269 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1270 } elseif ($key ==
't.numero_compte<=') {
1271 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1272 } elseif ($key ==
't.subledger_account>=') {
1273 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1274 } elseif ($key ==
't.subledger_account<=') {
1275 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1276 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1277 $sqlwhere[] = $this->db->sanitize($key).
" = ".((int) $value);
1278 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1279 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1280 } elseif ($key ==
't.subledger_label') {
1281 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1282 } elseif ($key ==
't.code_journal' && !empty($value)) {
1283 if (is_array($value)) {
1284 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1288 } elseif ($key ==
't.reconciled_option') {
1289 $sqlwhere[] =
't.lettering_code IS NULL';
1291 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
1295 if (count($sqlwhere) > 0) {
1296 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1305 if ($errormessage) {
1306 $this->errors[] = $errormessage;
1307 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1311 if (!empty($option)) {
1312 $sql .=
" AND t.subledger_account IS NOT NULL";
1313 $sql .=
" AND t.subledger_account <> ''";
1314 $sql .=
" GROUP BY t.numero_compte, t.subledger_account, t.subledger_label";
1315 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
1316 $sortorder =
'ASC'.($sortfield ?
','.$sortfield :
'');
1318 $sql .=
' GROUP BY t.numero_compte';
1319 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
1320 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1323 if (!empty($sortfield)) {
1324 $sql .= $this->db->order($sortfield, $sortorder);
1326 if (!empty($limit)) {
1327 $sql .= $this->db->plimit($limit + 1, $offset);
1331 $resql = $this->db->query($sql);
1334 $num = $this->db->num_rows($resql);
1337 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1340 $line->numero_compte = $obj->numero_compte;
1342 if (!empty($option)) {
1343 $line->subledger_account = $obj->subledger_account;
1344 $line->subledger_label = $obj->subledger_label;
1346 $line->debit = $obj->debit;
1347 $line->credit = $obj->credit;
1349 $this->lines[] = $line;
1353 $this->db->free($resql);
1357 $this->errors[] =
'Error '.$this->db->lasterror();
1358 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1380 if (isset($this->doc_type)) {
1381 $this->doc_type = trim($this->doc_type);
1383 if (isset($this->doc_ref)) {
1384 $this->doc_ref = trim($this->doc_ref);
1386 if (isset($this->fk_doc)) {
1387 $this->fk_doc = (int) $this->fk_doc;
1389 if (isset($this->fk_docdet)) {
1390 $this->fk_docdet = (int) $this->fk_docdet;
1392 if (isset($this->thirdparty_code)) {
1393 $this->thirdparty_code = trim($this->thirdparty_code);
1395 if (isset($this->subledger_account)) {
1396 $this->subledger_account = trim($this->subledger_account);
1398 if (isset($this->subledger_label)) {
1399 $this->subledger_label = trim($this->subledger_label);
1401 if (isset($this->numero_compte)) {
1402 $this->numero_compte = trim($this->numero_compte);
1404 if (isset($this->label_compte)) {
1405 $this->label_compte = trim($this->label_compte);
1407 if (isset($this->label_operation)) {
1408 $this->label_operation = trim($this->label_operation);
1410 if (isset($this->sens)) {
1411 $this->sens = trim($this->sens);
1413 if (isset($this->import_key)) {
1414 $this->import_key = trim($this->import_key);
1416 if (isset($this->code_journal)) {
1417 $this->code_journal = trim($this->code_journal);
1419 if (isset($this->journal_label)) {
1420 $this->journal_label = trim($this->journal_label);
1422 if (isset($this->piece_num)) {
1423 $this->piece_num = (int) $this->piece_num;
1429 } elseif ($result == 0) {
1431 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1433 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1438 $this->debit = (float)
price2num($this->debit,
'MT');
1439 $this->credit = (float)
price2num($this->credit,
'MT');
1440 $this->montant = (float)
price2num($this->montant,
'MT');
1446 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.$mode.
' SET';
1447 $sql .=
' doc_date = '.(!isset($this->doc_date) ||
dol_strlen($this->doc_date) != 0 ?
"'".$this->db->idate($this->doc_date).
"'" :
'null').
',';
1448 $sql .=
' doc_type = '.(isset($this->doc_type) ?
"'".$this->db->escape($this->doc_type).
"'" :
"null").
',';
1449 $sql .=
' doc_ref = '.(isset($this->doc_ref) ?
"'".$this->db->escape($this->doc_ref).
"'" :
"null").
',';
1450 $sql .=
' fk_doc = '.(isset($this->fk_doc) ? $this->fk_doc :
"null").
',';
1451 $sql .=
' fk_docdet = '.(isset($this->fk_docdet) ? $this->fk_docdet :
"null").
',';
1452 $sql .=
' thirdparty_code = '.(isset($this->thirdparty_code) ?
"'".$this->db->escape($this->thirdparty_code).
"'" :
"null").
',';
1453 $sql .=
' subledger_account = '.(isset($this->subledger_account) ?
"'".$this->db->escape($this->subledger_account).
"'" :
"null").
',';
1454 $sql .=
' subledger_label = '.(isset($this->subledger_label) ?
"'".$this->db->escape($this->subledger_label).
"'" :
"null").
',';
1455 $sql .=
' numero_compte = '.(isset($this->numero_compte) ?
"'".$this->db->escape($this->numero_compte).
"'" :
"null").
',';
1456 $sql .=
' label_compte = '.(isset($this->label_compte) ?
"'".$this->db->escape($this->label_compte).
"'" :
"null").
',';
1457 $sql .=
' label_operation = '.(isset($this->label_operation) ?
"'".$this->db->escape($this->label_operation).
"'" :
"null").
',';
1458 $sql .=
' debit = '.(isset($this->debit) ? $this->debit :
"null").
',';
1459 $sql .=
' credit = '.(isset($this->credit) ? $this->credit :
"null").
',';
1460 $sql .=
' montant = '.(isset($this->montant) ? $this->montant :
"null").
',';
1461 $sql .=
' sens = '.(isset($this->sens) ?
"'".$this->db->escape($this->sens).
"'" :
"null").
',';
1462 $sql .=
' fk_user_author = '.(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
',';
1463 $sql .=
' import_key = '.(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
',';
1464 $sql .=
' code_journal = '.(isset($this->code_journal) ?
"'".$this->db->escape($this->code_journal).
"'" :
"null").
',';
1465 $sql .=
' journal_label = '.(isset($this->journal_label) ?
"'".$this->db->escape($this->journal_label).
"'" :
"null").
',';
1466 $sql .=
' piece_num = '.(isset($this->piece_num) ? $this->piece_num :
"null");
1467 $sql .=
' WHERE rowid='.((int) $this->
id);
1471 $resql = $this->db->query($sql);
1474 $this->errors[] =
'Error '.$this->db->lasterror();
1475 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1490 $this->db->rollback();
1494 $this->db->commit();
1509 public function updateByMvt($piece_num =
'', $field =
'', $value =
'', $mode =
'')
1514 if (!isset($sql_filter)) {
1520 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.$mode;
1521 $sql .=
" SET ".$this->db->sanitize($field).
" = ".(is_numeric($value) ? ((float) $value) :
"'".$this->db->escape($value).
"'");
1522 $sql .=
" WHERE piece_num = ".((int) $piece_num);
1523 $sql .= $sql_filter;
1525 $resql = $this->db->query($sql);
1529 $this->errors[] =
'Error '.$this->db->lasterror();
1530 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1533 $this->db->rollback();
1537 $this->db->commit();
1551 public function delete(
User $user, $notrigger = 0, $mode =
'')
1560 } elseif ($result == 0) {
1562 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1564 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1584 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.$mode;
1585 $sql .=
' WHERE rowid='.((int) $this->
id);
1587 $resql = $this->db->query($sql);
1590 $this->errors[] =
'Error '.$this->db->lasterror();
1591 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1597 $this->db->rollback();
1601 $this->db->commit();
1619 if (!isset($sql_filter)) {
1625 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1626 $sql .=
" WHERE import_key = '".$this->db->escape($importkey).
"'";
1627 $sql .= $sql_filter;
1629 $resql = $this->db->query($sql);
1632 $this->errors[] =
"Error ".$this->db->lasterror();
1633 dol_syslog(get_class($this).
"::delete Error ".$this->db->lasterror(), LOG_ERR);
1634 $this->db->rollback();
1638 $this->db->commit();
1653 global $conf, $langs;
1655 if (empty($delyear) && empty($journal)) {
1656 $this->error =
'ErrorOneFieldRequired';
1659 if (!empty($delmonth) && empty($delyear)) {
1660 $this->error =
'YearRequiredIfMonthDefined';
1665 if (!isset($sql_filter)) {
1673 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1674 $sql .=
" WHERE 1 = 1";
1676 if (!empty($journal)) {
1677 $sql .=
" AND code_journal = '".$this->db->escape($journal).
"'";
1679 $sql .=
" AND entity = " . ((int) $conf->entity);
1681 $sql .=
" AND date_validated IS NULL";
1682 $sql .= $sql_filter;
1686 $resql = $this->db->query($sql);
1689 $this->errors[] =
"Error ".$this->db->lasterror();
1690 foreach ($this->errors as $errmsg) {
1691 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1692 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1694 $this->db->rollback();
1698 $this->db->commit();
1714 if (!isset($sql_filter)) {
1722 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1723 $sql .=
" WHERE piece_num = ".(int) $piecenum;
1724 $sql .=
" AND date_validated IS NULL";
1725 $sql .=
" AND entity = " . ((int) $conf->entity);
1726 $sql .= $sql_filter;
1728 $resql = $this->db->query($sql);
1731 $this->errors[] =
"Error ".$this->db->lasterror();
1732 foreach ($this->errors as $errmsg) {
1733 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1734 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1736 $this->db->rollback();
1740 $this->db->commit();
1769 $object->context[
'createfromclone'] =
'createfromclone';
1770 $result =
$object->create($user);
1775 $this->errors =
$object->errors;
1776 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1779 unset(
$object->context[
'createfromclone']);
1783 $this->db->commit();
1787 $this->db->rollback();
1806 $this->doc_date = $now;
1807 $this->doc_type =
'';
1808 $this->doc_ref =
'';
1810 $this->fk_docdet = 0;
1811 $this->thirdparty_code =
'CU001';
1812 $this->subledger_account =
'41100001';
1813 $this->subledger_label =
'My customer company';
1814 $this->numero_compte =
'411';
1815 $this->label_compte =
'Customer';
1816 $this->label_operation =
'Sales of pea';
1817 $this->debit = 99.9;
1818 $this->credit = 0.0;
1819 $this->amount = 0.0;
1821 $this->fk_user_author = $user->id;
1822 $this->import_key =
'20201027';
1823 $this->code_journal =
'VT';
1824 $this->journal_label =
'Journal de vente';
1825 $this->piece_num = 1234;
1826 $this->date_creation = $now;
1842 $sql =
"SELECT piece_num, doc_date, code_journal, journal_label, doc_ref, doc_type,";
1843 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation, import_key";
1845 if ($mode !=
"_tmp") {
1846 $sql .=
", date_export";
1848 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1849 $sql .=
" WHERE piece_num = ".((int) $piecenum);
1850 $sql .=
" AND entity = " . ((int) $conf->entity);
1853 $result = $this->db->query($sql);
1855 $obj = $this->db->fetch_object($result);
1857 $this->piece_num = $obj->piece_num;
1858 $this->code_journal = $obj->code_journal;
1859 $this->journal_label = $obj->journal_label;
1860 $this->doc_date = $this->db->jdate($obj->doc_date);
1861 $this->doc_ref = $obj->doc_ref;
1862 $this->doc_type = $obj->doc_type;
1863 $this->date_creation = $this->db->jdate($obj->date_creation);
1864 $this->date_modification = $this->db->jdate($obj->date_modification);
1865 if ($mode !=
"_tmp") {
1866 $this->date_export = $this->db->jdate($obj->date_export);
1868 $this->date_validation = $this->db->jdate($obj->date_validation);
1869 $this->import_key = $obj->import_key;
1871 $this->error =
"Error ".$this->db->lasterror();
1872 dol_syslog(__METHOD__.$this->error, LOG_ERR);
1889 $sql =
"SELECT MAX(piece_num)+1 as max FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1890 $sql .=
" WHERE entity = " . ((int) $conf->entity);
1892 dol_syslog(get_class($this).
"::getNextNumMvt", LOG_DEBUG);
1894 $result = $this->db->query($sql);
1897 $obj = $this->db->fetch_object($result);
1899 $result = $obj->max;
1901 if (empty($result)) {
1906 $this->error =
"Error ".$this->db->lasterror();
1907 dol_syslog(get_class($this).
"::getNextNumMvt ".$this->error, LOG_ERR);
1923 $sql =
"SELECT rowid, doc_date, doc_type,";
1924 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
1925 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
1926 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, journal_label, piece_num,";
1927 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation";
1929 if ($mode !=
"_tmp") {
1930 $sql .=
", date_export";
1932 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1933 $sql .=
" WHERE piece_num = ".((int) $piecenum);
1934 $sql .=
" AND entity = " . ((int) $conf->entity);
1937 $result = $this->db->query($sql);
1939 while ($obj = $this->db->fetch_object($result)) {
1942 $line->id = $obj->rowid;
1944 $line->doc_date = $this->db->jdate($obj->doc_date);
1945 $line->doc_type = $obj->doc_type;
1946 $line->doc_ref = $obj->doc_ref;
1947 $line->fk_doc = $obj->fk_doc;
1948 $line->fk_docdet = $obj->fk_docdet;
1949 $line->thirdparty_code = $obj->thirdparty_code;
1950 $line->subledger_account = $obj->subledger_account;
1951 $line->subledger_label = $obj->subledger_label;
1952 $line->numero_compte = $obj->numero_compte;
1953 $line->label_compte = $obj->label_compte;
1954 $line->label_operation = $obj->label_operation;
1955 $line->debit = $obj->debit;
1956 $line->credit = $obj->credit;
1957 $line->montant = $obj->amount;
1958 $line->amount = $obj->amount;
1959 $line->sens = $obj->sens;
1960 $line->code_journal = $obj->code_journal;
1961 $line->journal_label = $obj->journal_label;
1962 $line->piece_num = $obj->piece_num;
1963 $line->date_creation = $obj->date_creation;
1964 $line->date_modification = $obj->date_modification;
1965 if ($mode !=
"_tmp") {
1966 $line->date_export = $obj->date_export;
1968 $line->date_validation = $obj->date_validation;
1970 $this->linesmvt[] = $line;
1973 $this->error =
"Error ".$this->db->lasterror();
1974 dol_syslog(__METHOD__.$this->error, LOG_ERR);
1993 $sql =
"SELECT rowid, doc_date, doc_type,";
1994 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
1995 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
1996 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, piece_num,";
1997 $sql .=
" date_validated as date_validation";
1998 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
1999 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2001 dol_syslog(get_class($this).
"::export_bookkeeping", LOG_DEBUG);
2003 $resql = $this->db->query($sql);
2006 $this->linesexport = array();
2008 $num = $this->db->num_rows($resql);
2009 while ($obj = $this->db->fetch_object($resql)) {
2012 $line->id = $obj->rowid;
2014 $line->doc_date = $this->db->jdate($obj->doc_date);
2015 $line->doc_type = $obj->doc_type;
2016 $line->doc_ref = $obj->doc_ref;
2017 $line->fk_doc = $obj->fk_doc;
2018 $line->fk_docdet = $obj->fk_docdet;
2019 $line->thirdparty_code = $obj->thirdparty_code;
2020 $line->subledger_account = $obj->subledger_account;
2021 $line->subledger_label = $obj->subledger_label;
2022 $line->numero_compte = $obj->numero_compte;
2023 $line->label_compte = $obj->label_compte;
2024 $line->label_operation = $obj->label_operation;
2025 $line->debit = $obj->debit;
2026 $line->credit = $obj->credit;
2027 $line->montant = $obj->amount;
2028 $line->amount = $obj->amount;
2029 $line->sens = $obj->sens;
2030 $line->code_journal = $obj->code_journal;
2031 $line->piece_num = $obj->piece_num;
2032 $line->date_validation = $obj->date_validation;
2034 $this->linesexport[] = $line;
2036 $this->db->free($resql);
2040 $this->error =
"Error ".$this->db->lasterror();
2041 dol_syslog(get_class($this).
"::export_bookkeeping ".$this->error, LOG_ERR);
2061 if (!isset($sql_filter)) {
2067 if ($direction == 0) {
2071 if ($next_piecenum < 0) {
2077 $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";
2078 $resql = $this->db->query($sql);
2081 $this->errors[] =
'Error '.$this->db->lasterror();
2082 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2087 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
' (doc_date, doc_type,';
2088 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2089 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2090 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num, date_creation)';
2091 $sql .=
' SELECT doc_date, doc_type,';
2092 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2093 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2094 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.((int) $next_piecenum).
", '".$this->db->idate($now).
"'";
2095 $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);
2096 $sql .= $sql_filter;
2097 $resql = $this->db->query($sql);
2100 $this->errors[] =
'Error '.$this->db->lasterror();
2101 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2106 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2107 $resql = $this->db->query($sql);
2110 $this->errors[] =
'Error '.$this->db->lasterror();
2111 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2114 } elseif ($direction == 1) {
2116 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2117 $resql = $this->db->query($sql);
2120 $this->errors[] =
'Error '.$this->db->lasterror();
2121 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2126 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'_tmp (doc_date, doc_type,';
2127 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2128 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2129 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)';
2130 $sql .=
' SELECT doc_date, doc_type,';
2131 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2132 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2133 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num';
2134 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2135 $sql .= $sql_filter;
2136 $resql = $this->db->query($sql);
2139 $this->errors[] =
'Error '.$this->db->lasterror();
2140 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2145 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2146 $sql .= $sql_filter;
2147 $resql = $this->db->query($sql);
2150 $this->errors[] =
'Error '.$this->db->lasterror();
2151 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2156 $this->db->commit();
2159 $this->db->rollback();
2187 public function select_account($selectid, $htmlname =
'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase =
'')
2192 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
2196 $sql =
"SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version";
2197 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab";
2198 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.account_number = ab.numero_compte";
2199 $sql .=
" AND aa.active = 1";
2200 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2201 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2202 $sql .=
" AND ab.entity = " . ((int) $conf->entity);
2203 $sql .=
" ORDER BY account_number ASC";
2205 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2206 $resql = $this->db->query($sql);
2209 $this->error =
"Error ".$this->db->lasterror();
2210 dol_syslog(get_class($this).
"::select_account ".$this->error, LOG_ERR);
2219 while ($obj = $this->db->fetch_object($resql)) {
2222 $select_value_in = $obj->rowid;
2223 $select_value_out = $obj->rowid;
2225 if ($select_in == 1) {
2226 $select_value_in = $obj->account_number;
2228 if ($select_out == 1) {
2229 $select_value_out = $obj->account_number;
2234 if (($selectid !=
'') && $selectid == $select_value_in) {
2235 $selected = $select_value_out;
2238 $options[$select_value_out] = $label;
2241 $out .=
Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0,
'', 0, 0, 0,
'',
'maxwidth300');
2242 $this->db->free($resql);
2258 $sql =
"SELECT root.rowid, root.account_number, root.label as label,";
2259 $sql .=
" parent.rowid as parent_rowid, parent.account_number as parent_account_number, parent.label as parent_label";
2260 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_account as aa";
2261 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2262 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2263 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as parent ON aa.account_parent = parent.rowid AND parent.active = 1";
2264 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as root ON parent.account_parent = root.rowid AND root.active = 1";
2265 $sql .=
" WHERE aa.account_number = '".$this->db->escape($account).
"'";
2266 $sql .=
" AND aa.entity = " . ((int) $conf->entity);
2268 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2269 $resql = $this->db->query($sql);
2272 if ($this->db->num_rows($resql)) {
2273 $obj = $this->db->fetch_object($resql);
2276 $result = array(
'id' => $obj->rowid,
'account_number' => $obj->account_number,
'label' => $obj->label);
2279 $this->error =
"Error ".$this->db->lasterror();
2280 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2299 $sql =
"SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
2300 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_account as aa ";
2301 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2302 $sql .=
" AND aa.account_number = '".$this->db->escape($account).
"'";
2303 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2304 $sql .=
" AND aa.active = 1";
2305 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
2306 $sql .=
" WHERE aa.entity = " . ((int) $conf->entity);
2308 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2309 $resql = $this->db->query($sql);
2312 if ($this->db->num_rows($resql)) {
2313 $obj = $this->db->fetch_object($resql);
2315 if (empty($obj->category)) {
2318 return $obj->label.
' ('.$obj->category.
')';
2321 $this->error =
"Error ".$this->db->lasterror();
2322 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2338 $alias = trim($alias);
2339 $alias = !empty($alias) && strpos($alias,
'.') < 0 ? $alias .
"." : $alias;
2341 if (!isset(self::$can_modify_bookkeeping_sql_cached[$alias]) || $force) {
2347 $sql_list = array();
2348 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2349 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2350 $sql_list[] =
"('" . $this->db->idate($fiscal_period[
'date_start']) .
"' <= ".$this->db->sanitize($alias).
"doc_date AND ".$this->db->sanitize($alias).
"doc_date <= '" . $this->db->idate($fiscal_period[
'date_end']) .
"')";
2353 $sqlsanitized = implode(
' OR ', $sql_list);
2354 self::$can_modify_bookkeeping_sql_cached[$alias] = !empty($sql_list) ?
" AND (".$sqlsanitized.
")" :
"";
2357 return self::$can_modify_bookkeeping_sql_cached[$alias];
2379 $result = $bookkeeping->fetch($id,
null, $mode);
2384 if (!empty($conf->cache[
'closed_fiscal_period_cached']) && is_array($conf->cache[
'closed_fiscal_period_cached'])) {
2385 foreach ($conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2386 if ($fiscal_period[
'date_start'] <= $bookkeeping->doc_date && $bookkeeping->doc_date <= $fiscal_period[
'date_end']) {
2400 $result = $bookkeeping->fetch($id,
null, $mode);
2405 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2406 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2407 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'])) {
2434 if (!empty($conf->cache[
'closed_fiscal_period_cached']) && is_array($conf->cache[
'closed_fiscal_period_cached'])) {
2435 foreach ($conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2436 if ($fiscal_period[
'date_start'] <= $date && $date <= $fiscal_period[
'date_end']) {
2449 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2450 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2451 if (!empty($fiscal_period[
'date_start']) && $fiscal_period[
'date_start'] <= $date && (empty($fiscal_period[
'date_end']) || $date <= $fiscal_period[
'date_end'])) {
2472 if ($mode ==
'active') {
2473 if (!isset($conf->cache[
'active_fiscal_period_cached']) || $force) {
2474 $sql =
"SELECT date_start, date_end";
2475 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2476 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2477 $sql .=
" AND statut = 0";
2479 $resql = $this->db->query($sql);
2481 $this->errors[] = $this->db->lasterror();
2486 while ($obj = $this->db->fetch_object($resql)) {
2488 'date_start' => $this->db->jdate($obj->date_start),
2489 'date_end' => $this->db->jdate($obj->date_end),
2492 $conf->cache[
'active_fiscal_period_cached'] = $list;
2495 if ($mode ==
'closed') {
2496 if (!isset($conf->cache[
'closed_fiscal_period_cached']) || $force) {
2497 $sql =
"SELECT date_start, date_end";
2498 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2499 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2500 $sql .=
" AND statut = 1";
2502 $resql = $this->db->query($sql);
2504 $this->errors[] = $this->db->lasterror();
2509 while ($obj = $this->db->fetch_object($resql)) {
2511 'date_start' => $this->db->jdate($obj->date_start),
2512 'date_end' => $this->db->jdate($obj->date_end),
2515 $conf->cache[
'closed_fiscal_period_cached'] = $list;
2533 $sql =
"SELECT rowid, label, date_start, date_end, statut";
2534 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2535 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2536 if (!empty($filter)) {
2537 $sql .=
" AND (" . $this->db->sanitize($filter, 1, 1, 1) .
')';
2539 $sql .= $this->db->order(
'date_start',
'ASC');
2541 $resql = $this->db->query($sql);
2543 $this->errors[] = $this->db->lasterror();
2547 while ($obj = $this->db->fetch_object($resql)) {
2548 $list[$obj->rowid] = array(
2549 'id' => (
int) $obj->rowid,
2550 'label' => $obj->label,
2551 'date_start' => $this->db->jdate($obj->date_start),
2552 'date_end' => $this->db->jdate($obj->date_end),
2553 'status' => (
int) $obj->statut,
2572 $sql =
"SELECT YEAR(b.doc_date) as year";
2573 for ($i = 1; $i <= 12; $i++) {
2574 $sql .=
", SUM(".$this->db->ifsql(
"MONTH(b.doc_date) = ".((
int) $i),
"1",
"0") .
") AS month".((int) $i);
2576 $sql .=
", COUNT(b.rowid) as total";
2577 $sql .=
" FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping as b";
2578 $sql .=
" WHERE b.doc_date >= '" . $this->db->idate($date_start) .
"'";
2579 $sql .=
" AND b.doc_date <= '" . $this->db->idate($date_end) .
"'";
2580 $sql .=
" AND b.entity IN (" .
getEntity(
'bookkeeping', 0) .
")";
2586 $sql .=
" AND b.doc_date BETWEEN 0 AND 0";
2589 $sql .=
" AND date_validated IS NULL";
2592 $sql .=
" GROUP BY YEAR(b.doc_date)";
2593 $sql .= $this->db->order(
"year",
'ASC');
2596 $resql = $this->db->query($sql);
2598 $this->errors[] = $this->db->lasterror();
2602 while ($obj = $this->db->fetch_object($resql)) {
2603 $total += (int) $obj->total;
2605 'year' => (
int) $obj->year,
2607 'total' => (
int) $obj->total,
2609 for ($i = 1; $i <= 12; $i++) {
2610 $year_list[
'count'][$i] = (int) $obj->{
'month' . $i};
2613 $list[] = $year_list;
2616 $this->db->free($resql);
2638 $sql =
" UPDATE " . MAIN_DB_PREFIX .
"accounting_bookkeeping";
2639 $sql .=
" SET date_validated = '" . $this->db->idate($now) .
"'";
2640 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2641 $sql .=
" AND DATE(doc_date) >= '" . $this->db->idate($date_start) .
"'";
2642 $sql .=
" AND DATE(doc_date) <= '" . $this->db->idate($date_end) .
"'";
2643 $sql .=
" AND date_validated IS NULL";
2646 $resql = $this->db->query($sql);
2648 $this->errors[] = $this->db->lasterror();
2668 $income_statement_amount = 0;
2670 if (
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
2671 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
2673 $pcg_type_filter = array();
2674 foreach ($accounting_groups_used_for_income_statement as $item) {
2675 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
2679 $sql .=
" t.numero_compte,";
2680 $sql .=
" aa.pcg_type,";
2681 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as accounting_result";
2682 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
2683 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'accounting_account as aa ON aa.account_number = t.numero_compte';
2684 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
2685 $sql .=
" AND aa.entity = " . ((int) $conf->entity);
2686 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX .
'accounting_system WHERE rowid = ' . ((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')) .
')';
2687 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
2688 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) .
"'";
2689 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
2690 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
2692 $resql = $this->db->query($sql);
2694 $this->errors[] =
'Error ' . $this->db->lasterror();
2695 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2697 while ($obj = $this->db->fetch_object($resql)) {
2698 $income_statement_amount += $obj->accounting_result;
2703 return (
string) $income_statement_amount;
2715 public function closeFiscalPeriod($fiscal_period_id, $new_fiscal_period_id, $separate_auxiliary_account =
false, $generate_bookkeeping_records =
true)
2717 global $conf, $langs, $user;
2720 $fiscal_period_id = max(0, $fiscal_period_id);
2721 if (empty($fiscal_period_id)) {
2722 $langs->load(
'errors');
2723 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2727 $result = $fiscal_period->fetch($fiscal_period_id);
2729 $this->error = $fiscal_period->error;
2730 $this->errors = $fiscal_period->errors;
2732 } elseif (empty($fiscal_period->id)) {
2733 $langs->loadLangs(array(
'errors',
'compta'));
2734 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
2739 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
2740 if (empty($new_fiscal_period_id)) {
2741 $langs->load(
'errors');
2742 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2745 $new_fiscal_period =
new Fiscalyear($this->db);
2746 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
2748 $this->error = $new_fiscal_period->error;
2749 $this->errors = $new_fiscal_period->errors;
2751 } elseif (empty($new_fiscal_period->id)) {
2752 $langs->loadLangs(array(
'errors',
'compta'));
2753 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
2760 $fiscal_period->statut = Fiscalyear::STATUS_CLOSED;
2761 $fiscal_period->status = Fiscalyear::STATUS_CLOSED;
2762 $result = $fiscal_period->update($user);
2764 $this->error = $fiscal_period->error;
2765 $this->errors = $fiscal_period->errors;
2769 if (!$error && !empty($generate_bookkeeping_records)) {
2771 if (empty($journal_id)) {
2772 $langs->loadLangs(array(
'errors',
'accountancy'));
2773 $this->errors[] = $langs->trans(
'ErrorBadParameters') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
2780 $result = $journal->fetch($journal_id);
2782 $this->error = $journal->error;
2783 $this->errors = $journal->errors;
2785 } elseif ($result == 0) {
2786 $langs->loadLangs(array(
'errors',
'accountancy'));
2787 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
2793 $accounting_groups_used_for_balance_sheet_account = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))),
'strlen');
2794 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
2796 $pcg_type_filter = array();
2797 $tmp = array_merge($accounting_groups_used_for_balance_sheet_account, $accounting_groups_used_for_income_statement);
2798 foreach ($tmp as $item) {
2799 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
2803 $sql .=
" t.numero_compte,";
2804 $sql .=
" t.label_compte,";
2805 if ($separate_auxiliary_account) {
2806 $sql .=
" t.subledger_account,";
2807 $sql .=
" t.subledger_label,";
2809 $sql .=
" aa.pcg_type,";
2810 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as opening_balance";
2811 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
2812 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'accounting_account as aa ON aa.account_number = t.numero_compte';
2813 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
2814 $sql .=
" AND aa.entity = ". ((int) $conf->entity);
2815 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM '.MAIN_DB_PREFIX.
'accounting_system WHERE rowid = '.((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')).
')';
2816 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
2817 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
2818 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
2819 $sql .=
' GROUP BY t.numero_compte, t.label_compte, aa.pcg_type';
2820 if ($separate_auxiliary_account) {
2821 $sql .=
' ,t.subledger_account, t.subledger_label';
2823 $sql .= $this->db->order(
"t.numero_compte",
"ASC");
2825 $resql = $this->db->query($sql);
2827 $this->errors[] =
'Error ' . $this->db->lasterror();
2828 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2833 $income_statement_amount = 0;
2834 while ($obj = $this->db->fetch_object($resql)) {
2835 if (in_array($obj->pcg_type, $accounting_groups_used_for_income_statement)) {
2836 $income_statement_amount += $obj->opening_balance;
2839 $mt = $obj->opening_balance;
2842 $bookkeeping->doc_date = $new_fiscal_period->date_start;
2843 $bookkeeping->date_lim_reglement = 0;
2844 $bookkeeping->doc_ref = $new_fiscal_period->label;
2845 $bookkeeping->date_creation = $now;
2846 $bookkeeping->doc_type =
'closure';
2847 $bookkeeping->fk_doc = $new_fiscal_period->id;
2848 $bookkeeping->fk_docdet = 0;
2849 $bookkeeping->thirdparty_code =
'';
2851 if ($separate_auxiliary_account) {
2852 $bookkeeping->subledger_account = $obj->subledger_account;
2853 $bookkeeping->subledger_label = $obj->subledger_label;
2855 $bookkeeping->subledger_account =
'';
2856 $bookkeeping->subledger_label =
'';
2859 $bookkeeping->numero_compte = $obj->numero_compte;
2860 $bookkeeping->label_compte = $obj->label_compte;
2862 $bookkeeping->label_operation = $new_fiscal_period->label;
2863 $bookkeeping->montant = $mt;
2864 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
2865 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
2866 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
2867 $bookkeeping->code_journal = $journal->code;
2868 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
2869 $bookkeeping->fk_user_author = $user->id;
2870 $bookkeeping->entity = $conf->entity;
2872 $result = $bookkeeping->create($user);
2874 $this->error = $bookkeeping->error;
2875 $this->errors = $bookkeeping->errors;
2883 if (!$error && $income_statement_amount != 0) {
2884 $mt = $income_statement_amount;
2886 $accountingaccount->fetch(
null,
getDolGlobalString($income_statement_amount < 0 ?
'ACCOUNTING_RESULT_LOSS' :
'ACCOUNTING_RESULT_PROFIT'),
true);
2889 $bookkeeping->doc_date = $new_fiscal_period->date_start;
2890 $bookkeeping->date_lim_reglement = 0;
2891 $bookkeeping->doc_ref = $new_fiscal_period->label;
2892 $bookkeeping->date_creation = $now;
2893 $bookkeeping->doc_type =
'closure';
2894 $bookkeeping->fk_doc = $new_fiscal_period->id;
2895 $bookkeeping->fk_docdet = 0;
2896 $bookkeeping->thirdparty_code =
'';
2898 if ($separate_auxiliary_account) {
2899 $bookkeeping->subledger_label =
'';
2900 $bookkeeping->subledger_account = $obj->subledger_account;
2901 $bookkeeping->subledger_label = $obj->subledger_label;
2903 $bookkeeping->subledger_account =
'';
2904 $bookkeeping->subledger_label =
'';
2907 $bookkeeping->numero_compte = $accountingaccount->account_number;
2908 $bookkeeping->label_compte = $accountingaccount->label;
2910 $bookkeeping->label_operation = $new_fiscal_period->label;
2911 $bookkeeping->montant = $mt;
2912 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
2913 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
2914 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
2915 $bookkeeping->code_journal = $journal->code;
2916 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
2917 $bookkeeping->fk_user_author = $user->id;
2918 $bookkeeping->entity = $conf->entity;
2920 $result = $bookkeeping->create($user);
2922 $this->error = $bookkeeping->error;
2923 $this->errors = $bookkeeping->errors;
2927 $this->db->free($resql);
2933 $this->db->rollback();
2936 $this->db->commit();
2953 global $conf, $langs, $user;
2956 $fiscal_period_id = max(0, $fiscal_period_id);
2957 if (empty($fiscal_period_id)) {
2958 $langs->load(
'errors');
2959 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2963 $result = $fiscal_period->fetch($fiscal_period_id);
2965 $this->error = $fiscal_period->error;
2966 $this->errors = $fiscal_period->errors;
2968 } elseif (empty($fiscal_period->id)) {
2969 $langs->loadLangs(array(
'errors',
'compta'));
2970 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
2975 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
2976 if (empty($new_fiscal_period_id)) {
2977 $langs->load(
'errors');
2978 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2981 $new_fiscal_period =
new Fiscalyear($this->db);
2982 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
2984 $this->error = $new_fiscal_period->error;
2985 $this->errors = $new_fiscal_period->errors;
2987 } elseif (empty($new_fiscal_period->id)) {
2988 $langs->loadLangs(array(
'errors',
'compta'));
2989 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
2994 $inventory_journal_id = max(0, $inventory_journal_id);
2995 if (empty($inventory_journal_id)) {
2996 $langs->load(
'errors');
2997 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3002 $result = $inventory_journal->fetch($inventory_journal_id);
3004 $this->error = $inventory_journal->error;
3005 $this->errors = $inventory_journal->errors;
3007 } elseif ($result == 0) {
3008 $langs->loadLangs(array(
'errors',
'accountancy'));
3009 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'InventoryJournal');
3016 $sql =
'SELECT t.rowid';
3017 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
3018 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
3019 $sql .=
" AND code_journal = '" . $this->db->escape($inventory_journal->code) .
"'";
3020 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) .
"'";
3021 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
3022 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
3023 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
3025 $resql = $this->db->query($sql);
3027 $this->errors[] =
'Error ' . $this->db->lasterror();
3028 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3033 while ($obj = $this->db->fetch_object($resql)) {
3035 $result = $bookkeeping->fetch($obj->rowid);
3037 $this->error = $inventory_journal->error;
3038 $this->errors = $inventory_journal->errors;
3041 } elseif ($result == 0) {
3042 $langs->loadLangs(array(
'errors',
'accountancy'));
3043 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'LineId') .
': ' . $obj->rowid;
3048 $bookkeeping->id = 0;
3049 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3050 $bookkeeping->doc_ref = $new_fiscal_period->label;
3051 $bookkeeping->date_creation = $now;
3052 $bookkeeping->doc_type =
'accounting_reversal';
3053 $bookkeeping->fk_doc = $new_fiscal_period->id;
3054 $bookkeeping->fk_docdet = 0;
3056 $bookkeeping->montant = -$bookkeeping->montant;
3057 $bookkeeping->sens = ($bookkeeping->montant >= 0) ?
'C' :
'D';
3058 $old_debit = $bookkeeping->debit;
3059 $bookkeeping->debit = $bookkeeping->credit;
3060 $bookkeeping->credit = $old_debit;
3062 $bookkeeping->fk_user_author = $user->id;
3063 $bookkeeping->entity = $conf->entity;
3065 $result = $bookkeeping->create($user);
3067 $this->error = $bookkeeping->error;
3068 $this->errors = $bookkeeping->errors;
3073 $this->db->free($resql);
3077 $this->db->rollback();
3080 $this->db->commit();
3096 public $doc_date =
null;
3110 public $thirdparty_code;
3111 public $subledger_account;
3112 public $subledger_label;
3113 public $numero_compte;
3114 public $label_compte;
3115 public $label_operation;
3133 public $multicurrency_amount;
3138 public $multicurrency_code;
3144 public $lettering_code;
3145 public $date_lettering;
3150 public $fk_user_author;
3153 public $code_journal;
3154 public $journal_label;
3163 public $date_creation;
3168 public $date_modification;
3173 public $date_export;
3178 public $date_validation;
3183 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.
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.