dolibarr 21.0.4
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 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 $reshook = $hookmanager->executeHooks('export', $parameters, $TData);
555 if ($reshook != 1) {
556 $this->errors[] = $langs->trans('accountancy_error_modelnotfound');
557 } elseif (!empty($hookmanager->resArray['downloadFileFullName']) && !empty($hookmanager->resArray['downloadFilePath'])) {
558 $exportFileFullName = $hookmanager->resArray['downloadFileFullName'];
559 $exportFilePath = $hookmanager->resArray['downloadFilePath'];
560 }
561 break;
562 }
563
564
565 // Create and download export file or archive
566 if ($outputMode == 1 || $outputMode == 2) {
567 $error = 0;
568
569 // close export file
570 if ($exportFile) {
571 fclose($exportFile);
572 }
573
574 if ($withAttachment == 1) {
575 // create archive file
576 if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
577 // archive files
578 $downloadFileMimeType = 'application/zip';
579 $downloadFileFullName = $archiveFullName;
580 $downloadFilePath = $archivePath;
581
582 // create archive
583 $archive = new ZipArchive();
584 $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
585 if ($res !== true) {
586 $error++;
587 $this->errors[] = $langs->trans('ErrorFileNotFound', $archivePath);
588 }
589 if (!$error) {
590 // add files
591 foreach ($archiveFileList as $archiveFileArr) {
592 $res = $archive->addFile($archiveFileArr['path'], $archiveFileArr['name']);
593 if (!$res) {
594 $error++;
595 $this->errors[] = $langs->trans('ErrorArchiveAddFile', $archiveFileArr['name']);
596 break;
597 }
598 }
599 }
600 if (!$error) {
601 // close archive
602 $archive->close();
603 }
604 }
605 }
606
607 if (!$error) {
608 // download after writing files
609 if ($downloadMode == 1) {
610 if ($withAttachment == 0) {
611 // only download exported file
612 if (!empty($exportFileFullName) && !empty($exportFilePath)) {
613 $downloadFileMimeType = $mimetype;
614 $downloadFileFullName = $exportFileFullName;
615 $downloadFilePath = $exportFilePath;
616 }
617 }
618
619 // download export file or archive
620 if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath) && empty($noouput)) {
621 // deprecated. We must not use this anymore, but have $noouput = 1 because HTTP header must be sent
622 // into main page not into a method.
623 header('Content-Type: ' . $downloadFileMimeType);
624 header('Content-Disposition: attachment; filename=' . $downloadFileFullName);
625 header('Cache-Control: Public, must-revalidate');
626 header('Pragma: public');
627 header('Content-Length: ' . dol_filesize($downloadFilePath));
628
629 readfileLowMemory($downloadFilePath);
630 }
631
632 $this->generatedfiledata = array('downloadFilePath' => $downloadFilePath, 'downloadFileMimeType' => $downloadFileMimeType, 'downloadFileFullName' => $downloadFileFullName);
633 }
634 }
635
636 if ($error) {
637 return -1;
638 }
639 }
640
641 return 1;
642 }
643
644
652 public function exportCegid($objectLines, $exportFile = null)
653 {
654 $separator = ";";
655 $end_line = "\n";
656
657 foreach ($objectLines as $line) {
658 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
659
660 $tab = array();
661
662 $tab[] = $date_document;
663 $tab[] = $line->code_journal;
664 $tab[] = length_accountg($line->numero_compte);
665 $tab[] = length_accounta($line->subledger_account);
666 $tab[] = $line->sens;
667 $tab[] = price2fec(abs($line->debit - $line->credit));
668 $tab[] = dol_string_unaccent($line->label_operation);
669 $tab[] = dol_string_unaccent($line->doc_ref);
670
671 $output = implode($separator, $tab).$end_line;
672 if ($exportFile) {
673 fwrite($exportFile, $output);
674 } else {
675 print $output;
676 }
677 }
678 }
679
688 public function exportCogilog($objectLines, $exportFile = null)
689 {
690 $separator = "\t";
691 $end_line = "\n";
692
693 foreach ($objectLines as $line) {
694 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
695
696 $refInvoice = '';
697 if ($line->doc_type == 'customer_invoice') {
698 // Customer invoice
699 require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
700 $invoice = new Facture($this->db);
701 $invoice->fetch($line->fk_doc);
702
703 $refInvoice = $invoice->ref;
704 } elseif ($line->doc_type == 'supplier_invoice') {
705 // Supplier invoice
706 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
707 $invoice = new FactureFournisseur($this->db);
708 $invoice->fetch($line->fk_doc);
709
710 $refInvoice = $invoice->ref_supplier;
711 }
712
713 $tab = array();
714
715 $tab[] = $line->code_journal;
716 $tab[] = $date_document;
717 $tab[] = $refInvoice;
718 if (empty($line->subledger_account)) {
719 $tab[] = length_accountg($line->numero_compte);
720 } else {
721 $tab[] = length_accounta($line->subledger_account);
722 }
723 $tab[] = "";
724 $tab[] = $line->label_operation;
725 $tab[] = $date_document;
726 if ($line->sens == 'D') {
727 $tab[] = price($line->debit);
728 $tab[] = "";
729 } elseif ($line->sens == 'C') {
730 $tab[] = "";
731 $tab[] = price($line->credit);
732 }
733 $tab[] = $line->doc_ref;
734 $tab[] = $line->label_operation;
735
736 $output = implode($separator, $tab).$end_line;
737 if ($exportFile) {
738 fwrite($exportFile, $output);
739 } else {
740 print $output;
741 }
742 }
743 }
744
752 public function exportCoala($objectLines, $exportFile = null)
753 {
754 // Coala export
755 $separator = ";";
756 $end_line = "\n";
757
758 foreach ($objectLines as $line) {
759 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
760
761 $tab = array();
762
763 $tab[] = $date_document;
764 $tab[] = $line->code_journal;
765 $tab[] = length_accountg($line->numero_compte);
766 $tab[] = $line->piece_num;
767 $tab[] = $line->doc_ref;
768 $tab[] = price($line->debit);
769 $tab[] = price($line->credit);
770 $tab[] = 'E';
771 $tab[] = length_accounta($line->subledger_account);
772
773 $output = implode($separator, $tab).$end_line;
774 if ($exportFile) {
775 fwrite($exportFile, $output);
776 } else {
777 print $output;
778 }
779 }
780 }
781
789 public function exportBob50($objectLines, $exportFile = null)
790 {
791 // Bob50
792 $separator = ";";
793 $end_line = "\n";
794
795 foreach ($objectLines as $line) {
796 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
797
798 $tab = array();
799
800 $tab[] = $line->piece_num;
801 $tab[] = $date_document;
802
803 if (empty($line->subledger_account)) {
804 $tab[] = 'G';
805 $tab[] = length_accountg($line->numero_compte);
806 } else {
807 if (substr($line->numero_compte, 0, 3) == '411') {
808 $tab[] = 'C';
809 }
810 if (substr($line->numero_compte, 0, 3) == '401') {
811 $tab[] = 'F';
812 }
813 $tab[] = length_accounta($line->subledger_account);
814 }
815
816 $tab[] = price($line->debit);
817 $tab[] = price($line->credit);
818 $tab[] = dol_trunc($line->label_operation, 32);
819
820 $output = implode($separator, $tab).$end_line;
821 if ($exportFile) {
822 fwrite($exportFile, $output);
823 } else {
824 print $output;
825 }
826 }
827 }
828
844 public function exportCiel($objectLines, $exportFile = null)
845 {
846 $end_line = "\r\n";
847
848 $i = 1;
849
850 foreach ($objectLines as $line) {
851 $code_compta = length_accountg($line->numero_compte);
852 if (!empty($line->subledger_account)) {
853 $code_compta = length_accounta($line->subledger_account);
854 }
855
856 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
857 $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d');
858
859 $tab = array();
860
861 $tab[] = str_pad((string) $line->piece_num, 5);
862 $tab[] = str_pad(self::trunc($line->code_journal, 2), 2);
863 $tab[] = str_pad($date_document, 8, ' ', STR_PAD_LEFT);
864 $tab[] = str_pad($date_echeance, 8, ' ', STR_PAD_LEFT);
865 $tab[] = str_pad(self::trunc($line->doc_ref, 12), 12);
866 $tab[] = str_pad(self::trunc($code_compta, 11), 11);
867 $tab[] = str_pad(self::trunc(dol_string_unaccent($line->doc_ref).dol_string_unaccent($line->label_operation), 25), 25);
868 $tab[] = str_pad(price2fec(abs($line->debit - $line->credit)), 13, ' ', STR_PAD_LEFT);
869 $tab[] = str_pad($line->sens, 1);
870 $tab[] = str_repeat(' ', 18); // Analytical accounting - Not managed in Dolibarr
871 $tab[] = str_pad(self::trunc(dol_string_unaccent($line->label_operation), 34), 34);
872 $tab[] = 'O2003'; // 0 = EUR | 2003 = Format Ciel
873
874 $output = implode($tab).$end_line;
875 if ($exportFile) {
876 fwrite($exportFile, $output);
877 } else {
878 print $output;
879 }
880 $i++;
881 }
882 }
883
899 public function exportQuadratus($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
900 {
901 global $conf, $db;
902
903 $end_line = "\r\n";
904
905 // We should use dol_now function not time however this is wrong date to transfer in accounting
906 foreach ($objectLines as $line) {
907 // Clean some data
908 $line->doc_ref = dol_string_unaccent($line->doc_ref);
909
910 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
911 $line->label_operation = str_replace(array("- ", "…", "..."), "", $line->label_operation);
912 $line->label_operation = dol_string_unaccent($line->label_operation);
913
914 $line->numero_compte = dol_string_unaccent($line->numero_compte);
915 $line->label_compte = dol_string_unaccent($line->label_compte);
916 $line->subledger_account = dol_string_unaccent($line->subledger_account);
917
918 $line->subledger_label = str_replace(array("- ", "…", "..."), "", $line->subledger_label);
919 $line->subledger_label = dol_string_unaccent($line->subledger_label);
920
921 $code_compta = $line->numero_compte;
922 if (!empty($line->subledger_account)) {
923 $code_compta = $line->subledger_account;
924 }
925
926 $tab = array();
927
928 if (!empty($line->subledger_account)) {
929 $tab['type_ligne'] = 'C';
930 $tab['num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8);
931 $tab['lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30);
932
933 if ($line->doc_type == 'customer_invoice') {
934 $tab['lib_alpha'] = strtoupper(str_pad('C'.self::trunc(dol_string_unaccent($line->subledger_label), 6), 7));
935 $tab['filler'] = str_repeat(' ', 52);
936 $tab['coll_compte'] = str_pad(self::trunc(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), 8), 8);
937 } elseif ($line->doc_type == 'supplier_invoice') {
938 $tab['lib_alpha'] = strtoupper(str_pad('F'.self::trunc(dol_string_unaccent($line->subledger_label), 6), 7));
939 $tab['filler'] = str_repeat(' ', 52);
940 $tab['coll_compte'] = str_pad(self::trunc(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER'), 8), 8);
941 } else {
942 $tab['filler'] = str_repeat(' ', 59);
943 $tab['coll_compte'] = str_pad(' ', 8);
944 }
945
946 $tab['filler2'] = str_repeat(' ', 110);
947 $tab['Maj'] = 2; // Partial update (alpha key, label, address, collectif, RIB)
948
949 if ($line->doc_type == 'customer_invoice') {
950 $tab['type_compte'] = 'C';
951 } elseif ($line->doc_type == 'supplier_invoice') {
952 $tab['type_compte'] = 'F';
953 } else {
954 $tab['type_compte'] = 'G';
955 }
956
957 $tab['filler3'] = str_repeat(' ', 235);
958
959 $tab['end_line'] = $end_line;
960
961 if ($exportFile) {
962 fwrite($exportFile, implode($tab));
963 } else {
964 print implode($tab);
965 }
966 }
967
968 $tab = array();
969 $tab['type_ligne'] = 'M';
970 $tab['num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
971 $tab['code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
972 $tab['folio'] = '000';
973
974 // We use invoice date $line->doc_date not $date_ecriture which is the transfer date
975 // maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
976 //$tab['date_ecriture'] = $date_ecriture;
977 $tab['date_ecriture'] = dol_print_date($line->doc_date, '%d%m%y');
978 $tab['filler'] = ' ';
979 $tab['libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.' '.$line->label_operation, 20), 20);
980
981 // Credit invoice - invert sens
982 /*
983 if ($line->montant < 0) {
984 if ($line->sens == 'C') {
985 $tab['sens'] = 'D';
986 } else {
987 $tab['sens'] = 'C';
988 }
989 $tab['signe_montant'] = '-';
990 } else {
991 $tab['sens'] = $line->sens; // C or D
992 $tab['signe_montant'] = '+';
993 }*/
994 $tab['sens'] = $line->sens; // C or D
995 $tab['signe_montant'] = '+';
996
997 // The amount must be in centimes without decimal points.
998 $tab['montant'] = str_pad((string) abs(($line->debit - $line->credit) * 100), 12, '0', STR_PAD_LEFT);
999 $tab['contrepartie'] = str_repeat(' ', 8);
1000
1001 // Force date format : %d%m%y
1002 if (!empty($line->date_lim_reglement)) {
1003 $tab['date_echeance'] = dol_print_date($line->date_lim_reglement, '%d%m%y'); // Format must be ddmmyy
1004 } else {
1005 $tab['date_echeance'] = '000000';
1006 }
1007
1008 // Please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
1009 // $tab['lettrage'] = str_repeat(' ', 5);
1010 $tab['lettrage'] = str_repeat(' ', 2);
1011 $tab['codestat'] = str_repeat(' ', 3);
1012 $tab['num_piece'] = str_pad(self::trunc((string) $line->piece_num, 5), 5);
1013
1014 // Keep correct quadra named field instead of anon filler
1015 // $tab['filler2'] = str_repeat(' ', 20);
1016 $tab['affaire'] = str_repeat(' ', 10);
1017 $tab['quantity1'] = str_repeat(' ', 10);
1018 $tab['num_piece2'] = str_pad(self::trunc((string) $line->piece_num, 8), 8);
1019 $tab['devis'] = str_pad($conf->currency, 3);
1020 $tab['code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
1021 $tab['filler3'] = str_repeat(' ', 3);
1022
1023 // Keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
1024 // 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
1025 // TODO: we should filter more than only accent to avoid wrong line size
1026 // TODO: remove invoice number doc_ref in label,
1027 // TODO: we should offer an option for customer to build the label using invoice number / name / date in accounting software
1028 //$tab['libelle_ecriture2'] = str_pad(self::trunc($line->doc_ref . ' ' . $line->label_operation, 30), 30);
1029 $tab['libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
1030 $tab['codetva'] = str_repeat(' ', 2);
1031
1032 // We need to keep the 10 latest number of invoices doc_ref not the beginning part that is the useless almost same part
1033 // $tab['num_piece3'] = str_pad(self::trunc($line->piece_num, 10), 10);
1034 $tab['num_piece3'] = str_pad(substr(self::trunc($line->doc_ref, 20), -10), 10);
1035 $tab['reserved'] = str_repeat(' ', 10); // position 159
1036 $tab['currency_amount'] = str_repeat(' ', 13); // position 169
1037 // get document file
1038 $attachmentFileName = '';
1039 if ($withAttachment == 1) {
1040 $attachmentFileKey = trim((string) $line->piece_num);
1041
1042 if (!isset($archiveFileList[$attachmentFileKey])) {
1043 $objectDirPath = '';
1044 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1045 if ($line->doc_type == 'customer_invoice') {
1046 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1047 } elseif ($line->doc_type == 'expense_report') {
1048 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1049 } elseif ($line->doc_type == 'supplier_invoice') {
1050 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1051 $invoice = new FactureFournisseur($this->db);
1052 $invoice->fetch($line->fk_doc);
1053 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1054 $objectDirPath .= '/'.rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1055 }
1056 $arrayofinclusion = array();
1057 // If it is a supplier invoice, we want to use last uploaded file
1058 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1059 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1060 if (!empty($fileFoundList)) {
1061 $attachmentFileNameTrunc = str_pad(self::trunc((string) $line->piece_num, 8), 8, '0', STR_PAD_LEFT);
1062 foreach ($fileFoundList as $fileFound) {
1063 if (strstr($fileFound['name'], $objectFileName)) {
1064 // skip native invoice pdfs (canelle)
1065 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1066 if ($line->doc_type == 'supplier_invoice') {
1067 if ($fileFound['name'] === $objectFileName.'.pdf') {
1068 continue;
1069 }
1070 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1071 continue;
1072 }
1073 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1074 if (file_exists($fileFoundPath)) {
1075 $archiveFileList[$attachmentFileKey] = array(
1076 'path' => $fileFoundPath,
1077 'name' => $attachmentFileNameTrunc.'.pdf',
1078 );
1079 break;
1080 }
1081 }
1082 }
1083 }
1084 }
1085
1086 if (isset($archiveFileList[$attachmentFileKey])) {
1087 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1088 }
1089 }
1090 if (dol_strlen($attachmentFileName) == 12) {
1091 $tab['attachment'] = $attachmentFileName; // position 182
1092 } else {
1093 $tab['attachment'] = str_repeat(' ', 12); // position 182
1094 }
1095 $tab['filler4'] = str_repeat(' ', 38);
1096 $tab['end_line'] = $end_line;
1097
1098 if ($exportFile) {
1099 fwrite($exportFile, implode($tab));
1100 } else {
1101 print implode($tab);
1102 }
1103 }
1104
1105 return $archiveFileList;
1106 }
1107
1118 public function exportWinfic($objectLines, $exportFile = null)
1119 {
1120 global $conf;
1121
1122 $end_line = "\r\n";
1123 $index = 1;
1124
1125 // Warning ! When truncation is necessary, no dot because 3 dots = three characters. The columns are shifted
1126
1127 foreach ($objectLines as $line) {
1128 $code_compta = $line->numero_compte;
1129 if (!empty($line->subledger_account)) {
1130 $code_compta = $line->subledger_account;
1131 }
1132
1133 $tab = array();
1134 //$tab['type_ligne'] = 'M';
1135 $tab['code_journal'] = str_pad(dol_trunc($line->code_journal, 2, 'right', 'UTF-8', 1), 2);
1136
1137 //We use invoice date $line->doc_date not $date_ecriture which is the transfer date
1138 //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
1139 //$tab['date_ecriture'] = $date_ecriture;
1140 $tab['date_operation'] = dol_print_date($line->doc_date, '%d%m%Y');
1141
1142 $tab['folio'] = ' 1';
1143
1144 $tab['num_ecriture'] = str_pad(dol_trunc((string) $index, 6, 'right', 'UTF-8', 1), 6, ' ', STR_PAD_LEFT);
1145
1146 $tab['jour_ecriture'] = dol_print_date($line->doc_date, '%d%m%y');
1147
1148 $tab['num_compte'] = str_pad(dol_trunc($code_compta, 6, 'right', 'UTF-8', 1), 6, '0');
1149
1150 if ($line->sens == 'D') {
1151 $tab['montant_debit'] = str_pad(number_format($line->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1152
1153 $tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1154 } else {
1155 $tab['montant_debit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1156
1157 $tab['montant_crebit'] = str_pad(number_format($line->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1158 }
1159
1160 $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);
1161
1162 $tab['lettrage'] = str_repeat(dol_trunc($line->lettering_code, 2, 'left', 'UTF-8', 1), 2);
1163
1164 $tab['code_piece'] = str_pad(dol_trunc((string) $line->piece_num, 5, 'left', 'UTF-8', 1), 5, ' ', STR_PAD_LEFT);
1165
1166 $tab['code_stat'] = str_repeat(' ', 4);
1167
1168 if (!empty($line->date_lim_reglement)) {
1169 $tab['date_echeance'] = dol_print_date($line->date_lim_reglement, '%d%m%Y');
1170 } else {
1171 $tab['date_echeance'] = dol_print_date($line->doc_date, '%d%m%Y');
1172 }
1173
1174 $tab['monnaie'] = '1';
1175
1176 $tab['filler'] = ' ';
1177
1178 $tab['ind_compteur'] = ' ';
1179
1180 $tab['quantite'] = '0,000000000';
1181
1182 $tab['code_pointage'] = str_repeat(' ', 2);
1183
1184 $tab['end_line'] = $end_line;
1185
1186 print implode('|', $tab);
1187
1188 $index++;
1189 }
1190 }
1191
1192
1200 public function exportEbp($objectLines, $exportFile = null)
1201 {
1202 $separator = ',';
1203 $end_line = "\n";
1204
1205 foreach ($objectLines as $line) {
1206 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
1207
1208 $tab = array();
1209
1210 $tab[] = $line->id;
1211 $tab[] = $date_document;
1212 $tab[] = $line->code_journal;
1213 if (empty($line->subledger_account)) {
1214 $tab[] = $line->numero_compte;
1215 } else {
1216 $tab[] = $line->subledger_account;
1217 }
1218 //$tab[] = substr(length_accountg($line->numero_compte), 0, 2) . $separator;
1219 $tab[] = '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"';
1220 $tab[] = '"'.dol_trunc((string) $line->piece_num, 15, 'right', 'UTF-8', 1).'"';
1221 $tab[] = price2num(abs($line->debit - $line->credit));
1222 $tab[] = $line->sens;
1223 $tab[] = $date_document;
1224 //print 'EUR';
1225
1226 $output = implode($separator, $tab).$end_line;
1227 if ($exportFile) {
1228 fwrite($exportFile, $output);
1229 } else {
1230 print $output;
1231 }
1232 }
1233 }
1234
1235
1243 public function exportAgiris($objectLines, $exportFile = null)
1244 {
1245 $separator = ';';
1246 $end_line = "\n";
1247
1248 foreach ($objectLines as $line) {
1249 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
1250
1251 $tab = array();
1252
1253 $tab[] = $line->piece_num;
1254 $tab[] = self::toAnsi($line->label_operation);
1255 $tab[] = $date_document;
1256 $tab[] = self::toAnsi($line->label_operation);
1257
1258 if (empty($line->subledger_account)) {
1259 $tab[] = length_accountg($line->numero_compte);
1260 $tab[] = self::toAnsi($line->label_compte);
1261 } else {
1262 $tab[] = length_accounta($line->subledger_account);
1263 $tab[] = self::toAnsi($line->subledger_label);
1264 }
1265
1266 $tab[] = self::toAnsi($line->doc_ref);
1267 $tab[] = price($line->debit);
1268 $tab[] = price($line->credit);
1269 $tab[] = price(abs($line->debit - $line->credit));
1270 $tab[] = $line->sens;
1271 $tab[] = $line->lettering_code;
1272 $tab[] = $line->code_journal;
1273
1274 $output = implode($separator, $tab).$end_line;
1275 if ($exportFile) {
1276 fwrite($exportFile, $output);
1277 } else {
1278 print $output;
1279 }
1280 }
1281 }
1282
1290 public function exportOpenConcerto($objectLines, $exportFile = null)
1291 {
1292 $separator = ';';
1293 $end_line = "\n";
1294
1295 foreach ($objectLines as $line) {
1296 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
1297
1298 $tab = array();
1299
1300 $tab[] = $date_document;
1301 $tab[] = $line->code_journal;
1302 if (empty($line->subledger_account)) {
1303 $tab[] = length_accountg($line->numero_compte);
1304 } else {
1305 $tab[] = length_accounta($line->subledger_account);
1306 }
1307 $tab[] = $line->doc_ref;
1308 $tab[] = $line->label_operation;
1309 $tab[] = price($line->debit);
1310 $tab[] = price($line->credit);
1311
1312 $output = implode($separator, $tab).$end_line;
1313 if ($exportFile) {
1314 fwrite($exportFile, $output);
1315 } else {
1316 print $output;
1317 }
1318 }
1319 }
1320
1328 public function exportConfigurable($objectLines, $exportFile = null)
1329 {
1330 global $conf;
1331
1332 $separator = $this->separator;
1333
1334 foreach ($objectLines as $line) {
1335 $date_document = dol_print_date($line->doc_date, getDolGlobalString('ACCOUNTING_EXPORT_DATE'));
1336
1337 $tab = array();
1338 // export configurable
1339 $tab[] = $line->piece_num;
1340 $tab[] = $date_document;
1341 $tab[] = $line->doc_ref;
1342 $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
1343 $tab[] = length_accountg($line->numero_compte);
1344 $tab[] = length_accounta($line->subledger_account);
1345 $tab[] = price2num($line->debit);
1346 $tab[] = price2num($line->credit);
1347 $tab[] = price2num($line->debit - $line->credit);
1348 $tab[] = $line->code_journal;
1349
1350 $output = implode($separator, $tab).$this->end_line;
1351 if ($exportFile) {
1352 fwrite($exportFile, $output);
1353 } else {
1354 print $output;
1355 }
1356 }
1357 }
1358
1371 public function exportFEC($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
1372 {
1373 global $conf, $langs;
1374
1375 $separator = "\t";
1376 $end_line = "\r\n";
1377
1378 $tab = array();
1379 $tab[] = "JournalCode";
1380 $tab[] = "JournalLib";
1381 $tab[] = "EcritureNum";
1382 $tab[] = "EcritureDate";
1383 $tab[] = "CompteNum";
1384 $tab[] = "CompteLib";
1385 $tab[] = "CompAuxNum";
1386 $tab[] = "CompAuxLib";
1387 $tab[] = "PieceRef";
1388 $tab[] = "PieceDate";
1389 $tab[] = "EcritureLib";
1390 $tab[] = "Debit";
1391 $tab[] = "Credit";
1392 $tab[] = "EcritureLet";
1393 $tab[] = "DateLet";
1394 $tab[] = "ValidDate";
1395 $tab[] = "Montantdevise";
1396 $tab[] = "Idevise";
1397 $tab[] = "DateLimitReglmt";
1398 $tab[] = "NumFacture";
1399 $tab[] = "FichierFacture";
1400
1401 $output = implode($separator, $tab).$end_line;
1402 if ($exportFile) {
1403 fwrite($exportFile, $output);
1404 } else {
1405 print $output;
1406 }
1407
1408 foreach ($objectLines as $line) {
1409 if ($line->debit == 0 && $line->credit == 0) {
1410 //var_dump($line->id);
1411 //unset($array[$line]);
1412 } else {
1413 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1414 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1415 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1416 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1417 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1418
1419 $refInvoice = '';
1420 if ($line->doc_type == 'customer_invoice') {
1421 // Customer invoice
1422 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1423 $invoice = new Facture($this->db);
1424 $invoice->fetch($line->fk_doc);
1425
1426 $refInvoice = $invoice->ref;
1427 } elseif ($line->doc_type == 'supplier_invoice') {
1428 // Supplier invoice
1429 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1430 $invoice = new FactureFournisseur($this->db);
1431 $invoice->fetch($line->fk_doc);
1432
1433 $refInvoice = $invoice->ref_supplier;
1434 }
1435
1436 $tab = array();
1437
1438 // FEC:JournalCode
1439 $tab[] = $line->code_journal;
1440
1441 // FEC:JournalLib
1442 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1443 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1444 $tab[] = $labeljournal;
1445
1446 // FEC:EcritureNum
1447 $tab[] = $line->piece_num;
1448
1449 // FEC:EcritureDate
1450 $tab[] = $date_document;
1451
1452 // FEC:CompteNum
1453 $tab[] = length_accountg($line->numero_compte);
1454
1455 // FEC:CompteLib
1456 $tab[] = dol_string_unaccent($line->label_compte);
1457
1458 // FEC:CompAuxNum
1459 $tab[] = length_accounta($line->subledger_account);
1460
1461 // FEC:CompAuxLib
1462 $tab[] = dol_string_unaccent($line->subledger_label);
1463
1464 // FEC:PieceRef
1465 $tab[] = $line->doc_ref;
1466
1467 // FEC:PieceDate
1468 $tab[] = dol_string_unaccent($date_creation);
1469
1470 // FEC:EcritureLib
1471 // Clean label operation to prevent problem on export with tab separator & other character
1472 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1473 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1474 $tab[] = dol_string_unaccent($line->label_operation);
1475
1476 // FEC:Debit
1477 $tab[] = price2fec($line->debit);
1478
1479 // FEC:Credit
1480 $tab[] = price2fec($line->credit);
1481
1482 // FEC:EcritureLet
1483 $tab[] = $line->lettering_code;
1484
1485 // FEC:DateLet
1486 $tab[] = $date_lettering;
1487
1488 // FEC:ValidDate
1489 $tab[] = $date_validation;
1490
1491 // FEC:Montantdevise
1492 $tab[] = $line->multicurrency_amount;
1493
1494 // FEC:Idevise
1495 $tab[] = $line->multicurrency_code;
1496
1497 // FEC_suppl:DateLimitReglmt
1498 $tab[] = $date_limit_payment;
1499
1500 // FEC_suppl:NumFacture
1501 // Clean ref invoice to prevent problem on export with tab separator & other character
1502 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1503 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1504
1505 // FEC_suppl:FichierFacture
1506 // get document file
1507 $attachmentFileName = '';
1508 if ($withAttachment == 1) {
1509 $attachmentFileKey = trim((string) $line->piece_num);
1510
1511 if (!isset($archiveFileList[$attachmentFileKey])) {
1512 $objectDirPath = '';
1513 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1514 if ($line->doc_type == 'customer_invoice') {
1515 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1516 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1517 }
1518 } elseif ($line->doc_type == 'expense_report') {
1519 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1520 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1521 }
1522 } elseif ($line->doc_type == 'supplier_invoice') {
1523 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1524 '@phan-var-force FactureFournisseur $invoice';
1526 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1527 $objectDirPath .= '/' . rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1528 }
1529 }
1530 $arrayofinclusion = array();
1531 // If it is a supplier invoice, we want to use last uploaded file
1532 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1533 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1534 if (!empty($fileFoundList)) {
1535 $attachmentFileNameTrunc = $line->doc_ref;
1536 foreach ($fileFoundList as $fileFound) {
1537 if (strstr($fileFound['name'], $objectFileName)) {
1538 // skip native invoice pdfs (canelle)
1539 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1540 if ($line->doc_type == 'supplier_invoice') {
1541 if ($fileFound['name'] === $objectFileName.'.pdf') {
1542 continue;
1543 }
1544 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1545 continue;
1546 }
1547 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1548 if (file_exists($fileFoundPath)) {
1549 $archiveFileList[$attachmentFileKey] = array(
1550 'path' => $fileFoundPath,
1551 'name' => $attachmentFileNameTrunc.'.pdf',
1552 );
1553 break;
1554 }
1555 }
1556 }
1557 }
1558 }
1559
1560 if (isset($archiveFileList[$attachmentFileKey])) {
1561 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1562 }
1563 }
1564
1565 $tab[] = $attachmentFileName;
1566
1567 $output = implode($separator, $tab).$end_line;
1568
1569 if ($exportFile) {
1570 fwrite($exportFile, $output);
1571 } else {
1572 print $output;
1573 }
1574 }
1575 }
1576
1577 return $archiveFileList;
1578 }
1579
1592 public function exportFEC2($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
1593 {
1594 global $conf, $langs;
1595
1596 $separator = "\t";
1597 $end_line = "\r\n";
1598
1599 $tab = array();
1600 $tab[] = "JournalCode";
1601 $tab[] = "JournalLib";
1602 $tab[] = "EcritureNum";
1603 $tab[] = "EcritureDate";
1604 $tab[] = "CompteNum";
1605 $tab[] = "CompteLib";
1606 $tab[] = "CompAuxNum";
1607 $tab[] = "CompAuxLib";
1608 $tab[] = "PieceRef";
1609 $tab[] = "PieceDate";
1610 $tab[] = "EcritureLib";
1611 $tab[] = "Debit";
1612 $tab[] = "Credit";
1613 $tab[] = "EcritureLet";
1614 $tab[] = "DateLet";
1615 $tab[] = "ValidDate";
1616 $tab[] = "Montantdevise";
1617 $tab[] = "Idevise";
1618 $tab[] = "DateLimitReglmt";
1619 $tab[] = "NumFacture";
1620 $tab[] = "FichierFacture";
1621
1622 $output = implode($separator, $tab).$end_line;
1623 if ($exportFile) {
1624 fwrite($exportFile, $output);
1625 } else {
1626 print $output;
1627 }
1628
1629 foreach ($objectLines as $line) {
1630 if ($line->debit == 0 && $line->credit == 0) {
1631 //unset($array[$line]);
1632 } else {
1633 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1634 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1635 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1636 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1637 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1638
1639 $refInvoice = '';
1640 if ($line->doc_type == 'customer_invoice') {
1641 // Customer invoice
1642 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1643 $invoice = new Facture($this->db);
1644 $invoice->fetch($line->fk_doc);
1645
1646 $refInvoice = $invoice->ref;
1647 } elseif ($line->doc_type == 'supplier_invoice') {
1648 // Supplier invoice
1649 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1650 $invoice = new FactureFournisseur($this->db);
1651 $invoice->fetch($line->fk_doc);
1652
1653 $refInvoice = $invoice->ref_supplier;
1654 }
1655
1656 $tab = array();
1657
1658 // FEC:JournalCode
1659 $tab[] = $line->code_journal;
1660
1661 // FEC:JournalLib
1662 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1663 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1664 $tab[] = $labeljournal;
1665
1666 // FEC:EcritureNum
1667 $tab[] = $line->piece_num;
1668
1669 // FEC:EcritureDate
1670 $tab[] = $date_creation;
1671
1672 // FEC:CompteNum
1673 $tab[] = length_accountg($line->numero_compte);
1674
1675 // FEC:CompteLib
1676 $tab[] = dol_string_unaccent($line->label_compte);
1677
1678 // FEC:CompAuxNum
1679 $tab[] = length_accounta($line->subledger_account);
1680
1681 // FEC:CompAuxLib
1682 $tab[] = dol_string_unaccent($line->subledger_label);
1683
1684 // FEC:PieceRef
1685 $tab[] = $line->doc_ref;
1686
1687 // FEC:PieceDate
1688 $tab[] = $date_document;
1689
1690 // FEC:EcritureLib
1691 // Clean label operation to prevent problem on export with tab separator & other character
1692 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1693 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1694 $tab[] = dol_string_unaccent($line->label_operation);
1695
1696 // FEC:Debit
1697 $tab[] = price2fec($line->debit);
1698
1699 // FEC:Credit
1700 $tab[] = price2fec($line->credit);
1701
1702 // FEC:EcritureLet
1703 $tab[] = $line->lettering_code;
1704
1705 // FEC:DateLet
1706 $tab[] = $date_lettering;
1707
1708 // FEC:ValidDate
1709 $tab[] = $date_validation;
1710
1711 // FEC:Montantdevise
1712 $tab[] = $line->multicurrency_amount;
1713
1714 // FEC:Idevise
1715 $tab[] = $line->multicurrency_code;
1716
1717 // FEC_suppl:DateLimitReglmt
1718 $tab[] = $date_limit_payment;
1719
1720 // FEC_suppl:NumFacture
1721 // Clean ref invoice to prevent problem on export with tab separator & other character
1722 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1723 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1724
1725 // FEC_suppl:FichierFacture
1726 // get document file
1727 $attachmentFileName = '';
1728 if ($withAttachment == 1) {
1729 $attachmentFileKey = trim((string) $line->piece_num);
1730
1731 if (!isset($archiveFileList[$attachmentFileKey])) {
1732 $objectDirPath = '';
1733 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1734 if ($line->doc_type == 'customer_invoice') {
1735 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1736 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1737 }
1738 } elseif ($line->doc_type == 'expense_report') {
1739 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1740 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1741 }
1742 } elseif ($line->doc_type == 'supplier_invoice') {
1743 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1744 '@phan-var-force FactureFournisseur $invoice';
1746 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1747 $objectDirPath .= '/' . rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1748 }
1749 }
1750 $arrayofinclusion = array();
1751 // If it is a supplier invoice, we want to use last uploaded file
1752 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1753 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1754 if (!empty($fileFoundList)) {
1755 $attachmentFileNameTrunc = $line->doc_ref;
1756 foreach ($fileFoundList as $fileFound) {
1757 if (strstr($fileFound['name'], $objectFileName)) {
1758 // skip native invoice pdfs (canelle)
1759 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1760 if ($line->doc_type == 'supplier_invoice') {
1761 if ($fileFound['name'] === $objectFileName.'.pdf') {
1762 continue;
1763 }
1764 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1765 continue;
1766 }
1767 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1768 if (file_exists($fileFoundPath)) {
1769 $archiveFileList[$attachmentFileKey] = array(
1770 'path' => $fileFoundPath,
1771 'name' => $attachmentFileNameTrunc.'.pdf',
1772 );
1773 break;
1774 }
1775 }
1776 }
1777 }
1778 }
1779
1780 if (isset($archiveFileList[$attachmentFileKey])) {
1781 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1782 }
1783 }
1784
1785 $tab[] = $attachmentFileName;
1786
1787 $output = implode($separator, $tab).$end_line;
1788 if ($exportFile) {
1789 fwrite($exportFile, $output);
1790 } else {
1791 print $output;
1792 }
1793 }
1794 }
1795
1796 return $archiveFileList;
1797 }
1798
1809 public function exportSAGE50SWISS($objectLines, $exportFile = null)
1810 {
1811 // SAGE50SWISS
1812 $separator = ',';
1813 $end_line = "\r\n";
1814
1815 // Print header line
1816 $tab = array();
1817
1818 $tab[] = "Blg";
1819 $tab[] = "Datum";
1820 $tab[] = "Kto";
1821 $tab[] = "S/H";
1822 $tab[] = "Grp";
1823 $tab[] = "GKto";
1824 $tab[] = "SId";
1825 $tab[] = "SIdx";
1826 $tab[] = "KIdx";
1827 $tab[] = "BTyp";
1828 $tab[] = "MTyp";
1829 $tab[] = "Code";
1830 $tab[] = "Netto";
1831 $tab[] = "Steuer";
1832 $tab[] = "FW-Betrag";
1833 $tab[] = "Tx1";
1834 $tab[] = "Tx2";
1835 $tab[] = "PkKey";
1836 $tab[] = "OpId";
1837 $tab[] = "Flag";
1838
1839 $output = implode($separator, $tab).$end_line;
1840 if ($exportFile) {
1841 fwrite($exportFile, $output);
1842 } else {
1843 print $output;
1844 }
1845
1846 $thisPieceNum = "";
1847 $thisPieceAccountNr = "";
1848 $aSize = count($objectLines);
1849 foreach ($objectLines as $aIndex => $line) {
1850 $sammelBuchung = false;
1851 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1852 $sammelBuchung = true;
1853 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1854 $sammelBuchung = true;
1855 } elseif ($aIndex + 1 < $aSize
1856 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1857 && $aIndex - 1 < $aSize
1858 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1859 ) {
1860 $sammelBuchung = true;
1861 }
1862
1863 $tab = array();
1864
1865 //Blg
1866 $tab[] = $line->piece_num;
1867
1868 // Datum
1869 $date_document = dol_print_date($line->doc_date, '%d.%m.%Y');
1870 $tab[] = $date_document;
1871
1872 // Kto
1873 $tab[] = length_accountg($line->numero_compte);
1874 // S/H
1875 if ($line->sens == 'D') {
1876 $tab[] = 'S';
1877 } else {
1878 $tab[] = 'H';
1879 }
1880 // Grp
1881 $tab[] = self::trunc($line->code_journal, 1);
1882 // GKto
1883 if (empty($line->code_tiers)) {
1884 if ($line->piece_num == $thisPieceNum) {
1885 $tab[] = length_accounta($thisPieceAccountNr);
1886 } else {
1887 $tab[] = "div";
1888 }
1889 } else {
1890 $tab[] = length_accounta($line->code_tiers);
1891 }
1892 // SId
1893 $tab[] = $this->separator;
1894 // SIdx
1895 $tab[] = "0";
1896 // KIdx
1897 $tab[] = "0";
1898 // BTyp
1899 $tab[] = "0";
1900
1901 // MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
1902 if ($sammelBuchung) {
1903 $tab[] = "2";
1904 } else {
1905 $tab[] = "1";
1906 }
1907 // Code
1908 $tab[] = '""';
1909 // Netto
1910 $tab[] = abs($line->debit - $line->credit);
1911 // Steuer
1912 $tab[] = "0.00";
1913 // FW-Betrag
1914 $tab[] = "0.00";
1915 // Tx1
1916 $line1 = self::toAnsi($line->label_compte, 29);
1917 if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
1918 $line1 = "";
1919 }
1920 $line2 = self::toAnsi($line->doc_ref, 29);
1921 if (strlen($line1) == 0) {
1922 $line1 = $line2;
1923 $line2 = "";
1924 }
1925 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1926 $line1 = $line1.' / '.$line2;
1927 $line2 = "";
1928 }
1929
1930 $tab[] = '"'.self::toAnsi($line1).'"';
1931 // Tx2
1932 $tab[] = '"'.self::toAnsi($line2).'"';
1933 //PkKey
1934 $tab[] = "0";
1935 //OpId
1936 $tab[] = $this->separator;
1937
1938 // Flag
1939 $tab[] = "0";
1940
1941 $output = implode($separator, $tab).$end_line;
1942 if ($exportFile) {
1943 fwrite($exportFile, $output);
1944 } else {
1945 print $output;
1946 }
1947
1948 if ($line->piece_num !== $thisPieceNum) {
1949 $thisPieceNum = $line->piece_num;
1950 $thisPieceAccountNr = $line->numero_compte;
1951 }
1952 }
1953 }
1954
1963 public function exportLDCompta($objectLines, $exportFile = null)
1964 {
1965 $separator = ';';
1966 $end_line = "\r\n";
1967
1968 foreach ($objectLines as $line) {
1969 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1970 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1971 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1972
1973 $tab = array();
1974
1975 // TYPE
1976 $type_enregistrement = 'E'; // For write movement
1977 $tab[] = $type_enregistrement;
1978 // JNAL
1979 $tab[] = substr($line->code_journal, 0, 2);
1980 // NECR
1981 $tab[] = $line->id;
1982 // NPIE
1983 $tab[] = $line->piece_num;
1984 // DATP
1985 $tab[] = $date_document;
1986 // LIBE
1987 $tab[] = $line->label_operation;
1988 // DATH
1989 $tab[] = $date_lim_reglement;
1990 // CNPI
1991 if ($line->doc_type == 'supplier_invoice') {
1992 if (($line->debit - $line->credit) > 0) {
1993 $nature_piece = 'AF';
1994 } else {
1995 $nature_piece = 'FF';
1996 }
1997 } elseif ($line->doc_type == 'customer_invoice') {
1998 if (($line->debit - $line->credit) < 0) {
1999 $nature_piece = 'AC';
2000 } else {
2001 $nature_piece = 'FC';
2002 }
2003 } else {
2004 $nature_piece = '';
2005 }
2006 $tab[] = $nature_piece;
2007 // RACI
2008 // if (!empty($line->subledger_account)) {
2009 // if ($line->doc_type == 'supplier_invoice') {
2010 // $racine_subledger_account = '40';
2011 // } elseif ($line->doc_type == 'customer_invoice') {
2012 // $racine_subledger_account = '41';
2013 // } else {
2014 // $racine_subledger_account = '';
2015 // }
2016 // } else {
2017 $racine_subledger_account = ''; // for records of type E leave this field blank
2018 // }
2019
2020 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2021 // MONT
2022 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2, 2);
2023 // CODC
2024 $tab[] = $line->sens;
2025 // CPTG
2026 $tab[] = length_accountg($line->numero_compte);
2027 // DATE
2028 $tab[] = $date_creation;
2029 // CLET
2030 $tab[] = $line->lettering_code;
2031 // DATL
2032 $tab[] = $line->date_lettering;
2033 // CPTA
2034 if (!empty($line->subledger_account)) {
2035 $tab[] = length_accounta($line->subledger_account);
2036 } else {
2037 $tab[] = "";
2038 }
2039 // C.N.A.T
2040 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2041 $tab[] = 'F';
2042 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2043 $tab[] = 'C';
2044 } else {
2045 $tab[] = "";
2046 }
2047 // SECT
2048 $tab[] = "";
2049 // CTRE
2050 $tab[] = "";
2051 // NORL
2052 $tab[] = "";
2053 // DATV
2054 $tab[] = "";
2055 // REFD
2056 $tab[] = $line->doc_ref;
2057 // CODH
2058 $tab[] = "";
2059 // NSEQ
2060 $tab[] = "";
2061 // MTDV
2062 $tab[] = '0';
2063 // CODV
2064 $tab[] = "";
2065 // TXDV
2066 $tab[] = '0';
2067 // MOPM
2068 $tab[] = "";
2069 // BONP
2070 $tab[] = "";
2071 // BQAF
2072 $tab[] = "";
2073 // ECES
2074 $tab[] = "";
2075 // TXTL
2076 $tab[] = "";
2077 // ECRM
2078 $tab[] = "";
2079 // DATK
2080 $tab[] = "";
2081 // HEUK
2082 $tab[] = "";
2083
2084 $output = implode($separator, $tab).$end_line;
2085 if ($exportFile) {
2086 fwrite($exportFile, $output);
2087 } else {
2088 print $output;
2089 }
2090 }
2091 }
2092
2103 public function exportLDCompta10($objectLines, $exportFile = null)
2104 {
2105 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
2106
2107 $separator = ';';
2108 $end_line = "\r\n";
2109 $last_codeinvoice = '';
2110
2111 foreach ($objectLines as $line) {
2112 // TYPE C
2113 if ($last_codeinvoice != $line->doc_ref) {
2114 //recherche societe en fonction de son code client
2115 $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
2116 $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
2117 $resql = $this->db->query($sql);
2118
2119 if ($resql && $this->db->num_rows($resql) > 0) {
2120 $soc = $this->db->fetch_object($resql);
2121
2122 $address = array('', '', '');
2123 if (strpos($soc->address, "\n") !== false) {
2124 $address = explode("\n", $soc->address);
2125 if (is_array($address) && count($address) > 0) {
2126 foreach ($address as $key => $data) {
2127 $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
2128 $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
2129 }
2130 }
2131 } else {
2132 $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
2133 $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
2134 $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
2135 }
2136
2137 $tab = array();
2138
2139 $type_enregistrement = 'C';
2140 //TYPE
2141 $tab[] = $type_enregistrement;
2142 //NOCL
2143 $tab[] = $soc->code_client;
2144 //NMCM
2145 $tab[] = "";
2146 //LIBI
2147 $tab[] = "";
2148 //TITR
2149 $tab[] = "";
2150 //RSSO
2151 $tab[] = $soc->nom;
2152 //CAD1
2153 $tab[] = $address[0];
2154 //CAD2
2155 $tab[] = $address[1];
2156 //CAD3
2157 $tab[] = $address[2];
2158 //COPO
2159 $tab[] = $soc->zip;
2160 //BUDI
2161 $tab[] = substr($soc->town, 0, 40);
2162 //CPAY
2163 $tab[] = "";
2164 //PAYS
2165 $tab[] = substr(getCountry($soc->fk_pays), 0, 40);
2166 //NTEL
2167 $tab[] = $soc->phone;
2168 //TLEX
2169 $tab[] = "";
2170 //TLPO
2171 $tab[] = "";
2172 //TLCY
2173 $tab[] = "";
2174 //NINT
2175 $tab[] = "";
2176 //COMM
2177 $tab[] = "";
2178 //SIRE
2179 $tab[] = str_replace(" ", "", $soc->siret);
2180 //RIBP
2181 $tab[] = "";
2182 //DOBQ
2183 $tab[] = "";
2184 //IBBQ
2185 $tab[] = "";
2186 //COBQ
2187 $tab[] = "";
2188 //GUBQ
2189 $tab[] = "";
2190 //CPBQ
2191 $tab[] = "";
2192 //CLBQ
2193 $tab[] = "";
2194 //BIBQ
2195 $tab[] = "";
2196 //MOPM
2197 $tab[] = "";
2198 //DJPM
2199 $tab[] = "";
2200 //DMPM
2201 $tab[] = "";
2202 //REFM
2203 $tab[] = "";
2204 //SLVA
2205 $tab[] = "";
2206 //PLCR
2207 $tab[] = "";
2208 //ECFI
2209 $tab[] = "";
2210 //CREP
2211 $tab[] = "";
2212 //NREP
2213 $tab[] = "";
2214 //TREP
2215 $tab[] = "";
2216 //MREP
2217 $tab[] = "";
2218 //GRRE
2219 $tab[] = "";
2220 //LTTA
2221 $tab[] = "";
2222 //CACT
2223 $tab[] = "";
2224 //CODV
2225 $tab[] = "";
2226 //GRTR
2227 $tab[] = "";
2228 //NOFP
2229 $tab[] = "";
2230 //BQAF
2231 $tab[] = "";
2232 //BONP
2233 $tab[] = "";
2234 //CESC
2235 $tab[] = "";
2236
2237 $output = implode($separator, $tab).$end_line;
2238 if ($exportFile) {
2239 fwrite($exportFile, $output);
2240 } else {
2241 print $output;
2242 }
2243 }
2244 }
2245
2246 $tab = array();
2247
2248 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2249 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
2250 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2251
2252 // TYPE E
2253 $type_enregistrement = 'E'; // For write movement
2254 $tab[] = $type_enregistrement;
2255 // JNAL
2256 $tab[] = substr($line->code_journal, 0, 2);
2257 // NECR
2258 $tab[] = $line->id;
2259 // NPIE
2260 $tab[] = $line->piece_num;
2261 // DATP
2262 $tab[] = $date_document;
2263 // LIBE
2264 $tab[] = dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1);
2265 // DATH
2266 $tab[] = $date_lim_reglement;
2267 // CNPI
2268 if ($line->doc_type == 'supplier_invoice') {
2269 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.
2270 $nature_piece = 'AF';
2271 } else {
2272 $nature_piece = 'FF';
2273 }
2274 } elseif ($line->doc_type == 'customer_invoice') {
2275 if (($line->amount) < 0) {
2276 $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.
2277 } else {
2278 $nature_piece = 'FC';
2279 }
2280 } else {
2281 $nature_piece = '';
2282 }
2283 $tab[] = $nature_piece;
2284 // RACI
2285 // if (!empty($line->subledger_account)) {
2286 // if ($line->doc_type == 'supplier_invoice') {
2287 // $racine_subledger_account = '40';
2288 // } elseif ($line->doc_type == 'customer_invoice') {
2289 // $racine_subledger_account = '41';
2290 // } else {
2291 // $racine_subledger_account = '';
2292 // }
2293 // } else {
2294 $racine_subledger_account = ''; // for records of type E leave this field blank
2295 // }
2296
2297 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2298 // MONT
2299 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2);
2300 // CODC
2301 $tab[] = $line->sens;
2302 // CPTG
2303 $tab[] = length_accountg($line->numero_compte);
2304 // DATE
2305 $tab[] = $date_document;
2306 // CLET
2307 $tab[] = $line->lettering_code;
2308 // DATL
2309 $tab[] = $line->date_lettering;
2310 // CPTA
2311 if (!empty($line->subledger_account)) {
2312 $tab[] = length_accounta($line->subledger_account);
2313 } else {
2314 $tab[] = "";
2315 }
2316 // C.N.A.T
2317 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2318 $tab[] = 'F';
2319 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2320 $tab[] = 'C';
2321 } else {
2322 $tab[] = "";
2323 }
2324 // CTRE
2325 $tab[] = "";
2326 // NORL
2327 $tab[] = "";
2328 // DATV
2329 $tab[] = "";
2330 // REFD
2331 $tab[] = $line->doc_ref;
2332 // NECA
2333 $tab[] = '0';
2334 // CSEC
2335 $tab[] = "";
2336 // CAFF
2337 $tab[] = "";
2338 // CDES
2339 $tab[] = "";
2340 // QTUE
2341 $tab[] = "";
2342 // MTDV
2343 $tab[] = '0';
2344 // CODV
2345 $tab[] = "";
2346 // TXDV
2347 $tab[] = '0';
2348 // MOPM
2349 $tab[] = "";
2350 // BONP
2351 $tab[] = "";
2352 // BQAF
2353 $tab[] = "";
2354 // ECES
2355 $tab[] = "";
2356 // TXTL
2357 $tab[] = "";
2358 // ECRM
2359 $tab[] = "";
2360 // DATK
2361 $tab[] = "";
2362 // HEUK
2363 $tab[] = "";
2364
2365 $output = implode($separator, $tab).$end_line;
2366 if ($exportFile) {
2367 fwrite($exportFile, $output);
2368 } else {
2369 print $output;
2370 }
2371
2372 $last_codeinvoice = $line->doc_ref;
2373 }
2374 }
2375
2383 public function exportCharlemagne($objectLines, $exportFile = null)
2384 {
2385 global $langs;
2386 $langs->load('compta');
2387
2388 $separator = "\t";
2389 $end_line = "\n";
2390
2391 $tab = array();
2392
2393 $tab[] = $langs->transnoentitiesnoconv('Date');
2394 $tab[] = self::trunc($langs->transnoentitiesnoconv('Journal'), 6);
2395 $tab[] = self::trunc($langs->transnoentitiesnoconv('Account'), 15);
2396 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60);
2397 $tab[] = self::trunc($langs->transnoentitiesnoconv('Piece'), 20);
2398 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60);
2399 $tab[] = $langs->transnoentitiesnoconv('Amount');
2400 $tab[] = 'S';
2401 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15);
2402 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60);
2403 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15);
2404 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60);
2405 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15);
2406 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60);
2407
2408 $output = implode($separator, $tab).$end_line;
2409 if ($exportFile) {
2410 fwrite($exportFile, $output);
2411 } else {
2412 print $output;
2413 }
2414
2415 foreach ($objectLines as $line) {
2416 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2417
2418 $tab = array();
2419
2420 $tab[] = $date_document; //Date
2421
2422 $tab[] = self::trunc($line->code_journal, 6); //Journal code
2423
2424 if (!empty($line->subledger_account)) {
2425 $account = $line->subledger_account;
2426 } else {
2427 $account = $line->numero_compte;
2428 }
2429 $tab[] = self::trunc($account, 15); //Account number
2430
2431 $tab[] = self::trunc($line->label_compte, 60); //Account label
2432 $tab[] = self::trunc($line->doc_ref, 20); //Piece
2433 // Clean label operation to prevent problem on export with tab separator & other character
2434 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
2435 $tab[] = self::trunc($line->label_operation, 60); //Operation label
2436 $tab[] = price(abs($line->debit - $line->credit)); //Amount
2437 $tab[] = $line->sens; //Direction
2438 $tab[] = ""; //Analytic
2439 $tab[] = ""; //Analytic
2440 $tab[] = ""; //Analytic
2441 $tab[] = ""; //Analytic
2442 $tab[] = ""; //Analytic
2443 $tab[] = ""; //Analytic
2444
2445 $output = implode($separator, $tab).$end_line;
2446 if ($exportFile) {
2447 fwrite($exportFile, $output);
2448 } else {
2449 print $output;
2450 }
2451 }
2452 }
2453
2461 public function exportGestimumV3($objectLines, $exportFile = null)
2462 {
2463 global $langs;
2464
2465 $separator = ',';
2466 $end_line = "\r\n";
2467
2468 $invoices_infos = array();
2469 $supplier_invoices_infos = array();
2470 foreach ($objectLines as $line) {
2471 if ($line->debit == 0 && $line->credit == 0) {
2472 //unset($array[$line]);
2473 } else {
2474 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
2475 $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2476
2477 $invoice_ref = $line->doc_ref;
2478 $company_name = "";
2479
2480 if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
2481 if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2482 ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2483 if ($line->doc_type == 'customer_invoice') {
2484 // Get new customer invoice ref and company name
2485 $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
2486 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
2487 $sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
2488 $resql = $this->db->query($sql);
2489 if ($resql) {
2490 if ($obj = $this->db->fetch_object($resql)) {
2491 // Save invoice infos
2492 $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2493 $invoice_ref = $obj->ref;
2494 $company_name = $obj->nom;
2495 }
2496 }
2497 } else {
2498 // Get new supplier invoice ref and company name
2499 $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
2500 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
2501 $sql .= ' WHERE ff.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 $supplier_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 }
2512 } elseif ($line->doc_type == 'customer_invoice') {
2513 // Retrieve invoice infos
2514 $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
2515 $company_name = $invoices_infos[$line->fk_doc]['company_name'];
2516 } else {
2517 // Retrieve invoice infos
2518 $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
2519 $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
2520 }
2521 }
2522
2523 $tab = array();
2524
2525 $tab[] = $line->id;
2526 $tab[] = $date_document;
2527 $tab[] = substr($line->code_journal, 0, 4);
2528
2529 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
2530 $tab[] = length_accountg($line->subledger_account);
2531 } else {
2532 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2533 }
2534 //Libellé Auto
2535 $tab[] = "";
2536 //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"';
2537 //Libellé manual
2538 $tab[] = dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1);
2539 //Numéro de pièce
2540 $tab[] = dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1);
2541 //Devise
2542 $tab[] = 'EUR';
2543 //Amount
2544 $tab[] = price2num(abs($line->debit - $line->credit));
2545 //Sens
2546 $tab[] = $line->sens;
2547 //Code lettrage
2548 $tab[] = "";
2549 //Date Echéance
2550 $tab[] = $date_echeance;
2551
2552 $output = implode($separator, $tab).$end_line;
2553 if ($exportFile) {
2554 fwrite($exportFile, $output);
2555 } else {
2556 print $output;
2557 }
2558 }
2559 }
2560 }
2561
2569 public function exportGestimumV5($objectLines, $exportFile = null)
2570 {
2571 $separator = ',';
2572 $end_line = "\r\n";
2573
2574 foreach ($objectLines as $line) {
2575 if ($line->debit == 0 && $line->credit == 0) {
2576 //unset($array[$line]);
2577 } else {
2578 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
2579
2580 $tab = array();
2581
2582 $tab[] = $line->id;
2583 $tab[] = $date_document;
2584 $tab[] = substr($line->code_journal, 0, 4);
2585 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
2586 $tab[] = length_accountg($line->subledger_account);
2587 } else {
2588 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2589 }
2590 $tab[] = "";
2591 $tab[] = '"'.dol_trunc(str_replace('"', '', $line->label_operation), 40, 'right', 'UTF-8', 1).'"';
2592 $tab[] = '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"';
2593 $tab[] = '"' . dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1) . '"';
2594 $tab[] = price2num(abs($line->debit - $line->credit));
2595 $tab[] = $line->sens;
2596 $tab[] = $date_document;
2597 $tab[] = "";
2598 $tab[] = "";
2599 $tab[] = 'EUR';
2600
2601 $output = implode($separator, $tab).$end_line;
2602 if ($exportFile) {
2603 fwrite($exportFile, $output);
2604 } else {
2605 print $output;
2606 }
2607 }
2608 }
2609 }
2610
2620 public function exportiSuiteExpert($objectLines, $exportFile = null)
2621 {
2622 $separator = ';';
2623 $end_line = "\r\n";
2624
2625
2626 foreach ($objectLines as $line) {
2627 $tab = array();
2628
2629 $date = dol_print_date($line->doc_date, '%d/%m/%Y');
2630
2631 $tab[] = $line->piece_num;
2632 $tab[] = $date;
2633 $tab[] = substr($date, 6, 4);
2634 $tab[] = substr($date, 3, 2);
2635 $tab[] = substr($date, 0, 2);
2636 $tab[] = $line->doc_ref;
2637 //Conversion de chaine UTF8 en Latin9
2638 $tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
2639
2640 //Calcul de la longueur des numéros de comptes
2641 $taille_numero = strlen(length_accountg($line->numero_compte));
2642
2643 //Création du numéro de client et fournisseur générique
2644 $numero_cpt_client = '411';
2645 $numero_cpt_fourn = '401';
2646 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2647 $numero_cpt_client .= '0';
2648 $numero_cpt_fourn .= '0';
2649 }
2650
2651 //Création des comptes auxiliaire des clients et fournisseur
2652 if (length_accountg($line->numero_compte) == $numero_cpt_client || length_accountg($line->numero_compte) == $numero_cpt_fourn) {
2653 $tab[] = rtrim(length_accounta($line->subledger_account), "0");
2654 } else {
2655 $tab[] = length_accountg($line->numero_compte);
2656 }
2657 $nom_client = explode(" - ", $line->label_operation);
2658 $tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
2659 $tab[] = price($line->debit);
2660 $tab[] = price($line->credit);
2661 $tab[] = price($line->montant);
2662 $tab[] = $line->code_journal;
2663
2664 $output = implode($separator, $tab).$end_line;
2665 if ($exportFile) {
2666 fwrite($exportFile, $output);
2667 } else {
2668 print $output;
2669 }
2670 }
2671 }
2672
2680 public static function trunc($str, $size)
2681 {
2682 return dol_trunc($str, $size, 'right', 'UTF-8', 1);
2683 }
2684
2692 public static function toAnsi($str, $size = -1)
2693 {
2694 $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
2695 if ($retVal >= 0 && $size >= 0) {
2696 $retVal = dol_substr($retVal, 0, $size, 'Windows-1251');
2697 }
2698 return $retVal;
2699 }
2700}
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