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);
29 # Most fields are handled by the Transaction superclass
31 security_inhibit => 0,
38 my $self = $class->SUPER::new();
39 foreach my $element (keys %fields) {
40 $self->{_permitted}->{$element} = $fields{$element};
42 @{$self}{keys %fields} = values %fields;
43 # $self->{'due'} = time() + (60*60*24*14); # two weeks hence
44 $debug and warn "new ILS::Transaction::Checkout : " . Dumper $self;
45 return bless $self, $class;
50 syslog('LOG_DEBUG', "ILS::Transaction::Checkout performing checkout...");
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 $patron = Koha::Patrons->find( { cardnumber => $patron_barcode } );
57 my $borrower = $patron->unblessed;
58 $debug and warn "do_checkout borrower: . " . Dumper $borrower;
59 my ($issuingimpossible, $needsconfirmation) = _can_we_issue($patron, $barcode,
60 C4::Context->preference("AllowItemsOnHoldCheckoutSIP")
63 my $noerror=1; # If set to zero we block the issue
64 if (keys %{$issuingimpossible}) {
65 foreach (keys %{$issuingimpossible}) {
66 # do something here so we pass these errors
67 $self->screen_msg("Issue failed : $_");
72 foreach my $confirmation (keys %{$needsconfirmation}) {
73 if ($confirmation eq 'RENEW_ISSUE'){
74 $self->screen_msg("Item already checked out to you: renewing item.");
75 } elsif ($confirmation eq 'RESERVED' or $confirmation eq 'RESERVE_WAITING') {
76 my $x = $self->{item}->available($patron_barcode);
78 $self->screen_msg("Item was reserved for you.");
80 $self->screen_msg("Item is reserved for another patron upon return.");
83 } elsif ($confirmation eq 'ISSUED_TO_ANOTHER') {
84 $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');
91 } elsif ($confirmation eq 'HIGHHOLDS') {
92 $overridden_duedate = $needsconfirmation->{$confirmation}->{returndate};
93 $self->screen_msg('Loan period reduced for high-demand item');
94 } elsif ($confirmation eq 'RENTALCHARGE') {
95 if ($self->{fee_ack} ne 'Y') {
99 } elsif ($confirmation eq 'PREVISSUE') {
100 $self->screen_msg("This item was previously checked out by you");
103 # We've been returned a case other than those above
104 $self->screen_msg("Item cannot be issued: $confirmation");
106 syslog('LOG_DEBUG', "Blocking checkout Reason:$confirmation");
111 my $itemnumber = $self->{item}->{itemnumber};
113 $debug and warn "shelf has ($_->{itemnumber} for $_->{borrowernumber}). this is ($itemnumber, $self->{patron}->{borrowernumber})";
114 ($_->{itemnumber} eq $itemnumber) or next; # skip it if not this item
115 ($_->{borrowernumber} == $self->{patron}->{borrowernumber}) and last;
116 # if item was waiting for this patron, we're done. AddIssue takes care of the "W" hold.
117 $debug and warn "Item is on hold shelf for another patron.";
118 $self->screen_msg("Item is on hold shelf for another patron.");
121 my ($fee, undef) = GetIssuingCharges($itemnumber, $self->{patron}->{borrowernumber});
123 $self->{sip_fee_type} = '06';
124 $self->{fee_amount} = sprintf '%.2f', $fee;
125 if ($self->{fee_ack} eq 'N' ) {
130 $debug and warn "cannot issue: " . Dumper($issuingimpossible) . "\n" . Dumper($needsconfirmation);
135 $debug and warn "do_checkout: calling AddIssue(\$borrower,$barcode, $overridden_duedate, 0)\n"
136 # . "w/ \$borrower: " . Dumper($borrower)
137 . "w/ C4::Context->userenv: " . Dumper(C4::Context->userenv);
138 my $issue = AddIssue( $borrower, $barcode, $overridden_duedate, 0 );
139 $self->{due} = $self->duedatefromissue($issue, $itemnumber);
146 my ( $patron, $barcode, $pref ) = @_;
148 my ( $issuingimpossible, $needsconfirmation, $alerts ) =
149 CanBookBeIssued( $patron, $barcode, undef, 0, $pref );
150 for my $href ( $issuingimpossible, $needsconfirmation ) {
152 # some data is returned using lc keys we only
153 foreach my $key ( keys %{$href} ) {
154 if ( $key =~ m/[^A-Z_]/ ) {
155 delete $href->{$key};
159 return ( $issuingimpossible, $needsconfirmation );