Bug 7021: Patron category in the statistics table

This patch populates the koha.statistics.usercode with borrowers.categorycode where it is easily available.
Currently for statistics.type 'issue' OR 'localuse' OR 'renew'.

Supplied a script to UPDATE the old statistics records.

Have fun!

To test:
1. Add loan for patron.
2. Check statistics table
=> 'usercode' column for this issue should now contain patrons categorycode

To test add_statistics_borrowers_categorycode.pl:
1. Run add_statistics_borrowers_categorycode.pl
2. Check statistics table
=> all statistics which are type 'issue' OR 'localuse' OR 'renew'
should now contain patrons categorycode in 'usercode' column

Also prove that tests in t/db_dependent/Circulation.t still pass.

Rebased-by: Emmi Takkinen <emmi.takkinen@koha-suomi.fi>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Olli-Antti Kivilahti 2014-07-02 19:54:33 +03:00 committed by Tomas Cohen Arazi
parent cbed9618c9
commit b9158641d4
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
3 changed files with 9 additions and 2 deletions

View file

@ -819,7 +819,8 @@ sub CanBookBeIssued {
itemnumber => $item_object->itemnumber, itemnumber => $item_object->itemnumber,
itemtype => $effective_itemtype, itemtype => $effective_itemtype,
borrowernumber => $patron->borrowernumber, borrowernumber => $patron->borrowernumber,
ccode => $item_object->ccode} ccode => $item_object->ccode},
usercode => $patron->categorycode,
); );
ModDateLastSeen( $item_object->itemnumber ); # FIXME Move to Koha::Item ModDateLastSeen( $item_object->itemnumber ); # FIXME Move to Koha::Item
return( { STATS => 1 }, {}); return( { STATS => 1 }, {});
@ -1740,6 +1741,7 @@ sub AddIssue {
location => $item_object->location, location => $item_object->location,
borrowernumber => $borrower->{'borrowernumber'}, borrowernumber => $borrower->{'borrowernumber'},
ccode => $item_object->ccode, ccode => $item_object->ccode,
usercode => $borrower->{'categorycode'}
} }
); );
@ -3188,6 +3190,7 @@ sub AddRenewal {
location => $item_object->location, location => $item_object->location,
borrowernumber => $borrowernumber, borrowernumber => $borrowernumber,
ccode => $item_object->ccode, ccode => $item_object->ccode,
usercode => $patron->categorycode,
} }
); );

View file

@ -65,6 +65,7 @@ C<$params> is an hashref whose expected keys are:
other : sipmode other : sipmode
itemtype : the type of the item itemtype : the type of the item
ccode : the collection code of the item ccode : the collection code of the item
usercode : the categorycode of the patron
type key is mandatory. type key is mandatory.
For types used in C4::Circulation (renew,issue,localuse,return), the following other keys are mandatory: For types used in C4::Circulation (renew,issue,localuse,return), the following other keys are mandatory:
@ -82,7 +83,7 @@ sub UpdateStats {
# make some controls # make some controls
return () if ! defined $params; return () if ! defined $params;
# change these arrays if new types of transaction or new parameters are allowed # change these arrays if new types of transaction or new parameters are allowed
my @allowed_keys = qw (type branch amount other itemnumber itemtype borrowernumber ccode location); my @allowed_keys = qw (type branch amount other itemnumber itemtype borrowernumber ccode location usercode);
my @allowed_circulation_types = qw (renew issue localuse return onsite_checkout recall); my @allowed_circulation_types = qw (renew issue localuse return onsite_checkout recall);
my @allowed_accounts_types = qw (writeoff payment); my @allowed_accounts_types = qw (writeoff payment);
my @circulation_mandatory_keys = qw (type branch borrowernumber itemnumber ccode itemtype); my @circulation_mandatory_keys = qw (type branch borrowernumber itemnumber ccode itemtype);
@ -123,6 +124,7 @@ sub UpdateStats {
my $itemtype = exists $params->{itemtype} ? $params->{itemtype} : ''; my $itemtype = exists $params->{itemtype} ? $params->{itemtype} : '';
my $location = exists $params->{location} ? $params->{location} : undef; my $location = exists $params->{location} ? $params->{location} : undef;
my $ccode = exists $params->{ccode} ? $params->{ccode} : ''; my $ccode = exists $params->{ccode} ? $params->{ccode} : '';
my $usercode = exists $params->{usercode} ? $params->{usercode} : undef;
my $dtf = Koha::Database->new->schema->storage->datetime_parser; my $dtf = Koha::Database->new->schema->storage->datetime_parser;
my $statistic = Koha::Statistic->new( my $statistic = Koha::Statistic->new(
@ -137,6 +139,7 @@ sub UpdateStats {
location => $location, location => $location,
borrowernumber => $borrowernumber, borrowernumber => $borrowernumber,
ccode => $ccode, ccode => $ccode,
usercode => $usercode,
} }
)->store; )->store;

View file

@ -4937,6 +4937,7 @@ CREATE TABLE `statistics` (
`location` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'authorized value for the shelving location for this item (MARC21 952$c)', `location` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'authorized value for the shelving location for this item (MARC21 952$c)',
`borrowernumber` int(11) DEFAULT NULL COMMENT 'foreign key from the borrowers table, links transaction to a specific borrower', `borrowernumber` int(11) DEFAULT NULL COMMENT 'foreign key from the borrowers table, links transaction to a specific borrower',
`ccode` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'foreign key from the items table, links transaction to a specific collection code', `ccode` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'foreign key from the items table, links transaction to a specific collection code',
`usercode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
KEY `timeidx` (`datetime`), KEY `timeidx` (`datetime`),
KEY `branch_idx` (`branch`), KEY `branch_idx` (`branch`),
KEY `type_idx` (`type`), KEY `type_idx` (`type`),