28 require_once DOL_DOCUMENT_ROOT .
'/core/class/commonobject.class.php';
43 public $errors = array();
48 public $element =
'accountingbookkeeping';
53 public $table_element =
'accounting_bookkeeping';
63 public $lines = array ();
71 public $date_lim_reglement;
96 public $thirdparty_code;
101 public $subledger_account;
106 public $subledger_label;
111 public $numero_compte;
116 public $label_compte;
121 public $label_operation;
130 public $fk_user_author;
133 public $code_journal;
134 public $journal_label;
156 global $conf, $langs;
163 if (isset($this->doc_type)) {
164 $this->doc_type = trim($this->doc_type);
166 if (isset($this->doc_ref)) {
167 $this->doc_ref = trim($this->doc_ref);
169 if (isset($this->fk_doc)) {
170 $this->fk_doc = trim($this->fk_doc);
172 if (isset($this->fk_docdet)) {
173 $this->fk_docdet = trim($this->fk_docdet);
175 if (isset($this->thirdparty_code)) {
176 $this->thirdparty_code = trim($this->thirdparty_code);
178 if (isset($this->subledger_account)) {
179 $this->subledger_account = trim($this->subledger_account);
181 if (isset($this->subledger_label)) {
182 $this->subledger_label = trim($this->subledger_label);
184 if (isset($this->numero_compte)) {
185 $this->numero_compte = trim($this->numero_compte);
187 if (isset($this->label_compte)) {
188 $this->label_compte = trim($this->label_compte);
190 if (isset($this->label_operation)) {
191 $this->label_operation = trim($this->label_operation);
193 if (isset($this->debit)) {
194 $this->debit = trim($this->debit);
196 if (isset($this->credit)) {
197 $this->credit = trim($this->credit);
199 if (isset($this->montant)) {
200 $this->montant = trim($this->montant);
202 if (isset($this->sens)) {
203 $this->sens = trim($this->sens);
205 if (isset($this->fk_user_author)) {
206 $this->fk_user_author = trim($this->fk_user_author);
208 if (isset($this->import_key)) {
209 $this->import_key = trim($this->import_key);
211 if (isset($this->code_journal)) {
212 $this->code_journal = trim($this->code_journal);
214 if (isset($this->journal_label)) {
215 $this->journal_label = trim($this->journal_label);
217 if (isset($this->piece_num)) {
218 $this->piece_num = trim($this->piece_num);
220 if (empty($this->debit)) $this->debit = 0;
221 if (empty($this->credit)) $this->credit = 0;
224 if (empty($this->numero_compte) || $this->numero_compte ==
'-1' || $this->numero_compte ==
'NotDefined')
226 $langs->loadLangs(array(
"errors"));
227 if (in_array($this->doc_type, array(
'bank',
'expense_report')))
229 $this->errors[]=$langs->trans(
'ErrorFieldAccountNotDefinedForBankLine', $this->fk_docdet, $this->doc_type);
234 $mesg=$this->doc_ref.
', '.$langs->trans(
"AccountAccounting").
': '.$this->numero_compte;
235 if ($this->subledger_account && $this->subledger_account != $this->numero_compte)
237 $mesg.=
', '.$langs->trans(
"SubledgerAccount").
': '.$this->subledger_account;
239 $this->errors[]=$langs->trans(
'ErrorFieldAccountNotDefinedForLine', $mesg);
247 $this->piece_num = 0;
254 $sql =
"SELECT count(*) as nb";
255 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
256 $sql .=
" WHERE doc_type = '" . $this->db->escape($this->doc_type) .
"'";
257 $sql .=
" AND fk_doc = " . $this->fk_doc;
259 $sql .=
" AND numero_compte = '" . $this->db->escape($this->numero_compte) .
"'";
260 $sql .=
" AND label_operation = '" . $this->db->escape($this->label_operation) .
"'";
261 $sql .=
" AND entity IN (" .
getEntity(
'accountancy') .
")";
263 $resql = $this->db->query($sql);
266 $row = $this->db->fetch_object(
$resql);
270 $sqlnum =
"SELECT piece_num";
271 $sqlnum .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
272 $sqlnum .=
" WHERE doc_type = '" . $this->db->escape($this->doc_type) .
"'";
273 $sqlnum .=
" AND fk_docdet = " . $this->db->escape($this->fk_docdet);
274 $sqlnum .=
" AND doc_ref = '" . $this->db->escape($this->doc_ref) .
"'";
275 $sqlnum .=
" AND entity IN (" .
getEntity(
'accountancy') .
")";
277 dol_syslog(get_class($this) .
":: create sqlnum=" . $sqlnum, LOG_DEBUG);
278 $resqlnum = $this->db->query($sqlnum);
280 $objnum = $this->db->fetch_object($resqlnum);
281 $this->piece_num = $objnum->piece_num;
283 dol_syslog(get_class($this) .
":: create this->piece_num=" . $this->piece_num, LOG_DEBUG);
284 if (empty($this->piece_num)) {
285 $sqlnum =
"SELECT MAX(piece_num)+1 as maxpiecenum";
286 $sqlnum .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
287 $sqlnum .=
" WHERE entity IN (" .
getEntity(
'accountancy') .
")";
289 dol_syslog(get_class($this) .
":: create sqlnum=" . $sqlnum, LOG_DEBUG);
290 $resqlnum = $this->db->query($sqlnum);
292 $objnum = $this->db->fetch_object($resqlnum);
293 $this->piece_num = $objnum->maxpiecenum;
296 dol_syslog(get_class($this) .
":: create this->piece_num=" . $this->piece_num, LOG_DEBUG);
297 if (empty($this->piece_num)) {
298 $this->piece_num = 1;
303 $sql =
"INSERT INTO " . MAIN_DB_PREFIX . $this->table_element .
" (";
305 $sql .=
", date_lim_reglement";
306 $sql .=
", doc_type";
309 $sql .=
", fk_docdet";
310 $sql .=
", thirdparty_code";
311 $sql .=
", subledger_account";
312 $sql .=
", subledger_label";
313 $sql .=
", numero_compte";
314 $sql .=
", label_compte";
315 $sql .=
", label_operation";
320 $sql .=
", fk_user_author";
321 $sql .=
", date_creation";
322 $sql .=
", code_journal";
323 $sql .=
", journal_label";
324 $sql .=
", piece_num";
326 $sql .=
") VALUES (";
327 $sql .=
"'" . $this->db->idate($this->doc_date) .
"'";
328 $sql .=
", ".(! isset($this->date_lim_reglement) ||
dol_strlen($this->date_lim_reglement) == 0 ?
'NULL' :
"'" . $this->db->idate($this->date_lim_reglement) .
"'");
329 $sql .=
",'" . $this->db->escape($this->doc_type) .
"'";
330 $sql .=
",'" . $this->db->escape($this->doc_ref) .
"'";
331 $sql .=
"," . $this->fk_doc;
332 $sql .=
"," . $this->fk_docdet;
333 $sql .=
",'" . $this->db->escape($this->thirdparty_code) .
"'";
334 $sql .=
",'" . $this->db->escape($this->subledger_account) .
"'";
335 $sql .=
",'" . $this->db->escape($this->subledger_label) .
"'";
336 $sql .=
",'" . $this->db->escape($this->numero_compte) .
"'";
337 $sql .=
",'" . $this->db->escape($this->label_compte) .
"'";
338 $sql .=
",'" . $this->db->escape($this->label_operation) .
"'";
339 $sql .=
"," . $this->debit;
340 $sql .=
"," . $this->credit;
341 $sql .=
"," . $this->montant;
342 $sql .=
",'" . $this->db->escape($this->sens) .
"'";
343 $sql .=
",'" . $this->db->escape($this->fk_user_author) .
"'";
344 $sql .=
",'" . $this->db->idate($now).
"'";
345 $sql .=
",'" . $this->db->escape($this->code_journal) .
"'";
346 $sql .=
",'" . $this->db->escape($this->journal_label) .
"'";
347 $sql .=
"," . $this->db->escape($this->piece_num);
348 $sql .=
", " . (! isset($this->entity) ? $conf->entity : $this->entity);
351 dol_syslog(get_class($this) .
":: create sql=" . $sql, LOG_DEBUG);
352 $resql = $this->db->query($sql);
354 $id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
362 $this->errors[] =
'Error Create Error ' . $result .
' lecture ID';
363 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
368 $this->errors[] =
'Error ' . $this->db->lasterror();
369 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
374 $this->error=
'BookkeepingRecordAlreadyExists';
375 dol_syslog(__METHOD__ .
' ' . $this->error, LOG_WARNING);
380 $this->errors[] =
'Error ' . $this->db->lasterror();
381 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
396 $this->db->rollback();
414 function getNomUrl($withpicto=0, $option=
'', $notooltip=0, $morecss=
'', $save_lastsearch_value=-1)
416 global $db, $conf, $langs;
417 global $dolibarr_main_authentication, $dolibarr_main_demo;
420 if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;
425 $label =
'<u>' . $langs->trans(
"Transaction") .
'</u>';
427 $label.=
'<b>' . $langs->trans(
'Ref') .
':</b> ' . $this->piece_num;
429 $url = DOL_URL_ROOT.
'/accountancy/bookkeeping/card.php?piece_num='.$this->piece_num;
431 if ($option !=
'nolink')
434 $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
435 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values=1;
436 if ($add_save_lastsearch_values) $url.=
'&save_lastsearch_values=1';
440 if (empty($notooltip))
442 if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
444 $label=$langs->trans(
"ShowTransaction");
445 $linkclose.=
' alt="'.dol_escape_htmltag($label, 1).
'"';
447 $linkclose.=
' title="'.dol_escape_htmltag($label, 1).
'"';
448 $linkclose.=
' class="classfortooltip'.($morecss?
' '.$morecss:
'').
'"';
450 else $linkclose = ($morecss?
' class="'.$morecss.
'"':
'');
452 $linkstart =
'<a href="'.$url.
'"';
453 $linkstart.=$linkclose.
'>';
456 $result .= $linkstart;
457 if ($withpicto) $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);
458 if ($withpicto != 2) $result.= $this->piece_num;
483 if (isset($this->doc_type)) {
484 $this->doc_type = trim($this->doc_type);
486 if (isset($this->doc_ref)) {
487 $this->doc_ref = trim($this->doc_ref);
489 if (isset($this->fk_doc)) {
490 $this->fk_doc = trim($this->fk_doc);
492 if (isset($this->fk_docdet)) {
493 $this->fk_docdet = trim($this->fk_docdet);
495 if (isset($this->thirdparty_code)) {
496 $this->thirdparty_code = trim($this->thirdparty_code);
498 if (isset($this->subledger_account)) {
499 $this->subledger_account = trim($this->subledger_account);
501 if (isset($this->subledger_label)) {
502 $this->subledger_label = trim($this->subledger_label);
504 if (isset($this->numero_compte)) {
505 $this->numero_compte = trim($this->numero_compte);
507 if (isset($this->label_compte)) {
508 $this->label_compte = trim($this->label_compte);
510 if (isset($this->label_operation)) {
511 $this->label_operation = trim($this->label_operation);
513 if (isset($this->debit)) {
514 $this->debit = trim($this->debit);
516 if (isset($this->credit)) {
517 $this->credit = trim($this->credit);
519 if (isset($this->montant)) {
520 $this->montant = trim($this->montant);
522 if (isset($this->sens)) {
523 $this->sens = trim($this->sens);
525 if (isset($this->fk_user_author)) {
526 $this->fk_user_author = trim($this->fk_user_author);
528 if (isset($this->import_key)) {
529 $this->import_key = trim($this->import_key);
531 if (isset($this->code_journal)) {
532 $this->code_journal = trim($this->code_journal);
534 if (isset($this->journal_label)) {
535 $this->journal_label = trim($this->journal_label);
537 if (isset($this->piece_num)) {
538 $this->piece_num = trim($this->piece_num);
540 if (empty($this->debit)) $this->debit = 0;
541 if (empty($this->credit)) $this->credit = 0;
543 $this->debit =
price2num($this->debit,
'MT');
544 $this->credit =
price2num($this->credit,
'MT');
552 $sql =
'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . $mode.
'(';
554 $sql .=
'date_lim_reglement,';
558 $sql .=
'fk_docdet,';
559 $sql .=
'thirdparty_code,';
560 $sql .=
'subledger_account,';
561 $sql .=
'subledger_label,';
562 $sql .=
'numero_compte,';
563 $sql .=
'label_compte,';
564 $sql .=
'label_operation,';
569 $sql .=
'fk_user_author,';
570 $sql .=
'date_creation,';
571 $sql .=
'code_journal,';
572 $sql .=
'journal_label,';
573 $sql .=
'piece_num,';
575 $sql .=
') VALUES (';
576 $sql .=
' ' . (! isset($this->doc_date) ||
dol_strlen($this->doc_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->doc_date) .
"'") .
',';
577 $sql .=
' ' . (! isset($this->date_lim_reglement) ||
dol_strlen($this->date_lim_reglement) == 0 ?
'NULL' :
"'" . $this->db->idate($this->date_lim_reglement) .
"'") .
',';
578 $sql .=
' ' . (! isset($this->doc_type) ?
'NULL' :
"'" . $this->db->escape($this->doc_type) .
"'") .
',';
579 $sql .=
' ' . (! isset($this->doc_ref) ?
'NULL' :
"'" . $this->db->escape($this->doc_ref) .
"'") .
',';
580 $sql .=
' ' . (empty($this->fk_doc) ?
'0' : $this->fk_doc) .
',';
581 $sql .=
' ' . (empty($this->fk_docdet) ?
'0' : $this->fk_docdet) .
',';
582 $sql .=
' ' . (! isset($this->thirdparty_code) ?
'NULL' :
"'" . $this->db->escape($this->thirdparty_code) .
"'") .
',';
583 $sql .=
' ' . (! isset($this->subledger_account) ?
'NULL' :
"'" . $this->db->escape($this->subledger_account) .
"'") .
',';
584 $sql .=
' ' . (! isset($this->subledger_label) ?
'NULL' :
"'" . $this->db->escape($this->subledger_label) .
"'") .
',';
585 $sql .=
' ' . (! isset($this->numero_compte) ?
'NULL' :
"'" . $this->db->escape($this->numero_compte) .
"'") .
',';
586 $sql .=
' ' . (! isset($this->label_compte) ?
'NULL' :
"'" . $this->db->escape($this->label_compte) .
"'") .
',';
587 $sql .=
' ' . (! isset($this->label_operation) ?
'NULL' :
"'" . $this->db->escape($this->label_operation) .
"'") .
',';
588 $sql .=
' ' . (! isset($this->debit) ?
'NULL' : $this->debit ).
',';
589 $sql .=
' ' . (! isset($this->credit) ?
'NULL' : $this->credit ).
',';
590 $sql .=
' ' . (! isset($this->montant) ?
'NULL' : $this->montant ).
',';
591 $sql .=
' ' . (! isset($this->sens) ?
'NULL' :
"'" . $this->db->escape($this->sens) .
"'") .
',';
592 $sql .=
' ' . $user->id .
',';
593 $sql .=
' ' .
"'" . $this->db->idate($now) .
"',";
594 $sql .=
' ' . (empty($this->code_journal) ?
'NULL' :
"'" . $this->db->escape($this->code_journal) .
"'") .
',';
595 $sql .=
' ' . (empty($this->journal_label) ?
'NULL' :
"'" . $this->db->escape($this->journal_label) .
"'") .
',';
596 $sql .=
' ' . (empty($this->piece_num) ?
'NULL' : $this->db->escape($this->piece_num)).
',';
597 $sql .=
' ' . (! isset($this->entity) ? $conf->entity : $this->entity);
602 $resql = $this->db->query($sql);
605 $this->errors[] =
'Error ' . $this->db->lasterror();
606 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
610 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element . $mode);
625 $this->db->rollback();
644 public function fetch($id, $ref = null, $mode=
'')
652 $sql .=
" t.doc_date,";
653 $sql .=
" t.date_lim_reglement,";
654 $sql .=
" t.doc_type,";
655 $sql .=
" t.doc_ref,";
656 $sql .=
" t.fk_doc,";
657 $sql .=
" t.fk_docdet,";
658 $sql .=
" t.thirdparty_code,";
659 $sql .=
" t.subledger_account,";
660 $sql .=
" t.subledger_label,";
661 $sql .=
" t.numero_compte,";
662 $sql .=
" t.label_compte,";
663 $sql .=
" t.label_operation,";
665 $sql .=
" t.credit,";
666 $sql .=
" t.montant,";
668 $sql .=
" t.fk_user_author,";
669 $sql .=
" t.import_key,";
670 $sql .=
" t.code_journal,";
671 $sql .=
" t.journal_label,";
672 $sql .=
" t.piece_num,";
673 $sql .=
" t.date_creation";
674 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element.$mode.
' as t';
675 $sql .=
' WHERE 1 = 1';
676 $sql .=
" AND entity IN (" .
getEntity(
'accountancy') .
")";
678 $sql .=
' AND t.ref = ' .
'\'' . $ref .
'\'';
680 $sql .=
' AND t.rowid = ' . $id;
683 $resql = $this->db->query($sql);
685 $numrows = $this->db->num_rows(
$resql);
687 $obj = $this->db->fetch_object(
$resql);
689 $this->
id = $obj->rowid;
691 $this->doc_date = $this->db->jdate($obj->doc_date);
692 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
693 $this->doc_type = $obj->doc_type;
694 $this->doc_ref = $obj->doc_ref;
695 $this->fk_doc = $obj->fk_doc;
696 $this->fk_docdet = $obj->fk_docdet;
697 $this->thirdparty_code = $obj->thirdparty_code;
698 $this->subledger_account = $obj->subledger_account;
699 $this->subledger_label = $obj->subledger_label;
700 $this->numero_compte = $obj->numero_compte;
701 $this->label_compte = $obj->label_compte;
702 $this->label_operation = $obj->label_operation;
703 $this->debit = $obj->debit;
704 $this->credit = $obj->credit;
705 $this->montant = $obj->montant;
706 $this->sens = $obj->sens;
707 $this->fk_user_author = $obj->fk_user_author;
708 $this->import_key = $obj->import_key;
709 $this->code_journal = $obj->code_journal;
710 $this->journal_label = $obj->journal_label;
711 $this->piece_num = $obj->piece_num;
712 $this->date_creation = $this->db->jdate($obj->date_creation);
722 $this->errors[] =
'Error ' . $this->db->lasterror();
723 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
742 public function fetchAllByAccount($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
748 $this->lines = array();
752 $sql .=
" t.doc_date,";
753 $sql .=
" t.doc_type,";
754 $sql .=
" t.doc_ref,";
755 $sql .=
" t.fk_doc,";
756 $sql .=
" t.fk_docdet,";
757 $sql .=
" t.thirdparty_code,";
758 $sql .=
" t.subledger_account,";
759 $sql .=
" t.subledger_label,";
760 $sql .=
" t.numero_compte,";
761 $sql .=
" t.label_compte,";
762 $sql .=
" t.label_operation,";
764 $sql .=
" t.credit,";
765 $sql .=
" t.montant,";
767 $sql .=
" t.multicurrency_amount,";
768 $sql .=
" t.multicurrency_code,";
769 $sql .=
" t.lettering_code,";
770 $sql .=
" t.date_lettering,";
771 $sql .=
" t.fk_user_author,";
772 $sql .=
" t.import_key,";
773 $sql .=
" t.code_journal,";
774 $sql .=
" t.journal_label,";
775 $sql .=
" t.piece_num,";
776 $sql .=
" t.date_creation";
778 $sqlwhere = array ();
779 if (count($filter) > 0) {
780 foreach ( $filter as $key => $value ) {
781 if ($key ==
't.doc_date') {
782 $sqlwhere[] = $key .
'=\'' . $this->db->idate($value) .
'\'';
783 } elseif ($key ==
't.doc_date>=' || $key ==
't.doc_date<=') {
784 $sqlwhere[] = $key .
'\'' . $this->db->idate($value) .
'\'';
785 } elseif ($key ==
't.numero_compte>=' || $key ==
't.numero_compte<=' || $key ==
't.subledger_account>=' || $key ==
't.subledger_account<=') {
786 $sqlwhere[] = $key .
'\'' . $this->db->escape($value) .
'\'';
787 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
788 $sqlwhere[] = $key .
'=' . $value;
789 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
790 $sqlwhere[] = $key .
' LIKE \'' . $this->db->escape($value) .
'%\'';
791 } elseif ($key ==
't.date_creation>=' || $key ==
't.date_creation<=') {
792 $sqlwhere[] = $key .
'\'' . $this->db->idate($value) .
'\'';
793 } elseif ($key ==
't.credit' || $key ==
't.debit') {
800 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
801 $sql .=
' WHERE 1 = 1';
802 $sql .=
" AND entity IN (" .
getEntity(
'accountancy') .
")";
803 if (count($sqlwhere) > 0) {
804 $sql .=
' AND ' . implode(
' ' . $filtermode .
' ', $sqlwhere);
807 $sql .=
' ORDER BY t.numero_compte ASC';
808 if (! empty($sortfield)) {
809 $sql .=
', ' . $sortfield .
' ' .$sortorder;
811 if (! empty($limit)) {
812 $sql .=
' ' . $this->db->plimit($limit + 1, $offset);
815 $resql = $this->db->query($sql);
817 $num = $this->db->num_rows(
$resql);
820 while (($obj = $this->db->fetch_object(
$resql)) && (empty($limit) || $i < min($limit, $num))) {
823 $line->id = $obj->rowid;
825 $line->doc_date = $this->db->jdate($obj->doc_date);
826 $line->doc_type = $obj->doc_type;
827 $line->doc_ref = $obj->doc_ref;
828 $line->fk_doc = $obj->fk_doc;
829 $line->fk_docdet = $obj->fk_docdet;
830 $line->thirdparty_code = $obj->thirdparty_code;
831 $line->subledger_account = $obj->subledger_account;
832 $line->subledger_label = $obj->subledger_label;
833 $line->numero_compte = $obj->numero_compte;
834 $line->label_compte = $obj->label_compte;
835 $line->label_operation = $obj->label_operation;
836 $line->debit = $obj->debit;
837 $line->credit = $obj->credit;
838 $line->montant = $obj->montant;
839 $line->sens = $obj->sens;
840 $line->multicurrency_amount = $obj->multicurrency_amount;
841 $line->multicurrency_code = $obj->multicurrency_code;
842 $line->lettering_code = $obj->lettering_code;
843 $line->date_lettering = $obj->date_lettering;
844 $line->fk_user_author = $obj->fk_user_author;
845 $line->import_key = $obj->import_key;
846 $line->code_journal = $obj->code_journal;
847 $line->journal_label = $obj->journal_label;
848 $line->piece_num = $obj->piece_num;
849 $line->date_creation = $obj->date_creation;
851 $this->lines[] = $line;
859 $this->errors[] =
'Error ' . $this->db->lasterror();
860 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
877 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
885 $sql .=
" t.doc_date,";
886 $sql .=
" t.doc_type,";
887 $sql .=
" t.doc_ref,";
888 $sql .=
" t.fk_doc,";
889 $sql .=
" t.fk_docdet,";
890 $sql .=
" t.thirdparty_code,";
891 $sql .=
" t.subledger_account,";
892 $sql .=
" t.subledger_label,";
893 $sql .=
" t.numero_compte,";
894 $sql .=
" t.label_compte,";
895 $sql .=
" t.label_operation,";
897 $sql .=
" t.credit,";
898 $sql .=
" t.lettering_code,";
899 $sql .=
" t.montant,";
901 $sql .=
" t.fk_user_author,";
902 $sql .=
" t.import_key,";
903 $sql .=
" t.code_journal,";
904 $sql .=
" t.journal_label,";
905 $sql .=
" t.piece_num,";
906 $sql .=
" t.date_creation,";
907 $sql .=
" t.tms as date_modification";
908 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
910 $sqlwhere = array ();
911 if (count($filter) > 0) {
912 foreach ( $filter as $key => $value ) {
913 if ($key ==
't.doc_date') {
914 $sqlwhere[] = $key .
'=\'' . $this->db->idate($value) .
'\'';
915 } elseif ($key ==
't.doc_date>=' || $key ==
't.doc_date<=') {
916 $sqlwhere[] = $key .
'\'' . $this->db->idate($value) .
'\'';
917 } elseif ($key ==
't.numero_compte>=' || $key ==
't.numero_compte<=' || $key ==
't.subledger_account>=' || $key ==
't.subledger_account<=') {
918 $sqlwhere[] = $key .
'\'' . $this->db->escape($value) .
'\'';
919 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
920 $sqlwhere[] = $key .
'=' . $value;
921 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
922 $sqlwhere[] = $key .
' LIKE \'' . $this->db->escape($value) .
'%\'';
923 } elseif ($key ==
't.date_creation>=' || $key ==
't.date_creation<=') {
924 $sqlwhere[] = $key .
'\'' . $this->db->idate($value) .
'\'';
925 } elseif ($key ==
't.tms>=' || $key ==
't.tms<=') {
926 $sqlwhere[] = $key .
'\'' . $this->db->idate($value) .
'\'';
927 } elseif ($key ==
't.credit' || $key ==
't.debit') {
934 $sql.=
' WHERE t.entity IN (' .
getEntity(
'accountancy') .
')';
935 if (count($sqlwhere) > 0) {
936 $sql .=
' AND ' . implode(
' ' . $filtermode .
' ', $sqlwhere);
939 if (! empty($sortfield)) {
940 $sql .= $this->db->order($sortfield, $sortorder);
942 if (! empty($limit)) {
943 $sql .=
' ' . $this->db->plimit($limit + 1, $offset);
945 $this->lines = array();
947 $resql = $this->db->query($sql);
949 $num = $this->db->num_rows(
$resql);
952 while (($obj = $this->db->fetch_object(
$resql)) && (empty($limit) || $i < min($limit, $num)))
956 $line->id = $obj->rowid;
958 $line->doc_date = $this->db->jdate($obj->doc_date);
959 $line->doc_type = $obj->doc_type;
960 $line->doc_ref = $obj->doc_ref;
961 $line->fk_doc = $obj->fk_doc;
962 $line->fk_docdet = $obj->fk_docdet;
963 $line->thirdparty_code = $obj->thirdparty_code;
964 $line->subledger_account = $obj->subledger_account;
965 $line->subledger_label = $obj->subledger_label;
966 $line->numero_compte = $obj->numero_compte;
967 $line->label_compte = $obj->label_compte;
968 $line->label_operation = $obj->label_operation;
969 $line->debit = $obj->debit;
970 $line->credit = $obj->credit;
971 $line->montant = $obj->montant;
972 $line->sens = $obj->sens;
973 $line->lettering_code = $obj->lettering_code;
974 $line->fk_user_author = $obj->fk_user_author;
975 $line->import_key = $obj->import_key;
976 $line->code_journal = $obj->code_journal;
977 $line->journal_label = $obj->journal_label;
978 $line->piece_num = $obj->piece_num;
979 $line->date_creation = $this->db->jdate($obj->date_creation);
980 $line->date_modification = $this->db->jdate($obj->date_modification);
982 $this->lines[] = $line;
990 $this->errors[] =
'Error ' . $this->db->lasterror();
991 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
1008 public function fetchAllBalance($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
1012 $this->lines = array();
1017 $sql .=
" t.numero_compte,";
1018 $sql .=
" SUM(t.debit) as debit,";
1019 $sql .=
" SUM(t.credit) as credit";
1020 $sql .=
' FROM ' . MAIN_DB_PREFIX . $this->table_element .
' as t';
1022 $sqlwhere = array ();
1023 if (count($filter) > 0) {
1024 foreach ( $filter as $key => $value ) {
1025 if ($key ==
't.doc_date') {
1026 $sqlwhere[] = $key .
'=\'' . $this->db->idate($value) .
'\'';
1027 } elseif ($key ==
't.doc_date>=' || $key ==
't.doc_date<=') {
1028 $sqlwhere[] = $key .
'\'' . $this->db->idate($value) .
'\'';
1029 } elseif ($key ==
't.numero_compte>=' || $key ==
't.numero_compte<=' || $key ==
't.subledger_account>=' || $key ==
't.subledger_account<=') {
1030 $sqlwhere[] = $key .
'\'' . $this->db->escape($value) .
'\'';
1031 } elseif ($key ==
't.fk_doc' || $key ==
't.fk_docdet' || $key ==
't.piece_num') {
1032 $sqlwhere[] = $key .
'=' . $value;
1033 } elseif ($key ==
't.subledger_account' || $key ==
't.numero_compte') {
1034 $sqlwhere[] = $key .
' LIKE \'' . $this->db->escape($value) .
'%\'';
1035 } elseif ($key ==
't.subledger_label') {
1036 $sqlwhere[] = $key .
' LIKE \'' . $this->db->escape($value) .
'%\'';
1038 $sqlwhere[] = $key .
' LIKE \'%' . $this->db->escape($value) .
'%\'';
1042 $sql.=
' WHERE entity IN (' .
getEntity(
'accountancy') .
')';
1043 if (count($sqlwhere) > 0) {
1044 $sql .=
' AND ' . implode(
' ' . $filtermode .
' ', $sqlwhere);
1047 $sql .=
' GROUP BY t.numero_compte';
1049 if (! empty($sortfield)) {
1050 $sql .= $this->db->order($sortfield, $sortorder);
1052 if (! empty($limit)) {
1053 $sql .=
' ' . $this->db->plimit($limit + 1, $offset);
1056 $resql = $this->db->query($sql);
1059 $num = $this->db->num_rows(
$resql);
1062 while (($obj = $this->db->fetch_object(
$resql)) && (empty($limit) || $i < min($limit, $num)))
1066 $line->numero_compte = $obj->numero_compte;
1067 $line->debit = $obj->debit;
1068 $line->credit = $obj->credit;
1070 $this->lines[] = $line;
1078 $this->errors[] =
'Error ' . $this->db->lasterror();
1079 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
1100 if (isset($this->doc_type)) {
1101 $this->doc_type = trim($this->doc_type);
1103 if (isset($this->doc_ref)) {
1104 $this->doc_ref = trim($this->doc_ref);
1106 if (isset($this->fk_doc)) {
1107 $this->fk_doc = trim($this->fk_doc);
1109 if (isset($this->fk_docdet)) {
1110 $this->fk_docdet = trim($this->fk_docdet);
1112 if (isset($this->thirdparty_code)) {
1113 $this->thirdparty_code = trim($this->thirdparty_code);
1115 if (isset($this->subledger_account)) {
1116 $this->subledger_account = trim($this->subledger_account);
1118 if (isset($this->subledger_label)) {
1119 $this->subledger_label = trim($this->subledger_label);
1121 if (isset($this->numero_compte)) {
1122 $this->numero_compte = trim($this->numero_compte);
1124 if (isset($this->label_compte)) {
1125 $this->label_compte = trim($this->label_compte);
1127 if (isset($this->label_operation)) {
1128 $this->label_operation = trim($this->label_operation);
1130 if (isset($this->debit)) {
1131 $this->debit = trim($this->debit);
1133 if (isset($this->credit)) {
1134 $this->credit = trim($this->credit);
1136 if (isset($this->montant)) {
1137 $this->montant = trim($this->montant);
1139 if (isset($this->sens)) {
1140 $this->sens = trim($this->sens);
1142 if (isset($this->fk_user_author)) {
1143 $this->fk_user_author = trim($this->fk_user_author);
1145 if (isset($this->import_key)) {
1146 $this->import_key = trim($this->import_key);
1148 if (isset($this->code_journal)) {
1149 $this->code_journal = trim($this->code_journal);
1151 if (isset($this->journal_label)) {
1152 $this->journal_label = trim($this->journal_label);
1154 if (isset($this->piece_num)) {
1155 $this->piece_num = trim($this->piece_num);
1158 $this->debit =
price2num($this->debit,
'MT');
1159 $this->credit =
price2num($this->credit,
'MT');
1165 $sql =
'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . $mode.
' SET';
1166 $sql .=
' doc_date = ' . (! isset($this->doc_date) ||
dol_strlen($this->doc_date) != 0 ?
"'" . $this->db->idate($this->doc_date) .
"'" :
'null') .
',';
1167 $sql .=
' doc_type = ' . (isset($this->doc_type) ?
"'" . $this->db->escape($this->doc_type) .
"'" :
"null") .
',';
1168 $sql .=
' doc_ref = ' . (isset($this->doc_ref) ?
"'" . $this->db->escape($this->doc_ref) .
"'" :
"null") .
',';
1169 $sql .=
' fk_doc = ' . (isset($this->fk_doc) ? $this->fk_doc :
"null") .
',';
1170 $sql .=
' fk_docdet = ' . (isset($this->fk_docdet) ? $this->fk_docdet :
"null") .
',';
1171 $sql .=
' thirdparty_code = ' . (isset($this->thirdparty_code) ?
"'" . $this->db->escape($this->thirdparty_code) .
"'" :
"null") .
',';
1172 $sql .=
' subledger_account = ' . (isset($this->subledger_account) ?
"'" . $this->db->escape($this->subledger_account) .
"'" :
"null") .
',';
1173 $sql .=
' subledger_label = ' . (isset($this->subledger_label) ?
"'" . $this->db->escape($this->subledger_label) .
"'" :
"null") .
',';
1174 $sql .=
' numero_compte = ' . (isset($this->numero_compte) ?
"'" . $this->db->escape($this->numero_compte) .
"'" :
"null") .
',';
1175 $sql .=
' label_compte = ' . (isset($this->label_compte) ?
"'" . $this->db->escape($this->label_compte) .
"'" :
"null") .
',';
1176 $sql .=
' label_operation = ' . (isset($this->label_operation) ?
"'" . $this->db->escape($this->label_operation) .
"'" :
"null") .
',';
1177 $sql .=
' debit = ' . (isset($this->debit) ? $this->debit :
"null") .
',';
1178 $sql .=
' credit = ' . (isset($this->credit) ? $this->credit :
"null") .
',';
1179 $sql .=
' montant = ' . (isset($this->montant) ? $this->montant :
"null") .
',';
1180 $sql .=
' sens = ' . (isset($this->sens) ?
"'" . $this->db->escape($this->sens) .
"'" :
"null") .
',';
1181 $sql .=
' fk_user_author = ' . (isset($this->fk_user_author) ? $this->fk_user_author :
"null") .
',';
1182 $sql .=
' import_key = ' . (isset($this->import_key) ?
"'" . $this->db->escape($this->import_key) .
"'" :
"null") .
',';
1183 $sql .=
' code_journal = ' . (isset($this->code_journal) ?
"'" . $this->db->escape($this->code_journal) .
"'" :
"null") .
',';
1184 $sql .=
' journal_label = ' . (isset($this->journal_label) ?
"'" . $this->db->escape($this->journal_label) .
"'" :
"null") .
',';
1185 $sql .=
' piece_num = ' . (isset($this->piece_num) ? $this->piece_num :
"null");
1186 $sql .=
' WHERE rowid=' . $this->id;
1190 $resql = $this->db->query($sql);
1193 $this->errors[] =
'Error ' . $this->db->lasterror();
1194 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
1209 $this->db->rollback();
1211 return - 1 * $error;
1213 $this->db->commit();
1228 public function updateByMvt($piece_num=
'', $field=
'', $value=
'', $mode=
'')
1234 $sql =
"UPDATE " . MAIN_DB_PREFIX . $this->table_element . $mode .
" as ab";
1235 $sql .=
' SET ab.' . $field .
'=' . (is_numeric($value)?$value:
"'".$this->db->escape($value).
"'");
1236 $sql .=
' WHERE ab.piece_num=' . $piece_num ;
1237 $resql = $this->db->query($sql);
1241 $this->errors[] =
'Error ' . $this->db->lasterror();
1242 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
1245 $this->db->rollback();
1249 $this->db->commit();
1263 public function delete(
User $user, $notrigger =
false, $mode=
'')
1282 $sql =
'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element.$mode;
1283 $sql .=
' WHERE rowid=' . $this->id;
1285 $resql = $this->db->query($sql);
1288 $this->errors[] =
'Error ' . $this->db->lasterror();
1289 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
1295 $this->db->rollback();
1297 return - 1 * $error;
1299 $this->db->commit();
1317 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
1318 $sql .=
" WHERE import_key = '" . $this->db->escape($importkey) .
"'";
1320 $resql = $this->db->query($sql);
1323 $this->errors[] =
"Error " . $this->db->lasterror();
1324 dol_syslog(get_class($this).
"::delete Error " . $this->db->lasterror(), LOG_ERR);
1325 $this->db->rollback();
1329 $this->db->commit();
1345 if (empty($delyear) && empty($journal))
1354 $sql.=
" FROM " . MAIN_DB_PREFIX . $this->table_element.$mode;
1355 $sql.=
" WHERE 1 = 1";
1356 if (! empty($delyear)) $sql.=
" AND YEAR(doc_date) = " . $delyear;
1357 if (! empty($journal)) $sql.=
" AND code_journal = '".$this->db->escape($journal).
"'";
1358 $sql .=
" AND entity IN (" .
getEntity(
'accountancy') .
")";
1359 $resql = $this->db->query($sql);
1362 $this->errors[] =
"Error " . $this->db->lasterror();
1363 foreach ( $this->errors as $errmsg ) {
1364 dol_syslog(get_class($this) .
"::delete " . $errmsg, LOG_ERR);
1365 $this->error .= ($this->error ?
', ' . $errmsg : $errmsg);
1367 $this->db->rollback();
1371 $this->db->commit();
1389 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
1390 $sql .=
" WHERE piece_num = " . (int) $piecenum;
1391 $sql .=
" AND entity IN (" .
getEntity(
'accountancy') .
")";
1393 $resql = $this->db->query($sql);
1396 $this->errors[] =
"Error " . $this->db->lasterror();
1397 foreach ( $this->errors as $errmsg ) {
1398 dol_syslog(get_class($this) .
"::delete " . $errmsg, LOG_ERR);
1399 $this->error .= ($this->error ?
', ' . $errmsg : $errmsg);
1401 $this->db->rollback();
1405 $this->db->commit();
1428 $object->fetch($fromid);
1436 $object->context[
'createfromclone'] =
'createfromclone';
1437 $result = $object->create($user);
1442 $this->errors = $object->errors;
1443 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
1446 unset($object->context[
'createfromclone']);
1450 $this->db->commit();
1454 $this->db->rollback();
1473 $this->doc_date = $now;
1474 $this->doc_type =
'';
1475 $this->doc_ref =
'';
1477 $this->fk_docdet =
'';
1478 $this->thirdparty_code =
'CU001';
1479 $this->subledger_account =
'41100001';
1480 $this->subledger_label =
'My customer company';
1481 $this->numero_compte =
'411';
1482 $this->label_compte =
'Customer';
1483 $this->label_operation =
'Sales of pea';
1484 $this->debit = 99.9;
1486 $this->montant =
'';
1488 $this->fk_user_author = $user->id;
1489 $this->import_key =
'';
1490 $this->code_journal =
'VT';
1491 $this->journal_label =
'Journal de vente';
1492 $this->piece_num =
'';
1493 $this->date_creation = $now;
1507 $sql =
"SELECT piece_num,doc_date,code_journal,journal_label,doc_ref,doc_type,date_creation";
1508 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element.$mode;
1509 $sql .=
" WHERE piece_num = " . $piecenum;
1510 $sql .=
" AND entity IN (" .
getEntity(
'accountancy') .
")";
1512 dol_syslog(get_class($this) .
"::" . __METHOD__, LOG_DEBUG);
1513 $result = $this->db->query($sql);
1515 $obj = $this->db->fetch_object($result);
1517 $this->piece_num = $obj->piece_num;
1518 $this->code_journal = $obj->code_journal;
1519 $this->journal_label = $obj->journal_label;
1520 $this->doc_date = $this->db->jdate($obj->doc_date);
1521 $this->doc_ref = $obj->doc_ref;
1522 $this->doc_type = $obj->doc_type;
1523 $this->date_creation = $obj->date_creation;
1525 $this->error =
"Error " . $this->db->lasterror();
1526 dol_syslog(get_class($this) .
"::" . __METHOD__ . $this->error, LOG_ERR);
1543 $sql =
"SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element.$mode;
1544 $sql .=
" WHERE entity IN (" .
getEntity(
'accountancy') .
")";
1546 dol_syslog(get_class($this) .
"getNextNumMvt sql=" . $sql, LOG_DEBUG);
1547 $result = $this->db->query($sql);
1550 $obj = $this->db->fetch_object($result);
1551 if ($obj) $result = $obj->max;
1552 if (empty($result)) $result = 1;
1555 $this->error =
"Error " . $this->db->lasterror();
1556 dol_syslog(get_class($this) .
"::getNextNumMvt " . $this->error, LOG_ERR);
1572 $sql =
"SELECT rowid, doc_date, doc_type,";
1573 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
1574 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
1575 $sql .=
" montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num, date_creation";
1576 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element.$mode;
1577 $sql .=
" WHERE piece_num = " . $piecenum;
1578 $sql .=
" AND entity IN (" .
getEntity(
'accountancy') .
")";
1580 dol_syslog(get_class($this) .
"::" . __METHOD__, LOG_DEBUG);
1581 $result = $this->db->query($sql);
1584 while ($obj = $this->db->fetch_object($result)) {
1588 $line->id = $obj->rowid;
1590 $line->doc_date = $this->db->jdate($obj->doc_date);
1591 $line->doc_type = $obj->doc_type;
1592 $line->doc_ref = $obj->doc_ref;
1593 $line->fk_doc = $obj->fk_doc;
1594 $line->fk_docdet = $obj->fk_docdet;
1595 $line->thirdparty_code = $obj->thirdparty_code;
1596 $line->subledger_account = $obj->subledger_account;
1597 $line->subledger_label = $obj->subledger_label;
1598 $line->numero_compte = $obj->numero_compte;
1599 $line->label_compte = $obj->label_compte;
1600 $line->label_operation = $obj->label_operation;
1601 $line->debit = $obj->debit;
1602 $line->credit = $obj->credit;
1603 $line->montant = $obj->montant;
1604 $line->sens = $obj->sens;
1605 $line->code_journal = $obj->code_journal;
1606 $line->journal_label = $obj->journal_label;
1607 $line->piece_num = $obj->piece_num;
1608 $line->date_creation = $obj->date_creation;
1610 $this->linesmvt[] = $line;
1613 $this->error =
"Error " . $this->db->lasterror();
1614 dol_syslog(get_class($this) .
"::" . __METHOD__ . $this->error, LOG_ERR);
1633 $sql =
"SELECT rowid, doc_date, doc_type,";
1634 $sql .=
" doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
1635 $sql .=
" numero_compte, label_compte, label_operation, debit, credit,";
1636 $sql .=
" montant, sens, fk_user_author, import_key, code_journal, piece_num";
1637 $sql .=
" FROM " . MAIN_DB_PREFIX . $this->table_element;
1638 $sql .=
" WHERE entity IN (" .
getEntity(
'accountancy') .
")";
1640 dol_syslog(get_class($this) .
"::export_bookkeping", LOG_DEBUG);
1642 $resql = $this->db->query($sql);
1645 $this->linesexport = array ();
1647 $num = $this->db->num_rows(
$resql);
1648 while ($obj = $this->db->fetch_object(
$resql)) {
1651 $line->id = $obj->rowid;
1653 $line->doc_date = $this->db->jdate($obj->doc_date);
1654 $line->doc_type = $obj->doc_type;
1655 $line->doc_ref = $obj->doc_ref;
1656 $line->fk_doc = $obj->fk_doc;
1657 $line->fk_docdet = $obj->fk_docdet;
1658 $line->thirdparty_code = $obj->thirdparty_code;
1659 $line->subledger_account = $obj->subledger_account;
1660 $line->subledger_label = $obj->subledger_label;
1661 $line->numero_compte = $obj->numero_compte;
1662 $line->label_compte = $obj->label_compte;
1663 $line->label_operation = $obj->label_operation;
1664 $line->debit = $obj->debit;
1665 $line->credit = $obj->credit;
1666 $line->montant = $obj->montant;
1667 $line->sens = $obj->sens;
1668 $line->code_journal = $obj->code_journal;
1669 $line->piece_num = $obj->piece_num;
1671 $this->linesexport[] = $line;
1677 $this->error =
"Error " . $this->db->lasterror();
1678 dol_syslog(get_class($this) .
"::export_bookkeping " . $this->error, LOG_ERR);
1699 if ($next_piecenum < 0) {
1702 $sql =
'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element.
'(doc_date, doc_type,';
1703 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
1704 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
1705 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)';
1706 $sql .=
'SELECT doc_date, doc_type,';
1707 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
1708 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
1709 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.$next_piecenum.
'';
1710 $sql .=
' FROM '.MAIN_DB_PREFIX . $this->table_element.
'_tmp WHERE piece_num = '.$piece_num;
1711 $resql = $this->db->query($sql);
1714 $this->errors[] =
'Error ' . $this->db->lasterror();
1715 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
1717 $sql =
'DELETE FROM '.MAIN_DB_PREFIX . $this->table_element.
'_tmp WHERE piece_num = '.$piece_num;
1718 $resql = $this->db->query($sql);
1721 $this->errors[] =
'Error ' . $this->db->lasterror();
1722 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
1724 } elseif ($direction==1) {
1725 $sql =
'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element.
'_tmp WHERE piece_num = '.$piece_num;
1726 $resql = $this->db->query($sql);
1729 $this->errors[] =
'Error ' . $this->db->lasterror();
1730 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
1732 $sql =
'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element.
'_tmp(doc_date, doc_type,';
1733 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
1734 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
1735 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)';
1736 $sql .=
'SELECT doc_date, doc_type,';
1737 $sql .=
' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
1738 $sql .=
' numero_compte, label_compte, label_operation, debit, credit,';
1739 $sql .=
' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num';
1740 $sql .=
' FROM '.MAIN_DB_PREFIX . $this->table_element.
' WHERE piece_num = '.$piece_num;
1741 $resql = $this->db->query($sql);
1744 $this->errors[] =
'Error ' . $this->db->lasterror();
1745 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
1747 $sql =
'DELETE FROM '.MAIN_DB_PREFIX . $this->table_element.
'_tmp WHERE piece_num = '.$piece_num;
1748 $resql = $this->db->query($sql);
1751 $this->errors[] =
'Error ' . $this->db->lasterror();
1752 dol_syslog(__METHOD__ .
' ' . join(
',', $this->errors), LOG_ERR);
1756 $this->db->commit();
1759 $this->db->rollback();
1787 function select_account($selectid, $htmlname =
'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase =
'')
1792 require_once DOL_DOCUMENT_ROOT .
'/core/lib/accounting.lib.php';
1794 $pcgver = $conf->global->CHARTOFACCOUNTS;
1796 $sql =
"SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version";
1797 $sql .=
" FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping as ab";
1798 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"accounting_account as aa ON aa.account_number = ab.numero_compte";
1799 $sql .=
" AND aa.active = 1";
1800 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
1801 $sql .=
" AND asy.rowid = " . $pcgver;
1802 $sql .=
" AND ab.entity IN (" .
getEntity(
'accountancy') .
")";
1803 $sql .=
" ORDER BY account_number ASC";
1805 dol_syslog(get_class($this) .
"::select_account", LOG_DEBUG);
1806 $resql = $this->db->query($sql);
1809 $this->error =
"Error " . $this->db->lasterror();
1810 dol_syslog(get_class($this) .
"::select_account " . $this->error, LOG_ERR);
1819 while ($obj = $this->db->fetch_object(
$resql)) {
1822 $select_value_in = $obj->rowid;
1823 $select_value_out = $obj->rowid;
1825 if ($select_in == 1) {
1826 $select_value_in = $obj->account_number;
1828 if ($select_out == 1) {
1829 $select_value_out = $obj->account_number;
1834 if (($selectid !=
'') && $selectid == $select_value_in) {
1835 $selected = $select_value_out;
1838 $options[$select_value_out] = $label;
1841 $out .=
Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0,
'', 0, 0, 0,
'',
'maxwidth300');
1857 $pcgver = $conf->global->CHARTOFACCOUNTS;
1859 $sql =
"SELECT root.account_number, root.label as label";
1860 $sql .=
" FROM " . MAIN_DB_PREFIX .
"accounting_account as aa";
1861 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
1862 $sql .=
" AND asy.rowid = " . $pcgver;
1863 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"accounting_account as parent ON aa.account_parent = parent.rowid";
1864 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"accounting_account as root ON parent.account_parent = root.rowid";
1865 $sql .=
" WHERE aa.account_number = '" . $account .
"'";
1866 $sql .=
" AND parent.active = 1";
1867 $sql .=
" AND root.active = 1";
1868 $sql .=
" AND aa.entity IN (" .
getEntity(
'accountancy') .
")";
1870 dol_syslog(get_class($this) .
"::select_account sql=" . $sql, LOG_DEBUG);
1871 $resql = $this->db->query($sql);
1874 if ($this->db->num_rows(
$resql)) {
1875 $obj = $this->db->fetch_object(
$resql);
1880 $this->error =
"Error " . $this->db->lasterror();
1881 dol_syslog(__METHOD__ .
" " . $this->error, LOG_ERR);
1899 $pcgver = $conf->global->CHARTOFACCOUNTS;
1900 $sql =
"SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
1901 $sql .=
" FROM " . MAIN_DB_PREFIX .
"accounting_account as aa ";
1902 $sql .=
" INNER JOIN " . MAIN_DB_PREFIX .
"accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
1903 $sql .=
" AND aa.account_number = '" . $account .
"'";
1904 $sql .=
" AND asy.rowid = " . $pcgver;
1905 $sql .=
" AND aa.active = 1";
1906 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
1907 $sql .=
" WHERE aa.entity IN (" .
getEntity(
'accountancy') .
")";
1909 dol_syslog(get_class($this) .
"::select_account sql=" . $sql, LOG_DEBUG);
1910 $resql = $this->db->query($sql);
1913 if ($this->db->num_rows(
$resql)) {
1914 $obj = $this->db->fetch_object(
$resql);
1916 if(empty($obj->category)){
1919 return $obj->label.
' ('.$obj->category.
')';
1922 $this->error =
"Error " . $this->db->lasterror();
1923 dol_syslog(__METHOD__ .
" " . $this->error, LOG_ERR);
1939 public $doc_date =
'';
1953 public $thirdparty_code;
1954 public $subledger_account;
1955 public $subledger_label;
1956 public $numero_compte;
1957 public $label_compte;
1958 public $label_operation;
1967 public $fk_user_author;
1970 public $code_journal;
1971 public $journal_label;
1973 public $date_creation;
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
deleteByImportkey($importkey)
Delete bookkepping by importkey.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
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.
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
deleteMvtNum($piecenum)
Delete bookkepping by piece number.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
__construct(DoliDB $db)
Constructor.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load object in memory from the database.
deleteByYearAndJournal($delyear='', $journal='', $mode='')
Delete bookkepping by year.
export_bookkeping($model='ebp')
Export bookkeping.
getNextNumMvt($mode='')
Return next number movement.
Class to manage Ledger (General Ledger and Subledger)
get_compte_racine($account=null)
Description of a root accounting account.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
update(User $user, $notrigger=false, $mode='')
Update object into database.
transformTransaction($direction=0, $piece_num='')
Transform transaction.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_now($mode='gmt')
Return date for now.
fetchPerMvt($piecenum, $mode='')
Load an accounting document into memory from database.
createFromClone($fromid)
Load an object from its id and create a new one in database.
fetchAllBalance($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load object in memory from the database.
fetchAllPerMvt($piecenum, $mode='')
Load all informations of accountancy document.
create(User $user, $notrigger=false)
Create object into database.
fetch($id, $ref=null, $mode='')
Load object in memory from the database.
fetchAllByAccount($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load object in memory from the database.
get_compte_desc($account=null)
Description of accounting account.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
updateByMvt($piece_num='', $field='', $value='', $mode='')
Update movement.
createStd(User $user, $notrigger=false, $mode='')
Create object into database.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)