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;
389 $filename =
'general_ledger-'.$this->getFormatCode($formatexportset);
390 $type_export =
'general_ledger';
392 $completefilename =
'';
394 $exportFileName =
'';
395 $exportFilePath =
'';
396 $exportFileFullName =
'';
397 $downloadFileMimeType =
'';
398 $downloadFileFullName =
'';
399 $downloadFilePath =
'';
400 $archiveFullName =
'';
402 $archiveFileList = array();
403 if ($withAttachment == 1) {
404 if ($downloadMode == 0) {
407 if ($outputMode == 0) {
412 if (!extension_loaded(
'zip')) {
413 $langs->load(
'install');
414 $this->errors[] = $langs->trans(
'ErrorPHPDoesNotSupport',
'ZIP');
420 if ($downloadMode == 0) {
426 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
428 if ($outputMode == 1 || $outputMode == 2) {
429 if ($outputMode == 1) {
431 if (!empty($conf->accounting->multidir_temp[$conf->entity])) {
432 $outputDir = $conf->accounting->multidir_temp[$conf->entity];
434 $outputDir = $conf->accounting->dir_temp;
438 if (!empty($conf->accounting->multidir_output[$conf->entity])) {
439 $outputDir = $conf->accounting->multidir_output[$conf->entity];
441 $outputDir = $conf->accounting->dir_output;
445 $outputDir .=
'/export';
446 $outputDir .=
'/'.dol_sanitizePathName((
string) $formatexportset);
451 $this->errors[] = $langs->trans(
'ErrorCanNotCreateDir', $outputDir);
456 if ($outputDir !=
'') {
458 $langs->load(
'errors');
459 $this->errors[] = $langs->trans(
'ErrorDirNotFound', $outputDir);
463 if (!empty($completefilename)) {
465 $exportFileFullName = $completefilename;
466 $exportFileBaseName = basename($exportFileFullName);
467 $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME);
468 $exportFilePath = $outputDir .
'/' . $exportFileFullName;
469 $exportFile = fopen($exportFilePath,
'w');
471 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $exportFilePath);
475 if ($withAttachment == 1) {
476 $archiveFileList[0] = array(
477 'path' => $exportFilePath,
478 'name' => $exportFileFullName,
482 $archiveFullName = $exportFileName .
'.zip';
483 $archivePath = $outputDir .
'/' . $archiveFullName;
490 switch ($formatexportset) {
491 case self::$EXPORT_TYPE_CONFIGURABLE:
494 case self::$EXPORT_TYPE_CEGID:
497 case self::$EXPORT_TYPE_COALA:
500 case self::$EXPORT_TYPE_BOB50:
503 case self::$EXPORT_TYPE_CIEL:
506 case self::$EXPORT_TYPE_QUADRATUS:
507 $archiveFileList = $this->
exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment);
509 case self::$EXPORT_TYPE_WINFIC:
512 case self::$EXPORT_TYPE_EBP:
515 case self::$EXPORT_TYPE_COGILOG:
518 case self::$EXPORT_TYPE_AGIRIS:
521 case self::$EXPORT_TYPE_OPENCONCERTO:
524 case self::$EXPORT_TYPE_SAGE50_SWISS:
527 case self::$EXPORT_TYPE_CHARLEMAGNE:
530 case self::$EXPORT_TYPE_LDCOMPTA:
533 case self::$EXPORT_TYPE_LDCOMPTA10:
536 case self::$EXPORT_TYPE_GESTIMUMV3:
539 case self::$EXPORT_TYPE_GESTIMUMV5:
542 case self::$EXPORT_TYPE_FEC:
543 $archiveFileList = $this->
exportFEC($TData, $exportFile, $archiveFileList, $withAttachment);
545 case self::$EXPORT_TYPE_FEC2:
546 $archiveFileList = $this->
exportFEC2($TData, $exportFile, $archiveFileList, $withAttachment);
548 case self::$EXPORT_TYPE_ISUITEEXPERT:
551 case self::$EXPORT_TYPE_ISTEA:
556 $parameters = array(
'format' => $formatexportset,
'exportFile' => $exportFile);
558 $reshook = $hookmanager->executeHooks(
'export', $parameters, $TData);
560 $this->errors[] = $langs->trans(
'accountancy_error_modelnotfound');
567 if ($outputMode == 1 || $outputMode == 2) {
575 if ($withAttachment == 1) {
577 if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
579 $downloadFileMimeType =
'application/zip';
580 $downloadFileFullName = $archiveFullName;
581 $downloadFilePath = $archivePath;
584 $archive =
new ZipArchive();
585 $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
588 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $archivePath);
592 foreach ($archiveFileList as $archiveFileArr) {
593 $res = $archive->addFile($archiveFileArr[
'path'], $archiveFileArr[
'name']);
596 $this->errors[] = $langs->trans(
'ErrorArchiveAddFile', $archiveFileArr[
'name']);
610 if ($downloadMode == 1) {
611 if ($withAttachment == 0) {
613 if (!empty($exportFileFullName) && !empty($exportFilePath)) {
614 $downloadFileMimeType = $mimetype;
615 $downloadFileFullName = $exportFileFullName;
616 $downloadFilePath = $exportFilePath;
621 if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath) && empty($noouput)) {
624 header(
'Content-Type: ' . $downloadFileMimeType);
625 header(
'Content-Disposition: attachment; filename=' . $downloadFileFullName);
626 header(
'Cache-Control: Public, must-revalidate');
627 header(
'Pragma: public');
628 header(
'Content-Length: ' .
dol_filesize($downloadFilePath));
633 $this->generatedfiledata = array(
'downloadFilePath' => $downloadFilePath,
'downloadFileMimeType' => $downloadFileMimeType,
'downloadFileFullName' => $downloadFileFullName);
658 foreach ($objectLines as $line) {
663 $tab[] = $date_document;
664 $tab[] = $line->code_journal;
667 $tab[] = $line->sens;
668 $tab[] =
price2fec(abs($line->debit - $line->credit));
672 $output = implode($separator, $tab).$end_line;
674 fwrite($exportFile, $output);
694 foreach ($objectLines as $line) {
698 if ($line->doc_type ==
'customer_invoice') {
700 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
701 $invoice =
new Facture($this->db);
702 $invoice->fetch($line->fk_doc);
704 $refInvoice = $invoice->ref;
705 } elseif ($line->doc_type ==
'supplier_invoice') {
707 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture.class.php';
709 $invoice->fetch($line->fk_doc);
711 $refInvoice = $invoice->ref_supplier;
716 $tab[] = $line->code_journal;
717 $tab[] = $date_document;
718 $tab[] = $refInvoice;
719 if (empty($line->subledger_account)) {
725 $tab[] = $line->label_operation;
726 $tab[] = $date_document;
727 if ($line->sens ==
'D') {
728 $tab[] =
price($line->debit);
730 } elseif ($line->sens ==
'C') {
732 $tab[] =
price($line->credit);
734 $tab[] = $line->doc_ref;
735 $tab[] = $line->label_operation;
737 $output = implode($separator, $tab).$end_line;
739 fwrite($exportFile, $output);
759 foreach ($objectLines as $line) {
764 $tab[] = $date_document;
765 $tab[] = $line->code_journal;
767 $tab[] = $line->piece_num;
768 $tab[] = $line->doc_ref;
769 $tab[] =
price($line->debit);
770 $tab[] =
price($line->credit);
774 $output = implode($separator, $tab).$end_line;
776 fwrite($exportFile, $output);
796 foreach ($objectLines as $line) {
801 $tab[] = $line->piece_num;
802 $tab[] = $date_document;
804 if (empty($line->subledger_account)) {
808 if (substr($line->numero_compte, 0, 3) ==
'411') {
811 if (substr($line->numero_compte, 0, 3) ==
'401') {
817 $tab[] =
price($line->debit);
818 $tab[] =
price($line->credit);
819 $tab[] =
dol_trunc($line->label_operation, 32);
821 $output = implode($separator, $tab).$end_line;
823 fwrite($exportFile, $output);
851 foreach ($objectLines as $line) {
853 if (!empty($line->subledger_account)) {
858 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
862 $tab[] = str_pad((
string) $line->piece_num, 5);
863 $tab[] = str_pad(self::trunc($line->code_journal, 2), 2);
864 $tab[] = str_pad($date_document, 8,
' ', STR_PAD_LEFT);
865 $tab[] = str_pad($date_echeance, 8,
' ', STR_PAD_LEFT);
866 $tab[] = str_pad(self::trunc($line->doc_ref, 12), 12);
867 $tab[] = str_pad(self::trunc($code_compta, 11), 11);
868 $tab[] = str_pad(self::trunc(
dol_string_unaccent($line->doc_ref).dol_string_unaccent($line->label_operation), 25), 25);
869 $tab[] = str_pad(
price2fec(abs($line->debit - $line->credit)), 13,
' ', STR_PAD_LEFT);
870 $tab[] = str_pad($line->sens, 1);
871 $tab[] = str_repeat(
' ', 18);
875 $output = implode($tab).$end_line;
877 fwrite($exportFile, $output);
900 public function exportQuadratus($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
906 $conf->cache[
'archiveFileList_notfound'] = array();
910 foreach ($objectLines as $line) {
916 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
917 $line->label_operation = str_replace(array(
"- ",
"…",
"..."),
"", $line->label_operation);
924 $line->subledger_label = str_replace(array(
"- ",
"…",
"..."),
"", $line->subledger_label);
927 $code_compta = $line->numero_compte;
928 if (!empty($line->subledger_account)) {
929 $code_compta = $line->subledger_account;
934 if (!empty($line->subledger_account)) {
935 $tab[
'type_ligne'] =
'C';
936 $tab[
'num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8);
937 $tab[
'lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30);
939 if ($line->doc_type ==
'customer_invoice') {
940 $tab[
'lib_alpha'] = strtoupper(self::trunc(
dol_string_unaccent($line->subledger_label), 7));
941 $tab[
'filler'] = str_repeat(
' ', 52);
942 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'), 8), 8);
943 } elseif ($line->doc_type ==
'supplier_invoice') {
944 $tab[
'lib_alpha'] = strtoupper(self::trunc(
dol_string_unaccent($line->subledger_label), 7));
945 $tab[
'filler'] = str_repeat(
' ', 52);
946 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'), 8), 8);
948 $tab[
'filler'] = str_repeat(
' ', 59);
949 $tab[
'coll_compte'] = str_pad(
' ', 8);
952 $tab[
'filler2'] = str_repeat(
' ', 110);
955 if ($line->doc_type ==
'customer_invoice') {
956 $tab[
'type_compte'] =
'C';
957 } elseif ($line->doc_type ==
'supplier_invoice') {
958 $tab[
'type_compte'] =
'F';
960 $tab[
'type_compte'] =
'G';
963 $tab[
'filler3'] = str_repeat(
' ', 235);
965 $tab[
'end_line'] = $end_line;
968 fwrite($exportFile, implode($tab));
975 $tab[
'type_ligne'] =
'M';
976 $tab[
'num_compte'] = str_pad(self::trunc((
string) $code_compta, 8), 8);
977 $tab[
'code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
978 $tab[
'folio'] =
'000';
983 $tab[
'date_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
984 $tab[
'filler'] =
' ';
985 $tab[
'libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.
' '.$line->label_operation, 20), 20);
1000 $tab[
'sens'] = $line->sens;
1001 $tab[
'signe_montant'] =
'+';
1004 $tab[
'montant'] = str_pad((
string) abs(($line->debit - $line->credit) * 100), 12,
'0', STR_PAD_LEFT);
1005 $tab[
'contrepartie'] = str_repeat(
' ', 8);
1008 if (!empty($line->date_lim_reglement)) {
1009 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%y');
1011 $tab[
'date_echeance'] =
'000000';
1016 $tab[
'lettrage'] = str_repeat(
' ', 2);
1017 $tab[
'codestat'] = str_repeat(
' ', 3);
1018 $tab[
'num_piece'] = str_pad(self::trunc((
string) $line->piece_num, 5), 5);
1022 $tab[
'affaire'] = str_repeat(
' ', 10);
1023 $tab[
'quantity1'] = str_repeat(
' ', 10);
1024 $tab[
'num_piece2'] = str_pad(self::trunc((
string) $line->piece_num, 8), 8);
1026 $tab[
'code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
1027 $tab[
'filler3'] = str_repeat(
' ', 3);
1035 $tab[
'libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
1036 $tab[
'codetva'] = str_repeat(
' ', 2);
1040 $tab[
'num_piece3'] = str_pad(substr(self::trunc($line->doc_ref, 20), -10), 10);
1041 $tab[
'reserved'] = str_repeat(
' ', 10);
1042 $tab[
'currency_amount'] = str_repeat(
' ', 13);
1045 $attachmentFileName =
'';
1046 if ($withAttachment == 1) {
1047 $attachmentFileKey = trim((
string) $line->piece_num);
1049 if (!isset($archiveFileList[$attachmentFileKey])) {
1051 $objectDirPath =
'';
1053 if ($line->doc_type ==
'customer_invoice') {
1054 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1055 } elseif ($line->doc_type ==
'expense_report') {
1056 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1057 } elseif ($line->doc_type ==
'supplier_invoice') {
1058 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1060 $invoice->fetch($line->fk_doc);
1061 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1062 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1065 if ($objectDirPath && empty($conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1066 $arrayofinclusion = array();
1068 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1070 $fileFoundPath =
'';
1071 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1073 if (!empty($fileFoundList)) {
1074 $attachmentFileNameTrunc = str_pad(self::trunc((
string) $line->piece_num, 8), 8,
'0', STR_PAD_LEFT);
1076 foreach ($fileFoundList as $fileFound) {
1077 if (strstr($fileFound[
'name'], $objectFileName)) {
1080 if ($line->doc_type ==
'supplier_invoice') {
1081 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1084 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1087 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1088 if (file_exists($fileFoundPath)) {
1089 $archiveFileList[$attachmentFileKey] = array(
1090 'path' => $fileFoundPath,
1091 'name' => $attachmentFileNameTrunc.
'.pdf',
1099 if (empty($fileFoundPath)) {
1101 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1106 if (isset($archiveFileList[$attachmentFileKey])) {
1107 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1111 if (
dol_strlen((
string) $attachmentFileName) == 12) {
1112 $tab[
'attachment'] = $attachmentFileName;
1114 $tab[
'attachment'] = str_repeat(
' ', 12);
1116 $tab[
'filler4'] = str_repeat(
' ', 38);
1117 $tab[
'end_line'] = $end_line;
1120 fwrite($exportFile, implode($tab));
1122 print implode($tab);
1126 return $archiveFileList;
1148 foreach ($objectLines as $line) {
1149 $code_compta = $line->numero_compte;
1150 if (!empty($line->subledger_account)) {
1151 $code_compta = $line->subledger_account;
1156 $tab[
'code_journal'] = str_pad(
dol_trunc($line->code_journal, 2,
'right',
'UTF-8', 1), 2);
1161 $tab[
'date_operation'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1163 $tab[
'folio'] =
' 1';
1165 $tab[
'num_ecriture'] = str_pad(
dol_trunc((
string) $index, 6,
'right',
'UTF-8', 1), 6,
' ', STR_PAD_LEFT);
1167 $tab[
'jour_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
1169 $tab[
'num_compte'] = str_pad(
dol_trunc((
string) $code_compta, 6,
'right',
'UTF-8', 1), 6,
'0');
1171 if ($line->sens ==
'D') {
1172 $tab[
'montant_debit'] = str_pad(number_format($line->debit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1174 $tab[
'montant_crebit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1176 $tab[
'montant_debit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1178 $tab[
'montant_crebit'] = str_pad(number_format($line->credit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1183 $tab[
'lettrage'] = str_repeat(
dol_trunc((
string) $line->lettering_code, 2,
'left',
'UTF-8', 1), 2);
1185 $tab[
'code_piece'] = str_pad(
dol_trunc((
string) $line->piece_num, 5,
'left',
'UTF-8', 1), 5,
' ', STR_PAD_LEFT);
1187 $tab[
'code_stat'] = str_repeat(
' ', 4);
1189 if (!empty($line->date_lim_reglement)) {
1190 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%Y');
1192 $tab[
'date_echeance'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1195 $tab[
'monnaie'] =
'1';
1197 $tab[
'filler'] =
' ';
1199 $tab[
'ind_compteur'] =
' ';
1201 $tab[
'quantite'] =
'0,000000000';
1203 $tab[
'code_pointage'] = str_repeat(
' ', 2);
1205 $tab[
'end_line'] = $end_line;
1207 $output = implode(
'|', $tab);
1209 fwrite($exportFile, $output);
1231 foreach ($objectLines as $line) {
1237 $tab[] = $date_document;
1238 $tab[] = $line->code_journal;
1239 if (empty($line->subledger_account)) {
1240 $tab[] = $line->numero_compte;
1242 $tab[] = $line->subledger_account;
1245 $tab[] =
'"'.dol_trunc($line->label_operation, 40,
'right',
'UTF-8', 1).
'"';
1246 $tab[] =
'"'.dol_trunc((
string) $line->piece_num, 15,
'right',
'UTF-8', 1).
'"';
1247 $tab[] =
price2num(abs($line->debit - $line->credit));
1248 $tab[] = $line->sens;
1249 $tab[] = $date_document;
1252 $output = implode($separator, $tab).$end_line;
1254 fwrite($exportFile, $output);
1274 foreach ($objectLines as $line) {
1279 $tab[] = $line->piece_num;
1281 $tab[] = $date_document;
1284 if (empty($line->subledger_account)) {
1293 $tab[] =
price($line->debit);
1294 $tab[] =
price($line->credit);
1295 $tab[] =
price(abs($line->debit - $line->credit));
1296 $tab[] = $line->sens;
1297 $tab[] = $line->lettering_code;
1298 $tab[] = $line->code_journal;
1300 $output = implode($separator, $tab).$end_line;
1302 fwrite($exportFile, $output);
1321 foreach ($objectLines as $line) {
1326 $tab[] = $date_document;
1327 $tab[] = $line->code_journal;
1328 if (empty($line->subledger_account)) {
1333 $tab[] = $line->doc_ref;
1334 $tab[] = $line->label_operation;
1335 $tab[] =
price($line->debit);
1336 $tab[] =
price($line->credit);
1338 $output = implode($separator, $tab).$end_line;
1340 fwrite($exportFile, $output);
1358 $separator = $this->separator;
1360 foreach ($objectLines as $line) {
1365 $tab[] = $line->piece_num;
1366 $tab[] = $date_document;
1367 $tab[] = $line->doc_ref;
1368 $tab[] = preg_match(
'/'.$separator.
'/', $line->label_operation) ?
"'".$line->label_operation.
"'" : $line->label_operation;
1373 $tab[] =
price2num($line->debit - $line->credit);
1374 $tab[] = $line->code_journal;
1376 $output = implode($separator, $tab).$this->end_line;
1378 fwrite($exportFile, $output);
1401 foreach ($objectLines as $line) {
1402 if ($line->subledger_account && substr($line->subledger_account, 0, 1) ==
'4') {
1403 $tiers[$line->piece_num] = $line->subledger_label;
1407 foreach ($objectLines as $line) {
1412 $search = array(
'Paiement fournisseur ',
'Virement ',
'Paiement ');
1413 $replace = array(
'Paiemt fourn ',
'Virt ',
'Paiemt ');
1414 $label_operation = str_replace($search, $replace, $line->label_operation);
1416 $label_operation = preg_match(
'/'.$separator.
'/', $label_operation) ?
"'".$label_operation.
"'" : $label_operation;
1420 $tab[] = $line->piece_num;
1421 $tab[] = $date_document;
1422 $tab[] = $line->doc_ref;
1423 $tab[] = array_key_exists($line->piece_num, $tiers) ? $tiers[$line->piece_num] :
'';
1424 $tab[] =
length_accountg(($line->subledger_account && (substr($line->subledger_account, 0, 2) == substr($line->numero_compte, 0, 2))) ? $line->subledger_account : $line->numero_compte);
1425 $tab[] =
length_accountg($line->subledger_account ? $line->subledger_account : $line->numero_compte);
1426 $tab[] =
length_accountg($line->subledger_account ? $line->numero_compte :
'');
1427 $tab[] = ($line->doc_type ==
'bank') ? $label_operation : ($line->subledger_account ? $line->subledger_label : $line->label_compte);
1428 $tab[] = $label_operation;
1431 $tab[] = $line->code_journal;
1433 $output = mb_convert_encoding(
'"'.implode(
'"'.$separator.
'"', $tab).
'"'.$this->end_line,
'ISO-8859-1');
1435 fwrite($exportFile, $output);
1454 public function exportFEC($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1456 global $conf, $langs;
1462 $tab[] =
"JournalCode";
1463 $tab[] =
"JournalLib";
1464 $tab[] =
"EcritureNum";
1465 $tab[] =
"EcritureDate";
1466 $tab[] =
"CompteNum";
1467 $tab[] =
"CompteLib";
1468 $tab[] =
"CompAuxNum";
1469 $tab[] =
"CompAuxLib";
1470 $tab[] =
"PieceRef";
1471 $tab[] =
"PieceDate";
1472 $tab[] =
"EcritureLib";
1475 $tab[] =
"EcritureLet";
1477 $tab[] =
"ValidDate";
1478 $tab[] =
"Montantdevise";
1480 $tab[] =
"DateLimitReglmt";
1481 $tab[] =
"NumFacture";
1482 $tab[] =
"FichierFacture";
1484 $output = implode($separator, $tab).$end_line;
1486 fwrite($exportFile, $output);
1491 $conf->cache[
'archiveFileList_notfound'] = array();
1494 foreach ($objectLines as $line) {
1495 if ($line->debit == 0 && $line->credit == 0) {
1503 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1504 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1505 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1511 if ($line->doc_type ==
'customer_invoice') {
1513 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1514 $invoice =
new Facture($this->db);
1515 $invoice->fetch($line->fk_doc);
1517 $refInvoice = (string) $invoice->ref;
1518 } elseif ($line->doc_type ==
'supplier_invoice') {
1520 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1522 $invoice->fetch($line->fk_doc);
1524 $refInvoice = (string) $invoice->ref_supplier;
1530 $tab[] = $line->code_journal;
1535 $tab[] = $labeljournal;
1538 $tab[] = $line->piece_num;
1541 $tab[] = $date_document;
1556 $tab[] = $line->doc_ref;
1563 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1564 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1574 $tab[] = $line->lettering_code;
1577 $tab[] = $date_lettering;
1580 $tab[] = $date_validation;
1583 $tab[] = $line->multicurrency_amount;
1586 $tab[] = $line->multicurrency_code;
1589 $tab[] = $date_limit_payment;
1593 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1594 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1598 $attachmentFileName =
'';
1599 if ($withAttachment == 1) {
1600 $attachmentFileKey = trim((
string) $line->piece_num);
1602 if (!isset($archiveFileList[$attachmentFileKey])) {
1604 $objectDirPath =
'';
1606 if ($line->doc_type ==
'customer_invoice') {
1607 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1608 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1610 } elseif ($line->doc_type ==
'expense_report') {
1611 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1612 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1614 } elseif ($line->doc_type ==
'supplier_invoice' && $invoice instanceof
FactureFournisseur) {
1615 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1616 '@phan-var-force FactureFournisseur $invoice';
1617 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1618 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1622 if ($objectDirPath && empty($conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1623 $arrayofinclusion = array();
1625 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1627 $fileFoundPath =
'';
1628 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1630 if (!empty($fileFoundList)) {
1631 $attachmentFileNameTrunc = $line->doc_ref;
1633 foreach ($fileFoundList as $fileFound) {
1634 if (strstr($fileFound[
'name'], $objectFileName)) {
1637 if ($line->doc_type ==
'supplier_invoice') {
1638 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1641 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1644 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1645 if (file_exists($fileFoundPath)) {
1646 $archiveFileList[$attachmentFileKey] = array(
1647 'path' => $fileFoundPath,
1648 'name' => $attachmentFileNameTrunc.
'.pdf',
1656 if (empty($fileFoundPath)) {
1658 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1663 if (isset($archiveFileList[$attachmentFileKey])) {
1664 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1668 $tab[] = $attachmentFileName;
1670 $output = implode($separator, $tab).$end_line;
1673 fwrite($exportFile, $output);
1680 return $archiveFileList;
1695 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1697 global $conf, $langs;
1703 $tab[] =
"JournalCode";
1704 $tab[] =
"JournalLib";
1705 $tab[] =
"EcritureNum";
1706 $tab[] =
"EcritureDate";
1707 $tab[] =
"CompteNum";
1708 $tab[] =
"CompteLib";
1709 $tab[] =
"CompAuxNum";
1710 $tab[] =
"CompAuxLib";
1711 $tab[] =
"PieceRef";
1712 $tab[] =
"PieceDate";
1713 $tab[] =
"EcritureLib";
1716 $tab[] =
"EcritureLet";
1718 $tab[] =
"ValidDate";
1719 $tab[] =
"Montantdevise";
1721 $tab[] =
"DateLimitReglmt";
1722 $tab[] =
"NumFacture";
1723 $tab[] =
"FichierFacture";
1725 $output = implode($separator, $tab).$end_line;
1727 fwrite($exportFile, $output);
1732 $conf->cache[
'archiveFileList_notfound'] = array();
1735 foreach ($objectLines as $line) {
1736 if ($line->debit == 0 && $line->credit == 0) {
1743 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1744 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1745 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1751 if ($line->doc_type ==
'customer_invoice') {
1753 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1754 $invoice =
new Facture($this->db);
1755 $invoice->fetch($line->fk_doc);
1757 $refInvoice = (string) $invoice->ref;
1758 } elseif ($line->doc_type ==
'supplier_invoice') {
1760 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1762 $invoice->fetch($line->fk_doc);
1764 $refInvoice = (string) $invoice->ref_supplier;
1770 $tab[] = $line->code_journal;
1775 $tab[] = $labeljournal;
1778 $tab[] = $line->piece_num;
1781 $tab[] = $date_creation;
1796 $tab[] = $line->doc_ref;
1799 $tab[] = $date_document;
1803 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1804 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1814 $tab[] = $line->lettering_code;
1817 $tab[] = $date_lettering;
1820 $tab[] = $date_validation;
1823 $tab[] = $line->multicurrency_amount;
1826 $tab[] = $line->multicurrency_code;
1829 $tab[] = $date_limit_payment;
1833 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1834 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1838 $attachmentFileName =
'';
1839 if ($withAttachment == 1) {
1840 $attachmentFileKey = trim((
string) $line->piece_num);
1842 if (!isset($archiveFileList[$attachmentFileKey])) {
1844 $objectDirPath =
'';
1846 if ($line->doc_type ==
'customer_invoice') {
1847 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1848 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1850 } elseif ($line->doc_type ==
'expense_report') {
1851 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1852 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1854 } elseif ($line->doc_type ==
'supplier_invoice' && $invoice instanceof
FactureFournisseur) {
1855 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1856 '@phan-var-force FactureFournisseur $invoice';
1857 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1858 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1862 if ($objectDirPath && empty($conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1863 $arrayofinclusion = array();
1865 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1867 $fileFoundPath =
'';
1868 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1870 if (!empty($fileFoundList)) {
1871 $attachmentFileNameTrunc = $line->doc_ref;
1873 foreach ($fileFoundList as $fileFound) {
1874 if (strstr($fileFound[
'name'], $objectFileName)) {
1877 if ($line->doc_type ==
'supplier_invoice') {
1878 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1881 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1884 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1885 if (file_exists($fileFoundPath)) {
1886 $archiveFileList[$attachmentFileKey] = array(
1887 'path' => $fileFoundPath,
1888 'name' => $attachmentFileNameTrunc.
'.pdf',
1896 if (empty($fileFoundPath)) {
1898 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1903 if (isset($archiveFileList[$attachmentFileKey])) {
1904 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1908 $tab[] = $attachmentFileName;
1910 $output = implode($separator, $tab).$end_line;
1912 fwrite($exportFile, $output);
1919 return $archiveFileList;
1955 $tab[] =
"FW-Betrag";
1962 $output = implode($separator, $tab).$end_line;
1964 fwrite($exportFile, $output);
1970 $thisPieceAccountNr =
"";
1971 $aSize = count($objectLines);
1972 foreach ($objectLines as $aIndex => $line) {
1973 $sammelBuchung =
false;
1974 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1975 $sammelBuchung =
true;
1976 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1977 $sammelBuchung =
true;
1978 } elseif ($aIndex + 1 < $aSize
1979 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1980 && $aIndex - 1 < $aSize
1981 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1983 $sammelBuchung =
true;
1989 $tab[] = $line->piece_num;
1993 $tab[] = $date_document;
1998 if ($line->sens ==
'D') {
2006 if (empty($line->code_tiers)) {
2007 if ($line->piece_num == $thisPieceNum) {
2016 $tab[] = $this->separator;
2025 if ($sammelBuchung) {
2033 $tab[] = abs($line->debit - $line->credit);
2040 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
2044 if (strlen($line1) == 0) {
2048 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
2049 $line1 = $line1.
' / '.$line2;
2053 $tab[] =
'"'.self::toAnsi($line1).
'"';
2055 $tab[] =
'"'.self::toAnsi($line2).
'"';
2059 $tab[] = $this->separator;
2064 $output = implode($separator, $tab).$end_line;
2066 fwrite($exportFile, $output);
2071 if ($line->piece_num !== $thisPieceNum) {
2072 $thisPieceNum = $line->piece_num;
2073 $thisPieceAccountNr = $line->numero_compte;
2091 foreach ($objectLines as $line) {
2094 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2099 $type_enregistrement =
'E';
2100 $tab[] = $type_enregistrement;
2102 $tab[] = substr($line->code_journal, 0, 2);
2106 $tab[] = $line->piece_num;
2108 $tab[] = $date_document;
2110 $tab[] = $line->label_operation;
2112 $tab[] = $date_lim_reglement;
2114 if ($line->doc_type ==
'supplier_invoice') {
2115 if (($line->debit - $line->credit) > 0) {
2116 $nature_piece =
'AF';
2118 $nature_piece =
'FF';
2120 } elseif ($line->doc_type ==
'customer_invoice') {
2121 if (($line->debit - $line->credit) < 0) {
2122 $nature_piece =
'AC';
2124 $nature_piece =
'FC';
2129 $tab[] = $nature_piece;
2140 $racine_subledger_account =
'';
2143 $tab[] = $racine_subledger_account;
2145 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
2147 $tab[] = $line->sens;
2151 $tab[] = $date_creation;
2153 $tab[] = $line->lettering_code;
2155 $tab[] = $line->date_lettering;
2157 if (!empty($line->subledger_account)) {
2163 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2165 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2179 $tab[] = $line->doc_ref;
2207 $output = implode($separator, $tab).$end_line;
2209 fwrite($exportFile, $output);
2228 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2232 $last_codeinvoice =
'';
2234 foreach ($objectLines as $line) {
2236 if ($last_codeinvoice != $line->doc_ref) {
2238 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2239 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2240 $resql = $this->db->query($sql);
2242 if ($resql && $this->db->num_rows($resql) > 0) {
2243 $soc = $this->db->fetch_object($resql);
2245 $address = array(
'',
'',
'');
2246 if (strpos($soc->address,
"\n") !==
false) {
2247 $address = explode(
"\n", $soc->address);
2248 if (is_array($address) && count($address) > 0) {
2249 foreach ($address as $key => $data) {
2250 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2251 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2255 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2256 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2257 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2262 $type_enregistrement =
'C';
2264 $tab[] = $type_enregistrement;
2266 $tab[] = $soc->code_client;
2276 $tab[] = $address[0];
2278 $tab[] = $address[1];
2280 $tab[] = $address[2];
2284 $tab[] = substr($soc->town, 0, 40);
2288 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2290 $tab[] = $soc->phone;
2302 $tab[] = str_replace(
" ",
"", $soc->siret);
2360 $output = implode($separator, $tab).$end_line;
2362 fwrite($exportFile, $output);
2373 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2376 $type_enregistrement =
'E';
2377 $tab[] = $type_enregistrement;
2379 $tab[] = substr($line->code_journal, 0, 2);
2383 $tab[] = $line->piece_num;
2385 $tab[] = $date_document;
2387 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2389 $tab[] = $date_lim_reglement;
2391 if ($line->doc_type ==
'supplier_invoice') {
2392 if (($line->amount) < 0) {
2393 $nature_piece =
'AF';
2395 $nature_piece =
'FF';
2397 } elseif ($line->doc_type ==
'customer_invoice') {
2398 if (($line->amount) < 0) {
2399 $nature_piece =
'AC';
2401 $nature_piece =
'FC';
2406 $tab[] = $nature_piece;
2417 $racine_subledger_account =
'';
2420 $tab[] = $racine_subledger_account;
2422 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2424 $tab[] = $line->sens;
2428 $tab[] = $date_document;
2430 $tab[] = $line->lettering_code;
2432 $tab[] = $line->date_lettering;
2434 if (!empty($line->subledger_account)) {
2440 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2442 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2454 $tab[] = $line->doc_ref;
2488 $output = implode($separator, $tab).$end_line;
2490 fwrite($exportFile, $output);
2495 $last_codeinvoice = $line->doc_ref;
2509 $langs->load(
'compta');
2516 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2517 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2518 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2519 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2520 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2521 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2522 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2524 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2525 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2526 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2527 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2528 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2529 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2531 $output = implode($separator, $tab).$end_line;
2533 fwrite($exportFile, $output);
2538 foreach ($objectLines as $line) {
2543 $tab[] = $date_document;
2547 if (!empty($line->subledger_account)) {
2548 $account = $line->subledger_account;
2550 $account = $line->numero_compte;
2557 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2559 $tab[] =
price(abs($line->debit - $line->credit));
2560 $tab[] = $line->sens;
2568 $output = implode($separator, $tab).$end_line;
2570 fwrite($exportFile, $output);
2591 $invoices_infos = array();
2592 $supplier_invoices_infos = array();
2593 foreach ($objectLines as $line) {
2594 if ($line->debit == 0 && $line->credit == 0) {
2598 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2600 $invoice_ref = $line->doc_ref;
2603 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2604 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2605 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2606 if ($line->doc_type ==
'customer_invoice') {
2608 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2609 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2610 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2611 $resql = $this->db->query($sql);
2613 if ($obj = $this->db->fetch_object($resql)) {
2615 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2616 $invoice_ref = $obj->ref;
2617 $company_name = $obj->nom;
2622 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2623 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2624 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2625 $resql = $this->db->query($sql);
2627 if ($obj = $this->db->fetch_object($resql)) {
2629 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2630 $invoice_ref = $obj->ref;
2631 $company_name = $obj->nom;
2635 } elseif ($line->doc_type ==
'customer_invoice') {
2637 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2638 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2641 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2642 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2649 $tab[] = $date_document;
2650 $tab[] = substr($line->code_journal, 0, 4);
2652 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2661 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2663 $tab[] =
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1);
2667 $tab[] =
price2num(abs($line->debit - $line->credit));
2669 $tab[] = $line->sens;
2673 $tab[] = $date_echeance;
2675 $output = implode($separator, $tab).$end_line;
2677 fwrite($exportFile, $output);
2697 foreach ($objectLines as $line) {
2698 if ($line->debit == 0 && $line->credit == 0) {
2706 $tab[] = $date_document;
2707 $tab[] = substr($line->code_journal, 0, 4);
2708 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2714 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2715 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2716 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2717 $tab[] =
price2num(abs($line->debit - $line->credit));
2718 $tab[] = $line->sens;
2719 $tab[] = $date_document;
2724 $output = implode($separator, $tab).$end_line;
2726 fwrite($exportFile, $output);
2749 foreach ($objectLines as $line) {
2754 $tab[] = $line->piece_num;
2756 $tab[] = substr($date, 6, 4);
2757 $tab[] = substr($date, 3, 2);
2758 $tab[] = substr($date, 0, 2);
2759 $tab[] = $line->doc_ref;
2761 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2767 $numero_cpt_client =
'411';
2768 $numero_cpt_fourn =
'401';
2769 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2770 $numero_cpt_client .=
'0';
2771 $numero_cpt_fourn .=
'0';
2780 $nom_client = explode(
" - ", $line->label_operation);
2781 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2782 $tab[] =
price($line->debit);
2783 $tab[] =
price($line->credit);
2784 $tab[] =
price($line->montant);
2785 $tab[] = $line->code_journal;
2787 $output = implode($separator, $tab).$end_line;
2789 fwrite($exportFile, $output);
2803 public static function trunc($str, $size)
2805 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2815 public static function toAnsi($str, $size = -1)
2818 if ($retVal >= 0 && $size >= 0) {
2819 $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_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.