X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FDeliveryPlan.pm;h=98f168b1ec5e5e424bb55aa75dc10c9e4f0936ad;hb=41229db38e57ad893178df32d7a30045ef77f5fd;hp=07581c428ed23623a03614b834cffa14b319069a;hpb=28f67151ac88eb5bd0075c3b15419a734a0fca3a;p=kivitendo-erp.git diff --git a/SL/Controller/DeliveryPlan.pm b/SL/Controller/DeliveryPlan.pm index 07581c428..98f168b1e 100644 --- a/SL/Controller/DeliveryPlan.pm +++ b/SL/Controller/DeliveryPlan.pm @@ -5,14 +5,17 @@ use parent qw(SL::Controller::Base); use Clone qw(clone); use SL::DB::OrderItem; +use SL::DB::Business; use SL::Controller::Helper::GetModels; use SL::Controller::Helper::ReportGenerator; use SL::Locale::String; +use SL::AM; +use SL::DBUtils (); use Carp; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(db_args flat_filter) ], - 'scalar --get_set_init' => [ qw(models all_edit_right vc) ], + 'scalar --get_set_init' => [ qw(models all_edit_right vc all_employees all_businesses) ], ); __PACKAGE__->run_before(sub { $::auth->assert('delivery_plan'); }); @@ -28,7 +31,6 @@ my %sort_columns = ( ordnumber => t8('Order'), customer => t8('Customer'), vendor => t8('Vendor'), - value_of_goods => t8('Value of transferred goods'), ); @@ -38,7 +40,7 @@ sub action_list { $self->prepare_report; my $orderitems = $self->models->get; - + $self->calc_qtys($orderitems); $self->report_generator_list_objects(report => $self->{report}, objects => $orderitems); } @@ -51,7 +53,7 @@ sub prepare_report { my $report = SL::ReportGenerator->new(\%::myconfig, $::form); $self->{report} = $report; - my @columns = qw(reqdate customer vendor ordnumber partnumber description qty shipped_qty not_shipped_qty delivered_qty value_of_goods); + my @columns = qw(reqdate customer vendor ordnumber partnumber description qty shipped_qty not_shipped_qty delivered_qty); my @sortable = qw(reqdate customer vendor ordnumber partnumber description); @@ -62,33 +64,19 @@ sub prepare_report { partnumber => { sub => sub { $_[0]->part->partnumber }, obj_link => sub { $self->link_to($_[0]->part) } }, qty => { sub => sub { $_[0]->qty_as_number . ' ' . $_[0]->unit } }, - shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->shipped_qty, 2) . ' ' . $_[0]->unit } }, - not_shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->qty - $_[0]->shipped_qty, 2) . ' ' . $_[0]->unit } }, - delivered_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->delivered_qty, 2) . ' ' . $_[0]->unit } }, + shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]{shipped_qty}, 2) . ' ' . $_[0]->unit } }, + not_shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->qty - $_[0]{shipped_qty}, 2) . ' ' . $_[0]->unit } }, + delivered_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]{delivered_qty}, 2) .' ' . $_[0]->unit } }, ordnumber => { sub => sub { $_[0]->order->ordnumber }, obj_link => sub { $self->link_to($_[0]->order) } }, - #vendor => { sub => sub { $_[0]->order->vendor->name }, - # obj_link => sub { $self->link_to($_[0]->order->vendor) } }, - #customer => { sub => sub { $_[0]->order->customer->name }, - # obj_link => sub { $self->link_to($_[0]->order->customer) } }, + vendor => { sub => sub { $_[0]->order->vendor->name }, + visible => $vc eq 'vendor', + obj_link => sub { $self->link_to($_[0]->order->vendor) } }, + customer => { sub => sub { $_[0]->order->customer->name }, + visible => $vc eq 'customer', + obj_link => sub { $self->link_to($_[0]->order->customer) } }, ); - # add value of goods in report - if ($main::auth->assert('sales_order_edit') && $::instance_conf->get_delivery_plan_show_value_of_goods) { - $column_defs{value_of_goods} = { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->value_of_goods, 2) . ' ' . $_[0]->taxincluded } }; - } - - # hotfix for today - # if visible is not working - if ($vc eq 'customer') { - $column_defs{customer} = { sub => sub { $_[0]->order->customer->name }, - obj_link => sub { $self->link_to($_[0]->order->customer) } }; - } - if ($vc eq 'vendor') { - $column_defs{vendor} = { sub => sub { $_[0]->order->vendor->name }, - obj_link => sub { $self->link_to($_[0]->order->vendor) } }, - } - $column_defs{$_}->{text} = $sort_columns{$_} for keys %column_defs; $report->set_options( @@ -109,29 +97,68 @@ sub prepare_report { $self->models->finalize; # for filter laundering $self->models->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable); $report->set_options( - raw_top_info_text => $self->render('delivery_plan/report_top', { output => 0 }, vc => $vc), + raw_top_info_text => $self->render('delivery_plan/report_top', { output => 0 }), raw_bottom_info_text => $self->render('delivery_plan/report_bottom', { output => 0 }, models => $self->models), ); } +sub calc_qtys { + my ($self, $orderitems) = @_; + # using $orderitem->shipped_qty 40 times is far too slow. need to do it manually + # + + return unless scalar @$orderitems; + + my %orderitems_by_id = map { $_->id => $_ } @$orderitems; + + my $query = <get_standard_dbh, $query, map { $_->id } @$orderitems); + + for my $row (@$result) { + my $item = $orderitems_by_id{ $row->{id} }; + $item->{shipped_qty} ||= 0; + $item->{delivered_qty} ||= 0; + $item->{shipped_qty} += AM->convert_unit($row->{unit} => $item->unit) * $row->{qty}; + $item->{delivered_qty} += AM->convert_unit($row->{unit} => $item->unit) * $row->{qty} if $row->{delivered}; + } +} + sub make_filter_summary { my ($self) = @_; my $vc = $self->vc; + my ($business, $employee); my $filter = $::form->{filter} || {}; my @filter_strings; + $business = SL::DB::Business->new(id => $filter->{order}{customer}{"business_id"})->load->description if $filter->{order}{customer}{"business_id"}; + $employee = SL::DB::Employee->new(id => $filter->{order}{employee_id})->load->name if $filter->{order}{employee_id}; + my @filters = ( - [ $filter->{order}{"ordnumber:substr::ilike"}, $::locale->text('Number') ], - [ $filter->{part}{"partnumber:substr::ilike"}, $::locale->text('Part Number') ], - [ $filter->{"description:substr::ilike"}, $::locale->text('Part Description') ], - [ $filter->{"reqdate:date::ge"}, $::locale->text('Delivery Date') . " " . $::locale->text('From Date') ], - [ $filter->{"reqdate:date::le"}, $::locale->text('Delivery Date') . " " . $::locale->text('To Date') ], - [ $filter->{"qty:number"}, $::locale->text('Quantity') ], - [ $filter->{order}{vendor}{"name:substr::ilike"}, $::locale->text('Vendor') ], - [ $filter->{order}{vendor}{"vendornumber:substr::ilike"}, $::locale->text('Vendor Number') ], - [ $filter->{order}{customer}{"name:substr::ilike"}, $::locale->text('Customer') ], - [ $filter->{order}{customer}{"customernumber:substr::ilike"}, $::locale->text('Customer Number') ], + [ $filter->{order}{"ordnumber:substr::ilike"}, $::locale->text('Number') ], + [ $filter->{order}{globalproject}{"projectnumber:substr::ilike"}, $::locale->text('Document Project Number') ], + [ $filter->{part}{"partnumber:substr::ilike"}, $::locale->text('Part Number') ], + [ $filter->{"description:substr::ilike"}, $::locale->text('Part Description') ], + [ $filter->{"reqdate:date::ge"}, $::locale->text('Delivery Date') . " " . $::locale->text('From Date') ], + [ $filter->{"reqdate:date::le"}, $::locale->text('Delivery Date') . " " . $::locale->text('To Date') ], + [ $filter->{"qty:number"}, $::locale->text('Quantity') ], + [ $filter->{order}{vendor}{"name:substr::ilike"}, $::locale->text('Vendor') ], + [ $filter->{order}{vendor}{"vendornumber:substr::ilike"}, $::locale->text('Vendor Number') ], + [ $filter->{order}{customer}{"name:substr::ilike"}, $::locale->text('Customer') ], + [ $filter->{order}{customer}{"customernumber:substr::ilike"}, $::locale->text('Customer Number') ], + [ $business, $::locale->text('Customer type') ], + [ $employee, $::locale->text('Employee') ], ); my %flags = ( @@ -157,7 +184,7 @@ sub delivery_plan_query { my $employee_id = SL::DB::Manager::Employee->current->id; my $oe_owner = $_[0]->all_edit_right ? '' : " oe.employee_id = $employee_id AND"; # check delivered state for delivery_orders (transferred out) if enabled - my $filter_delivered = $::instance_conf->get_delivery_plan_calculate_transferred_do ? + my $filter_delivered = ($::instance_conf->get_delivery_plan_calculate_transferred_do) ? "AND (SELECT delivered from delivery_orders where id = doi.delivery_order_id)" : ''; [ "order.${vc}_id" => { gt => 0 }, @@ -275,6 +302,7 @@ sub init_models { }, query => $self->delivery_plan_query, with_objects => [ 'order', "order.$vc", 'part' ], + additional_url_params => { vc => $vc}, ); } @@ -285,6 +313,12 @@ sub init_vc { return $::form->{vc} if ($::form->{vc} eq 'customer' || $::form->{vc} eq 'vendor') || croak "self (DeliveryPlan) has no vc defined"; } +sub init_all_employees { + return SL::DB::Manager::Employee->get_all_sorted; +} +sub init_all_businesses { + return SL::DB::Manager::Business->get_all_sorted; +} sub link_to { my ($self, $object, %params) = @_;