From 141cdbb3a362c36e42769f6bd21efafe1b6ba58c Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Mon, 5 Nov 2007 17:14:05 -0600 Subject: [PATCH] Can check an item out now Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Circulation.pm | 15 +++++--- C4/SIP/ILS.pm | 60 +++++++++++++++++------------ C4/SIP/ILS/Item.pm | 16 +++++--- C4/SIP/ILS/Transaction/Checkout.pm | 62 ++++++++++++++++++++++++++++-- C4/SIP/koha_test/03checkout.t | 10 ++--- C4/SIP/koha_test/SIPtest.pm | 4 +- 6 files changed, 120 insertions(+), 47 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index b25b9f73de..036577c4df 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -680,7 +680,7 @@ sub CanBookBeIssued { # DEBTS my ($amount) = - GetMemberAccountRecords( $borrower->{'borrowernumber'}, $duedate ); + C4::Members::GetMemberAccountRecords( $borrower->{'borrowernumber'}, $duedate ); if ( C4::Context->preference("IssuingInProcess") ) { my $amountlimit = C4::Context->preference("noissuescharge"); if ( $amount > $amountlimit && !$inprocess ) { @@ -761,7 +761,7 @@ sub CanBookBeIssued { } # See if the item is on reserve. - my ( $restype, $res ) = CheckReserves( $item->{'itemnumber'} ); + my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->{'itemnumber'} ); if ($restype) { my $resbor = $res->{'borrowernumber'}; if ( $resbor ne $borrower->{'borrowernumber'} && $restype eq "Waiting" ) @@ -842,6 +842,8 @@ if ($borrower and $barcode and $barcodecheck ne '0'){ # my ($borrower, $flags) = &GetMemberDetails($borrowernumber, 0); # find which item we issue my $item = GetItem('', $barcode); + + my $datedue; # get actual issuing if there is one my $actualissue = GetItemIssue( $item->{itemnumber}); @@ -888,7 +890,7 @@ if ($borrower and $barcode and $barcodecheck ne '0'){ # See if the item is on reserve. my ( $restype, $res ) = - CheckReserves( $item->{'itemnumber'} ); + C4::Reserves::CheckReserves( $item->{'itemnumber'} ); if ($restype) { my $resbor = $res->{'borrowernumber'}; if ( $resbor eq $borrower->{'borrowernumber'} ) { @@ -964,7 +966,7 @@ if ($borrower and $barcode and $barcodecheck ne '0'){ $itype, $borrower->{'branchcode'} ); - my $datedue = time + ($loanlength) * 86400; + $datedue = time + ($loanlength) * 86400; my @datearr = localtime($datedue); my $dateduef = sprintf("%04d-%02d-%02d", 1900 + $datearr[5], $datearr[4] + 1, $datearr[3]); @@ -1019,6 +1021,7 @@ if ($borrower and $barcode and $barcodecheck ne '0'){ &logaction(C4::Context->userenv->{'number'},"CIRCULATION","ISSUE",$borrower->{'borrowernumber'},$biblio->{'biblionumber'}) if C4::Context->preference("IssueLog"); + return ($datedue); } } @@ -1619,8 +1622,8 @@ sub AddRenewal { if ( $datedue eq "" ) { my $biblio = GetBiblioFromItemNumber($itemnumber); - my $borrower = GetMemberDetails( $borrowernumber, 0 ); - my $loanlength = GetLoanLength( + my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ); + my $loanlength = GetLoanLength( $borrower->{'categorycode'}, (C4::Context->preference('item-level_itypes')) ? $biblio->{'ccode'} : $biblio->{'itemtype'} , $borrower->{'branchcode'} diff --git a/C4/SIP/ILS.pm b/C4/SIP/ILS.pm index 8749d66b48..3902c9b3de 100644 --- a/C4/SIP/ILS.pm +++ b/C4/SIP/ILS.pm @@ -19,7 +19,7 @@ use ILS::Transaction::Renew; use ILS::Transaction::RenewAll; my %supports = ( - 'magnetic media' => 0, + 'magnetic media' => 1, 'security inhibit' => 0, 'offline operation' => 0, "patron status request" => 1, @@ -43,9 +43,9 @@ sub new { my ($class, $institution) = @_; my $type = ref($class) || $class; my $self = {}; -use Data::Dumper; -warn " INSTITUTION:"; -warn Dumper($institution); +#use Data::Dumper; +#warn " INSTITUTION:"; +#warn Dumper($institution); syslog("LOG_DEBUG", "new ILS '%s'", $institution->{id}); $self->{institution} = $institution; @@ -54,13 +54,13 @@ warn Dumper($institution); sub find_patron { my $self = shift; - +warn "finding patron"; return ILS::Patron->new(@_); } sub find_item { my $self = shift; - +warn "find item"; return ILS::Item->new(@_); } @@ -135,34 +135,44 @@ sub checkout { my ($patron, $item, $circ); $circ = new ILS::Transaction::Checkout; - +warn "checking out"; # BEGIN TRANSACTION $circ->patron($patron = new ILS::Patron $patron_id); $circ->item($item = new ILS::Item $item_id); if (!$patron) { - $circ->screen_msg("Invalid Patron"); + $circ->screen_msg("Invalid Patron"); } elsif (!$patron->charge_ok) { - $circ->screen_msg("Patron Blocked"); + $circ->screen_msg("Patron Blocked"); } elsif (!$item) { - $circ->screen_msg("Invalid Item"); - } elsif (@{$item->hold_queue} && ($patron_id ne $item->hold_queue->[0])) { - $circ->screen_msg("Item on Hold for Another User"); + $circ->screen_msg("Invalid Item"); + } elsif ($item->hold_queue && @{$item->hold_queue} && ($patron_id ne $item->hold_queue->[0])) { + $circ->screen_msg("Item on Hold for Another User"); } elsif ($item->{patron} && ($item->{patron} ne $patron_id)) { # I can't deal with this right now - $circ->screen_msg("Item checked out to another patron"); + $circ->screen_msg("Item checked out to another patron"); } else { - $circ->ok(1); - # If the item is already associated with this patron, then - # we're renewing it. - $circ->renew_ok($item->{patron} && ($item->{patron} eq $patron_id)); - $item->{patron} = $patron_id; - $item->{due_date} = time + (14*24*60*60); # two weeks - push(@{$patron->{items}}, $item_id); - $circ->desensitize(!$item->magnetic); - - syslog("LOG_DEBUG", "ILS::Checkout: patron %s has checked out %s", - $patron_id, join(', ', @{$patron->{items}})); + $circ->do_checkout(); + if ($circ->ok){ + warn "circ is ok"; + # If the item is already associated with this patron, then + # we're renewing it. + $circ->renew_ok($item->{patron} && ($item->{patron} eq $patron_id)); + + $item->{patron} = $patron_id; + $item->{due_date} = time + (14*24*60*60); # two weeks +# $item->{due_date} = $circ->{due}; + warn "$item->{due_date}"; + push(@{$patron->{items}}, $item_id); + $circ->desensitize(!$item->magnetic); + + syslog("LOG_DEBUG", "ILS::Checkout: patron %s has checked out %s", + $patron_id, join(', ', @{$patron->{items}})); + } + else { + syslog("LOG_DEBUG", "ILS::Checkout Issue failed"); + + } } # END TRANSACTION @@ -208,7 +218,7 @@ sub pay_fee { my $trans; my $patron; - $trans = new ILS::Transaction::FeePayment; +# $trans = new ILS::Transaction::FeePayment; $patron = new ILS::Patron $patron_id; diff --git a/C4/SIP/ILS/Item.pm b/C4/SIP/ILS/Item.pm index e35fd37f95..81aa8064fb 100644 --- a/C4/SIP/ILS/Item.pm +++ b/C4/SIP/ILS/Item.pm @@ -14,6 +14,8 @@ use Sys::Syslog qw(syslog); use ILS::Transaction; +use C4::Biblio; + our %item_db = ( '1565921879' => { title => "Perl 5 desktop reference", @@ -42,14 +44,16 @@ sub new { my ($class, $item_id) = @_; my $type = ref($class) || $class; my $self; - - - if (!exists($item_db{$item_id})) { - syslog("LOG_DEBUG", "new ILS::Item('%s'): not found", $item_id); - return undef; + my $item = GetBiblioFromItemNumber( GetItemnumberFromBarcode($item_id) ); + + if (! $item) { + syslog("LOG_DEBUG", "new ILS::Item('%s'): not found", $item_id); + warn "no item $item_id"; + return undef; } + $item->{'id'} = $item->{'barcode'}; + $self = $item; - $self = $item_db{$item_id}; bless $self, $type; syslog("LOG_DEBUG", "new ILS::Item('%s'): found with title '%s'", diff --git a/C4/SIP/ILS/Transaction/Checkout.pm b/C4/SIP/ILS/Transaction/Checkout.pm index d445df7477..78404b858b 100644 --- a/C4/SIP/ILS/Transaction/Checkout.pm +++ b/C4/SIP/ILS/Transaction/Checkout.pm @@ -8,10 +8,14 @@ use warnings; use strict; use POSIX qw(strftime); +use Sys::Syslog qw(syslog); use ILS; use ILS::Transaction; +use C4::Circulation; +use C4::Members; + our @ISA = qw(ILS::Transaction); # Most fields are handled by the Transaction superclass @@ -27,13 +31,65 @@ sub new { my $element; foreach $element (keys %fields) { - $self->{_permitted}->{$element} = $fields{$element}; + $self->{_permitted}->{$element} = $fields{$element}; } @{$self}{keys %fields} = values %fields; - $self->{'due'} = time() + (60*60*24*14); # two weeks hence - + +# $self->{'due'} = time() + (60*60*24*14); # two weeks hence +# use Data::Dumper; +# warn Dumper $self; return bless $self, $class; } +sub do_checkout { + my $self = shift; + syslog('LOG_DEBUG', "ILS::Transaction::Checkout performing checkout..."); + my $barcode = $self->{item}->id; + my $patron_barcode = $self->{patron}->id; + warn $patron_barcode; + my $borrower = GetMember( $patron_barcode, 'cardnumber' ); +# use Data::Dumper; +# warn Dumper $borrower; + my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued ( $borrower, $barcode, 0, 0, 0, 0 ); + my $noerror=1; + foreach my $impossible ( keys %$issuingimpossible ) { + # do something here so we pass these errors + $self->screen_msg($issuingimpossible->{$impossible}); + $noerror = 0; + } + foreach my $confirmation ( keys %$needsconfirmation ) { + if ($confirmation eq 'RENEW_ISSUE'){ + if (!CanBookBeRenewed($borrower->{borrowernumber},$self->{item}->{itemnumber})){ + $noerror = 0; + warn "cant renew $borrower->{borrowernumber} $self->{item}->{itemnumber}"; + } + } + else { + $self->screen_msg($needsconfirmation->{$confirmation}); + $noerror = 0; + } + } + + + if ($noerror){ + warn "can issue"; + # we can issue + my $datedue = AddIssue( $borrower, $barcode, undef, 0 ); + $self->{'due'} = $datedue; + $self->ok(1); + } + else { + + + warn "cant issue"; + use Data::Dumper; + warn Dumper $issuingimpossible; + warn Dumper $needsconfirmation; + $self->ok(0); + } + return $self; + +} + 1; diff --git a/C4/SIP/koha_test/03checkout.t b/C4/SIP/koha_test/03checkout.t index da9dd28b16..70b00ec4e8 100644 --- a/C4/SIP/koha_test/03checkout.t +++ b/C4/SIP/koha_test/03checkout.t @@ -89,11 +89,11 @@ my $test; ## Test this by checking out exactly the same book a second time. ## The only difference should be that the "Renewal OK" flag should now ## be 'Y'. -#$test = clone($checkout_test_template); -#$test->{id} = 'Checkout: patron renewal'; -#$test->{pat} = qr/^121YNY$datepat/; -# -#push @tests, $test; +$test = clone($checkout_test_template); +$test->{id} = 'Checkout: patron renewal'; +$test->{pat} = qr/^121YNY$datepat/; + +push @tests, $test; # NOW check it in diff --git a/C4/SIP/koha_test/SIPtest.pm b/C4/SIP/koha_test/SIPtest.pm index 6dee85e02e..d44c10128f 100644 --- a/C4/SIP/koha_test/SIPtest.pm +++ b/C4/SIP/koha_test/SIPtest.pm @@ -59,8 +59,8 @@ our $user_ptype = 'A'; our $user_inet = 'N'; # Valid item barcode and corresponding title -our $item_barcode = '26000204'; -our $item_title = 'A community of writers :'; +our $item_barcode = '37000000012023'; +our $item_title = 'The not-just-anybody family.'; our $item_owner = 'kohalibrary'; # Another valid item -- 2.39.5