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 |
} |