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';
55 public $lines = array();
70 public $date_lim_reglement;
95 public $thirdparty_code;
100 public $subledger_account;
105 public $subledger_label;
110 public $numero_compte;
115 public $label_compte;
120 public $label_operation;
152 public $fk_user_author;
162 public $code_journal;
167 public $journal_label;
182 public $linesmvt = array();
187 public $linesexport = array();
197 public $picto =
'generic';
202 public static $can_modify_bookkeeping_sql_cached;
207 public $warnings = array();
229 global
$conf, $langs;
236 if (isset($this->doc_type)) {
237 $this->doc_type = trim($this->doc_type);
239 if (isset($this->doc_ref)) {
240 $this->doc_ref = trim($this->doc_ref);
241 $this->doc_ref =
dol_trunc($this->doc_ref, 300);
243 if (isset($this->fk_doc)) {
244 $this->fk_doc = (int) $this->fk_doc;
246 if (isset($this->fk_docdet)) {
247 $this->fk_docdet = (int) $this->fk_docdet;
249 if (isset($this->thirdparty_code)) {
250 $this->thirdparty_code = trim($this->thirdparty_code);
252 if (isset($this->subledger_account)) {
253 $this->subledger_account = trim($this->subledger_account);
255 if (isset($this->subledger_label)) {
256 $this->subledger_label = trim($this->subledger_label);
258 if (isset($this->numero_compte)) {
259 $this->numero_compte = trim($this->numero_compte);
261 if (isset($this->label_compte)) {
262 $this->label_compte = trim($this->label_compte);
264 if (isset($this->label_operation)) {
265 $this->label_operation = trim($this->label_operation);
267 if (isset($this->debit)) {
268 $this->debit = (float) $this->debit;
270 if (isset($this->credit)) {
271 $this->credit = (float) $this->credit;
273 if (isset($this->montant)) {
274 $this->montant = (float) $this->montant;
276 if (isset($this->
amount)) {
279 if (isset($this->sens)) {
280 $this->sens = trim($this->sens);
282 if (isset($this->import_key)) {
283 $this->import_key = trim($this->import_key);
285 if (isset($this->code_journal)) {
286 $this->code_journal = trim($this->code_journal);
288 if (isset($this->journal_label)) {
289 $this->journal_label = trim($this->journal_label);
291 if (isset($this->piece_num)) {
292 $this->piece_num = (int) $this->piece_num;
294 if (empty($this->debit)) {
297 if (empty($this->credit)) {
304 } elseif ($result == 0) {
306 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
308 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
314 if (($this->numero_compte ==
"") || $this->numero_compte ==
'-1' || $this->numero_compte ==
'NotDefined') {
315 $langs->loadLangs(array(
"errors"));
316 if (in_array($this->doc_type, array(
'bank',
'expense_report'))) {
317 $this->errors[] = $langs->trans(
'ErrorFieldAccountNotDefinedForBankLine', $this->fk_docdet, $this->doc_type);
320 $mesg = $this->doc_ref.
', '.$langs->trans(
"AccountAccounting").
': '.($this->numero_compte != -1 ? $this->numero_compte : $langs->trans(
"Unknown"));
321 if ($this->subledger_account && $this->subledger_account != $this->numero_compte) {
322 $mesg .=
', '.$langs->trans(
"SubledgerAccount").
': '.$this->subledger_account;
324 $this->errors[] = $langs->trans(
'ErrorFieldAccountNotDefinedForLine', $mesg);
332 $this->piece_num = 0;
340 $sql =
"SELECT count(*) as nb";
341 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
342 $sql .=
" WHERE doc_type = '".$this->db->escape($this->doc_type).
"'";
343 $sql .=
" AND fk_doc = ".((int) $this->fk_doc);
346 $sql .=
" AND fk_docdet = ".((int) $this->fk_docdet);
348 $sql .=
" AND numero_compte = '".$this->db->escape($this->numero_compte).
"'";
349 $sql .=
" AND label_operation = '".$this->db->escape($this->label_operation).
"'";
350 if (!empty($this->subledger_account)) {
351 $sql .=
" AND subledger_account = '".$this->db->escape($this->subledger_account).
"'";
353 $sql .=
" AND entity = ".$conf->entity;
359 if (($accountProfit && $this->numero_compte === trim($accountProfit)) ||
360 ($accountLoss && $this->numero_compte === trim($accountLoss))) {
362 $sql .=
" AND 1 = 2";
365 $resql = $this->db->query($sql);
368 $row = $this->db->fetch_object($resql);
371 $sqlnum =
"SELECT piece_num, ref";
372 $sqlnum .=
" FROM ".$this->db->prefix().$this->table_element;
373 $sqlnum .=
" WHERE doc_type = '".$this->db->escape($this->doc_type).
"'";
374 $sqlnum .=
" AND fk_doc = ".((int) $this->fk_doc);
377 $sqlnum .=
" AND fk_docdet = ".((int) $this->fk_docdet);
379 $sqlnum .=
" AND doc_ref = '".$this->db->escape($this->doc_ref).
"'";
380 $sqlnum .=
" AND entity = ".$conf->entity;
382 dol_syslog(get_class($this).
":: create sqlnum=".$sqlnum, LOG_DEBUG);
383 $resqlnum = $this->db->query($sqlnum);
385 $num = $this->db->num_rows($resqlnum);
387 $objnum = $this->db->fetch_object($resqlnum);
388 $this->piece_num = $objnum->piece_num;
389 $this->
ref = $objnum->ref;
391 $this->piece_num = 0;
396 dol_syslog(get_class($this).
"::create this->piece_num=".$this->piece_num, LOG_DEBUG);
397 if (empty($this->piece_num)) {
398 $sqlnum =
"SELECT MAX(piece_num)+1 as maxpiecenum";
399 $sqlnum .=
" FROM ".$this->db->prefix().$this->table_element;
400 $sqlnum .=
" WHERE entity = " . ((int)
$conf->entity);
402 $resqlnum = $this->db->query($sqlnum);
404 $objnum = $this->db->fetch_object($resqlnum);
405 $this->piece_num = $objnum->maxpiecenum;
408 $this->
ref = $this->getNextNumRef();
409 dol_syslog(get_class($this).
":: create now this->piece_num={$this->piece_num}, this->ref={$this->ref}", LOG_DEBUG);
411 if (empty($this->piece_num)) {
412 $this->piece_num = 1;
417 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
" (";
419 $sql .=
", date_lim_reglement";
420 $sql .=
", doc_type";
423 $sql .=
", fk_docdet";
424 $sql .=
", thirdparty_code";
425 $sql .=
", subledger_account";
426 $sql .=
", subledger_label";
427 $sql .=
", numero_compte";
428 $sql .=
", label_compte";
429 $sql .=
", label_operation";
434 $sql .=
", fk_user_author";
435 $sql .=
", date_creation";
436 $sql .=
", code_journal";
437 $sql .=
", journal_label";
438 $sql .=
", piece_num";
441 $sql .=
") VALUES (";
442 $sql .=
"'".$this->db->idate($this->doc_date).
"'";
443 $sql .=
", ".(isDolTms($this->date_lim_reglement) ?
"'".$this->db->idate($this->date_lim_reglement).
"'" :
'NULL');
444 $sql .=
", '".$this->db->escape($this->doc_type).
"'";
445 $sql .=
", '".$this->db->escape($this->doc_ref).
"'";
446 $sql .=
", ".((int) $this->fk_doc);
447 $sql .=
", ".((int) $this->fk_docdet);
448 $sql .=
", ".(!empty($this->thirdparty_code) ? (
"'".$this->db->escape($this->thirdparty_code).
"'") :
"NULL");
449 $sql .=
", ".(!empty($this->subledger_account) ? (
"'".$this->db->escape($this->subledger_account).
"'") :
"NULL");
450 $sql .=
", ".(!empty($this->subledger_label) ? (
"'".$this->db->escape($this->subledger_label).
"'") :
"NULL");
451 $sql .=
", '".$this->db->escape($this->numero_compte).
"'";
452 $sql .=
", ".(!empty($this->label_compte) ? (
"'".$this->db->escape($this->label_compte).
"'") :
"NULL");
453 $sql .=
", '".$this->db->escape($this->label_operation).
"'";
454 $sql .=
", ".((float) $this->debit);
455 $sql .=
", ".((float) $this->credit);
456 $sql .=
", ".((float) $this->montant);
457 $sql .=
", ".(!empty($this->sens) ? (
"'".$this->db->escape($this->sens).
"'") :
"NULL");
458 $sql .=
", '".$this->db->escape((
string) $this->fk_user_author).
"'";
459 $sql .=
", '".$this->db->idate($now).
"'";
460 $sql .=
", '".$this->db->escape($this->code_journal).
"'";
461 $sql .=
", ".(!empty($this->journal_label) ? (
"'".$this->db->escape($this->journal_label).
"'") :
"NULL");
462 $sql .=
", ".((int) $this->piece_num);
463 $sql .=
", '".$this->db->escape($this->
ref).
"'";
464 $sql .=
", ".(!isset($this->entity) ?
$conf->entity : $this->entity);
467 $resql = $this->db->query($sql);
469 $id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
477 $this->errors[] =
'Error Create Error '.$result.
' lecture ID';
478 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
483 $this->errors[] =
'Error '.$this->db->lasterror();
484 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
489 $this->error =
'BookkeepingRecordAlreadyExists';
490 $this->errors[] = $langs->trans(
'WarningBookkeepingRecordAlreadyExists', $this->doc_type, $this->fk_doc, $this->fk_docdet);
492 dol_syslog(get_class($this).
":: create duplicate record detected: doc_type={$this->doc_type}, doc_ref={$this->doc_ref}, fk_doc={((int) $this->fk_doc)}, fk_docdet={((int) $this->fk_docdet)}", LOG_WARNING);
497 $this->errors[] =
'Error '.$this->db->lasterror();
498 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
502 if (! $error && ! $notrigger) {
503 $result = $this->call_trigger(
'BOOKKEEPING_CREATE', $user);
511 $this->db->rollback();
536 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)
538 global
$conf, $langs, $user;
542 if (!empty($amount)) {
543 $this->doc_date = $doc_date;
544 $this->doc_ref = $doc_ref;
545 $this->doc_type = $doc_type;
546 $this->fk_doc = $fk_doc;
547 $this->fk_docdet = $fk_docdet;
549 $this->numero_compte = $numero_compte;
550 $this->label_compte = $label_compte;
552 $this->label_operation = $label_operation;
553 $this->subledger_account = $subledger_account;
555 $this->montant = $amount;
556 $this->sens = ($amount >= 0) ?
'D' :
'C';
557 $this->debit = ($amount >= 0 ? $amount : 0);
558 $this->credit = ($amount < 0 ? -$amount : 0);
560 $this->code_journal = $code_journal;
561 $this->journal_label = $journal_label;
563 $this->fk_user_author = $user->id;
564 $this->entity =
$conf->entity;
566 $result = $this->
create($user);
568 if ($this->error ==
'BookkeepingRecordAlreadyExists') {
569 $warning = $langs->trans(
'WarningBookkeepingRecordAlreadyExists', $this->doc_type, $this->fk_doc, $this->fk_docdet);
570 $this->warnings[] = $warning;
571 dol_syslog(__METHOD__.
' '.$warning, LOG_WARNING);
573 dol_syslog(__METHOD__.
' '.$this->errorsToString(), LOG_ERR);
591 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
593 global $db,
$conf, $langs;
594 global $dolibarr_main_authentication, $dolibarr_main_demo;
595 global $menumanager, $hookmanager;
597 if (!empty(
$conf->dol_no_mouse_hover)) {
604 $label =
'<u>'.$langs->trans(
"Transaction").
'</u>';
606 $label .=
'<b>'.$langs->trans(
'NumberingShort').
':</b> '.$this->piece_num;
608 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
610 $baseurl = DOL_URL_ROOT.
'/accountancy/bookkeeping/card.php';
611 $query = [
'piece_num' => $this->piece_num];
613 if ($option !=
'nolink') {
615 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
616 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
617 $add_save_lastsearch_values = 1;
619 if ($add_save_lastsearch_values) {
620 $query += [
'save_lastsearch_values' => 1];
626 if (empty($notooltip)) {
628 $label = $langs->trans(
"ShowTransaction");
629 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
631 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
632 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
634 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
637 $linkstart =
'<a href="'.$url.
'"';
638 $linkstart .= $linkclose.
'>';
641 $result .= $linkstart;
643 $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);
645 if ($withpicto != 2) {
646 $result .= $this->piece_num;
652 $hookmanager->initHooks(array($this->element .
'dao'));
653 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
654 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
656 $result = $hookmanager->resPrint;
658 $result .= $hookmanager->resPrint;
673 global
$conf, $langs;
675 $langs->loadLangs(array(
"accountancy",
"bills",
"compta"));
682 if (isset($this->doc_type)) {
683 $this->doc_type = trim($this->doc_type);
685 if (isset($this->doc_ref)) {
686 $this->doc_ref = trim($this->doc_ref);
688 if (isset($this->fk_doc)) {
689 $this->fk_doc = (int) $this->fk_doc;
691 if (isset($this->fk_docdet)) {
692 $this->fk_docdet = (int) $this->fk_docdet;
694 if (isset($this->thirdparty_code)) {
695 $this->thirdparty_code = trim($this->thirdparty_code);
697 if (isset($this->subledger_account)) {
698 $this->subledger_account = trim($this->subledger_account);
700 if (isset($this->subledger_label)) {
701 $this->subledger_label = trim($this->subledger_label);
703 if (isset($this->numero_compte)) {
704 $this->numero_compte = trim($this->numero_compte);
706 if (isset($this->label_compte)) {
707 $this->label_compte = trim($this->label_compte);
709 if (isset($this->label_operation)) {
710 $this->label_operation = trim($this->label_operation);
712 if (isset($this->sens)) {
713 $this->sens = trim($this->sens);
715 if (isset($this->import_key)) {
716 $this->import_key = trim($this->import_key);
718 if (isset($this->code_journal)) {
719 $this->code_journal = trim($this->code_journal);
721 if (isset($this->journal_label)) {
722 $this->journal_label = trim($this->journal_label);
724 if (isset($this->piece_num)) {
725 $this->piece_num = (int) $this->piece_num;
727 if (empty($this->debit)) {
730 if (empty($this->credit)) {
733 if (empty($this->montant)) {
740 } elseif ($result == 0) {
742 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
744 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
749 $this->debit = (float)
price2num($this->debit,
'MT');
750 $this->credit = (float)
price2num($this->credit,
'MT');
751 $this->montant = (float)
price2num($this->montant,
'MT');
756 $this->journal_label = $langs->trans($this->journal_label);
759 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.$mode.
' (';
761 $sql .=
'date_lim_reglement,';
765 $sql .=
'fk_docdet,';
766 $sql .=
'thirdparty_code,';
767 $sql .=
'subledger_account,';
768 $sql .=
'subledger_label,';
769 $sql .=
'numero_compte,';
770 $sql .=
'label_compte,';
771 $sql .=
'label_operation,';
776 $sql .=
'fk_user_author,';
777 $sql .=
'date_creation,';
778 $sql .=
'code_journal,';
779 $sql .=
'journal_label,';
780 $sql .=
'piece_num,';
783 $sql .=
') VALUES (';
784 $sql .=
' '.(isDolTms($this->doc_date) ?
"'".$this->db->idate($this->doc_date).
"'" :
'NULL').
',';
785 $sql .=
' '.(isDolTms($this->date_lim_reglement) ?
"'".$this->db->idate($this->date_lim_reglement).
"'" :
'NULL').
',';
786 $sql .=
' '.(!isset($this->doc_type) ?
'NULL' :
"'".$this->db->escape($this->doc_type).
"'").
',';
787 $sql .=
' '.(!isset($this->doc_ref) ?
'NULL' :
"'".$this->db->escape($this->doc_ref).
"'").
',';
788 $sql .=
' '.(empty($this->fk_doc) ?
'0' : (int) $this->fk_doc).
',';
789 $sql .=
' '.(empty($this->fk_docdet) ?
'0' : (int) $this->fk_docdet).
',';
790 $sql .=
' '.(!isset($this->thirdparty_code) ?
'NULL' :
"'".$this->db->escape($this->thirdparty_code).
"'").
',';
791 $sql .=
' '.(!isset($this->subledger_account) ?
'NULL' :
"'".$this->db->escape($this->subledger_account).
"'").
',';
792 $sql .=
' '.(!isset($this->subledger_label) ?
'NULL' :
"'".$this->db->escape($this->subledger_label).
"'").
',';
793 $sql .=
' '.(!isset($this->numero_compte) ?
'NULL' :
"'".$this->db->escape($this->numero_compte).
"'").
',';
794 $sql .=
' '.(!isset($this->label_compte) ?
'NULL' :
"'".$this->db->escape($this->label_compte).
"'").
',';
795 $sql .=
' '.(!isset($this->label_operation) ?
'NULL' :
"'".$this->db->escape($this->label_operation).
"'").
',';
796 $sql .=
' '.(!isset($this->debit) ?
'NULL' : $this->debit).
',';
797 $sql .=
' '.(!isset($this->credit) ?
'NULL' : $this->credit).
',';
798 $sql .=
' '.(!isset($this->montant) ?
'NULL' : $this->montant).
',';
799 $sql .=
' '.(!isset($this->sens) ?
'NULL' :
"'".$this->db->escape($this->sens).
"'").
',';
800 $sql .=
' '.((int) $user->id).
',';
801 $sql .=
' '.
"'".$this->db->idate($now).
"',";
802 $sql .=
' '.(empty($this->code_journal) ?
'NULL' :
"'".$this->db->escape($this->code_journal).
"'").
',';
803 $sql .=
' '.(empty($this->journal_label) ?
'NULL' :
"'".$this->db->escape($this->journal_label).
"'").
',';
804 $sql .=
' '.(empty($this->piece_num) ?
'NULL' : $this->db->escape((
string) $this->piece_num)).
',';
805 $sql .=
' '.(empty($this->
ref) ?
"''" :
"'".$this->db->escape($this->
ref).
"'").
',';
806 $sql .=
' '.(!isset($this->entity) ?
$conf->entity : $this->entity);
811 $resql = $this->db->query($sql);
814 $this->errors[] =
'Error '.$this->db->lasterror();
815 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
819 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element.$mode);
822 $result = $this->call_trigger(
'BOOKKEEPING_CREATE', $user);
831 $this->db->rollback();
849 public function fetch($id, $ref =
null, $mode =
'')
857 $sql .=
" t.doc_date,";
858 $sql .=
" t.date_lim_reglement,";
859 $sql .=
" t.doc_type,";
860 $sql .=
" t.doc_ref,";
861 $sql .=
" t.fk_doc,";
862 $sql .=
" t.fk_docdet,";
863 $sql .=
" t.thirdparty_code,";
864 $sql .=
" t.subledger_account,";
865 $sql .=
" t.subledger_label,";
866 $sql .=
" t.numero_compte,";
867 $sql .=
" t.label_compte,";
868 $sql .=
" t.label_operation,";
870 $sql .=
" t.credit,";
871 $sql .=
" t.montant as amount,";
873 $sql .=
" t.fk_user_author,";
874 $sql .=
" t.import_key,";
875 $sql .=
" t.code_journal,";
876 $sql .=
" t.journal_label,";
877 $sql .=
" t.piece_num,";
879 $sql .=
" t.date_creation,";
882 $sql .=
" t.date_export,";
884 $sql .=
" t.date_validated as date_validation";
885 $sql .=
' FROM '.$this->db->prefix().$this->table_element.$mode.
' as t';
886 $sql .=
' WHERE 1 = 1';
887 $sql .=
" AND entity = " . ((int)
$conf->entity);
889 $sql .=
" AND t.rowid = ".((int) $ref);
891 $sql .=
" AND t.rowid = ".((int) $id);
894 $resql = $this->db->query($sql);
896 $numrows = $this->db->num_rows($resql);
898 $obj = $this->db->fetch_object($resql);
900 $this->
id = $obj->rowid;
902 $this->doc_date = $this->db->jdate($obj->doc_date);
903 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
904 $this->doc_type = $obj->doc_type;
905 $this->doc_ref = $obj->doc_ref;
906 $this->fk_doc = $obj->fk_doc;
907 $this->fk_docdet = $obj->fk_docdet;
908 $this->thirdparty_code = $obj->thirdparty_code;
909 $this->subledger_account = $obj->subledger_account;
910 $this->subledger_label = $obj->subledger_label;
911 $this->numero_compte = $obj->numero_compte;
912 $this->label_compte = $obj->label_compte;
913 $this->label_operation = $obj->label_operation;
914 $this->debit = $obj->debit;
915 $this->credit = $obj->credit;
916 $this->montant = $obj->amount;
917 $this->
amount = $obj->amount;
918 $this->sens = $obj->sens;
919 $this->fk_user_author = $obj->fk_user_author;
920 $this->import_key = $obj->import_key;
921 $this->code_journal = $obj->code_journal;
922 $this->journal_label = $obj->journal_label;
923 $this->piece_num = $obj->piece_num;
924 $this->date_creation = $this->db->jdate($obj->date_creation);
926 $this->date_export = $this->db->jdate($obj->date_export);
928 $this->
ref = $obj->ref;
929 $this->date_validation = isset($obj->date_validation) ? $this->db->jdate($obj->date_validation) :
'';
931 $this->db->free($resql);
939 $this->errors[] =
'Error '.$this->db->lasterror();
940 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
960 public function fetchAllByAccount($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND', $option = 0, $countonly = 0)
966 $this->lines = array();
971 $sql .=
' COUNT(t.rowid) as nb';
974 $sql .=
" t.doc_date,";
975 $sql .=
" t.doc_type,";
976 $sql .=
" t.doc_ref,";
977 $sql .=
" t.fk_doc,";
978 $sql .=
" t.fk_docdet,";
979 $sql .=
" t.thirdparty_code,";
980 $sql .=
" t.subledger_account,";
981 $sql .=
" t.subledger_label,";
982 $sql .=
" t.numero_compte,";
983 $sql .=
" t.label_compte,";
984 $sql .=
" t.label_operation,";
986 $sql .=
" t.credit,";
987 $sql .=
" t.montant as amount,";
989 $sql .=
" t.multicurrency_amount,";
990 $sql .=
" t.multicurrency_code,";
991 $sql .=
" t.matching_general,";
992 $sql .=
" t.lettering_code,";
993 $sql .=
" t.date_lettering,";
994 $sql .=
" t.fk_user_author,";
995 $sql .=
" t.import_key,";
996 $sql .=
" t.code_journal,";
997 $sql .=
" t.journal_label,";
998 $sql .=
" t.piece_num,";
1000 $sql .=
" t.date_creation,";
1001 $sql .=
" t.date_export,";
1002 $sql .=
" t.date_validated as date_validation,";
1003 $sql .=
" t.date_lim_reglement,";
1004 $sql .=
" t.import_key";
1007 $sqlwhere = array();
1008 if (count($filter) > 0) {
1009 foreach ($filter as $key => $value) {
1010 if ($key ==
't.doc_date>=') {
1011 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate((
int) $value).
"'";
1012 } elseif ($key ==
't.doc_date<=') {
1013 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate((
int) $value).
"'";
1014 } elseif ($key ==
't.doc_date>') {
1015 $sqlwhere[] =
"t.doc_date > '".$this->db->idate((
int) $value).
"'";
1016 } elseif ($key ==
't.doc_date<') {
1017 $sqlwhere[] =
"t.doc_date < '".$this->db->idate((
int) $value).
"'";
1018 } elseif ($key ==
't.numero_compte>=') {
1019 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1020 } elseif ($key ==
't.numero_compte<=') {
1021 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1022 } elseif ($key ==
't.subledger_account>=') {
1023 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1024 } elseif ($key ==
't.subledger_account<=') {
1025 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1026 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1027 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
1028 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1029 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($this->db->escapeforlike($value)).
"%'";
1030 } elseif ($key ==
't.date_creation>=') {
1031 $sqlwhere[] =
"t.date_creation >= '".$this->db->idate((
int) $value).
"'";
1032 } elseif ($key ==
't.date_creation<=') {
1033 $sqlwhere[] =
"t.date_creation <= '".$this->db->idate((
int) $value).
"'";
1034 } elseif ($key ==
't.date_export>=') {
1035 $sqlwhere[] =
"t.date_export >= '".$this->db->idate((
int) $value).
"'";
1036 } elseif ($key ==
't.date_export<=') {
1037 $sqlwhere[] =
"t.date_export <= '".$this->db->idate((
int) $value).
"'";
1038 } elseif ($key ==
't.date_validated>=') {
1039 $sqlwhere[] =
"t.date_validated >= '".$this->db->idate((
int) $value).
"'";
1040 } elseif ($key ==
't.date_validated<=') {
1041 $sqlwhere[] =
"t.date_validated <= '".$this->db->idate((
int) $value).
"'";
1042 } elseif ($key ==
't.date_lim_reglement>=') {
1043 $sqlwhere[] =
"t.date_lim_reglement>='".$this->db->idate((
int) $value).
"'";
1044 } elseif ($key ==
't.date_lim_reglement<=') {
1045 $sqlwhere[] =
"t.date_lim_reglement<='".$this->db->idate((
int) $value).
"'";
1046 } elseif ($key ==
't.credit' || $key ==
't.debit') {
1048 } elseif ($key ==
't.reconciled_option') {
1049 $sqlwhere[] =
't.lettering_code IS NULL';
1050 } elseif ($key ==
't.code_journal' && !empty($value)) {
1051 if (is_array($value)) {
1052 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1056 } elseif ($key ==
't.search_accounting_code_in' && !empty($value)) {
1057 $sqlwhere[] =
"t.numero_compte IN (".$this->db->sanitize($value, 1).
")";
1063 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t';
1064 $sql .=
' WHERE entity = ' . ((int)
$conf->entity);
1065 if (count($sqlwhere) > 0) {
1066 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1069 if (!empty($option)) {
1070 $sql .=
" AND t.subledger_account IS NOT NULL";
1071 $sql .=
" AND t.subledger_account <> ''";
1072 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
1073 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1075 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
1076 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1080 $sql .= $this->db->order($sortfield, $sortorder);
1081 if (!empty($limit)) {
1082 $sql .= $this->db->plimit($limit + 1, $offset);
1086 $resql = $this->db->query($sql);
1089 $obj = $this->db->fetch_object($resql);
1094 $num = $this->db->num_rows($resql);
1097 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1100 $line->id = $obj->rowid;
1102 $line->doc_date = $this->db->jdate($obj->doc_date);
1103 $line->doc_type = $obj->doc_type;
1104 $line->doc_ref = $obj->doc_ref;
1105 $line->fk_doc = $obj->fk_doc;
1106 $line->fk_docdet = $obj->fk_docdet;
1107 $line->thirdparty_code = $obj->thirdparty_code;
1108 $line->subledger_account = $obj->subledger_account;
1109 $line->subledger_label = $obj->subledger_label;
1110 $line->numero_compte = $obj->numero_compte;
1111 $line->label_compte = $obj->label_compte;
1112 $line->label_operation = $obj->label_operation;
1113 $line->debit = $obj->debit;
1114 $line->credit = $obj->credit;
1115 $line->montant = $obj->amount;
1116 $line->amount = $obj->amount;
1117 $line->sens = $obj->sens;
1118 $line->multicurrency_amount = $obj->multicurrency_amount;
1119 $line->multicurrency_code = $obj->multicurrency_code;
1120 $line->matching_general = (bool) $obj->matching_general;
1121 $line->lettering_code = $obj->lettering_code;
1122 $line->date_lettering = $this->db->jdate($obj->date_lettering);
1123 $line->fk_user_author = $obj->fk_user_author;
1124 $line->import_key = $obj->import_key;
1125 $line->code_journal = $obj->code_journal;
1126 $line->journal_label = $obj->journal_label;
1127 $line->piece_num = $obj->piece_num;
1128 $line->ref = $obj->ref;
1129 $line->date_creation = $this->db->jdate($obj->date_creation);
1130 $line->date_export = $this->db->jdate($obj->date_export);
1131 $line->date_validation = $this->db->jdate($obj->date_validation);
1133 $line->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1134 $line->import_key = $obj->import_key;
1136 $this->lines[] = $line;
1141 $this->db->free($resql);
1145 $this->errors[] =
'Error '.$this->db->lasterror();
1146 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1164 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $showAlreadyExportMovements = 1)
1171 $sql .=
' t.rowid,';
1172 $sql .=
" t.doc_date,";
1173 $sql .=
" t.doc_type,";
1174 $sql .=
" t.doc_ref,";
1175 $sql .=
" t.fk_doc,";
1176 $sql .=
" t.fk_docdet,";
1177 $sql .=
" t.thirdparty_code,";
1178 $sql .=
" t.subledger_account,";
1179 $sql .=
" t.subledger_label,";
1180 $sql .=
" t.numero_compte,";
1181 $sql .=
" t.label_compte,";
1182 $sql .=
" t.label_operation,";
1183 $sql .=
" t.debit,";
1184 $sql .=
" t.credit,";
1185 $sql .=
" t.lettering_code,";
1186 $sql .=
" t.date_lettering,";
1187 $sql .=
" t.montant as amount,";
1189 $sql .=
" t.fk_user_author,";
1190 $sql .=
" t.import_key,";
1191 $sql .=
" t.code_journal,";
1192 $sql .=
" t.journal_label,";
1193 $sql .=
" t.piece_num,";
1194 $sql .=
" t.date_creation,";
1195 $sql .=
" t.date_lim_reglement,";
1196 $sql .=
" t.tms as date_modification,";
1197 $sql .=
" t.date_export,";
1198 $sql .=
" t.date_validated as date_validation";
1199 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t';
1200 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
1201 if ($showAlreadyExportMovements == 0) {
1202 $sql .=
" AND t.date_export IS NULL";
1206 if (is_array($filter)) {
1207 dol_syslog(
"You are using a deprecated use of fetchAll. filter parameter must be an USF string now.", LOG_WARNING);
1208 $sqlwhere = array();
1209 if (count($filter) > 0) {
1210 foreach ($filter as $key => $value) {
1211 if ($key ==
't.doc_date') {
1212 $sqlwhere[] = $this->db->sanitize($key).
" = '".$this->db->idate((
int) $value).
"'";
1213 } elseif ($key ==
't.doc_date>=') {
1214 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate((
int) $value).
"'";
1215 } elseif ($key ==
't.doc_date<=') {
1216 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate((
int) $value).
"'";
1217 } elseif ($key ==
't.doc_date>') {
1218 $sqlwhere[] =
"t.doc_date > '".$this->db->idate((
int) $value).
"'";
1219 } elseif ($key ==
't.doc_date<') {
1220 $sqlwhere[] =
"t.doc_date < '".$this->db->idate((
int) $value).
"'";
1221 } elseif ($key ==
't.numero_compte>=') {
1222 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1223 } elseif ($key ==
't.numero_compte<=') {
1224 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1225 } elseif ($key ==
't.subledger_account>=') {
1226 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1227 } elseif ($key ==
't.subledger_account<=') {
1228 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1229 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1230 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
1231 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1232 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1233 } elseif ($key ==
't.date_creation>=') {
1234 $sqlwhere[] =
"t.date_creation >= '".$this->db->idate((
int) $value).
"'";
1235 } elseif ($key ==
't.date_creation<=') {
1236 $sqlwhere[] =
"t.date_creation <= '".$this->db->idate((
int) $value).
"'";
1237 } elseif ($key ==
't.tms>=') {
1238 $sqlwhere[] =
"t.tms >= '".$this->db->idate((
int) $value).
"'";
1239 } elseif ($key ==
't.tms<=') {
1240 $sqlwhere[] =
"t.tms <= '".$this->db->idate((
int) $value).
"'";
1241 } elseif ($key ==
't.date_export>=') {
1242 $sqlwhere[] =
"t.date_export >= '".$this->db->idate((
int) $value).
"'";
1243 } elseif ($key ==
't.date_export<=') {
1244 $sqlwhere[] =
"t.date_export <= '".$this->db->idate((
int) $value).
"'";
1245 } elseif ($key ==
't.date_validated>=') {
1246 $sqlwhere[] =
"t.date_validated >= '".$this->db->idate((
int) $value).
"'";
1247 } elseif ($key ==
't.date_validated<=') {
1248 $sqlwhere[] =
"t.date_validated <= '".$this->db->idate((
int) $value).
"'";
1249 } elseif ($key ==
't.credit' || $key ==
't.debit') {
1251 } elseif ($key ==
't.code_journal' && !empty($value)) {
1252 if (is_array($value)) {
1253 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1257 } elseif ($key ==
't.reconciled_option') {
1258 $sqlwhere[] =
't.lettering_code IS NULL';
1264 if (count($sqlwhere) > 0) {
1265 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1273 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
1274 if ($errormessage) {
1275 $this->errors[] = $errormessage;
1276 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1280 if (!empty($sortfield)) {
1281 $sql .= $this->db->order($sortfield, $sortorder);
1283 if (!empty($limit)) {
1284 $sql .= $this->db->plimit($limit + 1, $offset);
1286 $this->lines = array();
1288 $resql = $this->db->query($sql);
1290 $num = $this->db->num_rows($resql);
1293 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1296 $line->id = $obj->rowid;
1298 $line->doc_date = $this->db->jdate($obj->doc_date);
1299 $line->doc_type = $obj->doc_type;
1300 $line->doc_ref = $obj->doc_ref;
1301 $line->fk_doc = $obj->fk_doc;
1302 $line->fk_docdet = $obj->fk_docdet;
1303 $line->thirdparty_code = $obj->thirdparty_code;
1304 $line->subledger_account = $obj->subledger_account;
1305 $line->subledger_label = $obj->subledger_label;
1306 $line->numero_compte = $obj->numero_compte;
1307 $line->label_compte = $obj->label_compte;
1308 $line->label_operation = $obj->label_operation;
1309 $line->debit = $obj->debit;
1310 $line->credit = $obj->credit;
1311 $line->montant = $obj->amount;
1312 $line->amount = $obj->amount;
1313 $line->sens = $obj->sens;
1314 $line->lettering_code = $obj->lettering_code;
1315 $line->date_lettering = $this->db->jdate($obj->date_lettering);
1316 $line->fk_user_author = $obj->fk_user_author;
1317 $line->import_key = $obj->import_key;
1318 $line->code_journal = $obj->code_journal;
1319 $line->journal_label = $obj->journal_label;
1320 $line->piece_num = $obj->piece_num;
1321 $line->date_creation = $this->db->jdate($obj->date_creation);
1322 $line->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1323 $line->date_modification = $this->db->jdate($obj->date_modification);
1324 $line->date_export = $this->db->jdate($obj->date_export);
1325 $line->date_validation = $this->db->jdate($obj->date_validation);
1327 $this->lines[] = $line;
1331 $this->db->free($resql);
1335 $this->errors[] =
'Error '.$this->db->lasterror();
1336 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1353 public function fetchAllBalance($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $option = 0)
1357 $this->lines = array();
1362 $sql .=
" t.numero_compte,";
1363 if (!empty($option)) {
1364 $sql .=
" t.subledger_account,";
1365 $sql .=
" t.subledger_label,";
1367 $sql .=
" SUM(t.debit) as debit,";
1368 $sql .=
" SUM(t.credit) as credit";
1369 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t';
1370 $sql .=
' WHERE entity = ' . ((int)
$conf->entity);
1373 if (is_array($filter)) {
1374 $sqlwhere = array();
1375 if (count($filter) > 0) {
1376 foreach ($filter as $key => $value) {
1377 if ($key ==
't.doc_date') {
1378 $sqlwhere[] = $this->db->sanitize($key).
" = '".$this->db->idate((
int) $value).
"'";
1379 } elseif ($key ==
't.doc_date>=') {
1380 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate((
int) $value).
"'";
1381 } elseif ($key ==
't.doc_date<=') {
1382 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate((
int) $value).
"'";
1383 } elseif ($key ==
't.doc_date>') {
1384 $sqlwhere[] =
"t.doc_date > '".$this->db->idate((
int) $value).
"'";
1385 } elseif ($key ==
't.doc_date<') {
1386 $sqlwhere[] =
"t.doc_date < '".$this->db->idate((
int) $value).
"'";
1387 } elseif ($key ==
't.numero_compte>=') {
1388 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1389 } elseif ($key ==
't.numero_compte<=') {
1390 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1391 } elseif ($key ==
't.subledger_account>=') {
1392 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1393 } elseif ($key ==
't.subledger_account<=') {
1394 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1395 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1396 $sqlwhere[] = $this->db->sanitize($key).
" = ".((int) $value);
1397 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1398 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1399 } elseif ($key ==
't.subledger_label') {
1400 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1401 } elseif ($key ==
't.code_journal' && !empty($value)) {
1402 if (is_array($value)) {
1403 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1407 } elseif ($key ==
't.reconciled_option') {
1408 $sqlwhere[] =
't.lettering_code IS NULL';
1410 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
1414 if (count($sqlwhere) > 0) {
1415 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1423 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
1424 if ($errormessage) {
1425 $this->errors[] = $errormessage;
1426 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1430 if (!empty($option)) {
1431 $sql .=
" AND t.subledger_account IS NOT NULL";
1432 $sql .=
" AND t.subledger_account <> ''";
1433 $sql .=
" GROUP BY t.numero_compte, t.subledger_account, t.subledger_label";
1434 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
1435 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1437 $sql .=
' GROUP BY t.numero_compte';
1438 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
1439 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1442 $sql .= $this->db->order($sortfield, $sortorder);
1444 if (!empty($limit)) {
1445 $sql .= $this->db->plimit($limit + 1, $offset);
1449 $resql = $this->db->query($sql);
1452 $num = $this->db->num_rows($resql);
1455 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1458 $line->numero_compte = $obj->numero_compte;
1460 if (!empty($option)) {
1461 $line->subledger_account = $obj->subledger_account;
1462 $line->subledger_label = $obj->subledger_label;
1464 $line->debit = $obj->debit;
1465 $line->credit = $obj->credit;
1467 $this->lines[] = $line;
1471 $this->db->free($resql);
1475 $this->errors[] =
'Error '.$this->db->lasterror();
1476 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1498 if (isset($this->doc_type)) {
1499 $this->doc_type = trim($this->doc_type);
1501 if (isset($this->doc_ref)) {
1502 $this->doc_ref = trim($this->doc_ref);
1504 if (isset($this->fk_doc)) {
1505 $this->fk_doc = (int) $this->fk_doc;
1507 if (isset($this->fk_docdet)) {
1508 $this->fk_docdet = (int) $this->fk_docdet;
1510 if (isset($this->thirdparty_code)) {
1511 $this->thirdparty_code = trim($this->thirdparty_code);
1513 if (isset($this->subledger_account)) {
1514 $this->subledger_account = trim($this->subledger_account);
1516 if (isset($this->subledger_label)) {
1517 $this->subledger_label = trim($this->subledger_label);
1519 if (isset($this->numero_compte)) {
1520 $this->numero_compte = trim($this->numero_compte);
1522 if (isset($this->label_compte)) {
1523 $this->label_compte = trim($this->label_compte);
1525 if (isset($this->label_operation)) {
1526 $this->label_operation = trim($this->label_operation);
1528 if (isset($this->sens)) {
1529 $this->sens = trim($this->sens);
1531 if (isset($this->import_key)) {
1532 $this->import_key = trim($this->import_key);
1534 if (isset($this->code_journal)) {
1535 $this->code_journal = trim($this->code_journal);
1537 if (isset($this->journal_label)) {
1538 $this->journal_label = trim($this->journal_label);
1540 if (isset($this->piece_num)) {
1541 $this->piece_num = (int) $this->piece_num;
1547 } elseif ($result == 0) {
1549 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1551 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1556 $this->debit = (float)
price2num($this->debit,
'MT');
1557 $this->credit = (float)
price2num($this->credit,
'MT');
1558 $this->montant = (float)
price2num($this->montant,
'MT');
1564 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.$mode.
' SET';
1565 $sql .=
' doc_date = '.(isDolTms($this->doc_date) ?
"'".$this->db->idate($this->doc_date).
"'" :
'null').
',';
1566 $sql .=
' doc_type = '.(isset($this->doc_type) ?
"'".$this->db->escape($this->doc_type).
"'" :
"null").
',';
1567 $sql .=
' doc_ref = '.(isset($this->doc_ref) ?
"'".$this->db->escape($this->doc_ref).
"'" :
"null").
',';
1568 $sql .=
' fk_doc = '.(isset($this->fk_doc) ? $this->fk_doc :
"null").
',';
1569 $sql .=
' fk_docdet = '.(isset($this->fk_docdet) ? $this->fk_docdet :
"null").
',';
1570 $sql .=
' thirdparty_code = '.(isset($this->thirdparty_code) ?
"'".$this->db->escape($this->thirdparty_code).
"'" :
"null").
',';
1571 $sql .=
' subledger_account = '.(isset($this->subledger_account) ?
"'".$this->db->escape($this->subledger_account).
"'" :
"null").
',';
1572 $sql .=
' subledger_label = '.(isset($this->subledger_label) ?
"'".$this->db->escape($this->subledger_label).
"'" :
"null").
',';
1573 $sql .=
' numero_compte = '.(isset($this->numero_compte) ?
"'".$this->db->escape($this->numero_compte).
"'" :
"null").
',';
1574 $sql .=
' label_compte = '.(isset($this->label_compte) ?
"'".$this->db->escape($this->label_compte).
"'" :
"null").
',';
1575 $sql .=
' label_operation = '.(isset($this->label_operation) ?
"'".$this->db->escape($this->label_operation).
"'" :
"null").
',';
1576 $sql .=
' debit = '.(isset($this->debit) ? $this->debit :
"null").
',';
1577 $sql .=
' credit = '.(isset($this->credit) ? $this->credit :
"null").
',';
1578 $sql .=
' montant = '.(isset($this->montant) ? $this->montant :
"null").
',';
1579 $sql .=
' sens = '.(isset($this->sens) ?
"'".$this->db->escape($this->sens).
"'" :
"null").
',';
1580 $sql .=
' fk_user_author = '.(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
',';
1581 $sql .=
' import_key = '.(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
',';
1582 $sql .=
' code_journal = '.(isset($this->code_journal) ?
"'".$this->db->escape($this->code_journal).
"'" :
"null").
',';
1583 $sql .=
' journal_label = '.(isset($this->journal_label) ?
"'".$this->db->escape($this->journal_label).
"'" :
"null").
',';
1584 $sql .=
' piece_num = '.(isset($this->piece_num) ? $this->piece_num :
"null");
1585 $sql .=
' WHERE rowid='.((int) $this->
id);
1589 $resql = $this->db->query($sql);
1592 $this->errors[] =
'Error '.$this->db->lasterror();
1593 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1597 if (! $error && ! $notrigger) {
1598 $result = $this->call_trigger(
'BOOKKEEPING_MODIFY', $user);
1606 $this->db->rollback();
1610 $this->db->commit();
1625 public function updateByMvt($piece_num =
'', $field =
'', $value =
'', $mode =
'')
1631 if (!isset($sql_filter)) {
1637 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.$mode;
1638 $sql .=
" SET ".$this->db->sanitize($field).
" = ".(is_numeric($value) ? ((float) $value) :
"'".$this->db->escape($value).
"'");
1639 $sql .=
" WHERE piece_num = ".((int) $piece_num);
1640 $sql .=
" AND entity = " . ((int)
$conf->entity);
1641 $sql .= $sql_filter;
1643 $resql = $this->db->query($sql);
1647 $this->errors[] =
'Error '.$this->db->lasterror();
1648 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1651 $this->db->rollback();
1655 $this->db->commit();
1669 public function delete(
User $user, $notrigger = 0, $mode =
'')
1678 } elseif ($result == 0) {
1680 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1682 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1693 $result = $this->call_trigger(
'BOOKKEEPING_DELETE', $user);
1700 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.$mode;
1701 $sql .=
' WHERE rowid='.((int) $this->
id);
1703 $resql = $this->db->query($sql);
1706 $this->errors[] =
'Error '.$this->db->lasterror();
1707 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1713 $this->db->rollback();
1717 $this->db->commit();
1735 if (!isset($sql_filter)) {
1741 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1742 $sql .=
" WHERE import_key = '".$this->db->escape($importkey).
"'";
1743 $sql .= $sql_filter;
1745 $resql = $this->db->query($sql);
1748 $this->errors[] =
"Error ".$this->db->lasterror();
1749 dol_syslog(get_class($this).
"::delete Error ".$this->db->lasterror(), LOG_ERR);
1750 $this->db->rollback();
1754 $this->db->commit();
1769 global
$conf, $langs;
1771 if (empty($delyear) && empty($journal)) {
1772 $this->error =
'ErrorOneFieldRequired';
1775 if (!empty($delmonth) && empty($delyear)) {
1776 $this->error =
'YearRequiredIfMonthDefined';
1781 if (!isset($sql_filter)) {
1789 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1790 $sql .=
" WHERE 1 = 1";
1792 if (!empty($journal)) {
1793 $sql .=
" AND code_journal = '".$this->db->escape($journal).
"'";
1795 $sql .=
" AND entity = " . ((int)
$conf->entity);
1797 $sql .=
" AND date_validated IS NULL";
1798 $sql .= $sql_filter;
1802 $resql = $this->db->query($sql);
1805 $this->errors[] =
"Error ".$this->db->lasterror();
1806 foreach ($this->errors as $errmsg) {
1807 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1808 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1810 $this->db->rollback();
1814 $this->db->commit();
1828 global
$conf, $user;
1831 if (!isset($sql_filter)) {
1842 $result = $this->call_trigger(
'BOOKKEEPING_DELETE', $user);
1851 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1852 $sql .=
" WHERE piece_num = ".(int) $piecenum;
1853 $sql .=
" AND date_validated IS NULL";
1854 $sql .=
" AND entity = " . ((int)
$conf->entity);
1855 $sql .= $sql_filter;
1857 $resql = $this->db->query($sql);
1860 $this->errors[] =
"Error ".$this->db->lasterror();
1861 foreach ($this->errors as $errmsg) {
1862 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1863 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1865 $this->db->rollback();
1868 $nbprocessed = $this->db->affected_rows($resql);
1874 $this->db->rollback();
1877 $this->db->commit();
1878 return $nbprocessed;
1907 $object->context[
'createfromclone'] =
'createfromclone';
1908 $result =
$object->create($user);
1913 $this->errors =
$object->errors;
1914 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1917 unset(
$object->context[
'createfromclone']);
1921 $this->db->commit();
1925 $this->db->rollback();
1944 $this->doc_date = $now;
1945 $this->doc_type =
'';
1946 $this->doc_ref =
'';
1948 $this->fk_docdet = 0;
1949 $this->thirdparty_code =
'CU001';
1950 $this->subledger_account =
'41100001';
1951 $this->subledger_label =
'My customer company';
1952 $this->numero_compte =
'411';
1953 $this->label_compte =
'Customer';
1954 $this->label_operation =
'Sales of pea';
1955 $this->debit = 99.9;
1956 $this->credit = 0.0;
1959 $this->fk_user_author = $user->id;
1960 $this->import_key =
'20201027';
1961 $this->code_journal =
'VT';
1962 $this->journal_label =
'Journal de vente';
1963 $this->piece_num = 1234;
1964 $this->date_creation = $now;
1980 $sql =
"SELECT piece_num, ref, doc_date, code_journal, journal_label, doc_ref, doc_type, fk_doc,";
1981 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation, date_lim_reglement, import_key";
1983 if ($mode !=
"_tmp") {
1984 $sql .=
", date_export";
1986 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1987 $sql .=
" WHERE piece_num = ".((int) $piecenum);
1988 $sql .=
" AND entity = " . ((int)
$conf->entity);
1991 $result = $this->db->query($sql);
1993 $obj = $this->db->fetch_object($result);
1995 $this->piece_num = $obj->piece_num;
1996 $this->
ref = $obj->ref;
1997 $this->code_journal = $obj->code_journal;
1998 $this->journal_label = $obj->journal_label;
1999 $this->doc_date = $this->db->jdate($obj->doc_date);
2000 $this->doc_ref = $obj->doc_ref;
2001 $this->doc_type = $obj->doc_type;
2002 $this->fk_doc = $obj->fk_doc;
2003 $this->date_creation = $this->db->jdate($obj->date_creation);
2004 $this->date_modification = $this->db->jdate($obj->date_modification);
2005 if ($mode !=
"_tmp") {
2006 $this->date_export = $this->db->jdate($obj->date_export);
2008 $this->date_validation = $this->db->jdate($obj->date_validation);
2009 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
2010 $this->import_key = $obj->import_key;
2012 $this->error =
"Error ".$this->db->lasterror();
2013 dol_syslog(__METHOD__.$this->error, LOG_ERR);
2030 $sql =
"SELECT MAX(piece_num) + 1 as max FROM ".$this->db->prefix().$this->table_element.$mode;
2031 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2033 dol_syslog(get_class($this).
"::getNextNumMvt", LOG_DEBUG);
2035 $result = $this->db->query($sql);
2038 $obj = $this->db->fetch_object($result);
2040 $result = $obj->max;
2042 if (empty($result)) {
2047 $this->error =
"Error ".$this->db->lasterror();
2048 dol_syslog(get_class($this).
"::getNextNumMvt ".$this->error, LOG_ERR);
2059 public function getNextNumRef()
2061 global $langs,
$conf;
2062 $langs->load(
"accountancy");
2071 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
2072 foreach ($dirmodels as $reldir) {
2076 $mybool = ((bool) @include_once $dir.$file) || $mybool;
2084 $obj =
new $classname();
2086 '@phan-var-force ModeleNumRefBookkeeping $obj';
2088 $numref = $obj->getNextValue($this);
2090 if ($numref !=
"") {
2093 $this->error = $obj->error;
2098 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_BOOKKEEPING_ADDON_NotDefined");
2116 $sql =
"SELECT rowid, doc_date, doc_type,";
2117 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
2118 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
2119 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, journal_label, piece_num,";
2120 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation";
2122 if ($mode !=
"_tmp") {
2123 $sql .=
", date_export";
2125 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
2126 $sql .=
" WHERE piece_num = ".((int) $piecenum);
2127 $sql .=
" AND entity = " . ((int)
$conf->entity);
2130 $result = $this->db->query($sql);
2132 while ($obj = $this->db->fetch_object($result)) {
2135 $line->id = $obj->rowid;
2137 $line->doc_date = $this->db->jdate($obj->doc_date);
2138 $line->doc_type = $obj->doc_type;
2139 $line->doc_ref = $obj->doc_ref;
2140 $line->fk_doc = $obj->fk_doc;
2141 $line->fk_docdet = $obj->fk_docdet;
2142 $line->thirdparty_code = $obj->thirdparty_code;
2143 $line->subledger_account = $obj->subledger_account;
2144 $line->subledger_label = $obj->subledger_label;
2145 $line->numero_compte = $obj->numero_compte;
2146 $line->label_compte = $obj->label_compte;
2147 $line->label_operation = $obj->label_operation;
2148 $line->debit = $obj->debit;
2149 $line->credit = $obj->credit;
2150 $line->montant = $obj->amount;
2151 $line->amount = $obj->amount;
2152 $line->sens = $obj->sens;
2153 $line->code_journal = $obj->code_journal;
2154 $line->journal_label = $obj->journal_label;
2155 $line->piece_num = $obj->piece_num;
2156 $line->date_creation = $obj->date_creation;
2157 $line->date_modification = $obj->date_modification;
2158 if ($mode !=
"_tmp") {
2159 $line->date_export = $obj->date_export;
2161 $line->date_validation = $obj->date_validation;
2163 $this->linesmvt[] = $line;
2166 $this->error =
"Error ".$this->db->lasterror();
2167 dol_syslog(__METHOD__.$this->error, LOG_ERR);
2186 $sql =
"SELECT rowid, doc_date, doc_type,";
2187 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
2188 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
2189 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, piece_num,";
2190 $sql .=
" date_validated as date_validation";
2191 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
2192 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2194 dol_syslog(get_class($this).
"::export_bookkeeping", LOG_DEBUG);
2196 $resql = $this->db->query($sql);
2199 $this->linesexport = array();
2201 $num = $this->db->num_rows($resql);
2202 while ($obj = $this->db->fetch_object($resql)) {
2205 $line->id = $obj->rowid;
2207 $line->doc_date = $this->db->jdate($obj->doc_date);
2208 $line->doc_type = $obj->doc_type;
2209 $line->doc_ref = $obj->doc_ref;
2210 $line->fk_doc = $obj->fk_doc;
2211 $line->fk_docdet = $obj->fk_docdet;
2212 $line->thirdparty_code = $obj->thirdparty_code;
2213 $line->subledger_account = $obj->subledger_account;
2214 $line->subledger_label = $obj->subledger_label;
2215 $line->numero_compte = $obj->numero_compte;
2216 $line->label_compte = $obj->label_compte;
2217 $line->label_operation = $obj->label_operation;
2218 $line->debit = $obj->debit;
2219 $line->credit = $obj->credit;
2220 $line->montant = $obj->amount;
2221 $line->amount = $obj->amount;
2222 $line->sens = $obj->sens;
2223 $line->code_journal = $obj->code_journal;
2224 $line->piece_num = $obj->piece_num;
2225 $line->date_validation = $obj->date_validation;
2227 $this->linesexport[] = $line;
2229 $this->db->free($resql);
2233 $this->error =
"Error ".$this->db->lasterror();
2234 dol_syslog(get_class($this).
"::export_bookkeeping ".$this->error, LOG_ERR);
2254 if (!isset($sql_filter)) {
2260 $tmpBookkeeping =
new self($this->db);
2261 $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}");
2262 $tmpBookkeeping->doc_date = $this->db->jdate($tmpData->doc_date);
2263 $tmpBookkeeping->code_journal = $tmpData->code_journal;
2266 $ref = $tmpData->ref ?: $tmpBookkeeping->getNextNumRef();
2267 if ($direction == 0) {
2271 if ($next_piecenum < 0) {
2276 $this->piece_num = $next_piecenum;
2280 $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";
2281 $resql = $this->db->query($sql);
2284 $this->errors[] =
'Error '.$this->db->lasterror();
2285 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2290 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
' (doc_date, doc_type, ref,';
2291 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2292 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2293 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num, date_creation)';
2294 $sql .=
' SELECT doc_date, doc_type,' .
"'{$ref}',";
2295 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2296 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2297 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.((int) $next_piecenum).
", '".$this->db->idate($now).
"'";
2298 $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);
2299 $sql .= $sql_filter;
2300 $resql = $this->db->query($sql);
2303 $this->errors[] =
'Error '.$this->db->lasterror();
2304 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2309 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2310 $resql = $this->db->query($sql);
2313 $this->errors[] =
'Error '.$this->db->lasterror();
2314 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2317 } elseif ($direction == 1) {
2318 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2319 $resql = $this->db->query($sql);
2322 $this->errors[] =
'Error '.$this->db->lasterror();
2323 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2327 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
'_tmp (doc_date, doc_type, ref,';
2328 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2329 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2330 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)';
2331 $sql .=
' SELECT doc_date, doc_type,' .
"'{$ref}',";
2332 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2333 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2334 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num';
2335 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2336 $sql .= $sql_filter;
2337 $resql = $this->db->query($sql);
2340 $this->errors[] =
'Error '.$this->db->lasterror();
2341 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2346 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int)
$conf->entity);
2347 $sql .= $sql_filter;
2348 $resql = $this->db->query($sql);
2351 $this->errors[] =
'Error '.$this->db->lasterror();
2352 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2357 $this->db->commit();
2360 $this->db->rollback();
2388 public function select_account($selectid, $htmlname =
'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase =
'')
2393 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
2397 $sql =
"SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version";
2398 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as ab";
2399 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as aa ON aa.account_number = ab.numero_compte";
2400 $sql .=
" AND aa.active = 1";
2401 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2402 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2403 $sql .=
" AND ab.entity = " . ((int)
$conf->entity);
2404 $sql .=
" ORDER BY account_number ASC";
2406 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2407 $resql = $this->db->query($sql);
2410 $this->error =
"Error ".$this->db->lasterror();
2411 dol_syslog(get_class($this).
"::select_account ".$this->error, LOG_ERR);
2420 while ($obj = $this->db->fetch_object($resql)) {
2423 $select_value_in = $obj->rowid;
2424 $select_value_out = $obj->rowid;
2426 if ($select_in == 1) {
2427 $select_value_in = $obj->account_number;
2429 if ($select_out == 1) {
2430 $select_value_out = $obj->account_number;
2435 if (($selectid !=
'') && $selectid == $select_value_in) {
2436 $selected = $select_value_out;
2439 $options[$select_value_out] = $label;
2442 $out .=
Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0,
'', 0, 0, 0,
'',
'maxwidth300');
2443 $this->db->free($resql);
2459 $sql =
"SELECT root.rowid, root.account_number, root.label as label,";
2460 $sql .=
" parent.rowid as parent_rowid, parent.account_number as parent_account_number, parent.label as parent_label";
2461 $sql .=
" FROM ".$this->db->prefix().
"accounting_account as aa";
2462 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2463 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2464 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as parent ON aa.account_parent = parent.rowid AND parent.active = 1";
2465 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as root ON parent.account_parent = root.rowid AND root.active = 1";
2466 $sql .=
" WHERE aa.account_number = '".$this->db->escape($account).
"'";
2467 $sql .=
" AND aa.entity = " . ((int)
$conf->entity);
2469 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2470 $resql = $this->db->query($sql);
2473 if ($this->db->num_rows($resql)) {
2474 $obj = $this->db->fetch_object($resql);
2477 $result = array(
'id' => $obj->rowid,
'account_number' => $obj->account_number,
'label' => $obj->label);
2480 $this->error =
"Error ".$this->db->lasterror();
2481 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2500 $sql =
"SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
2501 $sql .=
" FROM ".$this->db->prefix().
"accounting_account as aa ";
2502 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2503 $sql .=
" AND aa.account_number = '".$this->db->escape($account).
"'";
2504 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2505 $sql .=
" AND aa.active = 1";
2506 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
2507 $sql .=
" WHERE aa.entity = " . ((int)
$conf->entity);
2509 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2510 $resql = $this->db->query($sql);
2512 $obj = (object) array(
'label' =>
'');
2513 if ($this->db->num_rows($resql)) {
2514 $obj = $this->db->fetch_object($resql);
2516 if (empty($obj->category)) {
2519 return $obj->label.
' ('.$obj->category.
')';
2522 $this->error =
"Error ".$this->db->lasterror();
2523 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2539 $alias = trim($alias);
2540 $alias = !empty($alias) && strpos($alias,
'.') ===
false ? $alias .
"." : $alias;
2542 if (!isset(self::$can_modify_bookkeeping_sql_cached[$alias]) || $force) {
2548 $sql_list = array();
2549 if (!empty(
$conf->cache[
'active_fiscal_period_cached']) && is_array(
$conf->cache[
'active_fiscal_period_cached'])) {
2551 foreach (
$conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2552 $sql_list[$i] =
"(";
2553 $sql_list[$i] .=
"'".$this->db->idate($fiscal_period[
'date_start']) .
"' <= ".$this->db->sanitize($alias).
"doc_date";
2555 if (!empty($fiscal_period[
'date_end'])) {
2556 $sql_list[$i] .=
" AND ";
2557 $sql_list[$i] .= $this->db->sanitize($alias).
"doc_date <= '" . $this->db->idate((
int) $fiscal_period[
'date_end']).
"'";
2559 $sql_list[$i] .=
")";
2563 $sqlsanitized = implode(
' OR ', $sql_list);
2564 self::$can_modify_bookkeeping_sql_cached[$alias] = empty($sql_list) ?
"" :
" AND (".$sqlsanitized.
")";
2567 return self::$can_modify_bookkeeping_sql_cached[$alias];
2589 $result = $bookkeeping->fetch($id,
null, $mode);
2594 if (!empty(
$conf->cache[
'closed_fiscal_period_cached']) && is_array(
$conf->cache[
'closed_fiscal_period_cached'])) {
2595 foreach (
$conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2596 if ($fiscal_period[
'date_start'] <= $bookkeeping->doc_date && $bookkeeping->doc_date <= $fiscal_period[
'date_end']) {
2610 $result = $bookkeeping->fetch($id,
null, $mode);
2615 if (!empty(
$conf->cache[
'active_fiscal_period_cached']) && is_array(
$conf->cache[
'active_fiscal_period_cached'])) {
2616 foreach (
$conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2618 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'])) {
2642 global $hookmanager;
2643 $accountingLabelOperation =
'';
2646 $truncThirdpartyName = 16;
2649 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2651 $accountingLabelOperation = $thirdpartyname;
2653 if (!empty($reference)) {
2654 $accountingLabelOperation .=
' - '. $reference;
2656 if (!empty($labelaccount)) {
2657 $accountingLabelOperation .=
' - '. $labelaccount;
2659 } elseif (
getDolGlobalInt(
'ACCOUNTING_LABEL_OPERATION_ON_TRANSFER') == 1) {
2660 $truncThirdpartyName = 32;
2663 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2665 $accountingLabelOperation = $thirdpartyname;
2667 if (!empty($reference)) {
2668 $accountingLabelOperation .=
' - '. $reference;
2670 } elseif (
getDolGlobalInt(
'ACCOUNTING_LABEL_OPERATION_ON_TRANSFER') == 2) {
2671 $truncThirdpartyName = 64;
2674 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2676 $accountingLabelOperation = $thirdpartyname;
2682 'thirdpartyname' => $thirdpartyname,
2683 'reference' => $reference,
2684 'labelaccount' => $labelaccount,
2685 'accountingLabelOperation' => $accountingLabelOperation,
2688 if (!isset($hookmanager->resPrint)) {
2689 $hookmanager->resPrint =
'';
2692 $reshook = $hookmanager->executeHooks(
'accountingLabelForOperation', $parameters, $this, $action);
2695 $accountingLabelOperation = $hookmanager->resPrint;
2696 } elseif ($reshook == 0 && !empty($hookmanager->resPrint)) {
2697 $accountingLabelOperation .= $hookmanager->resPrint;
2700 dol_syslog(get_class($this) .
"::accountingLabelForOperation: " . $accountingLabelOperation, LOG_DEBUG);
2701 return $accountingLabelOperation;
2721 if (!empty(
$conf->cache[
'closed_fiscal_period_cached']) && is_array(
$conf->cache[
'closed_fiscal_period_cached'])) {
2722 foreach (
$conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2723 if ($fiscal_period[
'date_start'] <= $date && $date <= $fiscal_period[
'date_end']) {
2736 if (!empty(
$conf->cache[
'active_fiscal_period_cached']) && is_array(
$conf->cache[
'active_fiscal_period_cached'])) {
2737 foreach (
$conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2739 if (!empty($fiscal_period[
'date_start']) && $fiscal_period[
'date_start'] <= $date && (empty($fiscal_period[
'date_end']) || $date <= $fiscal_period[
'date_end'])) {
2760 if ($mode ==
'active') {
2761 if (!isset(
$conf->cache[
'active_fiscal_period_cached']) || $force) {
2762 $sql =
"SELECT date_start, date_end";
2763 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2764 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2765 $sql .=
" AND statut = 0";
2767 $resql = $this->db->query($sql);
2769 $this->errors[] = $this->db->lasterror();
2774 while ($obj = $this->db->fetch_object($resql)) {
2776 $date_end_base = $this->db->jdate($obj->date_end);
2780 'date_end' => $date_end,
2783 $conf->cache[
'active_fiscal_period_cached'] = $list;
2786 if ($mode ==
'closed') {
2787 if (!isset(
$conf->cache[
'closed_fiscal_period_cached']) || $force) {
2788 $sql =
"SELECT date_start, date_end";
2789 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2790 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2791 $sql .=
" AND statut = 1";
2793 $resql = $this->db->query($sql);
2795 $this->errors[] = $this->db->lasterror();
2800 while ($obj = $this->db->fetch_object($resql)) {
2802 $date_end_base = $this->db->jdate($obj->date_end);
2807 'date_end' => $date_end,
2810 $conf->cache[
'closed_fiscal_period_cached'] = $list;
2827 $sql =
"SELECT rowid, label, date_start, date_end, statut";
2828 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2829 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2830 $sql .= $this->db->order(
'date_start',
'ASC');
2832 $resql = $this->db->query($sql);
2834 $this->errors[] = $this->db->lasterror();
2838 while ($obj = $this->db->fetch_object($resql)) {
2839 $list[$obj->rowid] = array(
2840 'id' => (
int) $obj->rowid,
2841 'label' => $obj->label,
2842 'date_start' => $this->db->jdate($obj->date_start),
2843 'date_end' => $this->db->jdate($obj->date_end),
2844 'status' => (
int) $obj->statut,
2866 $sql =
"SELECT YEAR(b.doc_date) as year";
2867 for ($i = 1; $i <= 12; $i++) {
2868 $sql .=
", SUM(".$this->db->ifsql(
"MONTH(b.doc_date) = ".((
int) $i),
"1",
"0") .
") AS month".((int) $i);
2870 $sql .=
", COUNT(b.rowid) as total";
2871 $sql .=
" FROM " . $this->db->prefix() . $this->table_element .
" as b";
2872 $sql .=
" WHERE b.doc_date >= '" . $this->db->idate(
$date_start) .
"'";
2873 $sql .=
" AND b.doc_date <= '" . $this->db->idate($date_end) .
"'";
2874 $sql .=
" AND b.entity IN (" .
getEntity(
'bookkeeping', 0) .
")";
2879 $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)";
2882 $sql .=
" AND date_validated IS NULL";
2885 $sql .=
" GROUP BY YEAR(b.doc_date)";
2886 $sql .= $this->db->order(
"year",
'ASC');
2889 $resql = $this->db->query($sql);
2891 $this->errors[] = $this->db->lasterror();
2895 while ($obj = $this->db->fetch_object($resql)) {
2896 $total += (int) $obj->total;
2898 'year' => (
int) $obj->year,
2900 'total' => (
int) $obj->total,
2902 for ($i = 1; $i <= 12; $i++) {
2903 $year_list[
'count'][$i] = (int) $obj->{
'month' . $i};
2906 $list[] = $year_list;
2909 $this->db->free($resql);
2931 $sql =
" UPDATE " . $this->db->prefix() . $this->table_element;
2932 $sql .=
" SET date_validated = '" . $this->db->idate($now) .
"'";
2933 $sql .=
" WHERE entity = " . ((int)
$conf->entity);
2934 $sql .=
" AND DATE(doc_date) >= '" . $this->db->idate(
$date_start) .
"'";
2935 $sql .=
" AND DATE(doc_date) <= '" . $this->db->idate($date_end) .
"'";
2936 $sql .=
" AND date_validated IS NULL";
2939 $resql = $this->db->query($sql);
2941 $this->errors[] = $this->db->lasterror();
2961 $income_statement_amount = 0;
2963 if (
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
2964 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
2966 $pcg_type_filter = array();
2967 foreach ($accounting_groups_used_for_income_statement as $item) {
2968 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
2972 $sql .=
" t.numero_compte,";
2973 $sql .=
" aa.pcg_type,";
2974 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as accounting_result";
2975 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
2976 $sql .=
' LEFT JOIN ' . $this->db->prefix() .
'accounting_account as aa ON aa.account_number = t.numero_compte';
2977 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
2978 $sql .=
" AND aa.entity = " . ((int)
$conf->entity);
2979 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM ' . $this->db->prefix() .
'accounting_system WHERE rowid = ' . ((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')) .
')';
2980 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
2981 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate(
$date_start) .
"'";
2982 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
2983 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
2985 $resql = $this->db->query($sql);
2987 $this->errors[] =
'Error ' . $this->db->lasterror();
2988 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2990 while ($obj = $this->db->fetch_object($resql)) {
2991 $income_statement_amount += $obj->accounting_result;
2996 return (
string) $income_statement_amount;
3008 public function closeFiscalPeriod($fiscal_period_id, $new_fiscal_period_id, $separate_auxiliary_account =
false, $generate_bookkeeping_records =
true)
3010 global
$conf, $langs, $user;
3013 $fiscal_period_id = max(0, $fiscal_period_id);
3015 if (empty($fiscal_period_id)) {
3016 $langs->load(
'errors');
3017 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3022 $result = $fiscal_period->fetch($fiscal_period_id);
3024 $this->error = $fiscal_period->error;
3025 $this->errors = $fiscal_period->errors;
3027 } elseif (empty($fiscal_period->id)) {
3028 $langs->loadLangs(array(
'errors',
'compta'));
3029 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
3034 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
3035 if (empty($new_fiscal_period_id)) {
3036 $langs->load(
'errors');
3037 $this->errors[] = $langs->trans(
'ErrorBadParameters').
' - '.$langs->trans(
'AccountancyClosureStep3NewFiscalPeriod');
3040 $new_fiscal_period =
new Fiscalyear($this->db);
3041 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
3043 $this->error = $new_fiscal_period->error;
3044 $this->errors = $new_fiscal_period->errors;
3046 } elseif (empty($new_fiscal_period->id)) {
3047 $langs->loadLangs(array(
'errors',
'compta'));
3048 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
3055 $fiscal_period->statut = Fiscalyear::STATUS_CLOSED;
3056 $fiscal_period->status = Fiscalyear::STATUS_CLOSED;
3057 $result = $fiscal_period->update($user);
3059 $this->error = $fiscal_period->error;
3060 $this->errors = $fiscal_period->errors;
3064 if (!$error && !empty($generate_bookkeeping_records)) {
3066 if (empty($journal_id)) {
3067 $langs->loadLangs(array(
'errors',
'accountancy'));
3068 $this->errors[] = $langs->trans(
'ErrorBadParameters') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
3075 $result = $journal->fetch($journal_id);
3077 $this->error = $journal->error;
3078 $this->errors = $journal->errors;
3080 } elseif ($result == 0) {
3081 $langs->loadLangs(array(
'errors',
'accountancy'));
3082 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
3089 if (!$error && is_object($journal)) {
3090 $accounting_groups_used_for_balance_sheet_account = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))),
'strlen');
3091 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
3093 $pcg_type_filter = array();
3094 $tmp = array_merge($accounting_groups_used_for_balance_sheet_account, $accounting_groups_used_for_income_statement);
3095 foreach ($tmp as $item) {
3096 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
3100 $sql .=
" t.numero_compte,";
3101 if ($separate_auxiliary_account) {
3102 $sql .=
" NULLIF(t.subledger_account, '') as subledger_account,";
3104 $sql .=
" aa.pcg_type,";
3105 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as opening_balance";
3106 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
3107 $sql .=
' LEFT JOIN ' . $this->db->prefix() .
'accounting_account as aa ON aa.account_number = t.numero_compte';
3108 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
3109 $sql .=
" AND aa.entity = ". ((int)
$conf->entity);
3110 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM '.$this->db->prefix().
'accounting_system WHERE rowid = '.((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')).
')';
3111 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
3112 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
3113 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
3114 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
3115 if ($separate_auxiliary_account) {
3116 $sql .=
" , NULLIF(t.subledger_account, '')";
3118 $sql .=
' HAVING (SUM(t.credit) - SUM(t.debit)) != 0 ';
3119 $sql .= $this->db->order(
"t.numero_compte",
"ASC");
3121 $resql = $this->db->query($sql);
3123 $this->errors[] =
'Error ' . $this->db->lasterror();
3124 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3129 $income_statement_amount = 0;
3130 while ($obj = $this->db->fetch_object($resql)) {
3131 if (in_array($obj->pcg_type, $accounting_groups_used_for_income_statement)) {
3132 $income_statement_amount += $obj->opening_balance;
3135 $mt = $obj->opening_balance;
3138 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3140 $bookkeeping->date_lim_reglement =
'';
3141 $bookkeeping->doc_ref = $fiscal_period->label;
3143 $bookkeeping->date_creation = $now;
3144 $bookkeeping->doc_type =
'closure';
3145 $bookkeeping->fk_doc = $fiscal_period->id;
3146 $bookkeeping->fk_docdet = 0;
3147 $bookkeeping->thirdparty_code =
'';
3149 if ($separate_auxiliary_account) {
3150 $bookkeeping->subledger_account = $obj->subledger_account;
3152 $sql .=
" subledger_label";
3153 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
3154 $sql .=
" WHERE subledger_account = '" . $this->db->escape($obj->subledger_account) .
"'";
3155 $sql .=
" ORDER BY doc_date DESC";
3157 $result = $this->db->query($sql);
3159 $this->errors[] =
'Error: ' . $this->db->lasterror();
3160 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3163 $objtmp = $this->db->fetch_object($result);
3164 $bookkeeping->subledger_label = $objtmp->subledger_label;
3166 $bookkeeping->subledger_account =
null;
3167 $bookkeeping->subledger_label =
null;
3170 $bookkeeping->numero_compte = $obj->numero_compte;
3172 $accountingaccount->fetch(0, $obj->numero_compte);
3173 $bookkeeping->label_compte = $accountingaccount->label;
3175 $bookkeeping->label_operation = $new_fiscal_period->label;
3176 $bookkeeping->montant = $mt;
3177 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
3178 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
3179 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
3180 $bookkeeping->code_journal = $journal->code;
3181 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
3182 $bookkeeping->fk_user_author = $user->id;
3183 $bookkeeping->entity =
$conf->entity;
3185 $result = $bookkeeping->create($user);
3187 $this->setErrorsFromObject($bookkeeping);
3195 if (!$error && $income_statement_amount != 0) {
3196 $mt = $income_statement_amount;
3198 $accountingaccount->fetch(0,
getDolGlobalString($income_statement_amount < 0 ?
'ACCOUNTING_RESULT_LOSS' :
'ACCOUNTING_RESULT_PROFIT'),
true);
3201 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3203 $bookkeeping->date_lim_reglement =
'';
3204 $bookkeeping->doc_ref = $fiscal_period->label;
3206 $bookkeeping->date_creation = $now;
3207 $bookkeeping->doc_type =
'closure';
3208 $bookkeeping->fk_doc = $fiscal_period->id;
3209 $bookkeeping->fk_docdet = 0;
3210 $bookkeeping->thirdparty_code =
'';
3234 $bookkeeping->subledger_account =
null;
3235 $bookkeeping->subledger_label =
null;
3238 $bookkeeping->numero_compte = $accountingaccount->account_number;
3239 $bookkeeping->label_compte = $accountingaccount->label;
3241 $bookkeeping->label_operation = $new_fiscal_period->label;
3242 $bookkeeping->montant = $mt;
3243 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
3244 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
3245 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
3246 $bookkeeping->code_journal = $journal->code;
3247 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
3248 $bookkeeping->fk_user_author = $user->id;
3249 $bookkeeping->entity =
$conf->entity;
3251 $result = $bookkeeping->create($user);
3253 $this->setErrorsFromObject($bookkeeping);
3257 $this->db->free($resql);
3263 $this->db->rollback();
3266 $this->db->commit();
3283 global
$conf, $langs, $user;
3286 $fiscal_period_id = max(0, $fiscal_period_id);
3287 if (empty($fiscal_period_id)) {
3288 $langs->load(
'errors');
3289 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3293 $result = $fiscal_period->fetch($fiscal_period_id);
3295 $this->error = $fiscal_period->error;
3296 $this->errors = $fiscal_period->errors;
3298 } elseif (empty($fiscal_period->id)) {
3299 $langs->loadLangs(array(
'errors',
'compta'));
3300 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
3305 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
3306 if (empty($new_fiscal_period_id)) {
3307 $langs->load(
'errors');
3308 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3311 $new_fiscal_period =
new Fiscalyear($this->db);
3312 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
3314 $this->error = $new_fiscal_period->error;
3315 $this->errors = $new_fiscal_period->errors;
3317 } elseif (empty($new_fiscal_period->id)) {
3318 $langs->loadLangs(array(
'errors',
'compta'));
3319 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
3324 $inventory_journal_id = max(0, $inventory_journal_id);
3325 if (empty($inventory_journal_id)) {
3326 $langs->load(
'errors');
3327 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3332 $result = $inventory_journal->fetch($inventory_journal_id);
3334 $this->error = $inventory_journal->error;
3335 $this->errors = $inventory_journal->errors;
3337 } elseif ($result == 0) {
3338 $langs->loadLangs(array(
'errors',
'accountancy'));
3339 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'InventoryJournal');
3346 $sql =
'SELECT t.rowid';
3347 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
3348 $sql .=
' WHERE t.entity = ' . ((int)
$conf->entity);
3349 $sql .=
" AND code_journal = '" . $this->db->escape($inventory_journal->code) .
"'";
3350 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate(
$date_start) .
"'";
3351 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
3352 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
3353 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
3355 $resql = $this->db->query($sql);
3357 $this->errors[] =
'Error ' . $this->db->lasterror();
3358 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3363 while ($obj = $this->db->fetch_object($resql)) {
3365 $result = $bookkeeping->fetch($obj->rowid);
3367 $this->error = $inventory_journal->error;
3368 $this->errors = $inventory_journal->errors;
3371 } elseif ($result == 0) {
3372 $langs->loadLangs(array(
'errors',
'accountancy'));
3373 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'LineId') .
': ' . $obj->rowid;
3378 $bookkeeping->id = 0;
3379 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3380 $bookkeeping->doc_ref = $new_fiscal_period->label;
3381 $bookkeeping->date_creation = $now;
3382 $bookkeeping->doc_type =
'accounting_reversal';
3383 $bookkeeping->fk_doc = $new_fiscal_period->id;
3384 $bookkeeping->fk_docdet = 0;
3386 $bookkeeping->montant = -$bookkeeping->montant;
3387 $bookkeeping->sens = ($bookkeeping->montant >= 0) ?
'C' :
'D';
3388 $old_debit = $bookkeeping->debit;
3389 $bookkeeping->debit = $bookkeeping->credit;
3390 $bookkeeping->credit = $old_debit;
3392 $bookkeeping->fk_user_author = $user->id;
3393 $bookkeeping->entity =
$conf->entity;
3395 $result = $bookkeeping->create($user);
3397 $this->error = $bookkeeping->error;
3398 $this->errors = $bookkeeping->errors;
3403 $this->db->free($resql);
3407 $this->db->rollback();
3410 $this->db->commit();
3424 global $langs, $user;
3434 if ((
int) $accounting_account > 0) {
3435 $accountingaccount->fetch($accounting_account);
3437 foreach ($toselect as
$id) {
3438 if ($bookkeeping->fetch(
$id)) {
3440 $accountcustcode =
'411';
3446 $accountsuppcode =
'401';
3451 if (strpos($bookkeeping->numero_compte, $accountcustcode) === 0 || strpos($bookkeeping->numero_compte, $accountsuppcode) === 0) {
3452 $echecT[] = $bookkeeping->numero_compte;
3456 $bookkeeping->numero_compte = $accountingaccount->account_number;
3457 $bookkeeping->label_compte = $accountingaccount->label;
3459 $result = $bookkeeping->update($user);
3471 $echecImplode = implode(
",", $echecT);
3475 $this->db->rollback();
3479 setEventMessages($nb .
" " . $langs->trans(
'AssignAccountsSuccess'),
null,
'mesgs');
3480 } elseif ($nb > 0) {
3481 setEventMessages($nb .
" " . $langs->trans(
'AssignAccountSuccess'),
null,
'mesgs');
3487 if (!empty($echecImplode)) {
3488 $nbEchec = count(explode(
',', $echecImplode));
3490 $nbEchec == 1 ? $langs->trans(
'NoAccountChangedWithAccountNumber') .
' ' . $echecImplode : $langs->trans(
'NoAccountsChangedWithAccountNumber') .
' ' . $echecImplode,
3497 $this->db->rollback();
3500 $this->db->commit();
3513 public function newClone($piecenum, $code_journal, $docdate)
3520 $accountingJournal->fetch(0, $code_journal);
3524 $periodeFiscal = $bookKeepingValid->validBookkeepingDate($docdate);
3525 if ($periodeFiscal < 0) {
3528 } elseif ($periodeFiscal == 0) {
3530 setEventMessages($langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod'),
null,
'errors');
3532 setEventMessages($langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod'),
null,
'errors');
3533 header(
"Location: " . $_SERVER[
'HTTP_REFERER']);
3540 $bookKeepingInstance =
new BookKeeping($this->db);
3541 $pieceNumNext = $bookKeepingInstance->getNextNumMvt();
3544 $sqlRowidClone =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE piece_num = ".((int) $piecenum);
3545 $resqlRowidClone = $this->db->query($sqlRowidClone);
3547 if ($resqlRowidClone) {
3548 while ($objRowidClone = $this->db->fetch_object($resqlRowidClone)) {
3549 $cloneId[] = $objRowidClone->rowid;
3552 foreach ($cloneId as $toselectid) {
3554 if ($bookKeeping->fetch($toselectid)) {
3555 $code_journal =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $code_journal : $bookKeeping->code_journal;
3556 $journal_label =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $accountingJournal->label : $bookKeeping->journal_label;
3558 $sql =
"SELECT piece_num, label_operation, numero_compte, label_compte, doc_type, code_journal, fk_user_author, doc_ref,";
3559 $sql .=
" fk_doc, fk_docdet, debit, credit, journal_label, sens, montant, subledger_account, subledger_label";
3560 $sql .=
" FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping";
3561 $sql .=
" WHERE rowid = " . ((int) $toselectid);
3562 $resql = $this->db->query($sql);
3565 while ($obj = $this->db->fetch_object($resql)) {
3566 $docRef = $obj->doc_ref;
3567 if (preg_match(
'/ \((\d+)\)$/', $docRef, $matches)) {
3568 $docRef = preg_replace(
'/ \(\d+\)$/',
' (' . (((
int) $matches[1]) + 1) .
')', $docRef);
3573 $sql_insert =
"INSERT INTO " . MAIN_DB_PREFIX .
"accounting_bookkeeping";
3574 $sql_insert .=
" (piece_num, label_operation, numero_compte, label_compte, doc_type, code_journal, doc_date, fk_user_author, doc_ref,";
3575 $sql_insert .=
" fk_doc, fk_docdet, debit, credit, date_creation, journal_label, sens, montant, subledger_account, subledger_label)";
3576 $sql_insert .=
" VALUES";
3577 $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) .
"', ";
3578 $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) .
"')";
3580 $resqlInsert = $this->db->query($sql_insert);
3583 setEventMessages($langs->trans(
'CloningSuccess', $pieceNumNext),
null,
'mesgs');
3585 setEventMessages($langs->trans(
'CloningFailed') . $this->db->lasterror(),
null,
'errors');
3595 $this->db->rollback();
3598 $this->db->commit();
3613 global $langs, $user;
3619 if (empty($docdate)) {
3623 $idImplodeSelect = implode(
',', $toselect);
3626 $sqlPieceNum =
"SELECT DISTINCT(piece_num) FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE rowid IN (".$this->db->sanitize($idImplodeSelect).
")";
3627 $resqlPieceNum = $this->db->query($sqlPieceNum);
3629 if ($resqlPieceNum) {
3630 while ($objPieceNum = $this->db->fetch_object($resqlPieceNum)) {
3631 $pieceNumT[] = $objPieceNum->piece_num;
3634 foreach ($pieceNumT as $pieceNum) {
3636 $accountingJournal->fetch(0, $code_journal);
3638 $periodeFiscal = $bookKeepingValid->validBookkeepingDate($docdate);
3639 if ($periodeFiscal < 0) {
3641 } elseif ($periodeFiscal == 0) {
3643 setEventMessages($langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod'),
null,
'errors');
3645 setEventMessages($langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod'),
null,
'errors');
3646 header(
"Location: " . $_SERVER[
'HTTP_REFERER']);
3651 $bookKeepingInstance =
new BookKeeping($this->db);
3652 $pieceNumNext = $bookKeepingInstance->getNextNumMvt();
3654 $sqlRowidClone =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE piece_num = $pieceNum";
3655 $resqlRowidClone = $this->db->query($sqlRowidClone);
3657 if ($resqlRowidClone) {
3658 while ($objRowidClone = $this->db->fetch_object($resqlRowidClone)) {
3659 $cloneId[] = $objRowidClone->rowid;
3662 foreach ($cloneId as $toselectid) {
3664 if ($bookKeeping->fetch($toselectid)) {
3665 $code_journal =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $code_journal : $bookKeeping->code_journal;
3666 $journal_label =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $accountingJournal->label : $bookKeeping->journal_label;
3667 $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";
3668 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping WHERE rowid = " . ((int) $toselectid);
3670 $resql = $this->db->query($sql);
3672 while ($obj = $this->db->fetch_object($resql)) {
3673 $docRef = $obj->doc_ref;
3674 if (preg_match(
'/ \((\d+)\)$/', $docRef, $matches)) {
3675 $docRef = preg_replace(
'/ \(\d+\)$/',
' (' . (((
int) $matches[1]) + 1) .
')', $docRef);
3680 $sql_insert =
"INSERT INTO ".$this->db->prefix().
"accounting_bookkeeping (";
3681 $sql_insert .=
" piece_num";
3682 $sql_insert .=
", label_operation";
3683 $sql_insert .=
", numero_compte";
3684 $sql_insert .=
", label_compte";
3685 $sql_insert .=
", subledger_account";
3686 $sql_insert .=
", subledger_label";
3687 $sql_insert .=
", doc_type";
3688 $sql_insert .=
", code_journal";
3689 $sql_insert .=
", doc_date";
3690 $sql_insert .=
", date_creation";
3691 $sql_insert .=
", fk_user_author";
3692 $sql_insert .=
", doc_ref";
3693 $sql_insert .=
", fk_doc";
3694 $sql_insert .=
", fk_docdet";
3695 $sql_insert .=
", debit";
3696 $sql_insert .=
", credit";
3697 $sql_insert .=
", journal_label";
3698 $sql_insert .=
", sens";
3699 $sql_insert .=
", montant";
3701 $sql_insert .=
" VALUES (";
3702 $sql_insert .= $pieceNumNext;
3703 $sql_insert .=
", '" . $this->db->escape($obj->label_operation) .
"'";
3704 $sql_insert .=
", '" . $this->db->escape($obj->numero_compte) .
"'";
3705 $sql_insert .=
", '" . $this->db->escape($obj->label_compte) .
"'";
3706 $sql_insert .=
", '" . $this->db->escape($obj->subledger_account) .
"'";
3707 $sql_insert .=
", '" . $this->db->escape($obj->subledger_label) .
"'";
3708 $sql_insert .=
", ''";
3709 $sql_insert .=
", '" . $this->db->escape($code_journal) .
"'";
3710 $sql_insert .=
", '" . $this->db->idate($docdate).
"'";
3711 $sql_insert .=
", '" . $this->db->idate($now).
"'";
3712 $sql_insert .=
", ".($user->id > 0 ? ((int) $user->id) :
"NULL");
3713 $sql_insert .=
", '" . $this->db->escape($docRef) .
"'";
3714 $sql_insert .=
", 0";
3715 $sql_insert .=
", 0";
3716 $sql_insert .=
", " . (float) $obj->debit;
3717 $sql_insert .=
", " . (float) $obj->credit;
3718 $sql_insert .=
", '" . $this->db->escape($journal_label) .
"'";
3719 $sql_insert .=
", '" . $this->db->escape($obj->sens) .
"'";
3720 $sql_insert .=
", " . (float) $obj->montant;
3723 $resqlInsert = $this->db->query($sql_insert);
3726 setEventMessages($langs->trans(
'CloningSuccess', $pieceNumNext),
null,
'mesgs');
3740 $this->db->rollback();
3743 $this->db->commit();
3758 global $langs, $user;
3763 if (empty($docdate)) {
3768 $accountingJournal->fetch(0, $code_journal);
3771 $sqlAlreadyExtourne =
"SELECT DISTINCT(piece_num) FROM " .MAIN_DB_PREFIX.
"accounting_bookkeeping WHERE label_operation LIKE '%Extourne%'";
3772 $resqlAlreadyExtourne = $this->db->query($sqlAlreadyExtourne);
3773 $alreadyExtourneT = array();
3774 if ($resqlAlreadyExtourne) {
3775 while ($obj4 = $this->db->fetch_object($resqlAlreadyExtourne)) {
3776 $alreadyExtourneT [] = $obj4->piece_num;
3780 $idImplode = implode(
',', $toselect);
3781 $sql1 =
"SELECT DISTINCT(piece_num) from " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE rowid IN (".$this->db->sanitize($idImplode).
")";
3782 $resql1 = $this->db->query($sql1);
3786 while ($obj1 = $this->db->fetch_object($resql1)) {
3787 $pieceNumT [] = $obj1->piece_num;
3790 $i = mt_rand(0, 100);
3791 foreach ($pieceNumT as $pieceNum) {
3792 $newBookKeepingInstance =
new BookKeeping($this->db);
3793 $pieceNumNext = $newBookKeepingInstance->getNextNumMvt();
3795 $sql2 =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE piece_num = ".((int) $pieceNum);
3796 $resql2 = $this->db->query($sql2);
3799 while ($obj2 = $this->db->fetch_object($resql2)) {
3800 $extourneIds [] = $obj2->rowid;
3803 foreach ($extourneIds as $extourneId) {
3807 if ($bookKeeping->fetch($extourneId)) {
3808 if (in_array($bookKeeping->piece_num, $alreadyExtourneT)) {
3809 setEventMessages($langs->trans(
"AlreadyReturnedAccount", $bookKeeping->piece_num),
null,
'errors');
3811 $newBookKeeping->debit = $bookKeeping->credit;
3812 $newBookKeeping->credit = $bookKeeping->debit;
3813 if ($bookKeeping->sens ==
'D') {
3814 $newBookKeeping->sens =
'C';
3816 $newBookKeeping->sens =
'D';
3819 $newBookKeeping->label_operation = $langs->trans(
"ReturnAccount") .
" " . $bookKeeping->piece_num .
" - " . $bookKeeping->numero_compte .
" - " .
date(
'd/m/Y',
dol_now()) .
" - " . $i;
3821 $newBookKeeping->numero_compte = $bookKeeping->numero_compte;
3822 $newBookKeeping->label_compte = $bookKeeping->label_compte;
3823 $newBookKeeping->doc_type = $bookKeeping->doc_type;
3824 $newBookKeeping->code_journal = $bookKeeping->code_journal;
3825 $newBookKeeping->doc_date = $docdate;
3826 $newBookKeeping->fk_user_author = $user->id;
3827 $newBookKeeping->doc_ref = $bookKeeping->doc_ref;
3828 $newBookKeeping->montant = $bookKeeping->montant;
3829 $newBookKeeping->journal_label = $bookKeeping->journal_label;
3830 $newBookKeeping->subledger_account = $bookKeeping->subledger_account;
3831 $newBookKeeping->subledger_label = $bookKeeping->subledger_label;
3833 $createResult = $newBookKeeping->create($user);
3835 if ($createResult >= 0) {
3836 $newBookKeeping->piece_num = $pieceNumNext;
3837 $newBookKeeping->fk_doc = $bookKeeping->fk_doc;
3838 $newBookKeeping->fk_docdet = $bookKeeping->fk_docdet;
3839 $newBookKeeping->update($user);
3840 setEventMessages($langs->trans(
"SuccessReturnedAccount", $bookKeeping->piece_num),
null,
'mesgs');
3842 setEventMessages($langs->trans(
"ErrorWhileCreating", $newBookKeeping->error), $newBookKeeping->errors,
'errors');
3854 $this->db->rollback();
3857 $this->db->commit();
3876 public $doc_date =
null;
3900 public $thirdparty_code;
3905 public $subledger_account;
3910 public $subledger_label;
3915 public $numero_compte;
3920 public $label_compte;
3925 public $label_operation;
3951 public $multicurrency_amount;
3956 public $multicurrency_code;
3966 public $matching_general;
3971 public $lettering_code;
3976 public $date_lettering;
3981 public $fk_user_author;
3992 public $code_journal;
3997 public $journal_label;
4006 public $date_export;
4011 public $date_lim_reglement;
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
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,...
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class to manage fiscal year.
Class to manage Dolibarr users.
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
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 '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
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, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date