From f74da1e83442a730e2e56866f57b9f5aef93a3f5 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Thu, 16 Jun 2011 16:45:02 +0100 Subject: [PATCH] Bug 5549 : GetPendingIssues now returns DateTime objects Show due times in addition to dates in using screens --- C4/Members.pm | 4 + .../prog/en/modules/members/moremember.tt | 6 +- members/moremember.pl | 171 ++++++++++-------- members/readingrec.pl | 4 +- opac/opac-ics.pl | 4 +- opac/opac-user.pl | 2 +- 6 files changed, 108 insertions(+), 83 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 513819ee38..434a018cd6 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -37,6 +37,7 @@ use C4::Members::Attributes qw(SearchIdMatchingAttribute); use C4::NewsChannels; #get slip news use DateTime; use DateTime::Format::DateParse; +use Koha::DateUtils; our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug); @@ -1037,6 +1038,9 @@ sub GetPendingIssues { my $tz = C4::Context->tz(); my $today = DateTime->now( time_zone => $tz); foreach (@{$data}) { + if ($_->{issuedate}) { + $_->{issuedate} = dt_from_string($_->{issuedate}. 'sql'); + } $_->{date_due} or next; $_->{date_due} = DateTime::Format::DateParse->parse_datetime($_->{date_due}, $tz->name()); if ( DateTime->compare($_->{date_due}, $today) == -1 ) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index bd19584789..42d0ec032c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -396,8 +396,8 @@ function validate1(date) {
-[% IF ( relissuecount ) %] +[% IF relissueloop %]
diff --git a/members/moremember.pl b/members/moremember.pl index 4693cc764d..e9675798c3 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -56,6 +56,8 @@ use C4::Members::Attributes qw(GetBorrowerAttributes); #use Smart::Comments; #use Data::Dumper; +use DateTime; +use Koha::DateUtils; use vars qw($debug); @@ -65,7 +67,7 @@ BEGIN { my $dbh = C4::Context->dbh; -my $input = new CGI; +my $input = CGI->new; $debug or $debug = $input->param('debug') || 0; my $print = $input->param('print'); my $override_limit = $input->param("override_limit") || 0; @@ -247,85 +249,15 @@ my $relissue = []; if ( @borrowernumbers ) { $relissue = GetPendingIssues(@borrowernumbers); } -my $issuecount = @{$issue}; -my $relissuecount = @{$relissue}; my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} ); -my $today = POSIX::strftime("%Y-%m-%d", localtime); # iso format +my $today = DateTime->now( time_zone => C4::Context->tz); +$today->truncate(to => 'days'); my @borrowers_with_issues; my $overdues_exist = 0; my $totalprice = 0; -my @issuedata = build_issue_data($issue, $issuecount); -my @relissuedata = build_issue_data($relissue, $relissuecount); - -sub build_issue_data { - my $issue = shift; - my $issuecount = shift; - - my $localissue; - - for ( my $i = 0 ; $i < $issuecount ; $i++ ) { - my $datedue = $issue->[$i]{'date_due'}; - my $issuedate = $issue->[$i]{'issuedate'}; - $issue->[$i]{'date_due'} = format_date($issue->[$i]->{issuedate}); - $issue->[$i]{'issuedate'} = C4::Dates->new($issue->[$i]{'issuedate'},'iso')->output('syspref'); - my $biblionumber = $issue->[$i]{'biblionumber'}; - $issue->[$i]{'issuingbranchname'} = GetBranchName($issue->[$i]{'branchcode'}); - my %row = %{ $issue->[$i] }; - $totalprice += $issue->[$i]{'replacementprice'}; - $row{'replacementprice'} = $issue->[$i]{'replacementprice'}; - # item lost, damaged loops - if ($row{'itemlost'}) { - my $fw = GetFrameworkCode($issue->[$i]{'biblionumber'}); - my $category = GetAuthValCode('items.itemlost',$fw); - my $lostdbh = C4::Context->dbh; - my $sth = $lostdbh->prepare("select lib from authorised_values where category=? and authorised_value =? "); - $sth->execute($category, $row{'itemlost'}); - my $loststat = $sth->fetchrow; - if ($loststat) { - $row{'itemlost'} = $loststat; - } - } - if ($row{'damaged'}) { - my $fw = GetFrameworkCode($issue->[$i]{'biblionumber'}); - my $category = GetAuthValCode('items.damaged',$fw); - my $damageddbh = C4::Context->dbh; - my $sth = $damageddbh->prepare("select lib from authorised_values where category=? and authorised_value =? "); - $sth->execute($category, $row{'damaged'}); - my $damagedstat = $sth->fetchrow; - if ($damagedstat) { - $row{'itemdamaged'} = $damagedstat; - } - } - # end lost, damaged - if ( $issue->[$i]{overdue}) { - $overdues_exist = 1; - $row{'red'} = 1; - } - if ( $issuedate eq $today ) { - $row{'today'} = 1; - } - - #find the charge for an item - my ( $charge, $itemtype ) = - GetIssuingCharges( $issue->[$i]{'itemnumber'}, $issue->[$i]{'borrowernumber'} ); - - my $itemtypeinfo = getitemtypeinfo($itemtype); - $row{'itemtype_description'} = $itemtypeinfo->{description}; - $row{'itemtype_image'} = $itemtypeinfo->{imageurl}; - - $row{'charge'} = sprintf( "%.2f", $charge ); - - my ( $renewokay,$renewerror ) = CanBookBeRenewed( $issue->[$i]{'borrowernumber'}, $issue->[$i]{'itemnumber'}, $override_limit ); - $row{'norenew'} = !$renewokay; - $row{'can_confirm'} = ( !$renewokay && $renewerror ne 'on_reserve' ); - $row{"norenew_reason_$renewerror"} = 1 if $renewerror; - $row{'renew_failed'} = $renew_failed{ $issue->[$i]{'itemnumber'} }; - $row{'return_failed'} = $return_failed{$issue->[$i]{'barcode'}}; - push( @$localissue, \%row ); - } - return $localissue; -} +my @issuedata = build_issue_data($issue); +my @relissuedata = build_issue_data($relissue); ### ############################################################################### @@ -467,8 +399,6 @@ $template->param( totaldue_raw => $total, issueloop => @issuedata, relissueloop => @relissuedata, - issuecount => $issuecount, - relissuecount => $relissuecount, overdues_exist => $overdues_exist, error => $error, $error => 1, @@ -483,3 +413,90 @@ $template->param( ); output_html_with_http_headers $input, $cookie, $template->output; + +sub build_issue_data { + my $issues = shift; + + my $localissue; + + foreach my $issue ( @{$issues} ) { + + # Getting borrower details + my $memberdetails = GetMemberDetails( $issue->{borrowernumber} ); + $issue->{borrowername} = + $memberdetails->{firstname} . ' ' . $memberdetails->{surname}; + $issue->{cardnumber} = $memberdetails->{cardnumber}; + my $issuedate; + if ($issue->{issuedate} ) { + $issuedate = $issue->{issuedate}->clone(); + } + + #wtf $issue->{'date_due'} = format_date($issue->[$i]->{issuedate}); + $issue->{date_due} = output_pref( $issue->{date_due} ); + $issue->{issuedate} = output_pref( $issue->{issuedate} ) if defined $issue->{issuedate}; + my $biblionumber = $issue->{biblionumber}; + my %row = %{$issue}; + $totalprice += $issue->{replacementprice}; + + # item lost, damaged loops + if ( $row{'itemlost'} ) { + my $fw = GetFrameworkCode( $issue->{biblionumber} ); + my $category = GetAuthValCode( 'items.itemlost', $fw ); + my $lostdbh = C4::Context->dbh; + my $sth = $lostdbh->prepare( +"select lib from authorised_values where category=? and authorised_value =? " + ); + $sth->execute( $category, $row{'itemlost'} ); + my $loststat = $sth->fetchrow; + if ($loststat) { + $row{'itemlost'} = $loststat; + } + } + if ( $row{'damaged'} ) { + my $fw = GetFrameworkCode( $issue->{biblionumber} ); + my $category = GetAuthValCode( 'items.damaged', $fw ); + my $damageddbh = C4::Context->dbh; + my $sth = $damageddbh->prepare( +"select lib from authorised_values where category=? and authorised_value =? " + ); + $sth->execute( $category, $row{'damaged'} ); + my $damagedstat = $sth->fetchrow; + if ($damagedstat) { + $row{'itemdamaged'} = $damagedstat; + } + } + + # end lost, damaged + if ( $issue->{overdue} ) { + $overdues_exist = 1; + $row{red} = 1; + } + if ($issuedate) { + $issuedate->truncate( to => 'days' ); + if ( DateTime->compare( $issuedate, $today ) == 0 ) { + $row{today} = 1; + } + } + + #find the charge for an item + my ( $charge, $itemtype ) = + GetIssuingCharges( $issue->{itemnumber}, $borrowernumber ); + + my $itemtypeinfo = getitemtypeinfo($itemtype); + $row{'itemtype_description'} = $itemtypeinfo->{description}; + $row{'itemtype_image'} = $itemtypeinfo->{imageurl}; + + $row{'charge'} = sprintf( "%.2f", $charge ); + + my ( $renewokay, $renewerror ) = + CanBookBeRenewed( $borrowernumber, $issue->{itemnumber}, + $override_limit ); + $row{'norenew'} = !$renewokay; + $row{'can_confirm'} = ( !$renewokay && $renewerror ne 'on_reserve' ); + $row{"norenew_reason_$renewerror"} = 1 if $renewerror; + $row{renew_failed} = $renew_failed{ $issue->{itemnumber} }; + $row{return_failed} = $return_failed{ $issue->{barcode} }; + push( @{$localissue}, \%row ); + } + return $localissue; +} diff --git a/members/readingrec.pl b/members/readingrec.pl index d4ecf659f7..05ade6ab94 100755 --- a/members/readingrec.pl +++ b/members/readingrec.pl @@ -30,6 +30,7 @@ use C4::Output; use C4::Members; use C4::Branch; use List::MoreUtils qw/any uniq/; +use Koha::DateUtils; use C4::Dates qw/format_date/; use C4::Members::Attributes qw(GetBorrowerAttributes); @@ -75,7 +76,8 @@ foreach my $issue (@{$issues}){ $line{title} = $issue->{'title'}; $line{author} = $issue->{'author'}; $line{classification} = $issue->{'classification'} || $issue->{'itemcallnumber'}; - $line{date_due} = format_date($issue->{'date_due'}); + my $dt = dt_from_string($issue->{date_due}, 'sql'); + $line{date_due} = output_pref($dt); $line{returndate} = format_date($issue->{'returndate'}); $line{issuedate} = format_date($issue->{'issuedate'}); $line{issuingbranch} = GetBranchName($issue->{'branchcode'}); diff --git a/opac/opac-ics.pl b/opac/opac-ics.pl index 337a939a2b..d9d90a6711 100755 --- a/opac/opac-ics.pl +++ b/opac/opac-ics.pl @@ -28,6 +28,8 @@ use Data::ICal::Entry::Event; use DateTime; use DateTime::Format::ICal; use Date::Calc qw (Parse_Date); +use DateTime; +use DateTime::Event::ICal; use C4::Auth; use C4::Koha; @@ -54,7 +56,7 @@ my ( $borr ) = GetMemberDetails( $borrowernumber ); my $calendar = Data::ICal->new(); # get issued items .... -my ($issues) = GetPendingIssues($borrowernumber); +my $issues = GetPendingIssues($borrowernumber); foreach my $issue ( @$issues ) { my $vevent = Data::ICal::Entry::Event->new(); diff --git a/opac/opac-user.pl b/opac/opac-user.pl index 85724f1ad7..d49f7789a3 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -152,7 +152,7 @@ my $overdues_count = 0; my @overdues; my @issuedat; my $itemtypes = GetItemTypes(); -my ($issues) = GetPendingIssues($borrowernumber); +my $issues = GetPendingIssues($borrowernumber); if ($issues){ foreach my $issue ( sort { $b->{date_due}->datetime() cmp $a->{date_due}->datetime() } @{$issues} ) { # check for reserves -- 2.39.5