1c18f3420252ed358c46160fa9d872f72ccbe7e0
[kivitendo-erp.git] / SL / Controller / LiquidityProjection.pm
1 package SL::Controller::LiquidityProjection;
2
3 use strict;
4
5 use parent qw(SL::Controller::Base);
6
7 use SL::Locale::String;
8 use SL::LiquidityProjection;
9 use SL::Util qw(_hashify);
10
11 __PACKAGE__->run_before('check_auth');
12
13 use Rose::Object::MakeMethods::Generic (
14   scalar                  => [ qw(liquidity) ],
15   'scalar --get_set_init' => [ qw(oe_report_columns_str) ],
16 );
17
18
19 #
20 # actions
21 #
22
23 sub action_show {
24   my ($self) = @_;
25
26   $self->liquidity(SL::LiquidityProjection->new(%{ $::form->{params} })->create) if $::form->{params};
27
28   $::form->{params} ||= {
29     months            => 6,
30     type              => 1,
31     salesman          => 1,
32     buchungsgruppe    => 1,
33   };
34
35   $self->setup_show_action_bar;
36   $self->render('liquidity_projection/show', title => t8('Liquidity projection'));
37 }
38
39 #
40 # filters
41 #
42
43 sub check_auth                 { $::auth->assert('report') }
44 sub init_oe_report_columns_str { join '&', map { "$_=Y" } qw(open delivered notdelivered l_ordnumber l_transdate l_reqdate l_name l_employee l_salesman l_netamount l_amount l_transaction_description) }
45
46 #
47 # helpers
48 #
49
50 sub link_to_old_orders {
51   my $self    = shift;
52   my %params  = _hashify(0, @_);
53
54   my $reqdate = $params{reqdate};
55   my $months  = $params{months} * 1;
56
57   my $fields  = '';
58
59   if ($reqdate eq 'old') {
60     $fields .= '&reqdate_unset_or_old=Y';
61
62   } elsif ($reqdate eq 'future') {
63     my @now  = localtime;
64     $fields .= '&reqdatefrom=' . $self->iso_to_display(SL::LiquidityProjection::_the_date($now[5] + 1900, $now[4] + 1 + $months) . '-01');
65
66   } else {
67     $reqdate =~ m/(\d+)-(\d+)/;
68     $fields .=  '&reqdatefrom=' . $self->iso_to_display($reqdate . '-01');
69     $fields .=  '&reqdateto='   . $self->iso_to_display($reqdate . sprintf('-%02d', DateTime->last_day_of_month(year => $1, month => $2)->day));
70
71   }
72
73   return "oe.pl?action=orders&type=sales_order&vc=customer&" . $self->oe_report_columns_str . $fields;
74 }
75
76 sub iso_to_display {
77   my ($self, $date) = @_;
78
79   $::locale->reformat_date({ dateformat => 'yyyy-mm-dd' }, $date, $::myconfig{dateformat});
80 }
81
82 sub setup_show_action_bar {
83   my ($self, %params) = @_;
84
85   for my $bar ($::request->layout->get('actionbar')) {
86     $bar->add(
87       action => [
88         t8('Show'),
89         submit    => [ '#filter_form', { action => 'LiquidityProjection/show' } ],
90         accesskey => 'enter',
91       ],
92     );
93   }
94 }
95
96 1;