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