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

(-)a/C4/ILSDI/Services.pm (-2 / +2 lines)
Lines 627-633 sub HoldTitle { Link Here
627
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
627
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
628
    #    $title,      $checkitem, $found
628
    #    $title,      $checkitem, $found
629
    my $priority= C4::Reserves::CalculatePriority( $biblionumber );
629
    my $priority= C4::Reserves::CalculatePriority( $biblionumber );
630
    AddReserve( $branch, $borrowernumber, $biblionumber, 'a', undef, $priority, undef, undef, undef, $title, undef, undef );
630
    AddReserve( $branch, $borrowernumber, $biblionumber, undef, $priority, undef, undef, undef, $title, undef, undef );
631
631
632
    # Hashref building
632
    # Hashref building
633
    my $out;
633
    my $out;
Lines 704-710 sub HoldItem { Link Here
704
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
704
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
705
    #    $title,      $checkitem, $found
705
    #    $title,      $checkitem, $found
706
    my $priority= C4::Reserves::CalculatePriority( $biblionumber );
706
    my $priority= C4::Reserves::CalculatePriority( $biblionumber );
707
    AddReserve( $branch, $borrowernumber, $biblionumber, 'a', undef, $priority, undef, undef, undef, $title, $itemnumber, undef );
707
    AddReserve( $branch, $borrowernumber, $biblionumber, undef, $priority, undef, undef, undef, $title, $itemnumber, undef );
708
708
709
    # Hashref building
709
    # Hashref building
710
    my $out;
710
    my $out;
(-)a/C4/Reserves.pm (-48 / +26 lines)
Lines 146-166 BEGIN { Link Here
146
146
147
=head2 AddReserve
147
=head2 AddReserve
148
148
149
    AddReserve($branch,$borrowernumber,$biblionumber,$constraint,$bibitems,$priority,$resdate,$expdate,$notes,$title,$checkitem,$found)
149
    AddReserve($branch,$borrowernumber,$biblionumber,$bibitems,$priority,$resdate,$expdate,$notes,$title,$checkitem,$found)
150
150
151
=cut
151
=cut
152
152
153
sub AddReserve {
153
sub AddReserve {
154
    my (
154
    my (
155
        $branch,    $borrowernumber, $biblionumber,
155
        $branch,    $borrowernumber, $biblionumber,
156
        $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
156
        $bibitems,  $priority, $resdate, $expdate, $notes,
157
        $title,      $checkitem, $found
157
        $title,      $checkitem, $found
158
    ) = @_;
158
    ) = @_;
159
    my $fee =
159
    my $fee =
160
          GetReserveFee($borrowernumber, $biblionumber, $constraint,
160
          GetReserveFee($borrowernumber, $biblionumber,
161
            $bibitems );
161
            $bibitems );
162
    my $dbh     = C4::Context->dbh;
162
    my $dbh     = C4::Context->dbh;
163
    my $const   = lc substr( $constraint, 0, 1 );
164
    $resdate = format_date_in_iso( $resdate ) if ( $resdate );
163
    $resdate = format_date_in_iso( $resdate ) if ( $resdate );
165
    $resdate = C4::Dates->today( 'iso' ) unless ( $resdate );
164
    $resdate = C4::Dates->today( 'iso' ) unless ( $resdate );
166
    if ($expdate) {
165
    if ($expdate) {
Lines 194-213 sub AddReserve { Link Here
194
            "Reserve Charge - $title", $fee );
193
            "Reserve Charge - $title", $fee );
195
    }
194
    }
196
195
197
    #if ($const eq 'a'){
198
    my $query = qq{
196
    my $query = qq{
199
        INSERT INTO reserves
197
        INSERT INTO reserves
200
            (borrowernumber,biblionumber,reservedate,branchcode,constrainttype,
198
            (borrowernumber,biblionumber,reservedate,branchcode,
201
            priority,reservenotes,itemnumber,found,waitingdate,expirationdate)
199
            priority,reservenotes,itemnumber,found,waitingdate,expirationdate)
202
        VALUES
200
        VALUES
203
             (?,?,?,?,?,
201
             (?,?,?,?,?,
204
             ?,?,?,?,?,?)
202
             ?,?,?,?,?)
205
             };
203
             };
206
    my $sth = $dbh->prepare($query);
204
    my $sth = $dbh->prepare($query);
207
    $sth->execute(
205
    $sth->execute(
208
        $borrowernumber, $biblionumber, $resdate, $branch,
206
        $borrowernumber, $biblionumber, $resdate, $branch,      $priority,
209
        $const,          $priority,     $notes,   $checkitem,
207
        $notes,          $checkitem,    $found,   $waitingdate, $expdate
210
        $found,          $waitingdate,	$expdate
211
    );
208
    );
212
    my $reserve_id = $sth->{mysql_insertid};
209
    my $reserve_id = $sth->{mysql_insertid};
213
210
Lines 240-248 sub AddReserve { Link Here
240
        }
237
        }
241
    }
238
    }
242
239
243
    #}
244
    ($const eq "o" || $const eq "e") or return;   # FIXME: why not have a useful return value?
245
246
    return $reserve_id;
240
    return $reserve_id;
247
}
241
}
248
242
Lines 302-308 sub GetReservesFromBiblionumber { Link Here
302
                biblionumber,
296
                biblionumber,
303
                borrowernumber,
297
                borrowernumber,
304
                reservedate,
298
                reservedate,
305
                constrainttype,
306
                found,
299
                found,
307
                itemnumber,
300
                itemnumber,
308
                reservenotes,
301
                reservenotes,
Lines 659-676 sub GetOtherReserves { Link Here
659
652
660
=head2 GetReserveFee
653
=head2 GetReserveFee
661
654
662
  $fee = GetReserveFee($borrowernumber,$biblionumber,$constraint,$biblionumber);
655
  $fee = GetReserveFee($borrowernumber,$biblionumber,$biblionumber);
663
656
664
Calculate the fee for a reserve
657
Calculate the fee for a reserve
665
658
666
=cut
659
=cut
667
660
668
sub GetReserveFee {
661
sub GetReserveFee {
669
    my ($borrowernumber, $biblionumber, $constraint, $bibitems ) = @_;
662
    my ($borrowernumber, $biblionumber, $bibitems ) = @_;
670
663
671
    #check for issues;
664
    #check for issues;
672
    my $dbh   = C4::Context->dbh;
665
    my $dbh   = C4::Context->dbh;
673
    my $const = lc substr( $constraint, 0, 1 );
674
    my $query = qq{
666
    my $query = qq{
675
      SELECT * FROM borrowers
667
      SELECT * FROM borrowers
676
    LEFT JOIN categories ON borrowers.categorycode = categories.categorycode
668
    LEFT JOIN categories ON borrowers.categorycode = categories.categorycode
Lines 693-722 sub GetReserveFee { Link Here
693
        );
685
        );
694
        $sth1->execute($biblionumber);
686
        $sth1->execute($biblionumber);
695
        while ( my $data1 = $sth1->fetchrow_hashref ) {
687
        while ( my $data1 = $sth1->fetchrow_hashref ) {
696
            if ( $const eq "a" ) {
688
            my $found = 0;
697
                push @biblioitems, $data1;
689
            my $x     = 0;
698
            }
690
            while ( $x < $cntitems ) {
699
            else {
691
                if ( @$bibitems->{'biblioitemnumber'} ==
700
                my $found = 0;
692
                    $data->{'biblioitemnumber'} )
701
                my $x     = 0;
693
                {
702
                while ( $x < $cntitems ) {
694
                    $found = 1;
703
                    if ( @$bibitems->{'biblioitemnumber'} ==
704
                        $data->{'biblioitemnumber'} )
705
                    {
706
                        $found = 1;
707
                    }
708
                    $x++;
709
                }
710
                if ( $const eq 'o' ) {
711
                    if ( $found == 1 ) {
712
                        push @biblioitems, $data1;
713
                    }
714
                }
715
                else {
716
                    if ( $found == 0 ) {
717
                        push @biblioitems, $data1;
718
                    }
719
                }
695
                }
696
                $x++;
697
            }
698
699
            if ( $found == 0 ) {
700
                push @biblioitems, $data1;
720
            }
701
            }
721
        }
702
        }
722
        my $cntitemsfound = @biblioitems;
703
        my $cntitemsfound = @biblioitems;
Lines 1792-1798 sub _FixPriority { Link Here
1792
1773
1793
    # get whats left
1774
    # get whats left
1794
    my $query = "
1775
    my $query = "
1795
        SELECT reserve_id, borrowernumber, reservedate, constrainttype
1776
        SELECT reserve_id, borrowernumber, reservedate
1796
        FROM   reserves
1777
        FROM   reserves
1797
        WHERE  biblionumber   = ?
1778
        WHERE  biblionumber   = ?
1798
          AND  ((found <> 'W' AND found <> 'T') OR found IS NULL)
1779
          AND  ((found <> 'W' AND found <> 'T') OR found IS NULL)
Lines 1854-1866 sub _FixPriority { Link Here
1854
1835
1855
  @results = &_Findgroupreserve($biblioitemnumber, $biblionumber, $itemnumber, $lookahead, $ignore_borrowers);
1836
  @results = &_Findgroupreserve($biblioitemnumber, $biblionumber, $itemnumber, $lookahead, $ignore_borrowers);
1856
1837
1857
Looks for an item-specific match first, then for a title-level match, returning the
1838
Looks for a holds-queue based item-specific match first, then for a holds-queue title-level match, returning the
1858
first match found.  If neither, then we look for a 3rd kind of match based on
1839
first match found.  If neither, then we look for non-holds-queue based holds.
1859
reserve constraints.
1860
Lookahead is the number of days to look in advance.
1840
Lookahead is the number of days to look in advance.
1861
1841
1862
TODO: add more explanation about reserve constraints
1863
1864
C<&_Findgroupreserve> returns :
1842
C<&_Findgroupreserve> returns :
1865
C<@results> is an array of references-to-hash whose keys are mostly
1843
C<@results> is an array of references-to-hash whose keys are mostly
1866
fields from the reserves table of the Koha database, plus
1844
fields from the reserves table of the Koha database, plus
Lines 2235-2241 sub MergeHolds { Link Here
2235
        );
2213
        );
2236
        my $upd_sth = $dbh->prepare(
2214
        my $upd_sth = $dbh->prepare(
2237
"UPDATE reserves SET priority = ? WHERE biblionumber = ? AND borrowernumber = ?
2215
"UPDATE reserves SET priority = ? WHERE biblionumber = ? AND borrowernumber = ?
2238
        AND reservedate = ? AND constrainttype = ? AND (itemnumber = ? or itemnumber is NULL) "
2216
        AND reservedate = ? AND (itemnumber = ? or itemnumber is NULL) "
2239
        );
2217
        );
2240
        $sth->execute( $to_biblio, 'W', 'T' );
2218
        $sth->execute( $to_biblio, 'W', 'T' );
2241
        my $priority = 1;
2219
        my $priority = 1;
Lines 2243-2249 sub MergeHolds { Link Here
2243
            $upd_sth->execute(
2221
            $upd_sth->execute(
2244
                $priority,                    $to_biblio,
2222
                $priority,                    $to_biblio,
2245
                $reserve->{'borrowernumber'}, $reserve->{'reservedate'},
2223
                $reserve->{'borrowernumber'}, $reserve->{'reservedate'},
2246
                $reserve->{'constrainttype'}, $reserve->{'itemnumber'}
2224
                $reserve->{'itemnumber'}
2247
            );
2225
            );
2248
            $priority++;
2226
            $priority++;
2249
        }
2227
        }
(-)a/C4/SIP/ILS/Transaction/Hold.pm (-30 / +30 lines)
Lines 38-73 sub queue_position { Link Here
38
}
38
}
39
39
40
sub do_hold {
40
sub do_hold {
41
	my $self = shift;
41
    my $self = shift;
42
	unless ($self->{patron}) {
42
    unless ( $self->{patron} ) {
43
		$self->screen_msg('do_hold called with undefined patron');
43
        $self->screen_msg('do_hold called with undefined patron');
44
		$self->ok(0);
44
        $self->ok(0);
45
		return $self;
45
        return $self;
46
	}
46
    }
47
	my $borrower = GetMember( 'cardnumber'=>$self->{patron}->id);
47
    my $borrower = GetMember( 'cardnumber' => $self->{patron}->id );
48
	unless ($borrower) {
48
    unless ($borrower) {
49
		$self->screen_msg('No borrower matches cardnumber "' . $self->{patron}->id . '".');
49
        $self->screen_msg( 'No borrower matches cardnumber "' . $self->{patron}->id . '".' );
50
		$self->ok(0);
50
        $self->ok(0);
51
		return $self;
51
        return $self;
52
	}
52
    }
53
	my $bib = GetBiblioFromItemNumber(undef, $self->{item}->id);
53
    my $bib = GetBiblioFromItemNumber( undef, $self->{item}->id );
54
	unless ($bib) {
54
    unless ($bib) {
55
		$self->screen_msg('No biblio record matches barcode "' . $self->{item}->id . '".');
55
        $self->screen_msg( 'No biblio record matches barcode "' . $self->{item}->id . '".' );
56
		$self->ok(0);
56
        $self->ok(0);
57
		return $self;
57
        return $self;
58
	}
58
    }
59
	my $branch = ($self->pickup_location || $self->{patron}->branchcode);
59
    my $branch = ( $self->pickup_location || $self->{patron}->branchcode );
60
	unless ($branch) {
60
    unless ($branch) {
61
		$self->screen_msg('No branch specified (or found w/ patron).');
61
        $self->screen_msg('No branch specified (or found w/ patron).');
62
		$self->ok(0);
62
        $self->ok(0);
63
		return $self;
63
        return $self;
64
	}
64
    }
65
	my $bibno = $bib->{biblionumber};
65
    my $bibno = $bib->{biblionumber};
66
	AddReserve($branch, $borrower->{borrowernumber}, 
66
    AddReserve( $branch, $borrower->{borrowernumber}, $bibno, GetBiblioItemByBiblioNumber($bibno) );
67
				$bibno, 'a', GetBiblioItemByBiblioNumber($bibno)) ;
67
68
		# unfortunately no meaningful return value
68
    # unfortunately no meaningful return value
69
	$self->ok(1);
69
    $self->ok(1);
70
	return $self;
70
    return $self;
71
}
71
}
72
72
73
sub drop_hold {
73
sub drop_hold {
(-)a/opac/opac-reserve.pl (-1 / +1 lines)
Lines 285-291 if ( $query->param('place_reserve') ) { Link Here
285
        if ($canreserve) {
285
        if ($canreserve) {
286
            AddReserve(
286
            AddReserve(
287
                $branch,      $borrowernumber,
287
                $branch,      $borrowernumber,
288
                $biblioNum,   'a',
288
                $biblioNum,
289
                [$biblioNum], $rank,
289
                [$biblioNum], $rank,
290
                $startdate,   $expiration_date,
290
                $startdate,   $expiration_date,
291
                $notes,       $biblioData->{title},
291
                $notes,       $biblioData->{title},
(-)a/reserve/placerequest.pl (-12 / +2 lines)
Lines 38-47 my $input = CGI->new(); Link Here
38
checkauth($input, 0, { reserveforothers => 'place_holds' }, 'intranet');
38
checkauth($input, 0, { reserveforothers => 'place_holds' }, 'intranet');
39
39
40
my @bibitems=$input->param('biblioitem');
40
my @bibitems=$input->param('biblioitem');
41
# FIXME I think reqbib does not exist anymore, it's used in line 82, to AddReserve of contraint type 'o'
42
#       I bet it's a 2.x feature, reserving a given biblioitem, that is useless in Koha 3.0
43
#       we can remove this line, the AddReserve of constrainttype 'o',
44
#       and probably remove the reserveconstraint table as well, I never could fill anything in this table.
45
my @reqbib=$input->param('reqbib'); 
41
my @reqbib=$input->param('reqbib'); 
46
my $biblionumber=$input->param('biblionumber');
42
my $biblionumber=$input->param('biblionumber');
47
my $borrowernumber=$input->param('borrowernumber');
43
my $borrowernumber=$input->param('borrowernumber');
Lines 109-126 if ($type eq 'str8' && $borrower){ Link Here
109
105
110
        if ($multi_hold) {
106
        if ($multi_hold) {
111
            my $bibinfo = $bibinfos{$biblionumber};
107
            my $bibinfo = $bibinfos{$biblionumber};
112
            AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,'a',[$biblionumber],
108
            AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,[$biblionumber],
113
                       $bibinfo->{rank},$startdate,$expirationdate,$notes,$bibinfo->{title},$checkitem,$found);
109
                       $bibinfo->{rank},$startdate,$expirationdate,$notes,$bibinfo->{title},$checkitem,$found);
114
        } else {
110
        } else {
115
            if ($input->param('request') eq 'any'){
111
            if ($input->param('request') eq 'any'){
116
                # place a request on 1st available
112
                # place a request on 1st available
117
                AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,'a',\@realbi,$rank[0],$startdate,$expirationdate,$notes,$title,$checkitem,$found);
113
                AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,\@realbi,$rank[0],$startdate,$expirationdate,$notes,$title,$checkitem,$found);
118
            } elsif ($reqbib[0] ne ''){
119
                # FIXME : elsif probably never reached, (see top of the script)
120
                # place a request on a given item
121
                AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,'o',\@reqbib,$rank[0],$startdate,$expirationdate,$notes,$title,$checkitem, $found);
122
            } else {
123
                AddReserve($branch,$borrower->{'borrowernumber'},$biblionumber,'a',\@realbi,$rank[0],$startdate,$expirationdate,$notes,$title,$checkitem, $found);
124
            }
114
            }
125
        }
115
        }
126
    }
116
    }
(-)a/serials/routing-preview.pl (-3 / +1 lines)
Lines 79-85 if($ok){ Link Here
79
				$count--;
79
				$count--;
80
			}
80
			}
81
		}
81
		}
82
		my $const = 'o';
83
		my $notes;
82
		my $notes;
84
		my $title = $subs->{'bibliotitle'};
83
		my $title = $subs->{'bibliotitle'};
85
        for my $routing ( @routinglist ) {
84
        for my $routing ( @routinglist ) {
Lines 95-101 if($ok){ Link Here
95
                    branchcode     => $branch
94
                    branchcode     => $branch
96
                });
95
                });
97
            } else {
96
            } else {
98
                AddReserve($branch,$routing->{borrowernumber},$biblio,$const,\@bibitems,$routing->{ranking}, undef, undef, $notes,$title);
97
                AddReserve($branch,$routing->{borrowernumber},$biblio,\@bibitems,$routing->{ranking}, undef, undef, $notes,$title);
99
        }
98
        }
100
    }
99
    }
101
	}
100
	}
102
- 

Return to bug 9809