X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fdatev.pl;h=f3dbc2eb82bea431afafd5befe337076bd39e65c;hb=85d2b8bb3ea47265821098bd4cab73c681d09e92;hp=62a1cf006bdefc084c43414ec606429ad1c7f6db;hpb=081a4f9736f3bc345872be8f61632cbed4a8d9b3;p=kivitendo-erp.git diff --git a/bin/mozilla/datev.pl b/bin/mozilla/datev.pl index 62a1cf006..f3dbc2eb8 100644 --- a/bin/mozilla/datev.pl +++ b/bin/mozilla/datev.pl @@ -25,310 +25,157 @@ # #====================================================================== +use POSIX qw(strftime getcwd); +use Archive::Zip qw(:ERROR_CODES :CONSTANTS); + +use SL::Common; use SL::DATEV; +use strict; + 1; # end of main -sub continue { &{ $form->{nextsub} } } +require "bin/mozilla/common.pl"; + +sub continue { call_sub($main::form->{"nextsub"}); } sub export { - $lxdebug->enter_sub(); - - $form->{title} = $locale->text("DATEX - Export Assistent"); - - DATEV->get_datev_stamm(\%myconfig, \%$form); - $form->header; - - print qq| - - -
{script}> - - - - - - - - - - - - - - - - -
$form->{title}
| . $locale->text("DATEV Angaben") . qq|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| . $locale->text("Beraternummer") . qq|| . $locale->text("DFV-Kennzeichen") . qq|
| . $locale->text("Beratername") . qq|| . $locale->text("Password") . qq|
| . $locale->text("Mandantennummer") . qq|| . $locale->text("Datenträgernummer") . qq|
| - . $locale->text("Kontonummernerweiterung (KNE)") . qq|| . $locale->text("Abrechnungsnummer") . qq|
| - . $locale->text("Export Buchungsdaten") . qq| | - . $locale->text("Export Stammdaten") . qq|
-

- - - -{path}> -{login}> -{password}> - -
- -
- - - -|; - $lxdebug->leave_sub(); + $::lxdebug->enter_sub; + $::auth->assert('datev_export'); + + DATEV->get_datev_stamm(\%::myconfig, $::form); + $::form->header; + print $::form->parse_html_template('datev/export'); + + $::lxdebug->leave_sub; } sub export2 { - $lxdebug->enter_sub(); + $::lxdebug->enter_sub; + $::auth->assert('datev_export'); - if ($form->{exporttype} == 0) { - &export_bewegungsdaten(); + if ($::form->{exporttype} == 0) { + export_bewegungsdaten(); } else { - &export_stammdaten(); + export_stammdaten(); } - $lxdebug->leave_sub(); + $::lxdebug->leave_sub; } sub export_bewegungsdaten { - $lxdebug->enter_sub(); - - $form->{title} = $locale->text("DATEX - Export Assistent"); - - $form->{allemonate} = - qq| - - - - - - - - - - - |; - - $form->{allequartale} = - qq| - - - |; - $form->header; - - print qq| - - -
{script}> - - - - - - - - - - - - - - - - -
$form->{title}
| . $locale->text("Zeitraum") . qq|
- - - - - - - - - - - - - - - - - - - -
 | - . $locale->text('Monat') . qq|
 | - . $locale->text('Quartal') . qq|
 | - . $locale->text('Datum von') . qq|| . $locale->text('bis') . qq|
-

- - - - - - - - - - - - - - -{path}> -{login}> -{password}> - -
- -
- - - -|; - - $lxdebug->leave_sub(); + $::lxdebug->enter_sub; + $::auth->assert('datev_export'); + + $::form->header; + print $::form->parse_html_template('datev/export_bewegungsdaten'); + + $::lxdebug->leave_sub; } sub export_stammdaten { - $lxdebug->enter_sub(); - - $form->{title} = $locale->text("DATEX - Export Assistent"); - - $form->header; - - print qq| - - -
{script}> - - - - - - - - - - - - - - -
$form->{title}
| . $locale->text("Konten") . qq|
- - - - - - - - - -
| . $locale->text('Von Konto: ') . qq|
| . $locale->text('Bis Konto: ') . qq|
-

- - - - - - - - - - - - - -{path}> -{login}> -{password}> - -
- -
- - - -|; - - $lxdebug->leave_sub(); + $::lxdebug->enter_sub; + $::auth->assert('datev_export'); + + $::form->header; + print $::form->parse_html_template('datev/export_stammdaten'); + + $::lxdebug->leave_sub; } sub export3 { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $main::auth->assert('datev_export'); + + DATEV::clean_temporary_directories(); DATEV->save_datev_stamm(\%myconfig, \%$form); + my $link = "datev.pl?action=download&download_token="; + if ($form->{kne}) { - if (DATEV->kne_export(\%myconfig, \%$form)) { - $form->redirect($locale->text('KNE Export erfolgreich!')); + my $result = DATEV->kne_export(\%myconfig, \%$form); + if ($result && @{ $result->{filenames} }) { + $link .= Q($result->{download_token}); + + print(qq|
| . $locale->text('KNE-Export erfolgreich!') . qq|

Download|); + + print $form->parse_html_template('datev/net_gross_difference') if @{ $form->{net_gross_differences} }; + + } else { + $form->error("KNE-Export schlug fehl."); } } else { - if (DATEV->obe_export(\%myconfig, \%$form)) { - $form->redirect($locale->text('OBE Export erfolgreich!')); - } + # OBE-Export nicht implementiert. + + # my @filenames = DATEV->obe_export(\%myconfig, \%$form); + # if (@filenames) { + # print(qq|
| . $locale->text('OBE-Export erfolgreich!') . qq|
|); + # $link .= "&filenames=" . $form->escape(join(":", @filenames)); + # print(qq|
Download|); + # } else { + # $form->error("OBE-Export schlug fehl."); + # } + } + + print(""); + + $main::lxdebug->leave_sub(); +} + +sub download { + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; + + $main::auth->assert('datev_export'); + + my $tmp_name = Common->tmpname(); + my $zip_name = strftime("kivitendo-datev-export-%Y%m%d.zip", localtime(time())); + + my $cwd = getcwd(); + + my $path = DATEV::get_path_for_download_token($form->{download_token}); + if (!$path) { + $form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant.")); } - $lxdebug->leave_sub(); + + chdir($path) || die("chdir $path"); + + my @filenames = glob "*"; + + if (!@filenames) { + chdir($cwd); + DATEV::clean_temporary_directories(); + $form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant.")); + } + + my $zip = Archive::Zip->new(); + map { $zip->addFile($_); } @filenames; + $zip->writeToFileNamed($tmp_name); + + chdir($cwd); + + open(IN, $tmp_name) || die("open $tmp_name"); + $::locale->with_raw_io(\*STDOUT, sub { + print("Content-Type: application/zip\n"); + print("Content-Disposition: attachment; filename=\"${zip_name}\"\n\n"); + while () { + print($_); + } + }); + close(IN); + + unlink($tmp_name); + + DATEV::clean_temporary_directories(); + + $main::lxdebug->leave_sub(); }