Lines 26-31
use C4::Context;
Link Here
|
26 |
use String::Random qw( random_string ); |
26 |
use String::Random qw( random_string ); |
27 |
use Scalar::Util qw( looks_like_number ); |
27 |
use Scalar::Util qw( looks_like_number ); |
28 |
use Date::Calc qw/Today check_date Date_to_Days/; |
28 |
use Date::Calc qw/Today check_date Date_to_Days/; |
|
|
29 |
use List::MoreUtils qw( uniq ); |
29 |
use C4::Log; # logaction |
30 |
use C4::Log; # logaction |
30 |
use C4::Overdues; |
31 |
use C4::Overdues; |
31 |
use C4::Reserves; |
32 |
use C4::Reserves; |
Lines 64-71
BEGIN {
Link Here
|
64 |
&GetPendingIssues |
65 |
&GetPendingIssues |
65 |
&GetAllIssues |
66 |
&GetAllIssues |
66 |
|
67 |
|
67 |
&GetMemberAccountRecords |
|
|
68 |
|
69 |
&GetBorrowersToExpunge |
68 |
&GetBorrowersToExpunge |
70 |
|
69 |
|
71 |
&IssueSlip |
70 |
&IssueSlip |
Lines 736-784
sub GetAllIssues {
Link Here
|
736 |
} |
735 |
} |
737 |
|
736 |
|
738 |
|
737 |
|
739 |
=head2 GetMemberAccountRecords |
|
|
740 |
|
741 |
($total, $acctlines, $count) = &GetMemberAccountRecords($borrowernumber); |
742 |
|
743 |
Looks up accounting data for the patron with the given borrowernumber. |
744 |
|
745 |
C<&GetMemberAccountRecords> returns a three-element array. C<$acctlines> is a |
746 |
reference-to-array, where each element is a reference-to-hash; the |
747 |
keys are the fields of the C<accountlines> table in the Koha database. |
748 |
C<$count> is the number of elements in C<$acctlines>. C<$total> is the |
749 |
total amount outstanding for all of the account lines. |
750 |
|
751 |
=cut |
752 |
|
753 |
sub GetMemberAccountRecords { |
754 |
my ($borrowernumber) = @_; |
755 |
my $dbh = C4::Context->dbh; |
756 |
my @acctlines; |
757 |
my $numlines = 0; |
758 |
my $strsth = qq( |
759 |
SELECT * |
760 |
FROM accountlines |
761 |
WHERE borrowernumber=?); |
762 |
$strsth.=" ORDER BY accountlines_id desc"; |
763 |
my $sth= $dbh->prepare( $strsth ); |
764 |
$sth->execute( $borrowernumber ); |
765 |
|
766 |
my $total = 0; |
767 |
while ( my $data = $sth->fetchrow_hashref ) { |
768 |
if ( $data->{itemnumber} ) { |
769 |
my $item = Koha::Items->find( $data->{itemnumber} ); |
770 |
my $biblio = $item->biblio; |
771 |
$data->{biblionumber} = $biblio->biblionumber; |
772 |
$data->{title} = $biblio->title; |
773 |
} |
774 |
$acctlines[$numlines] = $data; |
775 |
$numlines++; |
776 |
$total += sprintf "%.0f", 1000*$data->{amountoutstanding}; # convert float to integer to avoid round-off errors |
777 |
} |
778 |
$total /= 1000; |
779 |
return ( $total, \@acctlines,$numlines); |
780 |
} |
781 |
|
782 |
=head2 GetMemberAccountBalance |
738 |
=head2 GetMemberAccountBalance |
783 |
|
739 |
|
784 |
($total_balance, $non_issue_balance, $other_charges) = &GetMemberAccountBalance($borrowernumber); |
740 |
($total_balance, $non_issue_balance, $other_charges) = &GetMemberAccountBalance($borrowernumber); |
Lines 795-800
Charges exempt from non-issue are:
Link Here
|
795 |
sub GetMemberAccountBalance { |
751 |
sub GetMemberAccountBalance { |
796 |
my ($borrowernumber) = @_; |
752 |
my ($borrowernumber) = @_; |
797 |
|
753 |
|
|
|
754 |
# FIXME REMOVE And add a warning in the about page + update DB if length(MANUAL_INV) > 5 |
798 |
my $ACCOUNT_TYPE_LENGTH = 5; # this is plain ridiculous... |
755 |
my $ACCOUNT_TYPE_LENGTH = 5; # this is plain ridiculous... |
799 |
|
756 |
|
800 |
my @not_fines; |
757 |
my @not_fines; |
Lines 802-817
sub GetMemberAccountBalance {
Link Here
|
802 |
push @not_fines, 'Rent' unless C4::Context->preference('RentalsInNoissuesCharge'); |
759 |
push @not_fines, 'Rent' unless C4::Context->preference('RentalsInNoissuesCharge'); |
803 |
unless ( C4::Context->preference('ManInvInNoissuesCharge') ) { |
760 |
unless ( C4::Context->preference('ManInvInNoissuesCharge') ) { |
804 |
my $dbh = C4::Context->dbh; |
761 |
my $dbh = C4::Context->dbh; |
805 |
my $man_inv_types = $dbh->selectcol_arrayref(qq{SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'}); |
762 |
push @not_fines, @{ $dbh->selectcol_arrayref(qq{SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'}) }; |
806 |
push @not_fines, map substr($_, 0, $ACCOUNT_TYPE_LENGTH), @$man_inv_types; |
|
|
807 |
} |
763 |
} |
808 |
my %not_fine = map {$_ => 1} @not_fines; |
764 |
@not_fines = map { substr($_, 0, $ACCOUNT_TYPE_LENGTH) } uniq (@not_fines); |
809 |
|
765 |
|
810 |
my ($total, $acctlines) = GetMemberAccountRecords($borrowernumber); |
766 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
811 |
my $other_charges = 0; |
767 |
my $total = $patron->account->balance; |
812 |
foreach (@$acctlines) { |
768 |
my $other_charges = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, accounttype => { -in => \@not_fines } }, { |
813 |
$other_charges += $_->{amountoutstanding} if $not_fine{ substr($_->{accounttype}, 0, $ACCOUNT_TYPE_LENGTH) }; |
769 |
select => [ { sum => 'amountoutstanding' } ], |
814 |
} |
770 |
as => ['total_other_charges'], |
|
|
771 |
}); |
772 |
$other_charges = $other_charges->count ? $other_charges->next->get_column('total_other_charges') : 0; |
815 |
|
773 |
|
816 |
return ( $total, $total - $other_charges, $other_charges); |
774 |
return ( $total, $total - $other_charges, $other_charges); |
817 |
} |
775 |
} |