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,
554 $reshook = $hookmanager->executeHooks(
'export', $parameters, $TData);
556 $this->errors[] = $langs->trans(
'accountancy_error_modelnotfound');
557 } elseif (!empty($hookmanager->resArray[
'downloadFileFullName']) && !empty($hookmanager->resArray[
'downloadFilePath'])) {
558 $exportFileFullName = $hookmanager->resArray[
'downloadFileFullName'];
559 $exportFilePath = $hookmanager->resArray[
'downloadFilePath'];
566 if ($outputMode == 1 || $outputMode == 2) {
574 if ($withAttachment == 1) {
576 if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
578 $downloadFileMimeType =
'application/zip';
579 $downloadFileFullName = $archiveFullName;
580 $downloadFilePath = $archivePath;
583 $archive =
new ZipArchive();
584 $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
587 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $archivePath);
591 foreach ($archiveFileList as $archiveFileArr) {
592 $res = $archive->addFile($archiveFileArr[
'path'], $archiveFileArr[
'name']);
595 $this->errors[] = $langs->trans(
'ErrorArchiveAddFile', $archiveFileArr[
'name']);
609 if ($downloadMode == 1) {
610 if ($withAttachment == 0) {
612 if (!empty($exportFileFullName) && !empty($exportFilePath)) {
613 $downloadFileMimeType = $mimetype;
614 $downloadFileFullName = $exportFileFullName;
615 $downloadFilePath = $exportFilePath;
620 if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath) && empty($noouput)) {
623 header(
'Content-Type: ' . $downloadFileMimeType);
624 header(
'Content-Disposition: attachment; filename=' . $downloadFileFullName);
625 header(
'Cache-Control: Public, must-revalidate');
626 header(
'Pragma: public');
627 header(
'Content-Length: ' .
dol_filesize($downloadFilePath));
632 $this->generatedfiledata = array(
'downloadFilePath' => $downloadFilePath,
'downloadFileMimeType' => $downloadFileMimeType,
'downloadFileFullName' => $downloadFileFullName);
657 foreach ($objectLines as $line) {
662 $tab[] = $date_document;
663 $tab[] = $line->code_journal;
666 $tab[] = $line->sens;
667 $tab[] =
price2fec(abs($line->debit - $line->credit));
671 $output = implode($separator, $tab).$end_line;
673 fwrite($exportFile, $output);
693 foreach ($objectLines as $line) {
697 if ($line->doc_type ==
'customer_invoice') {
699 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
700 $invoice =
new Facture($this->db);
701 $invoice->fetch($line->fk_doc);
703 $refInvoice = $invoice->ref;
704 } elseif ($line->doc_type ==
'supplier_invoice') {
706 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture.class.php';
708 $invoice->fetch($line->fk_doc);
710 $refInvoice = $invoice->ref_supplier;
715 $tab[] = $line->code_journal;
716 $tab[] = $date_document;
717 $tab[] = $refInvoice;
718 if (empty($line->subledger_account)) {
724 $tab[] = $line->label_operation;
725 $tab[] = $date_document;
726 if ($line->sens ==
'D') {
727 $tab[] =
price($line->debit);
729 } elseif ($line->sens ==
'C') {
731 $tab[] =
price($line->credit);
733 $tab[] = $line->doc_ref;
734 $tab[] = $line->label_operation;
736 $output = implode($separator, $tab).$end_line;
738 fwrite($exportFile, $output);
758 foreach ($objectLines as $line) {
763 $tab[] = $date_document;
764 $tab[] = $line->code_journal;
766 $tab[] = $line->piece_num;
767 $tab[] = $line->doc_ref;
768 $tab[] =
price($line->debit);
769 $tab[] =
price($line->credit);
773 $output = implode($separator, $tab).$end_line;
775 fwrite($exportFile, $output);
795 foreach ($objectLines as $line) {
800 $tab[] = $line->piece_num;
801 $tab[] = $date_document;
803 if (empty($line->subledger_account)) {
807 if (substr($line->numero_compte, 0, 3) ==
'411') {
810 if (substr($line->numero_compte, 0, 3) ==
'401') {
816 $tab[] =
price($line->debit);
817 $tab[] =
price($line->credit);
818 $tab[] =
dol_trunc($line->label_operation, 32);
820 $output = implode($separator, $tab).$end_line;
822 fwrite($exportFile, $output);
850 foreach ($objectLines as $line) {
852 if (!empty($line->subledger_account)) {
857 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
861 $tab[] = str_pad((
string) $line->piece_num, 5);
862 $tab[] = str_pad(self::trunc($line->code_journal, 2), 2);
863 $tab[] = str_pad($date_document, 8,
' ', STR_PAD_LEFT);
864 $tab[] = str_pad($date_echeance, 8,
' ', STR_PAD_LEFT);
865 $tab[] = str_pad(self::trunc($line->doc_ref, 12), 12);
866 $tab[] = str_pad(self::trunc($code_compta, 11), 11);
867 $tab[] = str_pad(self::trunc(
dol_string_unaccent($line->doc_ref).dol_string_unaccent($line->label_operation), 25), 25);
868 $tab[] = str_pad(
price2fec(abs($line->debit - $line->credit)), 13,
' ', STR_PAD_LEFT);
869 $tab[] = str_pad($line->sens, 1);
870 $tab[] = str_repeat(
' ', 18);
874 $output = implode($tab).$end_line;
876 fwrite($exportFile, $output);
899 public function exportQuadratus($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
906 foreach ($objectLines as $line) {
910 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
911 $line->label_operation = str_replace(array(
"- ",
"…",
"..."),
"", $line->label_operation);
918 $line->subledger_label = str_replace(array(
"- ",
"…",
"..."),
"", $line->subledger_label);
921 $code_compta = $line->numero_compte;
922 if (!empty($line->subledger_account)) {
923 $code_compta = $line->subledger_account;
928 if (!empty($line->subledger_account)) {
929 $tab[
'type_ligne'] =
'C';
930 $tab[
'num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8);
931 $tab[
'lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30);
933 if ($line->doc_type ==
'customer_invoice') {
934 $tab[
'lib_alpha'] = strtoupper(str_pad(
'C'.self::trunc(
dol_string_unaccent($line->subledger_label), 6), 7));
935 $tab[
'filler'] = str_repeat(
' ', 52);
936 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'), 8), 8);
937 } elseif ($line->doc_type ==
'supplier_invoice') {
938 $tab[
'lib_alpha'] = strtoupper(str_pad(
'F'.self::trunc(
dol_string_unaccent($line->subledger_label), 6), 7));
939 $tab[
'filler'] = str_repeat(
' ', 52);
940 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'), 8), 8);
942 $tab[
'filler'] = str_repeat(
' ', 59);
943 $tab[
'coll_compte'] = str_pad(
' ', 8);
946 $tab[
'filler2'] = str_repeat(
' ', 110);
949 if ($line->doc_type ==
'customer_invoice') {
950 $tab[
'type_compte'] =
'C';
951 } elseif ($line->doc_type ==
'supplier_invoice') {
952 $tab[
'type_compte'] =
'F';
954 $tab[
'type_compte'] =
'G';
957 $tab[
'filler3'] = str_repeat(
' ', 235);
959 $tab[
'end_line'] = $end_line;
962 fwrite($exportFile, implode($tab));
969 $tab[
'type_ligne'] =
'M';
970 $tab[
'num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
971 $tab[
'code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
972 $tab[
'folio'] =
'000';
977 $tab[
'date_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
978 $tab[
'filler'] =
' ';
979 $tab[
'libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.
' '.$line->label_operation, 20), 20);
994 $tab[
'sens'] = $line->sens;
995 $tab[
'signe_montant'] =
'+';
998 $tab[
'montant'] = str_pad((
string) abs(($line->debit - $line->credit) * 100), 12,
'0', STR_PAD_LEFT);
999 $tab[
'contrepartie'] = str_repeat(
' ', 8);
1002 if (!empty($line->date_lim_reglement)) {
1003 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%y');
1005 $tab[
'date_echeance'] =
'000000';
1010 $tab[
'lettrage'] = str_repeat(
' ', 2);
1011 $tab[
'codestat'] = str_repeat(
' ', 3);
1012 $tab[
'num_piece'] = str_pad(self::trunc((
string) $line->piece_num, 5), 5);
1016 $tab[
'affaire'] = str_repeat(
' ', 10);
1017 $tab[
'quantity1'] = str_repeat(
' ', 10);
1018 $tab[
'num_piece2'] = str_pad(self::trunc((
string) $line->piece_num, 8), 8);
1019 $tab[
'devis'] = str_pad(
$conf->currency, 3);
1020 $tab[
'code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
1021 $tab[
'filler3'] = str_repeat(
' ', 3);
1029 $tab[
'libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
1030 $tab[
'codetva'] = str_repeat(
' ', 2);
1034 $tab[
'num_piece3'] = str_pad(substr(self::trunc($line->doc_ref, 20), -10), 10);
1035 $tab[
'reserved'] = str_repeat(
' ', 10);
1036 $tab[
'currency_amount'] = str_repeat(
' ', 13);
1038 $attachmentFileName =
'';
1039 if ($withAttachment == 1) {
1040 $attachmentFileKey = trim((
string) $line->piece_num);
1042 if (!isset($archiveFileList[$attachmentFileKey])) {
1043 $objectDirPath =
'';
1045 if ($line->doc_type ==
'customer_invoice') {
1046 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1047 } elseif ($line->doc_type ==
'expense_report') {
1048 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1049 } elseif ($line->doc_type ==
'supplier_invoice') {
1050 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1052 $invoice->fetch($line->fk_doc);
1053 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1054 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1056 $arrayofinclusion = array();
1058 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1059 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1060 if (!empty($fileFoundList)) {
1061 $attachmentFileNameTrunc = str_pad(self::trunc((
string) $line->piece_num, 8), 8,
'0', STR_PAD_LEFT);
1062 foreach ($fileFoundList as $fileFound) {
1063 if (strstr($fileFound[
'name'], $objectFileName)) {
1066 if ($line->doc_type ==
'supplier_invoice') {
1067 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1070 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1073 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1074 if (file_exists($fileFoundPath)) {
1075 $archiveFileList[$attachmentFileKey] = array(
1076 'path' => $fileFoundPath,
1077 'name' => $attachmentFileNameTrunc.
'.pdf',
1086 if (isset($archiveFileList[$attachmentFileKey])) {
1087 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1091 $tab[
'attachment'] = $attachmentFileName;
1093 $tab[
'attachment'] = str_repeat(
' ', 12);
1095 $tab[
'filler4'] = str_repeat(
' ', 38);
1096 $tab[
'end_line'] = $end_line;
1099 fwrite($exportFile, implode($tab));
1101 print implode($tab);
1105 return $archiveFileList;
1127 foreach ($objectLines as $line) {
1128 $code_compta = $line->numero_compte;
1129 if (!empty($line->subledger_account)) {
1130 $code_compta = $line->subledger_account;
1135 $tab[
'code_journal'] = str_pad(
dol_trunc($line->code_journal, 2,
'right',
'UTF-8', 1), 2);
1140 $tab[
'date_operation'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1142 $tab[
'folio'] =
' 1';
1144 $tab[
'num_ecriture'] = str_pad(
dol_trunc((
string) $index, 6,
'right',
'UTF-8', 1), 6,
' ', STR_PAD_LEFT);
1146 $tab[
'jour_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
1148 $tab[
'num_compte'] = str_pad(
dol_trunc($code_compta, 6,
'right',
'UTF-8', 1), 6,
'0');
1150 if ($line->sens ==
'D') {
1151 $tab[
'montant_debit'] = str_pad(number_format($line->debit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1153 $tab[
'montant_crebit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1155 $tab[
'montant_debit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1157 $tab[
'montant_crebit'] = str_pad(number_format($line->credit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1162 $tab[
'lettrage'] = str_repeat(
dol_trunc($line->lettering_code, 2,
'left',
'UTF-8', 1), 2);
1164 $tab[
'code_piece'] = str_pad(
dol_trunc((
string) $line->piece_num, 5,
'left',
'UTF-8', 1), 5,
' ', STR_PAD_LEFT);
1166 $tab[
'code_stat'] = str_repeat(
' ', 4);
1168 if (!empty($line->date_lim_reglement)) {
1169 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%Y');
1171 $tab[
'date_echeance'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1174 $tab[
'monnaie'] =
'1';
1176 $tab[
'filler'] =
' ';
1178 $tab[
'ind_compteur'] =
' ';
1180 $tab[
'quantite'] =
'0,000000000';
1182 $tab[
'code_pointage'] = str_repeat(
' ', 2);
1184 $tab[
'end_line'] = $end_line;
1186 print implode(
'|', $tab);
1205 foreach ($objectLines as $line) {
1211 $tab[] = $date_document;
1212 $tab[] = $line->code_journal;
1213 if (empty($line->subledger_account)) {
1214 $tab[] = $line->numero_compte;
1216 $tab[] = $line->subledger_account;
1219 $tab[] =
'"'.dol_trunc($line->label_operation, 40,
'right',
'UTF-8', 1).
'"';
1220 $tab[] =
'"'.dol_trunc((
string) $line->piece_num, 15,
'right',
'UTF-8', 1).
'"';
1221 $tab[] =
price2num(abs($line->debit - $line->credit));
1222 $tab[] = $line->sens;
1223 $tab[] = $date_document;
1226 $output = implode($separator, $tab).$end_line;
1228 fwrite($exportFile, $output);
1248 foreach ($objectLines as $line) {
1253 $tab[] = $line->piece_num;
1255 $tab[] = $date_document;
1258 if (empty($line->subledger_account)) {
1267 $tab[] =
price($line->debit);
1268 $tab[] =
price($line->credit);
1269 $tab[] =
price(abs($line->debit - $line->credit));
1270 $tab[] = $line->sens;
1271 $tab[] = $line->lettering_code;
1272 $tab[] = $line->code_journal;
1274 $output = implode($separator, $tab).$end_line;
1276 fwrite($exportFile, $output);
1295 foreach ($objectLines as $line) {
1300 $tab[] = $date_document;
1301 $tab[] = $line->code_journal;
1302 if (empty($line->subledger_account)) {
1307 $tab[] = $line->doc_ref;
1308 $tab[] = $line->label_operation;
1309 $tab[] =
price($line->debit);
1310 $tab[] =
price($line->credit);
1312 $output = implode($separator, $tab).$end_line;
1314 fwrite($exportFile, $output);
1332 $separator = $this->separator;
1334 foreach ($objectLines as $line) {
1339 $tab[] = $line->piece_num;
1340 $tab[] = $date_document;
1341 $tab[] = $line->doc_ref;
1342 $tab[] = preg_match(
'/'.$separator.
'/', $line->label_operation) ?
"'".$line->label_operation.
"'" : $line->label_operation;
1347 $tab[] =
price2num($line->debit - $line->credit);
1348 $tab[] = $line->code_journal;
1350 $output = implode($separator, $tab).$this->end_line;
1352 fwrite($exportFile, $output);
1371 public function exportFEC($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1373 global
$conf, $langs;
1379 $tab[] =
"JournalCode";
1380 $tab[] =
"JournalLib";
1381 $tab[] =
"EcritureNum";
1382 $tab[] =
"EcritureDate";
1383 $tab[] =
"CompteNum";
1384 $tab[] =
"CompteLib";
1385 $tab[] =
"CompAuxNum";
1386 $tab[] =
"CompAuxLib";
1387 $tab[] =
"PieceRef";
1388 $tab[] =
"PieceDate";
1389 $tab[] =
"EcritureLib";
1392 $tab[] =
"EcritureLet";
1394 $tab[] =
"ValidDate";
1395 $tab[] =
"Montantdevise";
1397 $tab[] =
"DateLimitReglmt";
1398 $tab[] =
"NumFacture";
1399 $tab[] =
"FichierFacture";
1401 $output = implode($separator, $tab).$end_line;
1403 fwrite($exportFile, $output);
1408 foreach ($objectLines as $line) {
1409 if ($line->debit == 0 && $line->credit == 0) {
1415 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1416 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1417 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1420 if ($line->doc_type ==
'customer_invoice') {
1422 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1423 $invoice =
new Facture($this->db);
1424 $invoice->fetch($line->fk_doc);
1426 $refInvoice = $invoice->ref;
1427 } elseif ($line->doc_type ==
'supplier_invoice') {
1429 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1431 $invoice->fetch($line->fk_doc);
1433 $refInvoice = $invoice->ref_supplier;
1439 $tab[] = $line->code_journal;
1444 $tab[] = $labeljournal;
1447 $tab[] = $line->piece_num;
1450 $tab[] = $date_document;
1465 $tab[] = $line->doc_ref;
1472 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1473 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1483 $tab[] = $line->lettering_code;
1486 $tab[] = $date_lettering;
1489 $tab[] = $date_validation;
1492 $tab[] = $line->multicurrency_amount;
1495 $tab[] = $line->multicurrency_code;
1498 $tab[] = $date_limit_payment;
1502 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1503 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1507 $attachmentFileName =
'';
1508 if ($withAttachment == 1) {
1509 $attachmentFileKey = trim((
string) $line->piece_num);
1511 if (!isset($archiveFileList[$attachmentFileKey])) {
1512 $objectDirPath =
'';
1514 if ($line->doc_type ==
'customer_invoice') {
1515 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1516 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1518 } elseif ($line->doc_type ==
'expense_report') {
1519 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1520 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1522 } elseif ($line->doc_type ==
'supplier_invoice') {
1523 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1524 '@phan-var-force FactureFournisseur $invoice';
1526 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1527 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1530 $arrayofinclusion = array();
1532 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1533 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1534 if (!empty($fileFoundList)) {
1535 $attachmentFileNameTrunc = $line->doc_ref;
1536 foreach ($fileFoundList as $fileFound) {
1537 if (strstr($fileFound[
'name'], $objectFileName)) {
1540 if ($line->doc_type ==
'supplier_invoice') {
1541 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1544 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1547 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1548 if (file_exists($fileFoundPath)) {
1549 $archiveFileList[$attachmentFileKey] = array(
1550 'path' => $fileFoundPath,
1551 'name' => $attachmentFileNameTrunc.
'.pdf',
1560 if (isset($archiveFileList[$attachmentFileKey])) {
1561 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1565 $tab[] = $attachmentFileName;
1567 $output = implode($separator, $tab).$end_line;
1570 fwrite($exportFile, $output);
1577 return $archiveFileList;
1592 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1594 global
$conf, $langs;
1600 $tab[] =
"JournalCode";
1601 $tab[] =
"JournalLib";
1602 $tab[] =
"EcritureNum";
1603 $tab[] =
"EcritureDate";
1604 $tab[] =
"CompteNum";
1605 $tab[] =
"CompteLib";
1606 $tab[] =
"CompAuxNum";
1607 $tab[] =
"CompAuxLib";
1608 $tab[] =
"PieceRef";
1609 $tab[] =
"PieceDate";
1610 $tab[] =
"EcritureLib";
1613 $tab[] =
"EcritureLet";
1615 $tab[] =
"ValidDate";
1616 $tab[] =
"Montantdevise";
1618 $tab[] =
"DateLimitReglmt";
1619 $tab[] =
"NumFacture";
1620 $tab[] =
"FichierFacture";
1622 $output = implode($separator, $tab).$end_line;
1624 fwrite($exportFile, $output);
1629 foreach ($objectLines as $line) {
1630 if ($line->debit == 0 && $line->credit == 0) {
1635 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1636 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1637 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1640 if ($line->doc_type ==
'customer_invoice') {
1642 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1643 $invoice =
new Facture($this->db);
1644 $invoice->fetch($line->fk_doc);
1646 $refInvoice = $invoice->ref;
1647 } elseif ($line->doc_type ==
'supplier_invoice') {
1649 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1651 $invoice->fetch($line->fk_doc);
1653 $refInvoice = $invoice->ref_supplier;
1659 $tab[] = $line->code_journal;
1664 $tab[] = $labeljournal;
1667 $tab[] = $line->piece_num;
1670 $tab[] = $date_creation;
1685 $tab[] = $line->doc_ref;
1688 $tab[] = $date_document;
1692 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1693 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1703 $tab[] = $line->lettering_code;
1706 $tab[] = $date_lettering;
1709 $tab[] = $date_validation;
1712 $tab[] = $line->multicurrency_amount;
1715 $tab[] = $line->multicurrency_code;
1718 $tab[] = $date_limit_payment;
1722 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1723 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1727 $attachmentFileName =
'';
1728 if ($withAttachment == 1) {
1729 $attachmentFileKey = trim((
string) $line->piece_num);
1731 if (!isset($archiveFileList[$attachmentFileKey])) {
1732 $objectDirPath =
'';
1734 if ($line->doc_type ==
'customer_invoice') {
1735 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1736 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1738 } elseif ($line->doc_type ==
'expense_report') {
1739 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1740 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1742 } elseif ($line->doc_type ==
'supplier_invoice') {
1743 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1744 '@phan-var-force FactureFournisseur $invoice';
1746 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1747 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1750 $arrayofinclusion = array();
1752 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1753 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1754 if (!empty($fileFoundList)) {
1755 $attachmentFileNameTrunc = $line->doc_ref;
1756 foreach ($fileFoundList as $fileFound) {
1757 if (strstr($fileFound[
'name'], $objectFileName)) {
1760 if ($line->doc_type ==
'supplier_invoice') {
1761 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1764 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1767 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1768 if (file_exists($fileFoundPath)) {
1769 $archiveFileList[$attachmentFileKey] = array(
1770 'path' => $fileFoundPath,
1771 'name' => $attachmentFileNameTrunc.
'.pdf',
1780 if (isset($archiveFileList[$attachmentFileKey])) {
1781 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1785 $tab[] = $attachmentFileName;
1787 $output = implode($separator, $tab).$end_line;
1789 fwrite($exportFile, $output);
1796 return $archiveFileList;
1832 $tab[] =
"FW-Betrag";
1839 $output = implode($separator, $tab).$end_line;
1841 fwrite($exportFile, $output);
1847 $thisPieceAccountNr =
"";
1848 $aSize = count($objectLines);
1849 foreach ($objectLines as $aIndex => $line) {
1850 $sammelBuchung =
false;
1851 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1852 $sammelBuchung =
true;
1853 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1854 $sammelBuchung =
true;
1855 } elseif ($aIndex + 1 < $aSize
1856 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1857 && $aIndex - 1 < $aSize
1858 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1860 $sammelBuchung =
true;
1866 $tab[] = $line->piece_num;
1870 $tab[] = $date_document;
1875 if ($line->sens ==
'D') {
1883 if (empty($line->code_tiers)) {
1884 if ($line->piece_num == $thisPieceNum) {
1893 $tab[] = $this->separator;
1902 if ($sammelBuchung) {
1910 $tab[] = abs($line->debit - $line->credit);
1917 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
1921 if (strlen($line1) == 0) {
1925 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1926 $line1 = $line1.
' / '.$line2;
1930 $tab[] =
'"'.self::toAnsi($line1).
'"';
1932 $tab[] =
'"'.self::toAnsi($line2).
'"';
1936 $tab[] = $this->separator;
1941 $output = implode($separator, $tab).$end_line;
1943 fwrite($exportFile, $output);
1948 if ($line->piece_num !== $thisPieceNum) {
1949 $thisPieceNum = $line->piece_num;
1950 $thisPieceAccountNr = $line->numero_compte;
1968 foreach ($objectLines as $line) {
1971 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1976 $type_enregistrement =
'E';
1977 $tab[] = $type_enregistrement;
1979 $tab[] = substr($line->code_journal, 0, 2);
1983 $tab[] = $line->piece_num;
1985 $tab[] = $date_document;
1987 $tab[] = $line->label_operation;
1989 $tab[] = $date_lim_reglement;
1991 if ($line->doc_type ==
'supplier_invoice') {
1992 if (($line->debit - $line->credit) > 0) {
1993 $nature_piece =
'AF';
1995 $nature_piece =
'FF';
1997 } elseif ($line->doc_type ==
'customer_invoice') {
1998 if (($line->debit - $line->credit) < 0) {
1999 $nature_piece =
'AC';
2001 $nature_piece =
'FC';
2006 $tab[] = $nature_piece;
2017 $racine_subledger_account =
'';
2020 $tab[] = $racine_subledger_account;
2022 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
2024 $tab[] = $line->sens;
2028 $tab[] = $date_creation;
2030 $tab[] = $line->lettering_code;
2032 $tab[] = $line->date_lettering;
2034 if (!empty($line->subledger_account)) {
2040 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2042 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2056 $tab[] = $line->doc_ref;
2084 $output = implode($separator, $tab).$end_line;
2086 fwrite($exportFile, $output);
2105 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2109 $last_codeinvoice =
'';
2111 foreach ($objectLines as $line) {
2113 if ($last_codeinvoice != $line->doc_ref) {
2115 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2116 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2117 $resql = $this->db->query($sql);
2119 if ($resql && $this->db->num_rows($resql) > 0) {
2120 $soc = $this->db->fetch_object($resql);
2122 $address = array(
'',
'',
'');
2123 if (strpos($soc->address,
"\n") !==
false) {
2124 $address = explode(
"\n", $soc->address);
2125 if (is_array($address) && count($address) > 0) {
2126 foreach ($address as $key => $data) {
2127 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2128 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2132 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2133 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2134 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2139 $type_enregistrement =
'C';
2141 $tab[] = $type_enregistrement;
2143 $tab[] = $soc->code_client;
2153 $tab[] = $address[0];
2155 $tab[] = $address[1];
2157 $tab[] = $address[2];
2161 $tab[] = substr($soc->town, 0, 40);
2165 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2167 $tab[] = $soc->phone;
2179 $tab[] = str_replace(
" ",
"", $soc->siret);
2237 $output = implode($separator, $tab).$end_line;
2239 fwrite($exportFile, $output);
2250 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2253 $type_enregistrement =
'E';
2254 $tab[] = $type_enregistrement;
2256 $tab[] = substr($line->code_journal, 0, 2);
2260 $tab[] = $line->piece_num;
2262 $tab[] = $date_document;
2264 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2266 $tab[] = $date_lim_reglement;
2268 if ($line->doc_type ==
'supplier_invoice') {
2269 if (($line->amount) < 0) {
2270 $nature_piece =
'AF';
2272 $nature_piece =
'FF';
2274 } elseif ($line->doc_type ==
'customer_invoice') {
2275 if (($line->amount) < 0) {
2276 $nature_piece =
'AC';
2278 $nature_piece =
'FC';
2283 $tab[] = $nature_piece;
2294 $racine_subledger_account =
'';
2297 $tab[] = $racine_subledger_account;
2299 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2301 $tab[] = $line->sens;
2305 $tab[] = $date_document;
2307 $tab[] = $line->lettering_code;
2309 $tab[] = $line->date_lettering;
2311 if (!empty($line->subledger_account)) {
2317 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2319 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2331 $tab[] = $line->doc_ref;
2365 $output = implode($separator, $tab).$end_line;
2367 fwrite($exportFile, $output);
2372 $last_codeinvoice = $line->doc_ref;
2386 $langs->load(
'compta');
2393 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2394 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2395 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2396 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2397 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2398 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2399 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2401 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2402 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2403 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2404 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2405 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2406 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2408 $output = implode($separator, $tab).$end_line;
2410 fwrite($exportFile, $output);
2415 foreach ($objectLines as $line) {
2420 $tab[] = $date_document;
2424 if (!empty($line->subledger_account)) {
2425 $account = $line->subledger_account;
2427 $account = $line->numero_compte;
2434 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2436 $tab[] =
price(abs($line->debit - $line->credit));
2437 $tab[] = $line->sens;
2445 $output = implode($separator, $tab).$end_line;
2447 fwrite($exportFile, $output);
2468 $invoices_infos = array();
2469 $supplier_invoices_infos = array();
2470 foreach ($objectLines as $line) {
2471 if ($line->debit == 0 && $line->credit == 0) {
2475 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2477 $invoice_ref = $line->doc_ref;
2480 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2481 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2482 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2483 if ($line->doc_type ==
'customer_invoice') {
2485 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2486 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2487 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2488 $resql = $this->db->query($sql);
2490 if ($obj = $this->db->fetch_object($resql)) {
2492 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2493 $invoice_ref = $obj->ref;
2494 $company_name = $obj->nom;
2499 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2500 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2501 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2502 $resql = $this->db->query($sql);
2504 if ($obj = $this->db->fetch_object($resql)) {
2506 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2507 $invoice_ref = $obj->ref;
2508 $company_name = $obj->nom;
2512 } elseif ($line->doc_type ==
'customer_invoice') {
2514 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2515 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2518 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2519 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2526 $tab[] = $date_document;
2527 $tab[] = substr($line->code_journal, 0, 4);
2529 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2538 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2540 $tab[] =
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1);
2544 $tab[] =
price2num(abs($line->debit - $line->credit));
2546 $tab[] = $line->sens;
2550 $tab[] = $date_echeance;
2552 $output = implode($separator, $tab).$end_line;
2554 fwrite($exportFile, $output);
2574 foreach ($objectLines as $line) {
2575 if ($line->debit == 0 && $line->credit == 0) {
2583 $tab[] = $date_document;
2584 $tab[] = substr($line->code_journal, 0, 4);
2585 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2591 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2592 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2593 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2594 $tab[] =
price2num(abs($line->debit - $line->credit));
2595 $tab[] = $line->sens;
2596 $tab[] = $date_document;
2601 $output = implode($separator, $tab).$end_line;
2603 fwrite($exportFile, $output);
2626 foreach ($objectLines as $line) {
2631 $tab[] = $line->piece_num;
2633 $tab[] = substr($date, 6, 4);
2634 $tab[] = substr($date, 3, 2);
2635 $tab[] = substr($date, 0, 2);
2636 $tab[] = $line->doc_ref;
2638 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2644 $numero_cpt_client =
'411';
2645 $numero_cpt_fourn =
'401';
2646 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2647 $numero_cpt_client .=
'0';
2648 $numero_cpt_fourn .=
'0';
2657 $nom_client = explode(
" - ", $line->label_operation);
2658 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2659 $tab[] =
price($line->debit);
2660 $tab[] =
price($line->credit);
2661 $tab[] =
price($line->montant);
2662 $tab[] = $line->code_journal;
2664 $output = implode($separator, $tab).$end_line;
2666 fwrite($exportFile, $output);
2680 public static function trunc($str, $size)
2682 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2692 public static function toAnsi($str, $size = -1)
2695 if ($retVal >= 0 && $size >= 0) {
2696 $retVal =
dol_substr($retVal, 0, $size,
'Windows-1251');