]> wagnertech.de Git - kivitendo-erp.git/blobdiff - SL/DB/Project.pm
Lohnbuchhaltungsimport: Leere Werte für Abteilungen abfangen
[kivitendo-erp.git] / SL / DB / Project.pm
index aa97f764ea39573a89c830702f22bd54573de9b8..54975350c8bc71953b4f77b50caf0d7f03e75f4f 100644 (file)
@@ -12,6 +12,13 @@ use SL::DB::Helper::CustomVariables(
   cvars_alias => 1,
 );
 
   cvars_alias => 1,
 );
 
+__PACKAGE__->meta->add_relationship(
+  employee_invoice_permissions  => {
+    type       => 'many to many',
+    map_class  => 'SL::DB::EmployeeProjectInvoices',
+  },
+);
+
 __PACKAGE__->meta->initialize;
 
 sub validate {
 __PACKAGE__->meta->initialize;
 
 sub validate {
@@ -48,6 +55,12 @@ sub is_projectnumber_unique {
   return !SL::DB::Manager::Project->get_first(where => \@filter);
 }
 
   return !SL::DB::Manager::Project->get_first(where => \@filter);
 }
 
+sub displayable_name {
+  my ($self) = @_;
+
+  return join ' ', grep $_, $self->projectnumber, $self->description;
+}
+
 sub full_description {
   my ($self, %params) = @_;
 
 sub full_description {
   my ($self, %params) = @_;
 
@@ -60,7 +73,7 @@ sub full_description {
   } elsif ($params{style} =~ m/description/) {
     $description = $self->description;
 
   } elsif ($params{style} =~ m/description/) {
     $description = $self->description;
 
-  } elsif ($params{style} =~ m/full/) {
+  } elsif (($params{style} =~ m/full/) && $self->customer) {
     $description = $self->projectnumber;
     if ($self->description && do { my $desc = quotemeta $self->description; $self->projectnumber !~ m/$desc/ }) {
       $description .= ' ' . $self->description;
     $description = $self->projectnumber;
     if ($self->description && do { my $desc = quotemeta $self->description; $self->projectnumber !~ m/$desc/ }) {
       $description .= ' ' . $self->description;
@@ -78,6 +91,23 @@ sub full_description {
   return $description;
 }
 
   return $description;
 }
 
+sub may_employee_view_project_invoices {
+  my ($self, $employee) = @_;
+
+  return undef if !$self->id;
+
+  my $employee_id = ref($employee) ? $employee->id : $employee * 1;
+  my $query       = <<EOSQL;
+    SELECT project_id
+    FROM employee_project_invoices
+    WHERE (employee_id = ?)
+      AND (project_id  = ?)
+    LIMIT 1
+EOSQL
+
+  return !!$self->db->dbh->selectrow_arrayref($query, undef, $employee_id, $self->id)->[0];
+}
+
 1;
 
 __END__
 1;
 
 __END__
@@ -113,6 +143,11 @@ Returns trueish if the project number is not used for any other
 project in the database. Also returns trueish if no project number has
 been set yet.
 
 project in the database. Also returns trueish if no project number has
 been set yet.
 
+=item C<displayable_name>
+
+Returns a human-readable description of the project, consisting of projectnumber
+and description.
+
 =item C<full_description %params>
 
 Returns a full description for the project which can consist of the
 =item C<full_description %params>
 
 Returns a full description for the project which can consist of the
@@ -143,6 +178,9 @@ description in parenthesis (e.g. "Evil Corp (12345 World
 domination)"). If the project's description is already part of the
 project's number then it will not be appended.
 
 domination)"). If the project's description is already part of the
 project's number then it will not be appended.
 
+If this project isn't linked to a customer then the style C<both> is
+used instead.
+
 =back
 
 =back
 =back
 
 =back