Lines 177-183
sub patronflags {
Link Here
|
177 |
my %flags; |
177 |
my %flags; |
178 |
my ( $patroninformation) = @_; |
178 |
my ( $patroninformation) = @_; |
179 |
my $dbh=C4::Context->dbh; |
179 |
my $dbh=C4::Context->dbh; |
180 |
my ($balance, $owing) = GetMemberAccountBalance( $patroninformation->{'borrowernumber'}); |
180 |
my $patron = Koha::Patrons->find( $patroninformation->{borrowernumber} ); |
|
|
181 |
my $account = $patron->account; |
182 |
my $owing = $account->non_issues_charges; |
181 |
if ( $owing > 0 ) { |
183 |
if ( $owing > 0 ) { |
182 |
my %flaginfo; |
184 |
my %flaginfo; |
183 |
my $noissuescharge = C4::Context->preference("noissuescharge") || 5; |
185 |
my $noissuescharge = C4::Context->preference("noissuescharge") || 5; |
Lines 188-194
sub patronflags {
Link Here
|
188 |
} |
190 |
} |
189 |
$flags{'CHARGES'} = \%flaginfo; |
191 |
$flags{'CHARGES'} = \%flaginfo; |
190 |
} |
192 |
} |
191 |
elsif ( $balance < 0 ) { |
193 |
elsif ( ( my $balance = $account->balance ) < 0 ) { |
192 |
my %flaginfo; |
194 |
my %flaginfo; |
193 |
$flaginfo{'message'} = sprintf 'Patron has credit of %.02f', -$balance; |
195 |
$flaginfo{'message'} = sprintf 'Patron has credit of %.02f', -$balance; |
194 |
$flaginfo{'amount'} = sprintf "%.02f", $balance; |
196 |
$flaginfo{'amount'} = sprintf "%.02f", $balance; |
Lines 203-210
sub patronflags {
Link Here
|
203 |
my @guarantees = $p->guarantees(); |
205 |
my @guarantees = $p->guarantees(); |
204 |
my $guarantees_non_issues_charges; |
206 |
my $guarantees_non_issues_charges; |
205 |
foreach my $g ( @guarantees ) { |
207 |
foreach my $g ( @guarantees ) { |
206 |
my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id ); |
208 |
$guarantees_non_issues_charges += $g->account->non_issues_charges; |
207 |
$guarantees_non_issues_charges += $n; |
|
|
208 |
} |
209 |
} |
209 |
|
210 |
|
210 |
if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees ) { |
211 |
if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees ) { |
Lines 261-267
sub patronflags {
Link Here
|
261 |
$flags{'ODUES'} = \%flaginfo; |
262 |
$flags{'ODUES'} = \%flaginfo; |
262 |
} |
263 |
} |
263 |
|
264 |
|
264 |
my $patron = Koha::Patrons->find( $patroninformation->{borrowernumber} ); |
|
|
265 |
my $waiting_holds = $patron->holds->search({ found => 'W' }); |
265 |
my $waiting_holds = $patron->holds->search({ found => 'W' }); |
266 |
my $nowaiting = $waiting_holds->count; |
266 |
my $nowaiting = $waiting_holds->count; |
267 |
if ( $nowaiting > 0 ) { |
267 |
if ( $nowaiting > 0 ) { |
Lines 735-780
sub GetAllIssues {
Link Here
|
735 |
return $sth->fetchall_arrayref( {} ); |
735 |
return $sth->fetchall_arrayref( {} ); |
736 |
} |
736 |
} |
737 |
|
737 |
|
738 |
|
|
|
739 |
=head2 GetMemberAccountBalance |
740 |
|
741 |
($total_balance, $non_issue_balance, $other_charges) = &GetMemberAccountBalance($borrowernumber); |
742 |
|
743 |
Calculates amount immediately owing by the patron - non-issue charges. |
744 |
Based on GetMemberAccountRecords. |
745 |
Charges exempt from non-issue are: |
746 |
* Res (reserves) |
747 |
* Rent (rental) if RentalsInNoissuesCharge syspref is set to false |
748 |
* Manual invoices if ManInvInNoissuesCharge syspref is set to false |
749 |
|
750 |
=cut |
751 |
|
752 |
sub GetMemberAccountBalance { |
753 |
my ($borrowernumber) = @_; |
754 |
|
755 |
# FIXME REMOVE And add a warning in the about page + update DB if length(MANUAL_INV) > 5 |
756 |
my $ACCOUNT_TYPE_LENGTH = 5; # this is plain ridiculous... |
757 |
|
758 |
my @not_fines; |
759 |
push @not_fines, 'Res' unless C4::Context->preference('HoldsInNoissuesCharge'); |
760 |
push @not_fines, 'Rent' unless C4::Context->preference('RentalsInNoissuesCharge'); |
761 |
unless ( C4::Context->preference('ManInvInNoissuesCharge') ) { |
762 |
my $dbh = C4::Context->dbh; |
763 |
push @not_fines, @{ $dbh->selectcol_arrayref(qq{SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'}) }; |
764 |
} |
765 |
@not_fines = map { substr($_, 0, $ACCOUNT_TYPE_LENGTH) } uniq (@not_fines); |
766 |
|
767 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
768 |
my $total = $patron->account->balance; |
769 |
my $other_charges = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, accounttype => { -in => \@not_fines } }, { |
770 |
select => [ { sum => 'amountoutstanding' } ], |
771 |
as => ['total_other_charges'], |
772 |
}); |
773 |
$other_charges = $other_charges->count ? $other_charges->next->get_column('total_other_charges') : 0; |
774 |
|
775 |
return ( $total, $total - $other_charges, $other_charges); |
776 |
} |
777 |
|
778 |
sub checkcardnumber { |
738 |
sub checkcardnumber { |
779 |
my ( $cardnumber, $borrowernumber ) = @_; |
739 |
my ( $cardnumber, $borrowernumber ) = @_; |
780 |
|
740 |
|