Lines 103-109
BEGIN {
Link Here
|
103 |
&GetReservesForBranch |
103 |
&GetReservesForBranch |
104 |
&GetReservesToBranch |
104 |
&GetReservesToBranch |
105 |
&GetReserveCount |
105 |
&GetReserveCount |
106 |
&GetReserveFee |
|
|
107 |
&GetReserveInfo |
106 |
&GetReserveInfo |
108 |
&GetReserveStatus |
107 |
&GetReserveStatus |
109 |
|
108 |
|
Lines 156-164
sub AddReserve {
Link Here
|
156 |
$bibitems, $priority, $resdate, $expdate, $notes, |
155 |
$bibitems, $priority, $resdate, $expdate, $notes, |
157 |
$title, $checkitem, $found |
156 |
$title, $checkitem, $found |
158 |
) = @_; |
157 |
) = @_; |
159 |
my $fee = |
|
|
160 |
GetReserveFee($borrowernumber, $biblionumber, |
161 |
$bibitems ); |
162 |
my $dbh = C4::Context->dbh; |
158 |
my $dbh = C4::Context->dbh; |
163 |
$resdate = format_date_in_iso( $resdate ) if ( $resdate ); |
159 |
$resdate = format_date_in_iso( $resdate ) if ( $resdate ); |
164 |
$resdate = C4::Dates->today( 'iso' ) unless ( $resdate ); |
160 |
$resdate = C4::Dates->today( 'iso' ) unless ( $resdate ); |
Lines 178-198
sub AddReserve {
Link Here
|
178 |
$waitingdate = $resdate; |
174 |
$waitingdate = $resdate; |
179 |
} |
175 |
} |
180 |
|
176 |
|
181 |
#eval { |
|
|
182 |
# updates take place here |
177 |
# updates take place here |
183 |
if ( $fee > 0 ) { |
|
|
184 |
my $nextacctno = &getnextacctno( $borrowernumber ); |
185 |
my $query = qq{ |
186 |
INSERT INTO accountlines |
187 |
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding) |
188 |
VALUES |
189 |
(?,?,now(),?,?,'Res',?) |
190 |
}; |
191 |
my $usth = $dbh->prepare($query); |
192 |
$usth->execute( $borrowernumber, $nextacctno, $fee, |
193 |
"Reserve Charge - $title", $fee ); |
194 |
} |
195 |
|
196 |
my $query = qq{ |
178 |
my $query = qq{ |
197 |
INSERT INTO reserves |
179 |
INSERT INTO reserves |
198 |
(borrowernumber,biblionumber,reservedate,branchcode, |
180 |
(borrowernumber,biblionumber,reservedate,branchcode, |
Lines 207-212
sub AddReserve {
Link Here
|
207 |
$notes, $checkitem, $found, $waitingdate, $expdate |
189 |
$notes, $checkitem, $found, $waitingdate, $expdate |
208 |
); |
190 |
); |
209 |
my $reserve_id = $sth->{mysql_insertid}; |
191 |
my $reserve_id = $sth->{mysql_insertid}; |
|
|
192 |
# add a reserve fee if needed |
193 |
ChargeReserveFee( $borrowernumber, $biblionumber, $title ); |
210 |
|
194 |
|
211 |
# Send e-mail to librarian if syspref is active |
195 |
# Send e-mail to librarian if syspref is active |
212 |
if(C4::Context->preference("emailLibrarianWhenHoldIsPlaced")){ |
196 |
if(C4::Context->preference("emailLibrarianWhenHoldIsPlaced")){ |
Lines 650-742
sub GetOtherReserves {
Link Here
|
650 |
return ( $messages, $nextreservinfo ); |
634 |
return ( $messages, $nextreservinfo ); |
651 |
} |
635 |
} |
652 |
|
636 |
|
653 |
=head2 GetReserveFee |
637 |
=head2 ChargeReserveFee |
654 |
|
638 |
|
655 |
$fee = GetReserveFee($borrowernumber,$biblionumber,$biblionumber); |
639 |
$fee = ChargeReserveFee( $borrowernumber, $biblionumber, $title ); |
656 |
|
640 |
|
657 |
Calculate the fee for a reserve |
641 |
Charge the fee for a reserve (if applicable). |
658 |
|
642 |
|
659 |
=cut |
643 |
=cut |
660 |
|
644 |
|
661 |
sub GetReserveFee { |
645 |
sub ChargeReserveFee { |
662 |
my ($borrowernumber, $biblionumber, $bibitems ) = @_; |
646 |
my ( $borrowernumber, $biblionumber, $title ) = @_; |
663 |
|
647 |
my $borquery = qq{ |
664 |
#check for issues; |
648 |
SELECT reservefee FROM borrowers LEFT JOIN categories ON borrowers.categorycode = categories.categorycode WHERE borrowernumber = ? |
665 |
my $dbh = C4::Context->dbh; |
649 |
}; |
666 |
my $query = qq{ |
650 |
my $accquery = qq{ |
667 |
SELECT * FROM borrowers |
651 |
INSERT INTO accountlines ( borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding ) VALUES (?, ?, NOW(), ?, ?, 'Res', ?) |
668 |
LEFT JOIN categories ON borrowers.categorycode = categories.categorycode |
|
|
669 |
WHERE borrowernumber = ? |
670 |
}; |
652 |
}; |
671 |
my $sth = $dbh->prepare($query); |
|
|
672 |
$sth->execute($borrowernumber); |
673 |
my $data = $sth->fetchrow_hashref; |
674 |
my $fee = $data->{'reservefee'}; |
675 |
my $cntitems = @- > $bibitems; |
676 |
|
677 |
if ( $fee > 0 ) { |
678 |
|
679 |
# check for items on issue |
680 |
# first find biblioitem records |
681 |
my @biblioitems; |
682 |
my $sth1 = $dbh->prepare( |
683 |
"SELECT * FROM biblio LEFT JOIN biblioitems on biblio.biblionumber = biblioitems.biblionumber |
684 |
WHERE (biblio.biblionumber = ?)" |
685 |
); |
686 |
$sth1->execute($biblionumber); |
687 |
while ( my $data1 = $sth1->fetchrow_hashref ) { |
688 |
my $found = 0; |
689 |
my $x = 0; |
690 |
while ( $x < $cntitems ) { |
691 |
if ( @$bibitems->{'biblioitemnumber'} == |
692 |
$data->{'biblioitemnumber'} ) |
693 |
{ |
694 |
$found = 1; |
695 |
} |
696 |
$x++; |
697 |
} |
698 |
|
653 |
|
699 |
if ( $found == 0 ) { |
654 |
my $dbh = C4::Context->dbh; |
700 |
push @biblioitems, $data1; |
655 |
my ( $fee ) = $dbh->selectrow_array( $borquery, undef, ($borrowernumber) ); |
701 |
} |
656 |
if( $fee && $fee > 0 ) { |
702 |
} |
657 |
# This is a reconstruction of the old code: |
703 |
my $cntitemsfound = @biblioitems; |
658 |
# Calculate number of items, items issued and holds |
704 |
my $issues = 0; |
659 |
my ( $cnt1 ) = $dbh->selectrow_array( "SELECT COUNT(*) FROM items WHERE biblionumber=?", undef, ( $biblionumber ) ); |
705 |
my $x = 0; |
660 |
my ( $cnt2 ) = $dbh->selectrow_array( "SELECT COUNT(*) FROM issues LEFT JOIN items USING (itemnumber) WHERE biblionumber=?", undef, ( $biblionumber )); |
706 |
my $allissued = 1; |
661 |
my ( $cnt3 ) = $dbh->selectrow_array( "SELECT COUNT(*) FROM reserves WHERE biblionumber=? AND borrowernumber<>?", undef, ( $biblionumber, $borrowernumber ) ); |
707 |
while ( $x < $cntitemsfound ) { |
662 |
# If not all items are issued and there are no holds: charge no fee |
708 |
my $bitdata = $biblioitems[$x]; |
663 |
# NOTE: Lost, damaged, not-for-loan, etc. are just ignored here |
709 |
my $sth2 = $dbh->prepare( |
664 |
return if $cnt1 - $cnt2 > 0 && $cnt3 == 0; |
710 |
"SELECT * FROM items |
665 |
|
711 |
WHERE biblioitemnumber = ?" |
666 |
# Here we need to charge the fee |
712 |
); |
667 |
my $nextacctno = &getnextacctno( $borrowernumber ); |
713 |
$sth2->execute( $bitdata->{'biblioitemnumber'} ); |
668 |
$dbh->do( $accquery, undef, ( $borrowernumber, $nextacctno, $fee, "Reserve Charge - $title", $fee ) ); |
714 |
while ( my $itdata = $sth2->fetchrow_hashref ) { |
|
|
715 |
my $sth3 = $dbh->prepare( |
716 |
"SELECT * FROM issues |
717 |
WHERE itemnumber = ?" |
718 |
); |
719 |
$sth3->execute( $itdata->{'itemnumber'} ); |
720 |
if ( my $isdata = $sth3->fetchrow_hashref ) { |
721 |
} |
722 |
else { |
723 |
$allissued = 0; |
724 |
} |
725 |
} |
726 |
$x++; |
727 |
} |
728 |
if ( $allissued == 0 ) { |
729 |
my $rsth = |
730 |
$dbh->prepare("SELECT * FROM reserves WHERE biblionumber = ?"); |
731 |
$rsth->execute($biblionumber); |
732 |
if ( my $rdata = $rsth->fetchrow_hashref ) { |
733 |
} |
734 |
else { |
735 |
$fee = 0; |
736 |
} |
737 |
} |
738 |
} |
669 |
} |
739 |
return $fee; |
|
|
740 |
} |
670 |
} |
741 |
|
671 |
|
742 |
=head2 GetReservesToBranch |
672 |
=head2 GetReservesToBranch |
743 |
- |
|
|