Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 5b3c65a4

Von Bernd Bleßmann vor mehr als 3 Jahren hinzugefügt

  • ID 5b3c65a4fd8b913f4b4cba2adde73e1454c3e9a1
  • Vorgänger 6270ebd1
  • Nachfolger dbba5f4d

Zeiterfassung: Erweiterung f. Datum und Dauer: DB-Upgrade/Rose; Berichtsanzeige

Unterschiede anzeigen:

SL/Controller/TimeRecording.pm
29 29
__PACKAGE__->run_before('check_auth_edit', only => [ qw(edit save delete) ]);
30 30

  
31 31
my %sort_columns = (
32
  date         => t8('Date'),
32 33
  start_time   => t8('Start'),
33 34
  end_time     => t8('End'),
34 35
  customer     => t8('Customer'),
......
48 49
  my ($self, %params) = @_;
49 50

  
50 51
  $::form->{filter} //=  {
51
    staff_member_id       => SL::DB::Manager::Employee->current->id,
52
    "start_time:date::ge" => DateTime->now_local->add(weeks => -2)->to_kivitendo,
52
    staff_member_id => SL::DB::Manager::Employee->current->id,
53
    "date:date::ge" => DateTime->today_local->add(weeks => -2)->to_kivitendo,
53 54
  };
54 55

  
55 56
  $self->setup_list_action_bar;
......
195 196
  my $report      = SL::ReportGenerator->new(\%::myconfig, $::form);
196 197
  $self->{report} = $report;
197 198

  
198
  my @columns  = qw(start_time end_time customer part project description staff_member duration booked);
199
  my @columns  = qw(date start_time end_time customer part project description staff_member duration booked);
199 200

  
200 201
  my %column_defs = (
202
    date         => { text => t8('Date'),         sub => sub { $_[0]->date_as_date },
203
                      obj_link => sub { $self->url_for(action => 'edit', 'id' => $_[0]->id, callback => $self->models->get_callback) }  },
201 204
    start_time   => { text => t8('Start'),        sub => sub { $_[0]->start_time_as_timestamp },
202 205
                      obj_link => sub { $self->url_for(action => 'edit', 'id' => $_[0]->id, callback => $self->models->get_callback) }  },
203 206
    end_time     => { text => t8('End'),          sub => sub { $_[0]->end_time_as_timestamp },
SL/DB/Manager/TimeRecording.pm
16 16

  
17 17
sub _sort_spec {
18 18
  return ( default => [ 'start_time', 1 ],
19
           columns => { SIMPLE    => 'ALL' ,
20
                        customer  => [ 'lower(customer.name)', ],
19
           nulls   => {
20
             date       => 'FIRST',
21
             start_time => 'FIRST',
22
             end_time   => 'FIRST',
23
           },
24
           columns => { SIMPLE     => 'ALL' ,
25
                        start_time => [ 'date', 'start_time' ],
26
                        end_time   => [ 'date', 'end_time' ],
27
                        customer   => [ 'lower(customer.name)', 'date','start_time'],
21 28
           }
22 29
  );
23 30
}
SL/DB/MetaSetup/TimeRecording.pm
11 11
__PACKAGE__->meta->columns(
12 12
  booked          => { type => 'boolean', default => 'false' },
13 13
  customer_id     => { type => 'integer', not_null => 1 },
14
  date            => { type => 'date', not_null => 1 },
14 15
  description     => { type => 'text', not_null => 1 },
16
  duration        => { type => 'integer' },
15 17
  employee_id     => { type => 'integer', not_null => 1 },
16 18
  end_time        => { type => 'timestamp' },
17 19
  id              => { type => 'serial', not_null => 1 },
......
21 23
  payroll         => { type => 'boolean', default => 'false' },
22 24
  project_id      => { type => 'integer' },
23 25
  staff_member_id => { type => 'integer', not_null => 1 },
24
  start_time      => { type => 'timestamp', not_null => 1 },
26
  start_time      => { type => 'timestamp' },
25 27
);
26 28

  
27 29
__PACKAGE__->meta->primary_key_columns([ 'id' ]);
SL/DB/TimeRecording.pm
119 119
  return ($self->start_time_as_timestamp||$ph) . ' - ' . ($self->end_time_as_timestamp||$ph);
120 120
}
121 121

  
122
sub duration {
123
  my ($self) = @_;
124

  
125
  if ($self->start_time && $self->end_time) {
126
    return ($self->end_time->subtract_datetime_absolute($self->start_time))->seconds/60.0;
127
  } else {
128
    return;
129
  }
130
}
131

  
132 122
1;
sql/Pg-upgrade2/time_recordings_date_duration.sql
1
-- @tag: time_recordings_date_duration
2
-- @description: Erweiterung Zeiterfassung um Datum und Dauer
3
-- @depends: time_recordings2
4

  
5
ALTER TABLE time_recordings ADD   COLUMN date     DATE;
6
ALTER TABLE time_recordings ADD   COLUMN duration INTEGER;
7

  
8
UPDATE time_recordings SET date = start_time::DATE;
9
ALTER TABLE time_recordings ALTER COLUMN start_time DROP NOT NULL;
10
ALTER TABLE time_recordings ALTER COLUMN date SET NOT NULL;
11

  
12
UPDATE time_recordings SET duration = EXTRACT(EPOCH FROM (end_time - start_time))/60;
13

  
14
-- trigger to set date from start_time
15
CREATE OR REPLACE FUNCTION time_recordings_set_date_trigger()
16
RETURNS TRIGGER AS $$
17
  BEGIN
18
    IF NEW.start_time IS NOT NULL THEN
19
      NEW.date = NEW.start_time::DATE;
20
    END IF;
21
    RETURN NEW;
22
  END;
23
$$ LANGUAGE plpgsql;
24

  
25
CREATE TRIGGER time_recordings_set_date BEFORE INSERT OR UPDATE ON time_recordings FOR EACH ROW EXECUTE PROCEDURE time_recordings_set_date_trigger();
26

  
27
-- trigger to set duration from start_time and end_time
28
CREATE OR REPLACE FUNCTION time_recordings_set_duration_trigger()
29
RETURNS TRIGGER AS $$
30
  BEGIN
31
    IF NEW.start_time IS NOT NULL AND NEW.end_time IS NOT NULL THEN
32
      NEW.duration = EXTRACT(EPOCH FROM (NEW.end_time - NEW.start_time))/60;
33
    END IF;
34
    RETURN NEW;
35
  END;
36
$$ LANGUAGE plpgsql;
37

  
38
CREATE TRIGGER time_recordings_set_duration BEFORE INSERT OR UPDATE ON time_recordings FOR EACH ROW EXECUTE PROCEDURE time_recordings_set_duration_trigger();
templates/webpages/time_recording/_filter.html
11 11
<a href='#' onClick='javascript:$(".filter_toggle").toggle()'>[% 'Hide Filter' | $T8 %]</a>
12 12
 <table id='filter_table'>
13 13
  <tr>
14
   <th align="right">[% 'Start' | $T8 %] [% 'From Date' | $T8 %]</th>
15
   <td>[% L.date_tag('filter.start_time:date::ge', filter.start_time_date__ge) %]</td>
14
   <th align="right">[% 'Date' | $T8 %] [% 'From Date' | $T8 %]</th>
15
   <td>[% L.date_tag('filter.date:date::ge', filter.date_date__ge) %]</td>
16 16
  </tr>
17 17
  <tr>
18
   <th align="right">[% 'Start' | $T8 %] [% 'To Date' | $T8 %]</th>
19
   <td>[% L.date_tag('filter.start_time:date::le', filter.start_time_date__le) %]</td>
18
   <th align="right">[% 'Date' | $T8 %] [% 'To Date' | $T8 %]</th>
19
   <td>[% L.date_tag('filter.date:date::le', filter.date_date__le) %]</td>
20 20
  </tr>
21 21
  <tr>
22 22
    <th align="right">[% 'Customer' | $T8 %]</th>

Auch abrufbar als: Unified diff