24413d7813b194b96209c74a56cd2cc759a4a56b
[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->render('liquidity_projection/show', title => t8('Liquidity projection'));
36 }
37
38 #
39 # filters
40 #
41
42 sub check_auth                 { $::auth->assert('report') }
43 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) }
44
45 #
46 # helpers
47 #
48
49 sub link_to_old_orders {
50   my $self    = shift;
51   my %params  = _hashify(0, @_);
52
53   my $reqdate = $params{reqdate};
54   my $months  = $params{months} * 1;
55
56   my $fields  = '';
57
58   if ($reqdate eq 'old') {
59     $fields .= '&reqdate_unset_or_old=Y';
60
61   } elsif ($reqdate eq 'future') {
62     my @now  = localtime;
63     $fields .= '&reqdatefrom=' . $self->iso_to_display(SL::LiquidityProjection::_the_date($now[5] + 1900, $now[4] + 1 + $months) . '-01');
64
65   } else {
66     $reqdate =~ m/(\d+)-(\d+)/;
67     $fields .=  '&reqdatefrom=' . $self->iso_to_display($reqdate . '-01');
68     $fields .=  '&reqdateto='   . $self->iso_to_display($reqdate . sprintf('-%02d', DateTime->last_day_of_month(year => $1, month => $2)->day));
69
70   }
71
72   return "oe.pl?action=orders&type=sales_order&vc=customer&" . $self->oe_report_columns_str . $fields;
73 }
74
75 sub iso_to_display {
76   my ($self, $date) = @_;
77
78   $::locale->reformat_date({ dateformat => 'yyyy-mm-dd' }, $date, $::myconfig{dateformat});
79 }
80
81 1;