Lines 1768-1814
sub AddIssue {
Link Here
|
1768 |
# and SwitchOnSiteCheckouts is enabled this converts it to a regular checkout |
1768 |
# and SwitchOnSiteCheckouts is enabled this converts it to a regular checkout |
1769 |
$issue = Koha::Checkouts->find( { itemnumber => $item_object->itemnumber } ); |
1769 |
$issue = Koha::Checkouts->find( { itemnumber => $item_object->itemnumber } ); |
1770 |
|
1770 |
|
1771 |
# If this checkout relates to a booking, handle booking status appropriately |
1771 |
my $schema = Koha::Database->schema; |
1772 |
if ( my $booking = $item_object->find_booking( { checkout_date => $issuedate, due_date => $datedue } ) ) { |
1772 |
$schema->txn_do( |
1773 |
if ( $booking->patron_id == $patron->borrowernumber ) { |
1773 |
sub { |
|
|
1774 |
# If this checkout relates to a booking, handle booking status appropriately |
1775 |
if ( my $booking = |
1776 |
$item_object->find_booking( { checkout_date => $issuedate, due_date => $datedue } ) ) |
1777 |
{ |
1778 |
if ( $booking->patron_id == $patron->borrowernumber ) { |
1774 |
|
1779 |
|
1775 |
# Patron's own booking - mark as completed |
1780 |
# Patron's own booking - mark as completed and link checkout to booking |
1776 |
$booking->status('completed')->store; |
1781 |
$booking->status('completed')->store; |
1777 |
} else { |
1782 |
$issue_attributes->{'booking_id'} = $booking->booking_id; |
|
|
1783 |
} else { |
1778 |
|
1784 |
|
1779 |
# Another patron's booking - only cancel if checkout period overlaps with actual booking period |
1785 |
# Another patron's booking - only cancel if checkout period overlaps with actual booking period |
1780 |
my $booking_start = dt_from_string( $booking->start_date ); |
1786 |
my $booking_start = dt_from_string( $booking->start_date ); |
1781 |
my $booking_end = dt_from_string( $booking->end_date ); |
1787 |
my $booking_end = dt_from_string( $booking->end_date ); |
1782 |
|
1788 |
|
1783 |
# Check if checkout period overlaps with actual booking period (not just lead/trail) |
1789 |
# Check if checkout period overlaps with actual booking period (not just lead/trail) |
1784 |
if ( ( $issuedate >= $booking_start && $issuedate <= $booking_end ) |
1790 |
if ( ( $issuedate >= $booking_start && $issuedate <= $booking_end ) |
1785 |
|| ( $datedue >= $booking_start && $datedue <= $booking_end ) |
1791 |
|| ( $datedue >= $booking_start && $datedue <= $booking_end ) |
1786 |
|| ( $issuedate <= $booking_start && $datedue >= $booking_end ) ) |
1792 |
|| ( $issuedate <= $booking_start && $datedue >= $booking_end ) ) |
1787 |
{ |
1793 |
{ |
1788 |
# Checkout overlaps with actual booking period - cancel the booking |
1794 |
# Checkout overlaps with actual booking period - cancel the booking |
1789 |
$booking->status('cancelled')->store; |
1795 |
$booking->status('cancelled')->store; |
|
|
1796 |
} |
1797 |
|
1798 |
# If only in lead/trail period, do nothing - librarian has made informed decision |
1799 |
} |
1790 |
} |
1800 |
} |
1791 |
|
1801 |
|
1792 |
# If only in lead/trail period, do nothing - librarian has made informed decision |
1802 |
if ($issue) { |
1793 |
} |
1803 |
$issue->set($issue_attributes)->store; |
1794 |
} |
1804 |
} else { |
|
|
1805 |
$issue = Koha::Checkout->new( |
1806 |
{ |
1807 |
itemnumber => $item_object->itemnumber, |
1808 |
%$issue_attributes, |
1809 |
} |
1810 |
)->store; |
1795 |
|
1811 |
|
1796 |
if ($issue) { |
1812 |
# Ensure item is no longer listed in the holds queue |
1797 |
$issue->set($issue_attributes)->store; |
1813 |
$dbh->do( |
1798 |
} else { |
1814 |
q{DELETE tmp_holdsqueue, hold_fill_targets FROM tmp_holdsqueue LEFT JOIN hold_fill_targets USING ( itemnumber ) WHERE itemnumber = ?}, |
1799 |
$issue = Koha::Checkout->new( |
1815 |
undef, $item_object->id |
1800 |
{ |
1816 |
); |
1801 |
itemnumber => $item_object->itemnumber, |
|
|
1802 |
%$issue_attributes, |
1803 |
} |
1817 |
} |
1804 |
)->store; |
1818 |
} |
1805 |
|
1819 |
); |
1806 |
# Ensure item is no longer listed in the holds queue |
|
|
1807 |
$dbh->do( |
1808 |
q{DELETE tmp_holdsqueue, hold_fill_targets FROM tmp_holdsqueue LEFT JOIN hold_fill_targets USING ( itemnumber ) WHERE itemnumber = ?}, |
1809 |
undef, $item_object->id |
1810 |
); |
1811 |
} |
1812 |
$issue->discard_changes; |
1820 |
$issue->discard_changes; |
1813 |
|
1821 |
|
1814 |
#Update borrowers.lastseen |
1822 |
#Update borrowers.lastseen |
Lines 3475-3487
sub AddRenewal {
Link Here
|
3475 |
# of how many times it has been renewed. |
3483 |
# of how many times it has been renewed. |
3476 |
my $renews = ( $issue->renewals_count || 0 ) + 1; |
3484 |
my $renews = ( $issue->renewals_count || 0 ) + 1; |
3477 |
my $sth = $dbh->prepare( |
3485 |
my $sth = $dbh->prepare( |
3478 |
"UPDATE issues SET date_due = ?, renewals_count = ?, unseen_renewals = ?, lastreneweddate = ? WHERE issue_id = ?" |
3486 |
"UPDATE issues SET date_due = ?, renewals_count = ?, unseen_renewals = ?, lastreneweddate = ?, booking_id = ? WHERE issue_id = ?" |
3479 |
); |
3487 |
); |
3480 |
|
3488 |
|
3481 |
eval { |
3489 |
eval { |
3482 |
$sth->execute( |
3490 |
$sth->execute( |
3483 |
$datedue->strftime('%Y-%m-%d %H:%M'), $renews, $unseen_renewals, $lastreneweddate, |
3491 |
$datedue->strftime('%Y-%m-%d %H:%M'), $renews, $unseen_renewals, $lastreneweddate, |
3484 |
$issue->issue_id |
3492 |
$issue->booking_id, $issue->issue_id |
3485 |
); |
3493 |
); |
3486 |
}; |
3494 |
}; |
3487 |
if ( $sth->err ) { |
3495 |
if ( $sth->err ) { |