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