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);
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($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'];
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($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($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 print implode(
'|', $tab);
1194 foreach ($objectLines as $line) {
1200 $tab[] = $date_document;
1201 $tab[] = $line->code_journal;
1202 if (empty($line->subledger_account)) {
1203 $tab[] = $line->numero_compte;
1205 $tab[] = $line->subledger_account;
1208 $tab[] =
'"'.dol_trunc($line->label_operation, 40,
'right',
'UTF-8', 1).
'"';
1209 $tab[] =
'"'.dol_trunc((
string) $line->piece_num, 15,
'right',
'UTF-8', 1).
'"';
1210 $tab[] =
price2num(abs($line->debit - $line->credit));
1211 $tab[] = $line->sens;
1212 $tab[] = $date_document;
1215 $output = implode($separator, $tab).$end_line;
1217 fwrite($exportFile, $output);
1237 foreach ($objectLines as $line) {
1242 $tab[] = $line->piece_num;
1244 $tab[] = $date_document;
1247 if (empty($line->subledger_account)) {
1256 $tab[] =
price($line->debit);
1257 $tab[] =
price($line->credit);
1258 $tab[] =
price(abs($line->debit - $line->credit));
1259 $tab[] = $line->sens;
1260 $tab[] = $line->lettering_code;
1261 $tab[] = $line->code_journal;
1263 $output = implode($separator, $tab).$end_line;
1265 fwrite($exportFile, $output);
1284 foreach ($objectLines as $line) {
1289 $tab[] = $date_document;
1290 $tab[] = $line->code_journal;
1291 if (empty($line->subledger_account)) {
1296 $tab[] = $line->doc_ref;
1297 $tab[] = $line->label_operation;
1298 $tab[] =
price($line->debit);
1299 $tab[] =
price($line->credit);
1301 $output = implode($separator, $tab).$end_line;
1303 fwrite($exportFile, $output);
1321 $separator = $this->separator;
1323 foreach ($objectLines as $line) {
1328 $tab[] = $line->piece_num;
1329 $tab[] = $date_document;
1330 $tab[] = $line->doc_ref;
1331 $tab[] = preg_match(
'/'.$separator.
'/', $line->label_operation) ?
"'".$line->label_operation.
"'" : $line->label_operation;
1336 $tab[] =
price2num($line->debit - $line->credit);
1337 $tab[] = $line->code_journal;
1339 $output = implode($separator, $tab).$this->end_line;
1341 fwrite($exportFile, $output);
1360 public function exportFEC($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1362 global
$conf, $langs;
1368 $tab[] =
"JournalCode";
1369 $tab[] =
"JournalLib";
1370 $tab[] =
"EcritureNum";
1371 $tab[] =
"EcritureDate";
1372 $tab[] =
"CompteNum";
1373 $tab[] =
"CompteLib";
1374 $tab[] =
"CompAuxNum";
1375 $tab[] =
"CompAuxLib";
1376 $tab[] =
"PieceRef";
1377 $tab[] =
"PieceDate";
1378 $tab[] =
"EcritureLib";
1381 $tab[] =
"EcritureLet";
1383 $tab[] =
"ValidDate";
1384 $tab[] =
"Montantdevise";
1386 $tab[] =
"DateLimitReglmt";
1387 $tab[] =
"NumFacture";
1388 $tab[] =
"FichierFacture";
1390 $output = implode($separator, $tab).$end_line;
1392 fwrite($exportFile, $output);
1397 foreach ($objectLines as $line) {
1398 if ($line->debit == 0 && $line->credit == 0) {
1404 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1405 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1406 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1409 if ($line->doc_type ==
'customer_invoice') {
1411 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1412 $invoice =
new Facture($this->db);
1413 $invoice->fetch($line->fk_doc);
1415 $refInvoice = $invoice->ref;
1416 } elseif ($line->doc_type ==
'supplier_invoice') {
1418 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1420 $invoice->fetch($line->fk_doc);
1422 $refInvoice = $invoice->ref_supplier;
1428 $tab[] = $line->code_journal;
1433 $tab[] = $labeljournal;
1436 $tab[] = $line->piece_num;
1439 $tab[] = $date_document;
1454 $tab[] = $line->doc_ref;
1461 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1462 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1472 $tab[] = $line->lettering_code;
1475 $tab[] = $date_lettering;
1478 $tab[] = $date_validation;
1481 $tab[] = $line->multicurrency_amount;
1484 $tab[] = $line->multicurrency_code;
1487 $tab[] = $date_limit_payment;
1491 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1492 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1496 $attachmentFileName =
'';
1497 if ($withAttachment == 1) {
1498 $attachmentFileKey = trim((
string) $line->piece_num);
1500 if (!isset($archiveFileList[$attachmentFileKey])) {
1501 $objectDirPath =
'';
1503 if ($line->doc_type ==
'customer_invoice') {
1504 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1505 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1507 } elseif ($line->doc_type ==
'expense_report') {
1508 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1509 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1511 } elseif ($line->doc_type ==
'supplier_invoice') {
1512 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1513 '@phan-var-force FactureFournisseur $invoice';
1515 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1516 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1519 $arrayofinclusion = array();
1521 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1522 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1523 if (!empty($fileFoundList)) {
1524 $attachmentFileNameTrunc = $line->doc_ref;
1525 foreach ($fileFoundList as $fileFound) {
1526 if (strstr($fileFound[
'name'], $objectFileName)) {
1529 if ($line->doc_type ==
'supplier_invoice') {
1530 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1533 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1536 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1537 if (file_exists($fileFoundPath)) {
1538 $archiveFileList[$attachmentFileKey] = array(
1539 'path' => $fileFoundPath,
1540 'name' => $attachmentFileNameTrunc.
'.pdf',
1549 if (isset($archiveFileList[$attachmentFileKey])) {
1550 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1554 $tab[] = $attachmentFileName;
1556 $output = implode($separator, $tab).$end_line;
1559 fwrite($exportFile, $output);
1566 return $archiveFileList;
1581 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1583 global
$conf, $langs;
1589 $tab[] =
"JournalCode";
1590 $tab[] =
"JournalLib";
1591 $tab[] =
"EcritureNum";
1592 $tab[] =
"EcritureDate";
1593 $tab[] =
"CompteNum";
1594 $tab[] =
"CompteLib";
1595 $tab[] =
"CompAuxNum";
1596 $tab[] =
"CompAuxLib";
1597 $tab[] =
"PieceRef";
1598 $tab[] =
"PieceDate";
1599 $tab[] =
"EcritureLib";
1602 $tab[] =
"EcritureLet";
1604 $tab[] =
"ValidDate";
1605 $tab[] =
"Montantdevise";
1607 $tab[] =
"DateLimitReglmt";
1608 $tab[] =
"NumFacture";
1609 $tab[] =
"FichierFacture";
1611 $output = implode($separator, $tab).$end_line;
1613 fwrite($exportFile, $output);
1618 foreach ($objectLines as $line) {
1619 if ($line->debit == 0 && $line->credit == 0) {
1624 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1625 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1626 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1629 if ($line->doc_type ==
'customer_invoice') {
1631 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1632 $invoice =
new Facture($this->db);
1633 $invoice->fetch($line->fk_doc);
1635 $refInvoice = $invoice->ref;
1636 } elseif ($line->doc_type ==
'supplier_invoice') {
1638 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1640 $invoice->fetch($line->fk_doc);
1642 $refInvoice = $invoice->ref_supplier;
1648 $tab[] = $line->code_journal;
1653 $tab[] = $labeljournal;
1656 $tab[] = $line->piece_num;
1659 $tab[] = $date_creation;
1674 $tab[] = $line->doc_ref;
1677 $tab[] = $date_document;
1681 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1682 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1692 $tab[] = $line->lettering_code;
1695 $tab[] = $date_lettering;
1698 $tab[] = $date_validation;
1701 $tab[] = $line->multicurrency_amount;
1704 $tab[] = $line->multicurrency_code;
1707 $tab[] = $date_limit_payment;
1711 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1712 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1716 $attachmentFileName =
'';
1717 if ($withAttachment == 1) {
1718 $attachmentFileKey = trim((
string) $line->piece_num);
1720 if (!isset($archiveFileList[$attachmentFileKey])) {
1721 $objectDirPath =
'';
1723 if ($line->doc_type ==
'customer_invoice') {
1724 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_INVOICE_SOURCE_FILE')) {
1725 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1727 } elseif ($line->doc_type ==
'expense_report') {
1728 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_EXPENSEREPORT_SOURCE_FILE')) {
1729 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1731 } elseif ($line->doc_type ==
'supplier_invoice') {
1732 if (!
getDolGlobalInt(
'ACCOUNTING_EXPORT_REMOVE_SUPPLIERINVOICE_SOURCE_FILE')) {
1733 '@phan-var-force FactureFournisseur $invoice';
1735 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1736 $objectDirPath .=
'/' . rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1739 $arrayofinclusion = array();
1741 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1742 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1743 if (!empty($fileFoundList)) {
1744 $attachmentFileNameTrunc = $line->doc_ref;
1745 foreach ($fileFoundList as $fileFound) {
1746 if (strstr($fileFound[
'name'], $objectFileName)) {
1749 if ($line->doc_type ==
'supplier_invoice') {
1750 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1753 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1756 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1757 if (file_exists($fileFoundPath)) {
1758 $archiveFileList[$attachmentFileKey] = array(
1759 'path' => $fileFoundPath,
1760 'name' => $attachmentFileNameTrunc.
'.pdf',
1769 if (isset($archiveFileList[$attachmentFileKey])) {
1770 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1774 $tab[] = $attachmentFileName;
1776 $output = implode($separator, $tab).$end_line;
1778 fwrite($exportFile, $output);
1785 return $archiveFileList;
1821 $tab[] =
"FW-Betrag";
1828 $output = implode($separator, $tab).$end_line;
1830 fwrite($exportFile, $output);
1836 $thisPieceAccountNr =
"";
1837 $aSize = count($objectLines);
1838 foreach ($objectLines as $aIndex => $line) {
1839 $sammelBuchung =
false;
1840 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1841 $sammelBuchung =
true;
1842 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1843 $sammelBuchung =
true;
1844 } elseif ($aIndex + 1 < $aSize
1845 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1846 && $aIndex - 1 < $aSize
1847 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1849 $sammelBuchung =
true;
1855 $tab[] = $line->piece_num;
1859 $tab[] = $date_document;
1864 if ($line->sens ==
'D') {
1872 if (empty($line->code_tiers)) {
1873 if ($line->piece_num == $thisPieceNum) {
1882 $tab[] = $this->separator;
1891 if ($sammelBuchung) {
1899 $tab[] = abs($line->debit - $line->credit);
1906 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
1910 if (strlen($line1) == 0) {
1914 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1915 $line1 = $line1.
' / '.$line2;
1919 $tab[] =
'"'.self::toAnsi($line1).
'"';
1921 $tab[] =
'"'.self::toAnsi($line2).
'"';
1925 $tab[] = $this->separator;
1930 $output = implode($separator, $tab).$end_line;
1932 fwrite($exportFile, $output);
1937 if ($line->piece_num !== $thisPieceNum) {
1938 $thisPieceNum = $line->piece_num;
1939 $thisPieceAccountNr = $line->numero_compte;
1957 foreach ($objectLines as $line) {
1960 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1965 $type_enregistrement =
'E';
1966 $tab[] = $type_enregistrement;
1968 $tab[] = substr($line->code_journal, 0, 2);
1972 $tab[] = $line->piece_num;
1974 $tab[] = $date_document;
1976 $tab[] = $line->label_operation;
1978 $tab[] = $date_lim_reglement;
1980 if ($line->doc_type ==
'supplier_invoice') {
1981 if (($line->debit - $line->credit) > 0) {
1982 $nature_piece =
'AF';
1984 $nature_piece =
'FF';
1986 } elseif ($line->doc_type ==
'customer_invoice') {
1987 if (($line->debit - $line->credit) < 0) {
1988 $nature_piece =
'AC';
1990 $nature_piece =
'FC';
1995 $tab[] = $nature_piece;
2006 $racine_subledger_account =
'';
2009 $tab[] = $racine_subledger_account;
2011 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
2013 $tab[] = $line->sens;
2017 $tab[] = $date_creation;
2019 $tab[] = $line->lettering_code;
2021 $tab[] = $line->date_lettering;
2023 if (!empty($line->subledger_account)) {
2029 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2031 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2045 $tab[] = $line->doc_ref;
2073 $output = implode($separator, $tab).$end_line;
2075 fwrite($exportFile, $output);
2094 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2098 $last_codeinvoice =
'';
2100 foreach ($objectLines as $line) {
2102 if ($last_codeinvoice != $line->doc_ref) {
2104 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2105 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2106 $resql = $this->db->query($sql);
2108 if ($resql && $this->db->num_rows($resql) > 0) {
2109 $soc = $this->db->fetch_object($resql);
2111 $address = array(
'',
'',
'');
2112 if (strpos($soc->address,
"\n") !==
false) {
2113 $address = explode(
"\n", $soc->address);
2114 if (is_array($address) && count($address) > 0) {
2115 foreach ($address as $key => $data) {
2116 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2117 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2121 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2122 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2123 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2128 $type_enregistrement =
'C';
2130 $tab[] = $type_enregistrement;
2132 $tab[] = $soc->code_client;
2142 $tab[] = $address[0];
2144 $tab[] = $address[1];
2146 $tab[] = $address[2];
2150 $tab[] = substr($soc->town, 0, 40);
2154 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2156 $tab[] = $soc->phone;
2168 $tab[] = str_replace(
" ",
"", $soc->siret);
2226 $output = implode($separator, $tab).$end_line;
2228 fwrite($exportFile, $output);
2239 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2242 $type_enregistrement =
'E';
2243 $tab[] = $type_enregistrement;
2245 $tab[] = substr($line->code_journal, 0, 2);
2249 $tab[] = $line->piece_num;
2251 $tab[] = $date_document;
2253 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2255 $tab[] = $date_lim_reglement;
2257 if ($line->doc_type ==
'supplier_invoice') {
2258 if (($line->amount) < 0) {
2259 $nature_piece =
'AF';
2261 $nature_piece =
'FF';
2263 } elseif ($line->doc_type ==
'customer_invoice') {
2264 if (($line->amount) < 0) {
2265 $nature_piece =
'AC';
2267 $nature_piece =
'FC';
2272 $tab[] = $nature_piece;
2283 $racine_subledger_account =
'';
2286 $tab[] = $racine_subledger_account;
2288 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2290 $tab[] = $line->sens;
2294 $tab[] = $date_document;
2296 $tab[] = $line->lettering_code;
2298 $tab[] = $line->date_lettering;
2300 if (!empty($line->subledger_account)) {
2306 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2308 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2320 $tab[] = $line->doc_ref;
2354 $output = implode($separator, $tab).$end_line;
2356 fwrite($exportFile, $output);
2361 $last_codeinvoice = $line->doc_ref;
2375 $langs->load(
'compta');
2382 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2383 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2384 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2385 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2386 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2387 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2388 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2390 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2391 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2392 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2393 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2394 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2395 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2397 $output = implode($separator, $tab).$end_line;
2399 fwrite($exportFile, $output);
2404 foreach ($objectLines as $line) {
2409 $tab[] = $date_document;
2413 if (!empty($line->subledger_account)) {
2414 $account = $line->subledger_account;
2416 $account = $line->numero_compte;
2423 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2425 $tab[] =
price(abs($line->debit - $line->credit));
2426 $tab[] = $line->sens;
2434 $output = implode($separator, $tab).$end_line;
2436 fwrite($exportFile, $output);
2457 $invoices_infos = array();
2458 $supplier_invoices_infos = array();
2459 foreach ($objectLines as $line) {
2460 if ($line->debit == 0 && $line->credit == 0) {
2464 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2466 $invoice_ref = $line->doc_ref;
2469 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2470 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2471 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2472 if ($line->doc_type ==
'customer_invoice') {
2474 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2475 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2476 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2477 $resql = $this->db->query($sql);
2479 if ($obj = $this->db->fetch_object($resql)) {
2481 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2482 $invoice_ref = $obj->ref;
2483 $company_name = $obj->nom;
2488 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2489 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2490 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2491 $resql = $this->db->query($sql);
2493 if ($obj = $this->db->fetch_object($resql)) {
2495 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2496 $invoice_ref = $obj->ref;
2497 $company_name = $obj->nom;
2501 } elseif ($line->doc_type ==
'customer_invoice') {
2503 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2504 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2507 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2508 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2515 $tab[] = $date_document;
2516 $tab[] = substr($line->code_journal, 0, 4);
2518 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2527 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2529 $tab[] =
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1);
2533 $tab[] =
price2num(abs($line->debit - $line->credit));
2535 $tab[] = $line->sens;
2539 $tab[] = $date_echeance;
2541 $output = implode($separator, $tab).$end_line;
2543 fwrite($exportFile, $output);
2563 foreach ($objectLines as $line) {
2564 if ($line->debit == 0 && $line->credit == 0) {
2572 $tab[] = $date_document;
2573 $tab[] = substr($line->code_journal, 0, 4);
2574 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2580 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2581 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2582 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2583 $tab[] =
price2num(abs($line->debit - $line->credit));
2584 $tab[] = $line->sens;
2585 $tab[] = $date_document;
2590 $output = implode($separator, $tab).$end_line;
2592 fwrite($exportFile, $output);
2615 foreach ($objectLines as $line) {
2620 $tab[] = $line->piece_num;
2622 $tab[] = substr($date, 6, 4);
2623 $tab[] = substr($date, 3, 2);
2624 $tab[] = substr($date, 0, 2);
2625 $tab[] = $line->doc_ref;
2627 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2633 $numero_cpt_client =
'411';
2634 $numero_cpt_fourn =
'401';
2635 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2636 $numero_cpt_client .=
'0';
2637 $numero_cpt_fourn .=
'0';
2646 $nom_client = explode(
" - ", $line->label_operation);
2647 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2648 $tab[] =
price($line->debit);
2649 $tab[] =
price($line->credit);
2650 $tab[] =
price($line->montant);
2651 $tab[] = $line->code_journal;
2653 $output = implode($separator, $tab).$end_line;
2655 fwrite($exportFile, $output);
2669 public static function trunc($str, $size)
2671 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2681 public static function toAnsi($str, $size = -1)
2684 if ($retVal >= 0 && $size >= 0) {
2685 $retVal =
dol_substr($retVal, 0, $size,
'Windows-1251');