=head2 transferbook
($dotransfer, $messages, $iteminformation) = &transferbook($newbranch,
- $barcode, $ignore_reserves);
+ $barcode, $ignore_reserves, $trigger);
Transfers an item to a new branch. If the item is currently on loan, it is automatically returned before the actual transfer.
If C<$ignore_reserves> is true, C<&transferbook> ignores reserves.
Otherwise, if an item is reserved, the transfer fails.
+C<$trigger> is the enum value for what triggered the transfer.
+
Returns three values:
=over
=cut
sub transferbook {
- my ( $tbr, $barcode, $ignoreRs ) = @_;
+ my ( $tbr, $barcode, $ignoreRs, $trigger ) = @_;
my $messages;
my $dotransfer = 1;
my $item = Koha::Items->find( { barcode => $barcode } );
#actually do the transfer....
if ($dotransfer) {
- ModItemTransfer( $itemnumber, $fbr, $tbr );
+ ModItemTransfer( $itemnumber, $fbr, $tbr, $trigger );
# don't need to update MARC anymore, we do it in batch now
$messages->{'WasTransfered'} = 1;
if ($duedate && ref $duedate ne 'DateTime') {
$duedate = dt_from_string($duedate);
}
- my $now = DateTime->now( time_zone => C4::Context->tz() );
+ my $now = dt_from_string();
unless ( $duedate ) {
my $issuedate = $now->clone();
}
}
- my $issuedate = DateTime->now( time_zone => C4::Context->tz() );
+ my $issuedate = dt_from_string();
my $calendar = Koha::Calendar->new( branchcode => $branchcode );
# $issuedate defaults to today.
if ( !defined $issuedate ) {
- $issuedate = DateTime->now( time_zone => C4::Context->tz() );
+ $issuedate = dt_from_string();
}
else {
if ( ref $issuedate ne 'DateTime' ) {
}
}
- ModItem(
- {
- issues => ( $item_object->issues || 0 ) + 1,
- holdingbranch => C4::Context->userenv->{'branch'},
- itemlost => 0,
- onloan => $datedue->ymd(),
- datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
- },
- $item_object->biblionumber,
- $item_object->itemnumber,
- { log_action => 0 }
- );
+ $item_object->issues( ( $item_object->issues || 0 ) + 1);
+ $item_object->holdingbranch(C4::Context->userenv->{'branch'});
+ $item_object->itemlost(0);
+ $item_object->onloan($datedue->ymd());
+ $item_object->datelastborrowed( dt_from_string()->ymd() );
+ $item_object->store({log_action => 0});
ModDateLastSeen( $item_object->itemnumber );
# If it costs to borrow this book, charge it to the patron's account.
. Dumper($issue->unblessed) . "\n";
} else {
$messages->{'NotIssued'} = $barcode;
- ModItem({ onloan => undef }, $item->biblionumber, $item->itemnumber) if defined $item->onloan;
+ $item->onloan(undef)->store if defined $item->onloan;
+
# even though item is not on loan, it may still be transferred; therefore, get current branch info
$doreturn = 0;
# No issue, no borrowernumber. ONLY if $doreturn, *might* you have a $borrower later.
}
}
- my $item_unblessed = $item->unblessed;
# full item data, but no borrowernumber or checkout info (no issue)
my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch";
# get the proper branch to which to return the item
my $returnbranch = $hbr ne 'noreturn' ? $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 $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef;
my $borrowernumber = $patron ? $patron->borrowernumber : undef; # we don't know if we had a borrower or not
my $patron_unblessed = $patron ? $patron->unblessed : {};
if ($update_loc_rules->{_ALL_} eq '_BLANK_') { $update_loc_rules->{_ALL_} = ''; }
if ( $item->location ne $update_loc_rules->{_ALL_}) {
$messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{_ALL_} };
- ModItem( { location => $update_loc_rules->{_ALL_} }, undef, $itemnumber );
+ $item->location($update_loc_rules->{_ALL_})->store;
}
}
else {
if ( $update_loc_rules->{$key} eq '_BLANK_') { $update_loc_rules->{$key} = '' ;}
if ( ($item->location eq $key && $item->location ne $update_loc_rules->{$key}) || ($key eq '_BLANK_' && $item->location eq '' && $update_loc_rules->{$key} ne '') ) {
$messages->{'ItemLocationUpdated'} = { from => $item->location, to => $update_loc_rules->{$key} };
- ModItem( { location => $update_loc_rules->{$key} }, undef, $itemnumber );
+ $item->location($update_loc_rules->{$key})->store;
last;
}
}
foreach my $key ( keys %$rules ) {
if ( $item->notforloan eq $key ) {
$messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$key} };
- ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber, { log_action => 0 } );
+ $item->notforloan($rules->{$key})->store({ log_action => 0 });
last;
}
}
}
# check if the return is allowed at this branch
- my ($returnallowed, $message) = CanBookBeReturned($item_unblessed, $branch);
+ my ($returnallowed, $message) = CanBookBeReturned($item->unblessed, $branch);
unless ($returnallowed){
$messages->{'Wrongbranch'} = {
Wrongbranch => $branch,
};
unless ( $@ ) {
if ( C4::Context->preference('CalculateFinesOnReturn') && !$item->itemlost ) {
- _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed, return_date => $return_date } );
+ _CalculateAndUpdateFine( { issue => $issue, item => $item->unblessed, borrower => $patron_unblessed, return_date => $return_date } );
}
} else {
carp "The checkin for the following issue failed, Please go to the about page, section 'data corrupted' to know how to fix this problem ($@)" . Dumper( $issue->unblessed );
}
- ModItem( { onloan => undef }, $item->biblionumber, $item->itemnumber, { log_action => 0 } );
+ $item->onloan(undef)->store({ log_action => 0 });
}
# the holdingbranch is updated if the document is returned to another location.
# this is always done regardless of whether the item was on loan or not
my $item_holding_branch = $item->holdingbranch;
if ($item->holdingbranch ne $branch) {
- UpdateHoldingbranch($branch, $item->itemnumber);
- $item_unblessed->{'holdingbranch'} = $branch; # update item data holdingbranch too # FIXME I guess this is for the _debar_user_on_return call later
+ $item->holdingbranch($branch)->store;
}
my $leave_item_lost = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0;
if ( $issue and $issue->is_overdue ) {
# fix fine days
- my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item_unblessed, dt_from_string($issue->date_due), $return_date );
+ my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item->unblessed, dt_from_string($issue->date_due), $return_date );
if ($reminder){
$messages->{'PrevDebarred'} = $debardate;
} else {
if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) {
SendCirculationAlert({
type => 'CHECKIN',
- item => $item_unblessed,
+ item => $item->unblessed,
borrower => $patron->unblessed,
branch => $branch,
});
(C4::Context->preference("UseBranchTransferLimits") and
! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
)) {
- $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->itemnumber,$branch, $returnbranch;
- $debug and warn "item: " . Dumper($item_unblessed);
- ModItemTransfer($item->itemnumber, $branch, $returnbranch);
+ $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s, %s)", $item->itemnumber,$branch, $returnbranch, $transfer_trigger;
+ $debug and warn "item: " . Dumper($item->unblessed);
+ ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger);
$messages->{'WasTransfered'} = 1;
} else {
$messages->{'NeedsTransfer'} = $returnbranch;
+ $messages->{'TransferTrigger'} = $transfer_trigger;
}
}
# And finally delete the issue
$issue->delete;
- ModItem( { 'onloan' => undef }, undef, $itemnumber, { log_action => 0 } );
+ $issue->item->onloan(undef)->store({ log_action => 0 });
if ( C4::Context->preference('StoreLastBorrower') ) {
my $item = Koha::Items->find( $itemnumber );
$accountline->discard_changes->status('FOUND');
$accountline->store;
+ $accountline->item->paidfor('')->store({ log_action => 0 });
+
if ( defined $account and C4::Context->preference('AccountAutoReconcile') ) {
$account->reconcile_balance;
}
return ( 0, 'overdue');
}
- if ( $issue->auto_renew ) {
+ if ( $issue->auto_renew && $patron->autorenew_checkouts ) {
if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
return ( 0, 'auto_account_expired' );
$soonestrenewal->truncate( to => 'day' );
}
- if ( $soonestrenewal > DateTime->now( time_zone => C4::Context->tz() ) )
+ if ( $soonestrenewal > dt_from_string() )
{
- return ( 0, "auto_too_soon" ) if $issue->auto_renew;
+ return ( 0, "auto_too_soon" ) if $issue->auto_renew && $patron->autorenew_checkouts;
return ( 0, "too_soon" );
}
- elsif ( $issue->auto_renew ) {
+ elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) {
$auto_renew = 1;
}
}
# Fallback for automatic renewals:
# If norenewalbefore is undef, don't renew before due date.
- if ( $issue->auto_renew && !$auto_renew ) {
+ if ( $issue->auto_renew && !$auto_renew && $patron->autorenew_checkouts ) {
my $now = dt_from_string;
if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
$auto_renew = 1;
my $itemnumber = shift or return;
my $branch = shift;
my $datedue = shift;
- my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz);
+ my $lastreneweddate = shift || dt_from_string();
my $skipfinecalc = shift;
my $item_object = Koha::Items->find($itemnumber) or return;
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
dt_from_string( $issue->date_due, 'sql' ) :
- DateTime->now( time_zone => C4::Context->tz());
+ dt_from_string();
$datedue = CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, 'is a renewal');
}
# Update the renewal count on the item, and tell zebra to reindex
$renews = ( $item_object->renewals || 0 ) + 1;
- ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item_object->biblionumber, $itemnumber, { log_action => 0 } );
+ $item_object->renewals($renews);
+ $item_object->onloan($datedue);
+ $item_object->store({ log_action => 0 });
# Charge a new rental fee, if applicable
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
}
- unless ( C4::Context->interface eq 'opac' ) { #if from opac we are obeying OpacRenewalBranch as calculated in opac-renew.pl
- $branch = ( C4::Context->userenv && defined C4::Context->userenv->{branch} ) ? C4::Context->userenv->{branch} : $branch;
- }
-
# Add the renewal to stats
UpdateStats(
{
- branch => $branch,
+ branch => $item_object->renewal_branchcode({branch => $branch}),
type => 'renew',
amount => $charge,
itemnumber => $itemnumber,
# LOCK TABLES is not transaction-safe and implicitly commits any active transaction before attempting to lock the tables.
# If the LOCK/UNLOCK statements are executed from tests, the current transaction will be committed.
# To avoid that we need to guess if this code is execute from tests or not (yes it is a bit hacky)
- my $do_not_lock = ( exists $ENV{_} && $ENV{_} =~ m|prove| ) || $ENV{KOHA_NO_TABLE_LOCKS};
+ my $do_not_lock = ( exists $ENV{_} && $ENV{_} =~ m|prove| ) || $ENV{KOHA_TESTING};
for my $mtt (@transports) {
my $letter = C4::Letters::GetPreparedLetter (
ModItemTransfer($itemNumber, $FromLibrary, $waitingAtLibrary);
#third step changing holdingbranch of item
- UpdateHoldingbranch($FromLibrary,$itemNumber);
-}
-
-=head2 UpdateHoldingbranch
-
- $items = UpdateHoldingbranch($branch,$itmenumber);
-
-Simple methode for updating hodlingbranch in items BDD line
-
-=cut
-
-sub UpdateHoldingbranch {
- my ( $branch,$itemnumber ) = @_;
- ModItem({ holdingbranch => $branch }, undef, $itemnumber);
+ my $item = Koha::Items->find($itemNumber)->holdingbranch($FromLibrary)->store;
}
=head2 CalcDateDue
$datedue = $startdate->clone;
}
} else {
- $datedue =
- DateTime->now( time_zone => C4::Context->tz() )
- ->truncate( to => 'minute' );
+ $datedue = dt_from_string()->truncate( to => 'minute' );
}
#When item is marked lost automatically cancel its outstanding transfers and set items holdingbranch to the transfer source branch (frombranch)
if (my ( $datesent,$frombranch,$tobranch ) = GetTransfers($itemnumber)) {
- ModItem({holdingbranch => $frombranch}, undef, $itemnumber);
+ Koha::Items->find($itemnumber)->holdingbranch($frombranch)->store;
}
my $transferdeleted = DeleteTransfer($itemnumber);
}
$itemnumber,
$operation->{timestamp},
);
- ModItem(
- { renewals => 0, onloan => undef },
- $issue->{'biblionumber'},
- $itemnumber,
- { log_action => 0 }
- );
+ $item->renewals(0);
+ $item->onloan(undef);
+ $item->store({ log_action => 0 });
return "Success.";
} else {
return "Item not issued.";
}
#Get how many days the borrower has to reach the age restriction
- my @Today = split /-/, DateTime->today->ymd();
+ my @Today = split /-/, dt_from_string()->ymd();
my $daysToAgeRestriction = Date_to_Days(@alloweddate) - Date_to_Days(@Today);
#Negative days means the borrower went past the age restriction age
return ($restriction_year, $daysToAgeRestriction);