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);
24 use parent qw(C4::SIP::ILS::Transaction);
28 our $VERSION = 3.07.00.049;
30 # Most fields are handled by the Transaction superclass
32 security_inhibit => 0,
39 my $self = $class->SUPER::new();
40 foreach my $element (keys %fields) {
41 $self->{_permitted}->{$element} = $fields{$element};
43 @{$self}{keys %fields} = values %fields;
44 # $self->{'due'} = time() + (60*60*24*14); # two weeks hence
45 $debug and warn "new ILS::Transaction::Checkout : " . Dumper $self;
46 return bless $self, $class;
51 syslog('LOG_DEBUG', "ILS::Transaction::Checkout performing checkout...");
52 my $pending = $self->{item}->pending_queue;
53 my $shelf = $self->{item}->hold_shelf;
54 my $barcode = $self->{item}->id;
55 my $patron_barcode = $self->{patron}->id;
56 my $overridden_duedate; # usually passed as undef to AddIssue
57 $debug and warn "do_checkout: patron (" . $patron_barcode . ")";
58 my $borrower = $self->{patron}->getmemberdetails_object();
59 $debug and warn "do_checkout borrower: . " . Dumper $borrower;
60 my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued(
65 C4::Context->preference("AllowItemsOnHoldCheckout")
68 if (scalar keys %$issuingimpossible) {
69 foreach (keys %$issuingimpossible) {
70 # do something here so we pass these errors
71 $self->screen_msg($_ . ': ' . $issuingimpossible->{$_});
75 foreach my $confirmation (keys %{$needsconfirmation}) {
76 if ($confirmation eq 'RENEW_ISSUE'){
77 $self->screen_msg("Item already checked out to you: renewing item.");
78 } elsif ($confirmation eq 'RESERVED' or $confirmation eq 'RESERVE_WAITING') {
79 my $x = $self->{item}->available($patron_barcode);
81 $self->screen_msg("Item was reserved for you.");
83 $self->screen_msg("Item is reserved for another patron upon return.");
86 } elsif ($confirmation eq 'ISSUED_TO_ANOTHER') {
87 $self->screen_msg("Item already checked out to another patron. Please return item for check-in.");
89 } elsif ($confirmation eq 'DEBT') {
90 $self->screen_msg('Outstanding Fines block issue');
92 } elsif ($confirmation eq 'HIGHHOLDS') {
93 $overridden_duedate = $needsconfirmation->{$confirmation}->{returndate};
94 $self->screen_msg('Loan period reduced for high-demand item');
95 } elsif ($confirmation eq 'RENTALCHARGE') {
96 if ($self->{fee_ack} ne 'Y') {
100 $self->screen_msg($needsconfirmation->{$confirmation});
102 syslog('LOG_DEBUG', "Blocking checkout Reason:$confirmation");
106 my $itemnumber = $self->{item}->{itemnumber};
108 $debug and warn "shelf has ($_->{itemnumber} for $_->{borrowernumber}). this is ($itemnumber, $self->{patron}->{borrowernumber})";
109 ($_->{itemnumber} eq $itemnumber) or next; # skip it if not this item
110 ($_->{borrowernumber} == $self->{patron}->{borrowernumber}) and last;
111 # if item was waiting for this patron, we're done. AddIssue takes care of the "W" hold.
112 $debug and warn "Item is on hold shelf for another patron.";
113 $self->screen_msg("Item is on hold shelf for another patron.");
116 my ($fee, undef) = GetIssuingCharges($itemnumber, $self->{patron}->{borrowernumber});
118 $self->{sip_fee_type} = '06';
119 $self->{fee_amount} = sprintf '%.2f', $fee;
120 if ($self->{fee_ack} eq 'N' ) {
125 $debug and warn "cannot issue: " . Dumper($issuingimpossible) . "\n" . Dumper($needsconfirmation);
129 # Fill any reserves the patron had on the item.
130 # TODO: this logic should be pulled internal to AddIssue for all Koha.
131 $debug and warn "pending_queue: " . (@$pending) ? Dumper($pending) : '[]';
132 foreach (grep {$_->{borrowernumber} eq $self->{patron}->{borrowernumber}} @$pending) {
133 $debug and warn "Filling reserve (borrowernumber,biblionumber,reservedate): "
134 . sprintf("(%s,%s,%s)\n",$_->{borrowernumber},$_->{biblionumber},$_->{reservedate});
136 # TODO: adjust representation in $self->item
139 $debug and warn "do_checkout: calling AddIssue(\$borrower,$barcode, $overridden_duedate, 0)\n"
140 # . "w/ \$borrower: " . Dumper($borrower)
141 . "w/ C4::Context->userenv: " . Dumper(C4::Context->userenv);
142 my $issue = AddIssue( $borrower, $barcode, $overridden_duedate, 0 );
143 $self->{due} = $self->duedatefromissue($issue, $itemnumber);