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 = dol_string_nospecial($labeljournal, ' ');
1450 $tab[] = $labeljournal;
1451
1452 // FEC:EcritureNum
1453 $tab[] = $line->piece_num;
1454
1455 // FEC:EcritureDate
1456 $tab[] = $date_document;
1457
1458 // FEC:CompteNum
1459 $tab[] = length_accountg($line->numero_compte);
1460
1461 // FEC:CompteLib
1462 $tab[] = dol_string_unaccent($line->label_compte);
1463
1464 // FEC:CompAuxNum
1465 $tab[] = length_accounta($line->subledger_account);
1466
1467 // FEC:CompAuxLib
1468 $tab[] = dol_string_unaccent($line->subledger_label);
1469
1470 // FEC:PieceRef
1471 $tab[] = $line->doc_ref;
1472
1473 // FEC:PieceDate
1474 $tab[] = dol_string_unaccent($date_creation);
1475
1476 // FEC:EcritureLib
1477 // Clean label operation to prevent problem on export with tab separator & other character
1478 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1479 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1480 $tab[] = dol_string_unaccent($line->label_operation);
1481
1482 // FEC:Debit
1483 $tab[] = price2fec($line->debit);
1484
1485 // FEC:Credit
1486 $tab[] = price2fec($line->credit);
1487
1488 // FEC:EcritureLet
1489 $tab[] = $line->lettering_code;
1490
1491 // FEC:DateLet
1492 $tab[] = $date_lettering;
1493
1494 // FEC:ValidDate
1495 $tab[] = $date_validation;
1496
1497 // FEC:Montantdevise
1498 $tab[] = $line->multicurrency_amount;
1499
1500 // FEC:Idevise
1501 $tab[] = $line->multicurrency_code;
1502
1503 // FEC_suppl:DateLimitReglmt
1504 $tab[] = $date_limit_payment;
1505
1506 // FEC_suppl:NumFacture
1507 // Clean ref invoice to prevent problem on export with tab separator & other character
1508 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1509 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1510
1511 // FEC_suppl:FichierFacture
1512 // get document file
1513 $attachmentFileName = '';
1514 if ($withAttachment == 1) {
1515 $attachmentFileKey = trim((string) $line->piece_num);
1516
1517 if (!isset($archiveFileList[$attachmentFileKey])) {
1518 $objectDirPath = '';
1519 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1520 if ($line->doc_type == 'customer_invoice') {
1521 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1522 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1523 }
1524 } elseif ($line->doc_type == 'expense_report') {
1525 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1526 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1527 }
1528 } elseif ($line->doc_type == 'supplier_invoice') {
1529 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1530 '@phan-var-force FactureFournisseur $invoice';
1532 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1533 $objectDirPath .= '/' . rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1534 }
1535 }
1536 $arrayofinclusion = array();
1537 // If it is a supplier invoice, we want to use last uploaded file
1538 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1539 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1540 if (!empty($fileFoundList)) {
1541 $attachmentFileNameTrunc = $line->doc_ref;
1542 foreach ($fileFoundList as $fileFound) {
1543 if (strstr($fileFound['name'], $objectFileName)) {
1544 // skip native invoice pdfs (canelle)
1545 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1546 if ($line->doc_type == 'supplier_invoice') {
1547 if ($fileFound['name'] === $objectFileName.'.pdf') {
1548 continue;
1549 }
1550 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1551 continue;
1552 }
1553 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1554 if (file_exists($fileFoundPath)) {
1555 $archiveFileList[$attachmentFileKey] = array(
1556 'path' => $fileFoundPath,
1557 'name' => $attachmentFileNameTrunc.'.pdf',
1558 );
1559 break;
1560 }
1561 }
1562 }
1563 }
1564 }
1565
1566 if (isset($archiveFileList[$attachmentFileKey])) {
1567 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1568 }
1569 }
1570
1571 $tab[] = $attachmentFileName;
1572
1573 $output = implode($separator, $tab).$end_line;
1574
1575 if ($exportFile) {
1576 fwrite($exportFile, $output);
1577 } else {
1578 print $output;
1579 }
1580 }
1581 }
1582
1583 return $archiveFileList;
1584 }
1585
1598 public function exportFEC2($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
1599 {
1600 global $conf, $langs;
1601
1602 $separator = "\t";
1603 $end_line = "\r\n";
1604
1605 $tab = array();
1606 $tab[] = "JournalCode";
1607 $tab[] = "JournalLib";
1608 $tab[] = "EcritureNum";
1609 $tab[] = "EcritureDate";
1610 $tab[] = "CompteNum";
1611 $tab[] = "CompteLib";
1612 $tab[] = "CompAuxNum";
1613 $tab[] = "CompAuxLib";
1614 $tab[] = "PieceRef";
1615 $tab[] = "PieceDate";
1616 $tab[] = "EcritureLib";
1617 $tab[] = "Debit";
1618 $tab[] = "Credit";
1619 $tab[] = "EcritureLet";
1620 $tab[] = "DateLet";
1621 $tab[] = "ValidDate";
1622 $tab[] = "Montantdevise";
1623 $tab[] = "Idevise";
1624 $tab[] = "DateLimitReglmt";
1625 $tab[] = "NumFacture";
1626 $tab[] = "FichierFacture";
1627
1628 $output = implode($separator, $tab).$end_line;
1629 if ($exportFile) {
1630 fwrite($exportFile, $output);
1631 } else {
1632 print $output;
1633 }
1634
1635 foreach ($objectLines as $line) {
1636 if ($line->debit == 0 && $line->credit == 0) {
1637 //unset($array[$line]);
1638 } else {
1639 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1640 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1641 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1642 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1643 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1644
1645 $refInvoice = '';
1646 if ($line->doc_type == 'customer_invoice') {
1647 // Customer invoice
1648 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1649 $invoice = new Facture($this->db);
1650 $invoice->fetch($line->fk_doc);
1651
1652 $refInvoice = $invoice->ref;
1653 } elseif ($line->doc_type == 'supplier_invoice') {
1654 // Supplier invoice
1655 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1656 $invoice = new FactureFournisseur($this->db);
1657 $invoice->fetch($line->fk_doc);
1658
1659 $refInvoice = $invoice->ref_supplier;
1660 }
1661
1662 $tab = array();
1663
1664 // FEC:JournalCode
1665 $tab[] = $line->code_journal;
1666
1667 // FEC:JournalLib
1668 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1669 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1670 $tab[] = $labeljournal;
1671
1672 // FEC:EcritureNum
1673 $tab[] = $line->piece_num;
1674
1675 // FEC:EcritureDate
1676 $tab[] = $date_creation;
1677
1678 // FEC:CompteNum
1679 $tab[] = length_accountg($line->numero_compte);
1680
1681 // FEC:CompteLib
1682 $tab[] = dol_string_unaccent($line->label_compte);
1683
1684 // FEC:CompAuxNum
1685 $tab[] = length_accounta($line->subledger_account);
1686
1687 // FEC:CompAuxLib
1688 $tab[] = dol_string_unaccent($line->subledger_label);
1689
1690 // FEC:PieceRef
1691 $tab[] = $line->doc_ref;
1692
1693 // FEC:PieceDate
1694 $tab[] = $date_document;
1695
1696 // FEC:EcritureLib
1697 // Clean label operation to prevent problem on export with tab separator & other character
1698 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1699 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1700 $tab[] = dol_string_unaccent($line->label_operation);
1701
1702 // FEC:Debit
1703 $tab[] = price2fec($line->debit);
1704
1705 // FEC:Credit
1706 $tab[] = price2fec($line->credit);
1707
1708 // FEC:EcritureLet
1709 $tab[] = $line->lettering_code;
1710
1711 // FEC:DateLet
1712 $tab[] = $date_lettering;
1713
1714 // FEC:ValidDate
1715 $tab[] = $date_validation;
1716
1717 // FEC:Montantdevise
1718 $tab[] = $line->multicurrency_amount;
1719
1720 // FEC:Idevise
1721 $tab[] = $line->multicurrency_code;
1722
1723 // FEC_suppl:DateLimitReglmt
1724 $tab[] = $date_limit_payment;
1725
1726 // FEC_suppl:NumFacture
1727 // Clean ref invoice to prevent problem on export with tab separator & other character
1728 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1729 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1730
1731 // FEC_suppl:FichierFacture
1732 // get document file
1733 $attachmentFileName = '';
1734 if ($withAttachment == 1) {
1735 $attachmentFileKey = trim((string) $line->piece_num);
1736
1737 if (!isset($archiveFileList[$attachmentFileKey])) {
1738 $objectDirPath = '';
1739 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1740 if ($line->doc_type == 'customer_invoice') {
1741 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1742 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1743 }
1744 } elseif ($line->doc_type == 'expense_report') {
1745 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1746 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1747 }
1748 } elseif ($line->doc_type == 'supplier_invoice') {
1749 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1750 '@phan-var-force FactureFournisseur $invoice';
1752 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1753 $objectDirPath .= '/' . rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1754 }
1755 }
1756 $arrayofinclusion = array();
1757 // If it is a supplier invoice, we want to use last uploaded file
1758 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1759 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1760 if (!empty($fileFoundList)) {
1761 $attachmentFileNameTrunc = $line->doc_ref;
1762 foreach ($fileFoundList as $fileFound) {
1763 if (strstr($fileFound['name'], $objectFileName)) {
1764 // skip native invoice pdfs (canelle)
1765 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1766 if ($line->doc_type == 'supplier_invoice') {
1767 if ($fileFound['name'] === $objectFileName.'.pdf') {
1768 continue;
1769 }
1770 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1771 continue;
1772 }
1773 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1774 if (file_exists($fileFoundPath)) {
1775 $archiveFileList[$attachmentFileKey] = array(
1776 'path' => $fileFoundPath,
1777 'name' => $attachmentFileNameTrunc.'.pdf',
1778 );
1779 break;
1780 }
1781 }
1782 }
1783 }
1784 }
1785
1786 if (isset($archiveFileList[$attachmentFileKey])) {
1787 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1788 }
1789 }
1790
1791 $tab[] = $attachmentFileName;
1792
1793 $output = implode($separator, $tab).$end_line;
1794 if ($exportFile) {
1795 fwrite($exportFile, $output);
1796 } else {
1797 print $output;
1798 }
1799 }
1800 }
1801
1802 return $archiveFileList;
1803 }
1804
1815 public function exportSAGE50SWISS($objectLines, $exportFile = null)
1816 {
1817 // SAGE50SWISS
1818 $separator = ',';
1819 $end_line = "\r\n";
1820
1821 // Print header line
1822 $tab = array();
1823
1824 $tab[] = "Blg";
1825 $tab[] = "Datum";
1826 $tab[] = "Kto";
1827 $tab[] = "S/H";
1828 $tab[] = "Grp";
1829 $tab[] = "GKto";
1830 $tab[] = "SId";
1831 $tab[] = "SIdx";
1832 $tab[] = "KIdx";
1833 $tab[] = "BTyp";
1834 $tab[] = "MTyp";
1835 $tab[] = "Code";
1836 $tab[] = "Netto";
1837 $tab[] = "Steuer";
1838 $tab[] = "FW-Betrag";
1839 $tab[] = "Tx1";
1840 $tab[] = "Tx2";
1841 $tab[] = "PkKey";
1842 $tab[] = "OpId";
1843 $tab[] = "Flag";
1844
1845 $output = implode($separator, $tab).$end_line;
1846 if ($exportFile) {
1847 fwrite($exportFile, $output);
1848 } else {
1849 print $output;
1850 }
1851
1852 $thisPieceNum = "";
1853 $thisPieceAccountNr = "";
1854 $aSize = count($objectLines);
1855 foreach ($objectLines as $aIndex => $line) {
1856 $sammelBuchung = false;
1857 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1858 $sammelBuchung = true;
1859 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1860 $sammelBuchung = true;
1861 } elseif ($aIndex + 1 < $aSize
1862 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1863 && $aIndex - 1 < $aSize
1864 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1865 ) {
1866 $sammelBuchung = true;
1867 }
1868
1869 $tab = array();
1870
1871 //Blg
1872 $tab[] = $line->piece_num;
1873
1874 // Datum
1875 $date_document = dol_print_date($line->doc_date, '%d.%m.%Y');
1876 $tab[] = $date_document;
1877
1878 // Kto
1879 $tab[] = length_accountg($line->numero_compte);
1880 // S/H
1881 if ($line->sens == 'D') {
1882 $tab[] = 'S';
1883 } else {
1884 $tab[] = 'H';
1885 }
1886 // Grp
1887 $tab[] = self::trunc($line->code_journal, 1);
1888 // GKto
1889 if (empty($line->code_tiers)) {
1890 if ($line->piece_num == $thisPieceNum) {
1891 $tab[] = length_accounta($thisPieceAccountNr);
1892 } else {
1893 $tab[] = "div";
1894 }
1895 } else {
1896 $tab[] = length_accounta($line->code_tiers);
1897 }
1898 // SId
1899 $tab[] = $this->separator;
1900 // SIdx
1901 $tab[] = "0";
1902 // KIdx
1903 $tab[] = "0";
1904 // BTyp
1905 $tab[] = "0";
1906
1907 // MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
1908 if ($sammelBuchung) {
1909 $tab[] = "2";
1910 } else {
1911 $tab[] = "1";
1912 }
1913 // Code
1914 $tab[] = '""';
1915 // Netto
1916 $tab[] = abs($line->debit - $line->credit);
1917 // Steuer
1918 $tab[] = "0.00";
1919 // FW-Betrag
1920 $tab[] = "0.00";
1921 // Tx1
1922 $line1 = self::toAnsi($line->label_compte, 29);
1923 if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
1924 $line1 = "";
1925 }
1926 $line2 = self::toAnsi($line->doc_ref, 29);
1927 if (strlen($line1) == 0) {
1928 $line1 = $line2;
1929 $line2 = "";
1930 }
1931 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1932 $line1 = $line1.' / '.$line2;
1933 $line2 = "";
1934 }
1935
1936 $tab[] = '"'.self::toAnsi($line1).'"';
1937 // Tx2
1938 $tab[] = '"'.self::toAnsi($line2).'"';
1939 //PkKey
1940 $tab[] = "0";
1941 //OpId
1942 $tab[] = $this->separator;
1943
1944 // Flag
1945 $tab[] = "0";
1946
1947 $output = implode($separator, $tab).$end_line;
1948 if ($exportFile) {
1949 fwrite($exportFile, $output);
1950 } else {
1951 print $output;
1952 }
1953
1954 if ($line->piece_num !== $thisPieceNum) {
1955 $thisPieceNum = $line->piece_num;
1956 $thisPieceAccountNr = $line->numero_compte;
1957 }
1958 }
1959 }
1960
1969 public function exportLDCompta($objectLines, $exportFile = null)
1970 {
1971 $separator = ';';
1972 $end_line = "\r\n";
1973
1974 foreach ($objectLines as $line) {
1975 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1976 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1977 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1978
1979 $tab = array();
1980
1981 // TYPE
1982 $type_enregistrement = 'E'; // For write movement
1983 $tab[] = $type_enregistrement;
1984 // JNAL
1985 $tab[] = substr($line->code_journal, 0, 2);
1986 // NECR
1987 $tab[] = $line->id;
1988 // NPIE
1989 $tab[] = $line->piece_num;
1990 // DATP
1991 $tab[] = $date_document;
1992 // LIBE
1993 $tab[] = $line->label_operation;
1994 // DATH
1995 $tab[] = $date_lim_reglement;
1996 // CNPI
1997 if ($line->doc_type == 'supplier_invoice') {
1998 if (($line->debit - $line->credit) > 0) {
1999 $nature_piece = 'AF';
2000 } else {
2001 $nature_piece = 'FF';
2002 }
2003 } elseif ($line->doc_type == 'customer_invoice') {
2004 if (($line->debit - $line->credit) < 0) {
2005 $nature_piece = 'AC';
2006 } else {
2007 $nature_piece = 'FC';
2008 }
2009 } else {
2010 $nature_piece = '';
2011 }
2012 $tab[] = $nature_piece;
2013 // RACI
2014 // if (!empty($line->subledger_account)) {
2015 // if ($line->doc_type == 'supplier_invoice') {
2016 // $racine_subledger_account = '40';
2017 // } elseif ($line->doc_type == 'customer_invoice') {
2018 // $racine_subledger_account = '41';
2019 // } else {
2020 // $racine_subledger_account = '';
2021 // }
2022 // } else {
2023 $racine_subledger_account = ''; // for records of type E leave this field blank
2024 // }
2025
2026 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2027 // MONT
2028 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2, 2);
2029 // CODC
2030 $tab[] = $line->sens;
2031 // CPTG
2032 $tab[] = length_accountg($line->numero_compte);
2033 // DATE
2034 $tab[] = $date_creation;
2035 // CLET
2036 $tab[] = $line->lettering_code;
2037 // DATL
2038 $tab[] = $line->date_lettering;
2039 // CPTA
2040 if (!empty($line->subledger_account)) {
2041 $tab[] = length_accounta($line->subledger_account);
2042 } else {
2043 $tab[] = "";
2044 }
2045 // C.N.A.T
2046 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2047 $tab[] = 'F';
2048 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2049 $tab[] = 'C';
2050 } else {
2051 $tab[] = "";
2052 }
2053 // SECT
2054 $tab[] = "";
2055 // CTRE
2056 $tab[] = "";
2057 // NORL
2058 $tab[] = "";
2059 // DATV
2060 $tab[] = "";
2061 // REFD
2062 $tab[] = $line->doc_ref;
2063 // CODH
2064 $tab[] = "";
2065 // NSEQ
2066 $tab[] = "";
2067 // MTDV
2068 $tab[] = '0';
2069 // CODV
2070 $tab[] = "";
2071 // TXDV
2072 $tab[] = '0';
2073 // MOPM
2074 $tab[] = "";
2075 // BONP
2076 $tab[] = "";
2077 // BQAF
2078 $tab[] = "";
2079 // ECES
2080 $tab[] = "";
2081 // TXTL
2082 $tab[] = "";
2083 // ECRM
2084 $tab[] = "";
2085 // DATK
2086 $tab[] = "";
2087 // HEUK
2088 $tab[] = "";
2089
2090 $output = implode($separator, $tab).$end_line;
2091 if ($exportFile) {
2092 fwrite($exportFile, $output);
2093 } else {
2094 print $output;
2095 }
2096 }
2097 }
2098
2109 public function exportLDCompta10($objectLines, $exportFile = null)
2110 {
2111 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
2112
2113 $separator = ';';
2114 $end_line = "\r\n";
2115 $last_codeinvoice = '';
2116
2117 foreach ($objectLines as $line) {
2118 // TYPE C
2119 if ($last_codeinvoice != $line->doc_ref) {
2120 //recherche societe en fonction de son code client
2121 $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
2122 $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
2123 $resql = $this->db->query($sql);
2124
2125 if ($resql && $this->db->num_rows($resql) > 0) {
2126 $soc = $this->db->fetch_object($resql);
2127
2128 $address = array('', '', '');
2129 if (strpos($soc->address, "\n") !== false) {
2130 $address = explode("\n", $soc->address);
2131 if (is_array($address) && count($address) > 0) {
2132 foreach ($address as $key => $data) {
2133 $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
2134 $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
2135 }
2136 }
2137 } else {
2138 $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
2139 $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
2140 $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
2141 }
2142
2143 $tab = array();
2144
2145 $type_enregistrement = 'C';
2146 //TYPE
2147 $tab[] = $type_enregistrement;
2148 //NOCL
2149 $tab[] = $soc->code_client;
2150 //NMCM
2151 $tab[] = "";
2152 //LIBI
2153 $tab[] = "";
2154 //TITR
2155 $tab[] = "";
2156 //RSSO
2157 $tab[] = $soc->nom;
2158 //CAD1
2159 $tab[] = $address[0];
2160 //CAD2
2161 $tab[] = $address[1];
2162 //CAD3
2163 $tab[] = $address[2];
2164 //COPO
2165 $tab[] = $soc->zip;
2166 //BUDI
2167 $tab[] = substr($soc->town, 0, 40);
2168 //CPAY
2169 $tab[] = "";
2170 //PAYS
2171 $tab[] = substr(getCountry($soc->fk_pays), 0, 40);
2172 //NTEL
2173 $tab[] = $soc->phone;
2174 //TLEX
2175 $tab[] = "";
2176 //TLPO
2177 $tab[] = "";
2178 //TLCY
2179 $tab[] = "";
2180 //NINT
2181 $tab[] = "";
2182 //COMM
2183 $tab[] = "";
2184 //SIRE
2185 $tab[] = str_replace(" ", "", $soc->siret);
2186 //RIBP
2187 $tab[] = "";
2188 //DOBQ
2189 $tab[] = "";
2190 //IBBQ
2191 $tab[] = "";
2192 //COBQ
2193 $tab[] = "";
2194 //GUBQ
2195 $tab[] = "";
2196 //CPBQ
2197 $tab[] = "";
2198 //CLBQ
2199 $tab[] = "";
2200 //BIBQ
2201 $tab[] = "";
2202 //MOPM
2203 $tab[] = "";
2204 //DJPM
2205 $tab[] = "";
2206 //DMPM
2207 $tab[] = "";
2208 //REFM
2209 $tab[] = "";
2210 //SLVA
2211 $tab[] = "";
2212 //PLCR
2213 $tab[] = "";
2214 //ECFI
2215 $tab[] = "";
2216 //CREP
2217 $tab[] = "";
2218 //NREP
2219 $tab[] = "";
2220 //TREP
2221 $tab[] = "";
2222 //MREP
2223 $tab[] = "";
2224 //GRRE
2225 $tab[] = "";
2226 //LTTA
2227 $tab[] = "";
2228 //CACT
2229 $tab[] = "";
2230 //CODV
2231 $tab[] = "";
2232 //GRTR
2233 $tab[] = "";
2234 //NOFP
2235 $tab[] = "";
2236 //BQAF
2237 $tab[] = "";
2238 //BONP
2239 $tab[] = "";
2240 //CESC
2241 $tab[] = "";
2242
2243 $output = implode($separator, $tab).$end_line;
2244 if ($exportFile) {
2245 fwrite($exportFile, $output);
2246 } else {
2247 print $output;
2248 }
2249 }
2250 }
2251
2252 $tab = array();
2253
2254 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2255 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
2256 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2257
2258 // TYPE E
2259 $type_enregistrement = 'E'; // For write movement
2260 $tab[] = $type_enregistrement;
2261 // JNAL
2262 $tab[] = substr($line->code_journal, 0, 2);
2263 // NECR
2264 $tab[] = $line->id;
2265 // NPIE
2266 $tab[] = $line->piece_num;
2267 // DATP
2268 $tab[] = $date_document;
2269 // LIBE
2270 $tab[] = dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1);
2271 // DATH
2272 $tab[] = $date_lim_reglement;
2273 // CNPI
2274 if ($line->doc_type == 'supplier_invoice') {
2275 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.
2276 $nature_piece = 'AF';
2277 } else {
2278 $nature_piece = 'FF';
2279 }
2280 } elseif ($line->doc_type == 'customer_invoice') {
2281 if (($line->amount) < 0) {
2282 $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.
2283 } else {
2284 $nature_piece = 'FC';
2285 }
2286 } else {
2287 $nature_piece = '';
2288 }
2289 $tab[] = $nature_piece;
2290 // RACI
2291 // if (!empty($line->subledger_account)) {
2292 // if ($line->doc_type == 'supplier_invoice') {
2293 // $racine_subledger_account = '40';
2294 // } elseif ($line->doc_type == 'customer_invoice') {
2295 // $racine_subledger_account = '41';
2296 // } else {
2297 // $racine_subledger_account = '';
2298 // }
2299 // } else {
2300 $racine_subledger_account = ''; // for records of type E leave this field blank
2301 // }
2302
2303 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2304 // MONT
2305 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2);
2306 // CODC
2307 $tab[] = $line->sens;
2308 // CPTG
2309 $tab[] = length_accountg($line->numero_compte);
2310 // DATE
2311 $tab[] = $date_document;
2312 // CLET
2313 $tab[] = $line->lettering_code;
2314 // DATL
2315 $tab[] = $line->date_lettering;
2316 // CPTA
2317 if (!empty($line->subledger_account)) {
2318 $tab[] = length_accounta($line->subledger_account);
2319 } else {
2320 $tab[] = "";
2321 }
2322 // C.N.A.T
2323 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2324 $tab[] = 'F';
2325 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2326 $tab[] = 'C';
2327 } else {
2328 $tab[] = "";
2329 }
2330 // CTRE
2331 $tab[] = "";
2332 // NORL
2333 $tab[] = "";
2334 // DATV
2335 $tab[] = "";
2336 // REFD
2337 $tab[] = $line->doc_ref;
2338 // NECA
2339 $tab[] = '0';
2340 // CSEC
2341 $tab[] = "";
2342 // CAFF
2343 $tab[] = "";
2344 // CDES
2345 $tab[] = "";
2346 // QTUE
2347 $tab[] = "";
2348 // MTDV
2349 $tab[] = '0';
2350 // CODV
2351 $tab[] = "";
2352 // TXDV
2353 $tab[] = '0';
2354 // MOPM
2355 $tab[] = "";
2356 // BONP
2357 $tab[] = "";
2358 // BQAF
2359 $tab[] = "";
2360 // ECES
2361 $tab[] = "";
2362 // TXTL
2363 $tab[] = "";
2364 // ECRM
2365 $tab[] = "";
2366 // DATK
2367 $tab[] = "";
2368 // HEUK
2369 $tab[] = "";
2370
2371 $output = implode($separator, $tab).$end_line;
2372 if ($exportFile) {
2373 fwrite($exportFile, $output);
2374 } else {
2375 print $output;
2376 }
2377
2378 $last_codeinvoice = $line->doc_ref;
2379 }
2380 }
2381
2389 public function exportCharlemagne($objectLines, $exportFile = null)
2390 {
2391 global $langs;
2392 $langs->load('compta');
2393
2394 $separator = "\t";
2395 $end_line = "\n";
2396
2397 $tab = array();
2398
2399 $tab[] = $langs->transnoentitiesnoconv('Date');
2400 $tab[] = self::trunc($langs->transnoentitiesnoconv('Journal'), 6);
2401 $tab[] = self::trunc($langs->transnoentitiesnoconv('Account'), 15);
2402 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60);
2403 $tab[] = self::trunc($langs->transnoentitiesnoconv('Piece'), 20);
2404 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60);
2405 $tab[] = $langs->transnoentitiesnoconv('Amount');
2406 $tab[] = 'S';
2407 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15);
2408 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60);
2409 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15);
2410 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60);
2411 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15);
2412 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60);
2413
2414 $output = implode($separator, $tab).$end_line;
2415 if ($exportFile) {
2416 fwrite($exportFile, $output);
2417 } else {
2418 print $output;
2419 }
2420
2421 foreach ($objectLines as $line) {
2422 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2423
2424 $tab = array();
2425
2426 $tab[] = $date_document; //Date
2427
2428 $tab[] = self::trunc($line->code_journal, 6); //Journal code
2429
2430 if (!empty($line->subledger_account)) {
2431 $account = $line->subledger_account;
2432 } else {
2433 $account = $line->numero_compte;
2434 }
2435 $tab[] = self::trunc((string) $account, 15); //Account number
2436
2437 $tab[] = self::trunc($line->label_compte, 60); //Account label
2438 $tab[] = self::trunc($line->doc_ref, 20); //Piece
2439 // Clean label operation to prevent problem on export with tab separator & other character
2440 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
2441 $tab[] = self::trunc($line->label_operation, 60); //Operation label
2442 $tab[] = price(abs($line->debit - $line->credit)); //Amount
2443 $tab[] = $line->sens; //Direction
2444 $tab[] = ""; //Analytic
2445 $tab[] = ""; //Analytic
2446 $tab[] = ""; //Analytic
2447 $tab[] = ""; //Analytic
2448 $tab[] = ""; //Analytic
2449 $tab[] = ""; //Analytic
2450
2451 $output = implode($separator, $tab).$end_line;
2452 if ($exportFile) {
2453 fwrite($exportFile, $output);
2454 } else {
2455 print $output;
2456 }
2457 }
2458 }
2459
2467 public function exportGestimumV3($objectLines, $exportFile = null)
2468 {
2469 global $langs;
2470
2471 $separator = ',';
2472 $end_line = "\r\n";
2473
2474 $invoices_infos = array();
2475 $supplier_invoices_infos = array();
2476 foreach ($objectLines as $line) {
2477 if ($line->debit == 0 && $line->credit == 0) {
2478 //unset($array[$line]);
2479 } else {
2480 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
2481 $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2482
2483 $invoice_ref = $line->doc_ref;
2484 $company_name = "";
2485
2486 if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
2487 if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2488 ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2489 if ($line->doc_type == 'customer_invoice') {
2490 // Get new customer invoice ref and company name
2491 $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
2492 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
2493 $sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
2494 $resql = $this->db->query($sql);
2495 if ($resql) {
2496 if ($obj = $this->db->fetch_object($resql)) {
2497 // Save invoice infos
2498 $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2499 $invoice_ref = $obj->ref;
2500 $company_name = $obj->nom;
2501 }
2502 }
2503 } else {
2504 // Get new supplier invoice ref and company name
2505 $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
2506 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
2507 $sql .= ' WHERE ff.rowid = '.((int) $line->fk_doc);
2508 $resql = $this->db->query($sql);
2509 if ($resql) {
2510 if ($obj = $this->db->fetch_object($resql)) {
2511 // Save invoice infos
2512 $supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2513 $invoice_ref = $obj->ref;
2514 $company_name = $obj->nom;
2515 }
2516 }
2517 }
2518 } elseif ($line->doc_type == 'customer_invoice') {
2519 // Retrieve invoice infos
2520 $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
2521 $company_name = $invoices_infos[$line->fk_doc]['company_name'];
2522 } else {
2523 // Retrieve invoice infos
2524 $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
2525 $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
2526 }
2527 }
2528
2529 $tab = array();
2530
2531 $tab[] = $line->id;
2532 $tab[] = $date_document;
2533 $tab[] = substr($line->code_journal, 0, 4);
2534
2535 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
2536 $tab[] = length_accountg($line->subledger_account);
2537 } else {
2538 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2539 }
2540 //Libellé Auto
2541 $tab[] = "";
2542 //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"';
2543 //Libellé manual
2544 $tab[] = dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1);
2545 //Numéro de pièce
2546 $tab[] = dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1);
2547 //Devise
2548 $tab[] = 'EUR';
2549 //Amount
2550 $tab[] = price2num(abs($line->debit - $line->credit));
2551 //Sens
2552 $tab[] = $line->sens;
2553 //Code lettrage
2554 $tab[] = "";
2555 //Date Echéance
2556 $tab[] = $date_echeance;
2557
2558 $output = implode($separator, $tab).$end_line;
2559 if ($exportFile) {
2560 fwrite($exportFile, $output);
2561 } else {
2562 print $output;
2563 }
2564 }
2565 }
2566 }
2567
2575 public function exportGestimumV5($objectLines, $exportFile = null)
2576 {
2577 $separator = ',';
2578 $end_line = "\r\n";
2579
2580 foreach ($objectLines as $line) {
2581 if ($line->debit == 0 && $line->credit == 0) {
2582 //unset($array[$line]);
2583 } else {
2584 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
2585
2586 $tab = array();
2587
2588 $tab[] = $line->id;
2589 $tab[] = $date_document;
2590 $tab[] = substr($line->code_journal, 0, 4);
2591 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
2592 $tab[] = length_accountg($line->subledger_account);
2593 } else {
2594 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2595 }
2596 $tab[] = "";
2597 $tab[] = '"'.dol_trunc(str_replace('"', '', $line->label_operation), 40, 'right', 'UTF-8', 1).'"';
2598 $tab[] = '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"';
2599 $tab[] = '"' . dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1) . '"';
2600 $tab[] = price2num(abs($line->debit - $line->credit));
2601 $tab[] = $line->sens;
2602 $tab[] = $date_document;
2603 $tab[] = "";
2604 $tab[] = "";
2605 $tab[] = 'EUR';
2606
2607 $output = implode($separator, $tab).$end_line;
2608 if ($exportFile) {
2609 fwrite($exportFile, $output);
2610 } else {
2611 print $output;
2612 }
2613 }
2614 }
2615 }
2616
2626 public function exportiSuiteExpert($objectLines, $exportFile = null)
2627 {
2628 $separator = ';';
2629 $end_line = "\r\n";
2630
2631
2632 foreach ($objectLines as $line) {
2633 $tab = array();
2634
2635 $date = dol_print_date($line->doc_date, '%d/%m/%Y');
2636
2637 $tab[] = $line->piece_num;
2638 $tab[] = $date;
2639 $tab[] = substr($date, 6, 4);
2640 $tab[] = substr($date, 3, 2);
2641 $tab[] = substr($date, 0, 2);
2642 $tab[] = $line->doc_ref;
2643 //Conversion de chaine UTF8 en Latin9
2644 $tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
2645
2646 //Calcul de la longueur des numéros de comptes
2647 $taille_numero = strlen(length_accountg($line->numero_compte));
2648
2649 //Création du numéro de client et fournisseur générique
2650 $numero_cpt_client = '411';
2651 $numero_cpt_fourn = '401';
2652 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2653 $numero_cpt_client .= '0';
2654 $numero_cpt_fourn .= '0';
2655 }
2656
2657 //Création des comptes auxiliaire des clients et fournisseur
2658 if (length_accountg($line->numero_compte) == $numero_cpt_client || length_accountg($line->numero_compte) == $numero_cpt_fourn) {
2659 $tab[] = rtrim(length_accounta($line->subledger_account), "0");
2660 } else {
2661 $tab[] = length_accountg($line->numero_compte);
2662 }
2663 $nom_client = explode(" - ", $line->label_operation);
2664 $tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
2665 $tab[] = price($line->debit);
2666 $tab[] = price($line->credit);
2667 $tab[] = price($line->montant);
2668 $tab[] = $line->code_journal;
2669
2670 $output = implode($separator, $tab).$end_line;
2671 if ($exportFile) {
2672 fwrite($exportFile, $output);
2673 } else {
2674 print $output;
2675 }
2676 }
2677 }
2678
2686 public static function trunc($str, $size)
2687 {
2688 return dol_trunc($str, $size, 'right', 'UTF-8', 1);
2689 }
2690
2698 public static function toAnsi($str, $size = -1)
2699 {
2700 $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
2701 if ($retVal >= 0 && $size >= 0) {
2702 $retVal = dol_substr($retVal, 0, $size, 'Windows-1251');
2703 }
2704 return $retVal;
2705 }
2706}
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