From 6750a1b250775c8d0749e68ca261f063a4a36698 Mon Sep 17 00:00:00 2001 From: "Joe Atzberger (siptest" Date: Wed, 4 Jun 2008 18:14:47 -0500 Subject: [PATCH] Abstraction layer implementation for Transactions. Signed-off-by: Joshua Ferraro --- C4/SIP/ILS/Transaction.pm | 52 ++++++------ C4/SIP/ILS/Transaction/Checkout.pm | 64 +++++++------- C4/SIP/ILS/Transaction/Hold.pm | 132 +++++++++++++++++++++++++---- C4/SIP/ILS/Transaction/Renew.pm | 42 +++++---- 4 files changed, 198 insertions(+), 92 deletions(-) diff --git a/C4/SIP/ILS/Transaction.pm b/C4/SIP/ILS/Transaction.pm index b6d2ac17f9..eb8d71fcca 100644 --- a/C4/SIP/ILS/Transaction.pm +++ b/C4/SIP/ILS/Transaction.pm @@ -7,31 +7,31 @@ package ILS::Transaction; use Carp; use strict; use warnings; +use C4::Context; my %fields = ( - ok => 0, - patron => undef, - item => undef, - desensitize => 0, - alert => '', - transation_id => undef, - sip_fee_type => '01', # Other/Unknown - fee_amount => undef, - sip_currency => 'CAD', - screen_msg => '', - print_line => '', - ); + ok => 0, + patron => undef, + item => undef, + desensitize => 0, + alert => '', + transaction_id=> undef, + sip_fee_type => '01', # Other/Unknown + fee_amount => undef, + sip_currency => 'USD', # FIXME: why hardcoded? + screen_msg => '', + print_line => '', +); our $AUTOLOAD; sub new { - my $class = shift; - my $self = { - _permitted => \%fields, - %fields, - }; - - return bless $self, $class; + my $class = shift; + my $self = { + _permitted => \%fields, + %fields, + }; + return bless $self, $class; } sub DESTROY { @@ -46,14 +46,16 @@ sub AUTOLOAD { $name =~ s/.*://; unless (exists $self->{_permitted}->{$name}) { - croak "Can't access '$name' field of class '$class'"; + croak "Can't access '$name' field of class '$class'"; } - if (@_) { - return $self->{$name} = shift; - } else { - return $self->{$name}; - } + if (@_) { + return $self->{$name} = shift; + } else { + return $self->{$name}; + } } 1; +__END__ + diff --git a/C4/SIP/ILS/Transaction/Checkout.pm b/C4/SIP/ILS/Transaction/Checkout.pm index 262434f63a..048a9c9ab4 100644 --- a/C4/SIP/ILS/Transaction/Checkout.pm +++ b/C4/SIP/ILS/Transaction/Checkout.pm @@ -9,86 +9,84 @@ use strict; use POSIX qw(strftime); use Sys::Syslog qw(syslog); +use Data::Dumper; +use CGI; use ILS; use ILS::Transaction; +use C4::Context; use C4::Circulation; use C4::Members; -our @ISA = qw(ILS::Transaction); +use vars qw($VERSION @ISA $debug); + +BEGIN { + $VERSION = 1.01; + @ISA = qw(ILS::Transaction); + $debug = 0; +} # Most fields are handled by the Transaction superclass my %fields = ( security_inhibit => 0, due => undef, renew_ok => 0, - ); + ); sub new { my $class = shift;; my $self = $class->SUPER::new(); my $element; - foreach $element (keys %fields) { $self->{_permitted}->{$element} = $fields{$element}; } - @{$self}{keys %fields} = values %fields; - # $self->{'due'} = time() + (60*60*24*14); # two weeks hence -# use Data::Dumper; -# warn Dumper $self; + $debug and warn "new ILS::Transaction::Checkout : " . 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 $barcode = $self->{item}->id; my $patron_barcode = $self->{patron}->id; - warn $patron_barcode; + $debug and warn "do_checkout: patron (" . $patron_barcode . ")"; my $borrower = GetMember( $patron_barcode, 'cardnumber' ); -# use Data::Dumper; -# warn Dumper $borrower; - my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued ( $borrower, $barcode ); + $debug and warn "do_checkout borrower: . " . Dumper $borrower; + my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued( $borrower, $barcode ); my $noerror=1; - foreach my $impossible ( keys %$issuingimpossible ) { + foreach ( keys %$issuingimpossible ) { # do something here so we pass these errors - $self->screen_msg($issuingimpossible->{$impossible}); - $noerror = 0; + $self->screen_msg($issuingimpossible->{$_}); + $noerror = 0; } foreach my $confirmation ( keys %$needsconfirmation ) { if ($confirmation eq 'RENEW_ISSUE'){ my ($renewokay,$renewerror)= CanBookBeRenewed($borrower->{borrowernumber},$self->{item}->{itemnumber}); if (! $renewokay){ $noerror = 0; - warn "cant renew $borrower->{borrowernumber} $self->{item}->{itemnumber} $renewerror"; + warn "cannot renew $borrower->{borrowernumber} $self->{item}->{itemnumber} $renewerror"; } - } - else { + } 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; + unless ($noerror) { + warn "cannot issue: " . Dumper $issuingimpossible . "\n" . $needsconfirmation; $self->ok(0); + return $self; } + # can issue + $debug and warn "do_checkout: calling AddIssue(\$borrower,$barcode, undef, 0)\n" + # . "w/ \$borrower: " . Dumper($borrower) + . "w/ C4::Context->userenv: " . Dumper(C4::Context->userenv); + $self->{'due'} = AddIssue( $borrower, $barcode, undef, 0 ); + $self->ok(1); return $self; - } 1; +__END__ diff --git a/C4/SIP/ILS/Transaction/Hold.pm b/C4/SIP/ILS/Transaction/Hold.pm index 14b3a9d89b..69657539a4 100644 --- a/C4/SIP/ILS/Transaction/Hold.pm +++ b/C4/SIP/ILS/Transaction/Hold.pm @@ -9,31 +9,131 @@ use strict; use ILS; use ILS::Transaction; -our @ISA = qw(ILS::Transaction); +use C4::Reserves; # AddReserve +use C4::Members; # GetMember +use C4::Biblio; # GetBiblioFromItemNumber GetBiblioItemByBiblioNumber -my %fields = ( - expiration_date => 0, - pickup_location => undef, - ); - -sub new { - my $class = shift;; - my $self = $class->SUPER::new(); - my $element; +use vars qw($VERSION @ISA); - foreach $element (keys %fields) { - $self->{_permitted}->{$element} = $fields{$element}; - } +BEGIN { + $VERSION = 1.01; + @ISA = qw(ILS::Transaction); +} - @{$self}{keys %fields} = values %fields; +my %fields = ( + expiration_date => 0, + pickup_location => undef, + constraint_type => undef, +); - return bless $self, $class; +sub new { + my $class = shift; + my $self = $class->SUPER::new(); + my $element; + foreach $element (keys %fields) { + $self->{_permitted}->{$element} = $fields{$element}; + } + @{$self}{keys %fields} = values %fields; + return bless $self, $class; } sub queue_position { my $self = shift; - return $self->item->hold_queue_position($self->patron->id); } +sub do_hold { + my $self = shift; + unless ($self->{patron}) { + $self->screen_msg('do_hold called with undefined patron'); + $self->ok(0); + return $self; + } + my $borrower = GetMember( $self->{patron}->id, 'cardnumber'); + unless ($borrower) { + $self->screen_msg('No borrower matches cardnumber "' . $self->{patron}->id . '".'); + $self->ok(0); + return $self; + } + my $bib = GetBiblioFromItemNumber(undef, $self->{item}->id); + unless ($bib) { + $self->screen_msg('No biblio record matches barcode "' . $self->{item}->id . '".'); + $self->ok(0); + return $self; + } + my $branch = ($self->pickup_location || $self->{patron}->branchcode); + unless ($branch) { + $self->screen_msg('No branch specified (or found w/ patron).'); + $self->ok(0); + return $self; + } + my $bibno = $bib->{biblionumber}; + AddReserve($branch, $borrower->{borrowernumber}, + $bibno, 'a', GetBiblioItemByBiblioNumber($bibno)) ; + # unfortunately no meaningful return value + $self->ok(1); + return $self; +} + +sub drop_hold { + my $self = shift; + unless ($self->{patron}) { + $self->screen_msg('drop_hold called with undefined patron'); + $self->ok(0); + return $self; + } + my $borrower = GetMember( $self->{patron}->id, 'cardnumber'); + unless ($borrower) { + $self->screen_msg('No borrower matches cardnumber "' . $self->{patron}->id . '".'); + $self->ok(0); + return $self; + } + my $bib = GetBiblioFromItemNumber(undef, $self->{item}->id); + # FIXME: figure out if it is a item or title hold. Till then, cancel both. + CancelReserve($bib->{biblionumber}, undef, $borrower->{borrowernumber}); + CancelReserve(undef, $self->{item}->id, $borrower->{borrowernumber}); + # unfortunately no meaningful return value here either + $self->ok(1); + return $self; +} + +sub change_hold { + my $self = shift; + unless ($self->{patron}) { + $self->screen_msg('change_hold called with undefined patron'); + $self->ok(0); + return $self; + } + my $borrower = GetMember( $self->{patron}->id, 'cardnumber'); + unless ($borrower) { + $self->screen_msg('No borrower matches cardnumber "' . $self->{patron}->id . '".'); + $self->ok(0); + return $self; + } + my $bib = GetBiblioFromItemNumber(undef, $self->{item}->id); + unless ($bib) { + $self->screen_msg('No biblio record matches barcode "' . $self->{item}->id . '".'); + $self->ok(0); + return $self; + } + my $branch = ($self->pickup_location || $self->{patron}->branchcode); + unless ($branch) { + $self->screen_msg('No branch specified (or found w/ patron).'); + $self->ok(0); + return $self; + } + my $bibno = $bib->{biblionumber}; + ModReserve($bibno, $borrower->{borrowernumber}, $branch, GetBiblioItemByBiblioNumber($bibno)); + # unfortunately no meaningful return value + # ModReserve needs to be fixed to maintain priority by iteself (Feb 2008) + $self->ok(1); + return $self; +} 1; +__END__ + +# 10 friggin arguments +AddReserve($branch,$borrowernumber,$biblionumber,$constraint,$bibitems,$priority,$notes,$title,$checkitem,$found) + +ModReserve($rank, $biblio, $borrower, $branch , $itemnumber) + diff --git a/C4/SIP/ILS/Transaction/Renew.pm b/C4/SIP/ILS/Transaction/Renew.pm index da6542cd8e..5310936d2d 100644 --- a/C4/SIP/ILS/Transaction/Renew.pm +++ b/C4/SIP/ILS/Transaction/Renew.pm @@ -16,36 +16,42 @@ use C4::Members; our @ISA = qw(ILS::Transaction); my %fields = ( - renewal_ok => 0, - ); + renewal_ok => 0, +); sub new { - my $class = shift;; - my $self = $class->SUPER::new(); - my $element; + my $class = shift; + my $self = $class->SUPER::new(); + my $element; - foreach $element (keys %fields) { - $self->{_permitted}->{$element} = $fields{$element}; - } - - @{$self}{keys %fields} = values %fields; + foreach $element (keys %fields) { + $self->{_permitted}->{$element} = $fields{$element}; + } - return bless $self, $class; + @{$self}{keys %fields} = values %fields; # overkill? + return bless $self, $class; } -sub do_renew { +sub do_renew_for ($$) { my $self = shift; - my $borrower = my $borrower = GetMember( $self->{patron}->id, 'cardnumber'); + my $borrower = shift; my ($renewokay,$renewerror) = CanBookBeRenewed($borrower->{borrowernumber},$self->{item}->{itemnumber}); if ($renewokay){ my $datedue = AddIssue( $borrower, $self->{item}->id, undef, 0 ); - $self->{'due'} = $datedue; - $self->ok(1); + $self->{due} = $datedue; $self->renewal_ok(1); + } else { + $self->screen_msg(($self->screen_msg || '') . " " . $renewerror); + $self->renewal_ok(0); } - else { - $self->ok(0); - } + $self->ok(1) unless $!; return $self; +} + +sub do_renew { + my $self = shift; + my $borrower = GetMember( $self->{patron}->id, 'cardnumber'); + return $self->do_renew_for($borrower); } + 1; -- 2.39.5