X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FController%2FPart.pm;h=3f7409e8bb14a010d83c398f0fd7c9a80c2542fa;hb=2f5ea2de698efeaf8e7c31dcbc27b4e996f5e2ca;hp=cfc94eea14a0355d0a32bd49b41007e3e5258375;hpb=8c30110b9ee3e0c7f21a49df3ae91dd8f31f1caf;p=kivitendo-erp.git diff --git a/SL/Controller/Part.pm b/SL/Controller/Part.pm index cfc94eea1..3f7409e8b 100644 --- a/SL/Controller/Part.pm +++ b/SL/Controller/Part.pm @@ -12,6 +12,7 @@ use SL::Controller::Helper::GetModels; use SL::Locale::String qw(t8); use SL::JSON; use List::Util qw(sum); +use List::UtilsBy qw(extract_by); use SL::Helper::Flash; use Data::Dumper; use DateTime; @@ -124,11 +125,6 @@ sub action_save { # $self->part has been loaded, parsed and validated without errors and is ready to be saved $self->part->db->with_transaction(sub { - if ( $params{save_as_new} ) { - $self->part( $self->part->clone_and_reset_deep ); - $self->part->partnumber(undef); # will be assigned by _before_save_set_partnumber - }; - $self->part->save(cascade => 1); SL::DB::History->new( @@ -150,7 +146,6 @@ sub action_save { 1; }) or return $self->js->error(t8('The item couldn\'t be saved!') . " " . $self->part->db->error )->render; - ; flash_later('info', $is_new ? t8('The item has been created.') . " " . $self->part->displayable_name : t8('The item has been saved.')); if ( $::form->{callback} ) { @@ -162,9 +157,12 @@ sub action_save { } } -sub action_save_as_new { +sub action_abort { my ($self) = @_; - $self->action_save(save_as_new=>1); + + if ( $::form->{callback} ) { + $self->redirect_to($::form->unescape($::form->{callback})); + } } sub action_delete { @@ -230,8 +228,11 @@ sub render_form { $params{CUSTOM_VARIABLES} = CVar->get_custom_variables(module => 'IC', trans_id => $self->part->id); - CVar->render_inputs('variables' => $params{CUSTOM_VARIABLES}, show_disabled_message => 1, partsgroup_id => $self->part->partsgroup_id) - if (scalar @{ $params{CUSTOM_VARIABLES} }); + if (scalar @{ $params{CUSTOM_VARIABLES} }) { + CVar->render_inputs('variables' => $params{CUSTOM_VARIABLES}, show_disabled_message => 1, partsgroup_id => $self->part->partsgroup_id); + $params{CUSTOM_VARIABLES_FIRST_TAB} = []; + @{ $params{CUSTOM_VARIABLES_FIRST_TAB} } = extract_by { $_->{first_tab} == 1 } @{ $params{CUSTOM_VARIABLES} }; + } my %title_hash = ( part => t8('Edit Part'), assembly => t8('Edit Assembly'), @@ -280,8 +281,9 @@ sub action_update_item_totals { my $part_type = $::form->{part_type}; die unless $part_type =~ /^(assortment|assembly)$/; - my $sellprice_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'sellcost'); - my $lastcost_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'lastcost'); + my $sellprice_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'sellcost'); + my $lastcost_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'lastcost'); + my $items_weight_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'weight'); my $sum_diff = $sellprice_sum-$lastcost_sum; @@ -291,6 +293,7 @@ sub action_update_item_totals { ->html('#items_sum_diff', $::form->format_amount(\%::myconfig, $sum_diff, 2, 0)) ->html('#items_sellprice_sum_basic', $::form->format_amount(\%::myconfig, $sellprice_sum, 2, 0)) ->html('#items_lastcost_sum_basic', $::form->format_amount(\%::myconfig, $lastcost_sum, 2, 0)) + ->html('#items_weight_sum_basic' , $::form->format_amount(\%::myconfig, $items_weight_sum)) ->no_flash_clear->render(); } @@ -396,6 +399,7 @@ sub action_add_assembly_item { my $items_sellprice_sum = $part->items_sellprice_sum; my $items_lastcost_sum = $part->items_lastcost_sum; my $items_sum_diff = $items_sellprice_sum - $items_lastcost_sum; + my $items_weight_sum = $part->items_weight_sum; $self->js ->append('#assembly_rows', $html) # append in tbody @@ -406,6 +410,7 @@ sub action_add_assembly_item { ->html('#items_sum_diff', $::form->format_amount(\%::myconfig, $items_sum_diff , 2, 0)) ->html('#items_sellprice_sum_basic', $::form->format_amount(\%::myconfig, $items_sellprice_sum, 2, 0)) ->html('#items_lastcost_sum_basic' , $::form->format_amount(\%::myconfig, $items_lastcost_sum , 2, 0)) + ->html('#items_weight_sum_basic' , $::form->format_amount(\%::myconfig, $items_weight_sum)) ->render; } @@ -730,7 +735,9 @@ sub recalc_item_totals { } } elsif ( $part->is_assembly ) { $part->assemblies( @{$self->assembly_items} ); - if ( $params{price_type} eq 'lastcost' ) { + if ( $params{price_type} eq 'weight' ) { + return $part->items_weight_sum; + } elsif ( $params{price_type} eq 'lastcost' ) { return $part->items_lastcost_sum; } else { return $part->items_sellprice_sum; @@ -1335,6 +1342,12 @@ sub _setup_form_action_bar { ], ], # end of combobox "Save" + action => [ + t8('Abort'), + submit => [ '#ic', { action => "Part/abort" } ], + only_if => !!$::form->{show_abort}, + ], + action => [ t8('Delete'), call => [ 'kivi.Part.delete' ],