39require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
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;
89 public static $EXPORT_TYPE_ISTEA = 205;
92 public static $EXPORT_TYPE_FEC = 1000;
94 public static $EXPORT_TYPE_FEC2 = 1010;
104 public $errors = array();
109 public $separator =
'';
114 public $end_line =
'';
119 public $generatedfiledata = array();
129 global
$conf, $hookmanager;
135 $hookmanager->initHooks(array(
'accountancyexport'));
146 global $langs, $hookmanager;
148 $listofspecialformatexport = array(
149 self::$EXPORT_TYPE_CEGID => $langs->trans(
'Modelcsv_CEGID'),
150 self::$EXPORT_TYPE_COALA => $langs->trans(
'Modelcsv_COALA'),
151 self::$EXPORT_TYPE_BOB50 => $langs->trans(
'Modelcsv_bob50'),
152 self::$EXPORT_TYPE_CIEL => $langs->trans(
'Modelcsv_ciel'),
153 self::$EXPORT_TYPE_QUADRATUS => $langs->trans(
'Modelcsv_quadratus'),
154 self::$EXPORT_TYPE_WINFIC => $langs->trans(
'Modelcsv_winfic'),
155 self::$EXPORT_TYPE_EBP => $langs->trans(
'Modelcsv_ebp'),
156 self::$EXPORT_TYPE_COGILOG => $langs->trans(
'Modelcsv_cogilog'),
157 self::$EXPORT_TYPE_AGIRIS => $langs->trans(
'Modelcsv_agiris'),
158 self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans(
'Modelcsv_openconcerto'),
159 self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans(
'Modelcsv_Sage50_Swiss'),
160 self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans(
'Modelcsv_charlemagne'),
161 self::$EXPORT_TYPE_LDCOMPTA => $langs->trans(
'Modelcsv_LDCompta'),
162 self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans(
'Modelcsv_LDCompta10'),
163 self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans(
'Modelcsv_Gestinumv3'),
164 self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans(
'Modelcsv_Gestinumv5'),
165 self::$EXPORT_TYPE_ISUITEEXPERT =>
'Export iSuite Expert',
166 self::$EXPORT_TYPE_ISTEA => $langs->trans(
'Modelcsv_ISTEA'),
169 $listofgenericformatexport = array(
170 self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans(
'Modelcsv_configurable'),
171 self::$EXPORT_TYPE_FEC => $langs->trans(
'Modelcsv_FEC'),
172 self::$EXPORT_TYPE_FEC2 => $langs->trans(
'Modelcsv_FEC2'),
176 $listofexporttypes = $listofgenericformatexport + $listofspecialformatexport;
177 ksort($listofexporttypes, SORT_NUMERIC);
179 ksort($listofspecialformatexport, SORT_NUMERIC);
180 $listofexporttypes = array();
182 foreach ($listofgenericformatexport as $key => $val) {
184 $listofexporttypes[$key] = array(
'id' => $key,
'label' => $val,
'position' => $i);
186 $listofexporttypes[
'separator_'.$i] = array(
'id' => 0,
'label' =>
'----------------',
'position' => $i,
'disabled' =>
'disabled');
187 foreach ($listofspecialformatexport as $key => $val) {
189 $listofexporttypes[$key] = array(
'id' => $key,
'label' => $val,
'position' => $i);
194 $parameters = array();
195 $reshook = $hookmanager->executeHooks(
'getType', $parameters, $listofexporttypes);
197 return $listofexporttypes;
209 self::$EXPORT_TYPE_CONFIGURABLE =>
'csv',
210 self::$EXPORT_TYPE_CEGID =>
'cegid',
211 self::$EXPORT_TYPE_COALA =>
'coala',
212 self::$EXPORT_TYPE_BOB50 =>
'bob50',
213 self::$EXPORT_TYPE_CIEL =>
'ciel',
214 self::$EXPORT_TYPE_QUADRATUS =>
'quadratus',
215 self::$EXPORT_TYPE_WINFIC =>
'winfic',
216 self::$EXPORT_TYPE_EBP =>
'ebp',
217 self::$EXPORT_TYPE_COGILOG =>
'cogilog',
218 self::$EXPORT_TYPE_AGIRIS =>
'agiris',
219 self::$EXPORT_TYPE_OPENCONCERTO =>
'openconcerto',
220 self::$EXPORT_TYPE_SAGE50_SWISS =>
'sage50ch',
221 self::$EXPORT_TYPE_CHARLEMAGNE =>
'charlemagne',
222 self::$EXPORT_TYPE_LDCOMPTA =>
'ldcompta',
223 self::$EXPORT_TYPE_LDCOMPTA10 =>
'ldcompta10',
224 self::$EXPORT_TYPE_GESTIMUMV3 =>
'gestimumv3',
225 self::$EXPORT_TYPE_GESTIMUMV5 =>
'gestimumv5',
226 self::$EXPORT_TYPE_FEC =>
'fec',
227 self::$EXPORT_TYPE_FEC2 =>
'fec2',
228 self::$EXPORT_TYPE_ISUITEEXPERT =>
'isuiteexpert',
229 self::$EXPORT_TYPE_ISTEA =>
'istea',
233 $code = $formatcode[$type] ??
'';
234 $parameters = array(
'type' => $type);
235 $reshook = $hookmanager->executeHooks(
'getFormatCode', $parameters, $code);
249 $exporttypes = array(
251 self::$EXPORT_TYPE_CONFIGURABLE => array(
252 'label' => $langs->trans(
'Modelcsv_configurable'),
254 'ACCOUNTING_EXPORT_SEPARATORCSV' =>
getDolGlobalString(
'ACCOUNTING_EXPORT_SEPARATORCSV',
','),
258 self::$EXPORT_TYPE_CEGID => array(
259 'label' => $langs->trans(
'Modelcsv_CEGID'),
261 self::$EXPORT_TYPE_COALA => array(
262 'label' => $langs->trans(
'Modelcsv_COALA'),
264 self::$EXPORT_TYPE_BOB50 => array(
265 'label' => $langs->trans(
'Modelcsv_bob50'),
267 self::$EXPORT_TYPE_CIEL => array(
268 'label' => $langs->trans(
'Modelcsv_ciel'),
269 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
271 self::$EXPORT_TYPE_QUADRATUS => array(
272 'label' => $langs->trans(
'Modelcsv_quadratus'),
273 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
275 self::$EXPORT_TYPE_WINFIC => array(
276 'label' => $langs->trans(
'Modelcsv_winfic'),
277 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
279 self::$EXPORT_TYPE_EBP => array(
280 'label' => $langs->trans(
'Modelcsv_ebp'),
282 self::$EXPORT_TYPE_COGILOG => array(
283 'label' => $langs->trans(
'Modelcsv_cogilog'),
285 self::$EXPORT_TYPE_AGIRIS => array(
286 'label' => $langs->trans(
'Modelcsv_agiris'),
288 self::$EXPORT_TYPE_OPENCONCERTO => array(
289 'label' => $langs->trans(
'Modelcsv_openconcerto'),
291 self::$EXPORT_TYPE_SAGE50_SWISS => array(
292 'label' => $langs->trans(
'Modelcsv_Sage50_Swiss'),
294 self::$EXPORT_TYPE_CHARLEMAGNE => array(
295 'label' => $langs->trans(
'Modelcsv_charlemagne'),
296 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
298 self::$EXPORT_TYPE_LDCOMPTA => array(
299 'label' => $langs->trans(
'Modelcsv_LDCompta'),
301 self::$EXPORT_TYPE_LDCOMPTA10 => array(
302 'label' => $langs->trans(
'Modelcsv_LDCompta10'),
304 self::$EXPORT_TYPE_GESTIMUMV3 => array(
305 'label' => $langs->trans(
'Modelcsv_Gestinumv3'),
306 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
308 self::$EXPORT_TYPE_GESTIMUMV5 => array(
309 'label' => $langs->trans(
'Modelcsv_Gestinumv5'),
310 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
312 self::$EXPORT_TYPE_FEC => array(
313 'label' => $langs->trans(
'Modelcsv_FEC'),
314 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
316 self::$EXPORT_TYPE_FEC2 => array(
317 'label' => $langs->trans(
'Modelcsv_FEC2'),
318 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
320 self::$EXPORT_TYPE_ISUITEEXPERT => array(
321 'label' =>
'iSuite Expert',
322 'ACCOUNTING_EXPORT_FORMAT' =>
'csv',
324 self::$EXPORT_TYPE_ISTEA => array(
326 'ACCOUNTING_EXPORT_FORMAT' =>
'csv',
330 '1' => $langs->trans(
"Unix"),
331 '2' => $langs->trans(
"Windows")
334 'csv' => $langs->trans(
"csv"),
335 'txt' => $langs->trans(
"txt")
340 $parameters = array();
341 $reshook = $hookmanager->executeHooks(
'getTypeConfig', $parameters, $exporttypes);
354 switch ($formatexportset) {
355 case self::$EXPORT_TYPE_FEC:
356 $mime =
'text/tab-separated-values';
383 public function export(&$TData, $formatexportset, $withAttachment = 0, $downloadMode = 1, $outputMode = 1, $noouput = 1)
385 global $db,
$conf, $langs;
386 global $search_date_end, $hookmanager;
390 $filename =
'general_ledger-'.(!empty($formatcode) ? $formatcode : $formatexportset);
391 $type_export =
'general_ledger';
393 $completefilename =
'';
395 $exportFileName =
'';
396 $exportFilePath =
'';
397 $exportFileFullName =
'';
398 $downloadFileMimeType =
'';
399 $downloadFileFullName =
'';
400 $downloadFilePath =
'';
401 $archiveFullName =
'';
403 $archiveFileList = array();
404 if ($withAttachment == 1) {
405 if ($downloadMode == 0) {
408 if ($outputMode == 0) {
413 if (!extension_loaded(
'zip')) {
414 $langs->load(
'install');
415 $this->errors[] = $langs->trans(
'ErrorPHPDoesNotSupport',
'ZIP');
421 if ($downloadMode == 0) {
427 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
429 if ($outputMode == 1 || $outputMode == 2) {
430 if ($outputMode == 1) {
432 if (!empty(
$conf->accounting->multidir_temp[
$conf->entity])) {
433 $outputDir =
$conf->accounting->multidir_temp[
$conf->entity];
435 $outputDir =
$conf->accounting->dir_temp;
439 if (!empty(
$conf->accounting->multidir_output[
$conf->entity])) {
440 $outputDir =
$conf->accounting->multidir_output[
$conf->entity];
442 $outputDir =
$conf->accounting->dir_output;
446 $outputDir .=
'/export';
447 $outputDir .=
'/'.dol_sanitizePathName((
string) $formatexportset);
452 $this->errors[] = $langs->trans(
'ErrorCanNotCreateDir', $outputDir);
457 if ($outputDir !=
'') {
459 $langs->load(
'errors');
460 $this->errors[] = $langs->trans(
'ErrorDirNotFound', $outputDir);
465 if (empty($completefilename)) {
470 $exportFileFullName = $completefilename;
471 $exportFileBaseName = basename($exportFileFullName);
472 $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME);
473 $exportFilePath = $outputDir .
'/' . $exportFileFullName;
474 $exportFile = fopen($exportFilePath,
'w');
476 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $exportFilePath);
480 if ($withAttachment == 1) {
481 $archiveFileList[0] = array(
482 'path' => $exportFilePath,
483 'name' => $exportFileFullName,
487 $archiveFullName = $exportFileName .
'.zip';
488 $archivePath = $outputDir .
'/' . $archiveFullName;
494 switch ($formatexportset) {
495 case self::$EXPORT_TYPE_CONFIGURABLE:
498 case self::$EXPORT_TYPE_CEGID:
501 case self::$EXPORT_TYPE_COALA:
504 case self::$EXPORT_TYPE_BOB50:
507 case self::$EXPORT_TYPE_CIEL:
510 case self::$EXPORT_TYPE_QUADRATUS:
511 $archiveFileList = $this->
exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment);
513 case self::$EXPORT_TYPE_WINFIC:
516 case self::$EXPORT_TYPE_EBP:
519 case self::$EXPORT_TYPE_COGILOG:
522 case self::$EXPORT_TYPE_AGIRIS:
525 case self::$EXPORT_TYPE_OPENCONCERTO:
528 case self::$EXPORT_TYPE_SAGE50_SWISS:
531 case self::$EXPORT_TYPE_CHARLEMAGNE:
534 case self::$EXPORT_TYPE_LDCOMPTA:
537 case self::$EXPORT_TYPE_LDCOMPTA10:
540 case self::$EXPORT_TYPE_GESTIMUMV3:
543 case self::$EXPORT_TYPE_GESTIMUMV5:
546 case self::$EXPORT_TYPE_FEC:
547 $archiveFileList = $this->
exportFEC($TData, $exportFile, $archiveFileList, $withAttachment);
549 case self::$EXPORT_TYPE_FEC2:
550 $archiveFileList = $this->
exportFEC2($TData, $exportFile, $archiveFileList, $withAttachment);
552 case self::$EXPORT_TYPE_ISUITEEXPERT:
555 case self::$EXPORT_TYPE_ISTEA:
561 'format' => $formatexportset,
562 'file' => $exportFile,
563 'filepath' => $exportFilePath,
564 'filefullname' => $exportFileFullName,
567 $reshook = $hookmanager->executeHooks(
'export', $parameters, $TData);
569 $this->errors[] = $langs->trans(
'accountancy_error_modelnotfound');
570 } elseif (!empty($hookmanager->resArray[
'downloadFileFullName']) && !empty($hookmanager->resArray[
'downloadFilePath'])) {
571 $exportFileFullName = $hookmanager->resArray[
'downloadFileFullName'];
572 $exportFilePath = $hookmanager->resArray[
'downloadFilePath'];
579 if ($outputMode == 1 || $outputMode == 2) {
587 if ($withAttachment == 1) {
589 if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
591 $downloadFileMimeType =
'application/zip';
592 $downloadFileFullName = $archiveFullName;
593 $downloadFilePath = $archivePath;
596 $archive =
new ZipArchive();
597 $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
600 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $archivePath);
604 foreach ($archiveFileList as $archiveFileArr) {
605 $res = $archive->addFile($archiveFileArr[
'path'], $archiveFileArr[
'name']);
608 $this->errors[] = $langs->trans(
'ErrorArchiveAddFile', $archiveFileArr[
'name']);
622 if ($downloadMode == 1) {
623 if ($withAttachment == 0) {
625 if (!empty($exportFileFullName) && !empty($exportFilePath)) {
626 $downloadFileMimeType = $mimetype;
627 $downloadFileFullName = $exportFileFullName;
628 $downloadFilePath = $exportFilePath;
633 if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath) && empty($noouput)) {
636 header(
'Content-Type: ' . $downloadFileMimeType);
637 header(
'Content-Disposition: attachment; filename=' . $downloadFileFullName);
638 header(
'Cache-Control: Public, must-revalidate');
639 header(
'Pragma: public');
640 header(
'Content-Length: ' .
dol_filesize($downloadFilePath));
645 $this->generatedfiledata = array(
'downloadFilePath' => $downloadFilePath,
'downloadFileMimeType' => $downloadFileMimeType,
'downloadFileFullName' => $downloadFileFullName);
670 foreach ($objectLines as $line) {
675 $tab[] = $date_document;
676 $tab[] = $line->code_journal;
679 $tab[] = $line->sens;
680 $tab[] =
price2fec(abs($line->debit - $line->credit));
684 $output = implode($separator, $tab).$end_line;
686 fwrite($exportFile, $output);
706 foreach ($objectLines as $line) {
710 if ($line->doc_type ==
'customer_invoice') {
712 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
713 $invoice =
new Facture($this->db);
714 $invoice->fetch($line->fk_doc);
716 $refInvoice = $invoice->ref;
717 } elseif ($line->doc_type ==
'supplier_invoice') {
719 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture.class.php';
721 $invoice->fetch($line->fk_doc);
723 $refInvoice = $invoice->ref_supplier;
728 $tab[] = $line->code_journal;
729 $tab[] = $date_document;
730 $tab[] = $refInvoice;
731 if (empty($line->subledger_account)) {
737 $tab[] = $line->label_operation;
738 $tab[] = $date_document;
739 if ($line->sens ==
'D') {
740 $tab[] =
price($line->debit);
742 } elseif ($line->sens ==
'C') {
744 $tab[] =
price($line->credit);
746 $tab[] = $line->doc_ref;
747 $tab[] = $line->label_operation;
749 $output = implode($separator, $tab).$end_line;
751 fwrite($exportFile, $output);
771 foreach ($objectLines as $line) {
776 $tab[] = $date_document;
777 $tab[] = $line->code_journal;
779 $tab[] = $line->piece_num;
780 $tab[] = $line->doc_ref;
781 $tab[] =
price($line->debit);
782 $tab[] =
price($line->credit);
786 $output = implode($separator, $tab).$end_line;
788 fwrite($exportFile, $output);
808 foreach ($objectLines as $line) {
813 $tab[] = $line->piece_num;
814 $tab[] = $date_document;
816 if (empty($line->subledger_account)) {
820 if (substr($line->numero_compte, 0, 3) ==
'411') {
823 if (substr($line->numero_compte, 0, 3) ==
'401') {
829 $tab[] =
price($line->debit);
830 $tab[] =
price($line->credit);
831 $tab[] =
dol_trunc($line->label_operation, 32);
833 $output = implode($separator, $tab).$end_line;
835 fwrite($exportFile, $output);
863 foreach ($objectLines as $line) {
865 if (!empty($line->subledger_account)) {
870 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
874 $tab[] = str_pad((
string) $line->piece_num, 5);
875 $tab[] = str_pad(self::trunc($line->code_journal, 2), 2);
876 $tab[] = str_pad($date_document, 8,
' ', STR_PAD_LEFT);
877 $tab[] = str_pad($date_echeance, 8,
' ', STR_PAD_LEFT);
878 $tab[] = str_pad(self::trunc($line->doc_ref, 12), 12);
879 $tab[] = str_pad(self::trunc($code_compta, 11), 11);
880 $tab[] = str_pad(self::trunc(
dol_string_unaccent($line->doc_ref).dol_string_unaccent($line->label_operation), 25), 25);
881 $tab[] = str_pad(
price2fec(abs($line->debit - $line->credit)), 13,
' ', STR_PAD_LEFT);
882 $tab[] = str_pad($line->sens, 1);
883 $tab[] = str_repeat(
' ', 18);
887 $output = implode($tab).$end_line;
889 fwrite($exportFile, $output);
912 public function exportQuadratus($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
918 $conf->cache[
'archiveFileList_notfound'] = array();
922 foreach ($objectLines as $line) {
928 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
929 $line->label_operation = str_replace(array(
"- ",
"…",
"..."),
"", $line->label_operation);
936 $line->subledger_label = str_replace(array(
"- ",
"…",
"..."),
"", $line->subledger_label);
939 $code_compta = $line->numero_compte;
940 if (!empty($line->subledger_account)) {
941 $code_compta = $line->subledger_account;
946 if (!empty($line->subledger_account)) {
947 $tab[
'type_ligne'] =
'C';
948 $tab[
'num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8);
949 $tab[
'lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30);
951 if ($line->doc_type ==
'customer_invoice') {
952 $tab[
'lib_alpha'] = strtoupper(self::trunc(
dol_string_unaccent($line->subledger_label), 7));
953 $tab[
'filler'] = str_repeat(
' ', 52);
954 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'), 8), 8);
955 } elseif ($line->doc_type ==
'supplier_invoice') {
956 $tab[
'lib_alpha'] = strtoupper(self::trunc(
dol_string_unaccent($line->subledger_label), 7));
957 $tab[
'filler'] = str_repeat(
' ', 52);
958 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'), 8), 8);
960 $tab[
'filler'] = str_repeat(
' ', 59);
961 $tab[
'coll_compte'] = str_pad(
' ', 8);
964 $tab[
'filler2'] = str_repeat(
' ', 110);
975 if ($line->doc_type ==
'customer_invoice') {
976 $tab[
'type_compte'] =
'C';
977 } elseif ($line->doc_type ==
'supplier_invoice') {
978 $tab[
'type_compte'] =
'F';
980 $tab[
'type_compte'] =
'G';
983 $tab[
'filler3'] = str_repeat(
' ', 235);
985 $tab[
'end_line'] = $end_line;
988 fwrite($exportFile, implode($tab));
995 $tab[
'type_ligne'] =
'M';
996 $tab[
'num_compte'] = str_pad(self::trunc((
string) $code_compta, 8), 8);
997 $tab[
'code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
998 $tab[
'folio'] =
'000';
1003 $tab[
'date_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
1004 $tab[
'filler'] =
' ';
1005 $tab[
'libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.
' '.$line->label_operation, 20), 20);
1020 $tab[
'sens'] = $line->sens;
1021 $tab[
'signe_montant'] =
'+';
1024 $tab[
'montant'] = str_pad((
string) abs(($line->debit - $line->credit) * 100), 12,
'0', STR_PAD_LEFT);
1025 $tab[
'contrepartie'] = str_repeat(
' ', 8);
1028 if (!empty($line->date_lim_reglement)) {
1029 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%y');
1031 $tab[
'date_echeance'] =
'000000';
1036 $tab[
'lettrage'] = str_repeat(
' ', 2);
1037 $tab[
'codestat'] = str_repeat(
' ', 3);
1038 $tab[
'num_piece'] = str_pad(self::trunc((
string) $line->piece_num, 5), 5);
1042 $tab[
'affaire'] = str_repeat(
' ', 10);
1043 $tab[
'quantity1'] = str_repeat(
' ', 10);
1044 $tab[
'num_piece2'] = str_pad(self::trunc((
string) $line->piece_num, 8), 8);
1046 $tab[
'code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
1047 $tab[
'filler3'] = str_repeat(
' ', 3);
1055 $tab[
'libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
1056 $tab[
'codetva'] = str_repeat(
' ', 2);
1060 $tab[
'num_piece3'] = str_pad(substr(self::trunc($line->doc_ref, 20), -10), 10);
1061 $tab[
'reserved'] = str_repeat(
' ', 10);
1062 $tab[
'currency_amount'] = str_repeat(
' ', 13);
1065 $attachmentFileName =
'';
1066 if ($withAttachment == 1) {
1067 $attachmentFileKey = trim((
string) $line->piece_num);
1069 if (!isset($archiveFileList[$attachmentFileKey])) {
1071 $objectDirPath =
'';
1073 if ($line->doc_type ==
'customer_invoice') {
1074 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1075 } elseif ($line->doc_type ==
'expense_report') {
1076 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1077 } elseif ($line->doc_type ==
'supplier_invoice') {
1078 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1080 $invoice->fetch($line->fk_doc);
1081 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1082 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1085 if ($objectDirPath && empty(
$conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1086 $arrayofinclusion = array();
1088 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1090 $fileFoundPath =
'';
1091 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1093 if (!empty($fileFoundList)) {
1094 $attachmentFileNameTrunc = str_pad(self::trunc((
string) $line->piece_num, 8), 8,
'0', STR_PAD_LEFT);
1096 foreach ($fileFoundList as $fileFound) {
1097 if (strstr($fileFound[
'name'], $objectFileName)) {
1100 if ($line->doc_type ==
'supplier_invoice') {
1101 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1104 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1107 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1108 if (file_exists($fileFoundPath)) {
1109 $archiveFileList[$attachmentFileKey] = array(
1110 'path' => $fileFoundPath,
1111 'name' => $attachmentFileNameTrunc.
'.pdf',
1119 if (empty($fileFoundPath)) {
1121 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1126 if (isset($archiveFileList[$attachmentFileKey])) {
1127 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1131 if (
dol_strlen((
string) $attachmentFileName) == 12) {
1132 $tab[
'attachment'] = $attachmentFileName;
1134 $tab[
'attachment'] = str_repeat(
' ', 12);
1136 $tab[
'filler4'] = str_repeat(
' ', 38);
1137 $tab[
'end_line'] = $end_line;
1140 fwrite($exportFile, implode($tab));
1142 print implode($tab);
1146 return $archiveFileList;
1168 foreach ($objectLines as $line) {
1169 $code_compta = $line->numero_compte;
1170 if (!empty($line->subledger_account)) {
1171 $code_compta = $line->subledger_account;
1176 $tab[
'code_journal'] = str_pad(
dol_trunc($line->code_journal, 2,
'right',
'UTF-8', 1), 2);
1181 $tab[
'date_operation'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1183 $tab[
'folio'] =
' 1';
1185 $tab[
'num_ecriture'] = str_pad(
dol_trunc((
string) $index, 6,
'right',
'UTF-8', 1), 6,
' ', STR_PAD_LEFT);
1187 $tab[
'jour_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
1189 $tab[
'num_compte'] = str_pad(
dol_trunc((
string) $code_compta, 6,
'right',
'UTF-8', 1), 6,
'0');
1191 if ($line->sens ==
'D') {
1192 $tab[
'montant_debit'] = str_pad(number_format($line->debit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1194 $tab[
'montant_crebit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1196 $tab[
'montant_debit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1198 $tab[
'montant_crebit'] = str_pad(number_format($line->credit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1203 $tab[
'lettrage'] = str_repeat(
dol_trunc((
string) $line->lettering_code, 2,
'left',
'UTF-8', 1), 2);
1205 $tab[
'code_piece'] = str_pad(
dol_trunc((
string) $line->piece_num, 5,
'left',
'UTF-8', 1), 5,
' ', STR_PAD_LEFT);
1207 $tab[
'code_stat'] = str_repeat(
' ', 4);
1209 if (!empty($line->date_lim_reglement)) {
1210 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%Y');
1212 $tab[
'date_echeance'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1215 $tab[
'monnaie'] =
'1';
1217 $tab[
'filler'] =
' ';
1219 $tab[
'ind_compteur'] =
' ';
1221 $tab[
'quantite'] =
'0,000000000';
1223 $tab[
'code_pointage'] = str_repeat(
' ', 2);
1225 $tab[
'end_line'] = $end_line;
1227 $output = implode(
'|', $tab);
1229 fwrite($exportFile, $output);
1251 foreach ($objectLines as $line) {
1257 $tab[] = $date_document;
1258 $tab[] = $line->code_journal;
1259 if (empty($line->subledger_account)) {
1260 $tab[] = $line->numero_compte;
1262 $tab[] = $line->subledger_account;
1265 $tab[] =
'"'.dol_trunc($line->label_operation, 40,
'right',
'UTF-8', 1).
'"';
1266 $tab[] =
'"'.dol_trunc((
string) $line->piece_num, 15,
'right',
'UTF-8', 1).
'"';
1267 $tab[] =
price2num(abs($line->debit - $line->credit));
1268 $tab[] = $line->sens;
1269 $tab[] = $date_document;
1272 $output = implode($separator, $tab).$end_line;
1274 fwrite($exportFile, $output);
1294 foreach ($objectLines as $line) {
1299 $tab[] = $line->piece_num;
1301 $tab[] = $date_document;
1304 if (empty($line->subledger_account)) {
1313 $tab[] =
price($line->debit);
1314 $tab[] =
price($line->credit);
1315 $tab[] =
price(abs($line->debit - $line->credit));
1316 $tab[] = $line->sens;
1317 $tab[] = $line->lettering_code;
1318 $tab[] = $line->code_journal;
1320 $output = implode($separator, $tab).$end_line;
1322 fwrite($exportFile, $output);
1341 foreach ($objectLines as $line) {
1346 $tab[] = $date_document;
1347 $tab[] = $line->code_journal;
1348 if (empty($line->subledger_account)) {
1353 $tab[] = $line->doc_ref;
1354 $tab[] = $line->label_operation;
1355 $tab[] =
price($line->debit);
1356 $tab[] =
price($line->credit);
1358 $output = implode($separator, $tab).$end_line;
1360 fwrite($exportFile, $output);
1378 $separator = $this->separator;
1380 foreach ($objectLines as $line) {
1385 $tab[] = $line->piece_num;
1386 $tab[] = $date_document;
1387 $tab[] = $line->doc_ref;
1388 $tab[] = preg_match(
'/'.$separator.
'/', $line->label_operation) ?
"'".$line->label_operation.
"'" : $line->label_operation;
1393 $tab[] =
price2num($line->debit - $line->credit);
1394 $tab[] = $line->code_journal;
1396 $output = implode($separator, $tab).$this->end_line;
1398 fwrite($exportFile, $output);
1421 foreach ($objectLines as $line) {
1422 if ($line->subledger_account && substr($line->subledger_account, 0, 1) ==
'4') {
1423 $tiers[$line->piece_num] = $line->subledger_label;
1427 foreach ($objectLines as $line) {
1432 $search = array(
'Paiement fournisseur ',
'Virement ',
'Paiement ');
1433 $replace = array(
'Paiemt fourn ',
'Virt ',
'Paiemt ');
1434 $label_operation = str_replace($search, $replace, $line->label_operation);
1436 $label_operation = preg_match(
'/'.$separator.
'/', $label_operation) ?
"'".$label_operation.
"'" : $label_operation;
1440 $tab[] = $line->piece_num;
1441 $tab[] = $date_document;
1442 $tab[] = $line->doc_ref;
1443 $tab[] = array_key_exists($line->piece_num, $tiers) ? $tiers[$line->piece_num] :
'';
1444 $tab[] =
length_accountg(($line->subledger_account && (substr($line->subledger_account, 0, 2) == substr($line->numero_compte, 0, 2))) ? $line->subledger_account : $line->numero_compte);
1445 $tab[] =
length_accountg($line->subledger_account ? $line->subledger_account : $line->numero_compte);
1446 $tab[] =
length_accountg($line->subledger_account ? $line->numero_compte :
'');
1447 $tab[] = ($line->doc_type ==
'bank') ? $label_operation : ($line->subledger_account ? $line->subledger_label : $line->label_compte);
1448 $tab[] = $label_operation;
1451 $tab[] = $line->code_journal;
1453 $output = mb_convert_encoding(
'"'.implode(
'"'.$separator.
'"', $tab).
'"'.$this->end_line,
'ISO-8859-1');
1455 fwrite($exportFile, $output);
1474 public function exportFEC($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1476 global
$conf, $langs;
1482 $tab[] =
"JournalCode";
1483 $tab[] =
"JournalLib";
1484 $tab[] =
"EcritureNum";
1485 $tab[] =
"EcritureDate";
1486 $tab[] =
"CompteNum";
1487 $tab[] =
"CompteLib";
1488 $tab[] =
"CompAuxNum";
1489 $tab[] =
"CompAuxLib";
1490 $tab[] =
"PieceRef";
1491 $tab[] =
"PieceDate";
1492 $tab[] =
"EcritureLib";
1495 $tab[] =
"EcritureLet";
1497 $tab[] =
"ValidDate";
1498 $tab[] =
"Montantdevise";
1500 $tab[] =
"DateLimitReglmt";
1501 $tab[] =
"NumFacture";
1502 $tab[] =
"FichierFacture";
1504 $output = implode($separator, $tab).$end_line;
1506 fwrite($exportFile, $output);
1511 $conf->cache[
'archiveFileList_notfound'] = array();
1514 foreach ($objectLines as $line) {
1515 if ($line->debit == 0 && $line->credit == 0) {
1523 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1524 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1525 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1531 if ($line->doc_type ==
'customer_invoice') {
1533 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1534 $invoice =
new Facture($this->db);
1535 $invoice->fetch($line->fk_doc);
1537 $refInvoice = (
string) $invoice->ref;
1538 } elseif ($line->doc_type ==
'supplier_invoice') {
1540 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1542 $invoice->fetch($line->fk_doc);
1544 $refInvoice = (
string) $invoice->ref_supplier;
1550 $tab[] = $line->code_journal;
1555 $tab[] = $labeljournal;
1558 $tab[] = $line->piece_num;
1561 $tab[] = $date_document;
1576 $tab[] = $line->doc_ref;
1583 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1584 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1594 $tab[] = $line->lettering_code;
1597 $tab[] = $date_lettering;
1600 $tab[] = $date_validation;
1603 $tab[] = $line->multicurrency_amount;
1606 $tab[] = $line->multicurrency_code;
1609 $tab[] = $date_limit_payment;
1613 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1614 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1618 $attachmentFileName =
'';
1619 if ($withAttachment == 1) {
1620 $attachmentFileKey = trim((
string) $line->piece_num);
1622 if (!isset($archiveFileList[$attachmentFileKey])) {
1624 $objectDirPath =
'';
1626 if ($line->doc_type ==
'customer_invoice') {
1627 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1628 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1630 } elseif ($line->doc_type ==
'expense_report') {
1631 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1632 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1634 } elseif ($line->doc_type ==
'supplier_invoice' && $invoice instanceof
FactureFournisseur) {
1635 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1636 '@phan-var-force FactureFournisseur $invoice';
1637 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1638 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1642 if ($objectDirPath && empty(
$conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1643 $arrayofinclusion = array();
1645 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1647 $fileFoundPath =
'';
1648 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1650 if (!empty($fileFoundList)) {
1651 $attachmentFileNameTrunc = $line->doc_ref;
1653 foreach ($fileFoundList as $fileFound) {
1654 if (strstr($fileFound[
'name'], $objectFileName)) {
1657 if ($line->doc_type ==
'supplier_invoice') {
1658 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1661 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1664 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1665 if (file_exists($fileFoundPath)) {
1666 $archiveFileList[$attachmentFileKey] = array(
1667 'path' => $fileFoundPath,
1668 'name' => $attachmentFileNameTrunc.
'.pdf',
1676 if (empty($fileFoundPath)) {
1678 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1683 if (isset($archiveFileList[$attachmentFileKey])) {
1684 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1688 $tab[] = $attachmentFileName;
1690 $output = implode($separator, $tab).$end_line;
1693 fwrite($exportFile, $output);
1700 return $archiveFileList;
1715 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1717 global
$conf, $langs;
1723 $tab[] =
"JournalCode";
1724 $tab[] =
"JournalLib";
1725 $tab[] =
"EcritureNum";
1726 $tab[] =
"EcritureDate";
1727 $tab[] =
"CompteNum";
1728 $tab[] =
"CompteLib";
1729 $tab[] =
"CompAuxNum";
1730 $tab[] =
"CompAuxLib";
1731 $tab[] =
"PieceRef";
1732 $tab[] =
"PieceDate";
1733 $tab[] =
"EcritureLib";
1736 $tab[] =
"EcritureLet";
1738 $tab[] =
"ValidDate";
1739 $tab[] =
"Montantdevise";
1741 $tab[] =
"DateLimitReglmt";
1742 $tab[] =
"NumFacture";
1743 $tab[] =
"FichierFacture";
1745 $output = implode($separator, $tab).$end_line;
1747 fwrite($exportFile, $output);
1752 $conf->cache[
'archiveFileList_notfound'] = array();
1755 foreach ($objectLines as $line) {
1756 if ($line->debit == 0 && $line->credit == 0) {
1763 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1764 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1765 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1771 if ($line->doc_type ==
'customer_invoice') {
1773 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1774 $invoice =
new Facture($this->db);
1775 $invoice->fetch($line->fk_doc);
1777 $refInvoice = (
string) $invoice->ref;
1778 } elseif ($line->doc_type ==
'supplier_invoice') {
1780 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1782 $invoice->fetch($line->fk_doc);
1784 $refInvoice = (
string) $invoice->ref_supplier;
1790 $tab[] = $line->code_journal;
1795 $tab[] = $labeljournal;
1798 $tab[] = $line->piece_num;
1801 $tab[] = $date_creation;
1816 $tab[] = $line->doc_ref;
1819 $tab[] = $date_document;
1823 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1824 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1834 $tab[] = $line->lettering_code;
1837 $tab[] = $date_lettering;
1840 $tab[] = $date_validation;
1843 $tab[] = $line->multicurrency_amount;
1846 $tab[] = $line->multicurrency_code;
1849 $tab[] = $date_limit_payment;
1853 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1854 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1858 $attachmentFileName =
'';
1859 if ($withAttachment == 1) {
1860 $attachmentFileKey = trim((
string) $line->piece_num);
1862 if (!isset($archiveFileList[$attachmentFileKey])) {
1864 $objectDirPath =
'';
1866 if ($line->doc_type ==
'customer_invoice') {
1867 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1868 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1870 } elseif ($line->doc_type ==
'expense_report') {
1871 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1872 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1874 } elseif ($line->doc_type ==
'supplier_invoice' && $invoice instanceof
FactureFournisseur) {
1875 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1876 '@phan-var-force FactureFournisseur $invoice';
1877 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1878 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1882 if ($objectDirPath && empty(
$conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1883 $arrayofinclusion = array();
1885 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1887 $fileFoundPath =
'';
1888 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1890 if (!empty($fileFoundList)) {
1891 $attachmentFileNameTrunc = $line->doc_ref;
1893 foreach ($fileFoundList as $fileFound) {
1894 if (strstr($fileFound[
'name'], $objectFileName)) {
1897 if ($line->doc_type ==
'supplier_invoice') {
1898 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1901 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1904 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1905 if (file_exists($fileFoundPath)) {
1906 $archiveFileList[$attachmentFileKey] = array(
1907 'path' => $fileFoundPath,
1908 'name' => $attachmentFileNameTrunc.
'.pdf',
1916 if (empty($fileFoundPath)) {
1918 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1923 if (isset($archiveFileList[$attachmentFileKey])) {
1924 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1928 $tab[] = $attachmentFileName;
1930 $output = implode($separator, $tab).$end_line;
1932 fwrite($exportFile, $output);
1939 return $archiveFileList;
1975 $tab[] =
"FW-Betrag";
1982 $output = implode($separator, $tab).$end_line;
1984 fwrite($exportFile, $output);
1990 $thisPieceAccountNr =
"";
1991 $aSize = count($objectLines);
1992 foreach ($objectLines as $aIndex => $line) {
1993 $sammelBuchung =
false;
1994 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1995 $sammelBuchung =
true;
1996 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1997 $sammelBuchung =
true;
1998 } elseif ($aIndex + 1 < $aSize
1999 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
2000 && $aIndex - 1 < $aSize
2001 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
2003 $sammelBuchung =
true;
2009 $tab[] = $line->piece_num;
2013 $tab[] = $date_document;
2018 if ($line->sens ==
'D') {
2026 if (empty($line->code_tiers)) {
2027 if ($line->piece_num == $thisPieceNum) {
2036 $tab[] = $this->separator;
2045 if ($sammelBuchung) {
2053 $tab[] = abs($line->debit - $line->credit);
2060 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
2064 if (strlen($line1) == 0) {
2068 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
2069 $line1 = $line1.
' / '.$line2;
2073 $tab[] =
'"'.self::toAnsi($line1).
'"';
2075 $tab[] =
'"'.self::toAnsi($line2).
'"';
2079 $tab[] = $this->separator;
2084 $output = implode($separator, $tab).$end_line;
2086 fwrite($exportFile, $output);
2091 if ($line->piece_num !== $thisPieceNum) {
2092 $thisPieceNum = $line->piece_num;
2093 $thisPieceAccountNr = $line->numero_compte;
2111 foreach ($objectLines as $line) {
2114 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2119 $type_enregistrement =
'E';
2120 $tab[] = $type_enregistrement;
2122 $tab[] = substr($line->code_journal, 0, 2);
2126 $tab[] = $line->piece_num;
2128 $tab[] = $date_document;
2130 $tab[] = $line->label_operation;
2132 $tab[] = $date_lim_reglement;
2134 if ($line->doc_type ==
'supplier_invoice') {
2135 if (($line->debit - $line->credit) > 0) {
2136 $nature_piece =
'AF';
2138 $nature_piece =
'FF';
2140 } elseif ($line->doc_type ==
'customer_invoice') {
2141 if (($line->debit - $line->credit) < 0) {
2142 $nature_piece =
'AC';
2144 $nature_piece =
'FC';
2149 $tab[] = $nature_piece;
2160 $racine_subledger_account =
'';
2163 $tab[] = $racine_subledger_account;
2165 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
2167 $tab[] = $line->sens;
2171 $tab[] = $date_creation;
2173 $tab[] = $line->lettering_code;
2175 $tab[] = $line->date_lettering;
2177 if (!empty($line->subledger_account)) {
2183 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2185 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2199 $tab[] = $line->doc_ref;
2227 $output = implode($separator, $tab).$end_line;
2229 fwrite($exportFile, $output);
2248 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2252 $last_codeinvoice =
'';
2254 foreach ($objectLines as $line) {
2256 if ($last_codeinvoice != $line->doc_ref) {
2258 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2259 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2260 $resql = $this->db->query($sql);
2262 if ($resql && $this->db->num_rows($resql) > 0) {
2263 $soc = $this->db->fetch_object($resql);
2265 $address = array(
'',
'',
'');
2266 if (strpos($soc->address,
"\n") !==
false) {
2267 $address = explode(
"\n", $soc->address);
2268 if (is_array($address) && count($address) > 0) {
2269 foreach ($address as $key => $data) {
2270 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2271 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2275 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2276 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2277 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2282 $type_enregistrement =
'C';
2284 $tab[] = $type_enregistrement;
2286 $tab[] = $soc->code_client;
2296 $tab[] = $address[0];
2298 $tab[] = $address[1];
2300 $tab[] = $address[2];
2304 $tab[] = substr($soc->town, 0, 40);
2308 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2310 $tab[] = $soc->phone;
2322 $tab[] = str_replace(
" ",
"", $soc->siret);
2380 $output = implode($separator, $tab).$end_line;
2382 fwrite($exportFile, $output);
2393 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2396 $type_enregistrement =
'E';
2397 $tab[] = $type_enregistrement;
2399 $tab[] = substr($line->code_journal, 0, 2);
2403 $tab[] = $line->piece_num;
2405 $tab[] = $date_document;
2407 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2409 $tab[] = $date_lim_reglement;
2411 if ($line->doc_type ==
'supplier_invoice') {
2412 if (($line->amount) < 0) {
2413 $nature_piece =
'AF';
2415 $nature_piece =
'FF';
2417 } elseif ($line->doc_type ==
'customer_invoice') {
2418 if (($line->amount) < 0) {
2419 $nature_piece =
'AC';
2421 $nature_piece =
'FC';
2426 $tab[] = $nature_piece;
2437 $racine_subledger_account =
'';
2440 $tab[] = $racine_subledger_account;
2442 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2444 $tab[] = $line->sens;
2448 $tab[] = $date_document;
2450 $tab[] = $line->lettering_code;
2452 $tab[] = $line->date_lettering;
2454 if (!empty($line->subledger_account)) {
2460 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2462 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2474 $tab[] = $line->doc_ref;
2508 $output = implode($separator, $tab).$end_line;
2510 fwrite($exportFile, $output);
2515 $last_codeinvoice = $line->doc_ref;
2529 $langs->load(
'compta');
2536 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2537 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2538 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2539 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2540 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2541 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2542 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2544 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2545 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2546 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2547 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2548 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2549 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2551 $output = implode($separator, $tab).$end_line;
2553 fwrite($exportFile, $output);
2558 foreach ($objectLines as $line) {
2563 $tab[] = $date_document;
2567 if (!empty($line->subledger_account)) {
2568 $account = $line->subledger_account;
2570 $account = $line->numero_compte;
2577 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2579 $tab[] =
price(abs($line->debit - $line->credit));
2580 $tab[] = $line->sens;
2588 $output = implode($separator, $tab).$end_line;
2590 fwrite($exportFile, $output);
2611 $invoices_infos = array();
2612 $supplier_invoices_infos = array();
2613 foreach ($objectLines as $line) {
2614 if ($line->debit == 0 && $line->credit == 0) {
2618 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2620 $invoice_ref = $line->doc_ref;
2623 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2624 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2625 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2626 if ($line->doc_type ==
'customer_invoice') {
2628 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2629 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2630 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2631 $resql = $this->db->query($sql);
2633 if ($obj = $this->db->fetch_object($resql)) {
2635 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2636 $invoice_ref = $obj->ref;
2637 $company_name = $obj->nom;
2642 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2643 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2644 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2645 $resql = $this->db->query($sql);
2647 if ($obj = $this->db->fetch_object($resql)) {
2649 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2650 $invoice_ref = $obj->ref;
2651 $company_name = $obj->nom;
2655 } elseif ($line->doc_type ==
'customer_invoice') {
2657 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2658 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2661 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2662 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2669 $tab[] = $date_document;
2670 $tab[] = substr($line->code_journal, 0, 4);
2672 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2681 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2683 $tab[] =
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1);
2687 $tab[] =
price2num(abs($line->debit - $line->credit));
2689 $tab[] = $line->sens;
2693 $tab[] = $date_echeance;
2695 $output = implode($separator, $tab).$end_line;
2697 fwrite($exportFile, $output);
2717 foreach ($objectLines as $line) {
2718 if ($line->debit == 0 && $line->credit == 0) {
2726 $tab[] = $date_document;
2727 $tab[] = substr($line->code_journal, 0, 4);
2728 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2734 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2735 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2736 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2737 $tab[] =
price2num(abs($line->debit - $line->credit));
2738 $tab[] = $line->sens;
2739 $tab[] = $date_document;
2744 $output = implode($separator, $tab).$end_line;
2746 fwrite($exportFile, $output);
2769 foreach ($objectLines as $line) {
2774 $tab[] = $line->piece_num;
2776 $tab[] = substr($date, 6, 4);
2777 $tab[] = substr($date, 3, 2);
2778 $tab[] = substr($date, 0, 2);
2779 $tab[] = $line->doc_ref;
2781 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2787 $numero_cpt_client =
'411';
2788 $numero_cpt_fourn =
'401';
2789 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2790 $numero_cpt_client .=
'0';
2791 $numero_cpt_fourn .=
'0';
2800 $nom_client = explode(
" - ", $line->label_operation);
2801 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2802 $tab[] =
price($line->debit);
2803 $tab[] =
price($line->credit);
2804 $tab[] =
price($line->montant);
2805 $tab[] = $line->code_journal;
2807 $output = implode($separator, $tab).$end_line;
2809 fwrite($exportFile, $output);
2823 public static function trunc($str, $size)
2825 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2835 public static function toAnsi($str, $size = -1)
2838 if ($retVal >= 0 && $size >= 0) {
2839 $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
buildzip.php
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.