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