53 public static $EXPORT_TYPE_CONFIGURABLE = 1;
55 public static $EXPORT_TYPE_AGIRIS = 10;
57 public static $EXPORT_TYPE_EBP = 15;
59 public static $EXPORT_TYPE_CEGID = 20;
61 public static $EXPORT_TYPE_COGILOG = 25;
63 public static $EXPORT_TYPE_COALA = 30;
65 public static $EXPORT_TYPE_BOB50 = 35;
67 public static $EXPORT_TYPE_CIEL = 40;
69 public static $EXPORT_TYPE_SAGE50_SWISS = 45;
71 public static $EXPORT_TYPE_CHARLEMAGNE = 50;
73 public static $EXPORT_TYPE_QUADRATUS = 60;
75 public static $EXPORT_TYPE_WINFIC = 70;
77 public static $EXPORT_TYPE_OPENCONCERTO = 100;
79 public static $EXPORT_TYPE_LDCOMPTA = 110;
81 public static $EXPORT_TYPE_LDCOMPTA10 = 120;
83 public static $EXPORT_TYPE_GESTIMUMV3 = 130;
85 public static $EXPORT_TYPE_GESTIMUMV5 = 135;
87 public static $EXPORT_TYPE_ISUITEEXPERT = 200;
90 public static $EXPORT_TYPE_FEC = 1000;
92 public static $EXPORT_TYPE_FEC2 = 1010;
102 public $errors = array();
107 public $separator =
'';
112 public $end_line =
'';
117 public $generatedfiledata = array();
127 global
$conf, $hookmanager;
133 $hookmanager->initHooks(array(
'accountancyexport'));
144 global $langs, $hookmanager;
146 $listofspecialformatexport = array(
147 self::$EXPORT_TYPE_CEGID => $langs->trans(
'Modelcsv_CEGID'),
148 self::$EXPORT_TYPE_COALA => $langs->trans(
'Modelcsv_COALA'),
149 self::$EXPORT_TYPE_BOB50 => $langs->trans(
'Modelcsv_bob50'),
150 self::$EXPORT_TYPE_CIEL => $langs->trans(
'Modelcsv_ciel'),
151 self::$EXPORT_TYPE_QUADRATUS => $langs->trans(
'Modelcsv_quadratus'),
152 self::$EXPORT_TYPE_WINFIC => $langs->trans(
'Modelcsv_winfic'),
153 self::$EXPORT_TYPE_EBP => $langs->trans(
'Modelcsv_ebp'),
154 self::$EXPORT_TYPE_COGILOG => $langs->trans(
'Modelcsv_cogilog'),
155 self::$EXPORT_TYPE_AGIRIS => $langs->trans(
'Modelcsv_agiris'),
156 self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans(
'Modelcsv_openconcerto'),
157 self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans(
'Modelcsv_Sage50_Swiss'),
158 self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans(
'Modelcsv_charlemagne'),
159 self::$EXPORT_TYPE_LDCOMPTA => $langs->trans(
'Modelcsv_LDCompta'),
160 self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans(
'Modelcsv_LDCompta10'),
161 self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans(
'Modelcsv_Gestinumv3'),
162 self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans(
'Modelcsv_Gestinumv5'),
163 self::$EXPORT_TYPE_ISUITEEXPERT =>
'Export iSuite Expert',
166 $listofgenericformatexport = array(
167 self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans(
'Modelcsv_configurable'),
168 self::$EXPORT_TYPE_FEC => $langs->trans(
'Modelcsv_FEC'),
169 self::$EXPORT_TYPE_FEC2 => $langs->trans(
'Modelcsv_FEC2'),
173 $listofexporttypes = $listofgenericformatexport + $listofspecialformatexport;
174 ksort($listofexporttypes, SORT_NUMERIC);
176 ksort($listofspecialformatexport, SORT_NUMERIC);
177 $listofexporttypes = array();
179 foreach ($listofgenericformatexport as $key => $val) {
181 $listofexporttypes[$key] = array(
'id' => $key,
'label' => $val,
'position' => $i);
183 $listofexporttypes[
'separator_'.$i] = array(
'id' => 0,
'label' =>
'----------------',
'position' => $i,
'disabled' =>
'disabled');
184 foreach ($listofspecialformatexport as $key => $val) {
186 $listofexporttypes[$key] = array(
'id' => $key,
'label' => $val,
'position' => $i);
191 $parameters = array();
192 $reshook = $hookmanager->executeHooks(
'getType', $parameters, $listofexporttypes);
194 return $listofexporttypes;
206 self::$EXPORT_TYPE_CONFIGURABLE =>
'csv',
207 self::$EXPORT_TYPE_CEGID =>
'cegid',
208 self::$EXPORT_TYPE_COALA =>
'coala',
209 self::$EXPORT_TYPE_BOB50 =>
'bob50',
210 self::$EXPORT_TYPE_CIEL =>
'ciel',
211 self::$EXPORT_TYPE_QUADRATUS =>
'quadratus',
212 self::$EXPORT_TYPE_WINFIC =>
'winfic',
213 self::$EXPORT_TYPE_EBP =>
'ebp',
214 self::$EXPORT_TYPE_COGILOG =>
'cogilog',
215 self::$EXPORT_TYPE_AGIRIS =>
'agiris',
216 self::$EXPORT_TYPE_OPENCONCERTO =>
'openconcerto',
217 self::$EXPORT_TYPE_SAGE50_SWISS =>
'sage50ch',
218 self::$EXPORT_TYPE_CHARLEMAGNE =>
'charlemagne',
219 self::$EXPORT_TYPE_LDCOMPTA =>
'ldcompta',
220 self::$EXPORT_TYPE_LDCOMPTA10 =>
'ldcompta10',
221 self::$EXPORT_TYPE_GESTIMUMV3 =>
'gestimumv3',
222 self::$EXPORT_TYPE_GESTIMUMV5 =>
'gestimumv5',
223 self::$EXPORT_TYPE_FEC =>
'fec',
224 self::$EXPORT_TYPE_FEC2 =>
'fec2',
225 self::$EXPORT_TYPE_ISUITEEXPERT =>
'isuiteexpert',
229 $code = $formatcode[$type] ??
'';
230 $parameters = array(
'type' => $type);
231 $reshook = $hookmanager->executeHooks(
'getFormatCode', $parameters, $code);
245 $exporttypes = array(
247 self::$EXPORT_TYPE_CONFIGURABLE => array(
248 'label' => $langs->trans(
'Modelcsv_configurable'),
250 'ACCOUNTING_EXPORT_SEPARATORCSV' =>
getDolGlobalString(
'ACCOUNTING_EXPORT_SEPARATORCSV',
','),
254 self::$EXPORT_TYPE_CEGID => array(
255 'label' => $langs->trans(
'Modelcsv_CEGID'),
257 self::$EXPORT_TYPE_COALA => array(
258 'label' => $langs->trans(
'Modelcsv_COALA'),
260 self::$EXPORT_TYPE_BOB50 => array(
261 'label' => $langs->trans(
'Modelcsv_bob50'),
263 self::$EXPORT_TYPE_CIEL => array(
264 'label' => $langs->trans(
'Modelcsv_ciel'),
265 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
267 self::$EXPORT_TYPE_QUADRATUS => array(
268 'label' => $langs->trans(
'Modelcsv_quadratus'),
269 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
271 self::$EXPORT_TYPE_WINFIC => array(
272 'label' => $langs->trans(
'Modelcsv_winfic'),
273 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
275 self::$EXPORT_TYPE_EBP => array(
276 'label' => $langs->trans(
'Modelcsv_ebp'),
278 self::$EXPORT_TYPE_COGILOG => array(
279 'label' => $langs->trans(
'Modelcsv_cogilog'),
281 self::$EXPORT_TYPE_AGIRIS => array(
282 'label' => $langs->trans(
'Modelcsv_agiris'),
284 self::$EXPORT_TYPE_OPENCONCERTO => array(
285 'label' => $langs->trans(
'Modelcsv_openconcerto'),
287 self::$EXPORT_TYPE_SAGE50_SWISS => array(
288 'label' => $langs->trans(
'Modelcsv_Sage50_Swiss'),
290 self::$EXPORT_TYPE_CHARLEMAGNE => array(
291 'label' => $langs->trans(
'Modelcsv_charlemagne'),
292 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
294 self::$EXPORT_TYPE_LDCOMPTA => array(
295 'label' => $langs->trans(
'Modelcsv_LDCompta'),
297 self::$EXPORT_TYPE_LDCOMPTA10 => array(
298 'label' => $langs->trans(
'Modelcsv_LDCompta10'),
300 self::$EXPORT_TYPE_GESTIMUMV3 => array(
301 'label' => $langs->trans(
'Modelcsv_Gestinumv3'),
302 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
304 self::$EXPORT_TYPE_GESTIMUMV5 => array(
305 'label' => $langs->trans(
'Modelcsv_Gestinumv5'),
306 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
308 self::$EXPORT_TYPE_FEC => array(
309 'label' => $langs->trans(
'Modelcsv_FEC'),
310 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
312 self::$EXPORT_TYPE_FEC2 => array(
313 'label' => $langs->trans(
'Modelcsv_FEC2'),
314 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
316 self::$EXPORT_TYPE_ISUITEEXPERT => array(
317 'label' =>
'iSuite Expert',
318 'ACCOUNTING_EXPORT_FORMAT' =>
'csv',
322 '1' => $langs->trans(
"Unix"),
323 '2' => $langs->trans(
"Windows")
326 'csv' => $langs->trans(
"csv"),
327 'txt' => $langs->trans(
"txt")
332 $parameters = array();
333 $reshook = $hookmanager->executeHooks(
'getTypeConfig', $parameters, $exporttypes);
346 switch ($formatexportset) {
347 case self::$EXPORT_TYPE_FEC:
348 $mime =
'text/tab-separated-values';
375 public function export(&$TData, $formatexportset, $withAttachment = 0, $downloadMode = 1, $outputMode = 1, $noouput = 1)
377 global $db,
$conf, $langs;
378 global $search_date_end;
382 $filename =
'general_ledger-'.(!empty($formatcode) ? $formatcode : $formatexportset);
383 $type_export =
'general_ledger';
385 $completefilename =
'';
387 $exportFileName =
'';
388 $exportFilePath =
'';
389 $exportFileFullName =
'';
390 $downloadFileMimeType =
'';
391 $downloadFileFullName =
'';
392 $downloadFilePath =
'';
393 $archiveFullName =
'';
395 $archiveFileList = array();
396 if ($withAttachment == 1) {
397 if ($downloadMode == 0) {
400 if ($outputMode == 0) {
405 if (!extension_loaded(
'zip')) {
406 $langs->load(
'install');
407 $this->errors[] = $langs->trans(
'ErrorPHPDoesNotSupport',
'ZIP');
413 if ($downloadMode == 0) {
418 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
420 if ($outputMode == 1 || $outputMode == 2) {
421 if ($outputMode == 1) {
423 if (!empty(
$conf->accounting->multidir_temp[
$conf->entity])) {
424 $outputDir =
$conf->accounting->multidir_temp[
$conf->entity];
426 $outputDir =
$conf->accounting->dir_temp;
430 if (!empty(
$conf->accounting->multidir_output[
$conf->entity])) {
431 $outputDir =
$conf->accounting->multidir_output[
$conf->entity];
433 $outputDir =
$conf->accounting->dir_output;
437 $outputDir .=
'/export';
438 $outputDir .=
'/'.dol_sanitizePathName((
string) $formatexportset);
443 $this->errors[] = $langs->trans(
'ErrorCanNotCreateDir', $outputDir);
448 if ($outputDir !=
'') {
450 $langs->load(
'errors');
451 $this->errors[] = $langs->trans(
'ErrorDirNotFound', $outputDir);
456 if (empty($completefilename)) {
461 $exportFileFullName = $completefilename;
462 $exportFileBaseName = basename($exportFileFullName);
463 $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME);
464 $exportFilePath = $outputDir .
'/' . $exportFileFullName;
465 $exportFile = fopen($exportFilePath,
'w');
467 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $exportFilePath);
471 if ($withAttachment == 1) {
472 $archiveFileList[0] = array(
473 'path' => $exportFilePath,
474 'name' => $exportFileFullName,
478 $archiveFullName = $exportFileName .
'.zip';
479 $archivePath = $outputDir .
'/' . $archiveFullName;
485 switch ($formatexportset) {
486 case self::$EXPORT_TYPE_CONFIGURABLE:
489 case self::$EXPORT_TYPE_CEGID:
492 case self::$EXPORT_TYPE_COALA:
495 case self::$EXPORT_TYPE_BOB50:
498 case self::$EXPORT_TYPE_CIEL:
501 case self::$EXPORT_TYPE_QUADRATUS:
502 $archiveFileList = $this->
exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment);
504 case self::$EXPORT_TYPE_WINFIC:
507 case self::$EXPORT_TYPE_EBP:
510 case self::$EXPORT_TYPE_COGILOG:
513 case self::$EXPORT_TYPE_AGIRIS:
516 case self::$EXPORT_TYPE_OPENCONCERTO:
519 case self::$EXPORT_TYPE_SAGE50_SWISS:
522 case self::$EXPORT_TYPE_CHARLEMAGNE:
525 case self::$EXPORT_TYPE_LDCOMPTA:
528 case self::$EXPORT_TYPE_LDCOMPTA10:
531 case self::$EXPORT_TYPE_GESTIMUMV3:
534 case self::$EXPORT_TYPE_GESTIMUMV5:
537 case self::$EXPORT_TYPE_FEC:
538 $archiveFileList = $this->exportFEC($TData, $exportFile, $archiveFileList, $withAttachment);
540 case self::$EXPORT_TYPE_FEC2:
541 $archiveFileList = $this->exportFEC2($TData, $exportFile, $archiveFileList, $withAttachment);
543 case self::$EXPORT_TYPE_ISUITEEXPERT:
549 'format' => $formatexportset,
550 'file' => $exportFile,
551 'filepath' => $exportFilePath,
552 'filefullname' => $exportFileFullName,
555 $reshook = $hookmanager->executeHooks(
'export', $parameters, $TData);
557 $this->errors[] = $langs->trans(
'accountancy_error_modelnotfound');
558 } elseif (!empty($hookmanager->resArray[
'downloadFileFullName']) && !empty($hookmanager->resArray[
'downloadFilePath'])) {
559 $exportFileFullName = $hookmanager->resArray[
'downloadFileFullName'];
560 $exportFilePath = $hookmanager->resArray[
'downloadFilePath'];
567 if ($outputMode == 1 || $outputMode == 2) {
575 if ($withAttachment == 1) {
577 if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
579 $downloadFileMimeType =
'application/zip';
580 $downloadFileFullName = $archiveFullName;
581 $downloadFilePath = $archivePath;
584 $archive =
new ZipArchive();
585 $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
588 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $archivePath);
592 foreach ($archiveFileList as $archiveFileArr) {
593 $res = $archive->addFile($archiveFileArr[
'path'], $archiveFileArr[
'name']);
596 $this->errors[] = $langs->trans(
'ErrorArchiveAddFile', $archiveFileArr[
'name']);
610 if ($downloadMode == 1) {
611 if ($withAttachment == 0) {
613 if (!empty($exportFileFullName) && !empty($exportFilePath)) {
614 $downloadFileMimeType = $mimetype;
615 $downloadFileFullName = $exportFileFullName;
616 $downloadFilePath = $exportFilePath;
621 if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath) && empty($noouput)) {
624 header(
'Content-Type: ' . $downloadFileMimeType);
625 header(
'Content-Disposition: attachment; filename=' . $downloadFileFullName);
626 header(
'Cache-Control: Public, must-revalidate');
627 header(
'Pragma: public');
628 header(
'Content-Length: ' .
dol_filesize($downloadFilePath));
633 $this->generatedfiledata = array(
'downloadFilePath' => $downloadFilePath,
'downloadFileMimeType' => $downloadFileMimeType,
'downloadFileFullName' => $downloadFileFullName);
658 foreach ($objectLines as $line) {
663 $tab[] = $date_document;
664 $tab[] = $line->code_journal;
667 $tab[] = $line->sens;
668 $tab[] =
price2fec(abs($line->debit - $line->credit));
672 $output = implode($separator, $tab).$end_line;
674 fwrite($exportFile, $output);
694 foreach ($objectLines as $line) {
698 if ($line->doc_type ==
'customer_invoice') {
700 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
701 $invoice =
new Facture($this->db);
702 $invoice->fetch($line->fk_doc);
704 $refInvoice = $invoice->ref;
705 } elseif ($line->doc_type ==
'supplier_invoice') {
707 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture.class.php';
709 $invoice->fetch($line->fk_doc);
711 $refInvoice = $invoice->ref_supplier;
716 $tab[] = $line->code_journal;
717 $tab[] = $date_document;
718 $tab[] = $refInvoice;
719 if (empty($line->subledger_account)) {
725 $tab[] = $line->label_operation;
726 $tab[] = $date_document;
727 if ($line->sens ==
'D') {
728 $tab[] =
price($line->debit);
730 } elseif ($line->sens ==
'C') {
732 $tab[] =
price($line->credit);
734 $tab[] = $line->doc_ref;
735 $tab[] = $line->label_operation;
737 $output = implode($separator, $tab).$end_line;
739 fwrite($exportFile, $output);
759 foreach ($objectLines as $line) {
764 $tab[] = $date_document;
765 $tab[] = $line->code_journal;
767 $tab[] = $line->piece_num;
768 $tab[] = $line->doc_ref;
769 $tab[] =
price($line->debit);
770 $tab[] =
price($line->credit);
774 $output = implode($separator, $tab).$end_line;
776 fwrite($exportFile, $output);
796 foreach ($objectLines as $line) {
801 $tab[] = $line->piece_num;
802 $tab[] = $date_document;
804 if (empty($line->subledger_account)) {
808 if (substr($line->numero_compte, 0, 3) ==
'411') {
811 if (substr($line->numero_compte, 0, 3) ==
'401') {
817 $tab[] =
price($line->debit);
818 $tab[] =
price($line->credit);
819 $tab[] =
dol_trunc($line->label_operation, 32);
821 $output = implode($separator, $tab).$end_line;
823 fwrite($exportFile, $output);
851 foreach ($objectLines as $line) {
853 if (!empty($line->subledger_account)) {
858 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
862 $tab[] = str_pad((
string) $line->piece_num, 5);
863 $tab[] = str_pad(self::trunc($line->code_journal, 2), 2);
864 $tab[] = str_pad($date_document, 8,
' ', STR_PAD_LEFT);
865 $tab[] = str_pad($date_echeance, 8,
' ', STR_PAD_LEFT);
866 $tab[] = str_pad(self::trunc($line->doc_ref, 12), 12);
867 $tab[] = str_pad(self::trunc($code_compta, 11), 11);
868 $tab[] = str_pad(self::trunc(
dol_string_unaccent($line->doc_ref).dol_string_unaccent($line->label_operation), 25), 25);
869 $tab[] = str_pad(
price2fec(abs($line->debit - $line->credit)), 13,
' ', STR_PAD_LEFT);
870 $tab[] = str_pad($line->sens, 1);
871 $tab[] = str_repeat(
' ', 18);
875 $output = implode($tab).$end_line;
877 fwrite($exportFile, $output);
900 public function exportQuadratus($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
907 foreach ($objectLines as $line) {
911 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
912 $line->label_operation = str_replace(array(
"- ",
"…",
"..."),
"", $line->label_operation);
919 $line->subledger_label = str_replace(array(
"- ",
"…",
"..."),
"", $line->subledger_label);
922 $code_compta = $line->numero_compte;
923 if (!empty($line->subledger_account)) {
924 $code_compta = $line->subledger_account;
929 if (!empty($line->subledger_account)) {
930 $tab[
'type_ligne'] =
'C';
931 $tab[
'num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8);
932 $tab[
'lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30);
934 if ($line->doc_type ==
'customer_invoice') {
935 $tab[
'lib_alpha'] = strtoupper(str_pad(
'C'.self::trunc(
dol_string_unaccent($line->subledger_label), 6), 7));
936 $tab[
'filler'] = str_repeat(
' ', 52);
937 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'), 8), 8);
938 } elseif ($line->doc_type ==
'supplier_invoice') {
939 $tab[
'lib_alpha'] = strtoupper(str_pad(
'F'.self::trunc(
dol_string_unaccent($line->subledger_label), 6), 7));
940 $tab[
'filler'] = str_repeat(
' ', 52);
941 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'), 8), 8);
943 $tab[
'filler'] = str_repeat(
' ', 59);
944 $tab[
'coll_compte'] = str_pad(
' ', 8);
947 $tab[
'filler2'] = str_repeat(
' ', 110);
950 if ($line->doc_type ==
'customer_invoice') {
951 $tab[
'type_compte'] =
'C';
952 } elseif ($line->doc_type ==
'supplier_invoice') {
953 $tab[
'type_compte'] =
'F';
955 $tab[
'type_compte'] =
'G';
958 $tab[
'filler3'] = str_repeat(
' ', 235);
960 $tab[
'end_line'] = $end_line;
963 fwrite($exportFile, implode($tab));
970 $tab[
'type_ligne'] =
'M';
971 $tab[
'num_compte'] = str_pad(self::trunc((
string) $code_compta, 8), 8);
972 $tab[
'code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
973 $tab[
'folio'] =
'000';
978 $tab[
'date_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
979 $tab[
'filler'] =
' ';
980 $tab[
'libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.
' '.$line->label_operation, 20), 20);
995 $tab[
'sens'] = $line->sens;
996 $tab[
'signe_montant'] =
'+';
999 $tab[
'montant'] = str_pad((
string) abs(($line->debit - $line->credit) * 100), 12,
'0', STR_PAD_LEFT);
1000 $tab[
'contrepartie'] = str_repeat(
' ', 8);
1003 if (!empty($line->date_lim_reglement)) {
1004 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%y');
1006 $tab[
'date_echeance'] =
'000000';
1011 $tab[
'lettrage'] = str_repeat(
' ', 2);
1012 $tab[
'codestat'] = str_repeat(
' ', 3);
1013 $tab[
'num_piece'] = str_pad(self::trunc((
string) $line->piece_num, 5), 5);
1017 $tab[
'affaire'] = str_repeat(
' ', 10);
1018 $tab[
'quantity1'] = str_repeat(
' ', 10);
1019 $tab[
'num_piece2'] = str_pad(self::trunc((
string) $line->piece_num, 8), 8);
1020 $tab[
'devis'] = str_pad(
$conf->currency, 3);
1021 $tab[
'code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
1022 $tab[
'filler3'] = str_repeat(
' ', 3);
1030 $tab[
'libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
1031 $tab[
'codetva'] = str_repeat(
' ', 2);
1035 $tab[
'num_piece3'] = str_pad(substr(self::trunc($line->doc_ref, 20), -10), 10);
1036 $tab[
'reserved'] = str_repeat(
' ', 10);
1037 $tab[
'currency_amount'] = str_repeat(
' ', 13);
1039 $attachmentFileName =
'';
1040 if ($withAttachment == 1) {
1041 $attachmentFileKey = trim((
string) $line->piece_num);
1043 if (!isset($archiveFileList[$attachmentFileKey])) {
1044 $objectDirPath =
'';
1046 if ($line->doc_type ==
'customer_invoice') {
1047 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1048 } elseif ($line->doc_type ==
'expense_report') {
1049 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1050 } elseif ($line->doc_type ==
'supplier_invoice') {
1051 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1053 $invoice->fetch($line->fk_doc);
1054 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1055 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1057 $arrayofinclusion = array();
1059 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1060 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1061 if (!empty($fileFoundList)) {
1062 $attachmentFileNameTrunc = str_pad(self::trunc((
string) $line->piece_num, 8), 8,
'0', STR_PAD_LEFT);
1063 foreach ($fileFoundList as $fileFound) {
1064 if (strstr($fileFound[
'name'], $objectFileName)) {
1067 if ($line->doc_type ==
'supplier_invoice') {
1068 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1071 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1074 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1075 if (file_exists($fileFoundPath)) {
1076 $archiveFileList[$attachmentFileKey] = array(
1077 'path' => $fileFoundPath,
1078 'name' => $attachmentFileNameTrunc.
'.pdf',
1087 if (isset($archiveFileList[$attachmentFileKey])) {
1088 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1091 if (
dol_strlen((
string) $attachmentFileName) == 12) {
1092 $tab[
'attachment'] = $attachmentFileName;
1094 $tab[
'attachment'] = str_repeat(
' ', 12);
1096 $tab[
'filler4'] = str_repeat(
' ', 38);
1097 $tab[
'end_line'] = $end_line;
1100 fwrite($exportFile, implode($tab));
1102 print implode($tab);
1106 return $archiveFileList;
1128 foreach ($objectLines as $line) {
1129 $code_compta = $line->numero_compte;
1130 if (!empty($line->subledger_account)) {
1131 $code_compta = $line->subledger_account;
1136 $tab[
'code_journal'] = str_pad(
dol_trunc($line->code_journal, 2,
'right',
'UTF-8', 1), 2);
1141 $tab[
'date_operation'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1143 $tab[
'folio'] =
' 1';
1145 $tab[
'num_ecriture'] = str_pad(
dol_trunc((
string) $index, 6,
'right',
'UTF-8', 1), 6,
' ', STR_PAD_LEFT);
1147 $tab[
'jour_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
1149 $tab[
'num_compte'] = str_pad(
dol_trunc((
string) $code_compta, 6,
'right',
'UTF-8', 1), 6,
'0');
1151 if ($line->sens ==
'D') {
1152 $tab[
'montant_debit'] = str_pad(number_format($line->debit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1154 $tab[
'montant_crebit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1156 $tab[
'montant_debit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1158 $tab[
'montant_crebit'] = str_pad(number_format($line->credit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1163 $tab[
'lettrage'] = str_repeat(
dol_trunc((
string) $line->lettering_code, 2,
'left',
'UTF-8', 1), 2);
1165 $tab[
'code_piece'] = str_pad(
dol_trunc((
string) $line->piece_num, 5,
'left',
'UTF-8', 1), 5,
' ', STR_PAD_LEFT);
1167 $tab[
'code_stat'] = str_repeat(
' ', 4);
1169 if (!empty($line->date_lim_reglement)) {
1170 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%Y');
1172 $tab[
'date_echeance'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1175 $tab[
'monnaie'] =
'1';
1177 $tab[
'filler'] =
' ';
1179 $tab[
'ind_compteur'] =
' ';
1181 $tab[
'quantite'] =
'0,000000000';
1183 $tab[
'code_pointage'] = str_repeat(
' ', 2);
1185 $tab[
'end_line'] = $end_line;
1187 $output = implode(
'|', $tab);
1189 fwrite($exportFile, $output);
1211 foreach ($objectLines as $line) {
1217 $tab[] = $date_document;
1218 $tab[] = $line->code_journal;
1219 if (empty($line->subledger_account)) {
1220 $tab[] = $line->numero_compte;
1222 $tab[] = $line->subledger_account;
1225 $tab[] =
'"'.dol_trunc($line->label_operation, 40,
'right',
'UTF-8', 1).
'"';
1226 $tab[] =
'"'.dol_trunc((
string) $line->piece_num, 15,
'right',
'UTF-8', 1).
'"';
1227 $tab[] =
price2num(abs($line->debit - $line->credit));
1228 $tab[] = $line->sens;
1229 $tab[] = $date_document;
1232 $output = implode($separator, $tab).$end_line;
1234 fwrite($exportFile, $output);
1254 foreach ($objectLines as $line) {
1259 $tab[] = $line->piece_num;
1261 $tab[] = $date_document;
1264 if (empty($line->subledger_account)) {
1273 $tab[] =
price($line->debit);
1274 $tab[] =
price($line->credit);
1275 $tab[] =
price(abs($line->debit - $line->credit));
1276 $tab[] = $line->sens;
1277 $tab[] = $line->lettering_code;
1278 $tab[] = $line->code_journal;
1280 $output = implode($separator, $tab).$end_line;
1282 fwrite($exportFile, $output);
1301 foreach ($objectLines as $line) {
1306 $tab[] = $date_document;
1307 $tab[] = $line->code_journal;
1308 if (empty($line->subledger_account)) {
1313 $tab[] = $line->doc_ref;
1314 $tab[] = $line->label_operation;
1315 $tab[] =
price($line->debit);
1316 $tab[] =
price($line->credit);
1318 $output = implode($separator, $tab).$end_line;
1320 fwrite($exportFile, $output);
1338 $separator = $this->separator;
1340 foreach ($objectLines as $line) {
1345 $tab[] = $line->piece_num;
1346 $tab[] = $date_document;
1347 $tab[] = $line->doc_ref;
1348 $tab[] = preg_match(
'/'.$separator.
'/', $line->label_operation) ?
"'".$line->label_operation.
"'" : $line->label_operation;
1353 $tab[] =
price2num($line->debit - $line->credit);
1354 $tab[] = $line->code_journal;
1356 $output = implode($separator, $tab).$this->end_line;
1358 fwrite($exportFile, $output);
1377 public function exportFEC($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1379 global
$conf, $langs;
1385 $tab[] =
"JournalCode";
1386 $tab[] =
"JournalLib";
1387 $tab[] =
"EcritureNum";
1388 $tab[] =
"EcritureDate";
1389 $tab[] =
"CompteNum";
1390 $tab[] =
"CompteLib";
1391 $tab[] =
"CompAuxNum";
1392 $tab[] =
"CompAuxLib";
1393 $tab[] =
"PieceRef";
1394 $tab[] =
"PieceDate";
1395 $tab[] =
"EcritureLib";
1398 $tab[] =
"EcritureLet";
1400 $tab[] =
"ValidDate";
1401 $tab[] =
"Montantdevise";
1403 $tab[] =
"DateLimitReglmt";
1404 $tab[] =
"NumFacture";
1405 $tab[] =
"FichierFacture";
1407 $output = implode($separator, $tab).$end_line;
1409 fwrite($exportFile, $output);
1414 foreach ($objectLines as $line) {
1415 if ($line->debit == 0 && $line->credit == 0) {
1421 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1422 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1423 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1426 if ($line->doc_type ==
'customer_invoice') {
1428 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1429 $invoice =
new Facture($this->db);
1430 $invoice->fetch($line->fk_doc);
1432 $refInvoice = $invoice->ref;
1433 } elseif ($line->doc_type ==
'supplier_invoice') {
1435 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1437 $invoice->fetch($line->fk_doc);
1439 $refInvoice = $invoice->ref_supplier;
1445 $tab[] = $line->code_journal;
1449 $labeljournal = str_replace(array(
"\t",
"\n",
"\r"),
" ", $labeljournal);
1451 $tab[] = $labeljournal;
1454 $tab[] = $line->piece_num;
1457 $tab[] = $date_document;
1463 $line->label_compte = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_compte);
1470 $line->subledger_label = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->subledger_label);
1474 $line->doc_ref = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->doc_ref);
1475 $tab[] = $line->doc_ref;
1482 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1483 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1493 $line->lettering_code = str_replace(array(
"\t",
"\n",
"\r"),
" ", (
string) $line->lettering_code);
1494 $tab[] = $line->lettering_code;
1497 $tab[] = $date_lettering;
1500 $tab[] = $date_validation;
1503 $tab[] = $line->multicurrency_amount;
1506 $tab[] = $line->multicurrency_code;
1509 $tab[] = $date_limit_payment;
1513 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1514 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1518 $attachmentFileName =
'';
1519 if ($withAttachment == 1) {
1520 $attachmentFileKey = trim((
string) $line->piece_num);
1522 if (!isset($archiveFileList[$attachmentFileKey])) {
1523 $objectDirPath =
'';
1525 if ($line->doc_type ==
'customer_invoice') {
1526 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1527 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1529 } elseif ($line->doc_type ==
'expense_report') {
1530 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1531 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1533 } elseif ($line->doc_type ==
'supplier_invoice') {
1534 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1535 '@phan-var-force FactureFournisseur $invoice';
1537 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1538 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1541 $arrayofinclusion = array();
1543 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1544 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1545 if (!empty($fileFoundList)) {
1546 $attachmentFileNameTrunc = $line->doc_ref;
1547 foreach ($fileFoundList as $fileFound) {
1548 if (strstr($fileFound[
'name'], $objectFileName)) {
1551 if ($line->doc_type ==
'supplier_invoice') {
1552 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1555 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1558 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1559 if (file_exists($fileFoundPath)) {
1560 $archiveFileList[$attachmentFileKey] = array(
1561 'path' => $fileFoundPath,
1562 'name' => $attachmentFileNameTrunc.
'.pdf',
1571 if (isset($archiveFileList[$attachmentFileKey])) {
1572 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1576 $tab[] = $attachmentFileName;
1578 $output = implode($separator, $tab).$end_line;
1581 fwrite($exportFile, $output);
1588 return $archiveFileList;
1603 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1605 global
$conf, $langs;
1611 $tab[] =
"JournalCode";
1612 $tab[] =
"JournalLib";
1613 $tab[] =
"EcritureNum";
1614 $tab[] =
"EcritureDate";
1615 $tab[] =
"CompteNum";
1616 $tab[] =
"CompteLib";
1617 $tab[] =
"CompAuxNum";
1618 $tab[] =
"CompAuxLib";
1619 $tab[] =
"PieceRef";
1620 $tab[] =
"PieceDate";
1621 $tab[] =
"EcritureLib";
1624 $tab[] =
"EcritureLet";
1626 $tab[] =
"ValidDate";
1627 $tab[] =
"Montantdevise";
1629 $tab[] =
"DateLimitReglmt";
1630 $tab[] =
"NumFacture";
1631 $tab[] =
"FichierFacture";
1633 $output = implode($separator, $tab).$end_line;
1635 fwrite($exportFile, $output);
1640 foreach ($objectLines as $line) {
1641 if ($line->debit == 0 && $line->credit == 0) {
1646 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1647 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1648 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1651 if ($line->doc_type ==
'customer_invoice') {
1653 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1654 $invoice =
new Facture($this->db);
1655 $invoice->fetch($line->fk_doc);
1657 $refInvoice = $invoice->ref;
1658 } elseif ($line->doc_type ==
'supplier_invoice') {
1660 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1662 $invoice->fetch($line->fk_doc);
1664 $refInvoice = $invoice->ref_supplier;
1670 $tab[] = $line->code_journal;
1674 $labeljournal = str_replace(array(
"\t",
"\n",
"\r"),
" ", $labeljournal);
1676 $tab[] = $labeljournal;
1679 $tab[] = $line->piece_num;
1682 $tab[] = $date_creation;
1688 $line->label_compte = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_compte);
1695 $line->subledger_label = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->subledger_label);
1699 $line->doc_ref = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->doc_ref);
1700 $tab[] = $line->doc_ref;
1703 $tab[] = $date_document;
1707 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1708 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1718 $line->lettering_code = str_replace(array(
"\t",
"\n",
"\r"),
" ", (
string) $line->lettering_code);
1719 $tab[] = $line->lettering_code;
1722 $tab[] = $date_lettering;
1725 $tab[] = $date_validation;
1728 $tab[] = $line->multicurrency_amount;
1731 $tab[] = $line->multicurrency_code;
1734 $tab[] = $date_limit_payment;
1738 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1739 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1743 $attachmentFileName =
'';
1744 if ($withAttachment == 1) {
1745 $attachmentFileKey = trim((
string) $line->piece_num);
1747 if (!isset($archiveFileList[$attachmentFileKey])) {
1748 $objectDirPath =
'';
1750 if ($line->doc_type ==
'customer_invoice') {
1751 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1752 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1754 } elseif ($line->doc_type ==
'expense_report') {
1755 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1756 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1758 } elseif ($line->doc_type ==
'supplier_invoice') {
1759 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1760 '@phan-var-force FactureFournisseur $invoice';
1762 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1763 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1766 $arrayofinclusion = array();
1768 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1769 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1770 if (!empty($fileFoundList)) {
1771 $attachmentFileNameTrunc = $line->doc_ref;
1772 foreach ($fileFoundList as $fileFound) {
1773 if (strstr($fileFound[
'name'], $objectFileName)) {
1776 if ($line->doc_type ==
'supplier_invoice') {
1777 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1780 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1783 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1784 if (file_exists($fileFoundPath)) {
1785 $archiveFileList[$attachmentFileKey] = array(
1786 'path' => $fileFoundPath,
1787 'name' => $attachmentFileNameTrunc.
'.pdf',
1796 if (isset($archiveFileList[$attachmentFileKey])) {
1797 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1801 $tab[] = $attachmentFileName;
1803 $output = implode($separator, $tab).$end_line;
1805 fwrite($exportFile, $output);
1812 return $archiveFileList;
1848 $tab[] =
"FW-Betrag";
1855 $output = implode($separator, $tab).$end_line;
1857 fwrite($exportFile, $output);
1863 $thisPieceAccountNr =
"";
1864 $aSize = count($objectLines);
1865 foreach ($objectLines as $aIndex => $line) {
1866 $sammelBuchung =
false;
1867 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1868 $sammelBuchung =
true;
1869 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1870 $sammelBuchung =
true;
1871 } elseif ($aIndex + 1 < $aSize
1872 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1873 && $aIndex - 1 < $aSize
1874 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1876 $sammelBuchung =
true;
1882 $tab[] = $line->piece_num;
1886 $tab[] = $date_document;
1891 if ($line->sens ==
'D') {
1899 if (empty($line->code_tiers)) {
1900 if ($line->piece_num == $thisPieceNum) {
1909 $tab[] = $this->separator;
1918 if ($sammelBuchung) {
1926 $tab[] = abs($line->debit - $line->credit);
1933 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
1937 if (strlen($line1) == 0) {
1941 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1942 $line1 = $line1.
' / '.$line2;
1946 $tab[] =
'"'.self::toAnsi($line1).
'"';
1948 $tab[] =
'"'.self::toAnsi($line2).
'"';
1952 $tab[] = $this->separator;
1957 $output = implode($separator, $tab).$end_line;
1959 fwrite($exportFile, $output);
1964 if ($line->piece_num !== $thisPieceNum) {
1965 $thisPieceNum = $line->piece_num;
1966 $thisPieceAccountNr = $line->numero_compte;
1984 foreach ($objectLines as $line) {
1987 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1992 $type_enregistrement =
'E';
1993 $tab[] = $type_enregistrement;
1995 $tab[] = substr($line->code_journal, 0, 2);
1999 $tab[] = $line->piece_num;
2001 $tab[] = $date_document;
2003 $tab[] = $line->label_operation;
2005 $tab[] = $date_lim_reglement;
2007 if ($line->doc_type ==
'supplier_invoice') {
2008 if (($line->debit - $line->credit) > 0) {
2009 $nature_piece =
'AF';
2011 $nature_piece =
'FF';
2013 } elseif ($line->doc_type ==
'customer_invoice') {
2014 if (($line->debit - $line->credit) < 0) {
2015 $nature_piece =
'AC';
2017 $nature_piece =
'FC';
2022 $tab[] = $nature_piece;
2033 $racine_subledger_account =
'';
2036 $tab[] = $racine_subledger_account;
2038 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
2040 $tab[] = $line->sens;
2044 $tab[] = $date_creation;
2046 $tab[] = $line->lettering_code;
2048 $tab[] = $line->date_lettering;
2050 if (!empty($line->subledger_account)) {
2056 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2058 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2072 $tab[] = $line->doc_ref;
2100 $output = implode($separator, $tab).$end_line;
2102 fwrite($exportFile, $output);
2121 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2125 $last_codeinvoice =
'';
2127 foreach ($objectLines as $line) {
2129 if ($last_codeinvoice != $line->doc_ref) {
2131 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2132 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2133 $resql = $this->db->query($sql);
2135 if ($resql && $this->db->num_rows($resql) > 0) {
2136 $soc = $this->db->fetch_object($resql);
2138 $address = array(
'',
'',
'');
2139 if (strpos($soc->address,
"\n") !==
false) {
2140 $address = explode(
"\n", $soc->address);
2141 if (is_array($address) && count($address) > 0) {
2142 foreach ($address as $key => $data) {
2143 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2144 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2148 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2149 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2150 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2155 $type_enregistrement =
'C';
2157 $tab[] = $type_enregistrement;
2159 $tab[] = $soc->code_client;
2169 $tab[] = $address[0];
2171 $tab[] = $address[1];
2173 $tab[] = $address[2];
2177 $tab[] = substr($soc->town, 0, 40);
2181 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2183 $tab[] = $soc->phone;
2195 $tab[] = str_replace(
" ",
"", $soc->siret);
2253 $output = implode($separator, $tab).$end_line;
2255 fwrite($exportFile, $output);
2266 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2269 $type_enregistrement =
'E';
2270 $tab[] = $type_enregistrement;
2272 $tab[] = substr($line->code_journal, 0, 2);
2276 $tab[] = $line->piece_num;
2278 $tab[] = $date_document;
2280 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2282 $tab[] = $date_lim_reglement;
2284 if ($line->doc_type ==
'supplier_invoice') {
2285 if (($line->amount) < 0) {
2286 $nature_piece =
'AF';
2288 $nature_piece =
'FF';
2290 } elseif ($line->doc_type ==
'customer_invoice') {
2291 if (($line->amount) < 0) {
2292 $nature_piece =
'AC';
2294 $nature_piece =
'FC';
2299 $tab[] = $nature_piece;
2310 $racine_subledger_account =
'';
2313 $tab[] = $racine_subledger_account;
2315 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2317 $tab[] = $line->sens;
2321 $tab[] = $date_document;
2323 $tab[] = $line->lettering_code;
2325 $tab[] = $line->date_lettering;
2327 if (!empty($line->subledger_account)) {
2333 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2335 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2347 $tab[] = $line->doc_ref;
2381 $output = implode($separator, $tab).$end_line;
2383 fwrite($exportFile, $output);
2388 $last_codeinvoice = $line->doc_ref;
2402 $langs->load(
'compta');
2409 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2410 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2411 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2412 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2413 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2414 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2415 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2417 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2418 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2419 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2420 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2421 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2422 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2424 $output = implode($separator, $tab).$end_line;
2426 fwrite($exportFile, $output);
2431 foreach ($objectLines as $line) {
2436 $tab[] = $date_document;
2440 if (!empty($line->subledger_account)) {
2441 $account = $line->subledger_account;
2443 $account = $line->numero_compte;
2450 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2452 $tab[] =
price(abs($line->debit - $line->credit));
2453 $tab[] = $line->sens;
2461 $output = implode($separator, $tab).$end_line;
2463 fwrite($exportFile, $output);
2484 $invoices_infos = array();
2485 $supplier_invoices_infos = array();
2486 foreach ($objectLines as $line) {
2487 if ($line->debit == 0 && $line->credit == 0) {
2491 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2493 $invoice_ref = $line->doc_ref;
2496 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2497 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2498 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2499 if ($line->doc_type ==
'customer_invoice') {
2501 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2502 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2503 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2504 $resql = $this->db->query($sql);
2506 if ($obj = $this->db->fetch_object($resql)) {
2508 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2509 $invoice_ref = $obj->ref;
2510 $company_name = $obj->nom;
2515 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2516 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2517 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2518 $resql = $this->db->query($sql);
2520 if ($obj = $this->db->fetch_object($resql)) {
2522 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2523 $invoice_ref = $obj->ref;
2524 $company_name = $obj->nom;
2528 } elseif ($line->doc_type ==
'customer_invoice') {
2530 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2531 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2534 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2535 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2542 $tab[] = $date_document;
2543 $tab[] = substr($line->code_journal, 0, 4);
2545 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2554 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2556 $tab[] =
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1);
2560 $tab[] =
price2num(abs($line->debit - $line->credit));
2562 $tab[] = $line->sens;
2566 $tab[] = $date_echeance;
2568 $output = implode($separator, $tab).$end_line;
2570 fwrite($exportFile, $output);
2590 foreach ($objectLines as $line) {
2591 if ($line->debit == 0 && $line->credit == 0) {
2599 $tab[] = $date_document;
2600 $tab[] = substr($line->code_journal, 0, 4);
2601 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2607 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2608 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2609 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2610 $tab[] =
price2num(abs($line->debit - $line->credit));
2611 $tab[] = $line->sens;
2612 $tab[] = $date_document;
2617 $output = implode($separator, $tab).$end_line;
2619 fwrite($exportFile, $output);
2642 foreach ($objectLines as $line) {
2647 $tab[] = $line->piece_num;
2649 $tab[] = substr($date, 6, 4);
2650 $tab[] = substr($date, 3, 2);
2651 $tab[] = substr($date, 0, 2);
2652 $tab[] = $line->doc_ref;
2654 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2660 $numero_cpt_client =
'411';
2661 $numero_cpt_fourn =
'401';
2662 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2663 $numero_cpt_client .=
'0';
2664 $numero_cpt_fourn .=
'0';
2673 $nom_client = explode(
" - ", $line->label_operation);
2674 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2675 $tab[] =
price($line->debit);
2676 $tab[] =
price($line->credit);
2677 $tab[] =
price($line->montant);
2678 $tab[] = $line->code_journal;
2680 $output = implode($separator, $tab).$end_line;
2682 fwrite($exportFile, $output);
2696 public static function trunc($str, $size)
2698 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2708 public static function toAnsi($str, $size = -1)
2711 if ($retVal >= 0 && $size >= 0) {
2712 $retVal =
dol_substr($retVal, 0, $size,
'Windows-1251');