dolibarr  x.y.z
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-2022 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-2019 Frédéric France <frederic.france@netlogic.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  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program. If not, see <https://www.gnu.org/licenses/>.
30  */
31 
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
42 
43 
48 {
49  // Type of export. Used into $conf->global->ACCOUNTING_EXPORT_MODELCSV
50  public static $EXPORT_TYPE_CONFIGURABLE = 1; // CSV
51  public static $EXPORT_TYPE_AGIRIS = 10;
52  public static $EXPORT_TYPE_EBP = 15;
53  public static $EXPORT_TYPE_CEGID = 20;
54  public static $EXPORT_TYPE_COGILOG = 25;
55  public static $EXPORT_TYPE_COALA = 30;
56  public static $EXPORT_TYPE_BOB50 = 35;
57  public static $EXPORT_TYPE_CIEL = 40;
58  public static $EXPORT_TYPE_SAGE50_SWISS = 45;
59  public static $EXPORT_TYPE_CHARLEMAGNE = 50;
60  public static $EXPORT_TYPE_QUADRATUS = 60;
61  public static $EXPORT_TYPE_WINFIC = 70;
62  public static $EXPORT_TYPE_OPENCONCERTO = 100;
63  public static $EXPORT_TYPE_LDCOMPTA = 110;
64  public static $EXPORT_TYPE_LDCOMPTA10 = 120;
65  public static $EXPORT_TYPE_GESTIMUMV3 = 130;
66  public static $EXPORT_TYPE_GESTIMUMV5 = 135;
67  public static $EXPORT_TYPE_ISUITEEXPERT = 200;
68  // Generic FEC after that
69  public static $EXPORT_TYPE_FEC = 1000;
70  public static $EXPORT_TYPE_FEC2 = 1010;
71 
75  public $db;
76 
80  public $errors = array();
81 
86  public $separator = '';
87 
92  public $end_line = '';
93 
99  public function __construct(DoliDB $db)
100  {
101  global $conf, $hookmanager;
102 
103  $this->db = $db;
104  $this->separator = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
105  $this->end_line = empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? "\n" : ($conf->global->ACCOUNTING_EXPORT_ENDLINE == 1 ? "\n" : "\r\n");
106 
107  $hookmanager->initHooks(array('accountancyexport'));
108  }
109 
115  public function getType()
116  {
117  global $langs, $hookmanager;
118 
119  $listofexporttypes = array(
120  self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans('Modelcsv_configurable'),
121  self::$EXPORT_TYPE_CEGID => $langs->trans('Modelcsv_CEGID'),
122  self::$EXPORT_TYPE_COALA => $langs->trans('Modelcsv_COALA'),
123  self::$EXPORT_TYPE_BOB50 => $langs->trans('Modelcsv_bob50'),
124  self::$EXPORT_TYPE_CIEL => $langs->trans('Modelcsv_ciel'),
125  self::$EXPORT_TYPE_QUADRATUS => $langs->trans('Modelcsv_quadratus'),
126  self::$EXPORT_TYPE_WINFIC => $langs->trans('Modelcsv_winfic'),
127  self::$EXPORT_TYPE_EBP => $langs->trans('Modelcsv_ebp'),
128  self::$EXPORT_TYPE_COGILOG => $langs->trans('Modelcsv_cogilog'),
129  self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'),
130  self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans('Modelcsv_openconcerto'),
131  self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans('Modelcsv_Sage50_Swiss'),
132  self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans('Modelcsv_charlemagne'),
133  self::$EXPORT_TYPE_LDCOMPTA => $langs->trans('Modelcsv_LDCompta'),
134  self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans('Modelcsv_LDCompta10'),
135  self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans('Modelcsv_Gestinumv3'),
136  self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans('Modelcsv_Gestinumv5'),
137  self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'),
138  self::$EXPORT_TYPE_FEC2 => $langs->trans('Modelcsv_FEC2'),
139  self::$EXPORT_TYPE_ISUITEEXPERT => 'Export iSuite Expert',
140  );
141 
142  // allow modules to define export formats
143  $parameters = array();
144  $reshook = $hookmanager->executeHooks('getType', $parameters, $listofexporttypes);
145 
146  ksort($listofexporttypes, SORT_NUMERIC);
147 
148  return $listofexporttypes;
149  }
150 
157  public static function getFormatCode($type)
158  {
159  $formatcode = array(
160  self::$EXPORT_TYPE_CONFIGURABLE => 'csv',
161  self::$EXPORT_TYPE_CEGID => 'cegid',
162  self::$EXPORT_TYPE_COALA => 'coala',
163  self::$EXPORT_TYPE_BOB50 => 'bob50',
164  self::$EXPORT_TYPE_CIEL => 'ciel',
165  self::$EXPORT_TYPE_QUADRATUS => 'quadratus',
166  self::$EXPORT_TYPE_WINFIC => 'winfic',
167  self::$EXPORT_TYPE_EBP => 'ebp',
168  self::$EXPORT_TYPE_COGILOG => 'cogilog',
169  self::$EXPORT_TYPE_AGIRIS => 'agiris',
170  self::$EXPORT_TYPE_OPENCONCERTO => 'openconcerto',
171  self::$EXPORT_TYPE_SAGE50_SWISS => 'sage50ch',
172  self::$EXPORT_TYPE_CHARLEMAGNE => 'charlemagne',
173  self::$EXPORT_TYPE_LDCOMPTA => 'ldcompta',
174  self::$EXPORT_TYPE_LDCOMPTA10 => 'ldcompta10',
175  self::$EXPORT_TYPE_GESTIMUMV3 => 'gestimumv3',
176  self::$EXPORT_TYPE_GESTIMUMV5 => 'gestimumv5',
177  self::$EXPORT_TYPE_FEC => 'fec',
178  self::$EXPORT_TYPE_FEC2 => 'fec2',
179  self::$EXPORT_TYPE_ISUITEEXPERT => 'isuiteexpert',
180  );
181 
182  global $hookmanager;
183  $code = $formatcode[$type];
184  $parameters = array('type' => $type);
185  $reshook = $hookmanager->executeHooks('getFormatCode', $parameters, $code);
186 
187  return $code;
188  }
189 
195  public function getTypeConfig()
196  {
197  global $conf, $langs;
198 
199  $exporttypes = array(
200  'param' => array(
201  self::$EXPORT_TYPE_CONFIGURABLE => array(
202  'label' => $langs->trans('Modelcsv_configurable'),
203  'ACCOUNTING_EXPORT_FORMAT' => empty($conf->global->ACCOUNTING_EXPORT_FORMAT) ? 'txt' : $conf->global->ACCOUNTING_EXPORT_FORMAT,
204  'ACCOUNTING_EXPORT_SEPARATORCSV' => empty($conf->global->ACCOUNTING_EXPORT_SEPARATORCSV) ? ',' : $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV,
205  'ACCOUNTING_EXPORT_ENDLINE' => empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? 1 : $conf->global->ACCOUNTING_EXPORT_ENDLINE,
206  'ACCOUNTING_EXPORT_DATE' => empty($conf->global->ACCOUNTING_EXPORT_DATE) ? '%d%m%Y' : $conf->global->ACCOUNTING_EXPORT_DATE,
207  ),
208  self::$EXPORT_TYPE_CEGID => array(
209  'label' => $langs->trans('Modelcsv_CEGID'),
210  ),
211  self::$EXPORT_TYPE_COALA => array(
212  'label' => $langs->trans('Modelcsv_COALA'),
213  ),
214  self::$EXPORT_TYPE_BOB50 => array(
215  'label' => $langs->trans('Modelcsv_bob50'),
216  ),
217  self::$EXPORT_TYPE_CIEL => array(
218  'label' => $langs->trans('Modelcsv_ciel'),
219  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
220  ),
221  self::$EXPORT_TYPE_QUADRATUS => array(
222  'label' => $langs->trans('Modelcsv_quadratus'),
223  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
224  ),
225  self::$EXPORT_TYPE_WINFIC => array(
226  'label' => $langs->trans('Modelcsv_winfic'),
227  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
228  ),
229  self::$EXPORT_TYPE_EBP => array(
230  'label' => $langs->trans('Modelcsv_ebp'),
231  ),
232  self::$EXPORT_TYPE_COGILOG => array(
233  'label' => $langs->trans('Modelcsv_cogilog'),
234  ),
235  self::$EXPORT_TYPE_AGIRIS => array(
236  'label' => $langs->trans('Modelcsv_agiris'),
237  ),
238  self::$EXPORT_TYPE_OPENCONCERTO => array(
239  'label' => $langs->trans('Modelcsv_openconcerto'),
240  ),
241  self::$EXPORT_TYPE_SAGE50_SWISS => array(
242  'label' => $langs->trans('Modelcsv_Sage50_Swiss'),
243  ),
244  self::$EXPORT_TYPE_CHARLEMAGNE => array(
245  'label' => $langs->trans('Modelcsv_charlemagne'),
246  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
247  ),
248  self::$EXPORT_TYPE_LDCOMPTA => array(
249  'label' => $langs->trans('Modelcsv_LDCompta'),
250  ),
251  self::$EXPORT_TYPE_LDCOMPTA10 => array(
252  'label' => $langs->trans('Modelcsv_LDCompta10'),
253  ),
254  self::$EXPORT_TYPE_GESTIMUMV3 => array(
255  'label' => $langs->trans('Modelcsv_Gestinumv3'),
256  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
257  ),
258  self::$EXPORT_TYPE_GESTIMUMV5 => array(
259  'label' => $langs->trans('Modelcsv_Gestinumv5'),
260  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
261  ),
262  self::$EXPORT_TYPE_FEC => array(
263  'label' => $langs->trans('Modelcsv_FEC'),
264  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
265  ),
266  self::$EXPORT_TYPE_FEC2 => array(
267  'label' => $langs->trans('Modelcsv_FEC2'),
268  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
269  ),
270  self::$EXPORT_TYPE_ISUITEEXPERT => array(
271  'label' => 'iSuite Expert',
272  'ACCOUNTING_EXPORT_FORMAT' => 'csv',
273  ),
274  ),
275  'cr'=> array(
276  '1' => $langs->trans("Unix"),
277  '2' => $langs->trans("Windows")
278  ),
279  'format' => array(
280  'csv' => $langs->trans("csv"),
281  'txt' => $langs->trans("txt")
282  ),
283  );
284 
285  global $hookmanager;
286  $parameters = array();
287  $reshook = $hookmanager->executeHooks('getTypeConfig', $parameters, $exporttypes);
288  return $exporttypes;
289  }
290 
291 
298  public function getMimeType($formatexportset)
299  {
300  $mime = 'text/csv';
301 
302  switch ($formatexportset) {
303  case self::$EXPORT_TYPE_FEC:
304  $mime = 'text/tab-separated-values';
305  break;
306  default:
307  $mime = 'text/csv';
308  break;
309  }
310 
311  return $mime;
312  }
313 
322  public function export(&$TData, $formatexportset, $withAttachment = 0)
323  {
324  global $conf, $langs;
325  global $search_date_end; // Used into /accountancy/tpl/export_journal.tpl.php
326 
327  // Define name of file to save
328  $filename = 'general_ledger-'.$this->getFormatCode($formatexportset);
329  $type_export = 'general_ledger';
330 
331  global $db; // The tpl file use $db
332  $completefilename = '';
333  $exportFile = null;
334  $exportFileName = '';
335  $exportFilePath = '';
336  $archiveFileList = array();
337  if ($withAttachment == 1) {
338  // PHP ZIP extension must be enabled
339  if (!extension_loaded('zip')) {
340  $langs->load('install');
341  $this->errors[] = $langs->trans('ErrorPHPDoesNotSupport', 'ZIP');;
342  return -1;
343  }
344  } else {
345  $mimetype = $this->getMimeType($formatexportset);
346  top_httphead($mimetype, 1);
347  }
348  include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
349  if ($withAttachment == 1 && !empty($completefilename)) {
350  // create export file
351  $tmpDir = !empty($conf->accounting->multidir_temp[$conf->entity]) ? $conf->accounting->multidir_temp[$conf->entity] : $conf->accounting->dir_temp;
352  $exportFileFullName = $completefilename;
353  $exportFileBaseName = basename($exportFileFullName);
354  $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME);
355  $exportFilePath = $tmpDir.'/'.$exportFileFullName;
356  $exportFile = fopen($exportFilePath, 'w');
357  if (!$exportFile) {
358  $this->errors[] = $langs->trans('ErrorFileNotFound', $exportFilePath);
359  return -1;
360  }
361  $archiveFileList[0] = array(
362  'path' => $exportFilePath,
363  'name' => $exportFileFullName,
364  );
365 
366  // archive name and path
367  $archiveFullName = $exportFileName.'.zip';
368  $archivePath = $tmpDir.'/'.$archiveFullName;
369  }
370 
371  switch ($formatexportset) {
372  case self::$EXPORT_TYPE_CONFIGURABLE:
373  $this->exportConfigurable($TData);
374  break;
375  case self::$EXPORT_TYPE_CEGID:
376  $this->exportCegid($TData);
377  break;
378  case self::$EXPORT_TYPE_COALA:
379  $this->exportCoala($TData);
380  break;
381  case self::$EXPORT_TYPE_BOB50:
382  $this->exportBob50($TData);
383  break;
384  case self::$EXPORT_TYPE_CIEL:
385  $this->exportCiel($TData);
386  break;
387  case self::$EXPORT_TYPE_QUADRATUS:
388  $archiveFileList = $this->exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment);
389  break;
390  case self::$EXPORT_TYPE_WINFIC:
391  $this->exportWinfic($TData);
392  break;
393  case self::$EXPORT_TYPE_EBP:
394  $this->exportEbp($TData);
395  break;
396  case self::$EXPORT_TYPE_COGILOG:
397  $this->exportCogilog($TData);
398  break;
399  case self::$EXPORT_TYPE_AGIRIS:
400  $this->exportAgiris($TData);
401  break;
402  case self::$EXPORT_TYPE_OPENCONCERTO:
403  $this->exportOpenConcerto($TData);
404  break;
405  case self::$EXPORT_TYPE_SAGE50_SWISS:
406  $this->exportSAGE50SWISS($TData);
407  break;
408  case self::$EXPORT_TYPE_CHARLEMAGNE:
409  $this->exportCharlemagne($TData);
410  break;
411  case self::$EXPORT_TYPE_LDCOMPTA:
412  $this->exportLDCompta($TData);
413  break;
414  case self::$EXPORT_TYPE_LDCOMPTA10:
415  $this->exportLDCompta10($TData);
416  break;
417  case self::$EXPORT_TYPE_GESTIMUMV3:
418  $this->exportGestimumV3($TData);
419  break;
420  case self::$EXPORT_TYPE_GESTIMUMV5:
421  $this->exportGestimumV5($TData);
422  break;
423  case self::$EXPORT_TYPE_FEC:
424  $this->exportFEC($TData);
425  break;
426  case self::$EXPORT_TYPE_FEC2:
427  $this->exportFEC2($TData);
428  break;
429  case self::$EXPORT_TYPE_ISUITEEXPERT :
430  $this->exportiSuiteExpert($TData);
431  break;
432  default:
433  global $hookmanager;
434  $parameters = array('format' => $formatexportset);
435  // file contents will be created in the hooked function via print
436  $reshook = $hookmanager->executeHooks('export', $parameters, $TData);
437  if ($reshook != 1) {
438  $this->errors[] = $langs->trans('accountancy_error_modelnotfound');
439  }
440  break;
441  }
442 
443  // create and download export file or archive
444  if ($withAttachment == 1) {
445  $error = 0;
446 
447  // close export file
448  if ($exportFile) {
449  fclose($exportFile);
450  }
451 
452  if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
453  // archive files
454  $downloadFileMimeType = 'application/zip';
455  $downloadFileFullName = $archiveFullName;
456  $downloadFilePath = $archivePath;
457 
458  // create archive
459  $archive = new ZipArchive();
460  $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
461  if ($res !== true) {
462  $error++;
463  $this->errors[] = $langs->trans('ErrorFileNotFound', $archivePath);
464  }
465  if (!$error) {
466  // add files
467  foreach ($archiveFileList as $archiveFileArr) {
468  $res = $archive->addFile($archiveFileArr['path'], $archiveFileArr['name']);
469  if (!$res) {
470  $error++;
471  $this->errors[] = $langs->trans('ErrorArchiveAddFile', $archiveFileArr['name']);
472  break;
473  }
474  }
475  }
476  if (!$error) {
477  // close archive
478  $archive->close();
479  }
480  } elseif (!empty($exportFileFullName) && !empty($exportFilePath)) {
481  // only one file to download
482  $downloadFileMimeType = 'text/csv';
483  $downloadFileFullName = $exportFileFullName;
484  $downloadFilePath = $exportFilePath;
485  }
486 
487  if (!$error) {
488  // download export file
489  if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath)) {
490  header('Content-Type: '.$downloadFileMimeType);
491  header('Content-Disposition: attachment; filename='.$downloadFileFullName);
492  header('Cache-Control: Public, must-revalidate');
493  header('Pragma: public');
494  header('Content-Length: '.dol_filesize($downloadFilePath));
495  readfileLowMemory($downloadFilePath);
496  }
497  }
498 
499  if ($error) {
500  return -1;
501  }
502  }
503 
504  return 1;
505  }
506 
507 
514  public function exportCegid($objectLines)
515  {
516  foreach ($objectLines as $line) {
517  $date = dol_print_date($line->doc_date, '%d%m%Y');
518  $separator = ";";
519  $end_line = "\n";
520 
521  print $date.$separator;
522  print $line->code_journal.$separator;
523  print length_accountg($line->numero_compte).$separator;
524  print length_accounta($line->subledger_account).$separator;
525  print $line->sens.$separator;
526  print price2fec(abs($line->debit - $line->credit)).$separator;
527  print dol_string_unaccent($line->label_operation).$separator;
528  print dol_string_unaccent($line->doc_ref);
529  print $end_line;
530  }
531  }
532 
539  public function exportCogilog($objectLines)
540  {
541  foreach ($objectLines as $line) {
542  $date = dol_print_date($line->doc_date, '%d%m%Y');
543  $separator = ";";
544  $end_line = "\n";
545 
546  print $line->code_journal.$separator;
547  print $date.$separator;
548  print $line->piece_num.$separator;
549  print length_accountg($line->numero_compte).$separator;
550  print $separator;
551  print $line->label_operation.$separator;
552  print $date.$separator;
553  if ($line->sens == 'D') {
554  print price($line->debit).$separator;
555  print $separator;
556  } elseif ($line->sens == 'C') {
557  print $separator;
558  print price($line->credit).$separator;
559  }
560  print $line->doc_ref.$separator;
561  print $line->label_operation.$separator;
562  print $end_line;
563  }
564  }
565 
572  public function exportCoala($objectLines)
573  {
574  // Coala export
575  $separator = ";";
576  $end_line = "\n";
577 
578  foreach ($objectLines as $line) {
579  $date = dol_print_date($line->doc_date, '%d/%m/%Y');
580 
581  print $date.$separator;
582  print $line->code_journal.$separator;
583  print length_accountg($line->numero_compte).$separator;
584  print $line->piece_num.$separator;
585  print $line->doc_ref.$separator;
586  print price($line->debit).$separator;
587  print price($line->credit).$separator;
588  print 'E'.$separator;
589  print length_accounta($line->subledger_account).$separator;
590  print $end_line;
591  }
592  }
593 
600  public function exportBob50($objectLines)
601  {
602 
603  // Bob50
604  $separator = ";";
605  $end_line = "\n";
606 
607  foreach ($objectLines as $line) {
608  print $line->piece_num.$separator;
609  $date = dol_print_date($line->doc_date, '%d/%m/%Y');
610  print $date.$separator;
611 
612  if (empty($line->subledger_account)) {
613  print 'G'.$separator;
614  print length_accounta($line->numero_compte).$separator;
615  } else {
616  if (substr($line->numero_compte, 0, 3) == '411') {
617  print 'C'.$separator;
618  }
619  if (substr($line->numero_compte, 0, 3) == '401') {
620  print 'F'.$separator;
621  }
622  print length_accountg($line->subledger_account).$separator;
623  }
624 
625  print price($line->debit).$separator;
626  print price($line->credit).$separator;
627  print dol_trunc($line->label_operation, 32).$separator;
628  print $end_line;
629  }
630  }
631 
646  public function exportCiel(&$TData)
647  {
648  $end_line = "\r\n";
649 
650  $i = 1;
651 
652  foreach ($TData as $data) {
653  $code_compta = length_accountg($data->numero_compte);
654  if (!empty($data->subledger_account)) {
655  $code_compta = length_accounta($data->subledger_account);
656  }
657 
658  $date_document = dol_print_date($data->doc_date, '%Y%m%d');
659  $date_echeance = dol_print_date($data->date_lim_reglement, '%Y%m%d');
660 
661  $Tab = array();
662  $Tab['num_ecriture'] = str_pad($data->piece_num, 5);
663  $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
664  $Tab['date_ecriture'] = str_pad($date_document, 8, ' ', STR_PAD_LEFT);
665  $Tab['date_echeance'] = str_pad($date_echeance, 8, ' ', STR_PAD_LEFT);
666  $Tab['num_piece'] = str_pad(self::trunc($data->doc_ref, 12), 12);
667  $Tab['num_compte'] = str_pad(self::trunc($code_compta, 11), 11);
668  $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).dol_string_unaccent($data->label_operation), 25), 25);
669  $Tab['montant'] = str_pad(price2fec(abs($data->debit - $data->credit)), 13, ' ', STR_PAD_LEFT);
670  $Tab['type_montant'] = str_pad($data->sens, 1);
671  $Tab['vide'] = str_repeat(' ', 18); // Analytical accounting - Not managed in Dolibarr
672  $Tab['intitule_compte'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 34), 34);
673  $Tab['end'] = 'O2003'; // 0 = EUR | 2003 = Format Ciel
674 
675  $Tab['end_line'] = $end_line;
676 
677  print implode($Tab);
678  $i++;
679  }
680  }
681 
696  public function exportQuadratus(&$TData, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
697  {
698  global $conf, $db;
699 
700  $end_line = "\r\n";
701 
702  // We should use dol_now function not time however this is wrong date to transfert in accounting
703  // $date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
704  // $date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
705  foreach ($TData as $data) {
706  $code_compta = $data->numero_compte;
707  if (!empty($data->subledger_account)) {
708  $code_compta = $data->subledger_account;
709  }
710 
711  $Tab = array();
712 
713  if (!empty($data->subledger_account)) {
714  $Tab['type_ligne'] = 'C';
715  $Tab['num_compte'] = str_pad(self::trunc($data->subledger_account, 8), 8);
716  $Tab['lib_compte'] = str_pad(self::trunc($data->subledger_label, 30), 30);
717 
718  if ($data->doc_type == 'customer_invoice') {
719  $Tab['lib_alpha'] = strtoupper(str_pad('C'.self::trunc($data->subledger_label, 6), 6));
720  $Tab['filler'] = str_repeat(' ', 52);
721  $Tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, 8), 8);
722  } elseif ($data->doc_type == 'supplier_invoice') {
723  $Tab['lib_alpha'] = strtoupper(str_pad('F'.self::trunc($data->subledger_label, 6), 6));
724  $Tab['filler'] = str_repeat(' ', 52);
725  $Tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, 8), 8);
726  } else {
727  $Tab['filler'] = str_repeat(' ', 59);
728  $Tab['coll_compte'] = str_pad(' ', 8);
729  }
730 
731  $Tab['filler2'] = str_repeat(' ', 110);
732  $Tab['Maj'] = 2; // Partial update (alpha key, label, address, collectif, RIB)
733 
734  if ($data->doc_type == 'customer_invoice') {
735  $Tab['type_compte'] = 'C';
736  } elseif ($data->doc_type == 'supplier_invoice') {
737  $Tab['coll_compte'] = 'F';
738  } else {
739  $Tab['coll_compte'] = 'G';
740  }
741 
742  $Tab['filler3'] = str_repeat(' ', 235);
743 
744  $Tab['end_line'] = $end_line;
745 
746  if ($exportFile) {
747  fwrite($exportFile, implode($Tab));
748  } else {
749  print implode($Tab);
750  }
751  }
752 
753  $Tab = array();
754  $Tab['type_ligne'] = 'M';
755  $Tab['num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
756  $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
757  $Tab['folio'] = '000';
758 
759  // We use invoice date $data->doc_date not $date_ecriture which is the transfert date
760  // maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
761  //$Tab['date_ecriture'] = $date_ecriture;
762  $Tab['date_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
763  $Tab['filler'] = ' ';
764  $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).' '.dol_string_unaccent($data->label_operation), 20), 20);
765 
766  // Credit invoice - invert sens
767  /*
768  if ($data->montant < 0) {
769  if ($data->sens == 'C') {
770  $Tab['sens'] = 'D';
771  } else {
772  $Tab['sens'] = 'C';
773  }
774  $Tab['signe_montant'] = '-';
775  } else {
776  $Tab['sens'] = $data->sens; // C or D
777  $Tab['signe_montant'] = '+';
778  }*/
779  $Tab['sens'] = $data->sens; // C or D
780  $Tab['signe_montant'] = '+';
781 
782  // The amount must be in centimes without decimal points.
783  $Tab['montant'] = str_pad(abs(($data->debit - $data->credit) * 100), 12, '0', STR_PAD_LEFT);
784  $Tab['contrepartie'] = str_repeat(' ', 8);
785 
786  // Force date format : %d%m%y
787  if (!empty($data->date_lim_reglement)) {
788  //$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE);
789  $Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, '%d%m%y'); // Format must be ddmmyy
790  } else {
791  $Tab['date_echeance'] = '000000';
792  }
793 
794  // Please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
795  // $Tab['lettrage'] = str_repeat(' ', 5);
796  $Tab['lettrage'] = str_repeat(' ', 2);
797  $Tab['codestat'] = str_repeat(' ', 3);
798  $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 5), 5);
799 
800  // Keep correct quadra named field instead of anon filler
801  // $Tab['filler2'] = str_repeat(' ', 20);
802  $Tab['affaire'] = str_repeat(' ', 10);
803  $Tab['quantity1'] = str_repeat(' ', 10);
804  $Tab['num_piece2'] = str_pad(self::trunc($data->piece_num, 8), 8);
805  $Tab['devis'] = str_pad($conf->currency, 3);
806  $Tab['code_journal2'] = str_pad(self::trunc($data->code_journal, 3), 3);
807  $Tab['filler3'] = str_repeat(' ', 3);
808 
809  // Keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
810  // 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
811  // TODO: we should filter more than only accent to avoid wrong line size
812  // TODO: remove invoice number doc_ref in libelle,
813  // TODO: we should offer an option for customer to build the libelle using invoice number / name / date in accounting software
814  //$Tab['libelle_ecriture2'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref) . ' ' . dol_string_unaccent($data->label_operation), 30), 30);
815  $Tab['libelle_ecriture2'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 30), 30);
816  $Tab['codetva'] = str_repeat(' ', 2);
817 
818  // We need to keep the 10 lastest number of invoice doc_ref not the beginning part that is the unusefull almost same part
819  // $Tab['num_piece3'] = str_pad(self::trunc($data->piece_num, 10), 10);
820  $Tab['num_piece3'] = substr(self::trunc($data->doc_ref, 20), -10);
821  $Tab['reserved'] = str_repeat(' ', 10); // position 159
822  $Tab['currency_amount'] = str_repeat(' ', 13); // position 169
823  // get document file
824  $attachmentFileName = '';
825  if ($withAttachment == 1) {
826  $attachmentFileKey = trim($data->piece_num);
827 
828  if (!isset($archiveFileList[$attachmentFileKey])) {
829  $objectDirPath = '';
830  $objectFileName = dol_sanitizeFileName($data->doc_ref);
831  if ($data->doc_type == 'customer_invoice') {
832  $objectDirPath = !empty($conf->facture->multidir_output[$conf->entity]) ? $conf->facture->multidir_output[$conf->entity] : $conf->facture->dir_output;
833  } elseif ($data->doc_type == 'expense_report') {
834  $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->factureexpensereport->dir_output;
835  } elseif ($data->doc_type == 'supplier_invoice') {
836  $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
837  }
838  $arrayofinclusion = array();
839  $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').'\.pdf$';
840  $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, true);
841  if (!empty($fileFoundList)) {
842  $attachmentFileNameTrunc = str_pad(self::trunc($data->piece_num, 8), 8, '0', STR_PAD_LEFT);
843  foreach ($fileFoundList as $fileFound) {
844  if (strstr($fileFound['name'], $objectFileName)) {
845  $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
846  if (file_exists($fileFoundPath)) {
847  $archiveFileList[$attachmentFileKey] = array(
848  'path' => $fileFoundPath,
849  'name' => $attachmentFileNameTrunc.'.pdf',
850  );
851  break;
852  }
853  }
854  }
855  }
856  }
857 
858  if (isset($archiveFileList[$attachmentFileKey])) {
859  $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
860  }
861  }
862  if (dol_strlen($attachmentFileName) == 12) {
863  $Tab['attachment'] = $attachmentFileName; // position 182
864  } else {
865  $Tab['attachment'] = str_repeat(' ', 12); // position 182
866  }
867  $Tab['filler4'] = str_repeat(' ', 38);
868  $Tab['end_line'] = $end_line;
869 
870  if ($exportFile) {
871  fwrite($exportFile, implode($Tab));
872  } else {
873  print implode($Tab);
874  }
875  }
876 
877  return $archiveFileList;
878  }
879 
890  public function exportWinfic(&$TData)
891  {
892  global $conf;
893 
894  $end_line = "\r\n";
895  $index = 1;
896 
897  //We should use dol_now function not time however this is wrong date to transfert in accounting
898  //$date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
899  //$date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
900 
901  // Warning ! When truncation is necessary, no dot because 3 dots = three characters. The columns are shifted
902 
903  foreach ($TData as $data) {
904  $code_compta = $data->numero_compte;
905  if (!empty($data->subledger_account)) {
906  $code_compta = $data->subledger_account;
907  }
908 
909  $Tab = array();
910  //$Tab['type_ligne'] = 'M';
911  $Tab['code_journal'] = str_pad(dol_trunc($data->code_journal, 2, 'right', 'UTF-8', 1), 2);
912 
913  //We use invoice date $data->doc_date not $date_ecriture which is the transfert date
914  //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
915  //$Tab['date_ecriture'] = $date_ecriture;
916  $Tab['date_operation'] = dol_print_date($data->doc_date, '%d%m%Y');
917 
918  $Tab['folio'] = ' 1';
919 
920  $Tab['num_ecriture'] = str_pad(dol_trunc($index, 6, 'right', 'UTF-8', 1), 6, ' ', STR_PAD_LEFT);
921 
922  $Tab['jour_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
923 
924  $Tab['num_compte'] = str_pad(dol_trunc($code_compta, 6, 'right', 'UTF-8', 1), 6, '0');
925 
926  if ($data->sens == 'D') {
927  $Tab['montant_debit'] = str_pad(number_format($data->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
928 
929  $Tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
930  } else {
931  $Tab['montant_debit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
932 
933  $Tab['montant_crebit'] = str_pad(number_format($data->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
934  }
935 
936  $Tab['libelle_ecriture'] = str_pad(dol_trunc(dol_string_unaccent($data->doc_ref).' '.dol_string_unaccent($data->label_operation), 30, 'right', 'UTF-8', 1), 30);
937 
938  $Tab['lettrage'] = str_repeat(dol_trunc($data->lettering_code, 2, 'left', 'UTF-8', 1), 2);
939 
940  $Tab['code_piece'] = str_pad(dol_trunc($data->piece_num, 5, 'left', 'UTF-8', 1), 5, ' ', STR_PAD_LEFT);
941 
942  $Tab['code_stat'] = str_repeat(' ', 4);
943 
944  if (!empty($data->date_lim_reglement)) {
945  //$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE);
946  $Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, '%d%m%Y');
947  } else {
948  $Tab['date_echeance'] = dol_print_date($data->doc_date, '%d%m%Y');
949  }
950 
951  $Tab['monnaie'] = '1';
952 
953  $Tab['filler'] = ' ';
954 
955  $Tab['ind_compteur'] = ' ';
956 
957  $Tab['quantite'] = '0,000000000';
958 
959  $Tab['code_pointage'] = str_repeat(' ', 2);
960 
961  $Tab['end_line'] = $end_line;
962 
963  print implode('|', $Tab);
964 
965  $index++;
966  }
967  }
968 
969 
976  public function exportEbp($objectLines)
977  {
978 
979  $separator = ',';
980  $end_line = "\n";
981 
982  foreach ($objectLines as $line) {
983  $date = dol_print_date($line->doc_date, '%d%m%Y');
984 
985  print $line->id.$separator;
986  print $date.$separator;
987  print $line->code_journal.$separator;
988  if (empty($line->subledger_account)) {
989  print $line->numero_compte.$separator;
990  } else {
991  print $line->subledger_account.$separator;
992  }
993  //print substr(length_accountg($line->numero_compte), 0, 2) . $separator;
994  print '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"'.$separator;
995  print '"'.dol_trunc($line->piece_num, 15, 'right', 'UTF-8', 1).'"'.$separator;
996  print price2num(abs($line->debit - $line->credit)).$separator;
997  print $line->sens.$separator;
998  print $date.$separator;
999  //print 'EUR';
1000  print $end_line;
1001  }
1002  }
1003 
1004 
1011  public function exportAgiris($objectLines)
1012  {
1013 
1014  $separator = ';';
1015  $end_line = "\n";
1016 
1017  foreach ($objectLines as $line) {
1018  $date = dol_print_date($line->doc_date, '%d%m%Y');
1019 
1020  print $line->piece_num.$separator;
1021  print self::toAnsi($line->label_operation).$separator;
1022  print $date.$separator;
1023  print self::toAnsi($line->label_operation).$separator;
1024 
1025  if (empty($line->subledger_account)) {
1026  print length_accountg($line->numero_compte).$separator;
1027  print self::toAnsi($line->label_compte).$separator;
1028  } else {
1029  print length_accounta($line->subledger_account).$separator;
1030  print self::toAnsi($line->subledger_label).$separator;
1031  }
1032 
1033  print self::toAnsi($line->doc_ref).$separator;
1034  print price($line->debit).$separator;
1035  print price($line->credit).$separator;
1036  print price(abs($line->debit - $line->credit)).$separator;
1037  print $line->sens.$separator;
1038  print $line->lettering_code.$separator;
1039  print $line->code_journal;
1040  print $end_line;
1041  }
1042  }
1043 
1050  public function exportOpenConcerto($objectLines)
1051  {
1052 
1053  $separator = ';';
1054  $end_line = "\n";
1055 
1056  foreach ($objectLines as $line) {
1057  $date = dol_print_date($line->doc_date, '%d/%m/%Y');
1058 
1059  print $date.$separator;
1060  print $line->code_journal.$separator;
1061  if (empty($line->subledger_account)) {
1062  print length_accountg($line->numero_compte).$separator;
1063  } else {
1064  print length_accounta($line->subledger_account).$separator;
1065  }
1066  print $line->doc_ref.$separator;
1067  print $line->label_operation.$separator;
1068  print price($line->debit).$separator;
1069  print price($line->credit).$separator;
1070 
1071  print $end_line;
1072  }
1073  }
1074 
1081  public function exportConfigurable($objectLines)
1082  {
1083  global $conf;
1084 
1085  $separator = $this->separator;
1086 
1087  foreach ($objectLines as $line) {
1088  $tab = array();
1089  // export configurable
1090  $date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
1091  $tab[] = $line->piece_num;
1092  $tab[] = $date;
1093  $tab[] = $line->doc_ref;
1094  $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
1095  $tab[] = length_accountg($line->numero_compte);
1096  $tab[] = length_accounta($line->subledger_account);
1097  $tab[] = price2num($line->debit);
1098  $tab[] = price2num($line->credit);
1099  $tab[] = price2num($line->debit - $line->credit);
1100  $tab[] = $line->code_journal;
1101 
1102  print implode($separator, $tab).$this->end_line;
1103  }
1104  }
1105 
1112  public function exportFEC($objectLines)
1113  {
1114  global $langs;
1115 
1116  $separator = "\t";
1117  $end_line = "\r\n";
1118 
1119  print "JournalCode".$separator;
1120  print "JournalLib".$separator;
1121  print "EcritureNum".$separator;
1122  print "EcritureDate".$separator;
1123  print "CompteNum".$separator;
1124  print "CompteLib".$separator;
1125  print "CompAuxNum".$separator;
1126  print "CompAuxLib".$separator;
1127  print "PieceRef".$separator;
1128  print "PieceDate".$separator;
1129  print "EcritureLib".$separator;
1130  print "Debit".$separator;
1131  print "Credit".$separator;
1132  print "EcritureLet".$separator;
1133  print "DateLet".$separator;
1134  print "ValidDate".$separator;
1135  print "Montantdevise".$separator;
1136  print "Idevise".$separator;
1137  print "DateLimitReglmt".$separator;
1138  print "NumFacture";
1139  print $end_line;
1140 
1141  foreach ($objectLines as $line) {
1142  if ($line->debit == 0 && $line->credit == 0) {
1143  //unset($array[$line]);
1144  } else {
1145  $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1146  $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1147  $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1148  $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1149  $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1150 
1151  $refInvoice = '';
1152  if ($line->doc_type == 'customer_invoice') {
1153  // Customer invoice
1154  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1155  $invoice = new Facture($this->db);
1156  $invoice->fetch($line->fk_doc);
1157 
1158  $refInvoice = $invoice->ref;
1159  } elseif ($line->doc_type == 'supplier_invoice') {
1160  // Supplier invoice
1161  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1162  $invoice = new FactureFournisseur($this->db);
1163  $invoice->fetch($line->fk_doc);
1164 
1165  $refInvoice = $invoice->ref_supplier;
1166  }
1167 
1168  // FEC:JournalCode
1169  print $line->code_journal . $separator;
1170 
1171  // FEC:JournalLib
1172  print dol_string_unaccent($langs->transnoentities($line->journal_label)) . $separator;
1173 
1174  // FEC:EcritureNum
1175  print $line->piece_num . $separator;
1176 
1177  // FEC:EcritureDate
1178  print $date_document . $separator;
1179 
1180  // FEC:CompteNum
1181  print $line->numero_compte . $separator;
1182 
1183  // FEC:CompteLib
1184  print dol_string_unaccent($line->label_compte) . $separator;
1185 
1186  // FEC:CompAuxNum
1187  print $line->subledger_account . $separator;
1188 
1189  // FEC:CompAuxLib
1190  print dol_string_unaccent($line->subledger_label) . $separator;
1191 
1192  // FEC:PieceRef
1193  print $line->doc_ref . $separator;
1194 
1195  // FEC:PieceDate
1196  print dol_string_unaccent($date_creation) . $separator;
1197 
1198  // FEC:EcritureLib
1199  // Clean label operation to prevent problem on export with tab separator & other character
1200  $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1201  print dol_string_unaccent($line->label_operation) . $separator;
1202 
1203  // FEC:Debit
1204  print price2fec($line->debit) . $separator;
1205 
1206  // FEC:Credit
1207  print price2fec($line->credit) . $separator;
1208 
1209  // FEC:EcritureLet
1210  print $line->lettering_code . $separator;
1211 
1212  // FEC:DateLet
1213  print $date_lettering . $separator;
1214 
1215  // FEC:ValidDate
1216  print $date_validation . $separator;
1217 
1218  // FEC:Montantdevise
1219  print $line->multicurrency_amount . $separator;
1220 
1221  // FEC:Idevise
1222  print $line->multicurrency_code . $separator;
1223 
1224  // FEC_suppl:DateLimitReglmt
1225  print $date_limit_payment . $separator;
1226 
1227  // FEC_suppl:NumFacture
1228  // Clean ref invoice to prevent problem on export with tab separator & other character
1229  $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1230  print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1231 
1232  print $end_line;
1233  }
1234  }
1235  }
1236 
1243  public function exportFEC2($objectLines)
1244  {
1245  global $langs;
1246 
1247  $separator = "\t";
1248  $end_line = "\r\n";
1249 
1250  print "JournalCode".$separator;
1251  print "JournalLib".$separator;
1252  print "EcritureNum".$separator;
1253  print "EcritureDate".$separator;
1254  print "CompteNum".$separator;
1255  print "CompteLib".$separator;
1256  print "CompAuxNum".$separator;
1257  print "CompAuxLib".$separator;
1258  print "PieceRef".$separator;
1259  print "PieceDate".$separator;
1260  print "EcritureLib".$separator;
1261  print "Debit".$separator;
1262  print "Credit".$separator;
1263  print "EcritureLet".$separator;
1264  print "DateLet".$separator;
1265  print "ValidDate".$separator;
1266  print "Montantdevise".$separator;
1267  print "Idevise".$separator;
1268  print "DateLimitReglmt".$separator;
1269  print "NumFacture";
1270  print $end_line;
1271 
1272  foreach ($objectLines as $line) {
1273  if ($line->debit == 0 && $line->credit == 0) {
1274  //unset($array[$line]);
1275  } else {
1276  $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1277  $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1278  $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1279  $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1280  $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1281 
1282  $refInvoice = '';
1283  if ($line->doc_type == 'customer_invoice') {
1284  // Customer invoice
1285  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1286  $invoice = new Facture($this->db);
1287  $invoice->fetch($line->fk_doc);
1288 
1289  $refInvoice = $invoice->ref;
1290  } elseif ($line->doc_type == 'supplier_invoice') {
1291  // Supplier invoice
1292  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1293  $invoice = new FactureFournisseur($this->db);
1294  $invoice->fetch($line->fk_doc);
1295 
1296  $refInvoice = $invoice->ref_supplier;
1297  }
1298 
1299  // FEC:JournalCode
1300  print $line->code_journal . $separator;
1301 
1302  // FEC:JournalLib
1303  print dol_string_unaccent($langs->transnoentities($line->journal_label)) . $separator;
1304 
1305  // FEC:EcritureNum
1306  print $line->piece_num . $separator;
1307 
1308  // FEC:EcritureDate
1309  print $date_creation . $separator;
1310 
1311  // FEC:CompteNum
1312  print length_accountg($line->numero_compte) . $separator;
1313 
1314  // FEC:CompteLib
1315  print dol_string_unaccent($line->label_compte) . $separator;
1316 
1317  // FEC:CompAuxNum
1318  print length_accounta($line->subledger_account) . $separator;
1319 
1320  // FEC:CompAuxLib
1321  print dol_string_unaccent($line->subledger_label) . $separator;
1322 
1323  // FEC:PieceRef
1324  print $line->doc_ref . $separator;
1325 
1326  // FEC:PieceDate
1327  print $date_document . $separator;
1328 
1329  // FEC:EcritureLib
1330  // Clean label operation to prevent problem on export with tab separator & other character
1331  $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1332  print dol_string_unaccent($line->label_operation) . $separator;
1333 
1334  // FEC:Debit
1335  print price2fec($line->debit) . $separator;
1336 
1337  // FEC:Credit
1338  print price2fec($line->credit) . $separator;
1339 
1340  // FEC:EcritureLet
1341  print $line->lettering_code . $separator;
1342 
1343  // FEC:DateLet
1344  print $date_lettering . $separator;
1345 
1346  // FEC:ValidDate
1347  print $date_validation . $separator;
1348 
1349  // FEC:Montantdevise
1350  print $line->multicurrency_amount . $separator;
1351 
1352  // FEC:Idevise
1353  print $line->multicurrency_code . $separator;
1354 
1355  // FEC_suppl:DateLimitReglmt
1356  print $date_limit_payment . $separator;
1357 
1358  // FEC_suppl:NumFacture
1359  // Clean ref invoice to prevent problem on export with tab separator & other character
1360  $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1361  print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1362 
1363 
1364  print $end_line;
1365  }
1366  }
1367  }
1368 
1379  public function exportSAGE50SWISS($objectLines)
1380  {
1381  // SAGE50SWISS
1382  $this->separator = ',';
1383  $this->end_line = "\r\n";
1384 
1385  // Print header line
1386  print "Blg,Datum,Kto,S/H,Grp,GKto,SId,SIdx,KIdx,BTyp,MTyp,Code,Netto,Steuer,FW-Betrag,Tx1,Tx2,PkKey,OpId,Flag";
1387  print $this->end_line;
1388  $thisPieceNum = "";
1389  $thisPieceAccountNr = "";
1390  $aSize = count($objectLines);
1391  foreach ($objectLines as $aIndex => $line) {
1392  $sammelBuchung = false;
1393  if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1394  $sammelBuchung = true;
1395  } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1396  $sammelBuchung = true;
1397  } elseif ($aIndex + 1 < $aSize
1398  && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1399  && $aIndex - 1 < $aSize
1400  && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1401  ) {
1402  $sammelBuchung = true;
1403  }
1404 
1405  //Blg
1406  print $line->piece_num.$this->separator;
1407 
1408  // Datum
1409  $date = dol_print_date($line->doc_date, '%d.%m.%Y');
1410  print $date.$this->separator;
1411 
1412  // Kto
1413  print length_accountg($line->numero_compte).$this->separator;
1414  // S/H
1415  if ($line->sens == 'D') {
1416  print 'S'.$this->separator;
1417  } else {
1418  print 'H'.$this->separator;
1419  }
1420  //Grp
1421  print self::trunc($line->code_journal, 1).$this->separator;
1422  // GKto
1423  if (empty($line->code_tiers)) {
1424  if ($line->piece_num == $thisPieceNum) {
1425  print length_accounta($thisPieceAccountNr).$this->separator;
1426  } else {
1427  print "div".$this->separator;
1428  }
1429  } else {
1430  print length_accounta($line->code_tiers).$this->separator;
1431  }
1432  //SId
1433  print $this->separator;
1434  //SIdx
1435  print "0".$this->separator;
1436  //KIdx
1437  print "0".$this->separator;
1438  //BTyp
1439  print "0".$this->separator;
1440 
1441  //MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
1442  if ($sammelBuchung) {
1443  print "2".$this->separator;
1444  } else {
1445  print "1".$this->separator;
1446  }
1447  // Code
1448  print '""'.$this->separator;
1449  // Netto
1450  print abs($line->debit - $line->credit).$this->separator;
1451  // Steuer
1452  print "0.00".$this->separator;
1453  // FW-Betrag
1454  print "0.00".$this->separator;
1455  // Tx1
1456  $line1 = self::toAnsi($line->label_compte, 29);
1457  if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
1458  $line1 = "";
1459  }
1460  $line2 = self::toAnsi($line->doc_ref, 29);
1461  if (strlen($line1) == 0) {
1462  $line1 = $line2;
1463  $line2 = "";
1464  }
1465  if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1466  $line1 = $line1.' / '.$line2;
1467  $line2 = "";
1468  }
1469 
1470  print '"'.self::toAnsi($line1).'"'.$this->separator;
1471  // Tx2
1472  print '"'.self::toAnsi($line2).'"'.$this->separator;
1473  //PkKey
1474  print "0".$this->separator;
1475  //OpId
1476  print $this->separator;
1477 
1478  // Flag
1479  print "0";
1480 
1481  print $this->end_line;
1482 
1483  if ($line->piece_num !== $thisPieceNum) {
1484  $thisPieceNum = $line->piece_num;
1485  $thisPieceAccountNr = $line->numero_compte;
1486  }
1487  }
1488  }
1489 
1498  public function exportLDCompta($objectLines)
1499  {
1500 
1501  $separator = ';';
1502  $end_line = "\r\n";
1503 
1504  foreach ($objectLines as $line) {
1505  $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1506  $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1507  $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1508 
1509  // TYPE
1510  $type_enregistrement = 'E'; // For write movement
1511  print $type_enregistrement.$separator;
1512  // JNAL
1513  print substr($line->code_journal, 0, 2).$separator;
1514  // NECR
1515  print $line->id.$separator;
1516  // NPIE
1517  print $line->piece_num.$separator;
1518  // DATP
1519  print $date_document.$separator;
1520  // LIBE
1521  print $line->label_operation.$separator;
1522  // DATH
1523  print $date_lim_reglement.$separator;
1524  // CNPI
1525  if ($line->doc_type == 'supplier_invoice') {
1526  if (($line->debit - $line->credit) > 0) {
1527  $nature_piece = 'AF';
1528  } else {
1529  $nature_piece = 'FF';
1530  }
1531  } elseif ($line->doc_type == 'customer_invoice') {
1532  if (($line->debit - $line->credit) < 0) {
1533  $nature_piece = 'AC';
1534  } else {
1535  $nature_piece = 'FC';
1536  }
1537  } else {
1538  $nature_piece = '';
1539  }
1540  print $nature_piece.$separator;
1541  // RACI
1542  // if (!empty($line->subledger_account)) {
1543  // if ($line->doc_type == 'supplier_invoice') {
1544  // $racine_subledger_account = '40';
1545  // } elseif ($line->doc_type == 'customer_invoice') {
1546  // $racine_subledger_account = '41';
1547  // } else {
1548  // $racine_subledger_account = '';
1549  // }
1550  // } else {
1551  $racine_subledger_account = ''; // for records of type E leave this field blank
1552  // }
1553 
1554  print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
1555  // MONT
1556  print price(abs($line->debit - $line->credit), 0, '', 1, 2, 2).$separator;
1557  // CODC
1558  print $line->sens.$separator;
1559  // CPTG
1560  print length_accountg($line->numero_compte).$separator;
1561  // DATE
1562  print $date_creation.$separator;
1563  // CLET
1564  print $line->lettering_code.$separator;
1565  // DATL
1566  print $line->date_lettering.$separator;
1567  // CPTA
1568  if (!empty($line->subledger_account)) {
1569  print length_accounta($line->subledger_account).$separator;
1570  } else {
1571  print $separator;
1572  }
1573  // CNAT
1574  if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
1575  print 'F'.$separator;
1576  } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
1577  print 'C'.$separator;
1578  } else {
1579  print $separator;
1580  }
1581  // SECT
1582  print $separator;
1583  // CTRE
1584  print $separator;
1585  // NORL
1586  print $separator;
1587  // DATV
1588  print $separator;
1589  // REFD
1590  print $line->doc_ref.$separator;
1591  // CODH
1592  print $separator;
1593  // NSEQ
1594  print $separator;
1595  // MTDV
1596  print '0'.$separator;
1597  // CODV
1598  print $separator;
1599  // TXDV
1600  print '0'.$separator;
1601  // MOPM
1602  print $separator;
1603  // BONP
1604  print $separator;
1605  // BQAF
1606  print $separator;
1607  // ECES
1608  print $separator;
1609  // TXTL
1610  print $separator;
1611  // ECRM
1612  print $separator;
1613  // DATK
1614  print $separator;
1615  // HEUK
1616  print $separator;
1617 
1618  print $end_line;
1619  }
1620  }
1621 
1632  public function exportLDCompta10($objectLines)
1633  {
1634  require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
1635 
1636  $separator = ';';
1637  $end_line = "\r\n";
1638  $last_codeinvoice = '';
1639 
1640  foreach ($objectLines as $line) {
1641  // TYPE C
1642  if ($last_codeinvoice != $line->doc_ref) {
1643  //recherche societe en fonction de son code client
1644  $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
1645  $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
1646  $resql = $this->db->query($sql);
1647 
1648  if ($resql && $this->db->num_rows($resql) > 0) {
1649  $soc = $this->db->fetch_object($resql);
1650 
1651  $address = array('', '', '');
1652  if (strpos($soc->address, "\n") !== false) {
1653  $address = explode("\n", $soc->address);
1654  if (is_array($address) && count($address) > 0) {
1655  foreach ($address as $key => $data) {
1656  $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
1657  $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
1658  }
1659  }
1660  } else {
1661  $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
1662  $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
1663  $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
1664  }
1665 
1666  $type_enregistrement = 'C';
1667  //TYPE
1668  print $type_enregistrement.$separator;
1669  //NOCL
1670  print $soc->code_client.$separator;
1671  //NMCM
1672  print $separator;
1673  //LIBI
1674  print $separator;
1675  //TITR
1676  print $separator;
1677  //RSSO
1678  print $soc->nom.$separator;
1679  //CAD1
1680  print $address[0].$separator;
1681  //CAD2
1682  print $address[1].$separator;
1683  //CAD3
1684  print $address[2].$separator;
1685  //COPO
1686  print $soc->zip.$separator;
1687  //BUDI
1688  print substr($soc->town, 0, 40).$separator;
1689  //CPAY
1690  print $separator;
1691  //PAYS
1692  print substr(getCountry($soc->fk_pays), 0, 40).$separator;
1693  //NTEL
1694  print $soc->phone.$separator;
1695  //TLEX
1696  print $separator;
1697  //TLPO
1698  print $separator;
1699  //TLCY
1700  print $separator;
1701  //NINT
1702  print $separator;
1703  //COMM
1704  print $separator;
1705  //SIRE
1706  print str_replace(" ", "", $soc->siret).$separator;
1707  //RIBP
1708  print $separator;
1709  //DOBQ
1710  print $separator;
1711  //IBBQ
1712  print $separator;
1713  //COBQ
1714  print $separator;
1715  //GUBQ
1716  print $separator;
1717  //CPBQ
1718  print $separator;
1719  //CLBQ
1720  print $separator;
1721  //BIBQ
1722  print $separator;
1723  //MOPM
1724  print $separator;
1725  //DJPM
1726  print $separator;
1727  //DMPM
1728  print $separator;
1729  //REFM
1730  print $separator;
1731  //SLVA
1732  print $separator;
1733  //PLCR
1734  print $separator;
1735  //ECFI
1736  print $separator;
1737  //CREP
1738  print $separator;
1739  //NREP
1740  print $separator;
1741  //TREP
1742  print $separator;
1743  //MREP
1744  print $separator;
1745  //GRRE
1746  print $separator;
1747  //LTTA
1748  print $separator;
1749  //CACT
1750  print $separator;
1751  //CODV
1752  print $separator;
1753  //GRTR
1754  print $separator;
1755  //NOFP
1756  print $separator;
1757  //BQAF
1758  print $separator;
1759  //BONP
1760  print $separator;
1761  //CESC
1762  print $separator;
1763 
1764  print $end_line;
1765  }
1766  }
1767 
1768  $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1769  $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1770  $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1771 
1772  // TYPE E
1773  $type_enregistrement = 'E'; // For write movement
1774  print $type_enregistrement.$separator;
1775  // JNAL
1776  print substr($line->code_journal, 0, 2).$separator;
1777  // NECR
1778  print $line->id.$separator;
1779  // NPIE
1780  print $line->piece_num.$separator;
1781  // DATP
1782  print $date_document.$separator;
1783  // LIBE
1784  print dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1).$separator;
1785  // DATH
1786  print $date_lim_reglement.$separator;
1787  // CNPI
1788  if ($line->doc_type == 'supplier_invoice') {
1789  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.
1790  $nature_piece = 'AF';
1791  } else {
1792  $nature_piece = 'FF';
1793  }
1794  } elseif ($line->doc_type == 'customer_invoice') {
1795  if (($line->amount) < 0) {
1796  $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.
1797  } else {
1798  $nature_piece = 'FC';
1799  }
1800  } else {
1801  $nature_piece = '';
1802  }
1803  print $nature_piece.$separator;
1804  // RACI
1805  // if (!empty($line->subledger_account)) {
1806  // if ($line->doc_type == 'supplier_invoice') {
1807  // $racine_subledger_account = '40';
1808  // } elseif ($line->doc_type == 'customer_invoice') {
1809  // $racine_subledger_account = '41';
1810  // } else {
1811  // $racine_subledger_account = '';
1812  // }
1813  // } else {
1814  $racine_subledger_account = ''; // for records of type E leave this field blank
1815  // }
1816 
1817  print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
1818  // MONT
1819  print price(abs($line->debit - $line->credit), 0, '', 1, 2).$separator;
1820  // CODC
1821  print $line->sens.$separator;
1822  // CPTG
1823  print length_accountg($line->numero_compte).$separator;
1824  // DATE
1825  print $date_document.$separator;
1826  // CLET
1827  print $line->lettering_code.$separator;
1828  // DATL
1829  print $line->date_lettering.$separator;
1830  // CPTA
1831  if (!empty($line->subledger_account)) {
1832  print length_accounta($line->subledger_account).$separator;
1833  } else {
1834  print $separator;
1835  }
1836  // CNAT
1837  if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
1838  print 'F'.$separator;
1839  } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
1840  print 'C'.$separator;
1841  } else {
1842  print $separator;
1843  }
1844  // CTRE
1845  print $separator;
1846  // NORL
1847  print $separator;
1848  // DATV
1849  print $separator;
1850  // REFD
1851  print $line->doc_ref.$separator;
1852  // NECA
1853  print '0'.$separator;
1854  // CSEC
1855  print $separator;
1856  // CAFF
1857  print $separator;
1858  // CDES
1859  print $separator;
1860  // QTUE
1861  print $separator;
1862  // MTDV
1863  print '0'.$separator;
1864  // CODV
1865  print $separator;
1866  // TXDV
1867  print '0'.$separator;
1868  // MOPM
1869  print $separator;
1870  // BONP
1871  print $separator;
1872  // BQAF
1873  print $separator;
1874  // ECES
1875  print $separator;
1876  // TXTL
1877  print $separator;
1878  // ECRM
1879  print $separator;
1880  // DATK
1881  print $separator;
1882  // HEUK
1883  print $separator;
1884 
1885  print $end_line;
1886 
1887  $last_codeinvoice = $line->doc_ref;
1888  }
1889  }
1890 
1897  public function exportCharlemagne($objectLines)
1898  {
1899  global $langs;
1900  $langs->load('compta');
1901 
1902  $separator = "\t";
1903  $end_line = "\n";
1904 
1905  /*
1906  * Charlemagne export need header
1907  */
1908  print $langs->transnoentitiesnoconv('Date').$separator;
1909  print self::trunc($langs->transnoentitiesnoconv('Journal'), 6).$separator;
1910  print self::trunc($langs->transnoentitiesnoconv('Account'), 15).$separator;
1911  print self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60).$separator;
1912  print self::trunc($langs->transnoentitiesnoconv('Piece'), 20).$separator;
1913  print self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60).$separator;
1914  print $langs->transnoentitiesnoconv('Amount').$separator;
1915  print 'S'.$separator;
1916  print self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15).$separator;
1917  print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60).$separator;
1918  print self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15).$separator;
1919  print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60).$separator;
1920  print self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15).$separator;
1921  print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60).$separator;
1922  print $end_line;
1923 
1924  foreach ($objectLines as $line) {
1925  $date = dol_print_date($line->doc_date, '%Y%m%d');
1926  print $date.$separator; //Date
1927 
1928  print self::trunc($line->code_journal, 6).$separator; //Journal code
1929 
1930  if (!empty($line->subledger_account)) {
1931  $account = $line->subledger_account;
1932  } else {
1933  $account = $line->numero_compte;
1934  }
1935  print self::trunc($account, 15).$separator; //Account number
1936 
1937  print self::trunc($line->label_compte, 60).$separator; //Account label
1938  print self::trunc($line->doc_ref, 20).$separator; //Piece
1939  // Clean label operation to prevent problem on export with tab separator & other character
1940  $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1941  print self::trunc($line->label_operation, 60).$separator; //Operation label
1942  print price(abs($line->debit - $line->credit)).$separator; //Amount
1943  print $line->sens.$separator; //Direction
1944  print $separator; //Analytic
1945  print $separator; //Analytic
1946  print $separator; //Analytic
1947  print $separator; //Analytic
1948  print $separator; //Analytic
1949  print $separator; //Analytic
1950  print $end_line;
1951  }
1952  }
1953 
1961  public function exportGestimumV3($objectLines)
1962  {
1963  global $langs;
1964 
1965  $this->separator = ',';
1966 
1967  $invoices_infos = array();
1968  $supplier_invoices_infos = array();
1969  foreach ($objectLines as $line) {
1970  if ($line->debit == 0 && $line->credit == 0) {
1971  //unset($array[$line]);
1972  } else {
1973  $date = dol_print_date($line->doc_date, '%d/%m/%Y');
1974 
1975  $invoice_ref = $line->doc_ref;
1976  $company_name = "";
1977 
1978  if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
1979  if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
1980  ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
1981  if ($line->doc_type == 'customer_invoice') {
1982  // Get new customer invoice ref and company name
1983  $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
1984  $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
1985  $sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
1986  $resql = $this->db->query($sql);
1987  if ($resql) {
1988  if ($obj = $this->db->fetch_object($resql)) {
1989  // Save invoice infos
1990  $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
1991  $invoice_ref = $obj->ref;
1992  $company_name = $obj->nom;
1993  }
1994  }
1995  } else {
1996  // Get new supplier invoice ref and company name
1997  $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
1998  $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
1999  $sql .= ' WHERE ff.rowid = '.((int) $line->fk_doc);
2000  $resql = $this->db->query($sql);
2001  if ($resql) {
2002  if ($obj = $this->db->fetch_object($resql)) {
2003  // Save invoice infos
2004  $supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2005  $invoice_ref = $obj->ref;
2006  $company_name = $obj->nom;
2007  }
2008  }
2009  }
2010  } elseif ($line->doc_type == 'customer_invoice') {
2011  // Retrieve invoice infos
2012  $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
2013  $company_name = $invoices_infos[$line->fk_doc]['company_name'];
2014  } else {
2015  // Retrieve invoice infos
2016  $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
2017  $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
2018  }
2019  }
2020 
2021  print $line->id . $this->separator;
2022  print $date . $this->separator;
2023  print substr($line->code_journal, 0, 4) . $this->separator;
2024 
2025  if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
2026  print length_accountg($line->subledger_account) . $this->separator;
2027  } else {
2028  print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator;
2029  }
2030  //Libellé Auto
2031  print $this->separator;
2032  //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator;
2033  //Libellé manuel
2034  print dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1) . $this->separator;
2035  //Numéro de pièce
2036  print dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . $this->separator;
2037  //Devise
2038  print 'EUR' . $this->separator;
2039  //Amount
2040  print price2num(abs($line->debit - $line->credit)) . $this->separator;
2041  //Sens
2042  print $line->sens . $this->separator;
2043  //Code lettrage
2044  print $this->separator;
2045  //Date Echéance
2046  print $date;
2047  print $this->end_line;
2048  }
2049  }
2050  }
2051 
2059  public function exportGestimumV5($objectLines)
2060  {
2061 
2062  $this->separator = ',';
2063 
2064  foreach ($objectLines as $line) {
2065  if ($line->debit == 0 && $line->credit == 0) {
2066  //unset($array[$line]);
2067  } else {
2068  $date = dol_print_date($line->doc_date, '%d%m%Y');
2069 
2070  print $line->id . $this->separator;
2071  print $date . $this->separator;
2072  print substr($line->code_journal, 0, 4) . $this->separator;
2073  if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
2074  print length_accountg($line->subledger_account) . $this->separator;
2075  } else {
2076  print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator;
2077  }
2078  print $this->separator;
2079  //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator;
2080  print '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"' . $this->separator;
2081  print '"' . dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . '"' . $this->separator;
2082  print price2num(abs($line->debit - $line->credit)) . $this->separator;
2083  print $line->sens . $this->separator;
2084  print $date . $this->separator;
2085  print $this->separator;
2086  print $this->separator;
2087  print 'EUR';
2088  print $this->end_line;
2089  }
2090  }
2091  }
2092 
2102  public function exportiSuiteExpert($objectLines)
2103  {
2104  $this->separator = ';';
2105  $this->end_line = "\r\n";
2106 
2107 
2108  foreach ($objectLines as $line) {
2109  $tab = array();
2110 
2111  $date = dol_print_date($line->doc_date, '%d/%m/%Y');
2112 
2113  $tab[] = $line->piece_num;
2114  $tab[] = $date;
2115  $tab[] = substr($date, 6, 4);
2116  $tab[] = substr($date, 3, 2);
2117  $tab[] = substr($date, 0, 2);
2118  $tab[] = $line->doc_ref;
2119  //Conversion de chaine UTF8 en Latin9
2120  $tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
2121 
2122  //Calcul de la longueur des numéros de comptes
2123  $taille_numero = strlen(length_accountg($line->numero_compte));
2124 
2125  //Création du numéro de client générique
2126  $numero_cpt_client = '411';
2127  for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2128  $numero_cpt_client .= '0';
2129  }
2130 
2131  //Création des comptes auxiliaire des clients
2132  if (length_accountg($line->numero_compte) == $numero_cpt_client) {
2133  $tab[] = rtrim(length_accounta($line->subledger_account), "0");
2134  } else {
2135  $tab[] = length_accountg($line->numero_compte);
2136  }
2137  $nom_client = explode(" - ", $line->label_operation);
2138  $tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
2139  $tab[] = price($line->debit);
2140  $tab[] = price($line->credit);
2141  $tab[] = price($line->montant);
2142  $tab[] = $line->code_journal;
2143 
2144  $separator = $this->separator;
2145  print implode($separator, $tab) . $this->end_line;
2146  }
2147  }
2148 
2156  public static function trunc($str, $size)
2157  {
2158  return dol_trunc($str, $size, 'right', 'UTF-8', 1);
2159  }
2160 
2168  public static function toAnsi($str, $size = -1)
2169  {
2170  $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
2171  if ($retVal >= 0 && $size >= 0) {
2172  $retVal = mb_substr($retVal, 0, $size, 'Windows-1251');
2173  }
2174  return $retVal;
2175  }
2176 }
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.
exportAgiris($objectLines)
Export format : Agiris Isacompta.
exportWinfic(&$TData)
Export format : WinFic - eWinfic - WinSis Compta Last review for this format : 2022-11-01 Alexandre S...
exportEbp($objectLines)
Export format : EBP.
exportCiel(&$TData)
Export format : CIEL (Format XIMPORT) Format since 2003 compatible CIEL version > 2002 / Sage50 Last ...
getTypeConfig()
Array with all export type available (key + label) and parameters for config.
exportBob50($objectLines)
Export format : BOB50.
exportGestimumV5($objectLines)
Export format : Gestimum V5.
static trunc($str, $size)
trunc
exportLDCompta10($objectLines)
Export format : LD Compta version 10 & higher Last review for this format : 08-15-2021 Alexandre Span...
exportConfigurable($objectLines)
Export format : Configurable CSV.
exportCegid($objectLines)
Export format : CEGID.
static toAnsi($str, $size=-1)
toAnsi
getType()
Array with all export type available (key + label)
export(&$TData, $formatexportset, $withAttachment=0)
Function who chose which export to use with the default config, and make the export into a file.
static getFormatCode($type)
Return string to summarize the format (Used to generated export filename)
exportLDCompta($objectLines)
Export format : LD Compta version 9 http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Docu...
exportCoala($objectLines)
Export format : COALA.
exportCogilog($objectLines)
Export format : COGILOG.
exportCharlemagne($objectLines)
Export format : Charlemagne.
exportFEC($objectLines)
Export format : FEC.
exportFEC2($objectLines)
Export format : FEC2.
__construct(DoliDB $db)
Constructor.
getMimeType($formatexportset)
Return the MIME type of a file.
exportSAGE50SWISS($objectLines)
Export format : SAGE50SWISS.
exportGestimumV3($objectLines)
Export format : Gestimum V3.
exportQuadratus(&$TData, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : Quadratus (Format ASCII) Format since 2015 compatible QuadraCOMPTA Last review for th...
exportiSuiteExpert($objectLines)
Export format : iSuite Expert.
exportOpenConcerto($objectLines)
Export format : OpenConcerto.
Class to manage Dolibarr database access.
Class to manage suppliers invoices.
Class to manage invoices.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_filesize($pathoffile)
Return size of a file.
Definition: files.lib.php:584
dol_dir_list($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:61
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_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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $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.
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.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1436
$conf db
API class for accounts.
Definition: inc.php:41