dolibarr 22.0.5
accountancyexport.class.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
6 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7 * Copyright (C) 2016 Pierre-Henry Favre <phf@atm-consulting.fr>
8 * Copyright (C) 2016-2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
9 * Copyright (C) 2022 Lionel Vessiller <lvessiller@open-dsi.fr>
10 * Copyright (C) 2013-2017 Olivier Geffroy <jeff@jeffinfo.com>
11 * Copyright (C) 2017 Elarifr. Ari Elbaz <github@accedinfo.com>
12 * Copyright (C) 2017-2024 Frédéric France <frederic.france@free.fr>
13 * Copyright (C) 2017 André Schild <a.schild@aarboard.ch>
14 * Copyright (C) 2020 Guillaume Alexandre <guillaume@tag-info.fr>
15 * Copyright (C) 2022 Joachim Kueter <jkueter@gmx.de>
16 * Copyright (C) 2022 Progiseize <a.bisotti@progiseize.fr>
17 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 3 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <https://www.gnu.org/licenses/>.
31 */
32
39require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
45
50{
51 // Types of export.
53 public static $EXPORT_TYPE_CONFIGURABLE = 1; // CSV
55 public static $EXPORT_TYPE_AGIRIS = 10;
57 public static $EXPORT_TYPE_EBP = 15;
59 public static $EXPORT_TYPE_CEGID = 20;
61 public static $EXPORT_TYPE_COGILOG = 25;
63 public static $EXPORT_TYPE_COALA = 30;
65 public static $EXPORT_TYPE_BOB50 = 35;
67 public static $EXPORT_TYPE_CIEL = 40;
69 public static $EXPORT_TYPE_SAGE50_SWISS = 45;
71 public static $EXPORT_TYPE_CHARLEMAGNE = 50;
73 public static $EXPORT_TYPE_QUADRATUS = 60;
75 public static $EXPORT_TYPE_WINFIC = 70;
77 public static $EXPORT_TYPE_OPENCONCERTO = 100;
79 public static $EXPORT_TYPE_LDCOMPTA = 110;
81 public static $EXPORT_TYPE_LDCOMPTA10 = 120;
83 public static $EXPORT_TYPE_GESTIMUMV3 = 130;
85 public static $EXPORT_TYPE_GESTIMUMV5 = 135;
87 public static $EXPORT_TYPE_ISUITEEXPERT = 200;
88 // Generic FEC after that
90 public static $EXPORT_TYPE_FEC = 1000;
92 public static $EXPORT_TYPE_FEC2 = 1010;
93
97 public $db;
98
102 public $errors = array();
103
107 public $separator = '';
108
112 public $end_line = '';
113
117 public $generatedfiledata = array();
118
119
125 public function __construct(DoliDB $db)
126 {
127 global $conf, $hookmanager;
128
129 $this->db = $db;
130 $this->separator = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV');
131 $this->end_line = getDolGlobalString('ACCOUNTING_EXPORT_ENDLINE') ? (getDolGlobalInt('ACCOUNTING_EXPORT_ENDLINE') == 1 ? "\n" : "\r\n") : "\n";
132
133 $hookmanager->initHooks(array('accountancyexport'));
134 }
135
142 public function getType($mode = 0)
143 {
144 global $langs, $hookmanager;
145
146 $listofspecialformatexport = array(
147 self::$EXPORT_TYPE_CEGID => $langs->trans('Modelcsv_CEGID'),
148 self::$EXPORT_TYPE_COALA => $langs->trans('Modelcsv_COALA'),
149 self::$EXPORT_TYPE_BOB50 => $langs->trans('Modelcsv_bob50'),
150 self::$EXPORT_TYPE_CIEL => $langs->trans('Modelcsv_ciel'),
151 self::$EXPORT_TYPE_QUADRATUS => $langs->trans('Modelcsv_quadratus'),
152 self::$EXPORT_TYPE_WINFIC => $langs->trans('Modelcsv_winfic'),
153 self::$EXPORT_TYPE_EBP => $langs->trans('Modelcsv_ebp'),
154 self::$EXPORT_TYPE_COGILOG => $langs->trans('Modelcsv_cogilog'),
155 self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'),
156 self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans('Modelcsv_openconcerto'),
157 self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans('Modelcsv_Sage50_Swiss'),
158 self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans('Modelcsv_charlemagne'),
159 self::$EXPORT_TYPE_LDCOMPTA => $langs->trans('Modelcsv_LDCompta'),
160 self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans('Modelcsv_LDCompta10'),
161 self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans('Modelcsv_Gestinumv3'),
162 self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans('Modelcsv_Gestinumv5'),
163 self::$EXPORT_TYPE_ISUITEEXPERT => 'Export iSuite Expert',
164 );
165
166 $listofgenericformatexport = array(
167 self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans('Modelcsv_configurable'),
168 self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'),
169 self::$EXPORT_TYPE_FEC2 => $langs->trans('Modelcsv_FEC2'),
170 );
171
172 if (empty($mode)) {
173 $listofexporttypes = $listofgenericformatexport + $listofspecialformatexport;
174 ksort($listofexporttypes, SORT_NUMERIC);
175 } else {
176 ksort($listofspecialformatexport, SORT_NUMERIC);
177 $listofexporttypes = array();
178 $i = 0;
179 foreach ($listofgenericformatexport as $key => $val) {
180 $i++;
181 $listofexporttypes[$key] = array('id' => $key, 'label' => $val, 'position' => $i);
182 }
183 $listofexporttypes['separator_'.$i] = array('id' => 0, 'label' => '----------------', 'position' => $i, 'disabled' => 'disabled');
184 foreach ($listofspecialformatexport as $key => $val) {
185 $i++;
186 $listofexporttypes[$key] = array('id' => $key, 'label' => $val, 'position' => $i);
187 }
188 }
189
190 // allow modules to define export formats
191 $parameters = array();
192 $reshook = $hookmanager->executeHooks('getType', $parameters, $listofexporttypes);
193
194 return $listofexporttypes;
195 }
196
203 public static function getFormatCode($type)
204 {
205 $formatcode = array(
206 self::$EXPORT_TYPE_CONFIGURABLE => 'csv',
207 self::$EXPORT_TYPE_CEGID => 'cegid',
208 self::$EXPORT_TYPE_COALA => 'coala',
209 self::$EXPORT_TYPE_BOB50 => 'bob50',
210 self::$EXPORT_TYPE_CIEL => 'ciel',
211 self::$EXPORT_TYPE_QUADRATUS => 'quadratus',
212 self::$EXPORT_TYPE_WINFIC => 'winfic',
213 self::$EXPORT_TYPE_EBP => 'ebp',
214 self::$EXPORT_TYPE_COGILOG => 'cogilog',
215 self::$EXPORT_TYPE_AGIRIS => 'agiris',
216 self::$EXPORT_TYPE_OPENCONCERTO => 'openconcerto',
217 self::$EXPORT_TYPE_SAGE50_SWISS => 'sage50ch',
218 self::$EXPORT_TYPE_CHARLEMAGNE => 'charlemagne',
219 self::$EXPORT_TYPE_LDCOMPTA => 'ldcompta',
220 self::$EXPORT_TYPE_LDCOMPTA10 => 'ldcompta10',
221 self::$EXPORT_TYPE_GESTIMUMV3 => 'gestimumv3',
222 self::$EXPORT_TYPE_GESTIMUMV5 => 'gestimumv5',
223 self::$EXPORT_TYPE_FEC => 'fec',
224 self::$EXPORT_TYPE_FEC2 => 'fec2',
225 self::$EXPORT_TYPE_ISUITEEXPERT => 'isuiteexpert',
226 );
227
228 global $hookmanager;
229 $code = $formatcode[$type] ?? '';
230 $parameters = array('type' => $type);
231 $reshook = $hookmanager->executeHooks('getFormatCode', $parameters, $code);
232
233 return $code;
234 }
235
241 public function getTypeConfig()
242 {
243 global $langs;
244
245 $exporttypes = array(
246 'param' => array(
247 self::$EXPORT_TYPE_CONFIGURABLE => array(
248 'label' => $langs->trans('Modelcsv_configurable'),
249 'ACCOUNTING_EXPORT_FORMAT' => getDolGlobalString('ACCOUNTING_EXPORT_FORMAT', 'txt'),
250 'ACCOUNTING_EXPORT_SEPARATORCSV' => getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV', ','),
251 'ACCOUNTING_EXPORT_ENDLINE' => getDolGlobalString('ACCOUNTING_EXPORT_ENDLINE', 1),
252 'ACCOUNTING_EXPORT_DATE' => getDolGlobalString('ACCOUNTING_EXPORT_DATE', '%Y-%m-%d'),
253 ),
254 self::$EXPORT_TYPE_CEGID => array(
255 'label' => $langs->trans('Modelcsv_CEGID'),
256 ),
257 self::$EXPORT_TYPE_COALA => array(
258 'label' => $langs->trans('Modelcsv_COALA'),
259 ),
260 self::$EXPORT_TYPE_BOB50 => array(
261 'label' => $langs->trans('Modelcsv_bob50'),
262 ),
263 self::$EXPORT_TYPE_CIEL => array(
264 'label' => $langs->trans('Modelcsv_ciel'),
265 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
266 ),
267 self::$EXPORT_TYPE_QUADRATUS => array(
268 'label' => $langs->trans('Modelcsv_quadratus'),
269 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
270 ),
271 self::$EXPORT_TYPE_WINFIC => array(
272 'label' => $langs->trans('Modelcsv_winfic'),
273 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
274 ),
275 self::$EXPORT_TYPE_EBP => array(
276 'label' => $langs->trans('Modelcsv_ebp'),
277 ),
278 self::$EXPORT_TYPE_COGILOG => array(
279 'label' => $langs->trans('Modelcsv_cogilog'),
280 ),
281 self::$EXPORT_TYPE_AGIRIS => array(
282 'label' => $langs->trans('Modelcsv_agiris'),
283 ),
284 self::$EXPORT_TYPE_OPENCONCERTO => array(
285 'label' => $langs->trans('Modelcsv_openconcerto'),
286 ),
287 self::$EXPORT_TYPE_SAGE50_SWISS => array(
288 'label' => $langs->trans('Modelcsv_Sage50_Swiss'),
289 ),
290 self::$EXPORT_TYPE_CHARLEMAGNE => array(
291 'label' => $langs->trans('Modelcsv_charlemagne'),
292 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
293 ),
294 self::$EXPORT_TYPE_LDCOMPTA => array(
295 'label' => $langs->trans('Modelcsv_LDCompta'),
296 ),
297 self::$EXPORT_TYPE_LDCOMPTA10 => array(
298 'label' => $langs->trans('Modelcsv_LDCompta10'),
299 ),
300 self::$EXPORT_TYPE_GESTIMUMV3 => array(
301 'label' => $langs->trans('Modelcsv_Gestinumv3'),
302 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
303 ),
304 self::$EXPORT_TYPE_GESTIMUMV5 => array(
305 'label' => $langs->trans('Modelcsv_Gestinumv5'),
306 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
307 ),
308 self::$EXPORT_TYPE_FEC => array(
309 'label' => $langs->trans('Modelcsv_FEC'),
310 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
311 ),
312 self::$EXPORT_TYPE_FEC2 => array(
313 'label' => $langs->trans('Modelcsv_FEC2'),
314 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
315 ),
316 self::$EXPORT_TYPE_ISUITEEXPERT => array(
317 'label' => 'iSuite Expert',
318 'ACCOUNTING_EXPORT_FORMAT' => 'csv',
319 ),
320 ),
321 'cr' => array(
322 '1' => $langs->trans("Unix"),
323 '2' => $langs->trans("Windows")
324 ),
325 'format' => array(
326 'csv' => $langs->trans("csv"),
327 'txt' => $langs->trans("txt")
328 ),
329 );
330
331 global $hookmanager;
332 $parameters = array();
333 $reshook = $hookmanager->executeHooks('getTypeConfig', $parameters, $exporttypes);
334 return $exporttypes;
335 }
336
337
344 public function getMimeType($formatexportset)
345 {
346 switch ($formatexportset) {
347 case self::$EXPORT_TYPE_FEC:
348 $mime = 'text/tab-separated-values';
349 break;
350 default:
351 $mime = 'text/csv';
352 break;
353 }
354
355 return $mime;
356 }
357
375 public function export(&$TData, $formatexportset, $withAttachment = 0, $downloadMode = 1, $outputMode = 1, $noouput = 1)
376 {
377 global $db, $conf, $langs; // The tpl file use $db
378 global $search_date_end; // Used into /accountancy/tpl/export_journal.tpl.php
379
380 // Define name of file to save
381 $formatcode = $this->getFormatCode($formatexportset);
382 $filename = 'general_ledger-'.(!empty($formatcode) ? $formatcode : $formatexportset);
383 $type_export = 'general_ledger';
384
385 $completefilename = '';
386 $exportFile = null;
387 $exportFileName = '';
388 $exportFilePath = '';
389 $exportFileFullName = '';
390 $downloadFileMimeType = '';
391 $downloadFileFullName = '';
392 $downloadFilePath = '';
393 $archiveFullName = '';
394 $archivePath = '';
395 $archiveFileList = array();
396 if ($withAttachment == 1) {
397 if ($downloadMode == 0) {
398 $downloadMode = 1; // force to download after writing all files (can't use direct download)
399 }
400 if ($outputMode == 0) {
401 $outputMode = 1; // force to put files in a temp directory (can't use print on screen)
402 }
403
404 // PHP ZIP extension must be enabled
405 if (!extension_loaded('zip')) {
406 $langs->load('install');
407 $this->errors[] = $langs->trans('ErrorPHPDoesNotSupport', 'ZIP');
408 return -1;
409 }
410 }
411
412 $mimetype = $this->getMimeType($formatexportset);
413 if ($downloadMode == 0) {
414 // begin to print header for direct download
415 top_httphead($mimetype, 1);
416 }
417
418 include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
419
420 if ($outputMode == 1 || $outputMode == 2) {
421 if ($outputMode == 1) {
422 // uses the temp directory by default to write files
423 if (!empty($conf->accounting->multidir_temp[$conf->entity])) {
424 $outputDir = $conf->accounting->multidir_temp[$conf->entity];
425 } else {
426 $outputDir = $conf->accounting->dir_temp;
427 }
428 } else {
429 // uses the default export directory "accounting/export"
430 if (!empty($conf->accounting->multidir_output[$conf->entity])) {
431 $outputDir = $conf->accounting->multidir_output[$conf->entity];
432 } else {
433 $outputDir = $conf->accounting->dir_output;
434 }
435
436 // directory already created when module is enabled
437 $outputDir .= '/export';
438 $outputDir .= '/'.dol_sanitizePathName((string) $formatexportset);
439 }
440
441 if (!dol_is_dir($outputDir)) {
442 if (dol_mkdir($outputDir) < 0) {
443 $this->errors[] = $langs->trans('ErrorCanNotCreateDir', $outputDir);
444 return -1;
445 }
446 }
447
448 if ($outputDir != '') {
449 if (!dol_is_dir($outputDir)) {
450 $langs->load('errors');
451 $this->errors[] = $langs->trans('ErrorDirNotFound', $outputDir);
452 return -1;
453 }
454
455 // Fallback if template did not set $completefilename
456 if (empty($completefilename)) {
457 $completefilename = dol_sanitizeFileName($filename).'_'.dol_print_date(dol_now(), '%Y%m%d%H%M%S').'.txt';
458 }
459
460 // create export file
461 $exportFileFullName = $completefilename;
462 $exportFileBaseName = basename($exportFileFullName);
463 $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME);
464 $exportFilePath = $outputDir . '/' . $exportFileFullName;
465 $exportFile = fopen($exportFilePath, 'w');
466 if (!$exportFile) {
467 $this->errors[] = $langs->trans('ErrorFileNotFound', $exportFilePath);
468 return -1;
469 }
470
471 if ($withAttachment == 1) {
472 $archiveFileList[0] = array(
473 'path' => $exportFilePath,
474 'name' => $exportFileFullName,
475 );
476
477 // archive name and path
478 $archiveFullName = $exportFileName . '.zip';
479 $archivePath = $outputDir . '/' . $archiveFullName;
480 }
481 }
482 }
483
484 // export file (print on screen or write in a file) and prepare archive list if with attachment is set to 1
485 switch ($formatexportset) {
486 case self::$EXPORT_TYPE_CONFIGURABLE:
487 $this->exportConfigurable($TData, $exportFile);
488 break;
489 case self::$EXPORT_TYPE_CEGID:
490 $this->exportCegid($TData, $exportFile);
491 break;
492 case self::$EXPORT_TYPE_COALA:
493 $this->exportCoala($TData, $exportFile);
494 break;
495 case self::$EXPORT_TYPE_BOB50:
496 $this->exportBob50($TData, $exportFile);
497 break;
498 case self::$EXPORT_TYPE_CIEL:
499 $this->exportCiel($TData, $exportFile);
500 break;
501 case self::$EXPORT_TYPE_QUADRATUS:
502 $archiveFileList = $this->exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment);
503 break;
504 case self::$EXPORT_TYPE_WINFIC:
505 $this->exportWinfic($TData, $exportFile);
506 break;
507 case self::$EXPORT_TYPE_EBP:
508 $this->exportEbp($TData, $exportFile);
509 break;
510 case self::$EXPORT_TYPE_COGILOG:
511 $this->exportCogilog($TData, $exportFile);
512 break;
513 case self::$EXPORT_TYPE_AGIRIS:
514 $this->exportAgiris($TData, $exportFile);
515 break;
516 case self::$EXPORT_TYPE_OPENCONCERTO:
517 $this->exportOpenConcerto($TData, $exportFile);
518 break;
519 case self::$EXPORT_TYPE_SAGE50_SWISS:
520 $this->exportSAGE50SWISS($TData, $exportFile);
521 break;
522 case self::$EXPORT_TYPE_CHARLEMAGNE:
523 $this->exportCharlemagne($TData, $exportFile);
524 break;
525 case self::$EXPORT_TYPE_LDCOMPTA:
526 $this->exportLDCompta($TData, $exportFile);
527 break;
528 case self::$EXPORT_TYPE_LDCOMPTA10:
529 $this->exportLDCompta10($TData, $exportFile);
530 break;
531 case self::$EXPORT_TYPE_GESTIMUMV3:
532 $this->exportGestimumV3($TData, $exportFile);
533 break;
534 case self::$EXPORT_TYPE_GESTIMUMV5:
535 $this->exportGestimumV5($TData, $exportFile);
536 break;
537 case self::$EXPORT_TYPE_FEC:
538 $archiveFileList = $this->exportFEC($TData, $exportFile, $archiveFileList, $withAttachment);
539 break;
540 case self::$EXPORT_TYPE_FEC2:
541 $archiveFileList = $this->exportFEC2($TData, $exportFile, $archiveFileList, $withAttachment);
542 break;
543 case self::$EXPORT_TYPE_ISUITEEXPERT:
544 $this->exportiSuiteExpert($TData, $exportFile);
545 break;
546 default:
547 global $hookmanager;
548 $parameters = array(
549 'format' => $formatexportset,
550 'file' => $exportFile,
551 'filepath' => $exportFilePath,
552 'filefullname' => $exportFileFullName,
553 );
554 // file contents will be created in the hooked function via print and name will be returned.
555 $reshook = $hookmanager->executeHooks('export', $parameters, $TData);
556 if ($reshook != 1) {
557 $this->errors[] = $langs->trans('accountancy_error_modelnotfound');
558 } elseif (!empty($hookmanager->resArray['downloadFileFullName']) && !empty($hookmanager->resArray['downloadFilePath'])) {
559 $exportFileFullName = $hookmanager->resArray['downloadFileFullName'];
560 $exportFilePath = $hookmanager->resArray['downloadFilePath'];
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 // We should use dol_now function not time however this is wrong date to transfer in accounting
907 foreach ($objectLines as $line) {
908 // Clean some data
909 $line->doc_ref = dol_string_unaccent($line->doc_ref);
910
911 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
912 $line->label_operation = str_replace(array("- ", "…", "..."), "", $line->label_operation);
913 $line->label_operation = dol_string_unaccent($line->label_operation);
914
915 $line->numero_compte = dol_string_unaccent($line->numero_compte);
916 $line->label_compte = dol_string_unaccent($line->label_compte);
917 $line->subledger_account = dol_string_unaccent($line->subledger_account);
918
919 $line->subledger_label = str_replace(array("- ", "…", "..."), "", $line->subledger_label);
920 $line->subledger_label = dol_string_unaccent($line->subledger_label);
921
922 $code_compta = $line->numero_compte;
923 if (!empty($line->subledger_account)) {
924 $code_compta = $line->subledger_account;
925 }
926
927 $tab = array();
928
929 if (!empty($line->subledger_account)) {
930 $tab['type_ligne'] = 'C';
931 $tab['num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8);
932 $tab['lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30);
933
934 if ($line->doc_type == 'customer_invoice') {
935 $tab['lib_alpha'] = strtoupper(str_pad('C'.self::trunc(dol_string_unaccent($line->subledger_label), 6), 7));
936 $tab['filler'] = str_repeat(' ', 52);
937 $tab['coll_compte'] = str_pad(self::trunc(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), 8), 8);
938 } elseif ($line->doc_type == 'supplier_invoice') {
939 $tab['lib_alpha'] = strtoupper(str_pad('F'.self::trunc(dol_string_unaccent($line->subledger_label), 6), 7));
940 $tab['filler'] = str_repeat(' ', 52);
941 $tab['coll_compte'] = str_pad(self::trunc(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), 8), 8);
942 } else {
943 $tab['filler'] = str_repeat(' ', 59);
944 $tab['coll_compte'] = str_pad(' ', 8);
945 }
946
947 $tab['filler2'] = str_repeat(' ', 110);
948 $tab['Maj'] = 2; // Partial update (alpha key, label, address, collectif, RIB)
949
950 if ($line->doc_type == 'customer_invoice') {
951 $tab['type_compte'] = 'C';
952 } elseif ($line->doc_type == 'supplier_invoice') {
953 $tab['type_compte'] = 'F';
954 } else {
955 $tab['type_compte'] = 'G';
956 }
957
958 $tab['filler3'] = str_repeat(' ', 235);
959
960 $tab['end_line'] = $end_line;
961
962 if ($exportFile) {
963 fwrite($exportFile, implode($tab));
964 } else {
965 print implode($tab);
966 }
967 }
968
969 $tab = array();
970 $tab['type_ligne'] = 'M';
971 $tab['num_compte'] = str_pad(self::trunc((string) $code_compta, 8), 8);
972 $tab['code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
973 $tab['folio'] = '000';
974
975 // We use invoice date $line->doc_date not $date_ecriture which is the transfer date
976 // maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
977 //$tab['date_ecriture'] = $date_ecriture;
978 $tab['date_ecriture'] = dol_print_date($line->doc_date, '%d%m%y');
979 $tab['filler'] = ' ';
980 $tab['libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.' '.$line->label_operation, 20), 20);
981
982 // Credit invoice - invert sens
983 /*
984 if ($line->montant < 0) {
985 if ($line->sens == 'C') {
986 $tab['sens'] = 'D';
987 } else {
988 $tab['sens'] = 'C';
989 }
990 $tab['signe_montant'] = '-';
991 } else {
992 $tab['sens'] = $line->sens; // C or D
993 $tab['signe_montant'] = '+';
994 }*/
995 $tab['sens'] = $line->sens; // C or D
996 $tab['signe_montant'] = '+';
997
998 // The amount must be in centimes without decimal points.
999 $tab['montant'] = str_pad((string) abs(($line->debit - $line->credit) * 100), 12, '0', STR_PAD_LEFT);
1000 $tab['contrepartie'] = str_repeat(' ', 8);
1001
1002 // Force date format : %d%m%y
1003 if (!empty($line->date_lim_reglement)) {
1004 $tab['date_echeance'] = dol_print_date($line->date_lim_reglement, '%d%m%y'); // Format must be ddmmyy
1005 } else {
1006 $tab['date_echeance'] = '000000';
1007 }
1008
1009 // Please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
1010 // $tab['lettrage'] = str_repeat(' ', 5);
1011 $tab['lettrage'] = str_repeat(' ', 2);
1012 $tab['codestat'] = str_repeat(' ', 3);
1013 $tab['num_piece'] = str_pad(self::trunc((string) $line->piece_num, 5), 5);
1014
1015 // Keep correct quadra named field instead of anon filler
1016 // $tab['filler2'] = str_repeat(' ', 20);
1017 $tab['affaire'] = str_repeat(' ', 10);
1018 $tab['quantity1'] = str_repeat(' ', 10);
1019 $tab['num_piece2'] = str_pad(self::trunc((string) $line->piece_num, 8), 8);
1020 $tab['devis'] = str_pad($conf->currency, 3);
1021 $tab['code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
1022 $tab['filler3'] = str_repeat(' ', 3);
1023
1024 // Keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
1025 // 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
1026 // TODO: we should filter more than only accent to avoid wrong line size
1027 // TODO: remove invoice number doc_ref in label,
1028 // TODO: we should offer an option for customer to build the label using invoice number / name / date in accounting software
1029 //$tab['libelle_ecriture2'] = str_pad(self::trunc($line->doc_ref . ' ' . $line->label_operation, 30), 30);
1030 $tab['libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
1031 $tab['codetva'] = str_repeat(' ', 2);
1032
1033 // We need to keep the 10 latest number of invoices doc_ref not the beginning part that is the useless almost same part
1034 // $tab['num_piece3'] = str_pad(self::trunc($line->piece_num, 10), 10);
1035 $tab['num_piece3'] = str_pad(substr(self::trunc($line->doc_ref, 20), -10), 10);
1036 $tab['reserved'] = str_repeat(' ', 10); // position 159
1037 $tab['currency_amount'] = str_repeat(' ', 13); // position 169
1038 // get document file
1039 $attachmentFileName = '';
1040 if ($withAttachment == 1) {
1041 $attachmentFileKey = trim((string) $line->piece_num);
1042
1043 if (!isset($archiveFileList[$attachmentFileKey])) {
1044 $objectDirPath = '';
1045 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1046 if ($line->doc_type == 'customer_invoice') {
1047 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1048 } elseif ($line->doc_type == 'expense_report') {
1049 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1050 } elseif ($line->doc_type == 'supplier_invoice') {
1051 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1052 $invoice = new FactureFournisseur($this->db);
1053 $invoice->fetch($line->fk_doc);
1054 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1055 $objectDirPath .= '/'.rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1056 }
1057 $arrayofinclusion = array();
1058 // If it is a supplier invoice, we want to use last uploaded file
1059 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1060 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1061 if (!empty($fileFoundList)) {
1062 $attachmentFileNameTrunc = str_pad(self::trunc((string) $line->piece_num, 8), 8, '0', STR_PAD_LEFT);
1063 foreach ($fileFoundList as $fileFound) {
1064 if (strstr($fileFound['name'], $objectFileName)) {
1065 // skip native invoice pdfs (canelle)
1066 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1067 if ($line->doc_type == 'supplier_invoice') {
1068 if ($fileFound['name'] === $objectFileName.'.pdf') {
1069 continue;
1070 }
1071 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1072 continue;
1073 }
1074 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1075 if (file_exists($fileFoundPath)) {
1076 $archiveFileList[$attachmentFileKey] = array(
1077 'path' => $fileFoundPath,
1078 'name' => $attachmentFileNameTrunc.'.pdf',
1079 );
1080 break;
1081 }
1082 }
1083 }
1084 }
1085 }
1086
1087 if (isset($archiveFileList[$attachmentFileKey])) {
1088 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1089 }
1090 }
1091 if (dol_strlen((string) $attachmentFileName) == 12) {
1092 $tab['attachment'] = $attachmentFileName; // position 182
1093 } else {
1094 $tab['attachment'] = str_repeat(' ', 12); // position 182
1095 }
1096 $tab['filler4'] = str_repeat(' ', 38);
1097 $tab['end_line'] = $end_line;
1098
1099 if ($exportFile) {
1100 fwrite($exportFile, implode($tab));
1101 } else {
1102 print implode($tab);
1103 }
1104 }
1105
1106 return $archiveFileList;
1107 }
1108
1119 public function exportWinfic($objectLines, $exportFile = null)
1120 {
1121 global $conf;
1122
1123 $end_line = "\r\n";
1124 $index = 1;
1125
1126 // Warning ! When truncation is necessary, no dot because 3 dots = three characters. The columns are shifted
1127
1128 foreach ($objectLines as $line) {
1129 $code_compta = $line->numero_compte;
1130 if (!empty($line->subledger_account)) {
1131 $code_compta = $line->subledger_account;
1132 }
1133
1134 $tab = array();
1135 //$tab['type_ligne'] = 'M';
1136 $tab['code_journal'] = str_pad(dol_trunc($line->code_journal, 2, 'right', 'UTF-8', 1), 2);
1137
1138 //We use invoice date $line->doc_date not $date_ecriture which is the transfer date
1139 //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
1140 //$tab['date_ecriture'] = $date_ecriture;
1141 $tab['date_operation'] = dol_print_date($line->doc_date, '%d%m%Y');
1142
1143 $tab['folio'] = ' 1';
1144
1145 $tab['num_ecriture'] = str_pad(dol_trunc((string) $index, 6, 'right', 'UTF-8', 1), 6, ' ', STR_PAD_LEFT);
1146
1147 $tab['jour_ecriture'] = dol_print_date($line->doc_date, '%d%m%y');
1148
1149 $tab['num_compte'] = str_pad(dol_trunc((string) $code_compta, 6, 'right', 'UTF-8', 1), 6, '0');
1150
1151 if ($line->sens == 'D') {
1152 $tab['montant_debit'] = str_pad(number_format($line->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1153
1154 $tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1155 } else {
1156 $tab['montant_debit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1157
1158 $tab['montant_crebit'] = str_pad(number_format($line->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1159 }
1160
1161 $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);
1162
1163 $tab['lettrage'] = str_repeat(dol_trunc((string) $line->lettering_code, 2, 'left', 'UTF-8', 1), 2);
1164
1165 $tab['code_piece'] = str_pad(dol_trunc((string) $line->piece_num, 5, 'left', 'UTF-8', 1), 5, ' ', STR_PAD_LEFT);
1166
1167 $tab['code_stat'] = str_repeat(' ', 4);
1168
1169 if (!empty($line->date_lim_reglement)) {
1170 $tab['date_echeance'] = dol_print_date($line->date_lim_reglement, '%d%m%Y');
1171 } else {
1172 $tab['date_echeance'] = dol_print_date($line->doc_date, '%d%m%Y');
1173 }
1174
1175 $tab['monnaie'] = '1';
1176
1177 $tab['filler'] = ' ';
1178
1179 $tab['ind_compteur'] = ' ';
1180
1181 $tab['quantite'] = '0,000000000';
1182
1183 $tab['code_pointage'] = str_repeat(' ', 2);
1184
1185 $tab['end_line'] = $end_line;
1186
1187 $output = implode('|', $tab);
1188 if ($exportFile) {
1189 fwrite($exportFile, $output);
1190 } else {
1191 print $output;
1192 }
1193
1194 $index++;
1195 }
1196 }
1197
1198
1206 public function exportEbp($objectLines, $exportFile = null)
1207 {
1208 $separator = ',';
1209 $end_line = "\n";
1210
1211 foreach ($objectLines as $line) {
1212 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
1213
1214 $tab = array();
1215
1216 $tab[] = $line->id;
1217 $tab[] = $date_document;
1218 $tab[] = $line->code_journal;
1219 if (empty($line->subledger_account)) {
1220 $tab[] = $line->numero_compte;
1221 } else {
1222 $tab[] = $line->subledger_account;
1223 }
1224 //$tab[] = substr(length_accountg($line->numero_compte), 0, 2) . $separator;
1225 $tab[] = '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"';
1226 $tab[] = '"'.dol_trunc((string) $line->piece_num, 15, 'right', 'UTF-8', 1).'"';
1227 $tab[] = price2num(abs($line->debit - $line->credit));
1228 $tab[] = $line->sens;
1229 $tab[] = $date_document;
1230 //print 'EUR';
1231
1232 $output = implode($separator, $tab).$end_line;
1233 if ($exportFile) {
1234 fwrite($exportFile, $output);
1235 } else {
1236 print $output;
1237 }
1238 }
1239 }
1240
1241
1249 public function exportAgiris($objectLines, $exportFile = null)
1250 {
1251 $separator = ';';
1252 $end_line = "\n";
1253
1254 foreach ($objectLines as $line) {
1255 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
1256
1257 $tab = array();
1258
1259 $tab[] = $line->piece_num;
1260 $tab[] = self::toAnsi($line->label_operation);
1261 $tab[] = $date_document;
1262 $tab[] = self::toAnsi($line->label_operation);
1263
1264 if (empty($line->subledger_account)) {
1265 $tab[] = length_accountg($line->numero_compte);
1266 $tab[] = self::toAnsi($line->label_compte);
1267 } else {
1268 $tab[] = length_accounta($line->subledger_account);
1269 $tab[] = self::toAnsi($line->subledger_label);
1270 }
1271
1272 $tab[] = self::toAnsi($line->doc_ref);
1273 $tab[] = price($line->debit);
1274 $tab[] = price($line->credit);
1275 $tab[] = price(abs($line->debit - $line->credit));
1276 $tab[] = $line->sens;
1277 $tab[] = $line->lettering_code;
1278 $tab[] = $line->code_journal;
1279
1280 $output = implode($separator, $tab).$end_line;
1281 if ($exportFile) {
1282 fwrite($exportFile, $output);
1283 } else {
1284 print $output;
1285 }
1286 }
1287 }
1288
1296 public function exportOpenConcerto($objectLines, $exportFile = null)
1297 {
1298 $separator = ';';
1299 $end_line = "\n";
1300
1301 foreach ($objectLines as $line) {
1302 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
1303
1304 $tab = array();
1305
1306 $tab[] = $date_document;
1307 $tab[] = $line->code_journal;
1308 if (empty($line->subledger_account)) {
1309 $tab[] = length_accountg($line->numero_compte);
1310 } else {
1311 $tab[] = length_accounta($line->subledger_account);
1312 }
1313 $tab[] = $line->doc_ref;
1314 $tab[] = $line->label_operation;
1315 $tab[] = price($line->debit);
1316 $tab[] = price($line->credit);
1317
1318 $output = implode($separator, $tab).$end_line;
1319 if ($exportFile) {
1320 fwrite($exportFile, $output);
1321 } else {
1322 print $output;
1323 }
1324 }
1325 }
1326
1334 public function exportConfigurable($objectLines, $exportFile = null)
1335 {
1336 global $conf;
1337
1338 $separator = $this->separator;
1339
1340 foreach ($objectLines as $line) {
1341 $date_document = dol_print_date($line->doc_date, getDolGlobalString('ACCOUNTING_EXPORT_DATE'));
1342
1343 $tab = array();
1344 // export configurable
1345 $tab[] = $line->piece_num;
1346 $tab[] = $date_document;
1347 $tab[] = $line->doc_ref;
1348 $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
1349 $tab[] = length_accountg($line->numero_compte);
1350 $tab[] = length_accounta($line->subledger_account);
1351 $tab[] = price2num($line->debit);
1352 $tab[] = price2num($line->credit);
1353 $tab[] = price2num($line->debit - $line->credit);
1354 $tab[] = $line->code_journal;
1355
1356 $output = implode($separator, $tab).$this->end_line;
1357 if ($exportFile) {
1358 fwrite($exportFile, $output);
1359 } else {
1360 print $output;
1361 }
1362 }
1363 }
1364
1377 public function exportFEC($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
1378 {
1379 global $conf, $langs;
1380
1381 $separator = "\t";
1382 $end_line = "\r\n";
1383
1384 $tab = array();
1385 $tab[] = "JournalCode";
1386 $tab[] = "JournalLib";
1387 $tab[] = "EcritureNum";
1388 $tab[] = "EcritureDate";
1389 $tab[] = "CompteNum";
1390 $tab[] = "CompteLib";
1391 $tab[] = "CompAuxNum";
1392 $tab[] = "CompAuxLib";
1393 $tab[] = "PieceRef";
1394 $tab[] = "PieceDate";
1395 $tab[] = "EcritureLib";
1396 $tab[] = "Debit";
1397 $tab[] = "Credit";
1398 $tab[] = "EcritureLet";
1399 $tab[] = "DateLet";
1400 $tab[] = "ValidDate";
1401 $tab[] = "Montantdevise";
1402 $tab[] = "Idevise";
1403 $tab[] = "DateLimitReglmt";
1404 $tab[] = "NumFacture";
1405 $tab[] = "FichierFacture";
1406
1407 $output = implode($separator, $tab).$end_line;
1408 if ($exportFile) {
1409 fwrite($exportFile, $output);
1410 } else {
1411 print $output;
1412 }
1413
1414 foreach ($objectLines as $line) {
1415 if ($line->debit == 0 && $line->credit == 0) {
1416 //var_dump($line->id);
1417 //unset($array[$line]);
1418 } else {
1419 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1420 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1421 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1422 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1423 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1424
1425 $refInvoice = '';
1426 if ($line->doc_type == 'customer_invoice') {
1427 // Customer invoice
1428 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1429 $invoice = new Facture($this->db);
1430 $invoice->fetch($line->fk_doc);
1431
1432 $refInvoice = $invoice->ref;
1433 } elseif ($line->doc_type == 'supplier_invoice') {
1434 // Supplier invoice
1435 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1436 $invoice = new FactureFournisseur($this->db);
1437 $invoice->fetch($line->fk_doc);
1438
1439 $refInvoice = $invoice->ref_supplier;
1440 }
1441
1442 $tab = array();
1443
1444 // FEC:JournalCode
1445 $tab[] = $line->code_journal;
1446
1447 // FEC:JournalLib
1448 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1449 $labeljournal = str_replace(array("\t", "\n", "\r"), " ", $labeljournal);
1450 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1451 $tab[] = $labeljournal;
1452
1453 // FEC:EcritureNum
1454 $tab[] = $line->piece_num;
1455
1456 // FEC:EcritureDate
1457 $tab[] = $date_document;
1458
1459 // FEC:CompteNum
1460 $tab[] = length_accountg($line->numero_compte);
1461
1462 // FEC:CompteLib
1463 $line->label_compte = str_replace(array("\t", "\n", "\r"), " ", $line->label_compte);
1464 $tab[] = dol_string_unaccent($line->label_compte);
1465
1466 // FEC:CompAuxNum
1467 $tab[] = length_accounta($line->subledger_account);
1468
1469 // FEC:CompAuxLib
1470 $line->subledger_label = str_replace(array("\t", "\n", "\r"), " ", $line->subledger_label);
1471 $tab[] = dol_string_unaccent($line->subledger_label);
1472
1473 // FEC:PieceRef
1474 $tab[] = $line->doc_ref;
1475
1476 // FEC:PieceDate
1477 $tab[] = dol_string_unaccent($date_creation);
1478
1479 // FEC:EcritureLib
1480 // Clean label operation to prevent problem on export with tab separator & other character
1481 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1482 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1483 $tab[] = dol_string_unaccent($line->label_operation);
1484
1485 // FEC:Debit
1486 $tab[] = price2fec($line->debit);
1487
1488 // FEC:Credit
1489 $tab[] = price2fec($line->credit);
1490
1491 // FEC:EcritureLet
1492 $line->lettering_code = str_replace(array("\t", "\n", "\r"), " ", (string) $line->lettering_code);
1493 $tab[] = $line->lettering_code;
1494
1495 // FEC:DateLet
1496 $tab[] = $date_lettering;
1497
1498 // FEC:ValidDate
1499 $tab[] = $date_validation;
1500
1501 // FEC:Montantdevise
1502 $tab[] = $line->multicurrency_amount;
1503
1504 // FEC:Idevise
1505 $tab[] = $line->multicurrency_code;
1506
1507 // FEC_suppl:DateLimitReglmt
1508 $tab[] = $date_limit_payment;
1509
1510 // FEC_suppl:NumFacture
1511 // Clean ref invoice to prevent problem on export with tab separator & other character
1512 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1513 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1514
1515 // FEC_suppl:FichierFacture
1516 // get document file
1517 $attachmentFileName = '';
1518 if ($withAttachment == 1) {
1519 $attachmentFileKey = trim((string) $line->piece_num);
1520
1521 if (!isset($archiveFileList[$attachmentFileKey])) {
1522 $objectDirPath = '';
1523 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1524 if ($line->doc_type == 'customer_invoice') {
1525 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1526 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1527 }
1528 } elseif ($line->doc_type == 'expense_report') {
1529 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1530 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1531 }
1532 } elseif ($line->doc_type == 'supplier_invoice') {
1533 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1534 '@phan-var-force FactureFournisseur $invoice';
1536 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1537 $objectDirPath .= '/' . rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1538 }
1539 }
1540 $arrayofinclusion = array();
1541 // If it is a supplier invoice, we want to use last uploaded file
1542 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1543 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1544 if (!empty($fileFoundList)) {
1545 $attachmentFileNameTrunc = $line->doc_ref;
1546 foreach ($fileFoundList as $fileFound) {
1547 if (strstr($fileFound['name'], $objectFileName)) {
1548 // skip native invoice pdfs (canelle)
1549 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1550 if ($line->doc_type == 'supplier_invoice') {
1551 if ($fileFound['name'] === $objectFileName.'.pdf') {
1552 continue;
1553 }
1554 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1555 continue;
1556 }
1557 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1558 if (file_exists($fileFoundPath)) {
1559 $archiveFileList[$attachmentFileKey] = array(
1560 'path' => $fileFoundPath,
1561 'name' => $attachmentFileNameTrunc.'.pdf',
1562 );
1563 break;
1564 }
1565 }
1566 }
1567 }
1568 }
1569
1570 if (isset($archiveFileList[$attachmentFileKey])) {
1571 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1572 }
1573 }
1574
1575 $tab[] = $attachmentFileName;
1576
1577 $output = implode($separator, $tab).$end_line;
1578
1579 if ($exportFile) {
1580 fwrite($exportFile, $output);
1581 } else {
1582 print $output;
1583 }
1584 }
1585 }
1586
1587 return $archiveFileList;
1588 }
1589
1602 public function exportFEC2($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
1603 {
1604 global $conf, $langs;
1605
1606 $separator = "\t";
1607 $end_line = "\r\n";
1608
1609 $tab = array();
1610 $tab[] = "JournalCode";
1611 $tab[] = "JournalLib";
1612 $tab[] = "EcritureNum";
1613 $tab[] = "EcritureDate";
1614 $tab[] = "CompteNum";
1615 $tab[] = "CompteLib";
1616 $tab[] = "CompAuxNum";
1617 $tab[] = "CompAuxLib";
1618 $tab[] = "PieceRef";
1619 $tab[] = "PieceDate";
1620 $tab[] = "EcritureLib";
1621 $tab[] = "Debit";
1622 $tab[] = "Credit";
1623 $tab[] = "EcritureLet";
1624 $tab[] = "DateLet";
1625 $tab[] = "ValidDate";
1626 $tab[] = "Montantdevise";
1627 $tab[] = "Idevise";
1628 $tab[] = "DateLimitReglmt";
1629 $tab[] = "NumFacture";
1630 $tab[] = "FichierFacture";
1631
1632 $output = implode($separator, $tab).$end_line;
1633 if ($exportFile) {
1634 fwrite($exportFile, $output);
1635 } else {
1636 print $output;
1637 }
1638
1639 foreach ($objectLines as $line) {
1640 if ($line->debit == 0 && $line->credit == 0) {
1641 //unset($array[$line]);
1642 } else {
1643 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1644 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1645 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1646 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1647 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1648
1649 $refInvoice = '';
1650 if ($line->doc_type == 'customer_invoice') {
1651 // Customer invoice
1652 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1653 $invoice = new Facture($this->db);
1654 $invoice->fetch($line->fk_doc);
1655
1656 $refInvoice = $invoice->ref;
1657 } elseif ($line->doc_type == 'supplier_invoice') {
1658 // Supplier invoice
1659 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1660 $invoice = new FactureFournisseur($this->db);
1661 $invoice->fetch($line->fk_doc);
1662
1663 $refInvoice = $invoice->ref_supplier;
1664 }
1665
1666 $tab = array();
1667
1668 // FEC:JournalCode
1669 $tab[] = $line->code_journal;
1670
1671 // FEC:JournalLib
1672 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1673 $labeljournal = str_replace(array("\t", "\n", "\r"), " ", $labeljournal);
1674 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1675 $tab[] = $labeljournal;
1676
1677 // FEC:EcritureNum
1678 $tab[] = $line->piece_num;
1679
1680 // FEC:EcritureDate
1681 $tab[] = $date_creation;
1682
1683 // FEC:CompteNum
1684 $tab[] = length_accountg($line->numero_compte);
1685
1686 // FEC:CompteLib
1687 $line->label_compte = str_replace(array("\t", "\n", "\r"), " ", $line->label_compte);
1688 $tab[] = dol_string_unaccent($line->label_compte);
1689
1690 // FEC:CompAuxNum
1691 $tab[] = length_accounta($line->subledger_account);
1692
1693 // FEC:CompAuxLib
1694 $line->subledger_label = str_replace(array("\t", "\n", "\r"), " ", $line->subledger_label);
1695 $tab[] = dol_string_unaccent($line->subledger_label);
1696
1697 // FEC:PieceRef
1698 $tab[] = $line->doc_ref;
1699
1700 // FEC:PieceDate
1701 $tab[] = $date_document;
1702
1703 // FEC:EcritureLib
1704 // Clean label operation to prevent problem on export with tab separator & other character
1705 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1706 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1707 $tab[] = dol_string_unaccent($line->label_operation);
1708
1709 // FEC:Debit
1710 $tab[] = price2fec($line->debit);
1711
1712 // FEC:Credit
1713 $tab[] = price2fec($line->credit);
1714
1715 // FEC:EcritureLet
1716 $line->lettering_code = str_replace(array("\t", "\n", "\r"), " ", (string) $line->lettering_code);
1717 $tab[] = $line->lettering_code;
1718
1719 // FEC:DateLet
1720 $tab[] = $date_lettering;
1721
1722 // FEC:ValidDate
1723 $tab[] = $date_validation;
1724
1725 // FEC:Montantdevise
1726 $tab[] = $line->multicurrency_amount;
1727
1728 // FEC:Idevise
1729 $tab[] = $line->multicurrency_code;
1730
1731 // FEC_suppl:DateLimitReglmt
1732 $tab[] = $date_limit_payment;
1733
1734 // FEC_suppl:NumFacture
1735 // Clean ref invoice to prevent problem on export with tab separator & other character
1736 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1737 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1738
1739 // FEC_suppl:FichierFacture
1740 // get document file
1741 $attachmentFileName = '';
1742 if ($withAttachment == 1) {
1743 $attachmentFileKey = trim((string) $line->piece_num);
1744
1745 if (!isset($archiveFileList[$attachmentFileKey])) {
1746 $objectDirPath = '';
1747 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1748 if ($line->doc_type == 'customer_invoice') {
1749 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1750 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1751 }
1752 } elseif ($line->doc_type == 'expense_report') {
1753 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1754 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1755 }
1756 } elseif ($line->doc_type == 'supplier_invoice') {
1757 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1758 '@phan-var-force FactureFournisseur $invoice';
1760 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1761 $objectDirPath .= '/' . rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1762 }
1763 }
1764 $arrayofinclusion = array();
1765 // If it is a supplier invoice, we want to use last uploaded file
1766 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1767 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1768 if (!empty($fileFoundList)) {
1769 $attachmentFileNameTrunc = $line->doc_ref;
1770 foreach ($fileFoundList as $fileFound) {
1771 if (strstr($fileFound['name'], $objectFileName)) {
1772 // skip native invoice pdfs (canelle)
1773 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1774 if ($line->doc_type == 'supplier_invoice') {
1775 if ($fileFound['name'] === $objectFileName.'.pdf') {
1776 continue;
1777 }
1778 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1779 continue;
1780 }
1781 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1782 if (file_exists($fileFoundPath)) {
1783 $archiveFileList[$attachmentFileKey] = array(
1784 'path' => $fileFoundPath,
1785 'name' => $attachmentFileNameTrunc.'.pdf',
1786 );
1787 break;
1788 }
1789 }
1790 }
1791 }
1792 }
1793
1794 if (isset($archiveFileList[$attachmentFileKey])) {
1795 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1796 }
1797 }
1798
1799 $tab[] = $attachmentFileName;
1800
1801 $output = implode($separator, $tab).$end_line;
1802 if ($exportFile) {
1803 fwrite($exportFile, $output);
1804 } else {
1805 print $output;
1806 }
1807 }
1808 }
1809
1810 return $archiveFileList;
1811 }
1812
1823 public function exportSAGE50SWISS($objectLines, $exportFile = null)
1824 {
1825 // SAGE50SWISS
1826 $separator = ',';
1827 $end_line = "\r\n";
1828
1829 // Print header line
1830 $tab = array();
1831
1832 $tab[] = "Blg";
1833 $tab[] = "Datum";
1834 $tab[] = "Kto";
1835 $tab[] = "S/H";
1836 $tab[] = "Grp";
1837 $tab[] = "GKto";
1838 $tab[] = "SId";
1839 $tab[] = "SIdx";
1840 $tab[] = "KIdx";
1841 $tab[] = "BTyp";
1842 $tab[] = "MTyp";
1843 $tab[] = "Code";
1844 $tab[] = "Netto";
1845 $tab[] = "Steuer";
1846 $tab[] = "FW-Betrag";
1847 $tab[] = "Tx1";
1848 $tab[] = "Tx2";
1849 $tab[] = "PkKey";
1850 $tab[] = "OpId";
1851 $tab[] = "Flag";
1852
1853 $output = implode($separator, $tab).$end_line;
1854 if ($exportFile) {
1855 fwrite($exportFile, $output);
1856 } else {
1857 print $output;
1858 }
1859
1860 $thisPieceNum = "";
1861 $thisPieceAccountNr = "";
1862 $aSize = count($objectLines);
1863 foreach ($objectLines as $aIndex => $line) {
1864 $sammelBuchung = false;
1865 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1866 $sammelBuchung = true;
1867 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1868 $sammelBuchung = true;
1869 } elseif ($aIndex + 1 < $aSize
1870 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1871 && $aIndex - 1 < $aSize
1872 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1873 ) {
1874 $sammelBuchung = true;
1875 }
1876
1877 $tab = array();
1878
1879 //Blg
1880 $tab[] = $line->piece_num;
1881
1882 // Datum
1883 $date_document = dol_print_date($line->doc_date, '%d.%m.%Y');
1884 $tab[] = $date_document;
1885
1886 // Kto
1887 $tab[] = length_accountg($line->numero_compte);
1888 // S/H
1889 if ($line->sens == 'D') {
1890 $tab[] = 'S';
1891 } else {
1892 $tab[] = 'H';
1893 }
1894 // Grp
1895 $tab[] = self::trunc($line->code_journal, 1);
1896 // GKto
1897 if (empty($line->code_tiers)) {
1898 if ($line->piece_num == $thisPieceNum) {
1899 $tab[] = length_accounta($thisPieceAccountNr);
1900 } else {
1901 $tab[] = "div";
1902 }
1903 } else {
1904 $tab[] = length_accounta($line->code_tiers);
1905 }
1906 // SId
1907 $tab[] = $this->separator;
1908 // SIdx
1909 $tab[] = "0";
1910 // KIdx
1911 $tab[] = "0";
1912 // BTyp
1913 $tab[] = "0";
1914
1915 // MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
1916 if ($sammelBuchung) {
1917 $tab[] = "2";
1918 } else {
1919 $tab[] = "1";
1920 }
1921 // Code
1922 $tab[] = '""';
1923 // Netto
1924 $tab[] = abs($line->debit - $line->credit);
1925 // Steuer
1926 $tab[] = "0.00";
1927 // FW-Betrag
1928 $tab[] = "0.00";
1929 // Tx1
1930 $line1 = self::toAnsi($line->label_compte, 29);
1931 if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
1932 $line1 = "";
1933 }
1934 $line2 = self::toAnsi($line->doc_ref, 29);
1935 if (strlen($line1) == 0) {
1936 $line1 = $line2;
1937 $line2 = "";
1938 }
1939 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1940 $line1 = $line1.' / '.$line2;
1941 $line2 = "";
1942 }
1943
1944 $tab[] = '"'.self::toAnsi($line1).'"';
1945 // Tx2
1946 $tab[] = '"'.self::toAnsi($line2).'"';
1947 //PkKey
1948 $tab[] = "0";
1949 //OpId
1950 $tab[] = $this->separator;
1951
1952 // Flag
1953 $tab[] = "0";
1954
1955 $output = implode($separator, $tab).$end_line;
1956 if ($exportFile) {
1957 fwrite($exportFile, $output);
1958 } else {
1959 print $output;
1960 }
1961
1962 if ($line->piece_num !== $thisPieceNum) {
1963 $thisPieceNum = $line->piece_num;
1964 $thisPieceAccountNr = $line->numero_compte;
1965 }
1966 }
1967 }
1968
1977 public function exportLDCompta($objectLines, $exportFile = null)
1978 {
1979 $separator = ';';
1980 $end_line = "\r\n";
1981
1982 foreach ($objectLines as $line) {
1983 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1984 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1985 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1986
1987 $tab = array();
1988
1989 // TYPE
1990 $type_enregistrement = 'E'; // For write movement
1991 $tab[] = $type_enregistrement;
1992 // JNAL
1993 $tab[] = substr($line->code_journal, 0, 2);
1994 // NECR
1995 $tab[] = $line->id;
1996 // NPIE
1997 $tab[] = $line->piece_num;
1998 // DATP
1999 $tab[] = $date_document;
2000 // LIBE
2001 $tab[] = $line->label_operation;
2002 // DATH
2003 $tab[] = $date_lim_reglement;
2004 // CNPI
2005 if ($line->doc_type == 'supplier_invoice') {
2006 if (($line->debit - $line->credit) > 0) {
2007 $nature_piece = 'AF';
2008 } else {
2009 $nature_piece = 'FF';
2010 }
2011 } elseif ($line->doc_type == 'customer_invoice') {
2012 if (($line->debit - $line->credit) < 0) {
2013 $nature_piece = 'AC';
2014 } else {
2015 $nature_piece = 'FC';
2016 }
2017 } else {
2018 $nature_piece = '';
2019 }
2020 $tab[] = $nature_piece;
2021 // RACI
2022 // if (!empty($line->subledger_account)) {
2023 // if ($line->doc_type == 'supplier_invoice') {
2024 // $racine_subledger_account = '40';
2025 // } elseif ($line->doc_type == 'customer_invoice') {
2026 // $racine_subledger_account = '41';
2027 // } else {
2028 // $racine_subledger_account = '';
2029 // }
2030 // } else {
2031 $racine_subledger_account = ''; // for records of type E leave this field blank
2032 // }
2033
2034 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2035 // MONT
2036 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2, 2);
2037 // CODC
2038 $tab[] = $line->sens;
2039 // CPTG
2040 $tab[] = length_accountg($line->numero_compte);
2041 // DATE
2042 $tab[] = $date_creation;
2043 // CLET
2044 $tab[] = $line->lettering_code;
2045 // DATL
2046 $tab[] = $line->date_lettering;
2047 // CPTA
2048 if (!empty($line->subledger_account)) {
2049 $tab[] = length_accounta($line->subledger_account);
2050 } else {
2051 $tab[] = "";
2052 }
2053 // C.N.A.T
2054 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2055 $tab[] = 'F';
2056 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2057 $tab[] = 'C';
2058 } else {
2059 $tab[] = "";
2060 }
2061 // SECT
2062 $tab[] = "";
2063 // CTRE
2064 $tab[] = "";
2065 // NORL
2066 $tab[] = "";
2067 // DATV
2068 $tab[] = "";
2069 // REFD
2070 $tab[] = $line->doc_ref;
2071 // CODH
2072 $tab[] = "";
2073 // NSEQ
2074 $tab[] = "";
2075 // MTDV
2076 $tab[] = '0';
2077 // CODV
2078 $tab[] = "";
2079 // TXDV
2080 $tab[] = '0';
2081 // MOPM
2082 $tab[] = "";
2083 // BONP
2084 $tab[] = "";
2085 // BQAF
2086 $tab[] = "";
2087 // ECES
2088 $tab[] = "";
2089 // TXTL
2090 $tab[] = "";
2091 // ECRM
2092 $tab[] = "";
2093 // DATK
2094 $tab[] = "";
2095 // HEUK
2096 $tab[] = "";
2097
2098 $output = implode($separator, $tab).$end_line;
2099 if ($exportFile) {
2100 fwrite($exportFile, $output);
2101 } else {
2102 print $output;
2103 }
2104 }
2105 }
2106
2117 public function exportLDCompta10($objectLines, $exportFile = null)
2118 {
2119 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
2120
2121 $separator = ';';
2122 $end_line = "\r\n";
2123 $last_codeinvoice = '';
2124
2125 foreach ($objectLines as $line) {
2126 // TYPE C
2127 if ($last_codeinvoice != $line->doc_ref) {
2128 //recherche societe en fonction de son code client
2129 $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
2130 $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
2131 $resql = $this->db->query($sql);
2132
2133 if ($resql && $this->db->num_rows($resql) > 0) {
2134 $soc = $this->db->fetch_object($resql);
2135
2136 $address = array('', '', '');
2137 if (strpos($soc->address, "\n") !== false) {
2138 $address = explode("\n", $soc->address);
2139 if (is_array($address) && count($address) > 0) {
2140 foreach ($address as $key => $data) {
2141 $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
2142 $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
2143 }
2144 }
2145 } else {
2146 $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
2147 $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
2148 $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
2149 }
2150
2151 $tab = array();
2152
2153 $type_enregistrement = 'C';
2154 //TYPE
2155 $tab[] = $type_enregistrement;
2156 //NOCL
2157 $tab[] = $soc->code_client;
2158 //NMCM
2159 $tab[] = "";
2160 //LIBI
2161 $tab[] = "";
2162 //TITR
2163 $tab[] = "";
2164 //RSSO
2165 $tab[] = $soc->nom;
2166 //CAD1
2167 $tab[] = $address[0];
2168 //CAD2
2169 $tab[] = $address[1];
2170 //CAD3
2171 $tab[] = $address[2];
2172 //COPO
2173 $tab[] = $soc->zip;
2174 //BUDI
2175 $tab[] = substr($soc->town, 0, 40);
2176 //CPAY
2177 $tab[] = "";
2178 //PAYS
2179 $tab[] = substr(getCountry($soc->fk_pays), 0, 40);
2180 //NTEL
2181 $tab[] = $soc->phone;
2182 //TLEX
2183 $tab[] = "";
2184 //TLPO
2185 $tab[] = "";
2186 //TLCY
2187 $tab[] = "";
2188 //NINT
2189 $tab[] = "";
2190 //COMM
2191 $tab[] = "";
2192 //SIRE
2193 $tab[] = str_replace(" ", "", $soc->siret);
2194 //RIBP
2195 $tab[] = "";
2196 //DOBQ
2197 $tab[] = "";
2198 //IBBQ
2199 $tab[] = "";
2200 //COBQ
2201 $tab[] = "";
2202 //GUBQ
2203 $tab[] = "";
2204 //CPBQ
2205 $tab[] = "";
2206 //CLBQ
2207 $tab[] = "";
2208 //BIBQ
2209 $tab[] = "";
2210 //MOPM
2211 $tab[] = "";
2212 //DJPM
2213 $tab[] = "";
2214 //DMPM
2215 $tab[] = "";
2216 //REFM
2217 $tab[] = "";
2218 //SLVA
2219 $tab[] = "";
2220 //PLCR
2221 $tab[] = "";
2222 //ECFI
2223 $tab[] = "";
2224 //CREP
2225 $tab[] = "";
2226 //NREP
2227 $tab[] = "";
2228 //TREP
2229 $tab[] = "";
2230 //MREP
2231 $tab[] = "";
2232 //GRRE
2233 $tab[] = "";
2234 //LTTA
2235 $tab[] = "";
2236 //CACT
2237 $tab[] = "";
2238 //CODV
2239 $tab[] = "";
2240 //GRTR
2241 $tab[] = "";
2242 //NOFP
2243 $tab[] = "";
2244 //BQAF
2245 $tab[] = "";
2246 //BONP
2247 $tab[] = "";
2248 //CESC
2249 $tab[] = "";
2250
2251 $output = implode($separator, $tab).$end_line;
2252 if ($exportFile) {
2253 fwrite($exportFile, $output);
2254 } else {
2255 print $output;
2256 }
2257 }
2258 }
2259
2260 $tab = array();
2261
2262 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2263 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
2264 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2265
2266 // TYPE E
2267 $type_enregistrement = 'E'; // For write movement
2268 $tab[] = $type_enregistrement;
2269 // JNAL
2270 $tab[] = substr($line->code_journal, 0, 2);
2271 // NECR
2272 $tab[] = $line->id;
2273 // NPIE
2274 $tab[] = $line->piece_num;
2275 // DATP
2276 $tab[] = $date_document;
2277 // LIBE
2278 $tab[] = dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1);
2279 // DATH
2280 $tab[] = $date_lim_reglement;
2281 // CNPI
2282 if ($line->doc_type == 'supplier_invoice') {
2283 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.
2284 $nature_piece = 'AF';
2285 } else {
2286 $nature_piece = 'FF';
2287 }
2288 } elseif ($line->doc_type == 'customer_invoice') {
2289 if (($line->amount) < 0) {
2290 $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.
2291 } else {
2292 $nature_piece = 'FC';
2293 }
2294 } else {
2295 $nature_piece = '';
2296 }
2297 $tab[] = $nature_piece;
2298 // RACI
2299 // if (!empty($line->subledger_account)) {
2300 // if ($line->doc_type == 'supplier_invoice') {
2301 // $racine_subledger_account = '40';
2302 // } elseif ($line->doc_type == 'customer_invoice') {
2303 // $racine_subledger_account = '41';
2304 // } else {
2305 // $racine_subledger_account = '';
2306 // }
2307 // } else {
2308 $racine_subledger_account = ''; // for records of type E leave this field blank
2309 // }
2310
2311 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2312 // MONT
2313 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2);
2314 // CODC
2315 $tab[] = $line->sens;
2316 // CPTG
2317 $tab[] = length_accountg($line->numero_compte);
2318 // DATE
2319 $tab[] = $date_document;
2320 // CLET
2321 $tab[] = $line->lettering_code;
2322 // DATL
2323 $tab[] = $line->date_lettering;
2324 // CPTA
2325 if (!empty($line->subledger_account)) {
2326 $tab[] = length_accounta($line->subledger_account);
2327 } else {
2328 $tab[] = "";
2329 }
2330 // C.N.A.T
2331 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2332 $tab[] = 'F';
2333 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2334 $tab[] = 'C';
2335 } else {
2336 $tab[] = "";
2337 }
2338 // CTRE
2339 $tab[] = "";
2340 // NORL
2341 $tab[] = "";
2342 // DATV
2343 $tab[] = "";
2344 // REFD
2345 $tab[] = $line->doc_ref;
2346 // NECA
2347 $tab[] = '0';
2348 // CSEC
2349 $tab[] = "";
2350 // CAFF
2351 $tab[] = "";
2352 // CDES
2353 $tab[] = "";
2354 // QTUE
2355 $tab[] = "";
2356 // MTDV
2357 $tab[] = '0';
2358 // CODV
2359 $tab[] = "";
2360 // TXDV
2361 $tab[] = '0';
2362 // MOPM
2363 $tab[] = "";
2364 // BONP
2365 $tab[] = "";
2366 // BQAF
2367 $tab[] = "";
2368 // ECES
2369 $tab[] = "";
2370 // TXTL
2371 $tab[] = "";
2372 // ECRM
2373 $tab[] = "";
2374 // DATK
2375 $tab[] = "";
2376 // HEUK
2377 $tab[] = "";
2378
2379 $output = implode($separator, $tab).$end_line;
2380 if ($exportFile) {
2381 fwrite($exportFile, $output);
2382 } else {
2383 print $output;
2384 }
2385
2386 $last_codeinvoice = $line->doc_ref;
2387 }
2388 }
2389
2397 public function exportCharlemagne($objectLines, $exportFile = null)
2398 {
2399 global $langs;
2400 $langs->load('compta');
2401
2402 $separator = "\t";
2403 $end_line = "\n";
2404
2405 $tab = array();
2406
2407 $tab[] = $langs->transnoentitiesnoconv('Date');
2408 $tab[] = self::trunc($langs->transnoentitiesnoconv('Journal'), 6);
2409 $tab[] = self::trunc($langs->transnoentitiesnoconv('Account'), 15);
2410 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60);
2411 $tab[] = self::trunc($langs->transnoentitiesnoconv('Piece'), 20);
2412 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60);
2413 $tab[] = $langs->transnoentitiesnoconv('Amount');
2414 $tab[] = 'S';
2415 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15);
2416 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60);
2417 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15);
2418 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60);
2419 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15);
2420 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60);
2421
2422 $output = implode($separator, $tab).$end_line;
2423 if ($exportFile) {
2424 fwrite($exportFile, $output);
2425 } else {
2426 print $output;
2427 }
2428
2429 foreach ($objectLines as $line) {
2430 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2431
2432 $tab = array();
2433
2434 $tab[] = $date_document; //Date
2435
2436 $tab[] = self::trunc($line->code_journal, 6); //Journal code
2437
2438 if (!empty($line->subledger_account)) {
2439 $account = $line->subledger_account;
2440 } else {
2441 $account = $line->numero_compte;
2442 }
2443 $tab[] = self::trunc((string) $account, 15); //Account number
2444
2445 $tab[] = self::trunc($line->label_compte, 60); //Account label
2446 $tab[] = self::trunc($line->doc_ref, 20); //Piece
2447 // Clean label operation to prevent problem on export with tab separator & other character
2448 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
2449 $tab[] = self::trunc($line->label_operation, 60); //Operation label
2450 $tab[] = price(abs($line->debit - $line->credit)); //Amount
2451 $tab[] = $line->sens; //Direction
2452 $tab[] = ""; //Analytic
2453 $tab[] = ""; //Analytic
2454 $tab[] = ""; //Analytic
2455 $tab[] = ""; //Analytic
2456 $tab[] = ""; //Analytic
2457 $tab[] = ""; //Analytic
2458
2459 $output = implode($separator, $tab).$end_line;
2460 if ($exportFile) {
2461 fwrite($exportFile, $output);
2462 } else {
2463 print $output;
2464 }
2465 }
2466 }
2467
2475 public function exportGestimumV3($objectLines, $exportFile = null)
2476 {
2477 global $langs;
2478
2479 $separator = ',';
2480 $end_line = "\r\n";
2481
2482 $invoices_infos = array();
2483 $supplier_invoices_infos = array();
2484 foreach ($objectLines as $line) {
2485 if ($line->debit == 0 && $line->credit == 0) {
2486 //unset($array[$line]);
2487 } else {
2488 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
2489 $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2490
2491 $invoice_ref = $line->doc_ref;
2492 $company_name = "";
2493
2494 if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
2495 if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2496 ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2497 if ($line->doc_type == 'customer_invoice') {
2498 // Get new customer invoice ref and company name
2499 $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
2500 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
2501 $sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
2502 $resql = $this->db->query($sql);
2503 if ($resql) {
2504 if ($obj = $this->db->fetch_object($resql)) {
2505 // Save invoice infos
2506 $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2507 $invoice_ref = $obj->ref;
2508 $company_name = $obj->nom;
2509 }
2510 }
2511 } else {
2512 // Get new supplier invoice ref and company name
2513 $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
2514 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
2515 $sql .= ' WHERE ff.rowid = '.((int) $line->fk_doc);
2516 $resql = $this->db->query($sql);
2517 if ($resql) {
2518 if ($obj = $this->db->fetch_object($resql)) {
2519 // Save invoice infos
2520 $supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2521 $invoice_ref = $obj->ref;
2522 $company_name = $obj->nom;
2523 }
2524 }
2525 }
2526 } elseif ($line->doc_type == 'customer_invoice') {
2527 // Retrieve invoice infos
2528 $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
2529 $company_name = $invoices_infos[$line->fk_doc]['company_name'];
2530 } else {
2531 // Retrieve invoice infos
2532 $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
2533 $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
2534 }
2535 }
2536
2537 $tab = array();
2538
2539 $tab[] = $line->id;
2540 $tab[] = $date_document;
2541 $tab[] = substr($line->code_journal, 0, 4);
2542
2543 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
2544 $tab[] = length_accountg($line->subledger_account);
2545 } else {
2546 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2547 }
2548 //Libellé Auto
2549 $tab[] = "";
2550 //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"';
2551 //Libellé manual
2552 $tab[] = dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1);
2553 //Numéro de pièce
2554 $tab[] = dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1);
2555 //Devise
2556 $tab[] = 'EUR';
2557 //Amount
2558 $tab[] = price2num(abs($line->debit - $line->credit));
2559 //Sens
2560 $tab[] = $line->sens;
2561 //Code lettrage
2562 $tab[] = "";
2563 //Date Echéance
2564 $tab[] = $date_echeance;
2565
2566 $output = implode($separator, $tab).$end_line;
2567 if ($exportFile) {
2568 fwrite($exportFile, $output);
2569 } else {
2570 print $output;
2571 }
2572 }
2573 }
2574 }
2575
2583 public function exportGestimumV5($objectLines, $exportFile = null)
2584 {
2585 $separator = ',';
2586 $end_line = "\r\n";
2587
2588 foreach ($objectLines as $line) {
2589 if ($line->debit == 0 && $line->credit == 0) {
2590 //unset($array[$line]);
2591 } else {
2592 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
2593
2594 $tab = array();
2595
2596 $tab[] = $line->id;
2597 $tab[] = $date_document;
2598 $tab[] = substr($line->code_journal, 0, 4);
2599 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
2600 $tab[] = length_accountg($line->subledger_account);
2601 } else {
2602 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2603 }
2604 $tab[] = "";
2605 $tab[] = '"'.dol_trunc(str_replace('"', '', $line->label_operation), 40, 'right', 'UTF-8', 1).'"';
2606 $tab[] = '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"';
2607 $tab[] = '"' . dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1) . '"';
2608 $tab[] = price2num(abs($line->debit - $line->credit));
2609 $tab[] = $line->sens;
2610 $tab[] = $date_document;
2611 $tab[] = "";
2612 $tab[] = "";
2613 $tab[] = 'EUR';
2614
2615 $output = implode($separator, $tab).$end_line;
2616 if ($exportFile) {
2617 fwrite($exportFile, $output);
2618 } else {
2619 print $output;
2620 }
2621 }
2622 }
2623 }
2624
2634 public function exportiSuiteExpert($objectLines, $exportFile = null)
2635 {
2636 $separator = ';';
2637 $end_line = "\r\n";
2638
2639
2640 foreach ($objectLines as $line) {
2641 $tab = array();
2642
2643 $date = dol_print_date($line->doc_date, '%d/%m/%Y');
2644
2645 $tab[] = $line->piece_num;
2646 $tab[] = $date;
2647 $tab[] = substr($date, 6, 4);
2648 $tab[] = substr($date, 3, 2);
2649 $tab[] = substr($date, 0, 2);
2650 $tab[] = $line->doc_ref;
2651 //Conversion de chaine UTF8 en Latin9
2652 $tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
2653
2654 //Calcul de la longueur des numéros de comptes
2655 $taille_numero = strlen(length_accountg($line->numero_compte));
2656
2657 //Création du numéro de client et fournisseur générique
2658 $numero_cpt_client = '411';
2659 $numero_cpt_fourn = '401';
2660 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2661 $numero_cpt_client .= '0';
2662 $numero_cpt_fourn .= '0';
2663 }
2664
2665 //Création des comptes auxiliaire des clients et fournisseur
2666 if (length_accountg($line->numero_compte) == $numero_cpt_client || length_accountg($line->numero_compte) == $numero_cpt_fourn) {
2667 $tab[] = rtrim(length_accounta($line->subledger_account), "0");
2668 } else {
2669 $tab[] = length_accountg($line->numero_compte);
2670 }
2671 $nom_client = explode(" - ", $line->label_operation);
2672 $tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
2673 $tab[] = price($line->debit);
2674 $tab[] = price($line->credit);
2675 $tab[] = price($line->montant);
2676 $tab[] = $line->code_journal;
2677
2678 $output = implode($separator, $tab).$end_line;
2679 if ($exportFile) {
2680 fwrite($exportFile, $output);
2681 } else {
2682 print $output;
2683 }
2684 }
2685 }
2686
2694 public static function trunc($str, $size)
2695 {
2696 return dol_trunc($str, $size, 'right', 'UTF-8', 1);
2697 }
2698
2706 public static function toAnsi($str, $size = -1)
2707 {
2708 $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
2709 if ($retVal >= 0 && $size >= 0) {
2710 $retVal = dol_substr($retVal, 0, $size, 'Windows-1251');
2711 }
2712 return $retVal;
2713 }
2714}
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.
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)
__construct(DoliDB $db)
Constructor.
exportCegid($objectLines, $exportFile=null)
Export format : CEGID.
exportCoala($objectLines, $exportFile=null)
Export format : COALA.
getMimeType($formatexportset)
Return the MIME type of a file.
exportGestimumV5($objectLines, $exportFile=null)
Export format : Gestimum V5.
Class to manage Dolibarr database access.
Class to manage suppliers invoices.
Class to manage invoices.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_filesize($pathoffile)
Return size of a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
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_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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
dol_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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79