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.lettering_code,";
992 $sql .=
" t.date_lettering,";
993 $sql .=
" t.fk_user_author,";
994 $sql .=
" t.import_key,";
995 $sql .=
" t.code_journal,";
996 $sql .=
" t.journal_label,";
997 $sql .=
" t.piece_num,";
999 $sql .=
" t.date_creation,";
1000 $sql .=
" t.date_export,";
1001 $sql .=
" t.date_validated as date_validation,";
1002 $sql .=
" t.date_lim_reglement,";
1003 $sql .=
" t.import_key";
1006 $sqlwhere = array();
1007 if (count($filter) > 0) {
1008 foreach ($filter as $key => $value) {
1009 if ($key ==
't.doc_date>=') {
1010 $sqlwhere[] =
"t.doc_date >= '".$this->db->idate((
int) $value).
"'";
1011 } elseif ($key ==
't.doc_date<=') {
1012 $sqlwhere[] =
"t.doc_date <= '".$this->db->idate((
int) $value).
"'";
1013 } elseif ($key ==
't.doc_date>') {
1014 $sqlwhere[] =
"t.doc_date > '".$this->db->idate((
int) $value).
"'";
1015 } elseif ($key ==
't.doc_date<') {
1016 $sqlwhere[] =
"t.doc_date < '".$this->db->idate((
int) $value).
"'";
1017 } elseif ($key ==
't.numero_compte>=') {
1018 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1019 } elseif ($key ==
't.numero_compte<=') {
1020 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1021 } elseif ($key ==
't.subledger_account>=') {
1022 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1023 } elseif ($key ==
't.subledger_account<=') {
1024 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1025 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1026 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
1027 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1028 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($this->db->escapeforlike($value)).
"%'";
1029 } elseif ($key ==
't.date_creation>=') {
1030 $sqlwhere[] =
"t.date_creation >= '".$this->db->idate((
int) $value).
"'";
1031 } elseif ($key ==
't.date_creation<=') {
1032 $sqlwhere[] =
"t.date_creation <= '".$this->db->idate((
int) $value).
"'";
1033 } elseif ($key ==
't.date_export>=') {
1034 $sqlwhere[] =
"t.date_export >= '".$this->db->idate((
int) $value).
"'";
1035 } elseif ($key ==
't.date_export<=') {
1036 $sqlwhere[] =
"t.date_export <= '".$this->db->idate((
int) $value).
"'";
1037 } elseif ($key ==
't.date_validated>=') {
1038 $sqlwhere[] =
"t.date_validated >= '".$this->db->idate((
int) $value).
"'";
1039 } elseif ($key ==
't.date_validated<=') {
1040 $sqlwhere[] =
"t.date_validated <= '".$this->db->idate((
int) $value).
"'";
1041 } elseif ($key ==
't.date_lim_reglement>=') {
1042 $sqlwhere[] =
"t.date_lim_reglement>='".$this->db->idate((
int) $value).
"'";
1043 } elseif ($key ==
't.date_lim_reglement<=') {
1044 $sqlwhere[] =
"t.date_lim_reglement<='".$this->db->idate((
int) $value).
"'";
1045 } elseif ($key ==
't.credit' || $key ==
't.debit') {
1047 } elseif ($key ==
't.reconciled_option') {
1048 $sqlwhere[] =
't.lettering_code IS NULL';
1049 } elseif ($key ==
't.code_journal' && !empty($value)) {
1050 if (is_array($value)) {
1051 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1055 } elseif ($key ==
't.search_accounting_code_in' && !empty($value)) {
1056 $sqlwhere[] =
"t.numero_compte IN (".$this->db->sanitize($value, 1).
")";
1062 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t';
1063 $sql .=
' WHERE entity = ' . ((int) $conf->entity);
1064 if (count($sqlwhere) > 0) {
1065 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1068 if (!empty($option)) {
1069 $sql .=
" AND t.subledger_account IS NOT NULL";
1070 $sql .=
" AND t.subledger_account <> ''";
1071 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
1072 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1074 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
1075 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1079 $sql .= $this->db->order($sortfield, $sortorder);
1080 if (!empty($limit)) {
1081 $sql .= $this->db->plimit($limit + 1, $offset);
1085 $resql = $this->db->query($sql);
1088 $obj = $this->db->fetch_object($resql);
1093 $num = $this->db->num_rows($resql);
1096 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1099 $line->id = $obj->rowid;
1101 $line->doc_date = $this->db->jdate($obj->doc_date);
1102 $line->doc_type = $obj->doc_type;
1103 $line->doc_ref = $obj->doc_ref;
1104 $line->fk_doc = $obj->fk_doc;
1105 $line->fk_docdet = $obj->fk_docdet;
1106 $line->thirdparty_code = $obj->thirdparty_code;
1107 $line->subledger_account = $obj->subledger_account;
1108 $line->subledger_label = $obj->subledger_label;
1109 $line->numero_compte = $obj->numero_compte;
1110 $line->label_compte = $obj->label_compte;
1111 $line->label_operation = $obj->label_operation;
1112 $line->debit = $obj->debit;
1113 $line->credit = $obj->credit;
1114 $line->montant = $obj->amount;
1115 $line->amount = $obj->amount;
1116 $line->sens = $obj->sens;
1117 $line->multicurrency_amount = $obj->multicurrency_amount;
1118 $line->multicurrency_code = $obj->multicurrency_code;
1119 $line->lettering_code = $obj->lettering_code;
1120 $line->date_lettering = $this->db->jdate($obj->date_lettering);
1121 $line->fk_user_author = $obj->fk_user_author;
1122 $line->import_key = $obj->import_key;
1123 $line->code_journal = $obj->code_journal;
1124 $line->journal_label = $obj->journal_label;
1125 $line->piece_num = $obj->piece_num;
1126 $line->ref = $obj->ref;
1127 $line->date_creation = $this->db->jdate($obj->date_creation);
1128 $line->date_export = $this->db->jdate($obj->date_export);
1129 $line->date_validation = $this->db->jdate($obj->date_validation);
1131 $line->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1132 $line->import_key = $obj->import_key;
1134 $this->lines[] = $line;
1139 $this->db->free($resql);
1143 $this->errors[] =
'Error '.$this->db->lasterror();
1144 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1162 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $showAlreadyExportMovements = 1)
1169 $sql .=
' t.rowid,';
1170 $sql .=
" t.doc_date,";
1171 $sql .=
" t.doc_type,";
1172 $sql .=
" t.doc_ref,";
1173 $sql .=
" t.fk_doc,";
1174 $sql .=
" t.fk_docdet,";
1175 $sql .=
" t.thirdparty_code,";
1176 $sql .=
" t.subledger_account,";
1177 $sql .=
" t.subledger_label,";
1178 $sql .=
" t.numero_compte,";
1179 $sql .=
" t.label_compte,";
1180 $sql .=
" t.label_operation,";
1181 $sql .=
" t.debit,";
1182 $sql .=
" t.credit,";
1183 $sql .=
" t.lettering_code,";
1184 $sql .=
" t.date_lettering,";
1185 $sql .=
" t.montant as amount,";
1187 $sql .=
" t.fk_user_author,";
1188 $sql .=
" t.import_key,";
1189 $sql .=
" t.code_journal,";
1190 $sql .=
" t.journal_label,";
1191 $sql .=
" t.piece_num,";
1192 $sql .=
" t.date_creation,";
1193 $sql .=
" t.date_lim_reglement,";
1194 $sql .=
" t.tms as date_modification,";
1195 $sql .=
" t.date_export,";
1196 $sql .=
" t.date_validated as date_validation";
1197 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t';
1198 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
1199 if ($showAlreadyExportMovements == 0) {
1200 $sql .=
" AND t.date_export IS NULL";
1204 if (is_array($filter)) {
1205 dol_syslog(
"You are using a deprecated use of fetchAll. filter parameter must be an USF string now.", LOG_WARNING);
1206 $sqlwhere = array();
1207 if (count($filter) > 0) {
1208 foreach ($filter as $key => $value) {
1209 if ($key ==
't.doc_date') {
1210 $sqlwhere[] = $this->db->sanitize($key).
" = '".$this->db->idate((
int) $value).
"'";
1211 } elseif ($key ==
't.doc_date>=') {
1212 $sqlwhere[] =
"t.doc_date >= '".$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.numero_compte>=') {
1220 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1221 } elseif ($key ==
't.numero_compte<=') {
1222 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1223 } elseif ($key ==
't.subledger_account>=') {
1224 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1225 } elseif ($key ==
't.subledger_account<=') {
1226 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1227 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1228 $sqlwhere[] = $this->db->sanitize($key).
' = '.((int) $value);
1229 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1230 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1231 } elseif ($key ==
't.date_creation>=') {
1232 $sqlwhere[] =
"t.date_creation >= '".$this->db->idate((
int) $value).
"'";
1233 } elseif ($key ==
't.date_creation<=') {
1234 $sqlwhere[] =
"t.date_creation <= '".$this->db->idate((
int) $value).
"'";
1235 } elseif ($key ==
't.tms>=') {
1236 $sqlwhere[] =
"t.tms >= '".$this->db->idate((
int) $value).
"'";
1237 } elseif ($key ==
't.tms<=') {
1238 $sqlwhere[] =
"t.tms <= '".$this->db->idate((
int) $value).
"'";
1239 } elseif ($key ==
't.date_export>=') {
1240 $sqlwhere[] =
"t.date_export >= '".$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_validated>=') {
1244 $sqlwhere[] =
"t.date_validated >= '".$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.credit' || $key ==
't.debit') {
1249 } elseif ($key ==
't.code_journal' && !empty($value)) {
1250 if (is_array($value)) {
1251 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1255 } elseif ($key ==
't.reconciled_option') {
1256 $sqlwhere[] =
't.lettering_code IS NULL';
1262 if (count($sqlwhere) > 0) {
1263 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1272 if ($errormessage) {
1273 $this->errors[] = $errormessage;
1274 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1278 if (!empty($sortfield)) {
1279 $sql .= $this->db->order($sortfield, $sortorder);
1281 if (!empty($limit)) {
1282 $sql .= $this->db->plimit($limit + 1, $offset);
1284 $this->lines = array();
1286 $resql = $this->db->query($sql);
1288 $num = $this->db->num_rows($resql);
1291 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1294 $line->id = $obj->rowid;
1296 $line->doc_date = $this->db->jdate($obj->doc_date);
1297 $line->doc_type = $obj->doc_type;
1298 $line->doc_ref = $obj->doc_ref;
1299 $line->fk_doc = $obj->fk_doc;
1300 $line->fk_docdet = $obj->fk_docdet;
1301 $line->thirdparty_code = $obj->thirdparty_code;
1302 $line->subledger_account = $obj->subledger_account;
1303 $line->subledger_label = $obj->subledger_label;
1304 $line->numero_compte = $obj->numero_compte;
1305 $line->label_compte = $obj->label_compte;
1306 $line->label_operation = $obj->label_operation;
1307 $line->debit = $obj->debit;
1308 $line->credit = $obj->credit;
1309 $line->montant = $obj->amount;
1310 $line->amount = $obj->amount;
1311 $line->sens = $obj->sens;
1312 $line->lettering_code = $obj->lettering_code;
1313 $line->date_lettering = $this->db->jdate($obj->date_lettering);
1314 $line->fk_user_author = $obj->fk_user_author;
1315 $line->import_key = $obj->import_key;
1316 $line->code_journal = $obj->code_journal;
1317 $line->journal_label = $obj->journal_label;
1318 $line->piece_num = $obj->piece_num;
1319 $line->date_creation = $this->db->jdate($obj->date_creation);
1320 $line->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
1321 $line->date_modification = $this->db->jdate($obj->date_modification);
1322 $line->date_export = $this->db->jdate($obj->date_export);
1323 $line->date_validation = $this->db->jdate($obj->date_validation);
1325 $this->lines[] = $line;
1329 $this->db->free($resql);
1333 $this->errors[] =
'Error '.$this->db->lasterror();
1334 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1351 public function fetchAllBalance($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $option = 0)
1355 $this->lines = array();
1360 $sql .=
" t.numero_compte,";
1361 if (!empty($option)) {
1362 $sql .=
" t.subledger_account,";
1363 $sql .=
" t.subledger_label,";
1365 $sql .=
" SUM(t.debit) as debit,";
1366 $sql .=
" SUM(t.credit) as credit";
1367 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t';
1368 $sql .=
' WHERE entity = ' . ((int) $conf->entity);
1371 if (is_array($filter)) {
1372 $sqlwhere = array();
1373 if (count($filter) > 0) {
1374 foreach ($filter as $key => $value) {
1375 if ($key ==
't.doc_date') {
1376 $sqlwhere[] = $this->db->sanitize($key).
" = '".$this->db->idate((
int) $value).
"'";
1377 } elseif ($key ==
't.doc_date>=') {
1378 $sqlwhere[] =
"t.doc_date >= '".$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.numero_compte>=') {
1386 $sqlwhere[] =
"t.numero_compte >= '".$this->db->escape($value).
"'";
1387 } elseif ($key ==
't.numero_compte<=') {
1388 $sqlwhere[] =
"t.numero_compte <= '".$this->db->escape($value).
"'";
1389 } elseif ($key ==
't.subledger_account>=') {
1390 $sqlwhere[] =
"t.subledger_account >= '".$this->db->escape($value).
"'";
1391 } elseif ($key ==
't.subledger_account<=') {
1392 $sqlwhere[] =
"t.subledger_account <= '".$this->db->escape($value).
"'";
1393 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1394 $sqlwhere[] = $this->db->sanitize($key).
" = ".((int) $value);
1395 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1396 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1397 } elseif ($key ==
't.subledger_label') {
1398 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '".$this->db->escape($value).
"%'";
1399 } elseif ($key ==
't.code_journal' && !empty($value)) {
1400 if (is_array($value)) {
1401 $sqlwhere[] =
natural_search(
"t.code_journal", implode(
',', $value), 3, 1);
1405 } elseif ($key ==
't.reconciled_option') {
1406 $sqlwhere[] =
't.lettering_code IS NULL';
1408 $sqlwhere[] = $this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
1412 if (count($sqlwhere) > 0) {
1413 $sql .=
" AND ".implode(
" ".$this->db->sanitize($filtermode).
" ", $sqlwhere);
1422 if ($errormessage) {
1423 $this->errors[] = $errormessage;
1424 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1428 if (!empty($option)) {
1429 $sql .=
" AND t.subledger_account IS NOT NULL";
1430 $sql .=
" AND t.subledger_account <> ''";
1431 $sql .=
" GROUP BY t.numero_compte, t.subledger_account, t.subledger_label";
1432 $sortfield =
't.subledger_account'.($sortfield ?
','.$sortfield :
'');
1433 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1435 $sql .=
' GROUP BY t.numero_compte';
1436 $sortfield =
't.numero_compte'.($sortfield ?
','.$sortfield :
'');
1437 $sortorder =
'ASC'.($sortorder ?
','.$sortorder :
'');
1440 $sql .= $this->db->order($sortfield, $sortorder);
1442 if (!empty($limit)) {
1443 $sql .= $this->db->plimit($limit + 1, $offset);
1447 $resql = $this->db->query($sql);
1450 $num = $this->db->num_rows($resql);
1453 while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
1456 $line->numero_compte = $obj->numero_compte;
1458 if (!empty($option)) {
1459 $line->subledger_account = $obj->subledger_account;
1460 $line->subledger_label = $obj->subledger_label;
1462 $line->debit = $obj->debit;
1463 $line->credit = $obj->credit;
1465 $this->lines[] = $line;
1469 $this->db->free($resql);
1473 $this->errors[] =
'Error '.$this->db->lasterror();
1474 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1496 if (isset($this->doc_type)) {
1497 $this->doc_type = trim($this->doc_type);
1499 if (isset($this->doc_ref)) {
1500 $this->doc_ref = trim($this->doc_ref);
1502 if (isset($this->fk_doc)) {
1503 $this->fk_doc = (int) $this->fk_doc;
1505 if (isset($this->fk_docdet)) {
1506 $this->fk_docdet = (int) $this->fk_docdet;
1508 if (isset($this->thirdparty_code)) {
1509 $this->thirdparty_code = trim($this->thirdparty_code);
1511 if (isset($this->subledger_account)) {
1512 $this->subledger_account = trim($this->subledger_account);
1514 if (isset($this->subledger_label)) {
1515 $this->subledger_label = trim($this->subledger_label);
1517 if (isset($this->numero_compte)) {
1518 $this->numero_compte = trim($this->numero_compte);
1520 if (isset($this->label_compte)) {
1521 $this->label_compte = trim($this->label_compte);
1523 if (isset($this->label_operation)) {
1524 $this->label_operation = trim($this->label_operation);
1526 if (isset($this->sens)) {
1527 $this->sens = trim($this->sens);
1529 if (isset($this->import_key)) {
1530 $this->import_key = trim($this->import_key);
1532 if (isset($this->code_journal)) {
1533 $this->code_journal = trim($this->code_journal);
1535 if (isset($this->journal_label)) {
1536 $this->journal_label = trim($this->journal_label);
1538 if (isset($this->piece_num)) {
1539 $this->piece_num = (int) $this->piece_num;
1545 } elseif ($result == 0) {
1547 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1549 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1554 $this->debit = (float)
price2num($this->debit,
'MT');
1555 $this->credit = (float)
price2num($this->credit,
'MT');
1556 $this->montant = (float)
price2num($this->montant,
'MT');
1562 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.$mode.
' SET';
1563 $sql .=
' doc_date = '.(isDolTms($this->doc_date) ?
"'".$this->db->idate($this->doc_date).
"'" :
'null').
',';
1564 $sql .=
' doc_type = '.(isset($this->doc_type) ?
"'".$this->db->escape($this->doc_type).
"'" :
"null").
',';
1565 $sql .=
' doc_ref = '.(isset($this->doc_ref) ?
"'".$this->db->escape($this->doc_ref).
"'" :
"null").
',';
1566 $sql .=
' fk_doc = '.(isset($this->fk_doc) ? $this->fk_doc :
"null").
',';
1567 $sql .=
' fk_docdet = '.(isset($this->fk_docdet) ? $this->fk_docdet :
"null").
',';
1568 $sql .=
' thirdparty_code = '.(isset($this->thirdparty_code) ?
"'".$this->db->escape($this->thirdparty_code).
"'" :
"null").
',';
1569 $sql .=
' subledger_account = '.(isset($this->subledger_account) ?
"'".$this->db->escape($this->subledger_account).
"'" :
"null").
',';
1570 $sql .=
' subledger_label = '.(isset($this->subledger_label) ?
"'".$this->db->escape($this->subledger_label).
"'" :
"null").
',';
1571 $sql .=
' numero_compte = '.(isset($this->numero_compte) ?
"'".$this->db->escape($this->numero_compte).
"'" :
"null").
',';
1572 $sql .=
' label_compte = '.(isset($this->label_compte) ?
"'".$this->db->escape($this->label_compte).
"'" :
"null").
',';
1573 $sql .=
' label_operation = '.(isset($this->label_operation) ?
"'".$this->db->escape($this->label_operation).
"'" :
"null").
',';
1574 $sql .=
' debit = '.(isset($this->debit) ? $this->debit :
"null").
',';
1575 $sql .=
' credit = '.(isset($this->credit) ? $this->credit :
"null").
',';
1576 $sql .=
' montant = '.(isset($this->montant) ? $this->montant :
"null").
',';
1577 $sql .=
' sens = '.(isset($this->sens) ?
"'".$this->db->escape($this->sens).
"'" :
"null").
',';
1578 $sql .=
' fk_user_author = '.(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
',';
1579 $sql .=
' import_key = '.(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
',';
1580 $sql .=
' code_journal = '.(isset($this->code_journal) ?
"'".$this->db->escape($this->code_journal).
"'" :
"null").
',';
1581 $sql .=
' journal_label = '.(isset($this->journal_label) ?
"'".$this->db->escape($this->journal_label).
"'" :
"null").
',';
1582 $sql .=
' piece_num = '.(isset($this->piece_num) ? $this->piece_num :
"null");
1583 $sql .=
' WHERE rowid='.((int) $this->
id);
1587 $resql = $this->db->query($sql);
1590 $this->errors[] =
'Error '.$this->db->lasterror();
1591 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1595 if (! $error && ! $notrigger) {
1596 $result = $this->call_trigger(
'BOOKKEEPING_MODIFY', $user);
1604 $this->db->rollback();
1608 $this->db->commit();
1623 public function updateByMvt($piece_num =
'', $field =
'', $value =
'', $mode =
'')
1629 if (!isset($sql_filter)) {
1635 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.$mode;
1636 $sql .=
" SET ".$this->db->sanitize($field).
" = ".(is_numeric($value) ? ((float) $value) :
"'".$this->db->escape($value).
"'");
1637 $sql .=
" WHERE piece_num = ".((int) $piece_num);
1638 $sql .=
" AND entity = " . ((int) $conf->entity);
1639 $sql .= $sql_filter;
1641 $resql = $this->db->query($sql);
1645 $this->errors[] =
'Error '.$this->db->lasterror();
1646 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1649 $this->db->rollback();
1653 $this->db->commit();
1667 public function delete(
User $user, $notrigger = 0, $mode =
'')
1676 } elseif ($result == 0) {
1678 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
1680 $this->errors[] = $langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
1691 $result = $this->call_trigger(
'BOOKKEEPING_DELETE', $user);
1698 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.$mode;
1699 $sql .=
' WHERE rowid='.((int) $this->
id);
1701 $resql = $this->db->query($sql);
1704 $this->errors[] =
'Error '.$this->db->lasterror();
1705 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1711 $this->db->rollback();
1715 $this->db->commit();
1733 if (!isset($sql_filter)) {
1739 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1740 $sql .=
" WHERE import_key = '".$this->db->escape($importkey).
"'";
1741 $sql .= $sql_filter;
1743 $resql = $this->db->query($sql);
1746 $this->errors[] =
"Error ".$this->db->lasterror();
1747 dol_syslog(get_class($this).
"::delete Error ".$this->db->lasterror(), LOG_ERR);
1748 $this->db->rollback();
1752 $this->db->commit();
1767 global $conf, $langs;
1769 if (empty($delyear) && empty($journal)) {
1770 $this->error =
'ErrorOneFieldRequired';
1773 if (!empty($delmonth) && empty($delyear)) {
1774 $this->error =
'YearRequiredIfMonthDefined';
1779 if (!isset($sql_filter)) {
1787 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1788 $sql .=
" WHERE 1 = 1";
1790 if (!empty($journal)) {
1791 $sql .=
" AND code_journal = '".$this->db->escape($journal).
"'";
1793 $sql .=
" AND entity = " . ((int) $conf->entity);
1795 $sql .=
" AND date_validated IS NULL";
1796 $sql .= $sql_filter;
1800 $resql = $this->db->query($sql);
1803 $this->errors[] =
"Error ".$this->db->lasterror();
1804 foreach ($this->errors as $errmsg) {
1805 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1806 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1808 $this->db->rollback();
1812 $this->db->commit();
1826 global $conf, $user;
1829 if (!isset($sql_filter)) {
1840 $result = $this->call_trigger(
'BOOKKEEPING_DELETE', $user);
1849 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1850 $sql .=
" WHERE piece_num = ".(int) $piecenum;
1851 $sql .=
" AND date_validated IS NULL";
1852 $sql .=
" AND entity = " . ((int) $conf->entity);
1853 $sql .= $sql_filter;
1855 $resql = $this->db->query($sql);
1858 $this->errors[] =
"Error ".$this->db->lasterror();
1859 foreach ($this->errors as $errmsg) {
1860 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1861 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1863 $this->db->rollback();
1866 $nbprocessed = $this->db->affected_rows($resql);
1872 $this->db->rollback();
1875 $this->db->commit();
1876 return $nbprocessed;
1905 $object->context[
'createfromclone'] =
'createfromclone';
1906 $result =
$object->create($user);
1911 $this->errors =
$object->errors;
1912 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1915 unset(
$object->context[
'createfromclone']);
1919 $this->db->commit();
1923 $this->db->rollback();
1942 $this->doc_date = $now;
1943 $this->doc_type =
'';
1944 $this->doc_ref =
'';
1946 $this->fk_docdet = 0;
1947 $this->thirdparty_code =
'CU001';
1948 $this->subledger_account =
'41100001';
1949 $this->subledger_label =
'My customer company';
1950 $this->numero_compte =
'411';
1951 $this->label_compte =
'Customer';
1952 $this->label_operation =
'Sales of pea';
1953 $this->debit = 99.9;
1954 $this->credit = 0.0;
1957 $this->fk_user_author = $user->id;
1958 $this->import_key =
'20201027';
1959 $this->code_journal =
'VT';
1960 $this->journal_label =
'Journal de vente';
1961 $this->piece_num = 1234;
1962 $this->date_creation = $now;
1978 $sql =
"SELECT piece_num, ref, doc_date, code_journal, journal_label, doc_ref, doc_type,";
1979 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation, date_lim_reglement, import_key";
1981 if ($mode !=
"_tmp") {
1982 $sql .=
", date_export";
1984 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
1985 $sql .=
" WHERE piece_num = ".((int) $piecenum);
1986 $sql .=
" AND entity = " . ((int) $conf->entity);
1989 $result = $this->db->query($sql);
1991 $obj = $this->db->fetch_object($result);
1993 $this->piece_num = $obj->piece_num;
1994 $this->
ref = $obj->ref;
1995 $this->code_journal = $obj->code_journal;
1996 $this->journal_label = $obj->journal_label;
1997 $this->doc_date = $this->db->jdate($obj->doc_date);
1998 $this->doc_ref = $obj->doc_ref;
1999 $this->doc_type = $obj->doc_type;
2000 $this->date_creation = $this->db->jdate($obj->date_creation);
2001 $this->date_modification = $this->db->jdate($obj->date_modification);
2002 if ($mode !=
"_tmp") {
2003 $this->date_export = $this->db->jdate($obj->date_export);
2005 $this->date_validation = $this->db->jdate($obj->date_validation);
2006 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
2007 $this->import_key = $obj->import_key;
2009 $this->error =
"Error ".$this->db->lasterror();
2010 dol_syslog(__METHOD__.$this->error, LOG_ERR);
2027 $sql =
"SELECT MAX(piece_num) + 1 as max FROM ".$this->db->prefix().$this->table_element.$mode;
2028 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2030 dol_syslog(get_class($this).
"::getNextNumMvt", LOG_DEBUG);
2032 $result = $this->db->query($sql);
2035 $obj = $this->db->fetch_object($result);
2037 $result = $obj->max;
2039 if (empty($result)) {
2044 $this->error =
"Error ".$this->db->lasterror();
2045 dol_syslog(get_class($this).
"::getNextNumMvt ".$this->error, LOG_ERR);
2056 public function getNextNumRef()
2058 global $langs, $conf;
2059 $langs->load(
"accountancy");
2068 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
2069 foreach ($dirmodels as $reldir) {
2073 $mybool = ((bool) @include_once $dir.$file) || $mybool;
2081 $obj =
new $classname();
2083 '@phan-var-force ModeleNumRefBookkeeping $obj';
2085 $numref = $obj->getNextValue($this);
2087 if ($numref !=
"") {
2090 $this->error = $obj->error;
2095 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_BOOKKEEPING_ADDON_NotDefined");
2113 $sql =
"SELECT rowid, doc_date, doc_type,";
2114 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
2115 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
2116 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, journal_label, piece_num,";
2117 $sql .=
" date_creation, tms as date_modification, date_validated as date_validation";
2119 if ($mode !=
"_tmp") {
2120 $sql .=
", date_export";
2122 $sql .=
" FROM ".$this->db->prefix().$this->table_element.$mode;
2123 $sql .=
" WHERE piece_num = ".((int) $piecenum);
2124 $sql .=
" AND entity = " . ((int) $conf->entity);
2127 $result = $this->db->query($sql);
2129 while ($obj = $this->db->fetch_object($result)) {
2132 $line->id = $obj->rowid;
2134 $line->doc_date = $this->db->jdate($obj->doc_date);
2135 $line->doc_type = $obj->doc_type;
2136 $line->doc_ref = $obj->doc_ref;
2137 $line->fk_doc = $obj->fk_doc;
2138 $line->fk_docdet = $obj->fk_docdet;
2139 $line->thirdparty_code = $obj->thirdparty_code;
2140 $line->subledger_account = $obj->subledger_account;
2141 $line->subledger_label = $obj->subledger_label;
2142 $line->numero_compte = $obj->numero_compte;
2143 $line->label_compte = $obj->label_compte;
2144 $line->label_operation = $obj->label_operation;
2145 $line->debit = $obj->debit;
2146 $line->credit = $obj->credit;
2147 $line->montant = $obj->amount;
2148 $line->amount = $obj->amount;
2149 $line->sens = $obj->sens;
2150 $line->code_journal = $obj->code_journal;
2151 $line->journal_label = $obj->journal_label;
2152 $line->piece_num = $obj->piece_num;
2153 $line->date_creation = $obj->date_creation;
2154 $line->date_modification = $obj->date_modification;
2155 if ($mode !=
"_tmp") {
2156 $line->date_export = $obj->date_export;
2158 $line->date_validation = $obj->date_validation;
2160 $this->linesmvt[] = $line;
2163 $this->error =
"Error ".$this->db->lasterror();
2164 dol_syslog(__METHOD__.$this->error, LOG_ERR);
2183 $sql =
"SELECT rowid, doc_date, doc_type,";
2184 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
2185 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
2186 $sql .=
" montant as amount, sens, fk_user_author, import_key, code_journal, piece_num,";
2187 $sql .=
" date_validated as date_validation";
2188 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
2189 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2191 dol_syslog(get_class($this).
"::export_bookkeeping", LOG_DEBUG);
2193 $resql = $this->db->query($sql);
2196 $this->linesexport = array();
2198 $num = $this->db->num_rows($resql);
2199 while ($obj = $this->db->fetch_object($resql)) {
2202 $line->id = $obj->rowid;
2204 $line->doc_date = $this->db->jdate($obj->doc_date);
2205 $line->doc_type = $obj->doc_type;
2206 $line->doc_ref = $obj->doc_ref;
2207 $line->fk_doc = $obj->fk_doc;
2208 $line->fk_docdet = $obj->fk_docdet;
2209 $line->thirdparty_code = $obj->thirdparty_code;
2210 $line->subledger_account = $obj->subledger_account;
2211 $line->subledger_label = $obj->subledger_label;
2212 $line->numero_compte = $obj->numero_compte;
2213 $line->label_compte = $obj->label_compte;
2214 $line->label_operation = $obj->label_operation;
2215 $line->debit = $obj->debit;
2216 $line->credit = $obj->credit;
2217 $line->montant = $obj->amount;
2218 $line->amount = $obj->amount;
2219 $line->sens = $obj->sens;
2220 $line->code_journal = $obj->code_journal;
2221 $line->piece_num = $obj->piece_num;
2222 $line->date_validation = $obj->date_validation;
2224 $this->linesexport[] = $line;
2226 $this->db->free($resql);
2230 $this->error =
"Error ".$this->db->lasterror();
2231 dol_syslog(get_class($this).
"::export_bookkeeping ".$this->error, LOG_ERR);
2251 if (!isset($sql_filter)) {
2257 $tmpBookkeeping =
new self($this->db);
2258 $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}");
2259 $tmpBookkeeping->doc_date = $this->db->jdate($tmpData->doc_date);
2260 $tmpBookkeeping->code_journal = $tmpData->code_journal;
2263 $ref = $tmpData->ref ?: $tmpBookkeeping->getNextNumRef();
2264 if ($direction == 0) {
2268 if ($next_piecenum < 0) {
2274 $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";
2275 $resql = $this->db->query($sql);
2278 $this->errors[] =
'Error '.$this->db->lasterror();
2279 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2284 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
' (doc_date, doc_type, ref,';
2285 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2286 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2287 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num, date_creation)';
2288 $sql .=
' SELECT doc_date, doc_type,' .
"'{$ref}',";
2289 $sql .=
' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
2290 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2291 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.((int) $next_piecenum).
", '".$this->db->idate($now).
"'";
2292 $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);
2293 $sql .= $sql_filter;
2294 $resql = $this->db->query($sql);
2297 $this->errors[] =
'Error '.$this->db->lasterror();
2298 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2303 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2304 $resql = $this->db->query($sql);
2307 $this->errors[] =
'Error '.$this->db->lasterror();
2308 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2311 } elseif ($direction == 1) {
2312 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2313 $resql = $this->db->query($sql);
2316 $this->errors[] =
'Error '.$this->db->lasterror();
2317 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2321 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
'_tmp (doc_date, doc_type, ref,';
2322 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2323 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2324 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)';
2325 $sql .=
' SELECT doc_date, doc_type,' .
"'{$ref}',";
2326 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
2327 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
2328 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num';
2329 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2330 $sql .= $sql_filter;
2331 $resql = $this->db->query($sql);
2334 $this->errors[] =
'Error '.$this->db->lasterror();
2335 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2340 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
'_tmp WHERE piece_num = '.((int) $piece_num).
' AND entity = ' .((int) $conf->entity);
2341 $sql .= $sql_filter;
2342 $resql = $this->db->query($sql);
2345 $this->errors[] =
'Error '.$this->db->lasterror();
2346 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
2351 $this->db->commit();
2354 $this->db->rollback();
2382 public function select_account($selectid, $htmlname =
'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase =
'')
2387 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
2391 $sql =
"SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version";
2392 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as ab";
2393 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as aa ON aa.account_number = ab.numero_compte";
2394 $sql .=
" AND aa.active = 1";
2395 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2396 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2397 $sql .=
" AND ab.entity = " . ((int) $conf->entity);
2398 $sql .=
" ORDER BY account_number ASC";
2400 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2401 $resql = $this->db->query($sql);
2404 $this->error =
"Error ".$this->db->lasterror();
2405 dol_syslog(get_class($this).
"::select_account ".$this->error, LOG_ERR);
2414 while ($obj = $this->db->fetch_object($resql)) {
2417 $select_value_in = $obj->rowid;
2418 $select_value_out = $obj->rowid;
2420 if ($select_in == 1) {
2421 $select_value_in = $obj->account_number;
2423 if ($select_out == 1) {
2424 $select_value_out = $obj->account_number;
2429 if (($selectid !=
'') && $selectid == $select_value_in) {
2430 $selected = $select_value_out;
2433 $options[$select_value_out] = $label;
2436 $out .=
Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0,
'', 0, 0, 0,
'',
'maxwidth300');
2437 $this->db->free($resql);
2453 $sql =
"SELECT root.rowid, root.account_number, root.label as label,";
2454 $sql .=
" parent.rowid as parent_rowid, parent.account_number as parent_account_number, parent.label as parent_label";
2455 $sql .=
" FROM ".$this->db->prefix().
"accounting_account as aa";
2456 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2457 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2458 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as parent ON aa.account_parent = parent.rowid AND parent.active = 1";
2459 $sql .=
" LEFT JOIN ".$this->db->prefix().
"accounting_account as root ON parent.account_parent = root.rowid AND root.active = 1";
2460 $sql .=
" WHERE aa.account_number = '".$this->db->escape($account).
"'";
2461 $sql .=
" AND aa.entity = " . ((int) $conf->entity);
2463 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2464 $resql = $this->db->query($sql);
2467 if ($this->db->num_rows($resql)) {
2468 $obj = $this->db->fetch_object($resql);
2471 $result = array(
'id' => $obj->rowid,
'account_number' => $obj->account_number,
'label' => $obj->label);
2474 $this->error =
"Error ".$this->db->lasterror();
2475 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2494 $sql =
"SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
2495 $sql .=
" FROM ".$this->db->prefix().
"accounting_account as aa ";
2496 $sql .=
" INNER JOIN ".$this->db->prefix().
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
2497 $sql .=
" AND aa.account_number = '".$this->db->escape($account).
"'";
2498 $sql .=
" AND asy.rowid = ".((int) $pcgver);
2499 $sql .=
" AND aa.active = 1";
2500 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
2501 $sql .=
" WHERE aa.entity = " . ((int) $conf->entity);
2503 dol_syslog(get_class($this).
"::select_account", LOG_DEBUG);
2504 $resql = $this->db->query($sql);
2506 $obj = (object) array(
'label' =>
'');
2507 if ($this->db->num_rows($resql)) {
2508 $obj = $this->db->fetch_object($resql);
2510 if (empty($obj->category)) {
2513 return $obj->label.
' ('.$obj->category.
')';
2516 $this->error =
"Error ".$this->db->lasterror();
2517 dol_syslog(__METHOD__.
" ".$this->error, LOG_ERR);
2533 $alias = trim($alias);
2534 $alias = !empty($alias) && strpos($alias,
'.') ===
false ? $alias .
"." : $alias;
2536 if (!isset(self::$can_modify_bookkeeping_sql_cached[$alias]) || $force) {
2542 $sql_list = array();
2543 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2545 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2546 $sql_list[$i] =
"(";
2547 $sql_list[$i] .=
"'".$this->db->idate($fiscal_period[
'date_start']) .
"' <= ".$this->db->sanitize($alias).
"doc_date";
2548 if (!empty($fiscal_period[
'date_end'])) {
2549 $sql_list[$i] .=
" AND ";
2550 $sql_list[$i] .= $this->db->sanitize($alias).
"doc_date <= '" . $this->db->idate($fiscal_period[
'date_end']).
"'";
2552 $sql_list[$i] .=
")";
2556 $sqlsanitized = implode(
' OR ', $sql_list);
2557 self::$can_modify_bookkeeping_sql_cached[$alias] = empty($sql_list) ?
"" :
" AND (".$sqlsanitized.
")";
2560 return self::$can_modify_bookkeeping_sql_cached[$alias];
2582 $result = $bookkeeping->fetch($id,
null, $mode);
2587 if (!empty($conf->cache[
'closed_fiscal_period_cached']) && is_array($conf->cache[
'closed_fiscal_period_cached'])) {
2588 foreach ($conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2589 if ($fiscal_period[
'date_start'] <= $bookkeeping->doc_date && $bookkeeping->doc_date <= $fiscal_period[
'date_end']) {
2603 $result = $bookkeeping->fetch($id,
null, $mode);
2608 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2609 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2610 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'])) {
2634 $accountingLabelOperation =
'';
2637 $truncThirdpartyName = 16;
2640 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2642 $accountingLabelOperation = $thirdpartyname;
2644 if (!empty($reference)) {
2645 $accountingLabelOperation .=
' - '. $reference;
2647 if (!empty($labelaccount)) {
2648 $accountingLabelOperation .=
' - '. $labelaccount;
2650 } elseif (
getDolGlobalInt(
'ACCOUNTING_LABEL_OPERATION_ON_TRANSFER') == 1) {
2651 $truncThirdpartyName = 32;
2654 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2656 $accountingLabelOperation = $thirdpartyname;
2658 if (!empty($reference)) {
2659 $accountingLabelOperation .=
' - '. $reference;
2661 } elseif (
getDolGlobalInt(
'ACCOUNTING_LABEL_OPERATION_ON_TRANSFER') == 2) {
2662 $truncThirdpartyName = 64;
2665 $accountingLabelOperation =
dol_trunc($thirdpartyname, $truncThirdpartyName,
'right',
'UTF-8', 1);
2667 $accountingLabelOperation = $thirdpartyname;
2671 return $accountingLabelOperation;
2691 if (!empty($conf->cache[
'closed_fiscal_period_cached']) && is_array($conf->cache[
'closed_fiscal_period_cached'])) {
2692 foreach ($conf->cache[
'closed_fiscal_period_cached'] as $fiscal_period) {
2693 if ($fiscal_period[
'date_start'] <= $date && $date <= $fiscal_period[
'date_end']) {
2706 if (!empty($conf->cache[
'active_fiscal_period_cached']) && is_array($conf->cache[
'active_fiscal_period_cached'])) {
2707 foreach ($conf->cache[
'active_fiscal_period_cached'] as $fiscal_period) {
2708 if (!empty($fiscal_period[
'date_start']) && $fiscal_period[
'date_start'] <= $date && (empty($fiscal_period[
'date_end']) || $date <= $fiscal_period[
'date_end'])) {
2729 if ($mode ==
'active') {
2730 if (!isset($conf->cache[
'active_fiscal_period_cached']) || $force) {
2731 $sql =
"SELECT date_start, date_end";
2732 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2733 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2734 $sql .=
" AND statut = 0";
2736 $resql = $this->db->query($sql);
2738 $this->errors[] = $this->db->lasterror();
2743 while ($obj = $this->db->fetch_object($resql)) {
2744 $date_start = $this->db->jdate($obj->date_start);
2745 $date_end_base = $this->db->jdate($obj->date_end);
2748 'date_start' => $date_start,
2749 'date_end' => $date_end,
2752 $conf->cache[
'active_fiscal_period_cached'] = $list;
2755 if ($mode ==
'closed') {
2756 if (!isset($conf->cache[
'closed_fiscal_period_cached']) || $force) {
2757 $sql =
"SELECT date_start, date_end";
2758 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2759 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2760 $sql .=
" AND statut = 1";
2762 $resql = $this->db->query($sql);
2764 $this->errors[] = $this->db->lasterror();
2769 while ($obj = $this->db->fetch_object($resql)) {
2770 $date_start = $this->db->jdate($obj->date_start);
2771 $date_end_base = $this->db->jdate($obj->date_end);
2775 'date_start' => $date_start,
2776 'date_end' => $date_end,
2779 $conf->cache[
'closed_fiscal_period_cached'] = $list;
2796 $sql =
"SELECT rowid, label, date_start, date_end, statut";
2797 $sql .=
" FROM " . $this->db->prefix() .
"accounting_fiscalyear";
2798 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2799 $sql .= $this->db->order(
'date_start',
'ASC');
2801 $resql = $this->db->query($sql);
2803 $this->errors[] = $this->db->lasterror();
2807 while ($obj = $this->db->fetch_object($resql)) {
2808 $list[$obj->rowid] = array(
2809 'id' => (
int) $obj->rowid,
2810 'label' => $obj->label,
2811 'date_start' => $this->db->jdate($obj->date_start),
2812 'date_end' => $this->db->jdate($obj->date_end),
2813 'status' => (
int) $obj->statut,
2835 $sql =
"SELECT YEAR(b.doc_date) as year";
2836 for ($i = 1; $i <= 12; $i++) {
2837 $sql .=
", SUM(".$this->db->ifsql(
"MONTH(b.doc_date) = ".((
int) $i),
"1",
"0") .
") AS month".((int) $i);
2839 $sql .=
", COUNT(b.rowid) as total";
2840 $sql .=
" FROM " . $this->db->prefix() . $this->table_element .
" as b";
2841 $sql .=
" WHERE b.doc_date >= '" . $this->db->idate($date_start) .
"'";
2842 $sql .=
" AND b.doc_date <= '" . $this->db->idate($date_end) .
"'";
2843 $sql .=
" AND b.entity IN (" .
getEntity(
'bookkeeping', 0) .
")";
2848 $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)";
2851 $sql .=
" AND date_validated IS NULL";
2854 $sql .=
" GROUP BY YEAR(b.doc_date)";
2855 $sql .= $this->db->order(
"year",
'ASC');
2858 $resql = $this->db->query($sql);
2860 $this->errors[] = $this->db->lasterror();
2864 while ($obj = $this->db->fetch_object($resql)) {
2865 $total += (int) $obj->total;
2867 'year' => (
int) $obj->year,
2869 'total' => (
int) $obj->total,
2871 for ($i = 1; $i <= 12; $i++) {
2872 $year_list[
'count'][$i] = (int) $obj->{
'month' . $i};
2875 $list[] = $year_list;
2878 $this->db->free($resql);
2900 $sql =
" UPDATE " . $this->db->prefix() . $this->table_element;
2901 $sql .=
" SET date_validated = '" . $this->db->idate($now) .
"'";
2902 $sql .=
" WHERE entity = " . ((int) $conf->entity);
2903 $sql .=
" AND DATE(doc_date) >= '" . $this->db->idate($date_start) .
"'";
2904 $sql .=
" AND DATE(doc_date) <= '" . $this->db->idate($date_end) .
"'";
2905 $sql .=
" AND date_validated IS NULL";
2908 $resql = $this->db->query($sql);
2910 $this->errors[] = $this->db->lasterror();
2930 $income_statement_amount = 0;
2932 if (
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')) {
2933 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
2935 $pcg_type_filter = array();
2936 foreach ($accounting_groups_used_for_income_statement as $item) {
2937 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
2941 $sql .=
" t.numero_compte,";
2942 $sql .=
" aa.pcg_type,";
2943 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as accounting_result";
2944 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
2945 $sql .=
' LEFT JOIN ' . $this->db->prefix() .
'accounting_account as aa ON aa.account_number = t.numero_compte';
2946 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
2947 $sql .=
" AND aa.entity = " . ((int) $conf->entity);
2948 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM ' . $this->db->prefix() .
'accounting_system WHERE rowid = ' . ((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')) .
')';
2949 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
2950 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) .
"'";
2951 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
2952 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
2954 $resql = $this->db->query($sql);
2956 $this->errors[] =
'Error ' . $this->db->lasterror();
2957 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
2959 while ($obj = $this->db->fetch_object($resql)) {
2960 $income_statement_amount += $obj->accounting_result;
2965 return (
string) $income_statement_amount;
2977 public function closeFiscalPeriod($fiscal_period_id, $new_fiscal_period_id, $separate_auxiliary_account =
false, $generate_bookkeeping_records =
true)
2979 global $conf, $langs, $user;
2982 $fiscal_period_id = max(0, $fiscal_period_id);
2984 if (empty($fiscal_period_id)) {
2985 $langs->load(
'errors');
2986 $this->errors[] = $langs->trans(
'ErrorBadParameters');
2991 $result = $fiscal_period->fetch($fiscal_period_id);
2993 $this->error = $fiscal_period->error;
2994 $this->errors = $fiscal_period->errors;
2996 } elseif (empty($fiscal_period->id)) {
2997 $langs->loadLangs(array(
'errors',
'compta'));
2998 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
3003 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
3004 if (empty($new_fiscal_period_id)) {
3005 $langs->load(
'errors');
3006 $this->errors[] = $langs->trans(
'ErrorBadParameters').
' - '.$langs->trans(
'AccountancyClosureStep3NewFiscalPeriod');
3009 $new_fiscal_period =
new Fiscalyear($this->db);
3010 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
3012 $this->error = $new_fiscal_period->error;
3013 $this->errors = $new_fiscal_period->errors;
3015 } elseif (empty($new_fiscal_period->id)) {
3016 $langs->loadLangs(array(
'errors',
'compta'));
3017 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
3024 $fiscal_period->statut = Fiscalyear::STATUS_CLOSED;
3025 $fiscal_period->status = Fiscalyear::STATUS_CLOSED;
3026 $result = $fiscal_period->update($user);
3028 $this->error = $fiscal_period->error;
3029 $this->errors = $fiscal_period->errors;
3033 if (!$error && !empty($generate_bookkeeping_records)) {
3035 if (empty($journal_id)) {
3036 $langs->loadLangs(array(
'errors',
'accountancy'));
3037 $this->errors[] = $langs->trans(
'ErrorBadParameters') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
3044 $result = $journal->fetch($journal_id);
3046 $this->error = $journal->error;
3047 $this->errors = $journal->errors;
3049 } elseif ($result == 0) {
3050 $langs->loadLangs(array(
'errors',
'accountancy'));
3051 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'Codejournal') .
' (' . $langs->trans(
'AccountingJournalType9') .
')';
3058 if (!$error && is_object($journal)) {
3059 $accounting_groups_used_for_balance_sheet_account = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT'))),
'strlen');
3060 $accounting_groups_used_for_income_statement = array_filter(array_map(
'trim', explode(
',',
getDolGlobalString(
'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT'))),
'strlen');
3062 $pcg_type_filter = array();
3063 $tmp = array_merge($accounting_groups_used_for_balance_sheet_account, $accounting_groups_used_for_income_statement);
3064 foreach ($tmp as $item) {
3065 $pcg_type_filter[] =
"'" . $this->db->escape($item) .
"'";
3069 $sql .=
" t.numero_compte,";
3070 if ($separate_auxiliary_account) {
3071 $sql .=
" NULLIF(t.subledger_account, '') as subledger_account,";
3073 $sql .=
" aa.pcg_type,";
3074 $sql .=
" (SUM(t.credit) - SUM(t.debit)) as opening_balance";
3075 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
3076 $sql .=
' LEFT JOIN ' . $this->db->prefix() .
'accounting_account as aa ON aa.account_number = t.numero_compte';
3077 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
3078 $sql .=
" AND aa.entity = ". ((int) $conf->entity);
3079 $sql .=
' AND aa.fk_pcg_version IN (SELECT pcg_version FROM '.$this->db->prefix().
'accounting_system WHERE rowid = '.((int)
getDolGlobalInt(
'CHARTOFACCOUNTS')).
')';
3080 $sql .=
' AND aa.pcg_type IN (' . $this->db->sanitize(implode(
',', $pcg_type_filter), 1) .
')';
3081 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
3082 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
3083 $sql .=
' GROUP BY t.numero_compte, aa.pcg_type';
3084 if ($separate_auxiliary_account) {
3085 $sql .=
" , NULLIF(t.subledger_account, '')";
3087 $sql .=
' HAVING (SUM(t.credit) - SUM(t.debit)) != 0 ';
3088 $sql .= $this->db->order(
"t.numero_compte",
"ASC");
3090 $resql = $this->db->query($sql);
3092 $this->errors[] =
'Error ' . $this->db->lasterror();
3093 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3098 $income_statement_amount = 0;
3099 while ($obj = $this->db->fetch_object($resql)) {
3100 if (in_array($obj->pcg_type, $accounting_groups_used_for_income_statement)) {
3101 $income_statement_amount += $obj->opening_balance;
3104 $mt = $obj->opening_balance;
3107 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3109 $bookkeeping->date_lim_reglement =
'';
3110 $bookkeeping->doc_ref = $fiscal_period->label;
3112 $bookkeeping->date_creation = $now;
3113 $bookkeeping->doc_type =
'closure';
3114 $bookkeeping->fk_doc = $fiscal_period->id;
3115 $bookkeeping->fk_docdet = 0;
3116 $bookkeeping->thirdparty_code =
'';
3118 if ($separate_auxiliary_account) {
3119 $bookkeeping->subledger_account = $obj->subledger_account;
3121 $sql .=
" subledger_label";
3122 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
3123 $sql .=
" WHERE subledger_account = '" . $this->db->escape($obj->subledger_account) .
"'";
3124 $sql .=
" ORDER BY doc_date DESC";
3126 $result = $this->db->query($sql);
3128 $this->errors[] =
'Error: ' . $this->db->lasterror();
3129 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3132 $objtmp = $this->db->fetch_object($result);
3133 $bookkeeping->subledger_label = $objtmp->subledger_label;
3135 $bookkeeping->subledger_account =
null;
3136 $bookkeeping->subledger_label =
null;
3139 $bookkeeping->numero_compte = $obj->numero_compte;
3141 $accountingaccount->fetch(0, $obj->numero_compte);
3142 $bookkeeping->label_compte = $accountingaccount->label;
3144 $bookkeeping->label_operation = $new_fiscal_period->label;
3145 $bookkeeping->montant = $mt;
3146 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
3147 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
3148 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
3149 $bookkeeping->code_journal = $journal->code;
3150 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
3151 $bookkeeping->fk_user_author = $user->id;
3152 $bookkeeping->entity = $conf->entity;
3154 $result = $bookkeeping->create($user);
3156 $this->setErrorsFromObject($bookkeeping);
3164 if (!$error && $income_statement_amount != 0) {
3165 $mt = $income_statement_amount;
3167 $accountingaccount->fetch(0,
getDolGlobalString($income_statement_amount < 0 ?
'ACCOUNTING_RESULT_LOSS' :
'ACCOUNTING_RESULT_PROFIT'),
true);
3170 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3172 $bookkeeping->date_lim_reglement =
'';
3173 $bookkeeping->doc_ref = $fiscal_period->label;
3175 $bookkeeping->date_creation = $now;
3176 $bookkeeping->doc_type =
'closure';
3177 $bookkeeping->fk_doc = $fiscal_period->id;
3178 $bookkeeping->fk_docdet = 0;
3179 $bookkeeping->thirdparty_code =
'';
3203 $bookkeeping->subledger_account =
null;
3204 $bookkeeping->subledger_label =
null;
3207 $bookkeeping->numero_compte = $accountingaccount->account_number;
3208 $bookkeeping->label_compte = $accountingaccount->label;
3210 $bookkeeping->label_operation = $new_fiscal_period->label;
3211 $bookkeeping->montant = $mt;
3212 $bookkeeping->sens = ($mt >= 0) ?
'C' :
'D';
3213 $bookkeeping->debit = ($mt < 0) ? -$mt : 0;
3214 $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
3215 $bookkeeping->code_journal = $journal->code;
3216 $bookkeeping->journal_label = $langs->transnoentities($journal->label);
3217 $bookkeeping->fk_user_author = $user->id;
3218 $bookkeeping->entity = $conf->entity;
3220 $result = $bookkeeping->create($user);
3222 $this->setErrorsFromObject($bookkeeping);
3226 $this->db->free($resql);
3232 $this->db->rollback();
3235 $this->db->commit();
3252 global $conf, $langs, $user;
3255 $fiscal_period_id = max(0, $fiscal_period_id);
3256 if (empty($fiscal_period_id)) {
3257 $langs->load(
'errors');
3258 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3262 $result = $fiscal_period->fetch($fiscal_period_id);
3264 $this->error = $fiscal_period->error;
3265 $this->errors = $fiscal_period->errors;
3267 } elseif (empty($fiscal_period->id)) {
3268 $langs->loadLangs(array(
'errors',
'compta'));
3269 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $fiscal_period_id .
')';
3274 $new_fiscal_period_id = max(0, $new_fiscal_period_id);
3275 if (empty($new_fiscal_period_id)) {
3276 $langs->load(
'errors');
3277 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3280 $new_fiscal_period =
new Fiscalyear($this->db);
3281 $result = $new_fiscal_period->fetch($new_fiscal_period_id);
3283 $this->error = $new_fiscal_period->error;
3284 $this->errors = $new_fiscal_period->errors;
3286 } elseif (empty($new_fiscal_period->id)) {
3287 $langs->loadLangs(array(
'errors',
'compta'));
3288 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'FiscalPeriod') .
' (' . $new_fiscal_period_id .
')';
3293 $inventory_journal_id = max(0, $inventory_journal_id);
3294 if (empty($inventory_journal_id)) {
3295 $langs->load(
'errors');
3296 $this->errors[] = $langs->trans(
'ErrorBadParameters');
3301 $result = $inventory_journal->fetch($inventory_journal_id);
3303 $this->error = $inventory_journal->error;
3304 $this->errors = $inventory_journal->errors;
3306 } elseif ($result == 0) {
3307 $langs->loadLangs(array(
'errors',
'accountancy'));
3308 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'InventoryJournal');
3315 $sql =
'SELECT t.rowid';
3316 $sql .=
' FROM ' . $this->db->prefix() . $this->table_element .
' as t';
3317 $sql .=
' WHERE t.entity = ' . ((int) $conf->entity);
3318 $sql .=
" AND code_journal = '" . $this->db->escape($inventory_journal->code) .
"'";
3319 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($date_start) .
"'";
3320 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($date_end) .
"'";
3321 $sql .=
" AND DATE(t.doc_date) >= '" . $this->db->idate($fiscal_period->date_start) .
"'";
3322 $sql .=
" AND DATE(t.doc_date) <= '" . $this->db->idate($fiscal_period->date_end) .
"'";
3324 $resql = $this->db->query($sql);
3326 $this->errors[] =
'Error ' . $this->db->lasterror();
3327 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
3332 while ($obj = $this->db->fetch_object($resql)) {
3334 $result = $bookkeeping->fetch($obj->rowid);
3336 $this->error = $inventory_journal->error;
3337 $this->errors = $inventory_journal->errors;
3340 } elseif ($result == 0) {
3341 $langs->loadLangs(array(
'errors',
'accountancy'));
3342 $this->errors[] = $langs->trans(
'ErrorRecordNotFound') .
' - ' . $langs->trans(
'LineId') .
': ' . $obj->rowid;
3347 $bookkeeping->id = 0;
3348 $bookkeeping->doc_date = $new_fiscal_period->date_start;
3349 $bookkeeping->doc_ref = $new_fiscal_period->label;
3350 $bookkeeping->date_creation = $now;
3351 $bookkeeping->doc_type =
'accounting_reversal';
3352 $bookkeeping->fk_doc = $new_fiscal_period->id;
3353 $bookkeeping->fk_docdet = 0;
3355 $bookkeeping->montant = -$bookkeeping->montant;
3356 $bookkeeping->sens = ($bookkeeping->montant >= 0) ?
'C' :
'D';
3357 $old_debit = $bookkeeping->debit;
3358 $bookkeeping->debit = $bookkeeping->credit;
3359 $bookkeeping->credit = $old_debit;
3361 $bookkeeping->fk_user_author = $user->id;
3362 $bookkeeping->entity = $conf->entity;
3364 $result = $bookkeeping->create($user);
3366 $this->error = $bookkeeping->error;
3367 $this->errors = $bookkeeping->errors;
3372 $this->db->free($resql);
3376 $this->db->rollback();
3379 $this->db->commit();
3393 global $langs, $user;
3403 if ((
int) $accounting_account > 0) {
3404 $accountingaccount->fetch($accounting_account);
3406 foreach ($toselect as
$id) {
3407 if ($bookkeeping->fetch(
$id)) {
3409 $accountcustcode =
'411';
3413 $accountsuppcode =
'401';
3416 if (strpos($bookkeeping->numero_compte, $accountcustcode) === 0 || strpos($bookkeeping->numero_compte, $accountsuppcode) === 0) {
3417 $echecT[]=$bookkeeping->numero_compte;
3421 $bookkeeping->numero_compte = $accountingaccount->account_number;
3422 $bookkeeping->label_compte = $accountingaccount->label;
3424 $result = $bookkeeping->update($user);
3436 $echecImplode = implode(
",", $echecT);
3440 $this->db->rollback();
3444 setEventMessages($nb .
" " . $langs->trans(
'AssignAccountsSuccess'),
null,
'mesgs');
3445 } elseif ($nb > 0) {
3446 setEventMessages($nb .
" " . $langs->trans(
'AssignAccountSuccess'),
null,
'mesgs');
3452 if (!empty($echecImplode)) {
3453 $nbEchec = count(explode(
',', $echecImplode));
3454 setEventMessages($nbEchec == 1 ? $langs->trans(
'NoAccountChangedWithAccountNumber') .
' ' . $echecImplode : $langs->trans(
'NoAccountsChangedWithAccountNumber') .
' ' . $echecImplode,
null,
'errors'
3459 $this->db->rollback();
3462 $this->db->commit();
3475 public function newClone($piecenum, $code_journal, $docdate)
3482 $accountingJournal->fetch(0, $code_journal);
3486 $periodeFiscal = $bookKeepingValid->validBookkeepingDate($docdate);
3487 if ($periodeFiscal < 0) {
3490 } elseif ($periodeFiscal == 0) {
3492 setEventMessages($langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod'),
null,
'errors');
3494 setEventMessages($langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod'),
null,
'errors');
3495 header(
"Location: " . $_SERVER[
'HTTP_REFERER']);
3502 $bookKeepingInstance =
new BookKeeping($this->db);
3503 $pieceNumNext = $bookKeepingInstance->getNextNumMvt();
3506 $sqlRowidClone =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE piece_num = ".((int) $piecenum);
3507 $resqlRowidClone = $this->db->query($sqlRowidClone);
3509 if ($resqlRowidClone) {
3510 while ($objRowidClone = $this->db->fetch_object($resqlRowidClone)) {
3511 $cloneId[] = $objRowidClone->rowid;
3514 foreach ($cloneId as $toselectid) {
3516 if ($bookKeeping->fetch($toselectid)) {
3517 $code_journal =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $code_journal : $bookKeeping->code_journal;
3518 $journal_label =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $accountingJournal->label : $bookKeeping->journal_label;
3520 $sql =
"SELECT piece_num, label_operation, numero_compte, label_compte, doc_type, code_journal, fk_user_author, doc_ref,";
3521 $sql .=
" fk_doc, fk_docdet, debit, credit, journal_label, sens, montant, subledger_account, subledger_label";
3522 $sql .=
" FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping";
3523 $sql .=
" WHERE rowid = " . ((int) $toselectid);
3524 $resql = $this->db->query($sql);
3527 while ($obj = $this->db->fetch_object($resql)) {
3528 $docRef = $langs->trans(
'CloneOf', $obj->doc_ref);
3530 $sql_insert =
"INSERT INTO " . MAIN_DB_PREFIX .
"accounting_bookkeeping";
3531 $sql_insert .=
" (piece_num, label_operation, numero_compte, label_compte, doc_type, code_journal, doc_date, fk_user_author, doc_ref,";
3532 $sql_insert .=
" fk_doc, fk_docdet, debit, credit, date_creation, journal_label, sens, montant, subledger_account, subledger_label)";
3533 $sql_insert .=
" VALUES";
3534 $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) .
"', ";
3535 $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) .
"')";
3537 $resqlInsert = $this->db->query($sql_insert);
3540 setEventMessages($langs->trans(
'CloningSuccess', $pieceNumNext),
null,
'mesgs');
3542 setEventMessages($langs->trans(
'CloningFailed') . $this->db->lasterror(),
null,
'errors');
3552 $this->db->rollback();
3555 $this->db->commit();
3570 global $langs, $user;
3576 if (empty($docdate)) {
3580 $idImplodeSelect = implode(
',', $toselect);
3583 $sqlPieceNum =
"SELECT DISTINCT(piece_num) FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE rowid IN (".$this->db->sanitize($idImplodeSelect).
")";
3584 $resqlPieceNum = $this->db->query($sqlPieceNum);
3586 if ($resqlPieceNum) {
3587 while ($objPieceNum = $this->db->fetch_object($resqlPieceNum)) {
3588 $pieceNumT[] = $objPieceNum->piece_num;
3591 foreach ($pieceNumT as $pieceNum) {
3593 $accountingJournal->fetch(0, $code_journal);
3595 $periodeFiscal = $bookKeepingValid->validBookkeepingDate($docdate);
3596 if ($periodeFiscal < 0) {
3598 } elseif ($periodeFiscal == 0) {
3600 setEventMessages($langs->trans(
'ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod'),
null,
'errors');
3602 setEventMessages($langs->trans(
'ErrorBookkeepingDocDateNotOnActiveFiscalPeriod'),
null,
'errors');
3603 header(
"Location: " . $_SERVER[
'HTTP_REFERER']);
3608 $bookKeepingInstance =
new BookKeeping($this->db);
3609 $pieceNumNext = $bookKeepingInstance->getNextNumMvt();
3611 $sqlRowidClone =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE piece_num = $pieceNum";
3612 $resqlRowidClone = $this->db->query($sqlRowidClone);
3614 if ($resqlRowidClone) {
3615 while ($objRowidClone = $this->db->fetch_object($resqlRowidClone)) {
3616 $cloneId[] = $objRowidClone->rowid;
3619 foreach ($cloneId as $toselectid) {
3621 if ($bookKeeping->fetch($toselectid)) {
3622 $code_journal =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $code_journal : $bookKeeping->code_journal;
3623 $journal_label =
getDolGlobalString(
'ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL') ? $accountingJournal->label : $bookKeeping->journal_label;
3624 $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";
3625 $sql .=
" FROM ".$this->db->prefix().
"accounting_bookkeeping WHERE rowid = " . ((int) $toselectid);
3627 $resql = $this->db->query($sql);
3629 while ($obj = $this->db->fetch_object($resql)) {
3630 $docRef = $langs->trans(
"CloneOf", $obj->doc_ref);
3632 $sql_insert =
"INSERT INTO ".$this->db->prefix().
"accounting_bookkeeping (";
3633 $sql_insert .=
" piece_num";
3634 $sql_insert .=
", label_operation";
3635 $sql_insert .=
", numero_compte";
3636 $sql_insert .=
", label_compte";
3637 $sql_insert .=
", subledger_account";
3638 $sql_insert .=
", subledger_label";
3639 $sql_insert .=
", doc_type";
3640 $sql_insert .=
", code_journal";
3641 $sql_insert .=
", doc_date";
3642 $sql_insert .=
", date_creation";
3643 $sql_insert .=
", fk_user_author";
3644 $sql_insert .=
", doc_ref";
3645 $sql_insert .=
", fk_doc";
3646 $sql_insert .=
", fk_docdet";
3647 $sql_insert .=
", debit";
3648 $sql_insert .=
", credit";
3649 $sql_insert .=
", journal_label";
3650 $sql_insert .=
", sens";
3651 $sql_insert .=
", montant";
3653 $sql_insert .=
" VALUES (";
3654 $sql_insert .= $pieceNumNext;
3655 $sql_insert .=
", '" . $this->db->escape($obj->label_operation) .
"'";
3656 $sql_insert .=
", '" . $this->db->escape($obj->numero_compte) .
"'";
3657 $sql_insert .=
", '" . $this->db->escape($obj->label_compte) .
"'";
3658 $sql_insert .=
", '" . $this->db->escape($obj->subledger_account) .
"'";
3659 $sql_insert .=
", '" . $this->db->escape($obj->subledger_label) .
"'";
3660 $sql_insert .=
", ''";
3661 $sql_insert .=
", '" . $this->db->escape($code_journal) .
"'";
3662 $sql_insert .=
", '" . $this->db->idate($docdate).
"'";
3663 $sql_insert .=
", '" . $this->db->idate($now).
"'";
3664 $sql_insert .=
", ".($user->id > 0 ? ((int) $user->id) :
"NULL");
3665 $sql_insert .=
", '" . $this->db->escape($docRef) .
"'";
3666 $sql_insert .=
", 0";
3667 $sql_insert .=
", 0";
3668 $sql_insert .=
", " . (float) $obj->debit;
3669 $sql_insert .=
", " . (float) $obj->credit;
3670 $sql_insert .=
", '" . $this->db->escape($journal_label) .
"'";
3671 $sql_insert .=
", '" . $this->db->escape($obj->sens) .
"'";
3672 $sql_insert .=
", " . (float) $obj->montant;
3675 $resqlInsert = $this->db->query($sql_insert);
3678 setEventMessages($langs->trans(
'CloningSuccess', $pieceNumNext),
null,
'mesgs');
3692 $this->db->rollback();
3695 $this->db->commit();
3711 global $langs, $user;
3716 if (empty($docdate)) {
3721 $accountingJournal->fetch(0, $code_journal);
3724 $sqlAlreadyExtourne =
"SELECT DISTINCT(piece_num) FROM " .MAIN_DB_PREFIX.
"accounting_bookkeeping WHERE label_operation LIKE '%Extourne%'";
3725 $resqlAlreadyExtourne = $this->db->query($sqlAlreadyExtourne);
3726 $alreadyExtourneT = array();
3727 if ($resqlAlreadyExtourne) {
3728 while ($obj4 = $this->db->fetch_object($resqlAlreadyExtourne)) {
3729 $alreadyExtourneT []= $obj4->piece_num;
3733 $idImplode = implode(
',', $toselect);
3734 $sql1 =
"SELECT DISTINCT(piece_num) from " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE rowid IN (".$this->db->sanitize($idImplode).
")";
3735 $resql1 = $this->db->query($sql1);
3739 while ($obj1 = $this->db->fetch_object($resql1)) {
3740 $pieceNumT [] = $obj1->piece_num;
3743 $i = mt_rand(0, 100);
3744 foreach ($pieceNumT as $pieceNum) {
3745 $newBookKeepingInstance =
new BookKeeping($this->db);
3746 $pieceNumNext = $newBookKeepingInstance->getNextNumMvt();
3748 $sql2 =
"SELECT rowid FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE piece_num = ".((int) $pieceNum);
3749 $resql2 = $this->db->query($sql2);
3752 while ($obj2 = $this->db->fetch_object($resql2)) {
3753 $extourneIds [] = $obj2->rowid;
3756 foreach ($extourneIds as $extourneId) {
3760 if ($bookKeeping->fetch($extourneId)) {
3761 if (in_array($bookKeeping->piece_num, $alreadyExtourneT)) {
3762 setEventMessages($langs->trans(
"AlreadyReturnedAccount", $bookKeeping->piece_num),
null,
'errors');
3764 $newBookKeeping->debit = $bookKeeping->credit;
3765 $newBookKeeping->credit = $bookKeeping->debit;
3766 if ($bookKeeping->sens ==
'D') {
3767 $newBookKeeping->sens =
'C';
3769 $newBookKeeping->sens =
'D';
3772 $newBookKeeping->label_operation = $langs->trans(
"ReturnAccount") .
" " . $bookKeeping->piece_num .
" - " . $bookKeeping->numero_compte .
" - " .
date(
'd/m/Y',
dol_now()) .
" - " . $i;
3774 $newBookKeeping->numero_compte = $bookKeeping->numero_compte;
3775 $newBookKeeping->label_compte = $bookKeeping->label_compte;
3776 $newBookKeeping->doc_type = $bookKeeping->doc_type;
3777 $newBookKeeping->code_journal = $bookKeeping->code_journal;
3778 $newBookKeeping->doc_date = $docdate;
3779 $newBookKeeping->fk_user_author = $user->id;
3780 $newBookKeeping->doc_ref = $bookKeeping->doc_ref;
3781 $newBookKeeping->montant = $bookKeeping->montant;
3782 $newBookKeeping->journal_label = $bookKeeping->journal_label;
3783 $newBookKeeping->subledger_account = $bookKeeping->subledger_account;
3784 $newBookKeeping->subledger_label = $bookKeeping->subledger_label;
3786 $createResult = $newBookKeeping->create($user);
3788 if ($createResult >= 0) {
3789 $newBookKeeping->piece_num = $pieceNumNext;
3790 $newBookKeeping->fk_doc = $bookKeeping->fk_doc;
3791 $newBookKeeping->fk_docdet = $bookKeeping->fk_docdet;
3792 $newBookKeeping->update($user);
3793 setEventMessages($langs->trans(
"SuccessReturnedAccount", $bookKeeping->piece_num),
null,
'mesgs');
3795 setEventMessages($langs->trans(
"ErrorWhileCreating", $newBookKeeping->error), $newBookKeeping->errors,
'errors');
3807 $this->db->rollback();
3810 $this->db->commit();
3829 public $doc_date =
null;
3853 public $thirdparty_code;
3858 public $subledger_account;
3863 public $subledger_label;
3868 public $numero_compte;
3873 public $label_compte;
3878 public $label_operation;
3904 public $multicurrency_amount;
3909 public $multicurrency_code;
3919 public $lettering_code;
3924 public $date_lettering;
3929 public $fk_user_author;
3940 public $code_journal;
3945 public $journal_label;
3954 public $date_export;
3959 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...
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.
dolBuildUrl($url, $params=[], $addtoken=false)
Return path of url.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
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.
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as date