BUGFIX: Kreditorenbuchungen: Fehler beim Nutzen von Drafts
[kivitendo-erp.git] / SL / Controller / Employee.pm
1 package SL::Controller::Employee;
2
3 use strict;
4 use parent qw(SL::Controller::Base);
5
6 use SL::DB::Employee;
7 use SL::Helper::Flash;
8
9 __PACKAGE__->run_before('check_auth');
10 __PACKAGE__->run_before('load_all');
11 __PACKAGE__->run_before('load_from_form');
12 __PACKAGE__->run_before('assign_from_form');
13
14 our @updatable_columns = qw(deleted);
15
16 sub action_list {
17   my ($self, %params) = @_;
18
19   $self->render('employee/list', title => $::locale->text('Employees'));
20 }
21
22 sub action_edit {
23   my ($self, %params) = @_;
24
25   if ($self->{employee}) {
26     $self->render('employee/edit', title => $::locale->text('Edit Employee #1', $self->{employee}->safe_name));
27   } else {
28     flash('error', $::locale->text('Could not load employee'));
29     $self->redirect_to(action => 'list');
30   }
31 }
32
33 sub action_save {
34   my ($self, %params) = @_;
35
36   $self->{employee}->save;
37
38   flash('info', $::locale->text('Employee #1 saved!'));
39
40   $self->redirect_to(action => 'edit', 'employee.id' => $self->{employee}->id);
41 }
42
43 #################### private stuff ##########################
44
45 sub check_auth {
46   $::auth->assert('admin');
47 }
48
49 sub load_all {
50   $_[0]{employees} = SL::DB::Manager::Employee->get_all;
51 }
52
53 sub load_from_form {
54   $_[0]{employee} = SL::DB::Manager::Employee->find_by(id => delete $::form->{employee}{id});
55 }
56
57 sub assign_from_form {
58   my %data = %{ $::form->{employee} || {} };
59
60   return 1 unless keys %data;
61
62   $_[0]{employee}->assign_attributes(map { $_ => $data{$_} } @updatable_columns);
63   return 1;
64 }
65
66
67 ######################## behaviour ##########################
68
69 sub delay_flash_on_redirect { 1 }
70
71 1;