32require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/fiscalyear.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
46 public $element =
'accountingbookkeeping';
51 public $table_element =
'accounting_bookkeeping';
56 public $lines = array();
71 public $date_lim_reglement;
96 public $thirdparty_code;
101 public $subledger_account;
106 public $subledger_label;
111 public $numero_compte;
116 public $label_compte;
121 public $label_operation;
153 public $fk_user_author;
163 public $code_journal;
168 public $journal_label;
183 public $linesmvt = array();
188 public $linesexport = array();
198 public $picto =
'generic';
203 public static $can_modify_bookkeeping_sql_cached;
208 public $warnings = array();
230 global
$conf, $langs;
237 if (isset($this->doc_type)) {
238 $this->doc_type = trim($this->doc_type);
240 if (isset($this->doc_ref)) {
241 $this->doc_ref = trim($this->doc_ref);
242 $this->doc_ref =
dol_trunc($this->doc_ref, 300);
244 if (isset($this->fk_doc)) {
245 $this->fk_doc = (int) $this->fk_doc;
247 if (isset($this->fk_docdet)) {
248 $this->fk_docdet = (int) $this->fk_docdet;
250 if (isset($this->thirdparty_code)) {
251 $this->thirdparty_code = trim($this->thirdparty_code);
253 if (isset($this->subledger_account)) {
254 $this->subledger_account = trim($this->subledger_account);
256 if (isset($this->subledger_label)) {
257 $this->subledger_label = trim($this->subledger_label);
259 if (isset($this->numero_compte)) {
260 $this->numero_compte = trim($this->numero_compte);
262 if (isset($this->label_compte)) {
263 $this->label_compte = trim($this->label_compte);
265 if (isset($this->label_operation)) {
266 $this->label_operation = trim($this->label_operation);
268 if (isset($this->debit)) {
269 $this->debit = (float) $this->debit;
271 if (isset($this->credit)) {
272 $this->credit = (float) $this->credit;
274 if (isset($this->montant)) {
275 $this->montant = (float) $this->montant;
277 if (isset($this->
amount)) {
280 if (isset($this->sens)) {
281 $this->sens = trim($this->sens);
283 if (isset($this->import_key)) {
284 $this->import_key = trim($this->import_key);
286 if (isset($this->code_journal)) {
287 $this->code_journal = trim($this->code_journal);
289 if (isset($this->journal_label)) {
290 $this->journal_label = trim($this->journal_label);
292 if (isset($this->piece_num)) {
293 $this->piece_num = (int) $this->piece_num;
295 if (empty($this->debit)) {
298 if (empty($this->credit)) {
305 } elseif ($result == 0) {
307 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
309 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
315 if (($this->numero_compte ==
"") || $this->numero_compte ==
'-1' || $this->numero_compte ==
'NotDefined') {
316 $langs->loadLangs(array(
"errors"));
317 if (in_array($this->doc_type, array(
'bank',
'expense_report'))) {
318 $this->errors[] = $langs->trans(
'ErrorFieldAccountNotDefinedForBankLine', $this->fk_docdet, $this->doc_type);
321 $mesg = $this->doc_ref.
', '.$langs->trans(
"AccountAccounting").
': '.($this->numero_compte != -1 ? $this->numero_compte : $langs->trans(
"Unknown"));
322 if ($this->subledger_account && $this->subledger_account != $this->numero_compte) {
323 $mesg .=
', '.$langs->trans(
"SubledgerAccount").
': '.$this->subledger_account;
325 $this->errors[] = $langs->trans(
'ErrorFieldAccountNotDefinedForLine', $mesg);
333 $this->piece_num = 0;
346 $sql =
"SELECT count(*) as nb";
347 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
348 $sql .=
" WHERE doc_type = '".$this->db->escape($this->doc_type).
"'";
349 $sql .=
" AND fk_doc = ".((int) $this->fk_doc);
352 $sql .=
" AND fk_docdet = ".((int) $this->fk_docdet);
354 $sql .=
" AND numero_compte = '".$this->db->escape($this->numero_compte).
"'";
355 $sql .=
" AND label_operation = '".$this->db->escape($this->label_operation).
"'";
356 if (!empty($this->subledger_account)) {
357 $sql .=
" AND subledger_account = '".$this->db->escape($this->subledger_account).
"'";
359 $sql .=
" AND entity = ".((int)
$conf->entity);
365 if (($accountProfit && $this->numero_compte === trim($accountProfit)) ||
366 ($accountLoss && $this->numero_compte === trim($accountLoss))) {
368 $sql .=
" AND 1 = 2";
371 $resql = $this->db->query($sql);
374 $row = $this->db->fetch_object($resql);
377 $sqlnum =
"SELECT piece_num, ref";
378 $sqlnum .=
" FROM ".$this->db->prefix().$this->table_element;
379 $sqlnum .=
" WHERE doc_type = '".$this->db->escape($this->doc_type).
"'";
380 $sqlnum .=
" AND fk_doc = ".((int) $this->fk_doc);
383 $sqlnum .=
" AND fk_docdet = ".((int) $this->fk_docdet);
385 $sqlnum .=
" AND doc_ref = '".$this->db->escape($this->doc_ref).
"'";
386 $sqlnum .=
" AND entity = ".((int)
$conf->entity);
388 dol_syslog(get_class($this).
":: create sqlnum=".$sqlnum, LOG_DEBUG);
389 $resqlnum = $this->db->query($sqlnum);
391 $num = $this->db->num_rows($resqlnum);
393 $objnum = $this->db->fetch_object($resqlnum);
394 $this->piece_num = $objnum->piece_num;
395 $this->
ref = $objnum->ref;
397 $this->piece_num = 0;
402 dol_syslog(get_class($this).
"::create this->piece_num=".$this->piece_num, LOG_DEBUG);
403 if (empty($this->piece_num)) {
404 $sqlnum =
"SELECT MAX(piece_num)+1 as maxpiecenum";
405 $sqlnum .=
" FROM ".$this->db->prefix().$this->table_element;
406 $sqlnum .=
" WHERE entity = " . ((int)
$conf->entity);
408 $resqlnum = $this->db->query($sqlnum);
410 $objnum = $this->db->fetch_object($resqlnum);
411 $this->piece_num = $objnum->maxpiecenum;
414 $this->
ref = $this->getNextNumRef();
415 dol_syslog(get_class($this).
":: create now this->piece_num={$this->piece_num}, this->ref={$this->ref}", LOG_DEBUG);
417 if (empty($this->piece_num)) {
418 $this->piece_num = 1;
423 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
" (";
425 $sql .=
", date_lim_reglement";
426 $sql .=
", doc_type";
429 $sql .=
", fk_docdet";
430 $sql .=
", thirdparty_code";
431 $sql .=
", subledger_account";
432 $sql .=
", subledger_label";
433 $sql .=
", numero_compte";
434 $sql .=
", label_compte";
435 $sql .=
", label_operation";
440 $sql .=
", fk_user_author";
441 $sql .=
", date_creation";
442 $sql .=
", code_journal";
443 $sql .=
", journal_label";
444 $sql .=
", piece_num";
447 $sql .=
") VALUES (";
448 $sql .=
"'".$this->db->idate($this->doc_date).
"'";
449 $sql .=
", ".(isDolTms($this->date_lim_reglement) ?
"'".$this->db->idate($this->date_lim_reglement).
"'" :
'NULL');
450 $sql .=
", '".$this->db->escape($this->doc_type).
"'";
451 $sql .=
", '".$this->db->escape($this->doc_ref).
"'";
452 $sql .=
", ".((int) $this->fk_doc);
453 $sql .=
", ".((int) $this->fk_docdet);
454 $sql .=
", ".(!empty($this->thirdparty_code) ? (
"'".$this->db->escape($this->thirdparty_code).
"'") :
"NULL");
455 $sql .=
", ".(!empty($this->subledger_account) ? (
"'".$this->db->escape($this->subledger_account).
"'") :
"NULL");
456 $sql .=
", ".(!empty($this->subledger_label) ? (
"'".$this->db->escape($this->subledger_label).
"'") :
"NULL");
457 $sql .=
", '".$this->db->escape($this->numero_compte).
"'";
458 $sql .=
", ".(!empty($this->label_compte) ? (
"'".$this->db->escape($this->label_compte).
"'") :
"NULL");
459 $sql .=
", '".$this->db->escape($this->label_operation).
"'";
460 $sql .=
", ".((float) $this->debit);
461 $sql .=
", ".((float) $this->credit);
462 $sql .=
", ".((float) $this->montant);
463 $sql .=
", ".(!empty($this->sens) ? (
"'".$this->db->escape($this->sens).
"'") :
"NULL");
464 $sql .=
", ".((int) $this->fk_user_author);
465 $sql .=
", '".$this->db->idate($now).
"'";
466 $sql .=
", '".$this->db->escape($this->code_journal).
"'";
467 $sql .=
", ".(!empty($this->journal_label) ? (
"'".$this->db->escape($this->journal_label).
"'") :
"NULL");
468 $sql .=
", ".((int) $this->piece_num);
469 $sql .=
", '".$this->db->escape($this->
ref).
"'";
470 $sql .=
", ".(!isset($this->entity) ? ((int)
$conf->entity) : ((int) $this->entity));
473 $resql = $this->db->query($sql);
475 $id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
483 $this->errors[] =
'Error Create Error '.$result.
' lecture ID';
484 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
489 $this->errors[] =
'Error '.$this->db->lasterror();
490 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
495 $this->error =
'BookkeepingRecordAlreadyExists';
496 $this->errors[] = $langs->trans(
'WarningBookkeepingRecordAlreadyExists', $this->doc_type, $this->fk_doc, $this->fk_docdet);
498 dol_syslog(get_class($this).
":: create duplicate record detected: doc_type={$this->doc_type}, doc_ref={$this->doc_ref}, fk_doc={((int) $this->fk_doc)}, fk_docdet={((int) $this->fk_docdet)}", LOG_WARNING);
503 $this->errors[] =
'Error '.$this->db->lasterror();
504 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
508 if (! $error && ! $notrigger) {
509 $result = $this->call_trigger(
'BOOKKEEPING_CREATE', $user);
517 $this->db->rollback();
542 public function createFromValues($doc_date, $doc_ref, $doc_type, $fk_doc, $fk_docdet, $numero_compte, $label_compte, $label_operation, $amount, $code_journal, $journal_label, $subledger_account)
544 global
$conf, $langs, $user;
548 if (!empty($amount)) {
549 $this->doc_date = $doc_date;
550 $this->doc_ref = $doc_ref;
551 $this->doc_type = $doc_type;
552 $this->fk_doc = $fk_doc;
553 $this->fk_docdet = $fk_docdet;
555 $this->numero_compte = $numero_compte;
556 $this->label_compte = $label_compte;
558 $this->label_operation = $label_operation;
559 $this->subledger_account = $subledger_account;
561 $this->montant = $amount;
562 $this->sens = ($amount >= 0) ?
'D' :
'C';
563 $this->debit = ($amount >= 0 ? $amount : 0);
564 $this->credit = ($amount < 0 ? -$amount : 0);
566 $this->code_journal = $code_journal;
567 $this->journal_label = $journal_label;
569 $this->fk_user_author = $user->id;
570 $this->entity =
$conf->entity;
572 $result = $this->
create($user);
574 if ($this->error ==
'BookkeepingRecordAlreadyExists') {
575 $warning = $langs->trans(
'WarningBookkeepingRecordAlreadyExists', $this->doc_type, $this->fk_doc, $this->fk_docdet);
576 $this->warnings[] = $warning;
577 dol_syslog(__METHOD__.
' '.$warning, LOG_WARNING);
579 dol_syslog(__METHOD__.
' '.$this->errorsToString(), LOG_ERR);
597 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
599 global $db,
$conf, $langs;
600 global $dolibarr_main_authentication, $dolibarr_main_demo;
601 global $menumanager, $hookmanager;
603 if (!empty(
$conf->dol_no_mouse_hover)) {
610 $label =
'<u>'.$langs->trans(
"Transaction").
'</u>';
612 $label .=
'<b>'.$langs->trans(
'NumberingShort').
':</b> '.$this->piece_num;
614 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
616 $baseurl = DOL_URL_ROOT.
'/accountancy/bookkeeping/card.php';
617 $query = [
'piece_num' => $this->piece_num];
619 if ($option !=
'nolink') {
621 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
622 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
623 $add_save_lastsearch_values = 1;
625 if ($add_save_lastsearch_values) {
626 $query += [
'save_lastsearch_values' => 1];
632 if (empty($notooltip)) {
634 $label = $langs->trans(
"ShowTransaction");
635 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
637 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
638 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
640 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
643 $linkstart =
'<a href="'.$url.
'"';
644 $linkstart .= $linkclose.
'>';
647 $result .= $linkstart;
649 $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);
651 if ($withpicto != 2) {
652 $result .= $this->piece_num;
658 $hookmanager->initHooks(array($this->element .
'dao'));
659 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
660 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
662 $result = $hookmanager->resPrint;
664 $result .= $hookmanager->resPrint;
679 global
$conf, $langs;
681 $langs->loadLangs(array(
"accountancy",
"bills",
"compta"));
688 if (isset($this->doc_type)) {
689 $this->doc_type = trim($this->doc_type);
691 if (isset($this->doc_ref)) {
692 $this->doc_ref = trim($this->doc_ref);
694 if (isset($this->fk_doc)) {
695 $this->fk_doc = (int) $this->fk_doc;
697 if (isset($this->fk_docdet)) {
698 $this->fk_docdet = (int) $this->fk_docdet;
700 if (isset($this->thirdparty_code)) {
701 $this->thirdparty_code = trim($this->thirdparty_code);
703 if (isset($this->subledger_account)) {
704 $this->subledger_account = trim($this->subledger_account);
706 if (isset($this->subledger_label)) {
707 $this->subledger_label = trim($this->subledger_label);
709 if (isset($this->numero_compte)) {
710 $this->numero_compte = trim($this->numero_compte);
712 if (isset($this->label_compte)) {
713 $this->label_compte = trim($this->label_compte);
715 if (isset($this->label_operation)) {
716 $this->label_operation = trim($this->label_operation);
718 if (isset($this->sens)) {
719 $this->sens = trim($this->sens);
721 if (isset($this->import_key)) {
722 $this->import_key = trim($this->import_key);
724 if (isset($this->code_journal)) {
725 $this->code_journal = trim($this->code_journal);
727 if (isset($this->journal_label)) {
728 $this->journal_label = trim($this->journal_label);
730 if (isset($this->piece_num)) {
731 $this->piece_num = (int) $this->piece_num;
733 if (empty($this->debit)) {
736 if (empty($this->credit)) {
739 if (empty($this->montant)) {
746 } elseif ($result == 0) {
748 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
750 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
755 $this->debit = (float)
price2num($this->debit,
'MT');
756 $this->credit = (float)
price2num($this->credit,
'MT');
757 $this->montant = (float)
price2num($this->montant,
'MT');
762 $this->journal_label = $langs->trans($this->journal_label);
765 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.$mode.
' (';
767 $sql .=
'date_lim_reglement,';
771 $sql .=
'fk_docdet,';
772 $sql .=
'thirdparty_code,';
773 $sql .=
'subledger_account,';
774 $sql .=
'subledger_label,';
775 $sql .=
'numero_compte,';
776 $sql .=
'label_compte,';
777 $sql .=
'label_operation,';
782 $sql .=
'fk_user_author,';
783 $sql .=
'date_creation,';
784 $sql .=
'code_journal,';
785 $sql .=
'journal_label,';
786 $sql .=
'piece_num,';
789 $sql .=
') VALUES (';
790 $sql .=
' '.(isDolTms($this->doc_date) ?
"'".$this->db->idate($this->doc_date).
"'" :
'NULL').
',';
791 $sql .=
' '.(isDolTms($this->date_lim_reglement) ?
"'".$this->db->idate($this->date_lim_reglement).
"'" :
'NULL').
',';
792 $sql .=
' '.(!isset($this->doc_type) ?
'NULL' :
"'".$this->db->escape($this->doc_type).
"'").
',';
793 $sql .=
' '.(!isset($this->doc_ref) ?
'NULL' :
"'".$this->db->escape($this->doc_ref).
"'").
',';
794 $sql .=
' '.(empty($this->fk_doc) ?
'0' : (int) $this->fk_doc).
',';
795 $sql .=
' '.(empty($this->fk_docdet) ?
'0' : (int) $this->fk_docdet).
',';
796 $sql .=
' '.(!isset($this->thirdparty_code) ?
'NULL' :
"'".$this->db->escape($this->thirdparty_code).
"'").
',';
797 $sql .=
' '.(!isset($this->subledger_account) ?
'NULL' :
"'".$this->db->escape($this->subledger_account).
"'").
',';
798 $sql .=
' '.(!isset($this->subledger_label) ?
'NULL' :
"'".$this->db->escape($this->subledger_label).
"'").
',';
799 $sql .=
' '.(!isset($this->numero_compte) ?
'NULL' :
"'".$this->db->escape($this->numero_compte).
"'").
',';
800 $sql .=
' '.(!isset($this->label_compte) ?
'NULL' :
"'".$this->db->escape($this->label_compte).
"'").
',';
801 $sql .=
' '.(!isset($this->label_operation) ?
'NULL' :
"'".$this->db->escape($this->label_operation).
"'").
',';
802 $sql .=
' '.(!isset($this->debit) ?
'NULL' : ((float) $this->debit)).
',';
803 $sql .=
' '.(!isset($this->credit) ?
'NULL' : ((float) $this->credit)).
',';
804 $sql .=
' '.(!isset($this->montant) ?
'NULL' : ((float) $this->montant)).
',';
805 $sql .=
' '.(!isset($this->sens) ?
'NULL' :
"'".$this->db->escape($this->sens).
"'").
',';
806 $sql .=
' '.((int) $user->id).
',';
807 $sql .=
' '.
"'".$this->db->idate($now).
"',";
808 $sql .=
' '.(empty($this->code_journal) ?
'NULL' :
"'".$this->db->escape($this->code_journal).
"'").
',';
809 $sql .=
' '.(empty($this->journal_label) ?
'NULL' :
"'".$this->db->escape($this->journal_label).
"'").
',';
810 $sql .=
' '.(empty($this->piece_num) ?
'NULL' : ((int) $this->piece_num)).
',';
811 $sql .=
' '.(empty($this->
ref) ?
"''" :
"'".$this->db->escape($this->
ref).
"'").
',';
812 $sql .=
' '.(!isset($this->entity) ? ((int)
$conf->entity) : ((int) $this->entity));
817 $resql = $this->db->query($sql);
820 $this->errors[] =
'Error '.$this->db->lasterror();
821 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
825 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element.$mode);
828 $result = $this->call_trigger(
'BOOKKEEPING_CREATE', $user);
837 $this->db->rollback();
855 public function fetch($id, $ref =
null, $mode =
'')
863 $sql .=
" t.doc_date,";
864 $sql .=
" t.date_lim_reglement,";
865 $sql .=
" t.doc_type,";
866 $sql .=
" t.doc_ref,";
867 $sql .=
" t.fk_doc,";
868 $sql .=
" t.fk_docdet,";
869 $sql .=
" t.thirdparty_code,";
870 $sql .=
" t.subledger_account,";
871 $sql .=
" t.subledger_label,";
872 $sql .=
" t.numero_compte,";
873 $sql .=
" t.label_compte,";
874 $sql .=
" t.label_operation,";
876 $sql .=
" t.credit,";
877 $sql .=
" t.montant as amount,";
879 $sql .=
" t.fk_user_author,";
880 $sql .=
" t.import_key,";
881 $sql .=
" t.code_journal,";
882 $sql .=
" t.journal_label,";
883 $sql .=
" t.piece_num,";
885 $sql .=
" t.date_creation,";
888 $sql .=
" t.date_export,";
890 $sql .=
" t.date_validated as date_validation";
891 $sql .=
' FROM '.$this->db->prefix().$this->table_element.$mode.
' as t';
892 $sql .=
' WHERE 1 = 1';
893 $sql .=
" AND entity = " . ((int)
$conf->entity);
895 $sql .=
" AND t.rowid = ".((int) $ref);
897 $sql .=
" AND t.rowid = ".((int) $id);
900 $resql = $this->db->query($sql);
902 $numrows = $this->db->num_rows($resql);
904 $obj = $this->db->fetch_object($resql);
906 $this->
id = $obj->rowid;
908 $this->doc_date = $this->db->jdate($obj->doc_date);
909 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
910 $this->doc_type = $obj->doc_type;
911 $this->doc_ref = $obj->doc_ref;
912 $this->fk_doc = $obj->fk_doc;
913 $this->fk_docdet = $obj->fk_docdet;
914 $this->thirdparty_code = $obj->thirdparty_code;
915 $this->subledger_account = $obj->subledger_account;
916 $this->subledger_label = $obj->subledger_label;
917 $this->numero_compte = $obj->numero_compte;
918 $this->label_compte = $obj->label_compte;
919 $this->label_operation = $obj->label_operation;
920 $this->debit = $obj->debit;
921 $this->credit = $obj->credit;
922 $this->montant = $obj->amount;
923 $this->
amount = $obj->amount;
924 $this->sens = $obj->sens;
925 $this->fk_user_author = $obj->fk_user_author;
926 $this->import_key = $obj->import_key;
927 $this->code_journal = $obj->code_journal;
928 $this->journal_label = $obj->journal_label;
929 $this->piece_num = $obj->piece_num;
930 $this->date_creation = $this->db->jdate($obj->date_creation);
932 $this->date_export = $this->db->jdate($obj->date_export);
934 $this->
ref = $obj->ref;
935 $this->date_validation = isset($obj->date_validation) ? $this->db->jdate($obj->date_validation) :
'';
937 $this->db->free($resql);
945 $this->errors[] =
'Error '.$this->db->lasterror();
946 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
966 public function fetchAllByAccount($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND', $option = 0, $countonly = 0)
972 $this->lines = array();
977 $sql .=
' COUNT(t.rowid) as nb';
980 $sql .=
" t.doc_date,";
981 $sql .=
" t.doc_type,";
982 $sql .=
" t.doc_ref,";
983 $sql .=
" t.fk_doc,";
984 $sql .=
" t.fk_docdet,";
985 $sql .=
" t.thirdparty_code,";
986 $sql .=
" t.subledger_account,";
987 $sql .=
" t.subledger_label,";
988 $sql .=
" t.numero_compte,";
989 $sql .=
" t.label_compte,";
990 $sql .=
" t.label_operation,";
992 $sql .=
" t.credit,";
993 $sql .=
" t.montant as amount,";
995 $sql .=
" t.multicurrency_amount,";
996 $sql .=
" t.multicurrency_code,";
997 $sql .=
" t.matching_general,";
998 $sql .=
" t.lettering_code,";
999 $sql .=
" t.date_lettering,";
1000 $sql .=
" t.fk_user_author,";
1001 $sql .=
" t.import_key,";
1002 $sql .=
" t.code_journal,";
1003 $sql .=
" t.journal_label,";
1004 $sql .=
" t.piece_num,";
1006 $sql .=
" t.date_creation,";
1007 $sql .=
" t.date_export,";
1008 $sql .=
" t.date_validated as date_validation,";
1009 $sql .=
" t.date_lim_reglement,";
1010 $sql .=
" t.import_key";
1013 $sqlwhere = array();
1014 if (count($filter) > 0) {
1015 foreach ($filter as $key => $value) {
1016 if ($key ==
't.doc_date>=') {
1017 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate((
int) $value).
"'";
1018 } elseif ($key ==
't.doc_date<=') {
1019 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate((
int) $value).
"'";
1020 } elseif ($key ==
't.doc_date>') {
1021 $sqlwhere[] =
"t.doc_date > '".$this->db->idate((
int) $value).
"'";
1022 } elseif ($key ==
't.doc_date<') {
1023 $sqlwhere[] =
"t.doc_date < '".$this->db->idate((
int) $value).
"'";
1024 } elseif ($key ==
't.numero_compte>=') {
1025 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1026 } elseif ($key ==
't.numero_compte<=') {
1027 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1028 } elseif ($key ==
't.subledger_account>=') {
1029 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1030 } elseif ($key ==
't.subledger_account<=') {
1031 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1032 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1033 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
1034 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1035 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($this->db->escapeforlike($value)).
"%'";
1036 } elseif ($key ==
't.date_creation>=') {
1037 $sqlwhere[] =
"t.date_creation >= '".$this->db->idate((
int) $value).
"'";
1038 } elseif ($key ==
't.date_creation<=') {
1039 $sqlwhere[] =
"t.date_creation <= '".$this->db->idate((
int) $value).
"'";
1040 } elseif ($key ==
't.date_export>=') {
1041 $sqlwhere[] =
"t.date_export >= '".$this->db->idate((
int) $value).
"'";
1042 } elseif ($key ==
't.date_export<=') {
1043 $sqlwhere[] =
"t.date_export <= '".$this->db->idate((
int) $value).
"'";
1044 } elseif ($key ==
't.date_validated>=') {
1045 $sqlwhere[] =
"t.date_validated >= '".$this->db->idate((
int) $value).
"'";
1046 } elseif ($key ==
't.date_validated<=') {
1047 $sqlwhere[] =
"t.date_validated <= '".$this->db->idate((
int) $value).
"'";
1048 } elseif ($key ==
't.date_lim_reglement>=') {
1049 $sqlwhere[] =
"t.date_lim_reglement>='".$this->db->idate((
int) $value).
"'";
1050 } elseif ($key ==
't.date_lim_reglement<=') {
1051 $sqlwhere[] =
"t.date_lim_reglement<='".$this->db->idate((
int) $value).
"'";
1052 } elseif ($key ==
't.credit' || $key ==
't.debit') {
1054 } elseif ($key ==
't.reconciled_option') {
1055 $sqlwhere[] =
't.lettering_code IS NULL';
1056 } elseif ($key ==
't.code_journal' && !empty($value)) {
1057 if (is_array($value)) {
1058 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1062 } elseif ($key ==
't.search_accounting_code_in' && !empty($value)) {
1063 $sqlwhere[] =
"t.numero_compte IN (".$this->db->sanitize($value, 1).
")";
1069 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t';
1070 $sql .=
' WHERE entity = ' . ((int)
$conf->entity);
1071 if (count($sqlwhere) > 0) {
1072 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1075 if (!empty($option)) {
1076 $sql .=
" AND t.subledger_account IS NOT NULL";
1077 $sql .=
" AND t.subledger_account <> ''";
1078 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
1079 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1081 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
1082 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1086 $sql .= $this->db->order($sortfield, $sortorder);
1087 if (!empty($limit)) {
1088 $sql .= $this->db->plimit($limit + 1, $offset);
1092 $resql = $this->db->query($sql);
1095 $obj = $this->db->fetch_object($resql);
1100 $num = $this->db->num_rows($resql);
1103 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1106 $line->id = $obj->rowid;
1108 $line->doc_date = $this->db->jdate($obj->doc_date);
1109 $line->doc_type = $obj->doc_type;
1110 $line->doc_ref = $obj->doc_ref;
1111 $line->fk_doc = $obj->fk_doc;
1112 $line->fk_docdet = $obj->fk_docdet;
1113 $line->thirdparty_code = $obj->thirdparty_code;
1114 $line->subledger_account = $obj->subledger_account;
1115 $line->subledger_label = $obj->subledger_label;
1116 $line->numero_compte = $obj->numero_compte;
1117 $line->label_compte = $obj->label_compte;
1118 $line->label_operation = $obj->label_operation;
1119 $line->debit = $obj->debit;
1120 $line->credit = $obj->credit;
1121 $line->montant = $obj->amount;
1122 $line->amount = $obj->amount;
1123 $line->sens = $obj->sens;
1124 $line->multicurrency_amount = $obj->multicurrency_amount;
1125 $line->multicurrency_code = $obj->multicurrency_code;
1126 $line->matching_general = (bool) $obj->matching_general;
1127 $line->lettering_code = $obj->lettering_code;
1128 $line->date_lettering = $this->db->jdate($obj->date_lettering);
1129 $line->fk_user_author = $obj->fk_user_author;
1130 $line->import_key = $obj->import_key;
1131 $line->code_journal = $obj->code_journal;
1132 $line->journal_label = $obj->journal_label;
1133 $line->piece_num = $obj->piece_num;
1134 $line->ref = $obj->ref;
1135 $line->date_creation = $this->db->jdate($obj->date_creation);
1136 $line->date_export = $this->db->jdate($obj->date_export);
1137 $line->date_validation = $this->db->jdate($obj->date_validation);
1139 $line->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1140 $line->import_key = $obj->import_key;
1142 $this->lines[] = $line;
1147 $this->db->free($resql);
1151 $this->errors[] =
'Error '.$this->db->lasterror();
1152 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1170 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $showAlreadyExportMovements = 1)
1177 $sql .=
' t.rowid,';
1178 $sql .=
" t.doc_date,";
1179 $sql .=
" t.doc_type,";
1180 $sql .=
" t.doc_ref,";
1181 $sql .=
" t.fk_doc,";
1182 $sql .=
" t.fk_docdet,";
1183 $sql .=
" t.thirdparty_code,";
1184 $sql .=
" t.subledger_account,";
1185 $sql .=
" t.subledger_label,";
1186 $sql .=
" t.numero_compte,";
1187 $sql .=
" t.label_compte,";
1188 $sql .=
" t.label_operation,";
1189 $sql .=
" t.debit,";
1190 $sql .=
" t.credit,";
1191 $sql .=
" t.lettering_code,";
1192 $sql .=
" t.date_lettering,";
1193 $sql .=
" t.montant as amount,";
1195 $sql .=
" t.fk_user_author,";
1196 $sql .=
" t.import_key,";
1197 $sql .=
" t.code_journal,";
1198 $sql .=
" t.journal_label,";
1199 $sql .=
" t.piece_num,";
1200 $sql .=
" t.date_creation,";
1201 $sql .=
" t.date_lim_reglement,";
1202 $sql .=
" t.tms as date_modification,";
1203 $sql .=
" t.date_export,";
1204 $sql .=
" t.date_validated as date_validation";
1205 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t';
1206 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
1207 if ($showAlreadyExportMovements == 0) {
1208 $sql .=
" AND t.date_export IS NULL";
1212 if (is_array($filter)) {
1213 dol_syslog(
"You are using a deprecated use of fetchAll. filter parameter must be an USF string now.", LOG_WARNING);
1214 $sqlwhere = array();
1215 if (count($filter) > 0) {
1216 foreach ($filter as $key => $value) {
1217 if ($key ==
't.doc_date') {
1218 $sqlwhere[] = $this->db->sanitize($key).
" = '".$this->db->idate((
int) $value).
"'";
1219 } elseif ($key ==
't.doc_date>=') {
1220 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate((
int) $value).
"'";
1221 } elseif ($key ==
't.doc_date<=') {
1222 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate((
int) $value).
"'";
1223 } elseif ($key ==
't.doc_date>') {
1224 $sqlwhere[] =
"t.doc_date > '".$this->db->idate((
int) $value).
"'";
1225 } elseif ($key ==
't.doc_date<') {
1226 $sqlwhere[] =
"t.doc_date < '".$this->db->idate((
int) $value).
"'";
1227 } elseif ($key ==
't.numero_compte>=') {
1228 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1229 } elseif ($key ==
't.numero_compte<=') {
1230 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1231 } elseif ($key ==
't.subledger_account>=') {
1232 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1233 } elseif ($key ==
't.subledger_account<=') {
1234 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1235 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1236 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
1237 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1238 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1239 } elseif ($key ==
't.date_creation>=') {
1240 $sqlwhere[] =
"t.date_creation >= '".$this->db->idate((
int) $value).
"'";
1241 } elseif ($key ==
't.date_creation<=') {
1242 $sqlwhere[] =
"t.date_creation <= '".$this->db->idate((
int) $value).
"'";
1243 } elseif ($key ==
't.tms>=') {
1244 $sqlwhere[] =
"t.tms >= '".$this->db->idate((
int) $value).
"'";
1245 } elseif ($key ==
't.tms<=') {
1246 $sqlwhere[] =
"t.tms <= '".$this->db->idate((
int) $value).
"'";
1247 } elseif ($key ==
't.date_export>=') {
1248 $sqlwhere[] =
"t.date_export >= '".$this->db->idate((
int) $value).
"'";
1249 } elseif ($key ==
't.date_export<=') {
1250 $sqlwhere[] =
"t.date_export <= '".$this->db->idate((
int) $value).
"'";
1251 } elseif ($key ==
't.date_validated>=') {
1252 $sqlwhere[] =
"t.date_validated >= '".$this->db->idate((
int) $value).
"'";
1253 } elseif ($key ==
't.date_validated<=') {
1254 $sqlwhere[] =
"t.date_validated <= '".$this->db->idate((
int) $value).
"'";
1255 } elseif ($key ==
't.credit' || $key ==
't.debit') {
1257 } elseif ($key ==
't.code_journal' && !empty($value)) {
1258 if (is_array($value)) {
1259 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1263 } elseif ($key ==
't.reconciled_option') {
1264 $sqlwhere[] =
't.lettering_code IS NULL';
1270 if (count($sqlwhere) > 0) {
1271 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1280 if ($errormessage) {
1281 $this->errors[] = $errormessage;
1282 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1286 if (!empty($sortfield)) {
1287 $sql .= $this->db->order($sortfield, $sortorder);
1289 if (!empty($limit)) {
1290 $sql .= $this->db->plimit($limit + 1, $offset);
1292 $this->lines = array();
1294 $resql = $this->db->query($sql);
1296 $num = $this->db->num_rows($resql);
1299 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1302 $line->id = $obj->rowid;
1304 $line->doc_date = $this->db->jdate($obj->doc_date);
1305 $line->doc_type = $obj->doc_type;
1306 $line->doc_ref = $obj->doc_ref;
1307 $line->fk_doc = $obj->fk_doc;
1308 $line->fk_docdet = $obj->fk_docdet;
1309 $line->thirdparty_code = $obj->thirdparty_code;
1310 $line->subledger_account = $obj->subledger_account;
1311 $line->subledger_label = $obj->subledger_label;
1312 $line->numero_compte = $obj->numero_compte;
1313 $line->label_compte = $obj->label_compte;
1314 $line->label_operation = $obj->label_operation;
1315 $line->debit = $obj->debit;
1316 $line->credit = $obj->credit;
1317 $line->montant = $obj->amount;
1318 $line->amount = $obj->amount;
1319 $line->sens = $obj->sens;
1320 $line->lettering_code = $obj->lettering_code;
1321 $line->date_lettering = $this->db->jdate($obj->date_lettering);
1322 $line->fk_user_author = $obj->fk_user_author;
1323 $line->import_key = $obj->import_key;
1324 $line->code_journal = $obj->code_journal;
1325 $line->journal_label = $obj->journal_label;
1326 $line->piece_num = $obj->piece_num;
1327 $line->date_creation = $this->db->jdate($obj->date_creation);
1328 $line->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1329 $line->date_modification = $this->db->jdate($obj->date_modification);
1330 $line->date_export = $this->db->jdate($obj->date_export);
1331 $line->date_validation = $this->db->jdate($obj->date_validation);
1333 $this->lines[] = $line;
1337 $this->db->free($resql);
1341 $this->errors[] =
'Error '.$this->db->lasterror();
1342 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1359 public function fetchAllBalance($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $option = 0)
1363 $this->lines = array();
1368 $sql .=
" t.numero_compte,";
1369 if (!empty($option)) {
1370 $sql .=
" t.subledger_account,";
1371 $sql .=
" t.subledger_label,";
1373 $sql .=
" SUM(t.debit) as debit,";
1374 $sql .=
" SUM(t.credit) as credit";
1375 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t';
1376 $sql .=
' WHERE entity = ' . ((int)
$conf->entity);
1379 if (is_array($filter)) {
1380 $sqlwhere = array();
1381 if (count($filter) > 0) {
1382 foreach ($filter as $key => $value) {
1383 if ($key ==
't.doc_date') {
1384 $sqlwhere[] = $this->db->sanitize($key).
" = '".$this->db->idate((
int) $value).
"'";
1385 } elseif ($key ==
't.doc_date>=') {
1386 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate((
int) $value).
"'";
1387 } elseif ($key ==
't.doc_date<=') {
1388 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate((
int) $value).
"'";
1389 } elseif ($key ==
't.doc_date>') {
1390 $sqlwhere[] =
"t.doc_date > '".$this->db->idate((
int) $value).
"'";
1391 } elseif ($key ==
't.doc_date<') {
1392 $sqlwhere[] =
"t.doc_date < '".$this->db->idate((
int) $value).
"'";
1393 } elseif ($key ==
't.numero_compte>=') {
1394 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1395 } elseif ($key ==
't.numero_compte<=') {
1396 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1397 } elseif ($key ==
't.subledger_account>=') {
1398 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1399 } elseif ($key ==
't.subledger_account<=') {
1400 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1401 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1402 $sqlwhere[] = $this->db->sanitize($key).
" = ".((int) $value);
1403 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1404 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1405 } elseif ($key ==
't.subledger_label') {
1406 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1407 } elseif ($key ==
't.code_journal' && !empty($value)) {
1408 if (is_array($value)) {
1409 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1413 } elseif ($key ==
't.reconciled_option') {
1414 $sqlwhere[] =
't.lettering_code IS NULL';
1416 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
1420 if (count($sqlwhere) > 0) {
1421 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1430 if ($errormessage) {
1431 $this->errors[] = $errormessage;
1432 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1436 if (!empty($option)) {
1437 $sql .=
" AND t.subledger_account IS NOT NULL";
1438 $sql .=
" AND t.subledger_account <> ''";
1439 $sql .=
" GROUP BY t.numero_compte, t.subledger_account, t.subledger_label";
1440 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
1441 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1443 $sql .=
' GROUP BY t.numero_compte';
1444 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
1445 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1448 $sql .= $this->db->order($sortfield, $sortorder);
1450 if (!empty($limit)) {
1451 $sql .= $this->db->plimit($limit + 1, $offset);
1455 $resql = $this->db->query($sql);
1458 $num = $this->db->num_rows($resql);
1461 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1464 $line->numero_compte = $obj->numero_compte;
1466 if (!empty($option)) {
1467 $line->subledger_account = $obj->subledger_account;
1468 $line->subledger_label = $obj->subledger_label;
1470 $line->debit = $obj->debit;
1471 $line->credit = $obj->credit;
1473 $this->lines[] = $line;
1477 $this->db->free($resql);
1481 $this->errors[] =
'Error '.$this->db->lasterror();
1482 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1504 if (isset($this->doc_type)) {
1505 $this->doc_type = trim($this->doc_type);
1507 if (isset($this->doc_ref)) {
1508 $this->doc_ref = trim($this->doc_ref);
1510 if (isset($this->fk_doc)) {
1511 $this->fk_doc = (int) $this->fk_doc;
1513 if (isset($this->fk_docdet)) {
1514 $this->fk_docdet = (int) $this->fk_docdet;
1516 if (isset($this->thirdparty_code)) {
1517 $this->thirdparty_code = trim($this->thirdparty_code);
1519 if (isset($this->subledger_account)) {
1520 $this->subledger_account = trim($this->subledger_account);
1522 if (isset($this->subledger_label)) {
1523 $this->subledger_label = trim($this->subledger_label);
1525 if (isset($this->numero_compte)) {
1526 $this->numero_compte = trim($this->numero_compte);
1528 if (isset($this->label_compte)) {
1529 $this->label_compte = trim($this->label_compte);
1531 if (isset($this->label_operation)) {
1532 $this->label_operation = trim($this->label_operation);
1534 if (isset($this->sens)) {
1535 $this->sens = trim($this->sens);
1537 if (isset($this->import_key)) {
1538 $this->import_key = trim($this->import_key);
1540 if (isset($this->code_journal)) {
1541 $this->code_journal = trim($this->code_journal);
1543 if (isset($this->journal_label)) {
1544 $this->journal_label = trim($this->journal_label);
1546 if (isset($this->piece_num)) {
1547 $this->piece_num = (int) $this->piece_num;
1553 } elseif ($result == 0) {
1555 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1557 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1562 $this->debit = (float)
price2num($this->debit,
'MT');
1563 $this->credit = (float)
price2num($this->credit,
'MT');
1564 $this->montant = (float)
price2num($this->montant,
'MT');
1570 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.$mode.
' SET';
1571 $sql .=
' doc_date = '.(isDolTms($this->doc_date) ?
"'".$this->db->idate($this->doc_date).
"'" :
'null').
',';
1572 $sql .=
' doc_type = '.(isset($this->doc_type) ?
"'".$this->db->escape($this->doc_type).
"'" :
"null").
',';
1573 $sql .=
' doc_ref = '.(isset($this->doc_ref) ?
"'".$this->db->escape($this->doc_ref).
"'" :
"null").
',';
1574 $sql .=
' fk_doc = '.(isset($this->fk_doc) ? ((int) $this->fk_doc) :
"null").
',';
1575 $sql .=
' fk_docdet = '.(isset($this->fk_docdet) ? ((int) $this->fk_docdet) :
"null").
',';
1576 $sql .=
' thirdparty_code = '.(isset($this->thirdparty_code) ?
"'".$this->db->escape($this->thirdparty_code).
"'" :
"null").
',';
1577 $sql .=
' subledger_account = '.(isset($this->subledger_account) ?
"'".$this->db->escape($this->subledger_account).
"'" :
"null").
',';
1578 $sql .=
' subledger_label = '.(isset($this->subledger_label) ?
"'".$this->db->escape($this->subledger_label).
"'" :
"null").
',';
1579 $sql .=
' numero_compte = '.(isset($this->numero_compte) ?
"'".$this->db->escape($this->numero_compte).
"'" :
"null").
',';
1580 $sql .=
' label_compte = '.(isset($this->label_compte) ?
"'".$this->db->escape($this->label_compte).
"'" :
"null").
',';
1581 $sql .=
' label_operation = '.(isset($this->label_operation) ?
"'".$this->db->escape($this->label_operation).
"'" :
"null").
',';
1582 $sql .=
' debit = '.(isset($this->debit) ? ((float) $this->debit) :
"null").
',';
1583 $sql .=
' credit = '.(isset($this->credit) ? ((float) $this->credit) :
"null").
',';
1584 $sql .=
' montant = '.(isset($this->montant) ? ((float) $this->montant) :
"null").
',';
1585 $sql .=
' sens = '.(isset($this->sens) ?
"'".$this->db->escape($this->sens).
"'" :
"null").
',';
1586 $sql .=
' fk_user_author = '.(isset($this->fk_user_author) ? ((int) $this->fk_user_author) :
"null").
',';
1587 $sql .=
' import_key = '.(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
',';
1588 $sql .=
' code_journal = '.(isset($this->code_journal) ?
"'".$this->db->escape($this->code_journal).
"'" :
"null").
',';
1589 $sql .=
' journal_label = '.(isset($this->journal_label) ?
"'".$this->db->escape($this->journal_label).
"'" :
"null").
',';
1590 $sql .=
' piece_num = '.(isset($this->piece_num) ? ((int) $this->piece_num) :
"null");
1591 $sql .=
' WHERE rowid='.((int) $this->
id);
1595 $resql = $this->db->query($sql);
1598 $this->errors[] =
'Error '.$this->db->lasterror();
1599 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1603 if (! $error && ! $notrigger) {
1604 $result = $this->call_trigger(
'BOOKKEEPING_MODIFY', $user);
1612 $this->db->rollback();
1616 $this->db->commit();
1632 public function updateByMvt($piece_num =
'', $field =
'', $value =
'', $mode =
'', $notrigger = 0)
1634 global
$conf, $user;
1638 if (!isset($sql_filter)) {
1644 $sqlwhere =
" WHERE piece_num = ".((int) $piece_num);
1645 $sqlwhere .=
" AND entity = " . ((int)
$conf->entity);
1646 $sqlwhere .= $sql_filter;
1649 $oldlines = array();
1651 $oldlines = $this->
fetchLinesForTrigger(
"SELECT rowid FROM ".$this->db->prefix().$this->table_element.$mode.$sqlwhere, $mode);
1652 if (!is_array($oldlines)) {
1658 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.$mode;
1659 $sql .=
" SET ".$this->db->sanitize($field).
" = ".(is_numeric($value) ? ((float) $value) :
"'".$this->db->escape($value).
"'");
1662 $resql = $this->db->query($sql);
1666 $this->errors[] =
'Error '.$this->db->lasterror();
1667 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1672 if (!$error && !$notrigger && $this->
callTriggerPerLine(
'BOOKKEEPING_MODIFY', array_keys($oldlines), $user, $mode, $oldlines) < 0) {
1677 $this->db->rollback();
1681 $this->db->commit();
1696 $resql = $this->db->query($sql);
1698 $this->errors[] =
'Error '.$this->db->lasterror();
1699 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1704 while ($obj = $this->db->fetch_object($resql)) {
1706 if ($line->fetch((
int) $obj->rowid,
null, $mode) <= 0) {
1707 $this->errors[] = $line->error;
1710 $lines[(int) $obj->rowid] = $line;
1712 $this->db->free($resql);
1730 foreach ($lineids as $lineid) {
1732 if ($line->fetch((
int) $lineid,
null, $mode) <= 0) {
1733 $this->errors[] = $line->error;
1736 if (isset($oldlines[$lineid])) {
1737 $line->oldcopy = $oldlines[$lineid];
1739 if ($line->call_trigger($triggername, $user) < 0) {
1740 $this->error = $line->error;
1741 $this->errors = array_merge($this->errors, $line->errors);
1757 public function delete(
User $user, $notrigger = 0, $mode =
'')
1766 } elseif ($result == 0) {
1768 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1770 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1781 $result = $this->call_trigger(
'BOOKKEEPING_DELETE', $user);
1788 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.$mode;
1789 $sql .=
' WHERE rowid='.((int) $this->
id);
1791 $resql = $this->db->query($sql);
1794 $this->errors[] =
'Error '.$this->db->lasterror();
1795 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1801 $this->db->rollback();
1805 $this->db->commit();
1823 if (!isset($sql_filter)) {
1829 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1830 $sql .=
" WHERE import_key = '".$this->db->escape($importkey).
"'";
1831 $sql .= $sql_filter;
1833 $resql = $this->db->query($sql);
1836 $this->errors[] =
"Error ".$this->db->lasterror();
1837 dol_syslog(get_class($this).
"::delete Error ".$this->db->lasterror(), LOG_ERR);
1838 $this->db->rollback();
1842 $this->db->commit();
1857 global
$conf, $langs;
1859 if (empty($delyear) && empty($journal)) {
1860 $this->error =
'ErrorOneFieldRequired';
1863 if (!empty($delmonth) && empty($delyear)) {
1864 $this->error =
'YearRequiredIfMonthDefined';
1869 if (!isset($sql_filter)) {
1877 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1878 $sql .=
" WHERE 1 = 1";
1880 if (!empty($journal)) {
1881 $sql .=
" AND code_journal = '".$this->db->escape($journal).
"'";
1883 $sql .=
" AND entity = " . ((int)
$conf->entity);
1885 $sql .=
" AND date_validated IS NULL";
1886 $sql .= $sql_filter;
1890 $resql = $this->db->query($sql);
1893 $this->errors[] =
"Error ".$this->db->lasterror();
1894 foreach ($this->errors as $errmsg) {
1895 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1896 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1898 $this->db->rollback();
1902 $this->db->commit();
1916 global
$conf, $user;
1919 if (!isset($sql_filter)) {
1930 $result = $this->call_trigger(
'BOOKKEEPING_DELETE', $user);
1939 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1940 $sql .=
" WHERE piece_num = ".(int) $piecenum;
1941 $sql .=
" AND date_validated IS NULL";
1942 $sql .=
" AND entity = " . ((int)
$conf->entity);
1943 $sql .= $sql_filter;
1945 $resql = $this->db->query($sql);
1948 $this->errors[] =
"Error ".$this->db->lasterror();
1949 foreach ($this->errors as $errmsg) {
1950 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1951 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1953 $this->db->rollback();
1956 $nbprocessed = $this->db->affected_rows($resql);
1962 $this->db->rollback();
1965 $this->db->commit();
1966 return $nbprocessed;
1995 $object->context[
'createfromclone'] =
'createfromclone';
1996 $result =
$object->create($user);
2001 $this->errors =
$object->errors;
2002 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2005 unset(
$object->context[
'createfromclone']);
2009 $this->db->commit();
2013 $this->db->rollback();
2032 $this->doc_date = $now;
2033 $this->doc_type =
'';
2034 $this->doc_ref =
'';
2036 $this->fk_docdet = 0;
2037 $this->thirdparty_code =
'CU001';
2038 $this->subledger_account =
'41100001';
2039 $this->subledger_label =
'My customer company';
2040 $this->numero_compte =
'411';
2041 $this->label_compte =
'Customer';
2042 $this->label_operation =
'Sales of pea';
2043 $this->debit = 99.9;
2044 $this->credit = 0.0;
2047 $this->fk_user_author = $user->id;
2048 $this->import_key =
'20201027';
2049 $this->code_journal =
'VT';
2050 $this->journal_label =
'Journal de vente';
2051 $this->piece_num = 1234;
2052 $this->date_creation = $now;
2068 $sql =
"SELECT piece_num, ref, doc_date, code_journal, journal_label, doc_ref, doc_type, fk_doc,";
2069 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation, date_lim_reglement, import_key";
2071 if ($mode !=
"_tmp") {
2072 $sql .=
", date_export";
2074 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
2075 $sql .=
" WHERE piece_num = ".((int) $piecenum);
2076 $sql .=
" AND entity = " . ((int)
$conf->entity);
2079 $result = $this->db->query($sql);
2081 $obj = $this->db->fetch_object($result);
2083 $this->piece_num = $obj->piece_num;
2084 $this->
ref = $obj->ref;
2085 $this->code_journal = $obj->code_journal;
2086 $this->journal_label = $obj->journal_label;
2087 $this->doc_date = $this->db->jdate($obj->doc_date);
2088 $this->doc_ref = $obj->doc_ref;
2089 $this->doc_type = $obj->doc_type;
2090 $this->fk_doc = $obj->fk_doc;
2091 $this->date_creation = $this->db->jdate($obj->date_creation);
2092 $this->date_modification = $this->db->jdate($obj->date_modification);
2093 if ($mode !=
"_tmp") {
2094 $this->date_export = $this->db->jdate($obj->date_export);
2096 $this->date_validation = $this->db->jdate($obj->date_validation);
2097 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
2098 $this->import_key = $obj->import_key;
2100 $this->error =
"Error ".$this->db->lasterror();
2101 dol_syslog(__METHOD__.$this->error, LOG_ERR);
2118 $sql =
"SELECT MAX(piece_num) + 1 as max FROM ".$this->db->prefix().$this->table_element.$mode;
2119 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2121 dol_syslog(get_class($this).
"::getNextNumMvt", LOG_DEBUG);
2123 $result = $this->db->query($sql);
2126 $obj = $this->db->fetch_object($result);
2128 $result = $obj->max;
2130 if (empty($result)) {
2135 $this->error =
"Error ".$this->db->lasterror();
2136 dol_syslog(get_class($this).
"::getNextNumMvt ".$this->error, LOG_ERR);
2147 public function getNextNumRef()
2149 global $langs,
$conf;
2150 $langs->load(
"accountancy");
2159 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
2160 foreach ($dirmodels as $reldir) {
2164 $mybool = ((bool) @include_once $dir.$file) || $mybool;
2168 dol_print_error(
null,
"Failed to include file ".$file);
2172 $obj =
new $classname();
2174 '@phan-var-force ModeleNumRefBookkeeping $obj';
2176 $numref = $obj->getNextValue($this);
2178 if ($numref !=
"") {
2181 $this->error = $obj->error;
2186 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_BOOKKEEPING_ADDON_NotDefined");
2204 $sql =
"SELECT rowid, doc_date, doc_type,";
2205 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
2206 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
2207 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, journal_label, piece_num,";
2208 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation";
2210 if ($mode !=
"_tmp") {
2211 $sql .=
", date_export";
2213 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
2214 $sql .=
" WHERE piece_num = ".((int) $piecenum);
2215 $sql .=
" AND entity = " . ((int)
$conf->entity);
2218 $result = $this->db->query($sql);
2220 while ($obj = $this->db->fetch_object($result)) {
2223 $line->id = $obj->rowid;
2225 $line->doc_date = $this->db->jdate($obj->doc_date);
2226 $line->doc_type = $obj->doc_type;
2227 $line->doc_ref = $obj->doc_ref;
2228 $line->fk_doc = $obj->fk_doc;
2229 $line->fk_docdet = $obj->fk_docdet;
2230 $line->thirdparty_code = $obj->thirdparty_code;
2231 $line->subledger_account = $obj->subledger_account;
2232 $line->subledger_label = $obj->subledger_label;
2233 $line->numero_compte = $obj->numero_compte;
2234 $line->label_compte = $obj->label_compte;
2235 $line->label_operation = $obj->label_operation;
2236 $line->debit = $obj->debit;
2237 $line->credit = $obj->credit;
2238 $line->montant = $obj->amount;
2239 $line->amount = $obj->amount;
2240 $line->sens = $obj->sens;
2241 $line->code_journal = $obj->code_journal;
2242 $line->journal_label = $obj->journal_label;
2243 $line->piece_num = $obj->piece_num;
2244 $line->date_creation = $obj->date_creation;
2245 $line->date_modification = $obj->date_modification;
2246 if ($mode !=
"_tmp") {
2247 $line->date_export = $obj->date_export;
2249 $line->date_validation = $obj->date_validation;
2251 $this->linesmvt[] = $line;
2254 $this->error =
"Error ".$this->db->lasterror();
2255 dol_syslog(__METHOD__.$this->error, LOG_ERR);
2274 $sql =
"SELECT rowid, doc_date, doc_type,";
2275 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
2276 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
2277 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, piece_num,";
2278 $sql .=
" date_validated as date_validation";
2279 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
2280 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2282 dol_syslog(get_class($this).
"::export_bookkeeping", LOG_DEBUG);
2284 $resql = $this->db->query($sql);
2287 $this->linesexport = array();
2289 $num = $this->db->num_rows($resql);
2290 while ($obj = $this->db->fetch_object($resql)) {
2293 $line->id = $obj->rowid;
2295 $line->doc_date = $this->db->jdate($obj->doc_date);
2296 $line->doc_type = $obj->doc_type;
2297 $line->doc_ref = $obj->doc_ref;
2298 $line->fk_doc = $obj->fk_doc;
2299 $line->fk_docdet = $obj->fk_docdet;
2300 $line->thirdparty_code = $obj->thirdparty_code;
2301 $line->subledger_account = $obj->subledger_account;
2302 $line->subledger_label = $obj->subledger_label;
2303 $line->numero_compte = $obj->numero_compte;
2304 $line->label_compte = $obj->label_compte;
2305 $line->label_operation = $obj->label_operation;
2306 $line->debit = $obj->debit;
2307 $line->credit = $obj->credit;
2308 $line->montant = $obj->amount;
2309 $line->amount = $obj->amount;
2310 $line->sens = $obj->sens;
2311 $line->code_journal = $obj->code_journal;
2312 $line->piece_num = $obj->piece_num;
2313 $line->date_validation = $obj->date_validation;
2315 $this->linesexport[] = $line;
2317 $this->db->free($resql);
2321 $this->error =
"Error ".$this->db->lasterror();
2322 dol_syslog(get_class($this).
"::export_bookkeeping ".$this->error, LOG_ERR);
2337 global
$conf, $user;
2343 if (!isset($sql_filter)) {
2349 $tmpBookkeeping =
new self($this->db);
2350 $tmpData = $this->db->getRow(
"SELECT doc_date, code_journal, ref FROM {$this->db->prefix()}accounting_bookkeeping_tmp WHERE piece_num = '{$this->db->escape($piece_num)}' AND entity = {$conf->entity}");
2351 $tmpBookkeeping->doc_date = $this->db->jdate($tmpData->doc_date);
2352 $tmpBookkeeping->code_journal = $tmpData->code_journal;
2355 $ref = $tmpData->ref ?: $tmpBookkeeping->getNextNumRef();
2356 if ($direction == 0) {
2360 if ($next_piecenum < 0) {
2365 $this->piece_num = $next_piecenum;
2369 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity).
" AND numero_compte IS NULL AND debit = 0 AND credit = 0";
2370 $resql = $this->db->query($sql);
2373 $this->errors[] =
'Error '.$this->db->lasterror();
2374 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2379 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
' (doc_date, doc_type, ref,';
2380 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2381 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2382 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num, date_creation)';
2383 $sql .=
' SELECT doc_date, doc_type,' .
"'".$this->db->escape($ref).
"',";
2384 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2385 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2386 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.((int) $next_piecenum).
", '".$this->db->idate($now).
"'";
2387 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND numero_compte IS NOT NULL AND entity = ' .((int)
$conf->entity);
2388 $sql .= $sql_filter;
2389 $resql = $this->db->query($sql);
2392 $this->errors[] =
'Error '.$this->db->lasterror();
2393 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2398 if (!$error && !$notrigger) {
2399 $newlines = $this->
fetchLinesForTrigger(
'SELECT rowid FROM '.$this->db->prefix().$this->table_element.
' WHERE piece_num = '.((
int) $next_piecenum).
' AND entity = '.((
int)
$conf->entity));
2400 if (!is_array($newlines) || $this->
callTriggerPerLine(
'BOOKKEEPING_CREATE', array_keys($newlines), $user) < 0) {
2406 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2407 $resql = $this->db->query($sql);
2410 $this->errors[] =
'Error '.$this->db->lasterror();
2411 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2414 } elseif ($direction == 1) {
2415 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2416 $resql = $this->db->query($sql);
2419 $this->errors[] =
'Error '.$this->db->lasterror();
2420 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2424 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
'_tmp (doc_date, doc_type, ref,';
2425 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2426 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2427 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)';
2428 $sql .=
' SELECT doc_date, doc_type,' .
"'".$this->db->escape($ref).
"',";
2429 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2430 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2431 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num';
2432 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2433 $sql .= $sql_filter;
2434 $resql = $this->db->query($sql);
2437 $this->errors[] =
'Error '.$this->db->lasterror();
2438 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2443 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2444 $sql .= $sql_filter;
2445 $resql = $this->db->query($sql);
2448 $this->errors[] =
'Error '.$this->db->lasterror();
2449 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2454 $this->db->commit();
2457 $this->db->rollback();
2485 public function select_account($selectid, $htmlname =
'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase =
'')
2490 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
2494 $sql =
"SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version";
2495 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as ab";
2496 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as aa ON aa.account_number = ab.numero_compte";
2497 $sql .=
" AND aa.active = 1";
2498 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2499 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2500 $sql .=
" AND ab.entity = " . ((int)
$conf->entity);
2501 $sql .=
" ORDER BY account_number ASC";
2503 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2504 $resql = $this->db->query($sql);
2507 $this->error =
"Error ".$this->db->lasterror();
2508 dol_syslog(get_class($this).
"::select_account ".$this->error, LOG_ERR);
2517 while ($obj = $this->db->fetch_object($resql)) {
2520 $select_value_in = $obj->rowid;
2521 $select_value_out = $obj->rowid;
2523 if ($select_in == 1) {
2524 $select_value_in = $obj->account_number;
2526 if ($select_out == 1) {
2527 $select_value_out = $obj->account_number;
2532 if (($selectid !=
'') && $selectid == $select_value_in) {
2533 $selected = $select_value_out;
2536 $options[$select_value_out] = $label;
2539 $out .=
Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0,
'', 0, 0, 0,
'',
'maxwidth300');
2540 $this->db->free($resql);
2556 $sql =
"SELECT root.rowid, root.account_number, root.label as label,";
2557 $sql .=
" parent.rowid as parent_rowid, parent.account_number as parent_account_number, parent.label as parent_label";
2558 $sql .=
" FROM ".$this->db->prefix().
"accounting_account as aa";
2559 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2560 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2561 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as parent ON aa.account_parent = parent.rowid AND parent.active = 1";
2562 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as root ON parent.account_parent = root.rowid AND root.active = 1";
2563 $sql .=
" WHERE aa.account_number = '".$this->db->escape($account).
"'";
2564 $sql .=
" AND aa.entity = " . ((int)
$conf->entity);
2566 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2567 $resql = $this->db->query($sql);
2570 if ($this->db->num_rows($resql)) {
2571 $obj = $this->db->fetch_object($resql);
2574 $result = array(
'id' => $obj->rowid,
'account_number' => $obj->account_number,
'label' => $obj->label);
2577 $this->error =
"Error ".$this->db->lasterror();
2578 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2597 $sql =
"SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
2598 $sql .=
" FROM ".$this->db->prefix().
"accounting_account as aa ";
2599 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2600 $sql .=
" AND aa.account_number = '".$this->db->escape($account).
"'";
2601 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2602 $sql .=
" AND aa.active = 1";
2603 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
2604 $sql .=
" WHERE aa.entity = " . ((int)
$conf->entity);
2606 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2607 $resql = $this->db->query($sql);
2609 $obj = (object) array(
'label' =>
'');
2610 if ($this->db->num_rows($resql)) {
2611 $obj = $this->db->fetch_object($resql);
2613 if (empty($obj->category)) {
2616 return $obj->label.
' ('.$obj->category.
')';
2619 $this->error =
"Error ".$this->db->lasterror();
2620 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2636 $alias = trim($alias);
2637 $alias = !empty($alias) && strpos($alias,
'.') ===
false ? $alias .
"." : $alias;
2639 if (!isset(self::$can_modify_bookkeeping_sql_cached[$alias]) || $force) {
2645 $sql_list = array();
2646 if (!empty(
$conf->cache[
'active_fiscal_period_cached']) && is_array(
$conf->cache[
'active_fiscal_period_cached'])) {
2648 foreach (
$conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2649 $sql_list[$i] =
"(";
2650 $sql_list[$i] .=
"'".$this->db->idate($fiscal_period[
'date_start']) .
"' <= ".$this->db->sanitize($alias).
"doc_date";
2652 if (!empty($fiscal_period[
'date_end'])) {
2653 $sql_list[$i] .=
" AND ";
2654 $sql_list[$i] .= $this->db->sanitize($alias).
"doc_date <= '" . $this->db->idate((
int) $fiscal_period[
'date_end']).
"'";
2656 $sql_list[$i] .=
")";
2660 $sqlsanitized = implode(
' OR ', $sql_list);
2661 self::$can_modify_bookkeeping_sql_cached[$alias] = empty($sql_list) ?
"" :
" AND (".$sqlsanitized.
")";
2664 return self::$can_modify_bookkeeping_sql_cached[$alias];
2686 $result = $bookkeeping->fetch($id,
null, $mode);
2691 if (!empty(
$conf->cache[
'closed_fiscal_period_cached']) && is_array(
$conf->cache[
'closed_fiscal_period_cached'])) {
2692 foreach (
$conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2693 if ($fiscal_period[
'date_start'] <= $bookkeeping->doc_date && $bookkeeping->doc_date <= $fiscal_period[
'date_end']) {
2707 $result = $bookkeeping->fetch($id,
null, $mode);
2712 if (!empty(
$conf->cache[
'active_fiscal_period_cached']) && is_array(
$conf->cache[
'active_fiscal_period_cached'])) {
2713 foreach (
$conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2715 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'])) {
2739 global $hookmanager;
2740 $accountingLabelOperation =
'';
2743 $truncThirdpartyName = 16;
2746 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2748 $accountingLabelOperation = $thirdpartyname;
2750 if (!empty($reference)) {
2751 $accountingLabelOperation .=
' - '. $reference;
2753 if (!empty($labelaccount)) {
2754 $accountingLabelOperation .=
' - '. $labelaccount;
2756 } elseif (
getDolGlobalInt(
'ACCOUNTING_LABEL_OPERATION_ON_TRANSFER') == 1) {
2757 $truncThirdpartyName = 32;
2760 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2762 $accountingLabelOperation = $thirdpartyname;
2764 if (!empty($reference)) {
2765 $accountingLabelOperation .=
' - '. $reference;
2767 } elseif (
getDolGlobalInt(
'ACCOUNTING_LABEL_OPERATION_ON_TRANSFER') == 2) {
2768 $truncThirdpartyName = 64;
2771 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2773 $accountingLabelOperation = $thirdpartyname;
2779 'thirdpartyname' => $thirdpartyname,
2780 'reference' => $reference,
2781 'labelaccount' => $labelaccount,
2782 'accountingLabelOperation' => $accountingLabelOperation,
2785 if (!isset($hookmanager->resPrint)) {
2786 $hookmanager->resPrint =
'';
2789 $reshook = $hookmanager->executeHooks(
'accountingLabelForOperation', $parameters, $this, $action);
2792 $accountingLabelOperation = $hookmanager->resPrint;
2793 } elseif ($reshook == 0 && !empty($hookmanager->resPrint)) {
2794 $accountingLabelOperation .= $hookmanager->resPrint;
2797 dol_syslog(get_class($this) .
"::accountingLabelForOperation: " . $accountingLabelOperation, LOG_DEBUG);
2798 return $accountingLabelOperation;
2818 if (!empty(
$conf->cache[
'closed_fiscal_period_cached']) && is_array(
$conf->cache[
'closed_fiscal_period_cached'])) {
2819 foreach (
$conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2820 if ($fiscal_period[
'date_start'] <= $date && $date <= $fiscal_period[
'date_end']) {
2833 if (!empty(
$conf->cache[
'active_fiscal_period_cached']) && is_array(
$conf->cache[
'active_fiscal_period_cached'])) {
2834 foreach (
$conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2836 if (!empty($fiscal_period[
'date_start']) && $fiscal_period[
'date_start'] <= $date && (empty($fiscal_period[
'date_end']) || $date <= $fiscal_period[
'date_end'])) {
2857 if ($mode ==
'active') {
2858 if (!isset(
$conf->cache[
'active_fiscal_period_cached']) || $force) {
2859 $sql =
"SELECT date_start, date_end";
2860 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2861 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2862 $sql .=
" AND statut = 0";
2864 $resql = $this->db->query($sql);
2866 $this->errors[] = $this->db->lasterror();
2871 while ($obj = $this->db->fetch_object($resql)) {
2873 $date_end_base = $this->db->jdate($obj->date_end);
2877 'date_end' => $date_end,
2880 $conf->cache[
'active_fiscal_period_cached'] = $list;
2883 if ($mode ==
'closed') {
2884 if (!isset(
$conf->cache[
'closed_fiscal_period_cached']) || $force) {
2885 $sql =
"SELECT date_start, date_end";
2886 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2887 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2888 $sql .=
" AND statut = 1";
2890 $resql = $this->db->query($sql);
2892 $this->errors[] = $this->db->lasterror();
2897 while ($obj = $this->db->fetch_object($resql)) {
2899 $date_end_base = $this->db->jdate($obj->date_end);
2904 'date_end' => $date_end,
2907 $conf->cache[
'closed_fiscal_period_cached'] = $list;
2924 $sql =
"SELECT rowid, label, date_start, date_end, statut";
2925 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2926 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2927 $sql .= $this->db->order(
'date_start',
'ASC');
2929 $resql = $this->db->query($sql);
2931 $this->errors[] = $this->db->lasterror();
2935 while ($obj = $this->db->fetch_object($resql)) {
2936 $list[$obj->rowid] = array(
2937 'id' => (
int) $obj->rowid,
2938 'label' => $obj->label,
2939 'date_start' => $this->db->jdate($obj->date_start),
2940 'date_end' => $this->db->jdate($obj->date_end),
2941 'status' => (
int) $obj->statut,
2963 $sql =
"SELECT YEAR(b.doc_date) as year";
2964 for ($i = 1; $i <= 12; $i++) {
2965 $sql .=
", SUM(".$this->db->ifsql(
"MONTH(b.doc_date) = ".((
int) $i),
"1",
"0") .
") AS month".((int) $i);
2967 $sql .=
", COUNT(b.rowid) as total";
2968 $sql .=
" FROM " . $this->db->prefix() . $this->table_element .
" as b";
2969 $sql .=
" WHERE b.doc_date >= '" . $this->db->idate(
$date_start) .
"'";
2970 $sql .=
" AND b.doc_date <= '" . $this->db->idate($date_end) .
"'";
2971 $sql .=
" AND b.entity IN (" .
getEntity(
'bookkeeping', 0) .
")";
2976 $sql .=
" AND NOT EXISTS (SELECT rowid FROM ".MAIN_DB_PREFIX.
'accounting_fiscalyear as af WHERE b.doc_date >= af.date_start AND b.doc_date <= af.date_end AND af.entity = '.((int)
$conf->entity).
" AND af.statut = 1)";
2979 $sql .=
" AND date_validated IS NULL";
2982 $sql .=
" GROUP BY YEAR(b.doc_date)";
2983 $sql .= $this->db->order(
"year",
'ASC');
2986 $resql = $this->db->query($sql);
2988 $this->errors[] = $this->db->lasterror();
2992 while ($obj = $this->db->fetch_object($resql)) {
2993 $total += (int) $obj->total;
2995 'year' => (
int) $obj->year,
2997 'total' => (
int) $obj->total,
2999 for ($i = 1; $i <= 12; $i++) {
3000 $year_list[
'count'][$i] = (int) $obj->{
'month' . $i};
3003 $list[] = $year_list;
3006 $this->db->free($resql);
3028 $sql =
" UPDATE " . $this->db->prefix() . $this->table_element;
3029 $sql .=
" SET date_validated = '" . $this->db->idate($now) .
"'";
3030 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
3031 $sql .=
" AND DATE(doc_date) >= '" . $this->db->idate(
$date_start) .
"'";
3032 $sql .=
" AND DATE(doc_date) <= '" . $this->db->idate($date_end) .
"'";
3033 $sql .=
" AND date_validated IS NULL";
3036 $resql = $this->db->query($sql);
3038 $this->errors[] = $this->db->lasterror();
3058 $income_statement_amount = 0;
3060 if (
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
3061 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
3063 $pcg_type_filter = array();
3064 foreach ($accounting_groups_used_for_income_statement as $item) {
3065 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
3069 $sql .=
" t.numero_compte,";
3070 $sql .=
" aa.pcg_type,";
3071 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as accounting_result";
3072 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
3073 $sql .=
' LEFT JOIN ' . $this->db->prefix() .
'accounting_account as aa ON aa.account_number = t.numero_compte';
3074 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
3075 $sql .=
" AND aa.entity = " . ((int)
$conf->entity);
3076 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM ' . $this->db->prefix() .
'accounting_system WHERE rowid = ' . ((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')) .
')';
3077 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
3078 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate(
$date_start) .
"'";
3079 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
3080 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
3082 $resql = $this->db->query($sql);
3084 $this->errors[] =
'Error ' . $this->db->lasterror();
3085 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3087 while ($obj = $this->db->fetch_object($resql)) {
3088 $income_statement_amount += $obj->accounting_result;
3093 return (
string) $income_statement_amount;
3105 public function closeFiscalPeriod($fiscal_period_id, $new_fiscal_period_id, $separate_auxiliary_account =
false, $generate_bookkeeping_records =
true)
3107 global
$conf, $langs, $user;
3110 $fiscal_period_id = max(0, $fiscal_period_id);
3112 if (empty($fiscal_period_id)) {
3113 $langs->load(
'errors');
3114 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3119 $result = $fiscal_period->fetch($fiscal_period_id);
3121 $this->error = $fiscal_period->error;
3122 $this->errors = $fiscal_period->errors;
3124 } elseif (empty($fiscal_period->id)) {
3125 $langs->loadLangs(array(
'errors',
'compta'));
3126 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
3129 if (empty($fiscal_period->date_end)) {
3130 $langs->load(
'errors');
3131 $this->errors[] = $langs->trans(
'ErrorAccountancyClosureNoEndDate');
3136 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
3137 if (empty($new_fiscal_period_id)) {
3138 $langs->load(
'errors');
3139 $this->errors[] = $langs->trans(
'ErrorBadParameters').
' - '.$langs->trans(
'AccountancyClosureStep3NewFiscalPeriod');
3142 $new_fiscal_period =
new Fiscalyear($this->db);
3143 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
3145 $this->error = $new_fiscal_period->error;
3146 $this->errors = $new_fiscal_period->errors;
3148 } elseif (empty($new_fiscal_period->id)) {
3149 $langs->loadLangs(array(
'errors',
'compta'));
3150 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
3153 if ($new_fiscal_period->date_start <= $fiscal_period->date_end) {
3154 $langs->load(
'errors');
3155 $this->errors[] = $langs->trans(
'ErrorAccountancyClosureNoNextFiscalPeriod');
3162 $fiscal_period->statut = Fiscalyear::STATUS_CLOSED;
3163 $fiscal_period->status = Fiscalyear::STATUS_CLOSED;
3164 $result = $fiscal_period->update($user);
3166 $this->error = $fiscal_period->error;
3167 $this->errors = $fiscal_period->errors;
3171 if (!$error && !empty($generate_bookkeeping_records)) {
3173 if (empty($journal_id)) {
3174 $langs->loadLangs(array(
'errors',
'accountancy'));
3175 $this->errors[] = $langs->trans(
'ErrorBadParameters') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
3182 $result = $journal->fetch($journal_id);
3184 $this->error = $journal->error;
3185 $this->errors = $journal->errors;
3187 } elseif ($result == 0) {
3188 $langs->loadLangs(array(
'errors',
'accountancy'));
3189 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
3196 if (!$error && is_object($journal)) {
3197 $accounting_groups_used_for_balance_sheet_account = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))),
'strlen');
3198 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
3200 $pcg_type_filter = array();
3201 $tmp = array_merge($accounting_groups_used_for_balance_sheet_account, $accounting_groups_used_for_income_statement);
3202 foreach ($tmp as $item) {
3203 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
3207 $sql .=
" t.numero_compte,";
3208 if ($separate_auxiliary_account) {
3209 $sql .=
" NULLIF(t.subledger_account, '') as subledger_account,";
3211 $sql .=
" aa.pcg_type,";
3212 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as opening_balance";
3213 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
3214 $sql .=
' LEFT JOIN ' . $this->db->prefix() .
'accounting_account as aa ON aa.account_number = t.numero_compte';
3215 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
3216 $sql .=
" AND aa.entity = ". ((int)
$conf->entity);
3217 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM '.$this->db->prefix().
'accounting_system WHERE rowid = '.((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')).
')';
3218 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
3219 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
3220 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
3221 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
3222 if ($separate_auxiliary_account) {
3223 $sql .=
" , NULLIF(t.subledger_account, '')";
3225 $sql .=
' HAVING (SUM(t.credit) - SUM(t.debit)) != 0 ';
3226 $sql .= $this->db->order(
"t.numero_compte",
"ASC");
3228 $resql = $this->db->query($sql);
3230 $this->errors[] =
'Error ' . $this->db->lasterror();
3231 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3236 $income_statement_amount = 0;
3237 while ($obj = $this->db->fetch_object($resql)) {
3238 if (in_array($obj->pcg_type, $accounting_groups_used_for_income_statement)) {
3239 $income_statement_amount += $obj->opening_balance;
3242 $mt = $obj->opening_balance;
3245 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3247 $bookkeeping->date_lim_reglement =
'';
3248 $bookkeeping->doc_ref = $fiscal_period->label;
3250 $bookkeeping->date_creation = $now;
3251 $bookkeeping->doc_type =
'closure';
3252 $bookkeeping->fk_doc = $fiscal_period->id;
3253 $bookkeeping->fk_docdet = 0;
3254 $bookkeeping->thirdparty_code =
'';
3256 if ($separate_auxiliary_account) {
3257 $bookkeeping->subledger_account = $obj->subledger_account;
3259 $sql .=
" subledger_label";
3260 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
3261 $sql .=
" WHERE subledger_account = '" . $this->db->escape($obj->subledger_account) .
"'";
3262 $sql .=
" ORDER BY doc_date DESC";
3264 $result = $this->db->query($sql);
3266 $this->errors[] =
'Error: ' . $this->db->lasterror();
3267 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3270 $objtmp = $this->db->fetch_object($result);
3271 $bookkeeping->subledger_label = $objtmp->subledger_label;
3273 $bookkeeping->subledger_account =
null;
3274 $bookkeeping->subledger_label =
null;
3277 $bookkeeping->numero_compte = $obj->numero_compte;
3279 $accountingaccount->fetch(0, $obj->numero_compte);
3280 $bookkeeping->label_compte = $accountingaccount->label;
3282 $bookkeeping->label_operation = $new_fiscal_period->label;
3283 $bookkeeping->montant = $mt;
3284 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
3285 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
3286 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
3287 $bookkeeping->code_journal = $journal->code;
3288 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
3289 $bookkeeping->fk_user_author = $user->id;
3290 $bookkeeping->entity =
$conf->entity;
3292 $result = $bookkeeping->create($user);
3294 $this->setErrorsFromObject($bookkeeping);
3302 if (!$error && $income_statement_amount != 0) {
3303 $mt = $income_statement_amount;
3305 $accountingaccount->fetch(0,
getDolGlobalString($income_statement_amount < 0 ?
'ACCOUNTING_RESULT_LOSS' :
'ACCOUNTING_RESULT_PROFIT'),
true);
3308 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3310 $bookkeeping->date_lim_reglement =
'';
3311 $bookkeeping->doc_ref = $fiscal_period->label;
3313 $bookkeeping->date_creation = $now;
3314 $bookkeeping->doc_type =
'closure';
3315 $bookkeeping->fk_doc = $fiscal_period->id;
3316 $bookkeeping->fk_docdet = 0;
3317 $bookkeeping->thirdparty_code =
'';
3341 $bookkeeping->subledger_account =
null;
3342 $bookkeeping->subledger_label =
null;
3345 $bookkeeping->numero_compte = $accountingaccount->account_number;
3346 $bookkeeping->label_compte = $accountingaccount->label;
3348 $bookkeeping->label_operation = $new_fiscal_period->label;
3349 $bookkeeping->montant = $mt;
3350 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
3351 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
3352 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
3353 $bookkeeping->code_journal = $journal->code;
3354 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
3355 $bookkeeping->fk_user_author = $user->id;
3356 $bookkeeping->entity =
$conf->entity;
3358 $result = $bookkeeping->create($user);
3360 $this->setErrorsFromObject($bookkeeping);
3364 $this->db->free($resql);
3370 $this->db->rollback();
3373 $this->db->commit();
3390 global
$conf, $langs, $user;
3393 $fiscal_period_id = max(0, $fiscal_period_id);
3394 if (empty($fiscal_period_id)) {
3395 $langs->load(
'errors');
3396 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3400 $result = $fiscal_period->fetch($fiscal_period_id);
3402 $this->error = $fiscal_period->error;
3403 $this->errors = $fiscal_period->errors;
3405 } elseif (empty($fiscal_period->id)) {
3406 $langs->loadLangs(array(
'errors',
'compta'));
3407 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
3412 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
3413 if (empty($new_fiscal_period_id)) {
3414 $langs->load(
'errors');
3415 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3418 $new_fiscal_period =
new Fiscalyear($this->db);
3419 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
3421 $this->error = $new_fiscal_period->error;
3422 $this->errors = $new_fiscal_period->errors;
3424 } elseif (empty($new_fiscal_period->id)) {
3425 $langs->loadLangs(array(
'errors',
'compta'));
3426 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
3431 $inventory_journal_id = max(0, $inventory_journal_id);
3432 if (empty($inventory_journal_id)) {
3433 $langs->load(
'errors');
3434 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3439 $result = $inventory_journal->fetch($inventory_journal_id);
3441 $this->error = $inventory_journal->error;
3442 $this->errors = $inventory_journal->errors;
3444 } elseif ($result == 0) {
3445 $langs->loadLangs(array(
'errors',
'accountancy'));
3446 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'InventoryJournal');
3453 $sql =
'SELECT t.rowid';
3454 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
3455 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
3456 $sql .=
" AND code_journal = '" . $this->db->escape($inventory_journal->code) .
"'";
3457 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate(
$date_start) .
"'";
3458 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
3459 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
3460 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
3462 $resql = $this->db->query($sql);
3464 $this->errors[] =
'Error ' . $this->db->lasterror();
3465 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3470 while ($obj = $this->db->fetch_object($resql)) {
3472 $result = $bookkeeping->fetch($obj->rowid);
3474 $this->error = $inventory_journal->error;
3475 $this->errors = $inventory_journal->errors;
3478 } elseif ($result == 0) {
3479 $langs->loadLangs(array(
'errors',
'accountancy'));
3480 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'LineId') .
': ' . $obj->rowid;
3485 $bookkeeping->id = 0;
3486 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3487 $bookkeeping->doc_ref = $new_fiscal_period->label;
3488 $bookkeeping->date_creation = $now;
3489 $bookkeeping->doc_type =
'accounting_reversal';
3490 $bookkeeping->fk_doc = $new_fiscal_period->id;
3491 $bookkeeping->fk_docdet = 0;
3493 $bookkeeping->montant = -$bookkeeping->montant;
3494 $bookkeeping->sens = ($bookkeeping->montant >= 0) ?
'C' :
'D';
3495 $old_debit = $bookkeeping->debit;
3496 $bookkeeping->debit = $bookkeeping->credit;
3497 $bookkeeping->credit = $old_debit;
3499 $bookkeeping->fk_user_author = $user->id;
3500 $bookkeeping->entity =
$conf->entity;
3502 $result = $bookkeeping->create($user);
3504 $this->error = $bookkeeping->error;
3505 $this->errors = $bookkeeping->errors;
3510 $this->db->free($resql);
3514 $this->db->rollback();
3517 $this->db->commit();
3531 global $langs, $user;
3541 if ((
int) $accounting_account > 0) {
3542 $accountingaccount->fetch($accounting_account);
3544 foreach ($toselect as
$id) {
3545 if ($bookkeeping->fetch(
$id)) {
3547 $accountcustcode =
'411';
3553 $accountsuppcode =
'401';
3558 if (strpos($bookkeeping->numero_compte, $accountcustcode) === 0 || strpos($bookkeeping->numero_compte, $accountsuppcode) === 0) {
3559 $echecT[] = $bookkeeping->numero_compte;
3563 $bookkeeping->numero_compte = $accountingaccount->account_number;
3564 $bookkeeping->label_compte = $accountingaccount->label;
3566 $result = $bookkeeping->update($user);
3571 $this->error = $bookkeeping->error;
3572 $this->errors = $bookkeeping->errors;
3579 $echecImplode = implode(
",", $echecT);
3581 $this->error = $langs->trans(
'NoAccountSelected');
3582 $this->errors[] = $this->error;
3584 $this->db->rollback();
3588 setEventMessages($nb .
" " . $langs->trans(
'AssignAccountsSuccess'),
null,
'mesgs');
3589 } elseif ($nb > 0) {
3590 setEventMessages($nb .
" " . $langs->trans(
'AssignAccountSuccess'),
null,
'mesgs');
3592 $this->error = $langs->trans(
'AssignAccountError');
3593 $this->errors[] = $this->error;
3597 if (!empty($echecImplode)) {
3598 $nbEchec = count(explode(
',', $echecImplode));
3600 $nbEchec == 1 ? $langs->trans(
'NoAccountChangedWithAccountNumber') .
' ' . $echecImplode : $langs->trans(
'NoAccountsChangedWithAccountNumber') .
' ' . $echecImplode,
3607 $this->db->rollback();
3610 $this->db->commit();
3623 public function newClone($piecenum, $code_journal, $docdate)
3630 $accountingJournal->fetch(0, $code_journal);
3634 $periodeFiscal = $bookKeepingValid->validBookkeepingDate($docdate);
3635 if ($periodeFiscal < 0) {
3638 } elseif ($periodeFiscal == 0) {
3640 $this->error = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
3642 $this->error = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
3644 $this->errors[] = $this->error;
3650 $bookKeepingInstance =
new BookKeeping($this->db);
3651 $pieceNumNext = $bookKeepingInstance->getNextNumMvt();
3654 $sqlRowidClone =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE piece_num = ".((int) $piecenum);
3655 $resqlRowidClone = $this->db->query($sqlRowidClone);
3657 if ($resqlRowidClone) {
3658 while ($objRowidClone = $this->db->fetch_object($resqlRowidClone)) {
3659 $cloneId[] = $objRowidClone->rowid;
3662 foreach ($cloneId as $toselectid) {
3664 if ($bookKeeping->fetch($toselectid)) {
3665 $code_journal =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $code_journal : $bookKeeping->code_journal;
3666 $journal_label =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $accountingJournal->label : $bookKeeping->journal_label;
3668 $sql =
"SELECT piece_num, label_operation, numero_compte, label_compte, doc_type, code_journal, fk_user_author, doc_ref,";
3669 $sql .=
" fk_doc, fk_docdet, debit, credit, journal_label, sens, montant, subledger_account, subledger_label";
3670 $sql .=
" FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping";
3671 $sql .=
" WHERE rowid = " . ((int) $toselectid);
3672 $resql = $this->db->query($sql);
3675 while ($obj = $this->db->fetch_object($resql)) {
3676 $docRef = $obj->doc_ref;
3677 if (preg_match(
'/ \((\d+)\)$/', $docRef, $matches)) {
3678 $docRef = preg_replace(
'/ \(\d+\)$/',
' (' . (((
int) $matches[1]) + 1) .
')', $docRef);
3683 $sql_insert =
"INSERT INTO " . MAIN_DB_PREFIX .
"accounting_bookkeeping";
3684 $sql_insert .=
" (piece_num, label_operation, numero_compte, label_compte, doc_type, code_journal, doc_date, fk_user_author, doc_ref,";
3685 $sql_insert .=
" fk_doc, fk_docdet, debit, credit, date_creation, journal_label, sens, montant, subledger_account, subledger_label)";
3686 $sql_insert .=
" VALUES";
3687 $sql_insert .=
" (" . ((int) $pieceNumNext) .
", '" . $this->db->escape($obj->label_operation) .
"', '" . $this->db->escape($obj->numero_compte) .
"', '" . $this->db->escape($obj->label_compte) .
"', '" . $this->db->escape($obj->doc_type) .
"', '" . $this->db->escape($code_journal) .
"', '" . $this->db->idate($docdate) .
"', '" . $this->db->escape($obj->fk_user_author) .
"', '" . $this->db->escape($docRef) .
"', ";
3688 $sql_insert .=
" ". ((int) $obj->fk_doc) .
", " . ((int) $obj->fk_docdet) .
", " . (float) $obj->debit .
", " . (
float) $obj->credit .
", '" . $this->db->idate($docdate) .
"', '" . $this->db->escape($journal_label) .
"', '" . $this->db->escape($obj->sens) .
"', " . (float) $obj->montant .
", '" . $this->db->escape($obj->subledger_account) .
"', '" . $this->db->escape($obj->subledger_label) .
"')";
3690 $resqlInsert = $this->db->query($sql_insert);
3693 setEventMessages($langs->trans(
'CloningSuccess', $pieceNumNext),
null,
'mesgs');
3695 $this->error = $langs->trans(
'CloningFailed') . $this->db->lasterror();
3696 $this->errors[] = $this->error;
3706 $this->db->rollback();
3709 $this->db->commit();
3724 global $langs, $user;
3730 if (empty($docdate)) {
3734 $idImplodeSelect = implode(
',', $toselect);
3737 $sqlPieceNum =
"SELECT DISTINCT(piece_num) FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE rowid IN (".$this->db->sanitize($idImplodeSelect).
")";
3738 $resqlPieceNum = $this->db->query($sqlPieceNum);
3740 if ($resqlPieceNum) {
3741 while ($objPieceNum = $this->db->fetch_object($resqlPieceNum)) {
3742 $pieceNumT[] = $objPieceNum->piece_num;
3745 foreach ($pieceNumT as $pieceNum) {
3747 $accountingJournal->fetch(0, $code_journal);
3749 $periodeFiscal = $bookKeepingValid->validBookkeepingDate($docdate);
3750 if ($periodeFiscal < 0) {
3752 } elseif ($periodeFiscal == 0) {
3754 $this->error = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
3756 $this->error = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
3758 $this->errors[] = $this->error;
3762 $bookKeepingInstance =
new BookKeeping($this->db);
3763 $pieceNumNext = $bookKeepingInstance->getNextNumMvt();
3765 $sqlRowidClone =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE piece_num = ".((int) $pieceNum);
3766 $resqlRowidClone = $this->db->query($sqlRowidClone);
3768 if ($resqlRowidClone) {
3769 while ($objRowidClone = $this->db->fetch_object($resqlRowidClone)) {
3770 $cloneId[] = $objRowidClone->rowid;
3773 foreach ($cloneId as $toselectid) {
3775 if ($bookKeeping->fetch($toselectid)) {
3776 $code_journal =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $code_journal : $bookKeeping->code_journal;
3777 $journal_label =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $accountingJournal->label : $bookKeeping->journal_label;
3778 $sql =
"SELECT piece_num, label_operation, numero_compte, label_compte, subledger_account, subledger_label, doc_type, code_journal, fk_user_author, doc_ref, fk_doc, fk_docdet, debit, credit, journal_label, sens, montant";
3779 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping WHERE rowid = " . ((int) $toselectid);
3781 $resql = $this->db->query($sql);
3783 while ($obj = $this->db->fetch_object($resql)) {
3784 $docRef = $obj->doc_ref;
3785 if (preg_match(
'/ \((\d+)\)$/', $docRef, $matches)) {
3786 $docRef = preg_replace(
'/ \(\d+\)$/',
' (' . (((
int) $matches[1]) + 1) .
')', $docRef);
3791 $sql_insert =
"INSERT INTO ".$this->db->prefix().
"accounting_bookkeeping (";
3792 $sql_insert .=
" piece_num";
3793 $sql_insert .=
", label_operation";
3794 $sql_insert .=
", numero_compte";
3795 $sql_insert .=
", label_compte";
3796 $sql_insert .=
", subledger_account";
3797 $sql_insert .=
", subledger_label";
3798 $sql_insert .=
", doc_type";
3799 $sql_insert .=
", code_journal";
3800 $sql_insert .=
", doc_date";
3801 $sql_insert .=
", date_creation";
3802 $sql_insert .=
", fk_user_author";
3803 $sql_insert .=
", doc_ref";
3804 $sql_insert .=
", fk_doc";
3805 $sql_insert .=
", fk_docdet";
3806 $sql_insert .=
", debit";
3807 $sql_insert .=
", credit";
3808 $sql_insert .=
", journal_label";
3809 $sql_insert .=
", sens";
3810 $sql_insert .=
", montant";
3812 $sql_insert .=
" VALUES (";
3813 $sql_insert .= ((int) $pieceNumNext);
3814 $sql_insert .=
", '" . $this->db->escape($obj->label_operation) .
"'";
3815 $sql_insert .=
", '" . $this->db->escape($obj->numero_compte) .
"'";
3816 $sql_insert .=
", '" . $this->db->escape($obj->label_compte) .
"'";
3817 $sql_insert .=
", '" . $this->db->escape($obj->subledger_account) .
"'";
3818 $sql_insert .=
", '" . $this->db->escape($obj->subledger_label) .
"'";
3819 $sql_insert .=
", ''";
3820 $sql_insert .=
", '" . $this->db->escape($code_journal) .
"'";
3821 $sql_insert .=
", '" . $this->db->idate($docdate).
"'";
3822 $sql_insert .=
", '" . $this->db->idate($now).
"'";
3823 $sql_insert .=
", ".($user->id > 0 ? ((int) $user->id) :
"NULL");
3824 $sql_insert .=
", '" . $this->db->escape($docRef) .
"'";
3825 $sql_insert .=
", 0";
3826 $sql_insert .=
", 0";
3827 $sql_insert .=
", " . (float) $obj->debit;
3828 $sql_insert .=
", " . (float) $obj->credit;
3829 $sql_insert .=
", '" . $this->db->escape($journal_label) .
"'";
3830 $sql_insert .=
", '" . $this->db->escape($obj->sens) .
"'";
3831 $sql_insert .=
", " . (float) $obj->montant;
3834 $resqlInsert = $this->db->query($sql_insert);
3837 setEventMessages($langs->trans(
'CloningSuccess', $pieceNumNext),
null,
'mesgs');
3839 $this->error = $langs->trans(
'CloningFailed') . $this->db->lasterror();
3840 $this->errors[] = $this->error;
3852 $this->db->rollback();
3855 $this->db->commit();
3870 global $langs, $user;
3875 if (empty($docdate)) {
3880 $accountingJournal->fetch(0, $code_journal);
3883 $sqlAlreadyExtourne =
"SELECT DISTINCT(piece_num) FROM " .MAIN_DB_PREFIX.
"accounting_bookkeeping WHERE label_operation LIKE '%Extourne%'";
3884 $resqlAlreadyExtourne = $this->db->query($sqlAlreadyExtourne);
3885 $alreadyExtourneT = array();
3886 if ($resqlAlreadyExtourne) {
3887 while ($obj4 = $this->db->fetch_object($resqlAlreadyExtourne)) {
3888 $alreadyExtourneT [] = $obj4->piece_num;
3892 $idImplode = implode(
',', $toselect);
3893 $sql1 =
"SELECT DISTINCT(piece_num) from " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE rowid IN (".$this->db->sanitize($idImplode).
")";
3894 $resql1 = $this->db->query($sql1);
3898 while ($obj1 = $this->db->fetch_object($resql1)) {
3899 $pieceNumT [] = $obj1->piece_num;
3902 $i = mt_rand(0, 100);
3903 foreach ($pieceNumT as $pieceNum) {
3904 $newBookKeepingInstance =
new BookKeeping($this->db);
3905 $pieceNumNext = $newBookKeepingInstance->getNextNumMvt();
3907 $sql2 =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE piece_num = ".((int) $pieceNum);
3908 $resql2 = $this->db->query($sql2);
3911 while ($obj2 = $this->db->fetch_object($resql2)) {
3912 $extourneIds [] = $obj2->rowid;
3915 foreach ($extourneIds as $extourneId) {
3919 if ($bookKeeping->fetch($extourneId)) {
3920 if (in_array($bookKeeping->piece_num, $alreadyExtourneT)) {
3921 setEventMessages($langs->trans(
"AlreadyReturnedAccount", $bookKeeping->piece_num),
null,
'errors');
3923 $newBookKeeping->debit = $bookKeeping->credit;
3924 $newBookKeeping->credit = $bookKeeping->debit;
3925 if ($bookKeeping->sens ==
'D') {
3926 $newBookKeeping->sens =
'C';
3928 $newBookKeeping->sens =
'D';
3931 $newBookKeeping->label_operation = $langs->trans(
"ReturnAccount") .
" " . $bookKeeping->piece_num .
" - " . $bookKeeping->numero_compte .
" - " .
date(
'd/m/Y',
dol_now()) .
" - " . $i;
3933 $newBookKeeping->numero_compte = $bookKeeping->numero_compte;
3934 $newBookKeeping->label_compte = $bookKeeping->label_compte;
3935 $newBookKeeping->doc_type = $bookKeeping->doc_type;
3936 $newBookKeeping->code_journal = $bookKeeping->code_journal;
3937 $newBookKeeping->doc_date = $docdate;
3938 $newBookKeeping->fk_user_author = $user->id;
3939 $newBookKeeping->doc_ref = $bookKeeping->doc_ref;
3940 $newBookKeeping->montant = $bookKeeping->montant;
3941 $newBookKeeping->journal_label = $bookKeeping->journal_label;
3942 $newBookKeeping->subledger_account = $bookKeeping->subledger_account;
3943 $newBookKeeping->subledger_label = $bookKeeping->subledger_label;
3945 $createResult = $newBookKeeping->create($user);
3947 if ($createResult >= 0) {
3948 $newBookKeeping->piece_num = $pieceNumNext;
3949 $newBookKeeping->fk_doc = $bookKeeping->fk_doc;
3950 $newBookKeeping->fk_docdet = $bookKeeping->fk_docdet;
3951 $newBookKeeping->update($user);
3952 setEventMessages($langs->trans(
"SuccessReturnedAccount", $bookKeeping->piece_num),
null,
'mesgs');
3954 $this->error = $langs->trans(
"ErrorWhileCreating", $newBookKeeping->error);
3955 $this->errors = $newBookKeeping->errors;
3967 $this->db->rollback();
3970 $this->db->commit();
3989 public $doc_date =
null;
4013 public $thirdparty_code;
4018 public $subledger_account;
4023 public $subledger_label;
4028 public $numero_compte;
4033 public $label_compte;
4038 public $label_operation;
4064 public $multicurrency_amount;
4069 public $multicurrency_code;
4079 public $matching_general;
4084 public $lettering_code;
4089 public $date_lettering;
4094 public $fk_user_author;
4105 public $code_journal;
4110 public $journal_label;
4119 public $date_export;
4124 public $date_lim_reglement;
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $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='', $placeholder='')
Convert a html select field into an ajax combobox.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage accounting accounts.
Class to manage accounting journals.
Class to manage Ledger (General Ledger and Subledger)
updateByMvt($piece_num='', $field='', $value='', $mode='', $notrigger=0)
Update accounting movement.
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.
getFiscalPeriods()
Get list of fiscal period ordered by start date.
transformTransaction($direction=0, $piece_num='', $notrigger=0)
Transform transaction.
getNextNumMvt($mode='')
Return next bookkeeping piece number.
newCloneMass($toselect, $code_journal, $docdate)
Mass clone.
get_compte_desc($account=null)
Description of accounting account.
callTriggerPerLine($triggername, $lineids, User $user, $mode='', $oldlines=array())
Call a trigger for each line of a transaction changed or created with SQL requests,...
accountingLabelForOperation($thirdpartyname, $reference, $labelaccount, $full=0)
Generate label operation when operation is transferred into accounting according to ACCOUNTING_LABEL_...
__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.
fetchLinesForTrigger($sql, $mode='')
Load the lines found by a SQL request on rowid, to give them to triggers.
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.
newReturnAccount(array $toselect, $code_journal, $docdate)
Mass ReturnAccount.
fetchPerMvt($piecenum, $mode='')
Load an accounting document into memory from database.
assignAccountMass($toselect, $accounting_account=0)
Mass account assignment.
create(User $user, $notrigger=0)
Create object into database.
createStd(User $user, $notrigger=0, $mode='')
Create object into database.
update(User $user, $notrigger=0, $mode='')
Update object into database.
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.
createFromValues($doc_date, $doc_ref, $doc_type, $fk_doc, $fk_docdet, $numero_compte, $label_compte, $label_operation, $amount, $code_journal, $journal_label, $subledger_account)
Create a line in database from values as parameters.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
deleteMvtNum($piecenum, $mode='', $notrigger=0)
Delete bookkeeping by piece number.
newClone($piecenum, $code_journal, $docdate)
Clone accounting entry.
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 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).
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date