]> wagnertech.de Git - mfinanz.git/blob - SL/Controller/LiquidityProjection.pm
restart apache2 in postinst
[mfinanz.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 );
16
17
18 #
19 # actions
20 #
21
22 sub action_show {
23   my ($self) = @_;
24
25   $self->liquidity(SL::LiquidityProjection->new(%{ $::form->{params} })->create) if $::form->{params};
26
27   $::form->{params} ||= {
28     months            => 6,
29     type              => 1,
30     salesman          => 1,
31     buchungsgruppe    => 1,
32     parts_group       => 1,
33   };
34
35   $self->setup_show_action_bar;
36   $self->render('liquidity_projection/show', title => t8('Liquidity projection'));
37 }
38
39 sub action_list_orders {
40   my ($self) = @_;
41
42   my @orders = SL::LiquidityProjection->orders_for_time_period(
43     after  => $::form->{after}  ? DateTime->from_kivitendo($::form->{after})  : undef,
44     before => $::form->{before} ? DateTime->from_kivitendo($::form->{before}) : undef,
45   );
46
47   $self->render(
48     'liquidity_projection/list_orders',
49     title  => t8('Sales Orders'),
50     ORDERS => \@orders,
51   );
52 }
53
54 #
55 # filters
56 #
57
58 sub check_auth                 { $::auth->assert('report') }
59 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) }
60
61 #
62 # helpers
63 #
64
65 sub link_to_old_orders {
66   my $self    = shift;
67   my %params  = _hashify(0, @_);
68
69   my $reqdate = $params{reqdate};
70   my $months  = $params{months} * 1;
71   my $today   = DateTime->today_local->truncate(to => 'month');
72   my %url_params;
73
74   my $fields  = '';
75
76   if ($reqdate eq 'old') {
77     $url_params{before} = $today->to_kivitendo;
78
79   } elsif ($reqdate eq 'future') {
80     $url_params{after} = $today->add(months => $months)->to_kivitendo;
81
82   } else {
83     $reqdate            =~ m/(\d+)-(\d+)/;
84     my $date            = DateTime->new_local(year => $1, month => $2, day => 1);
85     $url_params{after}  = $date->to_kivitendo;
86     $url_params{before} = $date->add(months => 1)->to_kivitendo;
87   }
88
89   return $self->url_for(action => 'list_orders', %url_params);
90 }
91
92 sub setup_show_action_bar {
93   my ($self, %params) = @_;
94
95   for my $bar ($::request->layout->get('actionbar')) {
96     $bar->add(
97       action => [
98         t8('Show'),
99         submit    => [ '#filter_form', { action => 'LiquidityProjection/show' } ],
100         accesskey => 'enter',
101       ],
102     );
103   }
104 }
105
106 1;