+my $holds = Koha::Holds->search( { borrowernumber => $borrowernumber } ); # FIXME must be Koha::Patron->holds
+my $waiting_holds = $holds->waiting;
+$template->param(
+ holds_count => $holds->count(),
+ WaitingHolds => $waiting_holds,
+);
+
+if ( C4::Context->preference('UseRecalls') ) {
+ my $waiting_recalls = $patron->recalls->search({ status => 'waiting' });
+ $template->param( waiting_recalls => $waiting_recalls );
+}
+
+my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
+$no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
+if ( defined $no_issues_charge_guarantees ) {
+ my $guarantees_non_issues_charges = 0;
+ my $guarantees = $patron->guarantee_relationships->guarantees;
+ while ( my $g = $guarantees->next ) {
+ $guarantees_non_issues_charges += $g->account->non_issues_charges;
+ }
+ if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees ) {
+ $template->param(
+ charges_guarantees => 1,
+ chargesamount_guarantees => $guarantees_non_issues_charges,
+ );
+ }
+}
+
+if ( $patron->has_overdues ) {
+ $template->param( odues => 1 );
+}
+my $issues = $patron->checkouts;
+
+my $balance = 0;
+$balance = $patron->account->balance;
+
+my $account = $patron->account;
+if( ( my $owing = $account->non_issues_charges ) > 0 ) {
+ my $noissuescharge = C4::Context->preference("noissuescharge") || 5; # FIXME If noissuescharge == 0 then 5, why??
+ $template->param(
+ charges => 1,
+ chargesamount => $owing,
+ )
+} elsif ( $balance < 0 ) {
+ $template->param(
+ credits => 1,
+ creditsamount => -$balance,
+ );
+}
+
+# if the expiry date is before today ie they have expired
+if ( $patron->is_expired ) {
+ #borrowercard expired, no issues
+ $template->param(
+ expired => "1",
+ );
+}
+# check for NotifyBorrowerDeparture
+elsif ( $patron->is_going_to_expire ) {
+ # borrower card soon to expire warn librarian
+ $template->param( "warndeparture" => $patron->dateexpiry ,
+ );
+ if (C4::Context->preference('ReturnBeforeExpiry')){
+ $template->param("returnbeforeexpiry" => 1);
+ }
+}
+
+
+my $has_modifications = Koha::Patron::Modifications->search( { borrowernumber => $borrowernumber } )->count;
+