2 # An object to handle checkout status
5 package C4::SIP::ILS::Transaction::Checkout;
10 use POSIX qw(strftime);
11 use C4::SIP::Sip qw(siplog);
15 use C4::SIP::ILS::Transaction;
20 use C4::Reserves qw(ModReserveFill);
23 use parent qw(C4::SIP::ILS::Transaction);
25 # Most fields are handled by the Transaction superclass
27 security_inhibit => 0,
34 my $self = $class->SUPER::new();
35 foreach my $element (keys %fields) {
36 $self->{_permitted}->{$element} = $fields{$element};
38 @{$self}{keys %fields} = values %fields;
39 return bless $self, $class;
45 siplog('LOG_DEBUG', "ILS::Transaction::Checkout performing checkout...");
46 my $shelf = $self->{item}->hold_attached;
47 my $barcode = $self->{item}->id;
48 my $patron = Koha::Patrons->find($self->{patron}->{borrowernumber});
49 my $overridden_duedate; # usually passed as undef to AddIssue
50 my $prevcheckout_block_checkout = $account->{prevcheckout_block_checkout};
51 my ($issuingimpossible, $needsconfirmation) = _can_we_issue($patron, $barcode, 0);
53 my $noerror=1; # If set to zero we block the issue
54 if (keys %{$issuingimpossible}) {
55 foreach (keys %{$issuingimpossible}) {
56 # do something here so we pass these errors
57 $self->screen_msg("Issue failed : $_");
62 foreach my $confirmation (keys %{$needsconfirmation}) {
63 if ($confirmation eq 'RENEW_ISSUE'){
64 $self->screen_msg("Item already checked out to you: renewing item.");
65 } elsif ($confirmation eq 'RESERVED' and !C4::Context->preference("AllowItemsOnHoldCheckoutSIP")) {
66 $self->screen_msg("Item is reserved for another patron upon return.");
68 } elsif ($confirmation eq 'RESERVED' and C4::Context->preference("AllowItemsOnHoldCheckoutSIP")) {
70 } elsif ($confirmation eq 'RESERVE_WAITING'
71 or $confirmation eq 'TRANSFERRED'
72 or $confirmation eq 'PROCESSING') {
73 $self->screen_msg("Item is on hold for another patron.");
75 } elsif ($confirmation eq 'ISSUED_TO_ANOTHER') {
76 $self->screen_msg("Item already checked out to another patron. Please return item for check-in.");
79 } elsif ($confirmation eq 'DEBT') {
80 $self->screen_msg('Outstanding Fines block issue');
83 } elsif ($confirmation eq 'HIGHHOLDS') {
84 $overridden_duedate = $needsconfirmation->{$confirmation}->{returndate};
85 $self->screen_msg('Loan period reduced for high-demand item');
86 } elsif ($confirmation eq 'RENTALCHARGE') {
87 if ($self->{fee_ack} ne 'Y') {
91 } elsif ($confirmation eq 'PREVISSUE') {
92 $self->screen_msg("This item was previously checked out by you");
93 $noerror = 0 if ($prevcheckout_block_checkout);
95 } elsif ( $confirmation eq 'ADDITIONAL_MATERIALS' ) {
96 $self->screen_msg('Item must be checked out at a circulation desk');
100 # We've been returned a case other than those above
101 $self->screen_msg("Item cannot be issued: $confirmation");
103 siplog('LOG_DEBUG', "Blocking checkout Reason:$confirmation");
108 my $itemnumber = $self->{item}->{itemnumber};
109 my ($fee, undef) = GetIssuingCharges($itemnumber, $patron->borrowernumber);
111 $self->{sip_fee_type} = '06';
112 $self->{fee_amount} = sprintf '%.2f', $fee;
113 if ($self->{fee_ack} eq 'N' ) {
122 my $issue = AddIssue( $patron->unblessed, $barcode, $overridden_duedate, 0 );
123 $self->{due} = $self->duedatefromissue($issue, $itemnumber);
130 my ( $patron, $barcode, $pref ) = @_;
132 my ( $issuingimpossible, $needsconfirmation, $alerts ) =
133 CanBookBeIssued( $patron, $barcode, undef, 0, $pref );
134 for my $href ( $issuingimpossible, $needsconfirmation ) {
136 # some data is returned using lc keys we only
137 foreach my $key ( keys %{$href} ) {
138 if ( $key =~ m/[^A-Z_]/ ) {
139 delete $href->{$key};
143 return ( $issuingimpossible, $needsconfirmation );