dolibarr 22.0.5
accountancyexport.class.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
6 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7 * Copyright (C) 2016 Pierre-Henry Favre <phf@atm-consulting.fr>
8 * Copyright (C) 2016-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-2025 MDW <mdeweerd@users.noreply.github.com>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 3 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <https://www.gnu.org/licenses/>.
31 */
32
39require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
45
50{
51 // Types of export.
53 public static $EXPORT_TYPE_CONFIGURABLE = 1; // CSV
55 public static $EXPORT_TYPE_AGIRIS = 10;
57 public static $EXPORT_TYPE_EBP = 15;
59 public static $EXPORT_TYPE_CEGID = 20;
61 public static $EXPORT_TYPE_COGILOG = 25;
63 public static $EXPORT_TYPE_COALA = 30;
65 public static $EXPORT_TYPE_BOB50 = 35;
67 public static $EXPORT_TYPE_CIEL = 40;
69 public static $EXPORT_TYPE_SAGE50_SWISS = 45;
71 public static $EXPORT_TYPE_CHARLEMAGNE = 50;
73 public static $EXPORT_TYPE_QUADRATUS = 60;
75 public static $EXPORT_TYPE_WINFIC = 70;
77 public static $EXPORT_TYPE_OPENCONCERTO = 100;
79 public static $EXPORT_TYPE_LDCOMPTA = 110;
81 public static $EXPORT_TYPE_LDCOMPTA10 = 120;
83 public static $EXPORT_TYPE_GESTIMUMV3 = 130;
85 public static $EXPORT_TYPE_GESTIMUMV5 = 135;
87 public static $EXPORT_TYPE_ISUITEEXPERT = 200;
88 // Generic FEC after that
90 public static $EXPORT_TYPE_FEC = 1000;
92 public static $EXPORT_TYPE_FEC2 = 1010;
93
97 public $db;
98
102 public $errors = array();
103
107 public $separator = '';
108
112 public $end_line = '';
113
117 public $generatedfiledata = array();
118
119
125 public function __construct(DoliDB $db)
126 {
127 global $conf, $hookmanager;
128
129 $this->db = $db;
130 $this->separator = getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV');
131 $this->end_line = getDolGlobalString('ACCOUNTING_EXPORT_ENDLINE') ? (getDolGlobalInt('ACCOUNTING_EXPORT_ENDLINE') == 1 ? "\n" : "\r\n") : "\n";
132
133 $hookmanager->initHooks(array('accountancyexport'));
134 }
135
142 public function getType($mode = 0)
143 {
144 global $langs, $hookmanager;
145
146 $listofspecialformatexport = array(
147 self::$EXPORT_TYPE_CEGID => $langs->trans('Modelcsv_CEGID'),
148 self::$EXPORT_TYPE_COALA => $langs->trans('Modelcsv_COALA'),
149 self::$EXPORT_TYPE_BOB50 => $langs->trans('Modelcsv_bob50'),
150 self::$EXPORT_TYPE_CIEL => $langs->trans('Modelcsv_ciel'),
151 self::$EXPORT_TYPE_QUADRATUS => $langs->trans('Modelcsv_quadratus'),
152 self::$EXPORT_TYPE_WINFIC => $langs->trans('Modelcsv_winfic'),
153 self::$EXPORT_TYPE_EBP => $langs->trans('Modelcsv_ebp'),
154 self::$EXPORT_TYPE_COGILOG => $langs->trans('Modelcsv_cogilog'),
155 self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'),
156 self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans('Modelcsv_openconcerto'),
157 self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans('Modelcsv_Sage50_Swiss'),
158 self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans('Modelcsv_charlemagne'),
159 self::$EXPORT_TYPE_LDCOMPTA => $langs->trans('Modelcsv_LDCompta'),
160 self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans('Modelcsv_LDCompta10'),
161 self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans('Modelcsv_Gestinumv3'),
162 self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans('Modelcsv_Gestinumv5'),
163 self::$EXPORT_TYPE_ISUITEEXPERT => 'Export iSuite Expert',
164 );
165
166 $listofgenericformatexport = array(
167 self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans('Modelcsv_configurable'),
168 self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'),
169 self::$EXPORT_TYPE_FEC2 => $langs->trans('Modelcsv_FEC2'),
170 );
171
172 if (empty($mode)) {
173 $listofexporttypes = $listofgenericformatexport + $listofspecialformatexport;
174 ksort($listofexporttypes, SORT_NUMERIC);
175 } else {
176 ksort($listofspecialformatexport, SORT_NUMERIC);
177 $listofexporttypes = array();
178 $i = 0;
179 foreach ($listofgenericformatexport as $key => $val) {
180 $i++;
181 $listofexporttypes[$key] = array('id' => $key, 'label' => $val, 'position' => $i);
182 }
183 $listofexporttypes['separator_'.$i] = array('id' => 0, 'label' => '----------------', 'position' => $i, 'disabled' => 'disabled');
184 foreach ($listofspecialformatexport as $key => $val) {
185 $i++;
186 $listofexporttypes[$key] = array('id' => $key, 'label' => $val, 'position' => $i);
187 }
188 }
189
190 // allow modules to define export formats
191 $parameters = array();
192 $reshook = $hookmanager->executeHooks('getType', $parameters, $listofexporttypes);
193
194 return $listofexporttypes;
195 }
196
203 public static function getFormatCode($type)
204 {
205 $formatcode = array(
206 self::$EXPORT_TYPE_CONFIGURABLE => 'csv',
207 self::$EXPORT_TYPE_CEGID => 'cegid',
208 self::$EXPORT_TYPE_COALA => 'coala',
209 self::$EXPORT_TYPE_BOB50 => 'bob50',
210 self::$EXPORT_TYPE_CIEL => 'ciel',
211 self::$EXPORT_TYPE_QUADRATUS => 'quadratus',
212 self::$EXPORT_TYPE_WINFIC => 'winfic',
213 self::$EXPORT_TYPE_EBP => 'ebp',
214 self::$EXPORT_TYPE_COGILOG => 'cogilog',
215 self::$EXPORT_TYPE_AGIRIS => 'agiris',
216 self::$EXPORT_TYPE_OPENCONCERTO => 'openconcerto',
217 self::$EXPORT_TYPE_SAGE50_SWISS => 'sage50ch',
218 self::$EXPORT_TYPE_CHARLEMAGNE => 'charlemagne',
219 self::$EXPORT_TYPE_LDCOMPTA => 'ldcompta',
220 self::$EXPORT_TYPE_LDCOMPTA10 => 'ldcompta10',
221 self::$EXPORT_TYPE_GESTIMUMV3 => 'gestimumv3',
222 self::$EXPORT_TYPE_GESTIMUMV5 => 'gestimumv5',
223 self::$EXPORT_TYPE_FEC => 'fec',
224 self::$EXPORT_TYPE_FEC2 => 'fec2',
225 self::$EXPORT_TYPE_ISUITEEXPERT => 'isuiteexpert',
226 );
227
228 global $hookmanager;
229 $code = $formatcode[$type] ?? '';
230 $parameters = array('type' => $type);
231 $reshook = $hookmanager->executeHooks('getFormatCode', $parameters, $code);
232
233 return $code;
234 }
235
241 public function getTypeConfig()
242 {
243 global $langs;
244
245 $exporttypes = array(
246 'param' => array(
247 self::$EXPORT_TYPE_CONFIGURABLE => array(
248 'label' => $langs->trans('Modelcsv_configurable'),
249 'ACCOUNTING_EXPORT_FORMAT' => getDolGlobalString('ACCOUNTING_EXPORT_FORMAT', 'txt'),
250 'ACCOUNTING_EXPORT_SEPARATORCSV' => getDolGlobalString('ACCOUNTING_EXPORT_SEPARATORCSV', ','),
251 'ACCOUNTING_EXPORT_ENDLINE' => getDolGlobalString('ACCOUNTING_EXPORT_ENDLINE', 1),
252 'ACCOUNTING_EXPORT_DATE' => getDolGlobalString('ACCOUNTING_EXPORT_DATE', '%Y-%m-%d'),
253 ),
254 self::$EXPORT_TYPE_CEGID => array(
255 'label' => $langs->trans('Modelcsv_CEGID'),
256 ),
257 self::$EXPORT_TYPE_COALA => array(
258 'label' => $langs->trans('Modelcsv_COALA'),
259 ),
260 self::$EXPORT_TYPE_BOB50 => array(
261 'label' => $langs->trans('Modelcsv_bob50'),
262 ),
263 self::$EXPORT_TYPE_CIEL => array(
264 'label' => $langs->trans('Modelcsv_ciel'),
265 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
266 ),
267 self::$EXPORT_TYPE_QUADRATUS => array(
268 'label' => $langs->trans('Modelcsv_quadratus'),
269 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
270 ),
271 self::$EXPORT_TYPE_WINFIC => array(
272 'label' => $langs->trans('Modelcsv_winfic'),
273 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
274 ),
275 self::$EXPORT_TYPE_EBP => array(
276 'label' => $langs->trans('Modelcsv_ebp'),
277 ),
278 self::$EXPORT_TYPE_COGILOG => array(
279 'label' => $langs->trans('Modelcsv_cogilog'),
280 ),
281 self::$EXPORT_TYPE_AGIRIS => array(
282 'label' => $langs->trans('Modelcsv_agiris'),
283 ),
284 self::$EXPORT_TYPE_OPENCONCERTO => array(
285 'label' => $langs->trans('Modelcsv_openconcerto'),
286 ),
287 self::$EXPORT_TYPE_SAGE50_SWISS => array(
288 'label' => $langs->trans('Modelcsv_Sage50_Swiss'),
289 ),
290 self::$EXPORT_TYPE_CHARLEMAGNE => array(
291 'label' => $langs->trans('Modelcsv_charlemagne'),
292 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
293 ),
294 self::$EXPORT_TYPE_LDCOMPTA => array(
295 'label' => $langs->trans('Modelcsv_LDCompta'),
296 ),
297 self::$EXPORT_TYPE_LDCOMPTA10 => array(
298 'label' => $langs->trans('Modelcsv_LDCompta10'),
299 ),
300 self::$EXPORT_TYPE_GESTIMUMV3 => array(
301 'label' => $langs->trans('Modelcsv_Gestinumv3'),
302 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
303 ),
304 self::$EXPORT_TYPE_GESTIMUMV5 => array(
305 'label' => $langs->trans('Modelcsv_Gestinumv5'),
306 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
307 ),
308 self::$EXPORT_TYPE_FEC => array(
309 'label' => $langs->trans('Modelcsv_FEC'),
310 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
311 ),
312 self::$EXPORT_TYPE_FEC2 => array(
313 'label' => $langs->trans('Modelcsv_FEC2'),
314 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
315 ),
316 self::$EXPORT_TYPE_ISUITEEXPERT => array(
317 'label' => 'iSuite Expert',
318 'ACCOUNTING_EXPORT_FORMAT' => 'csv',
319 ),
320 ),
321 'cr' => array(
322 '1' => $langs->trans("Unix"),
323 '2' => $langs->trans("Windows")
324 ),
325 'format' => array(
326 'csv' => $langs->trans("csv"),
327 'txt' => $langs->trans("txt")
328 ),
329 );
330
331 global $hookmanager;
332 $parameters = array();
333 $reshook = $hookmanager->executeHooks('getTypeConfig', $parameters, $exporttypes);
334 return $exporttypes;
335 }
336
337
344 public function getMimeType($formatexportset)
345 {
346 switch ($formatexportset) {
347 case self::$EXPORT_TYPE_FEC:
348 $mime = 'text/tab-separated-values';
349 break;
350 default:
351 $mime = 'text/csv';
352 break;
353 }
354
355 return $mime;
356 }
357
375 public function export(&$TData, $formatexportset, $withAttachment = 0, $downloadMode = 1, $outputMode = 1, $noouput = 1)
376 {
377 global $db, $conf, $langs; // The tpl file use $db
378 global $search_date_end; // Used into /accountancy/tpl/export_journal.tpl.php
379
380 // Define name of file to save
381 $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, 'exportFile' => $exportFile);
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((string) $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((string) $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((string) $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((string) $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 $output = implode('|', $tab);
1176 if ($exportFile) {
1177 fwrite($exportFile, $output);
1178 } else {
1179 print $output;
1180 }
1181
1182 $index++;
1183 }
1184 }
1185
1186
1194 public function exportEbp($objectLines, $exportFile = null)
1195 {
1196 $separator = ',';
1197 $end_line = "\n";
1198
1199 foreach ($objectLines as $line) {
1200 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
1201
1202 $tab = array();
1203
1204 $tab[] = $line->id;
1205 $tab[] = $date_document;
1206 $tab[] = $line->code_journal;
1207 if (empty($line->subledger_account)) {
1208 $tab[] = $line->numero_compte;
1209 } else {
1210 $tab[] = $line->subledger_account;
1211 }
1212 //$tab[] = substr(length_accountg($line->numero_compte), 0, 2) . $separator;
1213 $tab[] = '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"';
1214 $tab[] = '"'.dol_trunc((string) $line->piece_num, 15, 'right', 'UTF-8', 1).'"';
1215 $tab[] = price2num(abs($line->debit - $line->credit));
1216 $tab[] = $line->sens;
1217 $tab[] = $date_document;
1218 //print 'EUR';
1219
1220 $output = implode($separator, $tab).$end_line;
1221 if ($exportFile) {
1222 fwrite($exportFile, $output);
1223 } else {
1224 print $output;
1225 }
1226 }
1227 }
1228
1229
1237 public function exportAgiris($objectLines, $exportFile = null)
1238 {
1239 $separator = ';';
1240 $end_line = "\n";
1241
1242 foreach ($objectLines as $line) {
1243 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
1244
1245 $tab = array();
1246
1247 $tab[] = $line->piece_num;
1248 $tab[] = self::toAnsi($line->label_operation);
1249 $tab[] = $date_document;
1250 $tab[] = self::toAnsi($line->label_operation);
1251
1252 if (empty($line->subledger_account)) {
1253 $tab[] = length_accountg($line->numero_compte);
1254 $tab[] = self::toAnsi($line->label_compte);
1255 } else {
1256 $tab[] = length_accounta($line->subledger_account);
1257 $tab[] = self::toAnsi($line->subledger_label);
1258 }
1259
1260 $tab[] = self::toAnsi($line->doc_ref);
1261 $tab[] = price($line->debit);
1262 $tab[] = price($line->credit);
1263 $tab[] = price(abs($line->debit - $line->credit));
1264 $tab[] = $line->sens;
1265 $tab[] = $line->lettering_code;
1266 $tab[] = $line->code_journal;
1267
1268 $output = implode($separator, $tab).$end_line;
1269 if ($exportFile) {
1270 fwrite($exportFile, $output);
1271 } else {
1272 print $output;
1273 }
1274 }
1275 }
1276
1284 public function exportOpenConcerto($objectLines, $exportFile = null)
1285 {
1286 $separator = ';';
1287 $end_line = "\n";
1288
1289 foreach ($objectLines as $line) {
1290 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
1291
1292 $tab = array();
1293
1294 $tab[] = $date_document;
1295 $tab[] = $line->code_journal;
1296 if (empty($line->subledger_account)) {
1297 $tab[] = length_accountg($line->numero_compte);
1298 } else {
1299 $tab[] = length_accounta($line->subledger_account);
1300 }
1301 $tab[] = $line->doc_ref;
1302 $tab[] = $line->label_operation;
1303 $tab[] = price($line->debit);
1304 $tab[] = price($line->credit);
1305
1306 $output = implode($separator, $tab).$end_line;
1307 if ($exportFile) {
1308 fwrite($exportFile, $output);
1309 } else {
1310 print $output;
1311 }
1312 }
1313 }
1314
1322 public function exportConfigurable($objectLines, $exportFile = null)
1323 {
1324 global $conf;
1325
1326 $separator = $this->separator;
1327
1328 foreach ($objectLines as $line) {
1329 $date_document = dol_print_date($line->doc_date, getDolGlobalString('ACCOUNTING_EXPORT_DATE'));
1330
1331 $tab = array();
1332 // export configurable
1333 $tab[] = $line->piece_num;
1334 $tab[] = $date_document;
1335 $tab[] = $line->doc_ref;
1336 $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
1337 $tab[] = length_accountg($line->numero_compte);
1338 $tab[] = length_accounta($line->subledger_account);
1339 $tab[] = price2num($line->debit);
1340 $tab[] = price2num($line->credit);
1341 $tab[] = price2num($line->debit - $line->credit);
1342 $tab[] = $line->code_journal;
1343
1344 $output = implode($separator, $tab).$this->end_line;
1345 if ($exportFile) {
1346 fwrite($exportFile, $output);
1347 } else {
1348 print $output;
1349 }
1350 }
1351 }
1352
1365 public function exportFEC($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
1366 {
1367 global $conf, $langs;
1368
1369 $separator = "\t";
1370 $end_line = "\r\n";
1371
1372 $tab = array();
1373 $tab[] = "JournalCode";
1374 $tab[] = "JournalLib";
1375 $tab[] = "EcritureNum";
1376 $tab[] = "EcritureDate";
1377 $tab[] = "CompteNum";
1378 $tab[] = "CompteLib";
1379 $tab[] = "CompAuxNum";
1380 $tab[] = "CompAuxLib";
1381 $tab[] = "PieceRef";
1382 $tab[] = "PieceDate";
1383 $tab[] = "EcritureLib";
1384 $tab[] = "Debit";
1385 $tab[] = "Credit";
1386 $tab[] = "EcritureLet";
1387 $tab[] = "DateLet";
1388 $tab[] = "ValidDate";
1389 $tab[] = "Montantdevise";
1390 $tab[] = "Idevise";
1391 $tab[] = "DateLimitReglmt";
1392 $tab[] = "NumFacture";
1393 $tab[] = "FichierFacture";
1394
1395 $output = implode($separator, $tab).$end_line;
1396 if ($exportFile) {
1397 fwrite($exportFile, $output);
1398 } else {
1399 print $output;
1400 }
1401
1402 foreach ($objectLines as $line) {
1403 if ($line->debit == 0 && $line->credit == 0) {
1404 //var_dump($line->id);
1405 //unset($array[$line]);
1406 } else {
1407 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1408 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1409 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1410 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1411 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1412
1413 $refInvoice = '';
1414 if ($line->doc_type == 'customer_invoice') {
1415 // Customer invoice
1416 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1417 $invoice = new Facture($this->db);
1418 $invoice->fetch($line->fk_doc);
1419
1420 $refInvoice = $invoice->ref;
1421 } elseif ($line->doc_type == 'supplier_invoice') {
1422 // Supplier invoice
1423 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1424 $invoice = new FactureFournisseur($this->db);
1425 $invoice->fetch($line->fk_doc);
1426
1427 $refInvoice = $invoice->ref_supplier;
1428 }
1429
1430 $tab = array();
1431
1432 // FEC:JournalCode
1433 $tab[] = $line->code_journal;
1434
1435 // FEC:JournalLib
1436 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1437 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1438 $tab[] = $labeljournal;
1439
1440 // FEC:EcritureNum
1441 $tab[] = $line->piece_num;
1442
1443 // FEC:EcritureDate
1444 $tab[] = $date_document;
1445
1446 // FEC:CompteNum
1447 $tab[] = length_accountg($line->numero_compte);
1448
1449 // FEC:CompteLib
1450 $tab[] = dol_string_unaccent($line->label_compte);
1451
1452 // FEC:CompAuxNum
1453 $tab[] = length_accounta($line->subledger_account);
1454
1455 // FEC:CompAuxLib
1456 $tab[] = dol_string_unaccent($line->subledger_label);
1457
1458 // FEC:PieceRef
1459 $tab[] = $line->doc_ref;
1460
1461 // FEC:PieceDate
1462 $tab[] = dol_string_unaccent($date_creation);
1463
1464 // FEC:EcritureLib
1465 // Clean label operation to prevent problem on export with tab separator & other character
1466 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1467 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1468 $tab[] = dol_string_unaccent($line->label_operation);
1469
1470 // FEC:Debit
1471 $tab[] = price2fec($line->debit);
1472
1473 // FEC:Credit
1474 $tab[] = price2fec($line->credit);
1475
1476 // FEC:EcritureLet
1477 $tab[] = $line->lettering_code;
1478
1479 // FEC:DateLet
1480 $tab[] = $date_lettering;
1481
1482 // FEC:ValidDate
1483 $tab[] = $date_validation;
1484
1485 // FEC:Montantdevise
1486 $tab[] = $line->multicurrency_amount;
1487
1488 // FEC:Idevise
1489 $tab[] = $line->multicurrency_code;
1490
1491 // FEC_suppl:DateLimitReglmt
1492 $tab[] = $date_limit_payment;
1493
1494 // FEC_suppl:NumFacture
1495 // Clean ref invoice to prevent problem on export with tab separator & other character
1496 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1497 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1498
1499 // FEC_suppl:FichierFacture
1500 // get document file
1501 $attachmentFileName = '';
1502 if ($withAttachment == 1) {
1503 $attachmentFileKey = trim((string) $line->piece_num);
1504
1505 if (!isset($archiveFileList[$attachmentFileKey])) {
1506 $objectDirPath = '';
1507 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1508 if ($line->doc_type == 'customer_invoice') {
1509 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1510 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1511 }
1512 } elseif ($line->doc_type == 'expense_report') {
1513 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1514 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1515 }
1516 } elseif ($line->doc_type == 'supplier_invoice') {
1517 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1518 '@phan-var-force FactureFournisseur $invoice';
1520 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1521 $objectDirPath .= '/' . rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1522 }
1523 }
1524 $arrayofinclusion = array();
1525 // If it is a supplier invoice, we want to use last uploaded file
1526 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1527 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1528 if (!empty($fileFoundList)) {
1529 $attachmentFileNameTrunc = $line->doc_ref;
1530 foreach ($fileFoundList as $fileFound) {
1531 if (strstr($fileFound['name'], $objectFileName)) {
1532 // skip native invoice pdfs (canelle)
1533 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1534 if ($line->doc_type == 'supplier_invoice') {
1535 if ($fileFound['name'] === $objectFileName.'.pdf') {
1536 continue;
1537 }
1538 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1539 continue;
1540 }
1541 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1542 if (file_exists($fileFoundPath)) {
1543 $archiveFileList[$attachmentFileKey] = array(
1544 'path' => $fileFoundPath,
1545 'name' => $attachmentFileNameTrunc.'.pdf',
1546 );
1547 break;
1548 }
1549 }
1550 }
1551 }
1552 }
1553
1554 if (isset($archiveFileList[$attachmentFileKey])) {
1555 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1556 }
1557 }
1558
1559 $tab[] = $attachmentFileName;
1560
1561 $output = implode($separator, $tab).$end_line;
1562
1563 if ($exportFile) {
1564 fwrite($exportFile, $output);
1565 } else {
1566 print $output;
1567 }
1568 }
1569 }
1570
1571 return $archiveFileList;
1572 }
1573
1586 public function exportFEC2($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
1587 {
1588 global $conf, $langs;
1589
1590 $separator = "\t";
1591 $end_line = "\r\n";
1592
1593 $tab = array();
1594 $tab[] = "JournalCode";
1595 $tab[] = "JournalLib";
1596 $tab[] = "EcritureNum";
1597 $tab[] = "EcritureDate";
1598 $tab[] = "CompteNum";
1599 $tab[] = "CompteLib";
1600 $tab[] = "CompAuxNum";
1601 $tab[] = "CompAuxLib";
1602 $tab[] = "PieceRef";
1603 $tab[] = "PieceDate";
1604 $tab[] = "EcritureLib";
1605 $tab[] = "Debit";
1606 $tab[] = "Credit";
1607 $tab[] = "EcritureLet";
1608 $tab[] = "DateLet";
1609 $tab[] = "ValidDate";
1610 $tab[] = "Montantdevise";
1611 $tab[] = "Idevise";
1612 $tab[] = "DateLimitReglmt";
1613 $tab[] = "NumFacture";
1614 $tab[] = "FichierFacture";
1615
1616 $output = implode($separator, $tab).$end_line;
1617 if ($exportFile) {
1618 fwrite($exportFile, $output);
1619 } else {
1620 print $output;
1621 }
1622
1623 foreach ($objectLines as $line) {
1624 if ($line->debit == 0 && $line->credit == 0) {
1625 //unset($array[$line]);
1626 } else {
1627 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1628 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1629 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1630 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1631 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1632
1633 $refInvoice = '';
1634 if ($line->doc_type == 'customer_invoice') {
1635 // Customer invoice
1636 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1637 $invoice = new Facture($this->db);
1638 $invoice->fetch($line->fk_doc);
1639
1640 $refInvoice = $invoice->ref;
1641 } elseif ($line->doc_type == 'supplier_invoice') {
1642 // Supplier invoice
1643 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1644 $invoice = new FactureFournisseur($this->db);
1645 $invoice->fetch($line->fk_doc);
1646
1647 $refInvoice = $invoice->ref_supplier;
1648 }
1649
1650 $tab = array();
1651
1652 // FEC:JournalCode
1653 $tab[] = $line->code_journal;
1654
1655 // FEC:JournalLib
1656 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1657 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1658 $tab[] = $labeljournal;
1659
1660 // FEC:EcritureNum
1661 $tab[] = $line->piece_num;
1662
1663 // FEC:EcritureDate
1664 $tab[] = $date_creation;
1665
1666 // FEC:CompteNum
1667 $tab[] = length_accountg($line->numero_compte);
1668
1669 // FEC:CompteLib
1670 $tab[] = dol_string_unaccent($line->label_compte);
1671
1672 // FEC:CompAuxNum
1673 $tab[] = length_accounta($line->subledger_account);
1674
1675 // FEC:CompAuxLib
1676 $tab[] = dol_string_unaccent($line->subledger_label);
1677
1678 // FEC:PieceRef
1679 $tab[] = $line->doc_ref;
1680
1681 // FEC:PieceDate
1682 $tab[] = $date_document;
1683
1684 // FEC:EcritureLib
1685 // Clean label operation to prevent problem on export with tab separator & other character
1686 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1687 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1688 $tab[] = dol_string_unaccent($line->label_operation);
1689
1690 // FEC:Debit
1691 $tab[] = price2fec($line->debit);
1692
1693 // FEC:Credit
1694 $tab[] = price2fec($line->credit);
1695
1696 // FEC:EcritureLet
1697 $tab[] = $line->lettering_code;
1698
1699 // FEC:DateLet
1700 $tab[] = $date_lettering;
1701
1702 // FEC:ValidDate
1703 $tab[] = $date_validation;
1704
1705 // FEC:Montantdevise
1706 $tab[] = $line->multicurrency_amount;
1707
1708 // FEC:Idevise
1709 $tab[] = $line->multicurrency_code;
1710
1711 // FEC_suppl:DateLimitReglmt
1712 $tab[] = $date_limit_payment;
1713
1714 // FEC_suppl:NumFacture
1715 // Clean ref invoice to prevent problem on export with tab separator & other character
1716 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1717 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1718
1719 // FEC_suppl:FichierFacture
1720 // get document file
1721 $attachmentFileName = '';
1722 if ($withAttachment == 1) {
1723 $attachmentFileKey = trim((string) $line->piece_num);
1724
1725 if (!isset($archiveFileList[$attachmentFileKey])) {
1726 $objectDirPath = '';
1727 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1728 if ($line->doc_type == 'customer_invoice') {
1729 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1730 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1731 }
1732 } elseif ($line->doc_type == 'expense_report') {
1733 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1734 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1735 }
1736 } elseif ($line->doc_type == 'supplier_invoice') {
1737 if (!getDolGlobalInt('ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1738 '@phan-var-force FactureFournisseur $invoice';
1740 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1741 $objectDirPath .= '/' . rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1742 }
1743 }
1744 $arrayofinclusion = array();
1745 // If it is a supplier invoice, we want to use last uploaded file
1746 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1747 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1748 if (!empty($fileFoundList)) {
1749 $attachmentFileNameTrunc = $line->doc_ref;
1750 foreach ($fileFoundList as $fileFound) {
1751 if (strstr($fileFound['name'], $objectFileName)) {
1752 // skip native invoice pdfs (canelle)
1753 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1754 if ($line->doc_type == 'supplier_invoice') {
1755 if ($fileFound['name'] === $objectFileName.'.pdf') {
1756 continue;
1757 }
1758 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1759 continue;
1760 }
1761 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1762 if (file_exists($fileFoundPath)) {
1763 $archiveFileList[$attachmentFileKey] = array(
1764 'path' => $fileFoundPath,
1765 'name' => $attachmentFileNameTrunc.'.pdf',
1766 );
1767 break;
1768 }
1769 }
1770 }
1771 }
1772 }
1773
1774 if (isset($archiveFileList[$attachmentFileKey])) {
1775 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1776 }
1777 }
1778
1779 $tab[] = $attachmentFileName;
1780
1781 $output = implode($separator, $tab).$end_line;
1782 if ($exportFile) {
1783 fwrite($exportFile, $output);
1784 } else {
1785 print $output;
1786 }
1787 }
1788 }
1789
1790 return $archiveFileList;
1791 }
1792
1803 public function exportSAGE50SWISS($objectLines, $exportFile = null)
1804 {
1805 // SAGE50SWISS
1806 $separator = ',';
1807 $end_line = "\r\n";
1808
1809 // Print header line
1810 $tab = array();
1811
1812 $tab[] = "Blg";
1813 $tab[] = "Datum";
1814 $tab[] = "Kto";
1815 $tab[] = "S/H";
1816 $tab[] = "Grp";
1817 $tab[] = "GKto";
1818 $tab[] = "SId";
1819 $tab[] = "SIdx";
1820 $tab[] = "KIdx";
1821 $tab[] = "BTyp";
1822 $tab[] = "MTyp";
1823 $tab[] = "Code";
1824 $tab[] = "Netto";
1825 $tab[] = "Steuer";
1826 $tab[] = "FW-Betrag";
1827 $tab[] = "Tx1";
1828 $tab[] = "Tx2";
1829 $tab[] = "PkKey";
1830 $tab[] = "OpId";
1831 $tab[] = "Flag";
1832
1833 $output = implode($separator, $tab).$end_line;
1834 if ($exportFile) {
1835 fwrite($exportFile, $output);
1836 } else {
1837 print $output;
1838 }
1839
1840 $thisPieceNum = "";
1841 $thisPieceAccountNr = "";
1842 $aSize = count($objectLines);
1843 foreach ($objectLines as $aIndex => $line) {
1844 $sammelBuchung = false;
1845 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1846 $sammelBuchung = true;
1847 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1848 $sammelBuchung = true;
1849 } elseif ($aIndex + 1 < $aSize
1850 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1851 && $aIndex - 1 < $aSize
1852 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1853 ) {
1854 $sammelBuchung = true;
1855 }
1856
1857 $tab = array();
1858
1859 //Blg
1860 $tab[] = $line->piece_num;
1861
1862 // Datum
1863 $date_document = dol_print_date($line->doc_date, '%d.%m.%Y');
1864 $tab[] = $date_document;
1865
1866 // Kto
1867 $tab[] = length_accountg($line->numero_compte);
1868 // S/H
1869 if ($line->sens == 'D') {
1870 $tab[] = 'S';
1871 } else {
1872 $tab[] = 'H';
1873 }
1874 // Grp
1875 $tab[] = self::trunc($line->code_journal, 1);
1876 // GKto
1877 if (empty($line->code_tiers)) {
1878 if ($line->piece_num == $thisPieceNum) {
1879 $tab[] = length_accounta($thisPieceAccountNr);
1880 } else {
1881 $tab[] = "div";
1882 }
1883 } else {
1884 $tab[] = length_accounta($line->code_tiers);
1885 }
1886 // SId
1887 $tab[] = $this->separator;
1888 // SIdx
1889 $tab[] = "0";
1890 // KIdx
1891 $tab[] = "0";
1892 // BTyp
1893 $tab[] = "0";
1894
1895 // MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
1896 if ($sammelBuchung) {
1897 $tab[] = "2";
1898 } else {
1899 $tab[] = "1";
1900 }
1901 // Code
1902 $tab[] = '""';
1903 // Netto
1904 $tab[] = abs($line->debit - $line->credit);
1905 // Steuer
1906 $tab[] = "0.00";
1907 // FW-Betrag
1908 $tab[] = "0.00";
1909 // Tx1
1910 $line1 = self::toAnsi($line->label_compte, 29);
1911 if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
1912 $line1 = "";
1913 }
1914 $line2 = self::toAnsi($line->doc_ref, 29);
1915 if (strlen($line1) == 0) {
1916 $line1 = $line2;
1917 $line2 = "";
1918 }
1919 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1920 $line1 = $line1.' / '.$line2;
1921 $line2 = "";
1922 }
1923
1924 $tab[] = '"'.self::toAnsi($line1).'"';
1925 // Tx2
1926 $tab[] = '"'.self::toAnsi($line2).'"';
1927 //PkKey
1928 $tab[] = "0";
1929 //OpId
1930 $tab[] = $this->separator;
1931
1932 // Flag
1933 $tab[] = "0";
1934
1935 $output = implode($separator, $tab).$end_line;
1936 if ($exportFile) {
1937 fwrite($exportFile, $output);
1938 } else {
1939 print $output;
1940 }
1941
1942 if ($line->piece_num !== $thisPieceNum) {
1943 $thisPieceNum = $line->piece_num;
1944 $thisPieceAccountNr = $line->numero_compte;
1945 }
1946 }
1947 }
1948
1957 public function exportLDCompta($objectLines, $exportFile = null)
1958 {
1959 $separator = ';';
1960 $end_line = "\r\n";
1961
1962 foreach ($objectLines as $line) {
1963 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1964 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1965 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1966
1967 $tab = array();
1968
1969 // TYPE
1970 $type_enregistrement = 'E'; // For write movement
1971 $tab[] = $type_enregistrement;
1972 // JNAL
1973 $tab[] = substr($line->code_journal, 0, 2);
1974 // NECR
1975 $tab[] = $line->id;
1976 // NPIE
1977 $tab[] = $line->piece_num;
1978 // DATP
1979 $tab[] = $date_document;
1980 // LIBE
1981 $tab[] = $line->label_operation;
1982 // DATH
1983 $tab[] = $date_lim_reglement;
1984 // CNPI
1985 if ($line->doc_type == 'supplier_invoice') {
1986 if (($line->debit - $line->credit) > 0) {
1987 $nature_piece = 'AF';
1988 } else {
1989 $nature_piece = 'FF';
1990 }
1991 } elseif ($line->doc_type == 'customer_invoice') {
1992 if (($line->debit - $line->credit) < 0) {
1993 $nature_piece = 'AC';
1994 } else {
1995 $nature_piece = 'FC';
1996 }
1997 } else {
1998 $nature_piece = '';
1999 }
2000 $tab[] = $nature_piece;
2001 // RACI
2002 // if (!empty($line->subledger_account)) {
2003 // if ($line->doc_type == 'supplier_invoice') {
2004 // $racine_subledger_account = '40';
2005 // } elseif ($line->doc_type == 'customer_invoice') {
2006 // $racine_subledger_account = '41';
2007 // } else {
2008 // $racine_subledger_account = '';
2009 // }
2010 // } else {
2011 $racine_subledger_account = ''; // for records of type E leave this field blank
2012 // }
2013
2014 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2015 // MONT
2016 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2, 2);
2017 // CODC
2018 $tab[] = $line->sens;
2019 // CPTG
2020 $tab[] = length_accountg($line->numero_compte);
2021 // DATE
2022 $tab[] = $date_creation;
2023 // CLET
2024 $tab[] = $line->lettering_code;
2025 // DATL
2026 $tab[] = $line->date_lettering;
2027 // CPTA
2028 if (!empty($line->subledger_account)) {
2029 $tab[] = length_accounta($line->subledger_account);
2030 } else {
2031 $tab[] = "";
2032 }
2033 // C.N.A.T
2034 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2035 $tab[] = 'F';
2036 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2037 $tab[] = 'C';
2038 } else {
2039 $tab[] = "";
2040 }
2041 // SECT
2042 $tab[] = "";
2043 // CTRE
2044 $tab[] = "";
2045 // NORL
2046 $tab[] = "";
2047 // DATV
2048 $tab[] = "";
2049 // REFD
2050 $tab[] = $line->doc_ref;
2051 // CODH
2052 $tab[] = "";
2053 // NSEQ
2054 $tab[] = "";
2055 // MTDV
2056 $tab[] = '0';
2057 // CODV
2058 $tab[] = "";
2059 // TXDV
2060 $tab[] = '0';
2061 // MOPM
2062 $tab[] = "";
2063 // BONP
2064 $tab[] = "";
2065 // BQAF
2066 $tab[] = "";
2067 // ECES
2068 $tab[] = "";
2069 // TXTL
2070 $tab[] = "";
2071 // ECRM
2072 $tab[] = "";
2073 // DATK
2074 $tab[] = "";
2075 // HEUK
2076 $tab[] = "";
2077
2078 $output = implode($separator, $tab).$end_line;
2079 if ($exportFile) {
2080 fwrite($exportFile, $output);
2081 } else {
2082 print $output;
2083 }
2084 }
2085 }
2086
2097 public function exportLDCompta10($objectLines, $exportFile = null)
2098 {
2099 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
2100
2101 $separator = ';';
2102 $end_line = "\r\n";
2103 $last_codeinvoice = '';
2104
2105 foreach ($objectLines as $line) {
2106 // TYPE C
2107 if ($last_codeinvoice != $line->doc_ref) {
2108 //recherche societe en fonction de son code client
2109 $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
2110 $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
2111 $resql = $this->db->query($sql);
2112
2113 if ($resql && $this->db->num_rows($resql) > 0) {
2114 $soc = $this->db->fetch_object($resql);
2115
2116 $address = array('', '', '');
2117 if (strpos($soc->address, "\n") !== false) {
2118 $address = explode("\n", $soc->address);
2119 if (is_array($address) && count($address) > 0) {
2120 foreach ($address as $key => $data) {
2121 $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
2122 $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
2123 }
2124 }
2125 } else {
2126 $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
2127 $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
2128 $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
2129 }
2130
2131 $tab = array();
2132
2133 $type_enregistrement = 'C';
2134 //TYPE
2135 $tab[] = $type_enregistrement;
2136 //NOCL
2137 $tab[] = $soc->code_client;
2138 //NMCM
2139 $tab[] = "";
2140 //LIBI
2141 $tab[] = "";
2142 //TITR
2143 $tab[] = "";
2144 //RSSO
2145 $tab[] = $soc->nom;
2146 //CAD1
2147 $tab[] = $address[0];
2148 //CAD2
2149 $tab[] = $address[1];
2150 //CAD3
2151 $tab[] = $address[2];
2152 //COPO
2153 $tab[] = $soc->zip;
2154 //BUDI
2155 $tab[] = substr($soc->town, 0, 40);
2156 //CPAY
2157 $tab[] = "";
2158 //PAYS
2159 $tab[] = substr(getCountry($soc->fk_pays), 0, 40);
2160 //NTEL
2161 $tab[] = $soc->phone;
2162 //TLEX
2163 $tab[] = "";
2164 //TLPO
2165 $tab[] = "";
2166 //TLCY
2167 $tab[] = "";
2168 //NINT
2169 $tab[] = "";
2170 //COMM
2171 $tab[] = "";
2172 //SIRE
2173 $tab[] = str_replace(" ", "", $soc->siret);
2174 //RIBP
2175 $tab[] = "";
2176 //DOBQ
2177 $tab[] = "";
2178 //IBBQ
2179 $tab[] = "";
2180 //COBQ
2181 $tab[] = "";
2182 //GUBQ
2183 $tab[] = "";
2184 //CPBQ
2185 $tab[] = "";
2186 //CLBQ
2187 $tab[] = "";
2188 //BIBQ
2189 $tab[] = "";
2190 //MOPM
2191 $tab[] = "";
2192 //DJPM
2193 $tab[] = "";
2194 //DMPM
2195 $tab[] = "";
2196 //REFM
2197 $tab[] = "";
2198 //SLVA
2199 $tab[] = "";
2200 //PLCR
2201 $tab[] = "";
2202 //ECFI
2203 $tab[] = "";
2204 //CREP
2205 $tab[] = "";
2206 //NREP
2207 $tab[] = "";
2208 //TREP
2209 $tab[] = "";
2210 //MREP
2211 $tab[] = "";
2212 //GRRE
2213 $tab[] = "";
2214 //LTTA
2215 $tab[] = "";
2216 //CACT
2217 $tab[] = "";
2218 //CODV
2219 $tab[] = "";
2220 //GRTR
2221 $tab[] = "";
2222 //NOFP
2223 $tab[] = "";
2224 //BQAF
2225 $tab[] = "";
2226 //BONP
2227 $tab[] = "";
2228 //CESC
2229 $tab[] = "";
2230
2231 $output = implode($separator, $tab).$end_line;
2232 if ($exportFile) {
2233 fwrite($exportFile, $output);
2234 } else {
2235 print $output;
2236 }
2237 }
2238 }
2239
2240 $tab = array();
2241
2242 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2243 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
2244 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2245
2246 // TYPE E
2247 $type_enregistrement = 'E'; // For write movement
2248 $tab[] = $type_enregistrement;
2249 // JNAL
2250 $tab[] = substr($line->code_journal, 0, 2);
2251 // NECR
2252 $tab[] = $line->id;
2253 // NPIE
2254 $tab[] = $line->piece_num;
2255 // DATP
2256 $tab[] = $date_document;
2257 // LIBE
2258 $tab[] = dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1);
2259 // DATH
2260 $tab[] = $date_lim_reglement;
2261 // CNPI
2262 if ($line->doc_type == 'supplier_invoice') {
2263 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.
2264 $nature_piece = 'AF';
2265 } else {
2266 $nature_piece = 'FF';
2267 }
2268 } elseif ($line->doc_type == 'customer_invoice') {
2269 if (($line->amount) < 0) {
2270 $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.
2271 } else {
2272 $nature_piece = 'FC';
2273 }
2274 } else {
2275 $nature_piece = '';
2276 }
2277 $tab[] = $nature_piece;
2278 // RACI
2279 // if (!empty($line->subledger_account)) {
2280 // if ($line->doc_type == 'supplier_invoice') {
2281 // $racine_subledger_account = '40';
2282 // } elseif ($line->doc_type == 'customer_invoice') {
2283 // $racine_subledger_account = '41';
2284 // } else {
2285 // $racine_subledger_account = '';
2286 // }
2287 // } else {
2288 $racine_subledger_account = ''; // for records of type E leave this field blank
2289 // }
2290
2291 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2292 // MONT
2293 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2);
2294 // CODC
2295 $tab[] = $line->sens;
2296 // CPTG
2297 $tab[] = length_accountg($line->numero_compte);
2298 // DATE
2299 $tab[] = $date_document;
2300 // CLET
2301 $tab[] = $line->lettering_code;
2302 // DATL
2303 $tab[] = $line->date_lettering;
2304 // CPTA
2305 if (!empty($line->subledger_account)) {
2306 $tab[] = length_accounta($line->subledger_account);
2307 } else {
2308 $tab[] = "";
2309 }
2310 // C.N.A.T
2311 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2312 $tab[] = 'F';
2313 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2314 $tab[] = 'C';
2315 } else {
2316 $tab[] = "";
2317 }
2318 // CTRE
2319 $tab[] = "";
2320 // NORL
2321 $tab[] = "";
2322 // DATV
2323 $tab[] = "";
2324 // REFD
2325 $tab[] = $line->doc_ref;
2326 // NECA
2327 $tab[] = '0';
2328 // CSEC
2329 $tab[] = "";
2330 // CAFF
2331 $tab[] = "";
2332 // CDES
2333 $tab[] = "";
2334 // QTUE
2335 $tab[] = "";
2336 // MTDV
2337 $tab[] = '0';
2338 // CODV
2339 $tab[] = "";
2340 // TXDV
2341 $tab[] = '0';
2342 // MOPM
2343 $tab[] = "";
2344 // BONP
2345 $tab[] = "";
2346 // BQAF
2347 $tab[] = "";
2348 // ECES
2349 $tab[] = "";
2350 // TXTL
2351 $tab[] = "";
2352 // ECRM
2353 $tab[] = "";
2354 // DATK
2355 $tab[] = "";
2356 // HEUK
2357 $tab[] = "";
2358
2359 $output = implode($separator, $tab).$end_line;
2360 if ($exportFile) {
2361 fwrite($exportFile, $output);
2362 } else {
2363 print $output;
2364 }
2365
2366 $last_codeinvoice = $line->doc_ref;
2367 }
2368 }
2369
2377 public function exportCharlemagne($objectLines, $exportFile = null)
2378 {
2379 global $langs;
2380 $langs->load('compta');
2381
2382 $separator = "\t";
2383 $end_line = "\n";
2384
2385 $tab = array();
2386
2387 $tab[] = $langs->transnoentitiesnoconv('Date');
2388 $tab[] = self::trunc($langs->transnoentitiesnoconv('Journal'), 6);
2389 $tab[] = self::trunc($langs->transnoentitiesnoconv('Account'), 15);
2390 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60);
2391 $tab[] = self::trunc($langs->transnoentitiesnoconv('Piece'), 20);
2392 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60);
2393 $tab[] = $langs->transnoentitiesnoconv('Amount');
2394 $tab[] = 'S';
2395 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15);
2396 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60);
2397 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15);
2398 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60);
2399 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15);
2400 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60);
2401
2402 $output = implode($separator, $tab).$end_line;
2403 if ($exportFile) {
2404 fwrite($exportFile, $output);
2405 } else {
2406 print $output;
2407 }
2408
2409 foreach ($objectLines as $line) {
2410 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2411
2412 $tab = array();
2413
2414 $tab[] = $date_document; //Date
2415
2416 $tab[] = self::trunc($line->code_journal, 6); //Journal code
2417
2418 if (!empty($line->subledger_account)) {
2419 $account = $line->subledger_account;
2420 } else {
2421 $account = $line->numero_compte;
2422 }
2423 $tab[] = self::trunc((string) $account, 15); //Account number
2424
2425 $tab[] = self::trunc($line->label_compte, 60); //Account label
2426 $tab[] = self::trunc($line->doc_ref, 20); //Piece
2427 // Clean label operation to prevent problem on export with tab separator & other character
2428 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
2429 $tab[] = self::trunc($line->label_operation, 60); //Operation label
2430 $tab[] = price(abs($line->debit - $line->credit)); //Amount
2431 $tab[] = $line->sens; //Direction
2432 $tab[] = ""; //Analytic
2433 $tab[] = ""; //Analytic
2434 $tab[] = ""; //Analytic
2435 $tab[] = ""; //Analytic
2436 $tab[] = ""; //Analytic
2437 $tab[] = ""; //Analytic
2438
2439 $output = implode($separator, $tab).$end_line;
2440 if ($exportFile) {
2441 fwrite($exportFile, $output);
2442 } else {
2443 print $output;
2444 }
2445 }
2446 }
2447
2455 public function exportGestimumV3($objectLines, $exportFile = null)
2456 {
2457 global $langs;
2458
2459 $separator = ',';
2460 $end_line = "\r\n";
2461
2462 $invoices_infos = array();
2463 $supplier_invoices_infos = array();
2464 foreach ($objectLines as $line) {
2465 if ($line->debit == 0 && $line->credit == 0) {
2466 //unset($array[$line]);
2467 } else {
2468 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
2469 $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2470
2471 $invoice_ref = $line->doc_ref;
2472 $company_name = "";
2473
2474 if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
2475 if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2476 ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2477 if ($line->doc_type == 'customer_invoice') {
2478 // Get new customer invoice ref and company name
2479 $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
2480 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
2481 $sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
2482 $resql = $this->db->query($sql);
2483 if ($resql) {
2484 if ($obj = $this->db->fetch_object($resql)) {
2485 // Save invoice infos
2486 $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2487 $invoice_ref = $obj->ref;
2488 $company_name = $obj->nom;
2489 }
2490 }
2491 } else {
2492 // Get new supplier invoice ref and company name
2493 $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
2494 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
2495 $sql .= ' WHERE ff.rowid = '.((int) $line->fk_doc);
2496 $resql = $this->db->query($sql);
2497 if ($resql) {
2498 if ($obj = $this->db->fetch_object($resql)) {
2499 // Save invoice infos
2500 $supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2501 $invoice_ref = $obj->ref;
2502 $company_name = $obj->nom;
2503 }
2504 }
2505 }
2506 } elseif ($line->doc_type == 'customer_invoice') {
2507 // Retrieve invoice infos
2508 $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
2509 $company_name = $invoices_infos[$line->fk_doc]['company_name'];
2510 } else {
2511 // Retrieve invoice infos
2512 $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
2513 $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
2514 }
2515 }
2516
2517 $tab = array();
2518
2519 $tab[] = $line->id;
2520 $tab[] = $date_document;
2521 $tab[] = substr($line->code_journal, 0, 4);
2522
2523 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
2524 $tab[] = length_accountg($line->subledger_account);
2525 } else {
2526 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2527 }
2528 //Libellé Auto
2529 $tab[] = "";
2530 //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"';
2531 //Libellé manual
2532 $tab[] = dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1);
2533 //Numéro de pièce
2534 $tab[] = dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1);
2535 //Devise
2536 $tab[] = 'EUR';
2537 //Amount
2538 $tab[] = price2num(abs($line->debit - $line->credit));
2539 //Sens
2540 $tab[] = $line->sens;
2541 //Code lettrage
2542 $tab[] = "";
2543 //Date Echéance
2544 $tab[] = $date_echeance;
2545
2546 $output = implode($separator, $tab).$end_line;
2547 if ($exportFile) {
2548 fwrite($exportFile, $output);
2549 } else {
2550 print $output;
2551 }
2552 }
2553 }
2554 }
2555
2563 public function exportGestimumV5($objectLines, $exportFile = null)
2564 {
2565 $separator = ',';
2566 $end_line = "\r\n";
2567
2568 foreach ($objectLines as $line) {
2569 if ($line->debit == 0 && $line->credit == 0) {
2570 //unset($array[$line]);
2571 } else {
2572 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
2573
2574 $tab = array();
2575
2576 $tab[] = $line->id;
2577 $tab[] = $date_document;
2578 $tab[] = substr($line->code_journal, 0, 4);
2579 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
2580 $tab[] = length_accountg($line->subledger_account);
2581 } else {
2582 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2583 }
2584 $tab[] = "";
2585 $tab[] = '"'.dol_trunc(str_replace('"', '', $line->label_operation), 40, 'right', 'UTF-8', 1).'"';
2586 $tab[] = '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"';
2587 $tab[] = '"' . dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1) . '"';
2588 $tab[] = price2num(abs($line->debit - $line->credit));
2589 $tab[] = $line->sens;
2590 $tab[] = $date_document;
2591 $tab[] = "";
2592 $tab[] = "";
2593 $tab[] = 'EUR';
2594
2595 $output = implode($separator, $tab).$end_line;
2596 if ($exportFile) {
2597 fwrite($exportFile, $output);
2598 } else {
2599 print $output;
2600 }
2601 }
2602 }
2603 }
2604
2614 public function exportiSuiteExpert($objectLines, $exportFile = null)
2615 {
2616 $separator = ';';
2617 $end_line = "\r\n";
2618
2619
2620 foreach ($objectLines as $line) {
2621 $tab = array();
2622
2623 $date = dol_print_date($line->doc_date, '%d/%m/%Y');
2624
2625 $tab[] = $line->piece_num;
2626 $tab[] = $date;
2627 $tab[] = substr($date, 6, 4);
2628 $tab[] = substr($date, 3, 2);
2629 $tab[] = substr($date, 0, 2);
2630 $tab[] = $line->doc_ref;
2631 //Conversion de chaine UTF8 en Latin9
2632 $tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
2633
2634 //Calcul de la longueur des numéros de comptes
2635 $taille_numero = strlen(length_accountg($line->numero_compte));
2636
2637 //Création du numéro de client et fournisseur générique
2638 $numero_cpt_client = '411';
2639 $numero_cpt_fourn = '401';
2640 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2641 $numero_cpt_client .= '0';
2642 $numero_cpt_fourn .= '0';
2643 }
2644
2645 //Création des comptes auxiliaire des clients et fournisseur
2646 if (length_accountg($line->numero_compte) == $numero_cpt_client || length_accountg($line->numero_compte) == $numero_cpt_fourn) {
2647 $tab[] = rtrim(length_accounta($line->subledger_account), "0");
2648 } else {
2649 $tab[] = length_accountg($line->numero_compte);
2650 }
2651 $nom_client = explode(" - ", $line->label_operation);
2652 $tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
2653 $tab[] = price($line->debit);
2654 $tab[] = price($line->credit);
2655 $tab[] = price($line->montant);
2656 $tab[] = $line->code_journal;
2657
2658 $output = implode($separator, $tab).$end_line;
2659 if ($exportFile) {
2660 fwrite($exportFile, $output);
2661 } else {
2662 print $output;
2663 }
2664 }
2665 }
2666
2674 public static function trunc($str, $size)
2675 {
2676 return dol_trunc($str, $size, 'right', 'UTF-8', 1);
2677 }
2678
2686 public static function toAnsi($str, $size = -1)
2687 {
2688 $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
2689 if ($retVal >= 0 && $size >= 0) {
2690 $retVal = dol_substr($retVal, 0, $size, 'Windows-1251');
2691 }
2692 return $retVal;
2693 }
2694}
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