&IsBranchTransferAllowed
&CreateBranchTransferLimit
&DeleteBranchTransferLimits
+ &TransferSlip
);
# subs to deal with offline circulation
Retrieves circulation rule attributes that apply to the given
branch and item type, regardless of patron category.
-The return value is a hashref containing the following key:
+The return value is a hashref containing the following keys:
holdallowed => Hold policy for this branch and itemtype. Possible values:
0: No holds allowed.
1: Holds allowed only by patrons that have the same homebranch as the item.
2: Holds allowed from any patron.
+returnbranch => branch to which to return item. Possible values:
+ noreturn: do not return, let item remain where checked in (floating collections)
+ homebranch: return to item's home branch
+
This searches branchitemrules in the following order:
* Same branchcode and itemtype
* branchcode '*', same itemtype
* branchcode and itemtype '*'
-Neither C<$branchcode> nor C<$categorycode> should be '*'.
+Neither C<$branchcode> nor C<$itemtype> should be '*'.
=cut
my $result = {};
my @attempts = (
- ['SELECT holdallowed
+ ['SELECT holdallowed, returnbranch
FROM branch_item_rules
WHERE branchcode = ?
AND itemtype = ?', $branchcode, $itemtype],
- ['SELECT holdallowed
+ ['SELECT holdallowed, returnbranch
FROM default_branch_circ_rules
WHERE branchcode = ?', $branchcode],
- ['SELECT holdallowed
+ ['SELECT holdallowed, returnbranch
FROM default_branch_item_rules
WHERE itemtype = ?', $itemtype],
- ['SELECT holdallowed
+ ['SELECT holdallowed, returnbranch
FROM default_circ_rules'],
);
foreach my $attempt (@attempts) {
my ($query, @bind_params) = @{$attempt};
+ my $search_result = $dbh->selectrow_hashref ( $query , {}, @bind_params );
# Since branch/category and branch/itemtype use the same per-branch
# defaults tables, we have to check that the key we want is set, not
# just that a row was returned
- return $result if ( defined( $result->{'holdallowed'} = $dbh->selectrow_array( $query, {}, @bind_params ) ) );
+ $result->{'holdallowed'} = $search_result->{'holdallowed'} unless ( defined $result->{'holdallowed'} );
+ $result->{'returnbranch'} = $search_result->{'returnbranch'} unless ( defined $result->{'returnbranch'} );
}
# built-in default circulation rule
- return {
- holdallowed => 2,
- };
+ $result->{'holdallowed'} = 2 unless ( defined $result->{'holdallowed'} );
+ $result->{'returnbranch'} = 'homebranch' unless ( defined $result->{'returnbranch'} );
+
+ return $result;
}
=head2 AddReturn
my $item = GetItem($itemnumber) or die "GetItem($itemnumber) failed";
# full item data, but no borrowernumber or checkout info (no issue)
# we know GetItem should work because GetItemnumberFromBarcode worked
- my $hbr = C4::Context->preference("HomeOrHoldingBranchReturn") || "homebranch";
- $hbr = $item->{$hbr} || '';
- # item must be from items table -- issues table has branchcode and issuingbranch, not homebranch nor holdingbranch
+ my $hbr = GetBranchItemRule($item->{'homebranch'}, $item->{'itype'})->{'returnbranch'} || "homebranch";
+ # get the proper branch to which to return the item
+ $hbr = $item->{$hbr} || $branch ;
+ # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
my $borrowernumber = $borrower->{'borrowernumber'} || undef; # we don't know if we had a borrower or not
borrowernumber => $borrower->{borrowernumber},
message_name => $message_name{$type},
});
- my $letter = C4::Letters::getletter('circulation', $type);
- C4::Letters::parseletter($letter, 'biblio', $item->{biblionumber});
- C4::Letters::parseletter($letter, 'biblioitems', $item->{biblionumber});
- C4::Letters::parseletter($letter, 'borrowers', $borrower->{borrowernumber});
- C4::Letters::parseletter($letter, 'branches', $branch);
+ my $letter = C4::Letters::GetPreparedLetter (
+ module => 'circulation',
+ letter_code => $type,
+ branchcode => $branch,
+ tables => {
+ 'biblio' => $item->{biblionumber},
+ 'biblioitems' => $item->{biblionumber},
+ 'borrowers' => $borrower,
+ 'branches' => $branch,
+ }
+ ) or return;
+
my @transports = @{ $borrower_preferences->{transports} };
# warn "no transports" unless @transports;
for (@transports) {
$message->update;
}
}
- $letter;
+
+ return $letter;
}
=head2 updateWrongTransfer
}
sub GetOfflineOperations {
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("SELECT * FROM pending_offline_operations WHERE branchcode=? ORDER BY timestamp");
- $sth->execute(C4::Context->userenv->{'branch'});
- my $results = $sth->fetchall_arrayref({});
- $sth->finish;
- return $results;
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare("SELECT * FROM pending_offline_operations WHERE branchcode=? ORDER BY timestamp");
+ $sth->execute(C4::Context->userenv->{'branch'});
+ my $results = $sth->fetchall_arrayref({});
+ $sth->finish;
+ return $results;
}
sub GetOfflineOperation {
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("SELECT * FROM pending_offline_operations WHERE operationid=?");
- $sth->execute( shift );
- my $result = $sth->fetchrow_hashref;
- $sth->finish;
- return $result;
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare("SELECT * FROM pending_offline_operations WHERE operationid=?");
+ $sth->execute( shift );
+ my $result = $sth->fetchrow_hashref;
+ $sth->finish;
+ return $result;
}
sub AddOfflineOperation {
- my $dbh = C4::Context->dbh;
- warn Data::Dumper::Dumper(@_);
- my $sth = $dbh->prepare("INSERT INTO pending_offline_operations VALUES('',?,?,?,?,?,?)");
- $sth->execute( @_ );
- return "Added.";
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare("INSERT INTO pending_offline_operations (userid, branchcode, timestamp, action, barcode, cardnumber) VALUES(?,?,?,?,?,?)");
+ $sth->execute( @_ );
+ return "Added.";
}
sub DeleteOfflineOperation {
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("DELETE FROM pending_offline_operations WHERE operationid=?");
- $sth->execute( shift );
- return "Deleted.";
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare("DELETE FROM pending_offline_operations WHERE operationid=?");
+ $sth->execute( shift );
+ return "Deleted.";
}
sub ProcessOfflineOperation {
- my $operation = shift;
+ my $operation = shift;
my $report;
- if ( $operation->{action} eq 'return' ) {
+ if ( $operation->{action} eq 'return' ) {
$report = ProcessOfflineReturn( $operation );
- } elsif ( $operation->{action} eq 'issue' ) {
- $report = ProcessOfflineIssue( $operation );
- }
+ } elsif ( $operation->{action} eq 'issue' ) {
+ $report = ProcessOfflineIssue( $operation );
+ }
- DeleteOfflineOperation( $operation->{operationid} ) if $operation->{operationid};
+ DeleteOfflineOperation( $operation->{operationid} ) if $operation->{operationid};
- return $report;
+ return $report;
}
sub ProcessOfflineReturn {
+=head2 TransferSlip
+
+ TransferSlip($user_branch, $itemnumber, $to_branch)
+
+ Returns letter hash ( see C4::Letters::GetPreparedLetter ) or undef
+
+=cut
+
+sub TransferSlip {
+ my ($branch, $itemnumber, $to_branch) = @_;
+
+ my $item = GetItem( $itemnumber )
+ or return;
+
+ my $pulldate = C4::Dates->new();
+
+ return C4::Letters::GetPreparedLetter (
+ module => 'circulation',
+ letter_code => 'TRANSFERSLIP',
+ branchcode => $branch,
+ tables => {
+ 'branches' => $to_branch,
+ 'biblio' => $item->{biblionumber},
+ 'items' => $item,
+ },
+ );
+}
+
+
1;
__END__