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

(-)a/C4/ILSDI/Services.pm (-2 / +10 lines)
Lines 26-32 use C4::Circulation; Link Here
26
use C4::Branch;
26
use C4::Branch;
27
use C4::Accounts;
27
use C4::Accounts;
28
use C4::Biblio;
28
use C4::Biblio;
29
use C4::Reserves qw(AddReserve GetReservesFromBiblionumber GetReservesFromBorrowernumber CanBookBeReserved CanItemBeReserved IsAvailableForItemLevelRequest);
29
use C4::Reserves qw(AddReserve GetReservesFromBiblionumber GetReservesFromBorrowernumber CanBookBeReserved CanItemBeReserved IsAvailableForItemLevelRequest AlreadyReserved ReachedMaxReserves);
30
use C4::Context;
30
use C4::Context;
31
use C4::AuthoritiesMarc;
31
use C4::AuthoritiesMarc;
32
use XML::Simple;
32
use XML::Simple;
Lines 605-613 sub HoldTitle { Link Here
605
    my $biblionumber = $cgi->param('bib_id');
605
    my $biblionumber = $cgi->param('bib_id');
606
    my $biblio = GetBiblio( $biblionumber );
606
    my $biblio = GetBiblio( $biblionumber );
607
    return { code => 'RecordNotFound' } unless $$biblio{biblionumber};
607
    return { code => 'RecordNotFound' } unless $$biblio{biblionumber};
608
    
608
609
    my $title = $$biblio{title};
609
    my $title = $$biblio{title};
610
610
611
    return { code => 'NotHoldable' } if ReachedMaxReserves($borrowernumber);
612
613
    return { code => 'NotHoldable' } if AlreadyReserved($biblionumber, $borrowernumber);
614
611
    # Check if the biblio can be reserved
615
    # Check if the biblio can be reserved
612
    return { code => 'NotHoldable' } unless CanBookBeReserved( $borrowernumber, $biblionumber ) eq 'OK';
616
    return { code => 'NotHoldable' } unless CanBookBeReserved( $borrowernumber, $biblionumber ) eq 'OK';
613
617
Lines 684-689 sub HoldItem { Link Here
684
    # If the biblio does not match the item, return an error code
688
    # If the biblio does not match the item, return an error code
685
    return { code => 'RecordNotFound' } if $$item{biblionumber} ne $$biblio{biblionumber};
689
    return { code => 'RecordNotFound' } if $$item{biblionumber} ne $$biblio{biblionumber};
686
690
691
    return { code => 'NotHoldable' } if ReachedMaxReserves($borrowernumber);
692
693
    return { code => 'NotHoldable' } if AlreadyReserved($biblionumber, $borrowernumber);
694
687
    # Check for item disponibility
695
    # Check for item disponibility
688
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber );
696
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber );
689
    my $canbookbereserved = C4::Reserves::CanBookBeReserved( $borrowernumber, $biblionumber );
697
    my $canbookbereserved = C4::Reserves::CanBookBeReserved( $borrowernumber, $biblionumber );
(-)a/C4/Reserves.pm (+49 lines)
Lines 124-129 BEGIN { Link Here
124
        &CancelReserve
124
        &CancelReserve
125
        &CancelExpiredReserves
125
        &CancelExpiredReserves
126
126
127
        &AlreadyReserved
128
        &ReachedMaxReserves
129
127
        &AutoUnsuspendReserves
130
        &AutoUnsuspendReserves
128
131
129
        &IsAvailableForItemLevelRequest
132
        &IsAvailableForItemLevelRequest
Lines 1109-1114 sub CancelExpiredReserves { Link Here
1109
1112
1110
}
1113
}
1111
1114
1115
=head2 AlreadyReserved
1116
1117
    $alreadyreserved = AlreadyReserved($biblionumber, $borrowernumber);
1118
1119
    return 1 if borrower already reserved this biblio.
1120
1121
=cut
1122
1123
sub AlreadyReserved {
1124
    my ($biblionumber, $borrowernumber) = @_;
1125
1126
    return 0 unless $biblionumber && $borrowernumber;
1127
1128
    my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
1129
1130
    return 0 unless scalar( @$reserves );
1131
1132
    foreach my $res (@$reserves) {
1133
        return 1 if $borrowernumber eq $res->{borrowernumber};
1134
    }
1135
1136
    return 0;
1137
}
1138
1139
=head2 ReachedMaxReserves
1140
1141
    $hasmaxreserves = ReachedMaxReserves($borrowernumber);
1142
1143
    return 1 if borrower reached maxreserves.
1144
1145
=cut
1146
1147
sub ReachedMaxReserves {
1148
    my $borrowernumber = shift;
1149
1150
    my $number_reserves = GetReserveCount( $borrowernumber );
1151
1152
    return 0 unless C4::Context->preference('maxreserves');
1153
1154
    if ( $number_reserves >= C4::Context->preference('maxreserves') ) {
1155
        return 1;
1156
    }
1157
1158
    return 0;
1159
}
1160
1112
=head2 AutoUnsuspendReserves
1161
=head2 AutoUnsuspendReserves
1113
1162
1114
  AutoUnsuspendReserves();
1163
  AutoUnsuspendReserves();
(-)a/reserve/request.pl (-14 / +5 lines)
Lines 135-145 if ($borrowernumber_hold && !$action) { Link Here
135
135
136
    # we check the reserves of the borrower, and if he can reserv a document
136
    # we check the reserves of the borrower, and if he can reserv a document
137
    # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
137
    # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
138
138
    if ( ReachedMaxReserves($borrowerinfo->{'borrowernumber'}) ) {
139
    my $number_reserves =
140
      GetReserveCount( $borrowerinfo->{'borrowernumber'} );
141
142
    if ( C4::Context->preference('maxreserves') && ($number_reserves >= C4::Context->preference('maxreserves')) ) {
143
        $warnings = 1;
139
        $warnings = 1;
144
        $maxreserves = 1;
140
        $maxreserves = 1;
145
    }
141
    }
Lines 225-247 foreach my $biblionumber (@biblionumbers) { Link Here
225
    my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
221
    my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
226
    my $count = scalar( @$reserves );
222
    my $count = scalar( @$reserves );
227
    my $totalcount = $count;
223
    my $totalcount = $count;
228
    my $holds_count = 0;
229
    my $alreadyreserved = 0;
224
    my $alreadyreserved = 0;
230
225
231
    foreach my $res (@$reserves) {
226
    foreach my $res (@$reserves) {
232
        if ( defined $res->{found} ) { # found can be 'W' or 'T'
227
        if ( defined $res->{found} ) { # found can be 'W' or 'T'
233
            $count--;
228
            $count--;
234
        }
229
        }
235
236
        if ( defined $borrowerinfo && defined($borrowerinfo->{borrowernumber}) && ($borrowerinfo->{borrowernumber} eq $res->{borrowernumber}) ) {
237
            $holds_count++;
238
        }
239
    }
230
    }
240
231
241
    if ( $holds_count ) {
232
    if ( AlreadyReserved($biblionumber, $borrowerinfo->{borrowernumber}) ) {
242
            $alreadyreserved = 1;
233
        $alreadyreserved = 1;
243
            $biblioloopiter{warn} = 1;
234
        $biblioloopiter{warn} = 1;
244
            $biblioloopiter{alreadyres} = 1;
235
        $biblioloopiter{alreadyres} = 1;
245
    }
236
    }
246
237
247
    $template->param(
238
    $template->param(
(-)a/t/db_dependent/ILSDI_Services.t (-2 / +74 lines)
Lines 4-12 use Modern::Perl; Link Here
4
4
5
use C4::Members qw/AddMember GetMember GetBorrowercategory/;
5
use C4::Members qw/AddMember GetMember GetBorrowercategory/;
6
use C4::Branch;
6
use C4::Branch;
7
use C4::Biblio;
8
use C4::Items;
9
use C4::Reserves;
7
use CGI qw ( -utf8 );
10
use CGI qw ( -utf8 );
11
use t::lib::Mocks;
8
12
9
use Test::More tests => 15;
13
use Test::More tests => 23;
10
14
11
BEGIN {
15
BEGIN {
12
    use_ok('C4::ILSDI::Services');
16
    use_ok('C4::ILSDI::Services');
Lines 18-23 my $dbh = C4::Context->dbh; Link Here
18
$dbh->{AutoCommit} = 0;
22
$dbh->{AutoCommit} = 0;
19
$dbh->{RaiseError} = 1;
23
$dbh->{RaiseError} = 1;
20
24
25
my $maxallowedreserves = 3;
26
t::lib::Mocks::mock_preference('maxreserves', $maxallowedreserves);
27
21
# Create patron
28
# Create patron
22
my %data = (
29
my %data = (
23
    firstname =>  'my firstname',
30
    firstname =>  'my firstname',
Lines 29-34 my %data = ( Link Here
29
    password => 'ilsdi-password',
36
    password => 'ilsdi-password',
30
);
37
);
31
38
39
my %data2 = (
40
    firstname =>  'Joe',
41
    surname => 'John',
42
    categorycode => 'UT',
43
    branchcode => 'UT',
44
    cardnumber => '99999',
45
    userid => 'jjohn',
46
    password => 'ilsdi-password',
47
);
48
32
# Crate patron category
49
# Crate patron category
33
unless ( GetBorrowercategory('UT') ) {
50
unless ( GetBorrowercategory('UT') ) {
34
    $dbh->do("INSERT INTO categories
51
    $dbh->do("INSERT INTO categories
Lines 44-51 unless ( GetBranchDetail('UT') ) { Link Here
44
61
45
62
46
my $borrowernumber = AddMember(%data);
63
my $borrowernumber = AddMember(%data);
64
my $borrowernumber2 = AddMember(%data2);
47
my $borrower = GetMember( borrowernumber => $borrowernumber );
65
my $borrower = GetMember( borrowernumber => $borrowernumber );
48
66
67
# Create biblio and item
68
my %item_branch_infos = (
69
    homebranch    => 'UT',
70
    holdingbranch => 'UT',
71
);
72
73
my $record = MARC::Record->new;
74
my $title = MARC::Field->new('200','','','a' => 'Hello world.');
75
$record->append_fields($title);
76
77
my ($biblionumber) = AddBiblio($record, '');
78
my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
79
my ($biblionumber3) = AddBiblio(MARC::Record->new, '');
80
my ($biblionumber4) = AddBiblio(MARC::Record->new, '');
81
my $itemnumber = AddItem({ barcode => '0101', %item_branch_infos }, $biblionumber);
82
my $itemnumber2 = AddItem({ barcode => '0201', %item_branch_infos }, $biblionumber2);
83
my $itemnumber3 = AddItem({ barcode => '0301', %item_branch_infos }, $biblionumber3);
84
my $itemnumber4 = AddItem({ barcode => '0401', %item_branch_infos }, $biblionumber4);
85
49
{ # AuthenticatePatron test
86
{ # AuthenticatePatron test
50
87
51
    my $query = new CGI;
88
    my $query = new CGI;
Lines 90-92 my $borrower = GetMember( borrowernumber => $borrowernumber ); Link Here
90
127
91
}
128
}
92
129
93
- 
130
{ # Add reserves tests
131
132
    my $query = new CGI;
133
    $query->param('patron_id',$borrowernumber);
134
    $query->param('bib_id', $biblionumber);
135
    $query->param('request_location','127.0.0.1');
136
    my $reply = C4::ILSDI::Services::HoldTitle($query);
137
    is($reply->{'title'}, 'Hello world.');
138
    is($reply->{'pickup_location'}, 'Unit test library', 'Hold title');
139
140
    $reply = C4::ILSDI::Services::HoldTitle($query);
141
    is($reply->{'code'}, 'NotHoldable', 'Hold same title again - ILSDI');
142
143
    $query->param('bib_id', $biblionumber2);
144
    $reply = C4::ILSDI::Services::HoldTitle($query);
145
    is($reply->{'pickup_location'}, 'Unit test library', 'Hold a second title - ILSDI');
146
147
    $query->param('bib_id', $biblionumber3);
148
    $reply = C4::ILSDI::Services::HoldTitle($query);
149
    is($reply->{'pickup_location'}, 'Unit test library', 'Hold a third title - ILSDI');
150
151
    $query->param('bib_id', $biblionumber4);
152
    $reply = C4::ILSDI::Services::HoldTitle($query);
153
    is($reply->{'code'}, 'NotHoldable', 'Hold a fourth title - ILSDI');
154
155
    $query->param('bib_id', $biblionumber4);
156
    $query->param('item_id', $itemnumber4);
157
    $reply = C4::ILSDI::Services::HoldItem($query);
158
    is($reply->{'code'}, 'NotHoldable', 'Hold a fourth item - ILSDI');
159
160
    $query->param('bib_id', $biblionumber);
161
    $query->param('patron_id',$borrowernumber2);
162
    $query->param('item_id', $itemnumber);
163
    $reply = C4::ILSDI::Services::HoldItem($query);
164
    is($reply->{'pickup_location'}, 'Unit test library', 'Joe John hold an item - ILSDI');
165
}

Return to bug 14155