&CanBookBeRenewed
&AddIssue
&AddRenewal
+ &GetRenewCount
&GetItemIssue
&GetItemIssues
&GetBorrowerIssues
sub AddIssue {
my ( $borrower, $barcode, $date, $cancelreserve ) = @_;
my $dbh = C4::Context->dbh;
-my $barcodecheck=CheckValidBarcode($barcode);
-if ($borrower and $barcode and $barcodecheck ne '0'){
+ my $barcodecheck=CheckValidBarcode($barcode);
+ if ($borrower and $barcode and $barcodecheck ne '0'){
# my ($borrower, $flags) = &GetMemberDetails($borrowernumber, 0);
- # find which item we issue
- my $item = GetItem('', $barcode);
-
- my $datedue;
-
- # get actual issuing if there is one
- my $actualissue = GetItemIssue( $item->{itemnumber});
-
- # get biblioinformation for this item
- my $biblio = GetBiblioFromItemNumber($item->{itemnumber});
-
- #
- # check if we just renew the issue.
- #
- if ( $actualissue->{borrowernumber} eq $borrower->{'borrowernumber'} ) {
- AddRenewal(
- $borrower->{'borrowernumber'},
- $item->{'itemnumber'}
- );
+ # find which item we issue
+ my $item = GetItem('', $barcode);
+ my $datedue;
+
+ # get actual issuing if there is one
+ my $actualissue = GetItemIssue( $item->{itemnumber});
+
+ # get biblioinformation for this item
+ my $biblio = GetBiblioFromItemNumber($item->{itemnumber});
+
+ #
+ # check if we just renew the issue.
+ #
+ if ( $actualissue->{borrowernumber} eq $borrower->{'borrowernumber'} ) {
+ AddRenewal(
+ $borrower->{'borrowernumber'},
+ $item->{'itemnumber'}
+ );
- }
- else {# it's NOT a renewal
+ }
+ else {
+ # it's NOT a renewal
if ( $actualissue->{borrowernumber}) {
# This book is currently on loan, but not to the person
# who wants to borrow it now. mark it returned before issuing to the new borrower
$item->{'issues'}++;
$sth =
$dbh->prepare(
- "UPDATE items SET issues=?, holdingbranch=?, itemlost=0, datelastborrowed = now() WHERE itemnumber=?");
+ "UPDATE items SET issues=?, holdingbranch=?, itemlost=0, datelastborrowed = now(), onloan = ? WHERE itemnumber=?");
$sth->execute(
$item->{'issues'},
C4::Context->userenv->{'branch'},
+ $dateduef->output('iso'),
$item->{'itemnumber'}
);
$sth->finish;
&ModDateLastSeen( $item->{'itemnumber'} );
+ my $record = GetMarcItem( $item->{'biblionumber'}, $item->{'itemnumber'} );
+ my $frameworkcode = GetFrameworkCode( $item->{'biblionumber'} );
+ ModItemInMarc( $record, $item->{'biblionumber'}, $item->{'itemnumber'}, $frameworkcode );
# If it costs to borrow this book, charge it to the patron's account.
my ( $charge, $itemtype ) = GetIssuingCharges(
$item->{'itemnumber'},
# continue to deal with returns cases, but not only if we have an issue
# the holdingbranch is updated if the document is returned in an other location .
- if ( $iteminformation->{'holdingbranch'} ne C4::Context->userenv->{'branch'} )
- {
- UpdateHoldingbranch(C4::Context->userenv->{'branch'},$iteminformation->{'itemnumber'});
- # reload iteminformation holdingbranch with the userenv value
- $iteminformation->{'holdingbranch'} = C4::Context->userenv->{'branch'};
- }
+ if ( $iteminformation->{'holdingbranch'} ne C4::Context->userenv->{'branch'} ) {
+ UpdateHoldingbranch(C4::Context->userenv->{'branch'},$iteminformation->{'itemnumber'});
+ # reload iteminformation holdingbranch with the userenv value
+ $iteminformation->{'holdingbranch'} = C4::Context->userenv->{'branch'};
+ }
ModDateLastSeen( $iteminformation->{'itemnumber'} );
+ if ($iteminformation->{borrowernumber}){
+ my $sth = $dbh->prepare("UPDATE items SET onloan = NULL where itemnumber = ?");
+ $sth->execute($iteminformation->{'itemnumber'});
+ $sth->finish();
+ my $record = GetMarcItem( $iteminformation->{'biblionumber'}, $iteminformation->{'itemnumber'} );
+ my $frameworkcode = GetFrameworkCode( $iteminformation->{'biblionumber'} );
+ ModItemInMarc( $record, $iteminformation->{'biblionumber'}, $iteminformation->{'itemnumber'}, $frameworkcode );
+ }
($borrower) = C4::Members::GetMemberDetails( $iteminformation->{borrowernumber}, 0 );
# fix up the accounts.....
);
$sth->execute( $datedue->output('iso'), $renews, $borrowernumber, $itemnumber );
$sth->finish;
-
+
# Log the renewal
# Charge a new rental fee, if applicable?
'Rent', $charge, $itemnumber );
$sth->finish;
}
- UpdateStats( C4::Context->userenv->{'branchcode'}, 'renew', $charge, '', $itemnumber );
+ UpdateStats( $branch, 'renew', $charge, '', $itemnumber );
}
+sub GetRenewCount {
+ # check renewal status
+ my ($bornum,$itemno)=@_;
+ my $dbh = C4::Context->dbh;
+ my $renewcount = 0;
+ my $renewsallowed = 0;
+ my $renewsleft = 0;
+ # Look in the issues table for this item, lent to this borrower,
+ # and not yet returned.
+
+ # FIXME - I think this function could be redone to use only one SQL call.
+ my $sth = $dbh->prepare("select * from issues
+ where (borrowernumber = ?)
+ and (itemnumber = ?)
+ and returndate is null");
+ $sth->execute($bornum,$itemno);
+ my $data = $sth->fetchrow_hashref;
+ $renewcount = $data->{'renewals'} if $data->{'renewals'};
+ my $sth2 = $dbh->prepare("select renewalsallowed from items,biblioitems,itemtypes
+ where (items.itemnumber = ?)
+ and (items.biblioitemnumber = biblioitems.biblioitemnumber)
+ and (biblioitems.itemtype = itemtypes.itemtype)");
+ $sth2->execute($itemno);
+ my $data2 = $sth2->fetchrow_hashref();
+ $renewsallowed = $data2->{'renewalsallowed'};
+ $renewsleft = $renewsallowed - $renewcount;
+ warn "Renewcount:$renewcount RenewsAll:$renewsallowed RenewLeft:$renewsleft";
+ return ($renewcount,$renewsallowed,$renewsleft);
+}
=head2 GetIssuingCharges
($charge, $item_type) = &GetIssuingCharges($itemnumber, $borrowernumber);