X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/1cc65ebc086c1821dfcd08bcc97f8b6255dcec65..815cf361bd5ae8ae0e7002423be5d307993f69f5:/SL/Controller/RequirementSpecOrder.pm diff --git a/SL/Controller/RequirementSpecOrder.pm b/SL/Controller/RequirementSpecOrder.pm index 6dfab604b..fc0fbea41 100644 --- a/SL/Controller/RequirementSpecOrder.pm +++ b/SL/Controller/RequirementSpecOrder.pm @@ -22,7 +22,7 @@ use constant TAB_ID => 'ui-tabs-4'; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(parts) ], - 'scalar --get_set_init' => [ qw(requirement_spec rs_order js h_unit_name all_customers all_parts) ], + 'scalar --get_set_init' => [ qw(requirement_spec rs_order js h_unit_name all_customers all_parts_time_unit) ], ); __PACKAGE__->run_before('setup'); @@ -40,6 +40,10 @@ sub action_list { sub action_new { my ($self) = @_; + if (!@{ $self->all_parts_time_unit }) { + return $self->js->flash('error', t8('This function requires the presence of articles with a time-based unit such as "h" or "min".'))->render($self); + } + my $html = $self->render('requirement_spec_order/new', { output => 0 }, make_part_title => sub { $_[0]->partnumber . ' ' . $_[0]->description }); $self->js->html('#' . TAB_ID(), $html) ->render($self); @@ -139,6 +143,10 @@ sub action_do_update { sub action_edit_assignment { my ($self) = @_; + if (!@{ $self->all_parts_time_unit }) { + return $self->js->flash('error', t8('This function requires the presence of articles with a time-based unit such as "h" or "min".'))->render($self); + } + my $html = $self->render('requirement_spec_order/edit_assignment', { output => 0 }, make_part_title => sub { $_[0]->partnumber . ' ' . $_[0]->description }); $self->js->html('#' . TAB_ID(), $html) ->render($self); @@ -154,6 +162,20 @@ sub action_save_assignment { ->render($self); } +sub action_delete { + my ($self) = @_; + + my $order = $self->rs_order->order; + + $order->delete; + $self->init_requirement_spec; + + my $html = $self->render('requirement_spec_order/list', { output => 0 }); + $self->js->html('#' . TAB_ID(), $html) + ->flash('info', $order->quotation ? t8('Sales quotation #1 has been deleted.', $order->quonumber) : t8('Sales order #1 has been deleted.', $order->ordnumber)) + ->render($self); +} + sub action_cancel { my ($self) = @_; @@ -170,7 +192,7 @@ sub setup { my ($self) = @_; $::auth->assert('sales_quotation_edit'); - $::request->{layout}->use_stylesheet("${_}.css") for qw(jquery.contextMenu requirement_spec); + $::request->{layout}->use_stylesheet("${_}.css") for qw(jquery.contextMenu requirement_spec autocomplete_part); $::request->{layout}->use_javascript("${_}.js") for qw(jquery.jstree jquery/jquery.contextMenu client_js requirement_spec); return 1; @@ -187,10 +209,19 @@ sub init_js { } sub init_all_customers { SL::DB::Manager::Customer->get_all_sorted } -sub init_all_parts { SL::DB::Manager::Part->get_all_sorted } sub init_h_unit_name { first { SL::DB::Manager::Unit->find_by(name => $_) } qw(Std h Stunde) }; sub init_rs_order { SL::DB::RequirementSpecOrder->new(id => $::form->{rs_order_id})->load }; +sub init_all_parts_time_unit { + my ($self) = @_; + + return [] unless $self->h_unit_name; + + my @convertible_unit_names = map { $_->name } @{ SL::DB::Manager::Unit->find_by(name => $self->h_unit_name)->convertible_units }; + + return SL::DB::Manager::Part->get_all_sorted(where => [ unit => \@convertible_unit_names ]); +} + # # helpers # @@ -210,7 +241,7 @@ sub create_order_item { if (!$section->{keep_description}) { $description = '<%fb_number%> <%title%>' unless $description =~ m{<%}; - $description =~ s{<% (.+?) %>}{$section->$1}egx; + $description =~ s{<% (.+?) %>}{ $section->can($1) ? $section->$1 : '<' . t8('Invalid variable #1', $1) . '>' }egx; } $item->assign_attributes(