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'] = substr(self::trunc($line->doc_ref, 20), -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 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1505 } elseif ($line->doc_type ==
'expense_report') {
1506 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1507 } elseif ($line->doc_type ==
'supplier_invoice') {
1508 '@phan-var-force FactureFournisseur $invoice';
1510 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1511 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1513 $arrayofinclusion = array();
1515 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1516 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1517 if (!empty($fileFoundList)) {
1518 $attachmentFileNameTrunc = $line->doc_ref;
1519 foreach ($fileFoundList as $fileFound) {
1520 if (strstr($fileFound[
'name'], $objectFileName)) {
1523 if ($line->doc_type ==
'supplier_invoice') {
1524 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1527 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1530 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1531 if (file_exists($fileFoundPath)) {
1532 $archiveFileList[$attachmentFileKey] = array(
1533 'path' => $fileFoundPath,
1534 'name' => $attachmentFileNameTrunc.
'.pdf',
1543 if (isset($archiveFileList[$attachmentFileKey])) {
1544 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1548 $tab[] = $attachmentFileName;
1550 $output = implode($separator, $tab).$end_line;
1553 fwrite($exportFile, $output);
1560 return $archiveFileList;
1575 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1577 global
$conf, $langs;
1583 $tab[] =
"JournalCode";
1584 $tab[] =
"JournalLib";
1585 $tab[] =
"EcritureNum";
1586 $tab[] =
"EcritureDate";
1587 $tab[] =
"CompteNum";
1588 $tab[] =
"CompteLib";
1589 $tab[] =
"CompAuxNum";
1590 $tab[] =
"CompAuxLib";
1591 $tab[] =
"PieceRef";
1592 $tab[] =
"PieceDate";
1593 $tab[] =
"EcritureLib";
1596 $tab[] =
"EcritureLet";
1598 $tab[] =
"ValidDate";
1599 $tab[] =
"Montantdevise";
1601 $tab[] =
"DateLimitReglmt";
1602 $tab[] =
"NumFacture";
1603 $tab[] =
"FichierFacture";
1605 $output = implode($separator, $tab).$end_line;
1607 fwrite($exportFile, $output);
1612 foreach ($objectLines as $line) {
1613 if ($line->debit == 0 && $line->credit == 0) {
1618 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1619 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1620 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1623 if ($line->doc_type ==
'customer_invoice') {
1625 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1626 $invoice =
new Facture($this->db);
1627 $invoice->fetch($line->fk_doc);
1629 $refInvoice = $invoice->ref;
1630 } elseif ($line->doc_type ==
'supplier_invoice') {
1632 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1634 $invoice->fetch($line->fk_doc);
1636 $refInvoice = $invoice->ref_supplier;
1642 $tab[] = $line->code_journal;
1647 $tab[] = $labeljournal;
1650 $tab[] = $line->piece_num;
1653 $tab[] = $date_creation;
1668 $tab[] = $line->doc_ref;
1671 $tab[] = $date_document;
1675 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1676 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1686 $tab[] = $line->lettering_code;
1689 $tab[] = $date_lettering;
1692 $tab[] = $date_validation;
1695 $tab[] = $line->multicurrency_amount;
1698 $tab[] = $line->multicurrency_code;
1701 $tab[] = $date_limit_payment;
1705 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1706 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1710 $attachmentFileName =
'';
1711 if ($withAttachment == 1) {
1712 $attachmentFileKey = trim((
string) $line->piece_num);
1714 if (!isset($archiveFileList[$attachmentFileKey])) {
1715 $objectDirPath =
'';
1717 if ($line->doc_type ==
'customer_invoice') {
1718 $objectDirPath = !empty(
$conf->invoice->multidir_output[
$conf->entity]) ?
$conf->invoice->multidir_output[
$conf->entity] :
$conf->invoice->dir_output;
1719 } elseif ($line->doc_type ==
'expense_report') {
1720 $objectDirPath = !empty(
$conf->expensereport->multidir_output[
$conf->entity]) ?
$conf->expensereport->multidir_output[
$conf->entity] :
$conf->expensereport->dir_output;
1721 } elseif ($line->doc_type ==
'supplier_invoice') {
1722 '@phan-var-force FactureFournisseur $invoice';
1724 $objectDirPath = !empty(
$conf->fournisseur->facture->multidir_output[
$conf->entity]) ?
$conf->fournisseur->facture->multidir_output[
$conf->entity] :
$conf->fournisseur->facture->dir_output;
1725 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1727 $arrayofinclusion = array();
1729 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1730 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1731 if (!empty($fileFoundList)) {
1732 $attachmentFileNameTrunc = $line->doc_ref;
1733 foreach ($fileFoundList as $fileFound) {
1734 if (strstr($fileFound[
'name'], $objectFileName)) {
1737 if ($line->doc_type ==
'supplier_invoice') {
1738 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1741 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1744 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1745 if (file_exists($fileFoundPath)) {
1746 $archiveFileList[$attachmentFileKey] = array(
1747 'path' => $fileFoundPath,
1748 'name' => $attachmentFileNameTrunc.
'.pdf',
1757 if (isset($archiveFileList[$attachmentFileKey])) {
1758 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1762 $tab[] = $attachmentFileName;
1764 $output = implode($separator, $tab).$end_line;
1766 fwrite($exportFile, $output);
1773 return $archiveFileList;
1809 $tab[] =
"FW-Betrag";
1816 $output = implode($separator, $tab).$end_line;
1818 fwrite($exportFile, $output);
1824 $thisPieceAccountNr =
"";
1825 $aSize = count($objectLines);
1826 foreach ($objectLines as $aIndex => $line) {
1827 $sammelBuchung =
false;
1828 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1829 $sammelBuchung =
true;
1830 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1831 $sammelBuchung =
true;
1832 } elseif ($aIndex + 1 < $aSize
1833 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1834 && $aIndex - 1 < $aSize
1835 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1837 $sammelBuchung =
true;
1843 $tab[] = $line->piece_num;
1847 $tab[] = $date_document;
1852 if ($line->sens ==
'D') {
1860 if (empty($line->code_tiers)) {
1861 if ($line->piece_num == $thisPieceNum) {
1870 $tab[] = $this->separator;
1879 if ($sammelBuchung) {
1887 $tab[] = abs($line->debit - $line->credit);
1894 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
1898 if (strlen($line1) == 0) {
1902 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1903 $line1 = $line1.
' / '.$line2;
1907 $tab[] =
'"'.self::toAnsi($line1).
'"';
1909 $tab[] =
'"'.self::toAnsi($line2).
'"';
1913 $tab[] = $this->separator;
1918 $output = implode($separator, $tab).$end_line;
1920 fwrite($exportFile, $output);
1925 if ($line->piece_num !== $thisPieceNum) {
1926 $thisPieceNum = $line->piece_num;
1927 $thisPieceAccountNr = $line->numero_compte;
1945 foreach ($objectLines as $line) {
1948 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1953 $type_enregistrement =
'E';
1954 $tab[] = $type_enregistrement;
1956 $tab[] = substr($line->code_journal, 0, 2);
1960 $tab[] = $line->piece_num;
1962 $tab[] = $date_document;
1964 $tab[] = $line->label_operation;
1966 $tab[] = $date_lim_reglement;
1968 if ($line->doc_type ==
'supplier_invoice') {
1969 if (($line->debit - $line->credit) > 0) {
1970 $nature_piece =
'AF';
1972 $nature_piece =
'FF';
1974 } elseif ($line->doc_type ==
'customer_invoice') {
1975 if (($line->debit - $line->credit) < 0) {
1976 $nature_piece =
'AC';
1978 $nature_piece =
'FC';
1983 $tab[] = $nature_piece;
1994 $racine_subledger_account =
'';
1997 $tab[] = $racine_subledger_account;
1999 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
2001 $tab[] = $line->sens;
2005 $tab[] = $date_creation;
2007 $tab[] = $line->lettering_code;
2009 $tab[] = $line->date_lettering;
2011 if (!empty($line->subledger_account)) {
2017 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2019 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2033 $tab[] = $line->doc_ref;
2061 $output = implode($separator, $tab).$end_line;
2063 fwrite($exportFile, $output);
2082 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2086 $last_codeinvoice =
'';
2088 foreach ($objectLines as $line) {
2090 if ($last_codeinvoice != $line->doc_ref) {
2092 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2093 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2094 $resql = $this->db->query($sql);
2096 if ($resql && $this->db->num_rows($resql) > 0) {
2097 $soc = $this->db->fetch_object($resql);
2099 $address = array(
'',
'',
'');
2100 if (strpos($soc->address,
"\n") !==
false) {
2101 $address = explode(
"\n", $soc->address);
2102 if (is_array($address) && count($address) > 0) {
2103 foreach ($address as $key => $data) {
2104 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2105 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2109 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2110 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2111 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2116 $type_enregistrement =
'C';
2118 $tab[] = $type_enregistrement;
2120 $tab[] = $soc->code_client;
2130 $tab[] = $address[0];
2132 $tab[] = $address[1];
2134 $tab[] = $address[2];
2138 $tab[] = substr($soc->town, 0, 40);
2142 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2144 $tab[] = $soc->phone;
2156 $tab[] = str_replace(
" ",
"", $soc->siret);
2214 $output = implode($separator, $tab).$end_line;
2216 fwrite($exportFile, $output);
2227 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2230 $type_enregistrement =
'E';
2231 $tab[] = $type_enregistrement;
2233 $tab[] = substr($line->code_journal, 0, 2);
2237 $tab[] = $line->piece_num;
2239 $tab[] = $date_document;
2241 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2243 $tab[] = $date_lim_reglement;
2245 if ($line->doc_type ==
'supplier_invoice') {
2246 if (($line->amount) < 0) {
2247 $nature_piece =
'AF';
2249 $nature_piece =
'FF';
2251 } elseif ($line->doc_type ==
'customer_invoice') {
2252 if (($line->amount) < 0) {
2253 $nature_piece =
'AC';
2255 $nature_piece =
'FC';
2260 $tab[] = $nature_piece;
2271 $racine_subledger_account =
'';
2274 $tab[] = $racine_subledger_account;
2276 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2278 $tab[] = $line->sens;
2282 $tab[] = $date_document;
2284 $tab[] = $line->lettering_code;
2286 $tab[] = $line->date_lettering;
2288 if (!empty($line->subledger_account)) {
2294 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2296 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2308 $tab[] = $line->doc_ref;
2342 $output = implode($separator, $tab).$end_line;
2344 fwrite($exportFile, $output);
2349 $last_codeinvoice = $line->doc_ref;
2363 $langs->load(
'compta');
2370 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2371 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2372 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2373 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2374 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2375 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2376 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2378 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2379 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2380 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2381 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2382 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2383 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2385 $output = implode($separator, $tab).$end_line;
2387 fwrite($exportFile, $output);
2392 foreach ($objectLines as $line) {
2397 $tab[] = $date_document;
2401 if (!empty($line->subledger_account)) {
2402 $account = $line->subledger_account;
2404 $account = $line->numero_compte;
2411 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2413 $tab[] =
price(abs($line->debit - $line->credit));
2414 $tab[] = $line->sens;
2422 $output = implode($separator, $tab).$end_line;
2424 fwrite($exportFile, $output);
2445 $invoices_infos = array();
2446 $supplier_invoices_infos = array();
2447 foreach ($objectLines as $line) {
2448 if ($line->debit == 0 && $line->credit == 0) {
2452 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2454 $invoice_ref = $line->doc_ref;
2457 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2458 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2459 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2460 if ($line->doc_type ==
'customer_invoice') {
2462 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2463 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2464 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2465 $resql = $this->db->query($sql);
2467 if ($obj = $this->db->fetch_object($resql)) {
2469 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2470 $invoice_ref = $obj->ref;
2471 $company_name = $obj->nom;
2476 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2477 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2478 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2479 $resql = $this->db->query($sql);
2481 if ($obj = $this->db->fetch_object($resql)) {
2483 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2484 $invoice_ref = $obj->ref;
2485 $company_name = $obj->nom;
2489 } elseif ($line->doc_type ==
'customer_invoice') {
2491 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2492 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2495 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2496 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2503 $tab[] = $date_document;
2504 $tab[] = substr($line->code_journal, 0, 4);
2506 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2515 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2517 $tab[] =
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1);
2521 $tab[] =
price2num(abs($line->debit - $line->credit));
2523 $tab[] = $line->sens;
2527 $tab[] = $date_echeance;
2529 $output = implode($separator, $tab).$end_line;
2531 fwrite($exportFile, $output);
2551 foreach ($objectLines as $line) {
2552 if ($line->debit == 0 && $line->credit == 0) {
2560 $tab[] = $date_document;
2561 $tab[] = substr($line->code_journal, 0, 4);
2562 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2568 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2569 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2570 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2571 $tab[] =
price2num(abs($line->debit - $line->credit));
2572 $tab[] = $line->sens;
2573 $tab[] = $date_document;
2578 $output = implode($separator, $tab).$end_line;
2580 fwrite($exportFile, $output);
2603 foreach ($objectLines as $line) {
2608 $tab[] = $line->piece_num;
2610 $tab[] = substr($date, 6, 4);
2611 $tab[] = substr($date, 3, 2);
2612 $tab[] = substr($date, 0, 2);
2613 $tab[] = $line->doc_ref;
2615 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2621 $numero_cpt_client =
'411';
2622 $numero_cpt_fourn =
'401';
2623 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2624 $numero_cpt_client .=
'0';
2625 $numero_cpt_fourn .=
'0';
2634 $nom_client = explode(
" - ", $line->label_operation);
2635 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2636 $tab[] =
price($line->debit);
2637 $tab[] =
price($line->credit);
2638 $tab[] =
price($line->montant);
2639 $tab[] = $line->code_journal;
2641 $output = implode($separator, $tab).$end_line;
2643 fwrite($exportFile, $output);
2657 public static function trunc($str, $size)
2659 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2669 public static function toAnsi($str, $size = -1)
2672 if ($retVal >= 0 && $size >= 0) {
2673 $retVal =
dol_substr($retVal, 0, $size,
'Windows-1251');