dolibarr 18.0.6
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-2024 Alexandre Spangaro <aspangaro@open-dsi.fr>
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-2019 Frédéric France <frederic.france@netlogic.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 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <https://www.gnu.org/licenses/>.
30 */
31
38require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
44
49{
50 // Type of export. Used into $conf->global->ACCOUNTING_EXPORT_MODELCSV
51 public static $EXPORT_TYPE_CONFIGURABLE = 1; // CSV
52 public static $EXPORT_TYPE_AGIRIS = 10;
53 public static $EXPORT_TYPE_EBP = 15;
54 public static $EXPORT_TYPE_CEGID = 20;
55 public static $EXPORT_TYPE_COGILOG = 25;
56 public static $EXPORT_TYPE_COALA = 30;
57 public static $EXPORT_TYPE_BOB50 = 35;
58 public static $EXPORT_TYPE_CIEL = 40;
59 public static $EXPORT_TYPE_SAGE50_SWISS = 45;
60 public static $EXPORT_TYPE_CHARLEMAGNE = 50;
61 public static $EXPORT_TYPE_QUADRATUS = 60;
62 public static $EXPORT_TYPE_WINFIC = 70;
63 public static $EXPORT_TYPE_OPENCONCERTO = 100;
64 public static $EXPORT_TYPE_LDCOMPTA = 110;
65 public static $EXPORT_TYPE_LDCOMPTA10 = 120;
66 public static $EXPORT_TYPE_GESTIMUMV3 = 130;
67 public static $EXPORT_TYPE_GESTIMUMV5 = 135;
68 public static $EXPORT_TYPE_ISUITEEXPERT = 200;
69 // Generic FEC after that
70 public static $EXPORT_TYPE_FEC = 1000;
71 public static $EXPORT_TYPE_FEC2 = 1010;
72
76 public $db;
77
81 public $errors = array();
82
87 public $separator = '';
88
93 public $end_line = '';
94
100 public function __construct(DoliDB $db)
101 {
102 global $conf, $hookmanager;
103
104 $this->db = $db;
105 $this->separator = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
106 $this->end_line = empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? "\n" : ($conf->global->ACCOUNTING_EXPORT_ENDLINE == 1 ? "\n" : "\r\n");
107
108 $hookmanager->initHooks(array('accountancyexport'));
109 }
110
116 public function getType()
117 {
118 global $langs, $hookmanager;
119
120 $listofexporttypes = array(
121 self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans('Modelcsv_configurable'),
122 self::$EXPORT_TYPE_CEGID => $langs->trans('Modelcsv_CEGID'),
123 self::$EXPORT_TYPE_COALA => $langs->trans('Modelcsv_COALA'),
124 self::$EXPORT_TYPE_BOB50 => $langs->trans('Modelcsv_bob50'),
125 self::$EXPORT_TYPE_CIEL => $langs->trans('Modelcsv_ciel'),
126 self::$EXPORT_TYPE_QUADRATUS => $langs->trans('Modelcsv_quadratus'),
127 self::$EXPORT_TYPE_WINFIC => $langs->trans('Modelcsv_winfic'),
128 self::$EXPORT_TYPE_EBP => $langs->trans('Modelcsv_ebp'),
129 self::$EXPORT_TYPE_COGILOG => $langs->trans('Modelcsv_cogilog'),
130 self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'),
131 self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans('Modelcsv_openconcerto'),
132 self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans('Modelcsv_Sage50_Swiss'),
133 self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans('Modelcsv_charlemagne'),
134 self::$EXPORT_TYPE_LDCOMPTA => $langs->trans('Modelcsv_LDCompta'),
135 self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans('Modelcsv_LDCompta10'),
136 self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans('Modelcsv_Gestinumv3'),
137 self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans('Modelcsv_Gestinumv5'),
138 self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'),
139 self::$EXPORT_TYPE_FEC2 => $langs->trans('Modelcsv_FEC2'),
140 self::$EXPORT_TYPE_ISUITEEXPERT => 'Export iSuite Expert',
141 );
142
143 // allow modules to define export formats
144 $parameters = array();
145 $reshook = $hookmanager->executeHooks('getType', $parameters, $listofexporttypes);
146
147 ksort($listofexporttypes, SORT_NUMERIC);
148
149 return $listofexporttypes;
150 }
151
158 public static function getFormatCode($type)
159 {
160 $formatcode = array(
161 self::$EXPORT_TYPE_CONFIGURABLE => 'csv',
162 self::$EXPORT_TYPE_CEGID => 'cegid',
163 self::$EXPORT_TYPE_COALA => 'coala',
164 self::$EXPORT_TYPE_BOB50 => 'bob50',
165 self::$EXPORT_TYPE_CIEL => 'ciel',
166 self::$EXPORT_TYPE_QUADRATUS => 'quadratus',
167 self::$EXPORT_TYPE_WINFIC => 'winfic',
168 self::$EXPORT_TYPE_EBP => 'ebp',
169 self::$EXPORT_TYPE_COGILOG => 'cogilog',
170 self::$EXPORT_TYPE_AGIRIS => 'agiris',
171 self::$EXPORT_TYPE_OPENCONCERTO => 'openconcerto',
172 self::$EXPORT_TYPE_SAGE50_SWISS => 'sage50ch',
173 self::$EXPORT_TYPE_CHARLEMAGNE => 'charlemagne',
174 self::$EXPORT_TYPE_LDCOMPTA => 'ldcompta',
175 self::$EXPORT_TYPE_LDCOMPTA10 => 'ldcompta10',
176 self::$EXPORT_TYPE_GESTIMUMV3 => 'gestimumv3',
177 self::$EXPORT_TYPE_GESTIMUMV5 => 'gestimumv5',
178 self::$EXPORT_TYPE_FEC => 'fec',
179 self::$EXPORT_TYPE_FEC2 => 'fec2',
180 self::$EXPORT_TYPE_ISUITEEXPERT => 'isuiteexpert',
181 );
182
183 global $hookmanager;
184 $code = $formatcode[$type];
185 $parameters = array('type' => $type);
186 $reshook = $hookmanager->executeHooks('getFormatCode', $parameters, $code);
187
188 return $code;
189 }
190
196 public function getTypeConfig()
197 {
198 global $conf, $langs;
199
200 $exporttypes = array(
201 'param' => array(
202 self::$EXPORT_TYPE_CONFIGURABLE => array(
203 'label' => $langs->trans('Modelcsv_configurable'),
204 'ACCOUNTING_EXPORT_FORMAT' => empty($conf->global->ACCOUNTING_EXPORT_FORMAT) ? 'txt' : $conf->global->ACCOUNTING_EXPORT_FORMAT,
205 'ACCOUNTING_EXPORT_SEPARATORCSV' => empty($conf->global->ACCOUNTING_EXPORT_SEPARATORCSV) ? ',' : $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV,
206 'ACCOUNTING_EXPORT_ENDLINE' => empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? 1 : $conf->global->ACCOUNTING_EXPORT_ENDLINE,
207 'ACCOUNTING_EXPORT_DATE' => getDolGlobalString('ACCOUNTING_EXPORT_DATE', '%Y-%m-%d'),
208 ),
209 self::$EXPORT_TYPE_CEGID => array(
210 'label' => $langs->trans('Modelcsv_CEGID'),
211 ),
212 self::$EXPORT_TYPE_COALA => array(
213 'label' => $langs->trans('Modelcsv_COALA'),
214 ),
215 self::$EXPORT_TYPE_BOB50 => array(
216 'label' => $langs->trans('Modelcsv_bob50'),
217 ),
218 self::$EXPORT_TYPE_CIEL => array(
219 'label' => $langs->trans('Modelcsv_ciel'),
220 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
221 ),
222 self::$EXPORT_TYPE_QUADRATUS => array(
223 'label' => $langs->trans('Modelcsv_quadratus'),
224 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
225 ),
226 self::$EXPORT_TYPE_WINFIC => array(
227 'label' => $langs->trans('Modelcsv_winfic'),
228 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
229 ),
230 self::$EXPORT_TYPE_EBP => array(
231 'label' => $langs->trans('Modelcsv_ebp'),
232 ),
233 self::$EXPORT_TYPE_COGILOG => array(
234 'label' => $langs->trans('Modelcsv_cogilog'),
235 ),
236 self::$EXPORT_TYPE_AGIRIS => array(
237 'label' => $langs->trans('Modelcsv_agiris'),
238 ),
239 self::$EXPORT_TYPE_OPENCONCERTO => array(
240 'label' => $langs->trans('Modelcsv_openconcerto'),
241 ),
242 self::$EXPORT_TYPE_SAGE50_SWISS => array(
243 'label' => $langs->trans('Modelcsv_Sage50_Swiss'),
244 ),
245 self::$EXPORT_TYPE_CHARLEMAGNE => array(
246 'label' => $langs->trans('Modelcsv_charlemagne'),
247 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
248 ),
249 self::$EXPORT_TYPE_LDCOMPTA => array(
250 'label' => $langs->trans('Modelcsv_LDCompta'),
251 ),
252 self::$EXPORT_TYPE_LDCOMPTA10 => array(
253 'label' => $langs->trans('Modelcsv_LDCompta10'),
254 ),
255 self::$EXPORT_TYPE_GESTIMUMV3 => array(
256 'label' => $langs->trans('Modelcsv_Gestinumv3'),
257 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
258 ),
259 self::$EXPORT_TYPE_GESTIMUMV5 => array(
260 'label' => $langs->trans('Modelcsv_Gestinumv5'),
261 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
262 ),
263 self::$EXPORT_TYPE_FEC => array(
264 'label' => $langs->trans('Modelcsv_FEC'),
265 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
266 ),
267 self::$EXPORT_TYPE_FEC2 => array(
268 'label' => $langs->trans('Modelcsv_FEC2'),
269 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
270 ),
271 self::$EXPORT_TYPE_ISUITEEXPERT => array(
272 'label' => 'iSuite Expert',
273 'ACCOUNTING_EXPORT_FORMAT' => 'csv',
274 ),
275 ),
276 'cr'=> array(
277 '1' => $langs->trans("Unix"),
278 '2' => $langs->trans("Windows")
279 ),
280 'format' => array(
281 'csv' => $langs->trans("csv"),
282 'txt' => $langs->trans("txt")
283 ),
284 );
285
286 global $hookmanager;
287 $parameters = array();
288 $reshook = $hookmanager->executeHooks('getTypeConfig', $parameters, $exporttypes);
289 return $exporttypes;
290 }
291
292
299 public function getMimeType($formatexportset)
300 {
301 $mime = 'text/csv';
302
303 switch ($formatexportset) {
304 case self::$EXPORT_TYPE_FEC:
305 $mime = 'text/tab-separated-values';
306 break;
307 default:
308 $mime = 'text/csv';
309 break;
310 }
311
312 return $mime;
313 }
314
330 public function export(&$TData, $formatexportset, $withAttachment = 0, $downloadMode = 0, $outputMode = 0)
331 {
332 global $conf, $langs;
333 global $search_date_end; // Used into /accountancy/tpl/export_journal.tpl.php
334
335 // Define name of file to save
336 $filename = 'general_ledger-'.$this->getFormatCode($formatexportset);
337 $type_export = 'general_ledger';
338
339 global $db; // The tpl file use $db
340 $completefilename = '';
341 $exportFile = null;
342 $exportFileName = '';
343 $exportFilePath = '';
344 $archiveFullName = '';
345 $archivePath = '';
346 $archiveFileList = array();
347 if ($withAttachment == 1) {
348 if ($downloadMode == 0) {
349 $downloadMode = 1; // force to download after writing all files (can't use direct download)
350 }
351 if ($outputMode == 0) {
352 $outputMode = 1; // force to put files in a temp directory (can't use print on screen)
353 }
354
355 // PHP ZIP extension must be enabled
356 if (!extension_loaded('zip')) {
357 $langs->load('install');
358 $this->errors[] = $langs->trans('ErrorPHPDoesNotSupport', 'ZIP');
359 return -1;
360 }
361 }
362
363 $mimetype = $this->getMimeType($formatexportset);
364 if ($downloadMode == 0) {
365 // begin to print header for direct download
366 top_httphead($mimetype, 1);
367 }
368 include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
369 if ($outputMode == 1 || $outputMode == 2) {
370 if ($outputMode == 1) {
371 // uses temp directory by default to write files
372 if (!empty($conf->accounting->multidir_temp[$conf->entity])) {
373 $outputDir = $conf->accounting->multidir_temp[$conf->entity];
374 } else {
375 $outputDir = $conf->accounting->dir_temp;
376 }
377 } else {
378 // uses default export directory "accounting/export"
379 if (!empty($conf->accounting->multidir_output[$conf->entity])) {
380 $outputDir = $conf->accounting->multidir_output[$conf->entity];
381 } else {
382 $outputDir = $conf->accounting->dir_output;
383 }
384
385 // directory already created when module is enabled
386 $outputDir .= '/export';
387 $outputDir .= '/'.dol_sanitizePathName($formatexportset);
388 }
389
390 if (!dol_is_dir($outputDir)) {
391 if (dol_mkdir($outputDir) < 0) {
392 $this->errors[] = $langs->trans('ErrorCanNotCreateDir', $outputDir);
393 return -1;
394 }
395 }
396
397 if ($outputDir != '') {
398 if (!dol_is_dir($outputDir)) {
399 $langs->load('errors');
400 $this->errors[] = $langs->trans('ErrorDirNotFound', $outputDir);
401 return -1;
402 }
403
404 if (!empty($completefilename)) {
405 // create export file
406 $exportFileFullName = $completefilename;
407 $exportFileBaseName = basename($exportFileFullName);
408 $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME);
409 $exportFilePath = $outputDir . '/' . $exportFileFullName;
410 $exportFile = fopen($exportFilePath, 'w');
411 if (!$exportFile) {
412 $this->errors[] = $langs->trans('ErrorFileNotFound', $exportFilePath);
413 return -1;
414 }
415
416 if ($withAttachment == 1) {
417 $archiveFileList[0] = array(
418 'path' => $exportFilePath,
419 'name' => $exportFileFullName,
420 );
421
422 // archive name and path
423 $archiveFullName = $exportFileName . '.zip';
424 $archivePath = $outputDir . '/' . $archiveFullName;
425 }
426 }
427 }
428 }
429
430 // export file (print on screen or write in a file) and prepare archive list if with attachment is set to 1
431 switch ($formatexportset) {
432 case self::$EXPORT_TYPE_CONFIGURABLE:
433 $this->exportConfigurable($TData, $exportFile);
434 break;
435 case self::$EXPORT_TYPE_CEGID:
436 $this->exportCegid($TData, $exportFile);
437 break;
438 case self::$EXPORT_TYPE_COALA:
439 $this->exportCoala($TData, $exportFile);
440 break;
441 case self::$EXPORT_TYPE_BOB50:
442 $this->exportBob50($TData, $exportFile);
443 break;
444 case self::$EXPORT_TYPE_CIEL:
445 $this->exportCiel($TData, $exportFile);
446 break;
447 case self::$EXPORT_TYPE_QUADRATUS:
448 $archiveFileList = $this->exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment);
449 break;
450 case self::$EXPORT_TYPE_WINFIC:
451 $this->exportWinfic($TData, $exportFile);
452 break;
453 case self::$EXPORT_TYPE_EBP:
454 $this->exportEbp($TData, $exportFile);
455 break;
456 case self::$EXPORT_TYPE_COGILOG:
457 $this->exportCogilog($TData, $exportFile);
458 break;
459 case self::$EXPORT_TYPE_AGIRIS:
460 $this->exportAgiris($TData, $exportFile);
461 break;
462 case self::$EXPORT_TYPE_OPENCONCERTO:
463 $this->exportOpenConcerto($TData, $exportFile);
464 break;
465 case self::$EXPORT_TYPE_SAGE50_SWISS:
466 $this->exportSAGE50SWISS($TData, $exportFile);
467 break;
468 case self::$EXPORT_TYPE_CHARLEMAGNE:
469 $this->exportCharlemagne($TData, $exportFile);
470 break;
471 case self::$EXPORT_TYPE_LDCOMPTA:
472 $this->exportLDCompta($TData, $exportFile);
473 break;
474 case self::$EXPORT_TYPE_LDCOMPTA10:
475 $this->exportLDCompta10($TData, $exportFile);
476 break;
477 case self::$EXPORT_TYPE_GESTIMUMV3:
478 $this->exportGestimumV3($TData, $exportFile);
479 break;
480 case self::$EXPORT_TYPE_GESTIMUMV5:
481 $this->exportGestimumV5($TData, $exportFile);
482 break;
483 case self::$EXPORT_TYPE_FEC:
484 $this->exportFEC($TData, $exportFile);
485 break;
486 case self::$EXPORT_TYPE_FEC2:
487 $this->exportFEC2($TData, $exportFile);
488 break;
489 case self::$EXPORT_TYPE_ISUITEEXPERT :
490 $this->exportiSuiteExpert($TData, $exportFile);
491 break;
492 default:
493 global $hookmanager;
494 $parameters = array('format' => $formatexportset);
495 // file contents will be created in the hooked function via print
496 $reshook = $hookmanager->executeHooks('export', $parameters, $TData);
497 if ($reshook != 1) {
498 $this->errors[] = $langs->trans('accountancy_error_modelnotfound');
499 }
500 break;
501 }
502
503 // create and download export file or archive
504 if ($outputMode == 1 || $outputMode == 2) {
505 $error = 0;
506
507 // close export file
508 if ($exportFile) {
509 fclose($exportFile);
510 }
511
512 if ($withAttachment == 1) {
513 // create archive file
514 if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
515 // archive files
516 $downloadFileMimeType = 'application/zip';
517 $downloadFileFullName = $archiveFullName;
518 $downloadFilePath = $archivePath;
519
520 // create archive
521 $archive = new ZipArchive();
522 $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
523 if ($res !== true) {
524 $error++;
525 $this->errors[] = $langs->trans('ErrorFileNotFound', $archivePath);
526 }
527 if (!$error) {
528 // add files
529 foreach ($archiveFileList as $archiveFileArr) {
530 $res = $archive->addFile($archiveFileArr['path'], $archiveFileArr['name']);
531 if (!$res) {
532 $error++;
533 $this->errors[] = $langs->trans('ErrorArchiveAddFile', $archiveFileArr['name']);
534 break;
535 }
536 }
537 }
538 if (!$error) {
539 // close archive
540 $archive->close();
541 }
542 }
543 }
544
545 if (!$error) {
546 // download after writing files
547 if ($downloadMode == 1) {
548 if ($withAttachment == 0) {
549 // only download exported file
550 if (!empty($exportFileFullName) && !empty($exportFilePath)) {
551 $downloadFileMimeType = $mimetype;
552 $downloadFileFullName = $exportFileFullName;
553 $downloadFilePath = $exportFilePath;
554 }
555 }
556
557 // download export file or archive
558 if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath)) {
559 header('Content-Type: ' . $downloadFileMimeType);
560 header('Content-Disposition: attachment; filename=' . $downloadFileFullName);
561 header('Cache-Control: Public, must-revalidate');
562 header('Pragma: public');
563 header('Content-Length: ' . dol_filesize($downloadFilePath));
564 readfileLowMemory($downloadFilePath);
565 }
566 }
567 }
568
569 if ($error) {
570 return -1;
571 }
572 }
573
574 return 1;
575 }
576
577
585 public function exportCegid($objectLines, $exportFile = null)
586 {
587 $separator = ";";
588 $end_line = "\n";
589
590 foreach ($objectLines as $line) {
591 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
592
593 $tab = array();
594
595 $tab[] = $date_document;
596 $tab[] = $line->code_journal;
597 $tab[] = length_accountg($line->numero_compte);
598 $tab[] = length_accounta($line->subledger_account);
599 $tab[] = $line->sens;
600 $tab[] = price2fec(abs($line->debit - $line->credit));
601 $tab[] = dol_string_unaccent($line->label_operation);
602 $tab[] = dol_string_unaccent($line->doc_ref);
603
604 $output = implode($separator, $tab).$end_line;
605 if ($exportFile) {
606 fwrite($exportFile, $output);
607 } else {
608 print $output;
609 }
610 }
611 }
612
621 public function exportCogilog($objectLines, $exportFile = null)
622 {
623 $separator = "\t";
624 $end_line = "\n";
625
626 foreach ($objectLines as $line) {
627 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
628
629 $refInvoice = '';
630 if ($line->doc_type == 'customer_invoice') {
631 // Customer invoice
632 require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
633 $invoice = new Facture($this->db);
634 $invoice->fetch($line->fk_doc);
635
636 $refInvoice = $invoice->ref;
637 } elseif ($line->doc_type == 'supplier_invoice') {
638 // Supplier invoice
639 require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
640 $invoice = new FactureFournisseur($this->db);
641 $invoice->fetch($line->fk_doc);
642
643 $refInvoice = $invoice->ref_supplier;
644 }
645
646 $tab = array();
647
648 $tab[] = $line->code_journal;
649 $tab[] = $date_document;
650 $tab[] = $refInvoice;
651 if (empty($line->subledger_account)) {
652 $tab[] = length_accountg($line->numero_compte);
653 } else {
654 $tab[] = length_accounta($line->subledger_account);
655 }
656 $tab[] = "";
657 $tab[] = $line->label_operation;
658 $tab[] = $date_document;
659 if ($line->sens == 'D') {
660 $tab[] = price($line->debit);
661 $tab[] = "";
662 } elseif ($line->sens == 'C') {
663 $tab[] = "";
664 $tab[] = price($line->credit);
665 }
666 $tab[] = $line->doc_ref;
667 $tab[] = $line->label_operation;
668
669 $output = implode($separator, $tab).$end_line;
670 if ($exportFile) {
671 fwrite($exportFile, $output);
672 } else {
673 print $output;
674 }
675 }
676 }
677
685 public function exportCoala($objectLines, $exportFile = null)
686 {
687 // Coala export
688 $separator = ";";
689 $end_line = "\n";
690
691 foreach ($objectLines as $line) {
692 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
693
694 $tab = array();
695
696 $tab[] = $date_document;
697 $tab[] = $line->code_journal;
698 $tab[] = length_accountg($line->numero_compte);
699 $tab[] = $line->piece_num;
700 $tab[] = $line->doc_ref;
701 $tab[] = price($line->debit);
702 $tab[] = price($line->credit);
703 $tab[] = 'E';
704 $tab[] = length_accounta($line->subledger_account);
705
706 $output = implode($separator, $tab).$end_line;
707 if ($exportFile) {
708 fwrite($exportFile, $output);
709 } else {
710 print $output;
711 }
712 }
713 }
714
722 public function exportBob50($objectLines, $exportFile = null)
723 {
724 // Bob50
725 $separator = ";";
726 $end_line = "\n";
727
728 foreach ($objectLines as $line) {
729 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
730
731 $tab = array();
732
733 $tab[] = $line->piece_num;
734 $tab[] = $date_document;
735
736 if (empty($line->subledger_account)) {
737 $tab[] = 'G';
738 $tab[] = length_accountg($line->numero_compte);
739 } else {
740 if (substr($line->numero_compte, 0, 3) == '411') {
741 $tab[] = 'C';
742 }
743 if (substr($line->numero_compte, 0, 3) == '401') {
744 $tab[] = 'F';
745 }
746 $tab[] = length_accounta($line->subledger_account);
747 }
748
749 $tab[] = price($line->debit);
750 $tab[] = price($line->credit);
751 $tab[] = dol_trunc($line->label_operation, 32);
752
753 $output = implode($separator, $tab).$end_line;
754 if ($exportFile) {
755 fwrite($exportFile, $output);
756 } else {
757 print $output;
758 }
759 }
760 }
761
777 public function exportCiel($objectLines, $exportFile = null)
778 {
779 $end_line = "\r\n";
780
781 $i = 1;
782
783 foreach ($objectLines as $line) {
784 $code_compta = length_accountg($line->numero_compte);
785 if (!empty($line->subledger_account)) {
786 $code_compta = length_accounta($line->subledger_account);
787 }
788
789 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
790 $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d');
791
792 $tab = array();
793
794 $tab[] = str_pad($line->piece_num, 5);
795 $tab[] = str_pad(self::trunc($line->code_journal, 2), 2);
796 $tab[] = str_pad($date_document, 8, ' ', STR_PAD_LEFT);
797 $tab[] = str_pad($date_echeance, 8, ' ', STR_PAD_LEFT);
798 $tab[] = str_pad(self::trunc($line->doc_ref, 12), 12);
799 $tab[] = str_pad(self::trunc($code_compta, 11), 11);
800 $tab[] = str_pad(self::trunc(dol_string_unaccent($line->doc_ref).dol_string_unaccent($line->label_operation), 25), 25);
801 $tab[] = str_pad(price2fec(abs($line->debit - $line->credit)), 13, ' ', STR_PAD_LEFT);
802 $tab[] = str_pad($line->sens, 1);
803 $tab[] = str_repeat(' ', 18); // Analytical accounting - Not managed in Dolibarr
804 $tab[] = str_pad(self::trunc(dol_string_unaccent($line->label_operation), 34), 34);
805 $tab[] = 'O2003'; // 0 = EUR | 2003 = Format Ciel
806
807 $output = implode($tab).$end_line;
808 if ($exportFile) {
809 fwrite($exportFile, $output);
810 } else {
811 print $output;
812 }
813 $i++;
814 }
815 }
816
831 public function exportQuadratus($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
832 {
833 global $conf, $db;
834
835 $end_line = "\r\n";
836
837 // We should use dol_now function not time however this is wrong date to transfert in accounting
838 // $date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
839 // $date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
840 foreach ($objectLines as $line) {
841 // Clean some data
842 $line->doc_ref = dol_string_unaccent($line->doc_ref);
843
844 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
845 $line->label_operation = str_replace(array("- ", "…", "..."), "", $line->label_operation);
846 $line->label_operation = dol_string_unaccent($line->label_operation);
847
848 $line->numero_compte = dol_string_unaccent($line->numero_compte);
849 $line->label_compte = dol_string_unaccent($line->label_compte);
850 $line->subledger_account = dol_string_unaccent($line->subledger_account);
851
852 $line->subledger_label = str_replace(array("- ", "…", "..."), "", $line->subledger_label);
853 $line->subledger_label = dol_string_unaccent($line->subledger_label);
854
855 $code_compta = $line->numero_compte;
856 if (!empty($line->subledger_account)) {
857 $code_compta = $line->subledger_account;
858 }
859
860 $tab = array();
861
862 if (!empty($line->subledger_account)) {
863 $tab['type_ligne'] = 'C';
864 $tab['num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8);
865 $tab['lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30);
866
867 if ($line->doc_type == 'customer_invoice') {
868 $tab['lib_alpha'] = strtoupper(str_pad('C'.self::trunc(dol_string_unaccent($line->subledger_label), 6), 7));
869 $tab['filler'] = str_repeat(' ', 52);
870 $tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, 8), 8);
871 } elseif ($line->doc_type == 'supplier_invoice') {
872 $tab['lib_alpha'] = strtoupper(str_pad('F'.self::trunc(dol_string_unaccent($line->subledger_label), 6), 7));
873 $tab['filler'] = str_repeat(' ', 52);
874 $tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, 8), 8);
875 } else {
876 $tab['filler'] = str_repeat(' ', 59);
877 $tab['coll_compte'] = str_pad(' ', 8);
878 }
879
880 $tab['filler2'] = str_repeat(' ', 110);
881 $tab['Maj'] = 2; // Partial update (alpha key, label, address, collectif, RIB)
882
883 if ($line->doc_type == 'customer_invoice') {
884 $tab['type_compte'] = 'C';
885 } elseif ($line->doc_type == 'supplier_invoice') {
886 $tab['type_compte'] = 'F';
887 } else {
888 $tab['type_compte'] = 'G';
889 }
890
891 $tab['filler3'] = str_repeat(' ', 235);
892
893 $tab['end_line'] = $end_line;
894
895 if ($exportFile) {
896 fwrite($exportFile, implode($tab));
897 } else {
898 print implode($tab);
899 }
900 }
901
902 $tab = array();
903 $tab['type_ligne'] = 'M';
904 $tab['num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
905 $tab['code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
906 $tab['folio'] = '000';
907
908 // We use invoice date $line->doc_date not $date_ecriture which is the transfert date
909 // maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
910 //$tab['date_ecriture'] = $date_ecriture;
911 $tab['date_ecriture'] = dol_print_date($line->doc_date, '%d%m%y');
912 $tab['filler'] = ' ';
913 $tab['libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.' '.$line->label_operation, 20), 20);
914
915 // Credit invoice - invert sens
916 /*
917 if ($line->montant < 0) {
918 if ($line->sens == 'C') {
919 $tab['sens'] = 'D';
920 } else {
921 $tab['sens'] = 'C';
922 }
923 $tab['signe_montant'] = '-';
924 } else {
925 $tab['sens'] = $line->sens; // C or D
926 $tab['signe_montant'] = '+';
927 }*/
928 $tab['sens'] = $line->sens; // C or D
929 $tab['signe_montant'] = '+';
930
931 // The amount must be in centimes without decimal points.
932 $tab['montant'] = str_pad(abs(($line->debit - $line->credit) * 100), 12, '0', STR_PAD_LEFT);
933 $tab['contrepartie'] = str_repeat(' ', 8);
934
935 // Force date format : %d%m%y
936 if (!empty($line->date_lim_reglement)) {
937 //$tab['date_echeance'] = dol_print_date($line->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE);
938 $tab['date_echeance'] = dol_print_date($line->date_lim_reglement, '%d%m%y'); // Format must be ddmmyy
939 } else {
940 $tab['date_echeance'] = '000000';
941 }
942
943 // Please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
944 // $tab['lettrage'] = str_repeat(' ', 5);
945 $tab['lettrage'] = str_repeat(' ', 2);
946 $tab['codestat'] = str_repeat(' ', 3);
947 $tab['num_piece'] = str_pad(self::trunc($line->piece_num, 5), 5);
948
949 // Keep correct quadra named field instead of anon filler
950 // $tab['filler2'] = str_repeat(' ', 20);
951 $tab['affaire'] = str_repeat(' ', 10);
952 $tab['quantity1'] = str_repeat(' ', 10);
953 $tab['num_piece2'] = str_pad(self::trunc($line->piece_num, 8), 8);
954 $tab['devis'] = str_pad($conf->currency, 3);
955 $tab['code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
956 $tab['filler3'] = str_repeat(' ', 3);
957
958 // Keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
959 // 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
960 // TODO: we should filter more than only accent to avoid wrong line size
961 // TODO: remove invoice number doc_ref in label,
962 // TODO: we should offer an option for customer to build the label using invoice number / name / date in accounting software
963 //$tab['libelle_ecriture2'] = str_pad(self::trunc($line->doc_ref . ' ' . $line->label_operation, 30), 30);
964 $tab['libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
965 $tab['codetva'] = str_repeat(' ', 2);
966
967 // We need to keep the 10 lastest number of invoice doc_ref not the beginning part that is the unusefull almost same part
968 // $tab['num_piece3'] = str_pad(self::trunc($line->piece_num, 10), 10);
969 $tab['num_piece3'] = substr(self::trunc($line->doc_ref, 20), -10);
970 $tab['reserved'] = str_repeat(' ', 10); // position 159
971 $tab['currency_amount'] = str_repeat(' ', 13); // position 169
972 // get document file
973 $attachmentFileName = '';
974 if ($withAttachment == 1) {
975 $attachmentFileKey = trim($line->piece_num);
976
977 if (!isset($archiveFileList[$attachmentFileKey])) {
978 $objectDirPath = '';
979 $objectFileName = dol_sanitizeFileName($line->doc_ref);
980 if ($line->doc_type == 'customer_invoice') {
981 $objectDirPath = !empty($conf->facture->multidir_output[$conf->entity]) ? $conf->facture->multidir_output[$conf->entity] : $conf->facture->dir_output;
982 } elseif ($line->doc_type == 'expense_report') {
983 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->factureexpensereport->dir_output;
984 } elseif ($line->doc_type == 'supplier_invoice') {
985 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
986 }
987 $arrayofinclusion = array();
988 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').'\.pdf$';
989 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, true);
990 if (!empty($fileFoundList)) {
991 $attachmentFileNameTrunc = str_pad(self::trunc($line->piece_num, 8), 8, '0', STR_PAD_LEFT);
992 foreach ($fileFoundList as $fileFound) {
993 if (strstr($fileFound['name'], $objectFileName)) {
994 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
995 if (file_exists($fileFoundPath)) {
996 $archiveFileList[$attachmentFileKey] = array(
997 'path' => $fileFoundPath,
998 'name' => $attachmentFileNameTrunc.'.pdf',
999 );
1000 break;
1001 }
1002 }
1003 }
1004 }
1005 }
1006
1007 if (isset($archiveFileList[$attachmentFileKey])) {
1008 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1009 }
1010 }
1011 if (dol_strlen($attachmentFileName) == 12) {
1012 $tab['attachment'] = $attachmentFileName; // position 182
1013 } else {
1014 $tab['attachment'] = str_repeat(' ', 12); // position 182
1015 }
1016 $tab['filler4'] = str_repeat(' ', 38);
1017 $tab['end_line'] = $end_line;
1018
1019 if ($exportFile) {
1020 fwrite($exportFile, implode($tab));
1021 } else {
1022 print implode($tab);
1023 }
1024 }
1025
1026 return $archiveFileList;
1027 }
1028
1039 public function exportWinfic($objectLines, $exportFile = null)
1040 {
1041 global $conf;
1042
1043 $end_line = "\r\n";
1044 $index = 1;
1045
1046 //We should use dol_now function not time however this is wrong date to transfert in accounting
1047 //$date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
1048 //$date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
1049
1050 // Warning ! When truncation is necessary, no dot because 3 dots = three characters. The columns are shifted
1051
1052 foreach ($objectLines as $line) {
1053 $code_compta = $line->numero_compte;
1054 if (!empty($line->subledger_account)) {
1055 $code_compta = $line->subledger_account;
1056 }
1057
1058 $tab = array();
1059 //$tab['type_ligne'] = 'M';
1060 $tab['code_journal'] = str_pad(dol_trunc($line->code_journal, 2, 'right', 'UTF-8', 1), 2);
1061
1062 //We use invoice date $line->doc_date not $date_ecriture which is the transfert date
1063 //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
1064 //$tab['date_ecriture'] = $date_ecriture;
1065 $tab['date_operation'] = dol_print_date($line->doc_date, '%d%m%Y');
1066
1067 $tab['folio'] = ' 1';
1068
1069 $tab['num_ecriture'] = str_pad(dol_trunc($index, 6, 'right', 'UTF-8', 1), 6, ' ', STR_PAD_LEFT);
1070
1071 $tab['jour_ecriture'] = dol_print_date($line->doc_date, '%d%m%y');
1072
1073 $tab['num_compte'] = str_pad(dol_trunc($code_compta, 6, 'right', 'UTF-8', 1), 6, '0');
1074
1075 if ($line->sens == 'D') {
1076 $tab['montant_debit'] = str_pad(number_format($line->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1077
1078 $tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1079 } else {
1080 $tab['montant_debit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1081
1082 $tab['montant_crebit'] = str_pad(number_format($line->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
1083 }
1084
1085 $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);
1086
1087 $tab['lettrage'] = str_repeat(dol_trunc($line->lettering_code, 2, 'left', 'UTF-8', 1), 2);
1088
1089 $tab['code_piece'] = str_pad(dol_trunc($line->piece_num, 5, 'left', 'UTF-8', 1), 5, ' ', STR_PAD_LEFT);
1090
1091 $tab['code_stat'] = str_repeat(' ', 4);
1092
1093 if (!empty($line->date_lim_reglement)) {
1094 //$tab['date_echeance'] = dol_print_date($line->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE);
1095 $tab['date_echeance'] = dol_print_date($line->date_lim_reglement, '%d%m%Y');
1096 } else {
1097 $tab['date_echeance'] = dol_print_date($line->doc_date, '%d%m%Y');
1098 }
1099
1100 $tab['monnaie'] = '1';
1101
1102 $tab['filler'] = ' ';
1103
1104 $tab['ind_compteur'] = ' ';
1105
1106 $tab['quantite'] = '0,000000000';
1107
1108 $tab['code_pointage'] = str_repeat(' ', 2);
1109
1110 $tab['end_line'] = $end_line;
1111
1112 print implode('|', $tab);
1113
1114 $index++;
1115 }
1116 }
1117
1118
1126 public function exportEbp($objectLines, $exportFile = null)
1127 {
1128
1129 $separator = ',';
1130 $end_line = "\n";
1131
1132 foreach ($objectLines as $line) {
1133 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
1134
1135 $tab = array();
1136
1137 $tab[] = $line->id;
1138 $tab[] = $date_document;
1139 $tab[] = $line->code_journal;
1140 if (empty($line->subledger_account)) {
1141 $tab[] = $line->numero_compte;
1142 } else {
1143 $tab[] = $line->subledger_account;
1144 }
1145 //$tab[] = substr(length_accountg($line->numero_compte), 0, 2) . $separator;
1146 $tab[] = '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"';
1147 $tab[] = '"'.dol_trunc($line->piece_num, 15, 'right', 'UTF-8', 1).'"';
1148 $tab[] = price2num(abs($line->debit - $line->credit));
1149 $tab[] = $line->sens;
1150 $tab[] = $date_document;
1151 //print 'EUR';
1152
1153 $output = implode($separator, $tab).$end_line;
1154 if ($exportFile) {
1155 fwrite($exportFile, $output);
1156 } else {
1157 print $output;
1158 }
1159 }
1160 }
1161
1162
1170 public function exportAgiris($objectLines, $exportFile = null)
1171 {
1172 $separator = ';';
1173 $end_line = "\n";
1174
1175 foreach ($objectLines as $line) {
1176 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
1177
1178 $tab = array();
1179
1180 $tab[] = $line->piece_num;
1181 $tab[] = self::toAnsi($line->label_operation);
1182 $tab[] = $date_document;
1183 $tab[] = self::toAnsi($line->label_operation);
1184
1185 if (empty($line->subledger_account)) {
1186 $tab[] = length_accountg($line->numero_compte);
1187 $tab[] = self::toAnsi($line->label_compte);
1188 } else {
1189 $tab[] = length_accounta($line->subledger_account);
1190 $tab[] = self::toAnsi($line->subledger_label);
1191 }
1192
1193 $tab[] = self::toAnsi($line->doc_ref);
1194 $tab[] = price($line->debit);
1195 $tab[] = price($line->credit);
1196 $tab[] = price(abs($line->debit - $line->credit));
1197 $tab[] = $line->sens;
1198 $tab[] = $line->lettering_code;
1199 $tab[] = $line->code_journal;
1200
1201 $output = implode($separator, $tab).$end_line;
1202 if ($exportFile) {
1203 fwrite($exportFile, $output);
1204 } else {
1205 print $output;
1206 }
1207 }
1208 }
1209
1217 public function exportOpenConcerto($objectLines, $exportFile = null)
1218 {
1219 $separator = ';';
1220 $end_line = "\n";
1221
1222 foreach ($objectLines as $line) {
1223 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
1224
1225 $tab = array();
1226
1227 $tab[] = $date_document;
1228 $tab[] = $line->code_journal;
1229 if (empty($line->subledger_account)) {
1230 $tab[] = length_accountg($line->numero_compte);
1231 } else {
1232 $tab[] = length_accounta($line->subledger_account);
1233 }
1234 $tab[] = $line->doc_ref;
1235 $tab[] = $line->label_operation;
1236 $tab[] = price($line->debit);
1237 $tab[] = price($line->credit);
1238
1239 $output = implode($separator, $tab).$end_line;
1240 if ($exportFile) {
1241 fwrite($exportFile, $output);
1242 } else {
1243 print $output;
1244 }
1245 }
1246 }
1247
1255 public function exportConfigurable($objectLines, $exportFile = null)
1256 {
1257 global $conf;
1258
1259 $separator = $this->separator;
1260
1261 foreach ($objectLines as $line) {
1262 $date_document = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
1263
1264 $tab = array();
1265 // export configurable
1266 $tab[] = $line->piece_num;
1267 $tab[] = $date_document;
1268 $tab[] = $line->doc_ref;
1269 $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
1270 $tab[] = length_accountg($line->numero_compte);
1271 $tab[] = length_accounta($line->subledger_account);
1272 $tab[] = price2num($line->debit);
1273 $tab[] = price2num($line->credit);
1274 $tab[] = price2num($line->debit - $line->credit);
1275 $tab[] = $line->code_journal;
1276
1277 $output = implode($separator, $tab).$this->end_line;
1278 if ($exportFile) {
1279 fwrite($exportFile, $output);
1280 } else {
1281 print $output;
1282 }
1283 }
1284 }
1285
1293 public function exportFEC($objectLines, $exportFile = null)
1294 {
1295 global $langs;
1296
1297 $separator = "\t";
1298 $end_line = "\r\n";
1299
1300 $tab = array();
1301 $tab[] = "JournalCode";
1302 $tab[] = "JournalLib";
1303 $tab[] = "EcritureNum";
1304 $tab[] = "EcritureDate";
1305 $tab[] = "CompteNum";
1306 $tab[] = "CompteLib";
1307 $tab[] = "CompAuxNum";
1308 $tab[] = "CompAuxLib";
1309 $tab[] = "PieceRef";
1310 $tab[] = "PieceDate";
1311 $tab[] = "EcritureLib";
1312 $tab[] = "Debit";
1313 $tab[] = "Credit";
1314 $tab[] = "EcritureLet";
1315 $tab[] = "DateLet";
1316 $tab[] = "ValidDate";
1317 $tab[] = "Montantdevise";
1318 $tab[] = "Idevise";
1319 $tab[] = "DateLimitReglmt";
1320 $tab[] = "NumFacture";
1321
1322 $output = implode($separator, $tab).$end_line;
1323 if ($exportFile) {
1324 fwrite($exportFile, $output);
1325 } else {
1326 print $output;
1327 }
1328
1329 foreach ($objectLines as $line) {
1330 if ($line->debit == 0 && $line->credit == 0) {
1331 //unset($array[$line]);
1332 } else {
1333 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1334 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1335 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1336 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1337 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1338
1339 $refInvoice = '';
1340 if ($line->doc_type == 'customer_invoice') {
1341 // Customer invoice
1342 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1343 $invoice = new Facture($this->db);
1344 $invoice->fetch($line->fk_doc);
1345
1346 $refInvoice = $invoice->ref;
1347 } elseif ($line->doc_type == 'supplier_invoice') {
1348 // Supplier invoice
1349 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1350 $invoice = new FactureFournisseur($this->db);
1351 $invoice->fetch($line->fk_doc);
1352
1353 $refInvoice = $invoice->ref_supplier;
1354 }
1355
1356 $tab = array();
1357
1358 // FEC:JournalCode
1359 $tab[] = $line->code_journal;
1360
1361 // FEC:JournalLib
1362 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1363 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1364 $tab[] = $labeljournal;
1365
1366 // FEC:EcritureNum
1367 $tab[] = $line->piece_num;
1368
1369 // FEC:EcritureDate
1370 $tab[] = $date_document;
1371
1372 // FEC:CompteNum
1373 $tab[] = length_accountg($line->numero_compte);
1374
1375 // FEC:CompteLib
1376 $tab[] = dol_string_unaccent($line->label_compte);
1377
1378 // FEC:CompAuxNum
1379 $tab[] = length_accounta($line->subledger_account);
1380
1381 // FEC:CompAuxLib
1382 $tab[] = dol_string_unaccent($line->subledger_label);
1383
1384 // FEC:PieceRef
1385 $tab[] = $line->doc_ref;
1386
1387 // FEC:PieceDate
1388 $tab[] = dol_string_unaccent($date_creation);
1389
1390 // FEC:EcritureLib
1391 // Clean label operation to prevent problem on export with tab separator & other character
1392 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1393 $tab[] = dol_string_unaccent($line->label_operation);
1394
1395 // FEC:Debit
1396 $tab[] = price2fec($line->debit);
1397
1398 // FEC:Credit
1399 $tab[] = price2fec($line->credit);
1400
1401 // FEC:EcritureLet
1402 $tab[] = $line->lettering_code;
1403
1404 // FEC:DateLet
1405 $tab[] = $date_lettering;
1406
1407 // FEC:ValidDate
1408 $tab[] = $date_validation;
1409
1410 // FEC:Montantdevise
1411 $tab[] = $line->multicurrency_amount;
1412
1413 // FEC:Idevise
1414 $tab[] = $line->multicurrency_code;
1415
1416 // FEC_suppl:DateLimitReglmt
1417 $tab[] = $date_limit_payment;
1418
1419 // FEC_suppl:NumFacture
1420 // Clean ref invoice to prevent problem on export with tab separator & other character
1421 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1422 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1423
1424 $output = implode($separator, $tab).$end_line;
1425 if ($exportFile) {
1426 fwrite($exportFile, $output);
1427 } else {
1428 print $output;
1429 }
1430 }
1431 }
1432 }
1433
1441 public function exportFEC2($objectLines, $exportFile = null)
1442 {
1443 global $langs;
1444
1445 $separator = "\t";
1446 $end_line = "\r\n";
1447
1448 $tab = array();
1449 $tab[] = "JournalCode";
1450 $tab[] = "JournalLib";
1451 $tab[] = "EcritureNum";
1452 $tab[] = "EcritureDate";
1453 $tab[] = "CompteNum";
1454 $tab[] = "CompteLib";
1455 $tab[] = "CompAuxNum";
1456 $tab[] = "CompAuxLib";
1457 $tab[] = "PieceRef";
1458 $tab[] = "PieceDate";
1459 $tab[] = "EcritureLib";
1460 $tab[] = "Debit";
1461 $tab[] = "Credit";
1462 $tab[] = "EcritureLet";
1463 $tab[] = "DateLet";
1464 $tab[] = "ValidDate";
1465 $tab[] = "Montantdevise";
1466 $tab[] = "Idevise";
1467 $tab[] = "DateLimitReglmt";
1468 $tab[] = "NumFacture";
1469
1470 $output = implode($separator, $tab).$end_line;
1471 if ($exportFile) {
1472 fwrite($exportFile, $output);
1473 } else {
1474 print $output;
1475 }
1476
1477 foreach ($objectLines as $line) {
1478 if ($line->debit == 0 && $line->credit == 0) {
1479 //unset($array[$line]);
1480 } else {
1481 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1482 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1483 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1484 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1485 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1486
1487 $refInvoice = '';
1488 if ($line->doc_type == 'customer_invoice') {
1489 // Customer invoice
1490 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1491 $invoice = new Facture($this->db);
1492 $invoice->fetch($line->fk_doc);
1493
1494 $refInvoice = $invoice->ref;
1495 } elseif ($line->doc_type == 'supplier_invoice') {
1496 // Supplier invoice
1497 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1498 $invoice = new FactureFournisseur($this->db);
1499 $invoice->fetch($line->fk_doc);
1500
1501 $refInvoice = $invoice->ref_supplier;
1502 }
1503
1504 $tab = array();
1505
1506 // FEC:JournalCode
1507 $tab[] = $line->code_journal;
1508
1509 // FEC:JournalLib
1510 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1511 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1512 $tab[] = $labeljournal;
1513
1514 // FEC:EcritureNum
1515 $tab[] = $line->piece_num;
1516
1517 // FEC:EcritureDate
1518 $tab[] = $date_creation;
1519
1520 // FEC:CompteNum
1521 $tab[] = length_accountg($line->numero_compte);
1522
1523 // FEC:CompteLib
1524 $tab[] = dol_string_unaccent($line->label_compte);
1525
1526 // FEC:CompAuxNum
1527 $tab[] = length_accounta($line->subledger_account);
1528
1529 // FEC:CompAuxLib
1530 $tab[] = dol_string_unaccent($line->subledger_label);
1531
1532 // FEC:PieceRef
1533 $tab[] = $line->doc_ref;
1534
1535 // FEC:PieceDate
1536 $tab[] = $date_document;
1537
1538 // FEC:EcritureLib
1539 // Clean label operation to prevent problem on export with tab separator & other character
1540 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1541 $tab[] = dol_string_unaccent($line->label_operation);
1542
1543 // FEC:Debit
1544 $tab[] = price2fec($line->debit);
1545
1546 // FEC:Credit
1547 $tab[] = price2fec($line->credit);
1548
1549 // FEC:EcritureLet
1550 $tab[] = $line->lettering_code;
1551
1552 // FEC:DateLet
1553 $tab[] = $date_lettering;
1554
1555 // FEC:ValidDate
1556 $tab[] = $date_validation;
1557
1558 // FEC:Montantdevise
1559 $tab[] = $line->multicurrency_amount;
1560
1561 // FEC:Idevise
1562 $tab[] = $line->multicurrency_code;
1563
1564 // FEC_suppl:DateLimitReglmt
1565 $tab[] = $date_limit_payment;
1566
1567 // FEC_suppl:NumFacture
1568 // Clean ref invoice to prevent problem on export with tab separator & other character
1569 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1570 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1571
1572 $output = implode($separator, $tab).$end_line;
1573 if ($exportFile) {
1574 fwrite($exportFile, $output);
1575 } else {
1576 print $output;
1577 }
1578 }
1579 }
1580 }
1581
1592 public function exportSAGE50SWISS($objectLines, $exportFile = null)
1593 {
1594 // SAGE50SWISS
1595 $separator = ',';
1596 $end_line = "\r\n";
1597
1598 // Print header line
1599 $tab = array();
1600
1601 $tab[] = "Blg";
1602 $tab[] = "Datum";
1603 $tab[] = "Kto";
1604 $tab[] = "S/H";
1605 $tab[] = "Grp";
1606 $tab[] = "GKto";
1607 $tab[] = "SId";
1608 $tab[] = "SIdx";
1609 $tab[] = "KIdx";
1610 $tab[] = "BTyp";
1611 $tab[] = "MTyp";
1612 $tab[] = "Code";
1613 $tab[] = "Netto";
1614 $tab[] = "Steuer";
1615 $tab[] = "FW-Betrag";
1616 $tab[] = "Tx1";
1617 $tab[] = "Tx2";
1618 $tab[] = "PkKey";
1619 $tab[] = "OpId";
1620 $tab[] = "Flag";
1621
1622 $output = implode($separator, $tab).$end_line;
1623 if ($exportFile) {
1624 fwrite($exportFile, $output);
1625 } else {
1626 print $output;
1627 }
1628
1629 $thisPieceNum = "";
1630 $thisPieceAccountNr = "";
1631 $aSize = count($objectLines);
1632 foreach ($objectLines as $aIndex => $line) {
1633 $sammelBuchung = false;
1634 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1635 $sammelBuchung = true;
1636 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1637 $sammelBuchung = true;
1638 } elseif ($aIndex + 1 < $aSize
1639 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1640 && $aIndex - 1 < $aSize
1641 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1642 ) {
1643 $sammelBuchung = true;
1644 }
1645
1646 $tab = array();
1647
1648 //Blg
1649 $tab[] = $line->piece_num;
1650
1651 // Datum
1652 $date_document = dol_print_date($line->doc_date, '%d.%m.%Y');
1653 $tab[] = $date_document;
1654
1655 // Kto
1656 $tab[] = length_accountg($line->numero_compte);
1657 // S/H
1658 if ($line->sens == 'D') {
1659 $tab[] = 'S';
1660 } else {
1661 $tab[] = 'H';
1662 }
1663 // Grp
1664 $tab[] = self::trunc($line->code_journal, 1);
1665 // GKto
1666 if (empty($line->code_tiers)) {
1667 if ($line->piece_num == $thisPieceNum) {
1668 $tab[] = length_accounta($thisPieceAccountNr);
1669 } else {
1670 $tab[] = "div";
1671 }
1672 } else {
1673 $tab[] = length_accounta($line->code_tiers);
1674 }
1675 // SId
1676 $tab[] = $this->separator;
1677 // SIdx
1678 $tab[] = "0";
1679 // KIdx
1680 $tab[] = "0";
1681 // BTyp
1682 $tab[] = "0";
1683
1684 // MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
1685 if ($sammelBuchung) {
1686 $tab[] = "2";
1687 } else {
1688 $tab[] = "1";
1689 }
1690 // Code
1691 $tab[] = '""';
1692 // Netto
1693 $tab[] = abs($line->debit - $line->credit);
1694 // Steuer
1695 $tab[] = "0.00";
1696 // FW-Betrag
1697 $tab[] = "0.00";
1698 // Tx1
1699 $line1 = self::toAnsi($line->label_compte, 29);
1700 if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
1701 $line1 = "";
1702 }
1703 $line2 = self::toAnsi($line->doc_ref, 29);
1704 if (strlen($line1) == 0) {
1705 $line1 = $line2;
1706 $line2 = "";
1707 }
1708 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1709 $line1 = $line1.' / '.$line2;
1710 $line2 = "";
1711 }
1712
1713 $tab[] = '"'.self::toAnsi($line1).'"';
1714 // Tx2
1715 $tab[] = '"'.self::toAnsi($line2).'"';
1716 //PkKey
1717 $tab[] = "0";
1718 //OpId
1719 $tab[] = $this->separator;
1720
1721 // Flag
1722 $tab[] = "0";
1723
1724 $output = implode($separator, $tab).$end_line;
1725 if ($exportFile) {
1726 fwrite($exportFile, $output);
1727 } else {
1728 print $output;
1729 }
1730
1731 if ($line->piece_num !== $thisPieceNum) {
1732 $thisPieceNum = $line->piece_num;
1733 $thisPieceAccountNr = $line->numero_compte;
1734 }
1735 }
1736 }
1737
1746 public function exportLDCompta($objectLines, $exportFile = null)
1747 {
1748
1749 $separator = ';';
1750 $end_line = "\r\n";
1751
1752 foreach ($objectLines as $line) {
1753 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1754 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1755 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1756
1757 $tab = array();
1758
1759 // TYPE
1760 $type_enregistrement = 'E'; // For write movement
1761 $tab[] = $type_enregistrement;
1762 // JNAL
1763 $tab[] = substr($line->code_journal, 0, 2);
1764 // NECR
1765 $tab[] = $line->id;
1766 // NPIE
1767 $tab[] = $line->piece_num;
1768 // DATP
1769 $tab[] = $date_document;
1770 // LIBE
1771 $tab[] = $line->label_operation;
1772 // DATH
1773 $tab[] = $date_lim_reglement;
1774 // CNPI
1775 if ($line->doc_type == 'supplier_invoice') {
1776 if (($line->debit - $line->credit) > 0) {
1777 $nature_piece = 'AF';
1778 } else {
1779 $nature_piece = 'FF';
1780 }
1781 } elseif ($line->doc_type == 'customer_invoice') {
1782 if (($line->debit - $line->credit) < 0) {
1783 $nature_piece = 'AC';
1784 } else {
1785 $nature_piece = 'FC';
1786 }
1787 } else {
1788 $nature_piece = '';
1789 }
1790 $tab[] = $nature_piece;
1791 // RACI
1792 // if (!empty($line->subledger_account)) {
1793 // if ($line->doc_type == 'supplier_invoice') {
1794 // $racine_subledger_account = '40';
1795 // } elseif ($line->doc_type == 'customer_invoice') {
1796 // $racine_subledger_account = '41';
1797 // } else {
1798 // $racine_subledger_account = '';
1799 // }
1800 // } else {
1801 $racine_subledger_account = ''; // for records of type E leave this field blank
1802 // }
1803
1804 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
1805 // MONT
1806 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2, 2);
1807 // CODC
1808 $tab[] = $line->sens;
1809 // CPTG
1810 $tab[] = length_accountg($line->numero_compte);
1811 // DATE
1812 $tab[] = $date_creation;
1813 // CLET
1814 $tab[] = $line->lettering_code;
1815 // DATL
1816 $tab[] = $line->date_lettering;
1817 // CPTA
1818 if (!empty($line->subledger_account)) {
1819 $tab[] = length_accounta($line->subledger_account);
1820 } else {
1821 $tab[] = "";
1822 }
1823 // CNAT
1824 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
1825 $tab[] = 'F';
1826 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
1827 $tab[] = 'C';
1828 } else {
1829 $tab[] = "";
1830 }
1831 // SECT
1832 $tab[] = "";
1833 // CTRE
1834 $tab[] = "";
1835 // NORL
1836 $tab[] = "";
1837 // DATV
1838 $tab[] = "";
1839 // REFD
1840 $tab[] = $line->doc_ref;
1841 // CODH
1842 $tab[] = "";
1843 // NSEQ
1844 $tab[] = "";
1845 // MTDV
1846 $tab[] = '0';
1847 // CODV
1848 $tab[] = "";
1849 // TXDV
1850 $tab[] = '0';
1851 // MOPM
1852 $tab[] = "";
1853 // BONP
1854 $tab[] = "";
1855 // BQAF
1856 $tab[] = "";
1857 // ECES
1858 $tab[] = "";
1859 // TXTL
1860 $tab[] = "";
1861 // ECRM
1862 $tab[] = "";
1863 // DATK
1864 $tab[] = "";
1865 // HEUK
1866 $tab[] = "";
1867
1868 $output = implode($separator, $tab).$end_line;
1869 if ($exportFile) {
1870 fwrite($exportFile, $output);
1871 } else {
1872 print $output;
1873 }
1874 }
1875 }
1876
1887 public function exportLDCompta10($objectLines, $exportFile = null)
1888 {
1889 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
1890
1891 $separator = ';';
1892 $end_line = "\r\n";
1893 $last_codeinvoice = '';
1894
1895 foreach ($objectLines as $line) {
1896 // TYPE C
1897 if ($last_codeinvoice != $line->doc_ref) {
1898 //recherche societe en fonction de son code client
1899 $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
1900 $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
1901 $resql = $this->db->query($sql);
1902
1903 if ($resql && $this->db->num_rows($resql) > 0) {
1904 $soc = $this->db->fetch_object($resql);
1905
1906 $address = array('', '', '');
1907 if (strpos($soc->address, "\n") !== false) {
1908 $address = explode("\n", $soc->address);
1909 if (is_array($address) && count($address) > 0) {
1910 foreach ($address as $key => $data) {
1911 $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
1912 $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
1913 }
1914 }
1915 } else {
1916 $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
1917 $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
1918 $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
1919 }
1920
1921 $tab = array();
1922
1923 $type_enregistrement = 'C';
1924 //TYPE
1925 $tab[] = $type_enregistrement;
1926 //NOCL
1927 $tab[] = $soc->code_client;
1928 //NMCM
1929 $tab[] = "";
1930 //LIBI
1931 $tab[] = "";
1932 //TITR
1933 $tab[] = "";
1934 //RSSO
1935 $tab[] = $soc->nom;
1936 //CAD1
1937 $tab[] = $address[0];
1938 //CAD2
1939 $tab[] = $address[1];
1940 //CAD3
1941 $tab[] = $address[2];
1942 //COPO
1943 $tab[] = $soc->zip;
1944 //BUDI
1945 $tab[] = substr($soc->town, 0, 40);
1946 //CPAY
1947 $tab[] = "";
1948 //PAYS
1949 $tab[] = substr(getCountry($soc->fk_pays), 0, 40);
1950 //NTEL
1951 $tab[] = $soc->phone;
1952 //TLEX
1953 $tab[] = "";
1954 //TLPO
1955 $tab[] = "";
1956 //TLCY
1957 $tab[] = "";
1958 //NINT
1959 $tab[] = "";
1960 //COMM
1961 $tab[] = "";
1962 //SIRE
1963 $tab[] = str_replace(" ", "", $soc->siret);
1964 //RIBP
1965 $tab[] = "";
1966 //DOBQ
1967 $tab[] = "";
1968 //IBBQ
1969 $tab[] = "";
1970 //COBQ
1971 $tab[] = "";
1972 //GUBQ
1973 $tab[] = "";
1974 //CPBQ
1975 $tab[] = "";
1976 //CLBQ
1977 $tab[] = "";
1978 //BIBQ
1979 $tab[] = "";
1980 //MOPM
1981 $tab[] = "";
1982 //DJPM
1983 $tab[] = "";
1984 //DMPM
1985 $tab[] = "";
1986 //REFM
1987 $tab[] = "";
1988 //SLVA
1989 $tab[] = "";
1990 //PLCR
1991 $tab[] = "";
1992 //ECFI
1993 $tab[] = "";
1994 //CREP
1995 $tab[] = "";
1996 //NREP
1997 $tab[] = "";
1998 //TREP
1999 $tab[] = "";
2000 //MREP
2001 $tab[] = "";
2002 //GRRE
2003 $tab[] = "";
2004 //LTTA
2005 $tab[] = "";
2006 //CACT
2007 $tab[] = "";
2008 //CODV
2009 $tab[] = "";
2010 //GRTR
2011 $tab[] = "";
2012 //NOFP
2013 $tab[] = "";
2014 //BQAF
2015 $tab[] = "";
2016 //BONP
2017 $tab[] = "";
2018 //CESC
2019 $tab[] = "";
2020
2021 $output = implode($separator, $tab).$end_line;
2022 if ($exportFile) {
2023 fwrite($exportFile, $output);
2024 } else {
2025 print $output;
2026 }
2027 }
2028 }
2029
2030 $tab = array();
2031
2032 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2033 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
2034 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2035
2036 // TYPE E
2037 $type_enregistrement = 'E'; // For write movement
2038 $tab[] = $type_enregistrement;
2039 // JNAL
2040 $tab[] = substr($line->code_journal, 0, 2);
2041 // NECR
2042 $tab[] = $line->id;
2043 // NPIE
2044 $tab[] = $line->piece_num;
2045 // DATP
2046 $tab[] = $date_document;
2047 // LIBE
2048 $tab[] = dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1);
2049 // DATH
2050 $tab[] = $date_lim_reglement;
2051 // CNPI
2052 if ($line->doc_type == 'supplier_invoice') {
2053 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.
2054 $nature_piece = 'AF';
2055 } else {
2056 $nature_piece = 'FF';
2057 }
2058 } elseif ($line->doc_type == 'customer_invoice') {
2059 if (($line->amount) < 0) {
2060 $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.
2061 } else {
2062 $nature_piece = 'FC';
2063 }
2064 } else {
2065 $nature_piece = '';
2066 }
2067 $tab[] = $nature_piece;
2068 // RACI
2069 // if (!empty($line->subledger_account)) {
2070 // if ($line->doc_type == 'supplier_invoice') {
2071 // $racine_subledger_account = '40';
2072 // } elseif ($line->doc_type == 'customer_invoice') {
2073 // $racine_subledger_account = '41';
2074 // } else {
2075 // $racine_subledger_account = '';
2076 // }
2077 // } else {
2078 $racine_subledger_account = ''; // for records of type E leave this field blank
2079 // }
2080
2081 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2082 // MONT
2083 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2);
2084 // CODC
2085 $tab[] = $line->sens;
2086 // CPTG
2087 $tab[] = length_accountg($line->numero_compte);
2088 // DATE
2089 $tab[] = $date_document;
2090 // CLET
2091 $tab[] = $line->lettering_code;
2092 // DATL
2093 $tab[] = $line->date_lettering;
2094 // CPTA
2095 if (!empty($line->subledger_account)) {
2096 $tab[] = length_accounta($line->subledger_account);
2097 } else {
2098 $tab[] = "";
2099 }
2100 // CNAT
2101 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2102 $tab[] = 'F';
2103 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2104 $tab[] = 'C';
2105 } else {
2106 $tab[] = "";
2107 }
2108 // CTRE
2109 $tab[] = "";
2110 // NORL
2111 $tab[] = "";
2112 // DATV
2113 $tab[] = "";
2114 // REFD
2115 $tab[] = $line->doc_ref;
2116 // NECA
2117 $tab[] = '0';
2118 // CSEC
2119 $tab[] = "";
2120 // CAFF
2121 $tab[] = "";
2122 // CDES
2123 $tab[] = "";
2124 // QTUE
2125 $tab[] = "";
2126 // MTDV
2127 $tab[] = '0';
2128 // CODV
2129 $tab[] = "";
2130 // TXDV
2131 $tab[] = '0';
2132 // MOPM
2133 $tab[] = "";
2134 // BONP
2135 $tab[] = "";
2136 // BQAF
2137 $tab[] = "";
2138 // ECES
2139 $tab[] = "";
2140 // TXTL
2141 $tab[] = "";
2142 // ECRM
2143 $tab[] = "";
2144 // DATK
2145 $tab[] = "";
2146 // HEUK
2147 $tab[] = "";
2148
2149 $output = implode($separator, $tab).$end_line;
2150 if ($exportFile) {
2151 fwrite($exportFile, $output);
2152 } else {
2153 print $output;
2154 }
2155
2156 $last_codeinvoice = $line->doc_ref;
2157 }
2158 }
2159
2167 public function exportCharlemagne($objectLines, $exportFile = null)
2168 {
2169 global $langs;
2170 $langs->load('compta');
2171
2172 $separator = "\t";
2173 $end_line = "\n";
2174
2175 $tab = array();
2176
2177 $tab[] = $langs->transnoentitiesnoconv('Date');
2178 $tab[] = self::trunc($langs->transnoentitiesnoconv('Journal'), 6);
2179 $tab[] = self::trunc($langs->transnoentitiesnoconv('Account'), 15);
2180 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60);
2181 $tab[] = self::trunc($langs->transnoentitiesnoconv('Piece'), 20);
2182 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60);
2183 $tab[] = $langs->transnoentitiesnoconv('Amount');
2184 $tab[] = 'S';
2185 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15);
2186 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60);
2187 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15);
2188 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60);
2189 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15);
2190 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60);
2191
2192 $output = implode($separator, $tab).$end_line;
2193 if ($exportFile) {
2194 fwrite($exportFile, $output);
2195 } else {
2196 print $output;
2197 }
2198
2199 foreach ($objectLines as $line) {
2200 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2201
2202 $tab = array();
2203
2204 $tab[] = $date_document; //Date
2205
2206 $tab[] = self::trunc($line->code_journal, 6); //Journal code
2207
2208 if (!empty($line->subledger_account)) {
2209 $account = $line->subledger_account;
2210 } else {
2211 $account = $line->numero_compte;
2212 }
2213 $tab[] = self::trunc($account, 15); //Account number
2214
2215 $tab[] = self::trunc($line->label_compte, 60); //Account label
2216 $tab[] = self::trunc($line->doc_ref, 20); //Piece
2217 // Clean label operation to prevent problem on export with tab separator & other character
2218 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
2219 $tab[] = self::trunc($line->label_operation, 60); //Operation label
2220 $tab[] = price(abs($line->debit - $line->credit)); //Amount
2221 $tab[] = $line->sens; //Direction
2222 $tab[] = ""; //Analytic
2223 $tab[] = ""; //Analytic
2224 $tab[] = ""; //Analytic
2225 $tab[] = ""; //Analytic
2226 $tab[] = ""; //Analytic
2227 $tab[] = ""; //Analytic
2228
2229 $output = implode($separator, $tab).$end_line;
2230 if ($exportFile) {
2231 fwrite($exportFile, $output);
2232 } else {
2233 print $output;
2234 }
2235 }
2236 }
2237
2245 public function exportGestimumV3($objectLines, $exportFile = null)
2246 {
2247 global $langs;
2248
2249 $separator = ',';
2250 $end_line = "\r\n";
2251
2252 $invoices_infos = array();
2253 $supplier_invoices_infos = array();
2254 foreach ($objectLines as $line) {
2255 if ($line->debit == 0 && $line->credit == 0) {
2256 //unset($array[$line]);
2257 } else {
2258 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
2259 $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2260
2261 $invoice_ref = $line->doc_ref;
2262 $company_name = "";
2263
2264 if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
2265 if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2266 ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2267 if ($line->doc_type == 'customer_invoice') {
2268 // Get new customer invoice ref and company name
2269 $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
2270 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
2271 $sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
2272 $resql = $this->db->query($sql);
2273 if ($resql) {
2274 if ($obj = $this->db->fetch_object($resql)) {
2275 // Save invoice infos
2276 $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2277 $invoice_ref = $obj->ref;
2278 $company_name = $obj->nom;
2279 }
2280 }
2281 } else {
2282 // Get new supplier invoice ref and company name
2283 $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
2284 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
2285 $sql .= ' WHERE ff.rowid = '.((int) $line->fk_doc);
2286 $resql = $this->db->query($sql);
2287 if ($resql) {
2288 if ($obj = $this->db->fetch_object($resql)) {
2289 // Save invoice infos
2290 $supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2291 $invoice_ref = $obj->ref;
2292 $company_name = $obj->nom;
2293 }
2294 }
2295 }
2296 } elseif ($line->doc_type == 'customer_invoice') {
2297 // Retrieve invoice infos
2298 $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
2299 $company_name = $invoices_infos[$line->fk_doc]['company_name'];
2300 } else {
2301 // Retrieve invoice infos
2302 $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
2303 $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
2304 }
2305 }
2306
2307 $tab = array();
2308
2309 $tab[] = $line->id;
2310 $tab[] = $date_document;
2311 $tab[] = substr($line->code_journal, 0, 4);
2312
2313 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
2314 $tab[] = length_accountg($line->subledger_account);
2315 } else {
2316 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2317 }
2318 //Libellé Auto
2319 $tab[] = "";
2320 //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"';
2321 //Libellé manuel
2322 $tab[] = dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1);
2323 //Numéro de pièce
2324 $tab[] = dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1);
2325 //Devise
2326 $tab[] = 'EUR';
2327 //Amount
2328 $tab[] = price2num(abs($line->debit - $line->credit));
2329 //Sens
2330 $tab[] = $line->sens;
2331 //Code lettrage
2332 $tab[] = "";
2333 //Date Echéance
2334 $tab[] = $date_echeance;
2335
2336 $output = implode($separator, $tab).$end_line;
2337 if ($exportFile) {
2338 fwrite($exportFile, $output);
2339 } else {
2340 print $output;
2341 }
2342 }
2343 }
2344 }
2345
2353 public function exportGestimumV5($objectLines, $exportFile = null)
2354 {
2355
2356 $separator = ',';
2357 $end_line = "\r\n";
2358
2359 foreach ($objectLines as $line) {
2360 if ($line->debit == 0 && $line->credit == 0) {
2361 //unset($array[$line]);
2362 } else {
2363 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
2364
2365 $tab = array();
2366
2367 $tab[] = $line->id;
2368 $tab[] = $date_document;
2369 $tab[] = substr($line->code_journal, 0, 4);
2370 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
2371 $tab[] = length_accountg($line->subledger_account);
2372 } else {
2373 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2374 }
2375 $tab[] = "";
2376 $tab[] = '"'.dol_trunc(str_replace('"', '', $line->label_operation), 40, 'right', 'UTF-8', 1).'"';
2377 $tab[] = '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"';
2378 $tab[] = '"' . dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . '"';
2379 $tab[] = price2num(abs($line->debit - $line->credit));
2380 $tab[] = $line->sens;
2381 $tab[] = $date_document;
2382 $tab[] = "";
2383 $tab[] = "";
2384 $tab[] = 'EUR';
2385
2386 $output = implode($separator, $tab).$end_line;
2387 if ($exportFile) {
2388 fwrite($exportFile, $output);
2389 } else {
2390 print $output;
2391 }
2392 }
2393 }
2394 }
2395
2405 public function exportiSuiteExpert($objectLines, $exportFile = null)
2406 {
2407 $separator = ';';
2408 $end_line = "\r\n";
2409
2410
2411 foreach ($objectLines as $line) {
2412 $tab = array();
2413
2414 $date = dol_print_date($line->doc_date, '%d/%m/%Y');
2415
2416 $tab[] = $line->piece_num;
2417 $tab[] = $date;
2418 $tab[] = substr($date, 6, 4);
2419 $tab[] = substr($date, 3, 2);
2420 $tab[] = substr($date, 0, 2);
2421 $tab[] = $line->doc_ref;
2422 //Conversion de chaine UTF8 en Latin9
2423 $tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
2424
2425 //Calcul de la longueur des numéros de comptes
2426 $taille_numero = strlen(length_accountg($line->numero_compte));
2427
2428 //Création du numéro de client et fournisseur générique
2429 $numero_cpt_client = '411';
2430 $numero_cpt_fourn = '401';
2431 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2432 $numero_cpt_client .= '0';
2433 $numero_cpt_fourn .= '0';
2434 }
2435
2436 //Création des comptes auxiliaire des clients et fournisseur
2437 if (length_accountg($line->numero_compte) == $numero_cpt_client || length_accountg($line->numero_compte) == $numero_cpt_fourn) {
2438 $tab[] = rtrim(length_accounta($line->subledger_account), "0");
2439 } else {
2440 $tab[] = length_accountg($line->numero_compte);
2441 }
2442 $nom_client = explode(" - ", $line->label_operation);
2443 $tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
2444 $tab[] = price($line->debit);
2445 $tab[] = price($line->credit);
2446 $tab[] = price($line->montant);
2447 $tab[] = $line->code_journal;
2448
2449 $output = implode($separator, $tab).$end_line;
2450 if ($exportFile) {
2451 fwrite($exportFile, $output);
2452 } else {
2453 print $output;
2454 }
2455 }
2456 }
2457
2465 public static function trunc($str, $size)
2466 {
2467 return dol_trunc($str, $size, 'right', 'UTF-8', 1);
2468 }
2469
2477 public static function toAnsi($str, $size = -1)
2478 {
2479 $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
2480 if ($retVal >= 0 && $size >= 0) {
2481 $retVal = mb_substr($retVal, 0, $size, 'Windows-1251');
2482 }
2483 return $retVal;
2484 }
2485}
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...
exportAgiris($objectLines, $exportFile=null)
Export format : Agiris Isacompta.
exportFEC2($objectLines, $exportFile=null)
Export format : FEC2.
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...
exportFEC($objectLines, $exportFile=null)
Export format : FEC.
exportCharlemagne($objectLines, $exportFile=null)
Export format : Charlemagne.
getTypeConfig()
Array with all export type 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.
export(&$TData, $formatexportset, $withAttachment=0, $downloadMode=0, $outputMode=0)
Function who chose which export to use with the default config, and make the export into a file.
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 ...
static toAnsi($str, $size=-1)
toAnsi
getType()
Array with all export type available (key + label)
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=0, $outputlangs='', $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($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:62
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $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.
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.