30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/fiscalyear.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
44 public $element =
'accountingbookkeeping';
49 public $table_element =
'accounting_bookkeeping';
59 public $lines = array();
74 public $date_lim_reglement;
99 public $thirdparty_code;
104 public $subledger_account;
109 public $subledger_label;
114 public $numero_compte;
119 public $label_compte;
124 public $label_operation;
156 public $fk_user_author;
166 public $code_journal;
171 public $journal_label;
181 public $linesmvt = array();
186 public $linesexport = array();
191 public $date_validation;
201 public $picto =
'generic';
206 public static $can_modify_bookkeeping_sql_cached;
228 global $conf, $langs;
235 if (isset($this->doc_type)) {
236 $this->doc_type = trim($this->doc_type);
238 if (isset($this->doc_ref)) {
239 $this->doc_ref = trim($this->doc_ref);
241 if (isset($this->fk_doc)) {
242 $this->fk_doc = (int) $this->fk_doc;
244 if (isset($this->fk_docdet)) {
245 $this->fk_docdet = (int) $this->fk_docdet;
247 if (isset($this->thirdparty_code)) {
248 $this->thirdparty_code = trim($this->thirdparty_code);
250 if (isset($this->subledger_account)) {
251 $this->subledger_account = trim($this->subledger_account);
253 if (isset($this->subledger_label)) {
254 $this->subledger_label = trim($this->subledger_label);
256 if (isset($this->numero_compte)) {
257 $this->numero_compte = trim($this->numero_compte);
259 if (isset($this->label_compte)) {
260 $this->label_compte = trim($this->label_compte);
262 if (isset($this->label_operation)) {
263 $this->label_operation = trim($this->label_operation);
265 if (isset($this->debit)) {
266 $this->debit = (float) $this->debit;
268 if (isset($this->credit)) {
269 $this->credit = (float) $this->credit;
271 if (isset($this->montant)) {
272 $this->montant = (float) $this->montant;
274 if (isset($this->amount)) {
275 $this->amount = (float) $this->amount;
277 if (isset($this->sens)) {
278 $this->sens = trim($this->sens);
280 if (isset($this->import_key)) {
281 $this->import_key = trim($this->import_key);
283 if (isset($this->code_journal)) {
284 $this->code_journal = trim($this->code_journal);
286 if (isset($this->journal_label)) {
287 $this->journal_label = trim($this->journal_label);
289 if (isset($this->piece_num)) {
290 $this->piece_num = (int) $this->piece_num;
292 if (empty($this->debit)) {
295 if (empty($this->credit)) {
302 } elseif ($result == 0) {
304 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
306 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
312 if (($this->numero_compte ==
"") || $this->numero_compte ==
'-1' || $this->numero_compte ==
'NotDefined') {
313 $langs->loadLangs(array(
"errors"));
314 if (in_array($this->doc_type, array(
'bank',
'expense_report'))) {
315 $this->errors[] = $langs->trans(
'ErrorFieldAccountNotDefinedForBankLine', $this->fk_docdet, $this->doc_type);
318 $mesg = $this->doc_ref.
', '.$langs->trans(
"AccountAccounting").
': '.($this->numero_compte != -1 ? $this->numero_compte : $langs->trans(
"Unknown"));
319 if ($this->subledger_account && $this->subledger_account != $this->numero_compte) {
320 $mesg .=
', '.$langs->trans(
"SubledgerAccount").
': '.$this->subledger_account;
322 $this->errors[] = $langs->trans(
'ErrorFieldAccountNotDefinedForLine', $mesg);
330 $this->piece_num = 0;
337 $sql =
"SELECT count(*) as nb";
338 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
339 $sql .=
" WHERE doc_type = '".$this->db->escape($this->doc_type).
"'";
340 $sql .=
" AND fk_doc = ".((int) $this->fk_doc);
343 $sql .=
" AND fk_docdet = ".((int) $this->fk_docdet);
345 $sql .=
" AND numero_compte = '".$this->db->escape($this->numero_compte).
"'";
346 $sql .=
" AND label_operation = '".$this->db->escape($this->label_operation).
"'";
347 if (!empty($this->subledger_account)) {
348 $sql .=
" AND subledger_account = '".$this->db->escape($this->subledger_account).
"'";
350 $sql .=
" AND entity = ".$conf->entity;
352 $resql = $this->db->query($sql);
355 $row = $this->db->fetch_object($resql);
358 $sqlnum =
"SELECT piece_num";
359 $sqlnum .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
360 $sqlnum .=
" WHERE doc_type = '".$this->db->escape($this->doc_type).
"'";
361 $sqlnum .=
" AND fk_doc = ".((int) $this->fk_doc);
364 $sqlnum .=
" AND fk_docdet = ".((int) $this->fk_docdet);
366 $sqlnum .=
" AND doc_ref = '".$this->db->escape($this->doc_ref).
"'";
367 $sqlnum .=
" AND entity = ".$conf->entity;
369 dol_syslog(get_class($this).
":: create sqlnum=".$sqlnum, LOG_DEBUG);
370 $resqlnum = $this->db->query($sqlnum);
372 $objnum = $this->db->fetch_object($resqlnum);
373 $this->piece_num = $objnum->piece_num;
376 dol_syslog(get_class($this).
"::create this->piece_num=".$this->piece_num, LOG_DEBUG);
377 if (empty($this->piece_num)) {
378 $sqlnum =
"SELECT MAX(piece_num)+1 as maxpiecenum";
379 $sqlnum .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
380 $sqlnum .=
" WHERE entity = " . ((int) $conf->entity);
382 $resqlnum = $this->db->query($sqlnum);
384 $objnum = $this->db->fetch_object($resqlnum);
385 $this->piece_num = $objnum->maxpiecenum;
387 dol_syslog(get_class($this).
":: create now this->piece_num=".$this->piece_num, LOG_DEBUG);
389 if (empty($this->piece_num)) {
390 $this->piece_num = 1;
395 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
" (";
397 $sql .=
", date_lim_reglement";
398 $sql .=
", doc_type";
401 $sql .=
", fk_docdet";
402 $sql .=
", thirdparty_code";
403 $sql .=
", subledger_account";
404 $sql .=
", subledger_label";
405 $sql .=
", numero_compte";
406 $sql .=
", label_compte";
407 $sql .=
", label_operation";
412 $sql .=
", fk_user_author";
413 $sql .=
", date_creation";
414 $sql .=
", code_journal";
415 $sql .=
", journal_label";
416 $sql .=
", piece_num";
418 $sql .=
") VALUES (";
419 $sql .=
"'".$this->db->idate($this->doc_date).
"'";
420 $sql .=
", ".(!isset($this->date_lim_reglement) ||
dol_strlen($this->date_lim_reglement) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_lim_reglement).
"'");
421 $sql .=
", '".$this->db->escape($this->doc_type).
"'";
422 $sql .=
", '".$this->db->escape($this->doc_ref).
"'";
423 $sql .=
", ".((int) $this->fk_doc);
424 $sql .=
", ".((int) $this->fk_docdet);
425 $sql .=
", ".(!empty($this->thirdparty_code) ? (
"'".$this->db->escape($this->thirdparty_code).
"'") :
"NULL");
426 $sql .=
", ".(!empty($this->subledger_account) ? (
"'".$this->db->escape($this->subledger_account).
"'") :
"NULL");
427 $sql .=
", ".(!empty($this->subledger_label) ? (
"'".$this->db->escape($this->subledger_label).
"'") :
"NULL");
428 $sql .=
", '".$this->db->escape($this->numero_compte).
"'";
429 $sql .=
", ".(!empty($this->label_compte) ? (
"'".$this->db->escape($this->label_compte).
"'") :
"NULL");
430 $sql .=
", '".$this->db->escape($this->label_operation).
"'";
431 $sql .=
", ".((float) $this->debit);
432 $sql .=
", ".((float) $this->credit);
433 $sql .=
", ".((float) $this->montant);
434 $sql .=
", ".(!empty($this->sens) ? (
"'".$this->db->escape($this->sens).
"'") :
"NULL");
435 $sql .=
", '".$this->db->escape($this->fk_user_author).
"'";
436 $sql .=
", '".$this->db->idate($now).
"'";
437 $sql .=
", '".$this->db->escape($this->code_journal).
"'";
438 $sql .=
", ".(!empty($this->journal_label) ? (
"'".$this->db->escape($this->journal_label).
"'") :
"NULL");
439 $sql .=
", ".((int) $this->piece_num);
440 $sql .=
", ".(!isset($this->entity) ? $conf->entity : $this->entity);
443 $resql = $this->db->query($sql);
445 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
453 $this->errors[] =
'Error Create Error '.$result.
' lecture ID';
454 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
459 $this->errors[] =
'Error '.$this->db->lasterror();
460 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
465 $this->error =
'BookkeepingRecordAlreadyExists';
466 dol_syslog(__METHOD__.
' '.$this->error, LOG_WARNING);
471 $this->errors[] =
'Error '.$this->db->lasterror();
472 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
487 $this->db->rollback();
505 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
507 global $db, $conf, $langs;
508 global $dolibarr_main_authentication, $dolibarr_main_demo;
509 global $menumanager, $hookmanager;
511 if (!empty($conf->dol_no_mouse_hover)) {
518 $label =
'<u>'.$langs->trans(
"Transaction").
'</u>';
520 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->piece_num;
522 $url = DOL_URL_ROOT.
'/accountancy/bookkeeping/card.php?piece_num='.$this->piece_num;
524 if ($option !=
'nolink') {
526 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
527 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
528 $add_save_lastsearch_values = 1;
530 if ($add_save_lastsearch_values) {
531 $url .=
'&save_lastsearch_values=1';
536 if (empty($notooltip)) {
538 $label = $langs->trans(
"ShowTransaction");
539 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
541 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
542 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
544 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
547 $linkstart =
'<a href="'.$url.
'"';
548 $linkstart .= $linkclose.
'>';
551 $result .= $linkstart;
553 $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);
555 if ($withpicto != 2) {
556 $result .= $this->piece_num;
562 $hookmanager->initHooks(array($this->element .
'dao'));
563 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
564 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
566 $result = $hookmanager->resPrint;
568 $result .= $hookmanager->resPrint;
505 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1) {
…}
583 global $conf, $langs;
585 $langs->loadLangs(array(
"accountancy",
"bills",
"compta"));
592 if (isset($this->doc_type)) {
593 $this->doc_type = trim($this->doc_type);
595 if (isset($this->doc_ref)) {
596 $this->doc_ref = trim($this->doc_ref);
598 if (isset($this->fk_doc)) {
599 $this->fk_doc = (int) $this->fk_doc;
601 if (isset($this->fk_docdet)) {
602 $this->fk_docdet = (int) $this->fk_docdet;
604 if (isset($this->thirdparty_code)) {
605 $this->thirdparty_code = trim($this->thirdparty_code);
607 if (isset($this->subledger_account)) {
608 $this->subledger_account = trim($this->subledger_account);
610 if (isset($this->subledger_label)) {
611 $this->subledger_label = trim($this->subledger_label);
613 if (isset($this->numero_compte)) {
614 $this->numero_compte = trim($this->numero_compte);
616 if (isset($this->label_compte)) {
617 $this->label_compte = trim($this->label_compte);
619 if (isset($this->label_operation)) {
620 $this->label_operation = trim($this->label_operation);
622 if (isset($this->sens)) {
623 $this->sens = trim($this->sens);
625 if (isset($this->import_key)) {
626 $this->import_key = trim($this->import_key);
628 if (isset($this->code_journal)) {
629 $this->code_journal = trim($this->code_journal);
631 if (isset($this->journal_label)) {
632 $this->journal_label = trim($this->journal_label);
634 if (isset($this->piece_num)) {
635 $this->piece_num = (int) $this->piece_num;
637 if (empty($this->debit)) {
640 if (empty($this->credit)) {
643 if (empty($this->montant)) {
650 } elseif ($result == 0) {
652 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
654 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
659 $this->debit = (float)
price2num($this->debit,
'MT');
660 $this->credit = (float)
price2num($this->credit,
'MT');
661 $this->montant = (float)
price2num($this->montant,
'MT');
666 $this->journal_label = $langs->trans($this->journal_label);
669 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.$mode.
' (';
671 $sql .=
'date_lim_reglement,';
675 $sql .=
'fk_docdet,';
676 $sql .=
'thirdparty_code,';
677 $sql .=
'subledger_account,';
678 $sql .=
'subledger_label,';
679 $sql .=
'numero_compte,';
680 $sql .=
'label_compte,';
681 $sql .=
'label_operation,';
686 $sql .=
'fk_user_author,';
687 $sql .=
'date_creation,';
688 $sql .=
'code_journal,';
689 $sql .=
'journal_label,';
690 $sql .=
'piece_num,';
692 $sql .=
') VALUES (';
693 $sql .=
' '.(!isset($this->doc_date) ||
dol_strlen($this->doc_date) == 0 ?
'NULL' :
"'".$this->db->idate($this->doc_date).
"'").
',';
694 $sql .=
' '.(!isset($this->date_lim_reglement) ||
dol_strlen($this->date_lim_reglement) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_lim_reglement).
"'").
',';
695 $sql .=
' '.(!isset($this->doc_type) ?
'NULL' :
"'".$this->db->escape($this->doc_type).
"'").
',';
696 $sql .=
' '.(!isset($this->doc_ref) ?
'NULL' :
"'".$this->db->escape($this->doc_ref).
"'").
',';
697 $sql .=
' '.(empty($this->fk_doc) ?
'0' : (int) $this->fk_doc).
',';
698 $sql .=
' '.(empty($this->fk_docdet) ?
'0' : (int) $this->fk_docdet).
',';
699 $sql .=
' '.(!isset($this->thirdparty_code) ?
'NULL' :
"'".$this->db->escape($this->thirdparty_code).
"'").
',';
700 $sql .=
' '.(!isset($this->subledger_account) ?
'NULL' :
"'".$this->db->escape($this->subledger_account).
"'").
',';
701 $sql .=
' '.(!isset($this->subledger_label) ?
'NULL' :
"'".$this->db->escape($this->subledger_label).
"'").
',';
702 $sql .=
' '.(!isset($this->numero_compte) ?
'NULL' :
"'".$this->db->escape($this->numero_compte).
"'").
',';
703 $sql .=
' '.(!isset($this->label_compte) ?
'NULL' :
"'".$this->db->escape($this->label_compte).
"'").
',';
704 $sql .=
' '.(!isset($this->label_operation) ?
'NULL' :
"'".$this->db->escape($this->label_operation).
"'").
',';
705 $sql .=
' '.(!isset($this->debit) ?
'NULL' : $this->debit).
',';
706 $sql .=
' '.(!isset($this->credit) ?
'NULL' : $this->credit).
',';
707 $sql .=
' '.(!isset($this->montant) ?
'NULL' : $this->montant).
',';
708 $sql .=
' '.(!isset($this->sens) ?
'NULL' :
"'".$this->db->escape($this->sens).
"'").
',';
709 $sql .=
' '.((int) $user->id).
',';
710 $sql .=
' '.
"'".$this->db->idate($now).
"',";
711 $sql .=
' '.(empty($this->code_journal) ?
'NULL' :
"'".$this->db->escape($this->code_journal).
"'").
',';
712 $sql .=
' '.(empty($this->journal_label) ?
'NULL' :
"'".$this->db->escape($this->journal_label).
"'").
',';
713 $sql .=
' '.(empty($this->piece_num) ?
'NULL' : $this->db->escape($this->piece_num)).
',';
714 $sql .=
' '.(!isset($this->entity) ? $conf->entity : $this->entity);
719 $resql = $this->db->query($sql);
722 $this->errors[] =
'Error '.$this->db->lasterror();
723 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
727 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element.$mode);
732 $this->db->rollback();
750 public function fetch($id, $ref =
null, $mode =
'')
758 $sql .=
" t.doc_date,";
759 $sql .=
" t.date_lim_reglement,";
760 $sql .=
" t.doc_type,";
761 $sql .=
" t.doc_ref,";
762 $sql .=
" t.fk_doc,";
763 $sql .=
" t.fk_docdet,";
764 $sql .=
" t.thirdparty_code,";
765 $sql .=
" t.subledger_account,";
766 $sql .=
" t.subledger_label,";
767 $sql .=
" t.numero_compte,";
768 $sql .=
" t.label_compte,";
769 $sql .=
" t.label_operation,";
771 $sql .=
" t.credit,";
772 $sql .=
" t.montant as amount,";
774 $sql .=
" t.fk_user_author,";
775 $sql .=
" t.import_key,";
776 $sql .=
" t.code_journal,";
777 $sql .=
" t.journal_label,";
778 $sql .=
" t.piece_num,";
779 $sql .=
" t.date_creation,";
781 if ($mode !=
"_tmp") {
782 $sql .=
" t.date_export,";
784 $sql .=
" t.date_validated as date_validation";
785 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.$mode.
' as t';
786 $sql .=
' WHERE 1 = 1';
787 $sql .=
" AND entity = " . ((int) $conf->entity);
789 $sql .=
" AND t.rowid = ".((int) $ref);
791 $sql .=
" AND t.rowid = ".((int) $id);
794 $resql = $this->db->query($sql);
796 $numrows = $this->db->num_rows($resql);
798 $obj = $this->db->fetch_object($resql);
800 $this->
id = $obj->rowid;
802 $this->doc_date = $this->db->jdate($obj->doc_date);
803 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
804 $this->doc_type = $obj->doc_type;
805 $this->doc_ref = $obj->doc_ref;
806 $this->fk_doc = $obj->fk_doc;
807 $this->fk_docdet = $obj->fk_docdet;
808 $this->thirdparty_code = $obj->thirdparty_code;
809 $this->subledger_account = $obj->subledger_account;
810 $this->subledger_label = $obj->subledger_label;
811 $this->numero_compte = $obj->numero_compte;
812 $this->label_compte = $obj->label_compte;
813 $this->label_operation = $obj->label_operation;
814 $this->debit = $obj->debit;
815 $this->credit = $obj->credit;
816 $this->montant = $obj->amount;
817 $this->amount = $obj->amount;
818 $this->sens = $obj->sens;
819 $this->fk_user_author = $obj->fk_user_author;
820 $this->import_key = $obj->import_key;
821 $this->code_journal = $obj->code_journal;
822 $this->journal_label = $obj->journal_label;
823 $this->piece_num = $obj->piece_num;
824 $this->date_creation = $this->db->jdate($obj->date_creation);
825 $this->date_export = $this->db->jdate($obj->date_export);
826 $this->date_validation = isset($obj->date_validation) ? $this->db->jdate($obj->date_validation) :
'';
828 $this->db->free($resql);
836 $this->errors[] =
'Error '.$this->db->lasterror();
837 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
750 public function fetch($id, $ref =
null, $mode =
'') {
…}
857 public function fetchAllByAccount($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND', $option = 0, $countonly = 0)
863 $this->lines = array();
868 $sql .=
' COUNT(t.rowid) as nb';
871 $sql .=
" t.doc_date,";
872 $sql .=
" t.doc_type,";
873 $sql .=
" t.doc_ref,";
874 $sql .=
" t.fk_doc,";
875 $sql .=
" t.fk_docdet,";
876 $sql .=
" t.thirdparty_code,";
877 $sql .=
" t.subledger_account,";
878 $sql .=
" t.subledger_label,";
879 $sql .=
" t.numero_compte,";
880 $sql .=
" t.label_compte,";
881 $sql .=
" t.label_operation,";
883 $sql .=
" t.credit,";
884 $sql .=
" t.montant as amount,";
886 $sql .=
" t.multicurrency_amount,";
887 $sql .=
" t.multicurrency_code,";
888 $sql .=
" t.lettering_code,";
889 $sql .=
" t.date_lettering,";
890 $sql .=
" t.fk_user_author,";
891 $sql .=
" t.import_key,";
892 $sql .=
" t.code_journal,";
893 $sql .=
" t.journal_label,";
894 $sql .=
" t.piece_num,";
895 $sql .=
" t.date_creation,";
896 $sql .=
" t.date_export,";
897 $sql .=
" t.date_validated as date_validation,";
898 $sql .=
" t.import_key";
902 if (count($filter) > 0) {
903 foreach ($filter as $key => $value) {
904 if ($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.doc_date>') {
909 $sqlwhere[] =
"t.doc_date > '".$this->db->idate($value).
"'";
910 } elseif ($key ==
't.doc_date<') {
911 $sqlwhere[] =
"t.doc_date < '".$this->db->idate($value).
"'";
912 } elseif ($key ==
't.numero_compte>=') {
913 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
914 } elseif ($key ==
't.numero_compte<=') {
915 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
916 } elseif ($key ==
't.subledger_account>=') {
917 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
918 } elseif ($key ==
't.subledger_account<=') {
919 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
920 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
921 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
922 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
923 $sqlwhere[] = $this->db->sanitize($key).
' LIKE \''.$this->db->escape($this->db->escapeforlike($value)).
'%\'';
924 } elseif ($key ==
't.date_creation>=') {
925 $sqlwhere[] =
't.date_creation >= \''.$this->db->idate($value).
'\'';
926 } elseif ($key ==
't.date_creation<=') {
927 $sqlwhere[] =
't.date_creation <= \''.$this->db->idate($value).
'\'';
928 } elseif ($key ==
't.date_export>=') {
929 $sqlwhere[] =
't.date_export >= \''.$this->db->idate($value).
'\'';
930 } elseif ($key ==
't.date_export<=') {
931 $sqlwhere[] =
't.date_export <= \''.$this->db->idate($value).
'\'';
932 } elseif ($key ==
't.date_validated>=') {
933 $sqlwhere[] =
't.date_validated >= \''.$this->db->idate($value).
'\'';
934 } elseif ($key ==
't.date_validated<=') {
935 $sqlwhere[] =
't.date_validated <= \''.$this->db->idate($value).
'\'';
936 } elseif ($key ==
't.credit' || $key ==
't.debit') {
938 } elseif ($key ==
't.reconciled_option') {
939 $sqlwhere[] =
't.lettering_code IS NULL';
940 } elseif ($key ==
't.code_journal' && !empty($value)) {
941 if (is_array($value)) {
942 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
946 } elseif ($key ==
't.search_accounting_code_in' && !empty($value)) {
947 $sqlwhere[] =
't.numero_compte IN ('.$this->db->sanitize($value, 1).
')';
953 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
954 $sql .=
' WHERE entity = ' . ((int) $conf->entity);
955 if (count($sqlwhere) > 0) {
956 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
959 if (!empty($option)) {
960 $sql .=
" AND t.subledger_account IS NOT NULL";
961 $sql .=
" AND t.subledger_account <> ''";
962 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
963 $sortorder =
'ASC'.($sortfield ?
','.$sortfield :
'');
965 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
966 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
970 $sql .= $this->db->order($sortfield, $sortorder);
971 if (!empty($limit)) {
972 $sql .= $this->db->plimit($limit + 1, $offset);
976 $resql = $this->db->query($sql);
979 $obj = $this->db->fetch_object($resql);
984 $num = $this->db->num_rows($resql);
987 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
990 $line->id = $obj->rowid;
992 $line->doc_date = $this->db->jdate($obj->doc_date);
993 $line->doc_type = $obj->doc_type;
994 $line->doc_ref = $obj->doc_ref;
995 $line->fk_doc = $obj->fk_doc;
996 $line->fk_docdet = $obj->fk_docdet;
997 $line->thirdparty_code = $obj->thirdparty_code;
998 $line->subledger_account = $obj->subledger_account;
999 $line->subledger_label = $obj->subledger_label;
1000 $line->numero_compte = $obj->numero_compte;
1001 $line->label_compte = $obj->label_compte;
1002 $line->label_operation = $obj->label_operation;
1003 $line->debit = $obj->debit;
1004 $line->credit = $obj->credit;
1005 $line->montant = $obj->amount;
1006 $line->amount = $obj->amount;
1007 $line->sens = $obj->sens;
1008 $line->multicurrency_amount = $obj->multicurrency_amount;
1009 $line->multicurrency_code = $obj->multicurrency_code;
1010 $line->lettering_code = $obj->lettering_code;
1011 $line->date_lettering = $obj->date_lettering;
1012 $line->fk_user_author = $obj->fk_user_author;
1013 $line->import_key = $obj->import_key;
1014 $line->code_journal = $obj->code_journal;
1015 $line->journal_label = $obj->journal_label;
1016 $line->piece_num = $obj->piece_num;
1017 $line->date_creation = $this->db->jdate($obj->date_creation);
1018 $line->date_export = $this->db->jdate($obj->date_export);
1019 $line->date_validation = $this->db->jdate($obj->date_validation);
1020 $line->import_key = $obj->import_key;
1022 $this->lines[] = $line;
1027 $this->db->free($resql);
1031 $this->errors[] =
'Error '.$this->db->lasterror();
1032 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
857 public function fetchAllByAccount($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND', $option = 0, $countonly = 0) {
…}
1050 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $showAlreadyExportMovements = 1)
1057 $sql .=
' t.rowid,';
1058 $sql .=
" t.doc_date,";
1059 $sql .=
" t.doc_type,";
1060 $sql .=
" t.doc_ref,";
1061 $sql .=
" t.fk_doc,";
1062 $sql .=
" t.fk_docdet,";
1063 $sql .=
" t.thirdparty_code,";
1064 $sql .=
" t.subledger_account,";
1065 $sql .=
" t.subledger_label,";
1066 $sql .=
" t.numero_compte,";
1067 $sql .=
" t.label_compte,";
1068 $sql .=
" t.label_operation,";
1069 $sql .=
" t.debit,";
1070 $sql .=
" t.credit,";
1071 $sql .=
" t.lettering_code,";
1072 $sql .=
" t.date_lettering,";
1073 $sql .=
" t.montant as amount,";
1075 $sql .=
" t.fk_user_author,";
1076 $sql .=
" t.import_key,";
1077 $sql .=
" t.code_journal,";
1078 $sql .=
" t.journal_label,";
1079 $sql .=
" t.piece_num,";
1080 $sql .=
" t.date_creation,";
1081 $sql .=
" t.date_lim_reglement,";
1082 $sql .=
" t.tms as date_modification,";
1083 $sql .=
" t.date_export,";
1084 $sql .=
" t.date_validated as date_validation";
1085 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1087 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
1088 if ($showAlreadyExportMovements == 0) {
1089 $sql .=
" AND t.date_export IS NULL";
1093 if (is_array($filter)) {
1094 dol_syslog(
"You are using a deprecated use of fetchAll. filter parameter mus be an USF string now.", LOG_WARNING);
1095 $sqlwhere = array();
1096 if (count($filter) > 0) {
1097 foreach ($filter as $key => $value) {
1098 if ($key ==
't.doc_date') {
1099 $sqlwhere[] = $this->db->sanitize($key).
' = \''.$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.doc_date>') {
1105 $sqlwhere[] =
"t.doc_date > '".$this->db->idate($value).
"'";
1106 } elseif ($key ==
't.doc_date<') {
1107 $sqlwhere[] =
"t.doc_date < '".$this->db->idate($value).
"'";
1108 } elseif ($key ==
't.numero_compte>=') {
1109 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1110 } elseif ($key ==
't.numero_compte<=') {
1111 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1112 } elseif ($key ==
't.subledger_account>=') {
1113 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1114 } elseif ($key ==
't.subledger_account<=') {
1115 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1116 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1117 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
1118 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1119 $sqlwhere[] = $this->db->sanitize($key).
' LIKE \''.$this->db->escape($value).
'%\'';
1120 } elseif ($key ==
't.date_creation>=') {
1121 $sqlwhere[] =
't.date_creation >= \''.$this->db->idate($value).
'\'';
1122 } elseif ($key ==
't.date_creation<=') {
1123 $sqlwhere[] =
't.date_creation <= \''.$this->db->idate($value).
'\'';
1124 } elseif ($key ==
't.tms>=') {
1125 $sqlwhere[] =
't.tms >= \''.$this->db->idate($value).
'\'';
1126 } elseif ($key ==
't.tms<=') {
1127 $sqlwhere[] =
't.tms <= \''.$this->db->idate($value).
'\'';
1128 } elseif ($key ==
't.date_export>=') {
1129 $sqlwhere[] =
't.date_export >= \''.$this->db->idate($value).
'\'';
1130 } elseif ($key ==
't.date_export<=') {
1131 $sqlwhere[] =
't.date_export <= \''.$this->db->idate($value).
'\'';
1132 } elseif ($key ==
't.date_validated>=') {
1133 $sqlwhere[] =
't.date_validated >= \''.$this->db->idate($value).
'\'';
1134 } elseif ($key ==
't.date_validated<=') {
1135 $sqlwhere[] =
't.date_validated <= \''.$this->db->idate($value).
'\'';
1136 } elseif ($key ==
't.credit' || $key ==
't.debit') {
1138 } elseif ($key ==
't.code_journal' && !empty($value)) {
1139 if (is_array($value)) {
1140 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1149 if (count($sqlwhere) > 0) {
1150 $sql .=
' AND '.implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1159 if ($errormessage) {
1160 $this->errors[] = $errormessage;
1161 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1165 if (!empty($sortfield)) {
1166 $sql .= $this->db->order($sortfield, $sortorder);
1168 if (!empty($limit)) {
1169 $sql .= $this->db->plimit($limit + 1, $offset);
1171 $this->lines = array();
1173 $resql = $this->db->query($sql);
1175 $num = $this->db->num_rows($resql);
1178 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1181 $line->id = $obj->rowid;
1183 $line->doc_date = $this->db->jdate($obj->doc_date);
1184 $line->doc_type = $obj->doc_type;
1185 $line->doc_ref = $obj->doc_ref;
1186 $line->fk_doc = $obj->fk_doc;
1187 $line->fk_docdet = $obj->fk_docdet;
1188 $line->thirdparty_code = $obj->thirdparty_code;
1189 $line->subledger_account = $obj->subledger_account;
1190 $line->subledger_label = $obj->subledger_label;
1191 $line->numero_compte = $obj->numero_compte;
1192 $line->label_compte = $obj->label_compte;
1193 $line->label_operation = $obj->label_operation;
1194 $line->debit = $obj->debit;
1195 $line->credit = $obj->credit;
1196 $line->montant = $obj->amount;
1197 $line->amount = $obj->amount;
1198 $line->sens = $obj->sens;
1199 $line->lettering_code = $obj->lettering_code;
1200 $line->date_lettering = $obj->date_lettering;
1201 $line->fk_user_author = $obj->fk_user_author;
1202 $line->import_key = $obj->import_key;
1203 $line->code_journal = $obj->code_journal;
1204 $line->journal_label = $obj->journal_label;
1205 $line->piece_num = $obj->piece_num;
1206 $line->date_creation = $this->db->jdate($obj->date_creation);
1207 $line->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1208 $line->date_modification = $this->db->jdate($obj->date_modification);
1209 $line->date_export = $this->db->jdate($obj->date_export);
1210 $line->date_validation = $this->db->jdate($obj->date_validation);
1212 $this->lines[] = $line;
1216 $this->db->free($resql);
1220 $this->errors[] =
'Error '.$this->db->lasterror();
1221 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1050 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $showAlreadyExportMovements = 1) {
…}
1238 public function fetchAllBalance($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $option = 0)
1242 $this->lines = array();
1247 $sql .=
" t.numero_compte,";
1248 if (!empty($option)) {
1249 $sql .=
" t.subledger_account,";
1250 $sql .=
" t.subledger_label,";
1252 $sql .=
" SUM(t.debit) as debit,";
1253 $sql .=
" SUM(t.credit) as credit";
1254 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
1255 $sql .=
' WHERE entity = ' . ((int) $conf->entity);
1258 if (is_array($filter)) {
1259 $sqlwhere = array();
1260 if (count($filter) > 0) {
1261 foreach ($filter as $key => $value) {
1262 if ($key ==
't.doc_date') {
1263 $sqlwhere[] = $this->db->sanitize($key).
" = '".$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.doc_date>') {
1269 $sqlwhere[] =
"t.doc_date > '".$this->db->idate($value).
"'";
1270 } elseif ($key ==
't.doc_date<') {
1271 $sqlwhere[] =
"t.doc_date < '".$this->db->idate($value).
"'";
1272 } elseif ($key ==
't.numero_compte>=') {
1273 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1274 } elseif ($key ==
't.numero_compte<=') {
1275 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1276 } elseif ($key ==
't.subledger_account>=') {
1277 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1278 } elseif ($key ==
't.subledger_account<=') {
1279 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1280 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1281 $sqlwhere[] = $this->db->sanitize($key).
" = ".((int) $value);
1282 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1283 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1284 } elseif ($key ==
't.subledger_label') {
1285 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1286 } elseif ($key ==
't.code_journal' && !empty($value)) {
1287 if (is_array($value)) {
1288 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1292 } elseif ($key ==
't.reconciled_option') {
1293 $sqlwhere[] =
't.lettering_code IS NULL';
1295 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
1299 if (count($sqlwhere) > 0) {
1300 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1309 if ($errormessage) {
1310 $this->errors[] = $errormessage;
1311 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1315 if (!empty($option)) {
1316 $sql .=
" AND t.subledger_account IS NOT NULL";
1317 $sql .=
" AND t.subledger_account <> ''";
1318 $sql .=
" GROUP BY t.numero_compte, t.subledger_account, t.subledger_label";
1319 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
1320 $sortorder =
'ASC'.($sortfield ?
','.$sortfield :
'');
1322 $sql .=
' GROUP BY t.numero_compte';
1323 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
1324 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1327 if (!empty($sortfield)) {
1328 $sql .= $this->db->order($sortfield, $sortorder);
1330 if (!empty($limit)) {
1331 $sql .= $this->db->plimit($limit + 1, $offset);
1335 $resql = $this->db->query($sql);
1338 $num = $this->db->num_rows($resql);
1341 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1344 $line->numero_compte = $obj->numero_compte;
1346 if (!empty($option)) {
1347 $line->subledger_account = $obj->subledger_account;
1348 $line->subledger_label = $obj->subledger_label;
1350 $line->debit = $obj->debit;
1351 $line->credit = $obj->credit;
1353 $this->lines[] = $line;
1357 $this->db->free($resql);
1361 $this->errors[] =
'Error '.$this->db->lasterror();
1362 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1238 public function fetchAllBalance($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $option = 0) {
…}
1384 if (isset($this->doc_type)) {
1385 $this->doc_type = trim($this->doc_type);
1387 if (isset($this->doc_ref)) {
1388 $this->doc_ref = trim($this->doc_ref);
1390 if (isset($this->fk_doc)) {
1391 $this->fk_doc = (int) $this->fk_doc;
1393 if (isset($this->fk_docdet)) {
1394 $this->fk_docdet = (int) $this->fk_docdet;
1396 if (isset($this->thirdparty_code)) {
1397 $this->thirdparty_code = trim($this->thirdparty_code);
1399 if (isset($this->subledger_account)) {
1400 $this->subledger_account = trim($this->subledger_account);
1402 if (isset($this->subledger_label)) {
1403 $this->subledger_label = trim($this->subledger_label);
1405 if (isset($this->numero_compte)) {
1406 $this->numero_compte = trim($this->numero_compte);
1408 if (isset($this->label_compte)) {
1409 $this->label_compte = trim($this->label_compte);
1411 if (isset($this->label_operation)) {
1412 $this->label_operation = trim($this->label_operation);
1414 if (isset($this->sens)) {
1415 $this->sens = trim($this->sens);
1417 if (isset($this->import_key)) {
1418 $this->import_key = trim($this->import_key);
1420 if (isset($this->code_journal)) {
1421 $this->code_journal = trim($this->code_journal);
1423 if (isset($this->journal_label)) {
1424 $this->journal_label = trim($this->journal_label);
1426 if (isset($this->piece_num)) {
1427 $this->piece_num = (int) $this->piece_num;
1433 } elseif ($result == 0) {
1435 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1437 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1442 $this->debit = (float)
price2num($this->debit,
'MT');
1443 $this->credit = (float)
price2num($this->credit,
'MT');
1444 $this->montant = (float)
price2num($this->montant,
'MT');
1450 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.$mode.
' SET';
1451 $sql .=
' doc_date = '.(!isset($this->doc_date) ||
dol_strlen($this->doc_date) != 0 ?
"'".$this->db->idate($this->doc_date).
"'" :
'null').
',';
1452 $sql .=
' doc_type = '.(isset($this->doc_type) ?
"'".$this->db->escape($this->doc_type).
"'" :
"null").
',';
1453 $sql .=
' doc_ref = '.(isset($this->doc_ref) ?
"'".$this->db->escape($this->doc_ref).
"'" :
"null").
',';
1454 $sql .=
' fk_doc = '.(isset($this->fk_doc) ? $this->fk_doc :
"null").
',';
1455 $sql .=
' fk_docdet = '.(isset($this->fk_docdet) ? $this->fk_docdet :
"null").
',';
1456 $sql .=
' thirdparty_code = '.(isset($this->thirdparty_code) ?
"'".$this->db->escape($this->thirdparty_code).
"'" :
"null").
',';
1457 $sql .=
' subledger_account = '.(isset($this->subledger_account) ?
"'".$this->db->escape($this->subledger_account).
"'" :
"null").
',';
1458 $sql .=
' subledger_label = '.(isset($this->subledger_label) ?
"'".$this->db->escape($this->subledger_label).
"'" :
"null").
',';
1459 $sql .=
' numero_compte = '.(isset($this->numero_compte) ?
"'".$this->db->escape($this->numero_compte).
"'" :
"null").
',';
1460 $sql .=
' label_compte = '.(isset($this->label_compte) ?
"'".$this->db->escape($this->label_compte).
"'" :
"null").
',';
1461 $sql .=
' label_operation = '.(isset($this->label_operation) ?
"'".$this->db->escape($this->label_operation).
"'" :
"null").
',';
1462 $sql .=
' debit = '.(isset($this->debit) ? $this->debit :
"null").
',';
1463 $sql .=
' credit = '.(isset($this->credit) ? $this->credit :
"null").
',';
1464 $sql .=
' montant = '.(isset($this->montant) ? $this->montant :
"null").
',';
1465 $sql .=
' sens = '.(isset($this->sens) ?
"'".$this->db->escape($this->sens).
"'" :
"null").
',';
1466 $sql .=
' fk_user_author = '.(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
',';
1467 $sql .=
' import_key = '.(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
',';
1468 $sql .=
' code_journal = '.(isset($this->code_journal) ?
"'".$this->db->escape($this->code_journal).
"'" :
"null").
',';
1469 $sql .=
' journal_label = '.(isset($this->journal_label) ?
"'".$this->db->escape($this->journal_label).
"'" :
"null").
',';
1470 $sql .=
' piece_num = '.(isset($this->piece_num) ? $this->piece_num :
"null");
1471 $sql .=
' WHERE rowid='.((int) $this->
id);
1475 $resql = $this->db->query($sql);
1478 $this->errors[] =
'Error '.$this->db->lasterror();
1479 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1494 $this->db->rollback();
1498 $this->db->commit();
1513 public function updateByMvt($piece_num =
'', $field =
'', $value =
'', $mode =
'')
1518 if (!isset($sql_filter)) {
1524 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.$mode;
1525 $sql .=
" SET ".$this->db->sanitize($field).
" = ".(is_numeric($value) ? ((float) $value) :
"'".$this->db->escape($value).
"'");
1526 $sql .=
" WHERE piece_num = ".((int) $piece_num);
1527 $sql .= $sql_filter;
1529 $resql = $this->db->query($sql);
1533 $this->errors[] =
'Error '.$this->db->lasterror();
1534 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1537 $this->db->rollback();
1541 $this->db->commit();
1513 public function updateByMvt($piece_num =
'', $field =
'', $value =
'', $mode =
'') {
…}
1555 public function delete(
User $user, $notrigger = 0, $mode =
'')
1564 } elseif ($result == 0) {
1566 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1568 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1588 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.$mode;
1589 $sql .=
' WHERE rowid='.((int) $this->
id);
1591 $resql = $this->db->query($sql);
1594 $this->errors[] =
'Error '.$this->db->lasterror();
1595 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1601 $this->db->rollback();
1605 $this->db->commit();
1555 public function delete(
User $user, $notrigger = 0, $mode =
'') {
…}
1623 if (!isset($sql_filter)) {
1629 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1630 $sql .=
" WHERE import_key = '".$this->db->escape($importkey).
"'";
1631 $sql .= $sql_filter;
1633 $resql = $this->db->query($sql);
1636 $this->errors[] =
"Error ".$this->db->lasterror();
1637 dol_syslog(get_class($this).
"::delete Error ".$this->db->lasterror(), LOG_ERR);
1638 $this->db->rollback();
1642 $this->db->commit();
1657 global $conf, $langs;
1659 if (empty($delyear) && empty($journal)) {
1660 $this->error =
'ErrorOneFieldRequired';
1663 if (!empty($delmonth) && empty($delyear)) {
1664 $this->error =
'YearRequiredIfMonthDefined';
1669 if (!isset($sql_filter)) {
1677 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1678 $sql .=
" WHERE 1 = 1";
1680 if (!empty($journal)) {
1681 $sql .=
" AND code_journal = '".$this->db->escape($journal).
"'";
1683 $sql .=
" AND entity = " . ((int) $conf->entity);
1685 $sql .=
" AND date_validated IS NULL";
1686 $sql .= $sql_filter;
1690 $resql = $this->db->query($sql);
1693 $this->errors[] =
"Error ".$this->db->lasterror();
1694 foreach ($this->errors as $errmsg) {
1695 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1696 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1698 $this->db->rollback();
1702 $this->db->commit();
1718 if (!isset($sql_filter)) {
1728 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1729 $sql .=
" WHERE piece_num = ".(int) $piecenum;
1730 $sql .=
" AND date_validated IS NULL";
1731 $sql .=
" AND entity = " . ((int) $conf->entity);
1732 $sql .= $sql_filter;
1734 $resql = $this->db->query($sql);
1737 $this->errors[] =
"Error ".$this->db->lasterror();
1738 foreach ($this->errors as $errmsg) {
1739 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1740 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1742 $this->db->rollback();
1745 $nbprocessed = $this->db->affected_rows($resql);
1748 $this->db->commit();
1750 return $nbprocessed;
1778 $object->context[
'createfromclone'] =
'createfromclone';
1779 $result =
$object->create($user);
1784 $this->errors =
$object->errors;
1785 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1788 unset(
$object->context[
'createfromclone']);
1792 $this->db->commit();
1796 $this->db->rollback();
1815 $this->doc_date = $now;
1816 $this->doc_type =
'';
1817 $this->doc_ref =
'';
1819 $this->fk_docdet = 0;
1820 $this->thirdparty_code =
'CU001';
1821 $this->subledger_account =
'41100001';
1822 $this->subledger_label =
'My customer company';
1823 $this->numero_compte =
'411';
1824 $this->label_compte =
'Customer';
1825 $this->label_operation =
'Sales of pea';
1826 $this->debit = 99.9;
1827 $this->credit = 0.0;
1828 $this->amount = 0.0;
1830 $this->fk_user_author = $user->id;
1831 $this->import_key =
'20201027';
1832 $this->code_journal =
'VT';
1833 $this->journal_label =
'Journal de vente';
1834 $this->piece_num = 1234;
1835 $this->date_creation = $now;
1851 $sql =
"SELECT piece_num, doc_date, code_journal, journal_label, doc_ref, doc_type,";
1852 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation, import_key";
1854 if ($mode !=
"_tmp") {
1855 $sql .=
", date_export";
1857 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1858 $sql .=
" WHERE piece_num = ".((int) $piecenum);
1859 $sql .=
" AND entity = " . ((int) $conf->entity);
1862 $result = $this->db->query($sql);
1864 $obj = $this->db->fetch_object($result);
1866 $this->piece_num = $obj->piece_num;
1867 $this->code_journal = $obj->code_journal;
1868 $this->journal_label = $obj->journal_label;
1869 $this->doc_date = $this->db->jdate($obj->doc_date);
1870 $this->doc_ref = $obj->doc_ref;
1871 $this->doc_type = $obj->doc_type;
1872 $this->date_creation = $this->db->jdate($obj->date_creation);
1873 $this->date_modification = $this->db->jdate($obj->date_modification);
1874 if ($mode !=
"_tmp") {
1875 $this->date_export = $this->db->jdate($obj->date_export);
1877 $this->date_validation = $this->db->jdate($obj->date_validation);
1878 $this->import_key = $obj->import_key;
1880 $this->error =
"Error ".$this->db->lasterror();
1881 dol_syslog(__METHOD__.$this->error, LOG_ERR);
1898 $sql =
"SELECT MAX(piece_num)+1 as max FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1899 $sql .=
" WHERE entity = " . ((int) $conf->entity);
1901 dol_syslog(get_class($this).
"::getNextNumMvt", LOG_DEBUG);
1903 $result = $this->db->query($sql);
1906 $obj = $this->db->fetch_object($result);
1908 $result = $obj->max;
1910 if (empty($result)) {
1915 $this->error =
"Error ".$this->db->lasterror();
1916 dol_syslog(get_class($this).
"::getNextNumMvt ".$this->error, LOG_ERR);
1932 $sql =
"SELECT rowid, doc_date, doc_type,";
1933 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
1934 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
1935 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, journal_label, piece_num,";
1936 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation";
1938 if ($mode !=
"_tmp") {
1939 $sql .=
", date_export";
1941 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
1942 $sql .=
" WHERE piece_num = ".((int) $piecenum);
1943 $sql .=
" AND entity = " . ((int) $conf->entity);
1946 $result = $this->db->query($sql);
1948 while ($obj = $this->db->fetch_object($result)) {
1951 $line->id = $obj->rowid;
1953 $line->doc_date = $this->db->jdate($obj->doc_date);
1954 $line->doc_type = $obj->doc_type;
1955 $line->doc_ref = $obj->doc_ref;
1956 $line->fk_doc = $obj->fk_doc;
1957 $line->fk_docdet = $obj->fk_docdet;
1958 $line->thirdparty_code = $obj->thirdparty_code;
1959 $line->subledger_account = $obj->subledger_account;
1960 $line->subledger_label = $obj->subledger_label;
1961 $line->numero_compte = $obj->numero_compte;
1962 $line->label_compte = $obj->label_compte;
1963 $line->label_operation = $obj->label_operation;
1964 $line->debit = $obj->debit;
1965 $line->credit = $obj->credit;
1966 $line->montant = $obj->amount;
1967 $line->amount = $obj->amount;
1968 $line->sens = $obj->sens;
1969 $line->code_journal = $obj->code_journal;
1970 $line->journal_label = $obj->journal_label;
1971 $line->piece_num = $obj->piece_num;
1972 $line->date_creation = $obj->date_creation;
1973 $line->date_modification = $obj->date_modification;
1974 if ($mode !=
"_tmp") {
1975 $line->date_export = $obj->date_export;
1977 $line->date_validation = $obj->date_validation;
1979 $this->linesmvt[] = $line;
1982 $this->error =
"Error ".$this->db->lasterror();
1983 dol_syslog(__METHOD__.$this->error, LOG_ERR);
2002 $sql =
"SELECT rowid, doc_date, doc_type,";
2003 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
2004 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
2005 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, piece_num,";
2006 $sql .=
" date_validated as date_validation";
2007 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
2008 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2010 dol_syslog(get_class($this).
"::export_bookkeeping", LOG_DEBUG);
2012 $resql = $this->db->query($sql);
2015 $this->linesexport = array();
2017 $num = $this->db->num_rows($resql);
2018 while ($obj = $this->db->fetch_object($resql)) {
2021 $line->id = $obj->rowid;
2023 $line->doc_date = $this->db->jdate($obj->doc_date);
2024 $line->doc_type = $obj->doc_type;
2025 $line->doc_ref = $obj->doc_ref;
2026 $line->fk_doc = $obj->fk_doc;
2027 $line->fk_docdet = $obj->fk_docdet;
2028 $line->thirdparty_code = $obj->thirdparty_code;
2029 $line->subledger_account = $obj->subledger_account;
2030 $line->subledger_label = $obj->subledger_label;
2031 $line->numero_compte = $obj->numero_compte;
2032 $line->label_compte = $obj->label_compte;
2033 $line->label_operation = $obj->label_operation;
2034 $line->debit = $obj->debit;
2035 $line->credit = $obj->credit;
2036 $line->montant = $obj->amount;
2037 $line->amount = $obj->amount;
2038 $line->sens = $obj->sens;
2039 $line->code_journal = $obj->code_journal;
2040 $line->piece_num = $obj->piece_num;
2041 $line->date_validation = $obj->date_validation;
2043 $this->linesexport[] = $line;
2045 $this->db->free($resql);
2049 $this->error =
"Error ".$this->db->lasterror();
2050 dol_syslog(get_class($this).
"::export_bookkeeping ".$this->error, LOG_ERR);
2070 if (!isset($sql_filter)) {
2076 if ($direction == 0) {
2080 if ($next_piecenum < 0) {
2086 $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";
2087 $resql = $this->db->query($sql);
2090 $this->errors[] =
'Error '.$this->db->lasterror();
2091 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2096 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
' (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, piece_num, date_creation)';
2100 $sql .=
' SELECT doc_date, doc_type,';
2101 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2102 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2103 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.((int) $next_piecenum).
", '".$this->db->idate($now).
"'";
2104 $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);
2105 $sql .= $sql_filter;
2106 $resql = $this->db->query($sql);
2109 $this->errors[] =
'Error '.$this->db->lasterror();
2110 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2115 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2116 $resql = $this->db->query($sql);
2119 $this->errors[] =
'Error '.$this->db->lasterror();
2120 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2123 } elseif ($direction == 1) {
2125 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2126 $resql = $this->db->query($sql);
2129 $this->errors[] =
'Error '.$this->db->lasterror();
2130 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2135 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.
'_tmp (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 .=
' SELECT doc_date, doc_type,';
2140 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2141 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2142 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num';
2143 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2144 $sql .= $sql_filter;
2145 $resql = $this->db->query($sql);
2148 $this->errors[] =
'Error '.$this->db->lasterror();
2149 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2154 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2155 $sql .= $sql_filter;
2156 $resql = $this->db->query($sql);
2159 $this->errors[] =
'Error '.$this->db->lasterror();
2160 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2165 $this->db->commit();
2168 $this->db->rollback();
2196 public function select_account($selectid, $htmlname =
'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase =
'')
2201 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
2205 $sql =
"SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version";
2206 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab";
2207 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as aa ON aa.account_number = ab.numero_compte";
2208 $sql .=
" AND aa.active = 1";
2209 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2210 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2211 $sql .=
" AND ab.entity = " . ((int) $conf->entity);
2212 $sql .=
" ORDER BY account_number ASC";
2214 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2215 $resql = $this->db->query($sql);
2218 $this->error =
"Error ".$this->db->lasterror();
2219 dol_syslog(get_class($this).
"::select_account ".$this->error, LOG_ERR);
2228 while ($obj = $this->db->fetch_object($resql)) {
2231 $select_value_in = $obj->rowid;
2232 $select_value_out = $obj->rowid;
2234 if ($select_in == 1) {
2235 $select_value_in = $obj->account_number;
2237 if ($select_out == 1) {
2238 $select_value_out = $obj->account_number;
2243 if (($selectid !=
'') && $selectid == $select_value_in) {
2244 $selected = $select_value_out;
2247 $options[$select_value_out] = $label;
2250 $out .=
Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0,
'', 0, 0, 0,
'',
'maxwidth300');
2251 $this->db->free($resql);
2196 public function select_account($selectid, $htmlname =
'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase =
'') {
…}
2267 $sql =
"SELECT root.rowid, root.account_number, root.label as label,";
2268 $sql .=
" parent.rowid as parent_rowid, parent.account_number as parent_account_number, parent.label as parent_label";
2269 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_account as aa";
2270 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2271 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2272 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as parent ON aa.account_parent = parent.rowid AND parent.active = 1";
2273 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"accounting_account as root ON parent.account_parent = root.rowid AND root.active = 1";
2274 $sql .=
" WHERE aa.account_number = '".$this->db->escape($account).
"'";
2275 $sql .=
" AND aa.entity = " . ((int) $conf->entity);
2277 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2278 $resql = $this->db->query($sql);
2281 if ($this->db->num_rows($resql)) {
2282 $obj = $this->db->fetch_object($resql);
2285 $result = array(
'id' => $obj->rowid,
'account_number' => $obj->account_number,
'label' => $obj->label);
2288 $this->error =
"Error ".$this->db->lasterror();
2289 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2308 $sql =
"SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
2309 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_account as aa ";
2310 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2311 $sql .=
" AND aa.account_number = '".$this->db->escape($account).
"'";
2312 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2313 $sql .=
" AND aa.active = 1";
2314 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
2315 $sql .=
" WHERE aa.entity = " . ((int) $conf->entity);
2317 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2318 $resql = $this->db->query($sql);
2321 if ($this->db->num_rows($resql)) {
2322 $obj = $this->db->fetch_object($resql);
2324 if (empty($obj->category)) {
2327 return $obj->label.
' ('.$obj->category.
')';
2330 $this->error =
"Error ".$this->db->lasterror();
2331 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2347 $alias = trim($alias);
2348 $alias = !empty($alias) && strpos($alias,
'.') < 0 ? $alias .
"." : $alias;
2350 if (!isset(self::$can_modify_bookkeeping_sql_cached[$alias]) || $force) {
2356 $sql_list = array();
2357 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2359 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2360 $sql_list[$i] =
"(";
2361 $sql_list[$i] .=
"'".$this->db->idate($fiscal_period[
'date_start']) .
"' <= ".$this->db->sanitize($alias).
"doc_date";
2362 if (!empty($fiscal_period[
'date_end'])) {
2363 $sql_list[$i] .=
" AND ";
2364 $sql_list[$i] .= $this->db->sanitize($alias).
"doc_date <= '" . $this->db->idate($fiscal_period[
'date_end']).
"'";
2366 $sql_list[$i] .=
")";
2370 $sqlsanitized = implode(
' OR ', $sql_list);
2371 self::$can_modify_bookkeeping_sql_cached[$alias] = empty($sql_list) ?
"" :
" AND (".$sqlsanitized.
")";
2374 return self::$can_modify_bookkeeping_sql_cached[$alias];
2396 $result = $bookkeeping->fetch($id,
null, $mode);
2401 if (!empty($conf->cache[
'closed_fiscal_period_cached']) && is_array($conf->cache[
'closed_fiscal_period_cached'])) {
2402 foreach ($conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2403 if ($fiscal_period[
'date_start'] <= $bookkeeping->doc_date && $bookkeeping->doc_date <= $fiscal_period[
'date_end']) {
2417 $result = $bookkeeping->fetch($id,
null, $mode);
2422 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2423 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2424 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'])) {
2451 if (!empty($conf->cache[
'closed_fiscal_period_cached']) && is_array($conf->cache[
'closed_fiscal_period_cached'])) {
2452 foreach ($conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2453 if ($fiscal_period[
'date_start'] <= $date && $date <= $fiscal_period[
'date_end']) {
2466 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2467 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2468 if (!empty($fiscal_period[
'date_start']) && $fiscal_period[
'date_start'] <= $date && (empty($fiscal_period[
'date_end']) || $date <= $fiscal_period[
'date_end'])) {
2489 if ($mode ==
'active') {
2490 if (!isset($conf->cache[
'active_fiscal_period_cached']) || $force) {
2491 $sql =
"SELECT date_start, date_end";
2492 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2493 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2494 $sql .=
" AND statut = 0";
2496 $resql = $this->db->query($sql);
2498 $this->errors[] = $this->db->lasterror();
2503 while ($obj = $this->db->fetch_object($resql)) {
2505 'date_start' => $this->db->jdate($obj->date_start),
2506 'date_end' => $this->db->jdate($obj->date_end),
2509 $conf->cache[
'active_fiscal_period_cached'] = $list;
2512 if ($mode ==
'closed') {
2513 if (!isset($conf->cache[
'closed_fiscal_period_cached']) || $force) {
2514 $sql =
"SELECT date_start, date_end";
2515 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2516 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2517 $sql .=
" AND statut = 1";
2519 $resql = $this->db->query($sql);
2521 $this->errors[] = $this->db->lasterror();
2526 while ($obj = $this->db->fetch_object($resql)) {
2528 'date_start' => $this->db->jdate($obj->date_start),
2529 'date_end' => $this->db->jdate($obj->date_end),
2532 $conf->cache[
'closed_fiscal_period_cached'] = $list;
2550 $sql =
"SELECT rowid, label, date_start, date_end, statut";
2551 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2552 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2553 if (!empty($filter)) {
2554 $sql .=
" AND (" . $this->db->sanitize($filter, 1, 1, 1) .
')';
2556 $sql .= $this->db->order(
'date_start',
'ASC');
2558 $resql = $this->db->query($sql);
2560 $this->errors[] = $this->db->lasterror();
2564 while ($obj = $this->db->fetch_object($resql)) {
2565 $list[$obj->rowid] = array(
2566 'id' => (
int) $obj->rowid,
2567 'label' => $obj->label,
2568 'date_start' => $this->db->jdate($obj->date_start),
2569 'date_end' => $this->db->jdate($obj->date_end),
2570 'status' => (
int) $obj->statut,
2589 $sql =
"SELECT YEAR(b.doc_date) as year";
2590 for ($i = 1; $i <= 12; $i++) {
2591 $sql .=
", SUM(".$this->db->ifsql(
"MONTH(b.doc_date) = ".((
int) $i),
"1",
"0") .
") AS month".((int) $i);
2593 $sql .=
", COUNT(b.rowid) as total";
2594 $sql .=
" FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping as b";
2595 $sql .=
" WHERE b.doc_date >= '" . $this->db->idate($date_start) .
"'";
2596 $sql .=
" AND b.doc_date <= '" . $this->db->idate($date_end) .
"'";
2597 $sql .=
" AND b.entity IN (" .
getEntity(
'bookkeeping', 0) .
")";
2603 $sql .=
" AND b.doc_date BETWEEN 0 AND 0";
2606 $sql .=
" AND date_validated IS NULL";
2609 $sql .=
" GROUP BY YEAR(b.doc_date)";
2610 $sql .= $this->db->order(
"year",
'ASC');
2613 $resql = $this->db->query($sql);
2615 $this->errors[] = $this->db->lasterror();
2619 while ($obj = $this->db->fetch_object($resql)) {
2620 $total += (int) $obj->total;
2622 'year' => (
int) $obj->year,
2624 'total' => (
int) $obj->total,
2626 for ($i = 1; $i <= 12; $i++) {
2627 $year_list[
'count'][$i] = (int) $obj->{
'month' . $i};
2630 $list[] = $year_list;
2633 $this->db->free($resql);
2655 $sql =
" UPDATE " . MAIN_DB_PREFIX .
"accounting_bookkeeping";
2656 $sql .=
" SET date_validated = '" . $this->db->idate($now) .
"'";
2657 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2658 $sql .=
" AND DATE(doc_date) >= '" . $this->db->idate($date_start) .
"'";
2659 $sql .=
" AND DATE(doc_date) <= '" . $this->db->idate($date_end) .
"'";
2660 $sql .=
" AND date_validated IS NULL";
2663 $resql = $this->db->query($sql);
2665 $this->errors[] = $this->db->lasterror();
2685 $income_statement_amount = 0;
2687 if (
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
2688 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
2690 $pcg_type_filter = array();
2691 foreach ($accounting_groups_used_for_income_statement as $item) {
2692 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
2696 $sql .=
" t.numero_compte,";
2697 $sql .=
" aa.pcg_type,";
2698 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as accounting_result";
2699 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
2700 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'accounting_account as aa ON aa.account_number = t.numero_compte';
2701 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
2702 $sql .=
" AND aa.entity = " . ((int) $conf->entity);
2703 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM ' . MAIN_DB_PREFIX .
'accounting_system WHERE rowid = ' . ((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')) .
')';
2704 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
2705 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) .
"'";
2706 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
2707 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
2709 $resql = $this->db->query($sql);
2711 $this->errors[] =
'Error ' . $this->db->lasterror();
2712 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2714 while ($obj = $this->db->fetch_object($resql)) {
2715 $income_statement_amount += $obj->accounting_result;
2720 return (
string) $income_statement_amount;
2732 public function closeFiscalPeriod($fiscal_period_id, $new_fiscal_period_id, $separate_auxiliary_account =
false, $generate_bookkeeping_records =
true)
2734 global $conf, $langs, $user;
2737 $fiscal_period_id = max(0, $fiscal_period_id);
2738 if (empty($fiscal_period_id)) {
2739 $langs->load(
'errors');
2740 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2744 $result = $fiscal_period->fetch($fiscal_period_id);
2746 $this->error = $fiscal_period->error;
2747 $this->errors = $fiscal_period->errors;
2749 } elseif (empty($fiscal_period->id)) {
2750 $langs->loadLangs(array(
'errors',
'compta'));
2751 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
2756 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
2757 if (empty($new_fiscal_period_id)) {
2758 $langs->load(
'errors');
2759 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2762 $new_fiscal_period =
new Fiscalyear($this->db);
2763 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
2765 $this->error = $new_fiscal_period->error;
2766 $this->errors = $new_fiscal_period->errors;
2768 } elseif (empty($new_fiscal_period->id)) {
2769 $langs->loadLangs(array(
'errors',
'compta'));
2770 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
2777 $fiscal_period->statut = Fiscalyear::STATUS_CLOSED;
2778 $fiscal_period->status = Fiscalyear::STATUS_CLOSED;
2779 $result = $fiscal_period->update($user);
2781 $this->error = $fiscal_period->error;
2782 $this->errors = $fiscal_period->errors;
2786 if (!$error && !empty($generate_bookkeeping_records)) {
2788 if (empty($journal_id)) {
2789 $langs->loadLangs(array(
'errors',
'accountancy'));
2790 $this->errors[] = $langs->trans(
'ErrorBadParameters') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
2797 $result = $journal->fetch($journal_id);
2799 $this->error = $journal->error;
2800 $this->errors = $journal->errors;
2802 } elseif ($result == 0) {
2803 $langs->loadLangs(array(
'errors',
'accountancy'));
2804 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
2810 $accounting_groups_used_for_balance_sheet_account = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))),
'strlen');
2811 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
2813 $pcg_type_filter = array();
2814 $tmp = array_merge($accounting_groups_used_for_balance_sheet_account, $accounting_groups_used_for_income_statement);
2815 foreach ($tmp as $item) {
2816 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
2820 $sql .=
" t.numero_compte,";
2821 if ($separate_auxiliary_account) {
2822 $sql .=
" NULLIF(t.subledger_account, '') as subledger_account,";
2824 $sql .=
" aa.pcg_type,";
2825 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as opening_balance";
2826 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
2827 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'accounting_account as aa ON aa.account_number = t.numero_compte';
2828 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
2829 $sql .=
" AND aa.entity = ". ((int) $conf->entity);
2830 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM '.MAIN_DB_PREFIX.
'accounting_system WHERE rowid = '.((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')).
')';
2831 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
2832 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
2833 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
2834 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
2835 if ($separate_auxiliary_account) {
2836 $sql .=
" , NULLIF(t.subledger_account, '')";
2838 $sql .=
' HAVING (SUM(t.credit) - SUM(t.debit)) != 0 ';
2839 $sql .= $this->db->order(
"t.numero_compte",
"ASC");
2841 $resql = $this->db->query($sql);
2843 $this->errors[] =
'Error ' . $this->db->lasterror();
2844 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2849 $income_statement_amount = 0;
2850 while ($obj = $this->db->fetch_object($resql)) {
2851 if (in_array($obj->pcg_type, $accounting_groups_used_for_income_statement)) {
2852 $income_statement_amount += $obj->opening_balance;
2855 $mt = $obj->opening_balance;
2858 $bookkeeping->doc_date = $new_fiscal_period->date_start;
2860 $bookkeeping->date_lim_reglement =
'';
2861 $bookkeeping->doc_ref = $fiscal_period->label;
2863 $bookkeeping->date_creation = $now;
2864 $bookkeeping->doc_type =
'closure';
2865 $bookkeeping->fk_doc = $fiscal_period->id;
2866 $bookkeeping->fk_docdet = 0;
2867 $bookkeeping->thirdparty_code =
'';
2869 if ($separate_auxiliary_account) {
2870 $bookkeeping->subledger_account = $obj->subledger_account;
2872 $sql .=
" subledger_label";
2873 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
2874 $sql .=
" WHERE subledger_account = '" . $this->db->escape($obj->subledger_account) .
"'";
2875 $sql .=
" ORDER BY doc_date DESC";
2877 $result = $this->db->query($sql);
2879 $this->errors[] =
'Error: ' . $this->db->lasterror();
2880 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2883 $objtmp = $this->db->fetch_object($result);
2884 $bookkeeping->subledger_label = $objtmp->subledger_label;
2886 $bookkeeping->subledger_account =
null;
2887 $bookkeeping->subledger_label =
null;
2890 $bookkeeping->numero_compte = $obj->numero_compte;
2892 $accountingaccount->fetch(
'', $obj->numero_compte);
2893 $bookkeeping->label_compte = $accountingaccount->label;
2895 $bookkeeping->label_operation = $new_fiscal_period->label;
2896 $bookkeeping->montant = $mt;
2897 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
2898 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
2899 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
2900 $bookkeeping->code_journal = $journal->code;
2901 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
2902 $bookkeeping->fk_user_author = $user->id;
2903 $bookkeeping->entity = $conf->entity;
2905 $result = $bookkeeping->create($user);
2907 $this->error = $bookkeeping->error;
2908 $this->errors = $bookkeeping->errors;
2916 if (!$error && $income_statement_amount != 0) {
2917 $mt = $income_statement_amount;
2919 $accountingaccount->fetch(
null,
getDolGlobalString($income_statement_amount < 0 ?
'ACCOUNTING_RESULT_LOSS' :
'ACCOUNTING_RESULT_PROFIT'),
true);
2922 $bookkeeping->doc_date = $new_fiscal_period->date_start;
2924 $bookkeeping->date_lim_reglement =
'';
2925 $bookkeeping->doc_ref = $fiscal_period->label;
2927 $bookkeeping->date_creation = $now;
2928 $bookkeeping->doc_type =
'closure';
2929 $bookkeeping->fk_doc = $fiscal_period->id;
2930 $bookkeeping->fk_docdet = 0;
2931 $bookkeeping->thirdparty_code =
'';
2933 if ($separate_auxiliary_account) {
2934 $bookkeeping->subledger_account = $obj->subledger_account;
2936 $sql .=
" subledger_label";
2937 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
2938 $sql .=
" WHERE subledger_account = '" . $this->db->escape($obj->subledger_account) .
"'";
2939 $sql .=
" ORDER BY doc_date DESC";
2941 $result = $this->db->query($sql);
2943 $this->errors[] =
'Error: ' . $this->db->lasterror();
2944 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2947 $objtmp = $this->db->fetch_object($result);
2948 $bookkeeping->subledger_label = $objtmp->subledger_label;
2950 $bookkeeping->subledger_account =
null;
2951 $bookkeeping->subledger_label =
null;
2954 $bookkeeping->numero_compte = $accountingaccount->account_number;
2955 $bookkeeping->label_compte = $accountingaccount->label;
2957 $bookkeeping->label_operation = $new_fiscal_period->label;
2958 $bookkeeping->montant = $mt;
2959 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
2960 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
2961 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
2962 $bookkeeping->code_journal = $journal->code;
2963 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
2964 $bookkeeping->fk_user_author = $user->id;
2965 $bookkeeping->entity = $conf->entity;
2967 $result = $bookkeeping->create($user);
2969 $this->error = $bookkeeping->error;
2970 $this->errors = $bookkeeping->errors;
2974 $this->db->free($resql);
2980 $this->db->rollback();
2983 $this->db->commit();
2732 public function closeFiscalPeriod($fiscal_period_id, $new_fiscal_period_id, $separate_auxiliary_account =
false, $generate_bookkeeping_records =
true) {
…}
3000 global $conf, $langs, $user;
3003 $fiscal_period_id = max(0, $fiscal_period_id);
3004 if (empty($fiscal_period_id)) {
3005 $langs->load(
'errors');
3006 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3010 $result = $fiscal_period->fetch($fiscal_period_id);
3012 $this->error = $fiscal_period->error;
3013 $this->errors = $fiscal_period->errors;
3015 } elseif (empty($fiscal_period->id)) {
3016 $langs->loadLangs(array(
'errors',
'compta'));
3017 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
3022 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
3023 if (empty($new_fiscal_period_id)) {
3024 $langs->load(
'errors');
3025 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3028 $new_fiscal_period =
new Fiscalyear($this->db);
3029 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
3031 $this->error = $new_fiscal_period->error;
3032 $this->errors = $new_fiscal_period->errors;
3034 } elseif (empty($new_fiscal_period->id)) {
3035 $langs->loadLangs(array(
'errors',
'compta'));
3036 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
3041 $inventory_journal_id = max(0, $inventory_journal_id);
3042 if (empty($inventory_journal_id)) {
3043 $langs->load(
'errors');
3044 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3049 $result = $inventory_journal->fetch($inventory_journal_id);
3051 $this->error = $inventory_journal->error;
3052 $this->errors = $inventory_journal->errors;
3054 } elseif ($result == 0) {
3055 $langs->loadLangs(array(
'errors',
'accountancy'));
3056 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'InventoryJournal');
3063 $sql =
'SELECT t.rowid';
3064 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
3065 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
3066 $sql .=
" AND code_journal = '" . $this->db->escape($inventory_journal->code) .
"'";
3067 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) .
"'";
3068 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
3069 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
3070 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
3072 $resql = $this->db->query($sql);
3074 $this->errors[] =
'Error ' . $this->db->lasterror();
3075 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3080 while ($obj = $this->db->fetch_object($resql)) {
3082 $result = $bookkeeping->fetch($obj->rowid);
3084 $this->error = $inventory_journal->error;
3085 $this->errors = $inventory_journal->errors;
3088 } elseif ($result == 0) {
3089 $langs->loadLangs(array(
'errors',
'accountancy'));
3090 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'LineId') .
': ' . $obj->rowid;
3095 $bookkeeping->id = 0;
3096 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3097 $bookkeeping->doc_ref = $new_fiscal_period->label;
3098 $bookkeeping->date_creation = $now;
3099 $bookkeeping->doc_type =
'accounting_reversal';
3100 $bookkeeping->fk_doc = $new_fiscal_period->id;
3101 $bookkeeping->fk_docdet = 0;
3103 $bookkeeping->montant = -$bookkeeping->montant;
3104 $bookkeeping->sens = ($bookkeeping->montant >= 0) ?
'C' :
'D';
3105 $old_debit = $bookkeeping->debit;
3106 $bookkeeping->debit = $bookkeeping->credit;
3107 $bookkeeping->credit = $old_debit;
3109 $bookkeeping->fk_user_author = $user->id;
3110 $bookkeeping->entity = $conf->entity;
3112 $result = $bookkeeping->create($user);
3114 $this->error = $bookkeeping->error;
3115 $this->errors = $bookkeeping->errors;
3120 $this->db->free($resql);
3124 $this->db->rollback();
3127 $this->db->commit();
3143 public $doc_date =
null;
3157 public $thirdparty_code;
3158 public $subledger_account;
3159 public $subledger_label;
3160 public $numero_compte;
3161 public $label_compte;
3162 public $label_operation;
3180 public $multicurrency_amount;
3185 public $multicurrency_code;
3191 public $lettering_code;
3192 public $date_lettering;
3197 public $fk_user_author;
3200 public $code_journal;
3201 public $journal_label;
3210 public $date_creation;
3215 public $date_modification;
3220 public $date_export;
3225 public $date_validation;
3230 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.