39require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
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';
1509 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1510 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1512 $arrayofinclusion = array();
1514 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1515 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1516 if (!empty($fileFoundList)) {
1517 $attachmentFileNameTrunc = $line->doc_ref;
1518 foreach ($fileFoundList as $fileFound) {
1519 if (strstr($fileFound[
'name'], $objectFileName)) {
1522 if ($line->doc_type ==
'supplier_invoice') {
1523 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1526 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1529 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1530 if (file_exists($fileFoundPath)) {
1531 $archiveFileList[$attachmentFileKey] = array(
1532 'path' => $fileFoundPath,
1533 'name' => $attachmentFileNameTrunc.
'.pdf',
1542 if (isset($archiveFileList[$attachmentFileKey])) {
1543 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1547 $tab[] = $attachmentFileName;
1549 $output = implode($separator, $tab).$end_line;
1552 fwrite($exportFile, $output);
1559 return $archiveFileList;
1574 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1576 global $conf, $langs;
1582 $tab[] =
"JournalCode";
1583 $tab[] =
"JournalLib";
1584 $tab[] =
"EcritureNum";
1585 $tab[] =
"EcritureDate";
1586 $tab[] =
"CompteNum";
1587 $tab[] =
"CompteLib";
1588 $tab[] =
"CompAuxNum";
1589 $tab[] =
"CompAuxLib";
1590 $tab[] =
"PieceRef";
1591 $tab[] =
"PieceDate";
1592 $tab[] =
"EcritureLib";
1595 $tab[] =
"EcritureLet";
1597 $tab[] =
"ValidDate";
1598 $tab[] =
"Montantdevise";
1600 $tab[] =
"DateLimitReglmt";
1601 $tab[] =
"NumFacture";
1602 $tab[] =
"FichierFacture";
1604 $output = implode($separator, $tab).$end_line;
1606 fwrite($exportFile, $output);
1611 foreach ($objectLines as $line) {
1612 if ($line->debit == 0 && $line->credit == 0) {
1617 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1618 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1619 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1622 if ($line->doc_type ==
'customer_invoice') {
1624 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1625 $invoice =
new Facture($this->db);
1626 $invoice->fetch($line->fk_doc);
1628 $refInvoice = $invoice->ref;
1629 } elseif ($line->doc_type ==
'supplier_invoice') {
1631 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1633 $invoice->fetch($line->fk_doc);
1635 $refInvoice = $invoice->ref_supplier;
1641 $tab[] = $line->code_journal;
1646 $tab[] = $labeljournal;
1649 $tab[] = $line->piece_num;
1652 $tab[] = $date_creation;
1667 $tab[] = $line->doc_ref;
1670 $tab[] = $date_document;
1674 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1675 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1685 $tab[] = $line->lettering_code;
1688 $tab[] = $date_lettering;
1691 $tab[] = $date_validation;
1694 $tab[] = $line->multicurrency_amount;
1697 $tab[] = $line->multicurrency_code;
1700 $tab[] = $date_limit_payment;
1704 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1705 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1709 $attachmentFileName =
'';
1710 if ($withAttachment == 1) {
1711 $attachmentFileKey = trim((
string) $line->piece_num);
1713 if (!isset($archiveFileList[$attachmentFileKey])) {
1714 $objectDirPath =
'';
1716 if ($line->doc_type ==
'customer_invoice') {
1717 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1718 } elseif ($line->doc_type ==
'expense_report') {
1719 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1720 } elseif ($line->doc_type ==
'supplier_invoice') {
1721 '@phan-var-force FactureFournisseur $invoice';
1722 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1723 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1725 $arrayofinclusion = array();
1727 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1728 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0, 1);
1729 if (!empty($fileFoundList)) {
1730 $attachmentFileNameTrunc = $line->doc_ref;
1731 foreach ($fileFoundList as $fileFound) {
1732 if (strstr($fileFound[
'name'], $objectFileName)) {
1735 if ($line->doc_type ==
'supplier_invoice') {
1736 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1739 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1742 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1743 if (file_exists($fileFoundPath)) {
1744 $archiveFileList[$attachmentFileKey] = array(
1745 'path' => $fileFoundPath,
1746 'name' => $attachmentFileNameTrunc.
'.pdf',
1755 if (isset($archiveFileList[$attachmentFileKey])) {
1756 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1760 $tab[] = $attachmentFileName;
1762 $output = implode($separator, $tab).$end_line;
1764 fwrite($exportFile, $output);
1771 return $archiveFileList;
1807 $tab[] =
"FW-Betrag";
1814 $output = implode($separator, $tab).$end_line;
1816 fwrite($exportFile, $output);
1822 $thisPieceAccountNr =
"";
1823 $aSize = count($objectLines);
1824 foreach ($objectLines as $aIndex => $line) {
1825 $sammelBuchung =
false;
1826 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1827 $sammelBuchung =
true;
1828 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1829 $sammelBuchung =
true;
1830 } elseif ($aIndex + 1 < $aSize
1831 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1832 && $aIndex - 1 < $aSize
1833 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1835 $sammelBuchung =
true;
1841 $tab[] = $line->piece_num;
1845 $tab[] = $date_document;
1850 if ($line->sens ==
'D') {
1858 if (empty($line->code_tiers)) {
1859 if ($line->piece_num == $thisPieceNum) {
1868 $tab[] = $this->separator;
1877 if ($sammelBuchung) {
1885 $tab[] = abs($line->debit - $line->credit);
1892 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
1896 if (strlen($line1) == 0) {
1900 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1901 $line1 = $line1.
' / '.$line2;
1905 $tab[] =
'"'.self::toAnsi($line1).
'"';
1907 $tab[] =
'"'.self::toAnsi($line2).
'"';
1911 $tab[] = $this->separator;
1916 $output = implode($separator, $tab).$end_line;
1918 fwrite($exportFile, $output);
1923 if ($line->piece_num !== $thisPieceNum) {
1924 $thisPieceNum = $line->piece_num;
1925 $thisPieceAccountNr = $line->numero_compte;
1943 foreach ($objectLines as $line) {
1946 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1951 $type_enregistrement =
'E';
1952 $tab[] = $type_enregistrement;
1954 $tab[] = substr($line->code_journal, 0, 2);
1958 $tab[] = $line->piece_num;
1960 $tab[] = $date_document;
1962 $tab[] = $line->label_operation;
1964 $tab[] = $date_lim_reglement;
1966 if ($line->doc_type ==
'supplier_invoice') {
1967 if (($line->debit - $line->credit) > 0) {
1968 $nature_piece =
'AF';
1970 $nature_piece =
'FF';
1972 } elseif ($line->doc_type ==
'customer_invoice') {
1973 if (($line->debit - $line->credit) < 0) {
1974 $nature_piece =
'AC';
1976 $nature_piece =
'FC';
1981 $tab[] = $nature_piece;
1992 $racine_subledger_account =
'';
1995 $tab[] = $racine_subledger_account;
1997 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
1999 $tab[] = $line->sens;
2003 $tab[] = $date_creation;
2005 $tab[] = $line->lettering_code;
2007 $tab[] = $line->date_lettering;
2009 if (!empty($line->subledger_account)) {
2015 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2017 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2031 $tab[] = $line->doc_ref;
2059 $output = implode($separator, $tab).$end_line;
2061 fwrite($exportFile, $output);
2080 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2084 $last_codeinvoice =
'';
2086 foreach ($objectLines as $line) {
2088 if ($last_codeinvoice != $line->doc_ref) {
2090 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2091 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2092 $resql = $this->db->query($sql);
2094 if ($resql && $this->db->num_rows($resql) > 0) {
2095 $soc = $this->db->fetch_object($resql);
2097 $address = array(
'',
'',
'');
2098 if (strpos($soc->address,
"\n") !==
false) {
2099 $address = explode(
"\n", $soc->address);
2100 if (is_array($address) && count($address) > 0) {
2101 foreach ($address as $key => $data) {
2102 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2103 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2107 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2108 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2109 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2114 $type_enregistrement =
'C';
2116 $tab[] = $type_enregistrement;
2118 $tab[] = $soc->code_client;
2128 $tab[] = $address[0];
2130 $tab[] = $address[1];
2132 $tab[] = $address[2];
2136 $tab[] = substr($soc->town, 0, 40);
2140 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2142 $tab[] = $soc->phone;
2154 $tab[] = str_replace(
" ",
"", $soc->siret);
2212 $output = implode($separator, $tab).$end_line;
2214 fwrite($exportFile, $output);
2225 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2228 $type_enregistrement =
'E';
2229 $tab[] = $type_enregistrement;
2231 $tab[] = substr($line->code_journal, 0, 2);
2235 $tab[] = $line->piece_num;
2237 $tab[] = $date_document;
2239 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2241 $tab[] = $date_lim_reglement;
2243 if ($line->doc_type ==
'supplier_invoice') {
2244 if (($line->amount) < 0) {
2245 $nature_piece =
'AF';
2247 $nature_piece =
'FF';
2249 } elseif ($line->doc_type ==
'customer_invoice') {
2250 if (($line->amount) < 0) {
2251 $nature_piece =
'AC';
2253 $nature_piece =
'FC';
2258 $tab[] = $nature_piece;
2269 $racine_subledger_account =
'';
2272 $tab[] = $racine_subledger_account;
2274 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2276 $tab[] = $line->sens;
2280 $tab[] = $date_document;
2282 $tab[] = $line->lettering_code;
2284 $tab[] = $line->date_lettering;
2286 if (!empty($line->subledger_account)) {
2292 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2294 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2306 $tab[] = $line->doc_ref;
2340 $output = implode($separator, $tab).$end_line;
2342 fwrite($exportFile, $output);
2347 $last_codeinvoice = $line->doc_ref;
2361 $langs->load(
'compta');
2368 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2369 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2370 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2371 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2372 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2373 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2374 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2376 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2377 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2378 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2379 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2380 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2381 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2383 $output = implode($separator, $tab).$end_line;
2385 fwrite($exportFile, $output);
2390 foreach ($objectLines as $line) {
2395 $tab[] = $date_document;
2399 if (!empty($line->subledger_account)) {
2400 $account = $line->subledger_account;
2402 $account = $line->numero_compte;
2409 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2411 $tab[] =
price(abs($line->debit - $line->credit));
2412 $tab[] = $line->sens;
2420 $output = implode($separator, $tab).$end_line;
2422 fwrite($exportFile, $output);
2443 $invoices_infos = array();
2444 $supplier_invoices_infos = array();
2445 foreach ($objectLines as $line) {
2446 if ($line->debit == 0 && $line->credit == 0) {
2450 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2452 $invoice_ref = $line->doc_ref;
2455 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2456 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2457 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2458 if ($line->doc_type ==
'customer_invoice') {
2460 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2461 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2462 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2463 $resql = $this->db->query($sql);
2465 if ($obj = $this->db->fetch_object($resql)) {
2467 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2468 $invoice_ref = $obj->ref;
2469 $company_name = $obj->nom;
2474 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2475 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2476 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2477 $resql = $this->db->query($sql);
2479 if ($obj = $this->db->fetch_object($resql)) {
2481 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2482 $invoice_ref = $obj->ref;
2483 $company_name = $obj->nom;
2487 } elseif ($line->doc_type ==
'customer_invoice') {
2489 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2490 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2493 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2494 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2501 $tab[] = $date_document;
2502 $tab[] = substr($line->code_journal, 0, 4);
2504 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2513 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2515 $tab[] =
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1);
2519 $tab[] =
price2num(abs($line->debit - $line->credit));
2521 $tab[] = $line->sens;
2525 $tab[] = $date_echeance;
2527 $output = implode($separator, $tab).$end_line;
2529 fwrite($exportFile, $output);
2549 foreach ($objectLines as $line) {
2550 if ($line->debit == 0 && $line->credit == 0) {
2558 $tab[] = $date_document;
2559 $tab[] = substr($line->code_journal, 0, 4);
2560 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2566 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2567 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2568 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', (
string) $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2569 $tab[] =
price2num(abs($line->debit - $line->credit));
2570 $tab[] = $line->sens;
2571 $tab[] = $date_document;
2576 $output = implode($separator, $tab).$end_line;
2578 fwrite($exportFile, $output);
2601 foreach ($objectLines as $line) {
2606 $tab[] = $line->piece_num;
2608 $tab[] = substr($date, 6, 4);
2609 $tab[] = substr($date, 3, 2);
2610 $tab[] = substr($date, 0, 2);
2611 $tab[] = $line->doc_ref;
2613 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2619 $numero_cpt_client =
'411';
2620 $numero_cpt_fourn =
'401';
2621 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2622 $numero_cpt_client .=
'0';
2623 $numero_cpt_fourn .=
'0';
2632 $nom_client = explode(
" - ", $line->label_operation);
2633 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2634 $tab[] =
price($line->debit);
2635 $tab[] =
price($line->credit);
2636 $tab[] =
price($line->montant);
2637 $tab[] = $line->code_journal;
2639 $output = implode($separator, $tab).$end_line;
2641 fwrite($exportFile, $output);
2655 public static function trunc($str, $size)
2657 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2667 public static function toAnsi($str, $size = -1)
2670 if ($retVal >= 0 && $size >= 0) {
2671 $retVal =
dol_substr($retVal, 0, $size,
'Windows-1251');
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
Manage the different format accountancy export.
exportCogilog($objectLines, $exportFile=null)
Export format : COGILOG Last review for this format : 2022-07-12 Alexandre Spangaro (aspangaro@open-d...
export(&$TData, $formatexportset, $withAttachment=0, $downloadMode=1, $outputMode=1, $noouput=1)
Function who chose which export to use with the default config, and make the export into a file.
exportAgiris($objectLines, $exportFile=null)
Export format : Agiris Isacompta.
exportQuadratus($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : Quadratus (Format ASCII) Format since 2015 compatible QuadraCOMPTA Last review for th...
exportWinfic($objectLines, $exportFile=null)
Export format : WinFic - eWinfic - WinSis Compta Last review for this format : 2022-11-01 Alexandre S...
exportSAGE50SWISS($objectLines, $exportFile=null)
Export format : SAGE50SWISS.
exportOpenConcerto($objectLines, $exportFile=null)
Export format : OpenConcerto.
exportEbp($objectLines, $exportFile=null)
Export format : EBP.
exportLDCompta10($objectLines, $exportFile=null)
Export format : LD Compta version 10 & higher Last review for this format : 08-15-2021 Alexandre Span...
exportCharlemagne($objectLines, $exportFile=null)
Export format : Charlemagne.
getTypeConfig()
Array with all export types available (key + label) and parameters for config.
exportFEC($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : FEC Last review for this format : 2023/10/12 Alexandre Spangaro (aspangaro@open-dsi....
exportLDCompta($objectLines, $exportFile=null)
Export format : LD Compta version 9 http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Docu...
exportBob50($objectLines, $exportFile=null)
Export format : BOB50.
exportGestimumV3($objectLines, $exportFile=null)
Export format : Gestimum V3.
static trunc($str, $size)
trunc
exportiSuiteExpert($objectLines, $exportFile=null)
Export format : iSuite Expert.
exportCiel($objectLines, $exportFile=null)
Export format : CIEL (Format XIMPORT) Format since 2003 compatible CIEL version > 2002 / Sage50 Last ...
getType($mode=0)
Array with all export type available (key + label)
static toAnsi($str, $size=-1)
toAnsi
exportConfigurable($objectLines, $exportFile=null)
Export format : Configurable CSV.
static getFormatCode($type)
Return string to summarize the format (Used to generated export filename)
exportFEC2($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : FEC2 Last review for this format : 2023/10/12 Alexandre Spangaro (aspangaro@open-dsi....
__construct(DoliDB $db)
Constructor.
exportCegid($objectLines, $exportFile=null)
Export format : CEGID.
exportCoala($objectLines, $exportFile=null)
Export format : COALA.
getMimeType($formatexportset)
Return the MIME type of a file.
exportGestimumV5($objectLines, $exportFile=null)
Export format : Gestimum V5.
Class to manage Dolibarr database access.
Class to manage suppliers invoices.
Class to manage invoices.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_filesize($pathoffile)
Return size of a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
price2fec($amount)
Function to format a value into a defined format for French administration (no thousand separator & d...
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.