dolibarr  18.0.0-alpha
accountancyexport.class.php
Go to the documentation of this file.
1 <?php
2 /*
3  * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
6  * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7  * Copyright (C) 2016 Pierre-Henry Favre <phf@atm-consulting.fr>
8  * Copyright (C) 2016-2023 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' => getDolGlobalString('ACCOUNTING_EXPORT_DATE', '%Y-%m-%d'),
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  // Clean some data
707  $data->doc_ref = dol_string_unaccent($data->doc_ref);
708  $data->label_operation = dol_string_unaccent($data->label_operation);
709  $data->numero_compte = dol_string_unaccent($data->numero_compte);
710  $data->label_compte = dol_string_unaccent($data->label_compte);
711  $data->subledger_account = dol_string_unaccent($data->subledger_account);
712  $data->subledger_label = dol_string_unaccent($data->subledger_label);
713 
714  $code_compta = $data->numero_compte;
715  if (!empty($data->subledger_account)) {
716  $code_compta = $data->subledger_account;
717  }
718 
719  $Tab = array();
720 
721  if (!empty($data->subledger_account)) {
722  $Tab['type_ligne'] = 'C';
723  $Tab['num_compte'] = str_pad(self::trunc($data->subledger_account, 8), 8);
724  $Tab['lib_compte'] = str_pad(self::trunc($data->subledger_label, 30), 30);
725 
726  if ($data->doc_type == 'customer_invoice') {
727  $Tab['lib_alpha'] = strtoupper(str_pad('C'.self::trunc($data->subledger_label, 6), 6));
728  $Tab['filler'] = str_repeat(' ', 52);
729  $Tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, 8), 8);
730  } elseif ($data->doc_type == 'supplier_invoice') {
731  $Tab['lib_alpha'] = strtoupper(str_pad('F'.self::trunc($data->subledger_label, 6), 6));
732  $Tab['filler'] = str_repeat(' ', 52);
733  $Tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, 8), 8);
734  } else {
735  $Tab['filler'] = str_repeat(' ', 59);
736  $Tab['coll_compte'] = str_pad(' ', 8);
737  }
738 
739  $Tab['filler2'] = str_repeat(' ', 110);
740  $Tab['Maj'] = 2; // Partial update (alpha key, label, address, collectif, RIB)
741 
742  if ($data->doc_type == 'customer_invoice') {
743  $Tab['type_compte'] = 'C';
744  } elseif ($data->doc_type == 'supplier_invoice') {
745  $Tab['type_compte'] = 'F';
746  } else {
747  $Tab['type_compte'] = 'G';
748  }
749 
750  $Tab['filler3'] = str_repeat(' ', 235);
751 
752  $Tab['end_line'] = $end_line;
753 
754  if ($exportFile) {
755  fwrite($exportFile, implode($Tab));
756  } else {
757  print implode($Tab);
758  }
759  }
760 
761  $Tab = array();
762  $Tab['type_ligne'] = 'M';
763  $Tab['num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
764  $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
765  $Tab['folio'] = '000';
766 
767  // We use invoice date $data->doc_date not $date_ecriture which is the transfert date
768  // maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
769  //$Tab['date_ecriture'] = $date_ecriture;
770  $Tab['date_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
771  $Tab['filler'] = ' ';
772  $Tab['libelle_ecriture'] = str_pad(self::trunc($data->doc_ref.' '.$data->label_operation, 20), 20);
773 
774  // Credit invoice - invert sens
775  /*
776  if ($data->montant < 0) {
777  if ($data->sens == 'C') {
778  $Tab['sens'] = 'D';
779  } else {
780  $Tab['sens'] = 'C';
781  }
782  $Tab['signe_montant'] = '-';
783  } else {
784  $Tab['sens'] = $data->sens; // C or D
785  $Tab['signe_montant'] = '+';
786  }*/
787  $Tab['sens'] = $data->sens; // C or D
788  $Tab['signe_montant'] = '+';
789 
790  // The amount must be in centimes without decimal points.
791  $Tab['montant'] = str_pad(abs(($data->debit - $data->credit) * 100), 12, '0', STR_PAD_LEFT);
792  $Tab['contrepartie'] = str_repeat(' ', 8);
793 
794  // Force date format : %d%m%y
795  if (!empty($data->date_lim_reglement)) {
796  //$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE);
797  $Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, '%d%m%y'); // Format must be ddmmyy
798  } else {
799  $Tab['date_echeance'] = '000000';
800  }
801 
802  // Please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
803  // $Tab['lettrage'] = str_repeat(' ', 5);
804  $Tab['lettrage'] = str_repeat(' ', 2);
805  $Tab['codestat'] = str_repeat(' ', 3);
806  $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 5), 5);
807 
808  // Keep correct quadra named field instead of anon filler
809  // $Tab['filler2'] = str_repeat(' ', 20);
810  $Tab['affaire'] = str_repeat(' ', 10);
811  $Tab['quantity1'] = str_repeat(' ', 10);
812  $Tab['num_piece2'] = str_pad(self::trunc($data->piece_num, 8), 8);
813  $Tab['devis'] = str_pad($conf->currency, 3);
814  $Tab['code_journal2'] = str_pad(self::trunc($data->code_journal, 3), 3);
815  $Tab['filler3'] = str_repeat(' ', 3);
816 
817  // Keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
818  // 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
819  // TODO: we should filter more than only accent to avoid wrong line size
820  // TODO: remove invoice number doc_ref in libelle,
821  // TODO: we should offer an option for customer to build the libelle using invoice number / name / date in accounting software
822  //$Tab['libelle_ecriture2'] = str_pad(self::trunc($data->doc_ref . ' ' . $data->label_operation, 30), 30);
823  $Tab['libelle_ecriture2'] = str_pad(self::trunc($data->label_operation, 30), 30);
824  $Tab['codetva'] = str_repeat(' ', 2);
825 
826  // We need to keep the 10 lastest number of invoice doc_ref not the beginning part that is the unusefull almost same part
827  // $Tab['num_piece3'] = str_pad(self::trunc($data->piece_num, 10), 10);
828  $Tab['num_piece3'] = substr(self::trunc($data->doc_ref, 20), -10);
829  $Tab['reserved'] = str_repeat(' ', 10); // position 159
830  $Tab['currency_amount'] = str_repeat(' ', 13); // position 169
831  // get document file
832  $attachmentFileName = '';
833  if ($withAttachment == 1) {
834  $attachmentFileKey = trim($data->piece_num);
835 
836  if (!isset($archiveFileList[$attachmentFileKey])) {
837  $objectDirPath = '';
838  $objectFileName = dol_sanitizeFileName($data->doc_ref);
839  if ($data->doc_type == 'customer_invoice') {
840  $objectDirPath = !empty($conf->facture->multidir_output[$conf->entity]) ? $conf->facture->multidir_output[$conf->entity] : $conf->facture->dir_output;
841  } elseif ($data->doc_type == 'expense_report') {
842  $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->factureexpensereport->dir_output;
843  } elseif ($data->doc_type == 'supplier_invoice') {
844  $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
845  }
846  $arrayofinclusion = array();
847  $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').'\.pdf$';
848  $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, true);
849  if (!empty($fileFoundList)) {
850  $attachmentFileNameTrunc = str_pad(self::trunc($data->piece_num, 8), 8, '0', STR_PAD_LEFT);
851  foreach ($fileFoundList as $fileFound) {
852  if (strstr($fileFound['name'], $objectFileName)) {
853  $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
854  if (file_exists($fileFoundPath)) {
855  $archiveFileList[$attachmentFileKey] = array(
856  'path' => $fileFoundPath,
857  'name' => $attachmentFileNameTrunc.'.pdf',
858  );
859  break;
860  }
861  }
862  }
863  }
864  }
865 
866  if (isset($archiveFileList[$attachmentFileKey])) {
867  $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
868  }
869  }
870  if (dol_strlen($attachmentFileName) == 12) {
871  $Tab['attachment'] = $attachmentFileName; // position 182
872  } else {
873  $Tab['attachment'] = str_repeat(' ', 12); // position 182
874  }
875  $Tab['filler4'] = str_repeat(' ', 38);
876  $Tab['end_line'] = $end_line;
877 
878  if ($exportFile) {
879  fwrite($exportFile, implode($Tab));
880  } else {
881  print implode($Tab);
882  }
883  }
884 
885  return $archiveFileList;
886  }
887 
898  public function exportWinfic(&$TData)
899  {
900  global $conf;
901 
902  $end_line = "\r\n";
903  $index = 1;
904 
905  //We should use dol_now function not time however this is wrong date to transfert in accounting
906  //$date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
907  //$date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
908 
909  // Warning ! When truncation is necessary, no dot because 3 dots = three characters. The columns are shifted
910 
911  foreach ($TData as $data) {
912  $code_compta = $data->numero_compte;
913  if (!empty($data->subledger_account)) {
914  $code_compta = $data->subledger_account;
915  }
916 
917  $Tab = array();
918  //$Tab['type_ligne'] = 'M';
919  $Tab['code_journal'] = str_pad(dol_trunc($data->code_journal, 2, 'right', 'UTF-8', 1), 2);
920 
921  //We use invoice date $data->doc_date not $date_ecriture which is the transfert date
922  //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
923  //$Tab['date_ecriture'] = $date_ecriture;
924  $Tab['date_operation'] = dol_print_date($data->doc_date, '%d%m%Y');
925 
926  $Tab['folio'] = ' 1';
927 
928  $Tab['num_ecriture'] = str_pad(dol_trunc($index, 6, 'right', 'UTF-8', 1), 6, ' ', STR_PAD_LEFT);
929 
930  $Tab['jour_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
931 
932  $Tab['num_compte'] = str_pad(dol_trunc($code_compta, 6, 'right', 'UTF-8', 1), 6, '0');
933 
934  if ($data->sens == 'D') {
935  $Tab['montant_debit'] = str_pad(number_format($data->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
936 
937  $Tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
938  } else {
939  $Tab['montant_debit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
940 
941  $Tab['montant_crebit'] = str_pad(number_format($data->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
942  }
943 
944  $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);
945 
946  $Tab['lettrage'] = str_repeat(dol_trunc($data->lettering_code, 2, 'left', 'UTF-8', 1), 2);
947 
948  $Tab['code_piece'] = str_pad(dol_trunc($data->piece_num, 5, 'left', 'UTF-8', 1), 5, ' ', STR_PAD_LEFT);
949 
950  $Tab['code_stat'] = str_repeat(' ', 4);
951 
952  if (!empty($data->date_lim_reglement)) {
953  //$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE);
954  $Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, '%d%m%Y');
955  } else {
956  $Tab['date_echeance'] = dol_print_date($data->doc_date, '%d%m%Y');
957  }
958 
959  $Tab['monnaie'] = '1';
960 
961  $Tab['filler'] = ' ';
962 
963  $Tab['ind_compteur'] = ' ';
964 
965  $Tab['quantite'] = '0,000000000';
966 
967  $Tab['code_pointage'] = str_repeat(' ', 2);
968 
969  $Tab['end_line'] = $end_line;
970 
971  print implode('|', $Tab);
972 
973  $index++;
974  }
975  }
976 
977 
984  public function exportEbp($objectLines)
985  {
986 
987  $separator = ',';
988  $end_line = "\n";
989 
990  foreach ($objectLines as $line) {
991  $date = dol_print_date($line->doc_date, '%d%m%Y');
992 
993  print $line->id.$separator;
994  print $date.$separator;
995  print $line->code_journal.$separator;
996  if (empty($line->subledger_account)) {
997  print $line->numero_compte.$separator;
998  } else {
999  print $line->subledger_account.$separator;
1000  }
1001  //print substr(length_accountg($line->numero_compte), 0, 2) . $separator;
1002  print '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"'.$separator;
1003  print '"'.dol_trunc($line->piece_num, 15, 'right', 'UTF-8', 1).'"'.$separator;
1004  print price2num(abs($line->debit - $line->credit)).$separator;
1005  print $line->sens.$separator;
1006  print $date.$separator;
1007  //print 'EUR';
1008  print $end_line;
1009  }
1010  }
1011 
1012 
1019  public function exportAgiris($objectLines)
1020  {
1021 
1022  $separator = ';';
1023  $end_line = "\n";
1024 
1025  foreach ($objectLines as $line) {
1026  $date = dol_print_date($line->doc_date, '%d%m%Y');
1027 
1028  print $line->piece_num.$separator;
1029  print self::toAnsi($line->label_operation).$separator;
1030  print $date.$separator;
1031  print self::toAnsi($line->label_operation).$separator;
1032 
1033  if (empty($line->subledger_account)) {
1034  print length_accountg($line->numero_compte).$separator;
1035  print self::toAnsi($line->label_compte).$separator;
1036  } else {
1037  print length_accounta($line->subledger_account).$separator;
1038  print self::toAnsi($line->subledger_label).$separator;
1039  }
1040 
1041  print self::toAnsi($line->doc_ref).$separator;
1042  print price($line->debit).$separator;
1043  print price($line->credit).$separator;
1044  print price(abs($line->debit - $line->credit)).$separator;
1045  print $line->sens.$separator;
1046  print $line->lettering_code.$separator;
1047  print $line->code_journal;
1048  print $end_line;
1049  }
1050  }
1051 
1058  public function exportOpenConcerto($objectLines)
1059  {
1060 
1061  $separator = ';';
1062  $end_line = "\n";
1063 
1064  foreach ($objectLines as $line) {
1065  $date = dol_print_date($line->doc_date, '%d/%m/%Y');
1066 
1067  print $date.$separator;
1068  print $line->code_journal.$separator;
1069  if (empty($line->subledger_account)) {
1070  print length_accountg($line->numero_compte).$separator;
1071  } else {
1072  print length_accounta($line->subledger_account).$separator;
1073  }
1074  print $line->doc_ref.$separator;
1075  print $line->label_operation.$separator;
1076  print price($line->debit).$separator;
1077  print price($line->credit).$separator;
1078 
1079  print $end_line;
1080  }
1081  }
1082 
1089  public function exportConfigurable($objectLines)
1090  {
1091  global $conf;
1092 
1093  $separator = $this->separator;
1094 
1095  foreach ($objectLines as $line) {
1096  $tab = array();
1097  // export configurable
1098  $date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
1099  $tab[] = $line->piece_num;
1100  $tab[] = $date;
1101  $tab[] = $line->doc_ref;
1102  $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
1103  $tab[] = length_accountg($line->numero_compte);
1104  $tab[] = length_accounta($line->subledger_account);
1105  $tab[] = price2num($line->debit);
1106  $tab[] = price2num($line->credit);
1107  $tab[] = price2num($line->debit - $line->credit);
1108  $tab[] = $line->code_journal;
1109 
1110  print implode($separator, $tab).$this->end_line;
1111  }
1112  }
1113 
1120  public function exportFEC($objectLines)
1121  {
1122  global $langs;
1123 
1124  $separator = "\t";
1125  $end_line = "\r\n";
1126 
1127  print "JournalCode".$separator;
1128  print "JournalLib".$separator;
1129  print "EcritureNum".$separator;
1130  print "EcritureDate".$separator;
1131  print "CompteNum".$separator;
1132  print "CompteLib".$separator;
1133  print "CompAuxNum".$separator;
1134  print "CompAuxLib".$separator;
1135  print "PieceRef".$separator;
1136  print "PieceDate".$separator;
1137  print "EcritureLib".$separator;
1138  print "Debit".$separator;
1139  print "Credit".$separator;
1140  print "EcritureLet".$separator;
1141  print "DateLet".$separator;
1142  print "ValidDate".$separator;
1143  print "Montantdevise".$separator;
1144  print "Idevise".$separator;
1145  print "DateLimitReglmt".$separator;
1146  print "NumFacture";
1147  print $end_line;
1148 
1149  foreach ($objectLines as $line) {
1150  if ($line->debit == 0 && $line->credit == 0) {
1151  //unset($array[$line]);
1152  } else {
1153  $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1154  $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1155  $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1156  $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1157  $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1158 
1159  $refInvoice = '';
1160  if ($line->doc_type == 'customer_invoice') {
1161  // Customer invoice
1162  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1163  $invoice = new Facture($this->db);
1164  $invoice->fetch($line->fk_doc);
1165 
1166  $refInvoice = $invoice->ref;
1167  } elseif ($line->doc_type == 'supplier_invoice') {
1168  // Supplier invoice
1169  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1170  $invoice = new FactureFournisseur($this->db);
1171  $invoice->fetch($line->fk_doc);
1172 
1173  $refInvoice = $invoice->ref_supplier;
1174  }
1175 
1176  // FEC:JournalCode
1177  print $line->code_journal . $separator;
1178 
1179  // FEC:JournalLib
1180  $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1181  $labeljournal = dol_string_nospecial($labeljournal, ' ');
1182  print $labeljournal . $separator;
1183 
1184  // FEC:EcritureNum
1185  print $line->piece_num . $separator;
1186 
1187  // FEC:EcritureDate
1188  print $date_document . $separator;
1189 
1190  // FEC:CompteNum
1191  print $line->numero_compte . $separator;
1192 
1193  // FEC:CompteLib
1194  print dol_string_unaccent($line->label_compte) . $separator;
1195 
1196  // FEC:CompAuxNum
1197  print $line->subledger_account . $separator;
1198 
1199  // FEC:CompAuxLib
1200  print dol_string_unaccent($line->subledger_label) . $separator;
1201 
1202  // FEC:PieceRef
1203  print $line->doc_ref . $separator;
1204 
1205  // FEC:PieceDate
1206  print dol_string_unaccent($date_creation) . $separator;
1207 
1208  // FEC:EcritureLib
1209  // Clean label operation to prevent problem on export with tab separator & other character
1210  $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1211  print dol_string_unaccent($line->label_operation) . $separator;
1212 
1213  // FEC:Debit
1214  print price2fec($line->debit) . $separator;
1215 
1216  // FEC:Credit
1217  print price2fec($line->credit) . $separator;
1218 
1219  // FEC:EcritureLet
1220  print $line->lettering_code . $separator;
1221 
1222  // FEC:DateLet
1223  print $date_lettering . $separator;
1224 
1225  // FEC:ValidDate
1226  print $date_validation . $separator;
1227 
1228  // FEC:Montantdevise
1229  print $line->multicurrency_amount . $separator;
1230 
1231  // FEC:Idevise
1232  print $line->multicurrency_code . $separator;
1233 
1234  // FEC_suppl:DateLimitReglmt
1235  print $date_limit_payment . $separator;
1236 
1237  // FEC_suppl:NumFacture
1238  // Clean ref invoice to prevent problem on export with tab separator & other character
1239  $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1240  print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1241 
1242  print $end_line;
1243  }
1244  }
1245  }
1246 
1253  public function exportFEC2($objectLines)
1254  {
1255  global $langs;
1256 
1257  $separator = "\t";
1258  $end_line = "\r\n";
1259 
1260  print "JournalCode".$separator;
1261  print "JournalLib".$separator;
1262  print "EcritureNum".$separator;
1263  print "EcritureDate".$separator;
1264  print "CompteNum".$separator;
1265  print "CompteLib".$separator;
1266  print "CompAuxNum".$separator;
1267  print "CompAuxLib".$separator;
1268  print "PieceRef".$separator;
1269  print "PieceDate".$separator;
1270  print "EcritureLib".$separator;
1271  print "Debit".$separator;
1272  print "Credit".$separator;
1273  print "EcritureLet".$separator;
1274  print "DateLet".$separator;
1275  print "ValidDate".$separator;
1276  print "Montantdevise".$separator;
1277  print "Idevise".$separator;
1278  print "DateLimitReglmt".$separator;
1279  print "NumFacture";
1280  print $end_line;
1281 
1282  foreach ($objectLines as $line) {
1283  if ($line->debit == 0 && $line->credit == 0) {
1284  //unset($array[$line]);
1285  } else {
1286  $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1287  $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1288  $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1289  $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
1290  $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1291 
1292  $refInvoice = '';
1293  if ($line->doc_type == 'customer_invoice') {
1294  // Customer invoice
1295  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1296  $invoice = new Facture($this->db);
1297  $invoice->fetch($line->fk_doc);
1298 
1299  $refInvoice = $invoice->ref;
1300  } elseif ($line->doc_type == 'supplier_invoice') {
1301  // Supplier invoice
1302  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
1303  $invoice = new FactureFournisseur($this->db);
1304  $invoice->fetch($line->fk_doc);
1305 
1306  $refInvoice = $invoice->ref_supplier;
1307  }
1308 
1309  // FEC:JournalCode
1310  print $line->code_journal . $separator;
1311 
1312  // FEC:JournalLib
1313  $labeljournal = dol_string_unaccent($langs->transnoentities($line->journal_label));
1314  $labeljournal = dol_string_nospecial($labeljournal, ' ');
1315  print $labeljournal . $separator;
1316 
1317  // FEC:EcritureNum
1318  print $line->piece_num . $separator;
1319 
1320  // FEC:EcritureDate
1321  print $date_creation . $separator;
1322 
1323  // FEC:CompteNum
1324  print length_accountg($line->numero_compte) . $separator;
1325 
1326  // FEC:CompteLib
1327  print dol_string_unaccent($line->label_compte) . $separator;
1328 
1329  // FEC:CompAuxNum
1330  print length_accounta($line->subledger_account) . $separator;
1331 
1332  // FEC:CompAuxLib
1333  print dol_string_unaccent($line->subledger_label) . $separator;
1334 
1335  // FEC:PieceRef
1336  print $line->doc_ref . $separator;
1337 
1338  // FEC:PieceDate
1339  print $date_document . $separator;
1340 
1341  // FEC:EcritureLib
1342  // Clean label operation to prevent problem on export with tab separator & other character
1343  $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1344  print dol_string_unaccent($line->label_operation) . $separator;
1345 
1346  // FEC:Debit
1347  print price2fec($line->debit) . $separator;
1348 
1349  // FEC:Credit
1350  print price2fec($line->credit) . $separator;
1351 
1352  // FEC:EcritureLet
1353  print $line->lettering_code . $separator;
1354 
1355  // FEC:DateLet
1356  print $date_lettering . $separator;
1357 
1358  // FEC:ValidDate
1359  print $date_validation . $separator;
1360 
1361  // FEC:Montantdevise
1362  print $line->multicurrency_amount . $separator;
1363 
1364  // FEC:Idevise
1365  print $line->multicurrency_code . $separator;
1366 
1367  // FEC_suppl:DateLimitReglmt
1368  print $date_limit_payment . $separator;
1369 
1370  // FEC_suppl:NumFacture
1371  // Clean ref invoice to prevent problem on export with tab separator & other character
1372  $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
1373  print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
1374 
1375 
1376  print $end_line;
1377  }
1378  }
1379  }
1380 
1391  public function exportSAGE50SWISS($objectLines)
1392  {
1393  // SAGE50SWISS
1394  $this->separator = ',';
1395  $this->end_line = "\r\n";
1396 
1397  // Print header line
1398  print "Blg,Datum,Kto,S/H,Grp,GKto,SId,SIdx,KIdx,BTyp,MTyp,Code,Netto,Steuer,FW-Betrag,Tx1,Tx2,PkKey,OpId,Flag";
1399  print $this->end_line;
1400  $thisPieceNum = "";
1401  $thisPieceAccountNr = "";
1402  $aSize = count($objectLines);
1403  foreach ($objectLines as $aIndex => $line) {
1404  $sammelBuchung = false;
1405  if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1406  $sammelBuchung = true;
1407  } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1408  $sammelBuchung = true;
1409  } elseif ($aIndex + 1 < $aSize
1410  && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1411  && $aIndex - 1 < $aSize
1412  && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1413  ) {
1414  $sammelBuchung = true;
1415  }
1416 
1417  //Blg
1418  print $line->piece_num.$this->separator;
1419 
1420  // Datum
1421  $date = dol_print_date($line->doc_date, '%d.%m.%Y');
1422  print $date.$this->separator;
1423 
1424  // Kto
1425  print length_accountg($line->numero_compte).$this->separator;
1426  // S/H
1427  if ($line->sens == 'D') {
1428  print 'S'.$this->separator;
1429  } else {
1430  print 'H'.$this->separator;
1431  }
1432  //Grp
1433  print self::trunc($line->code_journal, 1).$this->separator;
1434  // GKto
1435  if (empty($line->code_tiers)) {
1436  if ($line->piece_num == $thisPieceNum) {
1437  print length_accounta($thisPieceAccountNr).$this->separator;
1438  } else {
1439  print "div".$this->separator;
1440  }
1441  } else {
1442  print length_accounta($line->code_tiers).$this->separator;
1443  }
1444  //SId
1445  print $this->separator;
1446  //SIdx
1447  print "0".$this->separator;
1448  //KIdx
1449  print "0".$this->separator;
1450  //BTyp
1451  print "0".$this->separator;
1452 
1453  //MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
1454  if ($sammelBuchung) {
1455  print "2".$this->separator;
1456  } else {
1457  print "1".$this->separator;
1458  }
1459  // Code
1460  print '""'.$this->separator;
1461  // Netto
1462  print abs($line->debit - $line->credit).$this->separator;
1463  // Steuer
1464  print "0.00".$this->separator;
1465  // FW-Betrag
1466  print "0.00".$this->separator;
1467  // Tx1
1468  $line1 = self::toAnsi($line->label_compte, 29);
1469  if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
1470  $line1 = "";
1471  }
1472  $line2 = self::toAnsi($line->doc_ref, 29);
1473  if (strlen($line1) == 0) {
1474  $line1 = $line2;
1475  $line2 = "";
1476  }
1477  if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1478  $line1 = $line1.' / '.$line2;
1479  $line2 = "";
1480  }
1481 
1482  print '"'.self::toAnsi($line1).'"'.$this->separator;
1483  // Tx2
1484  print '"'.self::toAnsi($line2).'"'.$this->separator;
1485  //PkKey
1486  print "0".$this->separator;
1487  //OpId
1488  print $this->separator;
1489 
1490  // Flag
1491  print "0";
1492 
1493  print $this->end_line;
1494 
1495  if ($line->piece_num !== $thisPieceNum) {
1496  $thisPieceNum = $line->piece_num;
1497  $thisPieceAccountNr = $line->numero_compte;
1498  }
1499  }
1500  }
1501 
1510  public function exportLDCompta($objectLines)
1511  {
1512 
1513  $separator = ';';
1514  $end_line = "\r\n";
1515 
1516  foreach ($objectLines as $line) {
1517  $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1518  $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1519  $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1520 
1521  // TYPE
1522  $type_enregistrement = 'E'; // For write movement
1523  print $type_enregistrement.$separator;
1524  // JNAL
1525  print substr($line->code_journal, 0, 2).$separator;
1526  // NECR
1527  print $line->id.$separator;
1528  // NPIE
1529  print $line->piece_num.$separator;
1530  // DATP
1531  print $date_document.$separator;
1532  // LIBE
1533  print $line->label_operation.$separator;
1534  // DATH
1535  print $date_lim_reglement.$separator;
1536  // CNPI
1537  if ($line->doc_type == 'supplier_invoice') {
1538  if (($line->debit - $line->credit) > 0) {
1539  $nature_piece = 'AF';
1540  } else {
1541  $nature_piece = 'FF';
1542  }
1543  } elseif ($line->doc_type == 'customer_invoice') {
1544  if (($line->debit - $line->credit) < 0) {
1545  $nature_piece = 'AC';
1546  } else {
1547  $nature_piece = 'FC';
1548  }
1549  } else {
1550  $nature_piece = '';
1551  }
1552  print $nature_piece.$separator;
1553  // RACI
1554  // if (!empty($line->subledger_account)) {
1555  // if ($line->doc_type == 'supplier_invoice') {
1556  // $racine_subledger_account = '40';
1557  // } elseif ($line->doc_type == 'customer_invoice') {
1558  // $racine_subledger_account = '41';
1559  // } else {
1560  // $racine_subledger_account = '';
1561  // }
1562  // } else {
1563  $racine_subledger_account = ''; // for records of type E leave this field blank
1564  // }
1565 
1566  print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
1567  // MONT
1568  print price(abs($line->debit - $line->credit), 0, '', 1, 2, 2).$separator;
1569  // CODC
1570  print $line->sens.$separator;
1571  // CPTG
1572  print length_accountg($line->numero_compte).$separator;
1573  // DATE
1574  print $date_creation.$separator;
1575  // CLET
1576  print $line->lettering_code.$separator;
1577  // DATL
1578  print $line->date_lettering.$separator;
1579  // CPTA
1580  if (!empty($line->subledger_account)) {
1581  print length_accounta($line->subledger_account).$separator;
1582  } else {
1583  print $separator;
1584  }
1585  // CNAT
1586  if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
1587  print 'F'.$separator;
1588  } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
1589  print 'C'.$separator;
1590  } else {
1591  print $separator;
1592  }
1593  // SECT
1594  print $separator;
1595  // CTRE
1596  print $separator;
1597  // NORL
1598  print $separator;
1599  // DATV
1600  print $separator;
1601  // REFD
1602  print $line->doc_ref.$separator;
1603  // CODH
1604  print $separator;
1605  // NSEQ
1606  print $separator;
1607  // MTDV
1608  print '0'.$separator;
1609  // CODV
1610  print $separator;
1611  // TXDV
1612  print '0'.$separator;
1613  // MOPM
1614  print $separator;
1615  // BONP
1616  print $separator;
1617  // BQAF
1618  print $separator;
1619  // ECES
1620  print $separator;
1621  // TXTL
1622  print $separator;
1623  // ECRM
1624  print $separator;
1625  // DATK
1626  print $separator;
1627  // HEUK
1628  print $separator;
1629 
1630  print $end_line;
1631  }
1632  }
1633 
1644  public function exportLDCompta10($objectLines)
1645  {
1646  require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
1647 
1648  $separator = ';';
1649  $end_line = "\r\n";
1650  $last_codeinvoice = '';
1651 
1652  foreach ($objectLines as $line) {
1653  // TYPE C
1654  if ($last_codeinvoice != $line->doc_ref) {
1655  //recherche societe en fonction de son code client
1656  $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
1657  $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
1658  $resql = $this->db->query($sql);
1659 
1660  if ($resql && $this->db->num_rows($resql) > 0) {
1661  $soc = $this->db->fetch_object($resql);
1662 
1663  $address = array('', '', '');
1664  if (strpos($soc->address, "\n") !== false) {
1665  $address = explode("\n", $soc->address);
1666  if (is_array($address) && count($address) > 0) {
1667  foreach ($address as $key => $data) {
1668  $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
1669  $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
1670  }
1671  }
1672  } else {
1673  $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
1674  $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
1675  $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
1676  }
1677 
1678  $type_enregistrement = 'C';
1679  //TYPE
1680  print $type_enregistrement.$separator;
1681  //NOCL
1682  print $soc->code_client.$separator;
1683  //NMCM
1684  print $separator;
1685  //LIBI
1686  print $separator;
1687  //TITR
1688  print $separator;
1689  //RSSO
1690  print $soc->nom.$separator;
1691  //CAD1
1692  print $address[0].$separator;
1693  //CAD2
1694  print $address[1].$separator;
1695  //CAD3
1696  print $address[2].$separator;
1697  //COPO
1698  print $soc->zip.$separator;
1699  //BUDI
1700  print substr($soc->town, 0, 40).$separator;
1701  //CPAY
1702  print $separator;
1703  //PAYS
1704  print substr(getCountry($soc->fk_pays), 0, 40).$separator;
1705  //NTEL
1706  print $soc->phone.$separator;
1707  //TLEX
1708  print $separator;
1709  //TLPO
1710  print $separator;
1711  //TLCY
1712  print $separator;
1713  //NINT
1714  print $separator;
1715  //COMM
1716  print $separator;
1717  //SIRE
1718  print str_replace(" ", "", $soc->siret).$separator;
1719  //RIBP
1720  print $separator;
1721  //DOBQ
1722  print $separator;
1723  //IBBQ
1724  print $separator;
1725  //COBQ
1726  print $separator;
1727  //GUBQ
1728  print $separator;
1729  //CPBQ
1730  print $separator;
1731  //CLBQ
1732  print $separator;
1733  //BIBQ
1734  print $separator;
1735  //MOPM
1736  print $separator;
1737  //DJPM
1738  print $separator;
1739  //DMPM
1740  print $separator;
1741  //REFM
1742  print $separator;
1743  //SLVA
1744  print $separator;
1745  //PLCR
1746  print $separator;
1747  //ECFI
1748  print $separator;
1749  //CREP
1750  print $separator;
1751  //NREP
1752  print $separator;
1753  //TREP
1754  print $separator;
1755  //MREP
1756  print $separator;
1757  //GRRE
1758  print $separator;
1759  //LTTA
1760  print $separator;
1761  //CACT
1762  print $separator;
1763  //CODV
1764  print $separator;
1765  //GRTR
1766  print $separator;
1767  //NOFP
1768  print $separator;
1769  //BQAF
1770  print $separator;
1771  //BONP
1772  print $separator;
1773  //CESC
1774  print $separator;
1775 
1776  print $end_line;
1777  }
1778  }
1779 
1780  $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1781  $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1782  $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1783 
1784  // TYPE E
1785  $type_enregistrement = 'E'; // For write movement
1786  print $type_enregistrement.$separator;
1787  // JNAL
1788  print substr($line->code_journal, 0, 2).$separator;
1789  // NECR
1790  print $line->id.$separator;
1791  // NPIE
1792  print $line->piece_num.$separator;
1793  // DATP
1794  print $date_document.$separator;
1795  // LIBE
1796  print dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1).$separator;
1797  // DATH
1798  print $date_lim_reglement.$separator;
1799  // CNPI
1800  if ($line->doc_type == 'supplier_invoice') {
1801  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.
1802  $nature_piece = 'AF';
1803  } else {
1804  $nature_piece = 'FF';
1805  }
1806  } elseif ($line->doc_type == 'customer_invoice') {
1807  if (($line->amount) < 0) {
1808  $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.
1809  } else {
1810  $nature_piece = 'FC';
1811  }
1812  } else {
1813  $nature_piece = '';
1814  }
1815  print $nature_piece.$separator;
1816  // RACI
1817  // if (!empty($line->subledger_account)) {
1818  // if ($line->doc_type == 'supplier_invoice') {
1819  // $racine_subledger_account = '40';
1820  // } elseif ($line->doc_type == 'customer_invoice') {
1821  // $racine_subledger_account = '41';
1822  // } else {
1823  // $racine_subledger_account = '';
1824  // }
1825  // } else {
1826  $racine_subledger_account = ''; // for records of type E leave this field blank
1827  // }
1828 
1829  print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
1830  // MONT
1831  print price(abs($line->debit - $line->credit), 0, '', 1, 2).$separator;
1832  // CODC
1833  print $line->sens.$separator;
1834  // CPTG
1835  print length_accountg($line->numero_compte).$separator;
1836  // DATE
1837  print $date_document.$separator;
1838  // CLET
1839  print $line->lettering_code.$separator;
1840  // DATL
1841  print $line->date_lettering.$separator;
1842  // CPTA
1843  if (!empty($line->subledger_account)) {
1844  print length_accounta($line->subledger_account).$separator;
1845  } else {
1846  print $separator;
1847  }
1848  // CNAT
1849  if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
1850  print 'F'.$separator;
1851  } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
1852  print 'C'.$separator;
1853  } else {
1854  print $separator;
1855  }
1856  // CTRE
1857  print $separator;
1858  // NORL
1859  print $separator;
1860  // DATV
1861  print $separator;
1862  // REFD
1863  print $line->doc_ref.$separator;
1864  // NECA
1865  print '0'.$separator;
1866  // CSEC
1867  print $separator;
1868  // CAFF
1869  print $separator;
1870  // CDES
1871  print $separator;
1872  // QTUE
1873  print $separator;
1874  // MTDV
1875  print '0'.$separator;
1876  // CODV
1877  print $separator;
1878  // TXDV
1879  print '0'.$separator;
1880  // MOPM
1881  print $separator;
1882  // BONP
1883  print $separator;
1884  // BQAF
1885  print $separator;
1886  // ECES
1887  print $separator;
1888  // TXTL
1889  print $separator;
1890  // ECRM
1891  print $separator;
1892  // DATK
1893  print $separator;
1894  // HEUK
1895  print $separator;
1896 
1897  print $end_line;
1898 
1899  $last_codeinvoice = $line->doc_ref;
1900  }
1901  }
1902 
1909  public function exportCharlemagne($objectLines)
1910  {
1911  global $langs;
1912  $langs->load('compta');
1913 
1914  $separator = "\t";
1915  $end_line = "\n";
1916 
1917  /*
1918  * Charlemagne export need header
1919  */
1920  print $langs->transnoentitiesnoconv('Date').$separator;
1921  print self::trunc($langs->transnoentitiesnoconv('Journal'), 6).$separator;
1922  print self::trunc($langs->transnoentitiesnoconv('Account'), 15).$separator;
1923  print self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60).$separator;
1924  print self::trunc($langs->transnoentitiesnoconv('Piece'), 20).$separator;
1925  print self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60).$separator;
1926  print $langs->transnoentitiesnoconv('Amount').$separator;
1927  print 'S'.$separator;
1928  print self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15).$separator;
1929  print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60).$separator;
1930  print self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15).$separator;
1931  print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60).$separator;
1932  print self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15).$separator;
1933  print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60).$separator;
1934  print $end_line;
1935 
1936  foreach ($objectLines as $line) {
1937  $date = dol_print_date($line->doc_date, '%Y%m%d');
1938  print $date.$separator; //Date
1939 
1940  print self::trunc($line->code_journal, 6).$separator; //Journal code
1941 
1942  if (!empty($line->subledger_account)) {
1943  $account = $line->subledger_account;
1944  } else {
1945  $account = $line->numero_compte;
1946  }
1947  print self::trunc($account, 15).$separator; //Account number
1948 
1949  print self::trunc($line->label_compte, 60).$separator; //Account label
1950  print self::trunc($line->doc_ref, 20).$separator; //Piece
1951  // Clean label operation to prevent problem on export with tab separator & other character
1952  $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
1953  print self::trunc($line->label_operation, 60).$separator; //Operation label
1954  print price(abs($line->debit - $line->credit)).$separator; //Amount
1955  print $line->sens.$separator; //Direction
1956  print $separator; //Analytic
1957  print $separator; //Analytic
1958  print $separator; //Analytic
1959  print $separator; //Analytic
1960  print $separator; //Analytic
1961  print $separator; //Analytic
1962  print $end_line;
1963  }
1964  }
1965 
1973  public function exportGestimumV3($objectLines)
1974  {
1975  global $langs;
1976 
1977  $this->separator = ',';
1978 
1979  $invoices_infos = array();
1980  $supplier_invoices_infos = array();
1981  foreach ($objectLines as $line) {
1982  if ($line->debit == 0 && $line->credit == 0) {
1983  //unset($array[$line]);
1984  } else {
1985  $date = dol_print_date($line->doc_date, '%d/%m/%Y');
1986 
1987  $invoice_ref = $line->doc_ref;
1988  $company_name = "";
1989 
1990  if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
1991  if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
1992  ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
1993  if ($line->doc_type == 'customer_invoice') {
1994  // Get new customer invoice ref and company name
1995  $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
1996  $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
1997  $sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
1998  $resql = $this->db->query($sql);
1999  if ($resql) {
2000  if ($obj = $this->db->fetch_object($resql)) {
2001  // Save invoice infos
2002  $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2003  $invoice_ref = $obj->ref;
2004  $company_name = $obj->nom;
2005  }
2006  }
2007  } else {
2008  // Get new supplier invoice ref and company name
2009  $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
2010  $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
2011  $sql .= ' WHERE ff.rowid = '.((int) $line->fk_doc);
2012  $resql = $this->db->query($sql);
2013  if ($resql) {
2014  if ($obj = $this->db->fetch_object($resql)) {
2015  // Save invoice infos
2016  $supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
2017  $invoice_ref = $obj->ref;
2018  $company_name = $obj->nom;
2019  }
2020  }
2021  }
2022  } elseif ($line->doc_type == 'customer_invoice') {
2023  // Retrieve invoice infos
2024  $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
2025  $company_name = $invoices_infos[$line->fk_doc]['company_name'];
2026  } else {
2027  // Retrieve invoice infos
2028  $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
2029  $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
2030  }
2031  }
2032 
2033  print $line->id . $this->separator;
2034  print $date . $this->separator;
2035  print substr($line->code_journal, 0, 4) . $this->separator;
2036 
2037  if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
2038  print length_accountg($line->subledger_account) . $this->separator;
2039  } else {
2040  print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator;
2041  }
2042  //Libellé Auto
2043  print $this->separator;
2044  //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator;
2045  //Libellé manuel
2046  print dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1) . $this->separator;
2047  //Numéro de pièce
2048  print dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . $this->separator;
2049  //Devise
2050  print 'EUR' . $this->separator;
2051  //Amount
2052  print price2num(abs($line->debit - $line->credit)) . $this->separator;
2053  //Sens
2054  print $line->sens . $this->separator;
2055  //Code lettrage
2056  print $this->separator;
2057  //Date Echéance
2058  print $date;
2059  print $this->end_line;
2060  }
2061  }
2062  }
2063 
2071  public function exportGestimumV5($objectLines)
2072  {
2073 
2074  $this->separator = ',';
2075 
2076  foreach ($objectLines as $line) {
2077  if ($line->debit == 0 && $line->credit == 0) {
2078  //unset($array[$line]);
2079  } else {
2080  $date = dol_print_date($line->doc_date, '%d%m%Y');
2081 
2082  print $line->id . $this->separator;
2083  print $date . $this->separator;
2084  print substr($line->code_journal, 0, 4) . $this->separator;
2085  if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
2086  print length_accountg($line->subledger_account) . $this->separator;
2087  } else {
2088  print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator;
2089  }
2090  print $this->separator;
2091  //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator;
2092  print '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"' . $this->separator;
2093  print '"' . dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . '"' . $this->separator;
2094  print price2num(abs($line->debit - $line->credit)) . $this->separator;
2095  print $line->sens . $this->separator;
2096  print $date . $this->separator;
2097  print $this->separator;
2098  print $this->separator;
2099  print 'EUR';
2100  print $this->end_line;
2101  }
2102  }
2103  }
2104 
2114  public function exportiSuiteExpert($objectLines)
2115  {
2116  $this->separator = ';';
2117  $this->end_line = "\r\n";
2118 
2119 
2120  foreach ($objectLines as $line) {
2121  $tab = array();
2122 
2123  $date = dol_print_date($line->doc_date, '%d/%m/%Y');
2124 
2125  $tab[] = $line->piece_num;
2126  $tab[] = $date;
2127  $tab[] = substr($date, 6, 4);
2128  $tab[] = substr($date, 3, 2);
2129  $tab[] = substr($date, 0, 2);
2130  $tab[] = $line->doc_ref;
2131  //Conversion de chaine UTF8 en Latin9
2132  $tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
2133 
2134  //Calcul de la longueur des numéros de comptes
2135  $taille_numero = strlen(length_accountg($line->numero_compte));
2136 
2137  //Création du numéro de client et fournisseur générique
2138  $numero_cpt_client = '411';
2139  $numero_cpt_fourn = '401';
2140  for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2141  $numero_cpt_client .= '0';
2142  $numero_cpt_fourn .= '0';
2143  }
2144 
2145  //Création des comptes auxiliaire des clients et fournisseur
2146  if (length_accountg($line->numero_compte) == $numero_cpt_client || length_accountg($line->numero_compte) == $numero_cpt_fourn) {
2147  $tab[] = rtrim(length_accounta($line->subledger_account), "0");
2148  } else {
2149  $tab[] = length_accountg($line->numero_compte);
2150  }
2151  $nom_client = explode(" - ", $line->label_operation);
2152  $tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
2153  $tab[] = price($line->debit);
2154  $tab[] = price($line->credit);
2155  $tab[] = price($line->montant);
2156  $tab[] = $line->code_journal;
2157 
2158  $separator = $this->separator;
2159  print implode($separator, $tab) . $this->end_line;
2160  }
2161  }
2162 
2170  public static function trunc($str, $size)
2171  {
2172  return dol_trunc($str, $size, 'right', 'UTF-8', 1);
2173  }
2174 
2182  public static function toAnsi($str, $size = -1)
2183  {
2184  $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
2185  if ($retVal >= 0 && $size >= 0) {
2186  $retVal = mb_substr($retVal, 0, $size, 'Windows-1251');
2187  }
2188  return $retVal;
2189  }
2190 }
length_accounta
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
Definition: accounting.lib.php:133
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_trunc
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.
Definition: functions.lib.php:3950
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1236
AccountancyExport\exportGestimumV5
exportGestimumV5($objectLines)
Export format : Gestimum V5.
Definition: accountancyexport.class.php:2071
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
AccountancyExport\exportCogilog
exportCogilog($objectLines)
Export format : COGILOG.
Definition: accountancyexport.class.php:539
$sql
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)) $sql
Social contributions to pay.
Definition: index.php:745
FactureFournisseur
Class to manage suppliers invoices.
Definition: fournisseur.facture.class.php:51
AccountancyExport\getType
getType()
Array with all export type available (key + label)
Definition: accountancyexport.class.php:115
AccountancyExport\exportCoala
exportCoala($objectLines)
Export format : COALA.
Definition: accountancyexport.class.php:572
AccountancyExport\exportOpenConcerto
exportOpenConcerto($objectLines)
Export format : OpenConcerto.
Definition: accountancyexport.class.php:1058
dol_dir_list
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
AccountancyExport\getTypeConfig
getTypeConfig()
Array with all export type available (key + label) and parameters for config.
Definition: accountancyexport.class.php:195
AccountancyExport\trunc
static trunc($str, $size)
trunc
Definition: accountancyexport.class.php:2170
AccountancyExport\exportLDCompta
exportLDCompta($objectLines)
Export format : LD Compta version 9 http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Docu...
Definition: accountancyexport.class.php:1510
top_httphead
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1470
AccountancyExport\getFormatCode
static getFormatCode($type)
Return string to summarize the format (Used to generated export filename)
Definition: accountancyexport.class.php:157
AccountancyExport\exportGestimumV3
exportGestimumV3($objectLines)
Export format : Gestimum V3.
Definition: accountancyexport.class.php:1973
Facture
Class to manage invoices.
Definition: facture.class.php:60
AccountancyExport\exportCegid
exportCegid($objectLines)
Export format : CEGID.
Definition: accountancyexport.class.php:514
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5834
AccountancyExport\exportWinfic
exportWinfic(&$TData)
Export format : WinFic - eWinfic - WinSis Compta Last review for this format : 2022-11-01 Alexandre S...
Definition: accountancyexport.class.php:898
AccountancyExport\exportFEC2
exportFEC2($objectLines)
Export format : FEC2.
Definition: accountancyexport.class.php:1253
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2566
AccountancyExport\exportFEC
exportFEC($objectLines)
Export format : FEC.
Definition: accountancyexport.class.php:1120
AccountancyExport\exportBob50
exportBob50($objectLines)
Export format : BOB50.
Definition: accountancyexport.class.php:600
AccountancyExport
Manage the different format accountancy export.
Definition: accountancyexport.class.php:47
AccountancyExport\exportLDCompta10
exportLDCompta10($objectLines)
Export format : LD Compta version 10 & higher Last review for this format : 08-15-2021 Alexandre Span...
Definition: accountancyexport.class.php:1644
AccountancyExport\exportQuadratus
exportQuadratus(&$TData, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : Quadratus (Format ASCII) Format since 2015 compatible QuadraCOMPTA Last review for th...
Definition: accountancyexport.class.php:696
dol_string_nospecial
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='')
Clean a string from all punctuation characters to use it as a ref or login.
Definition: functions.lib.php:1408
dol_string_unaccent
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
Definition: functions.lib.php:1337
AccountancyExport\exportCharlemagne
exportCharlemagne($objectLines)
Export format : Charlemagne.
Definition: accountancyexport.class.php:1909
AccountancyExport\exportCiel
exportCiel(&$TData)
Export format : CIEL (Format XIMPORT) Format since 2003 compatible CIEL version > 2002 / Sage50 Last ...
Definition: accountancyexport.class.php:646
length_accountg
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
Definition: accounting.lib.php:94
AccountancyExport\exportConfigurable
exportConfigurable($objectLines)
Export format : Configurable CSV.
Definition: accountancyexport.class.php:1089
dol_string_nohtmltag
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Definition: functions.lib.php:6921
price2fec
price2fec($amount)
Function to format a value into a defined format for French administration (no thousand separator & d...
Definition: functions2.lib.php:2742
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3888
AccountancyExport\exportAgiris
exportAgiris($objectLines)
Export format : Agiris Isacompta.
Definition: accountancyexport.class.php:1019
readfileLowMemory
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
Definition: functions.lib.php:11495
AccountancyExport\exportiSuiteExpert
exportiSuiteExpert($objectLines)
Export format : iSuite Expert.
Definition: accountancyexport.class.php:2114
dol_filesize
dol_filesize($pathoffile)
Return size of a file.
Definition: files.lib.php:585
AccountancyExport\export
export(&$TData, $formatexportset, $withAttachment=0)
Function who chose which export to use with the default config, and make the export into a file.
Definition: accountancyexport.class.php:322
AccountancyExport\toAnsi
static toAnsi($str, $size=-1)
toAnsi
Definition: accountancyexport.class.php:2182
AccountancyExport\getMimeType
getMimeType($formatexportset)
Return the MIME type of a file.
Definition: accountancyexport.class.php:298
AccountancyExport\__construct
__construct(DoliDB $db)
Constructor.
Definition: accountancyexport.class.php:99
AccountancyExport\exportEbp
exportEbp($objectLines)
Export format : EBP.
Definition: accountancyexport.class.php:984
price
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.
Definition: functions.lib.php:5708
getCountry
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
Definition: company.lib.php:515
AccountancyExport\exportSAGE50SWISS
exportSAGE50SWISS($objectLines)
Export format : SAGE50SWISS.
Definition: accountancyexport.class.php:1391