X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FPart.pm;h=f589a715a5b61a292e1e758c238aac7b9f05c550;hb=b9cd11d78faef7815e435c11aa6a12793e9cb9c9;hp=804ad159032f0dd46e187b86443121d26a638bb2;hpb=115e5a24fdbd1afcabfea1e308aae00b6cd55106;p=kivitendo-erp.git diff --git a/SL/Controller/Part.pm b/SL/Controller/Part.pm index 804ad1590..f589a715a 100644 --- a/SL/Controller/Part.pm +++ b/SL/Controller/Part.pm @@ -33,7 +33,7 @@ use Rose::Object::MakeMethods::Generic ( all_buchungsgruppen all_payment_terms all_warehouses parts_classification_filter all_languages all_units all_price_factors) ], - 'scalar' => [ qw(warehouse bin) ], + 'scalar' => [ qw(warehouse bin stock_amounts journal) ], ); # safety @@ -140,11 +140,11 @@ sub action_save { )->save(); CVar->save_custom_variables( - dbh => $self->part->db->dbh, - module => 'IC', - trans_id => $self->part->id, - variables => $::form, # $::form->{cvar} would be nicer - always_valid => 1, + dbh => $self->part->db->dbh, + module => 'IC', + trans_id => $self->part->id, + variables => $::form, # $::form->{cvar} would be nicer + save_validity => 1, ); 1; @@ -229,7 +229,6 @@ sub render_form { %assembly_vars = %{ $self->prepare_assembly_render_vars } if $self->part->is_assembly; $params{CUSTOM_VARIABLES} = CVar->get_custom_variables(module => 'IC', trans_id => $self->part->id); - $_->{valid} = 1 for @{ $params{CUSTOM_VARIABLES} }; CVar->render_inputs('variables' => $params{CUSTOM_VARIABLES}, show_disabled_message => 1, partsgroup_id => $self->part->partsgroup_id) if (scalar @{ $params{CUSTOM_VARIABLES} }); @@ -264,6 +263,17 @@ sub action_history { history_entries => $history_entries); } +sub action_inventory { + my ($self) = @_; + + $::auth->assert('warehouse_contents'); + + $self->stock_amounts($self->part->get_simple_stock_sql); + $self->journal($self->part->get_mini_journal); + + $_[0]->render('part/_inventory_data', { layout => 0 }); +}; + sub action_update_item_totals { my ($self) = @_; @@ -400,23 +410,28 @@ sub action_add_assembly_item { } sub action_show_multi_items_dialog { + my ($self) = @_; + + my $search_term = $self->models->filtered->laundered->{all_substr_multi__ilike}; + $search_term ||= $self->models->filtered->laundered->{all_with_makemodel_substr_multi__ilike}; + $search_term ||= $self->models->filtered->laundered->{all_with_customer_partnumber_substr_multi__ilike}; + $_[0]->render('part/_multi_items_dialog', { layout => 0 }, - all_partsgroups => SL::DB::Manager::PartsGroup->get_all + all_partsgroups => SL::DB::Manager::PartsGroup->get_all, + search_term => $search_term ); } sub action_multi_items_update_result { my $max_count = 100; - $::form->{multi_items}->{filter}->{obsolete} = 0; - my $count = $_[0]->multi_items_models->count; if ($count == 0) { my $text = escape($::locale->text('No results.')); $_[0]->render($text, { layout => 0 }); } elsif ($count > $max_count) { - my $text = escpae($::locale->text('Too many results (#1 from #2).', $count, $max_count)); + my $text = escape($::locale->text('Too many results (#1 from #2).', $count, $max_count)); $_[0]->render($text, { layout => 0 }); } else { my $multi_items = $_[0]->multi_items_models->get; @@ -565,7 +580,9 @@ sub action_ajax_autocomplete { # since we need a second get models instance with different filters for that, # we only modify the original filter temporarily in place if ($::form->{prefer_exact}) { - local $::form->{filter}{'all::ilike'} = delete local $::form->{filter}{'all:substr:multi::ilike'}; + local $::form->{filter}{'all::ilike'} = delete local $::form->{filter}{'all:substr:multi::ilike'}; + local $::form->{filter}{'all_with_makemodel::ilike'} = delete local $::form->{filter}{'all_with_makemodel:substr:multi::ilike'}; + local $::form->{filter}{'all_with_customer_partnumber::ilike'} = delete local $::form->{filter}{'all_with_customer_partnumber:substr:multi::ilike'}; my $exact_models = SL::Controller::Helper::GetModels->new( controller => $self, @@ -601,7 +618,13 @@ sub action_test_page { } sub action_part_picker_search { - $_[0]->render('part/part_picker_search', { layout => 0 }); + my ($self) = @_; + + my $search_term = $self->models->filtered->laundered->{all_substr_multi__ilike}; + $search_term ||= $self->models->filtered->laundered->{all_with_makemodel_substr_multi__ilike}; + $search_term ||= $self->models->filtered->laundered->{all_with_customer_partnumber_substr_multi__ilike}; + + $_[0]->render('part/part_picker_search', { layout => 0 }, search_term => $search_term); } sub action_part_picker_result { @@ -644,6 +667,8 @@ sub prepare_assortment_render_vars { sub prepare_assembly_render_vars { my ($self) = @_; + croak("Need assembly item(s) to create a 'save as new' assembly.") unless $self->part->items; + my %vars = ( items_sellprice_sum => $self->part->items_sellprice_sum, items_lastcost_sum => $self->part->items_lastcost_sum, assembly_html => $self->render_assembly_items_to_html( \@{ $self->part->items } ), @@ -731,6 +756,8 @@ sub parse_form { $self->part->assign_attributes(%{ $params}); $self->part->bin_id(undef) unless $self->part->warehouse_id; + $self->normalize_text_blocks; + # Only reset items ([]) and rewrite from form if $::form->{assortment_items} isn't empty. This # will be the case for used assortments when saving, or when a used assortment # is "used as new" @@ -887,6 +914,8 @@ sub init_part { if ( $::form->{part}{id} ) { return SL::DB::Part->new(id => $::form->{part}{id})->load(with => [ qw(makemodels customerprices prices translations partsgroup shop_parts shop_parts.shop) ]); + } elsif ( $::form->{id} ) { + return SL::DB::Part->new(id => $::form->{id})->load; # used by inventory tab } else { die "part_type missing" unless $::form->{part}{part_type}; return SL::DB::Part->new(part_type => $::form->{part}{part_type}); @@ -1193,6 +1222,25 @@ sub check_has_valid_part_type { die "invalid part_type" unless $_[0] =~ /^(part|service|assembly|assortment)$/; } + +sub normalize_text_blocks { + my ($self) = @_; + + # check if feature is enabled (select normalize_part_descriptions from defaults) + return unless ($::instance_conf->get_normalize_part_descriptions); + + # text block + foreach (qw(description)) { + $self->part->{$_} =~ s/\s+$//s; + $self->part->{$_} =~ s/^\s+//s; + $self->part->{$_} =~ s/ {2,}/ /g; + } + # html block (caveat: can be circumvented by using bold or italics) + $self->part->{notes} =~ s/^

( )+\s+/

/s; + $self->part->{notes} =~ s/( )+<\/p>$/<\/p>/s; + +} + sub render_assortment_items_to_html { my ($self, $assortment_items, $number_of_items) = @_;