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