bug 2975: fix calculation of due dates by offline circ
authorGalen Charlton <gmcharlt@gmail.com>
Thu, 3 Mar 2011 19:52:46 +0000 (14:52 -0500)
committerChris Cormack <chrisc@catalyst.net.nz>
Mon, 7 Mar 2011 01:35:19 +0000 (14:35 +1300)
Offline circ no longer tries to calculate the due date
directly, instead relying on the AddIssue and AddRenewal
APIs to do so.  This corrects a bug where the due date
would be calculated incorrectly if the item-level_itypes
system preference is turned on.

This change also has the effect of causing the issue date
for loans uploaded via offline circulation to be set
to the time stamp recorded by the offline circulation client.

Test plan:

* Turn on item-level_itypes
* Create an example item whose loan policy per
  the item's item type would be different from
  the default policy based on the bib-level type.
* Create a test KOC file with a loan of the test
  item and the checkout date artificially set
  to yesterday.
* Upload the file:
  - Before the fix, the due date would be set
    to the default due date.  Also, the issue date
    will be set to the date of the upload.
  - After the fix, the due date would be calculated
    correctly based on the item's item type.  Also,
    the issue date will be set to the date recorded
    by the offline circulation client.

Signed-off-by: Galen Charlton <gmcharlt@gmail.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

offline_circ/process_koc.pl

index 5f0d9ff..eca9f86 100755 (executable)
@@ -247,12 +247,6 @@ sub kocIssueItem {
   my $item = GetBiblioFromItemNumber( undef, $circ->{ 'barcode' } );
   my $issue = GetItemIssue( $item->{'itemnumber'} );
 
-  my $issuingrule = GetIssuingRule( $borrower->{ 'categorycode' }, $item->{ 'itemtype' }, $branchcode );
-  my $issuelength = $issuingrule->{ 'issuelength' };
-  my ( $year, $month, $day ) = split( /-/, $circ->{'date'} );
-  ( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, $issuelength );
-  my $date_due = sprintf("%04d-%02d-%02d", $year, $month, $day);
-
   if ( $issue->{ 'date_due' } ) { ## Item is currently checked out to another person.
 #warn "Item Currently Issued.";
     my $issue = GetOpenIssue( $item->{'itemnumber'} );
@@ -260,12 +254,11 @@ sub kocIssueItem {
     if ( $issue->{'borrowernumber'} eq $borrower->{'borrowernumber'} ) { ## Issued to this person already, renew it.
 #warn "Item issued to this member already, renewing.";
     
-    my $date_due_object = C4::Dates->new($date_due ,'iso');
     C4::Circulation::AddRenewal(
         $issue->{'borrowernumber'},    # borrowernumber
         $item->{'itemnumber'},         # itemnumber
         undef,                         # branch
-        $date_due_object,              # datedue
+        undef,                         # datedue - let AddRenewal calculate it automatically
         $circ->{'date'},               # issuedate
     ) unless ($DEBUG);
 
@@ -288,8 +281,7 @@ sub kocIssueItem {
       my ( $c_y, $c_m, $c_d ) = split( /-/, $circ->{'date'} );
       
       if ( Date_to_Days( $i_y, $i_m, $i_d ) < Date_to_Days( $c_y, $c_m, $c_d ) ) { ## Current issue to a different persion is older than this issue, return and issue.
-        my $date_due_object = C4::Dates->new($date_due ,'iso');
-        C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, $date_due_object ) unless ( DEBUG );
+        C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
         push( @output, { issue => 1,
     title => $item->{ 'title' },
     biblionumber => $item->{'biblionumber'},
@@ -309,8 +301,7 @@ sub kocIssueItem {
     
     }
   } else { ## Item is not checked out to anyone at the moment, go ahead and issue it
-      my $date_due_object = C4::Dates->new($date_due ,'iso');
-      C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, $date_due_object ) unless ( DEBUG );
+      C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, undef, undef, $circ->{'date'} ) unless ( DEBUG );
     push( @output, { issue => 1,
     title => $item->{ 'title' },
     biblionumber => $item->{'biblionumber'},