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)) {
1724 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1725 $sql .=
" WHERE piece_num = ".(int) $piecenum;
1726 $sql .=
" AND date_validated IS NULL";
1727 $sql .=
" AND entity = " . ((int) $conf->entity);
1728 $sql .= $sql_filter;
1730 $resql = $this->db->query($sql);
1733 $this->errors[] =
"Error ".$this->db->lasterror();
1734 foreach ($this->errors as $errmsg) {
1735 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1736 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1738 $this->db->rollback();
1741 $nbprocessed = $this->db->affected_rows($resql);
1744 $this->db->commit();
1746 return $nbprocessed;
1774 $object->context[
'createfromclone'] =
'createfromclone';
1775 $result =
$object->create($user);
1780 $this->errors =
$object->errors;
1781 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1784 unset(
$object->context[
'createfromclone']);
1788 $this->db->commit();
1792 $this->db->rollback();
1811 $this->doc_date = $now;
1812 $this->doc_type =
'';
1813 $this->doc_ref =
'';
1815 $this->fk_docdet = 0;
1816 $this->thirdparty_code =
'CU001';
1817 $this->subledger_account =
'41100001';
1818 $this->subledger_label =
'My customer company';
1819 $this->numero_compte =
'411';
1820 $this->label_compte =
'Customer';
1821 $this->label_operation =
'Sales of pea';
1822 $this->debit = 99.9;
1823 $this->credit = 0.0;
1824 $this->amount = 0.0;
1826 $this->fk_user_author = $user->id;
1827 $this->import_key =
'20201027';
1828 $this->code_journal =
'VT';
1829 $this->journal_label =
'Journal de vente';
1830 $this->piece_num = 1234;
1831 $this->date_creation = $now;
1847 $sql =
"SELECT piece_num, doc_date, code_journal, journal_label, doc_ref, doc_type,";
1848 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation, import_key";
1850 if ($mode !=
"_tmp") {
1851 $sql .=
", date_export";
1853 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1854 $sql .=
" WHERE piece_num = ".((int) $piecenum);
1855 $sql .=
" AND entity = " . ((int) $conf->entity);
1858 $result = $this->db->query($sql);
1860 $obj = $this->db->fetch_object($result);
1862 $this->piece_num = $obj->piece_num;
1863 $this->code_journal = $obj->code_journal;
1864 $this->journal_label = $obj->journal_label;
1865 $this->doc_date = $this->db->jdate($obj->doc_date);
1866 $this->doc_ref = $obj->doc_ref;
1867 $this->doc_type = $obj->doc_type;
1868 $this->date_creation = $this->db->jdate($obj->date_creation);
1869 $this->date_modification = $this->db->jdate($obj->date_modification);
1870 if ($mode !=
"_tmp") {
1871 $this->date_export = $this->db->jdate($obj->date_export);
1873 $this->date_validation = $this->db->jdate($obj->date_validation);
1874 $this->import_key = $obj->import_key;
1876 $this->error =
"Error ".$this->db->lasterror();
1877 dol_syslog(__METHOD__.$this->error, LOG_ERR);
1894 $sql =
"SELECT MAX(piece_num)+1 as max FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1895 $sql .=
" WHERE entity = " . ((int) $conf->entity);
1897 dol_syslog(get_class($this).
"::getNextNumMvt", LOG_DEBUG);
1899 $result = $this->db->query($sql);
1902 $obj = $this->db->fetch_object($result);
1904 $result = $obj->max;
1906 if (empty($result)) {
1911 $this->error =
"Error ".$this->db->lasterror();
1912 dol_syslog(get_class($this).
"::getNextNumMvt ".$this->error, LOG_ERR);
1928 $sql =
"SELECT rowid, doc_date, doc_type,";
1929 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
1930 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
1931 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, journal_label, piece_num,";
1932 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation";
1934 if ($mode !=
"_tmp") {
1935 $sql .=
", date_export";
1937 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1938 $sql .=
" WHERE piece_num = ".((int) $piecenum);
1939 $sql .=
" AND entity = " . ((int) $conf->entity);
1942 $result = $this->db->query($sql);
1944 while ($obj = $this->db->fetch_object($result)) {
1947 $line->id = $obj->rowid;
1949 $line->doc_date = $this->db->jdate($obj->doc_date);
1950 $line->doc_type = $obj->doc_type;
1951 $line->doc_ref = $obj->doc_ref;
1952 $line->fk_doc = $obj->fk_doc;
1953 $line->fk_docdet = $obj->fk_docdet;
1954 $line->thirdparty_code = $obj->thirdparty_code;
1955 $line->subledger_account = $obj->subledger_account;
1956 $line->subledger_label = $obj->subledger_label;
1957 $line->numero_compte = $obj->numero_compte;
1958 $line->label_compte = $obj->label_compte;
1959 $line->label_operation = $obj->label_operation;
1960 $line->debit = $obj->debit;
1961 $line->credit = $obj->credit;
1962 $line->montant = $obj->amount;
1963 $line->amount = $obj->amount;
1964 $line->sens = $obj->sens;
1965 $line->code_journal = $obj->code_journal;
1966 $line->journal_label = $obj->journal_label;
1967 $line->piece_num = $obj->piece_num;
1968 $line->date_creation = $obj->date_creation;
1969 $line->date_modification = $obj->date_modification;
1970 if ($mode !=
"_tmp") {
1971 $line->date_export = $obj->date_export;
1973 $line->date_validation = $obj->date_validation;
1975 $this->linesmvt[] = $line;
1978 $this->error =
"Error ".$this->db->lasterror();
1979 dol_syslog(__METHOD__.$this->error, LOG_ERR);
1998 $sql =
"SELECT rowid, doc_date, doc_type,";
1999 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
2000 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
2001 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, piece_num,";
2002 $sql .=
" date_validated as date_validation";
2003 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
2004 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2006 dol_syslog(get_class($this).
"::export_bookkeeping", LOG_DEBUG);
2008 $resql = $this->db->query($sql);
2011 $this->linesexport = array();
2013 $num = $this->db->num_rows($resql);
2014 while ($obj = $this->db->fetch_object($resql)) {
2017 $line->id = $obj->rowid;
2019 $line->doc_date = $this->db->jdate($obj->doc_date);
2020 $line->doc_type = $obj->doc_type;
2021 $line->doc_ref = $obj->doc_ref;
2022 $line->fk_doc = $obj->fk_doc;
2023 $line->fk_docdet = $obj->fk_docdet;
2024 $line->thirdparty_code = $obj->thirdparty_code;
2025 $line->subledger_account = $obj->subledger_account;
2026 $line->subledger_label = $obj->subledger_label;
2027 $line->numero_compte = $obj->numero_compte;
2028 $line->label_compte = $obj->label_compte;
2029 $line->label_operation = $obj->label_operation;
2030 $line->debit = $obj->debit;
2031 $line->credit = $obj->credit;
2032 $line->montant = $obj->amount;
2033 $line->amount = $obj->amount;
2034 $line->sens = $obj->sens;
2035 $line->code_journal = $obj->code_journal;
2036 $line->piece_num = $obj->piece_num;
2037 $line->date_validation = $obj->date_validation;
2039 $this->linesexport[] = $line;
2041 $this->db->free($resql);
2045 $this->error =
"Error ".$this->db->lasterror();
2046 dol_syslog(get_class($this).
"::export_bookkeeping ".$this->error, LOG_ERR);
2066 if (!isset($sql_filter)) {
2072 if ($direction == 0) {
2076 if ($next_piecenum < 0) {
2082 $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";
2083 $resql = $this->db->query($sql);
2086 $this->errors[] =
'Error '.$this->db->lasterror();
2087 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2092 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
' (doc_date, doc_type,';
2093 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2094 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2095 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num, date_creation)';
2096 $sql .=
' SELECT doc_date, doc_type,';
2097 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2098 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2099 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.((int) $next_piecenum).
", '".$this->db->idate($now).
"'";
2100 $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);
2101 $sql .= $sql_filter;
2102 $resql = $this->db->query($sql);
2105 $this->errors[] =
'Error '.$this->db->lasterror();
2106 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2111 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2112 $resql = $this->db->query($sql);
2115 $this->errors[] =
'Error '.$this->db->lasterror();
2116 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2119 } elseif ($direction == 1) {
2121 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2122 $resql = $this->db->query($sql);
2125 $this->errors[] =
'Error '.$this->db->lasterror();
2126 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2131 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'_tmp (doc_date, doc_type,';
2132 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2133 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2134 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)';
2135 $sql .=
' SELECT doc_date, doc_type,';
2136 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2137 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2138 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num';
2139 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2140 $sql .= $sql_filter;
2141 $resql = $this->db->query($sql);
2144 $this->errors[] =
'Error '.$this->db->lasterror();
2145 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2150 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2151 $sql .= $sql_filter;
2152 $resql = $this->db->query($sql);
2155 $this->errors[] =
'Error '.$this->db->lasterror();
2156 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2161 $this->db->commit();
2164 $this->db->rollback();
2192 public function select_account($selectid, $htmlname =
'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase =
'')
2197 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
2201 $sql =
"SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version";
2202 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab";
2203 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.account_number = ab.numero_compte";
2204 $sql .=
" AND aa.active = 1";
2205 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2206 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2207 $sql .=
" AND ab.entity = " . ((int) $conf->entity);
2208 $sql .=
" ORDER BY account_number ASC";
2210 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2211 $resql = $this->db->query($sql);
2214 $this->error =
"Error ".$this->db->lasterror();
2215 dol_syslog(get_class($this).
"::select_account ".$this->error, LOG_ERR);
2224 while ($obj = $this->db->fetch_object($resql)) {
2227 $select_value_in = $obj->rowid;
2228 $select_value_out = $obj->rowid;
2230 if ($select_in == 1) {
2231 $select_value_in = $obj->account_number;
2233 if ($select_out == 1) {
2234 $select_value_out = $obj->account_number;
2239 if (($selectid !=
'') && $selectid == $select_value_in) {
2240 $selected = $select_value_out;
2243 $options[$select_value_out] = $label;
2246 $out .=
Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0,
'', 0, 0, 0,
'',
'maxwidth300');
2247 $this->db->free($resql);
2263 $sql =
"SELECT root.rowid, root.account_number, root.label as label,";
2264 $sql .=
" parent.rowid as parent_rowid, parent.account_number as parent_account_number, parent.label as parent_label";
2265 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_account as aa";
2266 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2267 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2268 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as parent ON aa.account_parent = parent.rowid AND parent.active = 1";
2269 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as root ON parent.account_parent = root.rowid AND root.active = 1";
2270 $sql .=
" WHERE aa.account_number = '".$this->db->escape($account).
"'";
2271 $sql .=
" AND aa.entity = " . ((int) $conf->entity);
2273 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2274 $resql = $this->db->query($sql);
2277 if ($this->db->num_rows($resql)) {
2278 $obj = $this->db->fetch_object($resql);
2281 $result = array(
'id' => $obj->rowid,
'account_number' => $obj->account_number,
'label' => $obj->label);
2284 $this->error =
"Error ".$this->db->lasterror();
2285 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2304 $sql =
"SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
2305 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_account as aa ";
2306 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2307 $sql .=
" AND aa.account_number = '".$this->db->escape($account).
"'";
2308 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2309 $sql .=
" AND aa.active = 1";
2310 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
2311 $sql .=
" WHERE aa.entity = " . ((int) $conf->entity);
2313 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2314 $resql = $this->db->query($sql);
2317 if ($this->db->num_rows($resql)) {
2318 $obj = $this->db->fetch_object($resql);
2320 if (empty($obj->category)) {
2323 return $obj->label.
' ('.$obj->category.
')';
2326 $this->error =
"Error ".$this->db->lasterror();
2327 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2343 $alias = trim($alias);
2344 $alias = !empty($alias) && strpos($alias,
'.') < 0 ? $alias .
"." : $alias;
2346 if (!isset(self::$can_modify_bookkeeping_sql_cached[$alias]) || $force) {
2352 $sql_list = array();
2353 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2355 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2356 $sql_list[$i] =
"(";
2357 $sql_list[$i] .=
"'".$this->db->idate($fiscal_period[
'date_start']) .
"' <= ".$this->db->sanitize($alias).
"doc_date";
2358 if (!empty($fiscal_period[
'date_end'])) {
2359 $sql_list[$i] .=
" AND ";
2360 $sql_list[$i] .= $this->db->sanitize($alias).
"doc_date <= '" . $this->db->idate($fiscal_period[
'date_end']).
"'";
2362 $sql_list[$i] .=
")";
2366 $sqlsanitized = implode(
' OR ', $sql_list);
2367 self::$can_modify_bookkeeping_sql_cached[$alias] = empty($sql_list) ?
"" :
" AND (".$sqlsanitized.
")";
2370 return self::$can_modify_bookkeeping_sql_cached[$alias];
2392 $result = $bookkeeping->fetch($id,
null, $mode);
2397 if (!empty($conf->cache[
'closed_fiscal_period_cached']) && is_array($conf->cache[
'closed_fiscal_period_cached'])) {
2398 foreach ($conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2399 if ($fiscal_period[
'date_start'] <= $bookkeeping->doc_date && $bookkeeping->doc_date <= $fiscal_period[
'date_end']) {
2413 $result = $bookkeeping->fetch($id,
null, $mode);
2418 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2419 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2420 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'])) {
2447 if (!empty($conf->cache[
'closed_fiscal_period_cached']) && is_array($conf->cache[
'closed_fiscal_period_cached'])) {
2448 foreach ($conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2449 if ($fiscal_period[
'date_start'] <= $date && $date <= $fiscal_period[
'date_end']) {
2462 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2463 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2464 if (!empty($fiscal_period[
'date_start']) && $fiscal_period[
'date_start'] <= $date && (empty($fiscal_period[
'date_end']) || $date <= $fiscal_period[
'date_end'])) {
2485 if ($mode ==
'active') {
2486 if (!isset($conf->cache[
'active_fiscal_period_cached']) || $force) {
2487 $sql =
"SELECT date_start, date_end";
2488 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2489 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2490 $sql .=
" AND statut = 0";
2492 $resql = $this->db->query($sql);
2494 $this->errors[] = $this->db->lasterror();
2499 while ($obj = $this->db->fetch_object($resql)) {
2501 'date_start' => $this->db->jdate($obj->date_start),
2502 'date_end' => $this->db->jdate($obj->date_end),
2505 $conf->cache[
'active_fiscal_period_cached'] = $list;
2508 if ($mode ==
'closed') {
2509 if (!isset($conf->cache[
'closed_fiscal_period_cached']) || $force) {
2510 $sql =
"SELECT date_start, date_end";
2511 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2512 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2513 $sql .=
" AND statut = 1";
2515 $resql = $this->db->query($sql);
2517 $this->errors[] = $this->db->lasterror();
2522 while ($obj = $this->db->fetch_object($resql)) {
2524 'date_start' => $this->db->jdate($obj->date_start),
2525 'date_end' => $this->db->jdate($obj->date_end),
2528 $conf->cache[
'closed_fiscal_period_cached'] = $list;
2546 $sql =
"SELECT rowid, label, date_start, date_end, statut";
2547 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2548 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2549 if (!empty($filter)) {
2550 $sql .=
" AND (" . $this->db->sanitize($filter, 1, 1, 1) .
')';
2552 $sql .= $this->db->order(
'date_start',
'ASC');
2554 $resql = $this->db->query($sql);
2556 $this->errors[] = $this->db->lasterror();
2560 while ($obj = $this->db->fetch_object($resql)) {
2561 $list[$obj->rowid] = array(
2562 'id' => (
int) $obj->rowid,
2563 'label' => $obj->label,
2564 'date_start' => $this->db->jdate($obj->date_start),
2565 'date_end' => $this->db->jdate($obj->date_end),
2566 'status' => (
int) $obj->statut,
2585 $sql =
"SELECT YEAR(b.doc_date) as year";
2586 for ($i = 1; $i <= 12; $i++) {
2587 $sql .=
", SUM(".$this->db->ifsql(
"MONTH(b.doc_date) = ".((
int) $i),
"1",
"0") .
") AS month".((int) $i);
2589 $sql .=
", COUNT(b.rowid) as total";
2590 $sql .=
" FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping as b";
2591 $sql .=
" WHERE b.doc_date >= '" . $this->db->idate($date_start) .
"'";
2592 $sql .=
" AND b.doc_date <= '" . $this->db->idate($date_end) .
"'";
2593 $sql .=
" AND b.entity IN (" .
getEntity(
'bookkeeping', 0) .
")";
2599 $sql .=
" AND b.doc_date BETWEEN 0 AND 0";
2602 $sql .=
" AND date_validated IS NULL";
2605 $sql .=
" GROUP BY YEAR(b.doc_date)";
2606 $sql .= $this->db->order(
"year",
'ASC');
2609 $resql = $this->db->query($sql);
2611 $this->errors[] = $this->db->lasterror();
2615 while ($obj = $this->db->fetch_object($resql)) {
2616 $total += (int) $obj->total;
2618 'year' => (
int) $obj->year,
2620 'total' => (
int) $obj->total,
2622 for ($i = 1; $i <= 12; $i++) {
2623 $year_list[
'count'][$i] = (int) $obj->{
'month' . $i};
2626 $list[] = $year_list;
2629 $this->db->free($resql);
2651 $sql =
" UPDATE " . MAIN_DB_PREFIX .
"accounting_bookkeeping";
2652 $sql .=
" SET date_validated = '" . $this->db->idate($now) .
"'";
2653 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2654 $sql .=
" AND DATE(doc_date) >= '" . $this->db->idate($date_start) .
"'";
2655 $sql .=
" AND DATE(doc_date) <= '" . $this->db->idate($date_end) .
"'";
2656 $sql .=
" AND date_validated IS NULL";
2659 $resql = $this->db->query($sql);
2661 $this->errors[] = $this->db->lasterror();
2681 $income_statement_amount = 0;
2683 if (
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
2684 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
2686 $pcg_type_filter = array();
2687 foreach ($accounting_groups_used_for_income_statement as $item) {
2688 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
2692 $sql .=
" t.numero_compte,";
2693 $sql .=
" aa.pcg_type,";
2694 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as accounting_result";
2695 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
2696 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'accounting_account as aa ON aa.account_number = t.numero_compte';
2697 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
2698 $sql .=
" AND aa.entity = " . ((int) $conf->entity);
2699 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX .
'accounting_system WHERE rowid = ' . ((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')) .
')';
2700 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
2701 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) .
"'";
2702 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
2703 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
2705 $resql = $this->db->query($sql);
2707 $this->errors[] =
'Error ' . $this->db->lasterror();
2708 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2710 while ($obj = $this->db->fetch_object($resql)) {
2711 $income_statement_amount += $obj->accounting_result;
2716 return (
string) $income_statement_amount;
2728 public function closeFiscalPeriod($fiscal_period_id, $new_fiscal_period_id, $separate_auxiliary_account =
false, $generate_bookkeeping_records =
true)
2730 global $conf, $langs, $user;
2733 $fiscal_period_id = max(0, $fiscal_period_id);
2734 if (empty($fiscal_period_id)) {
2735 $langs->load(
'errors');
2736 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2740 $result = $fiscal_period->fetch($fiscal_period_id);
2742 $this->error = $fiscal_period->error;
2743 $this->errors = $fiscal_period->errors;
2745 } elseif (empty($fiscal_period->id)) {
2746 $langs->loadLangs(array(
'errors',
'compta'));
2747 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
2752 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
2753 if (empty($new_fiscal_period_id)) {
2754 $langs->load(
'errors');
2755 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2758 $new_fiscal_period =
new Fiscalyear($this->db);
2759 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
2761 $this->error = $new_fiscal_period->error;
2762 $this->errors = $new_fiscal_period->errors;
2764 } elseif (empty($new_fiscal_period->id)) {
2765 $langs->loadLangs(array(
'errors',
'compta'));
2766 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
2773 $fiscal_period->statut = Fiscalyear::STATUS_CLOSED;
2774 $fiscal_period->status = Fiscalyear::STATUS_CLOSED;
2775 $result = $fiscal_period->update($user);
2777 $this->error = $fiscal_period->error;
2778 $this->errors = $fiscal_period->errors;
2782 if (!$error && !empty($generate_bookkeeping_records)) {
2784 if (empty($journal_id)) {
2785 $langs->loadLangs(array(
'errors',
'accountancy'));
2786 $this->errors[] = $langs->trans(
'ErrorBadParameters') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
2793 $result = $journal->fetch($journal_id);
2795 $this->error = $journal->error;
2796 $this->errors = $journal->errors;
2798 } elseif ($result == 0) {
2799 $langs->loadLangs(array(
'errors',
'accountancy'));
2800 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
2806 $accounting_groups_used_for_balance_sheet_account = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))),
'strlen');
2807 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
2809 $pcg_type_filter = array();
2810 $tmp = array_merge($accounting_groups_used_for_balance_sheet_account, $accounting_groups_used_for_income_statement);
2811 foreach ($tmp as $item) {
2812 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
2816 $sql .=
" t.numero_compte,";
2817 $sql .=
" t.label_compte,";
2818 if ($separate_auxiliary_account) {
2819 $sql .=
" t.subledger_account,";
2820 $sql .=
" t.subledger_label,";
2822 $sql .=
" aa.pcg_type,";
2823 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as opening_balance";
2824 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
2825 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'accounting_account as aa ON aa.account_number = t.numero_compte';
2826 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
2827 $sql .=
" AND aa.entity = ". ((int) $conf->entity);
2828 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM '.MAIN_DB_PREFIX.
'accounting_system WHERE rowid = '.((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')).
')';
2829 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
2830 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
2831 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
2832 $sql .=
' GROUP BY t.numero_compte, t.label_compte, aa.pcg_type';
2833 if ($separate_auxiliary_account) {
2834 $sql .=
' ,t.subledger_account, t.subledger_label';
2836 $sql .= $this->db->order(
"t.numero_compte",
"ASC");
2838 $resql = $this->db->query($sql);
2840 $this->errors[] =
'Error ' . $this->db->lasterror();
2841 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2846 $income_statement_amount = 0;
2847 while ($obj = $this->db->fetch_object($resql)) {
2848 if (in_array($obj->pcg_type, $accounting_groups_used_for_income_statement)) {
2849 $income_statement_amount += $obj->opening_balance;
2852 $mt = $obj->opening_balance;
2855 $bookkeeping->doc_date = $new_fiscal_period->date_start;
2856 $bookkeeping->date_lim_reglement = 0;
2857 $bookkeeping->doc_ref = $new_fiscal_period->label;
2858 $bookkeeping->date_creation = $now;
2859 $bookkeeping->doc_type =
'closure';
2860 $bookkeeping->fk_doc = $new_fiscal_period->id;
2861 $bookkeeping->fk_docdet = 0;
2862 $bookkeeping->thirdparty_code =
'';
2864 if ($separate_auxiliary_account) {
2865 $bookkeeping->subledger_account = $obj->subledger_account;
2866 $bookkeeping->subledger_label = $obj->subledger_label;
2868 $bookkeeping->subledger_account =
'';
2869 $bookkeeping->subledger_label =
'';
2872 $bookkeeping->numero_compte = $obj->numero_compte;
2873 $bookkeeping->label_compte = $obj->label_compte;
2875 $bookkeeping->label_operation = $new_fiscal_period->label;
2876 $bookkeeping->montant = $mt;
2877 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
2878 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
2879 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
2880 $bookkeeping->code_journal = $journal->code;
2881 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
2882 $bookkeeping->fk_user_author = $user->id;
2883 $bookkeeping->entity = $conf->entity;
2885 $result = $bookkeeping->create($user);
2887 $this->error = $bookkeeping->error;
2888 $this->errors = $bookkeeping->errors;
2896 if (!$error && $income_statement_amount != 0) {
2897 $mt = $income_statement_amount;
2899 $accountingaccount->fetch(
null,
getDolGlobalString($income_statement_amount < 0 ?
'ACCOUNTING_RESULT_LOSS' :
'ACCOUNTING_RESULT_PROFIT'),
true);
2902 $bookkeeping->doc_date = $new_fiscal_period->date_start;
2903 $bookkeeping->date_lim_reglement = 0;
2904 $bookkeeping->doc_ref = $new_fiscal_period->label;
2905 $bookkeeping->date_creation = $now;
2906 $bookkeeping->doc_type =
'closure';
2907 $bookkeeping->fk_doc = $new_fiscal_period->id;
2908 $bookkeeping->fk_docdet = 0;
2909 $bookkeeping->thirdparty_code =
'';
2911 if ($separate_auxiliary_account) {
2912 $bookkeeping->subledger_label =
'';
2913 $bookkeeping->subledger_account = $obj->subledger_account;
2914 $bookkeeping->subledger_label = $obj->subledger_label;
2916 $bookkeeping->subledger_account =
'';
2917 $bookkeeping->subledger_label =
'';
2920 $bookkeeping->numero_compte = $accountingaccount->account_number;
2921 $bookkeeping->label_compte = $accountingaccount->label;
2923 $bookkeeping->label_operation = $new_fiscal_period->label;
2924 $bookkeeping->montant = $mt;
2925 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
2926 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
2927 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
2928 $bookkeeping->code_journal = $journal->code;
2929 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
2930 $bookkeeping->fk_user_author = $user->id;
2931 $bookkeeping->entity = $conf->entity;
2933 $result = $bookkeeping->create($user);
2935 $this->error = $bookkeeping->error;
2936 $this->errors = $bookkeeping->errors;
2940 $this->db->free($resql);
2946 $this->db->rollback();
2949 $this->db->commit();
2966 global $conf, $langs, $user;
2969 $fiscal_period_id = max(0, $fiscal_period_id);
2970 if (empty($fiscal_period_id)) {
2971 $langs->load(
'errors');
2972 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2976 $result = $fiscal_period->fetch($fiscal_period_id);
2978 $this->error = $fiscal_period->error;
2979 $this->errors = $fiscal_period->errors;
2981 } elseif (empty($fiscal_period->id)) {
2982 $langs->loadLangs(array(
'errors',
'compta'));
2983 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
2988 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
2989 if (empty($new_fiscal_period_id)) {
2990 $langs->load(
'errors');
2991 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2994 $new_fiscal_period =
new Fiscalyear($this->db);
2995 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
2997 $this->error = $new_fiscal_period->error;
2998 $this->errors = $new_fiscal_period->errors;
3000 } elseif (empty($new_fiscal_period->id)) {
3001 $langs->loadLangs(array(
'errors',
'compta'));
3002 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
3007 $inventory_journal_id = max(0, $inventory_journal_id);
3008 if (empty($inventory_journal_id)) {
3009 $langs->load(
'errors');
3010 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3015 $result = $inventory_journal->fetch($inventory_journal_id);
3017 $this->error = $inventory_journal->error;
3018 $this->errors = $inventory_journal->errors;
3020 } elseif ($result == 0) {
3021 $langs->loadLangs(array(
'errors',
'accountancy'));
3022 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'InventoryJournal');
3029 $sql =
'SELECT t.rowid';
3030 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
3031 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
3032 $sql .=
" AND code_journal = '" . $this->db->escape($inventory_journal->code) .
"'";
3033 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) .
"'";
3034 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
3035 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
3036 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
3038 $resql = $this->db->query($sql);
3040 $this->errors[] =
'Error ' . $this->db->lasterror();
3041 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3046 while ($obj = $this->db->fetch_object($resql)) {
3048 $result = $bookkeeping->fetch($obj->rowid);
3050 $this->error = $inventory_journal->error;
3051 $this->errors = $inventory_journal->errors;
3054 } elseif ($result == 0) {
3055 $langs->loadLangs(array(
'errors',
'accountancy'));
3056 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'LineId') .
': ' . $obj->rowid;
3061 $bookkeeping->id = 0;
3062 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3063 $bookkeeping->doc_ref = $new_fiscal_period->label;
3064 $bookkeeping->date_creation = $now;
3065 $bookkeeping->doc_type =
'accounting_reversal';
3066 $bookkeeping->fk_doc = $new_fiscal_period->id;
3067 $bookkeeping->fk_docdet = 0;
3069 $bookkeeping->montant = -$bookkeeping->montant;
3070 $bookkeeping->sens = ($bookkeeping->montant >= 0) ?
'C' :
'D';
3071 $old_debit = $bookkeeping->debit;
3072 $bookkeeping->debit = $bookkeeping->credit;
3073 $bookkeeping->credit = $old_debit;
3075 $bookkeeping->fk_user_author = $user->id;
3076 $bookkeeping->entity = $conf->entity;
3078 $result = $bookkeeping->create($user);
3080 $this->error = $bookkeeping->error;
3081 $this->errors = $bookkeeping->errors;
3086 $this->db->free($resql);
3090 $this->db->rollback();
3093 $this->db->commit();
3109 public $doc_date =
null;
3123 public $thirdparty_code;
3124 public $subledger_account;
3125 public $subledger_label;
3126 public $numero_compte;
3127 public $label_compte;
3128 public $label_operation;
3146 public $multicurrency_amount;
3151 public $multicurrency_code;
3157 public $lettering_code;
3158 public $date_lettering;
3163 public $fk_user_author;
3166 public $code_journal;
3167 public $journal_label;
3176 public $date_creation;
3181 public $date_modification;
3186 public $date_export;
3191 public $date_validation;
3196 public $date_lim_reglement;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Class to manage accounting accounts.
Class to manage accounting journals.
Class to manage Ledger (General Ledger and Subledger)
closeFiscalPeriod($fiscal_period_id, $new_fiscal_period_id, $separate_auxiliary_account=false, $generate_bookkeeping_records=true)
Close fiscal period.
getCountByMonthForFiscalPeriod($date_start, $date_end)
Get list of count by month into the fiscal period.
fetchAllBalance($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND', $option=0)
Load object in memory from the database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
select_account($selectid, $htmlname='account', $showempty=0, $event=array(), $select_in=0, $select_out=0, $aabase='')
Return list of accounts with label by chart of accounts.
getNextNumMvt($mode='')
Return next movement number.
get_compte_desc($account=null)
Description of accounting account.
__construct(DoliDB $db)
Constructor.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
deleteByImportkey($importkey, $mode='')
Delete bookkeeping by importkey.
getRootAccount($account=null)
Return id and description of a root accounting account.
transformTransaction($direction=0, $piece_num='')
Transform transaction.
insertAccountingReversal($fiscal_period_id, $inventory_journal_id, $new_fiscal_period_id, $date_start, $date_end)
Insert accounting reversal into the inventory journal of the new fiscal period.
fetchPerMvt($piecenum, $mode='')
Load an accounting document into memory from database.
create(User $user, $notrigger=0)
Create object into database.
updateByMvt($piece_num='', $field='', $value='', $mode='')
Update accounting movement.
createStd(User $user, $notrigger=0, $mode='')
Create object into database.
update(User $user, $notrigger=0, $mode='')
Update object into database.
deleteMvtNum($piecenum, $mode='')
Delete bookkeeping by piece number.
getFiscalPeriods($filter='')
Get list of fiscal period ordered by start date.
validBookkeepingDate($date)
Is the bookkeeping date valid (on an open period or not on a closed period) ?
deleteByYearAndJournal($delyear=0, $journal='', $mode='', $delmonth=0)
Delete bookkeeping by year.
loadFiscalPeriods($force=false, $mode='active')
Load list of active fiscal period.
fetchAllByAccount($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND', $option=0, $countonly=0)
Load object in memory from the database in ->lines.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
getCanModifyBookkeepingSQL($alias='', $force=false)
Get SQL string for check if the bookkeeping can be modified or deleted ? (cached)
fetch($id, $ref=null, $mode='')
Load object in memory from the database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND', $showAlreadyExportMovements=1)
Load object in memory from the database.
accountingResult($date_start, $date_end)
Define accounting result.
canModifyBookkeeping($id, $mode='')
Is the bookkeeping can be modified or deleted ?
fetchAllPerMvt($piecenum, $mode='')
Load all accounting lines related to a given transaction ID $piecenum.
validateMovementForFiscalPeriod($date_start, $date_end)
Validate all movement between the specified dates.
export_bookkeeping($model='ebp')
Export bookkeeping.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class to manage fiscal year.
Class to manage Dolibarr users.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.