X-Git-Url: https://git.infodrom.org/?p=infodrom.org%2Fservice.infodrom.org;a=blobdiff_plain;f=src%2FInfoCon%2Fstempel%2Fstempel;h=7bb7bbcdcab9d21f11991b85e0ba38a97adefada;hp=ba0ba624138eb0c3d552f9913d15edde443dfbd8;hb=600133bccb4f5bbc11fc7ee39ca0499c95360d27;hpb=d7b962c8a338f66fd193aa4c30699045646c27e9 diff --git a/src/InfoCon/stempel/stempel b/src/InfoCon/stempel/stempel index ba0ba62..7bb7bbc 100755 --- a/src/InfoCon/stempel/stempel +++ b/src/InfoCon/stempel/stempel @@ -1,7 +1,7 @@ #! /usr/bin/perl -# Time Tracker -# Copyright (c) 2007,8,13,14 Martin Schulze +# InfoCon Time Tracker +# Copyright (c) 2007,8,13,14,15 Martin Schulze # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -78,13 +78,32 @@ sub tasklist return \@res; } +sub complete_customer +{ + my ($customer, $text, $line, $start) = @_; + + # return () unless exists $answers->{category} && length $answers->{category}; + + my $sql = sprintf("SELECT DISTINCT task FROM stempel WHERE start > now() - interval '1 month' AND customer = '%s' AND task LIKE '%s%%' ORDER BY task", + $customer, + $line); + + my $sth = $dbh->prepare($sql); + $sth->execute; + my @complete; + while (my $row = $sth->fetchrow_hashref) { + $row->{task} = substr $row->{task}, $start if $start; + push @complete, $row->{task}; + } + + return @complete; +} + sub open_task { my $term = new Term::ReadLine ''; my $customers = customerlist; - $term->addhistory($_) foreach (@$customers); - my $attribs = $term->Attribs; $attribs->{completion_entry_function} = $attribs->{list_completion_function}; $attribs->{completion_word} = $customers; @@ -100,6 +119,8 @@ sub open_task $term->addhistory($_) foreach (@$tasks); $attribs->{completion_word} = $tasks; + $attribs->{completion_entry_function} = undef; + $term->{completion_function} = sub {return complete_customer $customer, @_}; while (1) { my $task = $term->readline ('Aufgabe: '); return unless length $task; @@ -110,6 +131,7 @@ sub open_task next; } + $task =~ s/\s*$//; my $query = q{INSERT INTO stempel (start,customer,task) VALUES('now()',?,?)}; my $sth = $dbh->prepare($query); $sth->execute($customer, $task); @@ -122,7 +144,7 @@ sub quarter { my $min = shift; - return 15 if $min < 15; + return 15 if $min > 0 && $min < 15; return $min - $min%15 if ($min%15 < 3); @@ -142,7 +164,9 @@ sub hdiff sub close_task { + my $really = shift; my ($d_sec,$d_min,$d_hour,$d_mday,$d_mon,$d_year,$d_wday,$d_isdst) = localtime(); + my $today = 1; my $query = q{SELECT oid,start FROM stempel WHERE stop IS NULL}; my $sth = $dbh->prepare ($query); @@ -152,12 +176,18 @@ sub close_task my @d = split(/-/, $arr[0]); if ($d[0] != $d_year+1900 || $d[1] != $d_mon+1 || $d[2] != $d_mday) { - printf "Task not started today, aborting.\n"; - next; + if ($really) { + printf "Task not started today.\n"; + $today = 0; + } else { + printf "Task not started today, aborting, use -D if this is intentional.\n"; + next; + } } my @t = split(/:/, $arr[1]); my $int = quarter(hdiff($t[0], $t[1], $d_hour, $d_min)); + $int += 24 * 60 unless $today; $query = sprintf('UPDATE stempel SET stop=now(),time=%d WHERE oid = %d', $int, $row->{oid}); @@ -176,11 +206,25 @@ sub delete_task exit(0); } +sub reopen_task +{ + my $sql = q{SELECT max(id) AS max_id FROM stempel}; + my $sth = $dbh->prepare($sql); + if ($sth && $sth->execute > 0) { + my $row = $sth->fetchrow_hashref; + $sql = sprintf("UPDATE stempel SET stop = NULL, time = NULL WHERE id = %d", $row->{max_id}); + $dbh->do($sql); + } + + exit(0); +} + sub list_open { my $exit = shift; my ($d_sec,$d_min,$d_hour,$d_mday,$d_mon,$d_year,$d_wday,$d_isdst) = localtime(); my $query = q{SELECT customer,start,task FROM stempel WHERE time IS NULL ORDER BY start,customer}; + my $today = 1; my $sth = $dbh->prepare ($query); if ($sth && $sth->execute > 0) { @@ -191,12 +235,14 @@ sub list_open if ($d[0] != $d_year+1900 || $d[1] != $d_mon+1 || $d[2] != $d_mday) { printf "Task not started today.\n"; - next if $exit eq 1; + $today = 0; + next if defined $exit && $exit eq 1; } my @t = split(/:/, $arr[1]); my $time = sprintf('%02d:%02d', $t[0], $t[1]); my $int = quarter(hdiff($t[0], $t[1], $d_hour, $d_min)); + $int += 24 * 60 unless $today; printf "%-15s %s %s (%s) %s\n", $row->{customer}, $day, $time, min2hour($int), $row->{task}; } @@ -278,6 +324,18 @@ sub alter_task my $term = new Term::ReadLine ''; + my $sql = q{SELECT customer,task FROM stempel WHERE stop IS NULL}; + my $sth = $dbh->prepare($sql); + $sth->execute; + my $row = $sth->fetchrow_hashref; + + my $tasks = tasklist $row->{'customer'}; + $term->addhistory($_) foreach (@$tasks); + + my $attribs = $term->Attribs; + $attribs->{completion_word} = $tasks; + $term->{completion_function} = sub {return complete_customer $row->{'customer'}, @_}; + my $task = $term->readline ('Aufgabe: '); if (length($task) > 0) { @@ -298,7 +356,9 @@ stempel Copyright (c) 2007,8 Martin Schulze --close time close open task --help this text --end|-d terminate task + -D terminate task not started today --delete delete open task + --reopen re-open last task --task alter task content END exit; @@ -313,8 +373,10 @@ my %options = ('list:s' => \$opt_list, 'help' => \&help, 'close=i' => \$opt_close, 'delete' => \&delete_task, + 'reopen' => \&reopen_task, 'task|t' => \&alter_task, 'terminate|end|d' => \&close_task, + 'D' => sub {close_task(1);}, ); GetOptions %options;