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

(-)a/C4/Circulation.pm (-3 / +3 lines)
Lines 739-745 sub CanBookBeIssued { Link Here
739
    #
739
    #
740
    if ( $borrower->{'category_type'} eq 'X' && (  $item->{barcode}  )) { 
740
    if ( $borrower->{'category_type'} eq 'X' && (  $item->{barcode}  )) { 
741
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
741
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
742
        &UpdateStats(C4::Context->userenv->{'branch'},'localuse','','',$item->{'itemnumber'},$item->{'itemtype'},$borrower->{'borrowernumber'}, undef, $item->{'ccode'});
742
        &UpdateStats(C4::Context->userenv->{'branch'},'localuse','','',$item->{'itemnumber'},$item->{'itemtype'},$borrower->{'borrowernumber'}, undef, $item->{'ccode'}, $borrower->{'categorycode'});
743
        ModDateLastSeen( $item->{'itemnumber'} );
743
        ModDateLastSeen( $item->{'itemnumber'} );
744
        return( { STATS => 1 }, {});
744
        return( { STATS => 1 }, {});
745
    }
745
    }
Lines 1305-1311 sub AddIssue { Link Here
1305
            C4::Context->userenv->{'branch'},
1305
            C4::Context->userenv->{'branch'},
1306
            'issue', $charge,
1306
            'issue', $charge,
1307
            ($sipmode ? "SIP-$sipmode" : ''), $item->{'itemnumber'},
1307
            ($sipmode ? "SIP-$sipmode" : ''), $item->{'itemnumber'},
1308
            $item->{'itype'}, $borrower->{'borrowernumber'}, undef, $item->{'ccode'}
1308
            $item->{'itype'}, $borrower->{'borrowernumber'}, undef, $item->{'ccode'}, $borrower->{'categorycode'}
1309
        );
1309
        );
1310
1310
1311
        # Send a checkout slip.
1311
        # Send a checkout slip.
Lines 2630-2636 sub AddRenewal { Link Here
2630
    }
2630
    }
2631
2631
2632
    # Log the renewal
2632
    # Log the renewal
2633
    UpdateStats( $branch, 'renew', $charge, '', $itemnumber, $item->{itype}, $borrowernumber, undef, $item->{'ccode'});
2633
    UpdateStats( $branch, 'renew', $charge, '', $itemnumber, $item->{itype}, $borrowernumber, undef, $item->{'ccode'}, $borrower->{'categorycode'});
2634
	return $datedue;
2634
	return $datedue;
2635
}
2635
}
2636
2636
(-)a/C4/Stats.pm (-4 / +6 lines)
Lines 58-68 the Koha database, which acts as an activity log. Link Here
58
=item UpdateStats
58
=item UpdateStats
59
59
60
  &UpdateStats($branch, $type, $value, $other, $itemnumber,
60
  &UpdateStats($branch, $type, $value, $other, $itemnumber,
61
               $itemtype, $borrowernumber);
61
               $itemtype, $borrowernumber, $usercode);
62
62
63
Adds a line to the statistics table of the Koha database. In effect,
63
Adds a line to the statistics table of the Koha database. In effect,
64
it logs an event.
64
it logs an event.
65
65
66
C<$usercode> is borrowers.categorycode
67
66
C<$branch>, C<$type>, C<$value>, C<$other>, C<$itemnumber>,
68
C<$branch>, C<$type>, C<$value>, C<$other>, C<$itemnumber>,
67
C<$itemtype>, and C<$borrowernumber> correspond to the fields of the
69
C<$itemtype>, and C<$borrowernumber> correspond to the fields of the
68
statistics table in the Koha database.
70
statistics table in the Koha database.
Lines 76-93 sub UpdateStats { Link Here
76
    my (
78
    my (
77
        $branch,         $type,
79
        $branch,         $type,
78
        $amount,   $other,          $itemnum,
80
        $amount,   $other,          $itemnum,
79
        $itemtype, $borrowernumber, $accountno, $ccode
81
        $itemtype, $borrowernumber, $accountno, $ccode, $usercode
80
      )
82
      )
81
      = @_;
83
      = @_;
82
    my $dbh = C4::Context->dbh;
84
    my $dbh = C4::Context->dbh;
83
    my $sth = $dbh->prepare(
85
    my $sth = $dbh->prepare(
84
        "INSERT INTO statistics
86
        "INSERT INTO statistics
85
        (datetime, branch, type, value,
87
        (datetime, branch, type, value, usercode,
86
         other, itemnumber, itemtype, borrowernumber, proccode, ccode)
88
         other, itemnumber, itemtype, borrowernumber, proccode, ccode)
87
         VALUES (now(),?,?,?,?,?,?,?,?,?)"
89
         VALUES (now(),?,?,?,?,?,?,?,?,?)"
88
    );
90
    );
89
    $sth->execute(
91
    $sth->execute(
90
        $branch,    $type,    $amount,
92
        $branch,    $type,    $amount, $usercode,
91
        $other,     $itemnum, $itemtype, $borrowernumber,
93
        $other,     $itemnum, $itemtype, $borrowernumber,
92
		$accountno, $ccode
94
		$accountno, $ccode
93
    );
95
    );
(-)a/test/add_statistics_borrowers_categorycode.pl (-1 / +82 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 C4::Members;
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
    $stat->{usercode} = $borrower->{categorycode};
41
    $sthUpdateStat->execute( $stat->{usercode},
42
                             $stat->{datetime},
43
                             $stat->{branch},
44
                             $stat->{type},
45
                             $stat->{itemnumber},
46
                           );
47
    print(  $stat->{usercode} . " " .
48
            $stat->{datetime} . " " .
49
            $stat->{branch} . " " .
50
            $stat->{type} . " " .
51
            $stat->{itemnumber} . " "
52
          );
53
    print "\n";
54
  }
55
}
56
57
58
59
##Members are repeatedly loaded in various parts of this code. Better to cache them.
60
sub getCachedBorrower {
61
    my $borrowernumber = shift; #The hash to store all branches by branchcode
62
63
    if (egit xists $borrowers->{$borrowernumber}) {
64
        return $borrowers->{$borrowernumber};
65
    }
66
    my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
67
    $borrowers->{$borrowernumber} = $borrower;
68
    return $borrower;
69
}
70
##Deleted members are repeatedly loaded in various parts of this code. Better to cache them.
71
sub getCachedDeletedBorrower {
72
    my $borrowernumber = shift; #The hash to store all branches by branchcode
73
74
    if (exists $deletedBorrowers->{$borrowernumber}) {
75
        return $deletedBorrowers->{$borrowernumber};
76
    }
77
    $sthDelBor->execute( $borrowernumber );
78
    
79
    my $borrower = $sthDelBor->fetchrow_hashref();
80
    $borrowers->{$borrowernumber} = $borrower;
81
    return $borrower;
82
}

Return to bug 7021