@@ -, +, @@ checkouts and renewals verify each has the location column populated correctly --- C4/Circulation.pm | 2 ++ C4/Stats.pm | 13 +++++++------ installer/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 --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -1438,6 +1438,7 @@ sub AddIssue { other => ( $sipmode ? "SIP-$sipmode" : '' ), itemnumber => $item->{'itemnumber'}, itemtype => $item->{'itype'}, + location => $item->{location}, borrowernumber => $borrower->{'borrowernumber'}, ccode => $item->{'ccode'} } @@ -2971,6 +2972,7 @@ sub AddRenewal { amount => $charge, itemnumber => $itemnumber, itemtype => $item->{itype}, + location => $item->{location}, borrowernumber => $borrowernumber, ccode => $item->{'ccode'} } --- a/C4/Stats.pm +++ a/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 ); } --- a/installer/data/mysql/atomicupdate/bug_18882.perl +++ a/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"; +} --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -2013,6 +2013,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 --- a/t/db_dependent/Stats.t +++ a/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 --