5 # Copyright (c) 2007,8 Martin Schulze <joey@infodrom.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
28 my $table = "stempel";
29 my $engine = "dbi:Pg:dbname=infocon";
31 my $dbh = DBI->connect($engine);
33 print "Access to database denied!\n";
36 $dbh->do("SET DateStyle = 'ISO'");
42 return sprintf('%02d:%02d', $minutes/60, $minutes%60);
47 my $query = q{SELECT count(*) AS count FROM stempel WHERE stop IS NULL};
48 my $sth = $dbh->prepare ($query);
49 if ($sth && $sth->execute > 0) {
50 my $row = $sth->fetchrow_hashref;
51 return $row->{count} > 0 ? 1 : 0;
60 my $query = q{SELECT DISTINCT customer FROM stempel ORDER BY customer};
61 my $sth = $dbh->prepare ($query);
62 if ($sth && $sth->execute > 0) {
63 while ((my $row = $sth->fetchrow_hashref)) {
64 push @res, $row->{customer};
72 my $term = new Term::ReadLine '';
73 my @customers = customerlist;
75 $term->addhistory($_) foreach (@customers);
77 my $attribs = $term->Attribs;
78 $attribs->{completion_entry_function} = $attribs->{list_completion_function};
79 $attribs->{completion_word} = \@customers;
81 printf "[%s]\n", join (', ', @customers);
83 my $customer = $term->readline ('Kunde: ');
85 if (defined $customer && length($customer) > 0) {
86 $customer =~ s/\s*$//;
87 $attribs->{completion_word} = undef;
88 my $task = $term->readline ('Aufgabe: ');
89 if (length($task) > 0) {
90 my $query = q{INSERT INTO stempel (start,customer,task) VALUES('now()',?,?)};
91 my $sth = $dbh->prepare($query);
92 $sth->execute($customer, $task);
101 return 15 if $min < 15;
103 return $min - $min%15 if ($min%15 < 3);
105 return $min + 15-$min%15;
110 my ($sh, $sm, $eh, $em) = @_;
113 return ($eh-$sh)*60 + $em-$sm;
115 return ($eh-$sh)*60 - ($sm-$em);
121 my ($d_sec,$d_min,$d_hour,$d_mday,$d_mon,$d_year,$d_wday,$d_isdst) = localtime();
123 my $query = q{SELECT oid,start FROM stempel WHERE stop IS NULL};
124 my $sth = $dbh->prepare ($query);
125 if ($sth && $sth->execute > 0) {
126 while ((my $row = $sth->fetchrow_hashref)) {
127 my @arr = split(/ /, $row->{start});
128 my @d = split(/-/, $arr[0]);
130 if ($d[0] != $d_year+1900 || $d[1] != $d_mon+1 || $d[2] != $d_mday) {
131 printf "Task not started today, aborting.\n";
135 my @t = split(/:/, $arr[1]);
136 my $int = quarter(hdiff($t[0], $t[1], $d_hour, $d_min));
138 $query = sprintf('UPDATE stempel SET stop=now(),time=%d WHERE oid = %d',
141 printf "Wrote %s.\n", min2hour($int);
149 my ($d_sec,$d_min,$d_hour,$d_mday,$d_mon,$d_year,$d_wday,$d_isdst) = localtime();
150 my $query = q{SELECT customer,start,task FROM stempel WHERE time IS NULL ORDER BY start,customer};
152 my $sth = $dbh->prepare ($query);
153 if ($sth && $sth->execute > 0) {
154 while ((my $row = $sth->fetchrow_hashref)) {
155 my @arr = split(/ /, $row->{start});
157 my @d = split(/-/, $day);
159 if ($d[0] != $d_year+1900 || $d[1] != $d_mon+1 || $d[2] != $d_mday) {
160 printf "Task not started today, aborting.\n";
164 my @t = split(/:/, $arr[1]);
165 my $time = sprintf('%02d:%02d', $t[0], $t[1]);
166 my $int = quarter(hdiff($t[0], $t[1], $d_hour, $d_min));
168 printf "%-15s %s %s (%s) %s\n", $row->{customer}, $day, $time, min2hour($int), $row->{task};
176 # my $query = q{SELECT customer,sum(time) FROM stempel GROUP BY customer ORDER BY customer};
177 my $query = q{SELECT start,customer,time,task FROM stempel WHERE time IS NOT NULL ORDER BY customer,start};
179 my $sth = $dbh->prepare ($query);
181 if ($sth && $sth->execute > 0) {
182 while ((my $row = $sth->fetchrow_hashref)) {
183 if (defined $row->{time}) {
184 my $day = (split(/ /, $row->{start}))[0];
185 my $time = min2hour $row->{time};
186 printf "%-15s %s %s %s\n", $row->{customer}, $day, $time, $row->{task};
205 my ($d_sec,$d_min,$d_hour,$d_mday,$d_mon,$d_year,$d_wday,$d_isdst) = localtime();
207 return unless is_open;
210 my $query = sprintf("UPDATE stempel SET stop=start + interval '%d minutes',time=%d WHERE stop IS NULL",
211 $delta, quarter($delta));
218 stempel Copyright (c) 2007,8 Martin Schulze <joey\@infodrom.org>
221 --close time close open task
228 my $opt_close = undef;
229 my %options = ('list' => \&list_all,
230 'open' => \&list_open,
232 'close=i' => \$opt_close,
233 'terminate|end|d' => \&close_task,
238 late_close_task $opt_close;