X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fdatev.pl;h=d352252047b8dc5f65634a509d0825fe6ce517f5;hb=5494f687372570c9d1c5eb5c6aad73767e50820a;hp=72666769e7cbc6186825483d7f96c272039c35f7;hpb=4dbb09950c9f5596646537c12d991c99086fe7c1;p=kivitendo-erp.git diff --git a/bin/mozilla/datev.pl b/bin/mozilla/datev.pl index 72666769e..d35225204 100644 --- a/bin/mozilla/datev.pl +++ b/bin/mozilla/datev.pl @@ -22,29 +22,39 @@ #====================================================================== # # 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(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('datev_export'); $form->{title} = $locale->text("DATEX - Export Assistent"); - - DATEV->get_datev_stamm(\%myconfig, \%$form); + DATEV->get_datev_stamm(\%myconfig, \%$form); $form->header; - + print qq| @@ -56,47 +66,51 @@ sub export { $form->{title} - |.$locale->text("DATEV Angaben").qq| + | . $locale->text("DATEV Angaben") . qq| - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + | . # OBE-Export noch nicht implementiert! + 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("Beraternummer") . qq|| . $locale->text("DFV-Kennzeichen") . qq|
| . $locale->text("Beratername") . qq|| . $locale->text("Password") . qq|
| . $locale->text("Mandantennummer") . qq|| . $locale->text("Medium Number") . qq|
| . $locale->text("Kontonummernerweiterung (KNE)") . qq| |.$locale->text("Abrechnungsnummer").qq|
| . $locale->text("Abrechnungsnummer") . qq|
|.$locale->text("Export Buchungsdaten").qq| | + . $locale->text("Export Buchungsdaten") . qq| |.$locale->text("Export Stammdaten").qq| | + . $locale->text("Export Stammdaten") . qq|
@@ -107,54 +121,82 @@ sub export { -{path}> -{login}> -{password}> -
- + |; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub export2 { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; - if ($form->{exporttype}==0) { + $main::auth->assert('datev_export'); + + if ($form->{exporttype} == 0) { &export_bewegungsdaten(); - } else {&export_stammdaten();} - $lxdebug->leave_sub(); + } else { + &export_stammdaten(); + } + $main::lxdebug->leave_sub(); } sub export_bewegungsdaten { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $main::auth->assert('datev_export'); $form->{title} = $locale->text("DATEX - Export Assistent"); - $form->{allemonate}=qq| - - - - - - - - - - - |; - - $form->{allequartale}=qq| - - - |; + $form->{allemonate} = + qq| + + + + + + + + + + + |; + + $form->{allequartale} = + qq| + + + |; + $form->{"jsscript"} = 1; $form->header; - + print qq| @@ -166,30 +208,35 @@ sub export_bewegungsdaten { $form->{title} - |.$locale->text("Zeitraum").qq| + | . $locale->text("Zeitraum") . qq| - - + + + - - - - + + + - - - - - - + + + + + +
 |.$locale->text('Monat').qq|
 | + . $locale->text('Monat') . qq|
 |.$locale->text('Quartal').qq|
 | + . $locale->text('Quartal') . qq|
 |.$locale->text('Datum von').qq||.$locale->text('bis').qq|
 | + . $locale->text('Datum von') . qq| + | . $locale->text('bis') . qq| +
@@ -198,6 +245,10 @@ sub export_bewegungsdaten { +| . $form->write_trigger(\%myconfig, 2, + "transdatefrom", "BL", "trigger_transdatefrom", + "transdateto", "BL", "trigger_transdateto") . qq| + @@ -211,30 +262,30 @@ sub export_bewegungsdaten { -{path}> -{login}> -{password}> -
- + |; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub export_stammdaten { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + my $form = $main::form; + my $locale = $main::locale; - $form->{title} = $locale->text("DATEX - Export Assistent"); + $main::auth->assert('datev_export'); + $form->{title} = $locale->text("DATEX - Export Assistent"); $form->header; - + print qq| @@ -244,18 +295,18 @@ sub export_stammdaten { $form->{title} - |.$locale->text("Konten").qq| + | . $locale->text("Konten") . qq| - + - +
|.$locale->text('Von Konto: ').qq|| . $locale->text('Von Konto: ') . qq|
|.$locale->text('Bis Konto: ').qq|| . $locale->text('Bis Konto: ') . qq|
@@ -278,33 +329,110 @@ sub export_stammdaten { -{path}> -{login}> -{password}> -
- + |; - $lxdebug->leave_sub(); + $main::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("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.")); } - $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(); }