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