2 # An object to handle checkout status
5 package C4::SIP::ILS::Transaction::Checkout;
10 use POSIX qw(strftime);
11 use Sys::Syslog qw(syslog);
15 use C4::SIP::ILS::Transaction;
20 use C4::Reserves qw(ModReserveFill);
22 use parent qw(C4::SIP::ILS::Transaction);
26 our $VERSION = 3.07.00.049;
28 # Most fields are handled by the Transaction superclass
30 security_inhibit => 0,
37 my $self = $class->SUPER::new();
38 foreach my $element (keys %fields) {
39 $self->{_permitted}->{$element} = $fields{$element};
41 @{$self}{keys %fields} = values %fields;
42 # $self->{'due'} = time() + (60*60*24*14); # two weeks hence
43 $debug and warn "new ILS::Transaction::Checkout : " . Dumper $self;
44 return bless $self, $class;
49 syslog('LOG_DEBUG', "ILS::Transaction::Checkout performing checkout...");
50 my $pending = $self->{item}->pending_queue;
51 my $shelf = $self->{item}->hold_shelf;
52 my $barcode = $self->{item}->id;
53 my $patron_barcode = $self->{patron}->id;
54 my $overridden_duedate; # usually passed as undef to AddIssue
55 $debug and warn "do_checkout: patron (" . $patron_barcode . ")";
56 my $borrower = $self->{patron}->getmemberdetails_object();
57 $debug and warn "do_checkout borrower: . " . Dumper $borrower;
58 my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued(
63 C4::Context->preference("AllowItemsOnHoldCheckout")
66 if (scalar keys %$issuingimpossible) {
67 foreach (keys %$issuingimpossible) {
68 # do something here so we pass these errors
69 $self->screen_msg($_ . ': ' . $issuingimpossible->{$_});
73 foreach my $confirmation (keys %{$needsconfirmation}) {
74 if ($confirmation eq 'RENEW_ISSUE'){
75 $self->screen_msg("Item already checked out to you: renewing item.");
76 } elsif ($confirmation eq 'RESERVED' or $confirmation eq 'RESERVE_WAITING') {
77 my $x = $self->{item}->available($patron_barcode);
79 $self->screen_msg("Item was reserved for you.");
81 $self->screen_msg("Item is reserved for another patron upon return.");
84 } elsif ($confirmation eq 'ISSUED_TO_ANOTHER') {
85 $self->screen_msg("Item already checked out to another patron. Please return item for check-in.");
87 } elsif ($confirmation eq 'DEBT') {
88 $self->screen_msg('Outstanding Fines block issue');
90 } elsif ($confirmation eq 'HIGHHOLDS') {
91 $overridden_duedate = $needsconfirmation->{$confirmation}->{returndate};
92 $self->screen_msg('Loan period reduced for high-demand item');
94 $self->screen_msg($needsconfirmation->{$confirmation});
99 my $itemnumber = $self->{item}->{itemnumber};
101 $debug and warn "shelf has ($_->{itemnumber} for $_->{borrowernumber}). this is ($itemnumber, $self->{patron}->{borrowernumber})";
102 ($_->{itemnumber} eq $itemnumber) or next; # skip it if not this item
103 ($_->{borrowernumber} == $self->{patron}->{borrowernumber}) and last;
104 # if item was waiting for this patron, we're done. AddIssue takes care of the "W" hold.
105 $debug and warn "Item is on hold shelf for another patron.";
106 $self->screen_msg("Item is on hold shelf for another patron.");
110 $debug and warn "cannot issue: " . Dumper($issuingimpossible) . "\n" . Dumper($needsconfirmation);
114 # Fill any reserves the patron had on the item.
115 # TODO: this logic should be pulled internal to AddIssue for all Koha.
116 $debug and warn "pending_queue: " . (@$pending) ? Dumper($pending) : '[]';
117 foreach (grep {$_->{borrowernumber} eq $self->{patron}->{borrowernumber}} @$pending) {
118 $debug and warn "Filling reserve (borrowernumber,biblionumber,reservedate): "
119 . sprintf("(%s,%s,%s)\n",$_->{borrowernumber},$_->{biblionumber},$_->{reservedate});
121 # TODO: adjust representation in $self->item
124 $debug and warn "do_checkout: calling AddIssue(\$borrower,$barcode, $overridden_duedate, 0)\n"
125 # . "w/ \$borrower: " . Dumper($borrower)
126 . "w/ C4::Context->userenv: " . Dumper(C4::Context->userenv);
127 my $due_dt = AddIssue($borrower, $barcode, $overridden_duedate, 0);
129 $self->{due} = $due_dt->clone();
131 $self->{due} = undef;
134 #$self->{item}->due_date($due);