The offline circulation file processor originally used its own methods to
insert circulation data. This patch takes advantage of the updated
C4::Circulation methods that allow us to specify dates in the past.
This makes the offline circulation file processor use C4::Circulation
functions instead of its own and removes the deprecated subs.

moving from ForceIssue to AddIssue
replacing ForceRenewal with AddRenewal
moving from ForceReturn to MarkIssueReturned
removing deprecated Force* subs
fixing a few bugs in process_koc.pl
---
 C4/Circulation.pm           |  105 -------------------------------------------
 offline_circ/process_koc.pl |   45 +++++++++---------
 2 files changed, 22 insertions(+), 128 deletions(-)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 5cec366..c9c7684 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -63,9 +63,7 @@ BEGIN {
                &CanBookBeIssued
                &CanBookBeRenewed
                &AddIssue
-                &ForceIssue
                &AddRenewal
-                &ForceRenewal
                &GetRenewCount
                &GetItemIssue
                 &GetOpenIssue
@@ -81,7 +79,6 @@ BEGIN {
        # subs to deal with returns
        push @EXPORT, qw(
                &AddReturn
-                &ForceReturn
         &MarkIssueReturned
        );
 
@@ -1020,29 +1017,6 @@ sub AddIssue {
   }
 }
 
-=head2 ForceIssue
-
-ForceIssue()
-
-Issues an item to a member, ignoring any problems that would normally 
dissallow the issue.
-
-=cut
-
-sub ForceIssue {
-  my ( $borrowernumber, $itemnumber, $date_due, $branchcode, $date ) = @_;
-warn "ForceIssue( $borrowernumber, $itemnumber, $date_due, $branchcode, $date 
);";
-  my $dbh = C4::Context->dbh;
-  my $sth = $dbh->prepare( "INSERT INTO `issues` ( `borrowernumber`, 
`itemnumber`, `date_due`, `branchcode`, `issuingbranch`, `returndate`, 
`lastreneweddate`, `return`,  `renewals`, `timestamp`, `issuedate` )
-                            VALUES ( ?, ?, ?, ?, ?, NULL, NULL, NULL, NULL, 
NOW(), ? )" );
-  $sth->execute( $borrowernumber, $itemnumber, $date_due, $branchcode, 
$branchcode, $date );
-  $sth->finish();
-
-  my $item = GetBiblioFromItemNumber( $itemnumber );
-
-  UpdateStats( $branchcode, 'issue', undef, undef, $itemnumber, $item->{ 
'itemtype' }, $borrowernumber );
-}
-
-
 =head2 GetLoanLength
 
 Get loan length for an itemtype, a borrower type and a branch
@@ -1474,51 +1448,6 @@ sub AddReturn {
     return ( $doreturn, $messages, $iteminformation, $borrower );
 }
 
-=head2 ForceReturn
-
-ForceReturn( $barcode, $date, $branchcode );
-
-Returns an item is if it were returned on C<$date>.
-
-This function is non-interactive and does not check for reserves.
-
-C<$barcode> is the barcode of the item being returned.
-
-C<$date> is the date of the actual return, in the format YYYY-MM-DD.
-
-C<$branchcode> is the branchcode for the library the item was returned to.
-
-=cut
-
-sub ForceReturn {
-  my ( $barcode, $date, $branchcode ) = @_;
-  my $dbh = C4::Context->dbh;
-    
-  my $item = GetBiblioFromItemNumber( undef, $barcode );
-      
-  ## FIXME: Is there a way to get the borrower of an item through the Koha API?
-  my $sth=$dbh->prepare( "SELECT borrowernumber FROM issues WHERE itemnumber = 
? AND returndate IS NULL");
-  $sth->execute( $item->{'itemnumber'} );
-  my ( $borrowernumber ) = $sth->fetchrow;
-  $sth->finish();
-                
-  ## Move the issue from issues to old_issues
-  $sth = $dbh->prepare( "INSERT INTO old_issues ( SELECT * FROM issues WHERE 
itemnumber = ? AND returndate IS NULL )" );
-  $sth->execute( $item->{'itemnumber'} );
-  $sth->finish();
-  ## Delete the row in issues
-  $sth = $dbh->prepare( "DELETE FROM issues WHERE itemnumber = ? AND 
returndate IS NULL" );
-  $sth->execute( $item->{'itemnumber'} );
-  $sth->finish();
-  ## Now set the returndate
-  $sth = $dbh->prepare( 'UPDATE old_issues SET returndate = ? WHERE itemnumber 
= ? AND returndate IS NULL' );
-  $sth->execute( $date, $item->{'itemnumber'} );
-  $sth->finish();
-                                          
-  UpdateStats( $branchcode, 'return', my $amount, my $other, $item->{ 
'itemnumber' }, $item->{ 'itemtype' }, $borrowernumber );
-}
-
-
 =head2 MarkIssueReturned
 
 =over 4
@@ -2096,40 +2025,6 @@ sub AddRenewal {
     UpdateStats( $branch, 'renew', $charge, '', $itemnumber, $item->{itype}, 
$borrowernumber);
 }
 
-
-=head2 ForceRenewal
-
-ForRenewal( $itemnumber, $date, $date_due );
-
-Renews an item for the given date. This function should only be used to update 
renewals that have occurred in the past.
-
-C<$itemnumber> is the itemnumber of the item being renewed.
-
-C<$date> is the date the renewal took place, in the format YYYY-MM-DD
-
-C<$date_due> is the date the item is now due to be returned, in the format 
YYYY-MM-DD
-
-=cut
-
-sub ForceRenewal {
-  my ( $itemnumber, $date, $date_due ) = @_;
-  my $dbh = C4::Context->dbh;
-
-  my $sth = $dbh->prepare("SELECT * FROM issues WHERE itemnumber = ? AND 
returndate IS NULL");
-  $sth->execute( $itemnumber );
-  my $issue = $sth->fetchrow_hashref();
-  $sth->finish();
-  
-
-  $sth = $dbh->prepare('UPDATE issues SET renewals = ?, lastreneweddate = ?, 
date_due = ? WHERE itemnumber = ? AND returndate IS NULL');
-  $sth->execute( $issue->{'renewals'} + 1, $date, $date_due, $itemnumber );
-  $sth->finish();
-  
-  my $item = GetBiblioFromItemNumber( $itemnumber );
-  UpdateStats( $issue->{'branchcode'}, 'renew', undef, undef, $itemnumber, 
$item->{ 'itemtype' }, $issue->{'borrowernumber'} );
-}
-
-
 sub GetRenewCount {
     # check renewal status
     my ($bornum,$itemno)[EMAIL PROTECTED];
diff --git a/offline_circ/process_koc.pl b/offline_circ/process_koc.pl
index d15fb44..2df542e 100755
--- a/offline_circ/process_koc.pl
+++ b/offline_circ/process_koc.pl
@@ -80,6 +80,7 @@ while ( my $line = <$file> ) {
   } elsif ( $circ->{ 'type' } eq 'return' ) {
     kocReturnItem( $circ );
   } elsif ( $circ->{ 'type' } eq 'payment' ) {
+      $circ->{'payment_amount'} = delete $circ->{'barcode'};
     kocMakePayment( $circ );
   }
 }
@@ -104,7 +105,7 @@ sub kocIssueItem {
   my $issuelength = $issuingrule->{ 'issuelength' };
   my ( $year, $month, $day ) = split( /-/, $circ->{'date'} );
   ( $year, $month, $day ) = Add_Delta_Days( $year, $month, $day, $issuelength 
);
-  my $date_due = "$year-$month-$day";
+  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.";
@@ -113,12 +114,18 @@ warn "Item Currently Issued.";
     if ( $issue->{'borrowernumber'} eq $borrower->{'borrowernumber'} ) { ## 
Issued to this person already, renew it.
 warn "Item issued to this member already, renewing.";
     
-      my $renewals = $issue->{'renewals'} + 1;
-      ForceRenewal( $item->{'itemnumber'}, $circ->{'date'}, $date_due ) unless 
( DEBUG );
+    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
+        $circ->{'date'},               # issuedate
+    ) unless ($DEBUG);
 
       push( @output, { message => "Renewed $item->{ 'title' } ( $item->{ 
'barcode' } ) to $borrower->{ 'firstname' } $borrower->{ 'surename' } ( 
$borrower->{'cardnumber'} ) : $circ->{ 'datetime' }\n" } );
 
-    } else { 
+    } else {
 warn "Item issued to a different member.";
 warn "Date of previous issue: $issue->{'issuedate'}";
 warn "Date of this issue: $circ->{'date'}";
@@ -126,13 +133,7 @@ warn "Date of this issue: $circ->{'date'}";
       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.
-warn "Current issue to another member is older, returning and issuing";
-        push( @output, { message => "$item->{ 'title' } ( $item->{'barcode'} ) 
currently issued, returning item.\n" } );
-        ## AddReturnk() should be replaced with a custom function, as it will 
make the return date today, should be before the issue date of the current circ
-        AddReturn( $circ->{ 'barcode' }, $branchcode ) unless ( DEBUG );
-
-        ForceIssue( $borrower->{ 'borrowernumber' }, $item->{ 'itemnumber' }, 
$date_due, $branchcode, $circ->{'date'} ) unless ( DEBUG );
-
+        C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, $date_due ) 
unless ( DEBUG );
         push( @output, { message => "Issued $item->{ 'title' } ( $item->{ 
'barcode' } ) to $borrower->{ 'firstname' } $borrower->{ 'surename' } ( 
$borrower->{'cardnumber'} ) : $circ->{ 'datetime' }\n" } );
 
       } else { ## Current issue is *newer* than this issue, write a 'returned' 
issue, as the item is most likely in the hands of someone else now.
@@ -143,29 +144,27 @@ warn "Current issue to another member is newer. Doing 
nothing";
     
     }
   } else { ## Item is not checked out to anyone at the moment, go ahead and 
issue it
-    ForceIssue( $borrower->{ 'borrowernumber' }, $item->{ 'itemnumber' }, 
$date_due, $branchcode, $circ->{'date'} ) unless ( DEBUG );
+      C4::Circulation::AddIssue( $borrower, $circ->{'barcode'}, $date_due ) 
unless ( DEBUG );
     push( @output, { message => "Issued $item->{ 'title' } ( $item->{ 
'barcode' } ) to $borrower->{ 'firstname' } $borrower->{ 'surename' } ( 
$borrower->{'cardnumber'} ) : $circ->{ 'datetime' }\n" } );
   }  
 }
 
 sub kocReturnItem {
   my ( $circ ) = @_;
-  ForceReturn( $circ->{'barcode'}, $circ->{'date'}, $branchcode );
-  
-  my $item = GetBiblioFromItemNumber( undef, $circ->{'barcode'} );
+  my $borrower = GetMember( $circ->{ 'cardnumber' }, 'cardnumber' );
+  my $item = GetBiblioFromItemNumber( undef, $circ->{ 'barcode' } );
+  C4::Circulation::MarkIssueReturned( $borrower->{'borrowernumber'},
+                                      $item->{'itemnumber'},
+                                      undef,
+                                      $circ->{'date'} );
   
-  ## FIXME: Is there a way to get the borrower of an item through the Koha API?
-  my $sth=$dbh->prepare( "SELECT borrowernumber FROM issues WHERE itemnumber = 
? AND returndate IS NULL");
-  $sth->execute( $item->{'itemnumber'} );
-  my ( $borrowernumber ) = $sth->fetchrow;
-  $sth->finish();
-
-  push( @output, { message => "Returned $item->{ 'title' } ( $item->{ 
'barcode' } ) From borrower number $borrowernumber : $circ->{ 'datetime' }\n" } 
); 
+  push( @output, { message => "Returned $item->{ 'title' } ( $item->{ 
'barcode' } ) From borrower number $borrower->{'borrowernumber'} : $circ->{ 
'datetime' }\n" } ); 
 }
 
 sub kocMakePayment {
   my ( $circ ) = @_;
   my $borrower = GetMember( $circ->{ 'cardnumber' }, 'cardnumber' );
-  recordpayment( my $env, $borrower->{'borrowernumber'}, $circ->{'barcode'} );
+  recordpayment( $borrower->{'borrowernumber'}, $circ->{'payment_amount'} );
+  push( @output, { message => "accepted payment ($circ->{'payment_amount'}) 
from cardnumber ($circ->{'cardnumber'}), borrower 
($borrower->{'borrowernumber'})" } );
 }
 
-- 
1.5.6

_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha.org/mailman/listinfo/koha-patches

Reply via email to