X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/8165bc52de684ec8cd95a78515bb82a23d0dab5d..a222e32406aade497b6c8dce6f4869d8b0eec6e1:/SL/Controller/FinancialOverview.pm diff --git a/SL/Controller/FinancialOverview.pm b/SL/Controller/FinancialOverview.pm index 7779a0038..fec091572 100644 --- a/SL/Controller/FinancialOverview.pm +++ b/SL/Controller/FinancialOverview.pm @@ -5,6 +5,7 @@ use parent qw(SL::Controller::Base); use List::MoreUtils qw(none); +use SL::DB::Employee; use SL::DB::Invoice; use SL::DB::Order; use SL::DB::PurchaseInvoice; @@ -12,7 +13,8 @@ use SL::Controller::Helper::ReportGenerator; use SL::Locale::String; use Rose::Object::MakeMethods::Generic ( - scalar => [ qw(report number_columns year current_year types objects data subtotals_per_quarter) ], + scalar => [ qw(report number_columns year current_year types objects data subtotals_per_quarter salesman_id) ], + 'scalar --get_set_init' => [ qw(employees) ], ); __PACKAGE__->run_before(sub { $::auth->assert('report'); }); @@ -20,7 +22,7 @@ __PACKAGE__->run_before(sub { $::auth->assert('report'); }); sub action_list { my ($self) = @_; - $self->subtotals_per_quarter($::form->{subtotals_per_quarter}); + $self->$_($::form->{$_}) for qw(subtotals_per_quarter salesman_id); $self->get_objects; $self->calculate_data; @@ -64,7 +66,7 @@ sub prepare_report { ); $self->report->set_columns(%column_defs); $self->report->set_column_order(@columns); - $self->report->set_export_options(qw(list year subtotals_per_quarter)); + $self->report->set_export_options(qw(list year subtotals_per_quarter salesman_id)); $self->report->set_options_from_form; } @@ -77,15 +79,16 @@ sub get_objects { my $start = DateTime->new(year => $self->year, month => 1, day => 1); my $end = DateTime->new(year => $self->year, month => 12, day => 31); - my @date_filter = (and => [ transdate => { ge => $start }, transdate => { le => $end } ]); + my @f_date = (transdate => { ge => $start }, transdate => { le => $end }); + my @f_salesman = $self->salesman_id ? (salesman_id => $self->salesman_id) : (); $self->objects({ - sales_quotations => SL::DB::Manager::Order->get_all( where => [ and => [ @date_filter, SL::DB::Manager::Order->type_filter('sales_quotation') ]]), - sales_orders => SL::DB::Manager::Order->get_all( where => [ and => [ @date_filter, SL::DB::Manager::Order->type_filter('sales_order') ]]), - requests_for_quotation => SL::DB::Manager::Order->get_all( where => [ and => [ @date_filter, SL::DB::Manager::Order->type_filter('request_quotation') ]]), - purchase_orders => SL::DB::Manager::Order->get_all( where => [ and => [ @date_filter, SL::DB::Manager::Order->type_filter('purchase_order') ]]), - sales_invoices => SL::DB::Manager::Invoice->get_all( where => \@date_filter), - purchase_invoices => SL::DB::Manager::PurchaseInvoice->get_all(where => \@date_filter), + sales_quotations => SL::DB::Manager::Order->get_all( where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('sales_quotation') ]]), + sales_orders => SL::DB::Manager::Order->get_all( where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('sales_order') ]]), + requests_for_quotation => SL::DB::Manager::Order->get_all( where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('request_quotation') ]]), + purchase_orders => SL::DB::Manager::Order->get_all( where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('purchase_order') ]]), + sales_invoices => SL::DB::Manager::Invoice->get_all( where => [ and => [ @f_date, @f_salesman, ]]), + purchase_invoices => SL::DB::Manager::PurchaseInvoice->get_all(where => [ and => \@f_date ]), }); } @@ -130,8 +133,8 @@ sub list_data { for my $month (1..12) { my %data = ( - map({ ($_ => { data => $self->data->{$_}->[$month - 1] }) } @non_type_columns), - map({ ($_ => { data => $::form->format_amount(\%::myconfig, $self->data->{$_}->{months}->[$month - 1]) }) } @type_columns ), + map({ ($_ => { data => $self->data->{$_}->[$month - 1] }) } @non_type_columns), + map({ ($_ => { data => $::form->format_amount(\%::myconfig, $self->data->{$_}->{months}->[$month - 1], 2) }) } @type_columns ), ); $self->report->add_data(\%data); @@ -140,7 +143,7 @@ sub list_data { my %subtotal = ( year => { data => $self->year }, month => { data => $::locale->text('Total') }, - map { ($_ => { data => $::form->format_amount(\%::myconfig, $self->data->{$_}->{quarters}->[int(($month - 1) / 3)]) }) } @type_columns, + map { ($_ => { data => $::form->format_amount(\%::myconfig, $self->data->{$_}->{quarters}->[int(($month - 1) / 3)], 2) }) } @type_columns, ); $subtotal{$_}->{class} = 'listsubtotal' for @visible_columns; @@ -152,7 +155,7 @@ sub list_data { my %data = ( year => { data => $self->year }, quarter => { data => $::locale->text('Total') }, - map { ($_ => { data => $::form->format_amount(\%::myconfig, $self->data->{$_}->{year}) }) } @type_columns, + map { ($_ => { data => $::form->format_amount(\%::myconfig, $self->data->{$_}->{year}, 2) }) } @type_columns, ); $data{$_}->{class} = 'listtotal' for @visible_columns; @@ -162,4 +165,6 @@ sub list_data { return $self->report->generate_with_headers; } +sub init_employees { SL::DB::Manager::Employee->get_all_sorted } + 1;