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