32 public $element =
'accounting_journal';
37 public $table_element =
'accounting_journal';
42 public $fk_element =
'';
47 public $ismultientitymanaged = 0;
52 public $picto =
'generic';
87 static public $accounting_account_cached = array();
92 static public $nature_maps = array(
93 1 =>
'variousoperations',
97 5 =>
'expensereports',
119 public function fetch($rowid =
null, $journal_code =
null)
123 if ($rowid || $journal_code) {
124 $sql =
"SELECT rowid, code, label, nature, active";
125 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_journal";
128 $sql .=
" rowid = ".((int) $rowid);
129 } elseif ($journal_code) {
130 $sql .=
" code = '".$this->db->escape($journal_code).
"'";
131 $sql .=
" AND entity = ".$conf->entity;
134 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
135 $result = $this->
db->query($sql);
137 $obj = $this->
db->fetch_object($result);
140 $this->
id = $obj->rowid;
141 $this->
rowid = $obj->rowid;
143 $this->
code = $obj->code;
144 $this->
ref = $obj->code;
145 $this->label = $obj->label;
146 $this->nature = $obj->nature;
147 $this->active = $obj->active;
154 $this->error =
"Error ".$this->db->lasterror();
155 $this->errors[] =
"Error ".$this->db->lasterror();
173 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
175 $sql =
"SELECT rowid, code, label, nature, active";
176 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
179 if (count($filter) > 0) {
180 foreach ($filter as $key => $value) {
181 if ($key ==
't.code' || $key ==
't.label' || $key ==
't.nature') {
182 $sqlwhere[] = $key.
'\''.$this->
db->escape($value).
'\'';
183 } elseif ($key ==
't.rowid' || $key ==
't.active') {
184 $sqlwhere[] = $key.
'='.$value;
188 $sql .=
' WHERE 1 = 1';
189 $sql .=
" AND entity IN (".getEntity(
'accountancy').
")";
190 if (count($sqlwhere) > 0) {
191 $sql .=
" AND ".implode(
" ".$filtermode.
" ", $sqlwhere);
194 if (!empty($sortfield)) {
195 $sql .= $this->
db->order($sortfield, $sortorder);
197 if (!empty($limit)) {
198 $sql .= $this->
db->plimit($limit + 1, $offset);
200 $this->lines = array();
202 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
207 while ($obj = $this->
db->fetch_object(
$resql)) {
208 $line =
new self($this->db);
210 $line->id = $obj->rowid;
211 $line->code = $obj->code;
212 $line->label = $obj->label;
213 $line->nature = $obj->nature;
214 $line->active = $obj->active;
216 $this->lines[] = $line;
223 $this->errors[] =
'Error '.$this->db->lasterror();
224 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
240 public function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle =
'', $notooltip = 0)
242 global $langs, $conf, $user, $hookmanager;
244 if (!empty($conf->dol_no_mouse_hover)) {
250 $url = DOL_URL_ROOT.
'/accountancy/admin/journals_list.php?id=35';
252 $label =
'<u>'.$langs->trans(
"ShowAccountingJournal").
'</u>';
253 if (!empty($this->
code)) {
254 $label .=
'<br><b>'.$langs->trans(
'Code').
':</b> '.$this->code;
256 if (!empty($this->label)) {
257 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$langs->transnoentities($this->label);
260 $label .=
' - '.$moretitle;
264 if (empty($notooltip)) {
265 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
266 $label = $langs->trans(
"ShowAccountingJournal");
267 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
269 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
270 $linkclose .=
' class="classfortooltip"';
273 $linkstart =
'<a href="'.$url.
'"';
274 $linkstart .= $linkclose.
'>';
283 $label_link = $this->code;
284 if ($withlabel != 2 && !empty($this->label)) {
285 $label_link .=
' - '.($nourl ?
'<span class="opacitymedium">' :
'').$langs->transnoentities($this->label).($nourl ?
'</span>' :
'');
287 if ($withlabel == 2 && !empty($this->nature)) {
288 $key = $langs->trans(
"AccountingJournalType".strtoupper($this->nature));
289 $transferlabel = ($this->nature && $key !=
"AccountingJournalType".strtoupper($langs->trans($this->nature)) ? $key : $this->label);
290 $label_link .=
' - '.($nourl ?
'<span class="opacitymedium">' :
'').$transferlabel.($nourl ?
'</span>' :
'');
293 $result .= $linkstart;
295 $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);
297 if ($withpicto != 2) {
298 $result .= $label_link;
303 $hookmanager->initHooks(array(
'accountingjournaldao'));
304 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
305 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
307 $result = $hookmanager->resPrint;
309 $result .= $hookmanager->resPrint;
322 return $this->
LibType($this->nature, $mode);
338 $langs->loadLangs(array(
"accountancy"));
343 return $langs->trans(
'AccountingJournalType9');
344 } elseif ($nature == 5) {
345 return $langs->trans(
'AccountingJournalType5');
346 } elseif ($nature == 4) {
347 return $langs->trans(
'AccountingJournalType4');
348 } elseif ($nature == 3) {
349 return $langs->trans(
'AccountingJournalType3');
350 } elseif ($nature == 2) {
351 return $langs->trans(
'AccountingJournalType2');
352 } elseif ($nature == 1) {
353 return $langs->trans(
'AccountingJournalType1');
355 } elseif ($mode == 1) {
357 return $langs->trans(
'AccountingJournalType9');
358 } elseif ($nature == 5) {
359 return $langs->trans(
'AccountingJournalType5');
360 } elseif ($nature == 4) {
361 return $langs->trans(
'AccountingJournalType4');
362 } elseif ($nature == 3) {
363 return $langs->trans(
'AccountingJournalType3');
364 } elseif ($nature == 2) {
365 return $langs->trans(
'AccountingJournalType2');
366 } elseif ($nature == 1) {
367 return $langs->trans(
'AccountingJournalType1');
383 public function getData(
User $user, $type =
'view', $date_start =
null, $date_end =
null, $in_bookkeeping =
'notyet')
388 if (empty($type)) $type =
'view';
389 if (empty($in_bookkeeping)) $in_bookkeeping =
'notyet';
392 if (!is_object($hookmanager)) {
393 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
399 $hookmanager->initHooks(array(
'accountingjournaldao'));
400 $parameters = array(
'data' => &$data,
'user' => $user,
'type' => $type,
'date_start' => $date_start,
'date_end' => $date_end,
'in_bookkeeping' => $in_bookkeeping);
401 $reshook = $hookmanager->executeHooks(
'getData', $parameters, $this);
403 $this->error = $hookmanager->error;
404 $this->errors = $hookmanager->errors;
406 } elseif (empty($reshook)) {
407 switch ($this->nature) {
409 $data = $this->
getAssetData($user, $type, $date_start, $date_end, $in_bookkeeping);
433 public function getAssetData(
User $user, $type =
'view', $date_start =
null, $date_end =
null, $in_bookkeeping =
'notyet')
435 global $conf, $langs;
441 require_once DOL_DOCUMENT_ROOT .
'/core/lib/accounting.lib.php';
442 require_once DOL_DOCUMENT_ROOT .
'/asset/class/asset.class.php';
443 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
444 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
446 $langs->loadLangs(array(
"assets"));
452 if (empty($in_bookkeeping)) {
453 $in_bookkeeping =
'notyet';
467 $sql .=
"SELECT ad.fk_asset AS rowid, a.ref AS asset_ref, a.label AS asset_label, a.acquisition_value_ht AS asset_acquisition_value_ht";
468 $sql .=
", a.disposal_date AS asset_disposal_date, a.disposal_amount_ht AS asset_disposal_amount_ht, a.disposal_subject_to_vat AS asset_disposal_subject_to_vat";
469 $sql .=
", ad.rowid AS depreciation_id, ad.depreciation_mode, ad.ref AS depreciation_ref, ad.depreciation_date, ad.depreciation_ht, ad.accountancy_code_debit, ad.accountancy_code_credit";
470 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation as ad";
471 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"asset as a ON a.rowid = ad.fk_asset";
476 $sql .=
" WHERE a.entity IN (" .
getEntity(
'asset', 0) .
')';
478 if ($in_bookkeeping ==
'already') {
479 $sql .=
" AND EXISTS (SELECT iab.fk_docdet FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping AS iab WHERE iab.fk_docdet = ad.rowid AND doc_type = 'asset')";
480 } elseif ($in_bookkeeping ==
'notyet') {
481 $sql .=
" AND NOT EXISTS (SELECT iab.fk_docdet FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping AS iab WHERE iab.fk_docdet = ad.rowid AND doc_type = 'asset')";
483 $sql .=
" AND ad.ref != ''";
484 if ($date_start && $date_end) {
485 $sql .=
" AND ad.depreciation_date >= '" . $this->
db->idate($date_start) .
"' AND ad.depreciation_date <= '" . $this->
db->idate($date_end) .
"'";
488 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
489 $sql .=
" AND ad.depreciation_date >= '" . $this->
db->idate($conf->global->ACCOUNTING_DATE_START_BINDING) .
"'";
496 $sql .=
" ORDER BY ad.depreciation_date";
501 $this->errors[] = $this->
db->lasterror();
506 'elements' => array(),
508 while ($obj = $this->
db->fetch_object(
$resql)) {
509 if (!isset($pre_data[
'elements'][$obj->rowid])) {
510 $pre_data[
'elements'][$obj->rowid] = array(
511 'ref' => $obj->asset_ref,
512 'label' => $obj->asset_label,
513 'acquisition_value_ht' => $obj->asset_acquisition_value_ht,
514 'depreciation' => array(),
518 if (isset($obj->asset_disposal_date)) {
519 $pre_data[
'elements'][$obj->rowid][
'disposal'] = array(
520 'date' => $this->
db->jdate($obj->asset_disposal_date),
521 'amount' => $obj->asset_disposal_amount_ht,
522 'subject_to_vat' => !empty($obj->asset_disposal_subject_to_vat),
527 $compta_debit = empty($obj->accountancy_code_debit) ?
'NotDefined' : $obj->accountancy_code_debit;
528 $compta_credit = empty($obj->accountancy_code_credit) ?
'NotDefined' : $obj->accountancy_code_credit;
530 $pre_data[
'elements'][$obj->rowid][
'depreciation'][$obj->depreciation_id] = array(
531 'date' => $this->
db->jdate($obj->depreciation_date),
532 'ref' => $obj->depreciation_ref,
534 $compta_debit => -$obj->depreciation_ht,
535 $compta_credit => $obj->depreciation_ht,
540 $disposal_ref = $langs->transnoentitiesnoconv(
'AssetDisposal');
541 $journal = $this->code;
542 $journal_label = $this->label;
543 $journal_label_formatted = $langs->transnoentities($journal_label);
546 $element_static =
new Asset($this->
db);
548 $journal_data = array();
549 foreach ($pre_data[
'elements'] as $pre_data_id => $pre_data_info) {
550 $element_static->id = $pre_data_id;
551 $element_static->ref = (string) $pre_data_info[
"ref"];
552 $element_static->label = (string) $pre_data_info[
"label"];
553 $element_static->acquisition_value_ht = $pre_data_info[
"acquisition_value_ht"];
554 $element_link = $element_static->getNomUrl(1,
'with_label');
556 $element_name_formatted_0 =
dol_trunc($element_static->label, 16);
557 $element_name_formatted_1 = utf8_decode(
dol_trunc($element_static->label, 32));
558 $element_name_formatted_2 = utf8_decode(
dol_trunc($element_static->label, 16));
559 $label_operation = $element_static->getNomUrl(0,
'label', 16);
562 'ref' =>
dol_trunc($element_static->ref, 16,
'right',
'UTF-8', 1),
563 'error' => $pre_data_info[
'error'],
569 foreach ($pre_data_info[
'depreciation'] as $depreciation_id => $line) {
570 $depreciation_ref = $line[
"ref"];
571 $depreciation_date = $line[
"date"];
572 $depreciation_date_formatted =
dol_print_date($depreciation_date,
'day');
576 foreach ($line[
'lines'] as $account => $mt) {
579 if ($type ==
'view') {
581 if (($account_to_show ==
"") || $account_to_show ==
'NotDefined') {
582 $account_to_show =
'<span class="error">' . $langs->trans(
"AssetInAccountNotDefined") .
'</span>';
586 'date' => $depreciation_date_formatted,
587 'piece' => $element_link,
588 'account_accounting' => $account_to_show,
589 'subledger_account' =>
'',
590 'label_operation' => $label_operation .
' - ' . $depreciation_ref,
591 'debit' => $mt < 0 ?
price(-$mt) :
'',
592 'credit' => $mt >= 0 ?
price($mt) :
'',
594 } elseif ($type ==
'bookkeeping') {
595 if ($account_infos[
'found']) {
597 'doc_date' => $depreciation_date,
598 'date_lim_reglement' =>
'',
599 'doc_ref' => $element_static->ref,
600 'date_creation' => $now,
601 'doc_type' =>
'asset',
602 'fk_doc' => $element_static->id,
603 'fk_docdet' => $depreciation_id,
604 'thirdparty_code' =>
'',
605 'subledger_account' =>
'',
606 'subledger_label' =>
'',
607 'numero_compte' => $account,
608 'label_compte' => $account_infos[
'label'],
609 'label_operation' => $element_name_formatted_0 .
' - ' . $depreciation_ref,
611 'sens' => $mt < 0 ?
'D' :
'C',
612 'debit' => $mt < 0 ? -$mt : 0,
613 'credit' => $mt >= 0 ? $mt : 0,
614 'code_journal' => $journal,
615 'journal_label' => $journal_label_formatted,
618 'fk_user_author' => $user->id,
619 'entity' => $conf->entity,
625 $element_static->ref,
626 $account_infos[
'code_formatted_1'],
627 $element_name_formatted_0 .
' - ' . $depreciation_ref,
628 $mt < 0 ?
price(-$mt) :
'',
629 $mt >= 0 ?
price($mt) :
'',
633 $element[
'blocks'][] = $blocks;
638 if (!empty($pre_data_info[
'disposal'])) {
639 $disposal_date = $pre_data_info[
'disposal'][
'date'];
641 if ((!($date_start && $date_end) || ($date_start <= $disposal_date && $disposal_date <= $date_end)) &&
642 (empty($conf->global->ACCOUNTING_DATE_START_BINDING) || $conf->global->ACCOUNTING_DATE_START_BINDING <= $disposal_date)
644 $disposal_amount = $pre_data_info[
'disposal'][
'amount'];
645 $disposal_subject_to_vat = $pre_data_info[
'disposal'][
'subject_to_vat'];
647 $disposal_vat = $conf->global->ASSET_DISPOSAL_VAT > 0 ? $conf->global->ASSET_DISPOSAL_VAT : 20;
651 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
653 $result = $accountancy_codes->fetchAccountancyCodes($element_static->id);
655 $element[
'error'] = $accountancy_codes->errorsToString();
658 $element_static->fetchDepreciationLines();
659 foreach ($element_static->depreciation_lines as $mode_key => $depreciation_lines) {
660 $accountancy_codes_list = $accountancy_codes->accountancy_codes[$mode_key];
662 if (!isset($accountancy_codes_list[
'value_asset_sold'])) {
666 $accountancy_code_value_asset_sold = empty($accountancy_codes_list[
'value_asset_sold']) ?
'NotDefined' : $accountancy_codes_list[
'value_asset_sold'];
667 $accountancy_code_depreciation_asset = empty($accountancy_codes_list[
'depreciation_asset']) ?
'NotDefined' : $accountancy_codes_list[
'depreciation_asset'];
668 $accountancy_code_asset = empty($accountancy_codes_list[
'asset']) ?
'NotDefined' : $accountancy_codes_list[
'asset'];
669 $accountancy_code_receivable_on_assignment = empty($accountancy_codes_list[
'receivable_on_assignment']) ?
'NotDefined' : $accountancy_codes_list[
'receivable_on_assignment'];
670 $accountancy_code_vat_collected = empty($accountancy_codes_list[
'vat_collected']) ?
'NotDefined' : $accountancy_codes_list[
'vat_collected'];
671 $accountancy_code_proceeds_from_sales = empty($accountancy_codes_list[
'proceeds_from_sales']) ?
'NotDefined' : $accountancy_codes_list[
'proceeds_from_sales'];
673 $last_cumulative_amount_ht = 0;
674 $depreciated_ids = array_keys($pre_data_info[
'depreciation']);
675 foreach ($depreciation_lines as $line) {
676 $last_cumulative_amount_ht = $line[
'cumulative_depreciation_ht'];
677 if (!in_array($line[
'id'], $depreciated_ids) && empty($line[
'bookkeeping']) && !empty($line[
'ref'])) {
683 $lines[0][$accountancy_code_value_asset_sold] = -($element_static->acquisition_value_ht - $last_cumulative_amount_ht);
684 $lines[0][$accountancy_code_depreciation_asset] = -$last_cumulative_amount_ht;
685 $lines[0][$accountancy_code_asset] = $element_static->acquisition_value_ht;
687 $disposal_amount_vat = $disposal_subject_to_vat ? (double)
price2num($disposal_amount * $disposal_vat / 100,
'MT') : 0;
688 $lines[1][$accountancy_code_receivable_on_assignment] = -($disposal_amount + $disposal_amount_vat);
689 if ($disposal_subject_to_vat) $lines[1][$accountancy_code_vat_collected] = $disposal_amount_vat;
690 $lines[1][$accountancy_code_proceeds_from_sales] = $disposal_amount;
692 foreach ($lines as $lines_block) {
694 foreach ($lines_block as $account => $mt) {
697 if ($type ==
'view') {
699 if (($account_to_show ==
"") || $account_to_show ==
'NotDefined') {
700 $account_to_show =
'<span class="error">' . $langs->trans(
"AssetInAccountNotDefined") .
'</span>';
704 'date' => $disposal_date_formatted,
705 'piece' => $element_link,
706 'account_accounting' => $account_to_show,
707 'subledger_account' =>
'',
708 'label_operation' => $label_operation .
' - ' . $disposal_ref,
709 'debit' => $mt < 0 ?
price(-$mt) :
'',
710 'credit' => $mt >= 0 ?
price($mt) :
'',
712 } elseif ($type ==
'bookkeeping') {
713 if ($account_infos[
'found']) {
715 'doc_date' => $disposal_date,
716 'date_lim_reglement' =>
'',
717 'doc_ref' => $element_static->ref,
718 'date_creation' => $now,
719 'doc_type' =>
'asset',
720 'fk_doc' => $element_static->id,
722 'thirdparty_code' =>
'',
723 'subledger_account' =>
'',
724 'subledger_label' =>
'',
725 'numero_compte' => $account,
726 'label_compte' => $account_infos[
'label'],
727 'label_operation' => $element_name_formatted_0 .
' - ' . $disposal_ref,
729 'sens' => $mt < 0 ?
'D' :
'C',
730 'debit' => $mt < 0 ? -$mt : 0,
731 'credit' => $mt >= 0 ? $mt : 0,
732 'code_journal' => $journal,
733 'journal_label' => $journal_label_formatted,
736 'fk_user_author' => $user->id,
737 'entity' => $conf->entity,
743 $element_static->ref,
744 $account_infos[
'code_formatted_1'],
745 $element_name_formatted_0 .
' - ' . $disposal_ref,
746 $mt < 0 ?
price(-$mt) :
'',
747 $mt >= 0 ?
price($mt) :
'',
751 $element[
'blocks'][] = $blocks;
758 $journal_data[$pre_data_id] = $element;
762 return $journal_data;
810 global $conf, $langs, $hookmanager;
811 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/bookkeeping.class.php';
814 if (!is_object($hookmanager)) {
815 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
821 $hookmanager->initHooks(array(
'accountingjournaldao'));
822 $parameters = array(
'journal_data' => &$journal_data);
823 $reshook = $hookmanager->executeHooks(
'writeBookkeeping', $parameters, $this);
825 $this->error = $hookmanager->error;
826 $this->errors = $hookmanager->errors;
828 } elseif (empty($reshook)) {
830 $journal_data = is_array($journal_data) ? $journal_data : array();
832 foreach ($journal_data as $element_id => $element) {
839 if ($element[
'error'] ==
'somelinesarenotbound') {
842 $this->errors[] = $langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $element[
'ref']);
845 if (!$error_for_line) {
846 foreach ($element[
'blocks'] as $lines) {
847 foreach ($lines as $line) {
849 $bookkeeping->doc_date = $line[
'doc_date'];
850 $bookkeeping->date_lim_reglement = $line[
'date_lim_reglement'];
851 $bookkeeping->doc_ref = $line[
'doc_ref'];
852 $bookkeeping->date_creation = $line[
'date_creation'];
853 $bookkeeping->doc_type = $line[
'doc_type'];
854 $bookkeeping->fk_doc = $line[
'fk_doc'];
855 $bookkeeping->fk_docdet = $line[
'fk_docdet'];
856 $bookkeeping->thirdparty_code = $line[
'thirdparty_code'];
857 $bookkeeping->subledger_account = $line[
'subledger_account'];
858 $bookkeeping->subledger_label = $line[
'subledger_label'];
859 $bookkeeping->numero_compte = $line[
'numero_compte'];
860 $bookkeeping->label_compte = $line[
'label_compte'];
861 $bookkeeping->label_operation = $line[
'label_operation'];
862 $bookkeeping->montant = $line[
'montant'];
863 $bookkeeping->sens = $line[
'sens'];
864 $bookkeeping->debit = $line[
'debit'];
865 $bookkeeping->credit = $line[
'credit'];
866 $bookkeeping->code_journal = $line[
'code_journal'];
867 $bookkeeping->journal_label = $line[
'journal_label'];
868 $bookkeeping->piece_num = $line[
'piece_num'];
869 $bookkeeping->import_key = $line[
'import_key'];
870 $bookkeeping->fk_user_author = $user->id;
871 $bookkeeping->entity = $conf->entity;
873 $total_debit += $bookkeeping->debit;
874 $total_credit += $bookkeeping->credit;
876 $result = $bookkeeping->create($user);
878 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
881 $journal_data[$element_id][
'error'] =
'alreadyjournalized';
885 $journal_data[$element_id][
'error'] =
'other';
886 $this->errors[] = $bookkeeping->errorsToString();
904 if ($error_for_line) {
911 if (!$error_for_line && (
price2num($total_debit,
'MT') !=
price2num($total_credit,
'MT'))) {
914 $journal_data[$element_id][
'error'] =
'amountsnotbalanced';
915 $this->errors[] =
'Try to insert a non balanced transaction in book for ' . $element[
'blocks'] .
'. Canceled. Surely a bug.';
918 if (!$error_for_line) {
921 $this->
db->rollback();
923 if ($error >= $max_nb_errors) {
924 $this->errors[] = $langs->trans(
"ErrorTooManyErrorsProcessStopped");
931 return $error ? -$error : 1;
955 public function exportCsv(&$journal_data = array(), $search_date_end = 0, $sep =
'')
957 global $conf, $langs, $hookmanager;
959 if (empty($sep)) $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
963 if (!is_object($hookmanager)) {
964 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
968 $hookmanager->initHooks(array(
'accountingjournaldao'));
969 $parameters = array(
'journal_data' => &$journal_data,
'search_date_end' => &$search_date_end,
'sep' => &$sep,
'out' => &$out);
970 $reshook = $hookmanager->executeHooks(
'exportCsv', $parameters, $this);
972 $this->error = $hookmanager->error;
973 $this->errors = $hookmanager->errors;
975 } elseif (empty($reshook)) {
977 $journal_data = is_array($journal_data) ? $journal_data : array();
981 if ($this->nature == 4) {
983 $langs->transnoentitiesnoconv(
"BankId"),
984 $langs->transnoentitiesnoconv(
"Date"),
985 $langs->transnoentitiesnoconv(
"PaymentMode"),
986 $langs->transnoentitiesnoconv(
"AccountAccounting"),
987 $langs->transnoentitiesnoconv(
"LedgerAccount"),
988 $langs->transnoentitiesnoconv(
"SubledgerAccount"),
989 $langs->transnoentitiesnoconv(
"Label"),
990 $langs->transnoentitiesnoconv(
"AccountingDebit"),
991 $langs->transnoentitiesnoconv(
"AccountingCredit"),
992 $langs->transnoentitiesnoconv(
"Journal"),
993 $langs->transnoentitiesnoconv(
"Note"),
995 } elseif ($this->nature == 5) {
997 $langs->transnoentitiesnoconv(
"Date"),
998 $langs->transnoentitiesnoconv(
"Piece"),
999 $langs->transnoentitiesnoconv(
"AccountAccounting"),
1000 $langs->transnoentitiesnoconv(
"LabelOperation"),
1001 $langs->transnoentitiesnoconv(
"AccountingDebit"),
1002 $langs->transnoentitiesnoconv(
"AccountingCredit"),
1004 } elseif ($this->nature == 1) {
1006 $langs->transnoentitiesnoconv(
"Date"),
1007 $langs->transnoentitiesnoconv(
"Piece"),
1008 $langs->transnoentitiesnoconv(
"AccountAccounting"),
1009 $langs->transnoentitiesnoconv(
"LabelOperation"),
1010 $langs->transnoentitiesnoconv(
"AccountingDebit"),
1011 $langs->transnoentitiesnoconv(
"AccountingCredit"),
1015 if (!empty($header)) $out .=
'"' . implode(
'"' . $sep .
'"', $header) .
'"' .
"\n";
1016 foreach ($journal_data as $element_id => $element) {
1017 foreach ($element[
'blocks'] as $lines) {
1018 foreach ($lines as $line) {
1019 $out .=
'"' . implode(
'"' . $sep .
'"', $line) .
'"' .
"\n";
1036 if (!isset(self::$accounting_account_cached[$account])) {
1037 require_once DOL_DOCUMENT_ROOT .
'/core/lib/accounting.lib.php';
1038 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/accountingaccount.class.php';
1040 $result = $accountingaccount->fetch(
null, $account,
true);
1042 self::$accounting_account_cached[$account] = array(
1044 'label' => $accountingaccount->label,
1046 'label_formatted_1' => utf8_decode(
dol_trunc($accountingaccount->label, 32)),
1047 'label_formatted_2' =>
dol_trunc($accountingaccount->label, 32),
1050 self::$accounting_account_cached[$account] = array(
1054 'label_formatted_1' =>
'',
1055 'label_formatted_2' =>
'',
1060 return self::$accounting_account_cached[$account];