39require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
53 public static $EXPORT_TYPE_CONFIGURABLE = 1;
55 public static $EXPORT_TYPE_AGIRIS = 10;
57 public static $EXPORT_TYPE_EBP = 15;
59 public static $EXPORT_TYPE_CEGID = 20;
61 public static $EXPORT_TYPE_COGILOG = 25;
63 public static $EXPORT_TYPE_COALA = 30;
65 public static $EXPORT_TYPE_BOB50 = 35;
67 public static $EXPORT_TYPE_CIEL = 40;
69 public static $EXPORT_TYPE_SAGE50_SWISS = 45;
71 public static $EXPORT_TYPE_CHARLEMAGNE = 50;
73 public static $EXPORT_TYPE_QUADRATUS = 60;
75 public static $EXPORT_TYPE_WINFIC = 70;
77 public static $EXPORT_TYPE_OPENCONCERTO = 100;
79 public static $EXPORT_TYPE_LDCOMPTA = 110;
81 public static $EXPORT_TYPE_LDCOMPTA10 = 120;
83 public static $EXPORT_TYPE_GESTIMUMV3 = 130;
85 public static $EXPORT_TYPE_GESTIMUMV5 = 135;
87 public static $EXPORT_TYPE_ISUITEEXPERT = 200;
89 public static $EXPORT_TYPE_ISTEA = 205;
92 public static $EXPORT_TYPE_FEC = 1000;
94 public static $EXPORT_TYPE_FEC2 = 1010;
104 public $errors = array();
109 public $separator =
'';
114 public $end_line =
'';
119 public $generatedfiledata = array();
129 global $conf, $hookmanager;
135 $hookmanager->initHooks(array(
'accountancyexport'));
146 global $langs, $hookmanager;
148 $listofspecialformatexport = array(
149 self::$EXPORT_TYPE_CEGID => $langs->trans(
'Modelcsv_CEGID'),
150 self::$EXPORT_TYPE_COALA => $langs->trans(
'Modelcsv_COALA'),
151 self::$EXPORT_TYPE_BOB50 => $langs->trans(
'Modelcsv_bob50'),
152 self::$EXPORT_TYPE_CIEL => $langs->trans(
'Modelcsv_ciel'),
153 self::$EXPORT_TYPE_QUADRATUS => $langs->trans(
'Modelcsv_quadratus'),
154 self::$EXPORT_TYPE_WINFIC => $langs->trans(
'Modelcsv_winfic'),
155 self::$EXPORT_TYPE_EBP => $langs->trans(
'Modelcsv_ebp'),
156 self::$EXPORT_TYPE_COGILOG => $langs->trans(
'Modelcsv_cogilog'),
157 self::$EXPORT_TYPE_AGIRIS => $langs->trans(
'Modelcsv_agiris'),
158 self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans(
'Modelcsv_openconcerto'),
159 self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans(
'Modelcsv_Sage50_Swiss'),
160 self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans(
'Modelcsv_charlemagne'),
161 self::$EXPORT_TYPE_LDCOMPTA => $langs->trans(
'Modelcsv_LDCompta'),
162 self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans(
'Modelcsv_LDCompta10'),
163 self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans(
'Modelcsv_Gestinumv3'),
164 self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans(
'Modelcsv_Gestinumv5'),
165 self::$EXPORT_TYPE_ISUITEEXPERT =>
'Export iSuite Expert',
166 self::$EXPORT_TYPE_ISTEA => $langs->trans(
'Modelcsv_ISTEA'),
169 $listofgenericformatexport = array(
170 self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans(
'Modelcsv_configurable'),
171 self::$EXPORT_TYPE_FEC => $langs->trans(
'Modelcsv_FEC'),
172 self::$EXPORT_TYPE_FEC2 => $langs->trans(
'Modelcsv_FEC2'),
176 $listofexporttypes = $listofgenericformatexport + $listofspecialformatexport;
177 ksort($listofexporttypes, SORT_NUMERIC);
179 ksort($listofspecialformatexport, SORT_NUMERIC);
180 $listofexporttypes = array();
182 foreach ($listofgenericformatexport as $key => $val) {
184 $listofexporttypes[$key] = array(
'id' => $key,
'label' => $val,
'position' => $i);
186 $listofexporttypes[
'separator_'.$i] = array(
'id' => 0,
'label' =>
'----------------',
'position' => $i,
'disabled' =>
'disabled');
187 foreach ($listofspecialformatexport as $key => $val) {
189 $listofexporttypes[$key] = array(
'id' => $key,
'label' => $val,
'position' => $i);
194 $parameters = array();
195 $reshook = $hookmanager->executeHooks(
'getType', $parameters, $listofexporttypes);
197 return $listofexporttypes;
209 self::$EXPORT_TYPE_CONFIGURABLE =>
'csv',
210 self::$EXPORT_TYPE_CEGID =>
'cegid',
211 self::$EXPORT_TYPE_COALA =>
'coala',
212 self::$EXPORT_TYPE_BOB50 =>
'bob50',
213 self::$EXPORT_TYPE_CIEL =>
'ciel',
214 self::$EXPORT_TYPE_QUADRATUS =>
'quadratus',
215 self::$EXPORT_TYPE_WINFIC =>
'winfic',
216 self::$EXPORT_TYPE_EBP =>
'ebp',
217 self::$EXPORT_TYPE_COGILOG =>
'cogilog',
218 self::$EXPORT_TYPE_AGIRIS =>
'agiris',
219 self::$EXPORT_TYPE_OPENCONCERTO =>
'openconcerto',
220 self::$EXPORT_TYPE_SAGE50_SWISS =>
'sage50ch',
221 self::$EXPORT_TYPE_CHARLEMAGNE =>
'charlemagne',
222 self::$EXPORT_TYPE_LDCOMPTA =>
'ldcompta',
223 self::$EXPORT_TYPE_LDCOMPTA10 =>
'ldcompta10',
224 self::$EXPORT_TYPE_GESTIMUMV3 =>
'gestimumv3',
225 self::$EXPORT_TYPE_GESTIMUMV5 =>
'gestimumv5',
226 self::$EXPORT_TYPE_FEC =>
'fec',
227 self::$EXPORT_TYPE_FEC2 =>
'fec2',
228 self::$EXPORT_TYPE_ISUITEEXPERT =>
'isuiteexpert',
229 self::$EXPORT_TYPE_ISTEA =>
'istea',
233 $code = $formatcode[$type] ??
'';
234 $parameters = array(
'type' => $type);
235 $reshook = $hookmanager->executeHooks(
'getFormatCode', $parameters, $code);
249 $exporttypes = array(
251 self::$EXPORT_TYPE_CONFIGURABLE => array(
252 'label' => $langs->trans(
'Modelcsv_configurable'),
254 'ACCOUNTING_EXPORT_SEPARATORCSV' =>
getDolGlobalString(
'ACCOUNTING_EXPORT_SEPARATORCSV',
','),
258 self::$EXPORT_TYPE_CEGID => array(
259 'label' => $langs->trans(
'Modelcsv_CEGID'),
261 self::$EXPORT_TYPE_COALA => array(
262 'label' => $langs->trans(
'Modelcsv_COALA'),
264 self::$EXPORT_TYPE_BOB50 => array(
265 'label' => $langs->trans(
'Modelcsv_bob50'),
267 self::$EXPORT_TYPE_CIEL => array(
268 'label' => $langs->trans(
'Modelcsv_ciel'),
269 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
271 self::$EXPORT_TYPE_QUADRATUS => array(
272 'label' => $langs->trans(
'Modelcsv_quadratus'),
273 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
275 self::$EXPORT_TYPE_WINFIC => array(
276 'label' => $langs->trans(
'Modelcsv_winfic'),
277 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
279 self::$EXPORT_TYPE_EBP => array(
280 'label' => $langs->trans(
'Modelcsv_ebp'),
282 self::$EXPORT_TYPE_COGILOG => array(
283 'label' => $langs->trans(
'Modelcsv_cogilog'),
285 self::$EXPORT_TYPE_AGIRIS => array(
286 'label' => $langs->trans(
'Modelcsv_agiris'),
288 self::$EXPORT_TYPE_OPENCONCERTO => array(
289 'label' => $langs->trans(
'Modelcsv_openconcerto'),
291 self::$EXPORT_TYPE_SAGE50_SWISS => array(
292 'label' => $langs->trans(
'Modelcsv_Sage50_Swiss'),
294 self::$EXPORT_TYPE_CHARLEMAGNE => array(
295 'label' => $langs->trans(
'Modelcsv_charlemagne'),
296 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
298 self::$EXPORT_TYPE_LDCOMPTA => array(
299 'label' => $langs->trans(
'Modelcsv_LDCompta'),
301 self::$EXPORT_TYPE_LDCOMPTA10 => array(
302 'label' => $langs->trans(
'Modelcsv_LDCompta10'),
304 self::$EXPORT_TYPE_GESTIMUMV3 => array(
305 'label' => $langs->trans(
'Modelcsv_Gestinumv3'),
306 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
308 self::$EXPORT_TYPE_GESTIMUMV5 => array(
309 'label' => $langs->trans(
'Modelcsv_Gestinumv5'),
310 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
312 self::$EXPORT_TYPE_FEC => array(
313 'label' => $langs->trans(
'Modelcsv_FEC'),
314 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
316 self::$EXPORT_TYPE_FEC2 => array(
317 'label' => $langs->trans(
'Modelcsv_FEC2'),
318 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
320 self::$EXPORT_TYPE_ISUITEEXPERT => array(
321 'label' =>
'iSuite Expert',
322 'ACCOUNTING_EXPORT_FORMAT' =>
'csv',
324 self::$EXPORT_TYPE_ISTEA => array(
326 'ACCOUNTING_EXPORT_FORMAT' =>
'csv',
330 '1' => $langs->trans(
"Unix"),
331 '2' => $langs->trans(
"Windows")
334 'csv' => $langs->trans(
"csv"),
335 'txt' => $langs->trans(
"txt")
340 $parameters = array();
341 $reshook = $hookmanager->executeHooks(
'getTypeConfig', $parameters, $exporttypes);
354 switch ($formatexportset) {
355 case self::$EXPORT_TYPE_FEC:
356 $mime =
'text/tab-separated-values';
383 public function export(&$TData, $formatexportset, $withAttachment = 0, $downloadMode = 1, $outputMode = 1, $noouput = 1)
385 global $db, $conf, $langs;
386 global $search_date_end, $hookmanager;
390 $filename =
'general_ledger-'.(!empty($formatcode) ? $formatcode : $formatexportset);
391 $type_export =
'general_ledger';
393 $completefilename =
'';
395 $exportFileName =
'';
396 $exportFilePath =
'';
397 $exportFileFullName =
'';
398 $downloadFileMimeType =
'';
399 $downloadFileFullName =
'';
400 $downloadFilePath =
'';
401 $archiveFullName =
'';
403 $archiveFileList = array();
404 if ($withAttachment == 1) {
405 if ($downloadMode == 0) {
408 if ($outputMode == 0) {
413 if (!extension_loaded(
'zip')) {
414 $langs->load(
'install');
415 $this->errors[] = $langs->trans(
'ErrorPHPDoesNotSupport',
'ZIP');
421 if ($downloadMode == 0) {
427 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
429 if ($outputMode == 1 || $outputMode == 2) {
430 if ($outputMode == 1) {
432 if (!empty($conf->accounting->multidir_temp[$conf->entity])) {
433 $outputDir = $conf->accounting->multidir_temp[$conf->entity];
435 $outputDir = $conf->accounting->dir_temp;
439 if (!empty($conf->accounting->multidir_output[$conf->entity])) {
440 $outputDir = $conf->accounting->multidir_output[$conf->entity];
442 $outputDir = $conf->accounting->dir_output;
446 $outputDir .=
'/export';
447 $outputDir .=
'/'.dol_sanitizePathName((
string) $formatexportset);
452 $this->errors[] = $langs->trans(
'ErrorCanNotCreateDir', $outputDir);
457 if ($outputDir !=
'') {
459 $langs->load(
'errors');
460 $this->errors[] = $langs->trans(
'ErrorDirNotFound', $outputDir);
465 if (empty($completefilename)) {
470 $exportFileFullName = $completefilename;
471 $exportFileBaseName = basename($exportFileFullName);
472 $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME);
473 $exportFilePath = $outputDir .
'/' . $exportFileFullName;
474 $exportFile = fopen($exportFilePath,
'w');
476 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $exportFilePath);
480 if ($withAttachment == 1) {
481 $archiveFileList[0] = array(
482 'path' => $exportFilePath,
483 'name' => $exportFileFullName,
487 $archiveFullName = $exportFileName .
'.zip';
488 $archivePath = $outputDir .
'/' . $archiveFullName;
494 switch ($formatexportset) {
495 case self::$EXPORT_TYPE_CONFIGURABLE:
498 case self::$EXPORT_TYPE_CEGID:
501 case self::$EXPORT_TYPE_COALA:
504 case self::$EXPORT_TYPE_BOB50:
507 case self::$EXPORT_TYPE_CIEL:
510 case self::$EXPORT_TYPE_QUADRATUS:
511 $archiveFileList = $this->
exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment);
513 case self::$EXPORT_TYPE_WINFIC:
516 case self::$EXPORT_TYPE_EBP:
519 case self::$EXPORT_TYPE_COGILOG:
522 case self::$EXPORT_TYPE_AGIRIS:
525 case self::$EXPORT_TYPE_OPENCONCERTO:
528 case self::$EXPORT_TYPE_SAGE50_SWISS:
531 case self::$EXPORT_TYPE_CHARLEMAGNE:
534 case self::$EXPORT_TYPE_LDCOMPTA:
537 case self::$EXPORT_TYPE_LDCOMPTA10:
540 case self::$EXPORT_TYPE_GESTIMUMV3:
543 case self::$EXPORT_TYPE_GESTIMUMV5:
546 case self::$EXPORT_TYPE_FEC:
547 $archiveFileList = $this->
exportFEC($TData, $exportFile, $archiveFileList, $withAttachment);
549 case self::$EXPORT_TYPE_FEC2:
550 $archiveFileList = $this->
exportFEC2($TData, $exportFile, $archiveFileList, $withAttachment);
552 case self::$EXPORT_TYPE_ISUITEEXPERT:
555 case self::$EXPORT_TYPE_ISTEA:
561 'format' => $formatexportset,
562 'file' => $exportFile,
563 'filepath' => $exportFilePath,
564 'filefullname' => $exportFileFullName,
567 $reshook = $hookmanager->executeHooks(
'export', $parameters, $TData);
569 $this->errors[] = $langs->trans(
'accountancy_error_modelnotfound');
570 } elseif (!empty($hookmanager->resArray[
'downloadFileFullName']) && !empty($hookmanager->resArray[
'downloadFilePath'])) {
571 $exportFileFullName = $hookmanager->resArray[
'downloadFileFullName'];
572 $exportFilePath = $hookmanager->resArray[
'downloadFilePath'];
579 if ($outputMode == 1 || $outputMode == 2) {
587 if ($withAttachment == 1) {
589 if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
591 $downloadFileMimeType =
'application/zip';
592 $downloadFileFullName = $archiveFullName;
593 $downloadFilePath = $archivePath;
596 $archive =
new ZipArchive();
597 $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
600 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $archivePath);
604 foreach ($archiveFileList as $archiveFileArr) {
605 $res = $archive->addFile($archiveFileArr[
'path'], $archiveFileArr[
'name']);
608 $this->errors[] = $langs->trans(
'ErrorArchiveAddFile', $archiveFileArr[
'name']);
622 if ($downloadMode == 1) {
623 if ($withAttachment == 0) {
625 if (!empty($exportFileFullName) && !empty($exportFilePath)) {
626 $downloadFileMimeType = $mimetype;
627 $downloadFileFullName = $exportFileFullName;
628 $downloadFilePath = $exportFilePath;
633 if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath) && empty($noouput)) {
636 header(
'Content-Type: ' . $downloadFileMimeType);
637 header(
'Content-Disposition: attachment; filename=' . $downloadFileFullName);
638 header(
'Cache-Control: Public, must-revalidate');
639 header(
'Pragma: public');
640 header(
'Content-Length: ' .
dol_filesize($downloadFilePath));
645 $this->generatedfiledata = array(
'downloadFilePath' => $downloadFilePath,
'downloadFileMimeType' => $downloadFileMimeType,
'downloadFileFullName' => $downloadFileFullName);
670 foreach ($objectLines as $line) {
675 $tab[] = $date_document;
676 $tab[] = $line->code_journal;
679 $tab[] = $line->sens;
680 $tab[] =
price2fec(abs($line->debit - $line->credit));
684 $output = implode($separator, $tab).$end_line;
686 fwrite($exportFile, $output);
706 foreach ($objectLines as $line) {
710 if ($line->doc_type ==
'customer_invoice') {
712 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
713 $invoice =
new Facture($this->db);
714 $invoice->fetch($line->fk_doc);
716 $refInvoice = $invoice->ref;
717 } elseif ($line->doc_type ==
'supplier_invoice') {
719 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture.class.php';
721 $invoice->fetch($line->fk_doc);
723 $refInvoice = $invoice->ref_supplier;
728 $tab[] = $line->code_journal;
729 $tab[] = $date_document;
730 $tab[] = $refInvoice;
731 if (empty($line->subledger_account)) {
737 $tab[] = $line->label_operation;
738 $tab[] = $date_document;
739 if ($line->sens ==
'D') {
740 $tab[] =
price($line->debit);
742 } elseif ($line->sens ==
'C') {
744 $tab[] =
price($line->credit);
746 $tab[] = $line->doc_ref;
747 $tab[] = $line->label_operation;
749 $output = implode($separator, $tab).$end_line;
751 fwrite($exportFile, $output);
771 foreach ($objectLines as $line) {
776 $tab[] = $date_document;
777 $tab[] = $line->code_journal;
779 $tab[] = $line->piece_num;
780 $tab[] = $line->doc_ref;
781 $tab[] =
price($line->debit);
782 $tab[] =
price($line->credit);
786 $output = implode($separator, $tab).$end_line;
788 fwrite($exportFile, $output);
808 foreach ($objectLines as $line) {
813 $tab[] = $line->piece_num;
814 $tab[] = $date_document;
816 if (empty($line->subledger_account)) {
820 if (substr($line->numero_compte, 0, 3) ==
'411') {
823 if (substr($line->numero_compte, 0, 3) ==
'401') {
829 $tab[] =
price($line->debit);
830 $tab[] =
price($line->credit);
831 $tab[] =
dol_trunc($line->label_operation, 32);
833 $output = implode($separator, $tab).$end_line;
835 fwrite($exportFile, $output);
863 foreach ($objectLines as $line) {
865 if (!empty($line->subledger_account)) {
870 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
874 $tab[] = str_pad((
string) $line->piece_num, 5);
875 $tab[] = str_pad(self::trunc($line->code_journal, 2), 2);
876 $tab[] = str_pad($date_document, 8,
' ', STR_PAD_LEFT);
877 $tab[] = str_pad($date_echeance, 8,
' ', STR_PAD_LEFT);
878 $tab[] = str_pad(self::trunc($line->doc_ref, 12), 12);
879 $tab[] = str_pad(self::trunc($code_compta, 11), 11);
880 $tab[] = str_pad(self::trunc(
dol_string_unaccent($line->doc_ref).dol_string_unaccent($line->label_operation), 25), 25);
881 $tab[] = str_pad(
price2fec(abs($line->debit - $line->credit)), 13,
' ', STR_PAD_LEFT);
882 $tab[] = str_pad($line->sens, 1);
883 $tab[] = str_repeat(
' ', 18);
887 $output = implode($tab).$end_line;
889 fwrite($exportFile, $output);
912 public function exportQuadratus($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
918 $conf->cache[
'archiveFileList_notfound'] = array();
922 foreach ($objectLines as $line) {
928 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
929 $line->label_operation = str_replace(array(
"- ",
"…",
"..."),
"", $line->label_operation);
936 $line->subledger_label = str_replace(array(
"- ",
"…",
"..."),
"", $line->subledger_label);
939 $code_compta = $line->numero_compte;
940 if (!empty($line->subledger_account)) {
941 $code_compta = $line->subledger_account;
946 if (!empty($line->subledger_account)) {
947 $tab[
'type_ligne'] =
'C';
948 $tab[
'num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8);
949 $tab[
'lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30);
951 if ($line->doc_type ==
'customer_invoice') {
952 $tab[
'lib_alpha'] = strtoupper(self::trunc(
dol_string_unaccent($line->subledger_label), 7));
953 $tab[
'filler'] = str_repeat(
' ', 52);
954 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'), 8), 8);
955 } elseif ($line->doc_type ==
'supplier_invoice') {
956 $tab[
'lib_alpha'] = strtoupper(self::trunc(
dol_string_unaccent($line->subledger_label), 7));
957 $tab[
'filler'] = str_repeat(
' ', 52);
958 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'), 8), 8);
960 $tab[
'filler'] = str_repeat(
' ', 59);
961 $tab[
'coll_compte'] = str_pad(
' ', 8);
964 $tab[
'filler2'] = str_repeat(
' ', 110);
967 if ($line->doc_type ==
'customer_invoice') {
968 $tab[
'type_compte'] =
'C';
969 } elseif ($line->doc_type ==
'supplier_invoice') {
970 $tab[
'type_compte'] =
'F';
972 $tab[
'type_compte'] =
'G';
975 $tab[
'filler3'] = str_repeat(
' ', 235);
977 $tab[
'end_line'] = $end_line;
980 fwrite($exportFile, implode($tab));
987 $tab[
'type_ligne'] =
'M';
988 $tab[
'num_compte'] = str_pad(self::trunc((
string) $code_compta, 8), 8);
989 $tab[
'code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
990 $tab[
'folio'] =
'000';
995 $tab[
'date_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
996 $tab[
'filler'] =
' ';
997 $tab[
'libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.
' '.$line->label_operation, 20), 20);
1012 $tab[
'sens'] = $line->sens;
1013 $tab[
'signe_montant'] =
'+';
1016 $tab[
'montant'] = str_pad((
string) abs(($line->debit - $line->credit) * 100), 12,
'0', STR_PAD_LEFT);
1017 $tab[
'contrepartie'] = str_repeat(
' ', 8);
1020 if (!empty($line->date_lim_reglement)) {
1021 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%y');
1023 $tab[
'date_echeance'] =
'000000';
1028 $tab[
'lettrage'] = str_repeat(
' ', 2);
1029 $tab[
'codestat'] = str_repeat(
' ', 3);
1030 $tab[
'num_piece'] = str_pad(self::trunc((
string) $line->piece_num, 5), 5);
1034 $tab[
'affaire'] = str_repeat(
' ', 10);
1035 $tab[
'quantity1'] = str_repeat(
' ', 10);
1036 $tab[
'num_piece2'] = str_pad(self::trunc((
string) $line->piece_num, 8), 8);
1038 $tab[
'code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
1039 $tab[
'filler3'] = str_repeat(
' ', 3);
1047 $tab[
'libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
1048 $tab[
'codetva'] = str_repeat(
' ', 2);
1052 $tab[
'num_piece3'] = str_pad(substr(self::trunc($line->doc_ref, 20), -10), 10);
1053 $tab[
'reserved'] = str_repeat(
' ', 10);
1054 $tab[
'currency_amount'] = str_repeat(
' ', 13);
1057 $attachmentFileName =
'';
1058 if ($withAttachment == 1) {
1059 $attachmentFileKey = trim((
string) $line->piece_num);
1061 if (!isset($archiveFileList[$attachmentFileKey])) {
1063 $objectDirPath =
'';
1065 if ($line->doc_type ==
'customer_invoice') {
1066 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1067 } elseif ($line->doc_type ==
'expense_report') {
1068 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1069 } elseif ($line->doc_type ==
'supplier_invoice') {
1070 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1072 $invoice->fetch($line->fk_doc);
1073 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1074 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1077 if ($objectDirPath && empty($conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1078 $arrayofinclusion = array();
1080 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1082 $fileFoundPath =
'';
1083 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1085 if (!empty($fileFoundList)) {
1086 $attachmentFileNameTrunc = str_pad(self::trunc((
string) $line->piece_num, 8), 8,
'0', STR_PAD_LEFT);
1088 foreach ($fileFoundList as $fileFound) {
1089 if (strstr($fileFound[
'name'], $objectFileName)) {
1092 if ($line->doc_type ==
'supplier_invoice') {
1093 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1096 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1099 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1100 if (file_exists($fileFoundPath)) {
1101 $archiveFileList[$attachmentFileKey] = array(
1102 'path' => $fileFoundPath,
1103 'name' => $attachmentFileNameTrunc.
'.pdf',
1111 if (empty($fileFoundPath)) {
1113 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1118 if (isset($archiveFileList[$attachmentFileKey])) {
1119 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1123 if (
dol_strlen((
string) $attachmentFileName) == 12) {
1124 $tab[
'attachment'] = $attachmentFileName;
1126 $tab[
'attachment'] = str_repeat(
' ', 12);
1128 $tab[
'filler4'] = str_repeat(
' ', 38);
1129 $tab[
'end_line'] = $end_line;
1132 fwrite($exportFile, implode($tab));
1134 print implode($tab);
1138 return $archiveFileList;
1160 foreach ($objectLines as $line) {
1161 $code_compta = $line->numero_compte;
1162 if (!empty($line->subledger_account)) {
1163 $code_compta = $line->subledger_account;
1168 $tab[
'code_journal'] = str_pad(
dol_trunc($line->code_journal, 2,
'right',
'UTF-8', 1), 2);
1173 $tab[
'date_operation'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1175 $tab[
'folio'] =
' 1';
1177 $tab[
'num_ecriture'] = str_pad(
dol_trunc((
string) $index, 6,
'right',
'UTF-8', 1), 6,
' ', STR_PAD_LEFT);
1179 $tab[
'jour_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
1181 $tab[
'num_compte'] = str_pad(
dol_trunc((
string) $code_compta, 6,
'right',
'UTF-8', 1), 6,
'0');
1183 if ($line->sens ==
'D') {
1184 $tab[
'montant_debit'] = str_pad(number_format($line->debit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1186 $tab[
'montant_crebit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1188 $tab[
'montant_debit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1190 $tab[
'montant_crebit'] = str_pad(number_format($line->credit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1195 $tab[
'lettrage'] = str_repeat(
dol_trunc((
string) $line->lettering_code, 2,
'left',
'UTF-8', 1), 2);
1197 $tab[
'code_piece'] = str_pad(
dol_trunc((
string) $line->piece_num, 5,
'left',
'UTF-8', 1), 5,
' ', STR_PAD_LEFT);
1199 $tab[
'code_stat'] = str_repeat(
' ', 4);
1201 if (!empty($line->date_lim_reglement)) {
1202 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%Y');
1204 $tab[
'date_echeance'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1207 $tab[
'monnaie'] =
'1';
1209 $tab[
'filler'] =
' ';
1211 $tab[
'ind_compteur'] =
' ';
1213 $tab[
'quantite'] =
'0,000000000';
1215 $tab[
'code_pointage'] = str_repeat(
' ', 2);
1217 $tab[
'end_line'] = $end_line;
1219 $output = implode(
'|', $tab);
1221 fwrite($exportFile, $output);
1243 foreach ($objectLines as $line) {
1249 $tab[] = $date_document;
1250 $tab[] = $line->code_journal;
1251 if (empty($line->subledger_account)) {
1252 $tab[] = $line->numero_compte;
1254 $tab[] = $line->subledger_account;
1257 $tab[] =
'"'.dol_trunc($line->label_operation, 40,
'right',
'UTF-8', 1).
'"';
1258 $tab[] =
'"'.dol_trunc((
string) $line->piece_num, 15,
'right',
'UTF-8', 1).
'"';
1259 $tab[] =
price2num(abs($line->debit - $line->credit));
1260 $tab[] = $line->sens;
1261 $tab[] = $date_document;
1264 $output = implode($separator, $tab).$end_line;
1266 fwrite($exportFile, $output);
1286 foreach ($objectLines as $line) {
1291 $tab[] = $line->piece_num;
1293 $tab[] = $date_document;
1296 if (empty($line->subledger_account)) {
1305 $tab[] =
price($line->debit);
1306 $tab[] =
price($line->credit);
1307 $tab[] =
price(abs($line->debit - $line->credit));
1308 $tab[] = $line->sens;
1309 $tab[] = $line->lettering_code;
1310 $tab[] = $line->code_journal;
1312 $output = implode($separator, $tab).$end_line;
1314 fwrite($exportFile, $output);
1333 foreach ($objectLines as $line) {
1338 $tab[] = $date_document;
1339 $tab[] = $line->code_journal;
1340 if (empty($line->subledger_account)) {
1345 $tab[] = $line->doc_ref;
1346 $tab[] = $line->label_operation;
1347 $tab[] =
price($line->debit);
1348 $tab[] =
price($line->credit);
1350 $output = implode($separator, $tab).$end_line;
1352 fwrite($exportFile, $output);
1370 $separator = $this->separator;
1372 foreach ($objectLines as $line) {
1377 $tab[] = $line->piece_num;
1378 $tab[] = $date_document;
1379 $tab[] = $line->doc_ref;
1380 $tab[] = preg_match(
'/'.$separator.
'/', $line->label_operation) ?
"'".$line->label_operation.
"'" : $line->label_operation;
1385 $tab[] =
price2num($line->debit - $line->credit);
1386 $tab[] = $line->code_journal;
1388 $output = implode($separator, $tab).$this->end_line;
1390 fwrite($exportFile, $output);
1413 foreach ($objectLines as $line) {
1414 if ($line->subledger_account && substr($line->subledger_account, 0, 1) ==
'4') {
1415 $tiers[$line->piece_num] = $line->subledger_label;
1419 foreach ($objectLines as $line) {
1424 $search = array(
'Paiement fournisseur ',
'Virement ',
'Paiement ');
1425 $replace = array(
'Paiemt fourn ',
'Virt ',
'Paiemt ');
1426 $label_operation = str_replace($search, $replace, $line->label_operation);
1428 $label_operation = preg_match(
'/'.$separator.
'/', $label_operation) ?
"'".$label_operation.
"'" : $label_operation;
1432 $tab[] = $line->piece_num;
1433 $tab[] = $date_document;
1434 $tab[] = $line->doc_ref;
1435 $tab[] = array_key_exists($line->piece_num, $tiers) ? $tiers[$line->piece_num] :
'';
1436 $tab[] =
length_accountg(($line->subledger_account && (substr($line->subledger_account, 0, 2) == substr($line->numero_compte, 0, 2))) ? $line->subledger_account : $line->numero_compte);
1437 $tab[] =
length_accountg($line->subledger_account ? $line->subledger_account : $line->numero_compte);
1438 $tab[] =
length_accountg($line->subledger_account ? $line->numero_compte :
'');
1439 $tab[] = ($line->doc_type ==
'bank') ? $label_operation : ($line->subledger_account ? $line->subledger_label : $line->label_compte);
1440 $tab[] = $label_operation;
1443 $tab[] = $line->code_journal;
1445 $output = mb_convert_encoding(
'"'.implode(
'"'.$separator.
'"', $tab).
'"'.$this->end_line,
'ISO-8859-1');
1447 fwrite($exportFile, $output);
1466 public function exportFEC($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1468 global $conf, $langs;
1474 $tab[] =
"JournalCode";
1475 $tab[] =
"JournalLib";
1476 $tab[] =
"EcritureNum";
1477 $tab[] =
"EcritureDate";
1478 $tab[] =
"CompteNum";
1479 $tab[] =
"CompteLib";
1480 $tab[] =
"CompAuxNum";
1481 $tab[] =
"CompAuxLib";
1482 $tab[] =
"PieceRef";
1483 $tab[] =
"PieceDate";
1484 $tab[] =
"EcritureLib";
1487 $tab[] =
"EcritureLet";
1489 $tab[] =
"ValidDate";
1490 $tab[] =
"Montantdevise";
1492 $tab[] =
"DateLimitReglmt";
1493 $tab[] =
"NumFacture";
1494 $tab[] =
"FichierFacture";
1496 $output = implode($separator, $tab).$end_line;
1498 fwrite($exportFile, $output);
1503 $conf->cache[
'archiveFileList_notfound'] = array();
1506 foreach ($objectLines as $line) {
1507 if ($line->debit == 0 && $line->credit == 0) {
1515 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1516 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1517 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1523 if ($line->doc_type ==
'customer_invoice') {
1525 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1526 $invoice =
new Facture($this->db);
1527 $invoice->fetch($line->fk_doc);
1529 $refInvoice = (string) $invoice->ref;
1530 } elseif ($line->doc_type ==
'supplier_invoice') {
1532 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1534 $invoice->fetch($line->fk_doc);
1536 $refInvoice = (string) $invoice->ref_supplier;
1542 $tab[] = $line->code_journal;
1547 $tab[] = $labeljournal;
1550 $tab[] = $line->piece_num;
1553 $tab[] = $date_document;
1568 $tab[] = $line->doc_ref;
1575 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1576 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1586 $tab[] = $line->lettering_code;
1589 $tab[] = $date_lettering;
1592 $tab[] = $date_validation;
1595 $tab[] = $line->multicurrency_amount;
1598 $tab[] = $line->multicurrency_code;
1601 $tab[] = $date_limit_payment;
1605 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1606 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1610 $attachmentFileName =
'';
1611 if ($withAttachment == 1) {
1612 $attachmentFileKey = trim((
string) $line->piece_num);
1614 if (!isset($archiveFileList[$attachmentFileKey])) {
1616 $objectDirPath =
'';
1618 if ($line->doc_type ==
'customer_invoice') {
1619 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1620 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1622 } elseif ($line->doc_type ==
'expense_report') {
1623 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1624 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1626 } elseif ($line->doc_type ==
'supplier_invoice' && $invoice instanceof
FactureFournisseur) {
1627 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1628 '@phan-var-force FactureFournisseur $invoice';
1629 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1630 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1634 if ($objectDirPath && empty($conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1635 $arrayofinclusion = array();
1637 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1639 $fileFoundPath =
'';
1640 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1642 if (!empty($fileFoundList)) {
1643 $attachmentFileNameTrunc = $line->doc_ref;
1645 foreach ($fileFoundList as $fileFound) {
1646 if (strstr($fileFound[
'name'], $objectFileName)) {
1649 if ($line->doc_type ==
'supplier_invoice') {
1650 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1653 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1656 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1657 if (file_exists($fileFoundPath)) {
1658 $archiveFileList[$attachmentFileKey] = array(
1659 'path' => $fileFoundPath,
1660 'name' => $attachmentFileNameTrunc.
'.pdf',
1668 if (empty($fileFoundPath)) {
1670 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1675 if (isset($archiveFileList[$attachmentFileKey])) {
1676 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1680 $tab[] = $attachmentFileName;
1682 $output = implode($separator, $tab).$end_line;
1685 fwrite($exportFile, $output);
1692 return $archiveFileList;
1707 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1709 global $conf, $langs;
1715 $tab[] =
"JournalCode";
1716 $tab[] =
"JournalLib";
1717 $tab[] =
"EcritureNum";
1718 $tab[] =
"EcritureDate";
1719 $tab[] =
"CompteNum";
1720 $tab[] =
"CompteLib";
1721 $tab[] =
"CompAuxNum";
1722 $tab[] =
"CompAuxLib";
1723 $tab[] =
"PieceRef";
1724 $tab[] =
"PieceDate";
1725 $tab[] =
"EcritureLib";
1728 $tab[] =
"EcritureLet";
1730 $tab[] =
"ValidDate";
1731 $tab[] =
"Montantdevise";
1733 $tab[] =
"DateLimitReglmt";
1734 $tab[] =
"NumFacture";
1735 $tab[] =
"FichierFacture";
1737 $output = implode($separator, $tab).$end_line;
1739 fwrite($exportFile, $output);
1744 $conf->cache[
'archiveFileList_notfound'] = array();
1747 foreach ($objectLines as $line) {
1748 if ($line->debit == 0 && $line->credit == 0) {
1755 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1756 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1757 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1763 if ($line->doc_type ==
'customer_invoice') {
1765 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1766 $invoice =
new Facture($this->db);
1767 $invoice->fetch($line->fk_doc);
1769 $refInvoice = (string) $invoice->ref;
1770 } elseif ($line->doc_type ==
'supplier_invoice') {
1772 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1774 $invoice->fetch($line->fk_doc);
1776 $refInvoice = (string) $invoice->ref_supplier;
1782 $tab[] = $line->code_journal;
1787 $tab[] = $labeljournal;
1790 $tab[] = $line->piece_num;
1793 $tab[] = $date_creation;
1808 $tab[] = $line->doc_ref;
1811 $tab[] = $date_document;
1815 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1816 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1826 $tab[] = $line->lettering_code;
1829 $tab[] = $date_lettering;
1832 $tab[] = $date_validation;
1835 $tab[] = $line->multicurrency_amount;
1838 $tab[] = $line->multicurrency_code;
1841 $tab[] = $date_limit_payment;
1845 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1846 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1850 $attachmentFileName =
'';
1851 if ($withAttachment == 1) {
1852 $attachmentFileKey = trim((
string) $line->piece_num);
1854 if (!isset($archiveFileList[$attachmentFileKey])) {
1856 $objectDirPath =
'';
1858 if ($line->doc_type ==
'customer_invoice') {
1859 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1860 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1862 } elseif ($line->doc_type ==
'expense_report') {
1863 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1864 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1866 } elseif ($line->doc_type ==
'supplier_invoice' && $invoice instanceof
FactureFournisseur) {
1867 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1868 '@phan-var-force FactureFournisseur $invoice';
1869 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1870 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1874 if ($objectDirPath && empty($conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1875 $arrayofinclusion = array();
1877 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1879 $fileFoundPath =
'';
1880 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1882 if (!empty($fileFoundList)) {
1883 $attachmentFileNameTrunc = $line->doc_ref;
1885 foreach ($fileFoundList as $fileFound) {
1886 if (strstr($fileFound[
'name'], $objectFileName)) {
1889 if ($line->doc_type ==
'supplier_invoice') {
1890 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1893 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1896 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1897 if (file_exists($fileFoundPath)) {
1898 $archiveFileList[$attachmentFileKey] = array(
1899 'path' => $fileFoundPath,
1900 'name' => $attachmentFileNameTrunc.
'.pdf',
1908 if (empty($fileFoundPath)) {
1910 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1915 if (isset($archiveFileList[$attachmentFileKey])) {
1916 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1920 $tab[] = $attachmentFileName;
1922 $output = implode($separator, $tab).$end_line;
1924 fwrite($exportFile, $output);
1931 return $archiveFileList;
1967 $tab[] =
"FW-Betrag";
1974 $output = implode($separator, $tab).$end_line;
1976 fwrite($exportFile, $output);
1982 $thisPieceAccountNr =
"";
1983 $aSize = count($objectLines);
1984 foreach ($objectLines as $aIndex => $line) {
1985 $sammelBuchung =
false;
1986 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1987 $sammelBuchung =
true;
1988 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1989 $sammelBuchung =
true;
1990 } elseif ($aIndex + 1 < $aSize
1991 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1992 && $aIndex - 1 < $aSize
1993 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1995 $sammelBuchung =
true;
2001 $tab[] = $line->piece_num;
2005 $tab[] = $date_document;
2010 if ($line->sens ==
'D') {
2018 if (empty($line->code_tiers)) {
2019 if ($line->piece_num == $thisPieceNum) {
2028 $tab[] = $this->separator;
2037 if ($sammelBuchung) {
2045 $tab[] = abs($line->debit - $line->credit);
2052 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
2056 if (strlen($line1) == 0) {
2060 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
2061 $line1 = $line1.
' / '.$line2;
2065 $tab[] =
'"'.self::toAnsi($line1).
'"';
2067 $tab[] =
'"'.self::toAnsi($line2).
'"';
2071 $tab[] = $this->separator;
2076 $output = implode($separator, $tab).$end_line;
2078 fwrite($exportFile, $output);
2083 if ($line->piece_num !== $thisPieceNum) {
2084 $thisPieceNum = $line->piece_num;
2085 $thisPieceAccountNr = $line->numero_compte;
2103 foreach ($objectLines as $line) {
2106 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2111 $type_enregistrement =
'E';
2112 $tab[] = $type_enregistrement;
2114 $tab[] = substr($line->code_journal, 0, 2);
2118 $tab[] = $line->piece_num;
2120 $tab[] = $date_document;
2122 $tab[] = $line->label_operation;
2124 $tab[] = $date_lim_reglement;
2126 if ($line->doc_type ==
'supplier_invoice') {
2127 if (($line->debit - $line->credit) > 0) {
2128 $nature_piece =
'AF';
2130 $nature_piece =
'FF';
2132 } elseif ($line->doc_type ==
'customer_invoice') {
2133 if (($line->debit - $line->credit) < 0) {
2134 $nature_piece =
'AC';
2136 $nature_piece =
'FC';
2141 $tab[] = $nature_piece;
2152 $racine_subledger_account =
'';
2155 $tab[] = $racine_subledger_account;
2157 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
2159 $tab[] = $line->sens;
2163 $tab[] = $date_creation;
2165 $tab[] = $line->lettering_code;
2167 $tab[] = $line->date_lettering;
2169 if (!empty($line->subledger_account)) {
2175 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2177 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2191 $tab[] = $line->doc_ref;
2219 $output = implode($separator, $tab).$end_line;
2221 fwrite($exportFile, $output);
2240 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2244 $last_codeinvoice =
'';
2246 foreach ($objectLines as $line) {
2248 if ($last_codeinvoice != $line->doc_ref) {
2250 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2251 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2252 $resql = $this->db->query($sql);
2254 if ($resql && $this->db->num_rows($resql) > 0) {
2255 $soc = $this->db->fetch_object($resql);
2257 $address = array(
'',
'',
'');
2258 if (strpos($soc->address,
"\n") !==
false) {
2259 $address = explode(
"\n", $soc->address);
2260 if (is_array($address) && count($address) > 0) {
2261 foreach ($address as $key => $data) {
2262 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2263 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2267 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2268 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2269 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2274 $type_enregistrement =
'C';
2276 $tab[] = $type_enregistrement;
2278 $tab[] = $soc->code_client;
2288 $tab[] = $address[0];
2290 $tab[] = $address[1];
2292 $tab[] = $address[2];
2296 $tab[] = substr($soc->town, 0, 40);
2300 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2302 $tab[] = $soc->phone;
2314 $tab[] = str_replace(
" ",
"", $soc->siret);
2372 $output = implode($separator, $tab).$end_line;
2374 fwrite($exportFile, $output);
2385 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2388 $type_enregistrement =
'E';
2389 $tab[] = $type_enregistrement;
2391 $tab[] = substr($line->code_journal, 0, 2);
2395 $tab[] = $line->piece_num;
2397 $tab[] = $date_document;
2399 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2401 $tab[] = $date_lim_reglement;
2403 if ($line->doc_type ==
'supplier_invoice') {
2404 if (($line->amount) < 0) {
2405 $nature_piece =
'AF';
2407 $nature_piece =
'FF';
2409 } elseif ($line->doc_type ==
'customer_invoice') {
2410 if (($line->amount) < 0) {
2411 $nature_piece =
'AC';
2413 $nature_piece =
'FC';
2418 $tab[] = $nature_piece;
2429 $racine_subledger_account =
'';
2432 $tab[] = $racine_subledger_account;
2434 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2436 $tab[] = $line->sens;
2440 $tab[] = $date_document;
2442 $tab[] = $line->lettering_code;
2444 $tab[] = $line->date_lettering;
2446 if (!empty($line->subledger_account)) {
2452 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2454 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2466 $tab[] = $line->doc_ref;
2500 $output = implode($separator, $tab).$end_line;
2502 fwrite($exportFile, $output);
2507 $last_codeinvoice = $line->doc_ref;
2521 $langs->load(
'compta');
2528 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2529 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2530 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2531 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2532 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2533 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2534 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2536 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2537 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2538 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2539 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2540 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2541 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2543 $output = implode($separator, $tab).$end_line;
2545 fwrite($exportFile, $output);
2550 foreach ($objectLines as $line) {
2555 $tab[] = $date_document;
2559 if (!empty($line->subledger_account)) {
2560 $account = $line->subledger_account;
2562 $account = $line->numero_compte;
2569 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2571 $tab[] =
price(abs($line->debit - $line->credit));
2572 $tab[] = $line->sens;
2580 $output = implode($separator, $tab).$end_line;
2582 fwrite($exportFile, $output);
2603 $invoices_infos = array();
2604 $supplier_invoices_infos = array();
2605 foreach ($objectLines as $line) {
2606 if ($line->debit == 0 && $line->credit == 0) {
2610 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2612 $invoice_ref = $line->doc_ref;
2615 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2616 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2617 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2618 if ($line->doc_type ==
'customer_invoice') {
2620 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2621 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2622 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2623 $resql = $this->db->query($sql);
2625 if ($obj = $this->db->fetch_object($resql)) {
2627 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2628 $invoice_ref = $obj->ref;
2629 $company_name = $obj->nom;
2634 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2635 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2636 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2637 $resql = $this->db->query($sql);
2639 if ($obj = $this->db->fetch_object($resql)) {
2641 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2642 $invoice_ref = $obj->ref;
2643 $company_name = $obj->nom;
2647 } elseif ($line->doc_type ==
'customer_invoice') {
2649 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2650 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2653 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2654 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2661 $tab[] = $date_document;
2662 $tab[] = substr($line->code_journal, 0, 4);
2664 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2673 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2675 $tab[] =
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1);
2679 $tab[] =
price2num(abs($line->debit - $line->credit));
2681 $tab[] = $line->sens;
2685 $tab[] = $date_echeance;
2687 $output = implode($separator, $tab).$end_line;
2689 fwrite($exportFile, $output);
2709 foreach ($objectLines as $line) {
2710 if ($line->debit == 0 && $line->credit == 0) {
2718 $tab[] = $date_document;
2719 $tab[] = substr($line->code_journal, 0, 4);
2720 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2726 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2727 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2728 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2729 $tab[] =
price2num(abs($line->debit - $line->credit));
2730 $tab[] = $line->sens;
2731 $tab[] = $date_document;
2736 $output = implode($separator, $tab).$end_line;
2738 fwrite($exportFile, $output);
2761 foreach ($objectLines as $line) {
2766 $tab[] = $line->piece_num;
2768 $tab[] = substr($date, 6, 4);
2769 $tab[] = substr($date, 3, 2);
2770 $tab[] = substr($date, 0, 2);
2771 $tab[] = $line->doc_ref;
2773 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2779 $numero_cpt_client =
'411';
2780 $numero_cpt_fourn =
'401';
2781 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2782 $numero_cpt_client .=
'0';
2783 $numero_cpt_fourn .=
'0';
2792 $nom_client = explode(
" - ", $line->label_operation);
2793 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2794 $tab[] =
price($line->debit);
2795 $tab[] =
price($line->credit);
2796 $tab[] =
price($line->montant);
2797 $tab[] = $line->code_journal;
2799 $output = implode($separator, $tab).$end_line;
2801 fwrite($exportFile, $output);
2815 public static function trunc($str, $size)
2817 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2827 public static function toAnsi($str, $size = -1)
2830 if ($retVal >= 0 && $size >= 0) {
2831 $retVal =
dol_substr($retVal, 0, $size,
'Windows-1251');
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
Manage the different format accountancy export.
exportCogilog($objectLines, $exportFile=null)
Export format : COGILOG Last review for this format : 2022-07-12 Alexandre Spangaro (aspangaro@open-d...
export(&$TData, $formatexportset, $withAttachment=0, $downloadMode=1, $outputMode=1, $noouput=1)
Function who chose which export to use with the default config, and make the export into a file.
exportAgiris($objectLines, $exportFile=null)
Export format : Agiris Isacompta.
exportQuadratus($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : Quadratus (Format ASCII) Format since 2015 compatible QuadraCOMPTA Last review for th...
exportWinfic($objectLines, $exportFile=null)
Export format : WinFic - eWinfic - WinSis Compta Last review for this format : 2022-11-01 Alexandre S...
exportSAGE50SWISS($objectLines, $exportFile=null)
Export format : SAGE50SWISS.
exportOpenConcerto($objectLines, $exportFile=null)
Export format : OpenConcerto.
exportEbp($objectLines, $exportFile=null)
Export format : EBP.
exportLDCompta10($objectLines, $exportFile=null)
Export format : LD Compta version 10 & higher Last review for this format : 08-15-2021 Alexandre Span...
exportCharlemagne($objectLines, $exportFile=null)
Export format : Charlemagne.
getTypeConfig()
Array with all export types available (key + label) and parameters for config.
exportFEC($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : FEC Last review for this format : 2023/10/12 Alexandre Spangaro (aspangaro@open-dsi....
exportISTEA($objectLines, $exportFile=null)
Export format : ISTEA.
exportLDCompta($objectLines, $exportFile=null)
Export format : LD Compta version 9 http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Docu...
exportBob50($objectLines, $exportFile=null)
Export format : BOB50.
exportGestimumV3($objectLines, $exportFile=null)
Export format : Gestimum V3.
static trunc($str, $size)
trunc
exportiSuiteExpert($objectLines, $exportFile=null)
Export format : iSuite Expert.
exportCiel($objectLines, $exportFile=null)
Export format : CIEL (Format XIMPORT) Format since 2003 compatible CIEL version > 2002 / Sage50 Last ...
getType($mode=0)
Array with all export type available (key + label)
static toAnsi($str, $size=-1)
toAnsi
exportConfigurable($objectLines, $exportFile=null)
Export format : Configurable CSV.
static getFormatCode($type)
Return string to summarize the format (Used to generated export filename)
exportFEC2($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : FEC2 Last review for this format : 2023/10/12 Alexandre Spangaro (aspangaro@open-dsi....
__construct(DoliDB $db)
Constructor.
exportCegid($objectLines, $exportFile=null)
Export format : CEGID.
exportCoala($objectLines, $exportFile=null)
Export format : COALA.
getMimeType($formatexportset)
Return the MIME type of a file.
exportGestimumV5($objectLines, $exportFile=null)
Export format : Gestimum V5.
Class to manage Dolibarr database access.
Class to manage suppliers invoices.
Class to manage invoices.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_filesize($pathoffile)
Return size of a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
price2fec($amount)
Function to format a value into a defined format for French administration (no thousand separator & d...
dol_now($mode='gmt')
Return date for now.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.