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