Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a2d4ad4c

Von Moritz Bunkus vor mehr als 8 Jahren hinzugefügt

  • ID a2d4ad4c41a19e9323242c29b0dad2c63e7d0e88
  • Vorgänger 80b0139a
  • Nachfolger 2721bfd0

Finanzübersicht: Neue Spalte »Kosten« analog zu BWA-Kosten

Unterschiede anzeigen:

SL/Controller/FinancialOverview.pm
11 11
use SL::DB::Order;
12 12
use SL::DB::PeriodicInvoicesConfig;
13 13
use SL::DB::PurchaseInvoice;
14
use SL::DBUtils;
14 15
use SL::Controller::Helper::ReportGenerator;
15 16
use SL::Locale::String;
16 17

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

  
22 23
__PACKAGE__->run_before(sub { $::auth->assert('report'); });
......
29 30
  $self->get_objects;
30 31
  $self->calculate_one_time_data;
31 32
  $self->calculate_periodic_invoices;
33
  $self->calculate_costs if $self->show_costs;
32 34
  $self->prepare_report;
33 35
  $self->list_data;
34 36
}
......
55 57
    requests_for_quotation => { text => t8('Requests for Quotation') },
56 58
    purchase_orders        => { text => t8('Purchase Orders')        },
57 59
    purchase_invoices      => { text => t8('Purchase Invoices')      },
60
    costs                  => { text => t8('Costs')                  },
58 61
  );
59 62

  
60 63
  $column_defs{$_}->{align} = 'right' for @columns;
......
100 103
  $self->objects->{sales_orders} = [ grep { !$_->periodic_invoices_config || !$_->periodic_invoices_config->active } @{ $self->objects->{sales_orders} } ];
101 104
}
102 105

  
103
sub init_types { [ qw(sales_quotations sales_orders sales_orders_per_inv sales_invoices requests_for_quotation purchase_orders purchase_invoices) ] }
106
sub init_show_costs { $::instance_conf->get_profit_determination eq 'balance' }
107

  
108
sub init_types {
109
  my ($self) = @_;
110
  my @types  = qw(sales_quotations sales_orders sales_orders_per_inv sales_invoices requests_for_quotation purchase_orders purchase_invoices);
111
  push @types, 'costs' if $self->show_costs;
112

  
113
  return \@types;
114
}
104 115

  
105 116
sub init_data {
106 117
  my ($self) = @_;
......
126 137

  
127 138
  foreach my $type (@{ $self->types }) {
128 139
    my $src_object_type = $type eq 'sales_orders_per_inv' ? 'sales_orders' : $type;
129
    foreach my $object (@{ $self->objects->{ $src_object_type } }) {
140
    foreach my $object (@{ $self->objects->{ $src_object_type } || [] }) {
130 141
      my $month                              = $object->transdate->month - 1;
131 142
      my $tdata                              = $self->data->{$type};
132 143

  
......
170 181
  $sord->{year}                             += $net;
171 182
}
172 183

  
184
sub calculate_costs {
185
  my ($self) = @_;
186

  
187
  # Relevante BWA-Positionen für Kosten:
188
  #  4 – Mat./Wareneinkauf
189
  # 10 – Personalkosten
190
  # 11 – Raumkosten
191
  # 12 – Betriebl.Steuern
192
  # 13 – Versicherungsbeiträge
193
  # 14 – KFZ-Kosten ohne Steuern
194
  # 15 – Werbe-/Reisekosten
195
  # 16 – Kosten Warenabgabe
196
  # 17 – Abschreibungen
197
  # 18 – Reparatur/Instandhaltung
198
  # 20 – Sonstige Kosten
199
  my $query = <<SQL;
200
    SELECT SUM(ac.amount * chart_category_to_sgn(c.category)) AS amount,
201
      EXTRACT(month FROM ac.transdate) AS month
202
    FROM acc_trans ac
203
    LEFT JOIN chart c ON (c.id = ac.chart_id)
204
    WHERE (c.pos_bwa IN (4, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20))
205
      AND (ac.transdate >= ?)
206
      AND (ac.transdate <  ?)
207
    GROUP BY month
208
SQL
209

  
210
  my @args = (
211
    DateTime->new_local(day => 1, month => 1, year => $self->year)->to_kivitendo,
212
    DateTime->new_local(day => 1, month => 1, year => $self->year + 1)->to_kivitendo,
213
  );
214

  
215
  my @results = selectall_hashref_query($::form, SL::DB::AccTransaction->new->db->dbh, $query, @args);
216
  foreach my $row (@results) {
217
    my $month                              = $row->{month} - 1;
218
    my $tdata                              = $self->data->{costs};
219

  
220
    $tdata->{months}->[$month]            += $row->{amount};
221
    $tdata->{quarters}->[int($month / 3)] += $row->{amount};
222
    $tdata->{year}                        += $row->{amount};
223
  }
224
}
225

  
173 226
sub list_data {
174 227
  my ($self)           = @_;
175 228

  

Auch abrufbar als: Unified diff