Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1734e1ad

Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt

  • ID 1734e1ad21eea72ffe4f3ac606cc4a33f97bd5f5
  • Vorgänger fde528b6
  • Nachfolger 24597232

Finanzübersichtsbericht: wiederkehrende Rechnungen berücksichtigen

Die im ausgewählten Jahr zu erzeugenden Rechnungen werden in Summe der
Kategorie »Aufträge« für das erste zu erzeugende Rechnungsdatum
zugeschlagen.

Unterschiede anzeigen:

SL/Controller/FinancialOverview.pm
8 8
use SL::DB::Employee;
9 9
use SL::DB::Invoice;
10 10
use SL::DB::Order;
11
use SL::DB::PeriodicInvoicesConfig;
11 12
use SL::DB::PurchaseInvoice;
12 13
use SL::Controller::Helper::ReportGenerator;
13 14
use SL::Locale::String;
14 15

  
15 16
use Rose::Object::MakeMethods::Generic (
16
  scalar                  => [ qw(report number_columns year current_year types objects data subtotals_per_quarter salesman_id) ],
17
  'scalar --get_set_init' => [ qw(employees) ],
17
  scalar                  => [ qw(report number_columns year current_year objects data subtotals_per_quarter salesman_id) ],
18
  'scalar --get_set_init' => [ qw(employees types) ],
18 19
);
19 20

  
20 21
__PACKAGE__->run_before(sub { $::auth->assert('report'); });
......
25 26
  $self->$_($::form->{$_}) for qw(subtotals_per_quarter salesman_id);
26 27

  
27 28
  $self->get_objects;
28
  $self->calculate_data;
29
  $self->calculate_one_time_data;
30
  $self->calculate_periodic_invoices;
29 31
  $self->prepare_report;
30 32
  $self->list_data;
31 33
}
......
84 86

  
85 87
  $self->objects({
86 88
    sales_quotations       => SL::DB::Manager::Order->get_all(          where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('sales_quotation')   ]]),
87
    sales_orders           => SL::DB::Manager::Order->get_all(          where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('sales_order')       ]]),
89
    sales_orders           => SL::DB::Manager::Order->get_all(          where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('sales_order')       ]], with_objects => [ qw(periodic_invoices_config) ]),
88 90
    requests_for_quotation => SL::DB::Manager::Order->get_all(          where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('request_quotation') ]]),
89 91
    purchase_orders        => SL::DB::Manager::Order->get_all(          where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('purchase_order')    ]]),
90 92
    sales_invoices         => SL::DB::Manager::Invoice->get_all(        where => [ and => [ @f_date, @f_salesman, ]]),
91 93
    purchase_invoices      => SL::DB::Manager::PurchaseInvoice->get_all(where => [ and =>  \@f_date ]),
94
    periodic_invoices_cfg  => SL::DB::Manager::PeriodicInvoicesConfig->get_all(where => [ active => 1 ]),
92 95
  });
96

  
97
  $self->objects->{sales_orders} = [ grep { !$_->periodic_invoices_config || !$_->periodic_invoices_config->active } @{ $self->objects->{sales_orders} } ];
93 98
}
94 99

  
95
sub calculate_data {
96
  my ($self) = @_;
100
sub init_types { [ qw(sales_quotations sales_orders sales_invoices requests_for_quotation purchase_orders purchase_invoices) ] }
97 101

  
98
  $self->types([ qw(sales_quotations sales_orders sales_invoices requests_for_quotation purchase_orders purchase_invoices) ]);
102
sub init_data {
103
  my ($self) = @_;
99 104

  
100 105
  my %data  = (
101 106
    year    => [ ($self->year) x 12                   ],
......
110 115
    } @{ $self->types },
111 116
  );
112 117

  
113
  foreach my $type (keys %{ $self->objects }) {
118
  return \%data;
119
}
120

  
121
sub calculate_one_time_data {
122
  my ($self) = @_;
123

  
124
  foreach my $type (@{ $self->types }) {
114 125
    foreach my $object (@{ $self->objects->{ $type } }) {
115 126
      my $month                              = $object->transdate->month - 1;
116
      my $tdata                              = $data{$type};
127
      my $tdata                              = $self->data->{$type};
117 128

  
118 129
      $tdata->{months}->[$month]            += $object->netamount;
119 130
      $tdata->{quarters}->[int($month / 3)] += $object->netamount;
120 131
      $tdata->{year}                        += $object->netamount;
121 132
    }
122 133
  }
134
}
135

  
136
sub calculate_periodic_invoices {
137
  my ($self)     = @_;
138

  
139
  my $start_date = DateTime->new(year => $self->year, month =>  1, day =>  1, time_zone => $::locale->get_local_time_zone);
140
  my $end_date   = DateTime->new(year => $self->year, month => 12, day => 31, time_zone => $::locale->get_local_time_zone);
141

  
142
  $self->calculate_one_periodic_invoice(config => $_, start_date => $start_date, end_date => $end_date) for @{ $self->objects->{periodic_invoices_cfg} };
143
}
144

  
145
sub calculate_one_periodic_invoice {
146
  my ($self, %params) = @_;
147

  
148
  my @dates           = $params{config}->calculate_invoice_dates(start_date => $params{start_date}, end_date => $params{end_date});
149
  my $first_date      = $dates[0];
150

  
151
  return if !$first_date;
152

  
153
  my $net  = $params{config}->order->netamount * scalar(@dates);
154
  my $sord = $self->data->{sales_orders};
123 155

  
124
  $self->data(\%data);
156
  $sord->{months  }->[ $first_date->month   - 1 ] += $net;
157
  $sord->{quarters}->[ $first_date->quarter - 1 ] += $net;
158
  $sord->{year}                                   += $net;
125 159
}
126 160

  
127 161
sub list_data {

Auch abrufbar als: Unified diff