dolibarr 24.0.1
accountancyexport.class.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
6 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7 * Copyright (C) 2016 Pierre-Henry Favre <phf@atm-consulting.fr>
8 * Copyright (C) 2016-2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
9 * Copyright (C) 2022 Lionel Vessiller <lvessiller@open-dsi.fr>
10 * Copyright (C) 2013-2017 Olivier Geffroy <jeff@jeffinfo.com>
11 * Copyright (C) 2017 Elarifr. Ari Elbaz <github@accedinfo.com>
12 * Copyright (C) 2017-2026 Frédéric France <frederic.france@free.fr>
13 * Copyright (C) 2017 André Schild <a.schild@aarboard.ch>
14 * Copyright (C) 2020 Guillaume Alexandre <guillaume@tag-info.fr>
15 * Copyright (C) 2022 Joachim Kueter <jkueter@gmx.de>
16 * Copyright (C) 2022 Progiseize <a.bisotti@progiseize.fr>
17 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 3 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <https://www.gnu.org/licenses/>.
31 */
32
39require_once DOL_DOCUMENT_ROOT.'/core/lib/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
966 // Field "Maj" (static position 1 char):
967 // blank = no update if account already exists
968 // 2 = partial update (alpha key, label, address, collectif, RIB)
969 if (getDolGlobalString('ACCOUNTING_EXPORT_QUADRATUS_DISABLE_THIRDPARTY_UPDATE')) {
970 $tab['Maj'] = ' ';
971 } else {
972 $tab['Maj'] = 2;
973 }
974
975 if ($line->doc_type == 'customer_invoice') {
976 $tab['type_compte'] = 'C';
977 } elseif ($line->doc_type == 'supplier_invoice') {
978 $tab['type_compte'] = 'F';
979 } else {
980 $tab['type_compte'] = 'G';
981 }
982
983 $tab['filler3'] = str_repeat(' ', 235);
984
985 $tab['end_line'] = $end_line;
986
987 if ($exportFile) {
988 fwrite($exportFile, implode($tab));
989 } else {
990 print implode($tab);
991 }
992 }
993
994 $tab = array();
995 $tab['type_ligne'] = 'M';
996 $tab['num_compte'] = str_pad(self::trunc((string) $code_compta, 8), 8);
997 $tab['code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
998 $tab['folio'] = '000';
999
1000 // We use invoice date $line->doc_date not $date_ecriture which is the transfer date
1001 // maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
1002 //$tab['date_ecriture'] = $date_ecriture;
1003 $tab['date_ecriture'] = dol_print_date($line->doc_date, '%d%m%y');
1004 $tab['filler'] = ' ';
1005 $tab['libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.' '.$line->label_operation, 20), 20);
1006
1007 // Credit invoice - invert sens
1008 /*
1009 if ($line->montant < 0) {
1010 if ($line->sens == 'C') {
1011 $tab['sens'] = 'D';
1012 } else {
1013 $tab['sens'] = 'C';
1014 }
1015 $tab['signe_montant'] = '-';
1016 } else {
1017 $tab['sens'] = $line->sens; // C or D
1018 $tab['signe_montant'] = '+';
1019 }*/
1020 $tab['sens'] = $line->sens; // C or D
1021 $tab['signe_montant'] = '+';
1022
1023 // The amount must be in centimes without decimal points.
1024 $tab['montant'] = str_pad((string) abs(($line->debit - $line->credit) * 100), 12, '0', STR_PAD_LEFT);
1025 $tab['contrepartie'] = str_repeat(' ', 8);
1026
1027 // Force date format : %d%m%y
1028 if (!empty($line->date_lim_reglement)) {
1029 $tab['date_echeance'] = dol_print_date($line->date_lim_reglement, '%d%m%y'); // Format must be ddmmyy
1030 } else {
1031 $tab['date_echeance'] = '000000';
1032 }
1033
1034 // Please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
1035 // $tab['lettrage'] = str_repeat(' ', 5);
1036 $tab['lettrage'] = str_repeat(' ', 2);
1037 $tab['codestat'] = str_repeat(' ', 3);
1038 $tab['num_piece'] = str_pad(self::trunc((string) $line->piece_num, 5), 5);
1039
1040 // Keep correct quadra named field instead of anon filler
1041 // $tab['filler2'] = str_repeat(' ', 20);
1042 $tab['affaire'] = str_repeat(' ', 10);
1043 $tab['quantity1'] = str_repeat(' ', 10);
1044 $tab['num_piece2'] = str_pad(self::trunc((string) $line->piece_num, 8), 8);
1045 $tab['devis'] = str_pad(getDolCurrency(), 3);
1046 $tab['code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
1047 $tab['filler3'] = str_repeat(' ', 3);
1048
1049 // Keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
1050 // as we use utf8, we must remove accent to have only one ascii char instead of utf8 2 chars for specials that report wrong line size that will exceed import format spec
1051 // TODO: we should filter more than only accent to avoid wrong line size
1052 // TODO: remove invoice number doc_ref in label,
1053 // TODO: we should offer an option for customer to build the label using invoice number / name / date in accounting software
1054 //$tab['libelle_ecriture2'] = str_pad(self::trunc($line->doc_ref . ' ' . $line->label_operation, 30), 30);
1055 $tab['libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
1056 $tab['codetva'] = str_repeat(' ', 2);
1057
1058 // We need to keep the 10 latest number of invoices doc_ref not the beginning part that is the useless almost same part
1059 // $tab['num_piece3'] = str_pad(self::trunc($line->piece_num, 10), 10);
1060 $tab['num_piece3'] = str_pad(substr(self::trunc($line->doc_ref, 20), -10), 10);
1061 $tab['reserved'] = str_repeat(' ', 10); // position 159
1062 $tab['currency_amount'] = str_repeat(' ', 13); // position 169
1063
1064 // get document file
1065 $attachmentFileName = '';
1066 if ($withAttachment == 1) {
1067 $attachmentFileKey = trim((string) $line->piece_num);
1068
1069 if (!isset($archiveFileList[$attachmentFileKey])) {
1070 // We complete the $archiveFileList to add the file to the existing list (first entry was filled when function was called, we add here the next one)
1071 $objectDirPath = '';
1072 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1073 if ($line->doc_type == 'customer_invoice') {
1074 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1075 } elseif ($line->doc_type == 'expense_report') {
1076 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1077 } elseif ($line->doc_type == 'supplier_invoice') {
1078 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1079 $invoice = new FactureFournisseur($this->db);
1080 $invoice->fetch($line->fk_doc);
1081 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1082 $objectDirPath .= '/'.rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1083 }
1084
1085 if ($objectDirPath && empty($conf->cache['archiveFileList_notfound'][$attachmentFileKey])) {
1086 $arrayofinclusion = array();
1087 // If it is a supplier invoice, we want to use last uploaded file
1088 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1089
1090 $fileFoundPath = '';
1091 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1092
1093 if (!empty($fileFoundList)) {
1094 $attachmentFileNameTrunc = str_pad(self::trunc((string) $line->piece_num, 8), 8, '0', STR_PAD_LEFT);
1095
1096 foreach ($fileFoundList as $fileFound) {
1097 if (strstr($fileFound['name'], $objectFileName)) {
1098 // skip native invoice pdfs (canelle)
1099 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1100 if ($line->doc_type == 'supplier_invoice') {
1101 if ($fileFound['name'] === $objectFileName.'.pdf') {
1102 continue;
1103 }
1104 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1105 continue;
1106 }
1107 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1108 if (file_exists($fileFoundPath)) {
1109 $archiveFileList[$attachmentFileKey] = array(
1110 'path' => $fileFoundPath,
1111 'name' => $attachmentFileNameTrunc.'.pdf',
1112 );
1113 break;
1114 }
1115 }
1116 }
1117 }
1118
1119 if (empty($fileFoundPath)) {
1120 // Use also a cache if no file were found
1121 $conf->cache['archiveFileList_notfound'][$attachmentFileKey] = 1;
1122 }
1123 }
1124 }
1125
1126 if (isset($archiveFileList[$attachmentFileKey])) {
1127 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1128 }
1129 }
1130
1131 if (dol_strlen((string) $attachmentFileName) == 12) {
1132 $tab['attachment'] = $attachmentFileName; // position 182
1133 } else {
1134 $tab['attachment'] = str_repeat(' ', 12); // position 182
1135 }
1136 $tab['filler4'] = str_repeat(' ', 38);
1137 $tab['end_line'] = $end_line;
1138
1139 if ($exportFile) {
1140 fwrite($exportFile, implode($tab));
1141 } else {
1142 print implode($tab);
1143 }
1144 }
1145
1146 return $archiveFileList;
1147 }
1148
1159 public function exportWinfic($objectLines, $exportFile = null)
1160 {
1161 global $conf;
1162
1163 $end_line = "\r\n";
1164 $index = 1;
1165
1166 // Warning ! When truncation is necessary, no dot because 3 dots = three characters. The columns are shifted
1167
1168 foreach ($objectLines as $line) {
1169 $code_compta = $line->numero_compte;
1170 if (!empty($line->subledger_account)) {
1171 $code_compta = $line->subledger_account;
1172 }
1173
1174 $tab = array();
1175 //$tab['type_ligne'] = 'M';
1176 $tab['code_journal'] = str_pad(dol_trunc($line->code_journal, 2, 'right', 'UTF-8', 1), 2);
1177
1178 //We use invoice date $line->doc_date not $date_ecriture which is the transfer date
1179 //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
1180 //$tab['date_ecriture'] = $date_ecriture;
1181 $tab['date_operation'] = dol_print_date($line->doc_date, '%d%m%Y');
1182
1183 $tab['folio'] = ' 1';
1184
1185 $tab['num_ecriture'] = str_pad(dol_trunc((string) $index, 6, 'right', 'UTF-8', 1), 6, ' ', STR_PAD_LEFT);
1186
1187 $tab['jour_ecriture'] = dol_print_date($line->doc_date, '%d%m%y');
1188
1189 $tab['num_compte'] = str_pad(dol_trunc((string) $code_compta, 6, 'right', 'UTF-8', 1), 6, '0');
1190
1191 if ($line->sens == 'D') {
1192 $tab['montant_debit'] = str_pad(number_format($line->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1193
1194 $tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1195 } else {
1196 $tab['montant_debit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1197
1198 $tab['montant_crebit'] = str_pad(number_format($line->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1199 }
1200
1201 $tab['libelle_ecriture'] = str_pad(dol_trunc(dol_string_unaccent($line->doc_ref).' '.dol_string_unaccent($line->label_operation), 30, 'right', 'UTF-8', 1), 30);
1202
1203 $tab['lettrage'] = str_repeat(dol_trunc((string) $line->lettering_code, 2, 'left', 'UTF-8', 1), 2);
1204
1205 $tab['code_piece'] = str_pad(dol_trunc((string) $line->piece_num, 5, 'left', 'UTF-8', 1), 5, ' ', STR_PAD_LEFT);
1206
1207 $tab['code_stat'] = str_repeat(' ', 4);
1208
1209 if (!empty($line->date_lim_reglement)) {
1210 $tab['date_echeance'] = dol_print_date($line->date_lim_reglement, '%d%m%Y');
1211 } else {
1212 $tab['date_echeance'] = dol_print_date($line->doc_date, '%d%m%Y');
1213 }
1214
1215 $tab['monnaie'] = '1';
1216
1217 $tab['filler'] = ' ';
1218
1219 $tab['ind_compteur'] = ' ';
1220
1221 $tab['quantite'] = '0,000000000';
1222
1223 $tab['code_pointage'] = str_repeat(' ', 2);
1224
1225 $tab['end_line'] = $end_line;
1226
1227 $output = implode('|', $tab);
1228 if ($exportFile) {
1229 fwrite($exportFile, $output);
1230 } else {
1231 print $output;
1232 }
1233
1234 $index++;
1235 }
1236 }
1237
1238
1246 public function exportEbp($objectLines, $exportFile = null)
1247 {
1248 $separator = ',';
1249 $end_line = "\n";
1250
1251 foreach ($objectLines as $line) {
1252 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
1253
1254 $tab = array();
1255
1256 $tab[] = $line->id;
1257 $tab[] = $date_document;
1258 $tab[] = $line->code_journal;
1259 if (empty($line->subledger_account)) {
1260 $tab[] = $line->numero_compte;
1261 } else {
1262 $tab[] = $line->subledger_account;
1263 }
1264 //$tab[] = substr(length_accountg($line->numero_compte), 0, 2) . $separator;
1265 $tab[] = '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"';
1266 $tab[] = '"'.dol_trunc((string) $line->piece_num, 15, 'right', 'UTF-8', 1).'"';
1267 $tab[] = price2num(abs($line->debit - $line->credit));
1268 $tab[] = $line->sens;
1269 $tab[] = $date_document;
1270 //print 'EUR';
1271
1272 $output = implode($separator, $tab).$end_line;
1273 if ($exportFile) {
1274 fwrite($exportFile, $output);
1275 } else {
1276 print $output;
1277 }
1278 }
1279 }
1280
1281
1289 public function exportAgiris($objectLines, $exportFile = null)
1290 {
1291 $separator = ';';
1292 $end_line = "\n";
1293
1294 foreach ($objectLines as $line) {
1295 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
1296
1297 $tab = array();
1298
1299 $tab[] = $line->piece_num;
1300 $tab[] = self::toAnsi($line->label_operation);
1301 $tab[] = $date_document;
1302 $tab[] = self::toAnsi($line->label_operation);
1303
1304 if (empty($line->subledger_account)) {
1305 $tab[] = length_accountg($line->numero_compte);
1306 $tab[] = self::toAnsi($line->label_compte);
1307 } else {
1308 $tab[] = length_accounta($line->subledger_account);
1309 $tab[] = self::toAnsi($line->subledger_label);
1310 }
1311
1312 $tab[] = self::toAnsi($line->doc_ref);
1313 $tab[] = price($line->debit);
1314 $tab[] = price($line->credit);
1315 $tab[] = price(abs($line->debit - $line->credit));
1316 $tab[] = $line->sens;
1317 $tab[] = $line->lettering_code;
1318 $tab[] = $line->code_journal;
1319
1320 $output = implode($separator, $tab).$end_line;
1321 if ($exportFile) {
1322 fwrite($exportFile, $output);
1323 } else {
1324 print $output;
1325 }
1326 }
1327 }
1328
1336 public function exportOpenConcerto($objectLines, $exportFile = null)
1337 {
1338 $separator = ';';
1339 $end_line = "\n";
1340
1341 foreach ($objectLines as $line) {
1342 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
1343
1344 $tab = array();
1345
1346 $tab[] = $date_document;
1347 $tab[] = $line->code_journal;
1348 if (empty($line->subledger_account)) {
1349 $tab[] = length_accountg($line->numero_compte);
1350 } else {
1351 $tab[] = length_accounta($line->subledger_account);
1352 }
1353 $tab[] = $line->doc_ref;
1354 $tab[] = $line->label_operation;
1355 $tab[] = price($line->debit);
1356 $tab[] = price($line->credit);
1357
1358 $output = implode($separator, $tab).$end_line;
1359 if ($exportFile) {
1360 fwrite($exportFile, $output);
1361 } else {
1362 print $output;
1363 }
1364 }
1365 }
1366
1374 public function exportConfigurable($objectLines, $exportFile = null)
1375 {
1376 global $conf;
1377
1378 $separator = $this->separator;
1379
1380 foreach ($objectLines as $line) {
1381 $date_document = dol_print_date($line->doc_date, getDolGlobalString('ACCOUNTING_EXPORT_DATE'));
1382
1383 $tab = array();
1384 // export configurable
1385 $tab[] = $line->piece_num;
1386 $tab[] = $date_document;
1387 $tab[] = $line->doc_ref;
1388 $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
1389 $tab[] = length_accountg($line->numero_compte);
1390 $tab[] = length_accounta($line->subledger_account);
1391 $tab[] = price2num($line->debit);
1392 $tab[] = price2num($line->credit);
1393 $tab[] = price2num($line->debit - $line->credit);
1394 $tab[] = $line->code_journal;
1395
1396 $output = implode($separator, $tab).$this->end_line;
1397 if ($exportFile) {
1398 fwrite($exportFile, $output);
1399 } else {
1400 print $output;
1401 }
1402 }
1403 }
1404
1412 public function exportISTEA($objectLines, $exportFile = null)
1413 {
1414 global $conf;
1415
1416 $separator = ';';
1417 $end_line = "\n";
1418
1419 // Extract the Third party account numbers from the table to provide the correct line for ISTEA
1420 $tiers = [];
1421 foreach ($objectLines as $line) {
1422 if ($line->subledger_account && substr($line->subledger_account, 0, 1) == '4') {
1423 $tiers[$line->piece_num] = $line->subledger_label;
1424 }
1425 }
1426
1427 foreach ($objectLines as $line) {
1428 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
1429
1430 /*** preparation du champ label operation pour istea ***/
1431 // retrecissement du champs car ISTEA n'affiche pas bcp de caract�re.
1432 $search = array('Paiement fournisseur ', 'Virement ', 'Paiement ');
1433 $replace = array('Paiemt fourn ','Virt ','Paiemt ');
1434 $label_operation = str_replace($search, $replace, $line->label_operation);
1435 // encadrement par des ' si le champs contient le separateur
1436 $label_operation = preg_match('/'.$separator.'/', $label_operation) ? "'".$label_operation."'" : $label_operation;
1437
1438 $tab = array();
1439 // export configurable
1440 $tab[] = $line->piece_num; // colonne 1 : numero de piece ISTEA
1441 $tab[] = $date_document; // colonne 2 : date ISTEA
1442 $tab[] = $line->doc_ref; // colonne 3 : reference piece ISTEA
1443 $tab[] = array_key_exists($line->piece_num, $tiers) ? $tiers[$line->piece_num] : ''; // colonne 4 : nom tiers ISTEA
1444 $tab[] = length_accountg(($line->subledger_account && (substr($line->subledger_account, 0, 2) == substr($line->numero_compte, 0, 2))) ? $line->subledger_account : $line->numero_compte); // colonne 5 : numero de compte ISTEA
1445 $tab[] = length_accountg($line->subledger_account ? $line->subledger_account : $line->numero_compte); // colonne 6 : numero de compte
1446 $tab[] = length_accountg($line->subledger_account ? $line->numero_compte : ''); // G // colonne 7 : numero de compte principal (divers paiement ou 40100000 ou 41100000)
1447 $tab[] = ($line->doc_type == 'bank') ? $label_operation : ($line->subledger_account ? $line->subledger_label : $line->label_compte); // colonne 8 : label de l'operation ISTEA
1448 $tab[] = $label_operation; // colonne 9 : label de l'operation (semble non prise en compte par ISTEA)
1449 $tab[] = price2num($line->debit); // colonne 10 : debit ISTEA
1450 $tab[] = price2num($line->credit); // colonne 11 : credit ISTEA
1451 $tab[] = $line->code_journal; // colonne 12 : journal ISTEA
1452
1453 $output = mb_convert_encoding('"'.implode('"'.$separator.'"', $tab).'"'.$this->end_line, 'ISO-8859-1');
1454 if ($exportFile) {
1455 fwrite($exportFile, $output);
1456 } else {
1457 print $output;
1458 }
1459 }
1460 }
1461
1474 public function exportFEC($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
1475 {
1476 global $conf, $langs;
1477
1478 $separator = "\t";
1479 $end_line = "\r\n";
1480
1481 $tab = array();
1482 $tab[] = "JournalCode";
1483 $tab[] = "JournalLib";
1484 $tab[] = "EcritureNum";
1485 $tab[] = "EcritureDate";
1486 $tab[] = "CompteNum";
1487 $tab[] = "CompteLib";
1488 $tab[] = "CompAuxNum";
1489 $tab[] = "CompAuxLib";
1490 $tab[] = "PieceRef";
1491 $tab[] = "PieceDate";
1492 $tab[] = "EcritureLib";
1493 $tab[] = "Debit";
1494 $tab[] = "Credit";
1495 $tab[] = "EcritureLet";
1496 $tab[] = "DateLet";
1497 $tab[] = "ValidDate";
1498 $tab[] = "Montantdevise";
1499 $tab[] = "Idevise";
1500 $tab[] = "DateLimitReglmt";
1501 $tab[] = "NumFacture";
1502 $tab[] = "FichierFacture";
1503
1504 $output = implode($separator, $tab).$end_line;
1505 if ($exportFile) {
1506 fwrite($exportFile, $output);
1507 } else {
1508 print $output;
1509 }
1510
1511 $conf->cache['archiveFileList_notfound'] = array();
1512
1513 $i = 0;
1514 foreach ($objectLines as $line) {
1515 if ($line->debit == 0 && $line->credit == 0) {
1516 //var_dump($line->id);
1517 //unset($array[$line]);
1518 } else {
1519 $i++;
1520
1521 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1522 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1523 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1524 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1525 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1526
1527 $refInvoice = '';
1528 $invoice = null;
1529 // TODO The fetch of invoice is just to get the ->id, ->ref (and ->ref_supplier for supplier invoice) so
1530 // may be we can get them into the $objectLines and reuse a generic static objectinstead ?
1531 if ($line->doc_type == 'customer_invoice') {
1532 // Customer invoice
1533 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1534 $invoice = new Facture($this->db);
1535 $invoice->fetch($line->fk_doc);
1536
1537 $refInvoice = (string) $invoice->ref;
1538 } elseif ($line->doc_type == 'supplier_invoice') {
1539 // Supplier invoice
1540 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1541 $invoice = new FactureFournisseur($this->db);
1542 $invoice->fetch($line->fk_doc);
1543
1544 $refInvoice = (string) $invoice->ref_supplier;
1545 }
1546
1547 $tab = array();
1548
1549 // FEC:JournalCode
1550 $tab[] = $line->code_journal;
1551
1552 // FEC:JournalLib
1553 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1554 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1555 $tab[] = $labeljournal;
1556
1557 // FEC:EcritureNum
1558 $tab[] = $line->piece_num;
1559
1560 // FEC:EcritureDate
1561 $tab[] = $date_document;
1562
1563 // FEC:CompteNum
1564 $tab[] = length_accountg($line->numero_compte);
1565
1566 // FEC:CompteLib
1567 $tab[] = dol_string_unaccent($line->label_compte);
1568
1569 // FEC:CompAuxNum
1570 $tab[] = length_accounta($line->subledger_account);
1571
1572 // FEC:CompAuxLib
1573 $tab[] = dol_string_unaccent($line->subledger_label);
1574
1575 // FEC:PieceRef
1576 $tab[] = $line->doc_ref;
1577
1578 // FEC:PieceDate
1579 $tab[] = dol_string_unaccent($date_creation);
1580
1581 // FEC:EcritureLib
1582 // Clean label operation to prevent problem on export with tab separator & other character
1583 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1584 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1585 $tab[] = dol_string_unaccent($line->label_operation);
1586
1587 // FEC:Debit
1588 $tab[] = price2fec($line->debit);
1589
1590 // FEC:Credit
1591 $tab[] = price2fec($line->credit);
1592
1593 // FEC:EcritureLet
1594 $tab[] = $line->lettering_code;
1595
1596 // FEC:DateLet
1597 $tab[] = $date_lettering;
1598
1599 // FEC:ValidDate
1600 $tab[] = $date_validation;
1601
1602 // FEC:Montantdevise
1603 $tab[] = $line->multicurrency_amount;
1604
1605 // FEC:Idevise
1606 $tab[] = $line->multicurrency_code;
1607
1608 // FEC_suppl:DateLimitReglmt
1609 $tab[] = $date_limit_payment;
1610
1611 // FEC_suppl:NumFacture
1612 // Clean ref invoice to prevent problem on export with tab separator & other character
1613 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1614 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1615
1616 // FEC_suppl:FichierFacture
1617 // get document file
1618 $attachmentFileName = '';
1619 if ($withAttachment == 1) {
1620 $attachmentFileKey = trim((string) $line->piece_num);
1621
1622 if (!isset($archiveFileList[$attachmentFileKey])) {
1623 // 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)
1624 $objectDirPath = '';
1625 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1626 if ($line->doc_type == 'customer_invoice') {
1627 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1628 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1629 }
1630 } elseif ($line->doc_type == 'expense_report') {
1631 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1632 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1633 }
1634 } elseif ($line->doc_type == 'supplier_invoice' && $invoice instanceof FactureFournisseur) {
1635 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1636 '@phan-var-force FactureFournisseur $invoice';
1637 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1638 $objectDirPath .= '/' . rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1639 }
1640 }
1641
1642 if ($objectDirPath && empty($conf->cache['archiveFileList_notfound'][$attachmentFileKey])) {
1643 $arrayofinclusion = array();
1644 // If it is a supplier invoice, we want to use last uploaded file
1645 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1646
1647 $fileFoundPath = ''; // The path of last file found
1648 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1649
1650 if (!empty($fileFoundList)) {
1651 $attachmentFileNameTrunc = $line->doc_ref;
1652
1653 foreach ($fileFoundList as $fileFound) {
1654 if (strstr($fileFound['name'], $objectFileName)) {
1655 // skip native invoice pdfs (canelle)
1656 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1657 if ($line->doc_type == 'supplier_invoice') {
1658 if ($fileFound['name'] === $objectFileName.'.pdf') {
1659 continue;
1660 }
1661 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1662 continue;
1663 }
1664 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1665 if (file_exists($fileFoundPath)) {
1666 $archiveFileList[$attachmentFileKey] = array(
1667 'path' => $fileFoundPath,
1668 'name' => $attachmentFileNameTrunc.'.pdf',
1669 );
1670 break;
1671 }
1672 }
1673 }
1674 }
1675
1676 if (empty($fileFoundPath)) {
1677 // Use also a cache if no file were found
1678 $conf->cache['archiveFileList_notfound'][$attachmentFileKey] = 1;
1679 }
1680 }
1681 }
1682
1683 if (isset($archiveFileList[$attachmentFileKey])) {
1684 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1685 }
1686 }
1687
1688 $tab[] = $attachmentFileName;
1689
1690 $output = implode($separator, $tab).$end_line;
1691
1692 if ($exportFile) {
1693 fwrite($exportFile, $output);
1694 } else {
1695 print $output;
1696 }
1697 }
1698 }
1699
1700 return $archiveFileList;
1701 }
1702
1715 public function exportFEC2($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
1716 {
1717 global $conf, $langs;
1718
1719 $separator = "\t";
1720 $end_line = "\r\n";
1721
1722 $tab = array();
1723 $tab[] = "JournalCode";
1724 $tab[] = "JournalLib";
1725 $tab[] = "EcritureNum";
1726 $tab[] = "EcritureDate";
1727 $tab[] = "CompteNum";
1728 $tab[] = "CompteLib";
1729 $tab[] = "CompAuxNum";
1730 $tab[] = "CompAuxLib";
1731 $tab[] = "PieceRef";
1732 $tab[] = "PieceDate";
1733 $tab[] = "EcritureLib";
1734 $tab[] = "Debit";
1735 $tab[] = "Credit";
1736 $tab[] = "EcritureLet";
1737 $tab[] = "DateLet";
1738 $tab[] = "ValidDate";
1739 $tab[] = "Montantdevise";
1740 $tab[] = "Idevise";
1741 $tab[] = "DateLimitReglmt";
1742 $tab[] = "NumFacture";
1743 $tab[] = "FichierFacture";
1744
1745 $output = implode($separator, $tab).$end_line;
1746 if ($exportFile) {
1747 fwrite($exportFile, $output);
1748 } else {
1749 print $output;
1750 }
1751
1752 $conf->cache['archiveFileList_notfound'] = array();
1753
1754 $i = 0;
1755 foreach ($objectLines as $line) {
1756 if ($line->debit == 0 && $line->credit == 0) {
1757 //unset($array[$line]);
1758 } else {
1759 $i++;
1760
1761 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1762 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1763 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1764 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1765 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1766
1767 $refInvoice = '';
1768 $invoice = null;
1769 // TODO The fetch of invoice is just to get the ->id, ->ref (and ->ref_supplier for supplier invoice) so
1770 // may be we can get them into the $objectLines and reuse a generic static objectinstead ?
1771 if ($line->doc_type == 'customer_invoice') {
1772 // Customer invoice
1773 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1774 $invoice = new Facture($this->db);
1775 $invoice->fetch($line->fk_doc);
1776
1777 $refInvoice = (string) $invoice->ref;
1778 } elseif ($line->doc_type == 'supplier_invoice') {
1779 // Supplier invoice
1780 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1781 $invoice = new FactureFournisseur($this->db);
1782 $invoice->fetch($line->fk_doc);
1783
1784 $refInvoice = (string) $invoice->ref_supplier;
1785 }
1786
1787 $tab = array();
1788
1789 // FEC:JournalCode
1790 $tab[] = $line->code_journal;
1791
1792 // FEC:JournalLib
1793 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1794 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1795 $tab[] = $labeljournal;
1796
1797 // FEC:EcritureNum
1798 $tab[] = $line->piece_num;
1799
1800 // FEC:EcritureDate
1801 $tab[] = $date_creation;
1802
1803 // FEC:CompteNum
1804 $tab[] = length_accountg($line->numero_compte);
1805
1806 // FEC:CompteLib
1807 $tab[] = dol_string_unaccent($line->label_compte);
1808
1809 // FEC:CompAuxNum
1810 $tab[] = length_accounta($line->subledger_account);
1811
1812 // FEC:CompAuxLib
1813 $tab[] = dol_string_unaccent($line->subledger_label);
1814
1815 // FEC:PieceRef
1816 $tab[] = $line->doc_ref;
1817
1818 // FEC:PieceDate
1819 $tab[] = $date_document;
1820
1821 // FEC:EcritureLib
1822 // Clean label operation to prevent problem on export with tab separator & other character
1823 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1824 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1825 $tab[] = dol_string_unaccent($line->label_operation);
1826
1827 // FEC:Debit
1828 $tab[] = price2fec($line->debit);
1829
1830 // FEC:Credit
1831 $tab[] = price2fec($line->credit);
1832
1833 // FEC:EcritureLet
1834 $tab[] = $line->lettering_code;
1835
1836 // FEC:DateLet
1837 $tab[] = $date_lettering;
1838
1839 // FEC:ValidDate
1840 $tab[] = $date_validation;
1841
1842 // FEC:Montantdevise
1843 $tab[] = $line->multicurrency_amount;
1844
1845 // FEC:Idevise
1846 $tab[] = $line->multicurrency_code;
1847
1848 // FEC_suppl:DateLimitReglmt
1849 $tab[] = $date_limit_payment;
1850
1851 // FEC_suppl:NumFacture
1852 // Clean ref invoice to prevent problem on export with tab separator & other character
1853 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1854 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1855
1856 // FEC_suppl:FichierFacture
1857 // get document file
1858 $attachmentFileName = '';
1859 if ($withAttachment == 1) {
1860 $attachmentFileKey = trim((string) $line->piece_num);
1861
1862 if (!isset($archiveFileList[$attachmentFileKey])) {
1863 // 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)
1864 $objectDirPath = '';
1865 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1866 if ($line->doc_type == 'customer_invoice') {
1867 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1868 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1869 }
1870 } elseif ($line->doc_type == 'expense_report') {
1871 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1872 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1873 }
1874 } elseif ($line->doc_type == 'supplier_invoice' && $invoice instanceof FactureFournisseur) {
1875 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1876 '@phan-var-force FactureFournisseur $invoice';
1877 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1878 $objectDirPath .= '/' . rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1879 }
1880 }
1881
1882 if ($objectDirPath && empty($conf->cache['archiveFileList_notfound'][$attachmentFileKey])) {
1883 $arrayofinclusion = array();
1884 // If it is a supplier invoice, we want to use last uploaded file
1885 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1886
1887 $fileFoundPath = ''; // The path of last file found
1888 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1889
1890 if (!empty($fileFoundList)) {
1891 $attachmentFileNameTrunc = $line->doc_ref;
1892
1893 foreach ($fileFoundList as $fileFound) {
1894 if (strstr($fileFound['name'], $objectFileName)) {
1895 // skip native invoice pdfs (canelle)
1896 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1897 if ($line->doc_type == 'supplier_invoice') {
1898 if ($fileFound['name'] === $objectFileName.'.pdf') {
1899 continue;
1900 }
1901 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1902 continue;
1903 }
1904 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1905 if (file_exists($fileFoundPath)) {
1906 $archiveFileList[$attachmentFileKey] = array(
1907 'path' => $fileFoundPath,
1908 'name' => $attachmentFileNameTrunc.'.pdf',
1909 );
1910 break;
1911 }
1912 }
1913 }
1914 }
1915
1916 if (empty($fileFoundPath)) {
1917 // Use also a cache if no file were found
1918 $conf->cache['archiveFileList_notfound'][$attachmentFileKey] = 1;
1919 }
1920 }
1921 }
1922
1923 if (isset($archiveFileList[$attachmentFileKey])) {
1924 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1925 }
1926 }
1927
1928 $tab[] = $attachmentFileName;
1929
1930 $output = implode($separator, $tab).$end_line;
1931 if ($exportFile) {
1932 fwrite($exportFile, $output);
1933 } else {
1934 print $output;
1935 }
1936 }
1937 }
1938
1939 return $archiveFileList;
1940 }
1941
1952 public function exportSAGE50SWISS($objectLines, $exportFile = null)
1953 {
1954 // SAGE50SWISS
1955 $separator = ',';
1956 $end_line = "\r\n";
1957
1958 // Print header line
1959 $tab = array();
1960
1961 $tab[] = "Blg";
1962 $tab[] = "Datum";
1963 $tab[] = "Kto";
1964 $tab[] = "S/H";
1965 $tab[] = "Grp";
1966 $tab[] = "GKto";
1967 $tab[] = "SId";
1968 $tab[] = "SIdx";
1969 $tab[] = "KIdx";
1970 $tab[] = "BTyp";
1971 $tab[] = "MTyp";
1972 $tab[] = "Code";
1973 $tab[] = "Netto";
1974 $tab[] = "Steuer";
1975 $tab[] = "FW-Betrag";
1976 $tab[] = "Tx1";
1977 $tab[] = "Tx2";
1978 $tab[] = "PkKey";
1979 $tab[] = "OpId";
1980 $tab[] = "Flag";
1981
1982 $output = implode($separator, $tab).$end_line;
1983 if ($exportFile) {
1984 fwrite($exportFile, $output);
1985 } else {
1986 print $output;
1987 }
1988
1989 $thisPieceNum = "";
1990 $thisPieceAccountNr = "";
1991 $aSize = count($objectLines);
1992 foreach ($objectLines as $aIndex => $line) {
1993 $sammelBuchung = false;
1994 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1995 $sammelBuchung = true;
1996 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1997 $sammelBuchung = true;
1998 } elseif ($aIndex + 1 < $aSize
1999 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
2000 && $aIndex - 1 < $aSize
2001 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
2002 ) {
2003 $sammelBuchung = true;
2004 }
2005
2006 $tab = array();
2007
2008 //Blg
2009 $tab[] = $line->piece_num;
2010
2011 // Datum
2012 $date_document = dol_print_date($line->doc_date, '%d.%m.%Y');
2013 $tab[] = $date_document;
2014
2015 // Kto
2016 $tab[] = length_accountg($line->numero_compte);
2017 // S/H
2018 if ($line->sens == 'D') {
2019 $tab[] = 'S';
2020 } else {
2021 $tab[] = 'H';
2022 }
2023 // Grp
2024 $tab[] = self::trunc($line->code_journal, 1);
2025 // GKto
2026 if (empty($line->code_tiers)) {
2027 if ($line->piece_num == $thisPieceNum) {
2028 $tab[] = length_accounta($thisPieceAccountNr);
2029 } else {
2030 $tab[] = "div";
2031 }
2032 } else {
2033 $tab[] = length_accounta($line->code_tiers);
2034 }
2035 // SId
2036 $tab[] = $this->separator;
2037 // SIdx
2038 $tab[] = "0";
2039 // KIdx
2040 $tab[] = "0";
2041 // BTyp
2042 $tab[] = "0";
2043
2044 // MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
2045 if ($sammelBuchung) {
2046 $tab[] = "2";
2047 } else {
2048 $tab[] = "1";
2049 }
2050 // Code
2051 $tab[] = '""';
2052 // Netto
2053 $tab[] = abs($line->debit - $line->credit);
2054 // Steuer
2055 $tab[] = "0.00";
2056 // FW-Betrag
2057 $tab[] = "0.00";
2058 // Tx1
2059 $line1 = self::toAnsi($line->label_compte, 29);
2060 if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
2061 $line1 = "";
2062 }
2063 $line2 = self::toAnsi($line->doc_ref, 29);
2064 if (strlen($line1) == 0) {
2065 $line1 = $line2;
2066 $line2 = "";
2067 }
2068 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
2069 $line1 = $line1.' / '.$line2;
2070 $line2 = "";
2071 }
2072
2073 $tab[] = '"'.self::toAnsi($line1).'"';
2074 // Tx2
2075 $tab[] = '"'.self::toAnsi($line2).'"';
2076 //PkKey
2077 $tab[] = "0";
2078 //OpId
2079 $tab[] = $this->separator;
2080
2081 // Flag
2082 $tab[] = "0";
2083
2084 $output = implode($separator, $tab).$end_line;
2085 if ($exportFile) {
2086 fwrite($exportFile, $output);
2087 } else {
2088 print $output;
2089 }
2090
2091 if ($line->piece_num !== $thisPieceNum) {
2092 $thisPieceNum = $line->piece_num;
2093 $thisPieceAccountNr = $line->numero_compte;
2094 }
2095 }
2096 }
2097
2106 public function exportLDCompta($objectLines, $exportFile = null)
2107 {
2108 $separator = ';';
2109 $end_line = "\r\n";
2110
2111 foreach ($objectLines as $line) {
2112 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2113 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
2114 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2115
2116 $tab = array();
2117
2118 // TYPE
2119 $type_enregistrement = 'E'; // For write movement
2120 $tab[] = $type_enregistrement;
2121 // JNAL
2122 $tab[] = substr($line->code_journal, 0, 2);
2123 // NECR
2124 $tab[] = $line->id;
2125 // NPIE
2126 $tab[] = $line->piece_num;
2127 // DATP
2128 $tab[] = $date_document;
2129 // LIBE
2130 $tab[] = $line->label_operation;
2131 // DATH
2132 $tab[] = $date_lim_reglement;
2133 // CNPI
2134 if ($line->doc_type == 'supplier_invoice') {
2135 if (($line->debit - $line->credit) > 0) {
2136 $nature_piece = 'AF';
2137 } else {
2138 $nature_piece = 'FF';
2139 }
2140 } elseif ($line->doc_type == 'customer_invoice') {
2141 if (($line->debit - $line->credit) < 0) {
2142 $nature_piece = 'AC';
2143 } else {
2144 $nature_piece = 'FC';
2145 }
2146 } else {
2147 $nature_piece = '';
2148 }
2149 $tab[] = $nature_piece;
2150 // RACI
2151 // if (!empty($line->subledger_account)) {
2152 // if ($line->doc_type == 'supplier_invoice') {
2153 // $racine_subledger_account = '40';
2154 // } elseif ($line->doc_type == 'customer_invoice') {
2155 // $racine_subledger_account = '41';
2156 // } else {
2157 // $racine_subledger_account = '';
2158 // }
2159 // } else {
2160 $racine_subledger_account = ''; // for records of type E leave this field blank
2161 // }
2162
2163 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2164 // MONT
2165 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2, 2);
2166 // CODC
2167 $tab[] = $line->sens;
2168 // CPTG
2169 $tab[] = length_accountg($line->numero_compte);
2170 // DATE
2171 $tab[] = $date_creation;
2172 // CLET
2173 $tab[] = $line->lettering_code;
2174 // DATL
2175 $tab[] = $line->date_lettering;
2176 // CPTA
2177 if (!empty($line->subledger_account)) {
2178 $tab[] = length_accounta($line->subledger_account);
2179 } else {
2180 $tab[] = "";
2181 }
2182 // C.N.A.T
2183 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2184 $tab[] = 'F';
2185 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2186 $tab[] = 'C';
2187 } else {
2188 $tab[] = "";
2189 }
2190 // SECT
2191 $tab[] = "";
2192 // CTRE
2193 $tab[] = "";
2194 // NORL
2195 $tab[] = "";
2196 // DATV
2197 $tab[] = "";
2198 // REFD
2199 $tab[] = $line->doc_ref;
2200 // CODH
2201 $tab[] = "";
2202 // NSEQ
2203 $tab[] = "";
2204 // MTDV
2205 $tab[] = '0';
2206 // CODV
2207 $tab[] = "";
2208 // TXDV
2209 $tab[] = '0';
2210 // MOPM
2211 $tab[] = "";
2212 // BONP
2213 $tab[] = "";
2214 // BQAF
2215 $tab[] = "";
2216 // ECES
2217 $tab[] = "";
2218 // TXTL
2219 $tab[] = "";
2220 // ECRM
2221 $tab[] = "";
2222 // DATK
2223 $tab[] = "";
2224 // HEUK
2225 $tab[] = "";
2226
2227 $output = implode($separator, $tab).$end_line;
2228 if ($exportFile) {
2229 fwrite($exportFile, $output);
2230 } else {
2231 print $output;
2232 }
2233 }
2234 }
2235
2246 public function exportLDCompta10($objectLines, $exportFile = null)
2247 {
2248 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
2249
2250 $separator = ';';
2251 $end_line = "\r\n";
2252 $last_codeinvoice = '';
2253
2254 foreach ($objectLines as $line) {
2255 // TYPE C
2256 if ($last_codeinvoice != $line->doc_ref) {
2257 //search company by customer code
2258 $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
2259 $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
2260 $resql = $this->db->query($sql);
2261
2262 if ($resql && $this->db->num_rows($resql) > 0) {
2263 $soc = $this->db->fetch_object($resql);
2264
2265 $address = array('', '', '');
2266 if (strpos($soc->address, "\n") !== false) {
2267 $address = explode("\n", $soc->address);
2268 if (is_array($address) && count($address) > 0) {
2269 foreach ($address as $key => $data) {
2270 $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
2271 $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
2272 }
2273 }
2274 } else {
2275 $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
2276 $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
2277 $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
2278 }
2279
2280 $tab = array();
2281
2282 $type_enregistrement = 'C';
2283 //TYPE
2284 $tab[] = $type_enregistrement;
2285 //NOCL
2286 $tab[] = $soc->code_client;
2287 //NMCM
2288 $tab[] = "";
2289 //LIBI
2290 $tab[] = "";
2291 //TITR
2292 $tab[] = "";
2293 //RSSO
2294 $tab[] = $soc->nom;
2295 //CAD1
2296 $tab[] = $address[0];
2297 //CAD2
2298 $tab[] = $address[1];
2299 //CAD3
2300 $tab[] = $address[2];
2301 //COPO
2302 $tab[] = $soc->zip;
2303 //BUDI
2304 $tab[] = substr($soc->town, 0, 40);
2305 //CPAY
2306 $tab[] = "";
2307 //PAYS
2308 $tab[] = substr(getCountry($soc->fk_pays), 0, 40);
2309 //NTEL
2310 $tab[] = $soc->phone;
2311 //TLEX
2312 $tab[] = "";
2313 //TLPO
2314 $tab[] = "";
2315 //TLCY
2316 $tab[] = "";
2317 //NINT
2318 $tab[] = "";
2319 //COMM
2320 $tab[] = "";
2321 //SIRE
2322 $tab[] = str_replace(" ", "", $soc->siret);
2323 //RIBP
2324 $tab[] = "";
2325 //DOBQ
2326 $tab[] = "";
2327 //IBBQ
2328 $tab[] = "";
2329 //COBQ
2330 $tab[] = "";
2331 //GUBQ
2332 $tab[] = "";
2333 //CPBQ
2334 $tab[] = "";
2335 //CLBQ
2336 $tab[] = "";
2337 //BIBQ
2338 $tab[] = "";
2339 //MOPM
2340 $tab[] = "";
2341 //DJPM
2342 $tab[] = "";
2343 //DMPM
2344 $tab[] = "";
2345 //REFM
2346 $tab[] = "";
2347 //SLVA
2348 $tab[] = "";
2349 //PLCR
2350 $tab[] = "";
2351 //ECFI
2352 $tab[] = "";
2353 //CREP
2354 $tab[] = "";
2355 //NREP
2356 $tab[] = "";
2357 //TREP
2358 $tab[] = "";
2359 //MREP
2360 $tab[] = "";
2361 //GRRE
2362 $tab[] = "";
2363 //LTTA
2364 $tab[] = "";
2365 //CACT
2366 $tab[] = "";
2367 //CODV
2368 $tab[] = "";
2369 //GRTR
2370 $tab[] = "";
2371 //NOFP
2372 $tab[] = "";
2373 //BQAF
2374 $tab[] = "";
2375 //BONP
2376 $tab[] = "";
2377 //CESC
2378 $tab[] = "";
2379
2380 $output = implode($separator, $tab).$end_line;
2381 if ($exportFile) {
2382 fwrite($exportFile, $output);
2383 } else {
2384 print $output;
2385 }
2386 }
2387 }
2388
2389 $tab = array();
2390
2391 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2392 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
2393 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2394
2395 // TYPE E
2396 $type_enregistrement = 'E'; // For write movement
2397 $tab[] = $type_enregistrement;
2398 // JNAL
2399 $tab[] = substr($line->code_journal, 0, 2);
2400 // NECR
2401 $tab[] = $line->id;
2402 // NPIE
2403 $tab[] = $line->piece_num;
2404 // DATP
2405 $tab[] = $date_document;
2406 // LIBE
2407 $tab[] = dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1);
2408 // DATH
2409 $tab[] = $date_lim_reglement;
2410 // CNPI
2411 if ($line->doc_type == 'supplier_invoice') {
2412 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.
2413 $nature_piece = 'AF';
2414 } else {
2415 $nature_piece = 'FF';
2416 }
2417 } elseif ($line->doc_type == 'customer_invoice') {
2418 if (($line->amount) < 0) {
2419 $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.
2420 } else {
2421 $nature_piece = 'FC';
2422 }
2423 } else {
2424 $nature_piece = '';
2425 }
2426 $tab[] = $nature_piece;
2427 // RACI
2428 // if (!empty($line->subledger_account)) {
2429 // if ($line->doc_type == 'supplier_invoice') {
2430 // $racine_subledger_account = '40';
2431 // } elseif ($line->doc_type == 'customer_invoice') {
2432 // $racine_subledger_account = '41';
2433 // } else {
2434 // $racine_subledger_account = '';
2435 // }
2436 // } else {
2437 $racine_subledger_account = ''; // for records of type E leave this field blank
2438 // }
2439
2440 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2441 // MONT
2442 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2);
2443 // CODC
2444 $tab[] = $line->sens;
2445 // CPTG
2446 $tab[] = length_accountg($line->numero_compte);
2447 // DATE
2448 $tab[] = $date_document;
2449 // CLET
2450 $tab[] = $line->lettering_code;
2451 // DATL
2452 $tab[] = $line->date_lettering;
2453 // CPTA
2454 if (!empty($line->subledger_account)) {
2455 $tab[] = length_accounta($line->subledger_account);
2456 } else {
2457 $tab[] = "";
2458 }
2459 // C.N.A.T
2460 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2461 $tab[] = 'F';
2462 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2463 $tab[] = 'C';
2464 } else {
2465 $tab[] = "";
2466 }
2467 // CTRE
2468 $tab[] = "";
2469 // NORL
2470 $tab[] = "";
2471 // DATV
2472 $tab[] = "";
2473 // REFD
2474 $tab[] = $line->doc_ref;
2475 // NECA
2476 $tab[] = '0';
2477 // CSEC
2478 $tab[] = "";
2479 // CAFF
2480 $tab[] = "";
2481 // CDES
2482 $tab[] = "";
2483 // QTUE
2484 $tab[] = "";
2485 // MTDV
2486 $tab[] = '0';
2487 // CODV
2488 $tab[] = "";
2489 // TXDV
2490 $tab[] = '0';
2491 // MOPM
2492 $tab[] = "";
2493 // BONP
2494 $tab[] = "";
2495 // BQAF
2496 $tab[] = "";
2497 // ECES
2498 $tab[] = "";
2499 // TXTL
2500 $tab[] = "";
2501 // ECRM
2502 $tab[] = "";
2503 // DATK
2504 $tab[] = "";
2505 // HEUK
2506 $tab[] = "";
2507
2508 $output = implode($separator, $tab).$end_line;
2509 if ($exportFile) {
2510 fwrite($exportFile, $output);
2511 } else {
2512 print $output;
2513 }
2514
2515 $last_codeinvoice = $line->doc_ref;
2516 }
2517 }
2518
2526 public function exportCharlemagne($objectLines, $exportFile = null)
2527 {
2528 global $langs;
2529 $langs->load('compta');
2530
2531 $separator = "\t";
2532 $end_line = "\n";
2533
2534 $tab = array();
2535
2536 $tab[] = $langs->transnoentitiesnoconv('Date');
2537 $tab[] = self::trunc($langs->transnoentitiesnoconv('Journal'), 6);
2538 $tab[] = self::trunc($langs->transnoentitiesnoconv('Account'), 15);
2539 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60);
2540 $tab[] = self::trunc($langs->transnoentitiesnoconv('Piece'), 20);
2541 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60);
2542 $tab[] = $langs->transnoentitiesnoconv('Amount');
2543 $tab[] = 'S';
2544 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15);
2545 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60);
2546 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15);
2547 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60);
2548 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15);
2549 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60);
2550
2551 $output = implode($separator, $tab).$end_line;
2552 if ($exportFile) {
2553 fwrite($exportFile, $output);
2554 } else {
2555 print $output;
2556 }
2557
2558 foreach ($objectLines as $line) {
2559 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2560
2561 $tab = array();
2562
2563 $tab[] = $date_document; //Date
2564
2565 $tab[] = self::trunc($line->code_journal, 6); //Journal code
2566
2567 if (!empty($line->subledger_account)) {
2568 $account = $line->subledger_account;
2569 } else {
2570 $account = $line->numero_compte;
2571 }
2572 $tab[] = self::trunc((string) $account, 15); //Account number
2573
2574 $tab[] = self::trunc($line->label_compte, 60); //Account label
2575 $tab[] = self::trunc($line->doc_ref, 20); //Piece
2576 // Clean label operation to prevent problem on export with tab separator & other character
2577 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
2578 $tab[] = self::trunc($line->label_operation, 60); //Operation label
2579 $tab[] = price(abs($line->debit - $line->credit)); //Amount
2580 $tab[] = $line->sens; //Direction
2581 $tab[] = ""; //Analytic
2582 $tab[] = ""; //Analytic
2583 $tab[] = ""; //Analytic
2584 $tab[] = ""; //Analytic
2585 $tab[] = ""; //Analytic
2586 $tab[] = ""; //Analytic
2587
2588 $output = implode($separator, $tab).$end_line;
2589 if ($exportFile) {
2590 fwrite($exportFile, $output);
2591 } else {
2592 print $output;
2593 }
2594 }
2595 }
2596
2604 public function exportGestimumV3($objectLines, $exportFile = null)
2605 {
2606 global $langs;
2607
2608 $separator = ',';
2609 $end_line = "\r\n";
2610
2611 $invoices_infos = array();
2612 $supplier_invoices_infos = array();
2613 foreach ($objectLines as $line) {
2614 if ($line->debit == 0 && $line->credit == 0) {
2615 //unset($array[$line]);
2616 } else {
2617 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
2618 $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2619
2620 $invoice_ref = $line->doc_ref;
2621 $company_name = "";
2622
2623 if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
2624 if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2625 ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2626 if ($line->doc_type == 'customer_invoice') {
2627 // Get new customer invoice ref and company name
2628 $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
2629 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
2630 $sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
2631 $resql = $this->db->query($sql);
2632 if ($resql) {
2633 if ($obj = $this->db->fetch_object($resql)) {
2634 // Save invoice infos
2635 $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2636 $invoice_ref = $obj->ref;
2637 $company_name = $obj->nom;
2638 }
2639 }
2640 } else {
2641 // Get new supplier invoice ref and company name
2642 $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
2643 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
2644 $sql .= ' WHERE ff.rowid = '.((int) $line->fk_doc);
2645 $resql = $this->db->query($sql);
2646 if ($resql) {
2647 if ($obj = $this->db->fetch_object($resql)) {
2648 // Save invoice infos
2649 $supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2650 $invoice_ref = $obj->ref;
2651 $company_name = $obj->nom;
2652 }
2653 }
2654 }
2655 } elseif ($line->doc_type == 'customer_invoice') {
2656 // Retrieve invoice infos
2657 $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
2658 $company_name = $invoices_infos[$line->fk_doc]['company_name'];
2659 } else {
2660 // Retrieve invoice infos
2661 $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
2662 $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
2663 }
2664 }
2665
2666 $tab = array();
2667
2668 $tab[] = $line->id;
2669 $tab[] = $date_document;
2670 $tab[] = substr($line->code_journal, 0, 4);
2671
2672 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
2673 $tab[] = length_accountg($line->subledger_account);
2674 } else {
2675 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2676 }
2677 //Auto label
2678 $tab[] = "";
2679 //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"';
2680 //Manual label
2681 $tab[] = dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1);
2682 //Document number
2683 $tab[] = dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1);
2684 //Currency
2685 $tab[] = 'EUR';
2686 //Amount
2687 $tab[] = price2num(abs($line->debit - $line->credit));
2688 //Direction
2689 $tab[] = $line->sens;
2690 //Matching code
2691 $tab[] = "";
2692 //Due date
2693 $tab[] = $date_echeance;
2694
2695 $output = implode($separator, $tab).$end_line;
2696 if ($exportFile) {
2697 fwrite($exportFile, $output);
2698 } else {
2699 print $output;
2700 }
2701 }
2702 }
2703 }
2704
2712 public function exportGestimumV5($objectLines, $exportFile = null)
2713 {
2714 $separator = ',';
2715 $end_line = "\r\n";
2716
2717 foreach ($objectLines as $line) {
2718 if ($line->debit == 0 && $line->credit == 0) {
2719 //unset($array[$line]);
2720 } else {
2721 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
2722
2723 $tab = array();
2724
2725 $tab[] = $line->id;
2726 $tab[] = $date_document;
2727 $tab[] = substr($line->code_journal, 0, 4);
2728 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
2729 $tab[] = length_accountg($line->subledger_account);
2730 } else {
2731 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2732 }
2733 $tab[] = "";
2734 $tab[] = '"'.dol_trunc(str_replace('"', '', $line->label_operation), 40, 'right', 'UTF-8', 1).'"';
2735 $tab[] = '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"';
2736 $tab[] = '"' . dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1) . '"';
2737 $tab[] = price2num(abs($line->debit - $line->credit));
2738 $tab[] = $line->sens;
2739 $tab[] = $date_document;
2740 $tab[] = "";
2741 $tab[] = "";
2742 $tab[] = 'EUR';
2743
2744 $output = implode($separator, $tab).$end_line;
2745 if ($exportFile) {
2746 fwrite($exportFile, $output);
2747 } else {
2748 print $output;
2749 }
2750 }
2751 }
2752 }
2753
2763 public function exportiSuiteExpert($objectLines, $exportFile = null)
2764 {
2765 $separator = ';';
2766 $end_line = "\r\n";
2767
2768
2769 foreach ($objectLines as $line) {
2770 $tab = array();
2771
2772 $date = dol_print_date($line->doc_date, '%d/%m/%Y');
2773
2774 $tab[] = $line->piece_num;
2775 $tab[] = $date;
2776 $tab[] = substr($date, 6, 4);
2777 $tab[] = substr($date, 3, 2);
2778 $tab[] = substr($date, 0, 2);
2779 $tab[] = $line->doc_ref;
2780 // Convert the UTF-8 string in latin9
2781 $tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
2782
2783 //Calculate account number length
2784 $taille_numero = strlen(length_accountg($line->numero_compte));
2785
2786 //Build generic customer and supplier account number
2787 $numero_cpt_client = '411';
2788 $numero_cpt_fourn = '401';
2789 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2790 $numero_cpt_client .= '0';
2791 $numero_cpt_fourn .= '0';
2792 }
2793
2794 //Build auxiliary accounts for customers and suppliers
2795 if (length_accountg($line->numero_compte) == $numero_cpt_client || length_accountg($line->numero_compte) == $numero_cpt_fourn) {
2796 $tab[] = rtrim(length_accounta($line->subledger_account), "0");
2797 } else {
2798 $tab[] = length_accountg($line->numero_compte);
2799 }
2800 $nom_client = explode(" - ", $line->label_operation);
2801 $tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
2802 $tab[] = price($line->debit);
2803 $tab[] = price($line->credit);
2804 $tab[] = price($line->montant);
2805 $tab[] = $line->code_journal;
2806
2807 $output = implode($separator, $tab).$end_line;
2808 if ($exportFile) {
2809 fwrite($exportFile, $output);
2810 } else {
2811 print $output;
2812 }
2813 }
2814 }
2815
2823 public static function trunc($str, $size)
2824 {
2825 return dol_trunc($str, $size, 'right', 'UTF-8', 1);
2826 }
2827
2835 public static function toAnsi($str, $size = -1)
2836 {
2837 $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
2838 if ($retVal >= 0 && $size >= 0) {
2839 $retVal = dol_substr($retVal, 0, $size, 'Windows-1251');
2840 }
2841 return $retVal;
2842 }
2843}
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
Manage the different format accountancy export.
exportCogilog($objectLines, $exportFile=null)
Export format : COGILOG Last review for this format : 2022-07-12 Alexandre Spangaro (aspangaro@open-d...
export(&$TData, $formatexportset, $withAttachment=0, $downloadMode=1, $outputMode=1, $noouput=1)
Function who chose which export to use with the default config, and make the export into a file.
exportAgiris($objectLines, $exportFile=null)
Export format : Agiris Isacompta.
exportQuadratus($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : Quadratus (Format ASCII) Format since 2015 compatible QuadraCOMPTA Last review for th...
exportWinfic($objectLines, $exportFile=null)
Export format : WinFic - eWinfic - WinSis Compta Last review for this format : 2022-11-01 Alexandre S...
exportSAGE50SWISS($objectLines, $exportFile=null)
Export format : SAGE50SWISS.
exportOpenConcerto($objectLines, $exportFile=null)
Export format : OpenConcerto.
exportEbp($objectLines, $exportFile=null)
Export format : EBP.
exportLDCompta10($objectLines, $exportFile=null)
Export format : LD Compta version 10 & higher Last review for this format : 08-15-2021 Alexandre Span...
exportCharlemagne($objectLines, $exportFile=null)
Export format : Charlemagne.
getTypeConfig()
Array with all export types available (key + label) and parameters for config.
exportFEC($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : FEC Last review for this format : 2023/10/12 Alexandre Spangaro (aspangaro@open-dsi....
exportISTEA($objectLines, $exportFile=null)
Export format : ISTEA.
exportLDCompta($objectLines, $exportFile=null)
Export format : LD Compta version 9 http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Docu...
exportBob50($objectLines, $exportFile=null)
Export format : BOB50.
exportGestimumV3($objectLines, $exportFile=null)
Export format : Gestimum V3.
static trunc($str, $size)
trunc
exportiSuiteExpert($objectLines, $exportFile=null)
Export format : iSuite Expert.
exportCiel($objectLines, $exportFile=null)
Export format : CIEL (Format XIMPORT) Format since 2003 compatible CIEL version > 2002 / Sage50 Last ...
getType($mode=0)
Array with all export type available (key + label)
static toAnsi($str, $size=-1)
toAnsi
exportConfigurable($objectLines, $exportFile=null)
Export format : Configurable CSV.
static getFormatCode($type)
Return string to summarize the format (Used to generated export filename)
exportFEC2($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : FEC2 Last review for this format : 2023/10/12 Alexandre Spangaro (aspangaro@open-dsi....
__construct(DoliDB $db)
Constructor.
exportCegid($objectLines, $exportFile=null)
Export format : CEGID.
exportCoala($objectLines, $exportFile=null)
Export format : COALA.
getMimeType($formatexportset)
Return the MIME type of a file.
exportGestimumV5($objectLines, $exportFile=null)
Export format : Gestimum V5.
Class to manage Dolibarr database access.
Class to manage suppliers invoices.
Class to manage invoices.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_filesize($pathoffile)
Return size of a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php: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)
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.