31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/fiscalyear.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
45 public $element =
'accountingbookkeeping';
50 public $table_element =
'accounting_bookkeeping';
60 public $lines = array();
75 public $date_lim_reglement;
100 public $thirdparty_code;
105 public $subledger_account;
110 public $subledger_label;
115 public $numero_compte;
120 public $label_compte;
125 public $label_operation;
157 public $fk_user_author;
167 public $code_journal;
172 public $journal_label;
187 public $linesmvt = array();
192 public $linesexport = array();
202 public $picto =
'generic';
207 public static $can_modify_bookkeeping_sql_cached;
212 public $warnings = array();
234 global
$conf, $langs;
241 if (isset($this->doc_type)) {
242 $this->doc_type = trim($this->doc_type);
244 if (isset($this->doc_ref)) {
245 $this->doc_ref = trim($this->doc_ref);
246 $this->doc_ref =
dol_trunc($this->doc_ref, 300);
248 if (isset($this->fk_doc)) {
249 $this->fk_doc = (int) $this->fk_doc;
251 if (isset($this->fk_docdet)) {
252 $this->fk_docdet = (int) $this->fk_docdet;
254 if (isset($this->thirdparty_code)) {
255 $this->thirdparty_code = trim($this->thirdparty_code);
257 if (isset($this->subledger_account)) {
258 $this->subledger_account = trim($this->subledger_account);
260 if (isset($this->subledger_label)) {
261 $this->subledger_label = trim($this->subledger_label);
263 if (isset($this->numero_compte)) {
264 $this->numero_compte = trim($this->numero_compte);
266 if (isset($this->label_compte)) {
267 $this->label_compte = trim($this->label_compte);
269 if (isset($this->label_operation)) {
270 $this->label_operation = trim($this->label_operation);
272 if (isset($this->debit)) {
273 $this->debit = (float) $this->debit;
275 if (isset($this->credit)) {
276 $this->credit = (float) $this->credit;
278 if (isset($this->montant)) {
279 $this->montant = (float) $this->montant;
281 if (isset($this->amount)) {
282 $this->amount = (float) $this->amount;
284 if (isset($this->sens)) {
285 $this->sens = trim($this->sens);
287 if (isset($this->import_key)) {
288 $this->import_key = trim($this->import_key);
290 if (isset($this->code_journal)) {
291 $this->code_journal = trim($this->code_journal);
293 if (isset($this->journal_label)) {
294 $this->journal_label = trim($this->journal_label);
296 if (isset($this->piece_num)) {
297 $this->piece_num = (int) $this->piece_num;
299 if (empty($this->debit)) {
302 if (empty($this->credit)) {
309 } elseif ($result == 0) {
311 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
313 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
319 if (($this->numero_compte ==
"") || $this->numero_compte ==
'-1' || $this->numero_compte ==
'NotDefined') {
320 $langs->loadLangs(array(
"errors"));
321 if (in_array($this->doc_type, array(
'bank',
'expense_report'))) {
322 $this->errors[] = $langs->trans(
'ErrorFieldAccountNotDefinedForBankLine', $this->fk_docdet, $this->doc_type);
325 $mesg = $this->doc_ref.
', '.$langs->trans(
"AccountAccounting").
': '.($this->numero_compte != -1 ? $this->numero_compte : $langs->trans(
"Unknown"));
326 if ($this->subledger_account && $this->subledger_account != $this->numero_compte) {
327 $mesg .=
', '.$langs->trans(
"SubledgerAccount").
': '.$this->subledger_account;
329 $this->errors[] = $langs->trans(
'ErrorFieldAccountNotDefinedForLine', $mesg);
337 $this->piece_num = 0;
345 $sql =
"SELECT count(*) as nb";
346 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
347 $sql .=
" WHERE doc_type = '".$this->db->escape($this->doc_type).
"'";
348 $sql .=
" AND fk_doc = ".((int) $this->fk_doc);
351 $sql .=
" AND fk_docdet = ".((int) $this->fk_docdet);
353 $sql .=
" AND numero_compte = '".$this->db->escape($this->numero_compte).
"'";
354 $sql .=
" AND label_operation = '".$this->db->escape($this->label_operation).
"'";
355 if (!empty($this->subledger_account)) {
356 $sql .=
" AND subledger_account = '".$this->db->escape($this->subledger_account).
"'";
358 $sql .=
" AND entity = ".$conf->entity;
360 $resql = $this->db->query($sql);
363 $row = $this->db->fetch_object($resql);
366 $sqlnum =
"SELECT piece_num, ref";
367 $sqlnum .=
" FROM ".$this->db->prefix().$this->table_element;
368 $sqlnum .=
" WHERE doc_type = '".$this->db->escape($this->doc_type).
"'";
369 $sqlnum .=
" AND fk_doc = ".((int) $this->fk_doc);
372 $sqlnum .=
" AND fk_docdet = ".((int) $this->fk_docdet);
374 $sqlnum .=
" AND doc_ref = '".$this->db->escape($this->doc_ref).
"'";
375 $sqlnum .=
" AND entity = ".$conf->entity;
377 dol_syslog(get_class($this).
":: create sqlnum=".$sqlnum, LOG_DEBUG);
378 $resqlnum = $this->db->query($sqlnum);
380 $num = $this->db->num_rows($resqlnum);
382 $objnum = $this->db->fetch_object($resqlnum);
383 $this->piece_num = $objnum->piece_num;
384 $this->
ref = $objnum->ref;
386 $this->piece_num = 0;
391 dol_syslog(get_class($this).
"::create this->piece_num=".$this->piece_num, LOG_DEBUG);
392 if (empty($this->piece_num)) {
393 $sqlnum =
"SELECT MAX(piece_num)+1 as maxpiecenum";
394 $sqlnum .=
" FROM ".$this->db->prefix().$this->table_element;
395 $sqlnum .=
" WHERE entity = " . ((int)
$conf->entity);
397 $resqlnum = $this->db->query($sqlnum);
399 $objnum = $this->db->fetch_object($resqlnum);
400 $this->piece_num = $objnum->maxpiecenum;
403 $this->
ref = $this->getNextNumRef();
404 dol_syslog(get_class($this).
":: create now this->piece_num={$this->piece_num}, this->ref={$this->ref}", LOG_DEBUG);
406 if (empty($this->piece_num)) {
407 $this->piece_num = 1;
412 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
" (";
414 $sql .=
", date_lim_reglement";
415 $sql .=
", doc_type";
418 $sql .=
", fk_docdet";
419 $sql .=
", thirdparty_code";
420 $sql .=
", subledger_account";
421 $sql .=
", subledger_label";
422 $sql .=
", numero_compte";
423 $sql .=
", label_compte";
424 $sql .=
", label_operation";
429 $sql .=
", fk_user_author";
430 $sql .=
", date_creation";
431 $sql .=
", code_journal";
432 $sql .=
", journal_label";
433 $sql .=
", piece_num";
436 $sql .=
") VALUES (";
437 $sql .=
"'".$this->db->idate($this->doc_date).
"'";
438 $sql .=
", ".(isDolTms($this->date_lim_reglement) ?
"'".$this->db->idate($this->date_lim_reglement).
"'" :
'NULL');
439 $sql .=
", '".$this->db->escape($this->doc_type).
"'";
440 $sql .=
", '".$this->db->escape($this->doc_ref).
"'";
441 $sql .=
", ".((int) $this->fk_doc);
442 $sql .=
", ".((int) $this->fk_docdet);
443 $sql .=
", ".(!empty($this->thirdparty_code) ? (
"'".$this->db->escape($this->thirdparty_code).
"'") :
"NULL");
444 $sql .=
", ".(!empty($this->subledger_account) ? (
"'".$this->db->escape($this->subledger_account).
"'") :
"NULL");
445 $sql .=
", ".(!empty($this->subledger_label) ? (
"'".$this->db->escape($this->subledger_label).
"'") :
"NULL");
446 $sql .=
", '".$this->db->escape($this->numero_compte).
"'";
447 $sql .=
", ".(!empty($this->label_compte) ? (
"'".$this->db->escape($this->label_compte).
"'") :
"NULL");
448 $sql .=
", '".$this->db->escape($this->label_operation).
"'";
449 $sql .=
", ".((float) $this->debit);
450 $sql .=
", ".((float) $this->credit);
451 $sql .=
", ".((float) $this->montant);
452 $sql .=
", ".(!empty($this->sens) ? (
"'".$this->db->escape($this->sens).
"'") :
"NULL");
453 $sql .=
", '".$this->db->escape((
string) $this->fk_user_author).
"'";
454 $sql .=
", '".$this->db->idate($now).
"'";
455 $sql .=
", '".$this->db->escape($this->code_journal).
"'";
456 $sql .=
", ".(!empty($this->journal_label) ? (
"'".$this->db->escape($this->journal_label).
"'") :
"NULL");
457 $sql .=
", ".((int) $this->piece_num);
458 $sql .=
", '".$this->db->escape($this->
ref).
"'";
459 $sql .=
", ".(!isset($this->entity) ?
$conf->entity : $this->entity);
462 $resql = $this->db->query($sql);
464 $id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
472 $this->errors[] =
'Error Create Error '.$result.
' lecture ID';
473 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
478 $this->errors[] =
'Error '.$this->db->lasterror();
479 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
484 $this->error =
'BookkeepingRecordAlreadyExists';
485 dol_syslog(__METHOD__.
' '.$this->error, LOG_WARNING);
490 $this->errors[] =
'Error '.$this->db->lasterror();
491 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
495 if (! $error && ! $notrigger) {
496 $result = $this->
call_trigger(
'BOOKKEEPING_CREATE', $user);
504 $this->db->rollback();
529 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)
531 global
$conf, $langs, $user;
535 if (!empty($amount)) {
536 $this->doc_date = $doc_date;
537 $this->doc_ref = $doc_ref;
538 $this->doc_type = $doc_type;
539 $this->fk_doc = $fk_doc;
540 $this->fk_docdet = $fk_docdet;
542 $this->numero_compte = $numero_compte;
543 $this->label_compte = $label_compte;
545 $this->label_operation = $label_operation;
546 $this->subledger_account = $subledger_account;
548 $this->montant = $amount;
549 $this->sens = ($amount >= 0) ?
'D' :
'C';
550 $this->debit = ($amount >= 0 ? $amount : 0);
551 $this->credit = ($amount < 0 ? -$amount : 0);
553 $this->code_journal = $code_journal;
554 $this->journal_label = $journal_label;
556 $this->fk_user_author = $user->id;
557 $this->entity =
$conf->entity;
559 $result = $this->
create($user);
561 if ($this->error ==
'BookkeepingRecordAlreadyExists') {
562 $warning = $langs->trans(
'WarningBookkeepingRecordAlreadyExists', $this->doc_type, $this->fk_doc, $this->fk_docdet);
563 $this->warnings[] = $warning;
564 dol_syslog(__METHOD__.
' '.$warning, LOG_WARNING);
566 dol_syslog(__METHOD__.
' '.$this->errorsToString(), LOG_ERR);
584 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
586 global $db,
$conf, $langs;
588 global $menumanager, $hookmanager;
590 if (!empty(
$conf->dol_no_mouse_hover)) {
597 $label =
'<u>'.$langs->trans(
"Transaction").
'</u>';
599 $label .=
'<b>'.$langs->trans(
'NumberingShort').
':</b> '.$this->piece_num;
601 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
603 $url = DOL_URL_ROOT.
'/accountancy/bookkeeping/card.php?piece_num='.$this->piece_num;
605 if ($option !=
'nolink') {
607 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
608 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
609 $add_save_lastsearch_values = 1;
611 if ($add_save_lastsearch_values) {
612 $url .=
'&save_lastsearch_values=1';
617 if (empty($notooltip)) {
619 $label = $langs->trans(
"ShowTransaction");
620 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
622 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
623 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
625 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
628 $linkstart =
'<a href="'.$url.
'"';
629 $linkstart .= $linkclose.
'>';
632 $result .= $linkstart;
634 $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);
636 if ($withpicto != 2) {
637 $result .= $this->piece_num;
643 $hookmanager->initHooks(array($this->element .
'dao'));
644 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
645 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
647 $result = $hookmanager->resPrint;
649 $result .= $hookmanager->resPrint;
664 global
$conf, $langs;
666 $langs->loadLangs(array(
"accountancy",
"bills",
"compta"));
673 if (isset($this->doc_type)) {
674 $this->doc_type = trim($this->doc_type);
676 if (isset($this->doc_ref)) {
677 $this->doc_ref = trim($this->doc_ref);
679 if (isset($this->fk_doc)) {
680 $this->fk_doc = (int) $this->fk_doc;
682 if (isset($this->fk_docdet)) {
683 $this->fk_docdet = (int) $this->fk_docdet;
685 if (isset($this->thirdparty_code)) {
686 $this->thirdparty_code = trim($this->thirdparty_code);
688 if (isset($this->subledger_account)) {
689 $this->subledger_account = trim($this->subledger_account);
691 if (isset($this->subledger_label)) {
692 $this->subledger_label = trim($this->subledger_label);
694 if (isset($this->numero_compte)) {
695 $this->numero_compte = trim($this->numero_compte);
697 if (isset($this->label_compte)) {
698 $this->label_compte = trim($this->label_compte);
700 if (isset($this->label_operation)) {
701 $this->label_operation = trim($this->label_operation);
703 if (isset($this->sens)) {
704 $this->sens = trim($this->sens);
706 if (isset($this->import_key)) {
707 $this->import_key = trim($this->import_key);
709 if (isset($this->code_journal)) {
710 $this->code_journal = trim($this->code_journal);
712 if (isset($this->journal_label)) {
713 $this->journal_label = trim($this->journal_label);
715 if (isset($this->piece_num)) {
716 $this->piece_num = (int) $this->piece_num;
718 if (empty($this->debit)) {
721 if (empty($this->credit)) {
724 if (empty($this->montant)) {
731 } elseif ($result == 0) {
733 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
735 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
740 $this->debit = (float)
price2num($this->debit,
'MT');
741 $this->credit = (float)
price2num($this->credit,
'MT');
742 $this->montant = (float)
price2num($this->montant,
'MT');
747 $this->journal_label = $langs->trans($this->journal_label);
750 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.$mode.
' (';
752 $sql .=
'date_lim_reglement,';
756 $sql .=
'fk_docdet,';
757 $sql .=
'thirdparty_code,';
758 $sql .=
'subledger_account,';
759 $sql .=
'subledger_label,';
760 $sql .=
'numero_compte,';
761 $sql .=
'label_compte,';
762 $sql .=
'label_operation,';
767 $sql .=
'fk_user_author,';
768 $sql .=
'date_creation,';
769 $sql .=
'code_journal,';
770 $sql .=
'journal_label,';
771 $sql .=
'piece_num,';
774 $sql .=
') VALUES (';
775 $sql .=
' '.(isDolTms($this->doc_date) ?
"'".$this->db->idate($this->doc_date).
"'" :
'NULL').
',';
776 $sql .=
' '.(isDolTms($this->date_lim_reglement) ?
"'".$this->db->idate($this->date_lim_reglement).
"'" :
'NULL').
',';
777 $sql .=
' '.(!isset($this->doc_type) ?
'NULL' :
"'".$this->db->escape($this->doc_type).
"'").
',';
778 $sql .=
' '.(!isset($this->doc_ref) ?
'NULL' :
"'".$this->db->escape($this->doc_ref).
"'").
',';
779 $sql .=
' '.(empty($this->fk_doc) ?
'0' : (int) $this->fk_doc).
',';
780 $sql .=
' '.(empty($this->fk_docdet) ?
'0' : (int) $this->fk_docdet).
',';
781 $sql .=
' '.(!isset($this->thirdparty_code) ?
'NULL' :
"'".$this->db->escape($this->thirdparty_code).
"'").
',';
782 $sql .=
' '.(!isset($this->subledger_account) ?
'NULL' :
"'".$this->db->escape($this->subledger_account).
"'").
',';
783 $sql .=
' '.(!isset($this->subledger_label) ?
'NULL' :
"'".$this->db->escape($this->subledger_label).
"'").
',';
784 $sql .=
' '.(!isset($this->numero_compte) ?
'NULL' :
"'".$this->db->escape($this->numero_compte).
"'").
',';
785 $sql .=
' '.(!isset($this->label_compte) ?
'NULL' :
"'".$this->db->escape($this->label_compte).
"'").
',';
786 $sql .=
' '.(!isset($this->label_operation) ?
'NULL' :
"'".$this->db->escape($this->label_operation).
"'").
',';
787 $sql .=
' '.(!isset($this->debit) ?
'NULL' : $this->debit).
',';
788 $sql .=
' '.(!isset($this->credit) ?
'NULL' : $this->credit).
',';
789 $sql .=
' '.(!isset($this->montant) ?
'NULL' : $this->montant).
',';
790 $sql .=
' '.(!isset($this->sens) ?
'NULL' :
"'".$this->db->escape($this->sens).
"'").
',';
791 $sql .=
' '.((int) $user->id).
',';
792 $sql .=
' '.
"'".$this->db->idate($now).
"',";
793 $sql .=
' '.(empty($this->code_journal) ?
'NULL' :
"'".$this->db->escape($this->code_journal).
"'").
',';
794 $sql .=
' '.(empty($this->journal_label) ?
'NULL' :
"'".$this->db->escape($this->journal_label).
"'").
',';
795 $sql .=
' '.(empty($this->piece_num) ?
'NULL' : $this->db->escape((
string) $this->piece_num)).
',';
796 $sql .=
' '.(empty($this->
ref) ?
"''" :
"'".$this->db->escape($this->
ref).
"'").
',';
797 $sql .=
' '.(!isset($this->entity) ?
$conf->entity : $this->entity);
802 $resql = $this->db->query($sql);
805 $this->errors[] =
'Error '.$this->db->lasterror();
806 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
810 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element.$mode);
813 $result = $this->
call_trigger(
'BOOKKEEPING_CREATE', $user);
822 $this->db->rollback();
840 public function fetch($id, $ref =
null, $mode =
'')
848 $sql .=
" t.doc_date,";
849 $sql .=
" t.date_lim_reglement,";
850 $sql .=
" t.doc_type,";
851 $sql .=
" t.doc_ref,";
852 $sql .=
" t.fk_doc,";
853 $sql .=
" t.fk_docdet,";
854 $sql .=
" t.thirdparty_code,";
855 $sql .=
" t.subledger_account,";
856 $sql .=
" t.subledger_label,";
857 $sql .=
" t.numero_compte,";
858 $sql .=
" t.label_compte,";
859 $sql .=
" t.label_operation,";
861 $sql .=
" t.credit,";
862 $sql .=
" t.montant as amount,";
864 $sql .=
" t.fk_user_author,";
865 $sql .=
" t.import_key,";
866 $sql .=
" t.code_journal,";
867 $sql .=
" t.journal_label,";
868 $sql .=
" t.piece_num,";
870 $sql .=
" t.date_creation,";
873 $sql .=
" t.date_export,";
875 $sql .=
" t.date_validated as date_validation";
876 $sql .=
' FROM '.$this->db->prefix().$this->table_element.$mode.
' as t';
877 $sql .=
' WHERE 1 = 1';
878 $sql .=
" AND entity = " . ((int)
$conf->entity);
880 $sql .=
" AND t.rowid = ".((int) $ref);
882 $sql .=
" AND t.rowid = ".((int) $id);
885 $resql = $this->db->query($sql);
887 $numrows = $this->db->num_rows($resql);
889 $obj = $this->db->fetch_object($resql);
891 $this->
id = $obj->rowid;
893 $this->doc_date = $this->db->jdate($obj->doc_date);
894 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
895 $this->doc_type = $obj->doc_type;
896 $this->doc_ref = $obj->doc_ref;
897 $this->fk_doc = $obj->fk_doc;
898 $this->fk_docdet = $obj->fk_docdet;
899 $this->thirdparty_code = $obj->thirdparty_code;
900 $this->subledger_account = $obj->subledger_account;
901 $this->subledger_label = $obj->subledger_label;
902 $this->numero_compte = $obj->numero_compte;
903 $this->label_compte = $obj->label_compte;
904 $this->label_operation = $obj->label_operation;
905 $this->debit = $obj->debit;
906 $this->credit = $obj->credit;
907 $this->montant = $obj->amount;
908 $this->amount = $obj->amount;
909 $this->sens = $obj->sens;
910 $this->fk_user_author = $obj->fk_user_author;
911 $this->import_key = $obj->import_key;
912 $this->code_journal = $obj->code_journal;
913 $this->journal_label = $obj->journal_label;
914 $this->piece_num = $obj->piece_num;
915 $this->date_creation = $this->db->jdate($obj->date_creation);
917 $this->date_export = $this->db->jdate($obj->date_export);
919 $this->
ref = $obj->ref;
920 $this->date_validation = isset($obj->date_validation) ? $this->db->jdate($obj->date_validation) :
'';
922 $this->db->free($resql);
930 $this->errors[] =
'Error '.$this->db->lasterror();
931 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
951 public function fetchAllByAccount($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND', $option = 0, $countonly = 0)
957 $this->lines = array();
962 $sql .=
' COUNT(t.rowid) as nb';
965 $sql .=
" t.doc_date,";
966 $sql .=
" t.doc_type,";
967 $sql .=
" t.doc_ref,";
968 $sql .=
" t.fk_doc,";
969 $sql .=
" t.fk_docdet,";
970 $sql .=
" t.thirdparty_code,";
971 $sql .=
" t.subledger_account,";
972 $sql .=
" t.subledger_label,";
973 $sql .=
" t.numero_compte,";
974 $sql .=
" t.label_compte,";
975 $sql .=
" t.label_operation,";
977 $sql .=
" t.credit,";
978 $sql .=
" t.montant as amount,";
980 $sql .=
" t.multicurrency_amount,";
981 $sql .=
" t.multicurrency_code,";
982 $sql .=
" t.lettering_code,";
983 $sql .=
" t.date_lettering,";
984 $sql .=
" t.fk_user_author,";
985 $sql .=
" t.import_key,";
986 $sql .=
" t.code_journal,";
987 $sql .=
" t.journal_label,";
988 $sql .=
" t.piece_num,";
990 $sql .=
" t.date_creation,";
991 $sql .=
" t.date_export,";
992 $sql .=
" t.date_validated as date_validation,";
993 $sql .=
" t.date_lim_reglement,";
994 $sql .=
" t.import_key";
998 if (count($filter) > 0) {
999 foreach ($filter as $key => $value) {
1000 if ($key ==
't.doc_date>=') {
1001 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate((
int) $value).
"'";
1002 } elseif ($key ==
't.doc_date<=') {
1003 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate((
int) $value).
"'";
1004 } elseif ($key ==
't.doc_date>') {
1005 $sqlwhere[] =
"t.doc_date > '".$this->db->idate((
int) $value).
"'";
1006 } elseif ($key ==
't.doc_date<') {
1007 $sqlwhere[] =
"t.doc_date < '".$this->db->idate((
int) $value).
"'";
1008 } elseif ($key ==
't.numero_compte>=') {
1009 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1010 } elseif ($key ==
't.numero_compte<=') {
1011 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1012 } elseif ($key ==
't.subledger_account>=') {
1013 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1014 } elseif ($key ==
't.subledger_account<=') {
1015 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1016 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1017 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
1018 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1019 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($this->db->escapeforlike($value)).
"%'";
1020 } elseif ($key ==
't.date_creation>=') {
1021 $sqlwhere[] =
"t.date_creation >= '".$this->db->idate((
int) $value).
"'";
1022 } elseif ($key ==
't.date_creation<=') {
1023 $sqlwhere[] =
"t.date_creation <= '".$this->db->idate((
int) $value).
"'";
1024 } elseif ($key ==
't.date_export>=') {
1025 $sqlwhere[] =
"t.date_export >= '".$this->db->idate((
int) $value).
"'";
1026 } elseif ($key ==
't.date_export<=') {
1027 $sqlwhere[] =
"t.date_export <= '".$this->db->idate((
int) $value).
"'";
1028 } elseif ($key ==
't.date_validated>=') {
1029 $sqlwhere[] =
"t.date_validated >= '".$this->db->idate((
int) $value).
"'";
1030 } elseif ($key ==
't.date_validated<=') {
1031 $sqlwhere[] =
"t.date_validated <= '".$this->db->idate((
int) $value).
"'";
1032 } elseif ($key ==
't.date_lim_reglement>=') {
1033 $sqlwhere[] =
"t.date_lim_reglement>='".$this->db->idate((
int) $value).
"'";
1034 } elseif ($key ==
't.date_lim_reglement<=') {
1035 $sqlwhere[] =
"t.date_lim_reglement<='".$this->db->idate((
int) $value).
"'";
1036 } elseif ($key ==
't.credit' || $key ==
't.debit') {
1038 } elseif ($key ==
't.reconciled_option') {
1039 $sqlwhere[] =
't.lettering_code IS NULL';
1040 } elseif ($key ==
't.code_journal' && !empty($value)) {
1041 if (is_array($value)) {
1042 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1046 } elseif ($key ==
't.search_accounting_code_in' && !empty($value)) {
1047 $sqlwhere[] =
"t.numero_compte IN (".$this->db->sanitize($value, 1).
")";
1053 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t';
1054 $sql .=
' WHERE entity = ' . ((int)
$conf->entity);
1055 if (count($sqlwhere) > 0) {
1056 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1059 if (!empty($option)) {
1060 $sql .=
" AND t.subledger_account IS NOT NULL";
1061 $sql .=
" AND t.subledger_account <> ''";
1062 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
1063 $sortorder =
'ASC'.($sortfield ?
','.$sortfield :
'');
1065 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
1066 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1070 $sql .= $this->db->order($sortfield, $sortorder);
1071 if (!empty($limit)) {
1072 $sql .= $this->db->plimit($limit + 1, $offset);
1076 $resql = $this->db->query($sql);
1079 $obj = $this->db->fetch_object($resql);
1084 $num = $this->db->num_rows($resql);
1087 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1090 $line->id = $obj->rowid;
1092 $line->doc_date = $this->db->jdate($obj->doc_date);
1093 $line->doc_type = $obj->doc_type;
1094 $line->doc_ref = $obj->doc_ref;
1095 $line->fk_doc = $obj->fk_doc;
1096 $line->fk_docdet = $obj->fk_docdet;
1097 $line->thirdparty_code = $obj->thirdparty_code;
1098 $line->subledger_account = $obj->subledger_account;
1099 $line->subledger_label = $obj->subledger_label;
1100 $line->numero_compte = $obj->numero_compte;
1101 $line->label_compte = $obj->label_compte;
1102 $line->label_operation = $obj->label_operation;
1103 $line->debit = $obj->debit;
1104 $line->credit = $obj->credit;
1105 $line->montant = $obj->amount;
1106 $line->amount = $obj->amount;
1107 $line->sens = $obj->sens;
1108 $line->multicurrency_amount = $obj->multicurrency_amount;
1109 $line->multicurrency_code = $obj->multicurrency_code;
1110 $line->lettering_code = $obj->lettering_code;
1111 $line->date_lettering = $this->db->jdate($obj->date_lettering);
1112 $line->fk_user_author = $obj->fk_user_author;
1113 $line->import_key = $obj->import_key;
1114 $line->code_journal = $obj->code_journal;
1115 $line->journal_label = $obj->journal_label;
1116 $line->piece_num = $obj->piece_num;
1117 $line->ref = $obj->ref;
1118 $line->date_creation = $this->db->jdate($obj->date_creation);
1119 $line->date_export = $this->db->jdate($obj->date_export);
1120 $line->date_validation = $this->db->jdate($obj->date_validation);
1122 $line->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1123 $line->import_key = $obj->import_key;
1125 $this->lines[] = $line;
1130 $this->db->free($resql);
1134 $this->errors[] =
'Error '.$this->db->lasterror();
1135 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1153 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $showAlreadyExportMovements = 1)
1160 $sql .=
' t.rowid,';
1161 $sql .=
" t.doc_date,";
1162 $sql .=
" t.doc_type,";
1163 $sql .=
" t.doc_ref,";
1164 $sql .=
" t.fk_doc,";
1165 $sql .=
" t.fk_docdet,";
1166 $sql .=
" t.thirdparty_code,";
1167 $sql .=
" t.subledger_account,";
1168 $sql .=
" t.subledger_label,";
1169 $sql .=
" t.numero_compte,";
1170 $sql .=
" t.label_compte,";
1171 $sql .=
" t.label_operation,";
1172 $sql .=
" t.debit,";
1173 $sql .=
" t.credit,";
1174 $sql .=
" t.lettering_code,";
1175 $sql .=
" t.date_lettering,";
1176 $sql .=
" t.montant as amount,";
1178 $sql .=
" t.fk_user_author,";
1179 $sql .=
" t.import_key,";
1180 $sql .=
" t.code_journal,";
1181 $sql .=
" t.journal_label,";
1182 $sql .=
" t.piece_num,";
1183 $sql .=
" t.date_creation,";
1184 $sql .=
" t.date_lim_reglement,";
1185 $sql .=
" t.tms as date_modification,";
1186 $sql .=
" t.date_export,";
1187 $sql .=
" t.date_validated as date_validation";
1188 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t';
1189 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
1190 if ($showAlreadyExportMovements == 0) {
1191 $sql .=
" AND t.date_export IS NULL";
1195 if (is_array($filter)) {
1196 dol_syslog(
"You are using a deprecated use of fetchAll. filter parameter must be an USF string now.", LOG_WARNING);
1197 $sqlwhere = array();
1198 if (count($filter) > 0) {
1199 foreach ($filter as $key => $value) {
1200 if ($key ==
't.doc_date') {
1201 $sqlwhere[] = $this->db->sanitize($key).
" = '".$this->db->idate((
int) $value).
"'";
1202 } elseif ($key ==
't.doc_date>=') {
1203 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate((
int) $value).
"'";
1204 } elseif ($key ==
't.doc_date<=') {
1205 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate((
int) $value).
"'";
1206 } elseif ($key ==
't.doc_date>') {
1207 $sqlwhere[] =
"t.doc_date > '".$this->db->idate((
int) $value).
"'";
1208 } elseif ($key ==
't.doc_date<') {
1209 $sqlwhere[] =
"t.doc_date < '".$this->db->idate((
int) $value).
"'";
1210 } elseif ($key ==
't.numero_compte>=') {
1211 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1212 } elseif ($key ==
't.numero_compte<=') {
1213 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1214 } elseif ($key ==
't.subledger_account>=') {
1215 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1216 } elseif ($key ==
't.subledger_account<=') {
1217 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1218 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1219 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
1220 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1221 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1222 } elseif ($key ==
't.date_creation>=') {
1223 $sqlwhere[] =
"t.date_creation >= '".$this->db->idate((
int) $value).
"'";
1224 } elseif ($key ==
't.date_creation<=') {
1225 $sqlwhere[] =
"t.date_creation <= '".$this->db->idate((
int) $value).
"'";
1226 } elseif ($key ==
't.tms>=') {
1227 $sqlwhere[] =
"t.tms >= '".$this->db->idate((
int) $value).
"'";
1228 } elseif ($key ==
't.tms<=') {
1229 $sqlwhere[] =
"t.tms <= '".$this->db->idate((
int) $value).
"'";
1230 } elseif ($key ==
't.date_export>=') {
1231 $sqlwhere[] =
"t.date_export >= '".$this->db->idate((
int) $value).
"'";
1232 } elseif ($key ==
't.date_export<=') {
1233 $sqlwhere[] =
"t.date_export <= '".$this->db->idate((
int) $value).
"'";
1234 } elseif ($key ==
't.date_validated>=') {
1235 $sqlwhere[] =
"t.date_validated >= '".$this->db->idate((
int) $value).
"'";
1236 } elseif ($key ==
't.date_validated<=') {
1237 $sqlwhere[] =
"t.date_validated <= '".$this->db->idate((
int) $value).
"'";
1238 } elseif ($key ==
't.credit' || $key ==
't.debit') {
1240 } elseif ($key ==
't.code_journal' && !empty($value)) {
1241 if (is_array($value)) {
1242 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1246 } elseif ($key ==
't.reconciled_option') {
1247 $sqlwhere[] =
't.lettering_code IS NULL';
1253 if (count($sqlwhere) > 0) {
1254 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1263 if ($errormessage) {
1264 $this->errors[] = $errormessage;
1265 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1269 if (!empty($sortfield)) {
1270 $sql .= $this->db->order($sortfield, $sortorder);
1272 if (!empty($limit)) {
1273 $sql .= $this->db->plimit($limit + 1, $offset);
1275 $this->lines = array();
1277 $resql = $this->db->query($sql);
1279 $num = $this->db->num_rows($resql);
1282 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1285 $line->id = $obj->rowid;
1287 $line->doc_date = $this->db->jdate($obj->doc_date);
1288 $line->doc_type = $obj->doc_type;
1289 $line->doc_ref = $obj->doc_ref;
1290 $line->fk_doc = $obj->fk_doc;
1291 $line->fk_docdet = $obj->fk_docdet;
1292 $line->thirdparty_code = $obj->thirdparty_code;
1293 $line->subledger_account = $obj->subledger_account;
1294 $line->subledger_label = $obj->subledger_label;
1295 $line->numero_compte = $obj->numero_compte;
1296 $line->label_compte = $obj->label_compte;
1297 $line->label_operation = $obj->label_operation;
1298 $line->debit = $obj->debit;
1299 $line->credit = $obj->credit;
1300 $line->montant = $obj->amount;
1301 $line->amount = $obj->amount;
1302 $line->sens = $obj->sens;
1303 $line->lettering_code = $obj->lettering_code;
1304 $line->date_lettering = $this->db->jdate($obj->date_lettering);
1305 $line->fk_user_author = $obj->fk_user_author;
1306 $line->import_key = $obj->import_key;
1307 $line->code_journal = $obj->code_journal;
1308 $line->journal_label = $obj->journal_label;
1309 $line->piece_num = $obj->piece_num;
1310 $line->date_creation = $this->db->jdate($obj->date_creation);
1311 $line->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1312 $line->date_modification = $this->db->jdate($obj->date_modification);
1313 $line->date_export = $this->db->jdate($obj->date_export);
1314 $line->date_validation = $this->db->jdate($obj->date_validation);
1316 $this->lines[] = $line;
1320 $this->db->free($resql);
1324 $this->errors[] =
'Error '.$this->db->lasterror();
1325 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1342 public function fetchAllBalance($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $option = 0)
1346 $this->lines = array();
1351 $sql .=
" t.numero_compte,";
1352 if (!empty($option)) {
1353 $sql .=
" t.subledger_account,";
1354 $sql .=
" t.subledger_label,";
1356 $sql .=
" SUM(t.debit) as debit,";
1357 $sql .=
" SUM(t.credit) as credit";
1358 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t';
1359 $sql .=
' WHERE entity = ' . ((int)
$conf->entity);
1362 if (is_array($filter)) {
1363 $sqlwhere = array();
1364 if (count($filter) > 0) {
1365 foreach ($filter as $key => $value) {
1366 if ($key ==
't.doc_date') {
1367 $sqlwhere[] = $this->db->sanitize($key).
" = '".$this->db->idate((
int) $value).
"'";
1368 } elseif ($key ==
't.doc_date>=') {
1369 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate((
int) $value).
"'";
1370 } elseif ($key ==
't.doc_date<=') {
1371 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate((
int) $value).
"'";
1372 } elseif ($key ==
't.doc_date>') {
1373 $sqlwhere[] =
"t.doc_date > '".$this->db->idate((
int) $value).
"'";
1374 } elseif ($key ==
't.doc_date<') {
1375 $sqlwhere[] =
"t.doc_date < '".$this->db->idate((
int) $value).
"'";
1376 } elseif ($key ==
't.numero_compte>=') {
1377 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1378 } elseif ($key ==
't.numero_compte<=') {
1379 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1380 } elseif ($key ==
't.subledger_account>=') {
1381 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1382 } elseif ($key ==
't.subledger_account<=') {
1383 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1384 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1385 $sqlwhere[] = $this->db->sanitize($key).
" = ".((int) $value);
1386 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1387 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1388 } elseif ($key ==
't.subledger_label') {
1389 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1390 } elseif ($key ==
't.code_journal' && !empty($value)) {
1391 if (is_array($value)) {
1392 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1396 } elseif ($key ==
't.reconciled_option') {
1397 $sqlwhere[] =
't.lettering_code IS NULL';
1399 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
1403 if (count($sqlwhere) > 0) {
1404 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1413 if ($errormessage) {
1414 $this->errors[] = $errormessage;
1415 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1419 if (!empty($option)) {
1420 $sql .=
" AND t.subledger_account IS NOT NULL";
1421 $sql .=
" AND t.subledger_account <> ''";
1422 $sql .=
" GROUP BY t.numero_compte, t.subledger_account, t.subledger_label";
1423 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
1424 $sortorder =
'ASC'.($sortfield ?
','.$sortfield :
'');
1426 $sql .=
' GROUP BY t.numero_compte';
1427 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
1428 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1431 if (!empty($sortfield)) {
1432 $sql .= $this->db->order($sortfield, $sortorder);
1434 if (!empty($limit)) {
1435 $sql .= $this->db->plimit($limit + 1, $offset);
1439 $resql = $this->db->query($sql);
1442 $num = $this->db->num_rows($resql);
1445 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1448 $line->numero_compte = $obj->numero_compte;
1450 if (!empty($option)) {
1451 $line->subledger_account = $obj->subledger_account;
1452 $line->subledger_label = $obj->subledger_label;
1454 $line->debit = $obj->debit;
1455 $line->credit = $obj->credit;
1457 $this->lines[] = $line;
1461 $this->db->free($resql);
1465 $this->errors[] =
'Error '.$this->db->lasterror();
1466 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1488 if (isset($this->doc_type)) {
1489 $this->doc_type = trim($this->doc_type);
1491 if (isset($this->doc_ref)) {
1492 $this->doc_ref = trim($this->doc_ref);
1494 if (isset($this->fk_doc)) {
1495 $this->fk_doc = (int) $this->fk_doc;
1497 if (isset($this->fk_docdet)) {
1498 $this->fk_docdet = (int) $this->fk_docdet;
1500 if (isset($this->thirdparty_code)) {
1501 $this->thirdparty_code = trim($this->thirdparty_code);
1503 if (isset($this->subledger_account)) {
1504 $this->subledger_account = trim($this->subledger_account);
1506 if (isset($this->subledger_label)) {
1507 $this->subledger_label = trim($this->subledger_label);
1509 if (isset($this->numero_compte)) {
1510 $this->numero_compte = trim($this->numero_compte);
1512 if (isset($this->label_compte)) {
1513 $this->label_compte = trim($this->label_compte);
1515 if (isset($this->label_operation)) {
1516 $this->label_operation = trim($this->label_operation);
1518 if (isset($this->sens)) {
1519 $this->sens = trim($this->sens);
1521 if (isset($this->import_key)) {
1522 $this->import_key = trim($this->import_key);
1524 if (isset($this->code_journal)) {
1525 $this->code_journal = trim($this->code_journal);
1527 if (isset($this->journal_label)) {
1528 $this->journal_label = trim($this->journal_label);
1530 if (isset($this->piece_num)) {
1531 $this->piece_num = (int) $this->piece_num;
1537 } elseif ($result == 0) {
1539 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1541 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1546 $this->debit = (float)
price2num($this->debit,
'MT');
1547 $this->credit = (float)
price2num($this->credit,
'MT');
1548 $this->montant = (float)
price2num($this->montant,
'MT');
1554 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.$mode.
' SET';
1555 $sql .=
' doc_date = '.(isDolTms($this->doc_date) ?
"'".$this->db->idate($this->doc_date).
"'" :
'null').
',';
1556 $sql .=
' doc_type = '.(isset($this->doc_type) ?
"'".$this->db->escape($this->doc_type).
"'" :
"null").
',';
1557 $sql .=
' doc_ref = '.(isset($this->doc_ref) ?
"'".$this->db->escape($this->doc_ref).
"'" :
"null").
',';
1558 $sql .=
' fk_doc = '.(isset($this->fk_doc) ? $this->fk_doc :
"null").
',';
1559 $sql .=
' fk_docdet = '.(isset($this->fk_docdet) ? $this->fk_docdet :
"null").
',';
1560 $sql .=
' thirdparty_code = '.(isset($this->thirdparty_code) ?
"'".$this->db->escape($this->thirdparty_code).
"'" :
"null").
',';
1561 $sql .=
' subledger_account = '.(isset($this->subledger_account) ?
"'".$this->db->escape($this->subledger_account).
"'" :
"null").
',';
1562 $sql .=
' subledger_label = '.(isset($this->subledger_label) ?
"'".$this->db->escape($this->subledger_label).
"'" :
"null").
',';
1563 $sql .=
' numero_compte = '.(isset($this->numero_compte) ?
"'".$this->db->escape($this->numero_compte).
"'" :
"null").
',';
1564 $sql .=
' label_compte = '.(isset($this->label_compte) ?
"'".$this->db->escape($this->label_compte).
"'" :
"null").
',';
1565 $sql .=
' label_operation = '.(isset($this->label_operation) ?
"'".$this->db->escape($this->label_operation).
"'" :
"null").
',';
1566 $sql .=
' debit = '.(isset($this->debit) ? $this->debit :
"null").
',';
1567 $sql .=
' credit = '.(isset($this->credit) ? $this->credit :
"null").
',';
1568 $sql .=
' montant = '.(isset($this->montant) ? $this->montant :
"null").
',';
1569 $sql .=
' sens = '.(isset($this->sens) ?
"'".$this->db->escape($this->sens).
"'" :
"null").
',';
1570 $sql .=
' fk_user_author = '.(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
',';
1571 $sql .=
' import_key = '.(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
',';
1572 $sql .=
' code_journal = '.(isset($this->code_journal) ?
"'".$this->db->escape($this->code_journal).
"'" :
"null").
',';
1573 $sql .=
' journal_label = '.(isset($this->journal_label) ?
"'".$this->db->escape($this->journal_label).
"'" :
"null").
',';
1574 $sql .=
' piece_num = '.(isset($this->piece_num) ? $this->piece_num :
"null");
1575 $sql .=
' WHERE rowid='.((int) $this->
id);
1579 $resql = $this->db->query($sql);
1582 $this->errors[] =
'Error '.$this->db->lasterror();
1583 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1587 if (! $error && ! $notrigger) {
1588 $result = $this->
call_trigger(
'BOOKKEEPING_MODIFY', $user);
1596 $this->db->rollback();
1600 $this->db->commit();
1615 public function updateByMvt($piece_num =
'', $field =
'', $value =
'', $mode =
'')
1621 if (!isset($sql_filter)) {
1627 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.$mode;
1628 $sql .=
" SET ".$this->db->sanitize($field).
" = ".(is_numeric($value) ? ((float) $value) :
"'".$this->db->escape($value).
"'");
1629 $sql .=
" WHERE piece_num = ".((int) $piece_num);
1630 $sql .=
" AND entity = " . ((int)
$conf->entity);
1631 $sql .= $sql_filter;
1633 $resql = $this->db->query($sql);
1637 $this->errors[] =
'Error '.$this->db->lasterror();
1638 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1641 $this->db->rollback();
1645 $this->db->commit();
1659 public function delete(
User $user, $notrigger = 0, $mode =
'')
1668 } elseif ($result == 0) {
1670 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1672 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1683 $result = $this->
call_trigger(
'BOOKKEEPING_DELETE', $user);
1690 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.$mode;
1691 $sql .=
' WHERE rowid='.((int) $this->
id);
1693 $resql = $this->db->query($sql);
1696 $this->errors[] =
'Error '.$this->db->lasterror();
1697 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1703 $this->db->rollback();
1707 $this->db->commit();
1725 if (!isset($sql_filter)) {
1731 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1732 $sql .=
" WHERE import_key = '".$this->db->escape($importkey).
"'";
1733 $sql .= $sql_filter;
1735 $resql = $this->db->query($sql);
1738 $this->errors[] =
"Error ".$this->db->lasterror();
1739 dol_syslog(get_class($this).
"::delete Error ".$this->db->lasterror(), LOG_ERR);
1740 $this->db->rollback();
1744 $this->db->commit();
1759 global
$conf, $langs;
1761 if (empty($delyear) && empty($journal)) {
1762 $this->error =
'ErrorOneFieldRequired';
1765 if (!empty($delmonth) && empty($delyear)) {
1766 $this->error =
'YearRequiredIfMonthDefined';
1771 if (!isset($sql_filter)) {
1779 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1780 $sql .=
" WHERE 1 = 1";
1782 if (!empty($journal)) {
1783 $sql .=
" AND code_journal = '".$this->db->escape($journal).
"'";
1785 $sql .=
" AND entity = " . ((int)
$conf->entity);
1787 $sql .=
" AND date_validated IS NULL";
1788 $sql .= $sql_filter;
1792 $resql = $this->db->query($sql);
1795 $this->errors[] =
"Error ".$this->db->lasterror();
1796 foreach ($this->errors as $errmsg) {
1797 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1798 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1800 $this->db->rollback();
1804 $this->db->commit();
1818 global
$conf, $user;
1821 if (!isset($sql_filter)) {
1831 if (! $error && ! $notrigger) {
1832 $result = $this->
call_trigger(
'BOOKKEEPING_DELETE', $user);
1841 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1842 $sql .=
" WHERE piece_num = ".(int) $piecenum;
1843 $sql .=
" AND date_validated IS NULL";
1844 $sql .=
" AND entity = " . ((int)
$conf->entity);
1845 $sql .= $sql_filter;
1847 $resql = $this->db->query($sql);
1850 $this->errors[] =
"Error ".$this->db->lasterror();
1851 foreach ($this->errors as $errmsg) {
1852 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1853 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1855 $this->db->rollback();
1858 $nbprocessed = $this->db->affected_rows($resql);
1864 $this->db->rollback();
1867 $this->db->commit();
1868 return $nbprocessed;
1897 $object->context[
'createfromclone'] =
'createfromclone';
1898 $result =
$object->create($user);
1903 $this->errors =
$object->errors;
1904 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1907 unset(
$object->context[
'createfromclone']);
1911 $this->db->commit();
1915 $this->db->rollback();
1934 $this->doc_date = $now;
1935 $this->doc_type =
'';
1936 $this->doc_ref =
'';
1938 $this->fk_docdet = 0;
1939 $this->thirdparty_code =
'CU001';
1940 $this->subledger_account =
'41100001';
1941 $this->subledger_label =
'My customer company';
1942 $this->numero_compte =
'411';
1943 $this->label_compte =
'Customer';
1944 $this->label_operation =
'Sales of pea';
1945 $this->debit = 99.9;
1946 $this->credit = 0.0;
1947 $this->amount = 0.0;
1949 $this->fk_user_author = $user->id;
1950 $this->import_key =
'20201027';
1951 $this->code_journal =
'VT';
1952 $this->journal_label =
'Journal de vente';
1953 $this->piece_num = 1234;
1954 $this->date_creation = $now;
1970 $sql =
"SELECT piece_num, ref, doc_date, code_journal, journal_label, doc_ref, doc_type,";
1971 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation, date_lim_reglement, import_key";
1973 if ($mode !=
"_tmp") {
1974 $sql .=
", date_export";
1976 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1977 $sql .=
" WHERE piece_num = ".((int) $piecenum);
1978 $sql .=
" AND entity = " . ((int)
$conf->entity);
1981 $result = $this->db->query($sql);
1983 $obj = $this->db->fetch_object($result);
1985 $this->piece_num = $obj->piece_num;
1986 $this->
ref = $obj->ref;
1987 $this->code_journal = $obj->code_journal;
1988 $this->journal_label = $obj->journal_label;
1989 $this->doc_date = $this->db->jdate($obj->doc_date);
1990 $this->doc_ref = $obj->doc_ref;
1991 $this->doc_type = $obj->doc_type;
1992 $this->date_creation = $this->db->jdate($obj->date_creation);
1993 $this->date_modification = $this->db->jdate($obj->date_modification);
1994 if ($mode !=
"_tmp") {
1995 $this->date_export = $this->db->jdate($obj->date_export);
1997 $this->date_validation = $this->db->jdate($obj->date_validation);
1998 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1999 $this->import_key = $obj->import_key;
2001 $this->error =
"Error ".$this->db->lasterror();
2002 dol_syslog(__METHOD__.$this->error, LOG_ERR);
2019 $sql =
"SELECT MAX(piece_num) + 1 as max FROM ".$this->db->prefix().$this->table_element.$mode;
2020 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2022 dol_syslog(get_class($this).
"::getNextNumMvt", LOG_DEBUG);
2024 $result = $this->db->query($sql);
2027 $obj = $this->db->fetch_object($result);
2029 $result = $obj->max;
2031 if (empty($result)) {
2036 $this->error =
"Error ".$this->db->lasterror();
2037 dol_syslog(get_class($this).
"::getNextNumMvt ".$this->error, LOG_ERR);
2048 public function getNextNumRef()
2050 global $langs,
$conf;
2051 $langs->load(
"accountancy");
2060 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
2061 foreach ($dirmodels as $reldir) {
2065 $mybool = ((bool) @include_once $dir.$file) || $mybool;
2073 $obj =
new $classname();
2075 '@phan-var-force ModeleNumRefBookkeeping $obj';
2077 $numref = $obj->getNextValue($this);
2079 if ($numref !=
"") {
2082 $this->error = $obj->error;
2087 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_BOOKKEEPING_ADDON_NotDefined");
2105 $sql =
"SELECT rowid, doc_date, doc_type,";
2106 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
2107 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
2108 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, journal_label, piece_num,";
2109 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation";
2111 if ($mode !=
"_tmp") {
2112 $sql .=
", date_export";
2114 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
2115 $sql .=
" WHERE piece_num = ".((int) $piecenum);
2116 $sql .=
" AND entity = " . ((int)
$conf->entity);
2119 $result = $this->db->query($sql);
2121 while ($obj = $this->db->fetch_object($result)) {
2124 $line->id = $obj->rowid;
2126 $line->doc_date = $this->db->jdate($obj->doc_date);
2127 $line->doc_type = $obj->doc_type;
2128 $line->doc_ref = $obj->doc_ref;
2129 $line->fk_doc = $obj->fk_doc;
2130 $line->fk_docdet = $obj->fk_docdet;
2131 $line->thirdparty_code = $obj->thirdparty_code;
2132 $line->subledger_account = $obj->subledger_account;
2133 $line->subledger_label = $obj->subledger_label;
2134 $line->numero_compte = $obj->numero_compte;
2135 $line->label_compte = $obj->label_compte;
2136 $line->label_operation = $obj->label_operation;
2137 $line->debit = $obj->debit;
2138 $line->credit = $obj->credit;
2139 $line->montant = $obj->amount;
2140 $line->amount = $obj->amount;
2141 $line->sens = $obj->sens;
2142 $line->code_journal = $obj->code_journal;
2143 $line->journal_label = $obj->journal_label;
2144 $line->piece_num = $obj->piece_num;
2145 $line->date_creation = $obj->date_creation;
2146 $line->date_modification = $obj->date_modification;
2147 if ($mode !=
"_tmp") {
2148 $line->date_export = $obj->date_export;
2150 $line->date_validation = $obj->date_validation;
2152 $this->linesmvt[] = $line;
2155 $this->error =
"Error ".$this->db->lasterror();
2156 dol_syslog(__METHOD__.$this->error, LOG_ERR);
2175 $sql =
"SELECT rowid, doc_date, doc_type,";
2176 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
2177 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
2178 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, piece_num,";
2179 $sql .=
" date_validated as date_validation";
2180 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
2181 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2183 dol_syslog(get_class($this).
"::export_bookkeeping", LOG_DEBUG);
2185 $resql = $this->db->query($sql);
2188 $this->linesexport = array();
2190 $num = $this->db->num_rows($resql);
2191 while ($obj = $this->db->fetch_object($resql)) {
2194 $line->id = $obj->rowid;
2196 $line->doc_date = $this->db->jdate($obj->doc_date);
2197 $line->doc_type = $obj->doc_type;
2198 $line->doc_ref = $obj->doc_ref;
2199 $line->fk_doc = $obj->fk_doc;
2200 $line->fk_docdet = $obj->fk_docdet;
2201 $line->thirdparty_code = $obj->thirdparty_code;
2202 $line->subledger_account = $obj->subledger_account;
2203 $line->subledger_label = $obj->subledger_label;
2204 $line->numero_compte = $obj->numero_compte;
2205 $line->label_compte = $obj->label_compte;
2206 $line->label_operation = $obj->label_operation;
2207 $line->debit = $obj->debit;
2208 $line->credit = $obj->credit;
2209 $line->montant = $obj->amount;
2210 $line->amount = $obj->amount;
2211 $line->sens = $obj->sens;
2212 $line->code_journal = $obj->code_journal;
2213 $line->piece_num = $obj->piece_num;
2214 $line->date_validation = $obj->date_validation;
2216 $this->linesexport[] = $line;
2218 $this->db->free($resql);
2222 $this->error =
"Error ".$this->db->lasterror();
2223 dol_syslog(get_class($this).
"::export_bookkeeping ".$this->error, LOG_ERR);
2243 if (!isset($sql_filter)) {
2249 $tmpBookkeeping =
new self($this->db);
2250 $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}");
2251 $tmpBookkeeping->doc_date = $this->db->jdate($tmpData->doc_date);
2252 $tmpBookkeeping->code_journal = $tmpData->code_journal;
2255 $ref = $tmpData->ref ?: $tmpBookkeeping->getNextNumRef();
2256 if ($direction == 0) {
2260 if ($next_piecenum < 0) {
2266 $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";
2267 $resql = $this->db->query($sql);
2270 $this->errors[] =
'Error '.$this->db->lasterror();
2271 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2276 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
' (doc_date, doc_type, ref,';
2277 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2278 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2279 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num, date_creation)';
2280 $sql .=
' SELECT doc_date, doc_type,' .
"'{$ref}',";
2281 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2282 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2283 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.((int) $next_piecenum).
", '".$this->db->idate($now).
"'";
2284 $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);
2285 $sql .= $sql_filter;
2286 $resql = $this->db->query($sql);
2289 $this->errors[] =
'Error '.$this->db->lasterror();
2290 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2295 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2296 $resql = $this->db->query($sql);
2299 $this->errors[] =
'Error '.$this->db->lasterror();
2300 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2303 } elseif ($direction == 1) {
2305 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2306 $resql = $this->db->query($sql);
2309 $this->errors[] =
'Error '.$this->db->lasterror();
2310 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2315 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
'_tmp (doc_date, doc_type, ref,';
2316 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2317 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2318 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)';
2319 $sql .=
' SELECT doc_date, doc_type,' .
"'{$ref}',";
2320 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2321 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2322 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num';
2323 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2324 $sql .= $sql_filter;
2325 $resql = $this->db->query($sql);
2328 $this->errors[] =
'Error '.$this->db->lasterror();
2329 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2334 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2335 $sql .= $sql_filter;
2336 $resql = $this->db->query($sql);
2339 $this->errors[] =
'Error '.$this->db->lasterror();
2340 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2345 $this->db->commit();
2348 $this->db->rollback();
2376 public function select_account($selectid, $htmlname =
'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase =
'')
2381 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
2385 $sql =
"SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version";
2386 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as ab";
2387 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as aa ON aa.account_number = ab.numero_compte";
2388 $sql .=
" AND aa.active = 1";
2389 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2390 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2391 $sql .=
" AND ab.entity = " . ((int)
$conf->entity);
2392 $sql .=
" ORDER BY account_number ASC";
2394 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2395 $resql = $this->db->query($sql);
2398 $this->error =
"Error ".$this->db->lasterror();
2399 dol_syslog(get_class($this).
"::select_account ".$this->error, LOG_ERR);
2408 while ($obj = $this->db->fetch_object($resql)) {
2411 $select_value_in = $obj->rowid;
2412 $select_value_out = $obj->rowid;
2414 if ($select_in == 1) {
2415 $select_value_in = $obj->account_number;
2417 if ($select_out == 1) {
2418 $select_value_out = $obj->account_number;
2423 if (($selectid !=
'') && $selectid == $select_value_in) {
2424 $selected = $select_value_out;
2427 $options[$select_value_out] = $label;
2430 $out .=
Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0,
'', 0, 0, 0,
'',
'maxwidth300');
2431 $this->db->free($resql);
2447 $sql =
"SELECT root.rowid, root.account_number, root.label as label,";
2448 $sql .=
" parent.rowid as parent_rowid, parent.account_number as parent_account_number, parent.label as parent_label";
2449 $sql .=
" FROM ".$this->db->prefix().
"accounting_account as aa";
2450 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2451 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2452 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as parent ON aa.account_parent = parent.rowid AND parent.active = 1";
2453 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as root ON parent.account_parent = root.rowid AND root.active = 1";
2454 $sql .=
" WHERE aa.account_number = '".$this->db->escape($account).
"'";
2455 $sql .=
" AND aa.entity = " . ((int)
$conf->entity);
2457 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2458 $resql = $this->db->query($sql);
2461 if ($this->db->num_rows($resql)) {
2462 $obj = $this->db->fetch_object($resql);
2465 $result = array(
'id' => $obj->rowid,
'account_number' => $obj->account_number,
'label' => $obj->label);
2468 $this->error =
"Error ".$this->db->lasterror();
2469 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2488 $sql =
"SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
2489 $sql .=
" FROM ".$this->db->prefix().
"accounting_account as aa ";
2490 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2491 $sql .=
" AND aa.account_number = '".$this->db->escape($account).
"'";
2492 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2493 $sql .=
" AND aa.active = 1";
2494 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
2495 $sql .=
" WHERE aa.entity = " . ((int)
$conf->entity);
2497 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2498 $resql = $this->db->query($sql);
2500 $obj = (object) array(
'label' =>
'');
2501 if ($this->db->num_rows($resql)) {
2502 $obj = $this->db->fetch_object($resql);
2504 if (empty($obj->category)) {
2507 return $obj->label.
' ('.$obj->category.
')';
2510 $this->error =
"Error ".$this->db->lasterror();
2511 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2527 $alias = trim($alias);
2528 $alias = !empty($alias) && strpos($alias,
'.') ===
false ? $alias .
"." : $alias;
2530 if (!isset(self::$can_modify_bookkeeping_sql_cached[$alias]) || $force) {
2536 $sql_list = array();
2537 if (!empty(
$conf->cache[
'active_fiscal_period_cached']) && is_array(
$conf->cache[
'active_fiscal_period_cached'])) {
2539 foreach (
$conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2540 $sql_list[$i] =
"(";
2541 $sql_list[$i] .=
"'".$this->db->idate($fiscal_period[
'date_start']) .
"' <= ".$this->db->sanitize($alias).
"doc_date";
2542 if (!empty($fiscal_period[
'date_end'])) {
2543 $sql_list[$i] .=
" AND ";
2544 $sql_list[$i] .= $this->db->sanitize($alias).
"doc_date <= '" . $this->db->idate($fiscal_period[
'date_end']).
"'";
2546 $sql_list[$i] .=
")";
2550 $sqlsanitized = implode(
' OR ', $sql_list);
2551 self::$can_modify_bookkeeping_sql_cached[$alias] = empty($sql_list) ?
"" :
" AND (".$sqlsanitized.
")";
2554 return self::$can_modify_bookkeeping_sql_cached[$alias];
2576 $result = $bookkeeping->fetch($id,
null, $mode);
2581 if (!empty(
$conf->cache[
'closed_fiscal_period_cached']) && is_array(
$conf->cache[
'closed_fiscal_period_cached'])) {
2582 foreach (
$conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2583 if ($fiscal_period[
'date_start'] <= $bookkeeping->doc_date && $bookkeeping->doc_date <= $fiscal_period[
'date_end']) {
2597 $result = $bookkeeping->fetch($id,
null, $mode);
2602 if (!empty(
$conf->cache[
'active_fiscal_period_cached']) && is_array(
$conf->cache[
'active_fiscal_period_cached'])) {
2603 foreach (
$conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2604 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'])) {
2628 $accountingLabelOperation =
'';
2631 $truncThirdpartyName = 16;
2634 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2636 $accountingLabelOperation = $thirdpartyname;
2638 if (!empty($reference)) {
2639 $accountingLabelOperation .=
' - '. $reference;
2641 if (!empty($labelaccount)) {
2642 $accountingLabelOperation .=
' - '. $labelaccount;
2644 } elseif (
getDolGlobalInt(
'ACCOUNTING_LABEL_OPERATION_ON_TRANSFER') == 1) {
2645 $truncThirdpartyName = 32;
2648 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2650 $accountingLabelOperation = $thirdpartyname;
2652 if (!empty($reference)) {
2653 $accountingLabelOperation .=
' - '. $reference;
2655 } elseif (
getDolGlobalInt(
'ACCOUNTING_LABEL_OPERATION_ON_TRANSFER') == 2) {
2656 $truncThirdpartyName = 64;
2659 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2661 $accountingLabelOperation = $thirdpartyname;
2665 return $accountingLabelOperation;
2685 if (!empty(
$conf->cache[
'closed_fiscal_period_cached']) && is_array(
$conf->cache[
'closed_fiscal_period_cached'])) {
2686 foreach (
$conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2687 if ($fiscal_period[
'date_start'] <= $date && $date <= $fiscal_period[
'date_end']) {
2700 if (!empty(
$conf->cache[
'active_fiscal_period_cached']) && is_array(
$conf->cache[
'active_fiscal_period_cached'])) {
2701 foreach (
$conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2702 if (!empty($fiscal_period[
'date_start']) && $fiscal_period[
'date_start'] <= $date && (empty($fiscal_period[
'date_end']) || $date <= $fiscal_period[
'date_end'])) {
2723 if ($mode ==
'active') {
2724 if (!isset(
$conf->cache[
'active_fiscal_period_cached']) || $force) {
2725 $sql =
"SELECT date_start, date_end";
2726 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2727 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2728 $sql .=
" AND statut = 0";
2730 $resql = $this->db->query($sql);
2732 $this->errors[] = $this->db->lasterror();
2737 while ($obj = $this->db->fetch_object($resql)) {
2738 $date_start = $this->db->jdate($obj->date_start);
2739 $date_end_base = $this->db->jdate($obj->date_end);
2742 'date_start' => $date_start,
2743 'date_end' => $date_end,
2746 $conf->cache[
'active_fiscal_period_cached'] = $list;
2749 if ($mode ==
'closed') {
2750 if (!isset(
$conf->cache[
'closed_fiscal_period_cached']) || $force) {
2751 $sql =
"SELECT date_start, date_end";
2752 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2753 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2754 $sql .=
" AND statut = 1";
2756 $resql = $this->db->query($sql);
2758 $this->errors[] = $this->db->lasterror();
2763 while ($obj = $this->db->fetch_object($resql)) {
2764 $date_start = $this->db->jdate($obj->date_start);
2765 $date_end_base = $this->db->jdate($obj->date_end);
2769 'date_start' => $date_start,
2770 'date_end' => $date_end,
2773 $conf->cache[
'closed_fiscal_period_cached'] = $list;
2790 $sql =
"SELECT rowid, label, date_start, date_end, statut";
2791 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2792 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2793 $sql .= $this->db->order(
'date_start',
'ASC');
2795 $resql = $this->db->query($sql);
2797 $this->errors[] = $this->db->lasterror();
2801 while ($obj = $this->db->fetch_object($resql)) {
2802 $list[$obj->rowid] = array(
2803 'id' => (
int) $obj->rowid,
2804 'label' => $obj->label,
2805 'date_start' => $this->db->jdate($obj->date_start),
2806 'date_end' => $this->db->jdate($obj->date_end),
2807 'status' => (
int) $obj->statut,
2829 $sql =
"SELECT YEAR(b.doc_date) as year";
2830 for ($i = 1; $i <= 12; $i++) {
2831 $sql .=
", SUM(".$this->db->ifsql(
"MONTH(b.doc_date) = ".((
int) $i),
"1",
"0") .
") AS month".((int) $i);
2833 $sql .=
", COUNT(b.rowid) as total";
2834 $sql .=
" FROM " . $this->db->prefix() . $this->table_element .
" as b";
2835 $sql .=
" WHERE b.doc_date >= '" . $this->db->idate($date_start) .
"'";
2836 $sql .=
" AND b.doc_date <= '" . $this->db->idate($date_end) .
"'";
2837 $sql .=
" AND b.entity IN (" .
getEntity(
'bookkeeping', 0) .
")";
2842 $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)";
2845 $sql .=
" AND date_validated IS NULL";
2848 $sql .=
" GROUP BY YEAR(b.doc_date)";
2849 $sql .= $this->db->order(
"year",
'ASC');
2852 $resql = $this->db->query($sql);
2854 $this->errors[] = $this->db->lasterror();
2858 while ($obj = $this->db->fetch_object($resql)) {
2859 $total += (int) $obj->total;
2861 'year' => (
int) $obj->year,
2863 'total' => (
int) $obj->total,
2865 for ($i = 1; $i <= 12; $i++) {
2866 $year_list[
'count'][$i] = (int) $obj->{
'month' . $i};
2869 $list[] = $year_list;
2872 $this->db->free($resql);
2894 $sql =
" UPDATE " . $this->db->prefix() . $this->table_element;
2895 $sql .=
" SET date_validated = '" . $this->db->idate($now) .
"'";
2896 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2897 $sql .=
" AND DATE(doc_date) >= '" . $this->db->idate($date_start) .
"'";
2898 $sql .=
" AND DATE(doc_date) <= '" . $this->db->idate($date_end) .
"'";
2899 $sql .=
" AND date_validated IS NULL";
2902 $resql = $this->db->query($sql);
2904 $this->errors[] = $this->db->lasterror();
2924 $income_statement_amount = 0;
2926 if (
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
2927 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
2929 $pcg_type_filter = array();
2930 foreach ($accounting_groups_used_for_income_statement as $item) {
2931 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
2935 $sql .=
" t.numero_compte,";
2936 $sql .=
" aa.pcg_type,";
2937 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as accounting_result";
2938 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
2939 $sql .=
' LEFT JOIN ' . $this->db->prefix() .
'accounting_account as aa ON aa.account_number = t.numero_compte';
2940 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
2941 $sql .=
" AND aa.entity = " . ((int)
$conf->entity);
2942 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM ' . $this->db->prefix() .
'accounting_system WHERE rowid = ' . ((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')) .
')';
2943 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
2944 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) .
"'";
2945 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
2946 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
2948 $resql = $this->db->query($sql);
2950 $this->errors[] =
'Error ' . $this->db->lasterror();
2951 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2953 while ($obj = $this->db->fetch_object($resql)) {
2954 $income_statement_amount += $obj->accounting_result;
2959 return (
string) $income_statement_amount;
2971 public function closeFiscalPeriod($fiscal_period_id, $new_fiscal_period_id, $separate_auxiliary_account =
false, $generate_bookkeeping_records =
true)
2973 global
$conf, $langs, $user;
2976 $fiscal_period_id = max(0, $fiscal_period_id);
2977 if (empty($fiscal_period_id)) {
2978 $langs->load(
'errors');
2979 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2983 $result = $fiscal_period->fetch($fiscal_period_id);
2985 $this->error = $fiscal_period->error;
2986 $this->errors = $fiscal_period->errors;
2988 } elseif (empty($fiscal_period->id)) {
2989 $langs->loadLangs(array(
'errors',
'compta'));
2990 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
2995 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
2996 if (empty($new_fiscal_period_id)) {
2997 $langs->load(
'errors');
2998 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3001 $new_fiscal_period =
new Fiscalyear($this->db);
3002 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
3004 $this->error = $new_fiscal_period->error;
3005 $this->errors = $new_fiscal_period->errors;
3007 } elseif (empty($new_fiscal_period->id)) {
3008 $langs->loadLangs(array(
'errors',
'compta'));
3009 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
3016 $fiscal_period->statut = Fiscalyear::STATUS_CLOSED;
3017 $fiscal_period->status = Fiscalyear::STATUS_CLOSED;
3018 $result = $fiscal_period->update($user);
3020 $this->error = $fiscal_period->error;
3021 $this->errors = $fiscal_period->errors;
3025 if (!$error && !empty($generate_bookkeeping_records)) {
3027 if (empty($journal_id)) {
3028 $langs->loadLangs(array(
'errors',
'accountancy'));
3029 $this->errors[] = $langs->trans(
'ErrorBadParameters') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
3036 $result = $journal->fetch($journal_id);
3038 $this->error = $journal->error;
3039 $this->errors = $journal->errors;
3041 } elseif ($result == 0) {
3042 $langs->loadLangs(array(
'errors',
'accountancy'));
3043 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
3050 if (!$error && is_object($journal)) {
3051 $accounting_groups_used_for_balance_sheet_account = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))),
'strlen');
3052 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
3054 $pcg_type_filter = array();
3055 $tmp = array_merge($accounting_groups_used_for_balance_sheet_account, $accounting_groups_used_for_income_statement);
3056 foreach ($tmp as $item) {
3057 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
3061 $sql .=
" t.numero_compte,";
3062 if ($separate_auxiliary_account) {
3063 $sql .=
" NULLIF(t.subledger_account, '') as subledger_account,";
3065 $sql .=
" aa.pcg_type,";
3066 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as opening_balance";
3067 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
3068 $sql .=
' LEFT JOIN ' . $this->db->prefix() .
'accounting_account as aa ON aa.account_number = t.numero_compte';
3069 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
3070 $sql .=
" AND aa.entity = ". ((int)
$conf->entity);
3071 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM '.$this->db->prefix().
'accounting_system WHERE rowid = '.((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')).
')';
3072 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
3073 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
3074 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
3075 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
3076 if ($separate_auxiliary_account) {
3077 $sql .=
" , NULLIF(t.subledger_account, '')";
3079 $sql .=
' HAVING (SUM(t.credit) - SUM(t.debit)) != 0 ';
3080 $sql .= $this->db->order(
"t.numero_compte",
"ASC");
3082 $resql = $this->db->query($sql);
3084 $this->errors[] =
'Error ' . $this->db->lasterror();
3085 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3090 $income_statement_amount = 0;
3091 while ($obj = $this->db->fetch_object($resql)) {
3092 if (in_array($obj->pcg_type, $accounting_groups_used_for_income_statement)) {
3093 $income_statement_amount += $obj->opening_balance;
3096 $mt = $obj->opening_balance;
3099 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3101 $bookkeeping->date_lim_reglement =
'';
3102 $bookkeeping->doc_ref = $fiscal_period->label;
3104 $bookkeeping->date_creation = $now;
3105 $bookkeeping->doc_type =
'closure';
3106 $bookkeeping->fk_doc = $fiscal_period->id;
3107 $bookkeeping->fk_docdet = 0;
3108 $bookkeeping->thirdparty_code =
'';
3110 if ($separate_auxiliary_account) {
3111 $bookkeeping->subledger_account = $obj->subledger_account;
3113 $sql .=
" subledger_label";
3114 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
3115 $sql .=
" WHERE subledger_account = '" . $this->db->escape($obj->subledger_account) .
"'";
3116 $sql .=
" ORDER BY doc_date DESC";
3118 $result = $this->db->query($sql);
3120 $this->errors[] =
'Error: ' . $this->db->lasterror();
3121 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3124 $objtmp = $this->db->fetch_object($result);
3125 $bookkeeping->subledger_label = $objtmp->subledger_label;
3127 $bookkeeping->subledger_account =
null;
3128 $bookkeeping->subledger_label =
null;
3131 $bookkeeping->numero_compte = $obj->numero_compte;
3133 $accountingaccount->fetch(0, $obj->numero_compte);
3134 $bookkeeping->label_compte = $accountingaccount->label;
3136 $bookkeeping->label_operation = $new_fiscal_period->label;
3137 $bookkeeping->montant = $mt;
3138 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
3139 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
3140 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
3141 $bookkeeping->code_journal = $journal->code;
3142 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
3143 $bookkeeping->fk_user_author = $user->id;
3144 $bookkeeping->entity =
$conf->entity;
3146 $result = $bookkeeping->create($user);
3148 $this->setErrorsFromObject($bookkeeping);
3156 if (!$error && $income_statement_amount != 0) {
3157 $mt = $income_statement_amount;
3159 $accountingaccount->fetch(0,
getDolGlobalString($income_statement_amount < 0 ?
'ACCOUNTING_RESULT_LOSS' :
'ACCOUNTING_RESULT_PROFIT'),
true);
3162 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3164 $bookkeeping->date_lim_reglement =
'';
3165 $bookkeeping->doc_ref = $fiscal_period->label;
3167 $bookkeeping->date_creation = $now;
3168 $bookkeeping->doc_type =
'closure';
3169 $bookkeeping->fk_doc = $fiscal_period->id;
3170 $bookkeeping->fk_docdet = 0;
3171 $bookkeeping->thirdparty_code =
'';
3173 if ($separate_auxiliary_account) {
3174 $bookkeeping->subledger_account = $obj->subledger_account;
3176 $sql .=
" subledger_label";
3177 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
3178 $sql .=
" WHERE subledger_account = '" . $this->db->escape($obj->subledger_account) .
"'";
3179 $sql .=
" ORDER BY doc_date DESC";
3181 $result = $this->db->query($sql);
3183 $this->errors[] =
'Error: ' . $this->db->lasterror();
3184 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3187 $objtmp = $this->db->fetch_object($result);
3188 $bookkeeping->subledger_label = $objtmp->subledger_label ??
null;
3190 $bookkeeping->subledger_account =
null;
3191 $bookkeeping->subledger_label =
null;
3194 $bookkeeping->numero_compte = $accountingaccount->account_number;
3195 $bookkeeping->label_compte = $accountingaccount->label;
3197 $bookkeeping->label_operation = $new_fiscal_period->label;
3198 $bookkeeping->montant = $mt;
3199 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
3200 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
3201 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
3202 $bookkeeping->code_journal = $journal->code;
3203 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
3204 $bookkeeping->fk_user_author = $user->id;
3205 $bookkeeping->entity =
$conf->entity;
3207 $result = $bookkeeping->create($user);
3209 $this->setErrorsFromObject($bookkeeping);
3213 $this->db->free($resql);
3219 $this->db->rollback();
3222 $this->db->commit();
3239 global
$conf, $langs, $user;
3242 $fiscal_period_id = max(0, $fiscal_period_id);
3243 if (empty($fiscal_period_id)) {
3244 $langs->load(
'errors');
3245 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3249 $result = $fiscal_period->fetch($fiscal_period_id);
3251 $this->error = $fiscal_period->error;
3252 $this->errors = $fiscal_period->errors;
3254 } elseif (empty($fiscal_period->id)) {
3255 $langs->loadLangs(array(
'errors',
'compta'));
3256 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
3261 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
3262 if (empty($new_fiscal_period_id)) {
3263 $langs->load(
'errors');
3264 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3267 $new_fiscal_period =
new Fiscalyear($this->db);
3268 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
3270 $this->error = $new_fiscal_period->error;
3271 $this->errors = $new_fiscal_period->errors;
3273 } elseif (empty($new_fiscal_period->id)) {
3274 $langs->loadLangs(array(
'errors',
'compta'));
3275 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
3280 $inventory_journal_id = max(0, $inventory_journal_id);
3281 if (empty($inventory_journal_id)) {
3282 $langs->load(
'errors');
3283 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3288 $result = $inventory_journal->fetch($inventory_journal_id);
3290 $this->error = $inventory_journal->error;
3291 $this->errors = $inventory_journal->errors;
3293 } elseif ($result == 0) {
3294 $langs->loadLangs(array(
'errors',
'accountancy'));
3295 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'InventoryJournal');
3302 $sql =
'SELECT t.rowid';
3303 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
3304 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
3305 $sql .=
" AND code_journal = '" . $this->db->escape($inventory_journal->code) .
"'";
3306 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) .
"'";
3307 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
3308 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
3309 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
3311 $resql = $this->db->query($sql);
3313 $this->errors[] =
'Error ' . $this->db->lasterror();
3314 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3319 while ($obj = $this->db->fetch_object($resql)) {
3321 $result = $bookkeeping->fetch($obj->rowid);
3323 $this->error = $inventory_journal->error;
3324 $this->errors = $inventory_journal->errors;
3327 } elseif ($result == 0) {
3328 $langs->loadLangs(array(
'errors',
'accountancy'));
3329 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'LineId') .
': ' . $obj->rowid;
3334 $bookkeeping->id = 0;
3335 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3336 $bookkeeping->doc_ref = $new_fiscal_period->label;
3337 $bookkeeping->date_creation = $now;
3338 $bookkeeping->doc_type =
'accounting_reversal';
3339 $bookkeeping->fk_doc = $new_fiscal_period->id;
3340 $bookkeeping->fk_docdet = 0;
3342 $bookkeeping->montant = -$bookkeeping->montant;
3343 $bookkeeping->sens = ($bookkeeping->montant >= 0) ?
'C' :
'D';
3344 $old_debit = $bookkeeping->debit;
3345 $bookkeeping->debit = $bookkeeping->credit;
3346 $bookkeeping->credit = $old_debit;
3348 $bookkeeping->fk_user_author = $user->id;
3349 $bookkeeping->entity =
$conf->entity;
3351 $result = $bookkeeping->create($user);
3353 $this->error = $bookkeeping->error;
3354 $this->errors = $bookkeeping->errors;
3359 $this->db->free($resql);
3363 $this->db->rollback();
3366 $this->db->commit();
3380 global $langs, $user;
3390 if ((
int) $accounting_account > 0) {
3391 $accountingaccount->fetch($accounting_account);
3393 foreach ($toselect as
$id) {
3394 if ($bookkeeping->fetch(
$id)) {
3396 $accountcustcode =
'411';
3400 $accountsuppcode =
'401';
3403 if (strpos($bookkeeping->numero_compte, $accountcustcode) === 0 || strpos($bookkeeping->numero_compte, $accountsuppcode) === 0) {
3404 $echecT[]=$bookkeeping->numero_compte;
3408 $bookkeeping->numero_compte = $accountingaccount->account_number;
3409 $bookkeeping->label_compte = $accountingaccount->label;
3411 $result = $bookkeeping->update($user);
3423 $echecImplode = implode(
",", $echecT);
3427 $this->db->rollback();
3431 setEventMessages($nb .
" " . $langs->trans(
'AssignAccountsSuccess'),
null,
'mesgs');
3432 } elseif ($nb > 0) {
3433 setEventMessages($nb .
" " . $langs->trans(
'AssignAccountSuccess'),
null,
'mesgs');
3439 if (!empty($echecImplode)) {
3440 $nbEchec = count(explode(
',', $echecImplode));
3441 setEventMessages($nbEchec == 1 ? $langs->trans(
'NoAccountChangedWithAccountNumber') .
' ' . $echecImplode : $langs->trans(
'NoAccountsChangedWithAccountNumber') .
' ' . $echecImplode,
null,
'errors'
3446 $this->db->rollback();
3449 $this->db->commit();
3462 public function newClone($piecenum, $code_journal, $docdate)
3469 $accountingJournal->fetch(0, $code_journal);
3473 $periodeFiscal = $bookKeepingValid->validBookkeepingDate($docdate);
3474 if ($periodeFiscal < 0) {
3477 } elseif ($periodeFiscal == 0) {
3479 setEventMessages($langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod'),
null,
'errors');
3481 setEventMessages($langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod'),
null,
'errors');
3482 header(
"Location: " . $_SERVER[
'HTTP_REFERER']);
3489 $bookKeepingInstance =
new BookKeeping($this->db);
3490 $pieceNumNext = $bookKeepingInstance->getNextNumMvt();
3493 $sqlRowidClone =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE piece_num = ".((int) $piecenum);
3494 $resqlRowidClone = $this->db->query($sqlRowidClone);
3496 if ($resqlRowidClone) {
3497 while ($objRowidClone = $this->db->fetch_object($resqlRowidClone)) {
3498 $cloneId[] = $objRowidClone->rowid;
3501 foreach ($cloneId as $toselectid) {
3503 if ($bookKeeping->fetch($toselectid)) {
3504 $code_journal =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $code_journal : $bookKeeping->code_journal;
3505 $journal_label =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $accountingJournal->label : $bookKeeping->journal_label;
3507 $sql =
"SELECT piece_num, label_operation, numero_compte, label_compte, doc_type, code_journal, fk_user_author, doc_ref,";
3508 $sql .=
" fk_doc, fk_docdet, debit, credit, journal_label, sens, montant, subledger_account, subledger_label";
3509 $sql .=
" FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping";
3510 $sql .=
" WHERE rowid = " . ((int) $toselectid);
3511 $resql = $this->db->query($sql);
3514 while ($obj = $this->db->fetch_object($resql)) {
3515 $docRef = $langs->trans(
'CloneOf', $obj->doc_ref);
3517 $sql_insert =
"INSERT INTO " . MAIN_DB_PREFIX .
"accounting_bookkeeping";
3518 $sql_insert .=
" (piece_num, label_operation, numero_compte, label_compte, doc_type, code_journal, doc_date, fk_user_author, doc_ref,";
3519 $sql_insert .=
" fk_doc, fk_docdet, debit, credit, date_creation, journal_label, sens, montant, subledger_account, subledger_label)";
3520 $sql_insert .=
" VALUES";
3521 $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) .
"', ";
3522 $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) .
"')";
3524 $resqlInsert = $this->db->query($sql_insert);
3527 setEventMessages($langs->trans(
'CloningSuccess', $pieceNumNext),
null,
'mesgs');
3529 setEventMessages($langs->trans(
'CloningFailed') . $this->db->lasterror(),
null,
'errors');
3539 $this->db->rollback();
3542 $this->db->commit();
3557 global $langs, $user;
3563 if (empty($docdate)) {
3567 $idImplodeSelect = implode(
',', $toselect);
3570 $sqlPieceNum =
"SELECT DISTINCT(piece_num) FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE rowid IN (".$this->db->sanitize($idImplodeSelect).
")";
3571 $resqlPieceNum = $this->db->query($sqlPieceNum);
3573 if ($resqlPieceNum) {
3574 while ($objPieceNum = $this->db->fetch_object($resqlPieceNum)) {
3575 $pieceNumT[] = $objPieceNum->piece_num;
3578 foreach ($pieceNumT as $pieceNum) {
3580 $accountingJournal->fetch(0, $code_journal);
3582 $periodeFiscal = $bookKeepingValid->validBookkeepingDate($docdate);
3583 if ($periodeFiscal < 0) {
3585 } elseif ($periodeFiscal == 0) {
3587 setEventMessages($langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod'),
null,
'errors');
3589 setEventMessages($langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod'),
null,
'errors');
3590 header(
"Location: " . $_SERVER[
'HTTP_REFERER']);
3595 $bookKeepingInstance =
new BookKeeping($this->db);
3596 $pieceNumNext = $bookKeepingInstance->getNextNumMvt();
3598 $sqlRowidClone =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE piece_num = $pieceNum";
3599 $resqlRowidClone = $this->db->query($sqlRowidClone);
3601 if ($resqlRowidClone) {
3602 while ($objRowidClone = $this->db->fetch_object($resqlRowidClone)) {
3603 $cloneId[] = $objRowidClone->rowid;
3606 foreach ($cloneId as $toselectid) {
3608 if ($bookKeeping->fetch($toselectid)) {
3609 $code_journal =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $code_journal : $bookKeeping->code_journal;
3610 $journal_label =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $accountingJournal->label : $bookKeeping->journal_label;
3611 $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";
3612 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping WHERE rowid = " . ((int) $toselectid);
3614 $resql = $this->db->query($sql);
3616 while ($obj = $this->db->fetch_object($resql)) {
3617 $docRef = $langs->trans(
"CloneOf", $obj->doc_ref);
3619 $sql_insert =
"INSERT INTO ".$this->db->prefix().
"accounting_bookkeeping (";
3620 $sql_insert .=
" piece_num";
3621 $sql_insert .=
", label_operation";
3622 $sql_insert .=
", numero_compte";
3623 $sql_insert .=
", label_compte";
3624 $sql_insert .=
", subledger_account";
3625 $sql_insert .=
", subledger_label";
3626 $sql_insert .=
", doc_type";
3627 $sql_insert .=
", code_journal";
3628 $sql_insert .=
", doc_date";
3629 $sql_insert .=
", date_creation";
3630 $sql_insert .=
", fk_user_author";
3631 $sql_insert .=
", doc_ref";
3632 $sql_insert .=
", fk_doc";
3633 $sql_insert .=
", fk_docdet";
3634 $sql_insert .=
", debit";
3635 $sql_insert .=
", credit";
3636 $sql_insert .=
", journal_label";
3637 $sql_insert .=
", sens";
3638 $sql_insert .=
", montant";
3640 $sql_insert .=
" VALUES (";
3641 $sql_insert .= $pieceNumNext;
3642 $sql_insert .=
", '" . $this->db->escape($obj->label_operation) .
"'";
3643 $sql_insert .=
", '" . $this->db->escape($obj->numero_compte) .
"'";
3644 $sql_insert .=
", '" . $this->db->escape($obj->label_compte) .
"'";
3645 $sql_insert .=
", '" . $this->db->escape($obj->subledger_account) .
"'";
3646 $sql_insert .=
", '" . $this->db->escape($obj->subledger_label) .
"'";
3647 $sql_insert .=
", ''";
3648 $sql_insert .=
", '" . $this->db->escape($code_journal) .
"'";
3649 $sql_insert .=
", '" . $this->db->idate($docdate).
"'";
3650 $sql_insert .=
", '" . $this->db->idate($now).
"'";
3651 $sql_insert .=
", ".($user->id > 0 ? ((int) $user->id) :
"NULL");
3652 $sql_insert .=
", '" . $this->db->escape($docRef) .
"'";
3653 $sql_insert .=
", 0";
3654 $sql_insert .=
", 0";
3655 $sql_insert .=
", " . (float) $obj->debit;
3656 $sql_insert .=
", " . (float) $obj->credit;
3657 $sql_insert .=
", '" . $this->db->escape($journal_label) .
"'";
3658 $sql_insert .=
", '" . $this->db->escape($obj->sens) .
"'";
3659 $sql_insert .=
", " . (float) $obj->montant;
3662 $resqlInsert = $this->db->query($sql_insert);
3665 setEventMessages($langs->trans(
'CloningSuccess', $pieceNumNext),
null,
'mesgs');
3679 $this->db->rollback();
3682 $this->db->commit();
3698 global $langs, $user;
3703 if (empty($docdate)) {
3708 $accountingJournal->fetch(0, $code_journal);
3711 $sqlAlreadyExtourne =
"SELECT DISTINCT(piece_num) FROM " .MAIN_DB_PREFIX.
"accounting_bookkeeping WHERE label_operation LIKE '%Extourne%'";
3712 $resqlAlreadyExtourne = $this->db->query($sqlAlreadyExtourne);
3713 $alreadyExtourneT = array();
3714 if ($resqlAlreadyExtourne) {
3715 while ($obj4 = $this->db->fetch_object($resqlAlreadyExtourne)) {
3716 $alreadyExtourneT []= $obj4->piece_num;
3720 $idImplode = implode(
',', $toselect);
3721 $sql1 =
"SELECT DISTINCT(piece_num) from " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE rowid IN (".$this->db->sanitize($idImplode).
")";
3722 $resql1 = $this->db->query($sql1);
3726 while ($obj1 = $this->db->fetch_object($resql1)) {
3727 $pieceNumT [] = $obj1->piece_num;
3730 $i = mt_rand(0, 100);
3731 foreach ($pieceNumT as $pieceNum) {
3732 $newBookKeepingInstance =
new BookKeeping($this->db);
3733 $pieceNumNext = $newBookKeepingInstance->getNextNumMvt();
3735 $sql2 =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE piece_num = ".((int) $pieceNum);
3736 $resql2 = $this->db->query($sql2);
3739 while ($obj2 = $this->db->fetch_object($resql2)) {
3740 $extourneIds [] = $obj2->rowid;
3743 foreach ($extourneIds as $extourneId) {
3747 if ($bookKeeping->fetch($extourneId)) {
3748 if (in_array($bookKeeping->piece_num, $alreadyExtourneT)) {
3749 setEventMessages($langs->trans(
"AlreadyReturnedAccount", $bookKeeping->piece_num),
null,
'errors');
3751 $newBookKeeping->debit = $bookKeeping->credit;
3752 $newBookKeeping->credit = $bookKeeping->debit;
3753 if ($bookKeeping->sens ==
'D') {
3754 $newBookKeeping->sens =
'C';
3756 $newBookKeeping->sens =
'D';
3759 $newBookKeeping->label_operation = $langs->trans(
"ReturnAccount") .
" " . $bookKeeping->piece_num .
" - " . $bookKeeping->numero_compte .
" - " . date(
'd/m/Y',
dol_now()) .
" - " . $i;
3761 $newBookKeeping->numero_compte = $bookKeeping->numero_compte;
3762 $newBookKeeping->label_compte = $bookKeeping->label_compte;
3763 $newBookKeeping->doc_type = $bookKeeping->doc_type;
3764 $newBookKeeping->code_journal = $bookKeeping->code_journal;
3765 $newBookKeeping->doc_date = $docdate;
3766 $newBookKeeping->fk_user_author = $user->id;
3767 $newBookKeeping->doc_ref = $bookKeeping->doc_ref;
3768 $newBookKeeping->montant = $bookKeeping->montant;
3769 $newBookKeeping->journal_label = $bookKeeping->journal_label;
3770 $newBookKeeping->subledger_account = $bookKeeping->subledger_account;
3771 $newBookKeeping->subledger_label = $bookKeeping->subledger_label;
3773 $createResult = $newBookKeeping->create($user);
3775 if ($createResult >= 0) {
3776 $newBookKeeping->piece_num = $pieceNumNext;
3777 $newBookKeeping->fk_doc = $bookKeeping->fk_doc;
3778 $newBookKeeping->fk_docdet = $bookKeeping->fk_docdet;
3779 $newBookKeeping->update($user);
3780 setEventMessages($langs->trans(
"SuccessReturnedAccount", $bookKeeping->piece_num),
null,
'mesgs');
3782 setEventMessages($langs->trans(
"ErrorWhileCreating", $newBookKeeping->error), $newBookKeeping->errors,
'errors');
3794 $this->db->rollback();
3797 $this->db->commit();
3816 public $doc_date =
null;
3840 public $thirdparty_code;
3845 public $subledger_account;
3850 public $subledger_label;
3855 public $numero_compte;
3860 public $label_compte;
3865 public $label_operation;
3891 public $multicurrency_amount;
3896 public $multicurrency_code;
3906 public $lettering_code;
3911 public $date_lettering;
3916 public $fk_user_author;
3927 public $code_journal;
3932 public $journal_label;
3941 public $date_export;
3946 public $date_lim_reglement;
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Class to manage accounting accounts.
Class to manage accounting journals.
Class to manage Ledger (General Ledger and Subledger)
closeFiscalPeriod($fiscal_period_id, $new_fiscal_period_id, $separate_auxiliary_account=false, $generate_bookkeeping_records=true)
Close fiscal period.
getCountByMonthForFiscalPeriod($date_start, $date_end)
Get list of count by month into the fiscal period.
fetchAllBalance($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND', $option=0)
Load object in memory from the database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
select_account($selectid, $htmlname='account', $showempty=0, $event=array(), $select_in=0, $select_out=0, $aabase='')
Return list of accounts with label by chart of accounts.
getFiscalPeriods()
Get list of fiscal period ordered by start date.
getNextNumMvt($mode='')
Return next bookkeeping piece number.
newCloneMass($toselect, $code_journal, $docdate)
Mass clone.
get_compte_desc($account=null)
Description of accounting account.
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.
transformTransaction($direction=0, $piece_num='')
Transform transaction.
insertAccountingReversal($fiscal_period_id, $inventory_journal_id, $new_fiscal_period_id, $date_start, $date_end)
Insert accounting reversal into the inventory journal of the new fiscal period.
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.
updateByMvt($piece_num='', $field='', $value='', $mode='')
Update accounting movement.
createStd(User $user, $notrigger=0, $mode='')
Create object into database.
update(User $user, $notrigger=0, $mode='')
Update object into database.
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 of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class to manage fiscal year.
Class to manage Dolibarr users.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
global $dolibarr_main_demo