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';
52 public static $EXPORT_TYPE_CONFIGURABLE = 1;
53 public static $EXPORT_TYPE_AGIRIS = 10;
54 public static $EXPORT_TYPE_EBP = 15;
55 public static $EXPORT_TYPE_CEGID = 20;
56 public static $EXPORT_TYPE_COGILOG = 25;
57 public static $EXPORT_TYPE_COALA = 30;
58 public static $EXPORT_TYPE_BOB50 = 35;
59 public static $EXPORT_TYPE_CIEL = 40;
60 public static $EXPORT_TYPE_SAGE50_SWISS = 45;
61 public static $EXPORT_TYPE_CHARLEMAGNE = 50;
62 public static $EXPORT_TYPE_QUADRATUS = 60;
63 public static $EXPORT_TYPE_WINFIC = 70;
64 public static $EXPORT_TYPE_OPENCONCERTO = 100;
65 public static $EXPORT_TYPE_LDCOMPTA = 110;
66 public static $EXPORT_TYPE_LDCOMPTA10 = 120;
67 public static $EXPORT_TYPE_GESTIMUMV3 = 130;
68 public static $EXPORT_TYPE_GESTIMUMV5 = 135;
69 public static $EXPORT_TYPE_ISUITEEXPERT = 200;
71 public static $EXPORT_TYPE_FEC = 1000;
72 public static $EXPORT_TYPE_FEC2 = 1010;
82 public $errors = array();
87 public $separator =
'';
92 public $end_line =
'';
97 public $generatedfiledata = array();
107 global $conf, $hookmanager;
113 $hookmanager->initHooks(array(
'accountancyexport'));
124 global $langs, $hookmanager;
126 $listofspecialformatexport = array(
127 self::$EXPORT_TYPE_CEGID => $langs->trans(
'Modelcsv_CEGID'),
128 self::$EXPORT_TYPE_COALA => $langs->trans(
'Modelcsv_COALA'),
129 self::$EXPORT_TYPE_BOB50 => $langs->trans(
'Modelcsv_bob50'),
130 self::$EXPORT_TYPE_CIEL => $langs->trans(
'Modelcsv_ciel'),
131 self::$EXPORT_TYPE_QUADRATUS => $langs->trans(
'Modelcsv_quadratus'),
132 self::$EXPORT_TYPE_WINFIC => $langs->trans(
'Modelcsv_winfic'),
133 self::$EXPORT_TYPE_EBP => $langs->trans(
'Modelcsv_ebp'),
134 self::$EXPORT_TYPE_COGILOG => $langs->trans(
'Modelcsv_cogilog'),
135 self::$EXPORT_TYPE_AGIRIS => $langs->trans(
'Modelcsv_agiris'),
136 self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans(
'Modelcsv_openconcerto'),
137 self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans(
'Modelcsv_Sage50_Swiss'),
138 self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans(
'Modelcsv_charlemagne'),
139 self::$EXPORT_TYPE_LDCOMPTA => $langs->trans(
'Modelcsv_LDCompta'),
140 self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans(
'Modelcsv_LDCompta10'),
141 self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans(
'Modelcsv_Gestinumv3'),
142 self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans(
'Modelcsv_Gestinumv5'),
143 self::$EXPORT_TYPE_ISUITEEXPERT =>
'Export iSuite Expert',
146 $listofgenericformatexport = array(
147 self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans(
'Modelcsv_configurable'),
148 self::$EXPORT_TYPE_FEC => $langs->trans(
'Modelcsv_FEC'),
149 self::$EXPORT_TYPE_FEC2 => $langs->trans(
'Modelcsv_FEC2'),
153 $listofexporttypes = $listofgenericformatexport + $listofspecialformatexport;
154 ksort($listofexporttypes, SORT_NUMERIC);
156 ksort($listofspecialformatexport, SORT_NUMERIC);
157 $listofexporttypes = array();
159 foreach ($listofgenericformatexport as $key => $val) {
161 $listofexporttypes[$key] = array(
'id' => $key,
'label' => $val,
'position' => $i);
163 $listofexporttypes[
'separator_'.$i] = array(
'id' => 0,
'label' =>
'----------------',
'position' => $i,
'disabled' =>
'disabled');
164 foreach ($listofspecialformatexport as $key => $val) {
166 $listofexporttypes[$key] = array(
'id' => $key,
'label' => $val,
'position' => $i);
171 $parameters = array();
172 $reshook = $hookmanager->executeHooks(
'getType', $parameters, $listofexporttypes);
174 return $listofexporttypes;
186 self::$EXPORT_TYPE_CONFIGURABLE =>
'csv',
187 self::$EXPORT_TYPE_CEGID =>
'cegid',
188 self::$EXPORT_TYPE_COALA =>
'coala',
189 self::$EXPORT_TYPE_BOB50 =>
'bob50',
190 self::$EXPORT_TYPE_CIEL =>
'ciel',
191 self::$EXPORT_TYPE_QUADRATUS =>
'quadratus',
192 self::$EXPORT_TYPE_WINFIC =>
'winfic',
193 self::$EXPORT_TYPE_EBP =>
'ebp',
194 self::$EXPORT_TYPE_COGILOG =>
'cogilog',
195 self::$EXPORT_TYPE_AGIRIS =>
'agiris',
196 self::$EXPORT_TYPE_OPENCONCERTO =>
'openconcerto',
197 self::$EXPORT_TYPE_SAGE50_SWISS =>
'sage50ch',
198 self::$EXPORT_TYPE_CHARLEMAGNE =>
'charlemagne',
199 self::$EXPORT_TYPE_LDCOMPTA =>
'ldcompta',
200 self::$EXPORT_TYPE_LDCOMPTA10 =>
'ldcompta10',
201 self::$EXPORT_TYPE_GESTIMUMV3 =>
'gestimumv3',
202 self::$EXPORT_TYPE_GESTIMUMV5 =>
'gestimumv5',
203 self::$EXPORT_TYPE_FEC =>
'fec',
204 self::$EXPORT_TYPE_FEC2 =>
'fec2',
205 self::$EXPORT_TYPE_ISUITEEXPERT =>
'isuiteexpert',
209 $code = $formatcode[$type];
210 $parameters = array(
'type' => $type);
211 $reshook = $hookmanager->executeHooks(
'getFormatCode', $parameters, $code);
225 $exporttypes = array(
227 self::$EXPORT_TYPE_CONFIGURABLE => array(
228 'label' => $langs->trans(
'Modelcsv_configurable'),
230 'ACCOUNTING_EXPORT_SEPARATORCSV' =>
getDolGlobalString(
'ACCOUNTING_EXPORT_SEPARATORCSV',
','),
234 self::$EXPORT_TYPE_CEGID => array(
235 'label' => $langs->trans(
'Modelcsv_CEGID'),
237 self::$EXPORT_TYPE_COALA => array(
238 'label' => $langs->trans(
'Modelcsv_COALA'),
240 self::$EXPORT_TYPE_BOB50 => array(
241 'label' => $langs->trans(
'Modelcsv_bob50'),
243 self::$EXPORT_TYPE_CIEL => array(
244 'label' => $langs->trans(
'Modelcsv_ciel'),
245 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
247 self::$EXPORT_TYPE_QUADRATUS => array(
248 'label' => $langs->trans(
'Modelcsv_quadratus'),
249 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
251 self::$EXPORT_TYPE_WINFIC => array(
252 'label' => $langs->trans(
'Modelcsv_winfic'),
253 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
255 self::$EXPORT_TYPE_EBP => array(
256 'label' => $langs->trans(
'Modelcsv_ebp'),
258 self::$EXPORT_TYPE_COGILOG => array(
259 'label' => $langs->trans(
'Modelcsv_cogilog'),
261 self::$EXPORT_TYPE_AGIRIS => array(
262 'label' => $langs->trans(
'Modelcsv_agiris'),
264 self::$EXPORT_TYPE_OPENCONCERTO => array(
265 'label' => $langs->trans(
'Modelcsv_openconcerto'),
267 self::$EXPORT_TYPE_SAGE50_SWISS => array(
268 'label' => $langs->trans(
'Modelcsv_Sage50_Swiss'),
270 self::$EXPORT_TYPE_CHARLEMAGNE => array(
271 'label' => $langs->trans(
'Modelcsv_charlemagne'),
272 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
274 self::$EXPORT_TYPE_LDCOMPTA => array(
275 'label' => $langs->trans(
'Modelcsv_LDCompta'),
277 self::$EXPORT_TYPE_LDCOMPTA10 => array(
278 'label' => $langs->trans(
'Modelcsv_LDCompta10'),
280 self::$EXPORT_TYPE_GESTIMUMV3 => array(
281 'label' => $langs->trans(
'Modelcsv_Gestinumv3'),
282 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
284 self::$EXPORT_TYPE_GESTIMUMV5 => array(
285 'label' => $langs->trans(
'Modelcsv_Gestinumv5'),
286 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
288 self::$EXPORT_TYPE_FEC => array(
289 'label' => $langs->trans(
'Modelcsv_FEC'),
290 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
292 self::$EXPORT_TYPE_FEC2 => array(
293 'label' => $langs->trans(
'Modelcsv_FEC2'),
294 'ACCOUNTING_EXPORT_FORMAT' =>
'txt',
296 self::$EXPORT_TYPE_ISUITEEXPERT => array(
297 'label' =>
'iSuite Expert',
298 'ACCOUNTING_EXPORT_FORMAT' =>
'csv',
302 '1' => $langs->trans(
"Unix"),
303 '2' => $langs->trans(
"Windows")
306 'csv' => $langs->trans(
"csv"),
307 'txt' => $langs->trans(
"txt")
312 $parameters = array();
313 $reshook = $hookmanager->executeHooks(
'getTypeConfig', $parameters, $exporttypes);
326 switch ($formatexportset) {
327 case self::$EXPORT_TYPE_FEC:
328 $mime =
'text/tab-separated-values';
355 public function export(&$TData, $formatexportset, $withAttachment = 0, $downloadMode = 0, $outputMode = 0, $noouput = 0)
357 global $db, $conf, $langs;
358 global $search_date_end;
361 $filename =
'general_ledger-'.$this->getFormatCode($formatexportset);
362 $type_export =
'general_ledger';
364 $completefilename =
'';
366 $exportFileName =
'';
367 $exportFilePath =
'';
368 $exportFileFullName =
'';
369 $downloadFileMimeType =
'';
370 $downloadFileFullName =
'';
371 $downloadFilePath =
'';
372 $archiveFullName =
'';
374 $archiveFileList = array();
375 if ($withAttachment == 1) {
376 if ($downloadMode == 0) {
379 if ($outputMode == 0) {
384 if (!extension_loaded(
'zip')) {
385 $langs->load(
'install');
386 $this->errors[] = $langs->trans(
'ErrorPHPDoesNotSupport',
'ZIP');
392 if ($downloadMode == 0) {
397 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
399 if ($outputMode == 1 || $outputMode == 2) {
400 if ($outputMode == 1) {
402 if (!empty($conf->accounting->multidir_temp[$conf->entity])) {
403 $outputDir = $conf->accounting->multidir_temp[$conf->entity];
405 $outputDir = $conf->accounting->dir_temp;
409 if (!empty($conf->accounting->multidir_output[$conf->entity])) {
410 $outputDir = $conf->accounting->multidir_output[$conf->entity];
412 $outputDir = $conf->accounting->dir_output;
416 $outputDir .=
'/export';
417 $outputDir .=
'/'.dol_sanitizePathName($formatexportset);
422 $this->errors[] = $langs->trans(
'ErrorCanNotCreateDir', $outputDir);
427 if ($outputDir !=
'') {
429 $langs->load(
'errors');
430 $this->errors[] = $langs->trans(
'ErrorDirNotFound', $outputDir);
434 if (!empty($completefilename)) {
436 $exportFileFullName = $completefilename;
437 $exportFileBaseName = basename($exportFileFullName);
438 $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME);
439 $exportFilePath = $outputDir .
'/' . $exportFileFullName;
440 $exportFile = fopen($exportFilePath,
'w');
442 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $exportFilePath);
446 if ($withAttachment == 1) {
447 $archiveFileList[0] = array(
448 'path' => $exportFilePath,
449 'name' => $exportFileFullName,
453 $archiveFullName = $exportFileName .
'.zip';
454 $archivePath = $outputDir .
'/' . $archiveFullName;
461 switch ($formatexportset) {
462 case self::$EXPORT_TYPE_CONFIGURABLE:
465 case self::$EXPORT_TYPE_CEGID:
468 case self::$EXPORT_TYPE_COALA:
471 case self::$EXPORT_TYPE_BOB50:
474 case self::$EXPORT_TYPE_CIEL:
477 case self::$EXPORT_TYPE_QUADRATUS:
478 $archiveFileList = $this->
exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment);
480 case self::$EXPORT_TYPE_WINFIC:
483 case self::$EXPORT_TYPE_EBP:
486 case self::$EXPORT_TYPE_COGILOG:
489 case self::$EXPORT_TYPE_AGIRIS:
492 case self::$EXPORT_TYPE_OPENCONCERTO:
495 case self::$EXPORT_TYPE_SAGE50_SWISS:
498 case self::$EXPORT_TYPE_CHARLEMAGNE:
501 case self::$EXPORT_TYPE_LDCOMPTA:
504 case self::$EXPORT_TYPE_LDCOMPTA10:
507 case self::$EXPORT_TYPE_GESTIMUMV3:
510 case self::$EXPORT_TYPE_GESTIMUMV5:
513 case self::$EXPORT_TYPE_FEC:
514 $archiveFileList = $this->
exportFEC($TData, $exportFile, $archiveFileList, $withAttachment);
516 case self::$EXPORT_TYPE_FEC2:
517 $archiveFileList = $this->
exportFEC2($TData, $exportFile, $archiveFileList, $withAttachment);
519 case self::$EXPORT_TYPE_ISUITEEXPERT:
524 $parameters = array(
'format' => $formatexportset);
526 $reshook = $hookmanager->executeHooks(
'export', $parameters, $TData);
528 $this->errors[] = $langs->trans(
'accountancy_error_modelnotfound');
535 if ($outputMode == 1 || $outputMode == 2) {
543 if ($withAttachment == 1) {
545 if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
547 $downloadFileMimeType =
'application/zip';
548 $downloadFileFullName = $archiveFullName;
549 $downloadFilePath = $archivePath;
552 $archive =
new ZipArchive();
553 $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
556 $this->errors[] = $langs->trans(
'ErrorFileNotFound', $archivePath);
560 foreach ($archiveFileList as $archiveFileArr) {
561 $res = $archive->addFile($archiveFileArr[
'path'], $archiveFileArr[
'name']);
564 $this->errors[] = $langs->trans(
'ErrorArchiveAddFile', $archiveFileArr[
'name']);
578 if ($downloadMode == 1) {
579 if ($withAttachment == 0) {
581 if (!empty($exportFileFullName) && !empty($exportFilePath)) {
582 $downloadFileMimeType = $mimetype;
583 $downloadFileFullName = $exportFileFullName;
584 $downloadFilePath = $exportFilePath;
589 if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath) && empty($noouput)) {
592 header(
'Content-Type: ' . $downloadFileMimeType);
593 header(
'Content-Disposition: attachment; filename=' . $downloadFileFullName);
594 header(
'Cache-Control: Public, must-revalidate');
595 header(
'Pragma: public');
596 header(
'Content-Length: ' .
dol_filesize($downloadFilePath));
601 $this->generatedfiledata = array(
'downloadFilePath' => $downloadFilePath,
'downloadFileMimeType' => $downloadFileMimeType,
'downloadFileFullName' => $downloadFileFullName);
626 foreach ($objectLines as $line) {
631 $tab[] = $date_document;
632 $tab[] = $line->code_journal;
635 $tab[] = $line->sens;
636 $tab[] =
price2fec(abs($line->debit - $line->credit));
640 $output = implode($separator, $tab).$end_line;
642 fwrite($exportFile, $output);
662 foreach ($objectLines as $line) {
666 if ($line->doc_type ==
'customer_invoice') {
668 require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
669 $invoice =
new Facture($this->db);
670 $invoice->fetch($line->fk_doc);
672 $refInvoice = $invoice->ref;
673 } elseif ($line->doc_type ==
'supplier_invoice') {
675 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture.class.php';
677 $invoice->fetch($line->fk_doc);
679 $refInvoice = $invoice->ref_supplier;
684 $tab[] = $line->code_journal;
685 $tab[] = $date_document;
686 $tab[] = $refInvoice;
687 if (empty($line->subledger_account)) {
693 $tab[] = $line->label_operation;
694 $tab[] = $date_document;
695 if ($line->sens ==
'D') {
696 $tab[] =
price($line->debit);
698 } elseif ($line->sens ==
'C') {
700 $tab[] =
price($line->credit);
702 $tab[] = $line->doc_ref;
703 $tab[] = $line->label_operation;
705 $output = implode($separator, $tab).$end_line;
707 fwrite($exportFile, $output);
727 foreach ($objectLines as $line) {
732 $tab[] = $date_document;
733 $tab[] = $line->code_journal;
735 $tab[] = $line->piece_num;
736 $tab[] = $line->doc_ref;
737 $tab[] =
price($line->debit);
738 $tab[] =
price($line->credit);
742 $output = implode($separator, $tab).$end_line;
744 fwrite($exportFile, $output);
764 foreach ($objectLines as $line) {
769 $tab[] = $line->piece_num;
770 $tab[] = $date_document;
772 if (empty($line->subledger_account)) {
776 if (substr($line->numero_compte, 0, 3) ==
'411') {
779 if (substr($line->numero_compte, 0, 3) ==
'401') {
785 $tab[] =
price($line->debit);
786 $tab[] =
price($line->credit);
787 $tab[] =
dol_trunc($line->label_operation, 32);
789 $output = implode($separator, $tab).$end_line;
791 fwrite($exportFile, $output);
819 foreach ($objectLines as $line) {
821 if (!empty($line->subledger_account)) {
826 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
830 $tab[] = str_pad($line->piece_num, 5);
831 $tab[] = str_pad(self::trunc($line->code_journal, 2), 2);
832 $tab[] = str_pad($date_document, 8,
' ', STR_PAD_LEFT);
833 $tab[] = str_pad($date_echeance, 8,
' ', STR_PAD_LEFT);
834 $tab[] = str_pad(self::trunc($line->doc_ref, 12), 12);
835 $tab[] = str_pad(self::trunc($code_compta, 11), 11);
836 $tab[] = str_pad(self::trunc(
dol_string_unaccent($line->doc_ref).dol_string_unaccent($line->label_operation), 25), 25);
837 $tab[] = str_pad(
price2fec(abs($line->debit - $line->credit)), 13,
' ', STR_PAD_LEFT);
838 $tab[] = str_pad($line->sens, 1);
839 $tab[] = str_repeat(
' ', 18);
843 $output = implode($tab).$end_line;
845 fwrite($exportFile, $output);
868 public function exportQuadratus($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
875 foreach ($objectLines as $line) {
879 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
880 $line->label_operation = str_replace(array(
"- ",
"…",
"..."),
"", $line->label_operation);
887 $line->subledger_label = str_replace(array(
"- ",
"…",
"..."),
"", $line->subledger_label);
890 $code_compta = $line->numero_compte;
891 if (!empty($line->subledger_account)) {
892 $code_compta = $line->subledger_account;
897 if (!empty($line->subledger_account)) {
898 $tab[
'type_ligne'] =
'C';
899 $tab[
'num_compte'] = str_pad(self::trunc($line->subledger_account, 8), 8);
900 $tab[
'lib_compte'] = str_pad(self::trunc($line->subledger_label, 30), 30);
902 if ($line->doc_type ==
'customer_invoice') {
903 $tab[
'lib_alpha'] = strtoupper(str_pad(
'C'.self::trunc(
dol_string_unaccent($line->subledger_label), 6), 7));
904 $tab[
'filler'] = str_repeat(
' ', 52);
905 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_CUSTOMER'), 8), 8);
906 } elseif ($line->doc_type ==
'supplier_invoice') {
907 $tab[
'lib_alpha'] = strtoupper(str_pad(
'F'.self::trunc(
dol_string_unaccent($line->subledger_label), 6), 7));
908 $tab[
'filler'] = str_repeat(
' ', 52);
909 $tab[
'coll_compte'] = str_pad(self::trunc(
getDolGlobalString(
'ACCOUNTING_ACCOUNT_SUPPLIER'), 8), 8);
911 $tab[
'filler'] = str_repeat(
' ', 59);
912 $tab[
'coll_compte'] = str_pad(
' ', 8);
915 $tab[
'filler2'] = str_repeat(
' ', 110);
918 if ($line->doc_type ==
'customer_invoice') {
919 $tab[
'type_compte'] =
'C';
920 } elseif ($line->doc_type ==
'supplier_invoice') {
921 $tab[
'type_compte'] =
'F';
923 $tab[
'type_compte'] =
'G';
926 $tab[
'filler3'] = str_repeat(
' ', 235);
928 $tab[
'end_line'] = $end_line;
931 fwrite($exportFile, implode($tab));
938 $tab[
'type_ligne'] =
'M';
939 $tab[
'num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
940 $tab[
'code_journal'] = str_pad(self::trunc($line->code_journal, 2), 2);
941 $tab[
'folio'] =
'000';
946 $tab[
'date_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
947 $tab[
'filler'] =
' ';
948 $tab[
'libelle_ecriture'] = str_pad(self::trunc($line->doc_ref.
' '.$line->label_operation, 20), 20);
963 $tab[
'sens'] = $line->sens;
964 $tab[
'signe_montant'] =
'+';
967 $tab[
'montant'] = str_pad((
string) abs(($line->debit - $line->credit) * 100), 12,
'0', STR_PAD_LEFT);
968 $tab[
'contrepartie'] = str_repeat(
' ', 8);
971 if (!empty($line->date_lim_reglement)) {
972 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%y');
974 $tab[
'date_echeance'] =
'000000';
979 $tab[
'lettrage'] = str_repeat(
' ', 2);
980 $tab[
'codestat'] = str_repeat(
' ', 3);
981 $tab[
'num_piece'] = str_pad(self::trunc($line->piece_num, 5), 5);
985 $tab[
'affaire'] = str_repeat(
' ', 10);
986 $tab[
'quantity1'] = str_repeat(
' ', 10);
987 $tab[
'num_piece2'] = str_pad(self::trunc($line->piece_num, 8), 8);
988 $tab[
'devis'] = str_pad($conf->currency, 3);
989 $tab[
'code_journal2'] = str_pad(self::trunc($line->code_journal, 3), 3);
990 $tab[
'filler3'] = str_repeat(
' ', 3);
998 $tab[
'libelle_ecriture2'] = str_pad(self::trunc($line->label_operation, 30), 30);
999 $tab[
'codetva'] = str_repeat(
' ', 2);
1003 $tab[
'num_piece3'] = substr(self::trunc($line->doc_ref, 20), -10);
1004 $tab[
'reserved'] = str_repeat(
' ', 10);
1005 $tab[
'currency_amount'] = str_repeat(
' ', 13);
1007 $attachmentFileName =
'';
1008 if ($withAttachment == 1) {
1009 $attachmentFileKey = trim($line->piece_num);
1011 if (!isset($archiveFileList[$attachmentFileKey])) {
1012 $objectDirPath =
'';
1014 if ($line->doc_type ==
'customer_invoice') {
1015 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1016 } elseif ($line->doc_type ==
'expense_report') {
1017 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1018 } elseif ($line->doc_type ==
'supplier_invoice') {
1019 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1021 $invoice->fetch($line->fk_doc);
1022 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1023 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1025 $arrayofinclusion = array();
1027 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1028 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0,
true);
1029 if (!empty($fileFoundList)) {
1030 $attachmentFileNameTrunc = str_pad(self::trunc($line->piece_num, 8), 8,
'0', STR_PAD_LEFT);
1031 foreach ($fileFoundList as $fileFound) {
1032 if (strstr($fileFound[
'name'], $objectFileName)) {
1035 if ($line->doc_type ==
'supplier_invoice') {
1036 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1039 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1042 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1043 if (file_exists($fileFoundPath)) {
1044 $archiveFileList[$attachmentFileKey] = array(
1045 'path' => $fileFoundPath,
1046 'name' => $attachmentFileNameTrunc.
'.pdf',
1055 if (isset($archiveFileList[$attachmentFileKey])) {
1056 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1060 $tab[
'attachment'] = $attachmentFileName;
1062 $tab[
'attachment'] = str_repeat(
' ', 12);
1064 $tab[
'filler4'] = str_repeat(
' ', 38);
1065 $tab[
'end_line'] = $end_line;
1068 fwrite($exportFile, implode($tab));
1070 print implode($tab);
1074 return $archiveFileList;
1096 foreach ($objectLines as $line) {
1097 $code_compta = $line->numero_compte;
1098 if (!empty($line->subledger_account)) {
1099 $code_compta = $line->subledger_account;
1104 $tab[
'code_journal'] = str_pad(
dol_trunc($line->code_journal, 2,
'right',
'UTF-8', 1), 2);
1109 $tab[
'date_operation'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1111 $tab[
'folio'] =
' 1';
1113 $tab[
'num_ecriture'] = str_pad(
dol_trunc($index, 6,
'right',
'UTF-8', 1), 6,
' ', STR_PAD_LEFT);
1115 $tab[
'jour_ecriture'] =
dol_print_date($line->doc_date,
'%d%m%y');
1117 $tab[
'num_compte'] = str_pad(
dol_trunc($code_compta, 6,
'right',
'UTF-8', 1), 6,
'0');
1119 if ($line->sens ==
'D') {
1120 $tab[
'montant_debit'] = str_pad(number_format($line->debit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1122 $tab[
'montant_crebit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1124 $tab[
'montant_debit'] = str_pad(number_format(0, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1126 $tab[
'montant_crebit'] = str_pad(number_format($line->credit, 2,
',',
''), 13,
' ', STR_PAD_LEFT);
1131 $tab[
'lettrage'] = str_repeat(
dol_trunc($line->lettering_code, 2,
'left',
'UTF-8', 1), 2);
1133 $tab[
'code_piece'] = str_pad(
dol_trunc($line->piece_num, 5,
'left',
'UTF-8', 1), 5,
' ', STR_PAD_LEFT);
1135 $tab[
'code_stat'] = str_repeat(
' ', 4);
1137 if (!empty($line->date_lim_reglement)) {
1138 $tab[
'date_echeance'] =
dol_print_date($line->date_lim_reglement,
'%d%m%Y');
1140 $tab[
'date_echeance'] =
dol_print_date($line->doc_date,
'%d%m%Y');
1143 $tab[
'monnaie'] =
'1';
1145 $tab[
'filler'] =
' ';
1147 $tab[
'ind_compteur'] =
' ';
1149 $tab[
'quantite'] =
'0,000000000';
1151 $tab[
'code_pointage'] = str_repeat(
' ', 2);
1153 $tab[
'end_line'] = $end_line;
1155 print implode(
'|', $tab);
1174 foreach ($objectLines as $line) {
1180 $tab[] = $date_document;
1181 $tab[] = $line->code_journal;
1182 if (empty($line->subledger_account)) {
1183 $tab[] = $line->numero_compte;
1185 $tab[] = $line->subledger_account;
1188 $tab[] =
'"'.dol_trunc($line->label_operation, 40,
'right',
'UTF-8', 1).
'"';
1189 $tab[] =
'"'.dol_trunc($line->piece_num, 15,
'right',
'UTF-8', 1).
'"';
1190 $tab[] =
price2num(abs($line->debit - $line->credit));
1191 $tab[] = $line->sens;
1192 $tab[] = $date_document;
1195 $output = implode($separator, $tab).$end_line;
1197 fwrite($exportFile, $output);
1217 foreach ($objectLines as $line) {
1222 $tab[] = $line->piece_num;
1224 $tab[] = $date_document;
1227 if (empty($line->subledger_account)) {
1236 $tab[] =
price($line->debit);
1237 $tab[] =
price($line->credit);
1238 $tab[] =
price(abs($line->debit - $line->credit));
1239 $tab[] = $line->sens;
1240 $tab[] = $line->lettering_code;
1241 $tab[] = $line->code_journal;
1243 $output = implode($separator, $tab).$end_line;
1245 fwrite($exportFile, $output);
1264 foreach ($objectLines as $line) {
1269 $tab[] = $date_document;
1270 $tab[] = $line->code_journal;
1271 if (empty($line->subledger_account)) {
1276 $tab[] = $line->doc_ref;
1277 $tab[] = $line->label_operation;
1278 $tab[] =
price($line->debit);
1279 $tab[] =
price($line->credit);
1281 $output = implode($separator, $tab).$end_line;
1283 fwrite($exportFile, $output);
1301 $separator = $this->separator;
1303 foreach ($objectLines as $line) {
1308 $tab[] = $line->piece_num;
1309 $tab[] = $date_document;
1310 $tab[] = $line->doc_ref;
1311 $tab[] = preg_match(
'/'.$separator.
'/', $line->label_operation) ?
"'".$line->label_operation.
"'" : $line->label_operation;
1316 $tab[] =
price2num($line->debit - $line->credit);
1317 $tab[] = $line->code_journal;
1319 $output = implode($separator, $tab).$this->end_line;
1321 fwrite($exportFile, $output);
1340 public function exportFEC($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1342 global $conf, $langs;
1348 $tab[] =
"JournalCode";
1349 $tab[] =
"JournalLib";
1350 $tab[] =
"EcritureNum";
1351 $tab[] =
"EcritureDate";
1352 $tab[] =
"CompteNum";
1353 $tab[] =
"CompteLib";
1354 $tab[] =
"CompAuxNum";
1355 $tab[] =
"CompAuxLib";
1356 $tab[] =
"PieceRef";
1357 $tab[] =
"PieceDate";
1358 $tab[] =
"EcritureLib";
1361 $tab[] =
"EcritureLet";
1363 $tab[] =
"ValidDate";
1364 $tab[] =
"Montantdevise";
1366 $tab[] =
"DateLimitReglmt";
1367 $tab[] =
"NumFacture";
1368 $tab[] =
"FichierFacture";
1370 $output = implode($separator, $tab).$end_line;
1372 fwrite($exportFile, $output);
1377 foreach ($objectLines as $line) {
1378 if ($line->debit == 0 && $line->credit == 0) {
1384 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1385 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1386 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1389 if ($line->doc_type ==
'customer_invoice') {
1391 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1392 $invoice =
new Facture($this->db);
1393 $invoice->fetch($line->fk_doc);
1395 $refInvoice = $invoice->ref;
1396 } elseif ($line->doc_type ==
'supplier_invoice') {
1398 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1400 $invoice->fetch($line->fk_doc);
1402 $refInvoice = $invoice->ref_supplier;
1408 $tab[] = $line->code_journal;
1413 $tab[] = $labeljournal;
1416 $tab[] = $line->piece_num;
1419 $tab[] = $date_document;
1434 $tab[] = $line->doc_ref;
1441 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1442 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1452 $tab[] = $line->lettering_code;
1455 $tab[] = $date_lettering;
1458 $tab[] = $date_validation;
1461 $tab[] = $line->multicurrency_amount;
1464 $tab[] = $line->multicurrency_code;
1467 $tab[] = $date_limit_payment;
1471 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1472 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1476 $attachmentFileName =
'';
1477 if ($withAttachment == 1) {
1478 $attachmentFileKey = trim($line->piece_num);
1480 if (!isset($archiveFileList[$attachmentFileKey])) {
1481 $objectDirPath =
'';
1483 if ($line->doc_type ==
'customer_invoice') {
1484 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1485 } elseif ($line->doc_type ==
'expense_report') {
1486 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1487 } elseif ($line->doc_type ==
'supplier_invoice') {
1488 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1489 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1491 $arrayofinclusion = array();
1493 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1494 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0,
true);
1495 if (!empty($fileFoundList)) {
1496 $attachmentFileNameTrunc = $line->doc_ref;
1497 foreach ($fileFoundList as $fileFound) {
1498 if (strstr($fileFound[
'name'], $objectFileName)) {
1501 if ($line->doc_type ==
'supplier_invoice') {
1502 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1505 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1508 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1509 if (file_exists($fileFoundPath)) {
1510 $archiveFileList[$attachmentFileKey] = array(
1511 'path' => $fileFoundPath,
1512 'name' => $attachmentFileNameTrunc.
'.pdf',
1521 if (isset($archiveFileList[$attachmentFileKey])) {
1522 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1526 $tab[] = $attachmentFileName;
1528 $output = implode($separator, $tab).$end_line;
1531 fwrite($exportFile, $output);
1538 return $archiveFileList;
1553 public function exportFEC2($objectLines, $exportFile =
null, $archiveFileList = array(), $withAttachment = 0)
1555 global $conf, $langs;
1561 $tab[] =
"JournalCode";
1562 $tab[] =
"JournalLib";
1563 $tab[] =
"EcritureNum";
1564 $tab[] =
"EcritureDate";
1565 $tab[] =
"CompteNum";
1566 $tab[] =
"CompteLib";
1567 $tab[] =
"CompAuxNum";
1568 $tab[] =
"CompAuxLib";
1569 $tab[] =
"PieceRef";
1570 $tab[] =
"PieceDate";
1571 $tab[] =
"EcritureLib";
1574 $tab[] =
"EcritureLet";
1576 $tab[] =
"ValidDate";
1577 $tab[] =
"Montantdevise";
1579 $tab[] =
"DateLimitReglmt";
1580 $tab[] =
"NumFacture";
1581 $tab[] =
"FichierFacture";
1583 $output = implode($separator, $tab).$end_line;
1585 fwrite($exportFile, $output);
1590 foreach ($objectLines as $line) {
1591 if ($line->debit == 0 && $line->credit == 0) {
1596 $date_lettering =
dol_print_date($line->date_lettering,
'%Y%m%d');
1597 $date_validation =
dol_print_date($line->date_validation,
'%Y%m%d');
1598 $date_limit_payment =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1601 if ($line->doc_type ==
'customer_invoice') {
1603 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1604 $invoice =
new Facture($this->db);
1605 $invoice->fetch($line->fk_doc);
1607 $refInvoice = $invoice->ref;
1608 } elseif ($line->doc_type ==
'supplier_invoice') {
1610 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1612 $invoice->fetch($line->fk_doc);
1614 $refInvoice = $invoice->ref_supplier;
1620 $tab[] = $line->code_journal;
1625 $tab[] = $labeljournal;
1628 $tab[] = $line->piece_num;
1631 $tab[] = $date_creation;
1646 $tab[] = $line->doc_ref;
1649 $tab[] = $date_document;
1653 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
1654 $line->label_operation = str_replace(array(
"..."),
"", $line->label_operation);
1664 $tab[] = $line->lettering_code;
1667 $tab[] = $date_lettering;
1670 $tab[] = $date_validation;
1673 $tab[] = $line->multicurrency_amount;
1676 $tab[] = $line->multicurrency_code;
1679 $tab[] = $date_limit_payment;
1683 $refInvoice = str_replace(array(
"\t",
"\n",
"\r"),
" ", $refInvoice);
1684 $tab[] =
dol_trunc(self::toAnsi($refInvoice), 17,
'right',
'UTF-8', 1);
1688 $attachmentFileName =
'';
1689 if ($withAttachment == 1) {
1690 $attachmentFileKey = trim($line->piece_num);
1692 if (!isset($archiveFileList[$attachmentFileKey])) {
1693 $objectDirPath =
'';
1695 if ($line->doc_type ==
'customer_invoice') {
1696 $objectDirPath = !empty($conf->invoice->multidir_output[$conf->entity]) ? $conf->invoice->multidir_output[$conf->entity] : $conf->invoice->dir_output;
1697 } elseif ($line->doc_type ==
'expense_report') {
1698 $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->expensereport->dir_output;
1699 } elseif ($line->doc_type ==
'supplier_invoice') {
1700 $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
1701 $objectDirPath .=
'/'.rtrim(
get_exdir($invoice->id, 2, 0, 0, $invoice,
'invoice_supplier'),
'/');
1703 $arrayofinclusion = array();
1705 $arrayofinclusion[] =
'^'.preg_quote($objectFileName,
'/').(($line->doc_type ==
'supplier_invoice') ?
'.+' :
'').
'\.pdf$';
1706 $fileFoundList =
dol_dir_list($objectDirPath.
'/'.$objectFileName,
'files', 0, implode(
'|', $arrayofinclusion),
'(\.meta|_preview.*\.png)$',
'date', SORT_DESC, 0,
true);
1707 if (!empty($fileFoundList)) {
1708 $attachmentFileNameTrunc = $line->doc_ref;
1709 foreach ($fileFoundList as $fileFound) {
1710 if (strstr($fileFound[
'name'], $objectFileName)) {
1713 if ($line->doc_type ==
'supplier_invoice') {
1714 if ($fileFound[
'name'] === $objectFileName.
'.pdf') {
1717 } elseif ($fileFound[
'name'] !== $objectFileName.
'.pdf') {
1720 $fileFoundPath = $objectDirPath.
'/'.$objectFileName.
'/'.$fileFound[
'name'];
1721 if (file_exists($fileFoundPath)) {
1722 $archiveFileList[$attachmentFileKey] = array(
1723 'path' => $fileFoundPath,
1724 'name' => $attachmentFileNameTrunc.
'.pdf',
1733 if (isset($archiveFileList[$attachmentFileKey])) {
1734 $attachmentFileName = $archiveFileList[$attachmentFileKey][
'name'];
1738 $tab[] = $attachmentFileName;
1740 $output = implode($separator, $tab).$end_line;
1742 fwrite($exportFile, $output);
1749 return $archiveFileList;
1785 $tab[] =
"FW-Betrag";
1792 $output = implode($separator, $tab).$end_line;
1794 fwrite($exportFile, $output);
1800 $thisPieceAccountNr =
"";
1801 $aSize = count($objectLines);
1802 foreach ($objectLines as $aIndex => $line) {
1803 $sammelBuchung =
false;
1804 if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
1805 $sammelBuchung =
true;
1806 } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
1807 $sammelBuchung =
true;
1808 } elseif ($aIndex + 1 < $aSize
1809 && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
1810 && $aIndex - 1 < $aSize
1811 && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
1813 $sammelBuchung =
true;
1819 $tab[] = $line->piece_num;
1823 $tab[] = $date_document;
1828 if ($line->sens ==
'D') {
1836 if (empty($line->code_tiers)) {
1837 if ($line->piece_num == $thisPieceNum) {
1846 $tab[] = $this->separator;
1855 if ($sammelBuchung) {
1863 $tab[] = abs($line->debit - $line->credit);
1870 if ($line1 ==
"LIQ" || $line1 ==
"LIQ Beleg ok" || strlen($line1) <= 3) {
1874 if (strlen($line1) == 0) {
1878 if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
1879 $line1 = $line1.
' / '.$line2;
1883 $tab[] =
'"'.self::toAnsi($line1).
'"';
1885 $tab[] =
'"'.self::toAnsi($line2).
'"';
1889 $tab[] = $this->separator;
1894 $output = implode($separator, $tab).$end_line;
1896 fwrite($exportFile, $output);
1901 if ($line->piece_num !== $thisPieceNum) {
1902 $thisPieceNum = $line->piece_num;
1903 $thisPieceAccountNr = $line->numero_compte;
1921 foreach ($objectLines as $line) {
1924 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
1929 $type_enregistrement =
'E';
1930 $tab[] = $type_enregistrement;
1932 $tab[] = substr($line->code_journal, 0, 2);
1936 $tab[] = $line->piece_num;
1938 $tab[] = $date_document;
1940 $tab[] = $line->label_operation;
1942 $tab[] = $date_lim_reglement;
1944 if ($line->doc_type ==
'supplier_invoice') {
1945 if (($line->debit - $line->credit) > 0) {
1946 $nature_piece =
'AF';
1948 $nature_piece =
'FF';
1950 } elseif ($line->doc_type ==
'customer_invoice') {
1951 if (($line->debit - $line->credit) < 0) {
1952 $nature_piece =
'AC';
1954 $nature_piece =
'FC';
1959 $tab[] = $nature_piece;
1970 $racine_subledger_account =
'';
1973 $tab[] = $racine_subledger_account;
1975 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2, 2);
1977 $tab[] = $line->sens;
1981 $tab[] = $date_creation;
1983 $tab[] = $line->lettering_code;
1985 $tab[] = $line->date_lettering;
1987 if (!empty($line->subledger_account)) {
1993 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
1995 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2009 $tab[] = $line->doc_ref;
2037 $output = implode($separator, $tab).$end_line;
2039 fwrite($exportFile, $output);
2058 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2062 $last_codeinvoice =
'';
2064 foreach ($objectLines as $line) {
2066 if ($last_codeinvoice != $line->doc_ref) {
2068 $sql =
"SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX.
"societe";
2069 $sql .=
" WHERE code_client = '".$this->db->escape($line->thirdparty_code).
"'";
2070 $resql = $this->db->query($sql);
2072 if ($resql && $this->db->num_rows($resql) > 0) {
2073 $soc = $this->db->fetch_object($resql);
2075 $address = array(
'',
'',
'');
2076 if (strpos($soc->address,
"\n") !==
false) {
2077 $address = explode(
"\n", $soc->address);
2078 if (is_array($address) && count($address) > 0) {
2079 foreach ($address as $key => $data) {
2080 $address[$key] = str_replace(array(
"\t",
"\n",
"\r"),
"", $data);
2081 $address[$key] =
dol_trunc($address[$key], 40,
'right',
'UTF-8', 1);
2085 $address[0] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 0, 40);
2086 $address[1] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 41, 40);
2087 $address[2] = substr(str_replace(array(
"\t",
"\r"),
" ", $soc->address), 82, 40);
2092 $type_enregistrement =
'C';
2094 $tab[] = $type_enregistrement;
2096 $tab[] = $soc->code_client;
2106 $tab[] = $address[0];
2108 $tab[] = $address[1];
2110 $tab[] = $address[2];
2114 $tab[] = substr($soc->town, 0, 40);
2118 $tab[] = substr(
getCountry($soc->fk_pays), 0, 40);
2120 $tab[] = $soc->phone;
2132 $tab[] = str_replace(
" ",
"", $soc->siret);
2190 $output = implode($separator, $tab).$end_line;
2192 fwrite($exportFile, $output);
2203 $date_lim_reglement =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2206 $type_enregistrement =
'E';
2207 $tab[] = $type_enregistrement;
2209 $tab[] = substr($line->code_journal, 0, 2);
2213 $tab[] = $line->piece_num;
2215 $tab[] = $date_document;
2217 $tab[] =
dol_trunc($line->label_operation, 25,
'right',
'UTF-8', 1);
2219 $tab[] = $date_lim_reglement;
2221 if ($line->doc_type ==
'supplier_invoice') {
2222 if (($line->amount) < 0) {
2223 $nature_piece =
'AF';
2225 $nature_piece =
'FF';
2227 } elseif ($line->doc_type ==
'customer_invoice') {
2228 if (($line->amount) < 0) {
2229 $nature_piece =
'AC';
2231 $nature_piece =
'FC';
2236 $tab[] = $nature_piece;
2247 $racine_subledger_account =
'';
2250 $tab[] = $racine_subledger_account;
2252 $tab[] =
price(abs($line->debit - $line->credit), 0,
'', 1, 2);
2254 $tab[] = $line->sens;
2258 $tab[] = $date_document;
2260 $tab[] = $line->lettering_code;
2262 $tab[] = $line->date_lettering;
2264 if (!empty($line->subledger_account)) {
2270 if ($line->doc_type ==
'supplier_invoice' && !empty($line->subledger_account)) {
2272 } elseif ($line->doc_type ==
'customer_invoice' && !empty($line->subledger_account)) {
2284 $tab[] = $line->doc_ref;
2318 $output = implode($separator, $tab).$end_line;
2320 fwrite($exportFile, $output);
2325 $last_codeinvoice = $line->doc_ref;
2339 $langs->load(
'compta');
2346 $tab[] = $langs->transnoentitiesnoconv(
'Date');
2347 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Journal'), 6);
2348 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Account'), 15);
2349 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelAccount'), 60);
2350 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Piece'), 20);
2351 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'LabelOperation'), 60);
2352 $tab[] = $langs->transnoentitiesnoconv(
'Amount');
2354 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 1', 15);
2355 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 1', 60);
2356 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 2', 15);
2357 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 2', 60);
2358 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'Analytic').
' 3', 15);
2359 $tab[] =
self::trunc($langs->transnoentitiesnoconv(
'AnalyticLabel').
' 3', 60);
2361 $output = implode($separator, $tab).$end_line;
2363 fwrite($exportFile, $output);
2368 foreach ($objectLines as $line) {
2373 $tab[] = $date_document;
2377 if (!empty($line->subledger_account)) {
2378 $account = $line->subledger_account;
2380 $account = $line->numero_compte;
2387 $line->label_operation = str_replace(array(
"\t",
"\n",
"\r"),
" ", $line->label_operation);
2389 $tab[] =
price(abs($line->debit - $line->credit));
2390 $tab[] = $line->sens;
2398 $output = implode($separator, $tab).$end_line;
2400 fwrite($exportFile, $output);
2421 $invoices_infos = array();
2422 $supplier_invoices_infos = array();
2423 foreach ($objectLines as $line) {
2424 if ($line->debit == 0 && $line->credit == 0) {
2428 $date_echeance =
dol_print_date($line->date_lim_reglement,
'%Y%m%d');
2430 $invoice_ref = $line->doc_ref;
2433 if (($line->doc_type ==
'customer_invoice' || $line->doc_type ==
'supplier_invoice') && $line->fk_doc > 0) {
2434 if (($line->doc_type ==
'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
2435 ($line->doc_type ==
'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
2436 if ($line->doc_type ==
'customer_invoice') {
2438 $sql =
'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture as f';
2439 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON f.fk_soc = s.rowid';
2440 $sql .=
' WHERE f.rowid = '.((int) $line->fk_doc);
2441 $resql = $this->db->query($sql);
2443 if ($obj = $this->db->fetch_object($resql)) {
2445 $invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2446 $invoice_ref = $obj->ref;
2447 $company_name = $obj->nom;
2452 $sql =
'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX .
'facture_fourn as ff';
2453 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'societe AS s ON ff.fk_soc = s.rowid';
2454 $sql .=
' WHERE ff.rowid = '.((int) $line->fk_doc);
2455 $resql = $this->db->query($sql);
2457 if ($obj = $this->db->fetch_object($resql)) {
2459 $supplier_invoices_infos[$line->fk_doc] = array(
'ref' => $obj->ref,
'company_name' => $obj->nom);
2460 $invoice_ref = $obj->ref;
2461 $company_name = $obj->nom;
2465 } elseif ($line->doc_type ==
'customer_invoice') {
2467 $invoice_ref = $invoices_infos[$line->fk_doc][
'ref'];
2468 $company_name = $invoices_infos[$line->fk_doc][
'company_name'];
2471 $invoice_ref = $supplier_invoices_infos[$line->fk_doc][
'ref'];
2472 $company_name = $supplier_invoices_infos[$line->fk_doc][
'company_name'];
2479 $tab[] = $date_document;
2480 $tab[] = substr($line->code_journal, 0, 4);
2482 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2491 $tab[] =
dol_trunc(str_replace(
'"',
'', $invoice_ref . (!empty($company_name) ?
' - ' :
'') . $company_name), 40,
'right',
'UTF-8', 1);
2493 $tab[] =
dol_trunc(str_replace(
'"',
'', $line->piece_num), 10,
'right',
'UTF-8', 1);
2497 $tab[] =
price2num(abs($line->debit - $line->credit));
2499 $tab[] = $line->sens;
2503 $tab[] = $date_echeance;
2505 $output = implode($separator, $tab).$end_line;
2507 fwrite($exportFile, $output);
2527 foreach ($objectLines as $line) {
2528 if ($line->debit == 0 && $line->credit == 0) {
2536 $tab[] = $date_document;
2537 $tab[] = substr($line->code_journal, 0, 4);
2538 if ((substr($line->numero_compte, 0, 3) ==
'411') || (substr($line->numero_compte, 0, 3) ==
'401')) {
2544 $tab[] =
'"'.dol_trunc(str_replace(
'"',
'', $line->label_operation), 40,
'right',
'UTF-8', 1).
'"';
2545 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->doc_ref), 40,
'right',
'UTF-8', 1) .
'"';
2546 $tab[] =
'"' .
dol_trunc(str_replace(
'"',
'', $line->piece_num), 10,
'right',
'UTF-8', 1) .
'"';
2547 $tab[] =
price2num(abs($line->debit - $line->credit));
2548 $tab[] = $line->sens;
2549 $tab[] = $date_document;
2554 $output = implode($separator, $tab).$end_line;
2556 fwrite($exportFile, $output);
2579 foreach ($objectLines as $line) {
2584 $tab[] = $line->piece_num;
2586 $tab[] = substr($date, 6, 4);
2587 $tab[] = substr($date, 3, 2);
2588 $tab[] = substr($date, 0, 2);
2589 $tab[] = $line->doc_ref;
2591 $tab[] = mb_convert_encoding(str_replace(
' - Compte auxiliaire',
'', $line->label_operation),
"Windows-1252",
'UTF-8');
2597 $numero_cpt_client =
'411';
2598 $numero_cpt_fourn =
'401';
2599 for ($i = 1; $i <= ($taille_numero - 3); $i++) {
2600 $numero_cpt_client .=
'0';
2601 $numero_cpt_fourn .=
'0';
2610 $nom_client = explode(
" - ", $line->label_operation);
2611 $tab[] = mb_convert_encoding($nom_client[0],
"Windows-1252",
'UTF-8');
2612 $tab[] =
price($line->debit);
2613 $tab[] =
price($line->credit);
2614 $tab[] =
price($line->montant);
2615 $tab[] = $line->code_journal;
2617 $output = implode($separator, $tab).$end_line;
2619 fwrite($exportFile, $output);
2633 public static function trunc($str, $size)
2635 return dol_trunc($str, $size,
'right',
'UTF-8', 1);
2645 public static function toAnsi($str, $size = -1)
2648 if ($retVal >= 0 && $size >= 0) {
2649 $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.
export(&$TData, $formatexportset, $withAttachment=0, $downloadMode=0, $outputMode=0, $noouput=0)
Function who chose which export to use with the default config, and make the export into a file.
exportCogilog($objectLines, $exportFile=null)
Export format : COGILOG Last review for this format : 2022-07-12 Alexandre Spangaro (aspangaro@open-d...
exportAgiris($objectLines, $exportFile=null)
Export format : Agiris Isacompta.
exportQuadratus($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : Quadratus (Format ASCII) Format since 2015 compatible QuadraCOMPTA Last review for th...
exportWinfic($objectLines, $exportFile=null)
Export format : WinFic - eWinfic - WinSis Compta Last review for this format : 2022-11-01 Alexandre S...
exportSAGE50SWISS($objectLines, $exportFile=null)
Export format : SAGE50SWISS.
exportOpenConcerto($objectLines, $exportFile=null)
Export format : OpenConcerto.
exportEbp($objectLines, $exportFile=null)
Export format : EBP.
exportLDCompta10($objectLines, $exportFile=null)
Export format : LD Compta version 10 & higher Last review for this format : 08-15-2021 Alexandre Span...
exportCharlemagne($objectLines, $exportFile=null)
Export format : Charlemagne.
getTypeConfig()
Array with all export type available (key + label) and parameters for config.
exportFEC($objectLines, $exportFile=null, $archiveFileList=array(), $withAttachment=0)
Export format : FEC Last review for this format : 2023/10/12 Alexandre Spangaro (aspangaro@open-dsi....
exportLDCompta($objectLines, $exportFile=null)
Export format : LD Compta version 9 http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Docu...
exportBob50($objectLines, $exportFile=null)
Export format : BOB50.
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 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.