View | Details | Raw Unified | Return to bug 12001
Collapse All | Expand All

(-)a/C4/Circulation.pm (-1 / +1 lines)
Lines 2727-2733 sub CanBookBeRenewed { Link Here
2727
2727
2728
        if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) {
2728
        if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) {
2729
            my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals");
2729
            my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals");
2730
            my ( $amountoutstanding ) = C4::Members::GetMemberAccountRecords($patron->borrowernumber);
2730
            my $amountoutstanding = $patron->account->balance;
2731
            if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
2731
            if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
2732
                return ( 0, "auto_too_much_oweing" );
2732
                return ( 0, "auto_too_much_oweing" );
2733
            }
2733
            }
(-)a/C4/Members.pm (-8 / +12 lines)
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 777-782 sub GetMemberAccountRecords { Link Here
777
        $total += sprintf "%.0f", 1000*$data->{amountoutstanding}; # convert float to integer to avoid round-off errors
778
        $total += sprintf "%.0f", 1000*$data->{amountoutstanding}; # convert float to integer to avoid round-off errors
778
    }
779
    }
779
    $total /= 1000;
780
    $total /= 1000;
781
    $total = Koha::Account->new({patron_id => $borrowernumber})->balance;
780
    return ( $total, \@acctlines,$numlines);
782
    return ( $total, \@acctlines,$numlines);
781
}
783
}
782
784
Lines 796-801 Charges exempt from non-issue are: Link Here
796
sub GetMemberAccountBalance {
798
sub GetMemberAccountBalance {
797
    my ($borrowernumber) = @_;
799
    my ($borrowernumber) = @_;
798
800
801
    # FIXME REMOVE And add a warning in the about page + update DB if length(MANUAL_INV) > 5
799
    my $ACCOUNT_TYPE_LENGTH = 5; # this is plain ridiculous...
802
    my $ACCOUNT_TYPE_LENGTH = 5; # this is plain ridiculous...
800
803
801
    my @not_fines;
804
    my @not_fines;
Lines 803-818 sub GetMemberAccountBalance { Link Here
803
    push @not_fines, 'Rent' unless C4::Context->preference('RentalsInNoissuesCharge');
806
    push @not_fines, 'Rent' unless C4::Context->preference('RentalsInNoissuesCharge');
804
    unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
807
    unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
805
        my $dbh = C4::Context->dbh;
808
        my $dbh = C4::Context->dbh;
806
        my $man_inv_types = $dbh->selectcol_arrayref(qq{SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'});
809
        push @not_fines, @{ $dbh->selectcol_arrayref(qq{SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'}) };
807
        push @not_fines, map substr($_, 0, $ACCOUNT_TYPE_LENGTH), @$man_inv_types;
808
    }
810
    }
809
    my %not_fine = map {$_ => 1} @not_fines;
811
    @not_fines = map { substr($_, 0, $ACCOUNT_TYPE_LENGTH) } uniq (@not_fines);
810
812
811
    my ($total, $acctlines) = GetMemberAccountRecords($borrowernumber);
813
    my $patron = Koha::Patrons->find( $borrowernumber );
812
    my $other_charges = 0;
814
    my $total = $patron->account->balance;
813
    foreach (@$acctlines) {
815
    my $other_charges = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, accounttype => { -in => \@not_fines } }, {
814
        $other_charges += $_->{amountoutstanding} if $not_fine{ substr($_->{accounttype}, 0, $ACCOUNT_TYPE_LENGTH) };
816
            select => [ { sum => 'amountoutstanding' } ],
815
    }
817
            as => ['total_other_charges'],
818
        });
819
    $other_charges = $other_charges->count ? $other_charges->next->get_column('total_other_charges') : 0;
816
820
817
    return ( $total, $total - $other_charges, $other_charges);
821
    return ( $total, $total - $other_charges, $other_charges);
818
}
822
}
(-)a/C4/SIP/ILS/Patron.pm (-1 / +1 lines)
Lines 88-94 sub new { Link Here
88
        hold_ok         => ( !$debarred && !$expired && !$fine_blocked),
88
        hold_ok         => ( !$debarred && !$expired && !$fine_blocked),
89
        card_lost       => ( $kp->{lost} || $kp->{gonenoaddress} || $flags->{LOST} ),
89
        card_lost       => ( $kp->{lost} || $kp->{gonenoaddress} || $flags->{LOST} ),
90
        claims_returned => 0,
90
        claims_returned => 0,
91
        fines           => $fines_amount, # GetMemberAccountRecords($kp->{borrowernumber})
91
        fines           => $fines_amount,
92
        fees            => 0,             # currently not distinct from fines
92
        fees            => 0,             # currently not distinct from fines
93
        recall_overdue  => 0,
93
        recall_overdue  => 0,
94
        items_billed    => 0,
94
        items_billed    => 0,
(-)a/Koha/Account.pm (-1 / +2 lines)
Lines 279-285 sub balance { Link Here
279
            as => ['total_amountoutstanding'],
279
            as => ['total_amountoutstanding'],
280
        }
280
        }
281
    );
281
    );
282
    return $fines->count
282
283
    my $total = $fines->count
283
      ? $fines->next->get_column('total_amountoutstanding')
284
      ? $fines->next->get_column('total_amountoutstanding')
284
      : 0;
285
      : 0;
285
}
286
}
(-)a/Koha/Account/Line.pm (-1 / +14 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Carp;
20
use Carp;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Items;
23
24
24
use base qw(Koha::Object);
25
use base qw(Koha::Object);
25
26
Lines 33-39 Koha::Account::Lines - Koha accountline Object class Link Here
33
34
34
=cut
35
=cut
35
36
36
=head3 type
37
=head3 item
38
39
Return the item linked to this account line if exists
40
41
=cut
42
43
sub item {
44
    my ( $self ) = @_;
45
    my $rs = $self->_result->itemnumber;
46
    return Koha::Item->_new_from_dbic( $rs );
47
}
48
49
=head3 _type
37
50
38
=cut
51
=cut
39
52
(-)a/circ/circulation.pl (-1 / +1 lines)
Lines 543-549 foreach my $flag ( sort keys %$flags ) { Link Here
543
my $amountold = $flags ? $flags->{'CHARGES'}->{'message'} || 0 : 0;
543
my $amountold = $flags ? $flags->{'CHARGES'}->{'message'} || 0 : 0;
544
$amountold =~ s/^.*\$//;    # remove upto the $, if any
544
$amountold =~ s/^.*\$//;    # remove upto the $, if any
545
545
546
my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
546
my $total = $patron ? $patron->account->balance : 0;
547
547
548
if ( $patron && $patron->category->category_type eq 'C') {
548
if ( $patron && $patron->category->category_type eq 'C') {
549
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
549
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt (-1 / +1 lines)
Lines 108-114 $(document).ready(function() { Link Here
108
          [% CASE %][% account.accounttype %]
108
          [% CASE %][% account.accounttype %]
109
        [%- END -%]
109
        [%- END -%]
110
        [%- IF account.description %], [% account.description %][% END %]
110
        [%- IF account.description %], [% account.description %][% END %]
111
        &nbsp;[% IF ( account.itemnumber ) %]<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% account.biblionumber %]&amp;itemnumber=[% account.itemnumber %]">[% account.title |html %]</a>[% END %]</td>
111
        &nbsp;[% IF ( account.itemnumber ) %]<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% account.item.biblionumber %]&amp;itemnumber=[% account.itemnumber %]">[% account.item.biblio.title |html %]</a>[% END %]</td>
112
      <td>[% account.note | html_line_break %]</td>
112
      <td>[% account.note | html_line_break %]</td>
113
      [% IF ( account.amountcredit ) %]<td class="credit" style="text-align: right;">[% ELSE %]<td class="debit" style="text-align: right;">[% END %][% account.amount | $Price %]</td>
113
      [% IF ( account.amountcredit ) %]<td class="credit" style="text-align: right;">[% ELSE %]<td class="debit" style="text-align: right;">[% END %][% account.amount | $Price %]</td>
114
      [% IF ( account.amountoutstandingcredit ) %]<td class="credit" style="text-align: right;">[% ELSE %]<td class="debit" style="text-align: right;">[% END %][% account.amountoutstanding | $Price %]</td>
114
      [% IF ( account.amountoutstandingcredit ) %]<td class="credit" style="text-align: right;">[% ELSE %]<td class="debit" style="text-align: right;">[% END %][% account.amountoutstanding | $Price %]</td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-print.tt (-3 / +2 lines)
Lines 102-112 Link Here
102
            </tr>
102
            </tr>
103
103
104
            [% FOREACH account IN accounts %]
104
            [% FOREACH account IN accounts %]
105
                [% NEXT IF account.amountoutstanding == 0 %]
106
                <tr>
105
                <tr>
107
                    <td>
106
                    <td>
108
                        [% IF ( account.itemnumber ) %]<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% account.biblionumber %]&amp;itemnumber=[% account.itemnumber %]">[% END %]
107
                        [% IF ( account.itemnumber ) %]<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% account.item.biblionumber %]&amp;itemnumber=[% account.itemnumber %]">[% END %]
109
                        [% account.description %]&nbsp;[% IF ( account.printtitle ) %] [% account.title |html %][% END %]
108
                        [% account.description %]&nbsp;[% IF account.item AND account.accounttype != 'F' AND account.accounttype != 'FU' %] [% account.item.biblio.title |html %][% END %]
110
                        [% IF ( account.itemnumber ) %]</a>[% END %]
109
                        [% IF ( account.itemnumber ) %]</a>[% END %]
111
                    </td>
110
                    </td>
112
                    <td>[% account.date | $KohaDates %]</td>
111
                    <td>[% account.date | $KohaDates %]</td>
(-)a/members/boraccount.pl (-3 / +18 lines)
Lines 70-83 if ( $patron->category->category_type eq 'C') { Link Here
70
}
70
}
71
71
72
#get account details
72
#get account details
73
my ($total,$accts,undef)=GetMemberAccountRecords($borrowernumber);
73
my $total = $patron->account->balance;
74
75
my $accts = Koha::Account::Lines->search(
76
    { borrowernumber => $patron->borrowernumber },
77
    { order_by       => { -desc => 'accountlines_id' } }
78
);
79
74
my $totalcredit;
80
my $totalcredit;
75
if($total <= 0){
81
if($total <= 0){
76
        $totalcredit = 1;
82
        $totalcredit = 1;
77
}
83
}
78
84
79
my $reverse_col = 0; # Flag whether we need to show the reverse column
85
my $reverse_col = 0; # Flag whether we need to show the reverse column
80
foreach my $accountline ( @{$accts}) {
86
my @accountlines;
87
while ( my $line = $accts->next ) {
88
    # FIXME We should pass the $accts iterator to the template and do this formatting part there
89
    my $accountline = $line->unblessed;
81
    $accountline->{amount} += 0.00;
90
    $accountline->{amount} += 0.00;
82
    if ($accountline->{amount} <= 0 ) {
91
    if ($accountline->{amount} <= 0 ) {
83
        $accountline->{amountcredit} = 1;
92
        $accountline->{amountcredit} = 1;
Lines 93-98 foreach my $accountline ( @{$accts}) { Link Here
93
        $accountline->{payment} = 1;
102
        $accountline->{payment} = 1;
94
        $reverse_col = 1;
103
        $reverse_col = 1;
95
    }
104
    }
105
106
    if ( $accountline->{itemnumber} ) {
107
        # Because we will not have access to the object from the template
108
        $accountline->{item} = { biblionumber => $line->item->biblionumber, };
109
    }
110
    push @accountlines, $accountline;
96
}
111
}
97
112
98
$template->param( adultborrower => 1 ) if ( $patron->category->category_type =~ /^(A|I)$/ );
113
$template->param( adultborrower => 1 ) if ( $patron->category->category_type =~ /^(A|I)$/ );
Lines 116-122 $template->param( Link Here
116
    totalcredit         => $totalcredit,
131
    totalcredit         => $totalcredit,
117
    is_child            => ($patron->category->category_type eq 'C'),
132
    is_child            => ($patron->category->category_type eq 'C'),
118
    reverse_col         => $reverse_col,
133
    reverse_col         => $reverse_col,
119
    accounts            => $accts,
134
    accounts            => \@accountlines,
120
);
135
);
121
136
122
output_html_with_http_headers $input, $cookie, $template->output;
137
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/members/moremember.pl (-10 / +6 lines)
Lines 51-56 use C4::Biblio; Link Here
51
use C4::Form::MessagingPreferences;
51
use C4::Form::MessagingPreferences;
52
use List::MoreUtils qw/uniq/;
52
use List::MoreUtils qw/uniq/;
53
use C4::Members::Attributes qw(GetBorrowerAttributes);
53
use C4::Members::Attributes qw(GetBorrowerAttributes);
54
use Koha::Account::Lines;
54
use Koha::AuthorisedValues;
55
use Koha::AuthorisedValues;
55
use Koha::CsvProfiles;
56
use Koha::CsvProfiles;
56
use Koha::Patron::Debarments qw(GetDebarments);
57
use Koha::Patron::Debarments qw(GetDebarments);
Lines 219-236 else { Link Here
219
my $library = Koha::Libraries->find( $data->{branchcode})->unblessed;
220
my $library = Koha::Libraries->find( $data->{branchcode})->unblessed;
220
@{$data}{keys %$library} = values %$library; # merge in all branch columns
221
@{$data}{keys %$library} = values %$library; # merge in all branch columns
221
222
222
my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
223
224
# If printing a page, send the account informations to the template
223
# If printing a page, send the account informations to the template
225
if ($print eq "page") {
224
if ($print eq "page") {
226
    foreach my $accountline (@$accts) {
225
    my $accts = Koha::Account::Lines->search(
227
        $accountline->{amount} = sprintf '%.2f', $accountline->{amount};
226
        { borrowernumber => $patron->borrowernumber, amountoutstanding => { '>' => 0 } },
228
        $accountline->{amountoutstanding} = sprintf '%.2f', $accountline->{amountoutstanding};
227
        { order_by       => { -desc => 'accountlines_id' } }
229
228
    );
230
        if ($accountline->{accounttype} ne 'F' && $accountline->{accounttype} ne 'FU'){
231
            $accountline->{printtitle} = 1;
232
        }
233
    }
234
    $template->param( accounts => $accts );
229
    $template->param( accounts => $accts );
235
}
230
}
236
231
Lines 337-342 if ( C4::Context->preference("ExportCircHistory") ) { Link Here
337
my ( $subtag, $region ) = split '-', $patron->lang;
332
my ( $subtag, $region ) = split '-', $patron->lang;
338
my $translated_language = C4::Languages::language_get_description( $subtag, $subtag, 'language' );
333
my $translated_language = C4::Languages::language_get_description( $subtag, $subtag, 'language' );
339
334
335
my $total = $patron->account->balance;
340
$template->param(
336
$template->param(
341
    patron          => $patron,
337
    patron          => $patron,
342
    translated_language => $translated_language,
338
    translated_language => $translated_language,
(-)a/members/pay.pl (-1 / +2 lines)
Lines 131-137 output_html_with_http_headers $input, $cookie, $template->output; Link Here
131
131
132
sub add_accounts_to_template {
132
sub add_accounts_to_template {
133
133
134
    my ( $total, undef, undef ) = GetMemberAccountRecords($borrowernumber);
134
    my $patron = Koha::Patrons->find( $borrowernumber );
135
    my $total = $patron->account->balance;
135
    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $borrowernumber, amountoutstanding => { '!=' => 0 } }, { order_by => ['accounttype'] });
136
    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $borrowernumber, amountoutstanding => { '!=' => 0 } }, { order_by => ['accounttype'] });
136
    my @accounts;
137
    my @accounts;
137
    while ( my $account_line = $account_lines->next ) {
138
    while ( my $account_line = $account_lines->next ) {
(-)a/members/paycollect.pl (-1 / +1 lines)
Lines 63-69 my $user = $input->remote_user; Link Here
63
63
64
my $branch         = C4::Context->userenv->{'branch'};
64
my $branch         = C4::Context->userenv->{'branch'};
65
65
66
my ( $total_due, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber);
66
my $total_due = $patron->account->balance;
67
my $total_paid = $input->param('paid');
67
my $total_paid = $input->param('paid');
68
68
69
my $individual   = $input->param('pay_individual');
69
my $individual   = $input->param('pay_individual');
(-)a/members/printfeercpt.pl (-45 / +31 lines)
Lines 22-35 Link Here
22
# You should have received a copy of the GNU General Public License
22
# You should have received a copy of the GNU General Public License
23
# along with Koha; if not, see <http://www.gnu.org/licenses>.
23
# along with Koha; if not, see <http://www.gnu.org/licenses>.
24
24
25
use strict;
25
use Modern::Perl;
26
use warnings;
27
26
28
use C4::Auth;
27
use C4::Auth;
29
use C4::Output;
28
use C4::Output;
30
use CGI qw ( -utf8 );
29
use CGI qw ( -utf8 );
31
use C4::Members;
30
use C4::Members;
32
use C4::Accounts;
31
use C4::Accounts;
32
use Koha::Account::Lines;
33
use Koha::DateUtils;
33
use Koha::DateUtils;
34
use Koha::Patrons;
34
use Koha::Patrons;
35
use Koha::Patron::Categories;
35
use Koha::Patron::Categories;
Lines 71-124 if ( $data->{'category_type'} eq 'C') { Link Here
71
}
71
}
72
72
73
#get account details
73
#get account details
74
my ($total,$accts,$numaccts)=GetMemberAccountRecords($borrowernumber);
74
my $total = $patron->account->balance;
75
76
# FIXME This whole stuff is ugly and should be rewritten
77
# FIXME We should pass the $accts iterator to the template and do this formatting part there
78
my $accountline = Koha::Account::Lines->find($accountlines_id)->unblessed;
75
my $totalcredit;
79
my $totalcredit;
76
if($total <= 0){
80
if($total <= 0){
77
        $totalcredit = 1;
81
        $totalcredit = 1;
78
}
82
}
79
my @accountrows; # this is for the tmpl-loop
83
80
84
$accountline->{'amount'} += 0.00;
81
my $toggle;
85
if ( $accountline->{'amount'} <= 0 ) {
82
for (my $i=0;$i<$numaccts;$i++){
86
    $accountline->{'amountcredit'} = 1;
83
    next if ( $accts->[$i]{'accountlines_id'} ne $accountlines_id );
87
    $accountline->{'amount'} *= -1.00;
84
    if($i%2){
88
}
85
            $toggle = 0;
89
$accountline->{'amountoutstanding'} += 0.00;
86
    } else {
90
if ( $accountline->{'amountoutstanding'} <= 0 ) {
87
            $toggle = 1;
91
    $accountline->{'amountoutstandingcredit'} = 1;
88
    }
89
    $accts->[$i]{'toggle'} = $toggle;
90
    $accts->[$i]{'amount'}+=0.00;
91
    if($accts->[$i]{'amount'} <= 0){
92
        $accts->[$i]{'amountcredit'} = 1;
93
	$accts->[$i]{'amount'}*=-1.00;
94
    }
95
    $accts->[$i]{'amountoutstanding'}+=0.00;
96
    if($accts->[$i]{'amountoutstanding'} <= 0){
97
        $accts->[$i]{'amountoutstandingcredit'} = 1;
98
    }
99
100
    my %row = ( 'date'         => dt_from_string( $accts->[$i]{'date'} ),
101
                'amountcredit' => $accts->[$i]{'amountcredit'},
102
                'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
103
                'toggle' => $accts->[$i]{'toggle'},
104
                'description'       => $accts->[$i]{'description'},
105
				'itemnumber'       => $accts->[$i]{'itemnumber'},
106
				'biblionumber'       => $accts->[$i]{'biblionumber'},
107
                'amount'            => sprintf("%.2f",$accts->[$i]{'amount'}),
108
                'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}),
109
                'accountno' => $accts->[$i]{'accountno'},
110
                accounttype => $accts->[$i]{accounttype},
111
                'note' => $accts->[$i]{'note'},
112
                );
113
114
    if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){
115
        $row{'printtitle'}=1;
116
        $row{'title'} = $accts->[$i]{'title'};
117
    }
118
119
    push(@accountrows, \%row);
120
}
92
}
121
93
94
my %row = (
95
    'date'                    => dt_from_string( $accountline->{'date'} ),
96
    'amountcredit'            => $accountline->{'amountcredit'},
97
    'amountoutstandingcredit' => $accountline->{'amountoutstandingcredit'},
98
    'description'             => $accountline->{'description'},
99
    'amount'                  => sprintf( "%.2f", $accountline->{'amount'} ),
100
    'amountoutstanding' =>
101
      sprintf( "%.2f", $accountline->{'amountoutstanding'} ),
102
    'accountno' => $accountline->{'accountno'},
103
    accounttype => $accountline->{accounttype},
104
    'note'      => $accountline->{'note'},
105
);
106
122
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' || $data->{'category_type'} eq 'I' );
107
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' || $data->{'category_type'} eq 'I' );
123
108
124
$template->param( picture => 1 ) if $patron->image;
109
$template->param( picture => 1 ) if $patron->image;
Lines 144-149 $template->param( Link Here
144
    total               => sprintf("%.2f",$total),
129
    total               => sprintf("%.2f",$total),
145
    totalcredit         => $totalcredit,
130
    totalcredit         => $totalcredit,
146
	is_child        => ($data->{'category_type'} eq 'C'),
131
	is_child        => ($data->{'category_type'} eq 'C'),
147
    accounts            => \@accountrows );
132
    accounts            => [$accountline], # FIXME There is always only 1 row!
133
);
148
134
149
output_html_with_http_headers $input, $cookie, $template->output;
135
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/members/printinvoice.pl (-46 / +26 lines)
Lines 30-35 use CGI qw ( -utf8 ); Link Here
30
use C4::Members;
30
use C4::Members;
31
use C4::Accounts;
31
use C4::Accounts;
32
32
33
use Koha::Account::Lines;
33
use Koha::Patrons;
34
use Koha::Patrons;
34
use Koha::Patron::Categories;
35
use Koha::Patron::Categories;
35
36
Lines 66-123 if ( $data->{'category_type'} eq 'C' ) { Link Here
66
}
67
}
67
68
68
#get account details
69
#get account details
69
my ( $total, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber);
70
my $total = $patron->account->balance;
71
my $accountline = Koha::Account::Lines->find($accountlines_id)->unblessed;
72
70
my $totalcredit;
73
my $totalcredit;
71
if ( $total <= 0 ) {
74
if ( $total <= 0 ) {
72
    $totalcredit = 1;
75
    $totalcredit = 1;
73
}
76
}
74
77
75
my @accountrows;    # this is for the tmpl-loop
76
77
my $toggle;
78
for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
79
    next if ( $accts->[$i]{'accountlines_id'} ne $accountlines_id );
80
81
    if ( $i % 2 ) {
82
        $toggle = 0;
83
    } else {
84
        $toggle = 1;
85
    }
86
87
    $accts->[$i]{'toggle'} = $toggle;
88
    $accts->[$i]{'amount'} += 0.00;
89
90
    if ( $accts->[$i]{'amount'} <= 0 ) {
91
        $accts->[$i]{'amountcredit'} = 1;
92
    }
93
94
    $accts->[$i]{'amountoutstanding'} += 0.00;
95
    if ( $accts->[$i]{'amountoutstanding'} <= 0 ) {
96
        $accts->[$i]{'amountoutstandingcredit'} = 1;
97
    }
98
99
    my %row = (
100
        'date'                    => output_pref({ dt => dt_from_string( $accts->[$i]{'date'} ), dateonly => 1 }),
101
        'amountcredit'            => $accts->[$i]{'amountcredit'},
102
        'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
103
        'toggle'                  => $accts->[$i]{'toggle'},
104
        'description'             => $accts->[$i]{'description'},
105
        'itemnumber'              => $accts->[$i]{'itemnumber'},
106
        'biblionumber'            => $accts->[$i]{'biblionumber'},
107
        'amount'                  => sprintf( "%.2f", $accts->[$i]{'amount'} ),
108
        'amountoutstanding'       => sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} ),
109
        'accountno'               => $accts->[$i]{'accountno'},
110
        accounttype               => $accts->[$i]{accounttype},
111
        'note'                    => $accts->[$i]{'note'},
112
    );
113
114
    if ( $accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU' ) {
115
        $row{'printtitle'} = 1;
116
        $row{'title'}      = $accts->[$i]{'title'};
117
    }
118
78
119
    push( @accountrows, \%row );
79
$accountline->{'amount'} += 0.00;
80
if ( $accountline->{'amount'} <= 0 ) {
81
    $accountline->{'amountcredit'} = 1;
82
    $accountline->{'amount'} *= -1.00;
120
}
83
}
84
$accountline->{'amountoutstanding'} += 0.00;
85
if ( $accountline->{'amountoutstanding'} <= 0 ) {
86
    $accountline->{'amountoutstandingcredit'} = 1;
87
}
88
89
my %row = (
90
    'date'                    => dt_from_string( $accountline->{'date'}, dateonly => 1 ),
91
    'amountcredit'            => $accountline->{'amountcredit'},
92
    'amountoutstandingcredit' => $accountline->{'amountoutstandingcredit'},
93
    'description'             => $accountline->{'description'},
94
    'amount'                  => sprintf( "%.2f", $accountline->{'amount'} ),
95
    'amountoutstanding' =>
96
      sprintf( "%.2f", $accountline->{'amountoutstanding'} ),
97
    'accountno' => $accountline->{'accountno'},
98
    accounttype => $accountline->{accounttype},
99
    'note'      => $accountline->{'note'},
100
);
121
101
122
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' || $data->{'category_type'} eq 'I' );
102
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' || $data->{'category_type'} eq 'I' );
123
103
Lines 143-149 $template->param( Link Here
143
    total          => sprintf( "%.2f", $total ),
123
    total          => sprintf( "%.2f", $total ),
144
    totalcredit    => $totalcredit,
124
    totalcredit    => $totalcredit,
145
    is_child       => ( $data->{'category_type'} eq 'C' ),
125
    is_child       => ( $data->{'category_type'} eq 'C' ),
146
    accounts       => \@accountrows
126
    accounts       => [$accountline], # FIXME There is always only 1 row!
147
);
127
);
148
128
149
output_html_with_http_headers $input, $cookie, $template->output;
129
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/members/summary-print.pl (-8 / +5 lines)
Lines 53-66 my $data = $patron->unblessed; Link Here
53
$data->{description} = $category->description;
53
$data->{description} = $category->description;
54
$data->{category_type} = $category->category_type;
54
$data->{category_type} = $category->category_type;
55
55
56
my ( $total, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber);
56
my $total = $patron->account->balance;
57
foreach my $accountline (@$accts) {
57
my $accts = Koha::Account::Lines->search(
58
    if (   $accountline->{accounttype} ne 'F'
58
    { borrowernumber => $patron->borrowernumber },
59
        && $accountline->{accounttype} ne 'FU' )
59
    { order_by       => { -desc => 'accountlines_id' } }
60
    {
60
);
61
        $accountline->{printtitle} = 1;
62
    }
63
}
64
61
65
our $totalprice = 0;
62
our $totalprice = 0;
66
63
(-)a/opac/opac-main.pl (-13 / +19 lines)
Lines 67-88 my $koha_news_count = scalar @$all_koha_news; Link Here
67
my $quote = GetDailyQuote();   # other options are to pass in an exact quote id or select a random quote each pass... see perldoc C4::Koha
67
my $quote = GetDailyQuote();   # other options are to pass in an exact quote id or select a random quote each pass... see perldoc C4::Koha
68
68
69
# For dashboard
69
# For dashboard
70
my $checkouts = Koha::Checkouts->search({ borrowernumber => $borrowernumber })->count;
70
my $patron = Koha::Patrons->find( $borrowernumber );
71
my ( $overdues_count, $overdues ) = checkoverdues($borrowernumber);
71
72
my $holds_pending = Koha::Holds->search({ borrowernumber => $borrowernumber, found => undef })->count;
72
if ( $patron ) {
73
my $holds_waiting = Koha::Holds->search({ borrowernumber => $borrowernumber })->waiting->count;
73
    my $checkouts = Koha::Checkouts->search({ borrowernumber => $borrowernumber })->count;
74
my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
74
    my ( $overdues_count, $overdues ) = checkoverdues($borrowernumber);
75
75
    my $holds_pending = Koha::Holds->search({ borrowernumber => $borrowernumber, found => undef })->count;
76
if  ( $checkouts > 0 || $overdues_count > 0 || $holds_pending > 0 || $holds_waiting > 0 || $total > 0 ) {
76
    my $holds_waiting = Koha::Holds->search({ borrowernumber => $borrowernumber })->waiting->count;
77
    $template->param( dashboard_info => 1 );
77
    my $total = $patron->account->balance;
78
79
    if  ( $checkouts > 0 || $overdues_count > 0 || $holds_pending > 0 || $holds_waiting > 0 || $total > 0 ) {
80
        $template->param(
81
            dashboard_info => 1,
82
            checkouts           => $checkouts,
83
            overdues            => $overdues_count,
84
            holds_pending       => $holds_pending,
85
            holds_waiting       => $holds_waiting,
86
            total_owing         => $total,
87
        );
88
    }
78
}
89
}
79
90
80
$template->param(
91
$template->param(
81
    checkouts           => $checkouts,
82
    overdues            => $overdues_count,
83
    holds_pending       => $holds_pending,
84
    holds_waiting       => $holds_waiting,
85
    total_owing         => $total,
86
    koha_news           => $all_koha_news,
92
    koha_news           => $all_koha_news,
87
    koha_news_count     => $koha_news_count,
93
    koha_news_count     => $koha_news_count,
88
    branchcode          => $homebranch,
94
    branchcode          => $homebranch,
(-)a/opac/opac-reserve.pl (-1 / +1 lines)
Lines 330-336 if ( $query->param('place_reserve') ) { Link Here
330
my $noreserves     = 0;
330
my $noreserves     = 0;
331
my $maxoutstanding = C4::Context->preference("maxoutstanding");
331
my $maxoutstanding = C4::Context->preference("maxoutstanding");
332
$template->param( noreserve => 1 ) unless $maxoutstanding;
332
$template->param( noreserve => 1 ) unless $maxoutstanding;
333
my ( $amountoutstanding ) = GetMemberAccountRecords($borrowernumber);
333
my $amountoutstanding = $patron->account->balance;
334
if ( $amountoutstanding && ($amountoutstanding > $maxoutstanding) ) {
334
if ( $amountoutstanding && ($amountoutstanding > $maxoutstanding) ) {
335
    my $amount = sprintf "%.02f", $amountoutstanding;
335
    my $amount = sprintf "%.02f", $amountoutstanding;
336
    $template->param( message => 1 );
336
    $template->param( message => 1 );
(-)a/opac/opac-user.pl (-18 / +29 lines)
Lines 33-38 use C4::Output; Link Here
33
use C4::Biblio;
33
use C4::Biblio;
34
use C4::Items;
34
use C4::Items;
35
use C4::Letters;
35
use C4::Letters;
36
use Koha::Account::Lines;
36
use Koha::Libraries;
37
use Koha::Libraries;
37
use Koha::DateUtils;
38
use Koha::DateUtils;
38
use Koha::Holds;
39
use Koha::Holds;
Lines 88-94 if (!$borrowernumber) { Link Here
88
}
89
}
89
90
90
# get borrower information ....
91
# get borrower information ....
91
my $borr = Koha::Patrons->find( $borrowernumber )->unblessed;
92
my $patron = Koha::Patrons->find( $borrowernumber );
93
my $borr = $patron->unblessed;
92
94
93
my (  $today_year,   $today_month,   $today_day) = Today();
95
my (  $today_year,   $today_month,   $today_day) = Today();
94
my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
96
my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
Lines 116-122 if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) { Link Here
116
    $canrenew = 0;
118
    $canrenew = 0;
117
}
119
}
118
120
119
my ( $amountoutstanding ) = GetMemberAccountRecords($borrowernumber);
121
my $amountoutstanding = $patron->account->balance;
120
if ( $amountoutstanding > 5 ) {
122
if ( $amountoutstanding > 5 ) {
121
    $borr->{'amountoverfive'} = 1;
123
    $borr->{'amountoverfive'} = 1;
122
}
124
}
Lines 187-209 if ($issues){ Link Here
187
            $issue->{'reserved'} = 1;
189
            $issue->{'reserved'} = 1;
188
        }
190
        }
189
191
190
        my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
192
        # Must be moved in a module if reused
191
        my $charges = 0;
193
        my $charges = Koha::Account::Lines->search(
192
        my $rentalfines = 0;
194
            {
193
        foreach my $ac (@$accts) {
195
                borrowernumber    => $patron->borrowernumber,
194
            if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
196
                amountoutstanding => { '>' => 0 },
195
                $charges += $ac->{'amountoutstanding'}
197
                accounttype       => [ 'F', 'FU', 'L' ],
196
                  if $ac->{'accounttype'} eq 'F';
198
                itemnumber        => $issue->{itemnumber}
197
                $charges += $ac->{'amountoutstanding'}
199
            },
198
                  if $ac->{'accounttype'} eq 'FU';
200
            { select => [ { sum => 'amountoutstanding' } ], as => ['charges'] }
199
                $charges += $ac->{'amountoutstanding'}
201
        );
200
                  if $ac->{'accounttype'} eq 'L';
202
        $issue->{charges} = $charges->count ? $charges->next->get_column('charges') : 0;
201
                $rentalfines += $ac->{'amountoutstanding'}
203
202
                  if $ac->{'accounttype'} eq 'Rent';
204
        my $rental_fines = Koha::Account::Lines->search(
205
            {
206
                borrowernumber    => $patron->borrowernumber,
207
                amountoutstanding => { '>' => 0 },
208
                accounttype       => 'Rent',
209
                itemnumber        => $issue->{itemnumber}
210
            },
211
            {
212
                select => [ { sum => 'amountoutstanding' } ],
213
                as     => ['rental_fines']
203
            }
214
            }
204
        }
215
        );
205
        $issue->{'charges'} = $charges;
216
        $issue->{rentalfines} = $charges->count ? $charges->next->get_column('rental_fines') : 0;
206
        $issue->{'rentalfines'} = $rentalfines;
217
207
        my $marcrecord = GetMarcBiblio({ biblionumber => $issue->{'biblionumber'} });
218
        my $marcrecord = GetMarcBiblio({ biblionumber => $issue->{'biblionumber'} });
208
        $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, GetFrameworkCode($issue->{'biblionumber'}));
219
        $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, GetFrameworkCode($issue->{'biblionumber'}));
209
        # check if item is renewable
220
        # check if item is renewable
(-)a/reserve/request.pl (-1 / +2 lines)
Lines 180-185 if ($borrowernumber_hold && !$action) { Link Here
180
    }
180
    }
181
181
182
    my $is_debarred = $patron->is_debarred;
182
    my $is_debarred = $patron->is_debarred;
183
    my $amount_outstanding = $patron->account->balance;
183
    $template->param(
184
    $template->param(
184
                borrowernumber      => $patron->borrowernumber,
185
                borrowernumber      => $patron->borrowernumber,
185
                borrowersurname     => $patron->surname,
186
                borrowersurname     => $patron->surname,
Lines 198-204 if ($borrowernumber_hold && !$action) { Link Here
198
                messages            => $messages,
199
                messages            => $messages,
199
                warnings            => $warnings,
200
                warnings            => $warnings,
200
                restricted          => $is_debarred,
201
                restricted          => $is_debarred,
201
                amount_outstanding  => GetMemberAccountRecords($patron->borrowernumber),
202
                amount_outstanding  => $amount_outstanding,
202
    );
203
    );
203
}
204
}
204
205
(-)a/t/db_dependent/Koha/Patrons.t (-10 / +10 lines)
Lines 399-412 subtest 'add_enrolment_fee_if_needed' => sub { Link Here
399
    my $borrowernumber = C4::Members::AddMember(%borrower_data);
399
    my $borrowernumber = C4::Members::AddMember(%borrower_data);
400
    $borrower_data{borrowernumber} = $borrowernumber;
400
    $borrower_data{borrowernumber} = $borrowernumber;
401
401
402
    my ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
402
    my $patron = Koha::Patrons->find( $borrowernumber );
403
    is( $total, $enrolmentfee_K, "New kid pay $enrolmentfee_K" );
403
    my $total = $patron->account->balance;
404
    is( int($total), int($enrolmentfee_K), "New kid pay $enrolmentfee_K" );
404
405
405
    t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 0 );
406
    t::lib::Mocks::mock_preference( 'FeeOnChangePatronCategory', 0 );
406
    $borrower_data{categorycode} = 'J';
407
    $borrower_data{categorycode} = 'J';
407
    C4::Members::ModMember(%borrower_data);
408
    C4::Members::ModMember(%borrower_data);
408
    ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
409
    $total = $patron->account->balance;
409
    is( $total, $enrolmentfee_K, "Kid growing and become a juvenile, but shouldn't pay for the upgrade " );
410
    is( int($total), int($enrolmentfee_K), "Kid growing and become a juvenile, but shouldn't pay for the upgrade " );
410
411
411
    $borrower_data{categorycode} = 'K';
412
    $borrower_data{categorycode} = 'K';
412
    C4::Members::ModMember(%borrower_data);
413
    C4::Members::ModMember(%borrower_data);
Lines 414-429 subtest 'add_enrolment_fee_if_needed' => sub { Link Here
414
415
415
    $borrower_data{categorycode} = 'J';
416
    $borrower_data{categorycode} = 'J';
416
    C4::Members::ModMember(%borrower_data);
417
    C4::Members::ModMember(%borrower_data);
417
    ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
418
    $total = $patron->account->balance;
418
    is( $total, $enrolmentfee_K + $enrolmentfee_J, "Kid growing and become a juvenile, they should pay " . ( $enrolmentfee_K + $enrolmentfee_J ) );
419
    is( int($total), int($enrolmentfee_K + $enrolmentfee_J), "Kid growing and become a juvenile, they should pay " . ( $enrolmentfee_K + $enrolmentfee_J ) );
419
420
420
    # Check with calling directly Koha::Patron->get_enrolment_fee_if_needed
421
    # Check with calling directly Koha::Patron->get_enrolment_fee_if_needed
421
    my $patron = Koha::Patrons->find($borrowernumber);
422
    $patron->categorycode('YA')->store;
422
    $patron->categorycode('YA')->store;
423
    my $fee = $patron->add_enrolment_fee_if_needed;
423
    my $fee = $patron->add_enrolment_fee_if_needed;
424
    ($total) = C4::Members::GetMemberAccountRecords($borrowernumber);
424
    $total = $patron->account->balance;
425
    is( $total,
425
    is( int($total),
426
        $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA,
426
        int($enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA),
427
        "Juvenile growing and become an young adult, they should pay " . ( $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA )
427
        "Juvenile growing and become an young adult, they should pay " . ( $enrolmentfee_K + $enrolmentfee_J + $enrolmentfee_YA )
428
    );
428
    );
429
429
(-)a/t/db_dependent/Members.t (-5 / +5 lines)
Lines 386-393 subtest 'GetMemberAccountRecords' => sub { Link Here
386
        }
386
        }
387
    });
387
    });
388
388
389
    my ($total,undef,undef) = GetMemberAccountRecords( $borrowernumber );
389
    my $patron = Koha::Patrons->find( $borrowernumber );
390
    is( $total , 64.60, "Rounding works correctly in total calculation (single value)" );
390
    my $total = $patron->account->balance;
391
    is( sprintf("%.2f", $total), '64.60', "Rounding works correctly in total calculation (single value)" );
391
392
392
    my $accountline_2 = $builder->build({
393
    my $accountline_2 = $builder->build({
393
        source => 'Accountline',
394
        source => 'Accountline',
Lines 397-404 subtest 'GetMemberAccountRecords' => sub { Link Here
397
        }
398
        }
398
    });
399
    });
399
400
400
    ($total,undef,undef) = GetMemberAccountRecords( $borrowernumber );
401
    $total = $patron->account->balance;
401
    is( $total , 75.25, "Rounding works correctly in total calculation (multiple values)" );
402
    is( sprintf("%.2f", $total), '75.25', "Rounding works correctly in total calculation (multiple values)" );
402
403
403
};
404
};
404
405
405
- 

Return to bug 12001