X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fdatev.pl;h=79097022e8d10c7ef44b4d3f6f58731bf425c23f;hb=c255a38e15c7e342b32f569c20fd39812747f427;hp=d352252047b8dc5f65634a509d0825fe6ce517f5;hpb=8d011bee4d01444862f49a083f9e47b2b07f0a9c;p=kivitendo-erp.git diff --git a/bin/mozilla/datev.pl b/bin/mozilla/datev.pl index d35225204..79097022e 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 @@ -18,7 +18,8 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1335, USA. #====================================================================== # # Datev export module @@ -29,7 +30,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 SL::Locale::String qw(t8); +use SL::DB::Department; use strict; @@ -42,348 +45,80 @@ require "bin/mozilla/common.pl"; sub continue { call_sub($main::form->{"nextsub"}); } sub export { - $main::lxdebug->enter_sub(); + $::lxdebug->enter_sub; + $::auth->assert('datev_export'); - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; + my $stamm = SL::DATEV->new->get_datev_stamm; - $main::auth->assert('datev_export'); - - $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|
-

- - - -
- -
- - - -|; - $main::lxdebug->leave_sub(); + setup_datev_export_action_bar(); + + $::form->header; + print $::form->parse_html_template('datev/export', $stamm); + + $::lxdebug->leave_sub; } sub export2 { - $main::lxdebug->enter_sub(); - - my $form = $main::form; + $::lxdebug->enter_sub; + $::auth->assert('datev_export'); - $main::auth->assert('datev_export'); + export_bewegungsdaten(); - if ($form->{exporttype} == 0) { - &export_bewegungsdaten(); - } else { - &export_stammdaten(); - } - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } sub export_bewegungsdaten { - $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->{"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| - - - - - - - - - - - - - - -
- -
- - - -|; + $::lxdebug->enter_sub; + $::auth->assert('datev_export'); - $main::lxdebug->leave_sub(); -} + setup_datev_export2_action_bar(); -sub export_stammdaten { - $main::lxdebug->enter_sub(); + $::form->header; + $::form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all_sorted; + $::form->{show_pk_option} = SL::DATEV->new->check_vcnumbers_are_valid_pk_numbers; - my $form = $main::form; - my $locale = $main::locale; + # check if we have mismatching number length domains + SL::DATEV->new->check_valid_length_of_accounts; - $main::auth->assert('datev_export'); - - $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|
-

- - - - - - - - - - - - - -
- -
- - - -|; + print $::form->parse_html_template('datev/export_bewegungsdaten'); - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } sub export3 { - $main::lxdebug->enter_sub(); + $::lxdebug->enter_sub; + $::auth->assert('datev_export'); - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; - - $main::auth->assert('datev_export'); + my %data = ( + exporttype => $::form->{exporttype} ? DATEV_ET_STAMM : DATEV_ET_BUCHUNGEN, + format => $::form->{exportformat} eq 'kne' ? DATEV_FORMAT_KNE : DATEV_FORMAT_CSV, + ); - DATEV::clean_temporary_directories(); + @data{qw(from to)} = _get_dates( + $::form->{zeitraum}, $::form->{monat}, $::form->{quartal}, + $::form->{transdatefrom}, $::form->{transdateto}, + ); + $data{use_pk} = $::form->{use_pk}; + $data{locked} = $::form->{locked}; + $data{imported} = $::form->{imported}; - DATEV->save_datev_stamm(\%myconfig, \%$form); + my $datev = SL::DATEV->new(%data); - my $link = "datev.pl?action=download&download_token="; + $datev->clean_temporary_directories; + $datev->save_datev_stamm($::form); - if ($form->{kne}) { - my $result = DATEV->kne_export(\%myconfig, \%$form); - if ($result && @{ $result->{filenames} }) { - $link .= Q($result->{download_token}); + $datev->export; - print(qq|
| . $locale->text('KNE-Export erfolgreich!') . qq|

Download|); + if (!$datev->errors) { + setup_datev_export3_action_bar(download_token => $datev->download_token); - print $form->parse_html_template('datev/net_gross_difference') if @{ $form->{net_gross_differences} }; - - } else { - $form->error("KNE-Export schlug fehl."); - } + $::form->header; + print $::form->parse_html_template('datev/export3', { WARNINGS => $datev->warnings }); } else { - # 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."); - # } + $::form->error("Export schlug fehl.\n" . join "\n", $datev->errors); } - print(""); - - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } sub download { @@ -392,14 +127,16 @@ sub download { my $form = $main::form; my $locale = $main::locale; - $main::auth->assert('datev_export'); + $::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(); - my $path = DATEV::get_path_for_download_token($form->{download_token}); + 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.")); } @@ -410,7 +147,6 @@ sub download { 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.")); } @@ -432,7 +168,83 @@ sub download { unlink($tmp_name); - DATEV::clean_temporary_directories(); - $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); + # december export is usually in january/february + $fromdate = $fromdate->subtract(years => 1) if ($month == 12); + + $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); +} + +sub setup_datev_export_action_bar { + my %params = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Continue'), + submit => [ '#form', { action => 'export2' } ], + accesskey => 'enter', + ], + ); + } +} + +sub setup_datev_export2_action_bar { + my %params = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Export'), + submit => [ '#form', { action => 'export3' } ], + accesskey => 'enter', + ], + action => [ + t8('Back'), + call => [ 'kivi.history_back' ], + ], + ); + } +} + +sub setup_datev_export3_action_bar { + my %params = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + link => [ + t8('Download'), + link => [ 'datev.pl?action=download&download_token=' . $::form->escape($params{download_token}) ], + ], + action => [ + t8('Back'), + call => [ 'kivi.history_back' ], + ], + ); + } +}