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;
1450 $tab[] = $labeljournal;
1453 $tab[] = $line->piece_num;
1456 $tab[] = $date_document;
1471 $tab[] = $line->doc_ref;
1478 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1479 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1489 $tab[] = $line->lettering_code;
1492 $tab[] = $date_lettering;
1495 $tab[] = $date_validation;
1498 $tab[] = $line->multicurrency_amount;
1501 $tab[] = $line->multicurrency_code;
1504 $tab[] = $date_limit_payment;
1508 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1509 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1513 $attachmentFileName =
'';
1514 if ($withAttachment == 1) {
1515 $attachmentFileKey = trim((
string) $line->piece_num);
1517 if (!isset($archiveFileList[$attachmentFileKey])) {
1518 $objectDirPath =
'';
1520 if ($line->doc_type ==
'customer_invoice') {
1521 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1522 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1524 } elseif ($line->doc_type ==
'expense_report') {
1525 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1526 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1528 } elseif ($line->doc_type ==
'supplier_invoice') {
1529 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1530 '@phan-var-force FactureFournisseur $invoice';
1532 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1533 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1536 $arrayofinclusion = array();
1538 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1539 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1540 if (!empty($fileFoundList)) {
1541 $attachmentFileNameTrunc = $line->doc_ref;
1542 foreach ($fileFoundList as $fileFound) {
1543 if (strstr($fileFound[
'name'], $objectFileName)) {
1546 if ($line->doc_type ==
'supplier_invoice') {
1547 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1550 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1553 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1554 if (file_exists($fileFoundPath)) {
1555 $archiveFileList[$attachmentFileKey] = array(
1556 'path' => $fileFoundPath,
1557 'name' => $attachmentFileNameTrunc.
'.pdf',
1566 if (isset($archiveFileList[$attachmentFileKey])) {
1567 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1571 $tab[] = $attachmentFileName;
1573 $output = implode($separator, $tab).$end_line;
1576 fwrite($exportFile, $output);
1583 return $archiveFileList;
1598 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1600 global
$conf, $langs;
1606 $tab[] =
"JournalCode";
1607 $tab[] =
"JournalLib";
1608 $tab[] =
"EcritureNum";
1609 $tab[] =
"EcritureDate";
1610 $tab[] =
"CompteNum";
1611 $tab[] =
"CompteLib";
1612 $tab[] =
"CompAuxNum";
1613 $tab[] =
"CompAuxLib";
1614 $tab[] =
"PieceRef";
1615 $tab[] =
"PieceDate";
1616 $tab[] =
"EcritureLib";
1619 $tab[] =
"EcritureLet";
1621 $tab[] =
"ValidDate";
1622 $tab[] =
"Montantdevise";
1624 $tab[] =
"DateLimitReglmt";
1625 $tab[] =
"NumFacture";
1626 $tab[] =
"FichierFacture";
1628 $output = implode($separator, $tab).$end_line;
1630 fwrite($exportFile, $output);
1635 foreach ($objectLines as $line) {
1636 if ($line->debit == 0 && $line->credit == 0) {
1641 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1642 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1643 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1646 if ($line->doc_type ==
'customer_invoice') {
1648 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1649 $invoice =
new Facture($this->db);
1650 $invoice->fetch($line->fk_doc);
1652 $refInvoice = $invoice->ref;
1653 } elseif ($line->doc_type ==
'supplier_invoice') {
1655 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1657 $invoice->fetch($line->fk_doc);
1659 $refInvoice = $invoice->ref_supplier;
1665 $tab[] = $line->code_journal;
1670 $tab[] = $labeljournal;
1673 $tab[] = $line->piece_num;
1676 $tab[] = $date_creation;
1691 $tab[] = $line->doc_ref;
1694 $tab[] = $date_document;
1698 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1699 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1709 $tab[] = $line->lettering_code;
1712 $tab[] = $date_lettering;
1715 $tab[] = $date_validation;
1718 $tab[] = $line->multicurrency_amount;
1721 $tab[] = $line->multicurrency_code;
1724 $tab[] = $date_limit_payment;
1728 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1729 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1733 $attachmentFileName =
'';
1734 if ($withAttachment == 1) {
1735 $attachmentFileKey = trim((
string) $line->piece_num);
1737 if (!isset($archiveFileList[$attachmentFileKey])) {
1738 $objectDirPath =
'';
1740 if ($line->doc_type ==
'customer_invoice') {
1741 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1742 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1744 } elseif ($line->doc_type ==
'expense_report') {
1745 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1746 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1748 } elseif ($line->doc_type ==
'supplier_invoice') {
1749 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1750 '@phan-var-force FactureFournisseur $invoice';
1752 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1753 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1756 $arrayofinclusion = array();
1758 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1759 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1760 if (!empty($fileFoundList)) {
1761 $attachmentFileNameTrunc = $line->doc_ref;
1762 foreach ($fileFoundList as $fileFound) {
1763 if (strstr($fileFound[
'name'], $objectFileName)) {
1766 if ($line->doc_type ==
'supplier_invoice') {
1767 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1770 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1773 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1774 if (file_exists($fileFoundPath)) {
1775 $archiveFileList[$attachmentFileKey] = array(
1776 'path' => $fileFoundPath,
1777 'name' => $attachmentFileNameTrunc.
'.pdf',
1786 if (isset($archiveFileList[$attachmentFileKey])) {
1787 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1791 $tab[] = $attachmentFileName;
1793 $output = implode($separator, $tab).$end_line;
1795 fwrite($exportFile, $output);
1802 return $archiveFileList;
1838 $tab[] =
"FW-Betrag";
1845 $output = implode($separator, $tab).$end_line;
1847 fwrite($exportFile, $output);
1853 $thisPieceAccountNr =
"";
1854 $aSize = count($objectLines);
1855 foreach ($objectLines as $aIndex => $line) {
1856 $sammelBuchung =
false;
1857 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1858 $sammelBuchung =
true;
1859 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1860 $sammelBuchung =
true;
1861 } elseif ($aIndex + 1 < $aSize
1862 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1863 && $aIndex - 1 < $aSize
1864 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1866 $sammelBuchung =
true;
1872 $tab[] = $line->piece_num;
1876 $tab[] = $date_document;
1881 if ($line->sens ==
'D') {
1889 if (empty($line->code_tiers)) {
1890 if ($line->piece_num == $thisPieceNum) {
1899 $tab[] = $this->separator;
1908 if ($sammelBuchung) {
1916 $tab[] = abs($line->debit - $line->credit);
1923 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
1927 if (strlen($line1) == 0) {
1931 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1932 $line1 = $line1.
' / '.$line2;
1936 $tab[] =
'"'.self::toAnsi($line1).
'"';
1938 $tab[] =
'"'.self::toAnsi($line2).
'"';
1942 $tab[] = $this->separator;
1947 $output = implode($separator, $tab).$end_line;
1949 fwrite($exportFile, $output);
1954 if ($line->piece_num !== $thisPieceNum) {
1955 $thisPieceNum = $line->piece_num;
1956 $thisPieceAccountNr = $line->numero_compte;
1974 foreach ($objectLines as $line) {
1977 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1982 $type_enregistrement =
'E';
1983 $tab[] = $type_enregistrement;
1985 $tab[] = substr($line->code_journal, 0, 2);
1989 $tab[] = $line->piece_num;
1991 $tab[] = $date_document;
1993 $tab[] = $line->label_operation;
1995 $tab[] = $date_lim_reglement;
1997 if ($line->doc_type ==
'supplier_invoice') {
1998 if (($line->debit - $line->credit) > 0) {
1999 $nature_piece =
'AF';
2001 $nature_piece =
'FF';
2003 } elseif ($line->doc_type ==
'customer_invoice') {
2004 if (($line->debit - $line->credit) < 0) {
2005 $nature_piece =
'AC';
2007 $nature_piece =
'FC';
2012 $tab[] = $nature_piece;
2023 $racine_subledger_account =
'';
2026 $tab[] = $racine_subledger_account;
2028 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
2030 $tab[] = $line->sens;
2034 $tab[] = $date_creation;
2036 $tab[] = $line->lettering_code;
2038 $tab[] = $line->date_lettering;
2040 if (!empty($line->subledger_account)) {
2046 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2048 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2062 $tab[] = $line->doc_ref;
2090 $output = implode($separator, $tab).$end_line;
2092 fwrite($exportFile, $output);
2111 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2115 $last_codeinvoice =
'';
2117 foreach ($objectLines as $line) {
2119 if ($last_codeinvoice != $line->doc_ref) {
2121 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2122 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2123 $resql = $this->db->query($sql);
2125 if ($resql && $this->db->num_rows($resql) > 0) {
2126 $soc = $this->db->fetch_object($resql);
2128 $address = array(
'',
'',
'');
2129 if (strpos($soc->address,
"\n") !==
false) {
2130 $address = explode(
"\n", $soc->address);
2131 if (is_array($address) && count($address) > 0) {
2132 foreach ($address as $key => $data) {
2133 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2134 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2138 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2139 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2140 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2145 $type_enregistrement =
'C';
2147 $tab[] = $type_enregistrement;
2149 $tab[] = $soc->code_client;
2159 $tab[] = $address[0];
2161 $tab[] = $address[1];
2163 $tab[] = $address[2];
2167 $tab[] = substr($soc->town, 0, 40);
2171 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2173 $tab[] = $soc->phone;
2185 $tab[] = str_replace(
" ",
"", $soc->siret);
2243 $output = implode($separator, $tab).$end_line;
2245 fwrite($exportFile, $output);
2256 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2259 $type_enregistrement =
'E';
2260 $tab[] = $type_enregistrement;
2262 $tab[] = substr($line->code_journal, 0, 2);
2266 $tab[] = $line->piece_num;
2268 $tab[] = $date_document;
2270 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2272 $tab[] = $date_lim_reglement;
2274 if ($line->doc_type ==
'supplier_invoice') {
2275 if (($line->amount) < 0) {
2276 $nature_piece =
'AF';
2278 $nature_piece =
'FF';
2280 } elseif ($line->doc_type ==
'customer_invoice') {
2281 if (($line->amount) < 0) {
2282 $nature_piece =
'AC';
2284 $nature_piece =
'FC';
2289 $tab[] = $nature_piece;
2300 $racine_subledger_account =
'';
2303 $tab[] = $racine_subledger_account;
2305 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2307 $tab[] = $line->sens;
2311 $tab[] = $date_document;
2313 $tab[] = $line->lettering_code;
2315 $tab[] = $line->date_lettering;
2317 if (!empty($line->subledger_account)) {
2323 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2325 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2337 $tab[] = $line->doc_ref;
2371 $output = implode($separator, $tab).$end_line;
2373 fwrite($exportFile, $output);
2378 $last_codeinvoice = $line->doc_ref;
2392 $langs->load(
'compta');
2399 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2400 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2401 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2402 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2403 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2404 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2405 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2407 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2408 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2409 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2410 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2411 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2412 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2414 $output = implode($separator, $tab).$end_line;
2416 fwrite($exportFile, $output);
2421 foreach ($objectLines as $line) {
2426 $tab[] = $date_document;
2430 if (!empty($line->subledger_account)) {
2431 $account = $line->subledger_account;
2433 $account = $line->numero_compte;
2440 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2442 $tab[] =
price(abs($line->debit - $line->credit));
2443 $tab[] = $line->sens;
2451 $output = implode($separator, $tab).$end_line;
2453 fwrite($exportFile, $output);
2474 $invoices_infos = array();
2475 $supplier_invoices_infos = array();
2476 foreach ($objectLines as $line) {
2477 if ($line->debit == 0 && $line->credit == 0) {
2481 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2483 $invoice_ref = $line->doc_ref;
2486 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2487 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2488 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2489 if ($line->doc_type ==
'customer_invoice') {
2491 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2492 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2493 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2494 $resql = $this->db->query($sql);
2496 if ($obj = $this->db->fetch_object($resql)) {
2498 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2499 $invoice_ref = $obj->ref;
2500 $company_name = $obj->nom;
2505 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2506 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2507 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2508 $resql = $this->db->query($sql);
2510 if ($obj = $this->db->fetch_object($resql)) {
2512 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2513 $invoice_ref = $obj->ref;
2514 $company_name = $obj->nom;
2518 } elseif ($line->doc_type ==
'customer_invoice') {
2520 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2521 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2524 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2525 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2532 $tab[] = $date_document;
2533 $tab[] = substr($line->code_journal, 0, 4);
2535 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2544 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2546 $tab[] =
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1);
2550 $tab[] =
price2num(abs($line->debit - $line->credit));
2552 $tab[] = $line->sens;
2556 $tab[] = $date_echeance;
2558 $output = implode($separator, $tab).$end_line;
2560 fwrite($exportFile, $output);
2580 foreach ($objectLines as $line) {
2581 if ($line->debit == 0 && $line->credit == 0) {
2589 $tab[] = $date_document;
2590 $tab[] = substr($line->code_journal, 0, 4);
2591 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2597 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2598 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2599 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2600 $tab[] =
price2num(abs($line->debit - $line->credit));
2601 $tab[] = $line->sens;
2602 $tab[] = $date_document;
2607 $output = implode($separator, $tab).$end_line;
2609 fwrite($exportFile, $output);
2632 foreach ($objectLines as $line) {
2637 $tab[] = $line->piece_num;
2639 $tab[] = substr($date, 6, 4);
2640 $tab[] = substr($date, 3, 2);
2641 $tab[] = substr($date, 0, 2);
2642 $tab[] = $line->doc_ref;
2644 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2650 $numero_cpt_client =
'411';
2651 $numero_cpt_fourn =
'401';
2652 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2653 $numero_cpt_client .=
'0';
2654 $numero_cpt_fourn .=
'0';
2663 $nom_client = explode(
" - ", $line->label_operation);
2664 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2665 $tab[] =
price($line->debit);
2666 $tab[] =
price($line->credit);
2667 $tab[] =
price($line->montant);
2668 $tab[] = $line->code_journal;
2670 $output = implode($separator, $tab).$end_line;
2672 fwrite($exportFile, $output);
2686 public static function trunc($str, $size)
2688 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2698 public static function toAnsi($str, $size = -1)
2701 if ($retVal >= 0 && $size >= 0) {
2702 $retVal =
dol_substr($retVal, 0, $size,
'Windows-1251');