[Koha-patches] [PATCH] Bug 2605 - Date handling for bookcount.pl and cleanup
Joe Atzberger
joe.atzberger at liblime.com
Fri Sep 19 02:02:44 CEST 2008
4 or 5 HTML validation errors also corrected.
---
circ/bookcount.pl | 142 ++++++--------------
.../prog/en/modules/circ/bookcount.tmpl | 65 ++++++---
2 files changed, 89 insertions(+), 118 deletions(-)
diff --git a/circ/bookcount.pl b/circ/bookcount.pl
index eeeff41..72ae81b 100755
--- a/circ/bookcount.pl
+++ b/circ/bookcount.pl
@@ -41,44 +41,38 @@ my $branches = GetBranches;
my $idata = itemdatanum($itm);
my $data = GetBiblioItemData($bi);
-my $homebranch = $branches->{ $idata->{'homebranch'} }->{'branchname'};
+my $homebranch = $branches->{ $idata->{'homebranch'} }->{'branchname'};
my $holdingbranch = $branches->{ $idata->{'holdingbranch'} }->{'branchname'};
-my ( $lastmove, $message ) = lastmove($itm);
+my ($lastmove) = lastmove($itm);
-my $lastdate;
-my $count;
-if ( not $lastmove ) {
- $lastdate = $message;
- $count = issuessince( $itm, 0 );
-}
-else {
- $lastdate = $lastmove->{'datearrived'};
- $count = issuessince( $itm, $lastdate );
-}
+my $lastdate = ($lastmove) ? $lastmove->{'datearrived'} : 0;
+my $count = issuessince( $itm, $lastdate );
# make the page ...
-my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
- {
+my ($template, $loggedinuser, $cookie) = get_template_and_user({
template_name => "circ/bookcount.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => { circulate => 1 },
debug => 1,
- }
-);
+});
-my @branchloop;
+# make array of hashrefs using the branchcodes, sorted by branchname.
+my @branchloop = map {
+ {
+ issues=>issuesat($itm, $_),
+ seen=>lastseenat($itm, $_),
+ branchname=>$branches->{$_}->{branchname}
+ }
+ } sort {$branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}} keys %$branches;
-foreach my $branchcode ( keys %$branches ) {
- my %linebranch;
- $linebranch{issues} = issuesat( $itm, $branchcode );
- my $date = lastseenat( $itm, $branchcode );
- $linebranch{seen} = slashdate($date);
- $linebranch{branchname} = $branches->{$branchcode}->{'branchname'};
- push( @branchloop, \%linebranch );
+foreach (@branchloop) {
+ my ($date_part, $time_part) = split / /, $_->{seen};
+ $_->{date_part} = format_date($date_part);
+ $_->{time_part} = $time_part;
}
$template->param(
@@ -97,35 +91,27 @@ $template->param(
output_html_with_http_headers $input, $cookie, $template->output;
-sub itemdatanum {
+sub itemdatanum ($) {
my ($itemnumber) = @_;
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("select * from items where itemnumber=?");
+ my $sth = C4::Context->dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
$sth->execute($itemnumber);
- my $data = $sth->fetchrow_hashref;
- $sth->finish;
- return ($data);
+ return $sth->fetchrow_hashref;
}
-sub lastmove {
- my ($itemnumber) = @_;
- my $dbh = C4::Context->dbh;
- my $sth =
- $dbh->prepare(
-"select max(branchtransfers.datearrived) from branchtransfers where branchtransfers.itemnumber=?"
- );
+sub lastmove ($) {
+ my ($itemnumber) = shift;
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare(
+"SELECT MAX(branchtransfers.datearrived) FROM branchtransfers WHERE branchtransfers.itemnumber=?"
+ );
$sth->execute($itemnumber);
my ($date) = $sth->fetchrow_array;
- return ( 0, "Item has no branch transfers record" ) if not $date;
- $sth =
- $dbh->prepare(
-"Select * from branchtransfers where branchtransfers.itemnumber=? and branchtransfers.datearrived=?"
+ return 0 unless $date;
+ $sth = $dbh->prepare(
+"SELECT * FROM branchtransfers WHERE branchtransfers.itemnumber=? AND branchtransfers.datearrived=?"
);
- $sth->execute( $itemnumber, $date );
- my ($data) = $sth->fetchrow_hashref;
- return ( 0, "Item has no branch transfers record" ) if not $data;
- $sth->finish;
- return ( $data, "" );
+ $sth->execute($itemnumber, $date);
+ return $sth->fetchrow_hashref || 0;
}
sub issuessince {
@@ -133,14 +119,12 @@ sub issuessince {
my $dbh = C4::Context->dbh;
my $sth =
$dbh->prepare("SELECT SUM(count) FROM (
- SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and timestamp > ?
+ SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? AND timestamp > ?
UNION ALL
- SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and timestamp > ?
+ SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? AND timestamp > ?
) tmp");
- $sth->execute( $itemnumber, $date, $itemnumber, $date );
- my $count = $sth->fetchrow_arrayref->[0];
- $sth->finish;
- return ( $count );
+ $sth->execute($itemnumber, $date, $itemnumber, $date);
+ return $sth->fetchrow_arrayref->[0];
}
sub issuesat {
@@ -148,14 +132,12 @@ sub issuesat {
my $dbh = C4::Context->dbh;
my $sth =
$dbh->prepare("SELECT SUM(count) FROM (
- SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? and branchcode = ?
+ SELECT COUNT(*) AS count FROM issues WHERE itemnumber = ? AND branchcode = ?
UNION ALL
- SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? and branchcode = ?
+ SELECT COUNT(*) AS count FROM old_issues WHERE itemnumber = ? AND branchcode = ?
) tmp");
- $sth->execute( $itemnumber, $brcd, $itemnumber, $brcd );
- my ($count) = $sth->fetchrow_array;
- $sth->finish;
- return ($count);
+ $sth->execute($itemnumber, $brcd, $itemnumber, $brcd);
+ return $sth->fetchrow_arrayref->[0];
}
sub lastseenat {
@@ -163,51 +145,15 @@ sub lastseenat {
my $dbh = C4::Context->dbh;
my $sth =
$dbh->prepare("SELECT MAX(tstamp) FROM (
- SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? and branchcode = ?
+ SELECT MAX(timestamp) AS tstamp FROM issues WHERE itemnumber = ? AND branchcode = ?
UNION ALL
- SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? and branchcode = ?
+ SELECT MAX(timestamp) AS tstamp FROM old_issues WHERE itemnumber = ? AND branchcode = ?
) tmp");
$sth->execute( $itm, $brc, $itm, $brc );
my ($date1) = $sth->fetchrow_array;
- $sth->finish;
- $sth =
- $dbh->prepare(
-"Select max(datearrived) from branchtransfers where itemnumber=? and tobranch = ?"
- );
+ $sth = $dbh->prepare("SELECT MAX(datearrived) FROM branchtransfers WHERE itemnumber=? AND tobranch = ?");
$sth->execute( $itm, $brc );
my ($date2) = $sth->fetchrow_array;
- $sth->finish;
-
- #FIXME: MJR thinks unsafe
- $date1 =~ s/-//g;
- $date1 =~ s/://g;
- $date1 =~ s/ //g;
- $date2 =~ s/-//g;
- $date2 =~ s/://g;
- $date2 =~ s/ //g;
- my $date;
- if ( $date1 < $date2 ) {
- $date = $date2;
- }
- else {
- $date = $date1;
- }
- return ($date);
+ return (($date1 gt $date2) ? $date1 : $date2);
}
-#####################################################
-# write date....
-sub slashdate {
- my ($date) = @_;
- if ( not $date ) {
- return "never";
- }
- my ( $yr, $mo, $da, $hr, $mi ) = (
- substr( $date, 0, 4 ),
- substr( $date, 4, 2 ),
- substr( $date, 6, 2 ),
- substr( $date, 8, 2 ),
- substr( $date, 10, 2 )
- );
- return "$hr:$mi " . format_date("$yr-$mo-$da");
-}
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/bookcount.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/bookcount.tmpl
index c47f74d..c3d6993 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/bookcount.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/bookcount.tmpl
@@ -14,29 +14,54 @@
<div id="yui-main">
<div class="yui-b">
-<h2>
-<!-- TMPL_VAR Name="title" --> <!-- TMPL_IF NAME="author" --> by <!-- TMPL_VAR Name="author" --><!-- /TMPL_IF --></h2>
-<h3>Barcode <!-- TMPL_VAR Name="barcode" --></h3>
+<h1>
+<!-- TMPL_VAR Name="title" --> <!-- TMPL_IF NAME="author" -->(<!-- TMPL_VAR Name="author" -->)<!-- /TMPL_IF --></h1>
+<h2>Barcode <!-- TMPL_VAR Name="barcode" --></h2>
+<div class="tabitem">
+ <form action="/cgi-bin/koha/catalogue/detail.pl" method="get">
+ <input type="hidden" name="biblionumber" value="<!-- TMPL_VAR Name="biblionumber" -->" />
+ <input type="hidden" name="type" value="intra" />
+ <input type="submit" class="submit" value="Brief Display" />
+ </form>
+ <form action="/cgi-bin/koha/catalogue/moredetail.pl" method="get">
+ <input type="hidden" name="type" value="<!-- TMPL_VAR NAME="type" -->" />
+ <input type="hidden" name="item" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
+ <input type="hidden" name="biblionumber" value="<!-- TMPL_VAR NAME="biblionumber" -->" />
+ <input type="hidden" name="bi" value="<!-- TMPL_VAR NAME="biblioitemnumber" -->" />
+ <input type="submit" class="submit" value="Item Details" />
+ </form>
+ <!-- TMPL_UNLESS NAME="norequests" -->
+ <form action="/cgi-bin/koha/reserve/request.pl" method="get">
+ <input type="hidden" value="<!-- TMPL_VAR name="biblionumber" -->" name="biblionumber" />
+ <input type="submit" value="Place Reserve" class="submit" />
+ </form>
+ <!-- /TMPL_UNLESS -->
+</div>
+<br />
<table>
- <tr><th>Home Library</th><th>Current Library</th><th>Date arrived at current library </th><th>Number of issues since since last transfer</th></tr>
-
- <tr><td> <!-- TMPL_VAR Name="homebranch" --> </td><td> <!-- TMPL_VAR Name="holdingbranch" --></td><td> <!-- TMPL_VAR Name="lastdate" --> </td><td> <!-- TMPL_VAR Name="count" --> </td></tr>
+ <tr><th>Home Library: </th><td><!-- TMPL_VAR Name="homebranch" --></td></tr>
+ <tr><th>Current Library: </th><td><!-- TMPL_VAR Name="holdingbranch" --></td></tr>
+ <tr><th>Date arrived at current library: </th><td><span class="date"><!-- TMPL_VAR Name="lastdate" DEFAULT="never" --></span></td></tr>
+ <tr><th>Number of issues since since the above date :</th><td><!-- TMPL_VAR Name="count" --></td></tr>
</table>
+<br />
<table>
- <tr>
- <th>Library</th>
- <th>No. of times checked out</th>
- <th>Last Seen</th>
- </tr>
- <!-- TMPL_LOOP Name="branchloop" -->
- <tr>
- <td><!-- TMPL_VAR Name="branchname" --> </td>
- <td><!-- TMPL_VAR Name="issues" --> </td>
- <td><!-- TMPL_VAR Name="seen" --> </td>
- </tr>
- <!-- /TMPL_LOOP -->
- </table>
-
+ <tr>
+ <th>Library</th>
+ <th>No. of times checked out</th>
+ <th>Last seen in this Library at</th>
+ </tr>
+ <!-- TMPL_LOOP Name="branchloop" -->
+ <tr>
+ <td class="data"><!-- TMPL_VAR Name="branchname" --></td>
+ <td class="data"><!-- TMPL_VAR Name="issues" --></td>
+ <td class="data">
+ <span class="time"><!-- TMPL_VAR Name="time_part" DEFAULT="" --></span>
+ <span class="date"><!-- TMPL_VAR Name="date_part" DEFAULT="never" --></span>
+ </td>
+ </tr>
+ <!-- /TMPL_LOOP -->
+</table>
</div>
</div>
<div class="yui-b">
--
1.5.5.GIT
More information about the Koha-patches
mailing list