dolibarr  13.0.2
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-2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
9  * Copyright (C) 2013-2017 Olivier Geffroy <jeff@jeffinfo.com>
10  * Copyright (C) 2017 Elarifr. Ari Elbaz <github@accedinfo.com>
11  * Copyright (C) 2017-2019 Frédéric France <frederic.france@netlogic.fr>
12  * Copyright (C) 2017 André Schild <a.schild@aarboard.ch>
13  * Copyright (C) 2020 Guillaume Alexandre <guillaume@tag-info.fr>
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <https://www.gnu.org/licenses/>.
27  */
28 
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
37 
38 
43 {
44  // Type of export. Used into $conf->global->ACCOUNTING_EXPORT_MODELCSV
45  public static $EXPORT_TYPE_CONFIGURABLE = 1; // CSV
46  public static $EXPORT_TYPE_AGIRIS = 10;
47  public static $EXPORT_TYPE_EBP = 15;
48  public static $EXPORT_TYPE_CEGID = 20;
49  public static $EXPORT_TYPE_COGILOG = 25;
50  public static $EXPORT_TYPE_COALA = 30;
51  public static $EXPORT_TYPE_BOB50 = 35;
52  public static $EXPORT_TYPE_CIEL = 40;
53  public static $EXPORT_TYPE_SAGE50_SWISS = 45;
54  public static $EXPORT_TYPE_CHARLEMAGNE = 50;
55  public static $EXPORT_TYPE_QUADRATUS = 60;
56  public static $EXPORT_TYPE_WINFIC = 70;
57  public static $EXPORT_TYPE_OPENCONCERTO = 100;
58  public static $EXPORT_TYPE_LDCOMPTA = 110;
59  public static $EXPORT_TYPE_LDCOMPTA10 = 120;
60  public static $EXPORT_TYPE_GESTIMUMV3 = 130;
61  public static $EXPORT_TYPE_GESTIMUMV5 = 135;
62  public static $EXPORT_TYPE_FEC = 1000;
63  public static $EXPORT_TYPE_FEC2 = 1010;
64 
65 
69  public $errors = array();
70 
75  public $separator = '';
76 
81  public $end_line = '';
82 
88  public function __construct(DoliDB &$db)
89  {
90  global $conf;
91 
92  $this->db = &$db;
93  $this->separator = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
94  $this->end_line = empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? "\n" : ($conf->global->ACCOUNTING_EXPORT_ENDLINE == 1 ? "\n" : "\r\n");
95  }
96 
102  public static function getType()
103  {
104  global $langs;
105 
106  $listofexporttypes = array(
107  self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans('Modelcsv_configurable'),
108  self::$EXPORT_TYPE_CEGID => $langs->trans('Modelcsv_CEGID'),
109  self::$EXPORT_TYPE_COALA => $langs->trans('Modelcsv_COALA'),
110  self::$EXPORT_TYPE_BOB50 => $langs->trans('Modelcsv_bob50'),
111  self::$EXPORT_TYPE_CIEL => $langs->trans('Modelcsv_ciel'),
112  self::$EXPORT_TYPE_QUADRATUS => $langs->trans('Modelcsv_quadratus'),
113  self::$EXPORT_TYPE_WINFIC => $langs->trans('Modelcsv_winfic'),
114  self::$EXPORT_TYPE_EBP => $langs->trans('Modelcsv_ebp'),
115  self::$EXPORT_TYPE_COGILOG => $langs->trans('Modelcsv_cogilog'),
116  self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'),
117  self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans('Modelcsv_openconcerto'),
118  self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans('Modelcsv_Sage50_Swiss'),
119  self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans('Modelcsv_charlemagne'),
120  self::$EXPORT_TYPE_LDCOMPTA => $langs->trans('Modelcsv_LDCompta'),
121  self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans('Modelcsv_LDCompta10'),
122  self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans('Modelcsv_Gestinum_v3'),
123  self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans('Modelcsv_Gestinum_v5'),
124  self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'),
125  self::$EXPORT_TYPE_FEC2 => $langs->trans('Modelcsv_FEC2'),
126  );
127 
128  ksort($listofexporttypes, SORT_NUMERIC);
129 
130  return $listofexporttypes;
131  }
132 
139  public static function getFormatCode($type)
140  {
141  $formatcode = array(
142  self::$EXPORT_TYPE_CONFIGURABLE => 'csv',
143  self::$EXPORT_TYPE_CEGID => 'cegid',
144  self::$EXPORT_TYPE_COALA => 'coala',
145  self::$EXPORT_TYPE_BOB50 => 'bob50',
146  self::$EXPORT_TYPE_CIEL => 'ciel',
147  self::$EXPORT_TYPE_QUADRATUS => 'quadratus',
148  self::$EXPORT_TYPE_WINFIC => 'winfic',
149  self::$EXPORT_TYPE_EBP => 'ebp',
150  self::$EXPORT_TYPE_COGILOG => 'cogilog',
151  self::$EXPORT_TYPE_AGIRIS => 'agiris',
152  self::$EXPORT_TYPE_OPENCONCERTO => 'openconcerto',
153  self::$EXPORT_TYPE_SAGE50_SWISS => 'sage50ch',
154  self::$EXPORT_TYPE_CHARLEMAGNE => 'charlemagne',
155  self::$EXPORT_TYPE_LDCOMPTA => 'ldcompta',
156  self::$EXPORT_TYPE_LDCOMPTA10 => 'ldcompta10',
157  self::$EXPORT_TYPE_GESTIMUMV3 => 'gestimumv3',
158  self::$EXPORT_TYPE_GESTIMUMV5 => 'gestimumv5',
159  self::$EXPORT_TYPE_FEC => 'fec',
160  self::$EXPORT_TYPE_FEC2 => 'fec2',
161  );
162 
163  return $formatcode[$type];
164  }
165 
171  public static function getTypeConfig()
172  {
173  global $conf, $langs;
174 
175  return array(
176  'param' => array(
177  self::$EXPORT_TYPE_CONFIGURABLE => array(
178  'label' => $langs->trans('Modelcsv_configurable'),
179  'ACCOUNTING_EXPORT_FORMAT' => empty($conf->global->ACCOUNTING_EXPORT_FORMAT) ? 'txt' : $conf->global->ACCOUNTING_EXPORT_FORMAT,
180  'ACCOUNTING_EXPORT_SEPARATORCSV' => empty($conf->global->ACCOUNTING_EXPORT_SEPARATORCSV) ? ',' : $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV,
181  'ACCOUNTING_EXPORT_ENDLINE' => empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? 1 : $conf->global->ACCOUNTING_EXPORT_ENDLINE,
182  'ACCOUNTING_EXPORT_DATE' => empty($conf->global->ACCOUNTING_EXPORT_DATE) ? '%d%m%Y' : $conf->global->ACCOUNTING_EXPORT_DATE,
183  ),
184  self::$EXPORT_TYPE_CEGID => array(
185  'label' => $langs->trans('Modelcsv_CEGID'),
186  ),
187  self::$EXPORT_TYPE_COALA => array(
188  'label' => $langs->trans('Modelcsv_COALA'),
189  ),
190  self::$EXPORT_TYPE_BOB50 => array(
191  'label' => $langs->trans('Modelcsv_bob50'),
192  ),
193  self::$EXPORT_TYPE_CIEL => array(
194  'label' => $langs->trans('Modelcsv_ciel'),
195  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
196  ),
197  self::$EXPORT_TYPE_QUADRATUS => array(
198  'label' => $langs->trans('Modelcsv_quadratus'),
199  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
200  ),
201  self::$EXPORT_TYPE_WINFIC => array(
202  'label' => $langs->trans('Modelcsv_winfic'),
203  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
204  ),
205  self::$EXPORT_TYPE_EBP => array(
206  'label' => $langs->trans('Modelcsv_ebp'),
207  ),
208  self::$EXPORT_TYPE_COGILOG => array(
209  'label' => $langs->trans('Modelcsv_cogilog'),
210  ),
211  self::$EXPORT_TYPE_AGIRIS => array(
212  'label' => $langs->trans('Modelcsv_agiris'),
213  ),
214  self::$EXPORT_TYPE_OPENCONCERTO => array(
215  'label' => $langs->trans('Modelcsv_openconcerto'),
216  ),
217  self::$EXPORT_TYPE_SAGE50_SWISS => array(
218  'label' => $langs->trans('Modelcsv_Sage50_Swiss'),
219  ),
220  self::$EXPORT_TYPE_CHARLEMAGNE => array(
221  'label' => $langs->trans('Modelcsv_charlemagne'),
222  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
223  ),
224  self::$EXPORT_TYPE_LDCOMPTA => array(
225  'label' => $langs->trans('Modelcsv_LDCompta'),
226  ),
227  self::$EXPORT_TYPE_LDCOMPTA10 => array(
228  'label' => $langs->trans('Modelcsv_LDCompta10'),
229  ),
230  self::$EXPORT_TYPE_GESTIMUMV3 => array(
231  'label' => $langs->trans('Modelcsv_Gestinumv3'),
232  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
233  ),
234  self::$EXPORT_TYPE_GESTIMUMV5 => array(
235  'label' => $langs->trans('Modelcsv_Gestinumv5'),
236  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
237  ),
238  self::$EXPORT_TYPE_FEC => array(
239  'label' => $langs->trans('Modelcsv_FEC'),
240  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
241  ),
242  self::$EXPORT_TYPE_FEC2 => array(
243  'label' => $langs->trans('Modelcsv_FEC2'),
244  'ACCOUNTING_EXPORT_FORMAT' => 'txt',
245  ),
246  ),
247  'cr'=> array(
248  '1' => $langs->trans("Unix"),
249  '2' => $langs->trans("Windows")
250  ),
251  'format' => array(
252  'csv' => $langs->trans("csv"),
253  'txt' => $langs->trans("txt")
254  ),
255  );
256  }
257 
258 
266  public function export(&$TData, $formatexportset)
267  {
268  global $conf, $langs;
269  global $search_date_end; // Used into /accountancy/tpl/export_journal.tpl.php
270 
271  // Define name of file to save
272  $filename = 'general_ledger-'.$this->getFormatCode($formatexportset);
273  $type_export = 'general_ledger';
274 
275  global $db; // The tpl file use $db
276  include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
277 
278 
279  switch ($formatexportset) {
280  case self::$EXPORT_TYPE_CONFIGURABLE :
281  $this->exportConfigurable($TData);
282  break;
283  case self::$EXPORT_TYPE_CEGID :
284  $this->exportCegid($TData);
285  break;
286  case self::$EXPORT_TYPE_COALA :
287  $this->exportCoala($TData);
288  break;
289  case self::$EXPORT_TYPE_BOB50 :
290  $this->exportBob50($TData);
291  break;
292  case self::$EXPORT_TYPE_CIEL :
293  $this->exportCiel($TData);
294  break;
295  case self::$EXPORT_TYPE_QUADRATUS :
296  $this->exportQuadratus($TData);
297  break;
298  case self::$EXPORT_TYPE_WINFIC :
299  $this->exportWinfic($TData);
300  break;
301  case self::$EXPORT_TYPE_EBP :
302  $this->exportEbp($TData);
303  break;
304  case self::$EXPORT_TYPE_COGILOG :
305  $this->exportCogilog($TData);
306  break;
307  case self::$EXPORT_TYPE_AGIRIS :
308  $this->exportAgiris($TData);
309  break;
310  case self::$EXPORT_TYPE_OPENCONCERTO :
311  $this->exportOpenConcerto($TData);
312  break;
313  case self::$EXPORT_TYPE_SAGE50_SWISS :
314  $this->exportSAGE50SWISS($TData);
315  break;
316  case self::$EXPORT_TYPE_CHARLEMAGNE :
317  $this->exportCharlemagne($TData);
318  break;
319  case self::$EXPORT_TYPE_LDCOMPTA :
320  $this->exportLDCompta($TData);
321  break;
322  case self::$EXPORT_TYPE_LDCOMPTA10 :
323  $this->exportLDCompta10($TData);
324  break;
325  case self::$EXPORT_TYPE_GESTIMUMV3 :
326  $this->exportGestimumV3($TData);
327  break;
328  case self::$EXPORT_TYPE_GESTIMUMV5 :
329  $this->exportGestimumV5($TData);
330  break;
331  case self::$EXPORT_TYPE_FEC :
332  $this->exportFEC($TData);
333  break;
334  case self::$EXPORT_TYPE_FEC2 :
335  $this->exportFEC2($TData);
336  break;
337  default:
338  $this->errors[] = $langs->trans('accountancy_error_modelnotfound');
339  break;
340  }
341  }
342 
343 
350  public function exportCegid($objectLines)
351  {
352  foreach ($objectLines as $line) {
353  $date = dol_print_date($line->doc_date, '%d%m%Y');
354  $separator = ";";
355  $end_line = "\n";
356 
357  print $date.$separator;
358  print $line->code_journal.$separator;
359  print length_accountg($line->numero_compte).$separator;
360  print length_accounta($line->subledger_account).$separator;
361  print $line->sens.$separator;
362  print price2fec(abs($line->debit - $line->credit)).$separator;
363  print dol_string_unaccent($line->label_operation).$separator;
364  print dol_string_unaccent($line->doc_ref);
365  print $end_line;
366  }
367  }
368 
375  public function exportCogilog($objectLines)
376  {
377  foreach ($objectLines as $line) {
378  $date = dol_print_date($line->doc_date, '%d%m%Y');
379  $separator = ";";
380  $end_line = "\n";
381 
382  print $line->code_journal.$separator;
383  print $date.$separator;
384  print $line->piece_num.$separator;
385  print length_accountg($line->numero_compte).$separator;
386  print ''.$separator;
387  print $line->label_operation.$separator;
388  print $date.$separator;
389  if ($line->sens == 'D') {
390  print price($line->debit).$separator;
391  print ''.$separator;
392  } elseif ($line->sens == 'C') {
393  print ''.$separator;
394  print price($line->credit).$separator;
395  }
396  print $line->doc_ref.$separator;
397  print $line->label_operation.$separator;
398  print $end_line;
399  }
400  }
401 
408  public function exportCoala($objectLines)
409  {
410  // Coala export
411  $separator = ";";
412  $end_line = "\n";
413 
414  foreach ($objectLines as $line) {
415  $date = dol_print_date($line->doc_date, '%d/%m/%Y');
416 
417  print $date.$separator;
418  print $line->code_journal.$separator;
419  print length_accountg($line->numero_compte).$separator;
420  print $line->piece_num.$separator;
421  print $line->doc_ref.$separator;
422  print price($line->debit).$separator;
423  print price($line->credit).$separator;
424  print 'E'.$separator;
425  print length_accounta($line->subledger_account).$separator;
426  print $end_line;
427  }
428  }
429 
436  public function exportBob50($objectLines)
437  {
438 
439  // Bob50
440  $separator = ";";
441  $end_line = "\n";
442 
443  foreach ($objectLines as $line) {
444  print $line->piece_num.$separator;
445  $date = dol_print_date($line->doc_date, '%d/%m/%Y');
446  print $date.$separator;
447 
448  if (empty($line->subledger_account)) {
449  print 'G'.$separator;
450  print length_accounta($line->numero_compte).$separator;
451  } else {
452  if (substr($line->numero_compte, 0, 3) == '411') {
453  print 'C'.$separator;
454  }
455  if (substr($line->numero_compte, 0, 3) == '401') {
456  print 'F'.$separator;
457  }
458  print length_accountg($line->subledger_account).$separator;
459  }
460 
461  print price($line->debit).$separator;
462  print price($line->credit).$separator;
463  print dol_trunc($line->label_operation, 32).$separator;
464  print $end_line;
465  }
466  }
467 
474  public function exportCiel(&$TData)
475  {
476  global $conf;
477 
478  $end_line = "\r\n";
479 
480  $i = 1;
481  $date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be yyyymmdd
482  foreach ($TData as $data) {
483  $code_compta = $data->numero_compte;
484  if (!empty($data->subledger_account))
485  $code_compta = $data->subledger_account;
486 
487  $Tab = array();
488  $Tab['num_ecriture'] = str_pad($i, 5);
489  $Tab['code_journal'] = str_pad($data->code_journal, 2);
490  $Tab['date_ecriture'] = $date_ecriture;
491  $Tab['date_ope'] = dol_print_date($data->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
492  $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 12), 12);
493  $Tab['num_compte'] = str_pad(self::trunc($code_compta, 11), 11);
494  $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).dol_string_unaccent($data->label_operation), 25), 25);
495  $Tab['montant'] = str_pad(abs($data->debit - $data->credit), 13, ' ', STR_PAD_LEFT);
496  $Tab['type_montant'] = str_pad($data->sens, 1);
497  $Tab['vide'] = str_repeat(' ', 18);
498  $Tab['intitule_compte'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 34), 34);
499  $Tab['end'] = 'O2003';
500 
501  $Tab['end_line'] = $end_line;
502 
503  print implode($Tab);
504  $i++;
505  }
506  }
507 
514  public function exportQuadratus(&$TData)
515  {
516  global $conf;
517 
518  $end_line = "\r\n";
519 
520  // We should use dol_now function not time however this is wrong date to transfert in accounting
521  // $date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
522  // $date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
523  foreach ($TData as $data) {
524  $code_compta = $data->numero_compte;
525  if (!empty($data->subledger_account))
526  $code_compta = $data->subledger_account;
527 
528  $Tab = array();
529  $Tab['type_ligne'] = 'M';
530  $Tab['num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
531  $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
532  $Tab['folio'] = '000';
533 
534  // We use invoice date $data->doc_date not $date_ecriture which is the transfert date
535  // maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
536  //$Tab['date_ecriture'] = $date_ecriture;
537  $Tab['date_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
538  $Tab['filler'] = ' ';
539  $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).' '.dol_string_unaccent($data->label_operation), 20), 20);
540 
541  // Credit invoice - invert sens
542  /*
543  if ($data->montant < 0) {
544  if ($data->sens == 'C') {
545  $Tab['sens'] = 'D';
546  } else {
547  $Tab['sens'] = 'C';
548  }
549  $Tab['signe_montant'] = '-';
550  } else {
551  $Tab['sens'] = $data->sens; // C or D
552  $Tab['signe_montant'] = '+';
553  }*/
554  $Tab['sens'] = $data->sens; // C or D
555  $Tab['signe_montant'] = '+';
556 
557  // The amount must be in centimes without decimal points.
558  $Tab['montant'] = str_pad(abs(($data->debit - $abs->credit) * 100), 12, '0', STR_PAD_LEFT);
559  $Tab['contrepartie'] = str_repeat(' ', 8);
560 
561  // Force date format : %d%m%y
562  if (!empty($data->date_echeance)) {
563  //$Tab['date_echeance'] = dol_print_date($data->date_echeance, $conf->global->ACCOUNTING_EXPORT_DATE);
564  $Tab['date_echeance'] = dol_print_date($data->date_echeance, '%d%m%y'); // Format must be ddmmyy
565  } else {
566  $Tab['date_echeance'] = '000000';
567  }
568 
569  // Please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
570  // $Tab['lettrage'] = str_repeat(' ', 5);
571  $Tab['lettrage'] = str_repeat(' ', 2);
572  $Tab['codestat'] = str_repeat(' ', 3);
573  $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 5), 5);
574 
575  // Keep correct quadra named field instead of anon filler
576  // $Tab['filler2'] = str_repeat(' ', 20);
577  $Tab['affaire'] = str_repeat(' ', 10);
578  $Tab['quantity1'] = str_repeat(' ', 10);
579  $Tab['num_piece2'] = str_pad(self::trunc($data->piece_num, 8), 8);
580  $Tab['devis'] = str_pad($conf->currency, 3);
581  $Tab['code_journal2'] = str_pad(self::trunc($data->code_journal, 3), 3);
582  $Tab['filler3'] = str_repeat(' ', 3);
583 
584  // Keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
585  // 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
586  // TODO: we should filter more than only accent to avoid wrong line size
587  // TODO: remove invoice number doc_ref in libelle,
588  // TODO: we should offer an option for customer to build the libelle using invoice number / name / date in accounting software
589  //$Tab['libelle_ecriture2'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref) . ' ' . dol_string_unaccent($data->label_operation), 30), 30);
590  $Tab['libelle_ecriture2'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 30), 30);
591  $Tab['codetva'] = str_repeat(' ', 2);
592 
593  // We need to keep the 10 lastest number of invoice doc_ref not the beginning part that is the unusefull almost same part
594  // $Tab['num_piece3'] = str_pad(self::trunc($data->piece_num, 10), 10);
595  $Tab['num_piece3'] = substr(self::trunc($data->doc_ref, 20), -10);
596  $Tab['filler4'] = str_repeat(' ', 73);
597 
598  $Tab['end_line'] = $end_line;
599 
600  print implode($Tab);
601  }
602  }
603 
611  public function exportWinfic(&$TData)
612  {
613  global $conf;
614 
615  $end_line = "\r\n";
616 
617  //We should use dol_now function not time however this is wrong date to transfert in accounting
618  //$date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
619  //$date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
620  foreach ($TData as $data) {
621  $code_compta = $data->numero_compte;
622  if (!empty($data->subledger_account))
623  $code_compta = $data->subledger_account;
624 
625  $Tab = array();
626  //$Tab['type_ligne'] = 'M';
627  $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
628 
629  //We use invoice date $data->doc_date not $date_ecriture which is the transfert date
630  //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
631  //$Tab['date_ecriture'] = $date_ecriture;
632  $Tab['date_operation'] = dol_print_date($data->doc_date, '%d%m%Y');
633 
634  $Tab['folio'] = ' 1';
635 
636  $Tab['num_ecriture'] = str_pad(self::trunc($data->piece_num, 6), 6, ' ', STR_PAD_LEFT);
637 
638  $Tab['jour_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
639 
640  $Tab['num_compte'] = str_pad(self::trunc($code_compta, 6), 6, '0');
641 
642  if ($data->sens == 'D') {
643  $Tab['montant_debit'] = str_pad(number_format($data->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
644 
645  $Tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
646  } else {
647  $Tab['montant_debit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
648 
649  $Tab['montant_crebit'] = str_pad(number_format($data->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
650  }
651 
652  $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).' '.dol_string_unaccent($data->label_operation), 30), 30);
653 
654  $Tab['lettrage'] = str_repeat(' ', 2);
655 
656  $Tab['code_piece'] = str_repeat(' ', 5);
657 
658  $Tab['code_stat'] = str_repeat(' ', 4);
659 
660  if (!empty($data->date_echeance)) {
661  //$Tab['date_echeance'] = dol_print_date($data->date_echeance, $conf->global->ACCOUNTING_EXPORT_DATE);
662  $Tab['date_echeance'] = dol_print_date($data->date_echeance, '%d%m%Y');
663  } else {
664  $Tab['date_echeance'] = dol_print_date($data->doc_date, '%d%m%Y');
665  }
666 
667  $Tab['monnaie'] = '1';
668 
669  $Tab['filler'] = ' ';
670 
671  $Tab['ind_compteur'] = ' ';
672 
673  $Tab['quantite'] = '0,000000000';
674 
675  $Tab['code_pointage'] = str_repeat(' ', 2);
676 
677  $Tab['end_line'] = $end_line;
678 
679  print implode('|', $Tab);
680  }
681  }
682 
683 
690  public function exportEbp($objectLines)
691  {
692 
693  $separator = ',';
694  $end_line = "\n";
695 
696  foreach ($objectLines as $line) {
697  $date = dol_print_date($line->doc_date, '%d%m%Y');
698 
699  print $line->id.$separator;
700  print $date.$separator;
701  print $line->code_journal.$separator;
702  if (empty($line->subledger_account)) {
703  print $line->numero_compte.$separator;
704  } else {
705  print $line->subledger_account.$separator;
706  }
707  //print substr(length_accountg($line->numero_compte), 0, 2) . $separator;
708  print '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"'.$separator;
709  print '"'.dol_trunc($line->piece_num, 15, 'right', 'UTF-8', 1).'"'.$separator;
710  print price2num(abs($line->debit - $line->credit)).$separator;
711  print $line->sens.$separator;
712  print $date.$separator;
713  //print 'EUR';
714  print $end_line;
715  }
716  }
717 
718 
725  public function exportAgiris($objectLines)
726  {
727 
728  $separator = ';';
729  $end_line = "\n";
730 
731  foreach ($objectLines as $line) {
732  $date = dol_print_date($line->doc_date, '%d%m%Y');
733 
734  print $line->piece_num.$separator;
735  print self::toAnsi($line->label_operation).$separator;
736  print $date.$separator;
737  print self::toAnsi($line->label_operation).$separator;
738 
739  if (empty($line->subledger_account)) {
740  print length_accountg($line->numero_compte).$separator;
741  print self::toAnsi($line->label_compte).$separator;
742  } else {
743  print length_accounta($line->subledger_account).$separator;
744  print self::toAnsi($line->subledger_label).$separator;
745  }
746 
747  print self::toAnsi($line->doc_ref).$separator;
748  print price($line->debit).$separator;
749  print price($line->credit).$separator;
750  print price(abs($line->debit - $line->credit)).$separator;
751  print $line->sens.$separator;
752  print $line->lettering_code.$separator;
753  print $line->code_journal;
754  print $end_line;
755  }
756  }
757 
764  public function exportOpenConcerto($objectLines)
765  {
766 
767  $separator = ';';
768  $end_line = "\n";
769 
770  foreach ($objectLines as $line) {
771  $date = dol_print_date($line->doc_date, '%d/%m/%Y');
772 
773  print $date.$separator;
774  print $line->code_journal.$separator;
775  if (empty($line->subledger_account)) {
776  print length_accountg($line->numero_compte).$separator;
777  } else {
778  print length_accounta($line->subledger_account).$separator;
779  }
780  print $line->doc_ref.$separator;
781  print $line->label_operation.$separator;
782  print price($line->debit).$separator;
783  print price($line->credit).$separator;
784 
785  print $end_line;
786  }
787  }
788 
795  public function exportConfigurable($objectLines)
796  {
797  global $conf;
798 
799  $separator = $this->separator;
800 
801  foreach ($objectLines as $line) {
802  $tab = array();
803  // export configurable
804  $date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
805  $tab[] = $line->piece_num;
806  $tab[] = $date;
807  $tab[] = $line->doc_ref;
808  $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
809  $tab[] = length_accountg($line->numero_compte);
810  $tab[] = length_accounta($line->subledger_account);
811  $tab[] = price2num($line->debit);
812  $tab[] = price2num($line->credit);
813  $tab[] = price2num($line->debit - $line->credit);
814  $tab[] = $line->code_journal;
815 
816  print implode($separator, $tab).$this->end_line;
817  }
818  }
819 
826  public function exportFEC($objectLines)
827  {
828  global $langs;
829 
830  $separator = "\t";
831  $end_line = "\r\n";
832 
833  print "JournalCode".$separator;
834  print "JournalLib".$separator;
835  print "EcritureNum".$separator;
836  print "EcritureDate".$separator;
837  print "CompteNum".$separator;
838  print "CompteLib".$separator;
839  print "CompAuxNum".$separator;
840  print "CompAuxLib".$separator;
841  print "PieceRef".$separator;
842  print "PieceDate".$separator;
843  print "EcritureLib".$separator;
844  print "Debit".$separator;
845  print "Credit".$separator;
846  print "EcritureLet".$separator;
847  print "DateLet".$separator;
848  print "ValidDate".$separator;
849  print "Montantdevise".$separator;
850  print "Idevise";
851  print $end_line;
852 
853  foreach ($objectLines as $line) {
854  if ($line->debit == 0 && $line->credit == 0) {
855  //unset($array[$line]);
856  } else {
857  $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
858  $date_document = dol_print_date($line->doc_date, '%Y%m%d');
859  $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
860  $date_validation = dol_print_date($line->date_validated, '%Y%m%d');
861 
862  // FEC:JournalCode
863  print $line->code_journal . $separator;
864 
865  // FEC:JournalLib
866  print dol_string_unaccent($langs->transnoentities($line->journal_label)) . $separator;
867 
868  // FEC:EcritureNum
869  print $line->piece_num . $separator;
870 
871  // FEC:EcritureDate
872  print $date_document . $separator;
873 
874  // FEC:CompteNum
875  print $line->numero_compte . $separator;
876 
877  // FEC:CompteLib
878  print dol_string_unaccent($line->label_compte) . $separator;
879 
880  // FEC:CompAuxNum
881  print $line->subledger_account . $separator;
882 
883  // FEC:CompAuxLib
884  print dol_string_unaccent($line->subledger_label) . $separator;
885 
886  // FEC:PieceRef
887  print $line->doc_ref . $separator;
888 
889  // FEC:PieceDate
890  print dol_string_unaccent($date_creation) . $separator;
891 
892  // FEC:EcritureLib
893  print dol_string_unaccent($line->label_operation) . $separator;
894 
895  // FEC:Debit
896  print price2fec($line->debit) . $separator;
897 
898  // FEC:Credit
899  print price2fec($line->credit) . $separator;
900 
901  // FEC:EcritureLet
902  print $line->lettering_code . $separator;
903 
904  // FEC:DateLet
905  print $date_lettering . $separator;
906 
907  // FEC:ValidDate
908  print $date_validation . $separator;
909 
910  // FEC:Montantdevise
911  print $line->multicurrency_amount . $separator;
912 
913  // FEC:Idevise
914  print $line->multicurrency_code;
915 
916  print $end_line;
917  }
918  }
919  }
920 
927  public function exportFEC2($objectLines)
928  {
929  global $langs;
930 
931  $separator = "\t";
932  $end_line = "\r\n";
933 
934  print "JournalCode".$separator;
935  print "JournalLib".$separator;
936  print "EcritureNum".$separator;
937  print "EcritureDate".$separator;
938  print "CompteNum".$separator;
939  print "CompteLib".$separator;
940  print "CompAuxNum".$separator;
941  print "CompAuxLib".$separator;
942  print "PieceRef".$separator;
943  print "PieceDate".$separator;
944  print "EcritureLib".$separator;
945  print "Debit".$separator;
946  print "Credit".$separator;
947  print "EcritureLet".$separator;
948  print "DateLet".$separator;
949  print "ValidDate".$separator;
950  print "Montantdevise".$separator;
951  print "Idevise";
952  print $end_line;
953 
954  foreach ($objectLines as $line) {
955  if ($line->debit == 0 && $line->credit == 0) {
956  //unset($array[$line]);
957  } else {
958  $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
959  $date_document = dol_print_date($line->doc_date, '%Y%m%d');
960  $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
961  $date_validation = dol_print_date($line->date_validated, '%Y%m%d');
962 
963  // FEC:JournalCode
964  print $line->code_journal . $separator;
965 
966  // FEC:JournalLib
967  print dol_string_unaccent($langs->transnoentities($line->journal_label)) . $separator;
968 
969  // FEC:EcritureNum
970  print $line->piece_num . $separator;
971 
972  // FEC:EcritureDate
973  print $date_creation . $separator;
974 
975  // FEC:CompteNum
976  print $line->numero_compte . $separator;
977 
978  // FEC:CompteLib
979  print dol_string_unaccent($line->label_compte) . $separator;
980 
981  // FEC:CompAuxNum
982  print $line->subledger_account . $separator;
983 
984  // FEC:CompAuxLib
985  print dol_string_unaccent($line->subledger_label) . $separator;
986 
987  // FEC:PieceRef
988  print $line->doc_ref . $separator;
989 
990  // FEC:PieceDate
991  print $date_document . $separator;
992 
993  // FEC:EcritureLib
994  print dol_string_unaccent($line->label_operation) . $separator;
995 
996  // FEC:Debit
997  print price2fec($line->debit) . $separator;
998 
999  // FEC:Credit
1000  print price2fec($line->credit) . $separator;
1001 
1002  // FEC:EcritureLet
1003  print $line->lettering_code . $separator;
1004 
1005  // FEC:DateLet
1006  print $date_lettering . $separator;
1007 
1008  // FEC:ValidDate
1009  print $date_validation . $separator;
1010 
1011  // FEC:Montantdevise
1012  print $line->multicurrency_amount . $separator;
1013 
1014  // FEC:Idevise
1015  print $line->multicurrency_code;
1016 
1017  print $end_line;
1018  }
1019  }
1020  }
1021 
1032  public function exportSAGE50SWISS($objectLines)
1033  {
1034  // SAGE50SWISS
1035  $this->separator = ',';
1036  $this->end_line = "\r\n";
1037 
1038  // Print header line
1039  print "Blg,Datum,Kto,S/H,Grp,GKto,SId,SIdx,KIdx,BTyp,MTyp,Code,Netto,Steuer,FW-Betrag,Tx1,Tx2,PkKey,OpId,Flag";
1040  print $this->end_line;
1041  $thisPieceNum = "";
1042  $thisPieceAccountNr = "";
1043  $aSize = count($objectLines);
1044  foreach ($objectLines as $aIndex=>$line)
1045  {
1046  $sammelBuchung = false;
1047  if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num)
1048  {
1049  $sammelBuchung = true;
1050  } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num)
1051  {
1052  $sammelBuchung = true;
1053  } elseif ($aIndex + 1 < $aSize
1054  && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1055  && $aIndex - 1 < $aSize
1056  && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1057  )
1058  {
1059  $sammelBuchung = true;
1060  }
1061 
1062  //Blg
1063  print $line->piece_num.$this->separator;
1064 
1065  // Datum
1066  $date = dol_print_date($line->doc_date, '%d.%m.%Y');
1067  print $date.$this->separator;
1068 
1069  // Kto
1070  print length_accountg($line->numero_compte).$this->separator;
1071  // S/H
1072  if ($line->sens == 'D')
1073  {
1074  print 'S'.$this->separator;
1075  } else {
1076  print 'H'.$this->separator;
1077  }
1078  //Grp
1079  print self::trunc($line->code_journal, 1).$this->separator;
1080  // GKto
1081  if (empty($line->code_tiers))
1082  {
1083  if ($line->piece_num == $thisPieceNum)
1084  {
1085  print length_accounta($thisPieceAccountNr).$this->separator;
1086  } else {
1087  print "div".$this->separator;
1088  }
1089  } else {
1090  print length_accounta($line->code_tiers).$this->separator;
1091  }
1092  //SId
1093  print $this->separator;
1094  //SIdx
1095  print "0".$this->separator;
1096  //KIdx
1097  print "0".$this->separator;
1098  //BTyp
1099  print "0".$this->separator;
1100 
1101  //MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
1102  if ($sammelBuchung)
1103  {
1104  print "2".$this->separator;
1105  } else {
1106  print "1".$this->separator;
1107  }
1108  // Code
1109  print '""'.$this->separator;
1110  // Netto
1111  print abs($line->debit - $line->credit).$this->separator;
1112  // Steuer
1113  print "0.00".$this->separator;
1114  // FW-Betrag
1115  print "0.00".$this->separator;
1116  // Tx1
1117  $line1 = self::toAnsi($line->label_compte, 29);
1118  if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3)
1119  {
1120  $line1 = "";
1121  }
1122  $line2 = self::toAnsi($line->doc_ref, 29);
1123  if (strlen($line1) == 0)
1124  {
1125  $line1 = $line2;
1126  $line2 = "";
1127  }
1128  if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27)
1129  {
1130  $line1 = $line1.' / '.$line2;
1131  $line2 = "";
1132  }
1133 
1134  print '"'.self::toAnsi($line1).'"'.$this->separator;
1135  // Tx2
1136  print '"'.self::toAnsi($line2).'"'.$this->separator;
1137  //PkKey
1138  print "0".$this->separator;
1139  //OpId
1140  print $this->separator;
1141 
1142  // Flag
1143  print "0";
1144 
1145  print $this->end_line;
1146 
1147  if ($line->piece_num !== $thisPieceNum)
1148  {
1149  $thisPieceNum = $line->piece_num;
1150  $thisPieceAccountNr = $line->numero_compte;
1151  }
1152  }
1153  }
1154 
1163  public function exportLDCompta($objectLines)
1164  {
1165 
1166  $separator = ';';
1167  $end_line = "\r\n";
1168 
1169  foreach ($objectLines as $line) {
1170  $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1171  $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1172  $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1173 
1174  // TYPE
1175  $type_enregistrement = 'E'; // For write movement
1176  print $type_enregistrement.$separator;
1177  // JNAL
1178  print substr($line->code_journal, 0, 2).$separator;
1179  // NECR
1180  print $line->id.$separator;
1181  // NPIE
1182  print $line->piece_num.$separator;
1183  // DATP
1184  print $date_document.$separator;
1185  // LIBE
1186  print $line->label_operation.$separator;
1187  // DATH
1188  print $date_lim_reglement.$separator;
1189  // CNPI
1190  if ($line->doc_type == 'supplier_invoice') {
1191  if (($line->debit - $line->credit) > 0) {
1192  $nature_piece = 'AF';
1193  } else {
1194  $nature_piece = 'FF';
1195  }
1196  } elseif ($line->doc_type == 'customer_invoice') {
1197  if (($line->debit - $line->credit) < 0) {
1198  $nature_piece = 'AC';
1199  } else {
1200  $nature_piece = 'FC';
1201  }
1202  } else {
1203  $nature_piece = '';
1204  }
1205  print $nature_piece.$separator;
1206  // RACI
1207  // if (! empty($line->subledger_account)) {
1208  // if ($line->doc_type == 'supplier_invoice') {
1209  // $racine_subledger_account = '40';
1210  // } elseif ($line->doc_type == 'customer_invoice') {
1211  // $racine_subledger_account = '41';
1212  // } else {
1213  // $racine_subledger_account = '';
1214  // }
1215  // } else {
1216  $racine_subledger_account = ''; // for records of type E leave this field blank
1217  // }
1218 
1219  print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
1220  // MONT
1221  print price(abs($line->debit - $line->credit), 0, '', 1, 2, 2).$separator;
1222  // CODC
1223  print $line->sens.$separator;
1224  // CPTG
1225  print length_accountg($line->numero_compte).$separator;
1226  // DATE
1227  print $date_creation.$separator;
1228  // CLET
1229  print $line->lettering_code.$separator;
1230  // DATL
1231  print $line->date_lettering.$separator;
1232  // CPTA
1233  if (!empty($line->subledger_account)) {
1234  print length_accounta($line->subledger_account).$separator;
1235  } else {
1236  print $separator;
1237  }
1238  // CNAT
1239  if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
1240  print 'F'.$separator;
1241  } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
1242  print 'C'.$separator;
1243  } else {
1244  print $separator;
1245  }
1246  // SECT
1247  print $separator;
1248  // CTRE
1249  print $separator;
1250  // NORL
1251  print $separator;
1252  // DATV
1253  print $separator;
1254  // REFD
1255  print $line->doc_ref.$separator;
1256  // CODH
1257  print $separator;
1258  // NSEQ
1259  print $separator;
1260  // MTDV
1261  print '0'.$separator;
1262  // CODV
1263  print $separator;
1264  // TXDV
1265  print '0'.$separator;
1266  // MOPM
1267  print $separator;
1268  // BONP
1269  print $separator;
1270  // BQAF
1271  print $separator;
1272  // ECES
1273  print $separator;
1274  // TXTL
1275  print $separator;
1276  // ECRM
1277  print $separator;
1278  // DATK
1279  print $separator;
1280  // HEUK
1281  print $separator;
1282 
1283  print $end_line;
1284  }
1285  }
1286 
1295  public function exportLDCompta10($objectLines)
1296  {
1297  require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
1298 
1299  $separator = ';';
1300  $end_line = "\r\n";
1301  $last_codeinvoice = '';
1302 
1303  foreach ($objectLines as $line) {
1304  // TYPE C
1305  if ($last_codeinvoice != $line->doc_ref) {
1306  //recherche societe en fonction de son code client
1307  $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
1308  $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
1309  $resql = $this->db->query($sql);
1310 
1311  if ($resql && $this->db->num_rows($resql) > 0)
1312  {
1313  $soc = $this->db->fetch_object($resql);
1314 
1315  $address = array('', '', '');
1316  if (strpos($soc->address, "\n") !== false) {
1317  $address = explode("\n", $soc->address);
1318  if (is_array($address) && count($address) > 0) {
1319  foreach ($address as $key=>$data) {
1320  $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
1321  $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
1322  }
1323  }
1324  } else {
1325  $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
1326  $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
1327  $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
1328  }
1329 
1330  $type_enregistrement = 'C';
1331  //TYPE
1332  print $type_enregistrement.$separator;
1333  //NOCL
1334  print $soc->code_client.$separator;
1335  //NMCM
1336  print $separator;
1337  //LIBI
1338  print $separator;
1339  //TITR
1340  print $separator;
1341  //RSSO
1342  print $soc->nom.$separator;
1343  //CAD1
1344  print $address[0].$separator;
1345  //CAD2
1346  print $address[1].$separator;
1347  //CAD3
1348  print $address[2].$separator;
1349  //COPO
1350  print $soc->zip.$separator;
1351  //BUDI
1352  print substr($soc->town, 0, 40).$separator;
1353  //CPAY
1354  print $separator;
1355  //PAYS
1356  print substr(getCountry($soc->fk_pays), 0, 40).$separator;
1357  //NTEL
1358  print $soc->phone.$separator;
1359  //TLEX
1360  print $separator;
1361  //TLPO
1362  print $separator;
1363  //TLCY
1364  print $separator;
1365  //NINT
1366  print $separator;
1367  //COMM
1368  print $separator;
1369  //SIRE
1370  print str_replace(" ", "", $soc->siret).$separator;
1371  //RIBP
1372  print $separator;
1373  //DOBQ
1374  print $separator;
1375  //IBBQ
1376  print $separator;
1377  //COBQ
1378  print $separator;
1379  //GUBQ
1380  print $separator;
1381  //CPBQ
1382  print $separator;
1383  //CLBQ
1384  print $separator;
1385  //BIBQ
1386  print $separator;
1387  //MOPM
1388  print $separator;
1389  //DJPM
1390  print $separator;
1391  //DMPM
1392  print $separator;
1393  //REFM
1394  print $separator;
1395  //SLVA
1396  print $separator;
1397  //PLCR
1398  print $separator;
1399  //ECFI
1400  print $separator;
1401  //CREP
1402  print $separator;
1403  //NREP
1404  print $separator;
1405  //TREP
1406  print $separator;
1407  //MREP
1408  print $separator;
1409  //GRRE
1410  print $separator;
1411  //LTTA
1412  print $separator;
1413  //CACT
1414  print $separator;
1415  //CODV
1416  print $separator;
1417  //GRTR
1418  print $separator;
1419  //NOFP
1420  print $separator;
1421  //BQAF
1422  print $separator;
1423  //BONP
1424  print $separator;
1425  //CESC
1426  print $separator;
1427 
1428  print $end_line;
1429  }
1430  }
1431 
1432  $date_document = dol_print_date($line->doc_date, '%Y%m%d');
1433  $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1434  $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1435 
1436  // TYPE E
1437  $type_enregistrement = 'E'; // For write movement
1438  print $type_enregistrement.$separator;
1439  // JNAL
1440  print substr($line->code_journal, 0, 2).$separator;
1441  // NECR
1442  print $line->id.$separator;
1443  // NPIE
1444  print $line->piece_num.$separator;
1445  // DATP
1446  print $date_document.$separator;
1447  // LIBE
1448  print dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1).$separator;
1449  // DATH
1450  print $date_lim_reglement.$separator;
1451  // CNPI
1452  if ($line->doc_type == 'supplier_invoice') {
1453  if (($line->debit - $line->credit) > 0) {
1454  $nature_piece = 'AF';
1455  } else {
1456  $nature_piece = 'FF';
1457  }
1458  } elseif ($line->doc_type == 'customer_invoice') {
1459  if (($line->debit - $line->credit) < 0) {
1460  $nature_piece = 'AC';
1461  } else {
1462  $nature_piece = 'FC';
1463  }
1464  } else {
1465  $nature_piece = '';
1466  }
1467  print $nature_piece.$separator;
1468  // RACI
1469  // if (! empty($line->subledger_account)) {
1470  // if ($line->doc_type == 'supplier_invoice') {
1471  // $racine_subledger_account = '40';
1472  // } elseif ($line->doc_type == 'customer_invoice') {
1473  // $racine_subledger_account = '41';
1474  // } else {
1475  // $racine_subledger_account = '';
1476  // }
1477  // } else {
1478  $racine_subledger_account = ''; // for records of type E leave this field blank
1479  // }
1480 
1481  print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
1482  // MONT
1483  print price(abs($line->debit - $line->credit), 0, '', 1, 2).$separator;
1484  // CODC
1485  print $line->sens.$separator;
1486  // CPTG
1487  print length_accountg($line->numero_compte).$separator;
1488  // DATE
1489  print $date_document.$separator;
1490  // CLET
1491  print $line->lettering_code.$separator;
1492  // DATL
1493  print $line->date_lettering.$separator;
1494  // CPTA
1495  if (!empty($line->subledger_account)) {
1496  print length_accounta($line->subledger_account).$separator;
1497  } else {
1498  print $separator;
1499  }
1500  // CNAT
1501  if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
1502  print 'F'.$separator;
1503  } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
1504  print 'C'.$separator;
1505  } else {
1506  print $separator;
1507  }
1508  // CTRE
1509  print $separator;
1510  // NORL
1511  print $separator;
1512  // DATV
1513  print $separator;
1514  // REFD
1515  print $line->doc_ref.$separator;
1516  // NECA
1517  print '0'.$separator;
1518  // CSEC
1519  print $separator;
1520  // CAFF
1521  print $separator;
1522  // CDES
1523  print $separator;
1524  // QTUE
1525  print $separator;
1526  // MTDV
1527  print '0'.$separator;
1528  // CODV
1529  print $separator;
1530  // TXDV
1531  print '0'.$separator;
1532  // MOPM
1533  print $separator;
1534  // BONP
1535  print $separator;
1536  // BQAF
1537  print $separator;
1538  // ECES
1539  print $separator;
1540  // TXTL
1541  print $separator;
1542  // ECRM
1543  print $separator;
1544  // DATK
1545  print $separator;
1546  // HEUK
1547  print $separator;
1548 
1549  print $end_line;
1550 
1551  $last_codeinvoice = $line->doc_ref;
1552  }
1553  }
1554 
1561  public function exportCharlemagne($objectLines)
1562  {
1563  global $langs;
1564  $langs->load('compta');
1565 
1566  $separator = "\t";
1567  $end_line = "\n";
1568 
1569  /*
1570  * Charlemagne export need header
1571  */
1572  print $langs->transnoentitiesnoconv('Date').$separator;
1573  print self::trunc($langs->transnoentitiesnoconv('Journal'), 6).$separator;
1574  print self::trunc($langs->transnoentitiesnoconv('Account'), 15).$separator;
1575  print self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60).$separator;
1576  print self::trunc($langs->transnoentitiesnoconv('Piece'), 20).$separator;
1577  print self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60).$separator;
1578  print $langs->transnoentitiesnoconv('Amount').$separator;
1579  print 'S'.$separator;
1580  print self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15).$separator;
1581  print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60).$separator;
1582  print self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15).$separator;
1583  print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60).$separator;
1584  print self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15).$separator;
1585  print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60).$separator;
1586  print $end_line;
1587 
1588  foreach ($objectLines as $line) {
1589  $date = dol_print_date($line->doc_date, '%Y%m%d');
1590  print $date.$separator; //Date
1591 
1592  print self::trunc($line->code_journal, 6).$separator; //Journal code
1593 
1594  if (!empty($line->subledger_account)) $account = $line->subledger_account;
1595  else {
1596  $account = $line->numero_compte;
1597  }
1598  print self::trunc($account, 15).$separator; //Account number
1599 
1600  print self::trunc($line->label_compte, 60).$separator; //Account label
1601  print self::trunc($line->doc_ref, 20).$separator; //Piece
1602  print self::trunc($line->label_operation, 60).$separator; //Operation label
1603  print price(abs($line->debit - $line->credit)).$separator; //Amount
1604  print $line->sens.$separator; //Direction
1605  print $separator; //Analytic
1606  print $separator; //Analytic
1607  print $separator; //Analytic
1608  print $separator; //Analytic
1609  print $separator; //Analytic
1610  print $separator; //Analytic
1611  print $end_line;
1612  }
1613  }
1614 
1622  public function exportGestimumV3($objectLines)
1623  {
1624  global $langs;
1625 
1626  $this->separator = ',';
1627 
1628  $invoices_infos = array();
1629  $supplier_invoices_infos = array();
1630  foreach ($objectLines as $line) {
1631  if ($line->debit == 0 && $line->credit == 0) {
1632  //unset($array[$line]);
1633  } else {
1634  $date = dol_print_date($line->doc_date, '%d/%m/%Y');
1635 
1636  $invoice_ref = $line->doc_ref;
1637  $company_name = "";
1638 
1639  if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
1640  if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
1641  ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
1642  if ($line->doc_type == 'customer_invoice') {
1643  // Get new customer invoice ref and company name
1644  $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
1645  $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
1646  $sql .= ' WHERE f.rowid = ' . $line->fk_doc;
1647  $resql = $this->db->query($sql);
1648  if ($resql) {
1649  if ($obj = $this->db->fetch_object($resql)) {
1650  // Save invoice infos
1651  $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
1652  $invoice_ref = $obj->ref;
1653  $company_name = $obj->nom;
1654  }
1655  }
1656  } else {
1657  // Get new supplier invoice ref and company name
1658  $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
1659  $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
1660  $sql .= ' WHERE ff.rowid = ' . $line->fk_doc;
1661  $resql = $this->db->query($sql);
1662  if ($resql) {
1663  if ($obj = $this->db->fetch_object($resql)) {
1664  // Save invoice infos
1665  $supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
1666  $invoice_ref = $obj->ref;
1667  $company_name = $obj->nom;
1668  }
1669  }
1670  }
1671  } elseif ($line->doc_type == 'customer_invoice') {
1672  // Retrieve invoice infos
1673  $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
1674  $company_name = $invoices_infos[$line->fk_doc]['company_name'];
1675  } else {
1676  // Retrieve invoice infos
1677  $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
1678  $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
1679  }
1680  }
1681 
1682  print $line->id . $this->separator;
1683  print $date . $this->separator;
1684  print substr($line->code_journal, 0, 4) . $this->separator;
1685 
1686  if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
1687  print length_accountg($line->subledger_account) . $this->separator;
1688  } else {
1689  print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator;
1690  }
1691  //Libellé Auto
1692  print $this->separator;
1693  //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator;
1694  //Libellé manuel
1695  print dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1) . $this->separator;
1696  //Numéro de pièce
1697  print dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . $this->separator;
1698  //Devise
1699  print 'EUR' . $this->separator;
1700  //Amount
1701  print price2num(abs($line->debit - $line->credit)) . $this->separator;
1702  //Sens
1703  print $line->sens . $this->separator;
1704  //Code lettrage
1705  print $this->separator;
1706  //Date Echéance
1707  print $date;
1708  print $this->end_line;
1709  }
1710  }
1711  }
1712 
1720  public function exportGestimumV5($objectLines)
1721  {
1722 
1723  $this->separator = ',';
1724 
1725  foreach ($objectLines as $line) {
1726  if ($line->debit == 0 && $line->credit == 0) {
1727  //unset($array[$line]);
1728  } else {
1729  $date = dol_print_date($line->doc_date, '%d%m%Y');
1730 
1731  print $line->id . $this->separator;
1732  print $date . $this->separator;
1733  print substr($line->code_journal, 0, 4) . $this->separator;
1734  if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
1735  print length_accountg($line->subledger_account) . $this->separator;
1736  } else {
1737  print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator;
1738  }
1739  print $this->separator;
1740  //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator;
1741  print '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"' . $this->separator;
1742  print '"' . dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . '"' . $this->separator;
1743  print price2num(abs($line->debit - $line->credit)) . $this->separator;
1744  print $line->sens . $this->separator;
1745  print $date . $this->separator;
1746  print $this->separator;
1747  print $this->separator;
1748  print 'EUR';
1749  print $this->end_line;
1750  }
1751  }
1752  }
1753 
1761  public static function trunc($str, $size)
1762  {
1763  return dol_trunc($str, $size, 'right', 'UTF-8', 1);
1764  }
1765 
1773  public static function toAnsi($str, $size = -1)
1774  {
1775  $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
1776  if ($retVal >= 0 && $size >= 0)
1777  {
1778  $retVal = mb_substr($retVal, 0, $size, 'Windows-1251');
1779  }
1780  return $retVal;
1781  }
1782 }
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
static getFormatCode($type)
Return string to summarize the format (Used to generated export filename)
exportCharlemagne($objectLines)
Export format : Charlemagne.
static getTypeConfig()
Array with all export type available (key + label) and parameters for config.
dol_now($mode= 'auto')
Return date for now.
exportGestimumV3($objectLines)
Export format : Gestimum V3.
Class to manage Dolibarr database access.
static trunc($str, $size)
trunc
export(&$TData, $formatexportset)
Function who chose which export to use with the default config, and make the export into a file...
__construct(DoliDB &$db)
Constructor.
exportLDCompta($objectLines)
Export format : LD Compta version 9 http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Docu...
price2fec($amount)
Function to format a value into a defined format for French administration (no thousand separator &amp; d...
exportCoala($objectLines)
Export format : COALA.
exportBob50($objectLines)
Export format : BOB50.
$conf db
API class for accounts.
Definition: inc.php:54
exportFEC2($objectLines)
Export format : FEC2.
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...
exportOpenConcerto($objectLines)
Export format : OpenConcerto.
exportCogilog($objectLines)
Export format : COGILOG.
static getType()
Array with all export type available (key + label)
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
exportQuadratus(&$TData)
Export format : Quadratus.
exportGestimumV5($objectLines)
Export format : Gestimum V5.
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
exportAgiris($objectLines)
Export format : Agiris Isacompta.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
exportCegid($objectLines)
Export format : CEGID.
exportWinfic(&$TData)
Export format : WinFic - eWinfic - WinSis Compta.
exportConfigurable($objectLines)
Export format : Configurable CSV.
exportFEC($objectLines)
Export format : FEC.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Manage the different format accountancy export.
static toAnsi($str, $size=-1)
toAnsi
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
exportLDCompta10($objectLines)
Export format : LD Compta version 10 &amp; higher http://www.ldsysteme.fr/fileadmin/telechargement/np/ldc...
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
exportCiel(&$TData)
Export format : CIEL.
exportEbp($objectLines)
Export format : EBP.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...
exportSAGE50SWISS($objectLines)
Export format : SAGE50SWISS.
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.