X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fdatev.pl;h=9572e74bd4c2059da5ba9761b196a1ba1b789d0b;hb=4bd1e2f8b588972f10f92728301feacefd5ee4dd;hp=06393376766dd599aa976a4601bc9903899d8edd;hpb=63024c9f98f172ec904324fd0b6f9cc819ce7600;p=kivitendo-erp.git diff --git a/bin/mozilla/datev.pl b/bin/mozilla/datev.pl index 063933767..9572e74bd 100644 --- a/bin/mozilla/datev.pl +++ b/bin/mozilla/datev.pl @@ -1,5 +1,5 @@ #===================================================================== -# Lx-Office ERP +# kivitendo ERP # Copyright (c) 2004 # # Author: Philip Reetz @@ -29,7 +29,9 @@ use POSIX qw(strftime getcwd); use Archive::Zip qw(:ERROR_CODES :CONSTANTS); use SL::Common; -use SL::DATEV; +use SL::DATEV qw(:CONSTANTS); + +use strict; 1; @@ -37,360 +39,162 @@ use SL::DATEV; require "bin/mozilla/common.pl"; -sub continue { call_sub($form->{"nextsub"}); } +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|
- - - - - - - - - - - - - - - - - - - - - - - - | . # 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("Medium Number") . qq|
| . $locale->text("Kontonummernerweiterung (KNE)") . qq|| . $locale->text("Abrechnungsnummer") . qq|
| - . $locale->text("Export Buchungsdaten") . qq| | - . $locale->text("Export Stammdaten") . qq|
-

- - - -{login}> -{password}> - -
- -
- - - -|; - $lxdebug->leave_sub(); + $::lxdebug->enter_sub; + $::auth->assert('datev_export'); + + my $stamm = SL::DATEV->new->get_datev_stamm; + + $::form->header; + print $::form->parse_html_template('datev/export', $stamm); + + $::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->{"jsscript"} = 1; - $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| -
-

- -| . $form->write_trigger(\%myconfig, 2, - "transdatefrom", "BL", "trigger_transdatefrom", - "transdateto", "BL", "trigger_transdateto") . qq| - - - - - - - - - - - - - - -{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|
-

- - - - - - - - - - - - - -{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(); - - DATEV->save_datev_stamm(\%myconfig, \%$form); - - my $link = $form->{"script"} . "?"; - map({ $link .= "${_}=" . $form->escape($form->{$_}) . "&"; } qw(login password)); - $link .= "action=download"; - - if ($form->{kne}) { - my @filenames = DATEV->kne_export(\%myconfig, \%$form); - if (@filenames) { - print(qq|
| . $locale->text('KNE-Export erfolgreich!') . qq|
|); - $link .= "&filenames=" . $form->escape(join(":", @filenames)); - print(qq|
Download|); - } else { - $form->error("KNE-Export schlug fehl."); - } + $::lxdebug->enter_sub; + $::auth->assert('datev_export'); + + my %data = ( + exporttype => $::form->{exporttype} ? DATEV_ET_STAMM : DATEV_ET_BUCHUNGEN, + format => $::form->{kne} ? DATEV_FORMAT_KNE : DATEV_FORMAT_OBE, + ); + + if ($::form->{exporttype} == DATEV_ET_STAMM) { + $data{accnofrom} = $::form->{accnofrom}, + $data{accnoto} = $::form->{accnoto}, + } elsif ($::form->{exporttype} == DATEV_ET_BUCHUNGEN) { + @data{qw(from to)} = _get_dates( + $::form->{zeitraum}, $::form->{monat}, $::form->{quartal}, + $::form->{transdatefrom}, $::form->{transdateto}, + ); } else { - 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."); - } + die 'invalid exporttype'; } - print(""); + my $datev = SL::DATEV->new(%data); + + $datev->clean_temporary_directories; + $datev->save_datev_stamm($::form); + + $datev->export; - $lxdebug->leave_sub(); + if (!$datev->errors) { + $::form->header; + print $::form->parse_html_template('datev/export3', { datev => $datev }); + } else { + $::form->error("Export schlug fehl.\n" . join "\n", $datev->errors); + } + + $::lxdebug->leave_sub; } sub download { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; + + $::auth->assert('datev_export'); my $tmp_name = Common->tmpname(); - my $zip_name = strftime("lx-office-datev-export-%Y%m%d.zip", - localtime(time())); + my $zip_name = strftime("kivitendo-datev-export-%Y%m%d.zip", localtime(time())); my $cwd = getcwd(); - chdir("users") || die("chdir users"); - my @filenames = split(/:/, $form->{"filenames"}); - map({ s|.*/||; $form->error("Eine der KNE-Exportdateien wurde nicht " . - "gefunden. Wurde der Export bereits " . - "durchgeführt?") unless (-f $_); } - @filenames); + my $datev = SL::DATEV->new(download_token => $form->{download_token}); + + my $path = $datev->export_path; + 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); + $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); + map { $zip->addFile($_); } @filenames; $zip->writeToFileNamed($tmp_name); + chdir($cwd); open(IN, $tmp_name) || die("open $tmp_name"); - print("Content-Type: application/zip\n"); - print("Content-Disposition: attachment; filename=\"${zip_name}\"\n\n"); - while () { - print($_); - } + $::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); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); +} + +sub _get_dates { + $::lxdebug->enter_sub; + + my ($mode, $month, $quarter, $transdatefrom, $transdateto) = @_; + my ($fromdate, $todate); + + if ($mode eq "monat") { + $fromdate = DateTime->new(day => 1, month => $month, year => DateTime->today->year); + $todate = $fromdate->clone->add(months => 1)->add(days => -1); + } elsif ($mode eq "quartal") { + die 'quarter out of of bounds' if $quarter < 1 || $quarter > 4; + $fromdate = DateTime->new(day => 1, month => (3 * $quarter - 2), year => DateTime->today->year); + $todate = $fromdate->clone->add(months => 3)->add(days => -1); + } elsif ($mode eq "zeit") { + $fromdate = DateTime->from_lxoffice($transdatefrom); + $todate = DateTime->from_lxoffice($transdateto); + die 'need from and to time' unless $fromdate && $todate; + } else { + die 'undefined interval mode'; + } + + $::lxdebug->leave_sub; + + return ($fromdate, $todate); }