Pflichtenhefte -> Angebote/Aufträge: nur Artikel mit Zeit-basierenden Einheiten
[kivitendo-erp.git] / SL / Controller / RequirementSpecOrder.pm
index e444a7c..1630320 100644 (file)
@@ -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);
@@ -201,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
 #