dolibarr 25.0.0-alpha
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-2026 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-2026 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/functions2.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
44
49{
50 // Types of export.
52 public static $EXPORT_TYPE_CONFIGURABLE = 1; // CSV
54 public static $EXPORT_TYPE_AGIRIS = 10;
56 public static $EXPORT_TYPE_EBP = 15;
58 public static $EXPORT_TYPE_CEGID = 20;
60 public static $EXPORT_TYPE_COGILOG = 25;
62 public static $EXPORT_TYPE_COALA = 30;
64 public static $EXPORT_TYPE_BOB50 = 35;
66 public static $EXPORT_TYPE_CIEL = 40;
68 public static $EXPORT_TYPE_SAGE50_SWISS = 45;
70 public static $EXPORT_TYPE_CHARLEMAGNE = 50;
72 public static $EXPORT_TYPE_QUADRATUS = 60;
74 public static $EXPORT_TYPE_WINFIC = 70;
76 public static $EXPORT_TYPE_OPENCONCERTO = 100;
78 public static $EXPORT_TYPE_LDCOMPTA = 110;
80 public static $EXPORT_TYPE_LDCOMPTA10 = 120;
82 public static $EXPORT_TYPE_GESTIMUMV3 = 130;
84 public static $EXPORT_TYPE_GESTIMUMV5 = 135;
86 public static $EXPORT_TYPE_ISUITEEXPERT = 200;
88 public static $EXPORT_TYPE_ISTEA = 205;
89 // Generic FEC after that
91 public static $EXPORT_TYPE_FEC = 1000;
93 public static $EXPORT_TYPE_FEC2 = 1010;
94
98 public $db;
99
103 public $errors = array();
104
108 public $separator = '';
109
113 public $end_line = '';
114
118 public $generatedfiledata = array();
119
120
126 public function __construct(DoliDB $db)
127 {
128 global $hookmanager;
129
130 $this->db = $db;
131 $this->separator = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV');
132 $this->end_line = getDolGlobalString('ACCOUNTING_EXPORT_ENDLINE') ? (getDolGlobalInt('ACCOUNTING_EXPORT_ENDLINE') == 1 ? "\n" : "\r\n") : "\n";
133
134 $hookmanager->initHooks(array('accountancyexport'));
135 }
136
143 public function getType($mode = 0)
144 {
145 global $langs, $hookmanager;
146
147 $listofspecialformatexport = array(
148 self::$EXPORT_TYPE_CEGID => $langs->trans('Modelcsv_CEGID'),
149 self::$EXPORT_TYPE_COALA => $langs->trans('Modelcsv_COALA'),
150 self::$EXPORT_TYPE_BOB50 => $langs->trans('Modelcsv_bob50'),
151 self::$EXPORT_TYPE_CIEL => $langs->trans('Modelcsv_ciel'),
152 self::$EXPORT_TYPE_QUADRATUS => $langs->trans('Modelcsv_quadratus'),
153 self::$EXPORT_TYPE_WINFIC => $langs->trans('Modelcsv_winfic'),
154 self::$EXPORT_TYPE_EBP => $langs->trans('Modelcsv_ebp'),
155 self::$EXPORT_TYPE_COGILOG => $langs->trans('Modelcsv_cogilog'),
156 self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'),
157 self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans('Modelcsv_openconcerto'),
158 self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans('Modelcsv_Sage50_Swiss'),
159 self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans('Modelcsv_charlemagne'),
160 self::$EXPORT_TYPE_LDCOMPTA => $langs->trans('Modelcsv_LDCompta'),
161 self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans('Modelcsv_LDCompta10'),
162 self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans('Modelcsv_Gestinumv3'),
163 self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans('Modelcsv_Gestinumv5'),
164 self::$EXPORT_TYPE_ISUITEEXPERT => 'Export iSuite Expert',
165 self::$EXPORT_TYPE_ISTEA => $langs->trans('Modelcsv_ISTEA'),
166 );
167
168 $listofgenericformatexport = array(
169 self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans('Modelcsv_configurable'),
170 self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'),
171 self::$EXPORT_TYPE_FEC2 => $langs->trans('Modelcsv_FEC2'),
172 );
173
174 if (empty($mode)) {
175 $listofexporttypes = $listofgenericformatexport + $listofspecialformatexport;
176 ksort($listofexporttypes, SORT_NUMERIC);
177 } else {
178 ksort($listofspecialformatexport, SORT_NUMERIC);
179 $listofexporttypes = array();
180 $i = 0;
181 foreach ($listofgenericformatexport as $key => $val) {
182 $i++;
183 $listofexporttypes[$key] = array('id' => $key, 'label' => $val, 'position' => $i);
184 }
185 $listofexporttypes['separator_'.$i] = array('id' => 0, 'label' => '----------------', 'position' => $i, 'disabled' => 'disabled');
186 foreach ($listofspecialformatexport as $key => $val) {
187 $i++;
188 $listofexporttypes[$key] = array('id' => $key, 'label' => $val, 'position' => $i);
189 }
190 }
191
192 // allow modules to define export formats
193 $parameters = array();
194 $reshook = $hookmanager->executeHooks('getType', $parameters, $listofexporttypes);
195
196 return $listofexporttypes;
197 }
198
205 public static function getFormatCode($type)
206 {
207 $formatcode = array(
208 self::$EXPORT_TYPE_CONFIGURABLE => 'csv',
209 self::$EXPORT_TYPE_CEGID => 'cegid',
210 self::$EXPORT_TYPE_COALA => 'coala',
211 self::$EXPORT_TYPE_BOB50 => 'bob50',
212 self::$EXPORT_TYPE_CIEL => 'ciel',
213 self::$EXPORT_TYPE_QUADRATUS => 'quadratus',
214 self::$EXPORT_TYPE_WINFIC => 'winfic',
215 self::$EXPORT_TYPE_EBP => 'ebp',
216 self::$EXPORT_TYPE_COGILOG => 'cogilog',
217 self::$EXPORT_TYPE_AGIRIS => 'agiris',
218 self::$EXPORT_TYPE_OPENCONCERTO => 'openconcerto',
219 self::$EXPORT_TYPE_SAGE50_SWISS => 'sage50ch',
220 self::$EXPORT_TYPE_CHARLEMAGNE => 'charlemagne',
221 self::$EXPORT_TYPE_LDCOMPTA => 'ldcompta',
222 self::$EXPORT_TYPE_LDCOMPTA10 => 'ldcompta10',
223 self::$EXPORT_TYPE_GESTIMUMV3 => 'gestimumv3',
224 self::$EXPORT_TYPE_GESTIMUMV5 => 'gestimumv5',
225 self::$EXPORT_TYPE_FEC => 'fec',
226 self::$EXPORT_TYPE_FEC2 => 'fec2',
227 self::$EXPORT_TYPE_ISUITEEXPERT => 'isuiteexpert',
228 self::$EXPORT_TYPE_ISTEA => 'istea',
229 );
230
231 global $hookmanager;
232 $code = $formatcode[$type] ?? '';
233 $parameters = array('type' => $type);
234 $reshook = $hookmanager->executeHooks('getFormatCode', $parameters, $code);
235
236 return $code;
237 }
238
244 public function getTypeConfig()
245 {
246 global $langs;
247
248 $exporttypes = array(
249 'param' => array(
250 self::$EXPORT_TYPE_CONFIGURABLE => array(
251 'label' => $langs->trans('Modelcsv_configurable'),
252 'ACCOUNTING_EXPORT_FORMAT' => getDolGlobalString('ACCOUNTING_EXPORT_FORMAT', 'txt'),
253 'ACCOUNTING_EXPORT_SEPARATORCSV' => getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV', ','),
254 'ACCOUNTING_EXPORT_ENDLINE' => getDolGlobalString('ACCOUNTING_EXPORT_ENDLINE', 1),
255 'ACCOUNTING_EXPORT_DATE' => getDolGlobalString('ACCOUNTING_EXPORT_DATE', '%Y-%m-%d'),
256 ),
257 self::$EXPORT_TYPE_CEGID => array(
258 'label' => $langs->trans('Modelcsv_CEGID'),
259 ),
260 self::$EXPORT_TYPE_COALA => array(
261 'label' => $langs->trans('Modelcsv_COALA'),
262 ),
263 self::$EXPORT_TYPE_BOB50 => array(
264 'label' => $langs->trans('Modelcsv_bob50'),
265 ),
266 self::$EXPORT_TYPE_CIEL => array(
267 'label' => $langs->trans('Modelcsv_ciel'),
268 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
269 ),
270 self::$EXPORT_TYPE_QUADRATUS => array(
271 'label' => $langs->trans('Modelcsv_quadratus'),
272 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
273 ),
274 self::$EXPORT_TYPE_WINFIC => array(
275 'label' => $langs->trans('Modelcsv_winfic'),
276 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
277 ),
278 self::$EXPORT_TYPE_EBP => array(
279 'label' => $langs->trans('Modelcsv_ebp'),
280 ),
281 self::$EXPORT_TYPE_COGILOG => array(
282 'label' => $langs->trans('Modelcsv_cogilog'),
283 ),
284 self::$EXPORT_TYPE_AGIRIS => array(
285 'label' => $langs->trans('Modelcsv_agiris'),
286 ),
287 self::$EXPORT_TYPE_OPENCONCERTO => array(
288 'label' => $langs->trans('Modelcsv_openconcerto'),
289 ),
290 self::$EXPORT_TYPE_SAGE50_SWISS => array(
291 'label' => $langs->trans('Modelcsv_Sage50_Swiss'),
292 ),
293 self::$EXPORT_TYPE_CHARLEMAGNE => array(
294 'label' => $langs->trans('Modelcsv_charlemagne'),
295 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
296 ),
297 self::$EXPORT_TYPE_LDCOMPTA => array(
298 'label' => $langs->trans('Modelcsv_LDCompta'),
299 ),
300 self::$EXPORT_TYPE_LDCOMPTA10 => array(
301 'label' => $langs->trans('Modelcsv_LDCompta10'),
302 ),
303 self::$EXPORT_TYPE_GESTIMUMV3 => array(
304 'label' => $langs->trans('Modelcsv_Gestinumv3'),
305 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
306 ),
307 self::$EXPORT_TYPE_GESTIMUMV5 => array(
308 'label' => $langs->trans('Modelcsv_Gestinumv5'),
309 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
310 ),
311 self::$EXPORT_TYPE_FEC => array(
312 'label' => $langs->trans('Modelcsv_FEC'),
313 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
314 ),
315 self::$EXPORT_TYPE_FEC2 => array(
316 'label' => $langs->trans('Modelcsv_FEC2'),
317 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
318 ),
319 self::$EXPORT_TYPE_ISUITEEXPERT => array(
320 'label' => 'iSuite Expert',
321 'ACCOUNTING_EXPORT_FORMAT' => 'csv',
322 ),
323 self::$EXPORT_TYPE_ISTEA => array(
324 'label' => 'ISTEA',
325 'ACCOUNTING_EXPORT_FORMAT' => 'csv',
326 ),
327 ),
328 'cr' => array(
329 '1' => $langs->trans("Unix"),
330 '2' => $langs->trans("Windows")
331 ),
332 'format' => array(
333 'csv' => $langs->trans("csv"),
334 'txt' => $langs->trans("txt")
335 ),
336 );
337
338 global $hookmanager;
339 $parameters = array();
340 $reshook = $hookmanager->executeHooks('getTypeConfig', $parameters, $exporttypes);
341 return $exporttypes;
342 }
343
344
351 public function getMimeType($formatexportset)
352 {
353 switch ($formatexportset) {
354 case self::$EXPORT_TYPE_FEC:
355 $mime = 'text/tab-separated-values';
356 break;
357 default:
358 $mime = 'text/csv';
359 break;
360 }
361
362 return $mime;
363 }
364
382 public function export(&$TData, $formatexportset, $withAttachment = 0, $downloadMode = 1, $outputMode = 1, $noouput = 1)
383 {
384 global $db, $conf, $langs; // Used into /accountancy/tpl/export_journal.tpl.php
385 global $search_date_end, $hookmanager; // Used into /accountancy/tpl/export_journal.tpl.php
386
387 // Define name of file to save
388 $formatcode = $this->getFormatCode($formatexportset);
389 $filename = 'general_ledger-'.(!empty($formatcode) ? $formatcode : $formatexportset); // Used into /accountancy/tpl/export_journal.tpl.php
390 $type_export = 'general_ledger'; // Used into /accountancy/tpl/export_journal.tpl.php
391
392 $completefilename = '';
393 $exportFile = null;
394 $exportFileName = '';
395 $exportFilePath = '';
396 $exportFileFullName = '';
397 $downloadFileMimeType = '';
398 $downloadFileFullName = '';
399 $downloadFilePath = '';
400 $archiveFullName = '';
401 $archivePath = '';
403 $archiveFileList = array();
404 if ($withAttachment == 1) {
405 if ($downloadMode == 0) {
406 $downloadMode = 1; // force to download after writing all files (can't use direct download)
407 }
408 if ($outputMode == 0) {
409 $outputMode = 1; // force to put files in a temp directory (can't use print on screen)
410 }
411
412 // PHP ZIP extension must be enabled
413 if (!extension_loaded('zip')) {
414 $langs->load('install');
415 $this->errors[] = $langs->trans('ErrorPHPDoesNotSupport', 'ZIP');
416 return -1;
417 }
418 }
419
420 $mimetype = $this->getMimeType($formatexportset);
421 if ($downloadMode == 0) {
422 // begin to print header for direct download
423 top_httphead($mimetype, 1);
424 }
425
426 // Set var $completefilename and add HTTP header.
427 include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php'; // TODO Fix this: A tpl is for rendering data on output. For including common code, we must use .inc.php
428
429 if ($outputMode == 1 || $outputMode == 2) {
430 if ($outputMode == 1) {
431 // uses the temp directory by default to write files
432 if (!empty($conf->accounting->multidir_temp[$conf->entity])) {
433 $outputDir = $conf->accounting->multidir_temp[$conf->entity];
434 } else {
435 $outputDir = $conf->accounting->dir_temp;
436 }
437 } else {
438 // uses the default export directory "accounting/export"
439 if (!empty($conf->accounting->multidir_output[$conf->entity])) {
440 $outputDir = $conf->accounting->multidir_output[$conf->entity];
441 } else {
442 $outputDir = $conf->accounting->dir_output;
443 }
444
445 // directory already created when module is enabled
446 $outputDir .= '/export';
447 $outputDir .= '/'.dol_sanitizePathName((string) $formatexportset);
448 }
449
450 if (!dol_is_dir($outputDir)) {
451 if (dol_mkdir($outputDir) < 0) {
452 $this->errors[] = $langs->trans('ErrorCanNotCreateDir', $outputDir);
453 return -1;
454 }
455 }
456
457 if ($outputDir != '') {
458 if (!dol_is_dir($outputDir)) {
459 $langs->load('errors');
460 $this->errors[] = $langs->trans('ErrorDirNotFound', $outputDir);
461 return -1;
462 }
463
464 // Fallback if template did not set $completefilename
465 if (empty($completefilename)) {
466 $completefilename = dol_sanitizeFileName($filename).'_'.dol_print_date(dol_now(), '%Y%m%d%H%M%S').'.txt';
467 }
468
469 // create export file
470 $exportFileFullName = $completefilename;
471 $exportFileBaseName = basename($exportFileFullName);
472 $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME);
473 $exportFilePath = $outputDir . '/' . $exportFileFullName;
474 $exportFile = fopen($exportFilePath, 'w');
475 if (!$exportFile) {
476 $this->errors[] = $langs->trans('ErrorFileNotFound', $exportFilePath);
477 return -1;
478 }
479
480 if ($withAttachment == 1) {
481 $archiveFileList['0'] = array(
482 'path' => $exportFilePath,
483 'name' => $exportFileFullName,
484 );
485
486 // archive name and path
487 $archiveFullName = $exportFileName . '.zip';
488 $archivePath = $outputDir . '/' . $archiveFullName;
489 }
490 }
491 }
492
493 // export file (print on screen or write in a file) and prepare archive list if with attachment is set to 1
494 switch ($formatexportset) {
495 case self::$EXPORT_TYPE_CONFIGURABLE:
496 $this->exportConfigurable($TData, $exportFile);
497 break;
498 case self::$EXPORT_TYPE_CEGID:
499 $this->exportCegid($TData, $exportFile);
500 break;
501 case self::$EXPORT_TYPE_COALA:
502 $this->exportCoala($TData, $exportFile);
503 break;
504 case self::$EXPORT_TYPE_BOB50:
505 $this->exportBob50($TData, $exportFile);
506 break;
507 case self::$EXPORT_TYPE_CIEL:
508 $this->exportCiel($TData, $exportFile);
509 break;
510 case self::$EXPORT_TYPE_QUADRATUS:
511 $archiveFileList = $this->exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment);
512 break;
513 case self::$EXPORT_TYPE_WINFIC:
514 $this->exportWinfic($TData, $exportFile);
515 break;
516 case self::$EXPORT_TYPE_EBP:
517 $this->exportEbp($TData, $exportFile);
518 break;
519 case self::$EXPORT_TYPE_COGILOG:
520 $this->exportCogilog($TData, $exportFile);
521 break;
522 case self::$EXPORT_TYPE_AGIRIS:
523 $this->exportAgiris($TData, $exportFile);
524 break;
525 case self::$EXPORT_TYPE_OPENCONCERTO:
526 $this->exportOpenConcerto($TData, $exportFile);
527 break;
528 case self::$EXPORT_TYPE_SAGE50_SWISS:
529 $this->exportSAGE50SWISS($TData, $exportFile);
530 break;
531 case self::$EXPORT_TYPE_CHARLEMAGNE:
532 $this->exportCharlemagne($TData, $exportFile);
533 break;
534 case self::$EXPORT_TYPE_LDCOMPTA:
535 $this->exportLDCompta($TData, $exportFile);
536 break;
537 case self::$EXPORT_TYPE_LDCOMPTA10:
538 $this->exportLDCompta10($TData, $exportFile);
539 break;
540 case self::$EXPORT_TYPE_GESTIMUMV3:
541 $this->exportGestimumV3($TData, $exportFile);
542 break;
543 case self::$EXPORT_TYPE_GESTIMUMV5:
544 $this->exportGestimumV5($TData, $exportFile);
545 break;
546 case self::$EXPORT_TYPE_FEC:
547 $archiveFileList = $this->exportFEC($TData, $exportFile, $archiveFileList, $withAttachment);
548 break;
549 case self::$EXPORT_TYPE_FEC2:
550 $archiveFileList = $this->exportFEC2($TData, $exportFile, $archiveFileList, $withAttachment);
551 break;
552 case self::$EXPORT_TYPE_ISUITEEXPERT:
553 $this->exportiSuiteExpert($TData, $exportFile);
554 break;
555 case self::$EXPORT_TYPE_ISTEA:
556 $this->exportISTEA($TData, $exportFile);
557 break;
558 default:
559 global $hookmanager;
560 $parameters = array(
561 'format' => $formatexportset,
562 'file' => $exportFile,
563 'filepath' => $exportFilePath,
564 'filefullname' => $exportFileFullName,
565 );
566 // file contents will be created in the hooked function via print and name will be returned.
567 $reshook = $hookmanager->executeHooks('export', $parameters, $TData);
568 if ($reshook != 1) {
569 $this->errors[] = $langs->trans('accountancy_error_modelnotfound');
570 } elseif (!empty($hookmanager->resArray['downloadFileFullName']) && !empty($hookmanager->resArray['downloadFilePath'])) {
571 $exportFileFullName = $hookmanager->resArray['downloadFileFullName'];
572 $exportFilePath = $hookmanager->resArray['downloadFilePath'];
573 }
574 break;
575 }
576
577
578 // Create and download export file or archive
579 if ($outputMode == 1 || $outputMode == 2) {
580 $error = 0;
581
582 // close export file
583 if ($exportFile) {
584 fclose($exportFile);
585 }
586
587 if ($withAttachment == 1) {
588 // create archive file
589 if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
590 // archive files
591 $downloadFileMimeType = 'application/zip';
592 $downloadFileFullName = $archiveFullName;
593 $downloadFilePath = $archivePath;
594
595 // create archive
596 $archive = new ZipArchive();
597 $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
598 if ($res !== true) {
599 $error++;
600 $this->errors[] = $langs->trans('ErrorFileNotFound', $archivePath);
601 }
602 if (!$error) {
603 // add files
604 foreach ($archiveFileList as $archiveFileArr) {
605 $res = $archive->addFile($archiveFileArr['path'], $archiveFileArr['name']);
606 if (!$res) {
607 $error++;
608 $this->errors[] = $langs->trans('ErrorArchiveAddFile', $archiveFileArr['name']);
609 break;
610 }
611 }
612 }
613 if (!$error) {
614 // close archive
615 $archive->close();
616 }
617 }
618 }
619
620 if (!$error) {
621 // download after writing files
622 if ($downloadMode == 1) {
623 if ($withAttachment == 0) {
624 // only download exported file
625 if (!empty($exportFileFullName) && !empty($exportFilePath)) {
626 $downloadFileMimeType = $mimetype;
627 $downloadFileFullName = $exportFileFullName;
628 $downloadFilePath = $exportFilePath;
629 }
630 }
631
632 // download export file or archive
633 if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath) && empty($noouput)) {
634 // deprecated. We must not use this anymore, but have $noouput = 1 because HTTP header must be sent
635 // into main page not into a method.
636 header('Content-Type: ' . $downloadFileMimeType);
637 header('Content-Disposition: attachment; filename=' . $downloadFileFullName);
638 header('Cache-Control: Public, must-revalidate');
639 header('Pragma: public');
640 header('Content-Length: ' . dol_filesize($downloadFilePath));
641
642 readfileLowMemory($downloadFilePath);
643 }
644
645 $this->generatedfiledata = array('downloadFilePath' => $downloadFilePath, 'downloadFileMimeType' => $downloadFileMimeType, 'downloadFileFullName' => $downloadFileFullName);
646 }
647 }
648
649 if ($error) {
650 return -1;
651 }
652 }
653
654 return 1;
655 }
656
657
665 public function exportCegid($objectLines, $exportFile = null)
666 {
667 $separator = ";";
668 $end_line = "\n";
669
670 foreach ($objectLines as $line) {
671 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
672
673 $tab = array();
674
675 $tab[] = $date_document;
676 $tab[] = $line->code_journal;
677 $tab[] = length_accountg($line->numero_compte);
678 $tab[] = length_accounta($line->subledger_account);
679 $tab[] = $line->sens;
680 $tab[] = price2fec(abs($line->debit - $line->credit));
681 $tab[] = dol_string_unaccent($line->label_operation);
682 $tab[] = dol_string_unaccent($line->doc_ref);
683
684 $output = implode($separator, $tab).$end_line;
685 if ($exportFile) {
686 fwrite($exportFile, $output);
687 } else {
688 print $output;
689 }
690 }
691 }
692
701 public function exportCogilog($objectLines, $exportFile = null)
702 {
703 $separator = "\t";
704 $end_line = "\n";
705
706 foreach ($objectLines as $line) {
707 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
708
709 $refInvoice = '';
710 if ($line->doc_type == 'customer_invoice') {
711 // Customer invoice
712 require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
713 $invoice = new Facture($this->db);
714 $invoice->fetch($line->fk_doc);
715
716 $refInvoice = $invoice->ref;
717 } elseif ($line->doc_type == 'supplier_invoice') {
718 // Supplier invoice
719 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
720 $invoice = new FactureFournisseur($this->db);
721 $invoice->fetch($line->fk_doc);
722
723 $refInvoice = $invoice->ref_supplier;
724 }
725
726 $tab = array();
727
728 $tab[] = $line->code_journal;
729 $tab[] = $date_document;
730 $tab[] = $refInvoice;
731 if (empty($line->subledger_account)) {
732 $tab[] = length_accountg($line->numero_compte);
733 } else {
734 $tab[] = length_accounta($line->subledger_account);
735 }
736 $tab[] = "";
737 $tab[] = $line->label_operation;
738 $tab[] = $date_document;
739 if ($line->sens == 'D') {
740 $tab[] = price($line->debit);
741 $tab[] = "";
742 } elseif ($line->sens == 'C') {
743 $tab[] = "";
744 $tab[] = price($line->credit);
745 }
746 $tab[] = $line->doc_ref;
747 $tab[] = $line->label_operation;
748
749 $output = implode($separator, $tab).$end_line;
750 if ($exportFile) {
751 fwrite($exportFile, $output);
752 } else {
753 print $output;
754 }
755 }
756 }
757
765 public function exportCoala($objectLines, $exportFile = null)
766 {
767 // Coala export
768 $separator = ";";
769 $end_line = "\n";
770
771 foreach ($objectLines as $line) {
772 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
773
774 $tab = array();
775
776 $tab[] = $date_document;
777 $tab[] = $line->code_journal;
778 $tab[] = length_accountg($line->numero_compte);
779 $tab[] = $line->piece_num;
780 $tab[] = $line->doc_ref;
781 $tab[] = price($line->debit);
782 $tab[] = price($line->credit);
783 $tab[] = 'E';
784 $tab[] = length_accounta($line->subledger_account);
785
786 $output = implode($separator, $tab).$end_line;
787 if ($exportFile) {
788 fwrite($exportFile, $output);
789 } else {
790 print $output;
791 }
792 }
793 }
794
802 public function exportBob50($objectLines, $exportFile = null)
803 {
804 // Bob50
805 $separator = ";";
806 $end_line = "\n";
807
808 foreach ($objectLines as $line) {
809 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
810
811 $tab = array();
812
813 $tab[] = $line->piece_num;
814 $tab[] = $date_document;
815
816 if (empty($line->subledger_account)) {
817 $tab[] = 'G';
818 $tab[] = length_accountg($line->numero_compte);
819 } else {
820 if (substr($line->numero_compte, 0, 3) == '411') {
821 $tab[] = 'C';
822 }
823 if (substr($line->numero_compte, 0, 3) == '401') {
824 $tab[] = 'F';
825 }
826 $tab[] = length_accounta($line->subledger_account);
827 }
828
829 $tab[] = price($line->debit);
830 $tab[] = price($line->credit);
831 $tab[] = dol_trunc($line->label_operation, 32);
832
833 $output = implode($separator, $tab).$end_line;
834 if ($exportFile) {
835 fwrite($exportFile, $output);
836 } else {
837 print $output;
838 }
839 }
840 }
841
857 public function exportCiel($objectLines, $exportFile = null)
858 {
859 $end_line = "\r\n";
860
861 $i = 1;
862
863 foreach ($objectLines as $line) {
864 $code_compta = length_accountg($line->numero_compte);
865 if (!empty($line->subledger_account)) {
866 $code_compta = length_accounta($line->subledger_account);
867 }
868
869 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
870 $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d');
871
872 $tab = array();
873
874 $tab[] = str_pad((string) $line->piece_num, 5);
875 $tab[] = str_pad(self::trunc($line->code_journal, 2), 2);
876 $tab[] = str_pad($date_document, 8, ' ', STR_PAD_LEFT);
877 $tab[] = str_pad($date_echeance, 8, ' ', STR_PAD_LEFT);
878 $tab[] = str_pad(self::trunc($line->doc_ref, 12), 12);
879 $tab[] = str_pad(self::trunc($code_compta, 11), 11);
880 $tab[] = str_pad(self::trunc(dol_string_unaccent($line->doc_ref).dol_string_unaccent($line->label_operation), 25), 25);
881 $tab[] = str_pad(price2fec(abs($line->debit - $line->credit)), 13, ' ', STR_PAD_LEFT);
882 $tab[] = str_pad($line->sens, 1);
883 $tab[] = str_repeat(' ', 18); // Analytical accounting - Not managed in Dolibarr
884 $tab[] = str_pad(self::trunc(dol_string_unaccent($line->label_operation), 34), 34);
885 $tab[] = 'O2003'; // 0 = EUR | 2003 = Format Ciel
886
887 $output = implode($tab).$end_line;
888 if ($exportFile) {
889 fwrite($exportFile, $output);
890 } else {
891 print $output;
892 }
893 $i++;
894 }
895 }
896
912 public function exportQuadratus($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
913 {
914 global $conf;
915
916 $end_line = "\r\n";
917
918 $conf->cache['archiveFileList_notfound'] = array();
919
920 // We should use dol_now function not time however this is wrong date to transfer in accounting
921 $i = 0;
922 foreach ($objectLines as $line) {
923 $i++;
924
925 // Clean some data
926 $line->doc_ref = dol_string_unaccent($line->doc_ref);
927
928 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
929 $line->label_operation = str_replace(array("- ", "…", "..."), "", $line->label_operation);
930 $line->label_operation = dol_string_unaccent($line->label_operation);
931
932 $line->numero_compte = dol_string_unaccent($line->numero_compte);
933 $line->label_compte = dol_string_unaccent($line->label_compte);
934 $line->subledger_account = dol_string_unaccent($line->subledger_account);
935
936 $line->subledger_label = str_replace(array("- ", "…", "..."), "", $line->subledger_label);
937 $line->subledger_label = dol_string_unaccent($line->subledger_label);
938
939 $code_compta = $line->numero_compte;
940 if (!empty($line->subledger_account)) {
941 $code_compta = $line->subledger_account;
942 }
943
944 $tab = array();
945
946 if (!empty($line->subledger_account)) {
947 $tab['type_ligne'] = 'C';
948 $tab['num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8);
949 $tab['lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30);
950
951 if ($line->doc_type == 'customer_invoice') {
952 $tab['lib_alpha'] = strtoupper(self::trunc(dol_string_unaccent($line->subledger_label), 7));
953 $tab['filler'] = str_repeat(' ', 52);
954 $tab['coll_compte'] = str_pad(self::trunc(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), 8), 8);
955 } elseif ($line->doc_type == 'supplier_invoice') {
956 $tab['lib_alpha'] = strtoupper(self::trunc(dol_string_unaccent($line->subledger_label), 7));
957 $tab['filler'] = str_repeat(' ', 52);
958 $tab['coll_compte'] = str_pad(self::trunc(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), 8), 8);
959 } else {
960 $tab['filler'] = str_repeat(' ', 59);
961 $tab['coll_compte'] = str_pad(' ', 8);
962 }
963
964 $tab['filler2'] = str_repeat(' ', 110);
965
966 // Field "Maj" (static position 1 char):
967 // blank = no update if account already exists
968 // 2 = partial update (alpha key, label, address, collectif, RIB)
969 if (getDolGlobalString('ACCOUNTING_EXPORT_QUADRATUS_DISABLE_THIRDPARTY_UPDATE')) {
970 $tab['Maj'] = ' ';
971 } else {
972 $tab['Maj'] = 2;
973 }
974
975 if ($line->doc_type == 'customer_invoice') {
976 $tab['type_compte'] = 'C';
977 } elseif ($line->doc_type == 'supplier_invoice') {
978 $tab['type_compte'] = 'F';
979 } else {
980 $tab['type_compte'] = 'G';
981 }
982
983 $tab['filler3'] = str_repeat(' ', 235);
984
985 $tab['end_line'] = $end_line;
986
987 if ($exportFile) {
988 fwrite($exportFile, implode($tab));
989 } else {
990 print implode($tab);
991 }
992 }
993
994 $tab = array();
995 $tab['type_ligne'] = 'M';
996 $tab['num_compte'] = str_pad(self::trunc((string) $code_compta, 8), 8);
997 $tab['code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
998 $tab['folio'] = '000';
999
1000 // We use invoice date $line->doc_date not $date_ecriture which is the transfer date
1001 // maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
1002 //$tab['date_ecriture'] = $date_ecriture;
1003 $tab['date_ecriture'] = dol_print_date($line->doc_date, '%d%m%y');
1004 $tab['filler'] = ' ';
1005 $tab['libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.' '.$line->label_operation, 20), 20);
1006
1007 // Credit invoice - invert sens
1008 /*
1009 if ($line->montant < 0) {
1010 if ($line->sens == 'C') {
1011 $tab['sens'] = 'D';
1012 } else {
1013 $tab['sens'] = 'C';
1014 }
1015 $tab['signe_montant'] = '-';
1016 } else {
1017 $tab['sens'] = $line->sens; // C or D
1018 $tab['signe_montant'] = '+';
1019 }*/
1020 $tab['sens'] = $line->sens; // C or D
1021 $tab['signe_montant'] = '+';
1022
1023 // The amount must be in centimes without decimal points.
1024 $tab['montant'] = str_pad((string) abs(($line->debit - $line->credit) * 100), 12, '0', STR_PAD_LEFT);
1025 $tab['contrepartie'] = str_repeat(' ', 8);
1026
1027 // Force date format : %d%m%y
1028 if (!empty($line->date_lim_reglement)) {
1029 $tab['date_echeance'] = dol_print_date($line->date_lim_reglement, '%d%m%y'); // Format must be ddmmyy
1030 } else {
1031 $tab['date_echeance'] = '000000';
1032 }
1033
1034 // Please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
1035 // $tab['lettrage'] = str_repeat(' ', 5);
1036 $tab['lettrage'] = str_repeat(' ', 2);
1037 $tab['codestat'] = str_repeat(' ', 3);
1038 $tab['num_piece'] = str_pad(self::trunc((string) $line->piece_num, 5), 5);
1039
1040 // Keep correct quadra named field instead of anon filler
1041 // $tab['filler2'] = str_repeat(' ', 20);
1042 $tab['affaire'] = str_repeat(' ', 10);
1043 $tab['quantity1'] = str_repeat(' ', 10);
1044 $tab['num_piece2'] = str_pad(self::trunc((string) $line->piece_num, 8), 8);
1045 $tab['devis'] = str_pad(getDolCurrency(), 3);
1046 $tab['code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
1047 $tab['filler3'] = str_repeat(' ', 3);
1048
1049 // Keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
1050 // 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
1051 // TODO: we should filter more than only accent to avoid wrong line size
1052 // TODO: remove invoice number doc_ref in label,
1053 // TODO: we should offer an option for customer to build the label using invoice number / name / date in accounting software
1054 //$tab['libelle_ecriture2'] = str_pad(self::trunc($line->doc_ref . ' ' . $line->label_operation, 30), 30);
1055 $tab['libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
1056 $tab['codetva'] = str_repeat(' ', 2);
1057
1058 // We need to keep the 10 latest number of invoices doc_ref not the beginning part that is the useless almost same part
1059 // $tab['num_piece3'] = str_pad(self::trunc($line->piece_num, 10), 10);
1060 $tab['num_piece3'] = str_pad(substr(self::trunc($line->doc_ref, 20), -10), 10);
1061 $tab['reserved'] = str_repeat(' ', 10); // position 159
1062 $tab['currency_amount'] = str_repeat(' ', 13); // position 169
1063
1064 // get document file
1065 $attachmentFileName = '';
1066 if ($withAttachment == 1) {
1067 $attachmentFileKey = trim((string) $line->piece_num);
1068
1069 if (!isset($archiveFileList[$attachmentFileKey])) {
1070 // We complete the $archiveFileList to add the file to the existing list (first entry was filled when function was called, we add here the next one)
1071 $objectDirPath = '';
1072 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1073 if ($line->doc_type == 'customer_invoice') {
1074 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1075 } elseif ($line->doc_type == 'expense_report') {
1076 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1077 } elseif ($line->doc_type == 'supplier_invoice') {
1078 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1079 $invoice = new FactureFournisseur($this->db);
1080 $invoice->fetch($line->fk_doc);
1081 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1082 $objectDirPath .= '/'.rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1083 }
1084
1085 if ($objectDirPath && empty($conf->cache['archiveFileList_notfound'][$attachmentFileKey])) {
1086 $arrayofinclusion = array();
1087 // If it is a supplier invoice, we want to use last uploaded file
1088 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1089
1090 $fileFoundPath = '';
1091 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1092
1093 if (!empty($fileFoundList)) {
1094 $attachmentFileNameTrunc = str_pad(self::trunc((string) $line->piece_num, 8), 8, '0', STR_PAD_LEFT);
1095
1096 foreach ($fileFoundList as $fileFound) {
1097 if (strstr($fileFound['name'], $objectFileName)) {
1098 // skip native invoice pdfs (canelle)
1099 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1100 if ($line->doc_type == 'supplier_invoice') {
1101 if ($fileFound['name'] === $objectFileName.'.pdf') {
1102 continue;
1103 }
1104 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1105 continue;
1106 }
1107 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1108 if (file_exists($fileFoundPath)) {
1109 $archiveFileList[$attachmentFileKey] = array(
1110 'path' => $fileFoundPath,
1111 'name' => $attachmentFileNameTrunc.'.pdf',
1112 );
1113 break;
1114 }
1115 }
1116 }
1117 }
1118
1119 if (empty($fileFoundPath)) {
1120 // Use also a cache if no file were found
1121 $conf->cache['archiveFileList_notfound'][$attachmentFileKey] = 1;
1122 }
1123 }
1124 }
1125
1126 if (isset($archiveFileList[$attachmentFileKey])) {
1127 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1128 }
1129 }
1130
1131 if (dol_strlen((string) $attachmentFileName) == 12) {
1132 $tab['attachment'] = $attachmentFileName; // position 182
1133 } else {
1134 $tab['attachment'] = str_repeat(' ', 12); // position 182
1135 }
1136 $tab['filler4'] = str_repeat(' ', 38);
1137 $tab['end_line'] = $end_line;
1138
1139 if ($exportFile) {
1140 fwrite($exportFile, implode($tab));
1141 } else {
1142 print implode($tab);
1143 }
1144 }
1145
1146 return $archiveFileList;
1147 }
1148
1159 public function exportWinfic($objectLines, $exportFile = null)
1160 {
1161 global $conf;
1162
1163 $end_line = "\r\n";
1164 $index = 1;
1165
1166 // Warning ! When truncation is necessary, no dot because 3 dots = three characters. The columns are shifted
1167
1168 foreach ($objectLines as $line) {
1169 $code_compta = $line->numero_compte;
1170 if (!empty($line->subledger_account)) {
1171 $code_compta = $line->subledger_account;
1172 }
1173
1174 $tab = array();
1175 //$tab['type_ligne'] = 'M';
1176 $tab['code_journal'] = str_pad(dol_trunc($line->code_journal, 2, 'right', 'UTF-8', 1), 2);
1177
1178 //We use invoice date $line->doc_date not $date_ecriture which is the transfer date
1179 //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
1180 //$tab['date_ecriture'] = $date_ecriture;
1181 $tab['date_operation'] = dol_print_date($line->doc_date, '%d%m%Y');
1182
1183 $tab['folio'] = ' 1';
1184
1185 $tab['num_ecriture'] = str_pad(dol_trunc((string) $index, 6, 'right', 'UTF-8', 1), 6, ' ', STR_PAD_LEFT);
1186
1187 $tab['jour_ecriture'] = dol_print_date($line->doc_date, '%d%m%y');
1188
1189 $tab['num_compte'] = str_pad(dol_trunc((string) $code_compta, 6, 'right', 'UTF-8', 1), 6, '0');
1190
1191 if ($line->sens == 'D') {
1192 $tab['montant_debit'] = str_pad(number_format($line->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1193
1194 $tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1195 } else {
1196 $tab['montant_debit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1197
1198 $tab['montant_crebit'] = str_pad(number_format($line->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1199 }
1200
1201 $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);
1202
1203 $tab['lettrage'] = str_repeat(dol_trunc((string) $line->lettering_code, 2, 'left', 'UTF-8', 1), 2);
1204
1205 $tab['code_piece'] = str_pad(dol_trunc((string) $line->piece_num, 5, 'left', 'UTF-8', 1), 5, ' ', STR_PAD_LEFT);
1206
1207 $tab['code_stat'] = str_repeat(' ', 4);
1208
1209 if (!empty($line->date_lim_reglement)) {
1210 $tab['date_echeance'] = dol_print_date($line->date_lim_reglement, '%d%m%Y');
1211 } else {
1212 $tab['date_echeance'] = dol_print_date($line->doc_date, '%d%m%Y');
1213 }
1214
1215 $tab['monnaie'] = '1';
1216
1217 $tab['filler'] = ' ';
1218
1219 $tab['ind_compteur'] = ' ';
1220
1221 $tab['quantite'] = '0,000000000';
1222
1223 $tab['code_pointage'] = str_repeat(' ', 2);
1224
1225 $tab['end_line'] = $end_line;
1226
1227 $output = implode('|', $tab);
1228 if ($exportFile) {
1229 fwrite($exportFile, $output);
1230 } else {
1231 print $output;
1232 }
1233
1234 $index++;
1235 }
1236 }
1237
1238
1246 public function exportEbp($objectLines, $exportFile = null)
1247 {
1248 $separator = ',';
1249 $end_line = "\n";
1250
1251 foreach ($objectLines as $line) {
1252 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
1253
1254 $tab = array();
1255
1256 $tab[] = $line->id;
1257 $tab[] = $date_document;
1258 $tab[] = $line->code_journal;
1259 if (empty($line->subledger_account)) {
1260 $tab[] = $line->numero_compte;
1261 } else {
1262 $tab[] = $line->subledger_account;
1263 }
1264 //$tab[] = substr(length_accountg($line->numero_compte), 0, 2) . $separator;
1265 $tab[] = '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"';
1266 $tab[] = '"'.dol_trunc((string) $line->piece_num, 15, 'right', 'UTF-8', 1).'"';
1267 $tab[] = price2num(abs($line->debit - $line->credit));
1268 $tab[] = $line->sens;
1269 $tab[] = $date_document;
1270 //print 'EUR';
1271
1272 $output = implode($separator, $tab).$end_line;
1273 if ($exportFile) {
1274 fwrite($exportFile, $output);
1275 } else {
1276 print $output;
1277 }
1278 }
1279 }
1280
1281
1289 public function exportAgiris($objectLines, $exportFile = null)
1290 {
1291 $separator = ';';
1292 $end_line = "\n";
1293
1294 foreach ($objectLines as $line) {
1295 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
1296
1297 $tab = array();
1298
1299 $tab[] = $line->piece_num;
1300 $tab[] = self::toAnsi($line->label_operation);
1301 $tab[] = $date_document;
1302 $tab[] = self::toAnsi($line->label_operation);
1303
1304 if (empty($line->subledger_account)) {
1305 $tab[] = length_accountg($line->numero_compte);
1306 $tab[] = self::toAnsi($line->label_compte);
1307 } else {
1308 $tab[] = length_accounta($line->subledger_account);
1309 $tab[] = self::toAnsi($line->subledger_label);
1310 }
1311
1312 $tab[] = self::toAnsi($line->doc_ref);
1313 $tab[] = price($line->debit);
1314 $tab[] = price($line->credit);
1315 $tab[] = price(abs($line->debit - $line->credit));
1316 $tab[] = $line->sens;
1317 $tab[] = $line->lettering_code;
1318 $tab[] = $line->code_journal;
1319
1320 $output = implode($separator, $tab).$end_line;
1321 if ($exportFile) {
1322 fwrite($exportFile, $output);
1323 } else {
1324 print $output;
1325 }
1326 }
1327 }
1328
1336 public function exportOpenConcerto($objectLines, $exportFile = null)
1337 {
1338 $separator = ';';
1339 $end_line = "\n";
1340
1341 foreach ($objectLines as $line) {
1342 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
1343
1344 $tab = array();
1345
1346 $tab[] = $date_document;
1347 $tab[] = $line->code_journal;
1348 if (empty($line->subledger_account)) {
1349 $tab[] = length_accountg($line->numero_compte);
1350 } else {
1351 $tab[] = length_accounta($line->subledger_account);
1352 }
1353 $tab[] = $line->doc_ref;
1354 $tab[] = $line->label_operation;
1355 $tab[] = price($line->debit);
1356 $tab[] = price($line->credit);
1357
1358 $output = implode($separator, $tab).$end_line;
1359 if ($exportFile) {
1360 fwrite($exportFile, $output);
1361 } else {
1362 print $output;
1363 }
1364 }
1365 }
1366
1374 public function exportConfigurable($objectLines, $exportFile = null)
1375 {
1376 global $conf;
1377
1378 $separator = $this->separator;
1379
1380 foreach ($objectLines as $line) {
1381 $date_document = dol_print_date($line->doc_date, getDolGlobalString('ACCOUNTING_EXPORT_DATE'));
1382
1383 $tab = array();
1384 // export configurable
1385 $tab[] = $line->piece_num;
1386 $tab[] = $date_document;
1387 $tab[] = $line->doc_ref;
1388 $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
1389 $tab[] = length_accountg($line->numero_compte);
1390 $tab[] = length_accounta($line->subledger_account);
1391 $tab[] = price2num($line->debit);
1392 $tab[] = price2num($line->credit);
1393 $tab[] = price2num($line->debit - $line->credit);
1394 $tab[] = $line->code_journal;
1395
1396 $output = implode($separator, $tab).$this->end_line;
1397 if ($exportFile) {
1398 fwrite($exportFile, $output);
1399 } else {
1400 print $output;
1401 }
1402 }
1403 }
1404
1412 public function exportISTEA($objectLines, $exportFile = null)
1413 {
1414 global $conf;
1415
1416 $separator = ';';
1417 $end_line = "\n";
1418
1419 // Extract the Third party account numbers from the table to provide the correct line for ISTEA
1420 $tiers = [];
1421 foreach ($objectLines as $line) {
1422 if ($line->subledger_account && substr($line->subledger_account, 0, 1) == '4') {
1423 $tiers[$line->piece_num] = $line->subledger_label;
1424 }
1425 }
1426
1427 foreach ($objectLines as $line) {
1428 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
1429
1430 /*** prepare label operation field for ISTEA ***/
1431 // truncate the field because ISTEA does not display many characters.
1432 $search = array('Paiement fournisseur ', 'Virement ', 'Paiement ');
1433 $replace = array('Paiemt fourn ','Virt ','Paiemt ');
1434 $label_operation = str_replace($search, $replace, $line->label_operation);
1435 // frame with quotes if field contains the separator
1436 $label_operation = preg_match('/'.$separator.'/', $label_operation) ? "'".$label_operation."'" : $label_operation;
1437
1438 $tab = array();
1439 // export configurable
1440 $tab[] = $line->piece_num; // column 1: piece number ISTEA
1441 $tab[] = $date_document; // column 2: date ISTEA
1442 $tab[] = $line->doc_ref; // column 3: piece reference ISTEA
1443 $tab[] = array_key_exists($line->piece_num, $tiers) ? $tiers[$line->piece_num] : ''; // column 4: third party name ISTEA
1444 $tab[] = length_accountg(($line->subledger_account && (substr($line->subledger_account, 0, 2) == substr($line->numero_compte, 0, 2))) ? $line->subledger_account : $line->numero_compte); // column 5: account number ISTEA
1445 $tab[] = length_accountg($line->subledger_account ? $line->subledger_account : $line->numero_compte); // column 6: account number
1446 $tab[] = length_accountg($line->subledger_account ? $line->numero_compte : ''); // G // column 7: main account number (various payments or 40100000 or 41100000)
1447 $tab[] = ($line->doc_type == 'bank') ? $label_operation : ($line->subledger_account ? $line->subledger_label : $line->label_compte); // column 8: operation label ISTEA
1448 $tab[] = $label_operation; // column 9: operation label (seems not taken into account by ISTEA)
1449 $tab[] = price2num($line->debit); // column 10: debit ISTEA
1450 $tab[] = price2num($line->credit); // column 11: credit ISTEA
1451 $tab[] = $line->code_journal; // column 12: journal ISTEA
1452
1453 $output = mb_convert_encoding('"'.implode('"'.$separator.'"', $tab).'"'.$this->end_line, 'ISO-8859-1');
1454 if ($exportFile) {
1455 fwrite($exportFile, $output);
1456 } else {
1457 print $output;
1458 }
1459 }
1460 }
1461
1474 public function exportFEC($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
1475 {
1476 global $conf, $langs;
1477
1478 $separator = "\t";
1479 $end_line = "\r\n";
1480
1481 $tab = array();
1482 $tab[] = "JournalCode";
1483 $tab[] = "JournalLib";
1484 $tab[] = "EcritureNum";
1485 $tab[] = "EcritureDate";
1486 $tab[] = "CompteNum";
1487 $tab[] = "CompteLib";
1488 $tab[] = "CompAuxNum";
1489 $tab[] = "CompAuxLib";
1490 $tab[] = "PieceRef";
1491 $tab[] = "PieceDate";
1492 $tab[] = "EcritureLib";
1493 $tab[] = "Debit";
1494 $tab[] = "Credit";
1495 $tab[] = "EcritureLet";
1496 $tab[] = "DateLet";
1497 $tab[] = "ValidDate";
1498 $tab[] = "Montantdevise";
1499 $tab[] = "Idevise";
1500 $tab[] = "DateLimitReglmt";
1501 $tab[] = "NumFacture";
1502 $tab[] = "FichierFacture";
1503
1504 $output = implode($separator, $tab).$end_line;
1505 if ($exportFile) {
1506 fwrite($exportFile, $output);
1507 } else {
1508 print $output;
1509 }
1510
1511 $conf->cache['archiveFileList_notfound'] = array();
1512
1513 $i = 0;
1514 foreach ($objectLines as $line) {
1515 if ($line->debit == 0 && $line->credit == 0) {
1516 //var_dump($line->id);
1517 //unset($array[$line]);
1518 } else {
1519 $i++;
1520
1521 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1522 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1523 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1524 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1525 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1526
1527 $refInvoice = '';
1528 $invoice = null;
1529 // TODO The fetch of invoice is just to get the ->id, ->ref (and ->ref_supplier for supplier invoice) so
1530 // may be we can get them into the $objectLines and reuse a generic static objectinstead ?
1531 if ($line->doc_type == 'customer_invoice') {
1532 // Customer invoice
1533 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1534 $invoice = new Facture($this->db);
1535 $invoice->fetch($line->fk_doc);
1536
1537 $refInvoice = (string) $invoice->ref;
1538 } elseif ($line->doc_type == 'supplier_invoice') {
1539 // Supplier invoice
1540 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1541 $invoice = new FactureFournisseur($this->db);
1542 $invoice->fetch($line->fk_doc);
1543
1544 $refInvoice = (string) $invoice->ref_supplier;
1545 }
1546
1547 $tab = array();
1548
1549 // FEC:JournalCode
1550 $tab[] = $line->code_journal;
1551
1552 // FEC:JournalLib
1553 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1554 $labeljournal = str_replace(array("\t", "\n", "\r"), " ", $labeljournal);
1555 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1556 $tab[] = $labeljournal;
1557
1558 // FEC:EcritureNum
1559 $tab[] = $line->piece_num;
1560
1561 // FEC:EcritureDate
1562 $tab[] = $date_document;
1563
1564 // FEC:CompteNum
1565 $tab[] = length_accountg($line->numero_compte);
1566
1567 // FEC:CompteLib
1568 $line->label_compte = str_replace(array("\t", "\n", "\r"), " ", $line->label_compte);
1569 $tab[] = dol_string_unaccent($line->label_compte);
1570
1571 // FEC:CompAuxNum
1572 $tab[] = length_accounta($line->subledger_account);
1573
1574 // FEC:CompAuxLib
1575 $line->subledger_label = str_replace(array("\t", "\n", "\r"), " ", $line->subledger_label);
1576 $tab[] = dol_string_unaccent($line->subledger_label);
1577
1578 // FEC:PieceRef
1579 $line->doc_ref = str_replace(array("\t", "\n", "\r"), " ", $line->doc_ref);
1580 $tab[] = $line->doc_ref;
1581
1582 // FEC:PieceDate
1583 $tab[] = dol_string_unaccent($date_creation);
1584
1585 // FEC:EcritureLib
1586 // Clean label operation to prevent problem on export with tab separator & other character
1587 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1588 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1589 $tab[] = dol_string_unaccent($line->label_operation);
1590
1591 // FEC:Debit
1592 $tab[] = price2fec($line->debit);
1593
1594 // FEC:Credit
1595 $tab[] = price2fec($line->credit);
1596
1597 // FEC:EcritureLet
1598 $line->lettering_code = str_replace(array("\t", "\n", "\r"), " ", (string) $line->lettering_code);
1599 $tab[] = $line->lettering_code;
1600
1601 // FEC:DateLet
1602 $tab[] = $date_lettering;
1603
1604 // FEC:ValidDate
1605 $tab[] = $date_validation;
1606
1607 // FEC:Montantdevise
1608 $tab[] = $line->multicurrency_amount;
1609
1610 // FEC:Idevise
1611 $tab[] = $line->multicurrency_code;
1612
1613 // FEC_suppl:DateLimitReglmt
1614 $tab[] = $date_limit_payment;
1615
1616 // FEC_suppl:NumFacture
1617 // Clean ref invoice to prevent problem on export with tab separator & other character
1618 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1619 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1620
1621 // FEC_suppl:FichierFacture
1622 // get document file
1623 $attachmentFileName = '';
1624 if ($withAttachment == 1) {
1625 $attachmentFileKey = trim((string) $line->piece_num);
1626
1627 if (!isset($archiveFileList[$attachmentFileKey])) {
1628 // We complete the $archiveFileList to add the file to the existing list (first entry was filled when function was called, we add here the next one)
1629 $objectDirPath = '';
1630 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1631 if ($line->doc_type == 'customer_invoice') {
1632 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1633 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1634 }
1635 } elseif ($line->doc_type == 'expense_report') {
1636 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1637 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1638 }
1639 } elseif ($line->doc_type == 'supplier_invoice' && $invoice instanceof FactureFournisseur) {
1640 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1641 '@phan-var-force FactureFournisseur $invoice';
1642 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1643 $objectDirPath .= '/' . rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1644 }
1645 }
1646
1647 if ($objectDirPath && empty($conf->cache['archiveFileList_notfound'][$attachmentFileKey])) {
1648 $arrayofinclusion = array();
1649 // If it is a supplier invoice, we want to use last uploaded file
1650 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1651
1652 $fileFoundPath = ''; // The path of last file found
1653 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1654
1655 if (!empty($fileFoundList)) {
1656 $attachmentFileNameTrunc = $line->doc_ref;
1657
1658 foreach ($fileFoundList as $fileFound) {
1659 if (strstr($fileFound['name'], $objectFileName)) {
1660 // skip native invoice pdfs (canelle)
1661 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1662 if ($line->doc_type == 'supplier_invoice') {
1663 if ($fileFound['name'] === $objectFileName.'.pdf') {
1664 continue;
1665 }
1666 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1667 continue;
1668 }
1669 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1670 if (file_exists($fileFoundPath)) {
1671 $archiveFileList[$attachmentFileKey] = array(
1672 'path' => $fileFoundPath,
1673 'name' => $attachmentFileNameTrunc.'.pdf',
1674 );
1675 break;
1676 }
1677 }
1678 }
1679 }
1680
1681 if (empty($fileFoundPath)) {
1682 // Use also a cache if no file were found
1683 $conf->cache['archiveFileList_notfound'][$attachmentFileKey] = 1;
1684 }
1685 }
1686 }
1687
1688 if (isset($archiveFileList[$attachmentFileKey])) {
1689 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1690 }
1691 }
1692
1693 $tab[] = $attachmentFileName;
1694
1695 $output = implode($separator, $tab).$end_line;
1696
1697 if ($exportFile) {
1698 fwrite($exportFile, $output);
1699 } else {
1700 print $output;
1701 }
1702 }
1703 }
1704
1705 return $archiveFileList;
1706 }
1707
1720 public function exportFEC2($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
1721 {
1722 global $conf, $langs;
1723
1724 $separator = "\t";
1725 $end_line = "\r\n";
1726
1727 $tab = array();
1728 $tab[] = "JournalCode";
1729 $tab[] = "JournalLib";
1730 $tab[] = "EcritureNum";
1731 $tab[] = "EcritureDate";
1732 $tab[] = "CompteNum";
1733 $tab[] = "CompteLib";
1734 $tab[] = "CompAuxNum";
1735 $tab[] = "CompAuxLib";
1736 $tab[] = "PieceRef";
1737 $tab[] = "PieceDate";
1738 $tab[] = "EcritureLib";
1739 $tab[] = "Debit";
1740 $tab[] = "Credit";
1741 $tab[] = "EcritureLet";
1742 $tab[] = "DateLet";
1743 $tab[] = "ValidDate";
1744 $tab[] = "Montantdevise";
1745 $tab[] = "Idevise";
1746 $tab[] = "DateLimitReglmt";
1747 $tab[] = "NumFacture";
1748 $tab[] = "FichierFacture";
1749
1750 $output = implode($separator, $tab).$end_line;
1751 if ($exportFile) {
1752 fwrite($exportFile, $output);
1753 } else {
1754 print $output;
1755 }
1756
1757 $conf->cache['archiveFileList_notfound'] = array();
1758
1759 $i = 0;
1760 foreach ($objectLines as $line) {
1761 if ($line->debit == 0 && $line->credit == 0) {
1762 //unset($array[$line]);
1763 } else {
1764 $i++;
1765
1766 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1767 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1768 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1769 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1770 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1771
1772 $refInvoice = '';
1773 $invoice = null;
1774 // TODO The fetch of invoice is just to get the ->id, ->ref (and ->ref_supplier for supplier invoice) so
1775 // may be we can get them into the $objectLines and reuse a generic static objectinstead ?
1776 if ($line->doc_type == 'customer_invoice') {
1777 // Customer invoice
1778 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1779 $invoice = new Facture($this->db);
1780 $invoice->fetch($line->fk_doc);
1781
1782 $refInvoice = (string) $invoice->ref;
1783 } elseif ($line->doc_type == 'supplier_invoice') {
1784 // Supplier invoice
1785 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1786 $invoice = new FactureFournisseur($this->db);
1787 $invoice->fetch($line->fk_doc);
1788
1789 $refInvoice = (string) $invoice->ref_supplier;
1790 }
1791
1792 $tab = array();
1793
1794 // FEC:JournalCode
1795 $tab[] = $line->code_journal;
1796
1797 // FEC:JournalLib
1798 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1799 $labeljournal = str_replace(array("\t", "\n", "\r"), " ", $labeljournal);
1800 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1801 $tab[] = $labeljournal;
1802
1803 // FEC:EcritureNum
1804 $tab[] = $line->piece_num;
1805
1806 // FEC:EcritureDate
1807 $tab[] = $date_creation;
1808
1809 // FEC:CompteNum
1810 $tab[] = length_accountg($line->numero_compte);
1811
1812 // FEC:CompteLib
1813 $line->label_compte = str_replace(array("\t", "\n", "\r"), " ", $line->label_compte);
1814 $tab[] = dol_string_unaccent($line->label_compte);
1815
1816 // FEC:CompAuxNum
1817 $tab[] = length_accounta($line->subledger_account);
1818
1819 // FEC:CompAuxLib
1820 $line->subledger_label = str_replace(array("\t", "\n", "\r"), " ", $line->subledger_label);
1821 $tab[] = dol_string_unaccent($line->subledger_label);
1822
1823 // FEC:PieceRef
1824 $line->doc_ref = str_replace(array("\t", "\n", "\r"), " ", $line->doc_ref);
1825 $tab[] = $line->doc_ref;
1826
1827 // FEC:PieceDate
1828 $tab[] = $date_document;
1829
1830 // FEC:EcritureLib
1831 // Clean label operation to prevent problem on export with tab separator & other character
1832 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1833 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1834 $tab[] = dol_string_unaccent($line->label_operation);
1835
1836 // FEC:Debit
1837 $tab[] = price2fec($line->debit);
1838
1839 // FEC:Credit
1840 $tab[] = price2fec($line->credit);
1841
1842 // FEC:EcritureLet
1843 $line->lettering_code = str_replace(array("\t", "\n", "\r"), " ", (string) $line->lettering_code);
1844 $tab[] = $line->lettering_code;
1845
1846 // FEC:DateLet
1847 $tab[] = $date_lettering;
1848
1849 // FEC:ValidDate
1850 $tab[] = $date_validation;
1851
1852 // FEC:Montantdevise
1853 $tab[] = $line->multicurrency_amount;
1854
1855 // FEC:Idevise
1856 $tab[] = $line->multicurrency_code;
1857
1858 // FEC_suppl:DateLimitReglmt
1859 $tab[] = $date_limit_payment;
1860
1861 // FEC_suppl:NumFacture
1862 // Clean ref invoice to prevent problem on export with tab separator & other character
1863 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1864 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1865
1866 // FEC_suppl:FichierFacture
1867 // get document file
1868 $attachmentFileName = '';
1869 if ($withAttachment == 1) {
1870 $attachmentFileKey = trim((string) $line->piece_num);
1871
1872 if (!isset($archiveFileList[$attachmentFileKey])) {
1873 // We complete the $archiveFileList to add the file to the existing list (first entry was filled when function was called, we add here the next one)
1874 $objectDirPath = '';
1875 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1876 if ($line->doc_type == 'customer_invoice') {
1877 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1878 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1879 }
1880 } elseif ($line->doc_type == 'expense_report') {
1881 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1882 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1883 }
1884 } elseif ($line->doc_type == 'supplier_invoice' && $invoice instanceof FactureFournisseur) {
1885 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1886 '@phan-var-force FactureFournisseur $invoice';
1887 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1888 $objectDirPath .= '/' . rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1889 }
1890 }
1891
1892 if ($objectDirPath && empty($conf->cache['archiveFileList_notfound'][$attachmentFileKey])) {
1893 $arrayofinclusion = array();
1894 // If it is a supplier invoice, we want to use last uploaded file
1895 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1896
1897 $fileFoundPath = ''; // The path of last file found
1898 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1899
1900 if (!empty($fileFoundList)) {
1901 $attachmentFileNameTrunc = $line->doc_ref;
1902
1903 foreach ($fileFoundList as $fileFound) {
1904 if (strstr($fileFound['name'], $objectFileName)) {
1905 // skip native invoice pdfs (canelle)
1906 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1907 if ($line->doc_type == 'supplier_invoice') {
1908 if ($fileFound['name'] === $objectFileName.'.pdf') {
1909 continue;
1910 }
1911 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1912 continue;
1913 }
1914 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1915 if (file_exists($fileFoundPath)) {
1916 $archiveFileList[$attachmentFileKey] = array(
1917 'path' => $fileFoundPath,
1918 'name' => $attachmentFileNameTrunc.'.pdf',
1919 );
1920 break;
1921 }
1922 }
1923 }
1924 }
1925
1926 if (empty($fileFoundPath)) {
1927 // Use also a cache if no file were found
1928 $conf->cache['archiveFileList_notfound'][$attachmentFileKey] = 1;
1929 }
1930 }
1931 }
1932
1933 if (isset($archiveFileList[$attachmentFileKey])) {
1934 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1935 }
1936 }
1937
1938 $tab[] = $attachmentFileName;
1939
1940 $output = implode($separator, $tab).$end_line;
1941 if ($exportFile) {
1942 fwrite($exportFile, $output);
1943 } else {
1944 print $output;
1945 }
1946 }
1947 }
1948
1949 return $archiveFileList;
1950 }
1951
1962 public function exportSAGE50SWISS($objectLines, $exportFile = null)
1963 {
1964 // SAGE50SWISS
1965 $separator = ',';
1966 $end_line = "\r\n";
1967
1968 // Print header line
1969 $tab = array();
1970
1971 $tab[] = "Blg";
1972 $tab[] = "Datum";
1973 $tab[] = "Kto";
1974 $tab[] = "S/H";
1975 $tab[] = "Grp";
1976 $tab[] = "GKto";
1977 $tab[] = "SId";
1978 $tab[] = "SIdx";
1979 $tab[] = "KIdx";
1980 $tab[] = "BTyp";
1981 $tab[] = "MTyp";
1982 $tab[] = "Code";
1983 $tab[] = "Netto";
1984 $tab[] = "Steuer";
1985 $tab[] = "FW-Betrag";
1986 $tab[] = "Tx1";
1987 $tab[] = "Tx2";
1988 $tab[] = "PkKey";
1989 $tab[] = "OpId";
1990 $tab[] = "Flag";
1991
1992 $output = implode($separator, $tab).$end_line;
1993 if ($exportFile) {
1994 fwrite($exportFile, $output);
1995 } else {
1996 print $output;
1997 }
1998
1999 $thisPieceNum = "";
2000 $thisPieceAccountNr = "";
2001 $aSize = count($objectLines);
2002 foreach ($objectLines as $aIndex => $line) {
2003 $sammelBuchung = false;
2004 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
2005 $sammelBuchung = true;
2006 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
2007 $sammelBuchung = true;
2008 } elseif ($aIndex + 1 < $aSize
2009 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
2010 && $aIndex - 1 < $aSize
2011 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
2012 ) {
2013 $sammelBuchung = true;
2014 }
2015
2016 $tab = array();
2017
2018 //Blg
2019 $tab[] = $line->piece_num;
2020
2021 // Datum
2022 $date_document = dol_print_date($line->doc_date, '%d.%m.%Y');
2023 $tab[] = $date_document;
2024
2025 // Kto
2026 $tab[] = length_accountg($line->numero_compte);
2027 // S/H
2028 if ($line->sens == 'D') {
2029 $tab[] = 'S';
2030 } else {
2031 $tab[] = 'H';
2032 }
2033 // Grp
2034 $tab[] = self::trunc($line->code_journal, 1);
2035 // GKto
2036 if (empty($line->code_tiers)) {
2037 if ($line->piece_num == $thisPieceNum) {
2038 $tab[] = length_accounta($thisPieceAccountNr);
2039 } else {
2040 $tab[] = "div";
2041 }
2042 } else {
2043 $tab[] = length_accounta($line->code_tiers);
2044 }
2045 // SId
2046 $tab[] = $this->separator;
2047 // SIdx
2048 $tab[] = "0";
2049 // KIdx
2050 $tab[] = "0";
2051 // BTyp
2052 $tab[] = "0";
2053
2054 // MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
2055 if ($sammelBuchung) {
2056 $tab[] = "2";
2057 } else {
2058 $tab[] = "1";
2059 }
2060 // Code
2061 $tab[] = '""';
2062 // Netto
2063 $tab[] = abs($line->debit - $line->credit);
2064 // Steuer
2065 $tab[] = "0.00";
2066 // FW-Betrag
2067 $tab[] = "0.00";
2068 // Tx1
2069 $line1 = self::toAnsi($line->label_compte, 29);
2070 if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
2071 $line1 = "";
2072 }
2073 $line2 = self::toAnsi($line->doc_ref, 29);
2074 if (strlen($line1) == 0) {
2075 $line1 = $line2;
2076 $line2 = "";
2077 }
2078 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
2079 $line1 = $line1.' / '.$line2;
2080 $line2 = "";
2081 }
2082
2083 $tab[] = '"'.self::toAnsi($line1).'"';
2084 // Tx2
2085 $tab[] = '"'.self::toAnsi($line2).'"';
2086 //PkKey
2087 $tab[] = "0";
2088 //OpId
2089 $tab[] = $this->separator;
2090
2091 // Flag
2092 $tab[] = "0";
2093
2094 $output = implode($separator, $tab).$end_line;
2095 if ($exportFile) {
2096 fwrite($exportFile, $output);
2097 } else {
2098 print $output;
2099 }
2100
2101 if ($line->piece_num !== $thisPieceNum) {
2102 $thisPieceNum = $line->piece_num;
2103 $thisPieceAccountNr = $line->numero_compte;
2104 }
2105 }
2106 }
2107
2116 public function exportLDCompta($objectLines, $exportFile = null)
2117 {
2118 $separator = ';';
2119 $end_line = "\r\n";
2120
2121 foreach ($objectLines as $line) {
2122 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2123 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
2124 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2125
2126 $tab = array();
2127
2128 // TYPE
2129 $type_enregistrement = 'E'; // For write movement
2130 $tab[] = $type_enregistrement;
2131 // JNAL
2132 $tab[] = substr($line->code_journal, 0, 2);
2133 // NECR
2134 $tab[] = $line->id;
2135 // NPIE
2136 $tab[] = $line->piece_num;
2137 // DATP
2138 $tab[] = $date_document;
2139 // LIBE
2140 $tab[] = $line->label_operation;
2141 // DATH
2142 $tab[] = $date_lim_reglement;
2143 // CNPI
2144 if ($line->doc_type == 'supplier_invoice') {
2145 if (($line->debit - $line->credit) > 0) {
2146 $nature_piece = 'AF';
2147 } else {
2148 $nature_piece = 'FF';
2149 }
2150 } elseif ($line->doc_type == 'customer_invoice') {
2151 if (($line->debit - $line->credit) < 0) {
2152 $nature_piece = 'AC';
2153 } else {
2154 $nature_piece = 'FC';
2155 }
2156 } else {
2157 $nature_piece = '';
2158 }
2159 $tab[] = $nature_piece;
2160 // RACI
2161 // if (!empty($line->subledger_account)) {
2162 // if ($line->doc_type == 'supplier_invoice') {
2163 // $racine_subledger_account = '40';
2164 // } elseif ($line->doc_type == 'customer_invoice') {
2165 // $racine_subledger_account = '41';
2166 // } else {
2167 // $racine_subledger_account = '';
2168 // }
2169 // } else {
2170 $racine_subledger_account = ''; // for records of type E leave this field blank
2171 // }
2172
2173 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2174 // MONT
2175 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2, 2);
2176 // CODC
2177 $tab[] = $line->sens;
2178 // CPTG
2179 $tab[] = length_accountg($line->numero_compte);
2180 // DATE
2181 $tab[] = $date_creation;
2182 // CLET
2183 $tab[] = $line->lettering_code;
2184 // DATL
2185 $tab[] = $line->date_lettering;
2186 // CPTA
2187 if (!empty($line->subledger_account)) {
2188 $tab[] = length_accounta($line->subledger_account);
2189 } else {
2190 $tab[] = "";
2191 }
2192 // C.N.A.T
2193 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2194 $tab[] = 'F';
2195 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2196 $tab[] = 'C';
2197 } else {
2198 $tab[] = "";
2199 }
2200 // SECT
2201 $tab[] = "";
2202 // CTRE
2203 $tab[] = "";
2204 // NORL
2205 $tab[] = "";
2206 // DATV
2207 $tab[] = "";
2208 // REFD
2209 $tab[] = $line->doc_ref;
2210 // CODH
2211 $tab[] = "";
2212 // NSEQ
2213 $tab[] = "";
2214 // MTDV
2215 $tab[] = '0';
2216 // CODV
2217 $tab[] = "";
2218 // TXDV
2219 $tab[] = '0';
2220 // MOPM
2221 $tab[] = "";
2222 // BONP
2223 $tab[] = "";
2224 // BQAF
2225 $tab[] = "";
2226 // ECES
2227 $tab[] = "";
2228 // TXTL
2229 $tab[] = "";
2230 // ECRM
2231 $tab[] = "";
2232 // DATK
2233 $tab[] = "";
2234 // HEUK
2235 $tab[] = "";
2236
2237 $output = implode($separator, $tab).$end_line;
2238 if ($exportFile) {
2239 fwrite($exportFile, $output);
2240 } else {
2241 print $output;
2242 }
2243 }
2244 }
2245
2256 public function exportLDCompta10($objectLines, $exportFile = null)
2257 {
2258 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
2259
2260 $separator = ';';
2261 $end_line = "\r\n";
2262 $last_codeinvoice = '';
2263
2264 foreach ($objectLines as $line) {
2265 // TYPE C
2266 if ($last_codeinvoice != $line->doc_ref) {
2267 //search company by customer code
2268 $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
2269 $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
2270 $resql = $this->db->query($sql);
2271
2272 if ($resql && $this->db->num_rows($resql) > 0) {
2273 $soc = $this->db->fetch_object($resql);
2274
2275 $address = array('', '', '');
2276 if (strpos($soc->address, "\n") !== false) {
2277 $address = explode("\n", $soc->address);
2278 if (is_array($address) && count($address) > 0) {
2279 foreach ($address as $key => $data) {
2280 $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
2281 $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
2282 }
2283 }
2284 } else {
2285 $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
2286 $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
2287 $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
2288 }
2289
2290 $tab = array();
2291
2292 $type_enregistrement = 'C';
2293 //TYPE
2294 $tab[] = $type_enregistrement;
2295 //NOCL
2296 $tab[] = $soc->code_client;
2297 //NMCM
2298 $tab[] = "";
2299 //LIBI
2300 $tab[] = "";
2301 //TITR
2302 $tab[] = "";
2303 //RSSO
2304 $tab[] = $soc->nom;
2305 //CAD1
2306 $tab[] = $address[0];
2307 //CAD2
2308 $tab[] = $address[1];
2309 //CAD3
2310 $tab[] = $address[2];
2311 //COPO
2312 $tab[] = $soc->zip;
2313 //BUDI
2314 $tab[] = substr($soc->town, 0, 40);
2315 //CPAY
2316 $tab[] = "";
2317 //PAYS
2318 $tab[] = substr(getCountry($soc->fk_pays), 0, 40);
2319 //NTEL
2320 $tab[] = $soc->phone;
2321 //TLEX
2322 $tab[] = "";
2323 //TLPO
2324 $tab[] = "";
2325 //TLCY
2326 $tab[] = "";
2327 //NINT
2328 $tab[] = "";
2329 //COMM
2330 $tab[] = "";
2331 //SIRE
2332 $tab[] = str_replace(" ", "", $soc->siret);
2333 //RIBP
2334 $tab[] = "";
2335 //DOBQ
2336 $tab[] = "";
2337 //IBBQ
2338 $tab[] = "";
2339 //COBQ
2340 $tab[] = "";
2341 //GUBQ
2342 $tab[] = "";
2343 //CPBQ
2344 $tab[] = "";
2345 //CLBQ
2346 $tab[] = "";
2347 //BIBQ
2348 $tab[] = "";
2349 //MOPM
2350 $tab[] = "";
2351 //DJPM
2352 $tab[] = "";
2353 //DMPM
2354 $tab[] = "";
2355 //REFM
2356 $tab[] = "";
2357 //SLVA
2358 $tab[] = "";
2359 //PLCR
2360 $tab[] = "";
2361 //ECFI
2362 $tab[] = "";
2363 //CREP
2364 $tab[] = "";
2365 //NREP
2366 $tab[] = "";
2367 //TREP
2368 $tab[] = "";
2369 //MREP
2370 $tab[] = "";
2371 //GRRE
2372 $tab[] = "";
2373 //LTTA
2374 $tab[] = "";
2375 //CACT
2376 $tab[] = "";
2377 //CODV
2378 $tab[] = "";
2379 //GRTR
2380 $tab[] = "";
2381 //NOFP
2382 $tab[] = "";
2383 //BQAF
2384 $tab[] = "";
2385 //BONP
2386 $tab[] = "";
2387 //CESC
2388 $tab[] = "";
2389
2390 $output = implode($separator, $tab).$end_line;
2391 if ($exportFile) {
2392 fwrite($exportFile, $output);
2393 } else {
2394 print $output;
2395 }
2396 }
2397 }
2398
2399 $tab = array();
2400
2401 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2402 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
2403 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2404
2405 // TYPE E
2406 $type_enregistrement = 'E'; // For write movement
2407 $tab[] = $type_enregistrement;
2408 // JNAL
2409 $tab[] = substr($line->code_journal, 0, 2);
2410 // NECR
2411 $tab[] = $line->id;
2412 // NPIE
2413 $tab[] = $line->piece_num;
2414 // DATP
2415 $tab[] = $date_document;
2416 // LIBE
2417 $tab[] = dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1);
2418 // DATH
2419 $tab[] = $date_lim_reglement;
2420 // CNPI
2421 if ($line->doc_type == 'supplier_invoice') {
2422 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.
2423 $nature_piece = 'AF';
2424 } else {
2425 $nature_piece = 'FF';
2426 }
2427 } elseif ($line->doc_type == 'customer_invoice') {
2428 if (($line->amount) < 0) {
2429 $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.
2430 } else {
2431 $nature_piece = 'FC';
2432 }
2433 } else {
2434 $nature_piece = '';
2435 }
2436 $tab[] = $nature_piece;
2437 // RACI
2438 // if (!empty($line->subledger_account)) {
2439 // if ($line->doc_type == 'supplier_invoice') {
2440 // $racine_subledger_account = '40';
2441 // } elseif ($line->doc_type == 'customer_invoice') {
2442 // $racine_subledger_account = '41';
2443 // } else {
2444 // $racine_subledger_account = '';
2445 // }
2446 // } else {
2447 $racine_subledger_account = ''; // for records of type E leave this field blank
2448 // }
2449
2450 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2451 // MONT
2452 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2);
2453 // CODC
2454 $tab[] = $line->sens;
2455 // CPTG
2456 $tab[] = length_accountg($line->numero_compte);
2457 // DATE
2458 $tab[] = $date_document;
2459 // CLET
2460 $tab[] = $line->lettering_code;
2461 // DATL
2462 $tab[] = $line->date_lettering;
2463 // CPTA
2464 if (!empty($line->subledger_account)) {
2465 $tab[] = length_accounta($line->subledger_account);
2466 } else {
2467 $tab[] = "";
2468 }
2469 // C.N.A.T
2470 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2471 $tab[] = 'F';
2472 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2473 $tab[] = 'C';
2474 } else {
2475 $tab[] = "";
2476 }
2477 // CTRE
2478 $tab[] = "";
2479 // NORL
2480 $tab[] = "";
2481 // DATV
2482 $tab[] = "";
2483 // REFD
2484 $tab[] = $line->doc_ref;
2485 // NECA
2486 $tab[] = '0';
2487 // CSEC
2488 $tab[] = "";
2489 // CAFF
2490 $tab[] = "";
2491 // CDES
2492 $tab[] = "";
2493 // QTUE
2494 $tab[] = "";
2495 // MTDV
2496 $tab[] = '0';
2497 // CODV
2498 $tab[] = "";
2499 // TXDV
2500 $tab[] = '0';
2501 // MOPM
2502 $tab[] = "";
2503 // BONP
2504 $tab[] = "";
2505 // BQAF
2506 $tab[] = "";
2507 // ECES
2508 $tab[] = "";
2509 // TXTL
2510 $tab[] = "";
2511 // ECRM
2512 $tab[] = "";
2513 // DATK
2514 $tab[] = "";
2515 // HEUK
2516 $tab[] = "";
2517
2518 $output = implode($separator, $tab).$end_line;
2519 if ($exportFile) {
2520 fwrite($exportFile, $output);
2521 } else {
2522 print $output;
2523 }
2524
2525 $last_codeinvoice = $line->doc_ref;
2526 }
2527 }
2528
2536 public function exportCharlemagne($objectLines, $exportFile = null)
2537 {
2538 global $langs;
2539 $langs->load('compta');
2540
2541 $separator = "\t";
2542 $end_line = "\n";
2543
2544 $tab = array();
2545
2546 $tab[] = $langs->transnoentitiesnoconv('Date');
2547 $tab[] = self::trunc($langs->transnoentitiesnoconv('Journal'), 6);
2548 $tab[] = self::trunc($langs->transnoentitiesnoconv('Account'), 15);
2549 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60);
2550 $tab[] = self::trunc($langs->transnoentitiesnoconv('Piece'), 20);
2551 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60);
2552 $tab[] = $langs->transnoentitiesnoconv('Amount');
2553 $tab[] = 'S';
2554 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15);
2555 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60);
2556 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15);
2557 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60);
2558 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15);
2559 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60);
2560
2561 $output = implode($separator, $tab).$end_line;
2562 if ($exportFile) {
2563 fwrite($exportFile, $output);
2564 } else {
2565 print $output;
2566 }
2567
2568 foreach ($objectLines as $line) {
2569 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2570
2571 $tab = array();
2572
2573 $tab[] = $date_document; //Date
2574
2575 $tab[] = self::trunc($line->code_journal, 6); //Journal code
2576
2577 if (!empty($line->subledger_account)) {
2578 $account = $line->subledger_account;
2579 } else {
2580 $account = $line->numero_compte;
2581 }
2582 $tab[] = self::trunc((string) $account, 15); //Account number
2583
2584 $tab[] = self::trunc($line->label_compte, 60); //Account label
2585 $tab[] = self::trunc($line->doc_ref, 20); //Piece
2586 // Clean label operation to prevent problem on export with tab separator & other character
2587 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
2588 $tab[] = self::trunc($line->label_operation, 60); //Operation label
2589 $tab[] = price(abs($line->debit - $line->credit)); //Amount
2590 $tab[] = $line->sens; //Direction
2591 $tab[] = ""; //Analytic
2592 $tab[] = ""; //Analytic
2593 $tab[] = ""; //Analytic
2594 $tab[] = ""; //Analytic
2595 $tab[] = ""; //Analytic
2596 $tab[] = ""; //Analytic
2597
2598 $output = implode($separator, $tab).$end_line;
2599 if ($exportFile) {
2600 fwrite($exportFile, $output);
2601 } else {
2602 print $output;
2603 }
2604 }
2605 }
2606
2614 public function exportGestimumV3($objectLines, $exportFile = null)
2615 {
2616 global $langs;
2617
2618 $separator = ',';
2619 $end_line = "\r\n";
2620
2621 $invoices_infos = array();
2622 $supplier_invoices_infos = array();
2623 foreach ($objectLines as $line) {
2624 if ($line->debit == 0 && $line->credit == 0) {
2625 //unset($array[$line]);
2626 } else {
2627 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
2628 $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2629
2630 $invoice_ref = $line->doc_ref;
2631 $company_name = "";
2632
2633 if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
2634 if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2635 ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2636 if ($line->doc_type == 'customer_invoice') {
2637 // Get new customer invoice ref and company name
2638 $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
2639 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
2640 $sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
2641 $resql = $this->db->query($sql);
2642 if ($resql) {
2643 if ($obj = $this->db->fetch_object($resql)) {
2644 // Save invoice infos
2645 $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2646 $invoice_ref = $obj->ref;
2647 $company_name = $obj->nom;
2648 }
2649 }
2650 } else {
2651 // Get new supplier invoice ref and company name
2652 $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
2653 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
2654 $sql .= ' WHERE ff.rowid = '.((int) $line->fk_doc);
2655 $resql = $this->db->query($sql);
2656 if ($resql) {
2657 if ($obj = $this->db->fetch_object($resql)) {
2658 // Save invoice infos
2659 $supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2660 $invoice_ref = $obj->ref;
2661 $company_name = $obj->nom;
2662 }
2663 }
2664 }
2665 } elseif ($line->doc_type == 'customer_invoice') {
2666 // Retrieve invoice infos
2667 $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
2668 $company_name = $invoices_infos[$line->fk_doc]['company_name'];
2669 } else {
2670 // Retrieve invoice infos
2671 $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
2672 $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
2673 }
2674 }
2675
2676 $tab = array();
2677
2678 $tab[] = $line->id;
2679 $tab[] = $date_document;
2680 $tab[] = substr($line->code_journal, 0, 4);
2681
2682 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
2683 $tab[] = length_accountg($line->subledger_account);
2684 } else {
2685 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2686 }
2687 //Auto label
2688 $tab[] = "";
2689 //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"';
2690 //Manual label
2691 $tab[] = dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1);
2692 //Document number
2693 $tab[] = dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1);
2694 //Currency
2695 $tab[] = 'EUR';
2696 //Amount
2697 $tab[] = price2num(abs($line->debit - $line->credit));
2698 //Direction
2699 $tab[] = $line->sens;
2700 //Matching code
2701 $tab[] = "";
2702 //Due date
2703 $tab[] = $date_echeance;
2704
2705 $output = implode($separator, $tab).$end_line;
2706 if ($exportFile) {
2707 fwrite($exportFile, $output);
2708 } else {
2709 print $output;
2710 }
2711 }
2712 }
2713 }
2714
2722 public function exportGestimumV5($objectLines, $exportFile = null)
2723 {
2724 $separator = ',';
2725 $end_line = "\r\n";
2726
2727 foreach ($objectLines as $line) {
2728 if ($line->debit == 0 && $line->credit == 0) {
2729 //unset($array[$line]);
2730 } else {
2731 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
2732
2733 $tab = array();
2734
2735 $tab[] = $line->id;
2736 $tab[] = $date_document;
2737 $tab[] = substr($line->code_journal, 0, 4);
2738 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
2739 $tab[] = length_accountg($line->subledger_account);
2740 } else {
2741 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2742 }
2743 $tab[] = "";
2744 $tab[] = '"'.dol_trunc(str_replace('"', '', $line->label_operation), 40, 'right', 'UTF-8', 1).'"';
2745 $tab[] = '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"';
2746 $tab[] = '"' . dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1) . '"';
2747 $tab[] = price2num(abs($line->debit - $line->credit));
2748 $tab[] = $line->sens;
2749 $tab[] = $date_document;
2750 $tab[] = "";
2751 $tab[] = "";
2752 $tab[] = 'EUR';
2753
2754 $output = implode($separator, $tab).$end_line;
2755 if ($exportFile) {
2756 fwrite($exportFile, $output);
2757 } else {
2758 print $output;
2759 }
2760 }
2761 }
2762 }
2763
2773 public function exportiSuiteExpert($objectLines, $exportFile = null)
2774 {
2775 $separator = ';';
2776 $end_line = "\r\n";
2777
2778
2779 foreach ($objectLines as $line) {
2780 $tab = array();
2781
2782 $date = dol_print_date($line->doc_date, '%d/%m/%Y');
2783
2784 $tab[] = $line->piece_num;
2785 $tab[] = $date;
2786 $tab[] = substr($date, 6, 4);
2787 $tab[] = substr($date, 3, 2);
2788 $tab[] = substr($date, 0, 2);
2789 $tab[] = $line->doc_ref;
2790 // Convert the UTF-8 string in latin9
2791 $tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
2792
2793 //Calculate account number length
2794 $taille_numero = strlen(length_accountg($line->numero_compte));
2795
2796 //Build generic customer and supplier account number
2797 $numero_cpt_client = '411';
2798 $numero_cpt_fourn = '401';
2799 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2800 $numero_cpt_client .= '0';
2801 $numero_cpt_fourn .= '0';
2802 }
2803
2804 //Build auxiliary accounts for customers and suppliers
2805 if (length_accountg($line->numero_compte) == $numero_cpt_client || length_accountg($line->numero_compte) == $numero_cpt_fourn) {
2806 $tab[] = rtrim(length_accounta($line->subledger_account), "0");
2807 } else {
2808 $tab[] = length_accountg($line->numero_compte);
2809 }
2810 $nom_client = explode(" - ", $line->label_operation);
2811 $tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
2812 $tab[] = price($line->debit);
2813 $tab[] = price($line->credit);
2814 $tab[] = price($line->montant);
2815 $tab[] = $line->code_journal;
2816
2817 $output = implode($separator, $tab).$end_line;
2818 if ($exportFile) {
2819 fwrite($exportFile, $output);
2820 } else {
2821 print $output;
2822 }
2823 }
2824 }
2825
2833 public static function trunc($str, $size)
2834 {
2835 return dol_trunc($str, $size, 'right', 'UTF-8', 1);
2836 }
2837
2845 public static function toAnsi($str, $size = -1)
2846 {
2847 $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
2848 if ($retVal >= 0 && $size >= 0) {
2849 $retVal = dol_substr($retVal, 0, $size, 'Windows-1251');
2850 }
2851 return $retVal;
2852 }
2853}
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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...
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.
Definition files.lib.php:66
dol_is_dir($folder)
Test if filename is a directory.
price2fec($amount)
Function to format a value into a defined format for French administration (no thousand separator & d...
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.