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 && !empty($this->label)) {
285 $label_link .=
' - '.($nourl ?
'<span class="opacitymedium">' :
'').$langs->transnoentities($this->label).($nourl ?
'</span>' :
'');
288 $result .= $linkstart;
290 $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);
292 if ($withpicto != 2) {
293 $result .= $label_link;
298 $hookmanager->initHooks(array(
'accountingjournaldao'));
299 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
300 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
302 $result = $hookmanager->resPrint;
304 $result .= $hookmanager->resPrint;
317 return $this->
LibType($this->nature, $mode);
333 $langs->loadLangs(array(
"accountancy"));
338 return $langs->trans(
'AccountingJournalType9');
339 } elseif ($nature == 5) {
340 return $langs->trans(
'AccountingJournalType5');
341 } elseif ($nature == 4) {
342 return $langs->trans(
'AccountingJournalType4');
343 } elseif ($nature == 3) {
344 return $langs->trans(
'AccountingJournalType3');
345 } elseif ($nature == 2) {
346 return $langs->trans(
'AccountingJournalType2');
347 } elseif ($nature == 1) {
348 return $langs->trans(
'AccountingJournalType1');
350 } elseif ($mode == 1) {
352 return $langs->trans(
'AccountingJournalType9');
353 } elseif ($nature == 5) {
354 return $langs->trans(
'AccountingJournalType5');
355 } elseif ($nature == 4) {
356 return $langs->trans(
'AccountingJournalType4');
357 } elseif ($nature == 3) {
358 return $langs->trans(
'AccountingJournalType3');
359 } elseif ($nature == 2) {
360 return $langs->trans(
'AccountingJournalType2');
361 } elseif ($nature == 1) {
362 return $langs->trans(
'AccountingJournalType1');
378 public function getData(
User $user, $type =
'view', $date_start =
null, $date_end =
null, $in_bookkeeping =
'notyet')
383 if (empty($type)) $type =
'view';
384 if (empty($in_bookkeeping)) $in_bookkeeping =
'notyet';
387 if (!is_object($hookmanager)) {
388 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
394 $hookmanager->initHooks(array(
'accountingjournaldao'));
395 $parameters = array(
'data' => &$data,
'user' => $user,
'type' => $type,
'date_start' => $date_start,
'date_end' => $date_end,
'in_bookkeeping' => $in_bookkeeping);
396 $reshook = $hookmanager->executeHooks(
'getData', $parameters, $this);
398 $this->error = $hookmanager->error;
399 $this->errors = $hookmanager->errors;
401 } elseif (empty($reshook)) {
402 switch ($this->nature) {
404 $data = $this->
getAssetData($user, $type, $date_start, $date_end, $in_bookkeeping);
428 public function getAssetData(
User $user, $type =
'view', $date_start =
null, $date_end =
null, $in_bookkeeping =
'notyet')
430 global $conf, $langs;
436 require_once DOL_DOCUMENT_ROOT .
'/core/lib/accounting.lib.php';
437 require_once DOL_DOCUMENT_ROOT .
'/asset/class/asset.class.php';
438 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
439 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
441 $langs->loadLangs(array(
"assets"));
447 if (empty($in_bookkeeping)) {
448 $in_bookkeeping =
'notyet';
462 $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";
463 $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";
464 $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";
465 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation as ad";
466 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"asset as a ON a.rowid = ad.fk_asset";
471 $sql .=
" WHERE a.entity IN (" .
getEntity(
'asset', 0) .
')';
473 if ($in_bookkeeping ==
'already') {
474 $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')";
475 } elseif ($in_bookkeeping ==
'notyet') {
476 $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')";
478 $sql .=
" AND ad.ref != ''";
479 if ($date_start && $date_end) {
480 $sql .=
" AND ad.depreciation_date >= '" . $this->
db->idate($date_start) .
"' AND ad.depreciation_date <= '" . $this->
db->idate($date_end) .
"'";
483 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
484 $sql .=
" AND ad.depreciation_date >= '" . $this->
db->idate($conf->global->ACCOUNTING_DATE_START_BINDING) .
"'";
491 $sql .=
" ORDER BY ad.depreciation_date";
496 $this->errors[] = $this->
db->lasterror();
501 'elements' => array(),
503 while ($obj = $this->
db->fetch_object(
$resql)) {
504 if (!isset($pre_data[
'elements'][$obj->rowid])) {
505 $pre_data[
'elements'][$obj->rowid] = array(
506 'ref' => $obj->asset_ref,
507 'label' => $obj->asset_label,
508 'acquisition_value_ht' => $obj->asset_acquisition_value_ht,
509 'depreciation' => array(),
513 if (isset($obj->asset_disposal_date)) {
514 $pre_data[
'elements'][$obj->rowid][
'disposal'] = array(
515 'date' => $this->
db->jdate($obj->asset_disposal_date),
516 'amount' => $obj->asset_disposal_amount_ht,
517 'subject_to_vat' => !empty($obj->asset_disposal_subject_to_vat),
522 $compta_debit = empty($obj->accountancy_code_debit) ?
'NotDefined' : $obj->accountancy_code_debit;
523 $compta_credit = empty($obj->accountancy_code_credit) ?
'NotDefined' : $obj->accountancy_code_credit;
525 $pre_data[
'elements'][$obj->rowid][
'depreciation'][$obj->depreciation_id] = array(
526 'date' => $this->
db->jdate($obj->depreciation_date),
527 'ref' => $obj->depreciation_ref,
529 $compta_debit => -$obj->depreciation_ht,
530 $compta_credit => $obj->depreciation_ht,
535 $disposal_ref = $langs->transnoentitiesnoconv(
'AssetDisposal');
536 $journal = $this->code;
537 $journal_label = $this->label;
538 $journal_label_formatted = $langs->transnoentities($journal_label);
541 $element_static =
new Asset($this->
db);
543 $journal_data = array();
544 foreach ($pre_data[
'elements'] as $pre_data_id => $pre_data_info) {
545 $element_static->id = $pre_data_id;
546 $element_static->ref = (string) $pre_data_info[
"ref"];
547 $element_static->label = (string) $pre_data_info[
"label"];
548 $element_static->acquisition_value_ht = $pre_data_info[
"acquisition_value_ht"];
549 $element_link = $element_static->getNomUrl(1,
'with_label');
551 $element_name_formatted_0 =
dol_trunc($element_static->label, 16);
552 $element_name_formatted_1 = utf8_decode(
dol_trunc($element_static->label, 32));
553 $element_name_formatted_2 = utf8_decode(
dol_trunc($element_static->label, 16));
554 $label_operation = $element_static->getNomUrl(0,
'label', 16);
557 'ref' =>
dol_trunc($element_static->ref, 16,
'right',
'UTF-8', 1),
558 'error' => $pre_data_info[
'error'],
564 foreach ($pre_data_info[
'depreciation'] as $depreciation_id => $line) {
565 $depreciation_ref = $line[
"ref"];
566 $depreciation_date = $line[
"date"];
567 $depreciation_date_formatted =
dol_print_date($depreciation_date,
'day');
571 foreach ($line[
'lines'] as $account => $mt) {
574 if ($type ==
'view') {
576 if (($account_to_show ==
"") || $account_to_show ==
'NotDefined') {
577 $account_to_show =
'<span class="error">' . $langs->trans(
"AssetInAccountNotDefined") .
'</span>';
581 'date' => $depreciation_date_formatted,
582 'piece' => $element_link,
583 'account_accounting' => $account_to_show,
584 'subledger_account' =>
'',
585 'label_operation' => $label_operation .
' - ' . $depreciation_ref,
586 'debit' => $mt < 0 ?
price(-$mt) :
'',
587 'credit' => $mt >= 0 ?
price($mt) :
'',
589 } elseif ($type ==
'bookkeeping') {
590 if ($account_infos[
'found']) {
592 'doc_date' => $depreciation_date,
593 'date_lim_reglement' =>
'',
594 'doc_ref' => $element_static->ref,
595 'date_creation' => $now,
596 'doc_type' =>
'asset',
597 'fk_doc' => $element_static->id,
598 'fk_docdet' => $depreciation_id,
599 'thirdparty_code' =>
'',
600 'subledger_account' =>
'',
601 'subledger_label' =>
'',
602 'numero_compte' => $account,
603 'label_compte' => $account_infos[
'label'],
604 'label_operation' => $element_name_formatted_0 .
' - ' . $depreciation_ref,
606 'sens' => $mt < 0 ?
'D' :
'C',
607 'debit' => $mt < 0 ? -$mt : 0,
608 'credit' => $mt >= 0 ? $mt : 0,
609 'code_journal' => $journal,
610 'journal_label' => $journal_label_formatted,
613 'fk_user_author' => $user->id,
614 'entity' => $conf->entity,
620 $element_static->ref,
621 $account_infos[
'code_formatted_1'],
622 $element_name_formatted_0 .
' - ' . $depreciation_ref,
623 $mt < 0 ?
price(-$mt) :
'',
624 $mt >= 0 ?
price($mt) :
'',
628 $element[
'blocks'][] = $blocks;
633 if (!empty($pre_data_info[
'disposal'])) {
634 $disposal_date = $pre_data_info[
'disposal'][
'date'];
636 if ((!($date_start && $date_end) || ($date_start <= $disposal_date && $disposal_date <= $date_end)) &&
637 (empty($conf->global->ACCOUNTING_DATE_START_BINDING) || $conf->global->ACCOUNTING_DATE_START_BINDING <= $disposal_date)
639 $disposal_amount = $pre_data_info[
'disposal'][
'amount'];
640 $disposal_subject_to_vat = $pre_data_info[
'disposal'][
'subject_to_vat'];
642 $disposal_vat = $conf->global->ASSET_DISPOSAL_VAT > 0 ? $conf->global->ASSET_DISPOSAL_VAT : 20;
646 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
648 $result = $accountancy_codes->fetchAccountancyCodes($element_static->id);
650 $element[
'error'] = $accountancy_codes->errorsToString();
653 $element_static->fetchDepreciationLines();
654 foreach ($element_static->depreciation_lines as $mode_key => $depreciation_lines) {
655 $accountancy_codes_list = $accountancy_codes->accountancy_codes[$mode_key];
657 if (!isset($accountancy_codes_list[
'value_asset_sold'])) {
661 $accountancy_code_value_asset_sold = empty($accountancy_codes_list[
'value_asset_sold']) ?
'NotDefined' : $accountancy_codes_list[
'value_asset_sold'];
662 $accountancy_code_depreciation_asset = empty($accountancy_codes_list[
'depreciation_asset']) ?
'NotDefined' : $accountancy_codes_list[
'depreciation_asset'];
663 $accountancy_code_asset = empty($accountancy_codes_list[
'asset']) ?
'NotDefined' : $accountancy_codes_list[
'asset'];
664 $accountancy_code_receivable_on_assignment = empty($accountancy_codes_list[
'receivable_on_assignment']) ?
'NotDefined' : $accountancy_codes_list[
'receivable_on_assignment'];
665 $accountancy_code_vat_collected = empty($accountancy_codes_list[
'vat_collected']) ?
'NotDefined' : $accountancy_codes_list[
'vat_collected'];
666 $accountancy_code_proceeds_from_sales = empty($accountancy_codes_list[
'proceeds_from_sales']) ?
'NotDefined' : $accountancy_codes_list[
'proceeds_from_sales'];
668 $last_cumulative_amount_ht = 0;
669 $depreciated_ids = array_keys($pre_data_info[
'depreciation']);
670 foreach ($depreciation_lines as $line) {
671 $last_cumulative_amount_ht = $line[
'cumulative_depreciation_ht'];
672 if (!in_array($line[
'id'], $depreciated_ids) && empty($line[
'bookkeeping']) && !empty($line[
'ref'])) {
678 $lines[0][$accountancy_code_value_asset_sold] = -($element_static->acquisition_value_ht - $last_cumulative_amount_ht);
679 $lines[0][$accountancy_code_depreciation_asset] = -$last_cumulative_amount_ht;
680 $lines[0][$accountancy_code_asset] = $element_static->acquisition_value_ht;
682 $disposal_amount_vat = $disposal_subject_to_vat ? (double)
price2num($disposal_amount * $disposal_vat / 100,
'MT') : 0;
683 $lines[1][$accountancy_code_receivable_on_assignment] = -($disposal_amount + $disposal_amount_vat);
684 if ($disposal_subject_to_vat) $lines[1][$accountancy_code_vat_collected] = $disposal_amount_vat;
685 $lines[1][$accountancy_code_proceeds_from_sales] = $disposal_amount;
687 foreach ($lines as $lines_block) {
689 foreach ($lines_block as $account => $mt) {
692 if ($type ==
'view') {
694 if (($account_to_show ==
"") || $account_to_show ==
'NotDefined') {
695 $account_to_show =
'<span class="error">' . $langs->trans(
"AssetInAccountNotDefined") .
'</span>';
699 'date' => $disposal_date_formatted,
700 'piece' => $element_link,
701 'account_accounting' => $account_to_show,
702 'subledger_account' =>
'',
703 'label_operation' => $label_operation .
' - ' . $disposal_ref,
704 'debit' => $mt < 0 ?
price(-$mt) :
'',
705 'credit' => $mt >= 0 ?
price($mt) :
'',
707 } elseif ($type ==
'bookkeeping') {
708 if ($account_infos[
'found']) {
710 'doc_date' => $disposal_date,
711 'date_lim_reglement' =>
'',
712 'doc_ref' => $element_static->ref,
713 'date_creation' => $now,
714 'doc_type' =>
'asset',
715 'fk_doc' => $element_static->id,
717 'thirdparty_code' =>
'',
718 'subledger_account' =>
'',
719 'subledger_label' =>
'',
720 'numero_compte' => $account,
721 'label_compte' => $account_infos[
'label'],
722 'label_operation' => $element_name_formatted_0 .
' - ' . $disposal_ref,
724 'sens' => $mt < 0 ?
'D' :
'C',
725 'debit' => $mt < 0 ? -$mt : 0,
726 'credit' => $mt >= 0 ? $mt : 0,
727 'code_journal' => $journal,
728 'journal_label' => $journal_label_formatted,
731 'fk_user_author' => $user->id,
732 'entity' => $conf->entity,
738 $element_static->ref,
739 $account_infos[
'code_formatted_1'],
740 $element_name_formatted_0 .
' - ' . $disposal_ref,
741 $mt < 0 ?
price(-$mt) :
'',
742 $mt >= 0 ?
price($mt) :
'',
746 $element[
'blocks'][] = $blocks;
753 $journal_data[$pre_data_id] = $element;
757 return $journal_data;
805 global $conf, $langs, $hookmanager;
806 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/bookkeeping.class.php';
809 if (!is_object($hookmanager)) {
810 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
816 $hookmanager->initHooks(array(
'accountingjournaldao'));
817 $parameters = array(
'journal_data' => &$journal_data);
818 $reshook = $hookmanager->executeHooks(
'writeBookkeeping', $parameters, $this);
820 $this->error = $hookmanager->error;
821 $this->errors = $hookmanager->errors;
823 } elseif (empty($reshook)) {
825 $journal_data = is_array($journal_data) ? $journal_data : array();
827 foreach ($journal_data as $element_id => $element) {
834 if ($element[
'error'] ==
'somelinesarenotbound') {
837 $this->errors[] = $langs->trans(
'ErrorInvoiceContainsLinesNotYetBounded', $element[
'ref']);
840 if (!$error_for_line) {
841 foreach ($element[
'blocks'] as $lines) {
842 foreach ($lines as $line) {
844 $bookkeeping->doc_date = $line[
'doc_date'];
845 $bookkeeping->date_lim_reglement = $line[
'date_lim_reglement'];
846 $bookkeeping->doc_ref = $line[
'doc_ref'];
847 $bookkeeping->date_creation = $line[
'date_creation'];
848 $bookkeeping->doc_type = $line[
'doc_type'];
849 $bookkeeping->fk_doc = $line[
'fk_doc'];
850 $bookkeeping->fk_docdet = $line[
'fk_docdet'];
851 $bookkeeping->thirdparty_code = $line[
'thirdparty_code'];
852 $bookkeeping->subledger_account = $line[
'subledger_account'];
853 $bookkeeping->subledger_label = $line[
'subledger_label'];
854 $bookkeeping->numero_compte = $line[
'numero_compte'];
855 $bookkeeping->label_compte = $line[
'label_compte'];
856 $bookkeeping->label_operation = $line[
'label_operation'];
857 $bookkeeping->montant = $line[
'montant'];
858 $bookkeeping->sens = $line[
'sens'];
859 $bookkeeping->debit = $line[
'debit'];
860 $bookkeeping->credit = $line[
'credit'];
861 $bookkeeping->code_journal = $line[
'code_journal'];
862 $bookkeeping->journal_label = $line[
'journal_label'];
863 $bookkeeping->piece_num = $line[
'piece_num'];
864 $bookkeeping->import_key = $line[
'import_key'];
865 $bookkeeping->fk_user_author = $user->id;
866 $bookkeeping->entity = $conf->entity;
868 $total_debit += $bookkeeping->debit;
869 $total_credit += $bookkeeping->credit;
871 $result = $bookkeeping->create($user);
873 if ($bookkeeping->error ==
'BookkeepingRecordAlreadyExists') {
876 $journal_data[$element_id][
'error'] =
'alreadyjournalized';
880 $journal_data[$element_id][
'error'] =
'other';
881 $this->errors[] = $bookkeeping->errorsToString();
899 if ($error_for_line) {
906 if (!$error_for_line && (
price2num($total_debit,
'MT') !=
price2num($total_credit,
'MT'))) {
909 $journal_data[$element_id][
'error'] =
'amountsnotbalanced';
910 $this->errors[] =
'Try to insert a non balanced transaction in book for ' . $element[
'blocks'] .
'. Canceled. Surely a bug.';
913 if (!$error_for_line) {
916 $this->
db->rollback();
918 if ($error >= $max_nb_errors) {
919 $this->errors[] = $langs->trans(
"ErrorTooManyErrorsProcessStopped");
926 return $error ? -$error : 1;
950 public function exportCsv(&$journal_data = array(), $search_date_end = 0, $sep =
'')
952 global $conf, $langs, $hookmanager;
954 if (empty($sep)) $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
958 if (!is_object($hookmanager)) {
959 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
963 $hookmanager->initHooks(array(
'accountingjournaldao'));
964 $parameters = array(
'journal_data' => &$journal_data,
'search_date_end' => &$search_date_end,
'sep' => &$sep,
'out' => &$out);
965 $reshook = $hookmanager->executeHooks(
'exportCsv', $parameters, $this);
967 $this->error = $hookmanager->error;
968 $this->errors = $hookmanager->errors;
970 } elseif (empty($reshook)) {
972 $journal_data = is_array($journal_data) ? $journal_data : array();
976 if ($this->nature == 4) {
978 $langs->transnoentitiesnoconv(
"BankId"),
979 $langs->transnoentitiesnoconv(
"Date"),
980 $langs->transnoentitiesnoconv(
"PaymentMode"),
981 $langs->transnoentitiesnoconv(
"AccountAccounting"),
982 $langs->transnoentitiesnoconv(
"LedgerAccount"),
983 $langs->transnoentitiesnoconv(
"SubledgerAccount"),
984 $langs->transnoentitiesnoconv(
"Label"),
985 $langs->transnoentitiesnoconv(
"Debit"),
986 $langs->transnoentitiesnoconv(
"Credit"),
987 $langs->transnoentitiesnoconv(
"Journal"),
988 $langs->transnoentitiesnoconv(
"Note"),
990 } elseif ($this->nature == 5) {
992 $langs->transnoentitiesnoconv(
"Date"),
993 $langs->transnoentitiesnoconv(
"Piece"),
994 $langs->transnoentitiesnoconv(
"AccountAccounting"),
995 $langs->transnoentitiesnoconv(
"LabelOperation"),
996 $langs->transnoentitiesnoconv(
"Debit"),
997 $langs->transnoentitiesnoconv(
"Credit"),
999 } elseif ($this->nature == 1) {
1001 $langs->transnoentitiesnoconv(
"Date"),
1002 $langs->transnoentitiesnoconv(
"Piece"),
1003 $langs->transnoentitiesnoconv(
"AccountAccounting"),
1004 $langs->transnoentitiesnoconv(
"LabelOperation"),
1005 $langs->transnoentitiesnoconv(
"Debit"),
1006 $langs->transnoentitiesnoconv(
"Credit"),
1010 if (!empty($header)) $out .=
'"' . implode(
'"' . $sep .
'"', $header) .
'"' .
"\n";
1011 foreach ($journal_data as $element_id => $element) {
1012 foreach ($element[
'blocks'] as $lines) {
1013 foreach ($lines as $line) {
1014 $out .=
'"' . implode(
'"' . $sep .
'"', $line) .
'"' .
"\n";
1031 if (!isset(self::$accounting_account_cached[$account])) {
1032 require_once DOL_DOCUMENT_ROOT .
'/core/lib/accounting.lib.php';
1033 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/accountingaccount.class.php';
1035 $result = $accountingaccount->fetch(
null, $account,
true);
1037 self::$accounting_account_cached[$account] = array(
1039 'label' => $accountingaccount->label,
1041 'label_formatted_1' => utf8_decode(
dol_trunc($accountingaccount->label, 32)),
1042 'label_formatted_2' =>
dol_trunc($accountingaccount->label, 32),
1045 self::$accounting_account_cached[$account] = array(
1049 'label_formatted_1' =>
'',
1050 'label_formatted_2' =>
'',
1055 return self::$accounting_account_cached[$account];