[WTF CVS] wtf/lib/WTF/Pages Input.pm, 1.12, 1.13 Reports.pm, 1.12, 1.13
Brought to you by:
gryphonshafer
|
From: Gryphon S. <gry...@us...> - 2007-01-02 23:13:32
|
Update of /cvsroot/wtf-tracker/wtf/lib/WTF/Pages In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv17860/lib/WTF/Pages Modified Files: Input.pm Reports.pm Log Message: Changes to support the addition of feature request 1618513: vacation scheduler and OOO calendar Index: Reports.pm =================================================================== RCS file: /cvsroot/wtf-tracker/wtf/lib/WTF/Pages/Reports.pm,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Reports.pm 3 Dec 2006 23:03:43 -0000 1.12 --- Reports.pm 2 Jan 2007 23:13:28 -0000 1.13 *************** *** 363,369 **** ); ! my $total_alloc_days; $total_alloc_days += $_ for (@alloc_days); ! my $avg_alloc_days = int( @alloc_days / $total_alloc_days * 100 ) / 100; $sth->{'activity_summary_totals'}->execute( $month . '-01', $month . '-01' ) or die $dbh->errstr(); --- 363,369 ---- ); ! my $total_alloc_days = 0; $total_alloc_days += $_ for (@alloc_days); ! my $avg_alloc_days = ($total_alloc_days) ? int( @alloc_days / $total_alloc_days * 100 ) / 100 : 0; $sth->{'activity_summary_totals'}->execute( $month . '-01', $month . '-01' ) or die $dbh->errstr(); *************** *** 385,389 **** 'sick' => $sick, 'activities' => [ map { ! $_->{'alloc_percent'} = int( $_->{'alloc'} / $total_alloc_days * 100 ); $_; } @{$activities} ], --- 385,391 ---- 'sick' => $sick, 'activities' => [ map { ! $_->{'alloc_percent'} = ($total_alloc_days) ! ? int( $_->{'alloc'} / $total_alloc_days * 100 ) ! : 0; $_; } @{$activities} ], *************** *** 575,578 **** --- 577,610 ---- } + sub screen_ooo_calendar { + my ( $self, $r ) = @_; + my $req = WTF::Utils::get_req($r); + my $tmpl_obj = $self->setup_tmpl('reports/ooo_calendar.tmpl'); + + # get a date range of 30 days ago up through today + # or default to the inputted start and end if those are valid dates + my ( $date_start, $date_end ) = WTF::Utils::date_range( + 7, 21, + $req->param('date_start'), + $req->param('date_end'), + ); + + $sth->{'ooo_calendar'}->execute( $date_start, $date_end ) or die $dbh->errstr(); + + $tmpl_obj->param( + 'title' => 'OOO Calendar', + 'nav_bar' => WTF::Utils::nav_bar_data( $r, 'ooo_calendar' ), + 'show_calendar' => 1, + 'date_start' => $date_start, + 'date_end' => $date_end, + 'ooo_data' => WTF::Utils::tree_data( + $sth->{'ooo_calendar'}->fetchall_arrayref({}), + 'date', 'ooo_entries', + ), + ); + + return $tmpl_obj->output(); + } + 1; __END__ Index: Input.pm =================================================================== RCS file: /cvsroot/wtf-tracker/wtf/lib/WTF/Pages/Input.pm,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Input.pm 21 Dec 2006 19:33:54 -0000 1.12 --- Input.pm 2 Jan 2007 23:13:28 -0000 1.13 *************** *** 5,8 **** --- 5,9 ---- use base 'WTF::Pages'; use Apache2::Const -compile => 'REDIRECT'; + use Time::Local 'timelocal'; use WTF::DBH; use WTF::SQL; *************** *** 322,325 **** --- 323,414 ---- } + sub screen_myvacation { + my ( $self, $r ) = @_; + my $tmpl_obj = $self->setup_tmpl('input/myvacation.tmpl'); + + my $get_date_data = sub { + my ($query_name) = @_; + + $sth->{$query_name}->execute( $r->pnotes('user_id') ) or die $dbh->errstr(); + my ( $vacation, $sick, @date_data ) = ( 0, 0 ); + while ( $_ = $sth->{$query_name}->fetchrow_hashref() ) { + if ( + @date_data and # is there a previous entry + $date_data[-1]->{'previous_day'} eq $_->{'end_date'} and # is it next to current record + $date_data[-1]->{'vacation'} == $_->{'vacation'} # is it the same type of record + ) { + # merge the entry into the previous + $date_data[-1]->{'start_date'} = $_->{'end_date'}; + $date_data[-1]->{'previous_day'} = $_->{'previous_day'}; + $date_data[-1]->{'total'}++; + } + else { + # add the entry into the list + $_->{'start_date'} = $_->{'end_date'}; + $_->{'total'}++; + push @date_data, $_; + } + + # increment either the vacation or sick total count as appropriate + ( ( $_->{'vacation'} ) ? $vacation : $sick )++; + } + $sth->{$query_name}->finish(); + + return \@date_data, $vacation, $sick; + }; + + my ($future_vacation) = [ reverse @{ ( $get_date_data->('future_vacation') )[0] } ]; + my ( $vacation_sick, $vacation, $sick ) = $get_date_data->('vacation_sick'); + + $tmpl_obj->param( + 'title' => 'My Vacation and Sick Days', + 'nav_bar' => WTF::Utils::nav_bar_data( $r, 'myvacation' ), + 'show_calendar' => 1, + 'future_vacation' => $future_vacation, + 'vacation_sick' => $vacation_sick, + 'vacation' => $vacation, + 'sick' => $sick, + ); + return $tmpl_obj->output(); + } + + sub action_save_new_vacation { + my ( $self, $r ) = @_; + my $req = WTF::Utils::get_req($r); + + # delete a vacation range + if ( $req->param('action') and $req->param('action') eq 'delete' ) { + $sth->{'delete_vacation'}->execute( + $r->pnotes('user_id'), + $req->param('date_start'), + $req->param('date_end'), + ) or die $dbh->errstr(); + } + + # add a vacation range + else { + my ( $date_cursor, $date_end ) = map { + ( defined $_ and /^(\d{4})-(\d+)-(\d+)$/ ) ? timelocal( 0, 0, 0, $3, $2 - 1, $1 ) : 0 + } ( $req->param('date_start'), $req->param('date_end') ); + + # if both the start and end dates are real-ish, start at the start + # date, and for each day between that and the end date, add a vacation + # entry into the wtf.summary table + if ( $date_cursor > 0 and $date_end > 0 ) { + while ( $date_cursor <= $date_end ) { + my @date = ( localtime($date_cursor) )[ 3 .. 5 ]; + $sth->{'add_vacation'}->execute( + $r->pnotes('user_id'), + sprintf( "%4d-%02d-%02d", $date[2] + 1900, $date[1] + 1, $date[0] ), + ) or die $dbh->errstr(); + $date_cursor += 86_400; # 1 day + } + } + } + + $r->headers_out->set( 'Location' => ROOT_URL . '/view/input/myvacation' ); + return $r->status( Apache2::Const::REDIRECT ); + } + 1; __END__ |