From: Sven Schöling Date: Tue, 10 Nov 2015 11:33:37 +0000 (+0100) Subject: GDPDU: Export nach Buchungsjahr X-Git-Tag: release-3.5.4~1958 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=db11732b27f9d7bd86fb6bf1cd4150e59a54559f;p=kivitendo-erp.git GDPDU: Export nach Buchungsjahr --- diff --git a/SL/Controller/Gdpdu.pm b/SL/Controller/Gdpdu.pm index 29b65da69..596351b69 100644 --- a/SL/Controller/Gdpdu.pm +++ b/SL/Controller/Gdpdu.pm @@ -4,10 +4,13 @@ use strict; use parent qw(SL::Controller::Base); +use DateTime; use SL::GDPDU; use SL::Locale::String qw(t8); use SL::Helper::Flash; +use SL::DB::AccTransaction; + use Rose::Object::MakeMethods::Generic ( 'scalar --get_set_init' => [ qw(from to) ], ); @@ -20,7 +23,8 @@ sub action_filter { $self->from(DateTime->today->add(years => -1)->add(days => 1)) if !$self->from; $self->to(DateTime->today) if !$self->to; - $self->render('gdpdu/filter', title => t8('GDPDU Export')); + $::request->layout->add_javascripts('kivi.Gdpdu.js'); + $self->render('gdpdu/filter', current_year => DateTime->today->year, title => t8('GDPDU Export')); } sub action_export { @@ -52,20 +56,39 @@ sub check_inputs { my $error = 0; - if (!$::form->{from}) { - my $epoch = DateTime->new(day => 1, month => 1, year => 1900); - flash('info', t8('No start date given, setting to #1', $epoch->to_kivitendo)); - $self->from($epoch); - } - - if (!$::form->{to}) { - flash('info', t8('No end date given, setting to today')); - $self->to(DateTime->today); + if ($::form->{method} eq 'year') { + if ($::form->{year}) { + $self->from(DateTime->new(year => $::form->{year}, month => 1, day => 1)); + $self->to( DateTime->new(year => $::form->{year}, month => 12, day => 31)); + } else { + $error = 1; + flash('error', t8('No year given for method year')); + } + } else { + if (!$::form->{from}) { + my $epoch = DateTime->new(day => 1, month => 1, year => 1900); + flash('info', t8('No start date given, setting to #1', $epoch->to_kivitendo)); + $self->from($epoch); + } + + if (!$::form->{to}) { + flash('info', t8('No end date given, setting to today')); + $self->to(DateTime->today); + } } !$error; } +sub available_years { + my ($self) = @_; + + my $first_trans = SL::DB::Manager::AccTransaction->get_first(sort_by => 'transdate', limit => 1); + + return [] unless $first_trans; + return [ reverse $first_trans->transdate->year .. DateTime->today->year ]; +} + sub init_from { DateTime->from_kivitendo($::form->{from}) } sub init_to { DateTime->from_kivitendo($::form->{to}) } diff --git a/js/kivi.Gdpdu.js b/js/kivi.Gdpdu.js new file mode 100644 index 000000000..dfaba52c8 --- /dev/null +++ b/js/kivi.Gdpdu.js @@ -0,0 +1,23 @@ +namespace('kivi.Gdpdu', function(ns) { + ns.grey_invalid_options = function(el){ + console.log(el); + if ($(el).prop('checked')) { + $(el).closest('tr').find('input.datepicker').prop('disabled', false).datepicker('enable'); + $(el).closest('tr').find('select').prop('disabled', 0); + } else { + $(el).closest('tr').find('input.datepicker').prop('disabled', true).datepicker('disable'); + $(el).closest('tr').find('select').prop('disabled', 1); + } + } + + ns.update_all_radio = function () { + $('input[type=radio]').each(function(i,e) {ns.grey_invalid_options (e) }); + } + + ns.setup = function() { + ns.update_all_radio(); + $('input[type=radio]').change(ns.update_all_radio); + } +}); + +$(kivi.Gdpdu.setup); diff --git a/templates/webpages/gdpdu/filter.html b/templates/webpages/gdpdu/filter.html index 2f3a855ab..ead33877e 100644 --- a/templates/webpages/gdpdu/filter.html +++ b/templates/webpages/gdpdu/filter.html @@ -9,14 +9,18 @@

[% 'This export will include all records in the given time range and all supplicant information from checked entities. You will receive a single zip file. Please extract this file onto the data medium requested by your auditor.' | $T8 %]

-
+ - - + + + +
[% 'From Date' | $T8 %][% L.date_tag('from', SELF.from) %][% L.radio_button_tag('method', value='year', checked=1) %] + [% 'Year' | $T8 %][% L.select_tag('year', SELF.available_years, default=current_year) %]
[% L.radio_button_tag('method') %] + [% 'From Date' | $T8 %][% L.date_tag('from', SELF.from) %] [% 'To Date' | $T8 %] [% L.date_tag('to', SELF.to) %]