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();
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 =
'';
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;
1554 $labeljournal = str_replace(array(
"\t",
"\n",
"\r"),
" ", $labeljournal);
1556 $tab[] = $labeljournal;
1559 $tab[] = $line->piece_num;
1562 $tab[] = $date_document;
1568 $line->label_compte = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_compte);
1575 $line->subledger_label = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->subledger_label);
1579 $tab[] = $line->doc_ref;
1586 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1587 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1597 $line->lettering_code = str_replace(array(
"\t",
"\n",
"\r"),
" ", (
string) $line->lettering_code);
1598 $tab[] = $line->lettering_code;
1601 $tab[] = $date_lettering;
1604 $tab[] = $date_validation;
1607 $tab[] = $line->multicurrency_amount;
1610 $tab[] = $line->multicurrency_code;
1613 $tab[] = $date_limit_payment;
1617 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1618 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1622 $attachmentFileName =
'';
1623 if ($withAttachment == 1) {
1624 $attachmentFileKey = trim((
string) $line->piece_num);
1626 if (!isset($archiveFileList[$attachmentFileKey])) {
1628 $objectDirPath =
'';
1630 if ($line->doc_type ==
'customer_invoice') {
1631 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1632 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1634 } elseif ($line->doc_type ==
'expense_report') {
1635 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1636 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1638 } elseif ($line->doc_type ==
'supplier_invoice' && $invoice instanceof
FactureFournisseur) {
1639 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1640 '@phan-var-force FactureFournisseur $invoice';
1641 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1642 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1646 if ($objectDirPath && empty(
$conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1647 $arrayofinclusion = array();
1649 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1651 $fileFoundPath =
'';
1652 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1654 if (!empty($fileFoundList)) {
1655 $attachmentFileNameTrunc = $line->doc_ref;
1657 foreach ($fileFoundList as $fileFound) {
1658 if (strstr($fileFound[
'name'], $objectFileName)) {
1661 if ($line->doc_type ==
'supplier_invoice') {
1662 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1665 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1668 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1669 if (file_exists($fileFoundPath)) {
1670 $archiveFileList[$attachmentFileKey] = array(
1671 'path' => $fileFoundPath,
1672 'name' => $attachmentFileNameTrunc.
'.pdf',
1680 if (empty($fileFoundPath)) {
1682 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1687 if (isset($archiveFileList[$attachmentFileKey])) {
1688 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1692 $tab[] = $attachmentFileName;
1694 $output = implode($separator, $tab).$end_line;
1697 fwrite($exportFile, $output);
1704 return $archiveFileList;
1719 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1721 global
$conf, $langs;
1727 $tab[] =
"JournalCode";
1728 $tab[] =
"JournalLib";
1729 $tab[] =
"EcritureNum";
1730 $tab[] =
"EcritureDate";
1731 $tab[] =
"CompteNum";
1732 $tab[] =
"CompteLib";
1733 $tab[] =
"CompAuxNum";
1734 $tab[] =
"CompAuxLib";
1735 $tab[] =
"PieceRef";
1736 $tab[] =
"PieceDate";
1737 $tab[] =
"EcritureLib";
1740 $tab[] =
"EcritureLet";
1742 $tab[] =
"ValidDate";
1743 $tab[] =
"Montantdevise";
1745 $tab[] =
"DateLimitReglmt";
1746 $tab[] =
"NumFacture";
1747 $tab[] =
"FichierFacture";
1749 $output = implode($separator, $tab).$end_line;
1751 fwrite($exportFile, $output);
1756 $conf->cache[
'archiveFileList_notfound'] = array();
1759 foreach ($objectLines as $line) {
1760 if ($line->debit == 0 && $line->credit == 0) {
1767 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1768 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1769 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1775 if ($line->doc_type ==
'customer_invoice') {
1777 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1778 $invoice =
new Facture($this->db);
1779 $invoice->fetch($line->fk_doc);
1781 $refInvoice = (string) $invoice->ref;
1782 } elseif ($line->doc_type ==
'supplier_invoice') {
1784 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1786 $invoice->fetch($line->fk_doc);
1788 $refInvoice = (string) $invoice->ref_supplier;
1794 $tab[] = $line->code_journal;
1798 $labeljournal = str_replace(array(
"\t",
"\n",
"\r"),
" ", $labeljournal);
1800 $tab[] = $labeljournal;
1803 $tab[] = $line->piece_num;
1806 $tab[] = $date_creation;
1812 $line->label_compte = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_compte);
1819 $line->subledger_label = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->subledger_label);
1823 $tab[] = $line->doc_ref;
1826 $tab[] = $date_document;
1830 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1831 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1841 $line->lettering_code = str_replace(array(
"\t",
"\n",
"\r"),
" ", (
string) $line->lettering_code);
1842 $tab[] = $line->lettering_code;
1845 $tab[] = $date_lettering;
1848 $tab[] = $date_validation;
1851 $tab[] = $line->multicurrency_amount;
1854 $tab[] = $line->multicurrency_code;
1857 $tab[] = $date_limit_payment;
1861 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1862 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1866 $attachmentFileName =
'';
1867 if ($withAttachment == 1) {
1868 $attachmentFileKey = trim((
string) $line->piece_num);
1870 if (!isset($archiveFileList[$attachmentFileKey])) {
1872 $objectDirPath =
'';
1874 if ($line->doc_type ==
'customer_invoice') {
1875 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1876 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1878 } elseif ($line->doc_type ==
'expense_report') {
1879 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1880 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1882 } elseif ($line->doc_type ==
'supplier_invoice' && $invoice instanceof
FactureFournisseur) {
1883 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1884 '@phan-var-force FactureFournisseur $invoice';
1885 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1886 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1890 if ($objectDirPath && empty(
$conf->cache[
'archiveFileList_notfound'][$attachmentFileKey])) {
1891 $arrayofinclusion = array();
1893 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1895 $fileFoundPath =
'';
1896 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1898 if (!empty($fileFoundList)) {
1899 $attachmentFileNameTrunc = $line->doc_ref;
1901 foreach ($fileFoundList as $fileFound) {
1902 if (strstr($fileFound[
'name'], $objectFileName)) {
1905 if ($line->doc_type ==
'supplier_invoice') {
1906 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1909 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1912 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1913 if (file_exists($fileFoundPath)) {
1914 $archiveFileList[$attachmentFileKey] = array(
1915 'path' => $fileFoundPath,
1916 'name' => $attachmentFileNameTrunc.
'.pdf',
1924 if (empty($fileFoundPath)) {
1926 $conf->cache[
'archiveFileList_notfound'][$attachmentFileKey] = 1;
1931 if (isset($archiveFileList[$attachmentFileKey])) {
1932 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1936 $tab[] = $attachmentFileName;
1938 $output = implode($separator, $tab).$end_line;
1940 fwrite($exportFile, $output);
1947 return $archiveFileList;
1983 $tab[] =
"FW-Betrag";
1990 $output = implode($separator, $tab).$end_line;
1992 fwrite($exportFile, $output);
1998 $thisPieceAccountNr =
"";
1999 $aSize = count($objectLines);
2000 foreach ($objectLines as $aIndex => $line) {
2001 $sammelBuchung =
false;
2002 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
2003 $sammelBuchung =
true;
2004 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
2005 $sammelBuchung =
true;
2006 } elseif ($aIndex + 1 < $aSize
2007 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
2008 && $aIndex - 1 < $aSize
2009 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
2011 $sammelBuchung =
true;
2017 $tab[] = $line->piece_num;
2021 $tab[] = $date_document;
2026 if ($line->sens ==
'D') {
2034 if (empty($line->code_tiers)) {
2035 if ($line->piece_num == $thisPieceNum) {
2044 $tab[] = $this->separator;
2053 if ($sammelBuchung) {
2061 $tab[] = abs($line->debit - $line->credit);
2068 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
2072 if (strlen($line1) == 0) {
2076 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
2077 $line1 = $line1.
' / '.$line2;
2081 $tab[] =
'"'.self::toAnsi($line1).
'"';
2083 $tab[] =
'"'.self::toAnsi($line2).
'"';
2087 $tab[] = $this->separator;
2092 $output = implode($separator, $tab).$end_line;
2094 fwrite($exportFile, $output);
2099 if ($line->piece_num !== $thisPieceNum) {
2100 $thisPieceNum = $line->piece_num;
2101 $thisPieceAccountNr = $line->numero_compte;
2119 foreach ($objectLines as $line) {
2122 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2127 $type_enregistrement =
'E';
2128 $tab[] = $type_enregistrement;
2130 $tab[] = substr($line->code_journal, 0, 2);
2134 $tab[] = $line->piece_num;
2136 $tab[] = $date_document;
2138 $tab[] = $line->label_operation;
2140 $tab[] = $date_lim_reglement;
2142 if ($line->doc_type ==
'supplier_invoice') {
2143 if (($line->debit - $line->credit) > 0) {
2144 $nature_piece =
'AF';
2146 $nature_piece =
'FF';
2148 } elseif ($line->doc_type ==
'customer_invoice') {
2149 if (($line->debit - $line->credit) < 0) {
2150 $nature_piece =
'AC';
2152 $nature_piece =
'FC';
2157 $tab[] = $nature_piece;
2168 $racine_subledger_account =
'';
2171 $tab[] = $racine_subledger_account;
2173 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
2175 $tab[] = $line->sens;
2179 $tab[] = $date_creation;
2181 $tab[] = $line->lettering_code;
2183 $tab[] = $line->date_lettering;
2185 if (!empty($line->subledger_account)) {
2191 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2193 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2207 $tab[] = $line->doc_ref;
2235 $output = implode($separator, $tab).$end_line;
2237 fwrite($exportFile, $output);
2256 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2260 $last_codeinvoice =
'';
2262 foreach ($objectLines as $line) {
2264 if ($last_codeinvoice != $line->doc_ref) {
2266 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2267 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2268 $resql = $this->db->query($sql);
2270 if ($resql && $this->db->num_rows($resql) > 0) {
2271 $soc = $this->db->fetch_object($resql);
2273 $address = array(
'',
'',
'');
2274 if (strpos($soc->address,
"\n") !==
false) {
2275 $address = explode(
"\n", $soc->address);
2276 if (is_array($address) && count($address) > 0) {
2277 foreach ($address as $key => $data) {
2278 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2279 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2283 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2284 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2285 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2290 $type_enregistrement =
'C';
2292 $tab[] = $type_enregistrement;
2294 $tab[] = $soc->code_client;
2304 $tab[] = $address[0];
2306 $tab[] = $address[1];
2308 $tab[] = $address[2];
2312 $tab[] = substr($soc->town, 0, 40);
2316 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2318 $tab[] = $soc->phone;
2330 $tab[] = str_replace(
" ",
"", $soc->siret);
2388 $output = implode($separator, $tab).$end_line;
2390 fwrite($exportFile, $output);
2401 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2404 $type_enregistrement =
'E';
2405 $tab[] = $type_enregistrement;
2407 $tab[] = substr($line->code_journal, 0, 2);
2411 $tab[] = $line->piece_num;
2413 $tab[] = $date_document;
2415 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2417 $tab[] = $date_lim_reglement;
2419 if ($line->doc_type ==
'supplier_invoice') {
2420 if (($line->amount) < 0) {
2421 $nature_piece =
'AF';
2423 $nature_piece =
'FF';
2425 } elseif ($line->doc_type ==
'customer_invoice') {
2426 if (($line->amount) < 0) {
2427 $nature_piece =
'AC';
2429 $nature_piece =
'FC';
2434 $tab[] = $nature_piece;
2445 $racine_subledger_account =
'';
2448 $tab[] = $racine_subledger_account;
2450 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2452 $tab[] = $line->sens;
2456 $tab[] = $date_document;
2458 $tab[] = $line->lettering_code;
2460 $tab[] = $line->date_lettering;
2462 if (!empty($line->subledger_account)) {
2468 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2470 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2482 $tab[] = $line->doc_ref;
2516 $output = implode($separator, $tab).$end_line;
2518 fwrite($exportFile, $output);
2523 $last_codeinvoice = $line->doc_ref;
2537 $langs->load(
'compta');
2544 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2545 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2546 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2547 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2548 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2549 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2550 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2552 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2553 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2554 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2555 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2556 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2557 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2559 $output = implode($separator, $tab).$end_line;
2561 fwrite($exportFile, $output);
2566 foreach ($objectLines as $line) {
2571 $tab[] = $date_document;
2575 if (!empty($line->subledger_account)) {
2576 $account = $line->subledger_account;
2578 $account = $line->numero_compte;
2585 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2587 $tab[] =
price(abs($line->debit - $line->credit));
2588 $tab[] = $line->sens;
2596 $output = implode($separator, $tab).$end_line;
2598 fwrite($exportFile, $output);
2619 $invoices_infos = array();
2620 $supplier_invoices_infos = array();
2621 foreach ($objectLines as $line) {
2622 if ($line->debit == 0 && $line->credit == 0) {
2626 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2628 $invoice_ref = $line->doc_ref;
2631 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2632 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2633 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2634 if ($line->doc_type ==
'customer_invoice') {
2636 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2637 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2638 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2639 $resql = $this->db->query($sql);
2641 if ($obj = $this->db->fetch_object($resql)) {
2643 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2644 $invoice_ref = $obj->ref;
2645 $company_name = $obj->nom;
2650 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2651 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2652 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2653 $resql = $this->db->query($sql);
2655 if ($obj = $this->db->fetch_object($resql)) {
2657 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2658 $invoice_ref = $obj->ref;
2659 $company_name = $obj->nom;
2663 } elseif ($line->doc_type ==
'customer_invoice') {
2665 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2666 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2669 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2670 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2677 $tab[] = $date_document;
2678 $tab[] = substr($line->code_journal, 0, 4);
2680 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2689 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2691 $tab[] =
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1);
2695 $tab[] =
price2num(abs($line->debit - $line->credit));
2697 $tab[] = $line->sens;
2701 $tab[] = $date_echeance;
2703 $output = implode($separator, $tab).$end_line;
2705 fwrite($exportFile, $output);
2725 foreach ($objectLines as $line) {
2726 if ($line->debit == 0 && $line->credit == 0) {
2734 $tab[] = $date_document;
2735 $tab[] = substr($line->code_journal, 0, 4);
2736 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2742 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2743 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2744 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2745 $tab[] =
price2num(abs($line->debit - $line->credit));
2746 $tab[] = $line->sens;
2747 $tab[] = $date_document;
2752 $output = implode($separator, $tab).$end_line;
2754 fwrite($exportFile, $output);
2777 foreach ($objectLines as $line) {
2782 $tab[] = $line->piece_num;
2784 $tab[] = substr($date, 6, 4);
2785 $tab[] = substr($date, 3, 2);
2786 $tab[] = substr($date, 0, 2);
2787 $tab[] = $line->doc_ref;
2789 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2795 $numero_cpt_client =
'411';
2796 $numero_cpt_fourn =
'401';
2797 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2798 $numero_cpt_client .=
'0';
2799 $numero_cpt_fourn .=
'0';
2808 $nom_client = explode(
" - ", $line->label_operation);
2809 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2810 $tab[] =
price($line->debit);
2811 $tab[] =
price($line->credit);
2812 $tab[] =
price($line->montant);
2813 $tab[] = $line->code_journal;
2815 $output = implode($separator, $tab).$end_line;
2817 fwrite($exportFile, $output);
2831 public static function trunc($str, $size)
2833 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2843 public static function toAnsi($str, $size = -1)
2846 if ($retVal >= 0 && $size >= 0) {
2847 $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...
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)
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.