X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fdatev.pl;h=8915d2f8b90dd9d182781757774f73cc803ecde9;hb=d4a434e1deba2695ef4d4a3fc0d51ac1b2044fb0;hp=72666769e7cbc6186825483d7f96c272039c35f7;hpb=4dbb09950c9f5596646537c12d991c99086fe7c1;p=kivitendo-erp.git diff --git a/bin/mozilla/datev.pl b/bin/mozilla/datev.pl index 72666769e..8915d2f8b 100644 --- a/bin/mozilla/datev.pl +++ b/bin/mozilla/datev.pl @@ -22,289 +22,160 @@ #====================================================================== # # Datev export module -# +# #====================================================================== +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} } }; +# end of main +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(); - } else {&export_stammdaten();} - $lxdebug->leave_sub(); + if ($::form->{exporttype} == 0) { + export_bewegungsdaten(); + } else { + export_stammdaten(); + } + $::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."); + # } } - $lxdebug->leave_sub(); + + 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("lx-office-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.")); + } + + 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(); }