From 9fd0555ae828972a7268c56a4f5e56a4a681aa2b Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 29 Jun 2017 11:10:18 -0400 Subject: [PATCH] Bug 18882: Add location code to statistics table for checkouts and renewals Some libraries wish to track what the current location of items was at the time they were checked out. This will help libraries track which physical locations in the library patrons are more likely to check out a given book from. Test Plan: 1) Apply this patch 2) Run updatedatabase.pl 3) Check out an item that has a location set 4) Renew that item 5) View the checkout and renewal in the statistics table, verify each has the location column populated correctly Signed-off-by: Mark Tompsett Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- C4/Circulation.pm | 2 ++ C4/Stats.pm | 13 ++++++------ .../data/mysql/atomicupdate/bug_18882.perl | 9 ++++++++ installer/data/mysql/kohastructure.sql | 1 + t/db_dependent/Stats.t | 21 +++++++++++-------- 5 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_18882.perl diff --git a/C4/Circulation.pm b/C4/Circulation.pm index e49c16826e..5c55e8c8e9 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1436,6 +1436,7 @@ sub AddIssue { other => ( $sipmode ? "SIP-$sipmode" : '' ), itemnumber => $item->{'itemnumber'}, itemtype => $item->{'itype'}, + location => $item->{location}, borrowernumber => $borrower->{'borrowernumber'}, ccode => $item->{'ccode'} } @@ -2907,6 +2908,7 @@ sub AddRenewal { amount => $charge, itemnumber => $itemnumber, itemtype => $item->{itype}, + location => $item->{location}, borrowernumber => $borrowernumber, ccode => $item->{'ccode'} } diff --git a/C4/Stats.pm b/C4/Stats.pm index 54e3a390be..23e5807f27 100644 --- a/C4/Stats.pm +++ b/C4/Stats.pm @@ -84,7 +84,7 @@ sub UpdateStats { # make some controls return () if ! defined $params; # change these arrays if new types of transaction or new parameters are allowed - my @allowed_keys = qw (type branch amount other itemnumber itemtype borrowernumber accountno ccode); + my @allowed_keys = qw (type branch amount other itemnumber itemtype borrowernumber accountno ccode location); my @allowed_circulation_types = qw (renew issue localuse return onsite_checkout); my @allowed_accounts_types = qw (writeoff payment); my @circulation_mandatory_keys = qw (type branch borrowernumber itemnumber ccode itemtype); @@ -123,6 +123,7 @@ sub UpdateStats { my $amount = exists $params->{amount} ? $params->{amount} :''; my $other = exists $params->{other} ? $params->{other} :''; my $itemtype = exists $params->{itemtype} ? $params->{itemtype} :''; + my $location = exists $params->{location} ? $params->{location} :''; my $accountno = exists $params->{accountno} ? $params->{accountno} :''; my $ccode = exists $params->{ccode} ? $params->{ccode} :''; @@ -131,14 +132,14 @@ sub UpdateStats { "INSERT INTO statistics (datetime, branch, type, value, - other, itemnumber, itemtype, + other, itemnumber, itemtype, location, borrowernumber, proccode, ccode) - VALUES (now(),?,?,?,?,?,?,?,?,?)" + VALUES (now(),?,?,?,?,?,?,?,?,?,?)" ); $sth->execute( - $branch, $type, $amount, - $other, $itemnumber, $itemtype, - $borrowernumber, $accountno, $ccode + $branch, $type, $amount, $other, + $itemnumber, $itemtype, $location, $borrowernumber, + $accountno, $ccode ); } diff --git a/installer/data/mysql/atomicupdate/bug_18882.perl b/installer/data/mysql/atomicupdate/bug_18882.perl new file mode 100644 index 0000000000..154ef0d7b8 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_18882.perl @@ -0,0 +1,9 @@ +$DBversion = 'XXX'; +if ( CheckVersion($DBversion) ) { + if ( !column_exists( 'statistics', 'location' ) ) { + $dbh->do('ALTER TABLE statistics ADD COLUMN location VARCHAR(80) default NULL AFTER itemtype'); + } + + SetVersion($DBversion); + print "Upgrade to $DBversion done (Bug 18882 - Add location code to statistics table for checkouts and renewals)\n"; +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index e547168f62..36481ad3f6 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2018,6 +2018,7 @@ CREATE TABLE `statistics` ( -- information related to transactions (circulation `usercode` varchar(10) default NULL, -- unused in Koha `itemnumber` int(11) default NULL, -- foreign key from the items table, links transaction to a specific item `itemtype` varchar(10) default NULL, -- foreign key from the itemtypes table, links transaction to a specific item type + `location` varchar(80) default NULL, -- authorized value for the shelving location for this item (MARC21 952$c) `borrowernumber` int(11) default NULL, -- foreign key from the borrowers table, links transaction to a specific borrower `associatedborrower` int(11) default NULL, -- unused in Koha `ccode` varchar(10) default NULL, -- foreign key from the items table, links transaction to a specific collection code diff --git a/t/db_dependent/Stats.t b/t/db_dependent/Stats.t index 5ad960878c..21a32263d7 100644 --- a/t/db_dependent/Stats.t +++ b/t/db_dependent/Stats.t @@ -3,7 +3,7 @@ use Modern::Perl; use C4::Stats; -use Test::More tests => 17; +use Test::More tests => 18; BEGIN { use_ok('C4::Stats'); @@ -33,6 +33,7 @@ my $params = { amount =>5.1, other => "bla", itemtype => "BK", + location => "LOC", accountno => 51, ccode => "CODE", }; @@ -105,6 +106,7 @@ $params = { amount =>5.1, other => "bla", itemtype => "BK", + location => "LOC", accountno => 51, ccode => "CODE", type => "return" @@ -113,14 +115,15 @@ UpdateStats ($params); my $sth = $dbh->prepare("SELECT * FROM statistics"); $sth->execute(); my $line = ${ $sth->fetchall_arrayref( {} ) }[0]; -is ($params-> {branch}, $line->{branch}, "UpdateStats save branch param in branch field of statistics table"); -is ($params-> {type}, $line->{type}, "UpdateStats save type param in type field of statistics table"); -is ($params-> {borrowernumber}, $line->{borrowernumber}, "UpdateStats save borrowernumber param in borrowernumber field of statistics table"); -cmp_ok($params-> {amount},'==', $line->{value}, "UpdateStats save amount param in value field of statistics table"); -is ($params-> {other}, $line->{other}, "UpdateStats save other param in other field of statistics table"); -is ($params-> {itemtype}, $line->{itemtype}, "UpdateStats save itemtype param in itemtype field of statistics table"); -is ($params-> {accountno}, $line->{proccode}, "UpdateStats save accountno param in proccode field of statistics table"); -is ($params-> {ccode}, $line->{ccode}, "UpdateStats save ccode param in ccode field of statistics table"); +is ($params->{branch}, $line->{branch}, "UpdateStats save branch param in branch field of statistics table"); +is ($params->{type}, $line->{type}, "UpdateStats save type param in type field of statistics table"); +is ($params->{borrowernumber}, $line->{borrowernumber}, "UpdateStats save borrowernumber param in borrowernumber field of statistics table"); +cmp_ok($params->{amount},'==', $line->{value}, "UpdateStats save amount param in value field of statistics table"); +is ($params->{other}, $line->{other}, "UpdateStats save other param in other field of statistics table"); +is ($params->{itemtype}, $line->{itemtype}, "UpdateStats save itemtype param in itemtype field of statistics table"); +is ($params->{location}, $line->{location}, "UpdateStats save location param in location field of statistics table"); +is ($params->{accountno}, $line->{proccode}, "UpdateStats save accountno param in proccode field of statistics table"); +is ($params->{ccode}, $line->{ccode}, "UpdateStats save ccode param in ccode field of statistics table"); # # Test TotalPaid -- 2.20.1