&AddRenewal
&GetRenewCount
&GetItemIssue
+ &GetOpenIssue
&GetItemIssues
&GetBorrowerIssues
&GetIssuingCharges
return ( $dotransfer, $messages, $biblio );
}
-=head2 CanBookBeIssued
-
-Check if a book can be issued.
-
-my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued($borrower,$barcode,$year,$month,$day);
-
-=over 4
-
-=item C<$borrower> hash with borrower informations (from GetMemberDetails)
-
-=item C<$barcode> is the bar code of the book being issued.
-
-=item C<$year> C<$month> C<$day> contains the date of the return (in case it's forced by "stickyduedate".
-
-=back
-
-Returns :
-
-=over 4
-
-=item C<$issuingimpossible> a reference to a hash. It contains reasons why issuing is impossible.
-Possible values are :
-
-=back
-
-=head3 INVALID_DATE
-
-sticky due date is invalid
-
-=head3 GNA
-
-borrower gone with no address
-
-=head3 CARD_LOST
-
-borrower declared it's card lost
-
-=head3 DEBARRED
-
-borrower debarred
-
-=head3 UNKNOWN_BARCODE
-
-barcode unknown
-
-=head3 NOT_FOR_LOAN
-
-item is not for loan
-
-=head3 WTHDRAWN
-
-item withdrawn.
-
-=head3 RESTRICTED
-
-item is restricted (set by ??)
-
-C<$issuingimpossible> a reference to a hash. It contains reasons why issuing is impossible.
-Possible values are :
-
-=head3 DEBT
-
-borrower has debts.
-
-=head3 RENEW_ISSUE
-
-renewing, not issuing
-
-=head3 ISSUED_TO_ANOTHER
-
-issued to someone else.
-
-=head3 RESERVED
-
-reserved for someone else.
-
-=head3 INVALID_DATE
-
-sticky due date is invalid
-
-=head3 TOO_MANY
-
-if the borrower borrows to much things
-
-=cut
-
-# check if a book can be issued.
-
sub TooMany {
my $borrower = shift;
=head2 CanBookBeIssued
-( $issuingimpossible, $needsconfirmation ) =
- CanBookBeIssued( $borrower, $barcode, $duedatespec, $inprocess );
-C<$duedatespec> is a C4::Dates object.
+Check if a book can be issued.
+
+( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $borrower, $barcode, $duedatespec, $inprocess );
+
C<$issuingimpossible> and C<$needsconfirmation> are some hashref.
+=over 4
+
+=item C<$borrower> hash with borrower informations (from GetMemberDetails)
+
+=item C<$barcode> is the bar code of the book being issued.
+
+=item C<$duedatespec> is a C4::Dates object.
+
+=item C<$inprocess>
+
+=back
+
+Returns :
+
+=over 4
+
+=item C<$issuingimpossible> a reference to a hash. It contains reasons why issuing is impossible.
+Possible values are :
+
+=back
+
+=head3 INVALID_DATE
+
+sticky due date is invalid
+
+=head3 GNA
+
+borrower gone with no address
+
+=head3 CARD_LOST
+
+borrower declared it's card lost
+
+=head3 DEBARRED
+
+borrower debarred
+
+=head3 UNKNOWN_BARCODE
+
+barcode unknown
+
+=head3 NOT_FOR_LOAN
+
+item is not for loan
+
+=head3 WTHDRAWN
+
+item withdrawn.
+
+=head3 RESTRICTED
+
+item is restricted (set by ??)
+
+C<$issuingimpossible> a reference to a hash. It contains reasons why issuing is impossible.
+Possible values are :
+
+=head3 DEBT
+
+borrower has debts.
+
+=head3 RENEW_ISSUE
+
+renewing, not issuing
+
+=head3 ISSUED_TO_ANOTHER
+
+issued to someone else.
+
+=head3 RESERVED
+
+reserved for someone else.
+
+=head3 INVALID_DATE
+
+sticky due date is invalid
+
+=head3 TOO_MANY
+
+if the borrower borrows to much things
+
=cut
sub CanBookBeIssued {
=item C<$date> contains the max date of return. calculated if empty.
+=item C<$cancelreserve>
+
+=item C<$issuedate> the date to issue the item in iso format (YYYY-MM-DD). Defaults to today.
+
AddIssue does the following things :
- step 01: check that there is a borrowernumber & a barcode provided
- check for RENEWAL (book issued & being issued to the same patron)
=cut
sub AddIssue {
- my ( $borrower, $barcode, $date, $cancelreserve ) = @_;
+ my ( $borrower, $barcode, $datedue, $cancelreserve, $issuedate ) = @_;
my $dbh = C4::Context->dbh;
my $barcodecheck=CheckValidBarcode($barcode);
+
+ # $issuedate defaults to today.
+ if ( ! defined $issuedate ) {
+ $issuedate = strftime( "%Y-%m-%d", localtime );
+ }
if ($borrower and $barcode and $barcodecheck ne '0'){
# find which item we issue
my $item = GetItem('', $barcode) or return undef; # if we don't get an Item, abort.
- my $datedue;
my $branch;
# Get which branchcode we need
if (C4::Context->preference('CircControl') eq 'PickupLibrary'){
$borrower->{'borrowernumber'},
$item->{'itemnumber'},
$branch,
- $date
+ $datedue,
+ $issuedate,
);
}
# warn "Waiting";
# The item is on reserve and waiting, but has been
# reserved by some other patron.
- my ( $resborrower ) = GetMemberDetails( $resbor, 0 );
- my $branches = GetBranches();
- my $branchname =
- $branches->{ $res->{'branchcode'} }->{'branchname'};
}
elsif ( $restype eq "Reserved" ) {
# warn "Reserved";
# The item is reserved by someone else.
- my ( $resborrower ) = GetMemberDetails( $resbor, 0 );
- my $branches = GetBranches();
- my $branchname = $branches->{ $res->{'branchcode'} }->{'branchname'};
if ($cancelreserve) { # cancel reserves on this item
CancelReserve( 0, $res->{'itemnumber'},
$res->{'borrowernumber'} );
(borrowernumber, itemnumber,issuedate, date_due, branchcode)
VALUES (?,?,?,?,?)"
);
- my $dateduef;
- if ($date) {
- $dateduef = $date;
+ my $dateduef;
+ if ($datedue) {
+ $dateduef = $datedue;
} else {
- my $itype=(C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'} ;
- my $loanlength = GetLoanLength(
- $borrower->{'categorycode'},
- $itype,
- $branch
- );
- $dateduef = CalcDateDue(C4::Dates->new(),$loanlength,$branch);
- # if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate
- if ( C4::Context->preference('ReturnBeforeExpiry') && $dateduef->output('iso') gt $borrower->{dateexpiry} ) {
- $dateduef = C4::Dates->new($borrower->{dateexpiry},'iso');
- }
- };
- $sth->execute(
- $borrower->{'borrowernumber'},
- $item->{'itemnumber'},
- strftime( "%Y-%m-%d", localtime ),$dateduef->output('iso'), C4::Context->userenv->{'branch'}
- );
+ my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
+ my $loanlength = GetLoanLength( $borrower->{'categorycode'}, $itype, $branch );
+ $dateduef = CalcDateDue( C4::Dates->new( $issuedate, 'iso' ), $loanlength, $branch );
+
+ # if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate
+ if ( C4::Context->preference('ReturnBeforeExpiry') && $dateduef->output('iso') gt $borrower->{dateexpiry} ) {
+ $dateduef = C4::Dates->new( $borrower->{dateexpiry}, 'iso' );
+ }
+ }
+ $sth->execute(
+ $borrower->{'borrowernumber'}, # borrowernumber
+ $item->{'itemnumber'}, # itemnumber
+ $issuedate, # issuedate
+ $dateduef->output('iso'), # date_due
+ C4::Context->userenv->{'branch'} # branchcode
+ );
$sth->finish;
$item->{'issues'}++;
ModItem({ issues => $item->{'issues'},
Returns a book.
-C<$barcode> is the bar code of the book being returned. C<$branch> is
-the code of the branch where the book is being returned. C<$exemptfine>
-indicates that overdue charges for the item will be removed. C<$dropbox>
-indicates that the check-in date is assumed to be yesterday, or the last
-non-holiday as defined in C4::Calendar . If overdue
-charges are applied and C<$dropbox> is true, the last charge will be removed.
-This assumes that the fines accrual script has run for _today_.
+=over 4
+
+=item C<$barcode> is the bar code of the book being returned.
+
+=item C<$branch> is the code of the branch where the book is being returned.
+
+=item C<$exemptfine> indicates that overdue charges for the item will be
+removed.
+
+=item C<$dropbox> indicates that the check-in date is assumed to be
+yesterday, or the last non-holiday as defined in C4::Calendar . If
+overdue charges are applied and C<$dropbox> is true, the last charge
+will be removed. This assumes that the fines accrual script has run
+for _today_.
+
+=back
C<&AddReturn> returns a list of four items:
=over 4
-MarkIssueReturned($borrowernumber, $itemnumber, $dropbox_branch);
+MarkIssueReturned($borrowernumber, $itemnumber, $dropbox_branch, $returndate);
=back
moving the C<issues> row to C<old_issues> and
setting C<returndate> to the current date, or
the last non-holiday date of the branccode specified in
-C<dropbox> . Assumes you've already checked that
+C<dropbox_branch> . Assumes you've already checked that
it's safe to do this, i.e. last non-holiday > issuedate.
+if C<$returndate> is specified (in iso format), it is used as the date
+of the return. It is ignored when a dropbox_branch is passed in.
+
Ideally, this function would be internal to C<C4::Circulation>,
not exported, but it is currently needed by one
routine in C<C4::Accounts>.
=cut
sub MarkIssueReturned {
- my ($borrowernumber, $itemnumber, $dropbox_branch ) = @_;
- my $dbh = C4::Context->dbh;
- my $query = "UPDATE issues SET returndate=";
- my @bind = ($borrowernumber,$itemnumber);
- if($dropbox_branch) {
- my $calendar = C4::Calendar->new( branchcode => $dropbox_branch );
- my $dropboxdate = $calendar->addDate(C4::Dates->new(), -1 );
- unshift @bind, $dropboxdate->output('iso') ;
- $query .= " ? "
- } else {
- $query .= " now() ";
- }
- $query .= " WHERE borrowernumber = ? AND itemnumber = ?";
+ my ( $borrowernumber, $itemnumber, $dropbox_branch, $returndate ) = @_;
+ my $dbh = C4::Context->dbh;
+ my $query = "UPDATE issues SET returndate=";
+ my @bind;
+ if ($dropbox_branch) {
+ my $calendar = C4::Calendar->new( branchcode => $dropbox_branch );
+ my $dropboxdate = $calendar->addDate( C4::Dates->new(), -1 );
+ $query .= " ? ";
+ push @bind, $dropboxdate->output('iso');
+ } elsif ($returndate) {
+ $query .= " ? ";
+ push @bind, $returndate;
+ } else {
+ $query .= " now() ";
+ }
+ $query .= " WHERE borrowernumber = ? AND itemnumber = ?";
+ push @bind, $borrowernumber, $itemnumber;
# FIXME transaction
my $sth_upd = $dbh->prepare($query);
$sth_upd->execute(@bind);
Returns an array of hashes
+FIXME: Though the above says that this function returns nothing if the
+item is not issued, this actually returns a hasref that looks like
+this:
+ {
+ itemnumber => 1,
+ overdue => 1
+ }
+
+
=cut
sub GetItemIssue {
return ($data);
}
+=head2 GetOpenIssue
+
+$issue = GetOpenIssue( $itemnumber );
+
+Returns the row from the issues table if the item is currently issued, undef if the item is not currently issued
+
+C<$itemnumber> is the item's itemnumber
+
+Returns a hashref
+
+=cut
+
+sub GetOpenIssue {
+ my ( $itemnumber ) = @_;
+
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare( "SELECT * FROM issues WHERE itemnumber = ? AND returndate IS NULL" );
+ $sth->execute( $itemnumber );
+ my $issue = $sth->fetchrow_hashref();
+ return $issue;
+}
+
=head2 GetItemIssues
$issues = &GetItemIssues($itemnumber, $history);
LEFT JOIN borrowers ON borrowers.borrowernumber = issues.borrowernumber
LEFT JOIN items ON issues.itemnumber = items.itemnumber
LEFT JOIN biblioitems ON items.itemnumber = biblioitems.biblioitemnumber
- LEFT JOIN biblio ON biblio.biblionumber = items.biblioitemnumber
+ LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
WHERE biblio.biblionumber = ?
UNION ALL
SELECT old_issues.*,items.barcode,biblio.biblionumber,biblio.title, biblio.author,borrowers.cardnumber,borrowers.surname,borrowers.firstname
LEFT JOIN borrowers ON borrowers.borrowernumber = old_issues.borrowernumber
LEFT JOIN items ON old_issues.itemnumber = items.itemnumber
LEFT JOIN biblioitems ON items.itemnumber = biblioitems.biblioitemnumber
- LEFT JOIN biblio ON biblio.biblionumber = items.biblioitemnumber
+ LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
WHERE biblio.biblionumber = ?
ORDER BY timestamp
";
=head2 AddRenewal
-&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue]);
+&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$issuedate]);
Renews a loan.
C<$datedue> can be a C4::Dates object used to set the due date.
+C<$issuedate> can be a iso formatted date to use for the issuedate.
+
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically
from the book's item type.
my $item = GetItem($itemnumber) or return undef;
my $biblio = GetBiblioFromItemNumber($itemnumber) or return undef;
my $branch = (@_) ? shift : $item->{homebranch}; # opac-renew doesn't send branch
- my $datedue;
+ my $datedue = shift;
+ my $issuedate = shift;
# If the due date wasn't specified, calculate it by adding the
# book's loan length to today's date.
- unless (@_ and $datedue = shift and $datedue->output('iso')) {
+ unless ($datedue && $datedue->output('iso')) {
my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ) or return undef;
my $loanlength = GetLoanLength(
# Update the issues record to have the new due date, and a new count
# of how many times it has been renewed.
my $renews = $issuedata->{'renewals'} + 1;
- $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = CURRENT_DATE
+ $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = CURRENT_DATE, issuedate = ?
WHERE borrowernumber=?
AND itemnumber=?"
);
- $sth->execute( $datedue->output('iso'), $renews, $borrowernumber, $itemnumber );
+ $sth->execute( $datedue->output('iso'), $renews, $issuedate, $borrowernumber, $itemnumber );
$sth->finish;
# Update the renewal count on the item, and tell zebra to reindex