1 package SL::Controller::Gdpdu;
4 # - depending exclusive checkboses via javascript
8 use parent qw(SL::Controller::Base);
11 use SL::Locale::String qw(t8);
12 use SL::Helper::Flash;
14 use Rose::Object::MakeMethods::Generic (
15 'scalar --get_set_init' => [ qw(from to tables) ],
18 __PACKAGE__->run_before('check_auth');
23 $self->from(DateTime->today->add(years => -1)->add(days => 1)) if !$self->from;
24 $self->to(DateTime->today) if !$self->to;
26 $self->render('gdpdu/filter', title => t8('GDPDU Export'));
32 if (!$self->check_inputs) {
37 my $gdpdu = SL::GDPDU->new(
38 company => $::instance_conf->get_company,
39 location => $::instance_conf->get_address,
42 tables => $self->tables,
43 all_tables => !@{ $self->tables } && $::form->{all_tables},
46 my $filename = $gdpdu->generate_export;
48 $self->send_file($filename, name => t8('gdpdu-#1-#2.zip', $self->from->ymd, $self->to->ymd), unlink => 1);
53 sub check_auth { $::auth->assert('report') }
60 if ($::form->{tables}) {
61 $self->tables([ keys %{ $::form->{tables} } ]);
62 # theese three get inferred
63 push @{ $self->tables }, 'invoice' if $::form->{tables}{ar} || $::form->{tables}{ap};
64 push @{ $self->tables }, 'orderitems' if $::form->{tables}{oe};
65 push @{ $self->tables }, 'delivery_order_items' if $::form->{tables}{delivery_orders};
68 if (!@{ $self->tables } && !$::form->{all_tables}) {
69 flash('error', t8('No, I really do need checked tables to export.'));
73 if (!$::form->{from}) {
74 my $epoch = DateTime->new(day => 1, month => 1, year => 1900);
75 flash('info', t8('No start date given, setting to #1', $epoch->to_kivitendo));
80 flash('info', t8('No end date given, setting to today'));
81 $self->to(DateTime->today);
87 sub init_from { DateTime->from_kivitendo($::form->{from}) }
88 sub init_to { DateTime->from_kivitendo($::form->{to}) }
89 sub init_tables { [ ] }