Bug 22037: (QA follow-up) Implement use of CHARGES_GUARANTEES
[koha-ffzg.git] / C4 / SIP / ILS / Patron.pm
index 23c5764..96ec74a 100644 (file)
@@ -22,9 +22,9 @@ use C4::Context;
 use C4::Koha;
 use C4::Members;
 use C4::Reserves;
-use C4::Items qw( GetBarcodeFromItemnumber GetItemnumbersForBiblio);
 use C4::Auth qw(checkpw);
 
+use Koha::Items;
 use Koha::Libraries;
 use Koha::Patrons;
 
@@ -65,8 +65,12 @@ sub new {
     $dob and $dob =~ s/-//g;    # YYYYMMDD
     my $dexpiry     = $kp->{dateexpiry};
     $dexpiry and $dexpiry =~ s/-//g;    # YYYYMMDD
-    my $fines_amount = $patron->account->balance;
+
+    my $fines_amount = $flags->{CHARGES}->{amount}; # This "amount" is the negative balance or the one of the guarantees
     $fines_amount = ($fines_amount and $fines_amount > 0) ? $fines_amount : 0;
+    my $guarantees_fines_amount = $flags->{CHARGES_GUARANTEES} ? $flags->{CHARGES_GUARANTEES}->{amount} : 0;
+    $fines_amount += $guarantees_fines_amount;
+
     my $fee_limit = _fee_limit();
     my $fine_blocked = $fines_amount > $fee_limit;
     my $circ_blocked =( C4::Context->preference('OverduesBlockCirc') ne "noblock" &&  defined $flags->{ODUES}->{itemlist} ) ? 1 : 0;
@@ -130,7 +134,14 @@ sub new {
 
     # FIXME: populate fine_items recall_items
     $ilspatron{unavail_holds} = _get_outstanding_holds($kp->{borrowernumber});
-    $ilspatron{items} = $patron->pending_checkouts->unblessed;
+
+    my $pending_checkouts = $patron->pending_checkouts;
+    my @barcodes;
+    while ( my $c = $pending_checkouts->next ) {
+        push @barcodes, { barcode => $c->item->barcode };
+    }
+    $ilspatron{items} = \@barcodes;
+
     $self = \%ilspatron;
     $debug and warn Dumper($self);
     syslog("LOG_DEBUG", "new ILS::Patron(%s): found patron '%s'", $patron_id,$self->{id});
@@ -241,7 +252,7 @@ sub fee_amount {
     if ( $self->{fines} ) {
         return $self->{fines};
     }
-    return;
+    return 0;
 }
 
 sub fines_amount {
@@ -315,7 +326,8 @@ sub hold_items {
     my $self = shift;
     my $item_arr = $self->x_items('hold_items', @_);
     foreach my $item (@{$item_arr}) {
-        $item->{barcode} = GetBarcodeFromItemnumber($item->{itemnumber});
+        my $item_obj = Koha::Items->find($item->{itemnumber});
+        $item->{barcode} = $item_obj ? $item_obj->barcode : undef;
     }
     return $item_arr;
 }
@@ -483,15 +495,18 @@ sub _get_outstanding_holds {
     while ( my $hold = $holds->next ) {
         my $item;
         if ($hold->itemnumber) {
-            $item = $hold->itemnumber;
+            $item = $hold->item;
         }
         else {
             # We need to return a barcode for the biblio so the client
             # can request the biblio info
-            $item = ( GetItemnumbersForBiblio($hold->biblionumber) )->[0];
+            my $items = $hold->biblio->items;
+            $item = $items->count ? $items->next : undef;
         }
         my $unblessed_hold = $hold->unblessed;
-        $unblessed_hold->{barcode} = GetBarcodeFromItemnumber($item);
+
+        $unblessed_hold->{barcode} = $item ? $item->barcode : undef;
+
         push @holds, $unblessed_hold;
     }
     return \@holds;
@@ -616,7 +631,6 @@ __END__
 | contactname         | mediumtext   | YES  |     | NULL    |                |
 | contactfirstname    | text         | YES  |     | NULL    |                |
 | contacttitle        | text         | YES  |     | NULL    |                |
-| guarantorid         | int(11)      | YES  | MUL | NULL    |                |
 | borrowernotes       | mediumtext   | YES  |     | NULL    |                |
 | relationship        | varchar(100) | YES  |     | NULL    |                |
 | ethnicity           | varchar(50)  | YES  |     | NULL    |                |