53 public static $EXPORT_TYPE_CONFIGURABLE = 1;
55 public static $EXPORT_TYPE_AGIRIS = 10;
57 public static $EXPORT_TYPE_EBP = 15;
59 public static $EXPORT_TYPE_CEGID = 20;
61 public static $EXPORT_TYPE_COGILOG = 25;
63 public static $EXPORT_TYPE_COALA = 30;
65 public static $EXPORT_TYPE_BOB50 = 35;
67 public static $EXPORT_TYPE_CIEL = 40;
69 public static $EXPORT_TYPE_SAGE50_SWISS = 45;
71 public static $EXPORT_TYPE_CHARLEMAGNE = 50;
73 public static $EXPORT_TYPE_QUADRATUS = 60;
75 public static $EXPORT_TYPE_WINFIC = 70;
77 public static $EXPORT_TYPE_OPENCONCERTO = 100;
79 public static $EXPORT_TYPE_LDCOMPTA = 110;
81 public static $EXPORT_TYPE_LDCOMPTA10 = 120;
83 public static $EXPORT_TYPE_GESTIMUMV3 = 130;
85 public static $EXPORT_TYPE_GESTIMUMV5 = 135;
87 public static $EXPORT_TYPE_ISUITEEXPERT = 200;
90 public static $EXPORT_TYPE_FEC = 1000;
92 public static $EXPORT_TYPE_FEC2 = 1010;
102 public $errors = array();
107 public $separator =
'';
112 public $end_line =
'';
117 public $generatedfiledata = array();
127 global
$conf, $hookmanager;
133 $hookmanager->initHooks(array(
'accountancyexport'));
144 global $langs, $hookmanager;
146 $listofspecialformatexport = array(
147 self::$EXPORT_TYPE_CEGID => $langs->trans(
'Modelcsv_CEGID'),
148 self::$EXPORT_TYPE_COALA => $langs->trans(
'Modelcsv_COALA'),
149 self::$EXPORT_TYPE_BOB50 => $langs->trans(
'Modelcsv_bob50'),
150 self::$EXPORT_TYPE_CIEL => $langs->trans(
'Modelcsv_ciel'),
151 self::$EXPORT_TYPE_QUADRATUS => $langs->trans(
'Modelcsv_quadratus'),
152 self::$EXPORT_TYPE_WINFIC => $langs->trans(
'Modelcsv_winfic'),
153 self::$EXPORT_TYPE_EBP => $langs->trans(
'Modelcsv_ebp'),
154 self::$EXPORT_TYPE_COGILOG => $langs->trans(
'Modelcsv_cogilog'),
155 self::$EXPORT_TYPE_AGIRIS => $langs->trans(
'Modelcsv_agiris'),
156 self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans(
'Modelcsv_openconcerto'),
157 self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans(
'Modelcsv_Sage50_Swiss'),
158 self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans(
'Modelcsv_charlemagne'),
159 self::$EXPORT_TYPE_LDCOMPTA => $langs->trans(
'Modelcsv_LDCompta'),
160 self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans(
'Modelcsv_LDCompta10'),
161 self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans(
'Modelcsv_Gestinumv3'),
162 self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans(
'Modelcsv_Gestinumv5'),
163 self::$EXPORT_TYPE_ISUITEEXPERT =>
'Export iSuite Expert',
166 $listofgenericformatexport = array(
167 self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans(
'Modelcsv_configurable'),
168 self::$EXPORT_TYPE_FEC => $langs->trans(
'Modelcsv_FEC'),
169 self::$EXPORT_TYPE_FEC2 => $langs->trans(
'Modelcsv_FEC2'),
173 $listofexporttypes = $listofgenericformatexport + $listofspecialformatexport;
174 ksort($listofexporttypes, SORT_NUMERIC);
176 ksort($listofspecialformatexport, SORT_NUMERIC);
177 $listofexporttypes = array();
179 foreach ($listofgenericformatexport as $key => $val) {
181 $listofexporttypes[$key] = array(
'id' => $key,
'label' => $val,
'position' => $i);
183 $listofexporttypes[
'separator_'.$i] = array(
'id' => 0,
'label' =>
'----------------',
'position' => $i,
'disabled' =>
'disabled');
184 foreach ($listofspecialformatexport as $key => $val) {
186 $listofexporttypes[$key] = array(
'id' => $key,
'label' => $val,
'position' => $i);
191 $parameters = array();
192 $reshook = $hookmanager->executeHooks(
'getType', $parameters, $listofexporttypes);
194 return $listofexporttypes;
206 self::$EXPORT_TYPE_CONFIGURABLE =>
'csv',
207 self::$EXPORT_TYPE_CEGID =>
'cegid',
208 self::$EXPORT_TYPE_COALA =>
'coala',
209 self::$EXPORT_TYPE_BOB50 =>
'bob50',
210 self::$EXPORT_TYPE_CIEL =>
'ciel',
211 self::$EXPORT_TYPE_QUADRATUS =>
'quadratus',
212 self::$EXPORT_TYPE_WINFIC =>
'winfic',
213 self::$EXPORT_TYPE_EBP =>
'ebp',
214 self::$EXPORT_TYPE_COGILOG =>
'cogilog',
215 self::$EXPORT_TYPE_AGIRIS =>
'agiris',
216 self::$EXPORT_TYPE_OPENCONCERTO =>
'openconcerto',
217 self::$EXPORT_TYPE_SAGE50_SWISS =>
'sage50ch',
218 self::$EXPORT_TYPE_CHARLEMAGNE =>
'charlemagne',
219 self::$EXPORT_TYPE_LDCOMPTA =>
'ldcompta',
220 self::$EXPORT_TYPE_LDCOMPTA10 =>
'ldcompta10',
221 self::$EXPORT_TYPE_GESTIMUMV3 =>
'gestimumv3',
222 self::$EXPORT_TYPE_GESTIMUMV5 =>
'gestimumv5',
223 self::$EXPORT_TYPE_FEC =>
'fec',
224 self::$EXPORT_TYPE_FEC2 =>
'fec2',
225 self::$EXPORT_TYPE_ISUITEEXPERT =>
'isuiteexpert',
229 $code = $formatcode[$type] ??
'';
230 $parameters = array(
'type' => $type);
231 $reshook = $hookmanager->executeHooks(
'getFormatCode', $parameters, $code);
245 $exporttypes = array(
247 self::$EXPORT_TYPE_CONFIGURABLE => array(
248 'label' => $langs->trans(
'Modelcsv_configurable'),
250 'ACCOUNTING_EXPORT_SEPARATORCSV' =>
getDolGlobalString(
'ACCOUNTING_EXPORT_SEPARATORCSV',
','),
254 self::$EXPORT_TYPE_CEGID => array(
255 'label' => $langs->trans(
'Modelcsv_CEGID'),
257 self::$EXPORT_TYPE_COALA => array(
258 'label' => $langs->trans(
'Modelcsv_COALA'),
260 self::$EXPORT_TYPE_BOB50 => array(
261 'label' => $langs->trans(
'Modelcsv_bob50'),
263 self::$EXPORT_TYPE_CIEL => array(
264 'label' => $langs->trans(
'Modelcsv_ciel'),
265 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
267 self::$EXPORT_TYPE_QUADRATUS => array(
268 'label' => $langs->trans(
'Modelcsv_quadratus'),
269 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
271 self::$EXPORT_TYPE_WINFIC => array(
272 'label' => $langs->trans(
'Modelcsv_winfic'),
273 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
275 self::$EXPORT_TYPE_EBP => array(
276 'label' => $langs->trans(
'Modelcsv_ebp'),
278 self::$EXPORT_TYPE_COGILOG => array(
279 'label' => $langs->trans(
'Modelcsv_cogilog'),
281 self::$EXPORT_TYPE_AGIRIS => array(
282 'label' => $langs->trans(
'Modelcsv_agiris'),
284 self::$EXPORT_TYPE_OPENCONCERTO => array(
285 'label' => $langs->trans(
'Modelcsv_openconcerto'),
287 self::$EXPORT_TYPE_SAGE50_SWISS => array(
288 'label' => $langs->trans(
'Modelcsv_Sage50_Swiss'),
290 self::$EXPORT_TYPE_CHARLEMAGNE => array(
291 'label' => $langs->trans(
'Modelcsv_charlemagne'),
292 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
294 self::$EXPORT_TYPE_LDCOMPTA => array(
295 'label' => $langs->trans(
'Modelcsv_LDCompta'),
297 self::$EXPORT_TYPE_LDCOMPTA10 => array(
298 'label' => $langs->trans(
'Modelcsv_LDCompta10'),
300 self::$EXPORT_TYPE_GESTIMUMV3 => array(
301 'label' => $langs->trans(
'Modelcsv_Gestinumv3'),
302 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
304 self::$EXPORT_TYPE_GESTIMUMV5 => array(
305 'label' => $langs->trans(
'Modelcsv_Gestinumv5'),
306 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
308 self::$EXPORT_TYPE_FEC => array(
309 'label' => $langs->trans(
'Modelcsv_FEC'),
310 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
312 self::$EXPORT_TYPE_FEC2 => array(
313 'label' => $langs->trans(
'Modelcsv_FEC2'),
314 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
316 self::$EXPORT_TYPE_ISUITEEXPERT => array(
317 'label' =>
'iSuite Expert',
318 'ACCOUNTING_EXPORT_FORMAT' =>
'csv',
322 '1' => $langs->trans(
"Unix"),
323 '2' => $langs->trans(
"Windows")
326 'csv' => $langs->trans(
"csv"),
327 'txt' => $langs->trans(
"txt")
332 $parameters = array();
333 $reshook = $hookmanager->executeHooks(
'getTypeConfig', $parameters, $exporttypes);
346 switch ($formatexportset) {
347 case self::$EXPORT_TYPE_FEC:
348 $mime =
'text/tab-separated-values';
375 public function export(&$TData, $formatexportset, $withAttachment = 0, $downloadMode = 1, $outputMode = 1, $noouput = 1)
377 global $db,
$conf, $langs;
378 global $search_date_end;
381 $filename =
'general_ledger-'.$this->getFormatCode($formatexportset);
382 $type_export =
'general_ledger';
384 $completefilename =
'';
386 $exportFileName =
'';
387 $exportFilePath =
'';
388 $exportFileFullName =
'';
389 $downloadFileMimeType =
'';
390 $downloadFileFullName =
'';
391 $downloadFilePath =
'';
392 $archiveFullName =
'';
394 $archiveFileList = array();
395 if ($withAttachment == 1) {
396 if ($downloadMode == 0) {
399 if ($outputMode == 0) {
404 if (!extension_loaded(
'zip')) {
405 $langs->load(
'install');
406 $this->errors[] = $langs->trans(
'ErrorPHPDoesNotSupport',
'ZIP');
412 if ($downloadMode == 0) {
417 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
419 if ($outputMode == 1 || $outputMode == 2) {
420 if ($outputMode == 1) {
422 if (!empty(
$conf->accounting->multidir_temp[
$conf->entity])) {
423 $outputDir =
$conf->accounting->multidir_temp[
$conf->entity];
425 $outputDir =
$conf->accounting->dir_temp;
429 if (!empty(
$conf->accounting->multidir_output[
$conf->entity])) {
430 $outputDir =
$conf->accounting->multidir_output[
$conf->entity];
432 $outputDir =
$conf->accounting->dir_output;
436 $outputDir .=
'/export';
437 $outputDir .=
'/'.dol_sanitizePathName((
string) $formatexportset);
442 $this->errors[] = $langs->trans(
'ErrorCanNotCreateDir', $outputDir);
447 if ($outputDir !=
'') {
449 $langs->load(
'errors');
450 $this->errors[] = $langs->trans(
'ErrorDirNotFound', $outputDir);
454 if (!empty($completefilename)) {
456 $exportFileFullName = $completefilename;
457 $exportFileBaseName = basename($exportFileFullName);
458 $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME);
459 $exportFilePath = $outputDir .
'/' . $exportFileFullName;
460 $exportFile = fopen($exportFilePath,
'w');
462 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $exportFilePath);
466 if ($withAttachment == 1) {
467 $archiveFileList[0] = array(
468 'path' => $exportFilePath,
469 'name' => $exportFileFullName,
473 $archiveFullName = $exportFileName .
'.zip';
474 $archivePath = $outputDir .
'/' . $archiveFullName;
481 switch ($formatexportset) {
482 case self::$EXPORT_TYPE_CONFIGURABLE:
485 case self::$EXPORT_TYPE_CEGID:
488 case self::$EXPORT_TYPE_COALA:
491 case self::$EXPORT_TYPE_BOB50:
494 case self::$EXPORT_TYPE_CIEL:
497 case self::$EXPORT_TYPE_QUADRATUS:
498 $archiveFileList = $this->
exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment);
500 case self::$EXPORT_TYPE_WINFIC:
503 case self::$EXPORT_TYPE_EBP:
506 case self::$EXPORT_TYPE_COGILOG:
509 case self::$EXPORT_TYPE_AGIRIS:
512 case self::$EXPORT_TYPE_OPENCONCERTO:
515 case self::$EXPORT_TYPE_SAGE50_SWISS:
518 case self::$EXPORT_TYPE_CHARLEMAGNE:
521 case self::$EXPORT_TYPE_LDCOMPTA:
524 case self::$EXPORT_TYPE_LDCOMPTA10:
527 case self::$EXPORT_TYPE_GESTIMUMV3:
530 case self::$EXPORT_TYPE_GESTIMUMV5:
533 case self::$EXPORT_TYPE_FEC:
534 $archiveFileList = $this->exportFEC($TData, $exportFile, $archiveFileList, $withAttachment);
536 case self::$EXPORT_TYPE_FEC2:
537 $archiveFileList = $this->exportFEC2($TData, $exportFile, $archiveFileList, $withAttachment);
539 case self::$EXPORT_TYPE_ISUITEEXPERT:
544 $parameters = array(
'format' => $formatexportset,
'exportFile' => $exportFile);
546 $reshook = $hookmanager->executeHooks(
'export', $parameters, $TData);
548 $this->errors[] = $langs->trans(
'accountancy_error_modelnotfound');
555 if ($outputMode == 1 || $outputMode == 2) {
563 if ($withAttachment == 1) {
565 if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
567 $downloadFileMimeType =
'application/zip';
568 $downloadFileFullName = $archiveFullName;
569 $downloadFilePath = $archivePath;
572 $archive =
new ZipArchive();
573 $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
576 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $archivePath);
580 foreach ($archiveFileList as $archiveFileArr) {
581 $res = $archive->addFile($archiveFileArr[
'path'], $archiveFileArr[
'name']);
584 $this->errors[] = $langs->trans(
'ErrorArchiveAddFile', $archiveFileArr[
'name']);
598 if ($downloadMode == 1) {
599 if ($withAttachment == 0) {
601 if (!empty($exportFileFullName) && !empty($exportFilePath)) {
602 $downloadFileMimeType = $mimetype;
603 $downloadFileFullName = $exportFileFullName;
604 $downloadFilePath = $exportFilePath;
609 if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath) && empty($noouput)) {
612 header(
'Content-Type: ' . $downloadFileMimeType);
613 header(
'Content-Disposition: attachment; filename=' . $downloadFileFullName);
614 header(
'Cache-Control: Public, must-revalidate');
615 header(
'Pragma: public');
616 header(
'Content-Length: ' .
dol_filesize($downloadFilePath));
621 $this->generatedfiledata = array(
'downloadFilePath' => $downloadFilePath,
'downloadFileMimeType' => $downloadFileMimeType,
'downloadFileFullName' => $downloadFileFullName);
646 foreach ($objectLines as $line) {
651 $tab[] = $date_document;
652 $tab[] = $line->code_journal;
655 $tab[] = $line->sens;
656 $tab[] =
price2fec(abs($line->debit - $line->credit));
660 $output = implode($separator, $tab).$end_line;
662 fwrite($exportFile, $output);
682 foreach ($objectLines as $line) {
686 if ($line->doc_type ==
'customer_invoice') {
688 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
689 $invoice =
new Facture($this->db);
690 $invoice->fetch($line->fk_doc);
692 $refInvoice = $invoice->ref;
693 } elseif ($line->doc_type ==
'supplier_invoice') {
695 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture.class.php';
697 $invoice->fetch($line->fk_doc);
699 $refInvoice = $invoice->ref_supplier;
704 $tab[] = $line->code_journal;
705 $tab[] = $date_document;
706 $tab[] = $refInvoice;
707 if (empty($line->subledger_account)) {
713 $tab[] = $line->label_operation;
714 $tab[] = $date_document;
715 if ($line->sens ==
'D') {
716 $tab[] =
price($line->debit);
718 } elseif ($line->sens ==
'C') {
720 $tab[] =
price($line->credit);
722 $tab[] = $line->doc_ref;
723 $tab[] = $line->label_operation;
725 $output = implode($separator, $tab).$end_line;
727 fwrite($exportFile, $output);
747 foreach ($objectLines as $line) {
752 $tab[] = $date_document;
753 $tab[] = $line->code_journal;
755 $tab[] = $line->piece_num;
756 $tab[] = $line->doc_ref;
757 $tab[] =
price($line->debit);
758 $tab[] =
price($line->credit);
762 $output = implode($separator, $tab).$end_line;
764 fwrite($exportFile, $output);
784 foreach ($objectLines as $line) {
789 $tab[] = $line->piece_num;
790 $tab[] = $date_document;
792 if (empty($line->subledger_account)) {
796 if (substr($line->numero_compte, 0, 3) ==
'411') {
799 if (substr($line->numero_compte, 0, 3) ==
'401') {
805 $tab[] =
price($line->debit);
806 $tab[] =
price($line->credit);
807 $tab[] =
dol_trunc($line->label_operation, 32);
809 $output = implode($separator, $tab).$end_line;
811 fwrite($exportFile, $output);
839 foreach ($objectLines as $line) {
841 if (!empty($line->subledger_account)) {
846 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
850 $tab[] = str_pad((
string) $line->piece_num, 5);
851 $tab[] = str_pad(self::trunc($line->code_journal, 2), 2);
852 $tab[] = str_pad($date_document, 8,
' ', STR_PAD_LEFT);
853 $tab[] = str_pad($date_echeance, 8,
' ', STR_PAD_LEFT);
854 $tab[] = str_pad(self::trunc($line->doc_ref, 12), 12);
855 $tab[] = str_pad(self::trunc($code_compta, 11), 11);
856 $tab[] = str_pad(self::trunc(
dol_string_unaccent($line->doc_ref).dol_string_unaccent($line->label_operation), 25), 25);
857 $tab[] = str_pad(
price2fec(abs($line->debit - $line->credit)), 13,
' ', STR_PAD_LEFT);
858 $tab[] = str_pad($line->sens, 1);
859 $tab[] = str_repeat(
' ', 18);
863 $output = implode($tab).$end_line;
865 fwrite($exportFile, $output);
888 public function exportQuadratus($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
895 foreach ($objectLines as $line) {
899 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
900 $line->label_operation = str_replace(array(
"- ",
"…",
"..."),
"", $line->label_operation);
907 $line->subledger_label = str_replace(array(
"- ",
"…",
"..."),
"", $line->subledger_label);
910 $code_compta = $line->numero_compte;
911 if (!empty($line->subledger_account)) {
912 $code_compta = $line->subledger_account;
917 if (!empty($line->subledger_account)) {
918 $tab[
'type_ligne'] =
'C';
919 $tab[
'num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8);
920 $tab[
'lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30);
922 if ($line->doc_type ==
'customer_invoice') {
923 $tab[
'lib_alpha'] = strtoupper(str_pad(
'C'.self::trunc(
dol_string_unaccent($line->subledger_label), 6), 7));
924 $tab[
'filler'] = str_repeat(
' ', 52);
925 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'), 8), 8);
926 } elseif ($line->doc_type ==
'supplier_invoice') {
927 $tab[
'lib_alpha'] = strtoupper(str_pad(
'F'.self::trunc(
dol_string_unaccent($line->subledger_label), 6), 7));
928 $tab[
'filler'] = str_repeat(
' ', 52);
929 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'), 8), 8);
931 $tab[
'filler'] = str_repeat(
' ', 59);
932 $tab[
'coll_compte'] = str_pad(
' ', 8);
935 $tab[
'filler2'] = str_repeat(
' ', 110);
938 if ($line->doc_type ==
'customer_invoice') {
939 $tab[
'type_compte'] =
'C';
940 } elseif ($line->doc_type ==
'supplier_invoice') {
941 $tab[
'type_compte'] =
'F';
943 $tab[
'type_compte'] =
'G';
946 $tab[
'filler3'] = str_repeat(
' ', 235);
948 $tab[
'end_line'] = $end_line;
951 fwrite($exportFile, implode($tab));
958 $tab[
'type_ligne'] =
'M';
959 $tab[
'num_compte'] = str_pad(self::trunc((
string) $code_compta, 8), 8);
960 $tab[
'code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
961 $tab[
'folio'] =
'000';
966 $tab[
'date_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
967 $tab[
'filler'] =
' ';
968 $tab[
'libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.
' '.$line->label_operation, 20), 20);
983 $tab[
'sens'] = $line->sens;
984 $tab[
'signe_montant'] =
'+';
987 $tab[
'montant'] = str_pad((
string) abs(($line->debit - $line->credit) * 100), 12,
'0', STR_PAD_LEFT);
988 $tab[
'contrepartie'] = str_repeat(
' ', 8);
991 if (!empty($line->date_lim_reglement)) {
992 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%y');
994 $tab[
'date_echeance'] =
'000000';
999 $tab[
'lettrage'] = str_repeat(
' ', 2);
1000 $tab[
'codestat'] = str_repeat(
' ', 3);
1001 $tab[
'num_piece'] = str_pad(self::trunc((
string) $line->piece_num, 5), 5);
1005 $tab[
'affaire'] = str_repeat(
' ', 10);
1006 $tab[
'quantity1'] = str_repeat(
' ', 10);
1007 $tab[
'num_piece2'] = str_pad(self::trunc((
string) $line->piece_num, 8), 8);
1008 $tab[
'devis'] = str_pad(
$conf->currency, 3);
1009 $tab[
'code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
1010 $tab[
'filler3'] = str_repeat(
' ', 3);
1018 $tab[
'libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
1019 $tab[
'codetva'] = str_repeat(
' ', 2);
1023 $tab[
'num_piece3'] = str_pad(substr(self::trunc($line->doc_ref, 20), -10), 10);
1024 $tab[
'reserved'] = str_repeat(
' ', 10);
1025 $tab[
'currency_amount'] = str_repeat(
' ', 13);
1027 $attachmentFileName =
'';
1028 if ($withAttachment == 1) {
1029 $attachmentFileKey = trim((
string) $line->piece_num);
1031 if (!isset($archiveFileList[$attachmentFileKey])) {
1032 $objectDirPath =
'';
1034 if ($line->doc_type ==
'customer_invoice') {
1035 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1036 } elseif ($line->doc_type ==
'expense_report') {
1037 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1038 } elseif ($line->doc_type ==
'supplier_invoice') {
1039 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1041 $invoice->fetch($line->fk_doc);
1042 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1043 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1045 $arrayofinclusion = array();
1047 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1048 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1049 if (!empty($fileFoundList)) {
1050 $attachmentFileNameTrunc = str_pad(self::trunc((
string) $line->piece_num, 8), 8,
'0', STR_PAD_LEFT);
1051 foreach ($fileFoundList as $fileFound) {
1052 if (strstr($fileFound[
'name'], $objectFileName)) {
1055 if ($line->doc_type ==
'supplier_invoice') {
1056 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1059 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1062 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1063 if (file_exists($fileFoundPath)) {
1064 $archiveFileList[$attachmentFileKey] = array(
1065 'path' => $fileFoundPath,
1066 'name' => $attachmentFileNameTrunc.
'.pdf',
1075 if (isset($archiveFileList[$attachmentFileKey])) {
1076 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1079 if (
dol_strlen((
string) $attachmentFileName) == 12) {
1080 $tab[
'attachment'] = $attachmentFileName;
1082 $tab[
'attachment'] = str_repeat(
' ', 12);
1084 $tab[
'filler4'] = str_repeat(
' ', 38);
1085 $tab[
'end_line'] = $end_line;
1088 fwrite($exportFile, implode($tab));
1090 print implode($tab);
1094 return $archiveFileList;
1116 foreach ($objectLines as $line) {
1117 $code_compta = $line->numero_compte;
1118 if (!empty($line->subledger_account)) {
1119 $code_compta = $line->subledger_account;
1124 $tab[
'code_journal'] = str_pad(
dol_trunc($line->code_journal, 2,
'right',
'UTF-8', 1), 2);
1129 $tab[
'date_operation'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1131 $tab[
'folio'] =
' 1';
1133 $tab[
'num_ecriture'] = str_pad(
dol_trunc((
string) $index, 6,
'right',
'UTF-8', 1), 6,
' ', STR_PAD_LEFT);
1135 $tab[
'jour_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
1137 $tab[
'num_compte'] = str_pad(
dol_trunc((
string) $code_compta, 6,
'right',
'UTF-8', 1), 6,
'0');
1139 if ($line->sens ==
'D') {
1140 $tab[
'montant_debit'] = str_pad(number_format($line->debit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1142 $tab[
'montant_crebit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1144 $tab[
'montant_debit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1146 $tab[
'montant_crebit'] = str_pad(number_format($line->credit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1151 $tab[
'lettrage'] = str_repeat(
dol_trunc((
string) $line->lettering_code, 2,
'left',
'UTF-8', 1), 2);
1153 $tab[
'code_piece'] = str_pad(
dol_trunc((
string) $line->piece_num, 5,
'left',
'UTF-8', 1), 5,
' ', STR_PAD_LEFT);
1155 $tab[
'code_stat'] = str_repeat(
' ', 4);
1157 if (!empty($line->date_lim_reglement)) {
1158 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%Y');
1160 $tab[
'date_echeance'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1163 $tab[
'monnaie'] =
'1';
1165 $tab[
'filler'] =
' ';
1167 $tab[
'ind_compteur'] =
' ';
1169 $tab[
'quantite'] =
'0,000000000';
1171 $tab[
'code_pointage'] = str_repeat(
' ', 2);
1173 $tab[
'end_line'] = $end_line;
1175 $output = implode(
'|', $tab);
1177 fwrite($exportFile, $output);
1199 foreach ($objectLines as $line) {
1205 $tab[] = $date_document;
1206 $tab[] = $line->code_journal;
1207 if (empty($line->subledger_account)) {
1208 $tab[] = $line->numero_compte;
1210 $tab[] = $line->subledger_account;
1213 $tab[] =
'"'.dol_trunc($line->label_operation, 40,
'right',
'UTF-8', 1).
'"';
1214 $tab[] =
'"'.dol_trunc((
string) $line->piece_num, 15,
'right',
'UTF-8', 1).
'"';
1215 $tab[] =
price2num(abs($line->debit - $line->credit));
1216 $tab[] = $line->sens;
1217 $tab[] = $date_document;
1220 $output = implode($separator, $tab).$end_line;
1222 fwrite($exportFile, $output);
1242 foreach ($objectLines as $line) {
1247 $tab[] = $line->piece_num;
1249 $tab[] = $date_document;
1252 if (empty($line->subledger_account)) {
1261 $tab[] =
price($line->debit);
1262 $tab[] =
price($line->credit);
1263 $tab[] =
price(abs($line->debit - $line->credit));
1264 $tab[] = $line->sens;
1265 $tab[] = $line->lettering_code;
1266 $tab[] = $line->code_journal;
1268 $output = implode($separator, $tab).$end_line;
1270 fwrite($exportFile, $output);
1289 foreach ($objectLines as $line) {
1294 $tab[] = $date_document;
1295 $tab[] = $line->code_journal;
1296 if (empty($line->subledger_account)) {
1301 $tab[] = $line->doc_ref;
1302 $tab[] = $line->label_operation;
1303 $tab[] =
price($line->debit);
1304 $tab[] =
price($line->credit);
1306 $output = implode($separator, $tab).$end_line;
1308 fwrite($exportFile, $output);
1326 $separator = $this->separator;
1328 foreach ($objectLines as $line) {
1333 $tab[] = $line->piece_num;
1334 $tab[] = $date_document;
1335 $tab[] = $line->doc_ref;
1336 $tab[] = preg_match(
'/'.$separator.
'/', $line->label_operation) ?
"'".$line->label_operation.
"'" : $line->label_operation;
1341 $tab[] =
price2num($line->debit - $line->credit);
1342 $tab[] = $line->code_journal;
1344 $output = implode($separator, $tab).$this->end_line;
1346 fwrite($exportFile, $output);
1365 public function exportFEC($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1367 global
$conf, $langs;
1373 $tab[] =
"JournalCode";
1374 $tab[] =
"JournalLib";
1375 $tab[] =
"EcritureNum";
1376 $tab[] =
"EcritureDate";
1377 $tab[] =
"CompteNum";
1378 $tab[] =
"CompteLib";
1379 $tab[] =
"CompAuxNum";
1380 $tab[] =
"CompAuxLib";
1381 $tab[] =
"PieceRef";
1382 $tab[] =
"PieceDate";
1383 $tab[] =
"EcritureLib";
1386 $tab[] =
"EcritureLet";
1388 $tab[] =
"ValidDate";
1389 $tab[] =
"Montantdevise";
1391 $tab[] =
"DateLimitReglmt";
1392 $tab[] =
"NumFacture";
1393 $tab[] =
"FichierFacture";
1395 $output = implode($separator, $tab).$end_line;
1397 fwrite($exportFile, $output);
1402 foreach ($objectLines as $line) {
1403 if ($line->debit == 0 && $line->credit == 0) {
1409 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1410 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1411 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1414 if ($line->doc_type ==
'customer_invoice') {
1416 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1417 $invoice =
new Facture($this->db);
1418 $invoice->fetch($line->fk_doc);
1420 $refInvoice = $invoice->ref;
1421 } elseif ($line->doc_type ==
'supplier_invoice') {
1423 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1425 $invoice->fetch($line->fk_doc);
1427 $refInvoice = $invoice->ref_supplier;
1433 $tab[] = $line->code_journal;
1438 $tab[] = $labeljournal;
1441 $tab[] = $line->piece_num;
1444 $tab[] = $date_document;
1459 $tab[] = $line->doc_ref;
1466 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1467 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1477 $tab[] = $line->lettering_code;
1480 $tab[] = $date_lettering;
1483 $tab[] = $date_validation;
1486 $tab[] = $line->multicurrency_amount;
1489 $tab[] = $line->multicurrency_code;
1492 $tab[] = $date_limit_payment;
1496 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1497 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1501 $attachmentFileName =
'';
1502 if ($withAttachment == 1) {
1503 $attachmentFileKey = trim((
string) $line->piece_num);
1505 if (!isset($archiveFileList[$attachmentFileKey])) {
1506 $objectDirPath =
'';
1508 if ($line->doc_type ==
'customer_invoice') {
1509 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1510 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1512 } elseif ($line->doc_type ==
'expense_report') {
1513 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1514 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1516 } elseif ($line->doc_type ==
'supplier_invoice') {
1517 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1518 '@phan-var-force FactureFournisseur $invoice';
1520 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1521 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1524 $arrayofinclusion = array();
1526 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1527 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1528 if (!empty($fileFoundList)) {
1529 $attachmentFileNameTrunc = $line->doc_ref;
1530 foreach ($fileFoundList as $fileFound) {
1531 if (strstr($fileFound[
'name'], $objectFileName)) {
1534 if ($line->doc_type ==
'supplier_invoice') {
1535 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1538 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1541 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1542 if (file_exists($fileFoundPath)) {
1543 $archiveFileList[$attachmentFileKey] = array(
1544 'path' => $fileFoundPath,
1545 'name' => $attachmentFileNameTrunc.
'.pdf',
1554 if (isset($archiveFileList[$attachmentFileKey])) {
1555 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1559 $tab[] = $attachmentFileName;
1561 $output = implode($separator, $tab).$end_line;
1564 fwrite($exportFile, $output);
1571 return $archiveFileList;
1586 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1588 global
$conf, $langs;
1594 $tab[] =
"JournalCode";
1595 $tab[] =
"JournalLib";
1596 $tab[] =
"EcritureNum";
1597 $tab[] =
"EcritureDate";
1598 $tab[] =
"CompteNum";
1599 $tab[] =
"CompteLib";
1600 $tab[] =
"CompAuxNum";
1601 $tab[] =
"CompAuxLib";
1602 $tab[] =
"PieceRef";
1603 $tab[] =
"PieceDate";
1604 $tab[] =
"EcritureLib";
1607 $tab[] =
"EcritureLet";
1609 $tab[] =
"ValidDate";
1610 $tab[] =
"Montantdevise";
1612 $tab[] =
"DateLimitReglmt";
1613 $tab[] =
"NumFacture";
1614 $tab[] =
"FichierFacture";
1616 $output = implode($separator, $tab).$end_line;
1618 fwrite($exportFile, $output);
1623 foreach ($objectLines as $line) {
1624 if ($line->debit == 0 && $line->credit == 0) {
1629 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1630 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1631 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1634 if ($line->doc_type ==
'customer_invoice') {
1636 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1637 $invoice =
new Facture($this->db);
1638 $invoice->fetch($line->fk_doc);
1640 $refInvoice = $invoice->ref;
1641 } elseif ($line->doc_type ==
'supplier_invoice') {
1643 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1645 $invoice->fetch($line->fk_doc);
1647 $refInvoice = $invoice->ref_supplier;
1653 $tab[] = $line->code_journal;
1658 $tab[] = $labeljournal;
1661 $tab[] = $line->piece_num;
1664 $tab[] = $date_creation;
1679 $tab[] = $line->doc_ref;
1682 $tab[] = $date_document;
1686 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1687 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1697 $tab[] = $line->lettering_code;
1700 $tab[] = $date_lettering;
1703 $tab[] = $date_validation;
1706 $tab[] = $line->multicurrency_amount;
1709 $tab[] = $line->multicurrency_code;
1712 $tab[] = $date_limit_payment;
1716 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1717 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1721 $attachmentFileName =
'';
1722 if ($withAttachment == 1) {
1723 $attachmentFileKey = trim((
string) $line->piece_num);
1725 if (!isset($archiveFileList[$attachmentFileKey])) {
1726 $objectDirPath =
'';
1728 if ($line->doc_type ==
'customer_invoice') {
1729 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1730 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1732 } elseif ($line->doc_type ==
'expense_report') {
1733 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1734 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1736 } elseif ($line->doc_type ==
'supplier_invoice') {
1737 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1738 '@phan-var-force FactureFournisseur $invoice';
1740 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1741 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1744 $arrayofinclusion = array();
1746 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1747 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1748 if (!empty($fileFoundList)) {
1749 $attachmentFileNameTrunc = $line->doc_ref;
1750 foreach ($fileFoundList as $fileFound) {
1751 if (strstr($fileFound[
'name'], $objectFileName)) {
1754 if ($line->doc_type ==
'supplier_invoice') {
1755 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1758 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1761 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1762 if (file_exists($fileFoundPath)) {
1763 $archiveFileList[$attachmentFileKey] = array(
1764 'path' => $fileFoundPath,
1765 'name' => $attachmentFileNameTrunc.
'.pdf',
1774 if (isset($archiveFileList[$attachmentFileKey])) {
1775 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1779 $tab[] = $attachmentFileName;
1781 $output = implode($separator, $tab).$end_line;
1783 fwrite($exportFile, $output);
1790 return $archiveFileList;
1826 $tab[] =
"FW-Betrag";
1833 $output = implode($separator, $tab).$end_line;
1835 fwrite($exportFile, $output);
1841 $thisPieceAccountNr =
"";
1842 $aSize = count($objectLines);
1843 foreach ($objectLines as $aIndex => $line) {
1844 $sammelBuchung =
false;
1845 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1846 $sammelBuchung =
true;
1847 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1848 $sammelBuchung =
true;
1849 } elseif ($aIndex + 1 < $aSize
1850 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1851 && $aIndex - 1 < $aSize
1852 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1854 $sammelBuchung =
true;
1860 $tab[] = $line->piece_num;
1864 $tab[] = $date_document;
1869 if ($line->sens ==
'D') {
1877 if (empty($line->code_tiers)) {
1878 if ($line->piece_num == $thisPieceNum) {
1887 $tab[] = $this->separator;
1896 if ($sammelBuchung) {
1904 $tab[] = abs($line->debit - $line->credit);
1911 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
1915 if (strlen($line1) == 0) {
1919 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1920 $line1 = $line1.
' / '.$line2;
1924 $tab[] =
'"'.self::toAnsi($line1).
'"';
1926 $tab[] =
'"'.self::toAnsi($line2).
'"';
1930 $tab[] = $this->separator;
1935 $output = implode($separator, $tab).$end_line;
1937 fwrite($exportFile, $output);
1942 if ($line->piece_num !== $thisPieceNum) {
1943 $thisPieceNum = $line->piece_num;
1944 $thisPieceAccountNr = $line->numero_compte;
1962 foreach ($objectLines as $line) {
1965 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1970 $type_enregistrement =
'E';
1971 $tab[] = $type_enregistrement;
1973 $tab[] = substr($line->code_journal, 0, 2);
1977 $tab[] = $line->piece_num;
1979 $tab[] = $date_document;
1981 $tab[] = $line->label_operation;
1983 $tab[] = $date_lim_reglement;
1985 if ($line->doc_type ==
'supplier_invoice') {
1986 if (($line->debit - $line->credit) > 0) {
1987 $nature_piece =
'AF';
1989 $nature_piece =
'FF';
1991 } elseif ($line->doc_type ==
'customer_invoice') {
1992 if (($line->debit - $line->credit) < 0) {
1993 $nature_piece =
'AC';
1995 $nature_piece =
'FC';
2000 $tab[] = $nature_piece;
2011 $racine_subledger_account =
'';
2014 $tab[] = $racine_subledger_account;
2016 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
2018 $tab[] = $line->sens;
2022 $tab[] = $date_creation;
2024 $tab[] = $line->lettering_code;
2026 $tab[] = $line->date_lettering;
2028 if (!empty($line->subledger_account)) {
2034 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2036 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2050 $tab[] = $line->doc_ref;
2078 $output = implode($separator, $tab).$end_line;
2080 fwrite($exportFile, $output);
2099 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2103 $last_codeinvoice =
'';
2105 foreach ($objectLines as $line) {
2107 if ($last_codeinvoice != $line->doc_ref) {
2109 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2110 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2111 $resql = $this->db->query($sql);
2113 if ($resql && $this->db->num_rows($resql) > 0) {
2114 $soc = $this->db->fetch_object($resql);
2116 $address = array(
'',
'',
'');
2117 if (strpos($soc->address,
"\n") !==
false) {
2118 $address = explode(
"\n", $soc->address);
2119 if (is_array($address) && count($address) > 0) {
2120 foreach ($address as $key => $data) {
2121 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2122 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2126 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2127 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2128 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2133 $type_enregistrement =
'C';
2135 $tab[] = $type_enregistrement;
2137 $tab[] = $soc->code_client;
2147 $tab[] = $address[0];
2149 $tab[] = $address[1];
2151 $tab[] = $address[2];
2155 $tab[] = substr($soc->town, 0, 40);
2159 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2161 $tab[] = $soc->phone;
2173 $tab[] = str_replace(
" ",
"", $soc->siret);
2231 $output = implode($separator, $tab).$end_line;
2233 fwrite($exportFile, $output);
2244 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2247 $type_enregistrement =
'E';
2248 $tab[] = $type_enregistrement;
2250 $tab[] = substr($line->code_journal, 0, 2);
2254 $tab[] = $line->piece_num;
2256 $tab[] = $date_document;
2258 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2260 $tab[] = $date_lim_reglement;
2262 if ($line->doc_type ==
'supplier_invoice') {
2263 if (($line->amount) < 0) {
2264 $nature_piece =
'AF';
2266 $nature_piece =
'FF';
2268 } elseif ($line->doc_type ==
'customer_invoice') {
2269 if (($line->amount) < 0) {
2270 $nature_piece =
'AC';
2272 $nature_piece =
'FC';
2277 $tab[] = $nature_piece;
2288 $racine_subledger_account =
'';
2291 $tab[] = $racine_subledger_account;
2293 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2295 $tab[] = $line->sens;
2299 $tab[] = $date_document;
2301 $tab[] = $line->lettering_code;
2303 $tab[] = $line->date_lettering;
2305 if (!empty($line->subledger_account)) {
2311 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2313 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2325 $tab[] = $line->doc_ref;
2359 $output = implode($separator, $tab).$end_line;
2361 fwrite($exportFile, $output);
2366 $last_codeinvoice = $line->doc_ref;
2380 $langs->load(
'compta');
2387 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2388 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2389 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2390 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2391 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2392 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2393 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2395 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2396 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2397 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2398 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2399 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2400 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2402 $output = implode($separator, $tab).$end_line;
2404 fwrite($exportFile, $output);
2409 foreach ($objectLines as $line) {
2414 $tab[] = $date_document;
2418 if (!empty($line->subledger_account)) {
2419 $account = $line->subledger_account;
2421 $account = $line->numero_compte;
2428 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2430 $tab[] =
price(abs($line->debit - $line->credit));
2431 $tab[] = $line->sens;
2439 $output = implode($separator, $tab).$end_line;
2441 fwrite($exportFile, $output);
2462 $invoices_infos = array();
2463 $supplier_invoices_infos = array();
2464 foreach ($objectLines as $line) {
2465 if ($line->debit == 0 && $line->credit == 0) {
2469 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2471 $invoice_ref = $line->doc_ref;
2474 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2475 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2476 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2477 if ($line->doc_type ==
'customer_invoice') {
2479 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2480 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2481 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2482 $resql = $this->db->query($sql);
2484 if ($obj = $this->db->fetch_object($resql)) {
2486 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2487 $invoice_ref = $obj->ref;
2488 $company_name = $obj->nom;
2493 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2494 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2495 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2496 $resql = $this->db->query($sql);
2498 if ($obj = $this->db->fetch_object($resql)) {
2500 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2501 $invoice_ref = $obj->ref;
2502 $company_name = $obj->nom;
2506 } elseif ($line->doc_type ==
'customer_invoice') {
2508 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2509 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2512 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2513 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2520 $tab[] = $date_document;
2521 $tab[] = substr($line->code_journal, 0, 4);
2523 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2532 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2534 $tab[] =
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1);
2538 $tab[] =
price2num(abs($line->debit - $line->credit));
2540 $tab[] = $line->sens;
2544 $tab[] = $date_echeance;
2546 $output = implode($separator, $tab).$end_line;
2548 fwrite($exportFile, $output);
2568 foreach ($objectLines as $line) {
2569 if ($line->debit == 0 && $line->credit == 0) {
2577 $tab[] = $date_document;
2578 $tab[] = substr($line->code_journal, 0, 4);
2579 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2585 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2586 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2587 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2588 $tab[] =
price2num(abs($line->debit - $line->credit));
2589 $tab[] = $line->sens;
2590 $tab[] = $date_document;
2595 $output = implode($separator, $tab).$end_line;
2597 fwrite($exportFile, $output);
2620 foreach ($objectLines as $line) {
2625 $tab[] = $line->piece_num;
2627 $tab[] = substr($date, 6, 4);
2628 $tab[] = substr($date, 3, 2);
2629 $tab[] = substr($date, 0, 2);
2630 $tab[] = $line->doc_ref;
2632 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2638 $numero_cpt_client =
'411';
2639 $numero_cpt_fourn =
'401';
2640 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2641 $numero_cpt_client .=
'0';
2642 $numero_cpt_fourn .=
'0';
2651 $nom_client = explode(
" - ", $line->label_operation);
2652 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2653 $tab[] =
price($line->debit);
2654 $tab[] =
price($line->credit);
2655 $tab[] =
price($line->montant);
2656 $tab[] = $line->code_journal;
2658 $output = implode($separator, $tab).$end_line;
2660 fwrite($exportFile, $output);
2674 public static function trunc($str, $size)
2676 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2686 public static function toAnsi($str, $size = -1)
2689 if ($retVal >= 0 && $size >= 0) {
2690 $retVal =
dol_substr($retVal, 0, $size,
'Windows-1251');