1 package SL::Controller::GoBD;
5 use parent qw(SL::Controller::Base);
9 use SL::Locale::String qw(t8);
10 use SL::Helper::Flash;
12 use SL::DB::AccTransaction;
14 use Rose::Object::MakeMethods::Generic (
15 'scalar --get_set_init' => [ qw(from to) ],
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 $::request->layout->add_javascripts('kivi.GoBD.js');
27 $self->render('gobd/filter', current_year => DateTime->today->year, title => t8('GoBD Export'));
33 if (!$self->check_inputs) {
39 my $gobd = SL::GoBD->new(
40 company => $::instance_conf->get_company,
41 location => $::instance_conf->get_address,
47 $filename = $gobd->generate_export;
50 flash('error', t8('The export failed because of malformed transactions. Please fix those before exporting.'));
51 flash('error', $_) for @$errors;
57 $self->send_file($filename, name => t8('gobd-#1-#2.zip', $self->from->ymd, $self->to->ymd), unlink => 1);
62 sub check_auth { $::auth->assert('report') }
69 if ($::form->{method} eq 'year') {
70 if ($::form->{year}) {
71 $self->from(DateTime->new(year => $::form->{year}, month => 1, day => 1));
72 $self->to( DateTime->new(year => $::form->{year}, month => 12, day => 31));
75 flash('error', t8('No year given for method year'));
78 if (!$::form->{from}) {
79 my $epoch = DateTime->new(day => 1, month => 1, year => 1900);
80 flash('info', t8('No start date given, setting to #1', $epoch->to_kivitendo));
85 flash('info', t8('No end date given, setting to today'));
86 $self->to(DateTime->today);
96 my $first_trans = SL::DB::Manager::AccTransaction->get_first(sort_by => 'transdate', limit => 1);
98 return [] unless $first_trans;
99 return [ reverse $first_trans->transdate->year .. DateTime->today->year ];
102 sub init_from { DateTime->from_kivitendo($::form->{from}) }
103 sub init_to { DateTime->from_kivitendo($::form->{to}) }