[PATCH 2/2] Adds instant fine calculation at checkin

Elliott Davis tdavis at uttyler.edu
Thu Mar 29 22:05:10 CEST 2012


---
 C4/Circulation.pm |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 9c43f36..0adb8e3 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -36,6 +36,7 @@ use C4::Message;
 use C4::Debug;
 use C4::Branch; # GetBranches
 use C4::Log; # logaction
+use C4::Overdues qw(CalcFine UpdateFine);

 use Data::Dumper;
 use Koha::DateUtils;
@@ -1595,17 +1596,32 @@ sub AddReturn {

     # case of a return of document (deal with issues and holdingbranch)
     if ($doreturn) {
+ my $today =3D DateTime->now( time_zone =3D> C4::Context->tz() );
+ my $datedue =3D $issue->{date_due};
         $borrower or warn "AddReturn without current borrower";
- my $circControlBranch;
+ my $circControlBranch;
         if ($dropbox) {
             # define circControlBranch only if dropbox mode is set
             # don't allow dropbox mode to create an invalid entry in issue=
s (issuedate > today)
             # FIXME: check issuedate > returndate, factoring in holidays
             #$circControlBranch =3D _GetCircControlBranch($item,$borrower)=
 unless ( $item->{'issuedate'} eq C4::Dates->today('iso') );;
             $circControlBranch =3D _GetCircControlBranch($item,$borrower);
+     $today->add(days =3D> -1 );
+     $issue->{'overdue'} =3D DateTime->compare($issue->{'date_due'}, $toda=
y ) =3D=3D -1 ? 1 : 0;
         }
-
         if ($borrowernumber) {
+     if($issue->{'overdue'}){
+ my ( $amount, $type, $daycounttotal ) =3D C4::Overdues::CalcFine( $item, =
$borrower->{categorycode},$branch, $datedue, $today );
+ my $type ||=3D q{};
+ print STDERR "\n\nAMOUNT: $amount";
+ if ( $amount > 0 ) {
+     C4::Overdues::UpdateFine(
+ $issue->{itemnumber},
+ $issue->{borrowernumber},
+ $amount, $type, output_pref($datedue)
+ );
+ }
+     }
             MarkIssueReturned($borrowernumber, $item->{'itemnumber'}, $cir=
cControlBranch, '', $borrower->{'privacy'});
             $messages->{'WasReturned'} =3D 1;    # FIXME is the "=3D 1" ri=
ght?  This could be the borrower hash.
         }
--
1.7.2.5


--_000_CB9A7531404Etdavisuttyleredu_
Content-Type: text/html; charset="us-ascii"
Content-ID: <2FC4BE3240726442BA969F73FEF0FB31 at uttyler.edu>
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"=
>
</head>
<body style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-lin=
e-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-fami=
ly: Calibri, sans-serif; ">
<div>
<div>
<pre class=3D"bz_comment_text" id=3D"comment_text_2" style=3D"font-size: me=
dium; font-family: monospace; white-space: pre-wrap; width: 50em; color: rg=
b(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; =
letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webki=
t-auto; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0p=
x; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><span =
class=3D"Apple-style-span" style=3D"background-color: transparent; ">Adds I=
nstant fine calculation at checkin

To Test:

Check out an Item, hourly items are best but any will do.  Make sure the it=
em is overdue, and when you check the item in you should see a fine reflect=
ed that is correct for the amount of time it is overdue according to your s=
mart rules.</span></pre>
</div>
<div><br>
</div>
<div><br>
</div>
<div>From e13e051ca6742a02c70bdbcba04136da4046ee83 Mon Sep 17 00:00:00 2001=
</div>
<div>From: Elliott Davis &lt;<a href=3D"mailto:tdavis at uttyler.edu">tdavis at u=
ttyler.edu</a>&gt;</div>
<div>Date: Thu, 29 Mar 2012 20:05:10 &#43;0000</div>
<div>Subject: [PATCH 2/2] Adds instant fine calculation at checkin</div>
<div><br>
</div>
<div>---</div>
<div>&nbsp;C4/Circulation.pm | &nbsp; 20 &#43;&#43;&#43;&#43;&#43;&#43;&#43=
;&#43;&#43;&#43;&#43;&#43;&#43;&#43;&#43;&#43;&#43;&#43;--</div>
<div>&nbsp;1 files changed, 18 insertions(&#43;), 2 deletions(-)</div>
<div><br>
</div>
<div>diff --git a/C4/Circulation.pm b/C4/Circulation.pm</div>
<div>index 9c43f36..0adb8e3 100644</div>
<div>--- a/C4/Circulation.pm</div>
<div>&#43;&#43;&#43; b/C4/Circulation.pm</div>
<div>@@ -36,6 &#43;36,7 @@ use C4::Message;</div>
<div>&nbsp;use C4::Debug;</div>
<div>&nbsp;use C4::Branch; # GetBranches</div>
<div>&nbsp;use C4::Log; # logaction</div>
<div>&#43;use C4::Overdues qw(CalcFine UpdateFine);</div>
<div>&nbsp;</div>
<div>&nbsp;use Data::Dumper;</div>
<div>&nbsp;use Koha::DateUtils;</div>
<div>@@ -1595,17 &#43;1596,32 @@ sub AddReturn {</div>
<div>&nbsp;</div>
<div>&nbsp; &nbsp; &nbsp;# case of a return of document (deal with issues a=
nd holdingbranch)</div>
<div>&nbsp; &nbsp; &nbsp;if ($doreturn) {</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>my $today =3D DateTime-&gt;now( time_zone =3D&gt; C4::Context-&gt;tz() )=
;</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>my $datedue =3D $issue-&gt;{date_due};</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$borrower or warn &quot;AddReturn wi=
thout current borrower&quot;;</div>
<div>-<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </span>m=
y $circControlBranch;</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>my $circControlBranch;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ($dropbox) {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# define circControlBr=
anch only if dropbox mode is set</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# don't allow dropbox =
mode to create an invalid entry in issues (issuedate &gt; today)</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# FIXME: check issueda=
te &gt; returndate, factoring in holidays</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#$circControlBranch =
=3D _GetCircControlBranch($item,$borrower) unless ( $item-&gt;{'issuedate'}=
 eq C4::Dates-&gt;today('iso') );;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$circControlBranch =3D=
 _GetCircControlBranch($item,$borrower);</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>&nbsp;&nbsp; &nbsp;$today-&gt;add(days =3D&gt; -1 );</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>&nbsp;&nbsp; &nbsp;$issue-&gt;{'overdue'} =3D DateTime-&gt;compare($issu=
e-&gt;{'date_due'}, $today ) =3D=3D -1 ? 1 : 0;</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div>
<div>-</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ($borrowernumber) {</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>&nbsp;&nbsp; &nbsp;if($issue-&gt;{'overdue'}){</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>my ( $amount, $type, $daycounttotal ) =3D C4::Overdues::CalcFine( $item,=
 $borrower-&gt;{categorycode},$branch, $datedue, $today );</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>my $type ||=3D q{};</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>print STDERR &quot;\n\nAMOUNT: $amount&quot;;</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>if ( $amount &gt; 0 ) {</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>&nbsp;&nbsp; &nbsp;C4::Overdues::UpdateFine(</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>$issue-&gt;{itemnumber},</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>$issue-&gt;{borrowernumber},</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>$amount, $type, output_pref($datedue)</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>);</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>}</div>
<div>&#43;<span class=3D"Apple-tab-span" style=3D"white-space: pre; "> </sp=
an>&nbsp;&nbsp; &nbsp;}</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MarkIssueReturned($bor=
rowernumber, $item-&gt;{'itemnumber'}, $circControlBranch, '', $borrower-&g=
t;{'privacy'});</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$messages-&gt;{'WasRet=
urned'} =3D 1; &nbsp; &nbsp;# FIXME is the &quot;=3D 1&quot; right? &nbsp;T=
his could be the borrower hash.</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div>
<div>--&nbsp;</div>
<div>1.7.2.5</div>
</div>
<div><br>
</div>
</body>
</html>

--_000_CB9A7531404Etdavisuttyleredu_--


More information about the Koha-patches mailing list