Changing CanBookBeRenewed to pass back the reason a renewal cannot proceed
[koha.git] / C4 / SIP / ILS / Transaction / Checkout.pm
1 #
2 # An object to handle checkout status
3 #
4
5 package ILS::Transaction::Checkout;
6
7 use warnings;
8 use strict;
9
10 use POSIX qw(strftime);
11 use Sys::Syslog qw(syslog);
12
13 use ILS;
14 use ILS::Transaction;
15
16 use C4::Circulation;
17 use C4::Members;
18
19 our @ISA = qw(ILS::Transaction);
20
21 # Most fields are handled by the Transaction superclass
22 my %fields = (
23               security_inhibit => 0,
24               due              => undef,
25               renew_ok         => 0,
26               );
27
28 sub new {
29     my $class = shift;;
30     my $self = $class->SUPER::new();
31     my $element;
32
33     foreach $element (keys %fields) {
34                 $self->{_permitted}->{$element} = $fields{$element};
35     }
36
37     @{$self}{keys %fields} = values %fields;
38
39 #    $self->{'due'} = time() + (60*60*24*14); # two weeks hence
40 #       use Data::Dumper;
41 #    warn Dumper $self;    
42     return bless $self, $class;
43 }
44
45 sub do_checkout {
46         my $self = shift;
47         syslog('LOG_DEBUG', "ILS::Transaction::Checkout performing checkout...");
48         my $barcode = $self->{item}->id;
49         my $patron_barcode = $self->{patron}->id;
50         warn $patron_barcode;
51         my $borrower = GetMember( $patron_barcode, 'cardnumber' );
52 #       use Data::Dumper;
53 #       warn Dumper $borrower;
54         my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued ( $borrower, $barcode );
55         my $noerror=1;
56         foreach my $impossible ( keys %$issuingimpossible ) {
57                 # do something here so we pass these errors
58                 $self->screen_msg($issuingimpossible->{$impossible});
59                 $noerror = 0;                                                                                                                                  
60         }
61         foreach my $confirmation ( keys %$needsconfirmation ) {
62                 if ($confirmation eq 'RENEW_ISSUE'){
63                         my ($renewokay,$renewerror)= CanBookBeRenewed($borrower->{borrowernumber},$self->{item}->{itemnumber});
64                         if (! $renewokay){
65                                 $noerror = 0;
66                                 warn "cant renew $borrower->{borrowernumber} $self->{item}->{itemnumber} $renewerror";
67                         }
68                 }
69                 else {
70                         $self->screen_msg($needsconfirmation->{$confirmation});
71                         $noerror = 0;
72                 }
73         }            
74     
75         
76         if ($noerror){
77                 warn "can issue";
78                 # we can issue
79                 my $datedue = AddIssue( $borrower, $barcode, undef, 0 );                
80                 $self->{'due'} = $datedue;
81                 $self->ok(1);
82         }
83         else {          
84                 warn "cant issue";
85                 use Data::Dumper;
86                 warn Dumper $issuingimpossible;
87                 warn Dumper $needsconfirmation;
88                 $self->ok(0);
89         }
90         return $self;
91         
92 }
93
94 1;