dolibarr 22.0.5
accountancyexport.class.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
6 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7 * Copyright (C) 2016 Pierre-Henry Favre <phf@atm-consulting.fr>
8 * Copyright (C) 2016-2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
9 * Copyright (C) 2022 Lionel Vessiller <lvessiller@open-dsi.fr>
10 * Copyright (C) 2013-2017 Olivier Geffroy <jeff@jeffinfo.com>
11 * Copyright (C) 2017 Elarifr. Ari Elbaz <github@accedinfo.com>
12 * Copyright (C) 2017-2024 Frédéric France <frederic.france@free.fr>
13 * Copyright (C) 2017 André Schild <a.schild@aarboard.ch>
14 * Copyright (C) 2020 Guillaume Alexandre <guillaume@tag-info.fr>
15 * Copyright (C) 2022 Joachim Kueter <jkueter@gmx.de>
16 * Copyright (C) 2022 Progiseize <a.bisotti@progiseize.fr>
17 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 3 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <https://www.gnu.org/licenses/>.
31 */
32
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';
45
50{
51 // Types of export.
53 public static $EXPORT_TYPE_CONFIGURABLE = 1; // CSV
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;
88 // Generic FEC after that
90 public static $EXPORT_TYPE_FEC = 1000;
92 public static $EXPORT_TYPE_FEC2 = 1010;
93
97 public $db;
98
102 public $errors = array();
103
107 public $separator = '';
108
112 public $end_line = '';
113
117 public $generatedfiledata = array();
118
119
125 public function __construct(DoliDB $db)
126 {
127 global $conf, $hookmanager;
128
129 $this->db = $db;
130 $this->separator = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV');
131 $this->end_line = getDolGlobalString('ACCOUNTING_EXPORT_ENDLINE') ? (getDolGlobalInt('ACCOUNTING_EXPORT_ENDLINE') == 1 ? "\n" : "\r\n") : "\n";
132
133 $hookmanager->initHooks(array('accountancyexport'));
134 }
135
142 public function getType($mode = 0)
143 {
144 global $langs, $hookmanager;
145
146 $listofspecialformatexport = array(
147 self::$EXPORT_TYPE_CEGID => $langs->trans('Modelcsv_CEGID'),
148 self::$EXPORT_TYPE_COALA => $langs->trans('Modelcsv_COALA'),
149 self::$EXPORT_TYPE_BOB50 => $langs->trans('Modelcsv_bob50'),
150 self::$EXPORT_TYPE_CIEL => $langs->trans('Modelcsv_ciel'),
151 self::$EXPORT_TYPE_QUADRATUS => $langs->trans('Modelcsv_quadratus'),
152 self::$EXPORT_TYPE_WINFIC => $langs->trans('Modelcsv_winfic'),
153 self::$EXPORT_TYPE_EBP => $langs->trans('Modelcsv_ebp'),
154 self::$EXPORT_TYPE_COGILOG => $langs->trans('Modelcsv_cogilog'),
155 self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'),
156 self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans('Modelcsv_openconcerto'),
157 self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans('Modelcsv_Sage50_Swiss'),
158 self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans('Modelcsv_charlemagne'),
159 self::$EXPORT_TYPE_LDCOMPTA => $langs->trans('Modelcsv_LDCompta'),
160 self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans('Modelcsv_LDCompta10'),
161 self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans('Modelcsv_Gestinumv3'),
162 self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans('Modelcsv_Gestinumv5'),
163 self::$EXPORT_TYPE_ISUITEEXPERT => 'Export iSuite Expert',
164 );
165
166 $listofgenericformatexport = array(
167 self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans('Modelcsv_configurable'),
168 self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'),
169 self::$EXPORT_TYPE_FEC2 => $langs->trans('Modelcsv_FEC2'),
170 );
171
172 if (empty($mode)) {
173 $listofexporttypes = $listofgenericformatexport + $listofspecialformatexport;
174 ksort($listofexporttypes, SORT_NUMERIC);
175 } else {
176 ksort($listofspecialformatexport, SORT_NUMERIC);
177 $listofexporttypes = array();
178 $i = 0;
179 foreach ($listofgenericformatexport as $key => $val) {
180 $i++;
181 $listofexporttypes[$key] = array('id' => $key, 'label' => $val, 'position' => $i);
182 }
183 $listofexporttypes['separator_'.$i] = array('id' => 0, 'label' => '----------------', 'position' => $i, 'disabled' => 'disabled');
184 foreach ($listofspecialformatexport as $key => $val) {
185 $i++;
186 $listofexporttypes[$key] = array('id' => $key, 'label' => $val, 'position' => $i);
187 }
188 }
189
190 // allow modules to define export formats
191 $parameters = array();
192 $reshook = $hookmanager->executeHooks('getType', $parameters, $listofexporttypes);
193
194 return $listofexporttypes;
195 }
196
203 public static function getFormatCode($type)
204 {
205 $formatcode = array(
206 self::$EXPORT_TYPE_CONFIGURABLE => 'csv',
207 self::$EXPORT_TYPE_CEGID => 'cegid',
208 self::$EXPORT_TYPE_COALA => 'coala',
209 self::$EXPORT_TYPE_BOB50 => 'bob50',
210 self::$EXPORT_TYPE_CIEL => 'ciel',
211 self::$EXPORT_TYPE_QUADRATUS => 'quadratus',
212 self::$EXPORT_TYPE_WINFIC => 'winfic',
213 self::$EXPORT_TYPE_EBP => 'ebp',
214 self::$EXPORT_TYPE_COGILOG => 'cogilog',
215 self::$EXPORT_TYPE_AGIRIS => 'agiris',
216 self::$EXPORT_TYPE_OPENCONCERTO => 'openconcerto',
217 self::$EXPORT_TYPE_SAGE50_SWISS => 'sage50ch',
218 self::$EXPORT_TYPE_CHARLEMAGNE => 'charlemagne',
219 self::$EXPORT_TYPE_LDCOMPTA => 'ldcompta',
220 self::$EXPORT_TYPE_LDCOMPTA10 => 'ldcompta10',
221 self::$EXPORT_TYPE_GESTIMUMV3 => 'gestimumv3',
222 self::$EXPORT_TYPE_GESTIMUMV5 => 'gestimumv5',
223 self::$EXPORT_TYPE_FEC => 'fec',
224 self::$EXPORT_TYPE_FEC2 => 'fec2',
225 self::$EXPORT_TYPE_ISUITEEXPERT => 'isuiteexpert',
226 );
227
228 global $hookmanager;
229 $code = $formatcode[$type] ?? '';
230 $parameters = array('type' => $type);
231 $reshook = $hookmanager->executeHooks('getFormatCode', $parameters, $code);
232
233 return $code;
234 }
235
241 public function getTypeConfig()
242 {
243 global $langs;
244
245 $exporttypes = array(
246 'param' => array(
247 self::$EXPORT_TYPE_CONFIGURABLE => array(
248 'label' => $langs->trans('Modelcsv_configurable'),
249 'ACCOUNTING_EXPORT_FORMAT' => getDolGlobalString('ACCOUNTING_EXPORT_FORMAT', 'txt'),
250 'ACCOUNTING_EXPORT_SEPARATORCSV' => getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV', ','),
251 'ACCOUNTING_EXPORT_ENDLINE' => getDolGlobalString('ACCOUNTING_EXPORT_ENDLINE', 1),
252 'ACCOUNTING_EXPORT_DATE' => getDolGlobalString('ACCOUNTING_EXPORT_DATE', '%Y-%m-%d'),
253 ),
254 self::$EXPORT_TYPE_CEGID => array(
255 'label' => $langs->trans('Modelcsv_CEGID'),
256 ),
257 self::$EXPORT_TYPE_COALA => array(
258 'label' => $langs->trans('Modelcsv_COALA'),
259 ),
260 self::$EXPORT_TYPE_BOB50 => array(
261 'label' => $langs->trans('Modelcsv_bob50'),
262 ),
263 self::$EXPORT_TYPE_CIEL => array(
264 'label' => $langs->trans('Modelcsv_ciel'),
265 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
266 ),
267 self::$EXPORT_TYPE_QUADRATUS => array(
268 'label' => $langs->trans('Modelcsv_quadratus'),
269 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
270 ),
271 self::$EXPORT_TYPE_WINFIC => array(
272 'label' => $langs->trans('Modelcsv_winfic'),
273 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
274 ),
275 self::$EXPORT_TYPE_EBP => array(
276 'label' => $langs->trans('Modelcsv_ebp'),
277 ),
278 self::$EXPORT_TYPE_COGILOG => array(
279 'label' => $langs->trans('Modelcsv_cogilog'),
280 ),
281 self::$EXPORT_TYPE_AGIRIS => array(
282 'label' => $langs->trans('Modelcsv_agiris'),
283 ),
284 self::$EXPORT_TYPE_OPENCONCERTO => array(
285 'label' => $langs->trans('Modelcsv_openconcerto'),
286 ),
287 self::$EXPORT_TYPE_SAGE50_SWISS => array(
288 'label' => $langs->trans('Modelcsv_Sage50_Swiss'),
289 ),
290 self::$EXPORT_TYPE_CHARLEMAGNE => array(
291 'label' => $langs->trans('Modelcsv_charlemagne'),
292 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
293 ),
294 self::$EXPORT_TYPE_LDCOMPTA => array(
295 'label' => $langs->trans('Modelcsv_LDCompta'),
296 ),
297 self::$EXPORT_TYPE_LDCOMPTA10 => array(
298 'label' => $langs->trans('Modelcsv_LDCompta10'),
299 ),
300 self::$EXPORT_TYPE_GESTIMUMV3 => array(
301 'label' => $langs->trans('Modelcsv_Gestinumv3'),
302 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
303 ),
304 self::$EXPORT_TYPE_GESTIMUMV5 => array(
305 'label' => $langs->trans('Modelcsv_Gestinumv5'),
306 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
307 ),
308 self::$EXPORT_TYPE_FEC => array(
309 'label' => $langs->trans('Modelcsv_FEC'),
310 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
311 ),
312 self::$EXPORT_TYPE_FEC2 => array(
313 'label' => $langs->trans('Modelcsv_FEC2'),
314 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
315 ),
316 self::$EXPORT_TYPE_ISUITEEXPERT => array(
317 'label' => 'iSuite Expert',
318 'ACCOUNTING_EXPORT_FORMAT' => 'csv',
319 ),
320 ),
321 'cr' => array(
322 '1' => $langs->trans("Unix"),
323 '2' => $langs->trans("Windows")
324 ),
325 'format' => array(
326 'csv' => $langs->trans("csv"),
327 'txt' => $langs->trans("txt")
328 ),
329 );
330
331 global $hookmanager;
332 $parameters = array();
333 $reshook = $hookmanager->executeHooks('getTypeConfig', $parameters, $exporttypes);
334 return $exporttypes;
335 }
336
337
344 public function getMimeType($formatexportset)
345 {
346 switch ($formatexportset) {
347 case self::$EXPORT_TYPE_FEC:
348 $mime = 'text/tab-separated-values';
349 break;
350 default:
351 $mime = 'text/csv';
352 break;
353 }
354
355 return $mime;
356 }
357
375 public function export(&$TData, $formatexportset, $withAttachment = 0, $downloadMode = 1, $outputMode = 1, $noouput = 1)
376 {
377 global $db, $conf, $langs; // The tpl file use $db
378 global $search_date_end; // Used into /accountancy/tpl/export_journal.tpl.php
379
380 // Define name of file to save
381 $formatcode = $this->getFormatCode($formatexportset);
382 $filename = 'general_ledger-'.(!empty($formatcode) ? $formatcode : $formatexportset);
383 $type_export = 'general_ledger';
384
385 $completefilename = '';
386 $exportFile = null;
387 $exportFileName = '';
388 $exportFilePath = '';
389 $exportFileFullName = '';
390 $downloadFileMimeType = '';
391 $downloadFileFullName = '';
392 $downloadFilePath = '';
393 $archiveFullName = '';
394 $archivePath = '';
395 $archiveFileList = array();
396 if ($withAttachment == 1) {
397 if ($downloadMode == 0) {
398 $downloadMode = 1; // force to download after writing all files (can't use direct download)
399 }
400 if ($outputMode == 0) {
401 $outputMode = 1; // force to put files in a temp directory (can't use print on screen)
402 }
403
404 // PHP ZIP extension must be enabled
405 if (!extension_loaded('zip')) {
406 $langs->load('install');
407 $this->errors[] = $langs->trans('ErrorPHPDoesNotSupport', 'ZIP');
408 return -1;
409 }
410 }
411
412 $mimetype = $this->getMimeType($formatexportset);
413 if ($downloadMode == 0) {
414 // begin to print header for direct download
415 top_httphead($mimetype, 1);
416 }
417
418 include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
419
420 if ($outputMode == 1 || $outputMode == 2) {
421 if ($outputMode == 1) {
422 // uses the temp directory by default to write files
423 if (!empty($conf->accounting->multidir_temp[$conf->entity])) {
424 $outputDir = $conf->accounting->multidir_temp[$conf->entity];
425 } else {
426 $outputDir = $conf->accounting->dir_temp;
427 }
428 } else {
429 // uses the default export directory "accounting/export"
430 if (!empty($conf->accounting->multidir_output[$conf->entity])) {
431 $outputDir = $conf->accounting->multidir_output[$conf->entity];
432 } else {
433 $outputDir = $conf->accounting->dir_output;
434 }
435
436 // directory already created when module is enabled
437 $outputDir .= '/export';
438 $outputDir .= '/'.dol_sanitizePathName((string) $formatexportset);
439 }
440
441 if (!dol_is_dir($outputDir)) {
442 if (dol_mkdir($outputDir) < 0) {
443 $this->errors[] = $langs->trans('ErrorCanNotCreateDir', $outputDir);
444 return -1;
445 }
446 }
447
448 if ($outputDir != '') {
449 if (!dol_is_dir($outputDir)) {
450 $langs->load('errors');
451 $this->errors[] = $langs->trans('ErrorDirNotFound', $outputDir);
452 return -1;
453 }
454
455 // Fallback if template did not set $completefilename
456 if (empty($completefilename)) {
457 $completefilename = dol_sanitizeFileName($filename).'_'.dol_print_date(dol_now(), '%Y%m%d%H%M%S').'.txt';
458 }
459
460 // create export file
461 $exportFileFullName = $completefilename;
462 $exportFileBaseName = basename($exportFileFullName);
463 $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME);
464 $exportFilePath = $outputDir . '/' . $exportFileFullName;
465 $exportFile = fopen($exportFilePath, 'w');
466 if (!$exportFile) {
467 $this->errors[] = $langs->trans('ErrorFileNotFound', $exportFilePath);
468 return -1;
469 }
470
471 if ($withAttachment == 1) {
472 $archiveFileList[0] = array(
473 'path' => $exportFilePath,
474 'name' => $exportFileFullName,
475 );
476
477 // archive name and path
478 $archiveFullName = $exportFileName . '.zip';
479 $archivePath = $outputDir . '/' . $archiveFullName;
480 }
481 }
482 }
483
484 // export file (print on screen or write in a file) and prepare archive list if with attachment is set to 1
485 switch ($formatexportset) {
486 case self::$EXPORT_TYPE_CONFIGURABLE:
487 $this->exportConfigurable($TData, $exportFile);
488 break;
489 case self::$EXPORT_TYPE_CEGID:
490 $this->exportCegid($TData, $exportFile);
491 break;
492 case self::$EXPORT_TYPE_COALA:
493 $this->exportCoala($TData, $exportFile);
494 break;
495 case self::$EXPORT_TYPE_BOB50:
496 $this->exportBob50($TData, $exportFile);
497 break;
498 case self::$EXPORT_TYPE_CIEL:
499 $this->exportCiel($TData, $exportFile);
500 break;
501 case self::$EXPORT_TYPE_QUADRATUS:
502 $archiveFileList = $this->exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment);
503 break;
504 case self::$EXPORT_TYPE_WINFIC:
505 $this->exportWinfic($TData, $exportFile);
506 break;
507 case self::$EXPORT_TYPE_EBP:
508 $this->exportEbp($TData, $exportFile);
509 break;
510 case self::$EXPORT_TYPE_COGILOG:
511 $this->exportCogilog($TData, $exportFile);
512 break;
513 case self::$EXPORT_TYPE_AGIRIS:
514 $this->exportAgiris($TData, $exportFile);
515 break;
516 case self::$EXPORT_TYPE_OPENCONCERTO:
517 $this->exportOpenConcerto($TData, $exportFile);
518 break;
519 case self::$EXPORT_TYPE_SAGE50_SWISS:
520 $this->exportSAGE50SWISS($TData, $exportFile);
521 break;
522 case self::$EXPORT_TYPE_CHARLEMAGNE:
523 $this->exportCharlemagne($TData, $exportFile);
524 break;
525 case self::$EXPORT_TYPE_LDCOMPTA:
526 $this->exportLDCompta($TData, $exportFile);
527 break;
528 case self::$EXPORT_TYPE_LDCOMPTA10:
529 $this->exportLDCompta10($TData, $exportFile);
530 break;
531 case self::$EXPORT_TYPE_GESTIMUMV3:
532 $this->exportGestimumV3($TData, $exportFile);
533 break;
534 case self::$EXPORT_TYPE_GESTIMUMV5:
535 $this->exportGestimumV5($TData, $exportFile);
536 break;
537 case self::$EXPORT_TYPE_FEC:
538 $archiveFileList = $this->exportFEC($TData, $exportFile, $archiveFileList, $withAttachment);
539 break;
540 case self::$EXPORT_TYPE_FEC2:
541 $archiveFileList = $this->exportFEC2($TData, $exportFile, $archiveFileList, $withAttachment);
542 break;
543 case self::$EXPORT_TYPE_ISUITEEXPERT:
544 $this->exportiSuiteExpert($TData, $exportFile);
545 break;
546 default:
547 global $hookmanager;
548 $parameters = array(
549 'format' => $formatexportset,
550 'file' => $exportFile,
551 'filepath' => $exportFilePath,
552 'filefullname' => $exportFileFullName,
553 );
554 // file contents will be created in the hooked function via print and name will be returned.
555 $reshook = $hookmanager->executeHooks('export', $parameters, $TData);
556 if ($reshook != 1) {
557 $this->errors[] = $langs->trans('accountancy_error_modelnotfound');
558 } elseif (!empty($hookmanager->resArray['downloadFileFullName']) && !empty($hookmanager->resArray['downloadFilePath'])) {
559 $exportFileFullName = $hookmanager->resArray['downloadFileFullName'];
560 $exportFilePath = $hookmanager->resArray['downloadFilePath'];
561 }
562 break;
563 }
564
565
566 // Create and download export file or archive
567 if ($outputMode == 1 || $outputMode == 2) {
568 $error = 0;
569
570 // close export file
571 if ($exportFile) {
572 fclose($exportFile);
573 }
574
575 if ($withAttachment == 1) {
576 // create archive file
577 if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
578 // archive files
579 $downloadFileMimeType = 'application/zip';
580 $downloadFileFullName = $archiveFullName;
581 $downloadFilePath = $archivePath;
582
583 // create archive
584 $archive = new ZipArchive();
585 $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
586 if ($res !== true) {
587 $error++;
588 $this->errors[] = $langs->trans('ErrorFileNotFound', $archivePath);
589 }
590 if (!$error) {
591 // add files
592 foreach ($archiveFileList as $archiveFileArr) {
593 $res = $archive->addFile($archiveFileArr['path'], $archiveFileArr['name']);
594 if (!$res) {
595 $error++;
596 $this->errors[] = $langs->trans('ErrorArchiveAddFile', $archiveFileArr['name']);
597 break;
598 }
599 }
600 }
601 if (!$error) {
602 // close archive
603 $archive->close();
604 }
605 }
606 }
607
608 if (!$error) {
609 // download after writing files
610 if ($downloadMode == 1) {
611 if ($withAttachment == 0) {
612 // only download exported file
613 if (!empty($exportFileFullName) && !empty($exportFilePath)) {
614 $downloadFileMimeType = $mimetype;
615 $downloadFileFullName = $exportFileFullName;
616 $downloadFilePath = $exportFilePath;
617 }
618 }
619
620 // download export file or archive
621 if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath) && empty($noouput)) {
622 // deprecated. We must not use this anymore, but have $noouput = 1 because HTTP header must be sent
623 // into main page not into a method.
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));
629
630 readfileLowMemory($downloadFilePath);
631 }
632
633 $this->generatedfiledata = array('downloadFilePath' => $downloadFilePath, 'downloadFileMimeType' => $downloadFileMimeType, 'downloadFileFullName' => $downloadFileFullName);
634 }
635 }
636
637 if ($error) {
638 return -1;
639 }
640 }
641
642 return 1;
643 }
644
645
653 public function exportCegid($objectLines, $exportFile = null)
654 {
655 $separator = ";";
656 $end_line = "\n";
657
658 foreach ($objectLines as $line) {
659 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
660
661 $tab = array();
662
663 $tab[] = $date_document;
664 $tab[] = $line->code_journal;
665 $tab[] = length_accountg($line->numero_compte);
666 $tab[] = length_accounta($line->subledger_account);
667 $tab[] = $line->sens;
668 $tab[] = price2fec(abs($line->debit - $line->credit));
669 $tab[] = dol_string_unaccent($line->label_operation);
670 $tab[] = dol_string_unaccent($line->doc_ref);
671
672 $output = implode($separator, $tab).$end_line;
673 if ($exportFile) {
674 fwrite($exportFile, $output);
675 } else {
676 print $output;
677 }
678 }
679 }
680
689 public function exportCogilog($objectLines, $exportFile = null)
690 {
691 $separator = "\t";
692 $end_line = "\n";
693
694 foreach ($objectLines as $line) {
695 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
696
697 $refInvoice = '';
698 if ($line->doc_type == 'customer_invoice') {
699 // 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);
703
704 $refInvoice = $invoice->ref;
705 } elseif ($line->doc_type == 'supplier_invoice') {
706 // Supplier invoice
707 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
708 $invoice = new FactureFournisseur($this->db);
709 $invoice->fetch($line->fk_doc);
710
711 $refInvoice = $invoice->ref_supplier;
712 }
713
714 $tab = array();
715
716 $tab[] = $line->code_journal;
717 $tab[] = $date_document;
718 $tab[] = $refInvoice;
719 if (empty($line->subledger_account)) {
720 $tab[] = length_accountg($line->numero_compte);
721 } else {
722 $tab[] = length_accounta($line->subledger_account);
723 }
724 $tab[] = "";
725 $tab[] = $line->label_operation;
726 $tab[] = $date_document;
727 if ($line->sens == 'D') {
728 $tab[] = price($line->debit);
729 $tab[] = "";
730 } elseif ($line->sens == 'C') {
731 $tab[] = "";
732 $tab[] = price($line->credit);
733 }
734 $tab[] = $line->doc_ref;
735 $tab[] = $line->label_operation;
736
737 $output = implode($separator, $tab).$end_line;
738 if ($exportFile) {
739 fwrite($exportFile, $output);
740 } else {
741 print $output;
742 }
743 }
744 }
745
753 public function exportCoala($objectLines, $exportFile = null)
754 {
755 // Coala export
756 $separator = ";";
757 $end_line = "\n";
758
759 foreach ($objectLines as $line) {
760 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
761
762 $tab = array();
763
764 $tab[] = $date_document;
765 $tab[] = $line->code_journal;
766 $tab[] = length_accountg($line->numero_compte);
767 $tab[] = $line->piece_num;
768 $tab[] = $line->doc_ref;
769 $tab[] = price($line->debit);
770 $tab[] = price($line->credit);
771 $tab[] = 'E';
772 $tab[] = length_accounta($line->subledger_account);
773
774 $output = implode($separator, $tab).$end_line;
775 if ($exportFile) {
776 fwrite($exportFile, $output);
777 } else {
778 print $output;
779 }
780 }
781 }
782
790 public function exportBob50($objectLines, $exportFile = null)
791 {
792 // Bob50
793 $separator = ";";
794 $end_line = "\n";
795
796 foreach ($objectLines as $line) {
797 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
798
799 $tab = array();
800
801 $tab[] = $line->piece_num;
802 $tab[] = $date_document;
803
804 if (empty($line->subledger_account)) {
805 $tab[] = 'G';
806 $tab[] = length_accountg($line->numero_compte);
807 } else {
808 if (substr($line->numero_compte, 0, 3) == '411') {
809 $tab[] = 'C';
810 }
811 if (substr($line->numero_compte, 0, 3) == '401') {
812 $tab[] = 'F';
813 }
814 $tab[] = length_accounta($line->subledger_account);
815 }
816
817 $tab[] = price($line->debit);
818 $tab[] = price($line->credit);
819 $tab[] = dol_trunc($line->label_operation, 32);
820
821 $output = implode($separator, $tab).$end_line;
822 if ($exportFile) {
823 fwrite($exportFile, $output);
824 } else {
825 print $output;
826 }
827 }
828 }
829
845 public function exportCiel($objectLines, $exportFile = null)
846 {
847 $end_line = "\r\n";
848
849 $i = 1;
850
851 foreach ($objectLines as $line) {
852 $code_compta = length_accountg($line->numero_compte);
853 if (!empty($line->subledger_account)) {
854 $code_compta = length_accounta($line->subledger_account);
855 }
856
857 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
858 $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d');
859
860 $tab = array();
861
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); // Analytical accounting - Not managed in Dolibarr
872 $tab[] = str_pad(self::trunc(dol_string_unaccent($line->label_operation), 34), 34);
873 $tab[] = 'O2003'; // 0 = EUR | 2003 = Format Ciel
874
875 $output = implode($tab).$end_line;
876 if ($exportFile) {
877 fwrite($exportFile, $output);
878 } else {
879 print $output;
880 }
881 $i++;
882 }
883 }
884
900 public function exportQuadratus($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
901 {
902 global $conf, $db;
903
904 $end_line = "\r\n";
905
906 // We should use dol_now function not time however this is wrong date to transfer in accounting
907 foreach ($objectLines as $line) {
908 // Clean some data
909 $line->doc_ref = dol_string_unaccent($line->doc_ref);
910
911 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
912 $line->label_operation = str_replace(array("- ", "…", "..."), "", $line->label_operation);
913 $line->label_operation = dol_string_unaccent($line->label_operation);
914
915 $line->numero_compte = dol_string_unaccent($line->numero_compte);
916 $line->label_compte = dol_string_unaccent($line->label_compte);
917 $line->subledger_account = dol_string_unaccent($line->subledger_account);
918
919 $line->subledger_label = str_replace(array("- ", "…", "..."), "", $line->subledger_label);
920 $line->subledger_label = dol_string_unaccent($line->subledger_label);
921
922 $code_compta = $line->numero_compte;
923 if (!empty($line->subledger_account)) {
924 $code_compta = $line->subledger_account;
925 }
926
927 $tab = array();
928
929 if (!empty($line->subledger_account)) {
930 $tab['type_ligne'] = 'C';
931 $tab['num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8);
932 $tab['lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30);
933
934 if ($line->doc_type == 'customer_invoice') {
935 $tab['lib_alpha'] = strtoupper(str_pad('C'.self::trunc(dol_string_unaccent($line->subledger_label), 6), 7));
936 $tab['filler'] = str_repeat(' ', 52);
937 $tab['coll_compte'] = str_pad(self::trunc(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), 8), 8);
938 } elseif ($line->doc_type == 'supplier_invoice') {
939 $tab['lib_alpha'] = strtoupper(str_pad('F'.self::trunc(dol_string_unaccent($line->subledger_label), 6), 7));
940 $tab['filler'] = str_repeat(' ', 52);
941 $tab['coll_compte'] = str_pad(self::trunc(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), 8), 8);
942 } else {
943 $tab['filler'] = str_repeat(' ', 59);
944 $tab['coll_compte'] = str_pad(' ', 8);
945 }
946
947 $tab['filler2'] = str_repeat(' ', 110);
948 $tab['Maj'] = 2; // Partial update (alpha key, label, address, collectif, RIB)
949
950 if ($line->doc_type == 'customer_invoice') {
951 $tab['type_compte'] = 'C';
952 } elseif ($line->doc_type == 'supplier_invoice') {
953 $tab['type_compte'] = 'F';
954 } else {
955 $tab['type_compte'] = 'G';
956 }
957
958 $tab['filler3'] = str_repeat(' ', 235);
959
960 $tab['end_line'] = $end_line;
961
962 if ($exportFile) {
963 fwrite($exportFile, implode($tab));
964 } else {
965 print implode($tab);
966 }
967 }
968
969 $tab = array();
970 $tab['type_ligne'] = 'M';
971 $tab['num_compte'] = str_pad(self::trunc((string) $code_compta, 8), 8);
972 $tab['code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
973 $tab['folio'] = '000';
974
975 // We use invoice date $line->doc_date not $date_ecriture which is the transfer date
976 // maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
977 //$tab['date_ecriture'] = $date_ecriture;
978 $tab['date_ecriture'] = dol_print_date($line->doc_date, '%d%m%y');
979 $tab['filler'] = ' ';
980 $tab['libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.' '.$line->label_operation, 20), 20);
981
982 // Credit invoice - invert sens
983 /*
984 if ($line->montant < 0) {
985 if ($line->sens == 'C') {
986 $tab['sens'] = 'D';
987 } else {
988 $tab['sens'] = 'C';
989 }
990 $tab['signe_montant'] = '-';
991 } else {
992 $tab['sens'] = $line->sens; // C or D
993 $tab['signe_montant'] = '+';
994 }*/
995 $tab['sens'] = $line->sens; // C or D
996 $tab['signe_montant'] = '+';
997
998 // The amount must be in centimes without decimal points.
999 $tab['montant'] = str_pad((string) abs(($line->debit - $line->credit) * 100), 12, '0', STR_PAD_LEFT);
1000 $tab['contrepartie'] = str_repeat(' ', 8);
1001
1002 // Force date format : %d%m%y
1003 if (!empty($line->date_lim_reglement)) {
1004 $tab['date_echeance'] = dol_print_date($line->date_lim_reglement, '%d%m%y'); // Format must be ddmmyy
1005 } else {
1006 $tab['date_echeance'] = '000000';
1007 }
1008
1009 // Please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
1010 // $tab['lettrage'] = str_repeat(' ', 5);
1011 $tab['lettrage'] = str_repeat(' ', 2);
1012 $tab['codestat'] = str_repeat(' ', 3);
1013 $tab['num_piece'] = str_pad(self::trunc((string) $line->piece_num, 5), 5);
1014
1015 // Keep correct quadra named field instead of anon filler
1016 // $tab['filler2'] = str_repeat(' ', 20);
1017 $tab['affaire'] = str_repeat(' ', 10);
1018 $tab['quantity1'] = str_repeat(' ', 10);
1019 $tab['num_piece2'] = str_pad(self::trunc((string) $line->piece_num, 8), 8);
1020 $tab['devis'] = str_pad($conf->currency, 3);
1021 $tab['code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
1022 $tab['filler3'] = str_repeat(' ', 3);
1023
1024 // Keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
1025 // as we use utf8, we must remove accent to have only one ascii char instead of utf8 2 chars for specials that report wrong line size that will exceed import format spec
1026 // TODO: we should filter more than only accent to avoid wrong line size
1027 // TODO: remove invoice number doc_ref in label,
1028 // TODO: we should offer an option for customer to build the label using invoice number / name / date in accounting software
1029 //$tab['libelle_ecriture2'] = str_pad(self::trunc($line->doc_ref . ' ' . $line->label_operation, 30), 30);
1030 $tab['libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
1031 $tab['codetva'] = str_repeat(' ', 2);
1032
1033 // We need to keep the 10 latest number of invoices doc_ref not the beginning part that is the useless almost same part
1034 // $tab['num_piece3'] = str_pad(self::trunc($line->piece_num, 10), 10);
1035 $tab['num_piece3'] = str_pad(substr(self::trunc($line->doc_ref, 20), -10), 10);
1036 $tab['reserved'] = str_repeat(' ', 10); // position 159
1037 $tab['currency_amount'] = str_repeat(' ', 13); // position 169
1038 // get document file
1039 $attachmentFileName = '';
1040 if ($withAttachment == 1) {
1041 $attachmentFileKey = trim((string) $line->piece_num);
1042
1043 if (!isset($archiveFileList[$attachmentFileKey])) {
1044 $objectDirPath = '';
1045 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1046 if ($line->doc_type == 'customer_invoice') {
1047 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1048 } elseif ($line->doc_type == 'expense_report') {
1049 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1050 } elseif ($line->doc_type == 'supplier_invoice') {
1051 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1052 $invoice = new FactureFournisseur($this->db);
1053 $invoice->fetch($line->fk_doc);
1054 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1055 $objectDirPath .= '/'.rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1056 }
1057 $arrayofinclusion = array();
1058 // If it is a supplier invoice, we want to use last uploaded file
1059 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1060 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1061 if (!empty($fileFoundList)) {
1062 $attachmentFileNameTrunc = str_pad(self::trunc((string) $line->piece_num, 8), 8, '0', STR_PAD_LEFT);
1063 foreach ($fileFoundList as $fileFound) {
1064 if (strstr($fileFound['name'], $objectFileName)) {
1065 // skip native invoice pdfs (canelle)
1066 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1067 if ($line->doc_type == 'supplier_invoice') {
1068 if ($fileFound['name'] === $objectFileName.'.pdf') {
1069 continue;
1070 }
1071 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1072 continue;
1073 }
1074 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1075 if (file_exists($fileFoundPath)) {
1076 $archiveFileList[$attachmentFileKey] = array(
1077 'path' => $fileFoundPath,
1078 'name' => $attachmentFileNameTrunc.'.pdf',
1079 );
1080 break;
1081 }
1082 }
1083 }
1084 }
1085 }
1086
1087 if (isset($archiveFileList[$attachmentFileKey])) {
1088 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1089 }
1090 }
1091 if (dol_strlen((string) $attachmentFileName) == 12) {
1092 $tab['attachment'] = $attachmentFileName; // position 182
1093 } else {
1094 $tab['attachment'] = str_repeat(' ', 12); // position 182
1095 }
1096 $tab['filler4'] = str_repeat(' ', 38);
1097 $tab['end_line'] = $end_line;
1098
1099 if ($exportFile) {
1100 fwrite($exportFile, implode($tab));
1101 } else {
1102 print implode($tab);
1103 }
1104 }
1105
1106 return $archiveFileList;
1107 }
1108
1119 public function exportWinfic($objectLines, $exportFile = null)
1120 {
1121 global $conf;
1122
1123 $end_line = "\r\n";
1124 $index = 1;
1125
1126 // Warning ! When truncation is necessary, no dot because 3 dots = three characters. The columns are shifted
1127
1128 foreach ($objectLines as $line) {
1129 $code_compta = $line->numero_compte;
1130 if (!empty($line->subledger_account)) {
1131 $code_compta = $line->subledger_account;
1132 }
1133
1134 $tab = array();
1135 //$tab['type_ligne'] = 'M';
1136 $tab['code_journal'] = str_pad(dol_trunc($line->code_journal, 2, 'right', 'UTF-8', 1), 2);
1137
1138 //We use invoice date $line->doc_date not $date_ecriture which is the transfer date
1139 //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
1140 //$tab['date_ecriture'] = $date_ecriture;
1141 $tab['date_operation'] = dol_print_date($line->doc_date, '%d%m%Y');
1142
1143 $tab['folio'] = ' 1';
1144
1145 $tab['num_ecriture'] = str_pad(dol_trunc((string) $index, 6, 'right', 'UTF-8', 1), 6, ' ', STR_PAD_LEFT);
1146
1147 $tab['jour_ecriture'] = dol_print_date($line->doc_date, '%d%m%y');
1148
1149 $tab['num_compte'] = str_pad(dol_trunc((string) $code_compta, 6, 'right', 'UTF-8', 1), 6, '0');
1150
1151 if ($line->sens == 'D') {
1152 $tab['montant_debit'] = str_pad(number_format($line->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1153
1154 $tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1155 } else {
1156 $tab['montant_debit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1157
1158 $tab['montant_crebit'] = str_pad(number_format($line->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1159 }
1160
1161 $tab['libelle_ecriture'] = str_pad(dol_trunc(dol_string_unaccent($line->doc_ref).' '.dol_string_unaccent($line->label_operation), 30, 'right', 'UTF-8', 1), 30);
1162
1163 $tab['lettrage'] = str_repeat(dol_trunc((string) $line->lettering_code, 2, 'left', 'UTF-8', 1), 2);
1164
1165 $tab['code_piece'] = str_pad(dol_trunc((string) $line->piece_num, 5, 'left', 'UTF-8', 1), 5, ' ', STR_PAD_LEFT);
1166
1167 $tab['code_stat'] = str_repeat(' ', 4);
1168
1169 if (!empty($line->date_lim_reglement)) {
1170 $tab['date_echeance'] = dol_print_date($line->date_lim_reglement, '%d%m%Y');
1171 } else {
1172 $tab['date_echeance'] = dol_print_date($line->doc_date, '%d%m%Y');
1173 }
1174
1175 $tab['monnaie'] = '1';
1176
1177 $tab['filler'] = ' ';
1178
1179 $tab['ind_compteur'] = ' ';
1180
1181 $tab['quantite'] = '0,000000000';
1182
1183 $tab['code_pointage'] = str_repeat(' ', 2);
1184
1185 $tab['end_line'] = $end_line;
1186
1187 $output = implode('|', $tab);
1188 if ($exportFile) {
1189 fwrite($exportFile, $output);
1190 } else {
1191 print $output;
1192 }
1193
1194 $index++;
1195 }
1196 }
1197
1198
1206 public function exportEbp($objectLines, $exportFile = null)
1207 {
1208 $separator = ',';
1209 $end_line = "\n";
1210
1211 foreach ($objectLines as $line) {
1212 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
1213
1214 $tab = array();
1215
1216 $tab[] = $line->id;
1217 $tab[] = $date_document;
1218 $tab[] = $line->code_journal;
1219 if (empty($line->subledger_account)) {
1220 $tab[] = $line->numero_compte;
1221 } else {
1222 $tab[] = $line->subledger_account;
1223 }
1224 //$tab[] = substr(length_accountg($line->numero_compte), 0, 2) . $separator;
1225 $tab[] = '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"';
1226 $tab[] = '"'.dol_trunc((string) $line->piece_num, 15, 'right', 'UTF-8', 1).'"';
1227 $tab[] = price2num(abs($line->debit - $line->credit));
1228 $tab[] = $line->sens;
1229 $tab[] = $date_document;
1230 //print 'EUR';
1231
1232 $output = implode($separator, $tab).$end_line;
1233 if ($exportFile) {
1234 fwrite($exportFile, $output);
1235 } else {
1236 print $output;
1237 }
1238 }
1239 }
1240
1241
1249 public function exportAgiris($objectLines, $exportFile = null)
1250 {
1251 $separator = ';';
1252 $end_line = "\n";
1253
1254 foreach ($objectLines as $line) {
1255 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
1256
1257 $tab = array();
1258
1259 $tab[] = $line->piece_num;
1260 $tab[] = self::toAnsi($line->label_operation);
1261 $tab[] = $date_document;
1262 $tab[] = self::toAnsi($line->label_operation);
1263
1264 if (empty($line->subledger_account)) {
1265 $tab[] = length_accountg($line->numero_compte);
1266 $tab[] = self::toAnsi($line->label_compte);
1267 } else {
1268 $tab[] = length_accounta($line->subledger_account);
1269 $tab[] = self::toAnsi($line->subledger_label);
1270 }
1271
1272 $tab[] = self::toAnsi($line->doc_ref);
1273 $tab[] = price($line->debit);
1274 $tab[] = price($line->credit);
1275 $tab[] = price(abs($line->debit - $line->credit));
1276 $tab[] = $line->sens;
1277 $tab[] = $line->lettering_code;
1278 $tab[] = $line->code_journal;
1279
1280 $output = implode($separator, $tab).$end_line;
1281 if ($exportFile) {
1282 fwrite($exportFile, $output);
1283 } else {
1284 print $output;
1285 }
1286 }
1287 }
1288
1296 public function exportOpenConcerto($objectLines, $exportFile = null)
1297 {
1298 $separator = ';';
1299 $end_line = "\n";
1300
1301 foreach ($objectLines as $line) {
1302 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
1303
1304 $tab = array();
1305
1306 $tab[] = $date_document;
1307 $tab[] = $line->code_journal;
1308 if (empty($line->subledger_account)) {
1309 $tab[] = length_accountg($line->numero_compte);
1310 } else {
1311 $tab[] = length_accounta($line->subledger_account);
1312 }
1313 $tab[] = $line->doc_ref;
1314 $tab[] = $line->label_operation;
1315 $tab[] = price($line->debit);
1316 $tab[] = price($line->credit);
1317
1318 $output = implode($separator, $tab).$end_line;
1319 if ($exportFile) {
1320 fwrite($exportFile, $output);
1321 } else {
1322 print $output;
1323 }
1324 }
1325 }
1326
1334 public function exportConfigurable($objectLines, $exportFile = null)
1335 {
1336 global $conf;
1337
1338 $separator = $this->separator;
1339
1340 foreach ($objectLines as $line) {
1341 $date_document = dol_print_date($line->doc_date, getDolGlobalString('ACCOUNTING_EXPORT_DATE'));
1342
1343 $tab = array();
1344 // export configurable
1345 $tab[] = $line->piece_num;
1346 $tab[] = $date_document;
1347 $tab[] = $line->doc_ref;
1348 $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
1349 $tab[] = length_accountg($line->numero_compte);
1350 $tab[] = length_accounta($line->subledger_account);
1351 $tab[] = price2num($line->debit);
1352 $tab[] = price2num($line->credit);
1353 $tab[] = price2num($line->debit - $line->credit);
1354 $tab[] = $line->code_journal;
1355
1356 $output = implode($separator, $tab).$this->end_line;
1357 if ($exportFile) {
1358 fwrite($exportFile, $output);
1359 } else {
1360 print $output;
1361 }
1362 }
1363 }
1364
1377 public function exportFEC($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
1378 {
1379 global $conf, $langs;
1380
1381 $separator = "\t";
1382 $end_line = "\r\n";
1383
1384 $tab = array();
1385 $tab[] = "JournalCode";
1386 $tab[] = "JournalLib";
1387 $tab[] = "EcritureNum";
1388 $tab[] = "EcritureDate";
1389 $tab[] = "CompteNum";
1390 $tab[] = "CompteLib";
1391 $tab[] = "CompAuxNum";
1392 $tab[] = "CompAuxLib";
1393 $tab[] = "PieceRef";
1394 $tab[] = "PieceDate";
1395 $tab[] = "EcritureLib";
1396 $tab[] = "Debit";
1397 $tab[] = "Credit";
1398 $tab[] = "EcritureLet";
1399 $tab[] = "DateLet";
1400 $tab[] = "ValidDate";
1401 $tab[] = "Montantdevise";
1402 $tab[] = "Idevise";
1403 $tab[] = "DateLimitReglmt";
1404 $tab[] = "NumFacture";
1405 $tab[] = "FichierFacture";
1406
1407 $output = implode($separator, $tab).$end_line;
1408 if ($exportFile) {
1409 fwrite($exportFile, $output);
1410 } else {
1411 print $output;
1412 }
1413
1414 foreach ($objectLines as $line) {
1415 if ($line->debit == 0 && $line->credit == 0) {
1416 //var_dump($line->id);
1417 //unset($array[$line]);
1418 } else {
1419 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1420 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1421 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1422 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1423 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1424
1425 $refInvoice = '';
1426 if ($line->doc_type == 'customer_invoice') {
1427 // Customer invoice
1428 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1429 $invoice = new Facture($this->db);
1430 $invoice->fetch($line->fk_doc);
1431
1432 $refInvoice = $invoice->ref;
1433 } elseif ($line->doc_type == 'supplier_invoice') {
1434 // Supplier invoice
1435 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1436 $invoice = new FactureFournisseur($this->db);
1437 $invoice->fetch($line->fk_doc);
1438
1439 $refInvoice = $invoice->ref_supplier;
1440 }
1441
1442 $tab = array();
1443
1444 // FEC:JournalCode
1445 $tab[] = $line->code_journal;
1446
1447 // FEC:JournalLib
1448 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1449 $labeljournal = str_replace(array("\t", "\n", "\r"), " ", $labeljournal);
1450 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1451 $tab[] = $labeljournal;
1452
1453 // FEC:EcritureNum
1454 $tab[] = $line->piece_num;
1455
1456 // FEC:EcritureDate
1457 $tab[] = $date_document;
1458
1459 // FEC:CompteNum
1460 $tab[] = length_accountg($line->numero_compte);
1461
1462 // FEC:CompteLib
1463 $line->label_compte = str_replace(array("\t", "\n", "\r"), " ", $line->label_compte);
1464 $tab[] = dol_string_unaccent($line->label_compte);
1465
1466 // FEC:CompAuxNum
1467 $tab[] = length_accounta($line->subledger_account);
1468
1469 // FEC:CompAuxLib
1470 $line->subledger_label = str_replace(array("\t", "\n", "\r"), " ", $line->subledger_label);
1471 $tab[] = dol_string_unaccent($line->subledger_label);
1472
1473 // FEC:PieceRef
1474 $line->doc_ref = str_replace(array("\t", "\n", "\r"), " ", $line->doc_ref);
1475 $tab[] = $line->doc_ref;
1476
1477 // FEC:PieceDate
1478 $tab[] = dol_string_unaccent($date_creation);
1479
1480 // FEC:EcritureLib
1481 // Clean label operation to prevent problem on export with tab separator & other character
1482 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1483 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1484 $tab[] = dol_string_unaccent($line->label_operation);
1485
1486 // FEC:Debit
1487 $tab[] = price2fec($line->debit);
1488
1489 // FEC:Credit
1490 $tab[] = price2fec($line->credit);
1491
1492 // FEC:EcritureLet
1493 $line->lettering_code = str_replace(array("\t", "\n", "\r"), " ", (string) $line->lettering_code);
1494 $tab[] = $line->lettering_code;
1495
1496 // FEC:DateLet
1497 $tab[] = $date_lettering;
1498
1499 // FEC:ValidDate
1500 $tab[] = $date_validation;
1501
1502 // FEC:Montantdevise
1503 $tab[] = $line->multicurrency_amount;
1504
1505 // FEC:Idevise
1506 $tab[] = $line->multicurrency_code;
1507
1508 // FEC_suppl:DateLimitReglmt
1509 $tab[] = $date_limit_payment;
1510
1511 // FEC_suppl:NumFacture
1512 // Clean ref invoice to prevent problem on export with tab separator & other character
1513 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1514 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1515
1516 // FEC_suppl:FichierFacture
1517 // get document file
1518 $attachmentFileName = '';
1519 if ($withAttachment == 1) {
1520 $attachmentFileKey = trim((string) $line->piece_num);
1521
1522 if (!isset($archiveFileList[$attachmentFileKey])) {
1523 $objectDirPath = '';
1524 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1525 if ($line->doc_type == 'customer_invoice') {
1526 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1527 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1528 }
1529 } elseif ($line->doc_type == 'expense_report') {
1530 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1531 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1532 }
1533 } elseif ($line->doc_type == 'supplier_invoice') {
1534 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1535 '@phan-var-force FactureFournisseur $invoice';
1537 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1538 $objectDirPath .= '/' . rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1539 }
1540 }
1541 $arrayofinclusion = array();
1542 // If it is a supplier invoice, we want to use last uploaded file
1543 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1544 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1545 if (!empty($fileFoundList)) {
1546 $attachmentFileNameTrunc = $line->doc_ref;
1547 foreach ($fileFoundList as $fileFound) {
1548 if (strstr($fileFound['name'], $objectFileName)) {
1549 // skip native invoice pdfs (canelle)
1550 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1551 if ($line->doc_type == 'supplier_invoice') {
1552 if ($fileFound['name'] === $objectFileName.'.pdf') {
1553 continue;
1554 }
1555 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1556 continue;
1557 }
1558 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1559 if (file_exists($fileFoundPath)) {
1560 $archiveFileList[$attachmentFileKey] = array(
1561 'path' => $fileFoundPath,
1562 'name' => $attachmentFileNameTrunc.'.pdf',
1563 );
1564 break;
1565 }
1566 }
1567 }
1568 }
1569 }
1570
1571 if (isset($archiveFileList[$attachmentFileKey])) {
1572 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1573 }
1574 }
1575
1576 $tab[] = $attachmentFileName;
1577
1578 $output = implode($separator, $tab).$end_line;
1579
1580 if ($exportFile) {
1581 fwrite($exportFile, $output);
1582 } else {
1583 print $output;
1584 }
1585 }
1586 }
1587
1588 return $archiveFileList;
1589 }
1590
1603 public function exportFEC2($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
1604 {
1605 global $conf, $langs;
1606
1607 $separator = "\t";
1608 $end_line = "\r\n";
1609
1610 $tab = array();
1611 $tab[] = "JournalCode";
1612 $tab[] = "JournalLib";
1613 $tab[] = "EcritureNum";
1614 $tab[] = "EcritureDate";
1615 $tab[] = "CompteNum";
1616 $tab[] = "CompteLib";
1617 $tab[] = "CompAuxNum";
1618 $tab[] = "CompAuxLib";
1619 $tab[] = "PieceRef";
1620 $tab[] = "PieceDate";
1621 $tab[] = "EcritureLib";
1622 $tab[] = "Debit";
1623 $tab[] = "Credit";
1624 $tab[] = "EcritureLet";
1625 $tab[] = "DateLet";
1626 $tab[] = "ValidDate";
1627 $tab[] = "Montantdevise";
1628 $tab[] = "Idevise";
1629 $tab[] = "DateLimitReglmt";
1630 $tab[] = "NumFacture";
1631 $tab[] = "FichierFacture";
1632
1633 $output = implode($separator, $tab).$end_line;
1634 if ($exportFile) {
1635 fwrite($exportFile, $output);
1636 } else {
1637 print $output;
1638 }
1639
1640 foreach ($objectLines as $line) {
1641 if ($line->debit == 0 && $line->credit == 0) {
1642 //unset($array[$line]);
1643 } else {
1644 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1645 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1646 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1647 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1648 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1649
1650 $refInvoice = '';
1651 if ($line->doc_type == 'customer_invoice') {
1652 // Customer invoice
1653 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1654 $invoice = new Facture($this->db);
1655 $invoice->fetch($line->fk_doc);
1656
1657 $refInvoice = $invoice->ref;
1658 } elseif ($line->doc_type == 'supplier_invoice') {
1659 // Supplier invoice
1660 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1661 $invoice = new FactureFournisseur($this->db);
1662 $invoice->fetch($line->fk_doc);
1663
1664 $refInvoice = $invoice->ref_supplier;
1665 }
1666
1667 $tab = array();
1668
1669 // FEC:JournalCode
1670 $tab[] = $line->code_journal;
1671
1672 // FEC:JournalLib
1673 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1674 $labeljournal = str_replace(array("\t", "\n", "\r"), " ", $labeljournal);
1675 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1676 $tab[] = $labeljournal;
1677
1678 // FEC:EcritureNum
1679 $tab[] = $line->piece_num;
1680
1681 // FEC:EcritureDate
1682 $tab[] = $date_creation;
1683
1684 // FEC:CompteNum
1685 $tab[] = length_accountg($line->numero_compte);
1686
1687 // FEC:CompteLib
1688 $line->label_compte = str_replace(array("\t", "\n", "\r"), " ", $line->label_compte);
1689 $tab[] = dol_string_unaccent($line->label_compte);
1690
1691 // FEC:CompAuxNum
1692 $tab[] = length_accounta($line->subledger_account);
1693
1694 // FEC:CompAuxLib
1695 $line->subledger_label = str_replace(array("\t", "\n", "\r"), " ", $line->subledger_label);
1696 $tab[] = dol_string_unaccent($line->subledger_label);
1697
1698 // FEC:PieceRef
1699 $line->doc_ref = str_replace(array("\t", "\n", "\r"), " ", $line->doc_ref);
1700 $tab[] = $line->doc_ref;
1701
1702 // FEC:PieceDate
1703 $tab[] = $date_document;
1704
1705 // FEC:EcritureLib
1706 // Clean label operation to prevent problem on export with tab separator & other character
1707 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1708 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1709 $tab[] = dol_string_unaccent($line->label_operation);
1710
1711 // FEC:Debit
1712 $tab[] = price2fec($line->debit);
1713
1714 // FEC:Credit
1715 $tab[] = price2fec($line->credit);
1716
1717 // FEC:EcritureLet
1718 $line->lettering_code = str_replace(array("\t", "\n", "\r"), " ", (string) $line->lettering_code);
1719 $tab[] = $line->lettering_code;
1720
1721 // FEC:DateLet
1722 $tab[] = $date_lettering;
1723
1724 // FEC:ValidDate
1725 $tab[] = $date_validation;
1726
1727 // FEC:Montantdevise
1728 $tab[] = $line->multicurrency_amount;
1729
1730 // FEC:Idevise
1731 $tab[] = $line->multicurrency_code;
1732
1733 // FEC_suppl:DateLimitReglmt
1734 $tab[] = $date_limit_payment;
1735
1736 // FEC_suppl:NumFacture
1737 // Clean ref invoice to prevent problem on export with tab separator & other character
1738 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1739 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1740
1741 // FEC_suppl:FichierFacture
1742 // get document file
1743 $attachmentFileName = '';
1744 if ($withAttachment == 1) {
1745 $attachmentFileKey = trim((string) $line->piece_num);
1746
1747 if (!isset($archiveFileList[$attachmentFileKey])) {
1748 $objectDirPath = '';
1749 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1750 if ($line->doc_type == 'customer_invoice') {
1751 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1752 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1753 }
1754 } elseif ($line->doc_type == 'expense_report') {
1755 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1756 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1757 }
1758 } elseif ($line->doc_type == 'supplier_invoice') {
1759 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1760 '@phan-var-force FactureFournisseur $invoice';
1762 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1763 $objectDirPath .= '/' . rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1764 }
1765 }
1766 $arrayofinclusion = array();
1767 // If it is a supplier invoice, we want to use last uploaded file
1768 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1769 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1770 if (!empty($fileFoundList)) {
1771 $attachmentFileNameTrunc = $line->doc_ref;
1772 foreach ($fileFoundList as $fileFound) {
1773 if (strstr($fileFound['name'], $objectFileName)) {
1774 // skip native invoice pdfs (canelle)
1775 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1776 if ($line->doc_type == 'supplier_invoice') {
1777 if ($fileFound['name'] === $objectFileName.'.pdf') {
1778 continue;
1779 }
1780 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1781 continue;
1782 }
1783 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1784 if (file_exists($fileFoundPath)) {
1785 $archiveFileList[$attachmentFileKey] = array(
1786 'path' => $fileFoundPath,
1787 'name' => $attachmentFileNameTrunc.'.pdf',
1788 );
1789 break;
1790 }
1791 }
1792 }
1793 }
1794 }
1795
1796 if (isset($archiveFileList[$attachmentFileKey])) {
1797 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1798 }
1799 }
1800
1801 $tab[] = $attachmentFileName;
1802
1803 $output = implode($separator, $tab).$end_line;
1804 if ($exportFile) {
1805 fwrite($exportFile, $output);
1806 } else {
1807 print $output;
1808 }
1809 }
1810 }
1811
1812 return $archiveFileList;
1813 }
1814
1825 public function exportSAGE50SWISS($objectLines, $exportFile = null)
1826 {
1827 // SAGE50SWISS
1828 $separator = ',';
1829 $end_line = "\r\n";
1830
1831 // Print header line
1832 $tab = array();
1833
1834 $tab[] = "Blg";
1835 $tab[] = "Datum";
1836 $tab[] = "Kto";
1837 $tab[] = "S/H";
1838 $tab[] = "Grp";
1839 $tab[] = "GKto";
1840 $tab[] = "SId";
1841 $tab[] = "SIdx";
1842 $tab[] = "KIdx";
1843 $tab[] = "BTyp";
1844 $tab[] = "MTyp";
1845 $tab[] = "Code";
1846 $tab[] = "Netto";
1847 $tab[] = "Steuer";
1848 $tab[] = "FW-Betrag";
1849 $tab[] = "Tx1";
1850 $tab[] = "Tx2";
1851 $tab[] = "PkKey";
1852 $tab[] = "OpId";
1853 $tab[] = "Flag";
1854
1855 $output = implode($separator, $tab).$end_line;
1856 if ($exportFile) {
1857 fwrite($exportFile, $output);
1858 } else {
1859 print $output;
1860 }
1861
1862 $thisPieceNum = "";
1863 $thisPieceAccountNr = "";
1864 $aSize = count($objectLines);
1865 foreach ($objectLines as $aIndex => $line) {
1866 $sammelBuchung = false;
1867 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1868 $sammelBuchung = true;
1869 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1870 $sammelBuchung = true;
1871 } elseif ($aIndex + 1 < $aSize
1872 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1873 && $aIndex - 1 < $aSize
1874 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1875 ) {
1876 $sammelBuchung = true;
1877 }
1878
1879 $tab = array();
1880
1881 //Blg
1882 $tab[] = $line->piece_num;
1883
1884 // Datum
1885 $date_document = dol_print_date($line->doc_date, '%d.%m.%Y');
1886 $tab[] = $date_document;
1887
1888 // Kto
1889 $tab[] = length_accountg($line->numero_compte);
1890 // S/H
1891 if ($line->sens == 'D') {
1892 $tab[] = 'S';
1893 } else {
1894 $tab[] = 'H';
1895 }
1896 // Grp
1897 $tab[] = self::trunc($line->code_journal, 1);
1898 // GKto
1899 if (empty($line->code_tiers)) {
1900 if ($line->piece_num == $thisPieceNum) {
1901 $tab[] = length_accounta($thisPieceAccountNr);
1902 } else {
1903 $tab[] = "div";
1904 }
1905 } else {
1906 $tab[] = length_accounta($line->code_tiers);
1907 }
1908 // SId
1909 $tab[] = $this->separator;
1910 // SIdx
1911 $tab[] = "0";
1912 // KIdx
1913 $tab[] = "0";
1914 // BTyp
1915 $tab[] = "0";
1916
1917 // MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
1918 if ($sammelBuchung) {
1919 $tab[] = "2";
1920 } else {
1921 $tab[] = "1";
1922 }
1923 // Code
1924 $tab[] = '""';
1925 // Netto
1926 $tab[] = abs($line->debit - $line->credit);
1927 // Steuer
1928 $tab[] = "0.00";
1929 // FW-Betrag
1930 $tab[] = "0.00";
1931 // Tx1
1932 $line1 = self::toAnsi($line->label_compte, 29);
1933 if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
1934 $line1 = "";
1935 }
1936 $line2 = self::toAnsi($line->doc_ref, 29);
1937 if (strlen($line1) == 0) {
1938 $line1 = $line2;
1939 $line2 = "";
1940 }
1941 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1942 $line1 = $line1.' / '.$line2;
1943 $line2 = "";
1944 }
1945
1946 $tab[] = '"'.self::toAnsi($line1).'"';
1947 // Tx2
1948 $tab[] = '"'.self::toAnsi($line2).'"';
1949 //PkKey
1950 $tab[] = "0";
1951 //OpId
1952 $tab[] = $this->separator;
1953
1954 // Flag
1955 $tab[] = "0";
1956
1957 $output = implode($separator, $tab).$end_line;
1958 if ($exportFile) {
1959 fwrite($exportFile, $output);
1960 } else {
1961 print $output;
1962 }
1963
1964 if ($line->piece_num !== $thisPieceNum) {
1965 $thisPieceNum = $line->piece_num;
1966 $thisPieceAccountNr = $line->numero_compte;
1967 }
1968 }
1969 }
1970
1979 public function exportLDCompta($objectLines, $exportFile = null)
1980 {
1981 $separator = ';';
1982 $end_line = "\r\n";
1983
1984 foreach ($objectLines as $line) {
1985 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1986 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1987 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1988
1989 $tab = array();
1990
1991 // TYPE
1992 $type_enregistrement = 'E'; // For write movement
1993 $tab[] = $type_enregistrement;
1994 // JNAL
1995 $tab[] = substr($line->code_journal, 0, 2);
1996 // NECR
1997 $tab[] = $line->id;
1998 // NPIE
1999 $tab[] = $line->piece_num;
2000 // DATP
2001 $tab[] = $date_document;
2002 // LIBE
2003 $tab[] = $line->label_operation;
2004 // DATH
2005 $tab[] = $date_lim_reglement;
2006 // CNPI
2007 if ($line->doc_type == 'supplier_invoice') {
2008 if (($line->debit - $line->credit) > 0) {
2009 $nature_piece = 'AF';
2010 } else {
2011 $nature_piece = 'FF';
2012 }
2013 } elseif ($line->doc_type == 'customer_invoice') {
2014 if (($line->debit - $line->credit) < 0) {
2015 $nature_piece = 'AC';
2016 } else {
2017 $nature_piece = 'FC';
2018 }
2019 } else {
2020 $nature_piece = '';
2021 }
2022 $tab[] = $nature_piece;
2023 // RACI
2024 // if (!empty($line->subledger_account)) {
2025 // if ($line->doc_type == 'supplier_invoice') {
2026 // $racine_subledger_account = '40';
2027 // } elseif ($line->doc_type == 'customer_invoice') {
2028 // $racine_subledger_account = '41';
2029 // } else {
2030 // $racine_subledger_account = '';
2031 // }
2032 // } else {
2033 $racine_subledger_account = ''; // for records of type E leave this field blank
2034 // }
2035
2036 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2037 // MONT
2038 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2, 2);
2039 // CODC
2040 $tab[] = $line->sens;
2041 // CPTG
2042 $tab[] = length_accountg($line->numero_compte);
2043 // DATE
2044 $tab[] = $date_creation;
2045 // CLET
2046 $tab[] = $line->lettering_code;
2047 // DATL
2048 $tab[] = $line->date_lettering;
2049 // CPTA
2050 if (!empty($line->subledger_account)) {
2051 $tab[] = length_accounta($line->subledger_account);
2052 } else {
2053 $tab[] = "";
2054 }
2055 // C.N.A.T
2056 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2057 $tab[] = 'F';
2058 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2059 $tab[] = 'C';
2060 } else {
2061 $tab[] = "";
2062 }
2063 // SECT
2064 $tab[] = "";
2065 // CTRE
2066 $tab[] = "";
2067 // NORL
2068 $tab[] = "";
2069 // DATV
2070 $tab[] = "";
2071 // REFD
2072 $tab[] = $line->doc_ref;
2073 // CODH
2074 $tab[] = "";
2075 // NSEQ
2076 $tab[] = "";
2077 // MTDV
2078 $tab[] = '0';
2079 // CODV
2080 $tab[] = "";
2081 // TXDV
2082 $tab[] = '0';
2083 // MOPM
2084 $tab[] = "";
2085 // BONP
2086 $tab[] = "";
2087 // BQAF
2088 $tab[] = "";
2089 // ECES
2090 $tab[] = "";
2091 // TXTL
2092 $tab[] = "";
2093 // ECRM
2094 $tab[] = "";
2095 // DATK
2096 $tab[] = "";
2097 // HEUK
2098 $tab[] = "";
2099
2100 $output = implode($separator, $tab).$end_line;
2101 if ($exportFile) {
2102 fwrite($exportFile, $output);
2103 } else {
2104 print $output;
2105 }
2106 }
2107 }
2108
2119 public function exportLDCompta10($objectLines, $exportFile = null)
2120 {
2121 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
2122
2123 $separator = ';';
2124 $end_line = "\r\n";
2125 $last_codeinvoice = '';
2126
2127 foreach ($objectLines as $line) {
2128 // TYPE C
2129 if ($last_codeinvoice != $line->doc_ref) {
2130 //recherche societe en fonction de son code client
2131 $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
2132 $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
2133 $resql = $this->db->query($sql);
2134
2135 if ($resql && $this->db->num_rows($resql) > 0) {
2136 $soc = $this->db->fetch_object($resql);
2137
2138 $address = array('', '', '');
2139 if (strpos($soc->address, "\n") !== false) {
2140 $address = explode("\n", $soc->address);
2141 if (is_array($address) && count($address) > 0) {
2142 foreach ($address as $key => $data) {
2143 $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
2144 $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
2145 }
2146 }
2147 } else {
2148 $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
2149 $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
2150 $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
2151 }
2152
2153 $tab = array();
2154
2155 $type_enregistrement = 'C';
2156 //TYPE
2157 $tab[] = $type_enregistrement;
2158 //NOCL
2159 $tab[] = $soc->code_client;
2160 //NMCM
2161 $tab[] = "";
2162 //LIBI
2163 $tab[] = "";
2164 //TITR
2165 $tab[] = "";
2166 //RSSO
2167 $tab[] = $soc->nom;
2168 //CAD1
2169 $tab[] = $address[0];
2170 //CAD2
2171 $tab[] = $address[1];
2172 //CAD3
2173 $tab[] = $address[2];
2174 //COPO
2175 $tab[] = $soc->zip;
2176 //BUDI
2177 $tab[] = substr($soc->town, 0, 40);
2178 //CPAY
2179 $tab[] = "";
2180 //PAYS
2181 $tab[] = substr(getCountry($soc->fk_pays), 0, 40);
2182 //NTEL
2183 $tab[] = $soc->phone;
2184 //TLEX
2185 $tab[] = "";
2186 //TLPO
2187 $tab[] = "";
2188 //TLCY
2189 $tab[] = "";
2190 //NINT
2191 $tab[] = "";
2192 //COMM
2193 $tab[] = "";
2194 //SIRE
2195 $tab[] = str_replace(" ", "", $soc->siret);
2196 //RIBP
2197 $tab[] = "";
2198 //DOBQ
2199 $tab[] = "";
2200 //IBBQ
2201 $tab[] = "";
2202 //COBQ
2203 $tab[] = "";
2204 //GUBQ
2205 $tab[] = "";
2206 //CPBQ
2207 $tab[] = "";
2208 //CLBQ
2209 $tab[] = "";
2210 //BIBQ
2211 $tab[] = "";
2212 //MOPM
2213 $tab[] = "";
2214 //DJPM
2215 $tab[] = "";
2216 //DMPM
2217 $tab[] = "";
2218 //REFM
2219 $tab[] = "";
2220 //SLVA
2221 $tab[] = "";
2222 //PLCR
2223 $tab[] = "";
2224 //ECFI
2225 $tab[] = "";
2226 //CREP
2227 $tab[] = "";
2228 //NREP
2229 $tab[] = "";
2230 //TREP
2231 $tab[] = "";
2232 //MREP
2233 $tab[] = "";
2234 //GRRE
2235 $tab[] = "";
2236 //LTTA
2237 $tab[] = "";
2238 //CACT
2239 $tab[] = "";
2240 //CODV
2241 $tab[] = "";
2242 //GRTR
2243 $tab[] = "";
2244 //NOFP
2245 $tab[] = "";
2246 //BQAF
2247 $tab[] = "";
2248 //BONP
2249 $tab[] = "";
2250 //CESC
2251 $tab[] = "";
2252
2253 $output = implode($separator, $tab).$end_line;
2254 if ($exportFile) {
2255 fwrite($exportFile, $output);
2256 } else {
2257 print $output;
2258 }
2259 }
2260 }
2261
2262 $tab = array();
2263
2264 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2265 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
2266 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2267
2268 // TYPE E
2269 $type_enregistrement = 'E'; // For write movement
2270 $tab[] = $type_enregistrement;
2271 // JNAL
2272 $tab[] = substr($line->code_journal, 0, 2);
2273 // NECR
2274 $tab[] = $line->id;
2275 // NPIE
2276 $tab[] = $line->piece_num;
2277 // DATP
2278 $tab[] = $date_document;
2279 // LIBE
2280 $tab[] = dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1);
2281 // DATH
2282 $tab[] = $date_lim_reglement;
2283 // CNPI
2284 if ($line->doc_type == 'supplier_invoice') {
2285 if (($line->amount) < 0) { // Currently, only the sign of amount allows to know the type of invoice (standard or credit note). Other solution is to analyse debit/credit/role of account. TODO Add column doc_type_long or make amount mandatory with rule on sign.
2286 $nature_piece = 'AF';
2287 } else {
2288 $nature_piece = 'FF';
2289 }
2290 } elseif ($line->doc_type == 'customer_invoice') {
2291 if (($line->amount) < 0) {
2292 $nature_piece = 'AC'; // Currently, only the sign of amount allows to know the type of invoice (standard or credit note). Other solution is to analyse debit/credit/role of account. TODO Add column doc_type_long or make amount mandatory with rule on sign.
2293 } else {
2294 $nature_piece = 'FC';
2295 }
2296 } else {
2297 $nature_piece = '';
2298 }
2299 $tab[] = $nature_piece;
2300 // RACI
2301 // if (!empty($line->subledger_account)) {
2302 // if ($line->doc_type == 'supplier_invoice') {
2303 // $racine_subledger_account = '40';
2304 // } elseif ($line->doc_type == 'customer_invoice') {
2305 // $racine_subledger_account = '41';
2306 // } else {
2307 // $racine_subledger_account = '';
2308 // }
2309 // } else {
2310 $racine_subledger_account = ''; // for records of type E leave this field blank
2311 // }
2312
2313 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2314 // MONT
2315 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2);
2316 // CODC
2317 $tab[] = $line->sens;
2318 // CPTG
2319 $tab[] = length_accountg($line->numero_compte);
2320 // DATE
2321 $tab[] = $date_document;
2322 // CLET
2323 $tab[] = $line->lettering_code;
2324 // DATL
2325 $tab[] = $line->date_lettering;
2326 // CPTA
2327 if (!empty($line->subledger_account)) {
2328 $tab[] = length_accounta($line->subledger_account);
2329 } else {
2330 $tab[] = "";
2331 }
2332 // C.N.A.T
2333 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2334 $tab[] = 'F';
2335 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2336 $tab[] = 'C';
2337 } else {
2338 $tab[] = "";
2339 }
2340 // CTRE
2341 $tab[] = "";
2342 // NORL
2343 $tab[] = "";
2344 // DATV
2345 $tab[] = "";
2346 // REFD
2347 $tab[] = $line->doc_ref;
2348 // NECA
2349 $tab[] = '0';
2350 // CSEC
2351 $tab[] = "";
2352 // CAFF
2353 $tab[] = "";
2354 // CDES
2355 $tab[] = "";
2356 // QTUE
2357 $tab[] = "";
2358 // MTDV
2359 $tab[] = '0';
2360 // CODV
2361 $tab[] = "";
2362 // TXDV
2363 $tab[] = '0';
2364 // MOPM
2365 $tab[] = "";
2366 // BONP
2367 $tab[] = "";
2368 // BQAF
2369 $tab[] = "";
2370 // ECES
2371 $tab[] = "";
2372 // TXTL
2373 $tab[] = "";
2374 // ECRM
2375 $tab[] = "";
2376 // DATK
2377 $tab[] = "";
2378 // HEUK
2379 $tab[] = "";
2380
2381 $output = implode($separator, $tab).$end_line;
2382 if ($exportFile) {
2383 fwrite($exportFile, $output);
2384 } else {
2385 print $output;
2386 }
2387
2388 $last_codeinvoice = $line->doc_ref;
2389 }
2390 }
2391
2399 public function exportCharlemagne($objectLines, $exportFile = null)
2400 {
2401 global $langs;
2402 $langs->load('compta');
2403
2404 $separator = "\t";
2405 $end_line = "\n";
2406
2407 $tab = array();
2408
2409 $tab[] = $langs->transnoentitiesnoconv('Date');
2410 $tab[] = self::trunc($langs->transnoentitiesnoconv('Journal'), 6);
2411 $tab[] = self::trunc($langs->transnoentitiesnoconv('Account'), 15);
2412 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60);
2413 $tab[] = self::trunc($langs->transnoentitiesnoconv('Piece'), 20);
2414 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60);
2415 $tab[] = $langs->transnoentitiesnoconv('Amount');
2416 $tab[] = 'S';
2417 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15);
2418 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60);
2419 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15);
2420 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60);
2421 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15);
2422 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60);
2423
2424 $output = implode($separator, $tab).$end_line;
2425 if ($exportFile) {
2426 fwrite($exportFile, $output);
2427 } else {
2428 print $output;
2429 }
2430
2431 foreach ($objectLines as $line) {
2432 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2433
2434 $tab = array();
2435
2436 $tab[] = $date_document; //Date
2437
2438 $tab[] = self::trunc($line->code_journal, 6); //Journal code
2439
2440 if (!empty($line->subledger_account)) {
2441 $account = $line->subledger_account;
2442 } else {
2443 $account = $line->numero_compte;
2444 }
2445 $tab[] = self::trunc((string) $account, 15); //Account number
2446
2447 $tab[] = self::trunc($line->label_compte, 60); //Account label
2448 $tab[] = self::trunc($line->doc_ref, 20); //Piece
2449 // Clean label operation to prevent problem on export with tab separator & other character
2450 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
2451 $tab[] = self::trunc($line->label_operation, 60); //Operation label
2452 $tab[] = price(abs($line->debit - $line->credit)); //Amount
2453 $tab[] = $line->sens; //Direction
2454 $tab[] = ""; //Analytic
2455 $tab[] = ""; //Analytic
2456 $tab[] = ""; //Analytic
2457 $tab[] = ""; //Analytic
2458 $tab[] = ""; //Analytic
2459 $tab[] = ""; //Analytic
2460
2461 $output = implode($separator, $tab).$end_line;
2462 if ($exportFile) {
2463 fwrite($exportFile, $output);
2464 } else {
2465 print $output;
2466 }
2467 }
2468 }
2469
2477 public function exportGestimumV3($objectLines, $exportFile = null)
2478 {
2479 global $langs;
2480
2481 $separator = ',';
2482 $end_line = "\r\n";
2483
2484 $invoices_infos = array();
2485 $supplier_invoices_infos = array();
2486 foreach ($objectLines as $line) {
2487 if ($line->debit == 0 && $line->credit == 0) {
2488 //unset($array[$line]);
2489 } else {
2490 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
2491 $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2492
2493 $invoice_ref = $line->doc_ref;
2494 $company_name = "";
2495
2496 if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
2497 if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2498 ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2499 if ($line->doc_type == 'customer_invoice') {
2500 // Get new customer invoice ref and company name
2501 $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
2502 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
2503 $sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
2504 $resql = $this->db->query($sql);
2505 if ($resql) {
2506 if ($obj = $this->db->fetch_object($resql)) {
2507 // Save invoice infos
2508 $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2509 $invoice_ref = $obj->ref;
2510 $company_name = $obj->nom;
2511 }
2512 }
2513 } else {
2514 // Get new supplier invoice ref and company name
2515 $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
2516 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
2517 $sql .= ' WHERE ff.rowid = '.((int) $line->fk_doc);
2518 $resql = $this->db->query($sql);
2519 if ($resql) {
2520 if ($obj = $this->db->fetch_object($resql)) {
2521 // Save invoice infos
2522 $supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2523 $invoice_ref = $obj->ref;
2524 $company_name = $obj->nom;
2525 }
2526 }
2527 }
2528 } elseif ($line->doc_type == 'customer_invoice') {
2529 // Retrieve invoice infos
2530 $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
2531 $company_name = $invoices_infos[$line->fk_doc]['company_name'];
2532 } else {
2533 // Retrieve invoice infos
2534 $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
2535 $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
2536 }
2537 }
2538
2539 $tab = array();
2540
2541 $tab[] = $line->id;
2542 $tab[] = $date_document;
2543 $tab[] = substr($line->code_journal, 0, 4);
2544
2545 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
2546 $tab[] = length_accountg($line->subledger_account);
2547 } else {
2548 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2549 }
2550 //Libellé Auto
2551 $tab[] = "";
2552 //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"';
2553 //Libellé manual
2554 $tab[] = dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1);
2555 //Numéro de pièce
2556 $tab[] = dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1);
2557 //Devise
2558 $tab[] = 'EUR';
2559 //Amount
2560 $tab[] = price2num(abs($line->debit - $line->credit));
2561 //Sens
2562 $tab[] = $line->sens;
2563 //Code lettrage
2564 $tab[] = "";
2565 //Date Echéance
2566 $tab[] = $date_echeance;
2567
2568 $output = implode($separator, $tab).$end_line;
2569 if ($exportFile) {
2570 fwrite($exportFile, $output);
2571 } else {
2572 print $output;
2573 }
2574 }
2575 }
2576 }
2577
2585 public function exportGestimumV5($objectLines, $exportFile = null)
2586 {
2587 $separator = ',';
2588 $end_line = "\r\n";
2589
2590 foreach ($objectLines as $line) {
2591 if ($line->debit == 0 && $line->credit == 0) {
2592 //unset($array[$line]);
2593 } else {
2594 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
2595
2596 $tab = array();
2597
2598 $tab[] = $line->id;
2599 $tab[] = $date_document;
2600 $tab[] = substr($line->code_journal, 0, 4);
2601 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
2602 $tab[] = length_accountg($line->subledger_account);
2603 } else {
2604 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2605 }
2606 $tab[] = "";
2607 $tab[] = '"'.dol_trunc(str_replace('"', '', $line->label_operation), 40, 'right', 'UTF-8', 1).'"';
2608 $tab[] = '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"';
2609 $tab[] = '"' . dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1) . '"';
2610 $tab[] = price2num(abs($line->debit - $line->credit));
2611 $tab[] = $line->sens;
2612 $tab[] = $date_document;
2613 $tab[] = "";
2614 $tab[] = "";
2615 $tab[] = 'EUR';
2616
2617 $output = implode($separator, $tab).$end_line;
2618 if ($exportFile) {
2619 fwrite($exportFile, $output);
2620 } else {
2621 print $output;
2622 }
2623 }
2624 }
2625 }
2626
2636 public function exportiSuiteExpert($objectLines, $exportFile = null)
2637 {
2638 $separator = ';';
2639 $end_line = "\r\n";
2640
2641
2642 foreach ($objectLines as $line) {
2643 $tab = array();
2644
2645 $date = dol_print_date($line->doc_date, '%d/%m/%Y');
2646
2647 $tab[] = $line->piece_num;
2648 $tab[] = $date;
2649 $tab[] = substr($date, 6, 4);
2650 $tab[] = substr($date, 3, 2);
2651 $tab[] = substr($date, 0, 2);
2652 $tab[] = $line->doc_ref;
2653 //Conversion de chaine UTF8 en Latin9
2654 $tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
2655
2656 //Calcul de la longueur des numéros de comptes
2657 $taille_numero = strlen(length_accountg($line->numero_compte));
2658
2659 //Création du numéro de client et fournisseur générique
2660 $numero_cpt_client = '411';
2661 $numero_cpt_fourn = '401';
2662 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2663 $numero_cpt_client .= '0';
2664 $numero_cpt_fourn .= '0';
2665 }
2666
2667 //Création des comptes auxiliaire des clients et fournisseur
2668 if (length_accountg($line->numero_compte) == $numero_cpt_client || length_accountg($line->numero_compte) == $numero_cpt_fourn) {
2669 $tab[] = rtrim(length_accounta($line->subledger_account), "0");
2670 } else {
2671 $tab[] = length_accountg($line->numero_compte);
2672 }
2673 $nom_client = explode(" - ", $line->label_operation);
2674 $tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
2675 $tab[] = price($line->debit);
2676 $tab[] = price($line->credit);
2677 $tab[] = price($line->montant);
2678 $tab[] = $line->code_journal;
2679
2680 $output = implode($separator, $tab).$end_line;
2681 if ($exportFile) {
2682 fwrite($exportFile, $output);
2683 } else {
2684 print $output;
2685 }
2686 }
2687 }
2688
2696 public static function trunc($str, $size)
2697 {
2698 return dol_trunc($str, $size, 'right', 'UTF-8', 1);
2699 }
2700
2708 public static function toAnsi($str, $size = -1)
2709 {
2710 $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
2711 if ($retVal >= 0 && $size >= 0) {
2712 $retVal = dol_substr($retVal, 0, $size, 'Windows-1251');
2713 }
2714 return $retVal;
2715 }
2716}
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.
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)
__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.
Definition files.lib.php:63
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_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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
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_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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79