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));
630 readfileLowMemory($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);
963 if ($line->doc_type ==
'customer_invoice') {
964 $tab[
'type_compte'] =
'C';
965 } elseif ($line->doc_type ==
'supplier_invoice') {
966 $tab[
'type_compte'] =
'F';
968 $tab[
'type_compte'] =
'G';
971 $tab[
'filler3'] = str_repeat(
' ', 235);
973 $tab[
'end_line'] = $end_line;
976 fwrite($exportFile, implode($tab));
983 $tab[
'type_ligne'] =
'M';
984 $tab[
'num_compte'] = str_pad(self::trunc((
string) $code_compta, 8), 8);
985 $tab[
'code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
986 $tab[
'folio'] =
'000';
991 $tab[
'date_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
992 $tab[
'filler'] =
' ';
993 $tab[
'libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.
' '.$line->label_operation, 20), 20);
1008 $tab[
'sens'] = $line->sens;
1009 $tab[
'signe_montant'] =
'+';
1012 $tab[
'montant'] = str_pad((
string) abs(($line->debit - $line->credit) * 100), 12,
'0', STR_PAD_LEFT);
1013 $tab[
'contrepartie'] = str_repeat(
' ', 8);
1016 if (!empty($line->date_lim_reglement)) {
1017 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%y');
1019 $tab[
'date_echeance'] =
'000000';
1024 $tab[
'lettrage'] = str_repeat(
' ', 2);
1025 $tab[
'codestat'] = str_repeat(
' ', 3);
1026 $tab[
'num_piece'] = str_pad(self::trunc((
string) $line->piece_num, 5), 5);
1030 $tab[
'affaire'] = str_repeat(
' ', 10);
1031 $tab[
'quantity1'] = str_repeat(
' ', 10);
1032 $tab[
'num_piece2'] = str_pad(self::trunc((
string) $line->piece_num, 8), 8);
1034 $tab[
'code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
1035 $tab[
'filler3'] = str_repeat(
' ', 3);
1043 $tab[
'libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
1044 $tab[
'codetva'] = str_repeat(
' ', 2);
1048 $tab[
'num_piece3'] = str_pad(substr(self::trunc($line->doc_ref, 20), -10), 10);
1049 $tab[
'reserved'] = str_repeat(
' ', 10);
1050 $tab[
'currency_amount'] = str_repeat(
' ', 13);
1053 $attachmentFileName =
'';
1054 if ($withAttachment == 1) {
1055 $attachmentFileKey = trim((
string) $line->piece_num);
1057 if (!isset($archiveFileList[$attachmentFileKey])) {
1059 $objectDirPath =
'';
1061 if ($line->doc_type ==
'customer_invoice') {
1062 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1063 } elseif ($line->doc_type ==
'expense_report') {
1064 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1065 } elseif ($line->doc_type ==
'supplier_invoice') {
1066 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1068 $invoice->fetch($line->fk_doc);
1069 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1070 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1073 if ($objectDirPath && empty(
$conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1074 $arrayofinclusion = array();
1076 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1078 $fileFoundPath =
'';
1079 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1081 if (!empty($fileFoundList)) {
1082 $attachmentFileNameTrunc = str_pad(self::trunc((
string) $line->piece_num, 8), 8,
'0', STR_PAD_LEFT);
1084 foreach ($fileFoundList as $fileFound) {
1085 if (strstr($fileFound[
'name'], $objectFileName)) {
1088 if ($line->doc_type ==
'supplier_invoice') {
1089 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1092 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1095 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1096 if (file_exists($fileFoundPath)) {
1097 $archiveFileList[$attachmentFileKey] = array(
1098 'path' => $fileFoundPath,
1099 'name' => $attachmentFileNameTrunc.
'.pdf',
1107 if (empty($fileFoundPath)) {
1109 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1114 if (isset($archiveFileList[$attachmentFileKey])) {
1115 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1119 if (
dol_strlen((
string) $attachmentFileName) == 12) {
1120 $tab[
'attachment'] = $attachmentFileName;
1122 $tab[
'attachment'] = str_repeat(
' ', 12);
1124 $tab[
'filler4'] = str_repeat(
' ', 38);
1125 $tab[
'end_line'] = $end_line;
1128 fwrite($exportFile, implode($tab));
1130 print implode($tab);
1134 return $archiveFileList;
1156 foreach ($objectLines as $line) {
1157 $code_compta = $line->numero_compte;
1158 if (!empty($line->subledger_account)) {
1159 $code_compta = $line->subledger_account;
1164 $tab[
'code_journal'] = str_pad(
dol_trunc($line->code_journal, 2,
'right',
'UTF-8', 1), 2);
1169 $tab[
'date_operation'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1171 $tab[
'folio'] =
' 1';
1173 $tab[
'num_ecriture'] = str_pad(
dol_trunc((
string) $index, 6,
'right',
'UTF-8', 1), 6,
' ', STR_PAD_LEFT);
1175 $tab[
'jour_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
1177 $tab[
'num_compte'] = str_pad(
dol_trunc((
string) $code_compta, 6,
'right',
'UTF-8', 1), 6,
'0');
1179 if ($line->sens ==
'D') {
1180 $tab[
'montant_debit'] = str_pad(number_format($line->debit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1182 $tab[
'montant_crebit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1184 $tab[
'montant_debit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1186 $tab[
'montant_crebit'] = str_pad(number_format($line->credit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1191 $tab[
'lettrage'] = str_repeat(
dol_trunc((
string) $line->lettering_code, 2,
'left',
'UTF-8', 1), 2);
1193 $tab[
'code_piece'] = str_pad(
dol_trunc((
string) $line->piece_num, 5,
'left',
'UTF-8', 1), 5,
' ', STR_PAD_LEFT);
1195 $tab[
'code_stat'] = str_repeat(
' ', 4);
1197 if (!empty($line->date_lim_reglement)) {
1198 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%Y');
1200 $tab[
'date_echeance'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1203 $tab[
'monnaie'] =
'1';
1205 $tab[
'filler'] =
' ';
1207 $tab[
'ind_compteur'] =
' ';
1209 $tab[
'quantite'] =
'0,000000000';
1211 $tab[
'code_pointage'] = str_repeat(
' ', 2);
1213 $tab[
'end_line'] = $end_line;
1215 $output = implode(
'|', $tab);
1217 fwrite($exportFile, $output);
1239 foreach ($objectLines as $line) {
1245 $tab[] = $date_document;
1246 $tab[] = $line->code_journal;
1247 if (empty($line->subledger_account)) {
1248 $tab[] = $line->numero_compte;
1250 $tab[] = $line->subledger_account;
1253 $tab[] =
'"'.dol_trunc($line->label_operation, 40,
'right',
'UTF-8', 1).
'"';
1254 $tab[] =
'"'.dol_trunc((
string) $line->piece_num, 15,
'right',
'UTF-8', 1).
'"';
1255 $tab[] =
price2num(abs($line->debit - $line->credit));
1256 $tab[] = $line->sens;
1257 $tab[] = $date_document;
1260 $output = implode($separator, $tab).$end_line;
1262 fwrite($exportFile, $output);
1282 foreach ($objectLines as $line) {
1287 $tab[] = $line->piece_num;
1289 $tab[] = $date_document;
1292 if (empty($line->subledger_account)) {
1301 $tab[] =
price($line->debit);
1302 $tab[] =
price($line->credit);
1303 $tab[] =
price(abs($line->debit - $line->credit));
1304 $tab[] = $line->sens;
1305 $tab[] = $line->lettering_code;
1306 $tab[] = $line->code_journal;
1308 $output = implode($separator, $tab).$end_line;
1310 fwrite($exportFile, $output);
1329 foreach ($objectLines as $line) {
1334 $tab[] = $date_document;
1335 $tab[] = $line->code_journal;
1336 if (empty($line->subledger_account)) {
1341 $tab[] = $line->doc_ref;
1342 $tab[] = $line->label_operation;
1343 $tab[] =
price($line->debit);
1344 $tab[] =
price($line->credit);
1346 $output = implode($separator, $tab).$end_line;
1348 fwrite($exportFile, $output);
1366 $separator = $this->separator;
1368 foreach ($objectLines as $line) {
1373 $tab[] = $line->piece_num;
1374 $tab[] = $date_document;
1375 $tab[] = $line->doc_ref;
1376 $tab[] = preg_match(
'/'.$separator.
'/', $line->label_operation) ?
"'".$line->label_operation.
"'" : $line->label_operation;
1381 $tab[] =
price2num($line->debit - $line->credit);
1382 $tab[] = $line->code_journal;
1384 $output = implode($separator, $tab).$this->end_line;
1386 fwrite($exportFile, $output);
1409 foreach ($objectLines as $line) {
1410 if ($line->subledger_account && substr($line->subledger_account, 0, 1) ==
'4') {
1411 $tiers[$line->piece_num] = $line->subledger_label;
1415 foreach ($objectLines as $line) {
1420 $search = array(
'Paiement fournisseur ',
'Virement ',
'Paiement ');
1421 $replace = array(
'Paiemt fourn ',
'Virt ',
'Paiemt ');
1422 $label_operation = str_replace($search, $replace, $line->label_operation);
1424 $label_operation = preg_match(
'/'.$separator.
'/', $label_operation) ?
"'".$label_operation.
"'" : $label_operation;
1428 $tab[] = $line->piece_num;
1429 $tab[] = $date_document;
1430 $tab[] = $line->doc_ref;
1431 $tab[] = array_key_exists($line->piece_num, $tiers) ? $tiers[$line->piece_num] :
'';
1432 $tab[] =
length_accountg(($line->subledger_account && (substr($line->subledger_account, 0, 2) == substr($line->numero_compte, 0, 2))) ? $line->subledger_account : $line->numero_compte);
1433 $tab[] =
length_accountg($line->subledger_account ? $line->subledger_account : $line->numero_compte);
1434 $tab[] =
length_accountg($line->subledger_account ? $line->numero_compte :
'');
1435 $tab[] = ($line->doc_type ==
'bank') ? $label_operation : ($line->subledger_account ? $line->subledger_label : $line->label_compte);
1436 $tab[] = $label_operation;
1439 $tab[] = $line->code_journal;
1441 $output = mb_convert_encoding(
'"'.implode(
'"'.$separator.
'"', $tab).
'"'.$this->end_line,
'ISO-8859-1');
1443 fwrite($exportFile, $output);
1462 public function exportFEC($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1464 global
$conf, $langs;
1470 $tab[] =
"JournalCode";
1471 $tab[] =
"JournalLib";
1472 $tab[] =
"EcritureNum";
1473 $tab[] =
"EcritureDate";
1474 $tab[] =
"CompteNum";
1475 $tab[] =
"CompteLib";
1476 $tab[] =
"CompAuxNum";
1477 $tab[] =
"CompAuxLib";
1478 $tab[] =
"PieceRef";
1479 $tab[] =
"PieceDate";
1480 $tab[] =
"EcritureLib";
1483 $tab[] =
"EcritureLet";
1485 $tab[] =
"ValidDate";
1486 $tab[] =
"Montantdevise";
1488 $tab[] =
"DateLimitReglmt";
1489 $tab[] =
"NumFacture";
1490 $tab[] =
"FichierFacture";
1492 $output = implode($separator, $tab).$end_line;
1494 fwrite($exportFile, $output);
1499 $conf->cache[
'archiveFileList_notfound'] = array();
1502 foreach ($objectLines as $line) {
1503 if ($line->debit == 0 && $line->credit == 0) {
1511 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1512 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1513 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1519 if ($line->doc_type ==
'customer_invoice') {
1521 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1522 $invoice =
new Facture($this->db);
1523 $invoice->fetch($line->fk_doc);
1525 $refInvoice = (
string) $invoice->ref;
1526 } elseif ($line->doc_type ==
'supplier_invoice') {
1528 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1530 $invoice->fetch($line->fk_doc);
1532 $refInvoice = (
string) $invoice->ref_supplier;
1538 $tab[] = $line->code_journal;
1543 $tab[] = $labeljournal;
1546 $tab[] = $line->piece_num;
1549 $tab[] = $date_document;
1564 $tab[] = $line->doc_ref;
1571 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1572 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1582 $tab[] = $line->lettering_code;
1585 $tab[] = $date_lettering;
1588 $tab[] = $date_validation;
1591 $tab[] = $line->multicurrency_amount;
1594 $tab[] = $line->multicurrency_code;
1597 $tab[] = $date_limit_payment;
1601 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1602 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1606 $attachmentFileName =
'';
1607 if ($withAttachment == 1) {
1608 $attachmentFileKey = trim((
string) $line->piece_num);
1610 if (!isset($archiveFileList[$attachmentFileKey])) {
1612 $objectDirPath =
'';
1614 if ($line->doc_type ==
'customer_invoice') {
1615 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1616 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1618 } elseif ($line->doc_type ==
'expense_report') {
1619 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1620 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1622 } elseif ($line->doc_type ==
'supplier_invoice' && $invoice instanceof
FactureFournisseur) {
1623 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1624 '@phan-var-force FactureFournisseur $invoice';
1625 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1626 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1630 if ($objectDirPath && empty(
$conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1631 $arrayofinclusion = array();
1633 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1635 $fileFoundPath =
'';
1636 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1638 if (!empty($fileFoundList)) {
1639 $attachmentFileNameTrunc = $line->doc_ref;
1641 foreach ($fileFoundList as $fileFound) {
1642 if (strstr($fileFound[
'name'], $objectFileName)) {
1645 if ($line->doc_type ==
'supplier_invoice') {
1646 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1649 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1652 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1653 if (file_exists($fileFoundPath)) {
1654 $archiveFileList[$attachmentFileKey] = array(
1655 'path' => $fileFoundPath,
1656 'name' => $attachmentFileNameTrunc.
'.pdf',
1664 if (empty($fileFoundPath)) {
1666 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1671 if (isset($archiveFileList[$attachmentFileKey])) {
1672 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1676 $tab[] = $attachmentFileName;
1678 $output = implode($separator, $tab).$end_line;
1681 fwrite($exportFile, $output);
1688 return $archiveFileList;
1703 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1705 global
$conf, $langs;
1711 $tab[] =
"JournalCode";
1712 $tab[] =
"JournalLib";
1713 $tab[] =
"EcritureNum";
1714 $tab[] =
"EcritureDate";
1715 $tab[] =
"CompteNum";
1716 $tab[] =
"CompteLib";
1717 $tab[] =
"CompAuxNum";
1718 $tab[] =
"CompAuxLib";
1719 $tab[] =
"PieceRef";
1720 $tab[] =
"PieceDate";
1721 $tab[] =
"EcritureLib";
1724 $tab[] =
"EcritureLet";
1726 $tab[] =
"ValidDate";
1727 $tab[] =
"Montantdevise";
1729 $tab[] =
"DateLimitReglmt";
1730 $tab[] =
"NumFacture";
1731 $tab[] =
"FichierFacture";
1733 $output = implode($separator, $tab).$end_line;
1735 fwrite($exportFile, $output);
1740 $conf->cache[
'archiveFileList_notfound'] = array();
1743 foreach ($objectLines as $line) {
1744 if ($line->debit == 0 && $line->credit == 0) {
1751 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1752 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1753 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1759 if ($line->doc_type ==
'customer_invoice') {
1761 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1762 $invoice =
new Facture($this->db);
1763 $invoice->fetch($line->fk_doc);
1765 $refInvoice = (
string) $invoice->ref;
1766 } elseif ($line->doc_type ==
'supplier_invoice') {
1768 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1770 $invoice->fetch($line->fk_doc);
1772 $refInvoice = (
string) $invoice->ref_supplier;
1778 $tab[] = $line->code_journal;
1783 $tab[] = $labeljournal;
1786 $tab[] = $line->piece_num;
1789 $tab[] = $date_creation;
1804 $tab[] = $line->doc_ref;
1807 $tab[] = $date_document;
1811 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1812 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1822 $tab[] = $line->lettering_code;
1825 $tab[] = $date_lettering;
1828 $tab[] = $date_validation;
1831 $tab[] = $line->multicurrency_amount;
1834 $tab[] = $line->multicurrency_code;
1837 $tab[] = $date_limit_payment;
1841 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1842 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1846 $attachmentFileName =
'';
1847 if ($withAttachment == 1) {
1848 $attachmentFileKey = trim((
string) $line->piece_num);
1850 if (!isset($archiveFileList[$attachmentFileKey])) {
1852 $objectDirPath =
'';
1854 if ($line->doc_type ==
'customer_invoice') {
1855 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1856 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1858 } elseif ($line->doc_type ==
'expense_report') {
1859 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1860 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1862 } elseif ($line->doc_type ==
'supplier_invoice' && $invoice instanceof
FactureFournisseur) {
1863 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1864 '@phan-var-force FactureFournisseur $invoice';
1865 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1866 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1870 if ($objectDirPath && empty(
$conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1871 $arrayofinclusion = array();
1873 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1875 $fileFoundPath =
'';
1876 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1878 if (!empty($fileFoundList)) {
1879 $attachmentFileNameTrunc = $line->doc_ref;
1881 foreach ($fileFoundList as $fileFound) {
1882 if (strstr($fileFound[
'name'], $objectFileName)) {
1885 if ($line->doc_type ==
'supplier_invoice') {
1886 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1889 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1892 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1893 if (file_exists($fileFoundPath)) {
1894 $archiveFileList[$attachmentFileKey] = array(
1895 'path' => $fileFoundPath,
1896 'name' => $attachmentFileNameTrunc.
'.pdf',
1904 if (empty($fileFoundPath)) {
1906 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1911 if (isset($archiveFileList[$attachmentFileKey])) {
1912 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1916 $tab[] = $attachmentFileName;
1918 $output = implode($separator, $tab).$end_line;
1920 fwrite($exportFile, $output);
1927 return $archiveFileList;
1963 $tab[] =
"FW-Betrag";
1970 $output = implode($separator, $tab).$end_line;
1972 fwrite($exportFile, $output);
1978 $thisPieceAccountNr =
"";
1979 $aSize = count($objectLines);
1980 foreach ($objectLines as $aIndex => $line) {
1981 $sammelBuchung =
false;
1982 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1983 $sammelBuchung =
true;
1984 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1985 $sammelBuchung =
true;
1986 } elseif ($aIndex + 1 < $aSize
1987 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1988 && $aIndex - 1 < $aSize
1989 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1991 $sammelBuchung =
true;
1997 $tab[] = $line->piece_num;
2001 $tab[] = $date_document;
2006 if ($line->sens ==
'D') {
2014 if (empty($line->code_tiers)) {
2015 if ($line->piece_num == $thisPieceNum) {
2024 $tab[] = $this->separator;
2033 if ($sammelBuchung) {
2041 $tab[] = abs($line->debit - $line->credit);
2048 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
2052 if (strlen($line1) == 0) {
2056 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
2057 $line1 = $line1.
' / '.$line2;
2061 $tab[] =
'"'.self::toAnsi($line1).
'"';
2063 $tab[] =
'"'.self::toAnsi($line2).
'"';
2067 $tab[] = $this->separator;
2072 $output = implode($separator, $tab).$end_line;
2074 fwrite($exportFile, $output);
2079 if ($line->piece_num !== $thisPieceNum) {
2080 $thisPieceNum = $line->piece_num;
2081 $thisPieceAccountNr = $line->numero_compte;
2099 foreach ($objectLines as $line) {
2102 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2107 $type_enregistrement =
'E';
2108 $tab[] = $type_enregistrement;
2110 $tab[] = substr($line->code_journal, 0, 2);
2114 $tab[] = $line->piece_num;
2116 $tab[] = $date_document;
2118 $tab[] = $line->label_operation;
2120 $tab[] = $date_lim_reglement;
2122 if ($line->doc_type ==
'supplier_invoice') {
2123 if (($line->debit - $line->credit) > 0) {
2124 $nature_piece =
'AF';
2126 $nature_piece =
'FF';
2128 } elseif ($line->doc_type ==
'customer_invoice') {
2129 if (($line->debit - $line->credit) < 0) {
2130 $nature_piece =
'AC';
2132 $nature_piece =
'FC';
2137 $tab[] = $nature_piece;
2148 $racine_subledger_account =
'';
2151 $tab[] = $racine_subledger_account;
2153 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
2155 $tab[] = $line->sens;
2159 $tab[] = $date_creation;
2161 $tab[] = $line->lettering_code;
2163 $tab[] = $line->date_lettering;
2165 if (!empty($line->subledger_account)) {
2171 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2173 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2187 $tab[] = $line->doc_ref;
2215 $output = implode($separator, $tab).$end_line;
2217 fwrite($exportFile, $output);
2236 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2240 $last_codeinvoice =
'';
2242 foreach ($objectLines as $line) {
2244 if ($last_codeinvoice != $line->doc_ref) {
2246 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2247 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2248 $resql = $this->db->query($sql);
2250 if ($resql && $this->db->num_rows($resql) > 0) {
2251 $soc = $this->db->fetch_object($resql);
2253 $address = array(
'',
'',
'');
2254 if (strpos($soc->address,
"\n") !==
false) {
2255 $address = explode(
"\n", $soc->address);
2256 if (is_array($address) && count($address) > 0) {
2257 foreach ($address as $key => $data) {
2258 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2259 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2263 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2264 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2265 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2270 $type_enregistrement =
'C';
2272 $tab[] = $type_enregistrement;
2274 $tab[] = $soc->code_client;
2284 $tab[] = $address[0];
2286 $tab[] = $address[1];
2288 $tab[] = $address[2];
2292 $tab[] = substr($soc->town, 0, 40);
2296 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2298 $tab[] = $soc->phone;
2310 $tab[] = str_replace(
" ",
"", $soc->siret);
2368 $output = implode($separator, $tab).$end_line;
2370 fwrite($exportFile, $output);
2381 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2384 $type_enregistrement =
'E';
2385 $tab[] = $type_enregistrement;
2387 $tab[] = substr($line->code_journal, 0, 2);
2391 $tab[] = $line->piece_num;
2393 $tab[] = $date_document;
2395 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2397 $tab[] = $date_lim_reglement;
2399 if ($line->doc_type ==
'supplier_invoice') {
2400 if (($line->amount) < 0) {
2401 $nature_piece =
'AF';
2403 $nature_piece =
'FF';
2405 } elseif ($line->doc_type ==
'customer_invoice') {
2406 if (($line->amount) < 0) {
2407 $nature_piece =
'AC';
2409 $nature_piece =
'FC';
2414 $tab[] = $nature_piece;
2425 $racine_subledger_account =
'';
2428 $tab[] = $racine_subledger_account;
2430 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2432 $tab[] = $line->sens;
2436 $tab[] = $date_document;
2438 $tab[] = $line->lettering_code;
2440 $tab[] = $line->date_lettering;
2442 if (!empty($line->subledger_account)) {
2448 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2450 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2462 $tab[] = $line->doc_ref;
2496 $output = implode($separator, $tab).$end_line;
2498 fwrite($exportFile, $output);
2503 $last_codeinvoice = $line->doc_ref;
2517 $langs->load(
'compta');
2524 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2525 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2526 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2527 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2528 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2529 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2530 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2532 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2533 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2534 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2535 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2536 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2537 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2539 $output = implode($separator, $tab).$end_line;
2541 fwrite($exportFile, $output);
2546 foreach ($objectLines as $line) {
2551 $tab[] = $date_document;
2555 if (!empty($line->subledger_account)) {
2556 $account = $line->subledger_account;
2558 $account = $line->numero_compte;
2565 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2567 $tab[] =
price(abs($line->debit - $line->credit));
2568 $tab[] = $line->sens;
2576 $output = implode($separator, $tab).$end_line;
2578 fwrite($exportFile, $output);
2599 $invoices_infos = array();
2600 $supplier_invoices_infos = array();
2601 foreach ($objectLines as $line) {
2602 if ($line->debit == 0 && $line->credit == 0) {
2606 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2608 $invoice_ref = $line->doc_ref;
2611 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2612 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2613 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2614 if ($line->doc_type ==
'customer_invoice') {
2616 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2617 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2618 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2619 $resql = $this->db->query($sql);
2621 if ($obj = $this->db->fetch_object($resql)) {
2623 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2624 $invoice_ref = $obj->ref;
2625 $company_name = $obj->nom;
2630 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2631 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2632 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2633 $resql = $this->db->query($sql);
2635 if ($obj = $this->db->fetch_object($resql)) {
2637 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2638 $invoice_ref = $obj->ref;
2639 $company_name = $obj->nom;
2643 } elseif ($line->doc_type ==
'customer_invoice') {
2645 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2646 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2649 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2650 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2657 $tab[] = $date_document;
2658 $tab[] = substr($line->code_journal, 0, 4);
2660 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2669 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2671 $tab[] =
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1);
2675 $tab[] =
price2num(abs($line->debit - $line->credit));
2677 $tab[] = $line->sens;
2681 $tab[] = $date_echeance;
2683 $output = implode($separator, $tab).$end_line;
2685 fwrite($exportFile, $output);
2705 foreach ($objectLines as $line) {
2706 if ($line->debit == 0 && $line->credit == 0) {
2714 $tab[] = $date_document;
2715 $tab[] = substr($line->code_journal, 0, 4);
2716 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2722 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2723 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2724 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2725 $tab[] =
price2num(abs($line->debit - $line->credit));
2726 $tab[] = $line->sens;
2727 $tab[] = $date_document;
2732 $output = implode($separator, $tab).$end_line;
2734 fwrite($exportFile, $output);
2757 foreach ($objectLines as $line) {
2762 $tab[] = $line->piece_num;
2764 $tab[] = substr($date, 6, 4);
2765 $tab[] = substr($date, 3, 2);
2766 $tab[] = substr($date, 0, 2);
2767 $tab[] = $line->doc_ref;
2769 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2775 $numero_cpt_client =
'411';
2776 $numero_cpt_fourn =
'401';
2777 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2778 $numero_cpt_client .=
'0';
2779 $numero_cpt_fourn .=
'0';
2788 $nom_client = explode(
" - ", $line->label_operation);
2789 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2790 $tab[] =
price($line->debit);
2791 $tab[] =
price($line->credit);
2792 $tab[] =
price($line->montant);
2793 $tab[] = $line->code_journal;
2795 $output = implode($separator, $tab).$end_line;
2797 fwrite($exportFile, $output);
2811 public static function trunc($str, $size)
2813 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2823 public static function toAnsi($str, $size = -1)
2826 if ($retVal >= 0 && $size >= 0) {
2827 $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.
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)
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.