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

(-)a/C4/Circulation.pm (-11 / +14 lines)
Lines 829-843 sub CanBookBeIssued { Link Here
829
    #
829
    #
830
    if ( $patron->category->category_type eq 'X' && (  $item_object->barcode  )) {
830
    if ( $patron->category->category_type eq 'X' && (  $item_object->barcode  )) {
831
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
831
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
832
        C4::Stats::UpdateStats({
832
        C4::Stats::UpdateStats(
833
                     branch => C4::Context->userenv->{'branch'},
833
            {
834
                     type => 'localuse',
834
                branch         => C4::Context->userenv->{'branch'},
835
                     itemnumber => $item_object->itemnumber,
835
                type           => 'localuse',
836
                     itemtype => $effective_itemtype,
836
                itemnumber     => $item_object->itemnumber,
837
                     borrowernumber => $patron->borrowernumber,
837
                itemtype       => $effective_itemtype,
838
                     ccode => $item_object->ccode},
838
                borrowernumber => $patron->borrowernumber,
839
                     usercode => $patron->categorycode,
839
                ccode          => $item_object->ccode,
840
                    );
840
                categorycode   => $patron->categorycode,
841
            }
842
        );
841
        ModDateLastSeen( $item_object->itemnumber ); # FIXME Move to Koha::Item
843
        ModDateLastSeen( $item_object->itemnumber ); # FIXME Move to Koha::Item
842
        return( { STATS => 1 }, {});
844
        return( { STATS => 1 }, {});
843
    }
845
    }
Lines 1741-1747 sub AddIssue { Link Here
1741
                    location       => $item_object->location,
1743
                    location       => $item_object->location,
1742
                    borrowernumber => $borrower->{'borrowernumber'},
1744
                    borrowernumber => $borrower->{'borrowernumber'},
1743
                    ccode          => $item_object->ccode,
1745
                    ccode          => $item_object->ccode,
1744
                    usercode       => $borrower->{'categorycode'}
1746
                    categorycode   => $borrower->{'categorycode'}
1745
                }
1747
                }
1746
            );
1748
            );
1747
1749
Lines 2351-2356 sub AddReturn { Link Here
2351
        location       => $item->location,
2353
        location       => $item->location,
2352
        borrowernumber => $borrowernumber,
2354
        borrowernumber => $borrowernumber,
2353
        ccode          => $item->ccode,
2355
        ccode          => $item->ccode,
2356
        categorycode   => $patron->categorycode,
2354
    });
2357
    });
2355
2358
2356
    # Send a check-in slip. # NOTE: borrower may be undef. Do not try to send messages then.
2359
    # Send a check-in slip. # NOTE: borrower may be undef. Do not try to send messages then.
Lines 3225-3231 sub AddRenewal { Link Here
3225
                location       => $item_object->location,
3228
                location       => $item_object->location,
3226
                borrowernumber => $borrowernumber,
3229
                borrowernumber => $borrowernumber,
3227
                ccode          => $item_object->ccode,
3230
                ccode          => $item_object->ccode,
3228
                usercode       => $patron->categorycode,
3231
                categorycode   => $patron->categorycode,
3229
            }
3232
            }
3230
        );
3233
        );
3231
3234
(-)a/C4/Stats.pm (-4 / +4 lines)
Lines 65-71 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
    categorycode           : the categorycode of the patron
69
69
70
type key is mandatory.
70
type key is mandatory.
71
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 83-89 sub UpdateStats { Link Here
83
# make some controls
83
# make some controls
84
    return () if ! defined $params;
84
    return () if ! defined $params;
85
# 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
86
    my @allowed_keys = qw (type branch amount other itemnumber itemtype borrowernumber ccode location usercode);
86
    my @allowed_keys = qw (type branch amount other itemnumber itemtype borrowernumber ccode location categorycode);
87
    my @allowed_circulation_types = qw (renew issue localuse return onsite_checkout recall);
87
    my @allowed_circulation_types = qw (renew issue localuse return onsite_checkout recall);
88
    my @allowed_accounts_types = qw (writeoff payment);
88
    my @allowed_accounts_types = qw (writeoff payment);
89
    my @circulation_mandatory_keys = qw (type branch borrowernumber itemnumber ccode itemtype);
89
    my @circulation_mandatory_keys = qw (type branch borrowernumber itemnumber ccode itemtype);
Lines 124-130 sub UpdateStats { Link Here
124
    my $itemtype          = exists $params->{itemtype}       ? $params->{itemtype}       : '';
124
    my $itemtype          = exists $params->{itemtype}       ? $params->{itemtype}       : '';
125
    my $location          = exists $params->{location}       ? $params->{location}       : undef;
125
    my $location          = exists $params->{location}       ? $params->{location}       : undef;
126
    my $ccode             = exists $params->{ccode}          ? $params->{ccode}          : '';
126
    my $ccode             = exists $params->{ccode}          ? $params->{ccode}          : '';
127
    my $usercode          = exists $params->{usercode}       ? $params->{usercode}       : undef;
127
    my $categorycode      = exists $params->{categorycode}   ? $params->{categorycode}   : undef;
128
128
129
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
129
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
130
    my $statistic = Koha::Statistic->new(
130
    my $statistic = Koha::Statistic->new(
Lines 139-145 sub UpdateStats { Link Here
139
            location       => $location,
139
            location       => $location,
140
            borrowernumber => $borrowernumber,
140
            borrowernumber => $borrowernumber,
141
            ccode          => $ccode,
141
            ccode          => $ccode,
142
            usercode       => $usercode,
142
            categorycode   => $categorycode,
143
        }
143
        }
144
    )->store;
144
    )->store;
145
145
(-)a/installer/data/mysql/atomicupdate/Bug-7021-Reintroduce_usercode_column.perl (-2 / +2 lines)
Lines 3-10 if( CheckVersion( $DBversion ) ) { Link Here
3
    # you can use $dbh here like:
3
    # you can use $dbh here like:
4
    # $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" );
4
    # $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" );
5
5
6
    $dbh->do("ALTER TABLE statistics ADD COLUMN usercode varchar(10) AFTER ccode");
6
    $dbh->do("ALTER TABLE statistics ADD COLUMN categorycode varchar(10) AFTER ccode");
7
7
8
    # Always end with this (adjust the bug info)
8
    # Always end with this (adjust the bug info)
9
    NewVersion( $DBversion, 7021, "Bug 7021 - Reintroduce usercode column");
9
    NewVersion( $DBversion, 7021, "Bug 7021 - Introduce categorycode column");
10
}
10
}
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 4759-4765 CREATE TABLE `statistics` ( Link Here
4759
  `location` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'authorized value for the shelving location for this item (MARC21 952$c)',
4759
  `location` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'authorized value for the shelving location for this item (MARC21 952$c)',
4760
  `borrowernumber` int(11) DEFAULT NULL COMMENT 'foreign key from the borrowers table, links transaction to a specific borrower',
4760
  `borrowernumber` int(11) DEFAULT NULL COMMENT 'foreign key from the borrowers table, links transaction to a specific borrower',
4761
  `ccode` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'foreign key from the items table, links transaction to a specific collection code',
4761
  `ccode` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'foreign key from the items table, links transaction to a specific collection code',
4762
  `usercode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4762
  `categorycode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
4763
  KEY `timeidx` (`datetime`),
4763
  KEY `timeidx` (`datetime`),
4764
  KEY `branch_idx` (`branch`),
4764
  KEY `branch_idx` (`branch`),
4765
  KEY `type_idx` (`type`),
4765
  KEY `type_idx` (`type`),
(-)a/misc/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 categorycode = ? 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->{categorycode} = $borrower->{categorycode};
42
    $sthUpdateStat->execute( $stat->{categorycode},
43
                             $stat->{datetime},
44
                             $stat->{branch},
45
                             $stat->{type},
46
                             $stat->{itemnumber},
47
                           );
48
    print(  $stat->{categorycode} . " " .
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