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

(-)a/C4/Circulation.pm (-1 / +4 lines)
Lines 798-804 sub CanBookBeIssued { Link Here
798
                     itemnumber => $item_object->itemnumber,
798
                     itemnumber => $item_object->itemnumber,
799
                     itemtype => $effective_itemtype,
799
                     itemtype => $effective_itemtype,
800
                     borrowernumber => $patron->borrowernumber,
800
                     borrowernumber => $patron->borrowernumber,
801
                     ccode => $item_object->ccode}
801
                     ccode => $item_object->ccode},
802
                     usercode => $patron->categorycode,
802
                    );
803
                    );
803
        ModDateLastSeen( $item_object->itemnumber ); # FIXME Move to Koha::Item
804
        ModDateLastSeen( $item_object->itemnumber ); # FIXME Move to Koha::Item
804
        return( { STATS => 1 }, {});
805
        return( { STATS => 1 }, {});
Lines 1644-1649 sub AddIssue { Link Here
1644
                    location       => $item_object->location,
1645
                    location       => $item_object->location,
1645
                    borrowernumber => $borrower->{'borrowernumber'},
1646
                    borrowernumber => $borrower->{'borrowernumber'},
1646
                    ccode          => $item_object->ccode,
1647
                    ccode          => $item_object->ccode,
1648
                    usercode       => $borrower->{'categorycode'}
1647
                }
1649
                }
1648
            );
1650
            );
1649
1651
Lines 3064-3069 sub AddRenewal { Link Here
3064
                location       => $item_object->location,
3066
                location       => $item_object->location,
3065
                borrowernumber => $borrowernumber,
3067
                borrowernumber => $borrowernumber,
3066
                ccode          => $item_object->ccode,
3068
                ccode          => $item_object->ccode,
3069
                usercode       => $patron->categorycode,
3067
            }
3070
            }
3068
        );
3071
        );
3069
3072
(-)a/C4/Stats.pm (-1 / +4 lines)
Lines 65-70 C<$params> is an hashref whose expected keys are: Link Here
65
    other              : sipmode
65
    other              : sipmode
66
    itemtype           : the type of the item
66
    itemtype           : the type of the item
67
    ccode              : the collection code of the item
67
    ccode              : the collection code of the item
68
    usercode           : the categorycode of the patron
68
69
69
type key is mandatory.
70
type key is mandatory.
70
For types used in C4::Circulation (renew,issue,localuse,return), the following other keys are mandatory:
71
For types used in C4::Circulation (renew,issue,localuse,return), the following other keys are mandatory:
Lines 82-88 sub UpdateStats { Link Here
82
# make some controls
83
# make some controls
83
    return () if ! defined $params;
84
    return () if ! defined $params;
84
# change these arrays if new types of transaction or new parameters are allowed
85
# change these arrays if new types of transaction or new parameters are allowed
85
    my @allowed_keys = qw (type branch amount other itemnumber itemtype borrowernumber ccode location);
86
    my @allowed_keys = qw (type branch amount other itemnumber itemtype borrowernumber ccode location usercode);
86
    my @allowed_circulation_types = qw (renew issue localuse return onsite_checkout);
87
    my @allowed_circulation_types = qw (renew issue localuse return onsite_checkout);
87
    my @allowed_accounts_types = qw (writeoff payment);
88
    my @allowed_accounts_types = qw (writeoff payment);
88
    my @circulation_mandatory_keys = qw (type branch borrowernumber itemnumber ccode itemtype);
89
    my @circulation_mandatory_keys = qw (type branch borrowernumber itemnumber ccode itemtype);
Lines 123-128 sub UpdateStats { Link Here
123
    my $itemtype          = exists $params->{itemtype}       ? $params->{itemtype}       : '';
124
    my $itemtype          = exists $params->{itemtype}       ? $params->{itemtype}       : '';
124
    my $location          = exists $params->{location}       ? $params->{location}       : undef;
125
    my $location          = exists $params->{location}       ? $params->{location}       : undef;
125
    my $ccode             = exists $params->{ccode}          ? $params->{ccode}          : '';
126
    my $ccode             = exists $params->{ccode}          ? $params->{ccode}          : '';
127
    my $usercode          = exists $params->{usercode}       ? $params->{usercode}       : undef;
126
128
127
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
129
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
128
    my $statistic = Koha::Statistic->new(
130
    my $statistic = Koha::Statistic->new(
Lines 137-142 sub UpdateStats { Link Here
137
            location       => $location,
139
            location       => $location,
138
            borrowernumber => $borrowernumber,
140
            borrowernumber => $borrowernumber,
139
            ccode          => $ccode,
141
            ccode          => $ccode,
142
            usercode       => $usercode,
140
        }
143
        }
141
    )->store;
144
    )->store;
142
145
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 4706-4711 CREATE TABLE `statistics` ( Link Here
4706
  `location` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'authorized value for the shelving location for this item (MARC21 952$c)',
4706
  `location` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'authorized value for the shelving location for this item (MARC21 952$c)',
4707
  `borrowernumber` int(11) DEFAULT NULL COMMENT 'foreign key from the borrowers table, links transaction to a specific borrower',
4707
  `borrowernumber` int(11) DEFAULT NULL COMMENT 'foreign key from the borrowers table, links transaction to a specific borrower',
4708
  `ccode` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'foreign key from the items table, links transaction to a specific collection code',
4708
  `ccode` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'foreign key from the items table, links transaction to a specific collection code',
4709
  `usercode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4709
  KEY `timeidx` (`datetime`),
4710
  KEY `timeidx` (`datetime`),
4710
  KEY `branch_idx` (`branch`),
4711
  KEY `branch_idx` (`branch`),
4711
  KEY `type_idx` (`type`),
4712
  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