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