Adding calendar widget to circulation/stickyduedate
[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                         if (!CanBookBeRenewed($borrower->{borrowernumber},$self->{item}->{itemnumber})){
64                                 $noerror = 0;
65                                 warn "cant renew $borrower->{borrowernumber} $self->{item}->{itemnumber}";
66                         }
67                 }
68                 else {
69                         $self->screen_msg($needsconfirmation->{$confirmation});
70                         $noerror = 0;
71                 }
72         }            
73     
74         
75         if ($noerror){
76                 warn "can issue";
77                 # we can issue
78                 my $datedue = AddIssue( $borrower, $barcode, undef, 0 );                
79                 $self->{'due'} = $datedue;
80                 $self->ok(1);
81         }
82         else {          
83                 warn "cant issue";
84                 use Data::Dumper;
85                 warn Dumper $issuingimpossible;
86                 warn Dumper $needsconfirmation;
87                 $self->ok(0);
88         }
89         return $self;
90         
91 }
92
93 1;