dolibarr 21.0.0-beta
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';
1510 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1511 $objectDirPath .= '/'.rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1512 }
1513 $arrayofinclusion = array();
1514 // If it is a supplier invoice, we want to use last uploaded file
1515 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1516 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1517 if (!empty($fileFoundList)) {
1518 $attachmentFileNameTrunc = $line->doc_ref;
1519 foreach ($fileFoundList as $fileFound) {
1520 if (strstr($fileFound['name'], $objectFileName)) {
1521 // skip native invoice pdfs (canelle)
1522 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1523 if ($line->doc_type == 'supplier_invoice') {
1524 if ($fileFound['name'] === $objectFileName.'.pdf') {
1525 continue;
1526 }
1527 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1528 continue;
1529 }
1530 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1531 if (file_exists($fileFoundPath)) {
1532 $archiveFileList[$attachmentFileKey] = array(
1533 'path' => $fileFoundPath,
1534 'name' => $attachmentFileNameTrunc.'.pdf',
1535 );
1536 break;
1537 }
1538 }
1539 }
1540 }
1541 }
1542
1543 if (isset($archiveFileList[$attachmentFileKey])) {
1544 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1545 }
1546 }
1547
1548 $tab[] = $attachmentFileName;
1549
1550 $output = implode($separator, $tab).$end_line;
1551
1552 if ($exportFile) {
1553 fwrite($exportFile, $output);
1554 } else {
1555 print $output;
1556 }
1557 }
1558 }
1559
1560 return $archiveFileList;
1561 }
1562
1575 public function exportFEC2($objectLines, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
1576 {
1577 global $conf, $langs;
1578
1579 $separator = "\t";
1580 $end_line = "\r\n";
1581
1582 $tab = array();
1583 $tab[] = "JournalCode";
1584 $tab[] = "JournalLib";
1585 $tab[] = "EcritureNum";
1586 $tab[] = "EcritureDate";
1587 $tab[] = "CompteNum";
1588 $tab[] = "CompteLib";
1589 $tab[] = "CompAuxNum";
1590 $tab[] = "CompAuxLib";
1591 $tab[] = "PieceRef";
1592 $tab[] = "PieceDate";
1593 $tab[] = "EcritureLib";
1594 $tab[] = "Debit";
1595 $tab[] = "Credit";
1596 $tab[] = "EcritureLet";
1597 $tab[] = "DateLet";
1598 $tab[] = "ValidDate";
1599 $tab[] = "Montantdevise";
1600 $tab[] = "Idevise";
1601 $tab[] = "DateLimitReglmt";
1602 $tab[] = "NumFacture";
1603 $tab[] = "FichierFacture";
1604
1605 $output = implode($separator, $tab).$end_line;
1606 if ($exportFile) {
1607 fwrite($exportFile, $output);
1608 } else {
1609 print $output;
1610 }
1611
1612 foreach ($objectLines as $line) {
1613 if ($line->debit == 0 && $line->credit == 0) {
1614 //unset($array[$line]);
1615 } else {
1616 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1617 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1618 $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1619 $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1620 $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1621
1622 $refInvoice = '';
1623 if ($line->doc_type == 'customer_invoice') {
1624 // Customer invoice
1625 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1626 $invoice = new Facture($this->db);
1627 $invoice->fetch($line->fk_doc);
1628
1629 $refInvoice = $invoice->ref;
1630 } elseif ($line->doc_type == 'supplier_invoice') {
1631 // Supplier invoice
1632 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1633 $invoice = new FactureFournisseur($this->db);
1634 $invoice->fetch($line->fk_doc);
1635
1636 $refInvoice = $invoice->ref_supplier;
1637 }
1638
1639 $tab = array();
1640
1641 // FEC:JournalCode
1642 $tab[] = $line->code_journal;
1643
1644 // FEC:JournalLib
1645 $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1646 $labeljournal = dol_string_nospecial($labeljournal, ' ');
1647 $tab[] = $labeljournal;
1648
1649 // FEC:EcritureNum
1650 $tab[] = $line->piece_num;
1651
1652 // FEC:EcritureDate
1653 $tab[] = $date_creation;
1654
1655 // FEC:CompteNum
1656 $tab[] = length_accountg($line->numero_compte);
1657
1658 // FEC:CompteLib
1659 $tab[] = dol_string_unaccent($line->label_compte);
1660
1661 // FEC:CompAuxNum
1662 $tab[] = length_accounta($line->subledger_account);
1663
1664 // FEC:CompAuxLib
1665 $tab[] = dol_string_unaccent($line->subledger_label);
1666
1667 // FEC:PieceRef
1668 $tab[] = $line->doc_ref;
1669
1670 // FEC:PieceDate
1671 $tab[] = $date_document;
1672
1673 // FEC:EcritureLib
1674 // Clean label operation to prevent problem on export with tab separator & other character
1675 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1676 $line->label_operation = str_replace(array("..."), "", $line->label_operation);
1677 $tab[] = dol_string_unaccent($line->label_operation);
1678
1679 // FEC:Debit
1680 $tab[] = price2fec($line->debit);
1681
1682 // FEC:Credit
1683 $tab[] = price2fec($line->credit);
1684
1685 // FEC:EcritureLet
1686 $tab[] = $line->lettering_code;
1687
1688 // FEC:DateLet
1689 $tab[] = $date_lettering;
1690
1691 // FEC:ValidDate
1692 $tab[] = $date_validation;
1693
1694 // FEC:Montantdevise
1695 $tab[] = $line->multicurrency_amount;
1696
1697 // FEC:Idevise
1698 $tab[] = $line->multicurrency_code;
1699
1700 // FEC_suppl:DateLimitReglmt
1701 $tab[] = $date_limit_payment;
1702
1703 // FEC_suppl:NumFacture
1704 // Clean ref invoice to prevent problem on export with tab separator & other character
1705 $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1706 $tab[] = dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1707
1708 // FEC_suppl:FichierFacture
1709 // get document file
1710 $attachmentFileName = '';
1711 if ($withAttachment == 1) {
1712 $attachmentFileKey = trim((string) $line->piece_num);
1713
1714 if (!isset($archiveFileList[$attachmentFileKey])) {
1715 $objectDirPath = '';
1716 $objectFileName = dol_sanitizeFileName($line->doc_ref);
1717 if ($line->doc_type == 'customer_invoice') {
1718 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1719 } elseif ($line->doc_type == 'expense_report') {
1720 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1721 } elseif ($line->doc_type == 'supplier_invoice') {
1722 '@phan-var-force FactureFournisseur $invoice';
1724 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1725 $objectDirPath .= '/'.rtrim(get_exdir($invoice->id, 2, 0, 0, $invoice, 'invoice_supplier'), '/');
1726 }
1727 $arrayofinclusion = array();
1728 // If it is a supplier invoice, we want to use last uploaded file
1729 $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').(($line->doc_type == 'supplier_invoice') ? '.+' : '').'\.pdf$';
1730 $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, 1);
1731 if (!empty($fileFoundList)) {
1732 $attachmentFileNameTrunc = $line->doc_ref;
1733 foreach ($fileFoundList as $fileFound) {
1734 if (strstr($fileFound['name'], $objectFileName)) {
1735 // skip native invoice pdfs (canelle)
1736 // We want to retrieve an attachment representative of the supplier invoice, not a fake document generated by Dolibarr.
1737 if ($line->doc_type == 'supplier_invoice') {
1738 if ($fileFound['name'] === $objectFileName.'.pdf') {
1739 continue;
1740 }
1741 } elseif ($fileFound['name'] !== $objectFileName.'.pdf') {
1742 continue;
1743 }
1744 $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
1745 if (file_exists($fileFoundPath)) {
1746 $archiveFileList[$attachmentFileKey] = array(
1747 'path' => $fileFoundPath,
1748 'name' => $attachmentFileNameTrunc.'.pdf',
1749 );
1750 break;
1751 }
1752 }
1753 }
1754 }
1755 }
1756
1757 if (isset($archiveFileList[$attachmentFileKey])) {
1758 $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
1759 }
1760 }
1761
1762 $tab[] = $attachmentFileName;
1763
1764 $output = implode($separator, $tab).$end_line;
1765 if ($exportFile) {
1766 fwrite($exportFile, $output);
1767 } else {
1768 print $output;
1769 }
1770 }
1771 }
1772
1773 return $archiveFileList;
1774 }
1775
1786 public function exportSAGE50SWISS($objectLines, $exportFile = null)
1787 {
1788 // SAGE50SWISS
1789 $separator = ',';
1790 $end_line = "\r\n";
1791
1792 // Print header line
1793 $tab = array();
1794
1795 $tab[] = "Blg";
1796 $tab[] = "Datum";
1797 $tab[] = "Kto";
1798 $tab[] = "S/H";
1799 $tab[] = "Grp";
1800 $tab[] = "GKto";
1801 $tab[] = "SId";
1802 $tab[] = "SIdx";
1803 $tab[] = "KIdx";
1804 $tab[] = "BTyp";
1805 $tab[] = "MTyp";
1806 $tab[] = "Code";
1807 $tab[] = "Netto";
1808 $tab[] = "Steuer";
1809 $tab[] = "FW-Betrag";
1810 $tab[] = "Tx1";
1811 $tab[] = "Tx2";
1812 $tab[] = "PkKey";
1813 $tab[] = "OpId";
1814 $tab[] = "Flag";
1815
1816 $output = implode($separator, $tab).$end_line;
1817 if ($exportFile) {
1818 fwrite($exportFile, $output);
1819 } else {
1820 print $output;
1821 }
1822
1823 $thisPieceNum = "";
1824 $thisPieceAccountNr = "";
1825 $aSize = count($objectLines);
1826 foreach ($objectLines as $aIndex => $line) {
1827 $sammelBuchung = false;
1828 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1829 $sammelBuchung = true;
1830 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1831 $sammelBuchung = true;
1832 } elseif ($aIndex + 1 < $aSize
1833 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1834 && $aIndex - 1 < $aSize
1835 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1836 ) {
1837 $sammelBuchung = true;
1838 }
1839
1840 $tab = array();
1841
1842 //Blg
1843 $tab[] = $line->piece_num;
1844
1845 // Datum
1846 $date_document = dol_print_date($line->doc_date, '%d.%m.%Y');
1847 $tab[] = $date_document;
1848
1849 // Kto
1850 $tab[] = length_accountg($line->numero_compte);
1851 // S/H
1852 if ($line->sens == 'D') {
1853 $tab[] = 'S';
1854 } else {
1855 $tab[] = 'H';
1856 }
1857 // Grp
1858 $tab[] = self::trunc($line->code_journal, 1);
1859 // GKto
1860 if (empty($line->code_tiers)) {
1861 if ($line->piece_num == $thisPieceNum) {
1862 $tab[] = length_accounta($thisPieceAccountNr);
1863 } else {
1864 $tab[] = "div";
1865 }
1866 } else {
1867 $tab[] = length_accounta($line->code_tiers);
1868 }
1869 // SId
1870 $tab[] = $this->separator;
1871 // SIdx
1872 $tab[] = "0";
1873 // KIdx
1874 $tab[] = "0";
1875 // BTyp
1876 $tab[] = "0";
1877
1878 // MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
1879 if ($sammelBuchung) {
1880 $tab[] = "2";
1881 } else {
1882 $tab[] = "1";
1883 }
1884 // Code
1885 $tab[] = '""';
1886 // Netto
1887 $tab[] = abs($line->debit - $line->credit);
1888 // Steuer
1889 $tab[] = "0.00";
1890 // FW-Betrag
1891 $tab[] = "0.00";
1892 // Tx1
1893 $line1 = self::toAnsi($line->label_compte, 29);
1894 if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
1895 $line1 = "";
1896 }
1897 $line2 = self::toAnsi($line->doc_ref, 29);
1898 if (strlen($line1) == 0) {
1899 $line1 = $line2;
1900 $line2 = "";
1901 }
1902 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1903 $line1 = $line1.' / '.$line2;
1904 $line2 = "";
1905 }
1906
1907 $tab[] = '"'.self::toAnsi($line1).'"';
1908 // Tx2
1909 $tab[] = '"'.self::toAnsi($line2).'"';
1910 //PkKey
1911 $tab[] = "0";
1912 //OpId
1913 $tab[] = $this->separator;
1914
1915 // Flag
1916 $tab[] = "0";
1917
1918 $output = implode($separator, $tab).$end_line;
1919 if ($exportFile) {
1920 fwrite($exportFile, $output);
1921 } else {
1922 print $output;
1923 }
1924
1925 if ($line->piece_num !== $thisPieceNum) {
1926 $thisPieceNum = $line->piece_num;
1927 $thisPieceAccountNr = $line->numero_compte;
1928 }
1929 }
1930 }
1931
1940 public function exportLDCompta($objectLines, $exportFile = null)
1941 {
1942 $separator = ';';
1943 $end_line = "\r\n";
1944
1945 foreach ($objectLines as $line) {
1946 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1947 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1948 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1949
1950 $tab = array();
1951
1952 // TYPE
1953 $type_enregistrement = 'E'; // For write movement
1954 $tab[] = $type_enregistrement;
1955 // JNAL
1956 $tab[] = substr($line->code_journal, 0, 2);
1957 // NECR
1958 $tab[] = $line->id;
1959 // NPIE
1960 $tab[] = $line->piece_num;
1961 // DATP
1962 $tab[] = $date_document;
1963 // LIBE
1964 $tab[] = $line->label_operation;
1965 // DATH
1966 $tab[] = $date_lim_reglement;
1967 // CNPI
1968 if ($line->doc_type == 'supplier_invoice') {
1969 if (($line->debit - $line->credit) > 0) {
1970 $nature_piece = 'AF';
1971 } else {
1972 $nature_piece = 'FF';
1973 }
1974 } elseif ($line->doc_type == 'customer_invoice') {
1975 if (($line->debit - $line->credit) < 0) {
1976 $nature_piece = 'AC';
1977 } else {
1978 $nature_piece = 'FC';
1979 }
1980 } else {
1981 $nature_piece = '';
1982 }
1983 $tab[] = $nature_piece;
1984 // RACI
1985 // if (!empty($line->subledger_account)) {
1986 // if ($line->doc_type == 'supplier_invoice') {
1987 // $racine_subledger_account = '40';
1988 // } elseif ($line->doc_type == 'customer_invoice') {
1989 // $racine_subledger_account = '41';
1990 // } else {
1991 // $racine_subledger_account = '';
1992 // }
1993 // } else {
1994 $racine_subledger_account = ''; // for records of type E leave this field blank
1995 // }
1996
1997 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
1998 // MONT
1999 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2, 2);
2000 // CODC
2001 $tab[] = $line->sens;
2002 // CPTG
2003 $tab[] = length_accountg($line->numero_compte);
2004 // DATE
2005 $tab[] = $date_creation;
2006 // CLET
2007 $tab[] = $line->lettering_code;
2008 // DATL
2009 $tab[] = $line->date_lettering;
2010 // CPTA
2011 if (!empty($line->subledger_account)) {
2012 $tab[] = length_accounta($line->subledger_account);
2013 } else {
2014 $tab[] = "";
2015 }
2016 // C.N.A.T
2017 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2018 $tab[] = 'F';
2019 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2020 $tab[] = 'C';
2021 } else {
2022 $tab[] = "";
2023 }
2024 // SECT
2025 $tab[] = "";
2026 // CTRE
2027 $tab[] = "";
2028 // NORL
2029 $tab[] = "";
2030 // DATV
2031 $tab[] = "";
2032 // REFD
2033 $tab[] = $line->doc_ref;
2034 // CODH
2035 $tab[] = "";
2036 // NSEQ
2037 $tab[] = "";
2038 // MTDV
2039 $tab[] = '0';
2040 // CODV
2041 $tab[] = "";
2042 // TXDV
2043 $tab[] = '0';
2044 // MOPM
2045 $tab[] = "";
2046 // BONP
2047 $tab[] = "";
2048 // BQAF
2049 $tab[] = "";
2050 // ECES
2051 $tab[] = "";
2052 // TXTL
2053 $tab[] = "";
2054 // ECRM
2055 $tab[] = "";
2056 // DATK
2057 $tab[] = "";
2058 // HEUK
2059 $tab[] = "";
2060
2061 $output = implode($separator, $tab).$end_line;
2062 if ($exportFile) {
2063 fwrite($exportFile, $output);
2064 } else {
2065 print $output;
2066 }
2067 }
2068 }
2069
2080 public function exportLDCompta10($objectLines, $exportFile = null)
2081 {
2082 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
2083
2084 $separator = ';';
2085 $end_line = "\r\n";
2086 $last_codeinvoice = '';
2087
2088 foreach ($objectLines as $line) {
2089 // TYPE C
2090 if ($last_codeinvoice != $line->doc_ref) {
2091 //recherche societe en fonction de son code client
2092 $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
2093 $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
2094 $resql = $this->db->query($sql);
2095
2096 if ($resql && $this->db->num_rows($resql) > 0) {
2097 $soc = $this->db->fetch_object($resql);
2098
2099 $address = array('', '', '');
2100 if (strpos($soc->address, "\n") !== false) {
2101 $address = explode("\n", $soc->address);
2102 if (is_array($address) && count($address) > 0) {
2103 foreach ($address as $key => $data) {
2104 $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
2105 $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
2106 }
2107 }
2108 } else {
2109 $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
2110 $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
2111 $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
2112 }
2113
2114 $tab = array();
2115
2116 $type_enregistrement = 'C';
2117 //TYPE
2118 $tab[] = $type_enregistrement;
2119 //NOCL
2120 $tab[] = $soc->code_client;
2121 //NMCM
2122 $tab[] = "";
2123 //LIBI
2124 $tab[] = "";
2125 //TITR
2126 $tab[] = "";
2127 //RSSO
2128 $tab[] = $soc->nom;
2129 //CAD1
2130 $tab[] = $address[0];
2131 //CAD2
2132 $tab[] = $address[1];
2133 //CAD3
2134 $tab[] = $address[2];
2135 //COPO
2136 $tab[] = $soc->zip;
2137 //BUDI
2138 $tab[] = substr($soc->town, 0, 40);
2139 //CPAY
2140 $tab[] = "";
2141 //PAYS
2142 $tab[] = substr(getCountry($soc->fk_pays), 0, 40);
2143 //NTEL
2144 $tab[] = $soc->phone;
2145 //TLEX
2146 $tab[] = "";
2147 //TLPO
2148 $tab[] = "";
2149 //TLCY
2150 $tab[] = "";
2151 //NINT
2152 $tab[] = "";
2153 //COMM
2154 $tab[] = "";
2155 //SIRE
2156 $tab[] = str_replace(" ", "", $soc->siret);
2157 //RIBP
2158 $tab[] = "";
2159 //DOBQ
2160 $tab[] = "";
2161 //IBBQ
2162 $tab[] = "";
2163 //COBQ
2164 $tab[] = "";
2165 //GUBQ
2166 $tab[] = "";
2167 //CPBQ
2168 $tab[] = "";
2169 //CLBQ
2170 $tab[] = "";
2171 //BIBQ
2172 $tab[] = "";
2173 //MOPM
2174 $tab[] = "";
2175 //DJPM
2176 $tab[] = "";
2177 //DMPM
2178 $tab[] = "";
2179 //REFM
2180 $tab[] = "";
2181 //SLVA
2182 $tab[] = "";
2183 //PLCR
2184 $tab[] = "";
2185 //ECFI
2186 $tab[] = "";
2187 //CREP
2188 $tab[] = "";
2189 //NREP
2190 $tab[] = "";
2191 //TREP
2192 $tab[] = "";
2193 //MREP
2194 $tab[] = "";
2195 //GRRE
2196 $tab[] = "";
2197 //LTTA
2198 $tab[] = "";
2199 //CACT
2200 $tab[] = "";
2201 //CODV
2202 $tab[] = "";
2203 //GRTR
2204 $tab[] = "";
2205 //NOFP
2206 $tab[] = "";
2207 //BQAF
2208 $tab[] = "";
2209 //BONP
2210 $tab[] = "";
2211 //CESC
2212 $tab[] = "";
2213
2214 $output = implode($separator, $tab).$end_line;
2215 if ($exportFile) {
2216 fwrite($exportFile, $output);
2217 } else {
2218 print $output;
2219 }
2220 }
2221 }
2222
2223 $tab = array();
2224
2225 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2226 $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
2227 $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2228
2229 // TYPE E
2230 $type_enregistrement = 'E'; // For write movement
2231 $tab[] = $type_enregistrement;
2232 // JNAL
2233 $tab[] = substr($line->code_journal, 0, 2);
2234 // NECR
2235 $tab[] = $line->id;
2236 // NPIE
2237 $tab[] = $line->piece_num;
2238 // DATP
2239 $tab[] = $date_document;
2240 // LIBE
2241 $tab[] = dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1);
2242 // DATH
2243 $tab[] = $date_lim_reglement;
2244 // CNPI
2245 if ($line->doc_type == 'supplier_invoice') {
2246 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.
2247 $nature_piece = 'AF';
2248 } else {
2249 $nature_piece = 'FF';
2250 }
2251 } elseif ($line->doc_type == 'customer_invoice') {
2252 if (($line->amount) < 0) {
2253 $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.
2254 } else {
2255 $nature_piece = 'FC';
2256 }
2257 } else {
2258 $nature_piece = '';
2259 }
2260 $tab[] = $nature_piece;
2261 // RACI
2262 // if (!empty($line->subledger_account)) {
2263 // if ($line->doc_type == 'supplier_invoice') {
2264 // $racine_subledger_account = '40';
2265 // } elseif ($line->doc_type == 'customer_invoice') {
2266 // $racine_subledger_account = '41';
2267 // } else {
2268 // $racine_subledger_account = '';
2269 // }
2270 // } else {
2271 $racine_subledger_account = ''; // for records of type E leave this field blank
2272 // }
2273
2274 $tab[] = $racine_subledger_account; // deprecated CPTG & CPTA use instead
2275 // MONT
2276 $tab[] = price(abs($line->debit - $line->credit), 0, '', 1, 2);
2277 // CODC
2278 $tab[] = $line->sens;
2279 // CPTG
2280 $tab[] = length_accountg($line->numero_compte);
2281 // DATE
2282 $tab[] = $date_document;
2283 // CLET
2284 $tab[] = $line->lettering_code;
2285 // DATL
2286 $tab[] = $line->date_lettering;
2287 // CPTA
2288 if (!empty($line->subledger_account)) {
2289 $tab[] = length_accounta($line->subledger_account);
2290 } else {
2291 $tab[] = "";
2292 }
2293 // C.N.A.T
2294 if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
2295 $tab[] = 'F';
2296 } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
2297 $tab[] = 'C';
2298 } else {
2299 $tab[] = "";
2300 }
2301 // CTRE
2302 $tab[] = "";
2303 // NORL
2304 $tab[] = "";
2305 // DATV
2306 $tab[] = "";
2307 // REFD
2308 $tab[] = $line->doc_ref;
2309 // NECA
2310 $tab[] = '0';
2311 // CSEC
2312 $tab[] = "";
2313 // CAFF
2314 $tab[] = "";
2315 // CDES
2316 $tab[] = "";
2317 // QTUE
2318 $tab[] = "";
2319 // MTDV
2320 $tab[] = '0';
2321 // CODV
2322 $tab[] = "";
2323 // TXDV
2324 $tab[] = '0';
2325 // MOPM
2326 $tab[] = "";
2327 // BONP
2328 $tab[] = "";
2329 // BQAF
2330 $tab[] = "";
2331 // ECES
2332 $tab[] = "";
2333 // TXTL
2334 $tab[] = "";
2335 // ECRM
2336 $tab[] = "";
2337 // DATK
2338 $tab[] = "";
2339 // HEUK
2340 $tab[] = "";
2341
2342 $output = implode($separator, $tab).$end_line;
2343 if ($exportFile) {
2344 fwrite($exportFile, $output);
2345 } else {
2346 print $output;
2347 }
2348
2349 $last_codeinvoice = $line->doc_ref;
2350 }
2351 }
2352
2360 public function exportCharlemagne($objectLines, $exportFile = null)
2361 {
2362 global $langs;
2363 $langs->load('compta');
2364
2365 $separator = "\t";
2366 $end_line = "\n";
2367
2368 $tab = array();
2369
2370 $tab[] = $langs->transnoentitiesnoconv('Date');
2371 $tab[] = self::trunc($langs->transnoentitiesnoconv('Journal'), 6);
2372 $tab[] = self::trunc($langs->transnoentitiesnoconv('Account'), 15);
2373 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60);
2374 $tab[] = self::trunc($langs->transnoentitiesnoconv('Piece'), 20);
2375 $tab[] = self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60);
2376 $tab[] = $langs->transnoentitiesnoconv('Amount');
2377 $tab[] = 'S';
2378 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15);
2379 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60);
2380 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15);
2381 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60);
2382 $tab[] = self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15);
2383 $tab[] = self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60);
2384
2385 $output = implode($separator, $tab).$end_line;
2386 if ($exportFile) {
2387 fwrite($exportFile, $output);
2388 } else {
2389 print $output;
2390 }
2391
2392 foreach ($objectLines as $line) {
2393 $date_document = dol_print_date($line->doc_date, '%Y%m%d');
2394
2395 $tab = array();
2396
2397 $tab[] = $date_document; //Date
2398
2399 $tab[] = self::trunc($line->code_journal, 6); //Journal code
2400
2401 if (!empty($line->subledger_account)) {
2402 $account = $line->subledger_account;
2403 } else {
2404 $account = $line->numero_compte;
2405 }
2406 $tab[] = self::trunc($account, 15); //Account number
2407
2408 $tab[] = self::trunc($line->label_compte, 60); //Account label
2409 $tab[] = self::trunc($line->doc_ref, 20); //Piece
2410 // Clean label operation to prevent problem on export with tab separator & other character
2411 $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
2412 $tab[] = self::trunc($line->label_operation, 60); //Operation label
2413 $tab[] = price(abs($line->debit - $line->credit)); //Amount
2414 $tab[] = $line->sens; //Direction
2415 $tab[] = ""; //Analytic
2416 $tab[] = ""; //Analytic
2417 $tab[] = ""; //Analytic
2418 $tab[] = ""; //Analytic
2419 $tab[] = ""; //Analytic
2420 $tab[] = ""; //Analytic
2421
2422 $output = implode($separator, $tab).$end_line;
2423 if ($exportFile) {
2424 fwrite($exportFile, $output);
2425 } else {
2426 print $output;
2427 }
2428 }
2429 }
2430
2438 public function exportGestimumV3($objectLines, $exportFile = null)
2439 {
2440 global $langs;
2441
2442 $separator = ',';
2443 $end_line = "\r\n";
2444
2445 $invoices_infos = array();
2446 $supplier_invoices_infos = array();
2447 foreach ($objectLines as $line) {
2448 if ($line->debit == 0 && $line->credit == 0) {
2449 //unset($array[$line]);
2450 } else {
2451 $date_document = dol_print_date($line->doc_date, '%d/%m/%Y');
2452 $date_echeance = dol_print_date($line->date_lim_reglement, '%Y%m%d');
2453
2454 $invoice_ref = $line->doc_ref;
2455 $company_name = "";
2456
2457 if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
2458 if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2459 ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2460 if ($line->doc_type == 'customer_invoice') {
2461 // Get new customer invoice ref and company name
2462 $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
2463 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
2464 $sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
2465 $resql = $this->db->query($sql);
2466 if ($resql) {
2467 if ($obj = $this->db->fetch_object($resql)) {
2468 // Save invoice infos
2469 $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2470 $invoice_ref = $obj->ref;
2471 $company_name = $obj->nom;
2472 }
2473 }
2474 } else {
2475 // Get new supplier invoice ref and company name
2476 $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
2477 $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
2478 $sql .= ' WHERE ff.rowid = '.((int) $line->fk_doc);
2479 $resql = $this->db->query($sql);
2480 if ($resql) {
2481 if ($obj = $this->db->fetch_object($resql)) {
2482 // Save invoice infos
2483 $supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2484 $invoice_ref = $obj->ref;
2485 $company_name = $obj->nom;
2486 }
2487 }
2488 }
2489 } elseif ($line->doc_type == 'customer_invoice') {
2490 // Retrieve invoice infos
2491 $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
2492 $company_name = $invoices_infos[$line->fk_doc]['company_name'];
2493 } else {
2494 // Retrieve invoice infos
2495 $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
2496 $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
2497 }
2498 }
2499
2500 $tab = array();
2501
2502 $tab[] = $line->id;
2503 $tab[] = $date_document;
2504 $tab[] = substr($line->code_journal, 0, 4);
2505
2506 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
2507 $tab[] = length_accountg($line->subledger_account);
2508 } else {
2509 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2510 }
2511 //Libellé Auto
2512 $tab[] = "";
2513 //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"';
2514 //Libellé manual
2515 $tab[] = dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1);
2516 //Numéro de pièce
2517 $tab[] = dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1);
2518 //Devise
2519 $tab[] = 'EUR';
2520 //Amount
2521 $tab[] = price2num(abs($line->debit - $line->credit));
2522 //Sens
2523 $tab[] = $line->sens;
2524 //Code lettrage
2525 $tab[] = "";
2526 //Date Echéance
2527 $tab[] = $date_echeance;
2528
2529 $output = implode($separator, $tab).$end_line;
2530 if ($exportFile) {
2531 fwrite($exportFile, $output);
2532 } else {
2533 print $output;
2534 }
2535 }
2536 }
2537 }
2538
2546 public function exportGestimumV5($objectLines, $exportFile = null)
2547 {
2548 $separator = ',';
2549 $end_line = "\r\n";
2550
2551 foreach ($objectLines as $line) {
2552 if ($line->debit == 0 && $line->credit == 0) {
2553 //unset($array[$line]);
2554 } else {
2555 $date_document = dol_print_date($line->doc_date, '%d%m%Y');
2556
2557 $tab = array();
2558
2559 $tab[] = $line->id;
2560 $tab[] = $date_document;
2561 $tab[] = substr($line->code_journal, 0, 4);
2562 if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
2563 $tab[] = length_accountg($line->subledger_account);
2564 } else {
2565 $tab[] = substr(length_accountg($line->numero_compte), 0, 15);
2566 }
2567 $tab[] = "";
2568 $tab[] = '"'.dol_trunc(str_replace('"', '', $line->label_operation), 40, 'right', 'UTF-8', 1).'"';
2569 $tab[] = '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"';
2570 $tab[] = '"' . dol_trunc(str_replace('"', '', (string) $line->piece_num), 10, 'right', 'UTF-8', 1) . '"';
2571 $tab[] = price2num(abs($line->debit - $line->credit));
2572 $tab[] = $line->sens;
2573 $tab[] = $date_document;
2574 $tab[] = "";
2575 $tab[] = "";
2576 $tab[] = 'EUR';
2577
2578 $output = implode($separator, $tab).$end_line;
2579 if ($exportFile) {
2580 fwrite($exportFile, $output);
2581 } else {
2582 print $output;
2583 }
2584 }
2585 }
2586 }
2587
2597 public function exportiSuiteExpert($objectLines, $exportFile = null)
2598 {
2599 $separator = ';';
2600 $end_line = "\r\n";
2601
2602
2603 foreach ($objectLines as $line) {
2604 $tab = array();
2605
2606 $date = dol_print_date($line->doc_date, '%d/%m/%Y');
2607
2608 $tab[] = $line->piece_num;
2609 $tab[] = $date;
2610 $tab[] = substr($date, 6, 4);
2611 $tab[] = substr($date, 3, 2);
2612 $tab[] = substr($date, 0, 2);
2613 $tab[] = $line->doc_ref;
2614 //Conversion de chaine UTF8 en Latin9
2615 $tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
2616
2617 //Calcul de la longueur des numéros de comptes
2618 $taille_numero = strlen(length_accountg($line->numero_compte));
2619
2620 //Création du numéro de client et fournisseur générique
2621 $numero_cpt_client = '411';
2622 $numero_cpt_fourn = '401';
2623 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2624 $numero_cpt_client .= '0';
2625 $numero_cpt_fourn .= '0';
2626 }
2627
2628 //Création des comptes auxiliaire des clients et fournisseur
2629 if (length_accountg($line->numero_compte) == $numero_cpt_client || length_accountg($line->numero_compte) == $numero_cpt_fourn) {
2630 $tab[] = rtrim(length_accounta($line->subledger_account), "0");
2631 } else {
2632 $tab[] = length_accountg($line->numero_compte);
2633 }
2634 $nom_client = explode(" - ", $line->label_operation);
2635 $tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
2636 $tab[] = price($line->debit);
2637 $tab[] = price($line->credit);
2638 $tab[] = price($line->montant);
2639 $tab[] = $line->code_journal;
2640
2641 $output = implode($separator, $tab).$end_line;
2642 if ($exportFile) {
2643 fwrite($exportFile, $output);
2644 } else {
2645 print $output;
2646 }
2647 }
2648 }
2649
2657 public static function trunc($str, $size)
2658 {
2659 return dol_trunc($str, $size, 'right', 'UTF-8', 1);
2660 }
2661
2669 public static function toAnsi($str, $size = -1)
2670 {
2671 $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
2672 if ($retVal >= 0 && $size >= 0) {
2673 $retVal = dol_substr($retVal, 0, $size, 'Windows-1251');
2674 }
2675 return $retVal;
2676 }
2677}
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
Manage the different format accountancy export.
exportCogilog($objectLines, $exportFile=null)
Export format : COGILOG Last review for this format : 2022-07-12 Alexandre Spangaro (aspangaro@open-d...
export(&$TData, $formatexportset, $withAttachment=0, $downloadMode=1, $outputMode=1, $noouput=1)
Function who chose which export to use with the default config, and make the export into a file.
exportAgiris($objectLines, $exportFile=null)
Export format : Agiris Isacompta.
exportQuadratus($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : Quadratus (Format ASCII) Format since 2015 compatible QuadraCOMPTA Last review for th...
exportWinfic($objectLines, $exportFile=null)
Export format : WinFic - eWinfic - WinSis Compta Last review for this format : 2022-11-01 Alexandre S...
exportSAGE50SWISS($objectLines, $exportFile=null)
Export format : SAGE50SWISS.
exportOpenConcerto($objectLines, $exportFile=null)
Export format : OpenConcerto.
exportEbp($objectLines, $exportFile=null)
Export format : EBP.
exportLDCompta10($objectLines, $exportFile=null)
Export format : LD Compta version 10 & higher Last review for this format : 08-15-2021 Alexandre Span...
exportCharlemagne($objectLines, $exportFile=null)
Export format : Charlemagne.
getTypeConfig()
Array with all export types available (key + label) and parameters for config.
exportLDCompta($objectLines, $exportFile=null)
Export format : LD Compta version 9 http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Docu...
exportBob50($objectLines, $exportFile=null)
Export format : BOB50.
exportGestimumV3($objectLines, $exportFile=null)
Export format : Gestimum V3.
static trunc($str, $size)
trunc
exportiSuiteExpert($objectLines, $exportFile=null)
Export format : iSuite Expert.
exportCiel($objectLines, $exportFile=null)
Export format : CIEL (Format XIMPORT) Format since 2003 compatible CIEL version > 2002 / Sage50 Last ...
getType($mode=0)
Array with all export type available (key + label)
static toAnsi($str, $size=-1)
toAnsi
exportConfigurable($objectLines, $exportFile=null)
Export format : Configurable CSV.
static getFormatCode($type)
Return string to summarize the format (Used to generated export filename)
__construct(DoliDB $db)
Constructor.
exportCegid($objectLines, $exportFile=null)
Export format : CEGID.
exportCoala($objectLines, $exportFile=null)
Export format : COALA.
getMimeType($formatexportset)
Return the MIME type of a file.
exportGestimumV5($objectLines, $exportFile=null)
Export format : Gestimum V5.
Class to manage Dolibarr database access.
Class to manage suppliers invoices.
Class to manage invoices.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_filesize($pathoffile)
Return size of a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
dol_is_dir($folder)
Test if filename is a directory.
price2fec($amount)
Function to format a value into a defined format for French administration (no thousand separator & d...
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
dol_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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79