Permalink
Browse files

LLK #18845835 use AddIssue() instead of deprecated MarkIssueReturned()

for offline circ
  • Loading branch information...
1 parent c349c16 commit b76fc27cf99a03ceb0aca2864ec52cd2fb1844b7 @hgq hgq committed Sep 26, 2011
View
@@ -1101,165 +1101,4 @@ END { } # module clean-up code here (global destructor)
1;
__END__
-sub returnlost{ # deprecated
- my ( $borrowernumber, $itemnum ) = @_;
- C4::Circulation::MarkIssueReturned( $borrowernumber, $itemnum );
- my $borrower = C4::Members::GetMember( $borrowernumber, 'borrowernumber' );
- my @datearr = localtime(time);
- my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
- my $bor = "$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}";
- C4::Items::ModItem({ paidfor => "Paid for by $bor $date" }, undef, $itemnum);
-}
-
-
-=head2 fixaccounts (removed)
-
- &fixaccounts($borrowernumber, $accountnumber, $amount);
-
-#'
-# FIXME - I don't understand what this function does.
-sub fixaccounts {
- my ( $borrowernumber, $accountno, $amount ) = @_;
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare(
- "SELECT * FROM accountlines WHERE borrowernumber=?
- AND accountno=?"
- );
- $sth->execute( $borrowernumber, $accountno );
- my $data = $sth->fetchrow_hashref;
-
- # FIXME - Error-checking
- my $diff = $amount - $data->{'amount'};
- my $outstanding = $data->{'amountoutstanding'} + $diff;
- $sth->finish;
-
- $dbh->do(<<EOT);
- UPDATE accountlines
- SET amount = '$amount',
- amountoutstanding = '$outstanding'
- WHERE borrowernumber = $borrowernumber
- AND accountno = $accountno
-EOT
- # FIXME: exceedingly bad form. Use prepare with placholders ("?") in query and execute args.
-}
-
-=cut
-
-
-=head2 fixcredit #### DEPRECATED
-
- $amountleft = &fixcredit($borrowernumber, $data, $barcode, $type, $user);
-
- This function is only used internally, not exported.
-
-=cut
-
-# This function is deprecated in 3.0
-
-sub fixcredit {
-
- #here we update both the accountoffsets and the account lines
- my ( $borrowernumber, $data, $barcode, $type, $user ) = @_;
- my $dbh = C4::Context->dbh;
- my $newamtos = 0;
- my $accdata = "";
- my $amountleft = $data;
- if ( $barcode ne '' ) {
- my $item = GetBiblioFromItemNumber( '', $barcode );
- my $nextaccntno = getnextacctno($borrowernumber);
- my $query = "SELECT * FROM accountlines WHERE (borrowernumber=?
- AND itemnumber=? AND amountoutstanding > 0)";
- if ( $type eq 'CL' ) {
- $query .= " AND (accounttype = 'L' OR accounttype = 'Rep')";
- }
- elsif ( $type eq 'CF' ) {
- $query .= " AND (accounttype = 'F' OR accounttype = 'FU' OR
- accounttype='Res' OR accounttype='Rent')";
- }
- elsif ( $type eq 'CB' ) {
- $query .= " and accounttype='A'";
- }
-
- # print $query;
- my $sth = $dbh->prepare($query);
- $sth->execute( $borrowernumber, $item->{'itemnumber'} );
- $accdata = $sth->fetchrow_hashref;
- $sth->finish;
- if ( $accdata->{'amountoutstanding'} < $amountleft ) {
- $newamtos = 0;
- $amountleft -= $accdata->{'amountoutstanding'};
- }
- else {
- $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
- $amountleft = 0;
- }
- my $thisacct = $accdata->{accountno};
- my $usth = $dbh->prepare(
- "UPDATE accountlines SET amountoutstanding= ?
- WHERE (borrowernumber = ?) AND (accountno=?)"
- );
- $usth->execute( $newamtos, $borrowernumber, $thisacct );
- $usth->finish;
- $usth = $dbh->prepare(
- "INSERT INTO accountoffsets
- (borrowernumber, accountno, offsetaccount, offsetamount)
- VALUES (?,?,?,?)"
- );
- $usth->execute( $borrowernumber, $accdata->{'accountno'},
- $nextaccntno, $newamtos );
- $usth->finish;
- }
-
- # begin transaction
- my $nextaccntno = getnextacctno($borrowernumber);
-
- # get lines with outstanding amounts to offset
- my $sth = $dbh->prepare(
- "SELECT * FROM accountlines
- WHERE (borrowernumber = ?) AND (amountoutstanding >0)
- ORDER BY date"
- );
- $sth->execute($borrowernumber);
-
- # print $query;
- # offset transactions
- while ( ( $accdata = $sth->fetchrow_hashref ) and ( $amountleft > 0 ) ) {
- if ( $accdata->{'amountoutstanding'} < $amountleft ) {
- $newamtos = 0;
- $amountleft -= $accdata->{'amountoutstanding'};
- }
- else {
- $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
- $amountleft = 0;
- }
- my $thisacct = $accdata->{accountno};
- my $usth = $dbh->prepare(
- "UPDATE accountlines SET amountoutstanding= ?
- WHERE (borrowernumber = ?) AND (accountno=?)"
- );
- $usth->execute( $newamtos, $borrowernumber, $thisacct );
- $usth->finish;
- $usth = $dbh->prepare(
- "INSERT INTO accountoffsets
- (borrowernumber, accountno, offsetaccount, offsetamount)
- VALUE (?,?,?,?)"
- );
- $usth->execute( $borrowernumber, $accdata->{'accountno'},
- $nextaccntno, $newamtos );
- $usth->finish;
- }
- $sth->finish;
- $type = "Credit " . $type;
- C4::Stats::UpdateStats( $user, $type, $data, $user, '', '', $borrowernumber );
- $amountleft *= -1;
- return ($amountleft);
-
-}
-
-
-=head1 SEE ALSO
-
-DBI(3)
-
-=cut
@@ -58,7 +58,9 @@ function CheckForm(f) {
<!-- TMPL_ELSIF NAME="renew" --><p>Renewed
<!-- TMPL_ELSIF NAME="skip" --><p><span class=error>Skipped </span>
<!-- TMPL_ELSIF NAME="err" --><p><pre class=error>Error: <TMPL_VAR NAME="err"></pre>
+ <TMPL_ELSIF NAME="return"><p>Returned
</TMPL_IF><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->"><!-- TMPL_VAR NAME="title" --></a> (<!-- TMPL_VAR NAME="barcode" -->) to <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->"><!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --></a> (<!-- TMPL_VAR NAME="cardnumber" -->): <!-- TMPL_VAR NAME="datetime" --></p>
+
<!-- TMPL_IF NAME="payment" --><p>Accepted payment (<!-- TMPL_VAR NAME="amount" -->) from <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->"><!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --></a> (<!-- TMPL_VAR NAME="cardnumber" -->): <!-- TMPL_VAR NAME="datetime" --></p><!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
<!-- TMPL_ELSE -->
@@ -126,9 +126,10 @@
my $i = 0;
foreach my $line (@input_lines) {
## apparently, chomp isn't working?
- $line =~ s/\s*$//;
- $i++;
+ $line =~ s/\s*$//s;
+ next unless $line;
my $command_line = parse_command_line($line);
+ next unless $command_line;
# map command names in the file to subroutine names
my %dispatch_table = (
issue => \&kocIssueItem,
@@ -140,9 +141,10 @@
if ( exists $dispatch_table{ $command_line->{'command'} } ) {
$dispatch_table{ $command_line->{'command'} }->($command_line);
} else {
- warn "unknown command: '$command_line->{command}' not processed";
+ next;
}
+ $i++;
if ($runinbackground) {
$job->progress($i);
}
@@ -189,15 +191,14 @@ =head3 parse_command_line
sub parse_command_line {
my $command_line = shift;
chomp($command_line);
-
my ( $timestamp, $command, @args ) = split( /\t/, $command_line );
my ( $date, $time, $id ) = split( /\s/, $timestamp );
my %command = (
- date => $date,
- time => $time,
+ 'date' => $date,
+ 'time' => $time,
id => $id,
- command => $command,
+ 'command' => $command,
);
# set the rest of the keys using a hash slice
@@ -223,7 +224,6 @@ =head3 arguments_for_command
sub arguments_for_command {
my $command = shift;
-
# define the fields for this version of the file.
my %format = (
issue => [qw( cardnumber barcode )],
@@ -319,11 +319,15 @@ sub kocReturnItem {
#warn( Data::Dumper->Dump( [ $circ, $item ], [ qw( circ item ) ] ) );
my $borrowernumber = _get_borrowernumber_from_barcode( $circ->{'barcode'} );
if ( $borrowernumber ) {
+ C4::Circulation::AddReturn(
+ $circ->{barcode},
+ undef, #branch
+ undef, #exemptfine
+ undef, #dropbox,
+ $circ->{date}, # iso
+ undef, #tolost
+ );
my $borrower = GetMember( $borrowernumber, 'borrowernumber' );
- C4::Circulation::MarkIssueReturned( $borrowernumber,
- $item->{'itemnumber'},
- undef,
- $circ->{'date'} );
push( @output, { return => 1,
title => $item->{ 'title' },
@@ -23,7 +23,7 @@ sub methods : Test( 1 ) {
GetIssuingRule
GetBranchBorrowerCircRule
AddReturn
- MarkIssueReturned
+ _MarkIssueReturned
_FixOverduesOnReturn
_FixAccountForLostAndReturned
GetItemIssue
@@ -1,85 +0,0 @@
-package KohaTest::Circulation::MarkIssueReturned;
-use base qw(KohaTest::Circulation);
-
-use strict;
-use warnings;
-
-use Test::More;
-
-=head2 basic_usage
-
-basic usage of C4::Circulation::MarkIssueReturned
-
-=cut
-
-sub basic_usage : Test( 4 ) {
- my $self = shift;
-
- my $before_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
- ok( ! defined $before_issues->{'borrowernumber'}, 'our item is not checked out' )
- or diag( Data::Dumper->Dump( [ $before_issues ], [ 'before_issues' ] ) );
-
- my $datedue = $self->checkout_first_item();
- ok( $datedue, "Now it is checked out and due on $datedue" );
-
- my $after_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
- is( $after_issues->{'borrowernumber'}, $self->{'memberid'}, 'Our item is checked out to our borrower' )
- or diag( Data::Dumper->Dump( [ $after_issues ], [ 'after_issues' ] ) );
-
- C4::Circulation::MarkIssueReturned( $self->{'memberid'}, $self->{'items'}[0]{'itemnumber'} );
-
- my $after_return = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
- ok( ! defined $after_return->{'borrowernumber'}, 'The item is no longer checked out' )
- or diag( Data::Dumper->Dump( [ $after_return ], [ 'after_return' ] ) );
-
-}
-
-=head2 set_returndate
-
-check an item out, then, check it back in, specifying the returndate.
-
-verify that it's checked back in and the returndate is correct.
-
-=cut
-
-sub set_retundate : Test( 7 ) {
- my $self = shift;
-
- # It's not checked out to start with
- my $before_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
- ok( ! defined $before_issues->{'borrowernumber'}, 'our item is not checked out' )
- or diag( Data::Dumper->Dump( [ $before_issues ], [ 'before_issues' ] ) );
-
- # check it out
- my $datedue = $self->checkout_first_item();
- ok( $datedue, "Now it is checked out and due on $datedue" );
-
- # verify that it has been checked out
- my $after_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
- is( $after_issues->{'borrowernumber'}, $self->{'memberid'}, 'Our item is checked out to our borrower' )
- or diag( Data::Dumper->Dump( [ $after_issues ], [ 'after_issues' ] ) );
-
- # mark it as returned on some date
- my $returndate = $self->random_date();
- ok( $returndate, "return this item on $returndate" );
-
- C4::Circulation::MarkIssueReturned( $self->{'memberid'},
- $self->{'items'}[0]{'itemnumber'},
- undef,
- $returndate );
-
- # validate that it is no longer checked out.
- my $after_return = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
- ok( ! defined $after_return->{'borrowernumber'}, 'The item is no longer checked out' )
- or diag( Data::Dumper->Dump( [ $after_return ], [ 'after_return' ] ) );
-
- # grab the history for this item and make sure it looks right
- my $history = C4::Circulation::GetItemIssues( $self->{'items'}[0]{'itemnumber'}, 1 );
- is( scalar @$history, 1, 'this item has been checked out one time.' )
- or diag( Data::Dumper->Dump( [ $history ], [ 'history' ] ) );
- is( $history->[0]{'returndate'}, $returndate, "...and it was returned on $returndate" );
-
-}
-
-
-1;

0 comments on commit b76fc27

Please sign in to comment.