39require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
52 public static $EXPORT_TYPE_CONFIGURABLE = 1;
54 public static $EXPORT_TYPE_AGIRIS = 10;
56 public static $EXPORT_TYPE_EBP = 15;
58 public static $EXPORT_TYPE_CEGID = 20;
60 public static $EXPORT_TYPE_COGILOG = 25;
62 public static $EXPORT_TYPE_COALA = 30;
64 public static $EXPORT_TYPE_BOB50 = 35;
66 public static $EXPORT_TYPE_CIEL = 40;
68 public static $EXPORT_TYPE_SAGE50_SWISS = 45;
70 public static $EXPORT_TYPE_CHARLEMAGNE = 50;
72 public static $EXPORT_TYPE_QUADRATUS = 60;
74 public static $EXPORT_TYPE_WINFIC = 70;
76 public static $EXPORT_TYPE_OPENCONCERTO = 100;
78 public static $EXPORT_TYPE_LDCOMPTA = 110;
80 public static $EXPORT_TYPE_LDCOMPTA10 = 120;
82 public static $EXPORT_TYPE_GESTIMUMV3 = 130;
84 public static $EXPORT_TYPE_GESTIMUMV5 = 135;
86 public static $EXPORT_TYPE_ISUITEEXPERT = 200;
88 public static $EXPORT_TYPE_ISTEA = 205;
91 public static $EXPORT_TYPE_FEC = 1000;
93 public static $EXPORT_TYPE_FEC2 = 1010;
103 public $errors = array();
108 public $separator =
'';
113 public $end_line =
'';
118 public $generatedfiledata = array();
128 global
$conf, $hookmanager;
134 $hookmanager->initHooks(array(
'accountancyexport'));
145 global $langs, $hookmanager;
147 $listofspecialformatexport = array(
148 self::$EXPORT_TYPE_CEGID => $langs->trans(
'Modelcsv_CEGID'),
149 self::$EXPORT_TYPE_COALA => $langs->trans(
'Modelcsv_COALA'),
150 self::$EXPORT_TYPE_BOB50 => $langs->trans(
'Modelcsv_bob50'),
151 self::$EXPORT_TYPE_CIEL => $langs->trans(
'Modelcsv_ciel'),
152 self::$EXPORT_TYPE_QUADRATUS => $langs->trans(
'Modelcsv_quadratus'),
153 self::$EXPORT_TYPE_WINFIC => $langs->trans(
'Modelcsv_winfic'),
154 self::$EXPORT_TYPE_EBP => $langs->trans(
'Modelcsv_ebp'),
155 self::$EXPORT_TYPE_COGILOG => $langs->trans(
'Modelcsv_cogilog'),
156 self::$EXPORT_TYPE_AGIRIS => $langs->trans(
'Modelcsv_agiris'),
157 self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans(
'Modelcsv_openconcerto'),
158 self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans(
'Modelcsv_Sage50_Swiss'),
159 self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans(
'Modelcsv_charlemagne'),
160 self::$EXPORT_TYPE_LDCOMPTA => $langs->trans(
'Modelcsv_LDCompta'),
161 self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans(
'Modelcsv_LDCompta10'),
162 self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans(
'Modelcsv_Gestinumv3'),
163 self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans(
'Modelcsv_Gestinumv5'),
164 self::$EXPORT_TYPE_ISUITEEXPERT =>
'Export iSuite Expert',
165 self::$EXPORT_TYPE_ISTEA => $langs->trans(
'Modelcsv_ISTEA'),
168 $listofgenericformatexport = array(
169 self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans(
'Modelcsv_configurable'),
170 self::$EXPORT_TYPE_FEC => $langs->trans(
'Modelcsv_FEC'),
171 self::$EXPORT_TYPE_FEC2 => $langs->trans(
'Modelcsv_FEC2'),
175 $listofexporttypes = $listofgenericformatexport + $listofspecialformatexport;
176 ksort($listofexporttypes, SORT_NUMERIC);
178 ksort($listofspecialformatexport, SORT_NUMERIC);
179 $listofexporttypes = array();
181 foreach ($listofgenericformatexport as $key => $val) {
183 $listofexporttypes[$key] = array(
'id' => $key,
'label' => $val,
'position' => $i);
185 $listofexporttypes[
'separator_'.$i] = array(
'id' => 0,
'label' =>
'----------------',
'position' => $i,
'disabled' =>
'disabled');
186 foreach ($listofspecialformatexport as $key => $val) {
188 $listofexporttypes[$key] = array(
'id' => $key,
'label' => $val,
'position' => $i);
193 $parameters = array();
194 $reshook = $hookmanager->executeHooks(
'getType', $parameters, $listofexporttypes);
196 return $listofexporttypes;
208 self::$EXPORT_TYPE_CONFIGURABLE =>
'csv',
209 self::$EXPORT_TYPE_CEGID =>
'cegid',
210 self::$EXPORT_TYPE_COALA =>
'coala',
211 self::$EXPORT_TYPE_BOB50 =>
'bob50',
212 self::$EXPORT_TYPE_CIEL =>
'ciel',
213 self::$EXPORT_TYPE_QUADRATUS =>
'quadratus',
214 self::$EXPORT_TYPE_WINFIC =>
'winfic',
215 self::$EXPORT_TYPE_EBP =>
'ebp',
216 self::$EXPORT_TYPE_COGILOG =>
'cogilog',
217 self::$EXPORT_TYPE_AGIRIS =>
'agiris',
218 self::$EXPORT_TYPE_OPENCONCERTO =>
'openconcerto',
219 self::$EXPORT_TYPE_SAGE50_SWISS =>
'sage50ch',
220 self::$EXPORT_TYPE_CHARLEMAGNE =>
'charlemagne',
221 self::$EXPORT_TYPE_LDCOMPTA =>
'ldcompta',
222 self::$EXPORT_TYPE_LDCOMPTA10 =>
'ldcompta10',
223 self::$EXPORT_TYPE_GESTIMUMV3 =>
'gestimumv3',
224 self::$EXPORT_TYPE_GESTIMUMV5 =>
'gestimumv5',
225 self::$EXPORT_TYPE_FEC =>
'fec',
226 self::$EXPORT_TYPE_FEC2 =>
'fec2',
227 self::$EXPORT_TYPE_ISUITEEXPERT =>
'isuiteexpert',
228 self::$EXPORT_TYPE_ISTEA =>
'istea',
232 $code = $formatcode[$type] ??
'';
233 $parameters = array(
'type' => $type);
234 $reshook = $hookmanager->executeHooks(
'getFormatCode', $parameters, $code);
248 $exporttypes = array(
250 self::$EXPORT_TYPE_CONFIGURABLE => array(
251 'label' => $langs->trans(
'Modelcsv_configurable'),
253 'ACCOUNTING_EXPORT_SEPARATORCSV' =>
getDolGlobalString(
'ACCOUNTING_EXPORT_SEPARATORCSV',
','),
257 self::$EXPORT_TYPE_CEGID => array(
258 'label' => $langs->trans(
'Modelcsv_CEGID'),
260 self::$EXPORT_TYPE_COALA => array(
261 'label' => $langs->trans(
'Modelcsv_COALA'),
263 self::$EXPORT_TYPE_BOB50 => array(
264 'label' => $langs->trans(
'Modelcsv_bob50'),
266 self::$EXPORT_TYPE_CIEL => array(
267 'label' => $langs->trans(
'Modelcsv_ciel'),
268 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
270 self::$EXPORT_TYPE_QUADRATUS => array(
271 'label' => $langs->trans(
'Modelcsv_quadratus'),
272 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
274 self::$EXPORT_TYPE_WINFIC => array(
275 'label' => $langs->trans(
'Modelcsv_winfic'),
276 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
278 self::$EXPORT_TYPE_EBP => array(
279 'label' => $langs->trans(
'Modelcsv_ebp'),
281 self::$EXPORT_TYPE_COGILOG => array(
282 'label' => $langs->trans(
'Modelcsv_cogilog'),
284 self::$EXPORT_TYPE_AGIRIS => array(
285 'label' => $langs->trans(
'Modelcsv_agiris'),
287 self::$EXPORT_TYPE_OPENCONCERTO => array(
288 'label' => $langs->trans(
'Modelcsv_openconcerto'),
290 self::$EXPORT_TYPE_SAGE50_SWISS => array(
291 'label' => $langs->trans(
'Modelcsv_Sage50_Swiss'),
293 self::$EXPORT_TYPE_CHARLEMAGNE => array(
294 'label' => $langs->trans(
'Modelcsv_charlemagne'),
295 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
297 self::$EXPORT_TYPE_LDCOMPTA => array(
298 'label' => $langs->trans(
'Modelcsv_LDCompta'),
300 self::$EXPORT_TYPE_LDCOMPTA10 => array(
301 'label' => $langs->trans(
'Modelcsv_LDCompta10'),
303 self::$EXPORT_TYPE_GESTIMUMV3 => array(
304 'label' => $langs->trans(
'Modelcsv_Gestinumv3'),
305 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
307 self::$EXPORT_TYPE_GESTIMUMV5 => array(
308 'label' => $langs->trans(
'Modelcsv_Gestinumv5'),
309 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
311 self::$EXPORT_TYPE_FEC => array(
312 'label' => $langs->trans(
'Modelcsv_FEC'),
313 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
315 self::$EXPORT_TYPE_FEC2 => array(
316 'label' => $langs->trans(
'Modelcsv_FEC2'),
317 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
319 self::$EXPORT_TYPE_ISUITEEXPERT => array(
320 'label' =>
'iSuite Expert',
321 'ACCOUNTING_EXPORT_FORMAT' =>
'csv',
323 self::$EXPORT_TYPE_ISTEA => array(
325 'ACCOUNTING_EXPORT_FORMAT' =>
'csv',
329 '1' => $langs->trans(
"Unix"),
330 '2' => $langs->trans(
"Windows")
333 'csv' => $langs->trans(
"csv"),
334 'txt' => $langs->trans(
"txt")
339 $parameters = array();
340 $reshook = $hookmanager->executeHooks(
'getTypeConfig', $parameters, $exporttypes);
353 switch ($formatexportset) {
354 case self::$EXPORT_TYPE_FEC:
355 $mime =
'text/tab-separated-values';
382 public function export(&$TData, $formatexportset, $withAttachment = 0, $downloadMode = 1, $outputMode = 1, $noouput = 1)
384 global $db,
$conf, $langs;
385 global $search_date_end, $hookmanager;
389 $filename =
'general_ledger-'.(!empty($formatcode) ? $formatcode : $formatexportset);
390 $type_export =
'general_ledger';
392 $completefilename =
'';
394 $exportFileName =
'';
395 $exportFilePath =
'';
396 $exportFileFullName =
'';
397 $downloadFileMimeType =
'';
398 $downloadFileFullName =
'';
399 $downloadFilePath =
'';
400 $archiveFullName =
'';
402 $archiveFileList = array();
403 if ($withAttachment == 1) {
404 if ($downloadMode == 0) {
407 if ($outputMode == 0) {
412 if (!extension_loaded(
'zip')) {
413 $langs->load(
'install');
414 $this->errors[] = $langs->trans(
'ErrorPHPDoesNotSupport',
'ZIP');
420 if ($downloadMode == 0) {
426 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
428 if ($outputMode == 1 || $outputMode == 2) {
429 if ($outputMode == 1) {
431 if (!empty(
$conf->accounting->multidir_temp[
$conf->entity])) {
432 $outputDir =
$conf->accounting->multidir_temp[
$conf->entity];
434 $outputDir =
$conf->accounting->dir_temp;
438 if (!empty(
$conf->accounting->multidir_output[
$conf->entity])) {
439 $outputDir =
$conf->accounting->multidir_output[
$conf->entity];
441 $outputDir =
$conf->accounting->dir_output;
445 $outputDir .=
'/export';
446 $outputDir .=
'/'.dol_sanitizePathName((
string) $formatexportset);
451 $this->errors[] = $langs->trans(
'ErrorCanNotCreateDir', $outputDir);
456 if ($outputDir !=
'') {
458 $langs->load(
'errors');
459 $this->errors[] = $langs->trans(
'ErrorDirNotFound', $outputDir);
464 if (empty($completefilename)) {
469 $exportFileFullName = $completefilename;
470 $exportFileBaseName = basename($exportFileFullName);
471 $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME);
472 $exportFilePath = $outputDir .
'/' . $exportFileFullName;
473 $exportFile = fopen($exportFilePath,
'w');
475 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $exportFilePath);
479 if ($withAttachment == 1) {
480 $archiveFileList[0] = array(
481 'path' => $exportFilePath,
482 'name' => $exportFileFullName,
486 $archiveFullName = $exportFileName .
'.zip';
487 $archivePath = $outputDir .
'/' . $archiveFullName;
493 switch ($formatexportset) {
494 case self::$EXPORT_TYPE_CONFIGURABLE:
497 case self::$EXPORT_TYPE_CEGID:
500 case self::$EXPORT_TYPE_COALA:
503 case self::$EXPORT_TYPE_BOB50:
506 case self::$EXPORT_TYPE_CIEL:
509 case self::$EXPORT_TYPE_QUADRATUS:
510 $archiveFileList = $this->
exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment);
512 case self::$EXPORT_TYPE_WINFIC:
515 case self::$EXPORT_TYPE_EBP:
518 case self::$EXPORT_TYPE_COGILOG:
521 case self::$EXPORT_TYPE_AGIRIS:
524 case self::$EXPORT_TYPE_OPENCONCERTO:
527 case self::$EXPORT_TYPE_SAGE50_SWISS:
530 case self::$EXPORT_TYPE_CHARLEMAGNE:
533 case self::$EXPORT_TYPE_LDCOMPTA:
536 case self::$EXPORT_TYPE_LDCOMPTA10:
539 case self::$EXPORT_TYPE_GESTIMUMV3:
542 case self::$EXPORT_TYPE_GESTIMUMV5:
545 case self::$EXPORT_TYPE_FEC:
546 $archiveFileList = $this->
exportFEC($TData, $exportFile, $archiveFileList, $withAttachment);
548 case self::$EXPORT_TYPE_FEC2:
549 $archiveFileList = $this->
exportFEC2($TData, $exportFile, $archiveFileList, $withAttachment);
551 case self::$EXPORT_TYPE_ISUITEEXPERT:
554 case self::$EXPORT_TYPE_ISTEA:
560 'format' => $formatexportset,
561 'file' => $exportFile,
562 'filepath' => $exportFilePath,
563 'filefullname' => $exportFileFullName,
566 $reshook = $hookmanager->executeHooks(
'export', $parameters, $TData);
568 $this->errors[] = $langs->trans(
'accountancy_error_modelnotfound');
569 } elseif (!empty($hookmanager->resArray[
'downloadFileFullName']) && !empty($hookmanager->resArray[
'downloadFilePath'])) {
570 $exportFileFullName = $hookmanager->resArray[
'downloadFileFullName'];
571 $exportFilePath = $hookmanager->resArray[
'downloadFilePath'];
578 if ($outputMode == 1 || $outputMode == 2) {
586 if ($withAttachment == 1) {
588 if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
590 $downloadFileMimeType =
'application/zip';
591 $downloadFileFullName = $archiveFullName;
592 $downloadFilePath = $archivePath;
595 $archive =
new ZipArchive();
596 $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
599 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $archivePath);
603 foreach ($archiveFileList as $archiveFileArr) {
604 $res = $archive->addFile($archiveFileArr[
'path'], $archiveFileArr[
'name']);
607 $this->errors[] = $langs->trans(
'ErrorArchiveAddFile', $archiveFileArr[
'name']);
621 if ($downloadMode == 1) {
622 if ($withAttachment == 0) {
624 if (!empty($exportFileFullName) && !empty($exportFilePath)) {
625 $downloadFileMimeType = $mimetype;
626 $downloadFileFullName = $exportFileFullName;
627 $downloadFilePath = $exportFilePath;
632 if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath) && empty($noouput)) {
635 header(
'Content-Type: ' . $downloadFileMimeType);
636 header(
'Content-Disposition: attachment; filename=' . $downloadFileFullName);
637 header(
'Cache-Control: Public, must-revalidate');
638 header(
'Pragma: public');
639 header(
'Content-Length: ' .
dol_filesize($downloadFilePath));
644 $this->generatedfiledata = array(
'downloadFilePath' => $downloadFilePath,
'downloadFileMimeType' => $downloadFileMimeType,
'downloadFileFullName' => $downloadFileFullName);
669 foreach ($objectLines as $line) {
674 $tab[] = $date_document;
675 $tab[] = $line->code_journal;
678 $tab[] = $line->sens;
679 $tab[] =
price2fec(abs($line->debit - $line->credit));
683 $output = implode($separator, $tab).$end_line;
685 fwrite($exportFile, $output);
705 foreach ($objectLines as $line) {
709 if ($line->doc_type ==
'customer_invoice') {
711 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
712 $invoice =
new Facture($this->db);
713 $invoice->fetch($line->fk_doc);
715 $refInvoice = $invoice->ref;
716 } elseif ($line->doc_type ==
'supplier_invoice') {
718 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture.class.php';
720 $invoice->fetch($line->fk_doc);
722 $refInvoice = $invoice->ref_supplier;
727 $tab[] = $line->code_journal;
728 $tab[] = $date_document;
729 $tab[] = $refInvoice;
730 if (empty($line->subledger_account)) {
736 $tab[] = $line->label_operation;
737 $tab[] = $date_document;
738 if ($line->sens ==
'D') {
739 $tab[] =
price($line->debit);
741 } elseif ($line->sens ==
'C') {
743 $tab[] =
price($line->credit);
745 $tab[] = $line->doc_ref;
746 $tab[] = $line->label_operation;
748 $output = implode($separator, $tab).$end_line;
750 fwrite($exportFile, $output);
770 foreach ($objectLines as $line) {
775 $tab[] = $date_document;
776 $tab[] = $line->code_journal;
778 $tab[] = $line->piece_num;
779 $tab[] = $line->doc_ref;
780 $tab[] =
price($line->debit);
781 $tab[] =
price($line->credit);
785 $output = implode($separator, $tab).$end_line;
787 fwrite($exportFile, $output);
807 foreach ($objectLines as $line) {
812 $tab[] = $line->piece_num;
813 $tab[] = $date_document;
815 if (empty($line->subledger_account)) {
819 if (substr($line->numero_compte, 0, 3) ==
'411') {
822 if (substr($line->numero_compte, 0, 3) ==
'401') {
828 $tab[] =
price($line->debit);
829 $tab[] =
price($line->credit);
830 $tab[] =
dol_trunc($line->label_operation, 32);
832 $output = implode($separator, $tab).$end_line;
834 fwrite($exportFile, $output);
862 foreach ($objectLines as $line) {
864 if (!empty($line->subledger_account)) {
869 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
873 $tab[] = str_pad((
string) $line->piece_num, 5);
874 $tab[] = str_pad(self::trunc($line->code_journal, 2), 2);
875 $tab[] = str_pad($date_document, 8,
' ', STR_PAD_LEFT);
876 $tab[] = str_pad($date_echeance, 8,
' ', STR_PAD_LEFT);
877 $tab[] = str_pad(self::trunc($line->doc_ref, 12), 12);
878 $tab[] = str_pad(self::trunc($code_compta, 11), 11);
879 $tab[] = str_pad(self::trunc(
dol_string_unaccent($line->doc_ref).dol_string_unaccent($line->label_operation), 25), 25);
880 $tab[] = str_pad(
price2fec(abs($line->debit - $line->credit)), 13,
' ', STR_PAD_LEFT);
881 $tab[] = str_pad($line->sens, 1);
882 $tab[] = str_repeat(
' ', 18);
886 $output = implode($tab).$end_line;
888 fwrite($exportFile, $output);
911 public function exportQuadratus($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
917 $conf->cache[
'archiveFileList_notfound'] = array();
921 foreach ($objectLines as $line) {
927 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
928 $line->label_operation = str_replace(array(
"- ",
"…",
"..."),
"", $line->label_operation);
935 $line->subledger_label = str_replace(array(
"- ",
"…",
"..."),
"", $line->subledger_label);
938 $code_compta = $line->numero_compte;
939 if (!empty($line->subledger_account)) {
940 $code_compta = $line->subledger_account;
945 if (!empty($line->subledger_account)) {
946 $tab[
'type_ligne'] =
'C';
947 $tab[
'num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8);
948 $tab[
'lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30);
950 if ($line->doc_type ==
'customer_invoice') {
951 $tab[
'lib_alpha'] = strtoupper(self::trunc(
dol_string_unaccent($line->subledger_label), 7));
952 $tab[
'filler'] = str_repeat(
' ', 52);
953 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'), 8), 8);
954 } elseif ($line->doc_type ==
'supplier_invoice') {
955 $tab[
'lib_alpha'] = strtoupper(self::trunc(
dol_string_unaccent($line->subledger_label), 7));
956 $tab[
'filler'] = str_repeat(
' ', 52);
957 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'), 8), 8);
959 $tab[
'filler'] = str_repeat(
' ', 59);
960 $tab[
'coll_compte'] = str_pad(
' ', 8);
963 $tab[
'filler2'] = str_repeat(
' ', 110);
974 if ($line->doc_type ==
'customer_invoice') {
975 $tab[
'type_compte'] =
'C';
976 } elseif ($line->doc_type ==
'supplier_invoice') {
977 $tab[
'type_compte'] =
'F';
979 $tab[
'type_compte'] =
'G';
982 $tab[
'filler3'] = str_repeat(
' ', 235);
984 $tab[
'end_line'] = $end_line;
987 fwrite($exportFile, implode($tab));
994 $tab[
'type_ligne'] =
'M';
995 $tab[
'num_compte'] = str_pad(self::trunc((
string) $code_compta, 8), 8);
996 $tab[
'code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
997 $tab[
'folio'] =
'000';
1002 $tab[
'date_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
1003 $tab[
'filler'] =
' ';
1004 $tab[
'libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.
' '.$line->label_operation, 20), 20);
1019 $tab[
'sens'] = $line->sens;
1020 $tab[
'signe_montant'] =
'+';
1023 $tab[
'montant'] = str_pad((
string) abs(($line->debit - $line->credit) * 100), 12,
'0', STR_PAD_LEFT);
1024 $tab[
'contrepartie'] = str_repeat(
' ', 8);
1027 if (!empty($line->date_lim_reglement)) {
1028 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%y');
1030 $tab[
'date_echeance'] =
'000000';
1035 $tab[
'lettrage'] = str_repeat(
' ', 2);
1036 $tab[
'codestat'] = str_repeat(
' ', 3);
1037 $tab[
'num_piece'] = str_pad(self::trunc((
string) $line->piece_num, 5), 5);
1041 $tab[
'affaire'] = str_repeat(
' ', 10);
1042 $tab[
'quantity1'] = str_repeat(
' ', 10);
1043 $tab[
'num_piece2'] = str_pad(self::trunc((
string) $line->piece_num, 8), 8);
1045 $tab[
'code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
1046 $tab[
'filler3'] = str_repeat(
' ', 3);
1054 $tab[
'libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
1055 $tab[
'codetva'] = str_repeat(
' ', 2);
1059 $tab[
'num_piece3'] = str_pad(substr(self::trunc($line->doc_ref, 20), -10), 10);
1060 $tab[
'reserved'] = str_repeat(
' ', 10);
1061 $tab[
'currency_amount'] = str_repeat(
' ', 13);
1064 $attachmentFileName =
'';
1065 if ($withAttachment == 1) {
1066 $attachmentFileKey = trim((
string) $line->piece_num);
1068 if (!isset($archiveFileList[$attachmentFileKey])) {
1070 $objectDirPath =
'';
1072 if ($line->doc_type ==
'customer_invoice') {
1073 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1074 } elseif ($line->doc_type ==
'expense_report') {
1075 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1076 } elseif ($line->doc_type ==
'supplier_invoice') {
1077 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1079 $invoice->fetch($line->fk_doc);
1080 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1081 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1084 if ($objectDirPath && empty(
$conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1085 $arrayofinclusion = array();
1087 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1089 $fileFoundPath =
'';
1090 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1092 if (!empty($fileFoundList)) {
1093 $attachmentFileNameTrunc = str_pad(self::trunc((
string) $line->piece_num, 8), 8,
'0', STR_PAD_LEFT);
1095 foreach ($fileFoundList as $fileFound) {
1096 if (strstr($fileFound[
'name'], $objectFileName)) {
1099 if ($line->doc_type ==
'supplier_invoice') {
1100 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1103 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1106 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1107 if (file_exists($fileFoundPath)) {
1108 $archiveFileList[$attachmentFileKey] = array(
1109 'path' => $fileFoundPath,
1110 'name' => $attachmentFileNameTrunc.
'.pdf',
1118 if (empty($fileFoundPath)) {
1120 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1125 if (isset($archiveFileList[$attachmentFileKey])) {
1126 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1130 if (
dol_strlen((
string) $attachmentFileName) == 12) {
1131 $tab[
'attachment'] = $attachmentFileName;
1133 $tab[
'attachment'] = str_repeat(
' ', 12);
1135 $tab[
'filler4'] = str_repeat(
' ', 38);
1136 $tab[
'end_line'] = $end_line;
1139 fwrite($exportFile, implode($tab));
1141 print implode($tab);
1145 return $archiveFileList;
1167 foreach ($objectLines as $line) {
1168 $code_compta = $line->numero_compte;
1169 if (!empty($line->subledger_account)) {
1170 $code_compta = $line->subledger_account;
1175 $tab[
'code_journal'] = str_pad(
dol_trunc($line->code_journal, 2,
'right',
'UTF-8', 1), 2);
1180 $tab[
'date_operation'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1182 $tab[
'folio'] =
' 1';
1184 $tab[
'num_ecriture'] = str_pad(
dol_trunc((
string) $index, 6,
'right',
'UTF-8', 1), 6,
' ', STR_PAD_LEFT);
1186 $tab[
'jour_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
1188 $tab[
'num_compte'] = str_pad(
dol_trunc((
string) $code_compta, 6,
'right',
'UTF-8', 1), 6,
'0');
1190 if ($line->sens ==
'D') {
1191 $tab[
'montant_debit'] = str_pad(number_format($line->debit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1193 $tab[
'montant_crebit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1195 $tab[
'montant_debit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1197 $tab[
'montant_crebit'] = str_pad(number_format($line->credit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1202 $tab[
'lettrage'] = str_repeat(
dol_trunc((
string) $line->lettering_code, 2,
'left',
'UTF-8', 1), 2);
1204 $tab[
'code_piece'] = str_pad(
dol_trunc((
string) $line->piece_num, 5,
'left',
'UTF-8', 1), 5,
' ', STR_PAD_LEFT);
1206 $tab[
'code_stat'] = str_repeat(
' ', 4);
1208 if (!empty($line->date_lim_reglement)) {
1209 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%Y');
1211 $tab[
'date_echeance'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1214 $tab[
'monnaie'] =
'1';
1216 $tab[
'filler'] =
' ';
1218 $tab[
'ind_compteur'] =
' ';
1220 $tab[
'quantite'] =
'0,000000000';
1222 $tab[
'code_pointage'] = str_repeat(
' ', 2);
1224 $tab[
'end_line'] = $end_line;
1226 $output = implode(
'|', $tab);
1228 fwrite($exportFile, $output);
1250 foreach ($objectLines as $line) {
1256 $tab[] = $date_document;
1257 $tab[] = $line->code_journal;
1258 if (empty($line->subledger_account)) {
1259 $tab[] = $line->numero_compte;
1261 $tab[] = $line->subledger_account;
1264 $tab[] =
'"'.dol_trunc($line->label_operation, 40,
'right',
'UTF-8', 1).
'"';
1265 $tab[] =
'"'.dol_trunc((
string) $line->piece_num, 15,
'right',
'UTF-8', 1).
'"';
1266 $tab[] =
price2num(abs($line->debit - $line->credit));
1267 $tab[] = $line->sens;
1268 $tab[] = $date_document;
1271 $output = implode($separator, $tab).$end_line;
1273 fwrite($exportFile, $output);
1293 foreach ($objectLines as $line) {
1298 $tab[] = $line->piece_num;
1300 $tab[] = $date_document;
1303 if (empty($line->subledger_account)) {
1312 $tab[] =
price($line->debit);
1313 $tab[] =
price($line->credit);
1314 $tab[] =
price(abs($line->debit - $line->credit));
1315 $tab[] = $line->sens;
1316 $tab[] = $line->lettering_code;
1317 $tab[] = $line->code_journal;
1319 $output = implode($separator, $tab).$end_line;
1321 fwrite($exportFile, $output);
1340 foreach ($objectLines as $line) {
1345 $tab[] = $date_document;
1346 $tab[] = $line->code_journal;
1347 if (empty($line->subledger_account)) {
1352 $tab[] = $line->doc_ref;
1353 $tab[] = $line->label_operation;
1354 $tab[] =
price($line->debit);
1355 $tab[] =
price($line->credit);
1357 $output = implode($separator, $tab).$end_line;
1359 fwrite($exportFile, $output);
1377 $separator = $this->separator;
1379 foreach ($objectLines as $line) {
1384 $tab[] = $line->piece_num;
1385 $tab[] = $date_document;
1386 $tab[] = $line->doc_ref;
1387 $tab[] = preg_match(
'/'.$separator.
'/', $line->label_operation) ?
"'".$line->label_operation.
"'" : $line->label_operation;
1392 $tab[] =
price2num($line->debit - $line->credit);
1393 $tab[] = $line->code_journal;
1395 $output = implode($separator, $tab).$this->end_line;
1397 fwrite($exportFile, $output);
1420 foreach ($objectLines as $line) {
1421 if ($line->subledger_account && substr($line->subledger_account, 0, 1) ==
'4') {
1422 $tiers[$line->piece_num] = $line->subledger_label;
1426 foreach ($objectLines as $line) {
1431 $search = array(
'Paiement fournisseur ',
'Virement ',
'Paiement ');
1432 $replace = array(
'Paiemt fourn ',
'Virt ',
'Paiemt ');
1433 $label_operation = str_replace($search, $replace, $line->label_operation);
1435 $label_operation = preg_match(
'/'.$separator.
'/', $label_operation) ?
"'".$label_operation.
"'" : $label_operation;
1439 $tab[] = $line->piece_num;
1440 $tab[] = $date_document;
1441 $tab[] = $line->doc_ref;
1442 $tab[] = array_key_exists($line->piece_num, $tiers) ? $tiers[$line->piece_num] :
'';
1443 $tab[] =
length_accountg(($line->subledger_account && (substr($line->subledger_account, 0, 2) == substr($line->numero_compte, 0, 2))) ? $line->subledger_account : $line->numero_compte);
1444 $tab[] =
length_accountg($line->subledger_account ? $line->subledger_account : $line->numero_compte);
1445 $tab[] =
length_accountg($line->subledger_account ? $line->numero_compte :
'');
1446 $tab[] = ($line->doc_type ==
'bank') ? $label_operation : ($line->subledger_account ? $line->subledger_label : $line->label_compte);
1447 $tab[] = $label_operation;
1450 $tab[] = $line->code_journal;
1452 $output = mb_convert_encoding(
'"'.implode(
'"'.$separator.
'"', $tab).
'"'.$this->end_line,
'ISO-8859-1');
1454 fwrite($exportFile, $output);
1473 public function exportFEC($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1475 global
$conf, $langs;
1481 $tab[] =
"JournalCode";
1482 $tab[] =
"JournalLib";
1483 $tab[] =
"EcritureNum";
1484 $tab[] =
"EcritureDate";
1485 $tab[] =
"CompteNum";
1486 $tab[] =
"CompteLib";
1487 $tab[] =
"CompAuxNum";
1488 $tab[] =
"CompAuxLib";
1489 $tab[] =
"PieceRef";
1490 $tab[] =
"PieceDate";
1491 $tab[] =
"EcritureLib";
1494 $tab[] =
"EcritureLet";
1496 $tab[] =
"ValidDate";
1497 $tab[] =
"Montantdevise";
1499 $tab[] =
"DateLimitReglmt";
1500 $tab[] =
"NumFacture";
1501 $tab[] =
"FichierFacture";
1503 $output = implode($separator, $tab).$end_line;
1505 fwrite($exportFile, $output);
1510 $conf->cache[
'archiveFileList_notfound'] = array();
1513 foreach ($objectLines as $line) {
1514 if ($line->debit == 0 && $line->credit == 0) {
1522 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1523 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1524 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1530 if ($line->doc_type ==
'customer_invoice') {
1532 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1533 $invoice =
new Facture($this->db);
1534 $invoice->fetch($line->fk_doc);
1536 $refInvoice = (
string) $invoice->ref;
1537 } elseif ($line->doc_type ==
'supplier_invoice') {
1539 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1541 $invoice->fetch($line->fk_doc);
1543 $refInvoice = (
string) $invoice->ref_supplier;
1549 $tab[] = $line->code_journal;
1554 $tab[] = $labeljournal;
1557 $tab[] = $line->piece_num;
1560 $tab[] = $date_document;
1575 $tab[] = $line->doc_ref;
1582 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1583 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1593 $tab[] = $line->lettering_code;
1596 $tab[] = $date_lettering;
1599 $tab[] = $date_validation;
1602 $tab[] = $line->multicurrency_amount;
1605 $tab[] = $line->multicurrency_code;
1608 $tab[] = $date_limit_payment;
1612 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1613 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1617 $attachmentFileName =
'';
1618 if ($withAttachment == 1) {
1619 $attachmentFileKey = trim((
string) $line->piece_num);
1621 if (!isset($archiveFileList[$attachmentFileKey])) {
1623 $objectDirPath =
'';
1625 if ($line->doc_type ==
'customer_invoice') {
1626 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1627 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1629 } elseif ($line->doc_type ==
'expense_report') {
1630 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1631 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1633 } elseif ($line->doc_type ==
'supplier_invoice' && $invoice instanceof
FactureFournisseur) {
1634 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1635 '@phan-var-force FactureFournisseur $invoice';
1636 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1637 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1641 if ($objectDirPath && empty(
$conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1642 $arrayofinclusion = array();
1644 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1646 $fileFoundPath =
'';
1647 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1649 if (!empty($fileFoundList)) {
1650 $attachmentFileNameTrunc = $line->doc_ref;
1652 foreach ($fileFoundList as $fileFound) {
1653 if (strstr($fileFound[
'name'], $objectFileName)) {
1656 if ($line->doc_type ==
'supplier_invoice') {
1657 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1660 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1663 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1664 if (file_exists($fileFoundPath)) {
1665 $archiveFileList[$attachmentFileKey] = array(
1666 'path' => $fileFoundPath,
1667 'name' => $attachmentFileNameTrunc.
'.pdf',
1675 if (empty($fileFoundPath)) {
1677 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1682 if (isset($archiveFileList[$attachmentFileKey])) {
1683 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1687 $tab[] = $attachmentFileName;
1689 $output = implode($separator, $tab).$end_line;
1692 fwrite($exportFile, $output);
1699 return $archiveFileList;
1714 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1716 global
$conf, $langs;
1722 $tab[] =
"JournalCode";
1723 $tab[] =
"JournalLib";
1724 $tab[] =
"EcritureNum";
1725 $tab[] =
"EcritureDate";
1726 $tab[] =
"CompteNum";
1727 $tab[] =
"CompteLib";
1728 $tab[] =
"CompAuxNum";
1729 $tab[] =
"CompAuxLib";
1730 $tab[] =
"PieceRef";
1731 $tab[] =
"PieceDate";
1732 $tab[] =
"EcritureLib";
1735 $tab[] =
"EcritureLet";
1737 $tab[] =
"ValidDate";
1738 $tab[] =
"Montantdevise";
1740 $tab[] =
"DateLimitReglmt";
1741 $tab[] =
"NumFacture";
1742 $tab[] =
"FichierFacture";
1744 $output = implode($separator, $tab).$end_line;
1746 fwrite($exportFile, $output);
1751 $conf->cache[
'archiveFileList_notfound'] = array();
1754 foreach ($objectLines as $line) {
1755 if ($line->debit == 0 && $line->credit == 0) {
1762 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1763 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1764 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1770 if ($line->doc_type ==
'customer_invoice') {
1772 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1773 $invoice =
new Facture($this->db);
1774 $invoice->fetch($line->fk_doc);
1776 $refInvoice = (
string) $invoice->ref;
1777 } elseif ($line->doc_type ==
'supplier_invoice') {
1779 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1781 $invoice->fetch($line->fk_doc);
1783 $refInvoice = (
string) $invoice->ref_supplier;
1789 $tab[] = $line->code_journal;
1794 $tab[] = $labeljournal;
1797 $tab[] = $line->piece_num;
1800 $tab[] = $date_creation;
1815 $tab[] = $line->doc_ref;
1818 $tab[] = $date_document;
1822 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1823 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1833 $tab[] = $line->lettering_code;
1836 $tab[] = $date_lettering;
1839 $tab[] = $date_validation;
1842 $tab[] = $line->multicurrency_amount;
1845 $tab[] = $line->multicurrency_code;
1848 $tab[] = $date_limit_payment;
1852 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1853 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1857 $attachmentFileName =
'';
1858 if ($withAttachment == 1) {
1859 $attachmentFileKey = trim((
string) $line->piece_num);
1861 if (!isset($archiveFileList[$attachmentFileKey])) {
1863 $objectDirPath =
'';
1865 if ($line->doc_type ==
'customer_invoice') {
1866 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1867 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1869 } elseif ($line->doc_type ==
'expense_report') {
1870 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1871 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1873 } elseif ($line->doc_type ==
'supplier_invoice' && $invoice instanceof
FactureFournisseur) {
1874 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1875 '@phan-var-force FactureFournisseur $invoice';
1876 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1877 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1881 if ($objectDirPath && empty(
$conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1882 $arrayofinclusion = array();
1884 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1886 $fileFoundPath =
'';
1887 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1889 if (!empty($fileFoundList)) {
1890 $attachmentFileNameTrunc = $line->doc_ref;
1892 foreach ($fileFoundList as $fileFound) {
1893 if (strstr($fileFound[
'name'], $objectFileName)) {
1896 if ($line->doc_type ==
'supplier_invoice') {
1897 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1900 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1903 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1904 if (file_exists($fileFoundPath)) {
1905 $archiveFileList[$attachmentFileKey] = array(
1906 'path' => $fileFoundPath,
1907 'name' => $attachmentFileNameTrunc.
'.pdf',
1915 if (empty($fileFoundPath)) {
1917 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1922 if (isset($archiveFileList[$attachmentFileKey])) {
1923 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1927 $tab[] = $attachmentFileName;
1929 $output = implode($separator, $tab).$end_line;
1931 fwrite($exportFile, $output);
1938 return $archiveFileList;
1974 $tab[] =
"FW-Betrag";
1981 $output = implode($separator, $tab).$end_line;
1983 fwrite($exportFile, $output);
1989 $thisPieceAccountNr =
"";
1990 $aSize = count($objectLines);
1991 foreach ($objectLines as $aIndex => $line) {
1992 $sammelBuchung =
false;
1993 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1994 $sammelBuchung =
true;
1995 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1996 $sammelBuchung =
true;
1997 } elseif ($aIndex + 1 < $aSize
1998 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1999 && $aIndex - 1 < $aSize
2000 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
2002 $sammelBuchung =
true;
2008 $tab[] = $line->piece_num;
2012 $tab[] = $date_document;
2017 if ($line->sens ==
'D') {
2025 if (empty($line->code_tiers)) {
2026 if ($line->piece_num == $thisPieceNum) {
2035 $tab[] = $this->separator;
2044 if ($sammelBuchung) {
2052 $tab[] = abs($line->debit - $line->credit);
2059 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
2063 if (strlen($line1) == 0) {
2067 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
2068 $line1 = $line1.
' / '.$line2;
2072 $tab[] =
'"'.self::toAnsi($line1).
'"';
2074 $tab[] =
'"'.self::toAnsi($line2).
'"';
2078 $tab[] = $this->separator;
2083 $output = implode($separator, $tab).$end_line;
2085 fwrite($exportFile, $output);
2090 if ($line->piece_num !== $thisPieceNum) {
2091 $thisPieceNum = $line->piece_num;
2092 $thisPieceAccountNr = $line->numero_compte;
2110 foreach ($objectLines as $line) {
2113 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2118 $type_enregistrement =
'E';
2119 $tab[] = $type_enregistrement;
2121 $tab[] = substr($line->code_journal, 0, 2);
2125 $tab[] = $line->piece_num;
2127 $tab[] = $date_document;
2129 $tab[] = $line->label_operation;
2131 $tab[] = $date_lim_reglement;
2133 if ($line->doc_type ==
'supplier_invoice') {
2134 if (($line->debit - $line->credit) > 0) {
2135 $nature_piece =
'AF';
2137 $nature_piece =
'FF';
2139 } elseif ($line->doc_type ==
'customer_invoice') {
2140 if (($line->debit - $line->credit) < 0) {
2141 $nature_piece =
'AC';
2143 $nature_piece =
'FC';
2148 $tab[] = $nature_piece;
2159 $racine_subledger_account =
'';
2162 $tab[] = $racine_subledger_account;
2164 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
2166 $tab[] = $line->sens;
2170 $tab[] = $date_creation;
2172 $tab[] = $line->lettering_code;
2174 $tab[] = $line->date_lettering;
2176 if (!empty($line->subledger_account)) {
2182 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2184 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2198 $tab[] = $line->doc_ref;
2226 $output = implode($separator, $tab).$end_line;
2228 fwrite($exportFile, $output);
2247 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2251 $last_codeinvoice =
'';
2253 foreach ($objectLines as $line) {
2255 if ($last_codeinvoice != $line->doc_ref) {
2257 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2258 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2259 $resql = $this->db->query($sql);
2261 if ($resql && $this->db->num_rows($resql) > 0) {
2262 $soc = $this->db->fetch_object($resql);
2264 $address = array(
'',
'',
'');
2265 if (strpos($soc->address,
"\n") !==
false) {
2266 $address = explode(
"\n", $soc->address);
2267 if (is_array($address) && count($address) > 0) {
2268 foreach ($address as $key => $data) {
2269 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2270 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2274 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2275 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2276 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2281 $type_enregistrement =
'C';
2283 $tab[] = $type_enregistrement;
2285 $tab[] = $soc->code_client;
2295 $tab[] = $address[0];
2297 $tab[] = $address[1];
2299 $tab[] = $address[2];
2303 $tab[] = substr($soc->town, 0, 40);
2307 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2309 $tab[] = $soc->phone;
2321 $tab[] = str_replace(
" ",
"", $soc->siret);
2379 $output = implode($separator, $tab).$end_line;
2381 fwrite($exportFile, $output);
2392 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2395 $type_enregistrement =
'E';
2396 $tab[] = $type_enregistrement;
2398 $tab[] = substr($line->code_journal, 0, 2);
2402 $tab[] = $line->piece_num;
2404 $tab[] = $date_document;
2406 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2408 $tab[] = $date_lim_reglement;
2410 if ($line->doc_type ==
'supplier_invoice') {
2411 if (($line->amount) < 0) {
2412 $nature_piece =
'AF';
2414 $nature_piece =
'FF';
2416 } elseif ($line->doc_type ==
'customer_invoice') {
2417 if (($line->amount) < 0) {
2418 $nature_piece =
'AC';
2420 $nature_piece =
'FC';
2425 $tab[] = $nature_piece;
2436 $racine_subledger_account =
'';
2439 $tab[] = $racine_subledger_account;
2441 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2443 $tab[] = $line->sens;
2447 $tab[] = $date_document;
2449 $tab[] = $line->lettering_code;
2451 $tab[] = $line->date_lettering;
2453 if (!empty($line->subledger_account)) {
2459 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2461 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2473 $tab[] = $line->doc_ref;
2507 $output = implode($separator, $tab).$end_line;
2509 fwrite($exportFile, $output);
2514 $last_codeinvoice = $line->doc_ref;
2528 $langs->load(
'compta');
2535 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2536 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2537 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2538 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2539 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2540 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2541 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2543 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2544 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2545 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2546 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2547 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2548 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2550 $output = implode($separator, $tab).$end_line;
2552 fwrite($exportFile, $output);
2557 foreach ($objectLines as $line) {
2562 $tab[] = $date_document;
2566 if (!empty($line->subledger_account)) {
2567 $account = $line->subledger_account;
2569 $account = $line->numero_compte;
2576 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2578 $tab[] =
price(abs($line->debit - $line->credit));
2579 $tab[] = $line->sens;
2587 $output = implode($separator, $tab).$end_line;
2589 fwrite($exportFile, $output);
2610 $invoices_infos = array();
2611 $supplier_invoices_infos = array();
2612 foreach ($objectLines as $line) {
2613 if ($line->debit == 0 && $line->credit == 0) {
2617 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2619 $invoice_ref = $line->doc_ref;
2622 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2623 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2624 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2625 if ($line->doc_type ==
'customer_invoice') {
2627 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2628 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2629 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2630 $resql = $this->db->query($sql);
2632 if ($obj = $this->db->fetch_object($resql)) {
2634 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2635 $invoice_ref = $obj->ref;
2636 $company_name = $obj->nom;
2641 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2642 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2643 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2644 $resql = $this->db->query($sql);
2646 if ($obj = $this->db->fetch_object($resql)) {
2648 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2649 $invoice_ref = $obj->ref;
2650 $company_name = $obj->nom;
2654 } elseif ($line->doc_type ==
'customer_invoice') {
2656 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2657 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2660 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2661 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2668 $tab[] = $date_document;
2669 $tab[] = substr($line->code_journal, 0, 4);
2671 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2680 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2682 $tab[] =
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1);
2686 $tab[] =
price2num(abs($line->debit - $line->credit));
2688 $tab[] = $line->sens;
2692 $tab[] = $date_echeance;
2694 $output = implode($separator, $tab).$end_line;
2696 fwrite($exportFile, $output);
2716 foreach ($objectLines as $line) {
2717 if ($line->debit == 0 && $line->credit == 0) {
2725 $tab[] = $date_document;
2726 $tab[] = substr($line->code_journal, 0, 4);
2727 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2733 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2734 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2735 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2736 $tab[] =
price2num(abs($line->debit - $line->credit));
2737 $tab[] = $line->sens;
2738 $tab[] = $date_document;
2743 $output = implode($separator, $tab).$end_line;
2745 fwrite($exportFile, $output);
2768 foreach ($objectLines as $line) {
2773 $tab[] = $line->piece_num;
2775 $tab[] = substr($date, 6, 4);
2776 $tab[] = substr($date, 3, 2);
2777 $tab[] = substr($date, 0, 2);
2778 $tab[] = $line->doc_ref;
2780 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2786 $numero_cpt_client =
'411';
2787 $numero_cpt_fourn =
'401';
2788 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2789 $numero_cpt_client .=
'0';
2790 $numero_cpt_fourn .=
'0';
2799 $nom_client = explode(
" - ", $line->label_operation);
2800 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2801 $tab[] =
price($line->debit);
2802 $tab[] =
price($line->credit);
2803 $tab[] =
price($line->montant);
2804 $tab[] = $line->code_journal;
2806 $output = implode($separator, $tab).$end_line;
2808 fwrite($exportFile, $output);
2822 public static function trunc($str, $size)
2824 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2834 public static function toAnsi($str, $size = -1)
2837 if ($retVal >= 0 && $size >= 0) {
2838 $retVal =
dol_substr($retVal, 0, $size,
'Windows-1251');
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
Manage the different format accountancy export.
exportCogilog($objectLines, $exportFile=null)
Export format : COGILOG Last review for this format : 2022-07-12 Alexandre Spangaro (aspangaro@open-d...
export(&$TData, $formatexportset, $withAttachment=0, $downloadMode=1, $outputMode=1, $noouput=1)
Function who chose which export to use with the default config, and make the export into a file.
exportAgiris($objectLines, $exportFile=null)
Export format : Agiris Isacompta.
exportQuadratus($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : Quadratus (Format ASCII) Format since 2015 compatible QuadraCOMPTA Last review for th...
exportWinfic($objectLines, $exportFile=null)
Export format : WinFic - eWinfic - WinSis Compta Last review for this format : 2022-11-01 Alexandre S...
exportSAGE50SWISS($objectLines, $exportFile=null)
Export format : SAGE50SWISS.
exportOpenConcerto($objectLines, $exportFile=null)
Export format : OpenConcerto.
exportEbp($objectLines, $exportFile=null)
Export format : EBP.
exportLDCompta10($objectLines, $exportFile=null)
Export format : LD Compta version 10 & higher Last review for this format : 08-15-2021 Alexandre Span...
exportCharlemagne($objectLines, $exportFile=null)
Export format : Charlemagne.
getTypeConfig()
Array with all export types available (key + label) and parameters for config.
exportFEC($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : FEC Last review for this format : 2023/10/12 Alexandre Spangaro (aspangaro@open-dsi....
exportISTEA($objectLines, $exportFile=null)
Export format : ISTEA.
exportLDCompta($objectLines, $exportFile=null)
Export format : LD Compta version 9 http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Docu...
exportBob50($objectLines, $exportFile=null)
Export format : BOB50.
exportGestimumV3($objectLines, $exportFile=null)
Export format : Gestimum V3.
static trunc($str, $size)
trunc
exportiSuiteExpert($objectLines, $exportFile=null)
Export format : iSuite Expert.
exportCiel($objectLines, $exportFile=null)
Export format : CIEL (Format XIMPORT) Format since 2003 compatible CIEL version > 2002 / Sage50 Last ...
getType($mode=0)
Array with all export type available (key + label)
static toAnsi($str, $size=-1)
toAnsi
exportConfigurable($objectLines, $exportFile=null)
Export format : Configurable CSV.
static getFormatCode($type)
Return string to summarize the format (Used to generated export filename)
exportFEC2($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : FEC2 Last review for this format : 2023/10/12 Alexandre Spangaro (aspangaro@open-dsi....
__construct(DoliDB $db)
Constructor.
exportCegid($objectLines, $exportFile=null)
Export format : CEGID.
exportCoala($objectLines, $exportFile=null)
Export format : COALA.
getMimeType($formatexportset)
Return the MIME type of a file.
exportGestimumV5($objectLines, $exportFile=null)
Export format : Gestimum V5.
Class to manage Dolibarr database access.
Class to manage suppliers invoices.
Class to manage invoices.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_filesize($pathoffile)
Return size of a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
price2fec($amount)
Function to format a value into a defined format for French administration (no thousand separator & d...
dol_now($mode='gmt')
Return date for now.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.