2 # An object to handle checkout status
5 package ILS::Transaction::Checkout;
10 use POSIX qw(strftime);
11 use Sys::Syslog qw(syslog);
21 use C4::Reserves qw(ModReserveFill);
24 use vars qw($VERSION @ISA $debug);
28 @ISA = qw(ILS::Transaction);
31 # Most fields are handled by the Transaction superclass
33 security_inhibit => 0,
40 my $self = $class->SUPER::new();
42 foreach $element (keys %fields) {
43 $self->{_permitted}->{$element} = $fields{$element};
45 @{$self}{keys %fields} = values %fields;
46 # $self->{'due'} = time() + (60*60*24*14); # two weeks hence
47 $debug and warn "new ILS::Transaction::Checkout : " . Dumper $self;
48 return bless $self, $class;
53 syslog('LOG_DEBUG', "ILS::Transaction::Checkout performing checkout...");
54 my $pending = $self->{item}->pending_queue;
55 my $shelf = $self->{item}->hold_shelf;
56 my $barcode = $self->{item}->id;
57 my $patron_barcode = $self->{patron}->id;
58 $debug and warn "do_checkout: patron (" . $patron_barcode . ")";
59 my $borrower = $self->{patron}->getmemberdetails_object();
60 $debug and warn "do_checkout borrower: . " . Dumper $borrower;
61 my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued(
66 C4::Context->preference("AllowItemsOnHoldCheckout")
69 if (scalar keys %$issuingimpossible) {
70 foreach (keys %$issuingimpossible) {
71 # do something here so we pass these errors
72 $self->screen_msg($_ . ': ' . $issuingimpossible->{$_});
76 foreach my $confirmation (keys %$needsconfirmation) {
77 if ($confirmation eq 'RENEW_ISSUE'){
78 $self->screen_msg("Item already checked out to you: renewing item.");
79 } elsif ($confirmation eq 'RESERVED' or $confirmation eq 'RESERVE_WAITING') {
80 my $x = $self->{item}->available($patron_barcode);
82 $self->screen_msg("Item was reserved for you.");
84 $self->screen_msg("Item is reserved for another patron upon return.");
87 } elsif ($confirmation eq 'ISSUED_TO_ANOTHER') {
88 $self->screen_msg("Item already checked out to another patron. Please return item for check-in.");
90 } elsif ($confirmation eq 'DEBT') { # don't do anything, it's the minor debt, and alarms fire elsewhere
92 $self->screen_msg($needsconfirmation->{$confirmation});
97 my $itemnumber = $self->{item}->{itemnumber};
99 $debug and warn "shelf has ($_->{itemnumber} for $_->{borrowernumber}). this is ($itemnumber, $self->{patron}->{borrowernumber})";
100 ($_->{itemnumber} eq $itemnumber) or next; # skip it if not this item
101 ($_->{borrowernumber} == $self->{patron}->{borrowernumber}) and last;
102 # if item was waiting for this patron, we're done. AddIssue takes care of the "W" hold.
103 $debug and warn "Item is on hold shelf for another patron.";
104 $self->screen_msg("Item is on hold shelf for another patron.");
108 $debug and warn "cannot issue: " . Dumper($issuingimpossible) . "\n" . Dumper($needsconfirmation);
112 # Fill any reserves the patron had on the item.
113 # TODO: this logic should be pulled internal to AddIssue for all Koha.
114 $debug and warn "pending_queue: " . (@$pending) ? Dumper($pending) : '[]';
115 foreach (grep {$_->{borrowernumber} eq $self->{patron}->{borrowernumber}} @$pending) {
116 $debug and warn "Filling reserve (borrowernumber,biblionumber,reservedate): "
117 . sprintf("(%s,%s,%s)\n",$_->{borrowernumber},$_->{biblionumber},$_->{reservedate});
119 # TODO: adjust representation in $self->item
122 $debug and warn "do_checkout: calling AddIssue(\$borrower,$barcode, undef, 0)\n"
123 # . "w/ \$borrower: " . Dumper($borrower)
124 . "w/ C4::Context->userenv: " . Dumper(C4::Context->userenv);
125 my $c4due = AddIssue($borrower, $barcode, undef, 0);
126 my $due = $c4due->output('iso') || undef;
127 $debug and warn "Item due: $due";
128 $self->{'due'} = $due;
129 $self->{item}->due_date($due);