38require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
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';
51 public static $EXPORT_TYPE_CONFIGURABLE = 1;
52 public static $EXPORT_TYPE_AGIRIS = 10;
53 public static $EXPORT_TYPE_EBP = 15;
54 public static $EXPORT_TYPE_CEGID = 20;
55 public static $EXPORT_TYPE_COGILOG = 25;
56 public static $EXPORT_TYPE_COALA = 30;
57 public static $EXPORT_TYPE_BOB50 = 35;
58 public static $EXPORT_TYPE_CIEL = 40;
59 public static $EXPORT_TYPE_SAGE50_SWISS = 45;
60 public static $EXPORT_TYPE_CHARLEMAGNE = 50;
61 public static $EXPORT_TYPE_QUADRATUS = 60;
62 public static $EXPORT_TYPE_WINFIC = 70;
63 public static $EXPORT_TYPE_OPENCONCERTO = 100;
64 public static $EXPORT_TYPE_LDCOMPTA = 110;
65 public static $EXPORT_TYPE_LDCOMPTA10 = 120;
66 public static $EXPORT_TYPE_GESTIMUMV3 = 130;
67 public static $EXPORT_TYPE_GESTIMUMV5 = 135;
68 public static $EXPORT_TYPE_ISUITEEXPERT = 200;
70 public static $EXPORT_TYPE_FEC = 1000;
71 public static $EXPORT_TYPE_FEC2 = 1010;
81 public $errors = array();
87 public $separator =
'';
93 public $end_line =
'';
102 global $conf, $hookmanager;
105 $this->separator = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
108 $hookmanager->initHooks(array(
'accountancyexport'));
118 global $langs, $hookmanager;
120 $listofexporttypes = array(
121 self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans(
'Modelcsv_configurable'),
122 self::$EXPORT_TYPE_CEGID => $langs->trans(
'Modelcsv_CEGID'),
123 self::$EXPORT_TYPE_COALA => $langs->trans(
'Modelcsv_COALA'),
124 self::$EXPORT_TYPE_BOB50 => $langs->trans(
'Modelcsv_bob50'),
125 self::$EXPORT_TYPE_CIEL => $langs->trans(
'Modelcsv_ciel'),
126 self::$EXPORT_TYPE_QUADRATUS => $langs->trans(
'Modelcsv_quadratus'),
127 self::$EXPORT_TYPE_WINFIC => $langs->trans(
'Modelcsv_winfic'),
128 self::$EXPORT_TYPE_EBP => $langs->trans(
'Modelcsv_ebp'),
129 self::$EXPORT_TYPE_COGILOG => $langs->trans(
'Modelcsv_cogilog'),
130 self::$EXPORT_TYPE_AGIRIS => $langs->trans(
'Modelcsv_agiris'),
131 self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans(
'Modelcsv_openconcerto'),
132 self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans(
'Modelcsv_Sage50_Swiss'),
133 self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans(
'Modelcsv_charlemagne'),
134 self::$EXPORT_TYPE_LDCOMPTA => $langs->trans(
'Modelcsv_LDCompta'),
135 self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans(
'Modelcsv_LDCompta10'),
136 self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans(
'Modelcsv_Gestinumv3'),
137 self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans(
'Modelcsv_Gestinumv5'),
138 self::$EXPORT_TYPE_FEC => $langs->trans(
'Modelcsv_FEC'),
139 self::$EXPORT_TYPE_FEC2 => $langs->trans(
'Modelcsv_FEC2'),
140 self::$EXPORT_TYPE_ISUITEEXPERT =>
'Export iSuite Expert',
144 $parameters = array();
145 $reshook = $hookmanager->executeHooks(
'getType', $parameters, $listofexporttypes);
147 ksort($listofexporttypes, SORT_NUMERIC);
149 return $listofexporttypes;
161 self::$EXPORT_TYPE_CONFIGURABLE =>
'csv',
162 self::$EXPORT_TYPE_CEGID =>
'cegid',
163 self::$EXPORT_TYPE_COALA =>
'coala',
164 self::$EXPORT_TYPE_BOB50 =>
'bob50',
165 self::$EXPORT_TYPE_CIEL =>
'ciel',
166 self::$EXPORT_TYPE_QUADRATUS =>
'quadratus',
167 self::$EXPORT_TYPE_WINFIC =>
'winfic',
168 self::$EXPORT_TYPE_EBP =>
'ebp',
169 self::$EXPORT_TYPE_COGILOG =>
'cogilog',
170 self::$EXPORT_TYPE_AGIRIS =>
'agiris',
171 self::$EXPORT_TYPE_OPENCONCERTO =>
'openconcerto',
172 self::$EXPORT_TYPE_SAGE50_SWISS =>
'sage50ch',
173 self::$EXPORT_TYPE_CHARLEMAGNE =>
'charlemagne',
174 self::$EXPORT_TYPE_LDCOMPTA =>
'ldcompta',
175 self::$EXPORT_TYPE_LDCOMPTA10 =>
'ldcompta10',
176 self::$EXPORT_TYPE_GESTIMUMV3 =>
'gestimumv3',
177 self::$EXPORT_TYPE_GESTIMUMV5 =>
'gestimumv5',
178 self::$EXPORT_TYPE_FEC =>
'fec',
179 self::$EXPORT_TYPE_FEC2 =>
'fec2',
180 self::$EXPORT_TYPE_ISUITEEXPERT =>
'isuiteexpert',
184 $code = $formatcode[$type];
185 $parameters = array(
'type' => $type);
186 $reshook = $hookmanager->executeHooks(
'getFormatCode', $parameters, $code);
198 global $conf, $langs;
200 $exporttypes = array(
202 self::$EXPORT_TYPE_CONFIGURABLE => array(
203 'label' => $langs->trans(
'Modelcsv_configurable'),
205 'ACCOUNTING_EXPORT_SEPARATORCSV' =>
getDolGlobalString(
'ACCOUNTING_EXPORT_SEPARATORCSV',
','),
209 self::$EXPORT_TYPE_CEGID => array(
210 'label' => $langs->trans(
'Modelcsv_CEGID'),
212 self::$EXPORT_TYPE_COALA => array(
213 'label' => $langs->trans(
'Modelcsv_COALA'),
215 self::$EXPORT_TYPE_BOB50 => array(
216 'label' => $langs->trans(
'Modelcsv_bob50'),
218 self::$EXPORT_TYPE_CIEL => array(
219 'label' => $langs->trans(
'Modelcsv_ciel'),
220 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
222 self::$EXPORT_TYPE_QUADRATUS => array(
223 'label' => $langs->trans(
'Modelcsv_quadratus'),
224 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
226 self::$EXPORT_TYPE_WINFIC => array(
227 'label' => $langs->trans(
'Modelcsv_winfic'),
228 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
230 self::$EXPORT_TYPE_EBP => array(
231 'label' => $langs->trans(
'Modelcsv_ebp'),
233 self::$EXPORT_TYPE_COGILOG => array(
234 'label' => $langs->trans(
'Modelcsv_cogilog'),
236 self::$EXPORT_TYPE_AGIRIS => array(
237 'label' => $langs->trans(
'Modelcsv_agiris'),
239 self::$EXPORT_TYPE_OPENCONCERTO => array(
240 'label' => $langs->trans(
'Modelcsv_openconcerto'),
242 self::$EXPORT_TYPE_SAGE50_SWISS => array(
243 'label' => $langs->trans(
'Modelcsv_Sage50_Swiss'),
245 self::$EXPORT_TYPE_CHARLEMAGNE => array(
246 'label' => $langs->trans(
'Modelcsv_charlemagne'),
247 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
249 self::$EXPORT_TYPE_LDCOMPTA => array(
250 'label' => $langs->trans(
'Modelcsv_LDCompta'),
252 self::$EXPORT_TYPE_LDCOMPTA10 => array(
253 'label' => $langs->trans(
'Modelcsv_LDCompta10'),
255 self::$EXPORT_TYPE_GESTIMUMV3 => array(
256 'label' => $langs->trans(
'Modelcsv_Gestinumv3'),
257 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
259 self::$EXPORT_TYPE_GESTIMUMV5 => array(
260 'label' => $langs->trans(
'Modelcsv_Gestinumv5'),
261 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
263 self::$EXPORT_TYPE_FEC => array(
264 'label' => $langs->trans(
'Modelcsv_FEC'),
265 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
267 self::$EXPORT_TYPE_FEC2 => array(
268 'label' => $langs->trans(
'Modelcsv_FEC2'),
269 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
271 self::$EXPORT_TYPE_ISUITEEXPERT => array(
272 'label' =>
'iSuite Expert',
273 'ACCOUNTING_EXPORT_FORMAT' =>
'csv',
277 '1' => $langs->trans(
"Unix"),
278 '2' => $langs->trans(
"Windows")
281 'csv' => $langs->trans(
"csv"),
282 'txt' => $langs->trans(
"txt")
287 $parameters = array();
288 $reshook = $hookmanager->executeHooks(
'getTypeConfig', $parameters, $exporttypes);
303 switch ($formatexportset) {
304 case self::$EXPORT_TYPE_FEC:
305 $mime =
'text/tab-separated-values';
330 public function export(&$TData, $formatexportset, $withAttachment = 0, $downloadMode = 0, $outputMode = 0)
332 global $conf, $langs;
333 global $search_date_end;
336 $filename =
'general_ledger-'.$this->getFormatCode($formatexportset);
337 $type_export =
'general_ledger';
340 $completefilename =
'';
342 $exportFileName =
'';
343 $exportFilePath =
'';
344 $exportFileFullName =
'';
345 $downloadFileMimeType =
'';
346 $downloadFileFullName =
'';
347 $downloadFilePath =
'';
348 $archiveFullName =
'';
350 $archiveFileList = array();
351 if ($withAttachment == 1) {
352 if ($downloadMode == 0) {
355 if ($outputMode == 0) {
360 if (!extension_loaded(
'zip')) {
361 $langs->load(
'install');
362 $this->errors[] = $langs->trans(
'ErrorPHPDoesNotSupport',
'ZIP');
368 if ($downloadMode == 0) {
372 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
373 if ($outputMode == 1 || $outputMode == 2) {
374 if ($outputMode == 1) {
376 if (!empty($conf->accounting->multidir_temp[$conf->entity])) {
377 $outputDir = $conf->accounting->multidir_temp[$conf->entity];
379 $outputDir = $conf->accounting->dir_temp;
383 if (!empty($conf->accounting->multidir_output[$conf->entity])) {
384 $outputDir = $conf->accounting->multidir_output[$conf->entity];
386 $outputDir = $conf->accounting->dir_output;
390 $outputDir .=
'/export';
391 $outputDir .=
'/'.dol_sanitizePathName($formatexportset);
396 $this->errors[] = $langs->trans(
'ErrorCanNotCreateDir', $outputDir);
401 if ($outputDir !=
'') {
403 $langs->load(
'errors');
404 $this->errors[] = $langs->trans(
'ErrorDirNotFound', $outputDir);
408 if (!empty($completefilename)) {
410 $exportFileFullName = $completefilename;
411 $exportFileBaseName = basename($exportFileFullName);
412 $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME);
413 $exportFilePath = $outputDir .
'/' . $exportFileFullName;
414 $exportFile = fopen($exportFilePath,
'w');
416 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $exportFilePath);
420 if ($withAttachment == 1) {
421 $archiveFileList[0] = array(
422 'path' => $exportFilePath,
423 'name' => $exportFileFullName,
427 $archiveFullName = $exportFileName .
'.zip';
428 $archivePath = $outputDir .
'/' . $archiveFullName;
435 switch ($formatexportset) {
436 case self::$EXPORT_TYPE_CONFIGURABLE:
439 case self::$EXPORT_TYPE_CEGID:
442 case self::$EXPORT_TYPE_COALA:
445 case self::$EXPORT_TYPE_BOB50:
448 case self::$EXPORT_TYPE_CIEL:
451 case self::$EXPORT_TYPE_QUADRATUS:
452 $archiveFileList = $this->
exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment);
454 case self::$EXPORT_TYPE_WINFIC:
457 case self::$EXPORT_TYPE_EBP:
460 case self::$EXPORT_TYPE_COGILOG:
463 case self::$EXPORT_TYPE_AGIRIS:
466 case self::$EXPORT_TYPE_OPENCONCERTO:
469 case self::$EXPORT_TYPE_SAGE50_SWISS:
472 case self::$EXPORT_TYPE_CHARLEMAGNE:
475 case self::$EXPORT_TYPE_LDCOMPTA:
478 case self::$EXPORT_TYPE_LDCOMPTA10:
481 case self::$EXPORT_TYPE_GESTIMUMV3:
484 case self::$EXPORT_TYPE_GESTIMUMV5:
487 case self::$EXPORT_TYPE_FEC:
488 $archiveFileList = $this->
exportFEC($TData, $exportFile, $archiveFileList, $withAttachment);
490 case self::$EXPORT_TYPE_FEC2:
491 $archiveFileList = $this->
exportFEC2($TData, $exportFile, $archiveFileList, $withAttachment);
493 case self::$EXPORT_TYPE_ISUITEEXPERT:
498 $parameters = array(
'format' => $formatexportset);
500 $reshook = $hookmanager->executeHooks(
'export', $parameters, $TData);
502 $this->errors[] = $langs->trans(
'accountancy_error_modelnotfound');
508 if ($outputMode == 1 || $outputMode == 2) {
516 if ($withAttachment == 1) {
518 if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
520 $downloadFileMimeType =
'application/zip';
521 $downloadFileFullName = $archiveFullName;
522 $downloadFilePath = $archivePath;
525 $archive =
new ZipArchive();
526 $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
529 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $archivePath);
533 foreach ($archiveFileList as $archiveFileArr) {
534 $res = $archive->addFile($archiveFileArr[
'path'], $archiveFileArr[
'name']);
537 $this->errors[] = $langs->trans(
'ErrorArchiveAddFile', $archiveFileArr[
'name']);
551 if ($downloadMode == 1) {
552 if ($withAttachment == 0) {
554 if (!empty($exportFileFullName) && !empty($exportFilePath)) {
555 $downloadFileMimeType = $mimetype;
556 $downloadFileFullName = $exportFileFullName;
557 $downloadFilePath = $exportFilePath;
562 if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath)) {
563 header(
'Content-Type: ' . $downloadFileMimeType);
564 header(
'Content-Disposition: attachment; filename=' . $downloadFileFullName);
565 header(
'Cache-Control: Public, must-revalidate');
566 header(
'Pragma: public');
567 header(
'Content-Length: ' .
dol_filesize($downloadFilePath));
594 foreach ($objectLines as $line) {
599 $tab[] = $date_document;
600 $tab[] = $line->code_journal;
603 $tab[] = $line->sens;
604 $tab[] =
price2fec(abs($line->debit - $line->credit));
608 $output = implode($separator, $tab).$end_line;
610 fwrite($exportFile, $output);
630 foreach ($objectLines as $line) {
634 if ($line->doc_type ==
'customer_invoice') {
636 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
637 $invoice =
new Facture($this->db);
638 $invoice->fetch($line->fk_doc);
640 $refInvoice = $invoice->ref;
641 } elseif ($line->doc_type ==
'supplier_invoice') {
643 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture.class.php';
645 $invoice->fetch($line->fk_doc);
647 $refInvoice = $invoice->ref_supplier;
652 $tab[] = $line->code_journal;
653 $tab[] = $date_document;
654 $tab[] = $refInvoice;
655 if (empty($line->subledger_account)) {
661 $tab[] = $line->label_operation;
662 $tab[] = $date_document;
663 if ($line->sens ==
'D') {
664 $tab[] =
price($line->debit);
666 } elseif ($line->sens ==
'C') {
668 $tab[] =
price($line->credit);
670 $tab[] = $line->doc_ref;
671 $tab[] = $line->label_operation;
673 $output = implode($separator, $tab).$end_line;
675 fwrite($exportFile, $output);
695 foreach ($objectLines as $line) {
700 $tab[] = $date_document;
701 $tab[] = $line->code_journal;
703 $tab[] = $line->piece_num;
704 $tab[] = $line->doc_ref;
705 $tab[] =
price($line->debit);
706 $tab[] =
price($line->credit);
710 $output = implode($separator, $tab).$end_line;
712 fwrite($exportFile, $output);
732 foreach ($objectLines as $line) {
737 $tab[] = $line->piece_num;
738 $tab[] = $date_document;
740 if (empty($line->subledger_account)) {
744 if (substr($line->numero_compte, 0, 3) ==
'411') {
747 if (substr($line->numero_compte, 0, 3) ==
'401') {
753 $tab[] =
price($line->debit);
754 $tab[] =
price($line->credit);
755 $tab[] =
dol_trunc($line->label_operation, 32);
757 $output = implode($separator, $tab).$end_line;
759 fwrite($exportFile, $output);
787 foreach ($objectLines as $line) {
789 if (!empty($line->subledger_account)) {
794 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
798 $tab[] = str_pad($line->piece_num, 5);
799 $tab[] = str_pad(self::trunc($line->code_journal, 2), 2);
800 $tab[] = str_pad($date_document, 8,
' ', STR_PAD_LEFT);
801 $tab[] = str_pad($date_echeance, 8,
' ', STR_PAD_LEFT);
802 $tab[] = str_pad(self::trunc($line->doc_ref, 12), 12);
803 $tab[] = str_pad(self::trunc($code_compta, 11), 11);
804 $tab[] = str_pad(self::trunc(
dol_string_unaccent($line->doc_ref).dol_string_unaccent($line->label_operation), 25), 25);
805 $tab[] = str_pad(
price2fec(abs($line->debit - $line->credit)), 13,
' ', STR_PAD_LEFT);
806 $tab[] = str_pad($line->sens, 1);
807 $tab[] = str_repeat(
' ', 18);
811 $output = implode($tab).$end_line;
813 fwrite($exportFile, $output);
836 public function exportQuadratus($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
843 foreach ($objectLines as $line) {
847 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
848 $line->label_operation = str_replace(array(
"- ",
"…",
"..."),
"", $line->label_operation);
855 $line->subledger_label = str_replace(array(
"- ",
"…",
"..."),
"", $line->subledger_label);
858 $code_compta = $line->numero_compte;
859 if (!empty($line->subledger_account)) {
860 $code_compta = $line->subledger_account;
865 if (!empty($line->subledger_account)) {
866 $tab[
'type_ligne'] =
'C';
867 $tab[
'num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8);
868 $tab[
'lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30);
870 if ($line->doc_type ==
'customer_invoice') {
871 $tab[
'lib_alpha'] = strtoupper(str_pad(
'C'.self::trunc(
dol_string_unaccent($line->subledger_label), 6), 7));
872 $tab[
'filler'] = str_repeat(
' ', 52);
873 $tab[
'coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, 8), 8);
874 } elseif ($line->doc_type ==
'supplier_invoice') {
875 $tab[
'lib_alpha'] = strtoupper(str_pad(
'F'.self::trunc(
dol_string_unaccent($line->subledger_label), 6), 7));
876 $tab[
'filler'] = str_repeat(
' ', 52);
877 $tab[
'coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, 8), 8);
879 $tab[
'filler'] = str_repeat(
' ', 59);
880 $tab[
'coll_compte'] = str_pad(
' ', 8);
883 $tab[
'filler2'] = str_repeat(
' ', 110);
886 if ($line->doc_type ==
'customer_invoice') {
887 $tab[
'type_compte'] =
'C';
888 } elseif ($line->doc_type ==
'supplier_invoice') {
889 $tab[
'type_compte'] =
'F';
891 $tab[
'type_compte'] =
'G';
894 $tab[
'filler3'] = str_repeat(
' ', 235);
896 $tab[
'end_line'] = $end_line;
899 fwrite($exportFile, implode($tab));
906 $tab[
'type_ligne'] =
'M';
907 $tab[
'num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
908 $tab[
'code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
909 $tab[
'folio'] =
'000';
914 $tab[
'date_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
915 $tab[
'filler'] =
' ';
916 $tab[
'libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.
' '.$line->label_operation, 20), 20);
931 $tab[
'sens'] = $line->sens;
932 $tab[
'signe_montant'] =
'+';
935 $tab[
'montant'] = str_pad(abs(($line->debit - $line->credit) * 100), 12,
'0', STR_PAD_LEFT);
936 $tab[
'contrepartie'] = str_repeat(
' ', 8);
939 if (!empty($line->date_lim_reglement)) {
940 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%y');
942 $tab[
'date_echeance'] =
'000000';
947 $tab[
'lettrage'] = str_repeat(
' ', 2);
948 $tab[
'codestat'] = str_repeat(
' ', 3);
949 $tab[
'num_piece'] = str_pad(self::trunc($line->piece_num, 5), 5);
953 $tab[
'affaire'] = str_repeat(
' ', 10);
954 $tab[
'quantity1'] = str_repeat(
' ', 10);
955 $tab[
'num_piece2'] = str_pad(self::trunc($line->piece_num, 8), 8);
956 $tab[
'devis'] = str_pad($conf->currency, 3);
957 $tab[
'code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
958 $tab[
'filler3'] = str_repeat(
' ', 3);
966 $tab[
'libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
967 $tab[
'codetva'] = str_repeat(
' ', 2);
971 $tab[
'num_piece3'] = substr(self::trunc($line->doc_ref, 20), -10);
972 $tab[
'reserved'] = str_repeat(
' ', 10);
973 $tab[
'currency_amount'] = str_repeat(
' ', 13);
975 $attachmentFileName =
'';
976 if ($withAttachment == 1) {
977 $attachmentFileKey = trim($line->piece_num);
979 if (!isset($archiveFileList[$attachmentFileKey])) {
982 if ($line->doc_type ==
'customer_invoice') {
983 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
984 } elseif ($line->doc_type ==
'expense_report') {
985 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
986 } elseif ($line->doc_type ==
'supplier_invoice') {
987 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
989 $invoice->fetch($line->fk_doc);
990 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
991 $objectDirPath.=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
993 $arrayofinclusion = array();
995 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
996 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0,
true);
997 if (!empty($fileFoundList)) {
998 $attachmentFileNameTrunc = str_pad(self::trunc($line->piece_num, 8), 8,
'0', STR_PAD_LEFT);
999 foreach ($fileFoundList as $fileFound) {
1000 if (strstr($fileFound[
'name'], $objectFileName)) {
1003 if ($line->doc_type ==
'supplier_invoice') {
1004 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1007 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1010 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1011 if (file_exists($fileFoundPath)) {
1012 $archiveFileList[$attachmentFileKey] = array(
1013 'path' => $fileFoundPath,
1014 'name' => $attachmentFileNameTrunc.
'.pdf',
1023 if (isset($archiveFileList[$attachmentFileKey])) {
1024 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1028 $tab[
'attachment'] = $attachmentFileName;
1030 $tab[
'attachment'] = str_repeat(
' ', 12);
1032 $tab[
'filler4'] = str_repeat(
' ', 38);
1033 $tab[
'end_line'] = $end_line;
1036 fwrite($exportFile, implode($tab));
1038 print implode($tab);
1042 return $archiveFileList;
1064 foreach ($objectLines as $line) {
1065 $code_compta = $line->numero_compte;
1066 if (!empty($line->subledger_account)) {
1067 $code_compta = $line->subledger_account;
1072 $tab[
'code_journal'] = str_pad(
dol_trunc($line->code_journal, 2,
'right',
'UTF-8', 1), 2);
1077 $tab[
'date_operation'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1079 $tab[
'folio'] =
' 1';
1081 $tab[
'num_ecriture'] = str_pad(
dol_trunc($index, 6,
'right',
'UTF-8', 1), 6,
' ', STR_PAD_LEFT);
1083 $tab[
'jour_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
1085 $tab[
'num_compte'] = str_pad(
dol_trunc($code_compta, 6,
'right',
'UTF-8', 1), 6,
'0');
1087 if ($line->sens ==
'D') {
1088 $tab[
'montant_debit'] = str_pad(number_format($line->debit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1090 $tab[
'montant_crebit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1092 $tab[
'montant_debit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1094 $tab[
'montant_crebit'] = str_pad(number_format($line->credit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1099 $tab[
'lettrage'] = str_repeat(
dol_trunc($line->lettering_code, 2,
'left',
'UTF-8', 1), 2);
1101 $tab[
'code_piece'] = str_pad(
dol_trunc($line->piece_num, 5,
'left',
'UTF-8', 1), 5,
' ', STR_PAD_LEFT);
1103 $tab[
'code_stat'] = str_repeat(
' ', 4);
1105 if (!empty($line->date_lim_reglement)) {
1106 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%Y');
1108 $tab[
'date_echeance'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1111 $tab[
'monnaie'] =
'1';
1113 $tab[
'filler'] =
' ';
1115 $tab[
'ind_compteur'] =
' ';
1117 $tab[
'quantite'] =
'0,000000000';
1119 $tab[
'code_pointage'] = str_repeat(
' ', 2);
1121 $tab[
'end_line'] = $end_line;
1123 print implode(
'|', $tab);
1142 foreach ($objectLines as $line) {
1148 $tab[] = $date_document;
1149 $tab[] = $line->code_journal;
1150 if (empty($line->subledger_account)) {
1151 $tab[] = $line->numero_compte;
1153 $tab[] = $line->subledger_account;
1156 $tab[] =
'"'.dol_trunc($line->label_operation, 40,
'right',
'UTF-8', 1).
'"';
1157 $tab[] =
'"'.dol_trunc($line->piece_num, 15,
'right',
'UTF-8', 1).
'"';
1158 $tab[] =
price2num(abs($line->debit - $line->credit));
1159 $tab[] = $line->sens;
1160 $tab[] = $date_document;
1163 $output = implode($separator, $tab).$end_line;
1165 fwrite($exportFile, $output);
1185 foreach ($objectLines as $line) {
1190 $tab[] = $line->piece_num;
1192 $tab[] = $date_document;
1195 if (empty($line->subledger_account)) {
1204 $tab[] =
price($line->debit);
1205 $tab[] =
price($line->credit);
1206 $tab[] =
price(abs($line->debit - $line->credit));
1207 $tab[] = $line->sens;
1208 $tab[] = $line->lettering_code;
1209 $tab[] = $line->code_journal;
1211 $output = implode($separator, $tab).$end_line;
1213 fwrite($exportFile, $output);
1232 foreach ($objectLines as $line) {
1237 $tab[] = $date_document;
1238 $tab[] = $line->code_journal;
1239 if (empty($line->subledger_account)) {
1244 $tab[] = $line->doc_ref;
1245 $tab[] = $line->label_operation;
1246 $tab[] =
price($line->debit);
1247 $tab[] =
price($line->credit);
1249 $output = implode($separator, $tab).$end_line;
1251 fwrite($exportFile, $output);
1269 $separator = $this->separator;
1271 foreach ($objectLines as $line) {
1276 $tab[] = $line->piece_num;
1277 $tab[] = $date_document;
1278 $tab[] = $line->doc_ref;
1279 $tab[] = preg_match(
'/'.$separator.
'/', $line->label_operation) ?
"'".$line->label_operation.
"'" : $line->label_operation;
1284 $tab[] =
price2num($line->debit - $line->credit);
1285 $tab[] = $line->code_journal;
1287 $output = implode($separator, $tab).$this->end_line;
1289 fwrite($exportFile, $output);
1308 public function exportFEC($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1310 global $conf, $langs;
1316 $tab[] =
"JournalCode";
1317 $tab[] =
"JournalLib";
1318 $tab[] =
"EcritureNum";
1319 $tab[] =
"EcritureDate";
1320 $tab[] =
"CompteNum";
1321 $tab[] =
"CompteLib";
1322 $tab[] =
"CompAuxNum";
1323 $tab[] =
"CompAuxLib";
1324 $tab[] =
"PieceRef";
1325 $tab[] =
"PieceDate";
1326 $tab[] =
"EcritureLib";
1329 $tab[] =
"EcritureLet";
1331 $tab[] =
"ValidDate";
1332 $tab[] =
"Montantdevise";
1334 $tab[] =
"DateLimitReglmt";
1335 $tab[] =
"NumFacture";
1336 $tab[] =
"FichierFacture";
1338 $output = implode($separator, $tab).$end_line;
1340 fwrite($exportFile, $output);
1345 foreach ($objectLines as $line) {
1346 if ($line->debit == 0 && $line->credit == 0) {
1351 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1352 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1353 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1356 if ($line->doc_type ==
'customer_invoice') {
1358 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1359 $invoice =
new Facture($this->db);
1360 $invoice->fetch($line->fk_doc);
1362 $refInvoice = $invoice->ref;
1363 } elseif ($line->doc_type ==
'supplier_invoice') {
1365 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1367 $invoice->fetch($line->fk_doc);
1369 $refInvoice = $invoice->ref_supplier;
1375 $tab[] = $line->code_journal;
1380 $tab[] = $labeljournal;
1383 $tab[] = $line->piece_num;
1386 $tab[] = $date_document;
1401 $tab[] = $line->doc_ref;
1408 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1409 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1419 $tab[] = $line->lettering_code;
1422 $tab[] = $date_lettering;
1425 $tab[] = $date_validation;
1428 $tab[] = $line->multicurrency_amount;
1431 $tab[] = $line->multicurrency_code;
1434 $tab[] = $date_limit_payment;
1438 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1439 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1443 $attachmentFileName =
'';
1444 if ($withAttachment == 1) {
1445 $attachmentFileKey = trim($line->piece_num);
1447 if (!isset($archiveFileList[$attachmentFileKey])) {
1448 $objectDirPath =
'';
1450 if ($line->doc_type ==
'customer_invoice') {
1451 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1452 } elseif ($line->doc_type ==
'expense_report') {
1453 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1454 } elseif ($line->doc_type ==
'supplier_invoice') {
1455 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1456 $objectDirPath.=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1458 $arrayofinclusion = array();
1460 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1461 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0,
true);
1462 if (!empty($fileFoundList)) {
1463 $attachmentFileNameTrunc = $line->doc_ref;
1464 foreach ($fileFoundList as $fileFound) {
1465 if (strstr($fileFound[
'name'], $objectFileName)) {
1468 if ($line->doc_type ==
'supplier_invoice') {
1469 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1472 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1475 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1476 if (file_exists($fileFoundPath)) {
1477 $archiveFileList[$attachmentFileKey] = array(
1478 'path' => $fileFoundPath,
1479 'name' => $attachmentFileNameTrunc.
'.pdf',
1488 if (isset($archiveFileList[$attachmentFileKey])) {
1489 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1493 $tab[] = $attachmentFileName;
1495 $output = implode($separator, $tab).$end_line;
1497 fwrite($exportFile, $output);
1504 return $archiveFileList;
1519 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1521 global $conf, $langs;
1527 $tab[] =
"JournalCode";
1528 $tab[] =
"JournalLib";
1529 $tab[] =
"EcritureNum";
1530 $tab[] =
"EcritureDate";
1531 $tab[] =
"CompteNum";
1532 $tab[] =
"CompteLib";
1533 $tab[] =
"CompAuxNum";
1534 $tab[] =
"CompAuxLib";
1535 $tab[] =
"PieceRef";
1536 $tab[] =
"PieceDate";
1537 $tab[] =
"EcritureLib";
1540 $tab[] =
"EcritureLet";
1542 $tab[] =
"ValidDate";
1543 $tab[] =
"Montantdevise";
1545 $tab[] =
"DateLimitReglmt";
1546 $tab[] =
"NumFacture";
1547 $tab[] =
"FichierFacture";
1549 $output = implode($separator, $tab).$end_line;
1551 fwrite($exportFile, $output);
1556 foreach ($objectLines as $line) {
1557 if ($line->debit == 0 && $line->credit == 0) {
1562 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1563 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1564 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1567 if ($line->doc_type ==
'customer_invoice') {
1569 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1570 $invoice =
new Facture($this->db);
1571 $invoice->fetch($line->fk_doc);
1573 $refInvoice = $invoice->ref;
1574 } elseif ($line->doc_type ==
'supplier_invoice') {
1576 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1578 $invoice->fetch($line->fk_doc);
1580 $refInvoice = $invoice->ref_supplier;
1586 $tab[] = $line->code_journal;
1591 $tab[] = $labeljournal;
1594 $tab[] = $line->piece_num;
1597 $tab[] = $date_creation;
1612 $tab[] = $line->doc_ref;
1615 $tab[] = $date_document;
1619 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1620 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1630 $tab[] = $line->lettering_code;
1633 $tab[] = $date_lettering;
1636 $tab[] = $date_validation;
1639 $tab[] = $line->multicurrency_amount;
1642 $tab[] = $line->multicurrency_code;
1645 $tab[] = $date_limit_payment;
1649 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1650 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1654 $attachmentFileName =
'';
1655 if ($withAttachment == 1) {
1656 $attachmentFileKey = trim($line->piece_num);
1658 if (!isset($archiveFileList[$attachmentFileKey])) {
1659 $objectDirPath =
'';
1661 if ($line->doc_type ==
'customer_invoice') {
1662 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1663 } elseif ($line->doc_type ==
'expense_report') {
1664 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1665 } elseif ($line->doc_type ==
'supplier_invoice') {
1666 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1667 $objectDirPath.=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1669 $arrayofinclusion = array();
1671 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1672 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0,
true);
1673 if (!empty($fileFoundList)) {
1674 $attachmentFileNameTrunc = $line->doc_ref;
1675 foreach ($fileFoundList as $fileFound) {
1676 if (strstr($fileFound[
'name'], $objectFileName)) {
1679 if ($line->doc_type ==
'supplier_invoice') {
1680 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1683 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1686 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1687 if (file_exists($fileFoundPath)) {
1688 $archiveFileList[$attachmentFileKey] = array(
1689 'path' => $fileFoundPath,
1690 'name' => $attachmentFileNameTrunc.
'.pdf',
1699 if (isset($archiveFileList[$attachmentFileKey])) {
1700 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1704 $tab[] = $attachmentFileName;
1706 $output = implode($separator, $tab).$end_line;
1708 fwrite($exportFile, $output);
1715 return $archiveFileList;
1751 $tab[] =
"FW-Betrag";
1758 $output = implode($separator, $tab).$end_line;
1760 fwrite($exportFile, $output);
1766 $thisPieceAccountNr =
"";
1767 $aSize = count($objectLines);
1768 foreach ($objectLines as $aIndex => $line) {
1769 $sammelBuchung =
false;
1770 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1771 $sammelBuchung =
true;
1772 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1773 $sammelBuchung =
true;
1774 } elseif ($aIndex + 1 < $aSize
1775 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1776 && $aIndex - 1 < $aSize
1777 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1779 $sammelBuchung =
true;
1785 $tab[] = $line->piece_num;
1789 $tab[] = $date_document;
1794 if ($line->sens ==
'D') {
1802 if (empty($line->code_tiers)) {
1803 if ($line->piece_num == $thisPieceNum) {
1812 $tab[] = $this->separator;
1821 if ($sammelBuchung) {
1829 $tab[] = abs($line->debit - $line->credit);
1836 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
1840 if (strlen($line1) == 0) {
1844 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1845 $line1 = $line1.
' / '.$line2;
1849 $tab[] =
'"'.self::toAnsi($line1).
'"';
1851 $tab[] =
'"'.self::toAnsi($line2).
'"';
1855 $tab[] = $this->separator;
1860 $output = implode($separator, $tab).$end_line;
1862 fwrite($exportFile, $output);
1867 if ($line->piece_num !== $thisPieceNum) {
1868 $thisPieceNum = $line->piece_num;
1869 $thisPieceAccountNr = $line->numero_compte;
1887 foreach ($objectLines as $line) {
1890 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1895 $type_enregistrement =
'E';
1896 $tab[] = $type_enregistrement;
1898 $tab[] = substr($line->code_journal, 0, 2);
1902 $tab[] = $line->piece_num;
1904 $tab[] = $date_document;
1906 $tab[] = $line->label_operation;
1908 $tab[] = $date_lim_reglement;
1910 if ($line->doc_type ==
'supplier_invoice') {
1911 if (($line->debit - $line->credit) > 0) {
1912 $nature_piece =
'AF';
1914 $nature_piece =
'FF';
1916 } elseif ($line->doc_type ==
'customer_invoice') {
1917 if (($line->debit - $line->credit) < 0) {
1918 $nature_piece =
'AC';
1920 $nature_piece =
'FC';
1925 $tab[] = $nature_piece;
1936 $racine_subledger_account =
'';
1939 $tab[] = $racine_subledger_account;
1941 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
1943 $tab[] = $line->sens;
1947 $tab[] = $date_creation;
1949 $tab[] = $line->lettering_code;
1951 $tab[] = $line->date_lettering;
1953 if (!empty($line->subledger_account)) {
1959 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
1961 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
1975 $tab[] = $line->doc_ref;
2003 $output = implode($separator, $tab).$end_line;
2005 fwrite($exportFile, $output);
2024 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2028 $last_codeinvoice =
'';
2030 foreach ($objectLines as $line) {
2032 if ($last_codeinvoice != $line->doc_ref) {
2034 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2035 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2036 $resql = $this->db->query($sql);
2038 if ($resql && $this->db->num_rows($resql) > 0) {
2039 $soc = $this->db->fetch_object($resql);
2041 $address = array(
'',
'',
'');
2042 if (strpos($soc->address,
"\n") !==
false) {
2043 $address = explode(
"\n", $soc->address);
2044 if (is_array($address) && count($address) > 0) {
2045 foreach ($address as $key => $data) {
2046 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2047 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2051 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2052 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2053 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2058 $type_enregistrement =
'C';
2060 $tab[] = $type_enregistrement;
2062 $tab[] = $soc->code_client;
2072 $tab[] = $address[0];
2074 $tab[] = $address[1];
2076 $tab[] = $address[2];
2080 $tab[] = substr($soc->town, 0, 40);
2084 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2086 $tab[] = $soc->phone;
2098 $tab[] = str_replace(
" ",
"", $soc->siret);
2156 $output = implode($separator, $tab).$end_line;
2158 fwrite($exportFile, $output);
2169 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2172 $type_enregistrement =
'E';
2173 $tab[] = $type_enregistrement;
2175 $tab[] = substr($line->code_journal, 0, 2);
2179 $tab[] = $line->piece_num;
2181 $tab[] = $date_document;
2183 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2185 $tab[] = $date_lim_reglement;
2187 if ($line->doc_type ==
'supplier_invoice') {
2188 if (($line->amount) < 0) {
2189 $nature_piece =
'AF';
2191 $nature_piece =
'FF';
2193 } elseif ($line->doc_type ==
'customer_invoice') {
2194 if (($line->amount) < 0) {
2195 $nature_piece =
'AC';
2197 $nature_piece =
'FC';
2202 $tab[] = $nature_piece;
2213 $racine_subledger_account =
'';
2216 $tab[] = $racine_subledger_account;
2218 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2220 $tab[] = $line->sens;
2224 $tab[] = $date_document;
2226 $tab[] = $line->lettering_code;
2228 $tab[] = $line->date_lettering;
2230 if (!empty($line->subledger_account)) {
2236 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2238 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2250 $tab[] = $line->doc_ref;
2284 $output = implode($separator, $tab).$end_line;
2286 fwrite($exportFile, $output);
2291 $last_codeinvoice = $line->doc_ref;
2305 $langs->load(
'compta');
2312 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2313 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2314 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2315 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2316 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2317 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2318 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2320 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2321 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2322 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2323 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2324 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2325 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2327 $output = implode($separator, $tab).$end_line;
2329 fwrite($exportFile, $output);
2334 foreach ($objectLines as $line) {
2339 $tab[] = $date_document;
2343 if (!empty($line->subledger_account)) {
2344 $account = $line->subledger_account;
2346 $account = $line->numero_compte;
2353 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2355 $tab[] =
price(abs($line->debit - $line->credit));
2356 $tab[] = $line->sens;
2364 $output = implode($separator, $tab).$end_line;
2366 fwrite($exportFile, $output);
2387 $invoices_infos = array();
2388 $supplier_invoices_infos = array();
2389 foreach ($objectLines as $line) {
2390 if ($line->debit == 0 && $line->credit == 0) {
2394 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2396 $invoice_ref = $line->doc_ref;
2399 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2400 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2401 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2402 if ($line->doc_type ==
'customer_invoice') {
2404 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2405 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2406 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2407 $resql = $this->db->query($sql);
2409 if ($obj = $this->db->fetch_object($resql)) {
2411 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2412 $invoice_ref = $obj->ref;
2413 $company_name = $obj->nom;
2418 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2419 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2420 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2421 $resql = $this->db->query($sql);
2423 if ($obj = $this->db->fetch_object($resql)) {
2425 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2426 $invoice_ref = $obj->ref;
2427 $company_name = $obj->nom;
2431 } elseif ($line->doc_type ==
'customer_invoice') {
2433 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2434 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2437 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2438 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2445 $tab[] = $date_document;
2446 $tab[] = substr($line->code_journal, 0, 4);
2448 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2457 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2459 $tab[] =
dol_trunc(str_replace(
'"',
'', $line->piece_num), 10,
'right',
'UTF-8', 1);
2463 $tab[] =
price2num(abs($line->debit - $line->credit));
2465 $tab[] = $line->sens;
2469 $tab[] = $date_echeance;
2471 $output = implode($separator, $tab).$end_line;
2473 fwrite($exportFile, $output);
2493 foreach ($objectLines as $line) {
2494 if ($line->debit == 0 && $line->credit == 0) {
2502 $tab[] = $date_document;
2503 $tab[] = substr($line->code_journal, 0, 4);
2504 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2510 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2511 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2512 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2513 $tab[] =
price2num(abs($line->debit - $line->credit));
2514 $tab[] = $line->sens;
2515 $tab[] = $date_document;
2520 $output = implode($separator, $tab).$end_line;
2522 fwrite($exportFile, $output);
2545 foreach ($objectLines as $line) {
2550 $tab[] = $line->piece_num;
2552 $tab[] = substr($date, 6, 4);
2553 $tab[] = substr($date, 3, 2);
2554 $tab[] = substr($date, 0, 2);
2555 $tab[] = $line->doc_ref;
2557 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2563 $numero_cpt_client =
'411';
2564 $numero_cpt_fourn =
'401';
2565 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2566 $numero_cpt_client .=
'0';
2567 $numero_cpt_fourn .=
'0';
2576 $nom_client = explode(
" - ", $line->label_operation);
2577 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2578 $tab[] =
price($line->debit);
2579 $tab[] =
price($line->credit);
2580 $tab[] =
price($line->montant);
2581 $tab[] = $line->code_journal;
2583 $output = implode($separator, $tab).$end_line;
2585 fwrite($exportFile, $output);
2599 public static function trunc($str, $size)
2601 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2611 public static function toAnsi($str, $size = -1)
2614 if ($retVal >= 0 && $size >= 0) {
2615 $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 type 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....
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.
export(&$TData, $formatexportset, $withAttachment=0, $downloadMode=0, $outputMode=0)
Function who chose which export to use with the default config, and make the export into a file.
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 ...
static toAnsi($str, $size=-1)
toAnsi
getType()
Array with all export type available (key + label)
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=0, $outputlangs='', $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($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_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_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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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 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.