Bug 19134: C4::SMS falils on long driver name
[srvgit] / C4 / Reserves.pm
index 537d061..5098230 100644 (file)
@@ -36,6 +36,7 @@ use C4::Members qw();
 use C4::Letters;
 use C4::Log;
 
+use Koha::Biblios;
 use Koha::DateUtils;
 use Koha::Calendar;
 use Koha::Database;
@@ -43,6 +44,7 @@ use Koha::Hold;
 use Koha::Old::Hold;
 use Koha::Holds;
 use Koha::Libraries;
+use Koha::IssuingRules;
 use Koha::Items;
 use Koha::ItemTypes;
 use Koha::Patrons;
@@ -103,9 +105,6 @@ BEGIN {
         &AddReserve
 
         &GetReserve
-        &GetReservesFromItemnumber
-        &GetReservesFromBiblionumber
-        &GetReservesFromBorrowernumber
         &GetReservesForBranch
         &GetReservesToBranch
         &GetReserveCount
@@ -164,6 +163,7 @@ The following tables are available witin the HOLDPLACED message:
     biblio
     biblioitems
     items
+    reserves
 
 =cut
 
@@ -174,8 +174,6 @@ sub AddReserve {
         $title,    $checkitem,      $found,        $itemtype
     ) = @_;
 
-    my $dbh = C4::Context->dbh;
-
     $resdate = output_pref( { str => dt_from_string( $resdate ), dateonly => 1, dateformat => 'iso' })
         or output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' });
 
@@ -220,29 +218,33 @@ sub AddReserve {
     my $reserve_id = $hold->id();
 
     # add a reserve fee if needed
-    my $fee = GetReserveFee( $borrowernumber, $biblionumber );
-    ChargeReserveFee( $borrowernumber, $fee, $title );
+    if ( C4::Context->preference('HoldFeeMode') ne 'any_time_is_collected' ) {
+        my $reserve_fee = GetReserveFee( $borrowernumber, $biblionumber );
+        ChargeReserveFee( $borrowernumber, $reserve_fee, $title );
+    }
 
     _FixPriority({ biblionumber => $biblionumber});
 
     # Send e-mail to librarian if syspref is active
     if(C4::Context->preference("emailLibrarianWhenHoldIsPlaced")){
-        my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
-        my $library = Koha::Libraries->find($borrower->{branchcode})->unblessed;
+        my $patron = Koha::Patrons->find( $borrowernumber );
+        my $library = $patron->library;
         if ( my $letter =  C4::Letters::GetPreparedLetter (
             module => 'reserves',
             letter_code => 'HOLDPLACED',
             branchcode => $branch,
+            lang => $patron->lang,
             tables => {
-                'branches'    => $library,
-                'borrowers'   => $borrower,
+                'branches'    => $library->unblessed,
+                'borrowers'   => $patron->unblessed,
                 'biblio'      => $biblionumber,
                 'biblioitems' => $biblionumber,
                 'items'       => $checkitem,
+                'reserves'    => $hold->unblessed,
             },
         ) ) {
 
-            my $admin_email_address = $library->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress');
+            my $admin_email_address = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress');
 
             C4::Letters::EnqueueLetter(
                 {   letter                 => $letter,
@@ -277,146 +279,6 @@ sub GetReserve {
     return $sth->fetchrow_hashref();
 }
 
-=head2 GetReservesFromBiblionumber
-
-  my $reserves = GetReservesFromBiblionumber({
-    biblionumber => $biblionumber,
-    [ itemnumber => $itemnumber, ]
-    [ all_dates => 1|0 ]
-  });
-
-This function gets the list of reservations for one C<$biblionumber>,
-returning an arrayref pointing to the reserves for C<$biblionumber>.
-
-By default, only reserves whose start date falls before the current
-time are returned.  To return all reserves, including future ones,
-the C<all_dates> parameter can be included and set to a true value.
-
-If the C<itemnumber> parameter is supplied, reserves must be targeted
-to that item or not targeted to any item at all; otherwise, they
-are excluded from the list.
-
-=cut
-
-sub GetReservesFromBiblionumber {
-    my ( $params ) = @_;
-    my $biblionumber = $params->{biblionumber} or return [];
-    my $itemnumber = $params->{itemnumber};
-    my $all_dates = $params->{all_dates} // 0;
-    my $dbh   = C4::Context->dbh;
-
-    # Find the desired items in the reserves
-    my @params;
-    my $query = "
-        SELECT  reserve_id,
-                branchcode,
-                timestamp AS rtimestamp,
-                priority,
-                biblionumber,
-                borrowernumber,
-                reservedate,
-                found,
-                itemnumber,
-                reservenotes,
-                expirationdate,
-                lowestPriority,
-                suspend,
-                suspend_until,
-                itemtype
-        FROM     reserves
-        WHERE biblionumber = ? ";
-    push( @params, $biblionumber );
-    unless ( $all_dates ) {
-        $query .= " AND reservedate <= CAST(NOW() AS DATE) ";
-    }
-    if ( $itemnumber ) {
-        $query .= " AND ( itemnumber IS NULL OR itemnumber = ? )";
-        push( @params, $itemnumber );
-    }
-    $query .= "ORDER BY priority";
-    my $sth = $dbh->prepare($query);
-    $sth->execute( @params );
-    my @results;
-    while ( my $data = $sth->fetchrow_hashref ) {
-        push @results, $data;
-    }
-    return \@results;
-}
-
-=head2 GetReservesFromItemnumber
-
- ( $reservedate, $borrowernumber, $branchcode, $reserve_id, $waitingdate ) = GetReservesFromItemnumber($itemnumber);
-
-Get the first reserve for a specific item number (based on priority). Returns the abovementioned values for that reserve.
-
-The routine does not look at future reserves (read: item level holds), but DOES include future waits (a confirmed future hold).
-
-=cut
-
-sub GetReservesFromItemnumber {
-    my ($itemnumber) = @_;
-
-    my $schema = Koha::Database->new()->schema();
-
-    my $r = $schema->resultset('Reserve')->search(
-        {
-            itemnumber => $itemnumber,
-            suspend    => 0,
-            -or        => [
-                reservedate => \'<= CAST( NOW() AS DATE )',
-                waitingdate => { '!=', undef }
-            ]
-        },
-        {
-            order_by => 'priority',
-        }
-    )->first();
-
-    return unless $r;
-
-    return (
-        $r->reservedate(),
-        $r->get_column('borrowernumber'),
-        $r->get_column('branchcode'),
-        $r->reserve_id(),
-        $r->waitingdate(),
-    );
-}
-
-=head2 GetReservesFromBorrowernumber
-
-    $borrowerreserv = GetReservesFromBorrowernumber($borrowernumber,$tatus);
-
-TODO :: Descritpion
-
-=cut
-
-sub GetReservesFromBorrowernumber {
-    my ( $borrowernumber, $status ) = @_;
-    my $dbh   = C4::Context->dbh;
-    my $sth;
-    if ($status) {
-        $sth = $dbh->prepare("
-            SELECT *
-            FROM   reserves
-            WHERE  borrowernumber=?
-                AND found =?
-            ORDER BY reservedate
-        ");
-        $sth->execute($borrowernumber,$status);
-    } else {
-        $sth = $dbh->prepare("
-            SELECT *
-            FROM   reserves
-            WHERE  borrowernumber=?
-            ORDER BY reservedate
-        ");
-        $sth->execute($borrowernumber);
-    }
-    my $data = $sth->fetchall_arrayref({});
-    return @$data;
-}
-
 =head2 CanBookBeReserved
 
   $canReserve = &CanBookBeReserved($borrowernumber, $biblionumber)
@@ -469,8 +331,9 @@ sub CanItemBeReserved {
     # we retrieve borrowers and items informations #
     # item->{itype} will come for biblioitems if necessery
     my $item       = GetItem($itemnumber);
-    my $biblioData = C4::Biblio::GetBiblioData( $item->{biblionumber} );
-    my $borrower   = C4::Members::GetMember( 'borrowernumber' => $borrowernumber );
+    my $biblio     = Koha::Biblios->find( $item->{biblionumber} );
+    my $patron = Koha::Patrons->find( $borrowernumber );
+    my $borrower = $patron->unblessed;
 
     # If an item is damaged and we don't allow holds on damaged items, we can stop right here
     return 'damaged'
@@ -479,7 +342,7 @@ sub CanItemBeReserved {
 
     # Check for the age restriction
     my ( $ageRestriction, $daysToAgeRestriction ) =
-      C4::Circulation::GetAgeRestriction( $biblioData->{agerestriction}, $borrower );
+      C4::Circulation::GetAgeRestriction( $biblio->biblioitem->agerestriction, $borrower );
     return 'ageRestricted' if $daysToAgeRestriction && $daysToAgeRestriction > 0;
 
     # Check that the patron doesn't have an item level hold on this item already
@@ -519,7 +382,7 @@ sub CanItemBeReserved {
         $ruleitemtype = '*';
     }
 
-    my $item = Koha::Items->find( $itemnumber );
+    $item = Koha::Items->find( $itemnumber );
     my $holds = Koha::Holds->search(
         {
             borrowernumber => $borrowernumber,
@@ -582,7 +445,7 @@ sub CanItemBeReserved {
     if ( C4::Context->preference('IndependentBranches')
         and !C4::Context->preference('canreservefromotherbranches') )
     {
-        my $itembranch = $item->{homebranch};
+        my $itembranch = $item->homebranch;
         if ( $itembranch ne $borrower->{branchcode} ) {
             return 'cannotReserveFromOtherBranches';
         }
@@ -730,7 +593,7 @@ SELECT COUNT(*) FROM reserves WHERE biblionumber=? AND borrowernumber<>?
     my $dbh = C4::Context->dbh;
     my ( $fee ) = $dbh->selectrow_array( $borquery, undef, ($borrowernumber) );
     my $hold_fee_mode = C4::Context->preference('HoldFeeMode') || 'not_always';
-    if( $fee and $fee > 0 and $hold_fee_mode ne 'always' ) {
+    if( $fee and $fee > 0 and $hold_fee_mode eq 'not_always' ) {
         # This is a reconstruction of the old code:
         # Compare number of items with items issued, and optionally check holds
         # If not all items are issued and there are no holds: charge no fee
@@ -785,7 +648,7 @@ sub GetReservesForBranch {
     my $dbh = C4::Context->dbh;
 
     my $query = "
-        SELECT reserve_id,borrowernumber,reservedate,itemnumber,waitingdate
+        SELECT reserve_id,borrowernumber,reservedate,itemnumber,waitingdate, expirationdate
         FROM   reserves
         WHERE   priority='0'
         AND found='W'
@@ -946,12 +809,12 @@ sub CheckReserves {
             if ( $res->{'itemnumber'} == $itemnumber && $res->{'priority'} == 0) {
                 return ( "Waiting", $res, \@reserves ); # Found it
             } else {
-                my $borrowerinfo;
+                my $patron;
                 my $iteminfo;
                 my $local_hold_match;
 
                 if ($LocalHoldsPriority) {
-                    $borrowerinfo = C4::Members::GetMember( borrowernumber => $res->{'borrowernumber'} );
+                    $patron = Koha::Patrons->find( $res->{borrowernumber} );
                     $iteminfo = C4::Items::GetItem($itemnumber);
 
                     my $local_holds_priority_item_branchcode =
@@ -960,7 +823,7 @@ sub CheckReserves {
                       ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
                       ? $res->{branchcode}
                       : ( $LocalHoldsPriorityPatronControl eq 'HomeLibrary' )
-                      ? $borrowerinfo->{branchcode}
+                      ? $patron->branchcode
                       : undef;
                     $local_hold_match =
                       $local_holds_priority_item_branchcode eq
@@ -971,11 +834,11 @@ sub CheckReserves {
                 if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
                     $iteminfo ||= C4::Items::GetItem($itemnumber);
                     next if $res->{itemtype} && $res->{itemtype} ne _get_itype( $iteminfo );
-                    $borrowerinfo ||= C4::Members::GetMember( borrowernumber => $res->{'borrowernumber'} );
-                    my $branch = GetReservesControlBranch( $iteminfo, $borrowerinfo );
+                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
+                    my $branch = GetReservesControlBranch( $iteminfo, $patron->unblessed );
                     my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
                     next if ($branchitemrule->{'holdallowed'} == 0);
-                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $borrowerinfo->{'branchcode'}));
+                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
                     next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $iteminfo->{ $branchitemrule->{hold_fulfillment_policy} }) );
                     $priority = $res->{'priority'};
                     $highest  = $res;
@@ -1005,47 +868,28 @@ Cancels all reserves with an expiration date from before today.
 
 sub CancelExpiredReserves {
 
-    # Cancel reserves that have passed their expiration date.
+    my $today = dt_from_string();
+    my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays');
+
     my $dbh = C4::Context->dbh;
     my $sth = $dbh->prepare( "
         SELECT * FROM reserves WHERE DATE(expirationdate) < DATE( CURDATE() )
         AND expirationdate IS NOT NULL
-        AND found IS NULL
     " );
     $sth->execute();
 
     while ( my $res = $sth->fetchrow_hashref() ) {
-        CancelReserve({ reserve_id => $res->{'reserve_id'} });
-    }
-
-    # Cancel reserves that have been waiting too long
-    if ( C4::Context->preference("ExpireReservesMaxPickUpDelay") ) {
-        my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay");
-        my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays');
+        my $calendar = Koha::Calendar->new( branchcode => $res->{'branchcode'} );
+        my $cancel_params = { reserve_id => $res->{'reserve_id'} };
 
-        my $today = dt_from_string();
+        next if !$cancel_on_holidays && $calendar->is_holiday( $today );
 
-        my $query = "SELECT * FROM reserves WHERE TO_DAYS( NOW() ) - TO_DAYS( waitingdate ) > ? AND found = 'W' AND priority = 0";
-        $sth = $dbh->prepare( $query );
-        $sth->execute( $max_pickup_delay );
-
-        while ( my $res = $sth->fetchrow_hashref ) {
-            my $do_cancel = 1;
-            unless ( $cancel_on_holidays ) {
-                my $calendar = Koha::Calendar->new( branchcode => $res->{'branchcode'} );
-                my $is_holiday = $calendar->is_holiday( $today );
-
-                if ( $is_holiday ) {
-                    $do_cancel = 0;
-                }
-            }
-
-            if ( $do_cancel ) {
-                CancelReserve({ reserve_id => $res->{'reserve_id'}, charge_cancel_fee => 1 });
-            }
+        if ( $res->{found} eq 'W' ) {
+            $cancel_params->{charge_cancel_fee} = 1;
         }
-    }
 
+        CancelReserve($cancel_params);
+    }
 }
 
 =head2 AutoUnsuspendReserves
@@ -1181,7 +1025,6 @@ sub ModReserve {
     return unless ( $reserve_id || ( $borrowernumber && ( $biblionumber || $itemnumber ) ) );
     $reserve_id = GetReserveId({ biblionumber => $biblionumber, borrowernumber => $borrowernumber, itemnumber => $itemnumber }) unless ( $reserve_id );
 
-    my $dbh = C4::Context->dbh;
     if ( $rank eq "del" ) {
         CancelReserve({ reserve_id => $reserve_id });
     }
@@ -1231,8 +1074,6 @@ sub ModReserveFill {
     my ($res) = @_;
     my $reserve_id = $res->{'reserve_id'};
 
-    my $dbh = C4::Context->dbh;
-
     my $hold = Koha::Holds->find($reserve_id);
 
     # get the priority on this record....
@@ -1246,10 +1087,15 @@ sub ModReserveFill {
         }
     );
 
-    my $old_hold = Koha::Old::Hold->new( $hold->unblessed() )->store();
+    Koha::Old::Hold->new( $hold->unblessed() )->store();
 
     $hold->delete();
 
+    if ( C4::Context->preference('HoldFeeMode') eq 'any_time_is_collected' ) {
+        my $reserve_fee = GetReserveFee( $hold->borrowernumber, $hold->biblionumber );
+        ChargeReserveFee( $hold->borrowernumber, $reserve_fee, $hold->biblio->title );
+    }
+
     # now fix the priority on the others (if the priority wasn't
     # already sorted!)....
     unless ( $priority == 0 ) {
@@ -1286,12 +1132,12 @@ sub ModReserveStatus {
 
 =head2 ModReserveAffect
 
-  &ModReserveAffect($itemnumber,$borrowernumber,$diffBranchSend);
+  &ModReserveAffect($itemnumber,$borrowernumber,$diffBranchSend,$reserve_id);
 
-This function affect an item and a status for a given reserve
-The itemnumber parameter is used to find the biblionumber.
-with the biblionumber & the borrowernumber, we can affect the itemnumber
-to the correct reserve.
+This function affect an item and a status for a given reserve, either fetched directly
+by record_id, or by borrowernumber and itemnumber or biblionumber. If only biblionumber
+is given, only first reserve returned is affected, which is ok for anything but
+multi-item holds.
 
 if $transferToDo is not set, then the status is set to "Waiting" as well.
 otherwise, a transfer is on the way, and the end of the transfer will
@@ -1322,35 +1168,12 @@ sub ModReserveAffect {
 
     return unless $hold;
 
-    $reserve_id = $hold->id();
-
     my $already_on_shelf = $hold->found && $hold->found eq 'W';
 
-    # If we affect a reserve that has to be transferred, don't set to Waiting
-    my $query;
-    if ($transferToDo) {
-        $hold->set(
-            {
-                priority   => 0,
-                itemnumber => $itemnumber,
-                found      => 'T',
-            }
-        );
-    }
-    else {
-        # affect the reserve to Waiting as well.
-        $hold->set(
-            {
-                priority    => 0,
-                itemnumber  => $itemnumber,
-                found       => 'W',
-                waitingdate => dt_from_string(),
-            }
-        );
-    }
-    $hold->store();
+    $hold->itemnumber($itemnumber);
+    $hold->set_waiting($transferToDo);
 
-    _koha_notify_reserve( $itemnumber, $borrowernumber, $biblionumber )
+    _koha_notify_reserve( $hold->reserve_id )
       if ( !$transferToDo && !$already_on_shelf );
 
     _FixPriority( { biblionumber => $biblionumber } );
@@ -1518,7 +1341,7 @@ sub IsAvailableForItemLevelRequest {
         foreach my $i (@items) {
             $any_available = 1
               unless $i->itemlost
-              || $i->{notforloan} > 0
+              || $i->notforloan > 0
               || $i->withdrawn
               || $i->onloan
               || IsItemOnHoldAndFound( $i->id )
@@ -1579,8 +1402,8 @@ sub _get_itype {
 sub _OnShelfHoldsAllowed {
     my ($itype,$borrowercategory,$branchcode) = @_;
 
-    my $rule = C4::Circulation::GetIssuingRule($borrowercategory, $itype, $branchcode);
-    return $rule->{onshelfholds};
+    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule({ categorycode => $borrowercategory, itemtype => $itype, branchcode => $branchcode });
+    return $issuing_rule ? $issuing_rule->onshelfholds : undef;
 }
 
 =head2 AlterPriority
@@ -1595,8 +1418,6 @@ Input: $where is 'up', 'down', 'top' or 'bottom'. Biblionumber, Date reserve was
 sub AlterPriority {
     my ( $where, $reserve_id ) = @_;
 
-    my $dbh = C4::Context->dbh;
-
     my $reserve = GetReserve( $reserve_id );
 
     if ( $reserve->{cancellationdate} ) {
@@ -1958,7 +1779,7 @@ sub _Findgroupreserve {
 
 =head2 _koha_notify_reserve
 
-  _koha_notify_reserve( $itemnumber, $borrowernumber, $biblionumber );
+  _koha_notify_reserve( $hold->reserve_id );
 
 Sends a notification to the patron that their hold has been filled (through
 ModReserveAffect, _not_ ModReserveFill)
@@ -1985,10 +1806,11 @@ The following tables are availalbe witin the notice:
 =cut
 
 sub _koha_notify_reserve {
-    my ($itemnumber, $borrowernumber, $biblionumber) = @_;
+    my $reserve_id = shift;
+    my $hold = Koha::Holds->find($reserve_id);
+    my $borrowernumber = $hold->borrowernumber;
 
-    my $dbh = C4::Context->dbh;
-    my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
+    my $patron = Koha::Patrons->find( $borrowernumber );
 
     # Try to get the borrower's email address
     my $to_address = C4::Members::GetNoticeEmailAddress($borrowernumber);
@@ -1998,30 +1820,22 @@ sub _koha_notify_reserve {
             message_name => 'Hold_Filled'
     } );
 
-    my $sth = $dbh->prepare("
-        SELECT *
-        FROM   reserves
-        WHERE  borrowernumber = ?
-            AND biblionumber = ?
-    ");
-    $sth->execute( $borrowernumber, $biblionumber );
-    my $reserve = $sth->fetchrow_hashref;
-    my $library = Koha::Libraries->find( $reserve->{branchcode} )->unblessed;
+    my $library = Koha::Libraries->find( $hold->branchcode )->unblessed;
 
     my $admin_email_address = $library->{branchemail} || C4::Context->preference('KohaAdminEmailAddress');
 
     my %letter_params = (
         module => 'reserves',
-        branchcode => $reserve->{branchcode},
+        branchcode => $hold->branchcode,
+        lang => $patron->lang,
         tables => {
             'branches'       => $library,
-            'borrowers'      => $borrower,
-            'biblio'         => $biblionumber,
-            'biblioitems'    => $biblionumber,
-            'reserves'       => $reserve,
-            'items'          => $reserve->{'itemnumber'},
+            'borrowers'      => $patron->unblessed,
+            'biblio'         => $hold->biblionumber,
+            'biblioitems'    => $hold->biblionumber,
+            'reserves'       => $hold->unblessed,
+            'items'          => $hold->itemnumber,
         },
-        substitute => { today => output_pref( { dt => dt_from_string, dateonly => 1 } ) },
     );
 
     my $notification_sent = 0; #Keeping track if a Hold_filled message is sent. If no message can be sent, then default to a print message.
@@ -2047,7 +1861,7 @@ sub _koha_notify_reserve {
     while ( my ( $mtt, $letter_code ) = each %{ $messagingprefs->{transports} } ) {
         next if (
                ( $mtt eq 'email' and not $to_address ) # No email address
-            or ( $mtt eq 'sms'   and not $borrower->{smsalertnumber} ) # No SMS number
+            or ( $mtt eq 'sms'   and not $patron->smsalertnumber ) # No SMS number
             or ( $mtt eq 'phone' and C4::Context->preference('TalkingTechItivaPhoneNotification') ) # Notice is handled by TalkingTech_itiva_outbound.pl
         );
 
@@ -2175,7 +1989,6 @@ sub MoveReserve {
     return unless $res;
 
     my $biblionumber     =  $res->{biblionumber};
-    my $biblioitemnumber = $res->{biblioitemnumber};
 
     if ($res->{borrowernumber} == $borrowernumber) {
         ModReserveFill($res);
@@ -2332,6 +2145,8 @@ sub GetReserveId {
 
     my $hold = Koha::Holds->search( $params )->next();
 
+    return unless $hold;
+
     return $hold->id();
 }
 
@@ -2357,6 +2172,7 @@ sub ReserveSlip {
     my ($branch, $borrowernumber, $biblionumber) = @_;
 
 #   return unless ( C4::Context->boolean_preference('printreserveslips') );
+    my $patron = Koha::Patrons->find( $borrowernumber );
 
     my $reserve_id = GetReserveId({
         biblionumber => $biblionumber,
@@ -2368,6 +2184,7 @@ sub ReserveSlip {
         module => 'circulation',
         letter_code => 'HOLD_SLIP',
         branchcode => $branch,
+        lang => $patron->lang,
         tables => {
             'reserves'    => $reserve,
             'branches'    => $reserve->{branchcode},