Passed
Branch develop (96ac0e)
by
unknown
23:19
created

AccountancyExport::exportQuadratus()   B

Complexity

Conditions 9
Paths 41

Size

Total Lines 126
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 9
eloc 64
nop 1
dl 0
loc 126
rs 7.2298
c 2
b 0
f 0
nc 41

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * Copyright (C) 2007-2012  Laurent Destailleur <[email protected]>
4
 * Copyright (C) 2014       Juanjo Menent       <[email protected]>
5
 * Copyright (C) 2015       Florian Henry       <[email protected]>
6
 * Copyright (C) 2015       Raphaël Doursenaud  <[email protected]>
7
 * Copyright (C) 2016       Pierre-Henry Favre  <[email protected]>
8
 * Copyright (C) 2016-2021  Alexandre Spangaro  <[email protected]>
9
 * Copyright (C) 2013-2017  Olivier Geffroy     <[email protected]>
10
 * Copyright (C) 2017       Elarifr. Ari Elbaz  <[email protected]>
11
 * Copyright (C) 2017-2019  Frédéric France     <[email protected]>
12
 * Copyright (C) 2017       André Schild        <[email protected]>
13
 * Copyright (C) 2020       Guillaume Alexandre <[email protected]>
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
29
/**
30
 * \file		htdocs/accountancy/class/accountancyexport.class.php
31
 * \ingroup		Accountancy (Double entries)
32
 * \brief 		Class accountancy export
33
 */
34
35
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
36
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
37
38
39
/**
40
 * Manage the different format accountancy export
41
 */
42
class AccountancyExport
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_ISUITEEXPERT = 200;
63
	// Generic FEC after that
64
	public static $EXPORT_TYPE_FEC = 1000;
65
	public static $EXPORT_TYPE_FEC2 = 1010;
66
67
68
	/**
69
	 * @var string[] Error codes (or messages)
70
	 */
71
	public $errors = array();
72
73
	/**
74
	 *
75
	 * @var string Separator
76
	 */
77
	public $separator = '';
78
79
	/**
80
	 *
81
	 * @var string End of line
82
	 */
83
	public $end_line = '';
84
85
	/**
86
	 * Constructor
87
	 *
88
	 * @param DoliDb $db Database handler
89
	 */
90
	public function __construct(DoliDB &$db)
91
	{
92
		global $conf;
93
94
		$this->db = &$db;
95
		$this->separator = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
96
		$this->end_line = empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? "\n" : ($conf->global->ACCOUNTING_EXPORT_ENDLINE == 1 ? "\n" : "\r\n");
97
	}
98
99
	/**
100
	 * Array with all export type available (key + label)
101
	 *
102
	 * @return array of type
103
	 */
104
	public static function getType()
105
	{
106
		global $langs;
107
108
		$listofexporttypes = array(
109
			self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans('Modelcsv_configurable'),
110
			self::$EXPORT_TYPE_CEGID => $langs->trans('Modelcsv_CEGID'),
111
			self::$EXPORT_TYPE_COALA => $langs->trans('Modelcsv_COALA'),
112
			self::$EXPORT_TYPE_BOB50 => $langs->trans('Modelcsv_bob50'),
113
			self::$EXPORT_TYPE_CIEL => $langs->trans('Modelcsv_ciel'),
114
			self::$EXPORT_TYPE_QUADRATUS => $langs->trans('Modelcsv_quadratus'),
115
			self::$EXPORT_TYPE_WINFIC => $langs->trans('Modelcsv_winfic'),
116
			self::$EXPORT_TYPE_EBP => $langs->trans('Modelcsv_ebp'),
117
			self::$EXPORT_TYPE_COGILOG => $langs->trans('Modelcsv_cogilog'),
118
			self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'),
119
			self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans('Modelcsv_openconcerto'),
120
			self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans('Modelcsv_Sage50_Swiss'),
121
			self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans('Modelcsv_charlemagne'),
122
			self::$EXPORT_TYPE_LDCOMPTA => $langs->trans('Modelcsv_LDCompta'),
123
			self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans('Modelcsv_LDCompta10'),
124
			self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans('Modelcsv_Gestinumv3'),
125
			self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans('Modelcsv_Gestinumv5'),
126
			self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'),
127
			self::$EXPORT_TYPE_FEC2 => $langs->trans('Modelcsv_FEC2'),
128
			self::$EXPORT_TYPE_ISUITEEXPERT => 'Export iSuite Expert',
129
		);
130
131
		ksort($listofexporttypes, SORT_NUMERIC);
132
133
		return $listofexporttypes;
134
	}
135
136
	/**
137
	 * Return string to summarize the format (Used to generated export filename)
138
	 *
139
	 * @param	int		$type		Format id
140
	 * @return 	string				Format code
141
	 */
142
	public static function getFormatCode($type)
143
	{
144
		$formatcode = array(
145
			self::$EXPORT_TYPE_CONFIGURABLE => 'csv',
146
			self::$EXPORT_TYPE_CEGID => 'cegid',
147
			self::$EXPORT_TYPE_COALA => 'coala',
148
			self::$EXPORT_TYPE_BOB50 => 'bob50',
149
			self::$EXPORT_TYPE_CIEL => 'ciel',
150
			self::$EXPORT_TYPE_QUADRATUS => 'quadratus',
151
			self::$EXPORT_TYPE_WINFIC => 'winfic',
152
			self::$EXPORT_TYPE_EBP => 'ebp',
153
			self::$EXPORT_TYPE_COGILOG => 'cogilog',
154
			self::$EXPORT_TYPE_AGIRIS => 'agiris',
155
			self::$EXPORT_TYPE_OPENCONCERTO => 'openconcerto',
156
			self::$EXPORT_TYPE_SAGE50_SWISS => 'sage50ch',
157
			self::$EXPORT_TYPE_CHARLEMAGNE => 'charlemagne',
158
			self::$EXPORT_TYPE_LDCOMPTA => 'ldcompta',
159
			self::$EXPORT_TYPE_LDCOMPTA10 => 'ldcompta10',
160
			self::$EXPORT_TYPE_GESTIMUMV3 => 'gestimumv3',
161
			self::$EXPORT_TYPE_GESTIMUMV5 => 'gestimumv5',
162
			self::$EXPORT_TYPE_FEC => 'fec',
163
			self::$EXPORT_TYPE_FEC2 => 'fec2',
164
			self::$EXPORT_TYPE_ISUITEEXPERT => 'isuiteexpert',
165
		);
166
167
		return $formatcode[$type];
168
	}
169
170
	/**
171
	 * Array with all export type available (key + label) and parameters for config
172
	 *
173
	 * @return array of type
174
	 */
175
	public static function getTypeConfig()
176
	{
177
		global $conf, $langs;
178
179
		return array(
180
			'param' => array(
181
				self::$EXPORT_TYPE_CONFIGURABLE => array(
182
					'label' => $langs->trans('Modelcsv_configurable'),
183
					'ACCOUNTING_EXPORT_FORMAT' => empty($conf->global->ACCOUNTING_EXPORT_FORMAT) ? 'txt' : $conf->global->ACCOUNTING_EXPORT_FORMAT,
184
					'ACCOUNTING_EXPORT_SEPARATORCSV' => empty($conf->global->ACCOUNTING_EXPORT_SEPARATORCSV) ? ',' : $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV,
185
					'ACCOUNTING_EXPORT_ENDLINE' => empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? 1 : $conf->global->ACCOUNTING_EXPORT_ENDLINE,
186
					'ACCOUNTING_EXPORT_DATE' => empty($conf->global->ACCOUNTING_EXPORT_DATE) ? '%d%m%Y' : $conf->global->ACCOUNTING_EXPORT_DATE,
187
				),
188
				self::$EXPORT_TYPE_CEGID => array(
189
					'label' => $langs->trans('Modelcsv_CEGID'),
190
				),
191
				self::$EXPORT_TYPE_COALA => array(
192
					'label' => $langs->trans('Modelcsv_COALA'),
193
				),
194
				self::$EXPORT_TYPE_BOB50 => array(
195
					'label' => $langs->trans('Modelcsv_bob50'),
196
				),
197
				self::$EXPORT_TYPE_CIEL => array(
198
					'label' => $langs->trans('Modelcsv_ciel'),
199
					'ACCOUNTING_EXPORT_FORMAT' => 'txt',
200
				),
201
				self::$EXPORT_TYPE_QUADRATUS => array(
202
					'label' => $langs->trans('Modelcsv_quadratus'),
203
					'ACCOUNTING_EXPORT_FORMAT' => 'txt',
204
				),
205
				self::$EXPORT_TYPE_WINFIC => array(
206
					'label' => $langs->trans('Modelcsv_winfic'),
207
					'ACCOUNTING_EXPORT_FORMAT' => 'txt',
208
				),
209
				self::$EXPORT_TYPE_EBP => array(
210
					'label' => $langs->trans('Modelcsv_ebp'),
211
				),
212
				self::$EXPORT_TYPE_COGILOG => array(
213
					'label' => $langs->trans('Modelcsv_cogilog'),
214
				),
215
				self::$EXPORT_TYPE_AGIRIS => array(
216
					'label' => $langs->trans('Modelcsv_agiris'),
217
				),
218
				self::$EXPORT_TYPE_OPENCONCERTO => array(
219
					'label' => $langs->trans('Modelcsv_openconcerto'),
220
				),
221
				self::$EXPORT_TYPE_SAGE50_SWISS => array(
222
					'label' => $langs->trans('Modelcsv_Sage50_Swiss'),
223
				),
224
				self::$EXPORT_TYPE_CHARLEMAGNE => array(
225
					'label' => $langs->trans('Modelcsv_charlemagne'),
226
					'ACCOUNTING_EXPORT_FORMAT' => 'txt',
227
				),
228
				self::$EXPORT_TYPE_LDCOMPTA => array(
229
					'label' => $langs->trans('Modelcsv_LDCompta'),
230
				),
231
				self::$EXPORT_TYPE_LDCOMPTA10 => array(
232
					'label' => $langs->trans('Modelcsv_LDCompta10'),
233
				),
234
				self::$EXPORT_TYPE_GESTIMUMV3 => array(
235
					'label' => $langs->trans('Modelcsv_Gestinumv3'),
236
					'ACCOUNTING_EXPORT_FORMAT' => 'txt',
237
				),
238
				self::$EXPORT_TYPE_GESTIMUMV5 => array(
239
					'label' => $langs->trans('Modelcsv_Gestinumv5'),
240
					'ACCOUNTING_EXPORT_FORMAT' => 'txt',
241
				),
242
				self::$EXPORT_TYPE_FEC => array(
243
					'label' => $langs->trans('Modelcsv_FEC'),
244
					'ACCOUNTING_EXPORT_FORMAT' => 'txt',
245
				),
246
				self::$EXPORT_TYPE_FEC2 => array(
247
					'label' => $langs->trans('Modelcsv_FEC2'),
248
					'ACCOUNTING_EXPORT_FORMAT' => 'txt',
249
				),
250
				self::$EXPORT_TYPE_ISUITEEXPERT => array(
251
					'label' => 'iSuite Expert',
252
					'ACCOUNTING_EXPORT_FORMAT' => 'csv',
253
				),
254
			),
255
			'cr'=> array(
256
				'1' => $langs->trans("Unix"),
257
				'2' => $langs->trans("Windows")
258
			),
259
			'format' => array(
260
				'csv' => $langs->trans("csv"),
261
				'txt' => $langs->trans("txt")
262
			),
263
		);
264
	}
265
266
267
	/**
268
	 * Function who chose which export to use with the default config, and make the export into a file
269
	 *
270
	 * @param 	array	$TData 				Array with data
271
	 * @param	int		$formatexportset	Id of export format
272
	 * @return 	void
273
	 */
274
	public function export(&$TData, $formatexportset)
275
	{
276
		global $conf, $langs;
277
		global $search_date_end; // Used into /accountancy/tpl/export_journal.tpl.php
278
279
		// Define name of file to save
280
		$filename = 'general_ledger-'.$this->getFormatCode($formatexportset);
281
		$type_export = 'general_ledger';
282
283
		global $db; // The tpl file use $db
284
		include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
285
286
287
		switch ($formatexportset) {
288
			case self::$EXPORT_TYPE_CONFIGURABLE:
289
				$this->exportConfigurable($TData);
290
				break;
291
			case self::$EXPORT_TYPE_CEGID:
292
				$this->exportCegid($TData);
293
				break;
294
			case self::$EXPORT_TYPE_COALA:
295
				$this->exportCoala($TData);
296
				break;
297
			case self::$EXPORT_TYPE_BOB50:
298
				$this->exportBob50($TData);
299
				break;
300
			case self::$EXPORT_TYPE_CIEL:
301
				$this->exportCiel($TData);
302
				break;
303
			case self::$EXPORT_TYPE_QUADRATUS:
304
				$this->exportQuadratus($TData);
305
				break;
306
			case self::$EXPORT_TYPE_WINFIC:
307
				$this->exportWinfic($TData);
308
				break;
309
			case self::$EXPORT_TYPE_EBP:
310
				$this->exportEbp($TData);
311
				break;
312
			case self::$EXPORT_TYPE_COGILOG:
313
				$this->exportCogilog($TData);
314
				break;
315
			case self::$EXPORT_TYPE_AGIRIS:
316
				$this->exportAgiris($TData);
317
				break;
318
			case self::$EXPORT_TYPE_OPENCONCERTO:
319
				$this->exportOpenConcerto($TData);
320
				break;
321
			case self::$EXPORT_TYPE_SAGE50_SWISS:
322
				$this->exportSAGE50SWISS($TData);
323
				break;
324
			case self::$EXPORT_TYPE_CHARLEMAGNE:
325
				$this->exportCharlemagne($TData);
326
				break;
327
			case self::$EXPORT_TYPE_LDCOMPTA:
328
				$this->exportLDCompta($TData);
329
				break;
330
			case self::$EXPORT_TYPE_LDCOMPTA10:
331
				$this->exportLDCompta10($TData);
332
				break;
333
			case self::$EXPORT_TYPE_GESTIMUMV3:
334
				$this->exportGestimumV3($TData);
335
				break;
336
			case self::$EXPORT_TYPE_GESTIMUMV5:
337
				$this->exportGestimumV5($TData);
338
				break;
339
			case self::$EXPORT_TYPE_FEC:
340
				$this->exportFEC($TData);
341
				break;
342
			case self::$EXPORT_TYPE_FEC2:
343
				$this->exportFEC2($TData);
344
				break;
345
			case self::$EXPORT_TYPE_ISUITEEXPERT :
346
				$this->exportiSuiteExpert($TData);
347
				break;
348
			default:
349
				$this->errors[] = $langs->trans('accountancy_error_modelnotfound');
350
				break;
351
		}
352
	}
353
354
355
	/**
356
	 * Export format : CEGID
357
	 *
358
	 * @param array $objectLines data
359
	 * @return void
360
	 */
361
	public function exportCegid($objectLines)
362
	{
363
		foreach ($objectLines as $line) {
364
			$date = dol_print_date($line->doc_date, '%d%m%Y');
365
			$separator = ";";
366
			$end_line = "\n";
367
368
			print $date.$separator;
369
			print $line->code_journal.$separator;
370
			print length_accountg($line->numero_compte).$separator;
371
			print length_accounta($line->subledger_account).$separator;
372
			print $line->sens.$separator;
373
			print price2fec(abs($line->debit - $line->credit)).$separator;
374
			print dol_string_unaccent($line->label_operation).$separator;
375
			print dol_string_unaccent($line->doc_ref);
376
			print $end_line;
377
		}
378
	}
379
380
	/**
381
	 * Export format : COGILOG
382
	 *
383
	 * @param array $objectLines data
384
	 * @return void
385
	 */
386
	public function exportCogilog($objectLines)
387
	{
388
		foreach ($objectLines as $line) {
389
			$date = dol_print_date($line->doc_date, '%d%m%Y');
390
			$separator = ";";
391
			$end_line = "\n";
392
393
			print $line->code_journal.$separator;
394
			print $date.$separator;
395
			print $line->piece_num.$separator;
396
			print length_accountg($line->numero_compte).$separator;
397
			print ''.$separator;
398
			print $line->label_operation.$separator;
399
			print $date.$separator;
400
			if ($line->sens == 'D') {
401
				print price($line->debit).$separator;
402
				print ''.$separator;
403
			} elseif ($line->sens == 'C') {
404
				print ''.$separator;
405
				print price($line->credit).$separator;
406
			}
407
			print $line->doc_ref.$separator;
408
			print $line->label_operation.$separator;
409
			print $end_line;
410
		}
411
	}
412
413
	/**
414
	 * Export format : COALA
415
	 *
416
	 * @param array $objectLines data
417
	 * @return void
418
	 */
419
	public function exportCoala($objectLines)
420
	{
421
		// Coala export
422
		$separator = ";";
423
		$end_line = "\n";
424
425
		foreach ($objectLines as $line) {
426
			$date = dol_print_date($line->doc_date, '%d/%m/%Y');
427
428
			print $date.$separator;
429
			print $line->code_journal.$separator;
430
			print length_accountg($line->numero_compte).$separator;
431
			print $line->piece_num.$separator;
432
			print $line->doc_ref.$separator;
433
			print price($line->debit).$separator;
434
			print price($line->credit).$separator;
435
			print 'E'.$separator;
436
			print length_accounta($line->subledger_account).$separator;
437
			print $end_line;
438
		}
439
	}
440
441
	/**
442
	 * Export format : BOB50
443
	 *
444
	 * @param array $objectLines data
445
	 * @return void
446
	 */
447
	public function exportBob50($objectLines)
448
	{
449
450
		// Bob50
451
		$separator = ";";
452
		$end_line = "\n";
453
454
		foreach ($objectLines as $line) {
455
			print $line->piece_num.$separator;
456
			$date = dol_print_date($line->doc_date, '%d/%m/%Y');
457
			print $date.$separator;
458
459
			if (empty($line->subledger_account)) {
460
				print 'G'.$separator;
461
				print length_accounta($line->numero_compte).$separator;
462
			} else {
463
				if (substr($line->numero_compte, 0, 3) == '411') {
464
					print 'C'.$separator;
465
				}
466
				if (substr($line->numero_compte, 0, 3) == '401') {
467
					print 'F'.$separator;
468
				}
469
				print length_accountg($line->subledger_account).$separator;
470
			}
471
472
			print price($line->debit).$separator;
473
			print price($line->credit).$separator;
474
			print dol_trunc($line->label_operation, 32).$separator;
475
			print $end_line;
476
		}
477
	}
478
479
	/**
480
	 * Export format : CIEL (Format XIMPORT)
481
	 * Format since 2003 compatible CIEL version > 2002 / Sage50
482
	 * Last review for this format : 2021-09-13 Alexandre Spangaro ([email protected])
483
	 *
484
	 * Help : https://sage50c.online-help.sage.fr/aide-technique/
485
	 * In sage software | Use menu : "Exchange" > "Importing entries..."
486
	 *
487
	 * If you want to force filename to "XIMPORT.TXT" for automatically import file present in a directory :
488
	 * use constant ACCOUNTING_EXPORT_XIMPORT_FORCE_FILENAME
489
	 *
490
	 * @param array $TData data
491
	 * @return void
492
	 */
493
	public function exportCiel(&$TData)
494
	{
495
		$end_line = "\r\n";
496
497
		$i = 1;
498
499
		foreach ($TData as $data) {
500
			$code_compta = length_accountg($data->numero_compte);
501
			if (!empty($data->subledger_account)) {
502
				$code_compta = length_accounta($data->subledger_account);
503
			}
504
505
			$date_document = dol_print_date($data->doc_date, '%Y%m%d');
506
			$date_echeance = dol_print_date($data->date_lim_reglement, '%Y%m%d');
507
508
			$Tab = array();
509
			$Tab['num_ecriture'] = str_pad($data->piece_num, 5);
510
			$Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
511
			$Tab['date_ecriture'] = str_pad($date_document, 8, ' ', STR_PAD_LEFT);
512
			$Tab['date_echeance'] = str_pad($date_echeance, 8, ' ', STR_PAD_LEFT);
513
			$Tab['num_piece'] = str_pad(self::trunc($data->doc_ref, 12), 12);
514
			$Tab['num_compte'] = str_pad(self::trunc($code_compta, 11), 11);
515
			$Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).dol_string_unaccent($data->label_operation), 25), 25);
516
			$Tab['montant'] = str_pad(price2fec(abs($data->debit - $data->credit)), 13, ' ', STR_PAD_LEFT);
517
			$Tab['type_montant'] = str_pad($data->sens, 1);
518
			$Tab['vide'] = str_repeat(' ', 18); // Analytical accounting - Not managed in Dolibarr
519
			$Tab['intitule_compte'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 34), 34);
520
			$Tab['end'] = 'O2003'; // 0 = EUR | 2003 = Format Ciel
521
522
			$Tab['end_line'] = $end_line;
523
524
			print implode($Tab);
525
			$i++;
526
		}
527
	}
528
529
	/**
530
	 * Export format : Quadratus (Format ASCII)
531
	 * Format since 2015 compatible QuadraCOMPTA
532
	 * Last review for this format : 2021/09/13 Alexandre Spangaro ([email protected])
533
	 *
534
	 * Help : https://docplayer.fr/20769649-Fichier-d-entree-ascii-dans-quadracompta.html
535
	 * In QuadraCompta | Use menu : "Outils" > "Suivi des dossiers" > "Import ASCII(Compta)"
536
	 *
537
	 * @param array $TData data
538
	 * @return void
539
	 */
540
	public function exportQuadratus(&$TData)
541
	{
542
		global $conf, $db;
543
544
		$end_line = "\r\n";
545
546
		// We should use dol_now function not time however this is wrong date to transfert in accounting
547
		// $date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
548
		// $date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
549
		foreach ($TData as $data) {
550
			$code_compta = $data->numero_compte;
551
			if (!empty($data->subledger_account)) {
552
				$code_compta = $data->subledger_account;
553
			}
554
555
			$Tab = array();
556
557
			if (!empty($data->subledger_account)) {
558
				$Tab['type_ligne'] = 'C';
559
				$Tab['num_compte'] = str_pad(self::trunc($data->subledger_account, 8), 8);
560
				$Tab['lib_compte'] = str_pad(self::trunc($data->subledger_label, 30), 30);
561
562
				if ($data->doc_type == 'customer_invoice') {
563
					$Tab['lib_alpha'] = strtoupper(str_pad('C'.self::trunc($data->subledger_label, 6), 6));
564
					$Tab['filler'] = str_repeat(' ', 52);
565
					$Tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, 8), 8);
566
				} elseif ($data->doc_type == 'supplier_invoice') {
567
					$Tab['lib_alpha'] = strtoupper(str_pad('F'.self::trunc($data->subledger_label, 6), 6));
568
					$Tab['filler'] = str_repeat(' ', 52);
569
					$Tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, 8), 8);
570
				} else {
571
					$Tab['filler'] = str_repeat(' ', 59);
572
					$Tab['coll_compte'] = str_pad(' ', 8);
573
				}
574
575
				$Tab['filler2'] = str_repeat(' ', 110);
576
				$Tab['Maj'] = 2; // Partial update (alpha key, label, address, collectif, RIB)
577
578
				if ($data->doc_type == 'customer_invoice') {
579
					$Tab['type_compte'] = 'C';
580
				} elseif ($data->doc_type == 'supplier_invoice') {
581
					$Tab['coll_compte'] = 'F';
582
				} else {
583
					$Tab['coll_compte'] = 'G';
584
				}
585
586
				$Tab['filler3'] = str_repeat(' ', 235);
587
588
				$Tab['end_line'] = $end_line;
589
590
				print implode($Tab);
591
			}
592
593
			$Tab = array();
594
			$Tab['type_ligne'] = 'M';
595
			$Tab['num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
596
			$Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
597
			$Tab['folio'] = '000';
598
599
			// We use invoice date $data->doc_date not $date_ecriture which is the transfert date
600
			// maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
601
			//$Tab['date_ecriture'] = $date_ecriture;
602
			$Tab['date_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
603
			$Tab['filler'] = ' ';
604
			$Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).' '.dol_string_unaccent($data->label_operation), 20), 20);
605
606
			// Credit invoice - invert sens
607
			/*
608
			if ($data->montant < 0) {
609
				if ($data->sens == 'C') {
610
					$Tab['sens'] = 'D';
611
				} else {
612
					$Tab['sens'] = 'C';
613
				}
614
				$Tab['signe_montant'] = '-';
615
			} else {
616
				$Tab['sens'] = $data->sens; // C or D
617
				$Tab['signe_montant'] = '+';
618
			}*/
619
			$Tab['sens'] = $data->sens; // C or D
620
			$Tab['signe_montant'] = '+';
621
622
			// The amount must be in centimes without decimal points.
623
			$Tab['montant'] = str_pad(abs(($data->debit - $data->credit) * 100), 12, '0', STR_PAD_LEFT);
624
			$Tab['contrepartie'] = str_repeat(' ', 8);
625
626
			// Force date format : %d%m%y
627
			if (!empty($data->date_lim_reglement)) {
628
				//$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE);
629
				$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, '%d%m%y'); // Format must be ddmmyy
630
			} else {
631
				$Tab['date_echeance'] = '000000';
632
			}
633
634
			// Please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
635
			// $Tab['lettrage'] = str_repeat(' ', 5);
636
			$Tab['lettrage'] = str_repeat(' ', 2);
637
			$Tab['codestat'] = str_repeat(' ', 3);
638
			$Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 5), 5);
639
640
			// Keep correct quadra named field instead of anon filler
641
			// $Tab['filler2'] = str_repeat(' ', 20);
642
			$Tab['affaire'] = str_repeat(' ', 10);
643
			$Tab['quantity1'] = str_repeat(' ', 10);
644
			$Tab['num_piece2'] = str_pad(self::trunc($data->piece_num, 8), 8);
645
			$Tab['devis'] = str_pad($conf->currency, 3);
646
			$Tab['code_journal2'] = str_pad(self::trunc($data->code_journal, 3), 3);
647
			$Tab['filler3'] = str_repeat(' ', 3);
648
649
			// Keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
650
			// 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
651
			// TODO: we should filter more than only accent to avoid wrong line size
652
			// TODO: remove invoice number doc_ref in libelle,
653
			// TODO: we should offer an option for customer to build the libelle using invoice number / name / date in accounting software
654
			//$Tab['libelle_ecriture2'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref) . ' ' . dol_string_unaccent($data->label_operation), 30), 30);
655
			$Tab['libelle_ecriture2'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 30), 30);
656
			$Tab['codetva'] = str_repeat(' ', 2);
657
658
			// We need to keep the 10 lastest number of invoice doc_ref not the beginning part that is the unusefull almost same part
659
			// $Tab['num_piece3'] = str_pad(self::trunc($data->piece_num, 10), 10);
660
			$Tab['num_piece3'] = substr(self::trunc($data->doc_ref, 20), -10);
661
			$Tab['filler4'] = str_repeat(' ', 73);
662
663
			$Tab['end_line'] = $end_line;
664
665
			print implode($Tab);
666
		}
667
	}
668
669
	/**
670
	 * Export format : WinFic - eWinfic - WinSis Compta
671
	 *
672
	 *
673
	 * @param array $TData data
674
	 * @return void
675
	 */
676
	public function exportWinfic(&$TData)
677
	{
678
		global $conf;
679
680
		$end_line = "\r\n";
681
682
		//We should use dol_now function not time however this is wrong date to transfert in accounting
683
		//$date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
684
		//$date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
685
		foreach ($TData as $data) {
686
			$code_compta = $data->numero_compte;
687
			if (!empty($data->subledger_account)) {
688
				$code_compta = $data->subledger_account;
689
			}
690
691
			$Tab = array();
692
			//$Tab['type_ligne'] = 'M';
693
			$Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
694
695
			//We use invoice date $data->doc_date not $date_ecriture which is the transfert date
696
			//maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
697
			//$Tab['date_ecriture'] = $date_ecriture;
698
			$Tab['date_operation'] = dol_print_date($data->doc_date, '%d%m%Y');
699
700
			$Tab['folio'] = '     1';
701
702
			$Tab['num_ecriture'] = str_pad(self::trunc($data->piece_num, 6), 6, ' ', STR_PAD_LEFT);
703
704
			$Tab['jour_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
705
706
			$Tab['num_compte'] = str_pad(self::trunc($code_compta, 6), 6, '0');
707
708
			if ($data->sens == 'D') {
709
				$Tab['montant_debit']  = str_pad(number_format($data->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
710
711
				$Tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
712
			} else {
713
				$Tab['montant_debit']  = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
714
715
				$Tab['montant_crebit'] = str_pad(number_format($data->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
716
			}
717
718
			$Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).' '.dol_string_unaccent($data->label_operation), 30), 30);
719
720
			$Tab['lettrage'] = str_repeat(' ', 2);
721
722
			$Tab['code_piece'] = str_repeat(' ', 5);
723
724
			$Tab['code_stat'] = str_repeat(' ', 4);
725
726
			if (!empty($data->date_lim_reglement)) {
727
				//$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE);
728
				$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, '%d%m%Y');
729
			} else {
730
				$Tab['date_echeance'] = dol_print_date($data->doc_date, '%d%m%Y');
731
			}
732
733
			$Tab['monnaie'] = '1';
734
735
			$Tab['filler'] = ' ';
736
737
			$Tab['ind_compteur'] = ' ';
738
739
			$Tab['quantite'] = '0,000000000';
740
741
			$Tab['code_pointage'] = str_repeat(' ', 2);
742
743
			$Tab['end_line'] = $end_line;
744
745
			print implode('|', $Tab);
746
		}
747
	}
748
749
750
	/**
751
	 * Export format : EBP
752
	 *
753
	 * @param array $objectLines data
754
	 * @return void
755
	 */
756
	public function exportEbp($objectLines)
757
	{
758
759
		$separator = ',';
760
		$end_line = "\n";
761
762
		foreach ($objectLines as $line) {
763
			$date = dol_print_date($line->doc_date, '%d%m%Y');
764
765
			print $line->id.$separator;
766
			print $date.$separator;
767
			print $line->code_journal.$separator;
768
			if (empty($line->subledger_account)) {
769
				print $line->numero_compte.$separator;
770
			} else {
771
				print $line->subledger_account.$separator;
772
			}
773
			//print substr(length_accountg($line->numero_compte), 0, 2) . $separator;
774
			print '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"'.$separator;
775
			print '"'.dol_trunc($line->piece_num, 15, 'right', 'UTF-8', 1).'"'.$separator;
776
			print price2num(abs($line->debit - $line->credit)).$separator;
777
			print $line->sens.$separator;
778
			print $date.$separator;
779
			//print 'EUR';
780
			print $end_line;
781
		}
782
	}
783
784
785
	/**
786
	 * Export format : Agiris Isacompta
787
	 *
788
	 * @param array $objectLines data
789
	 * @return void
790
	 */
791
	public function exportAgiris($objectLines)
792
	{
793
794
		$separator = ';';
795
		$end_line = "\n";
796
797
		foreach ($objectLines as $line) {
798
			$date = dol_print_date($line->doc_date, '%d%m%Y');
799
800
			print $line->piece_num.$separator;
801
			print self::toAnsi($line->label_operation).$separator;
802
			print $date.$separator;
803
			print self::toAnsi($line->label_operation).$separator;
804
805
			if (empty($line->subledger_account)) {
806
				print length_accountg($line->numero_compte).$separator;
807
				print self::toAnsi($line->label_compte).$separator;
808
			} else {
809
				print length_accounta($line->subledger_account).$separator;
810
				print self::toAnsi($line->subledger_label).$separator;
811
			}
812
813
			print self::toAnsi($line->doc_ref).$separator;
814
			print price($line->debit).$separator;
815
			print price($line->credit).$separator;
816
			print price(abs($line->debit - $line->credit)).$separator;
817
			print $line->sens.$separator;
818
			print $line->lettering_code.$separator;
819
			print $line->code_journal;
820
			print $end_line;
821
		}
822
	}
823
824
	/**
825
	 * Export format : OpenConcerto
826
	 *
827
	 * @param array $objectLines data
828
	 * @return void
829
	 */
830
	public function exportOpenConcerto($objectLines)
831
	{
832
833
		$separator = ';';
834
		$end_line = "\n";
835
836
		foreach ($objectLines as $line) {
837
			$date = dol_print_date($line->doc_date, '%d/%m/%Y');
838
839
			print $date.$separator;
840
			print $line->code_journal.$separator;
841
			if (empty($line->subledger_account)) {
842
				print length_accountg($line->numero_compte).$separator;
843
			} else {
844
				print length_accounta($line->subledger_account).$separator;
845
			}
846
			print $line->doc_ref.$separator;
847
			print $line->label_operation.$separator;
848
			print price($line->debit).$separator;
849
			print price($line->credit).$separator;
850
851
			print $end_line;
852
		}
853
	}
854
855
	/**
856
	 * Export format : Configurable CSV
857
	 *
858
	 * @param array $objectLines data
859
	 * @return void
860
	 */
861
	public function exportConfigurable($objectLines)
862
	{
863
		global $conf;
864
865
		$separator = $this->separator;
866
867
		foreach ($objectLines as $line) {
868
			$tab = array();
869
			// export configurable
870
			$date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
871
			$tab[] = $line->piece_num;
872
			$tab[] = $date;
873
			$tab[] = $line->doc_ref;
874
			$tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
875
			$tab[] = length_accountg($line->numero_compte);
876
			$tab[] = length_accounta($line->subledger_account);
877
			$tab[] = price2num($line->debit);
878
			$tab[] = price2num($line->credit);
879
			$tab[] = price2num($line->debit - $line->credit);
880
			$tab[] = $line->code_journal;
881
882
			print implode($separator, $tab).$this->end_line;
883
		}
884
	}
885
886
	/**
887
	 * Export format : FEC
888
	 *
889
	 * @param array $objectLines data
890
	 * @return void
891
	 */
892
	public function exportFEC($objectLines)
893
	{
894
		global $langs;
895
896
		$separator = "\t";
897
		$end_line = "\r\n";
898
899
		print "JournalCode".$separator;
900
		print "JournalLib".$separator;
901
		print "EcritureNum".$separator;
902
		print "EcritureDate".$separator;
903
		print "CompteNum".$separator;
904
		print "CompteLib".$separator;
905
		print "CompAuxNum".$separator;
906
		print "CompAuxLib".$separator;
907
		print "PieceRef".$separator;
908
		print "PieceDate".$separator;
909
		print "EcritureLib".$separator;
910
		print "Debit".$separator;
911
		print "Credit".$separator;
912
		print "EcritureLet".$separator;
913
		print "DateLet".$separator;
914
		print "ValidDate".$separator;
915
		print "Montantdevise".$separator;
916
		print "Idevise".$separator;
917
		print "DateLimitReglmt";
918
		print $end_line;
919
920
		foreach ($objectLines as $line) {
921
			if ($line->debit == 0 && $line->credit == 0) {
922
				//unset($array[$line]);
923
			} else {
924
				$date_creation = dol_print_date($line->date_creation, '%Y%m%d');
925
				$date_document = dol_print_date($line->doc_date, '%Y%m%d');
926
				$date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
927
				$date_validation = dol_print_date($line->date_validated, '%Y%m%d');
928
				$date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
929
930
				// FEC:JournalCode
931
				print $line->code_journal . $separator;
932
933
				// FEC:JournalLib
934
				print dol_string_unaccent($langs->transnoentities($line->journal_label)) . $separator;
935
936
				// FEC:EcritureNum
937
				print $line->piece_num . $separator;
938
939
				// FEC:EcritureDate
940
				print $date_document . $separator;
941
942
				// FEC:CompteNum
943
				print $line->numero_compte . $separator;
944
945
				// FEC:CompteLib
946
				print dol_string_unaccent($line->label_compte) . $separator;
947
948
				// FEC:CompAuxNum
949
				print $line->subledger_account . $separator;
950
951
				// FEC:CompAuxLib
952
				print dol_string_unaccent($line->subledger_label) . $separator;
953
954
				// FEC:PieceRef
955
				print $line->doc_ref . $separator;
956
957
				// FEC:PieceDate
958
				print dol_string_unaccent($date_creation) . $separator;
959
960
				// FEC:EcritureLib
961
				print dol_string_unaccent($line->label_operation) . $separator;
962
963
				// FEC:Debit
964
				print price2fec($line->debit) . $separator;
965
966
				// FEC:Credit
967
				print price2fec($line->credit) . $separator;
968
969
				// FEC:EcritureLet
970
				print $line->lettering_code . $separator;
971
972
				// FEC:DateLet
973
				print $date_lettering . $separator;
974
975
				// FEC:ValidDate
976
				print $date_validation . $separator;
977
978
				// FEC:Montantdevise
979
				print $line->multicurrency_amount . $separator;
980
981
				// FEC:Idevise
982
				print $line->multicurrency_code.$separator;
983
984
				// FEC_suppl:DateLimitReglmt
985
				print $date_limit_payment;
986
987
				print $end_line;
988
			}
989
		}
990
	}
991
992
	/**
993
	 * Export format : FEC2
994
	 *
995
	 * @param array $objectLines data
996
	 * @return void
997
	 */
998
	public function exportFEC2($objectLines)
999
	{
1000
		global $langs;
1001
1002
		$separator = "\t";
1003
		$end_line = "\r\n";
1004
1005
		print "JournalCode".$separator;
1006
		print "JournalLib".$separator;
1007
		print "EcritureNum".$separator;
1008
		print "EcritureDate".$separator;
1009
		print "CompteNum".$separator;
1010
		print "CompteLib".$separator;
1011
		print "CompAuxNum".$separator;
1012
		print "CompAuxLib".$separator;
1013
		print "PieceRef".$separator;
1014
		print "PieceDate".$separator;
1015
		print "EcritureLib".$separator;
1016
		print "Debit".$separator;
1017
		print "Credit".$separator;
1018
		print "EcritureLet".$separator;
1019
		print "DateLet".$separator;
1020
		print "ValidDate".$separator;
1021
		print "Montantdevise".$separator;
1022
		print "Idevise".$separator;
1023
		print "DateLimitReglmt";
1024
		print $end_line;
1025
1026
		foreach ($objectLines as $line) {
1027
			if ($line->debit == 0 && $line->credit == 0) {
1028
				//unset($array[$line]);
1029
			} else {
1030
				$date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1031
				$date_document = dol_print_date($line->doc_date, '%Y%m%d');
1032
				$date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
1033
				$date_validation = dol_print_date($line->date_validated, '%Y%m%d');
1034
				$date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1035
1036
				// FEC:JournalCode
1037
				print $line->code_journal . $separator;
1038
1039
				// FEC:JournalLib
1040
				print dol_string_unaccent($langs->transnoentities($line->journal_label)) . $separator;
1041
1042
				// FEC:EcritureNum
1043
				print $line->piece_num . $separator;
1044
1045
				// FEC:EcritureDate
1046
				print $date_creation . $separator;
1047
1048
				// FEC:CompteNum
1049
				print length_accountg($line->numero_compte) . $separator;
1050
1051
				// FEC:CompteLib
1052
				print dol_string_unaccent($line->label_compte) . $separator;
1053
1054
				// FEC:CompAuxNum
1055
				print length_accounta($line->subledger_account) . $separator;
1056
1057
				// FEC:CompAuxLib
1058
				print dol_string_unaccent($line->subledger_label) . $separator;
1059
1060
				// FEC:PieceRef
1061
				print $line->doc_ref . $separator;
1062
1063
				// FEC:PieceDate
1064
				print $date_document . $separator;
1065
1066
				// FEC:EcritureLib
1067
				print dol_string_unaccent($line->label_operation) . $separator;
1068
1069
				// FEC:Debit
1070
				print price2fec($line->debit) . $separator;
1071
1072
				// FEC:Credit
1073
				print price2fec($line->credit) . $separator;
1074
1075
				// FEC:EcritureLet
1076
				print $line->lettering_code . $separator;
1077
1078
				// FEC:DateLet
1079
				print $date_lettering . $separator;
1080
1081
				// FEC:ValidDate
1082
				print $date_validation . $separator;
1083
1084
				// FEC:Montantdevise
1085
				print $line->multicurrency_amount . $separator;
1086
1087
				// FEC:Idevise
1088
				print $line->multicurrency_code . $separator;
1089
1090
				// FEC_suppl:DateLimitReglmt
1091
				print $date_limit_payment;
1092
1093
				print $end_line;
1094
			}
1095
		}
1096
	}
1097
1098
	/**
1099
	 * Export format : SAGE50SWISS
1100
	 *
1101
	 * https://onlinehelp.sageschweiz.ch/default.aspx?tabid=19984
1102
	 * http://media.topal.ch/Public/Schnittstellen/TAF/Specification/Sage50-TAF-format.pdf
1103
	 *
1104
	 * @param array $objectLines data
1105
	 *
1106
	 * @return void
1107
	 */
1108
	public function exportSAGE50SWISS($objectLines)
1109
	{
1110
		// SAGE50SWISS
1111
		$this->separator = ',';
1112
		$this->end_line = "\r\n";
1113
1114
		// Print header line
1115
		print "Blg,Datum,Kto,S/H,Grp,GKto,SId,SIdx,KIdx,BTyp,MTyp,Code,Netto,Steuer,FW-Betrag,Tx1,Tx2,PkKey,OpId,Flag";
1116
		print $this->end_line;
1117
		$thisPieceNum = "";
1118
		$thisPieceAccountNr = "";
1119
		$aSize = count($objectLines);
1120
		foreach ($objectLines as $aIndex => $line) {
1121
			$sammelBuchung = false;
1122
			if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1123
				$sammelBuchung = true;
1124
			} elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1125
				$sammelBuchung = true;
1126
			} elseif ($aIndex + 1 < $aSize
1127
					&& $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1128
					&& $aIndex - 1 < $aSize
1129
					&& $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1130
					) {
1131
				$sammelBuchung = true;
1132
			}
1133
1134
			//Blg
1135
			print $line->piece_num.$this->separator;
1136
1137
			// Datum
1138
			$date = dol_print_date($line->doc_date, '%d.%m.%Y');
1139
			print $date.$this->separator;
1140
1141
			// Kto
1142
			print length_accountg($line->numero_compte).$this->separator;
1143
			// S/H
1144
			if ($line->sens == 'D') {
1145
				print 'S'.$this->separator;
1146
			} else {
1147
				print 'H'.$this->separator;
1148
			}
1149
			//Grp
1150
			print self::trunc($line->code_journal, 1).$this->separator;
1151
			// GKto
1152
			if (empty($line->code_tiers)) {
1153
				if ($line->piece_num == $thisPieceNum) {
1154
					print length_accounta($thisPieceAccountNr).$this->separator;
1155
				} else {
1156
					print "div".$this->separator;
1157
				}
1158
			} else {
1159
				print length_accounta($line->code_tiers).$this->separator;
1160
			}
1161
			//SId
1162
			print $this->separator;
1163
			//SIdx
1164
			print "0".$this->separator;
1165
			//KIdx
1166
			print "0".$this->separator;
1167
			//BTyp
1168
			print "0".$this->separator;
1169
1170
			//MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
1171
			if ($sammelBuchung) {
1172
				print "2".$this->separator;
1173
			} else {
1174
				print "1".$this->separator;
1175
			}
1176
			// Code
1177
			print '""'.$this->separator;
1178
			// Netto
1179
			print abs($line->debit - $line->credit).$this->separator;
1180
			// Steuer
1181
			print "0.00".$this->separator;
1182
			// FW-Betrag
1183
			print "0.00".$this->separator;
1184
			// Tx1
1185
			$line1 = self::toAnsi($line->label_compte, 29);
1186
			if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
1187
				$line1 = "";
1188
			}
1189
			$line2 = self::toAnsi($line->doc_ref, 29);
1190
			if (strlen($line1) == 0) {
1191
				$line1 = $line2;
1192
				$line2 = "";
1193
			}
1194
			if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1195
				$line1 = $line1.' / '.$line2;
1196
				$line2 = "";
1197
			}
1198
1199
			print '"'.self::toAnsi($line1).'"'.$this->separator;
1200
			// Tx2
1201
			print '"'.self::toAnsi($line2).'"'.$this->separator;
1202
			//PkKey
1203
			print "0".$this->separator;
1204
			//OpId
1205
			print $this->separator;
1206
1207
			// Flag
1208
			print "0";
1209
1210
			print $this->end_line;
1211
1212
			if ($line->piece_num !== $thisPieceNum) {
1213
				$thisPieceNum = $line->piece_num;
1214
				$thisPieceAccountNr = $line->numero_compte;
1215
			}
1216
		}
1217
	}
1218
1219
	/**
1220
	 * Export format : LD Compta version 9
1221
	 * http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Documentation/IntCptW9.pdf
1222
	 *
1223
	 * @param array $objectLines data
1224
	 *
1225
	 * @return void
1226
	 */
1227
	public function exportLDCompta($objectLines)
1228
	{
1229
1230
		$separator = ';';
1231
		$end_line = "\r\n";
1232
1233
		foreach ($objectLines as $line) {
1234
			$date_document = dol_print_date($line->doc_date, '%Y%m%d');
1235
			$date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1236
			$date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1237
1238
			// TYPE
1239
			$type_enregistrement = 'E'; // For write movement
1240
			print $type_enregistrement.$separator;
1241
			// JNAL
1242
			print substr($line->code_journal, 0, 2).$separator;
1243
			// NECR
1244
			print $line->id.$separator;
1245
			// NPIE
1246
			print $line->piece_num.$separator;
1247
			// DATP
1248
			print $date_document.$separator;
1249
			// LIBE
1250
			print $line->label_operation.$separator;
1251
			// DATH
1252
			print $date_lim_reglement.$separator;
1253
			// CNPI
1254
			if ($line->doc_type == 'supplier_invoice') {
1255
				if (($line->debit - $line->credit) > 0) {
1256
					$nature_piece = 'AF';
1257
				} else {
1258
					$nature_piece = 'FF';
1259
				}
1260
			} elseif ($line->doc_type == 'customer_invoice') {
1261
				if (($line->debit - $line->credit) < 0) {
1262
					$nature_piece = 'AC';
1263
				} else {
1264
					$nature_piece = 'FC';
1265
				}
1266
			} else {
1267
				$nature_piece = '';
1268
			}
1269
			print $nature_piece.$separator;
1270
			// RACI
1271
			//			if (! empty($line->subledger_account)) {
1272
			//              if ($line->doc_type == 'supplier_invoice') {
1273
			//                  $racine_subledger_account = '40';
1274
			//              } elseif ($line->doc_type == 'customer_invoice') {
1275
			//                  $racine_subledger_account = '41';
1276
			//              } else {
1277
			//                  $racine_subledger_account = '';
1278
			//              }
1279
			//          } else {
1280
			$racine_subledger_account = ''; // for records of type E leave this field blank
1281
			//          }
1282
1283
			print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
1284
			// MONT
1285
			print price(abs($line->debit - $line->credit), 0, '', 1, 2, 2).$separator;
1286
			// CODC
1287
			print $line->sens.$separator;
1288
			// CPTG
1289
			print length_accountg($line->numero_compte).$separator;
1290
			// DATE
1291
			print $date_creation.$separator;
1292
			// CLET
1293
			print $line->lettering_code.$separator;
1294
			// DATL
1295
			print $line->date_lettering.$separator;
1296
			// CPTA
1297
			if (!empty($line->subledger_account)) {
1298
				print length_accounta($line->subledger_account).$separator;
1299
			} else {
1300
				print $separator;
1301
			}
1302
			// CNAT
1303
			if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
1304
				print 'F'.$separator;
1305
			} elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
1306
				print 'C'.$separator;
1307
			} else {
1308
				print $separator;
1309
			}
1310
			// SECT
1311
			print $separator;
1312
			// CTRE
1313
			print $separator;
1314
			// NORL
1315
			print $separator;
1316
			// DATV
1317
			print $separator;
1318
			// REFD
1319
			print $line->doc_ref.$separator;
1320
			// CODH
1321
			print $separator;
1322
			// NSEQ
1323
			print $separator;
1324
			// MTDV
1325
			print '0'.$separator;
1326
			// CODV
1327
			print $separator;
1328
			// TXDV
1329
			print '0'.$separator;
1330
			// MOPM
1331
			print $separator;
1332
			// BONP
1333
			print $separator;
1334
			// BQAF
1335
			print $separator;
1336
			// ECES
1337
			print $separator;
1338
			// TXTL
1339
			print $separator;
1340
			// ECRM
1341
			print $separator;
1342
			// DATK
1343
			print $separator;
1344
			// HEUK
1345
			print $separator;
1346
1347
			print $end_line;
1348
		}
1349
	}
1350
1351
	/**
1352
	 * Export format : LD Compta version 10 & higher
1353
	 * Last review for this format : 08-15-2021 Alexandre Spangaro ([email protected])
1354
	 *
1355
	 * Help : http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Documentation/IntCptW10.pdf
1356
	 *
1357
	 * @param array $objectLines data
1358
	 *
1359
	 * @return void
1360
	 */
1361
	public function exportLDCompta10($objectLines)
1362
	{
1363
		require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
1364
1365
		$separator = ';';
1366
		$end_line = "\r\n";
1367
		$last_codeinvoice = '';
1368
1369
		foreach ($objectLines as $line) {
1370
			// TYPE C
1371
			if ($last_codeinvoice != $line->doc_ref) {
1372
				//recherche societe en fonction de son code client
1373
				$sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
1374
				$sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
1375
				$resql = $this->db->query($sql);
1376
1377
				if ($resql && $this->db->num_rows($resql) > 0) {
1378
					$soc = $this->db->fetch_object($resql);
1379
1380
					$address = array('', '', '');
1381
					if (strpos($soc->address, "\n") !== false) {
1382
						$address = explode("\n", $soc->address);
1383
						if (is_array($address) && count($address) > 0) {
1384
							foreach ($address as $key => $data) {
1385
								$address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
1386
								$address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
1387
							}
1388
						}
1389
					} else {
1390
						$address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
1391
						$address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
1392
						$address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
1393
					}
1394
1395
					$type_enregistrement = 'C';
1396
					//TYPE
1397
					print $type_enregistrement.$separator;
1398
					//NOCL
1399
					print $soc->code_client.$separator;
1400
					//NMCM
1401
					print $separator;
1402
					//LIBI
1403
					print $separator;
1404
					//TITR
1405
					print $separator;
1406
					//RSSO
1407
					print $soc->nom.$separator;
1408
					//CAD1
1409
					print  $address[0].$separator;
1410
					//CAD2
1411
					print  $address[1].$separator;
1412
					//CAD3
1413
					print  $address[2].$separator;
1414
					//COPO
1415
					print  $soc->zip.$separator;
1416
					//BUDI
1417
					print  substr($soc->town, 0, 40).$separator;
1418
					//CPAY
1419
					print  $separator;
1420
					//PAYS
1421
					print  substr(getCountry($soc->fk_pays), 0, 40).$separator;
1422
					//NTEL
1423
					print $soc->phone.$separator;
1424
					//TLEX
1425
					print $separator;
1426
					//TLPO
1427
					print $separator;
1428
					//TLCY
1429
					print $separator;
1430
					//NINT
1431
					print $separator;
1432
					//COMM
1433
					print $separator;
1434
					//SIRE
1435
					print str_replace(" ", "", $soc->siret).$separator;
1436
					//RIBP
1437
					print $separator;
1438
					//DOBQ
1439
					print $separator;
1440
					//IBBQ
1441
					print $separator;
1442
					//COBQ
1443
					print $separator;
1444
					//GUBQ
1445
					print $separator;
1446
					//CPBQ
1447
					print $separator;
1448
					//CLBQ
1449
					print $separator;
1450
					//BIBQ
1451
					print $separator;
1452
					//MOPM
1453
					print $separator;
1454
					//DJPM
1455
					print $separator;
1456
					//DMPM
1457
					print $separator;
1458
					//REFM
1459
					print $separator;
1460
					//SLVA
1461
					print $separator;
1462
					//PLCR
1463
					print $separator;
1464
					//ECFI
1465
					print $separator;
1466
					//CREP
1467
					print $separator;
1468
					//NREP
1469
					print $separator;
1470
					//TREP
1471
					print $separator;
1472
					//MREP
1473
					print $separator;
1474
					//GRRE
1475
					print $separator;
1476
					//LTTA
1477
					print $separator;
1478
					//CACT
1479
					print $separator;
1480
					//CODV
1481
					print $separator;
1482
					//GRTR
1483
					print $separator;
1484
					//NOFP
1485
					print $separator;
1486
					//BQAF
1487
					print $separator;
1488
					//BONP
1489
					print $separator;
1490
					//CESC
1491
					print $separator;
1492
1493
					print $end_line;
1494
				}
1495
			}
1496
1497
			$date_document = dol_print_date($line->doc_date, '%Y%m%d');
1498
			$date_creation = dol_print_date($line->date_creation, '%Y%m%d');
1499
			$date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
1500
1501
			// TYPE E
1502
			$type_enregistrement = 'E'; // For write movement
1503
			print $type_enregistrement.$separator;
1504
			// JNAL
1505
			print substr($line->code_journal, 0, 2).$separator;
1506
			// NECR
1507
			print $line->id.$separator;
1508
			// NPIE
1509
			print $line->piece_num.$separator;
1510
			// DATP
1511
			print $date_document.$separator;
1512
			// LIBE
1513
			print dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1).$separator;
1514
			// DATH
1515
			print $date_lim_reglement.$separator;
1516
			// CNPI
1517
			if ($line->doc_type == 'supplier_invoice') {
1518
				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.
1519
					$nature_piece = 'AF';
1520
				} else {
1521
					$nature_piece = 'FF';
1522
				}
1523
			} elseif ($line->doc_type == 'customer_invoice') {
1524
				if (($line->amount) < 0) {
1525
					$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.
1526
				} else {
1527
					$nature_piece = 'FC';
1528
				}
1529
			} else {
1530
				$nature_piece = '';
1531
			}
1532
			print $nature_piece.$separator;
1533
			// RACI
1534
			//			if (! empty($line->subledger_account)) {
1535
			//				if ($line->doc_type == 'supplier_invoice') {
1536
			//					$racine_subledger_account = '40';
1537
			//				} elseif ($line->doc_type == 'customer_invoice') {
1538
			//					$racine_subledger_account = '41';
1539
			//				} else {
1540
			//					$racine_subledger_account = '';
1541
			//				}
1542
			//			} else {
1543
			$racine_subledger_account = ''; // for records of type E leave this field blank
1544
			//			}
1545
1546
			print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
1547
			// MONT
1548
			print price(abs($line->debit - $line->credit), 0, '', 1, 2).$separator;
1549
			// CODC
1550
			print $line->sens.$separator;
1551
			// CPTG
1552
			print length_accountg($line->numero_compte).$separator;
1553
			// DATE
1554
			print $date_document.$separator;
1555
			// CLET
1556
			print $line->lettering_code.$separator;
1557
			// DATL
1558
			print $line->date_lettering.$separator;
1559
			// CPTA
1560
			if (!empty($line->subledger_account)) {
1561
				print length_accounta($line->subledger_account).$separator;
1562
			} else {
1563
				print $separator;
1564
			}
1565
			// CNAT
1566
			if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
1567
				print 'F'.$separator;
1568
			} elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
1569
				print 'C'.$separator;
1570
			} else {
1571
				print $separator;
1572
			}
1573
			// CTRE
1574
			print $separator;
1575
			// NORL
1576
			print $separator;
1577
			// DATV
1578
			print $separator;
1579
			// REFD
1580
			print $line->doc_ref.$separator;
1581
			// NECA
1582
			print '0'.$separator;
1583
			// CSEC
1584
			print $separator;
1585
			// CAFF
1586
			print $separator;
1587
			// CDES
1588
			print $separator;
1589
			// QTUE
1590
			print $separator;
1591
			// MTDV
1592
			print '0'.$separator;
1593
			// CODV
1594
			print $separator;
1595
			// TXDV
1596
			print '0'.$separator;
1597
			// MOPM
1598
			print $separator;
1599
			// BONP
1600
			print $separator;
1601
			// BQAF
1602
			print $separator;
1603
			// ECES
1604
			print $separator;
1605
			// TXTL
1606
			print $separator;
1607
			// ECRM
1608
			print $separator;
1609
			// DATK
1610
			print $separator;
1611
			// HEUK
1612
			print $separator;
1613
1614
			print $end_line;
1615
1616
			$last_codeinvoice = $line->doc_ref;
1617
		}
1618
	}
1619
1620
	/**
1621
	 * Export format : Charlemagne
1622
	 *
1623
	 * @param array $objectLines data
1624
	 * @return void
1625
	 */
1626
	public function exportCharlemagne($objectLines)
1627
	{
1628
		global $langs;
1629
		$langs->load('compta');
1630
1631
		$separator = "\t";
1632
		$end_line = "\n";
1633
1634
		/*
1635
		 * Charlemagne export need header
1636
		 */
1637
		print $langs->transnoentitiesnoconv('Date').$separator;
1638
		print self::trunc($langs->transnoentitiesnoconv('Journal'), 6).$separator;
1639
		print self::trunc($langs->transnoentitiesnoconv('Account'), 15).$separator;
1640
		print self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60).$separator;
1641
		print self::trunc($langs->transnoentitiesnoconv('Piece'), 20).$separator;
1642
		print self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60).$separator;
1643
		print $langs->transnoentitiesnoconv('Amount').$separator;
1644
		print 'S'.$separator;
1645
		print self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15).$separator;
1646
		print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60).$separator;
1647
		print self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15).$separator;
1648
		print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60).$separator;
1649
		print self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15).$separator;
1650
		print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60).$separator;
1651
		print $end_line;
1652
1653
		foreach ($objectLines as $line) {
1654
			$date = dol_print_date($line->doc_date, '%Y%m%d');
1655
			print $date.$separator; //Date
1656
1657
			print self::trunc($line->code_journal, 6).$separator; //Journal code
1658
1659
			if (!empty($line->subledger_account)) {
1660
				$account = $line->subledger_account;
1661
			} else {
1662
				$account = $line->numero_compte;
1663
			}
1664
			print self::trunc($account, 15).$separator; //Account number
1665
1666
			print self::trunc($line->label_compte, 60).$separator; //Account label
1667
			print self::trunc($line->doc_ref, 20).$separator; //Piece
1668
			print self::trunc($line->label_operation, 60).$separator; //Operation label
1669
			print price(abs($line->debit - $line->credit)).$separator; //Amount
1670
			print $line->sens.$separator; //Direction
1671
			print $separator; //Analytic
1672
			print $separator; //Analytic
1673
			print $separator; //Analytic
1674
			print $separator; //Analytic
1675
			print $separator; //Analytic
1676
			print $separator; //Analytic
1677
			print $end_line;
1678
		}
1679
	}
1680
1681
	/**
1682
	 * Export format : Gestimum V3
1683
	 *
1684
	 * @param array $objectLines data
1685
	 *
1686
	 * @return void
1687
	 */
1688
	public function exportGestimumV3($objectLines)
1689
	{
1690
		global $langs;
1691
1692
		$this->separator = ',';
1693
1694
		$invoices_infos = array();
1695
		$supplier_invoices_infos = array();
1696
		foreach ($objectLines as $line) {
1697
			if ($line->debit == 0 && $line->credit == 0) {
1698
				//unset($array[$line]);
1699
			} else {
1700
				$date = dol_print_date($line->doc_date, '%d/%m/%Y');
1701
1702
				$invoice_ref = $line->doc_ref;
1703
				$company_name = "";
1704
1705
				if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
1706
					if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
1707
						($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
1708
						if ($line->doc_type == 'customer_invoice') {
1709
							// Get new customer invoice ref and company name
1710
							$sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
1711
							$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
1712
							$sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
1713
							$resql = $this->db->query($sql);
1714
							if ($resql) {
1715
								if ($obj = $this->db->fetch_object($resql)) {
1716
									// Save invoice infos
1717
									$invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
1718
									$invoice_ref = $obj->ref;
1719
									$company_name = $obj->nom;
1720
								}
1721
							}
1722
						} else {
1723
							// Get new supplier invoice ref and company name
1724
							$sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
1725
							$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
1726
							$sql .= ' WHERE ff.rowid = '.((int) $line->fk_doc);
1727
							$resql = $this->db->query($sql);
1728
							if ($resql) {
1729
								if ($obj = $this->db->fetch_object($resql)) {
1730
									// Save invoice infos
1731
									$supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
1732
									$invoice_ref = $obj->ref;
1733
									$company_name = $obj->nom;
1734
								}
1735
							}
1736
						}
1737
					} elseif ($line->doc_type == 'customer_invoice') {
1738
						// Retrieve invoice infos
1739
						$invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
1740
						$company_name = $invoices_infos[$line->fk_doc]['company_name'];
1741
					} else {
1742
						// Retrieve invoice infos
1743
						$invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
1744
						$company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
1745
					}
1746
				}
1747
1748
				print $line->id . $this->separator;
1749
				print $date . $this->separator;
1750
				print substr($line->code_journal, 0, 4) . $this->separator;
1751
1752
				if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
1753
					print length_accountg($line->subledger_account) . $this->separator;
1754
				} else {
1755
					print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator;
1756
				}
1757
				//Libellé Auto
1758
				print $this->separator;
1759
				//print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator;
1760
				//Libellé manuel
1761
				print dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1) . $this->separator;
1762
				//Numéro de pièce
1763
				print dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . $this->separator;
1764
				//Devise
1765
				print 'EUR' . $this->separator;
1766
				//Amount
1767
				print price2num(abs($line->debit - $line->credit)) . $this->separator;
1768
				//Sens
1769
				print $line->sens . $this->separator;
1770
				//Code lettrage
1771
				print $this->separator;
1772
				//Date Echéance
1773
				print $date;
1774
				print $this->end_line;
1775
			}
1776
		}
1777
	}
1778
1779
	/**
1780
	 * Export format : Gestimum V5
1781
	 *
1782
	 * @param array $objectLines data
1783
	 *
1784
	 * @return void
1785
	 */
1786
	public function exportGestimumV5($objectLines)
1787
	{
1788
1789
		$this->separator = ',';
1790
1791
		foreach ($objectLines as $line) {
1792
			if ($line->debit == 0 && $line->credit == 0) {
1793
				//unset($array[$line]);
1794
			} else {
1795
				$date = dol_print_date($line->doc_date, '%d%m%Y');
1796
1797
				print $line->id . $this->separator;
1798
				print $date . $this->separator;
1799
				print substr($line->code_journal, 0, 4) . $this->separator;
1800
				if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {	// TODO No hard code value
1801
					print length_accountg($line->subledger_account) . $this->separator;
1802
				} else {
1803
					print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator;
1804
				}
1805
				print $this->separator;
1806
				//print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator;
1807
				print '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"' . $this->separator;
1808
				print '"' . dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . '"' . $this->separator;
1809
				print price2num(abs($line->debit - $line->credit)) . $this->separator;
1810
				print $line->sens . $this->separator;
1811
				print $date . $this->separator;
1812
				print $this->separator;
1813
				print $this->separator;
1814
				print 'EUR';
1815
				print $this->end_line;
1816
			}
1817
		}
1818
	}
1819
1820
	/**
1821
	* Export format : iSuite Expert
1822
	*
1823
	* by OpenSolus [https://opensolus.fr]
1824
	*
1825
	* @param array $objectLines data
1826
	*
1827
	* @return void
1828
	*/
1829
	public function exportiSuiteExpert($objectLines)
1830
	{
1831
		$this->separator = ';';
1832
		$this->end_line = "\r\n";
1833
1834
1835
		foreach ($objectLines as $line) {
1836
			$tab = array();
1837
1838
			$date = dol_print_date($line->doc_date, '%d/%m/%Y');
1839
1840
			$tab[] = $line->piece_num;
1841
			$tab[] = $date;
1842
			$tab[] = substr($date, 6, 4);
1843
			$tab[] = substr($date, 3, 2);
1844
			$tab[] = substr($date, 0, 2);
1845
			$tab[] = $line->doc_ref;
1846
			//Conversion de chaine UTF8 en Latin9
1847
			$tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
1848
1849
			//Calcul de la longueur des numéros de comptes
1850
			$taille_numero = strlen(length_accountg($line->numero_compte));
1851
1852
			//Création du numéro de client générique
1853
			$numero_cpt_client = '411';
1854
			for ($i = 1; $i <= ($taille_numero - 3); $i++) {
1855
				$numero_cpt_client .= '0';
1856
			}
1857
1858
			//Création des comptes auxiliaire des clients
1859
			if (length_accountg($line->numero_compte) == $numero_cpt_client) {
1860
				$tab[] = rtrim(length_accounta($line->subledger_account), "0");
1861
			} else {
1862
				$tab[] = length_accountg($line->numero_compte);
1863
			}
1864
			$nom_client = explode(" - ", $line->label_operation);
1865
			$tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
1866
			$tab[] = price($line->debit);
1867
			$tab[] = price($line->credit);
1868
			$tab[] = price($line->montant);
1869
			$tab[] = $line->code_journal;
1870
1871
			$separator = $this->separator;
1872
			print implode($separator, $tab) . $this->end_line;
1873
		}
1874
	}
1875
1876
	/**
1877
	 * trunc
1878
	 *
1879
	 * @param string	$str 	String
1880
	 * @param integer 	$size 	Data to trunc
1881
	 * @return string
1882
	 */
1883
	public static function trunc($str, $size)
1884
	{
1885
		return dol_trunc($str, $size, 'right', 'UTF-8', 1);
1886
	}
1887
1888
	/**
1889
	 * toAnsi
1890
	 *
1891
	 * @param string	$str 		Original string to encode and optionaly truncate
1892
	 * @param integer 	$size 		Truncate string after $size characters
1893
	 * @return string 				String encoded in Windows-1251 charset
1894
	 */
1895
	public static function toAnsi($str, $size = -1)
1896
	{
1897
		$retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
1898
		if ($retVal >= 0 && $size >= 0) {
1899
			$retVal = mb_substr($retVal, 0, $size, 'Windows-1251');
1900
		}
1901
		return $retVal;
1902
	}
1903
}
1904