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;
18 use C4::Circulation qw( AddIssue GetIssuingCharges CanBookBeIssued );
20 use Koha::DateUtils qw( dt_from_string );
22 use parent qw(C4::SIP::ILS::Transaction);
24 # Most fields are handled by the Transaction superclass
26 security_inhibit => 0,
33 my $self = $class->SUPER::new();
34 foreach my $element (keys %fields) {
35 $self->{_permitted}->{$element} = $fields{$element};
37 @{$self}{keys %fields} = values %fields;
38 return bless $self, $class;
44 my $no_block_due_date = shift;
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 if ( $no_block_due_date ) {
54 my $year = substr($no_block_due_date,0,4);
55 my $month = substr($no_block_due_date,4,2);
56 my $day = substr($no_block_due_date,6,2);
57 my $hour = substr($no_block_due_date,12,2);
58 my $minute = substr($no_block_due_date,14,2);
59 my $second = substr($no_block_due_date,16,2);
61 my $iso = "$year-$month-$day $hour:$minute:$second";
62 $no_block_due_date = dt_from_string( $iso, "iso" );
65 my $noerror=1; # If set to zero we block the issue
66 if (keys %{$issuingimpossible}) {
67 foreach (keys %{$issuingimpossible}) {
68 # do something here so we pass these errors
69 $self->screen_msg("Issue failed : $_");
74 foreach my $confirmation (keys %{$needsconfirmation}) {
75 if ($confirmation eq 'RENEW_ISSUE'){
76 $self->screen_msg("Item already checked out to you: renewing item.");
77 } elsif ($confirmation eq 'RESERVED' and !C4::Context->preference("AllowItemsOnHoldCheckoutSIP")) {
78 $self->screen_msg("Item is reserved for another patron upon return.");
80 } elsif ($confirmation eq 'RESERVED' and C4::Context->preference("AllowItemsOnHoldCheckoutSIP")) {
82 } elsif ($confirmation eq 'RESERVE_WAITING'
83 or $confirmation eq 'TRANSFERRED'
84 or $confirmation eq 'PROCESSING') {
85 $self->screen_msg("Item is on hold for another patron.");
87 } elsif ($confirmation eq 'ISSUED_TO_ANOTHER') {
88 $self->screen_msg("Item already checked out to another patron. Please return item for check-in.");
91 } elsif ($confirmation eq 'DEBT') {
92 $self->screen_msg('Outstanding Fines block issue');
95 } elsif ($confirmation eq 'HIGHHOLDS') {
96 $overridden_duedate = $needsconfirmation->{$confirmation}->{returndate};
97 $self->screen_msg('Loan period reduced for high-demand item');
98 } elsif ($confirmation eq 'RENTALCHARGE') {
99 if ($self->{fee_ack} ne 'Y') {
103 } elsif ($confirmation eq 'PREVISSUE') {
104 $self->screen_msg("This item was previously checked out by you");
105 $noerror = 0 if ($prevcheckout_block_checkout);
107 } elsif ( $confirmation eq 'ADDITIONAL_MATERIALS' ) {
108 $self->screen_msg('Item must be checked out at a circulation desk');
112 # We've been returned a case other than those above
113 $self->screen_msg("Item cannot be issued: $confirmation");
115 siplog('LOG_DEBUG', "Blocking checkout Reason:$confirmation");
120 my $itemnumber = $self->{item}->{itemnumber};
121 my ($fee, undef) = GetIssuingCharges($itemnumber, $patron->borrowernumber);
123 $self->{sip_fee_type} = '06';
124 $self->{fee_amount} = sprintf '%.2f', $fee;
125 if ($self->{fee_ack} eq 'N' ) {
130 if ( $no_block_due_date ) {
131 $overridden_duedate = $no_block_due_date;
141 my $issue = AddIssue( $patron->unblessed, $barcode, $overridden_duedate, 0 );
142 $self->{due} = $self->duedatefromissue($issue, $itemnumber);
149 my ( $patron, $barcode, $pref ) = @_;
151 my ( $issuingimpossible, $needsconfirmation, $alerts ) =
152 CanBookBeIssued( $patron, $barcode, undef, 0, $pref );
153 for my $href ( $issuingimpossible, $needsconfirmation ) {
155 # some data is returned using lc keys we only
156 foreach my $key ( keys %{$href} ) {
157 if ( $key =~ m/[^A-Z_]/ ) {
158 delete $href->{$key};
162 return ( $issuingimpossible, $needsconfirmation );