Lines 1579-1586
sub AddReturn {
Link Here
|
1579 |
} |
1579 |
} |
1580 |
|
1580 |
|
1581 |
# case of a return of document (deal with issues and holdingbranch) |
1581 |
# case of a return of document (deal with issues and holdingbranch) |
1582 |
if ($doreturn) { |
|
|
1583 |
my $today = DateTime->now( time_zone => C4::Context->tz() ); |
1582 |
my $today = DateTime->now( time_zone => C4::Context->tz() ); |
|
|
1583 |
if ($doreturn) { |
1584 |
my $datedue = $issue->{date_due}; |
1584 |
my $datedue = $issue->{date_due}; |
1585 |
$borrower or warn "AddReturn without current borrower"; |
1585 |
$borrower or warn "AddReturn without current borrower"; |
1586 |
my $circControlBranch; |
1586 |
my $circControlBranch; |
Lines 1590-1596
sub AddReturn {
Link Here
|
1590 |
# FIXME: check issuedate > returndate, factoring in holidays |
1590 |
# FIXME: check issuedate > returndate, factoring in holidays |
1591 |
#$circControlBranch = _GetCircControlBranch($item,$borrower) unless ( $item->{'issuedate'} eq C4::Dates->today('iso') );; |
1591 |
#$circControlBranch = _GetCircControlBranch($item,$borrower) unless ( $item->{'issuedate'} eq C4::Dates->today('iso') );; |
1592 |
$circControlBranch = _GetCircControlBranch($item,$borrower); |
1592 |
$circControlBranch = _GetCircControlBranch($item,$borrower); |
1593 |
my $datedue = $issue->{date_due}; |
|
|
1594 |
$issue->{'overdue'} = DateTime->compare($issue->{'date_due'}, $today ) == -1 ? 1 : 0; |
1593 |
$issue->{'overdue'} = DateTime->compare($issue->{'date_due'}, $today ) == -1 ? 1 : 0; |
1595 |
} |
1594 |
} |
1596 |
|
1595 |
|
Lines 1654-1662
sub AddReturn {
Link Here
|
1654 |
my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox); |
1653 |
my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox); |
1655 |
defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!"; # zero is OK, check defined |
1654 |
defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!"; # zero is OK, check defined |
1656 |
|
1655 |
|
1657 |
# fix fine days |
1656 |
if ( $issue->{overdue} && $issue->{date_due} ) { |
1658 |
my $debardate = _FixFineDaysOnReturn( $borrower, $item, $issue->{date_due} ); |
1657 |
# fix fine days |
1659 |
$messages->{'Debarred'} = $debardate if ($debardate); |
1658 |
my $debardate = |
|
|
1659 |
_debar_user_on_return( $borrower, $item, $issue->{date_due}, $today ); |
1660 |
$messages->{Debarred} = $debardate if ($debardate); |
1661 |
} |
1660 |
} |
1662 |
} |
1661 |
|
1663 |
|
1662 |
# find reserves..... |
1664 |
# find reserves..... |
Lines 1781-1806
sub MarkIssueReturned {
Link Here
|
1781 |
$sth_del->execute($borrowernumber, $itemnumber); |
1783 |
$sth_del->execute($borrowernumber, $itemnumber); |
1782 |
} |
1784 |
} |
1783 |
|
1785 |
|
1784 |
=head2 _FixFineDaysOnReturn |
1786 |
=head2 _debar_user_on_return |
1785 |
|
1787 |
|
1786 |
&_FixFineDaysOnReturn($borrower, $item, $datedue); |
1788 |
_debar_user_on_return($borrower, $item, $datedue, today); |
1787 |
|
1789 |
|
1788 |
C<$borrower> borrower hashref |
1790 |
C<$borrower> borrower hashref |
1789 |
|
1791 |
|
1790 |
C<$item> item hashref |
1792 |
C<$item> item hashref |
1791 |
|
1793 |
|
1792 |
C<$datedue> date due |
1794 |
C<$datedue> date due DateTime object |
1793 |
|
1795 |
|
1794 |
Internal function, called only by AddReturn that calculate and update the user fine days, and debars him |
1796 |
C<$today> DateTime object representing the return time |
|
|
1797 |
|
1798 |
Internal function, called only by AddReturn that calculates and updates |
1799 |
the user fine days, and debars him if necessary. |
1800 |
|
1801 |
Should only be called for overdue returns |
1795 |
|
1802 |
|
1796 |
=cut |
1803 |
=cut |
1797 |
|
1804 |
|
1798 |
sub _FixFineDaysOnReturn { |
1805 |
sub _debar_user_on_return { |
1799 |
my ( $borrower, $item, $datedue ) = @_; |
1806 |
my ( $borrower, $item, $dt_due, $dt_today ) = @_; |
1800 |
return unless ($datedue); |
|
|
1801 |
|
1802 |
my $dt_due = dt_from_string( $datedue ); |
1803 |
my $dt_today = DateTime->now( time_zone => C4::Context->tz() ); |
1804 |
|
1807 |
|
1805 |
my $branchcode = _GetCircControlBranch( $item, $borrower ); |
1808 |
my $branchcode = _GetCircControlBranch( $item, $borrower ); |
1806 |
my $calendar = Koha::Calendar->new( branchcode => $branchcode ); |
1809 |
my $calendar = Koha::Calendar->new( branchcode => $branchcode ); |
Lines 1809-1843
sub _FixFineDaysOnReturn {
Link Here
|
1809 |
my $deltadays = $calendar->days_between( $dt_due, $dt_today ); |
1812 |
my $deltadays = $calendar->days_between( $dt_due, $dt_today ); |
1810 |
|
1813 |
|
1811 |
my $circcontrol = C4::Context::preference('CircControl'); |
1814 |
my $circcontrol = C4::Context::preference('CircControl'); |
1812 |
my $issuingrule = GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode ); |
1815 |
my $issuingrule = |
1813 |
my $finedays = $issuingrule->{finedays}; |
1816 |
GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode ); |
1814 |
my $unit = $issuingrule->{lengthunit}; |
1817 |
my $finedays = $issuingrule->{finedays}; |
1815 |
|
1818 |
my $unit = $issuingrule->{lengthunit}; |
1816 |
# exit if no finedays defined |
1819 |
|
1817 |
return unless $finedays; |
1820 |
if ($finedays) { |
1818 |
# finedays is in days, so hourly loans must multiply by 24 |
1821 |
|
1819 |
# thus 1 hour late equals 1 day suspension * finedays rate |
1822 |
# finedays is in days, so hourly loans must multiply by 24 |
1820 |
$finedays = $finedays * 24 if ($unit eq 'hours'); |
1823 |
# thus 1 hour late equals 1 day suspension * finedays rate |
1821 |
|
1824 |
$finedays = $finedays * 24 if ( $unit eq 'hours' ); |
1822 |
# grace period is measured in the same units as the loan |
1825 |
|
1823 |
my $grace = DateTime::Duration->new( $unit => $issuingrule->{firstremind} ); |
1826 |
# grace period is measured in the same units as the loan |
1824 |
|
1827 |
my $grace = |
1825 |
if ( ( $deltadays - $grace )->is_positive ) { # you can't compare DateTime::Durations with logical operators |
1828 |
DateTime::Duration->new( $unit => $issuingrule->{firstremind} ); |
1826 |
my $new_debar_dt = $dt_today->clone()->add_duration( $deltadays * $finedays ); |
1829 |
if ( $deltadays->subtract($grace)->is_positive() ) { |
1827 |
my $borrower_debar_dt = dt_from_string( $borrower->{debarred} ); |
1830 |
|
1828 |
# check to see if the current debar date is a valid date |
1831 |
my $new_debar_dt = |
1829 |
if ( $borrower->{debarred} && $borrower_debar_dt ) { |
1832 |
$dt_today->clone()->add_duration( $deltadays * $finedays ); |
1830 |
# if so, is it before the new date? update only if true |
1833 |
if ( $borrower->{debarred} ) { |
1831 |
if ( DateTime->compare( $borrower_debar_dt, $new_debar_dt ) == -1 ) { |
1834 |
my $borrower_debar_dt = dt_from_string( $borrower->{debarred} ); |
1832 |
C4::Members::DebarMember( $borrower->{borrowernumber}, $new_debar_dt->ymd() ); |
1835 |
|
1833 |
return $new_debar_dt->ymd(); |
1836 |
# Update patron only if new date > old |
|
|
1837 |
if ( DateTime->compare( $borrower_debar_dt, $new_debar_dt ) != |
1838 |
-1 ) |
1839 |
{ |
1840 |
return; |
1841 |
} |
1842 |
|
1834 |
} |
1843 |
} |
1835 |
# if the borrower's debar date is not set or valid, debar them |
1844 |
C4::Members::DebarMember( $borrower->{borrowernumber}, |
1836 |
} else { |
1845 |
$new_debar_dt->ymd() ); |
1837 |
C4::Members::DebarMember( $borrower->{borrowernumber}, $new_debar_dt->ymd() ); |
|
|
1838 |
return $new_debar_dt->ymd(); |
1846 |
return $new_debar_dt->ymd(); |
1839 |
} |
1847 |
} |
1840 |
} |
1848 |
} |
|
|
1849 |
return; |
1841 |
} |
1850 |
} |
1842 |
|
1851 |
|
1843 |
=head2 _FixOverduesOnReturn |
1852 |
=head2 _FixOverduesOnReturn |
1844 |
- |
|
|