View | Details | Raw Unified | Return to bug 7021
Collapse All | Expand All

(-)a/C4/Circulation.pm (-1 / +4 lines)
Lines 806-812 sub CanBookBeIssued { Link Here
806
                     itemnumber => $item_object->itemnumber,
806
                     itemnumber => $item_object->itemnumber,
807
                     itemtype => $effective_itemtype,
807
                     itemtype => $effective_itemtype,
808
                     borrowernumber => $patron->borrowernumber,
808
                     borrowernumber => $patron->borrowernumber,
809
                     ccode => $item_object->ccode}
809
                     ccode => $item_object->ccode},
810
                     usercode => $patron->categorycode,
810
                    );
811
                    );
811
        ModDateLastSeen( $item_object->itemnumber ); # FIXME Move to Koha::Item
812
        ModDateLastSeen( $item_object->itemnumber ); # FIXME Move to Koha::Item
812
        return( { STATS => 1 }, {});
813
        return( { STATS => 1 }, {});
Lines 1652-1657 sub AddIssue { Link Here
1652
                    location       => $item_object->location,
1653
                    location       => $item_object->location,
1653
                    borrowernumber => $borrower->{'borrowernumber'},
1654
                    borrowernumber => $borrower->{'borrowernumber'},
1654
                    ccode          => $item_object->ccode,
1655
                    ccode          => $item_object->ccode,
1656
                    usercode       => $borrower->{'categorycode'}
1655
                }
1657
                }
1656
            );
1658
            );
1657
1659
Lines 3137-3142 sub AddRenewal { Link Here
3137
                location       => $item_object->location,
3139
                location       => $item_object->location,
3138
                borrowernumber => $borrowernumber,
3140
                borrowernumber => $borrowernumber,
3139
                ccode          => $item_object->ccode,
3141
                ccode          => $item_object->ccode,
3142
                usercode       => $patron->categorycode,
3140
            }
3143
            }
3141
        );
3144
        );
3142
3145
(-)a/C4/Stats.pm (-1 / +4 lines)
Lines 66-71 C<$params> is an hashref whose expected keys are: Link Here
66
    other              : sipmode
66
    other              : sipmode
67
    itemtype           : the type of the item
67
    itemtype           : the type of the item
68
    ccode              : the collection code of the item
68
    ccode              : the collection code of the item
69
    usercode           : the categorycode of the patron
69
70
70
type key is mandatory.
71
type key is mandatory.
71
For types used in C4::Circulation (renew,issue,localuse,return), the following other keys are mandatory:
72
For types used in C4::Circulation (renew,issue,localuse,return), the following other keys are mandatory:
Lines 83-89 sub UpdateStats { Link Here
83
# make some controls
84
# make some controls
84
    return () if ! defined $params;
85
    return () if ! defined $params;
85
# change these arrays if new types of transaction or new parameters are allowed
86
# change these arrays if new types of transaction or new parameters are allowed
86
    my @allowed_keys = qw (type branch amount other itemnumber itemtype borrowernumber ccode location);
87
    my @allowed_keys = qw (type branch amount other itemnumber itemtype borrowernumber ccode location usercode);
87
    my @allowed_circulation_types = qw (renew issue localuse return onsite_checkout);
88
    my @allowed_circulation_types = qw (renew issue localuse return onsite_checkout);
88
    my @allowed_accounts_types = qw (writeoff payment);
89
    my @allowed_accounts_types = qw (writeoff payment);
89
    my @circulation_mandatory_keys = qw (type branch borrowernumber itemnumber ccode itemtype);
90
    my @circulation_mandatory_keys = qw (type branch borrowernumber itemnumber ccode itemtype);
Lines 124-129 sub UpdateStats { Link Here
124
    my $itemtype          = exists $params->{itemtype}       ? $params->{itemtype}       : '';
125
    my $itemtype          = exists $params->{itemtype}       ? $params->{itemtype}       : '';
125
    my $location          = exists $params->{location}       ? $params->{location}       : undef;
126
    my $location          = exists $params->{location}       ? $params->{location}       : undef;
126
    my $ccode             = exists $params->{ccode}          ? $params->{ccode}          : '';
127
    my $ccode             = exists $params->{ccode}          ? $params->{ccode}          : '';
128
    my $usercode          = exists $params->{usercode}       ? $params->{usercode}       : undef;
127
129
128
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
130
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
129
    my $statistic = Koha::Statistic->new(
131
    my $statistic = Koha::Statistic->new(
Lines 138-143 sub UpdateStats { Link Here
138
            location       => $location,
140
            location       => $location,
139
            borrowernumber => $borrowernumber,
141
            borrowernumber => $borrowernumber,
140
            ccode          => $ccode,
142
            ccode          => $ccode,
143
            usercode       => $usercode,
141
        }
144
        }
142
    )->store;
145
    )->store;
143
146
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 4693-4698 CREATE TABLE `statistics` ( Link Here
4693
  `location` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'authorized value for the shelving location for this item (MARC21 952$c)',
4693
  `location` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'authorized value for the shelving location for this item (MARC21 952$c)',
4694
  `borrowernumber` int(11) DEFAULT NULL COMMENT 'foreign key from the borrowers table, links transaction to a specific borrower',
4694
  `borrowernumber` int(11) DEFAULT NULL COMMENT 'foreign key from the borrowers table, links transaction to a specific borrower',
4695
  `ccode` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'foreign key from the items table, links transaction to a specific collection code',
4695
  `ccode` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'foreign key from the items table, links transaction to a specific collection code',
4696
  `usercode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4696
  KEY `timeidx` (`datetime`),
4697
  KEY `timeidx` (`datetime`),
4697
  KEY `branch_idx` (`branch`),
4698
  KEY `branch_idx` (`branch`),
4698
  KEY `type_idx` (`type`),
4699
  KEY `type_idx` (`type`),
(-)a/test/add_statistics_borrowers_categorycode.pl (-1 / +83 lines)
Line 0 Link Here
0
- 
1
#! /usr/bin/perl
2
3
## EXTRACTED USING THIS:
4
# grep -Pnir "'notforloan' => '6'" 01_items0* | grep -Po "'id' => '-?(\d+)'" | grep -Po "\d+" > itemnumbers_notforloan_6.txt
5
6
use Modern::Perl;
7
8
use C4::Context;
9
use utf8;
10
11
use Koha::Patrons;
12
13
use open ':encoding(utf8)';
14
binmode STDOUT, ':utf8';
15
16
17
print "\nTHE FOLLOWING STATISTIC ENTRIES HAVE BEEN UPDATED\n------------------------------------------------\n";
18
19
20
##Caches all the loaded Borrowers
21
my $borrowers = {};
22
my $deletedBorrowers = {};
23
24
my $dbh = C4::Context->dbh;
25
26
my $sthDelBor   = $dbh->prepare("SELECT * FROM deletedborrowers WHERE borrowernumber = ? ");
27
my $sthUpdateStat   = $dbh->prepare("UPDATE statistics SET usercode = ? WHERE datetime = ? AND branch = ? AND type = ? AND itemnumber = ? ");
28
29
my $query2 = "SELECT * FROM statistics WHERE type = 'issue' OR type = 'renew' OR type = 'localuse'";
30
my $sth2   = $dbh->prepare($query2);
31
$sth2->execute();
32
my $stats =  $sth2->fetchall_arrayref({});
33
34
foreach my $stat (@$stats) {
35
  my $borrower = getCachedBorrower( $stat->{borrowernumber} );
36
37
  $borrower = getCachedDeletedBorrower( $stat->{borrowernumber} ) unless $borrower;
38
39
  if ($borrower) {
40
    $borrower = $borrower->unblessed;
41
    $stat->{usercode} = $borrower->{categorycode};
42
    $sthUpdateStat->execute( $stat->{usercode},
43
                             $stat->{datetime},
44
                             $stat->{branch},
45
                             $stat->{type},
46
                             $stat->{itemnumber},
47
                           );
48
    print(  $stat->{usercode} . " " .
49
            $stat->{datetime} . " " .
50
            $stat->{branch} . " " .
51
            $stat->{type} . " " .
52
            $stat->{itemnumber} . " "
53
          );
54
    print "\n";
55
  }
56
}
57
58
59
60
##Members are repeatedly loaded in various parts of this code. Better to cache them.
61
sub getCachedBorrower {
62
    my $borrowernumber = shift; #The hash to store all branches by branchcode
63
64
    if (exists $borrowers->{$borrowernumber}) {
65
        return $borrowers->{$borrowernumber};
66
    }
67
    my $borrower = Koha::Patrons->find({ borrowernumber => $borrowernumber });
68
    $borrowers->{$borrowernumber} = $borrower;
69
    return $borrower;
70
}
71
##Deleted members are repeatedly loaded in various parts of this code. Better to cache them.
72
sub getCachedDeletedBorrower {
73
    my $borrowernumber = shift; #The hash to store all branches by branchcode
74
75
    if (exists $deletedBorrowers->{$borrowernumber}) {
76
        return $deletedBorrowers->{$borrowernumber};
77
    }
78
    $sthDelBor->execute( $borrowernumber );
79
80
    my $borrower = $sthDelBor->fetchrow_hashref();
81
    $borrowers->{$borrowernumber} = $borrower;
82
    return $borrower;
83
}

Return to bug 7021