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

(-)a/C4/Accounts.pm (-88 / +2 lines)
Lines 114-209 was made. Link Here
114
# FIXME - I'm not at all sure about the above, because I don't
114
# FIXME - I'm not at all sure about the above, because I don't
115
# understand what the acct* tables in the Koha database are for.
115
# understand what the acct* tables in the Koha database are for.
116
sub makepayment {
116
sub makepayment {
117
118
    #here we update both the accountoffsets and the account lines
119
    #updated to check, if they are paying off a lost item, we return the item
120
    # from their card, and put a note on the item record
121
    my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_;
117
    my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_;
122
    my $dbh = C4::Context->dbh;
123
    my $manager_id = 0;
124
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
125
126
    # begin transaction
127
    my $nextaccntno = getnextacctno($borrowernumber);
128
    my $newamtos    = 0;
129
    my $sth         = $dbh->prepare("SELECT * FROM accountlines WHERE accountlines_id=?");
130
    $sth->execute( $accountlines_id );
131
    my $data = $sth->fetchrow_hashref;
132
133
    my $payment;
134
    if ( $data->{'accounttype'} eq "Pay" ){
135
        my $udp = 		
136
            $dbh->prepare(
137
                "UPDATE accountlines
138
                    SET amountoutstanding = 0
139
                    WHERE accountlines_id = ?
140
                "
141
            );
142
        $udp->execute($accountlines_id);
143
    }else{
144
        my $udp = 		
145
            $dbh->prepare(
146
                "UPDATE accountlines
147
                    SET amountoutstanding = 0
148
                    WHERE accountlines_id = ?
149
                "
150
            );
151
        $udp->execute($accountlines_id);
152
153
         # create new line
154
        my $payment = 0 - $amount;
155
        $payment_note //= "";
156
        
157
        my $ins = 
158
            $dbh->prepare( 
159
                "INSERT 
160
                    INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note)
161
                    VALUES ( ?, ?, now(), ?, ?, '', 'Pay', 0, ?, ?)"
162
            );
163
        $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note);
164
    }
165
166
    if ( C4::Context->preference("FinesLog") ) {
167
        logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
168
            action                => 'fee_payment',
169
            borrowernumber        => $borrowernumber,
170
            old_amountoutstanding => $data->{'amountoutstanding'},
171
            new_amountoutstanding => 0,
172
            amount_paid           => $data->{'amountoutstanding'},
173
            accountlines_id       => $data->{'accountlines_id'},
174
            accountno             => $data->{'accountno'},
175
            manager_id            => $manager_id,
176
        }));
177
118
178
119
    return Koha::Account->new( { patron_id => $borrowernumber } )
179
        logaction("FINES", 'CREATE',$borrowernumber,Dumper({
120
      ->pay( { accountlines_id => $accountlines_id, amount => $amount, library_id => $branch, note => $payment_note } );
180
            action            => 'create_payment',
181
            borrowernumber    => $borrowernumber,
182
            accountno         => $nextaccntno,
183
            amount            => $payment,
184
            amountoutstanding => 0,,
185
            accounttype       => 'Pay',
186
            accountlines_paid => [$data->{'accountlines_id'}],
187
            manager_id        => $manager_id,
188
        }));
189
    }
190
191
    UpdateStats({
192
        branch => $branch,
193
        type   => 'payment',
194
        amount => $amount,
195
        borrowernumber => $borrowernumber,
196
        accountno => $accountno
197
    });
198
199
    #check to see what accounttype
200
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
201
        C4::Circulation::ReturnLostItem( $borrowernumber, $data->{'itemnumber'} );
202
    }
203
    my $sthr = $dbh->prepare("SELECT max(accountlines_id) AS lastinsertid FROM accountlines");
204
    $sthr->execute();
205
    my $datalastinsertid = $sthr->fetchrow_hashref;
206
    return $datalastinsertid->{'lastinsertid'};
207
}
121
}
208
122
209
=head2 getnextacctno
123
=head2 getnextacctno
(-)a/Koha/Account.pm (-8 / +65 lines)
Lines 47-60 sub new { Link Here
47
47
48
This method allows payments to be made against feees
48
This method allows payments to be made against feees
49
49
50
Koha::Account->new( { patron_id => $borrowernumber } )->pay(
51
    {
52
        amount     => $amount,
53
        sip        => $sipmode,
54
        note       => $note,
55
        id         => $accountlines_id,
56
        library_id => $branchcode,
57
    }
58
);
59
50
=cut
60
=cut
51
61
52
sub pay {
62
sub pay {
53
    my ( $self, $params ) = @_;
63
    my ( $self, $params ) = @_;
54
64
55
    my $amount = $params->{amount};
65
    my $amount          = $params->{amount};
56
    my $sip    = $params->{sip};
66
    my $sip             = $params->{sip};
57
    my $note   = $params->{note} || q{};
67
    my $note            = $params->{note} || q{};
68
    my $accountlines_id = $params->{accountlines_id};
69
    my $library_id      = $params->{library_id};
58
70
59
    my $userenv = C4::Context->userenv;
71
    my $userenv = C4::Context->userenv;
60
72
Lines 71-76 sub pay { Link Here
71
83
72
    my $manager_id = $userenv ? $userenv->{number} : 0;
84
    my $manager_id = $userenv ? $userenv->{number} : 0;
73
85
86
    my @fines_paid; # List of account lines paid on with this payment
87
88
    my $balance_remaining = $amount; # Set it now so we can adjust the amount if necessary
89
    $balance_remaining ||= 0;
90
91
    # We were passed a specific line to pay
92
    if ( $accountlines_id ) {
93
        my $fine = Koha::Account::Lines->find( $accountlines_id );
94
95
        # If accountline id is passed but no amount, we pay that line in full
96
        $amount = $fine->amountoutstanding unless defined($amount);
97
98
        my $old_amountoutstanding = $fine->amountoutstanding;
99
        $fine->amountoutstanding( 0 )->store();
100
101
        if ( $fine->accounttype eq 'Rep' || $fine->accounttype eq 'L' )
102
        {
103
            C4::Circulation::ReturnLostItem( $self->{patron_id}, $fine->itemnumber );
104
        }
105
106
        if ( C4::Context->preference("FinesLog") ) {
107
            logaction(
108
                "FINES", 'MODIFY',
109
                $self->{patron_id},
110
                Dumper(
111
                    {
112
                        action                => 'fee_payment',
113
                        borrowernumber        => $fine->borrowernumber,
114
                        old_amountoutstanding => $old_amountoutstanding,
115
                        new_amountoutstanding => 0,
116
                        amount_paid           => $old_amountoutstanding,
117
                        accountlines_id       => $fine->id,
118
                        accountno             => $fine->accountno,
119
                        manager_id            => $manager_id,
120
                        note                  => $note,
121
                    }
122
                )
123
            );
124
            push( @fines_paid, $fine->id );
125
        }
126
    }
127
128
    # Were not passed a specific line to pay, or the payment was for more
129
    # than the what was owed on the given line. In that case pay down other
130
    # lines with remaining balance.
74
    my @outstanding_fines = Koha::Account::Lines->search(
131
    my @outstanding_fines = Koha::Account::Lines->search(
75
        {
132
        {
76
            borrowernumber    => $self->{patron_id},
133
            borrowernumber    => $self->{patron_id},
Lines 78-85 sub pay { Link Here
78
        }
135
        }
79
    );
136
    );
80
137
81
    my $balance_remaining = $amount;
82
    my @fines_paid;
83
    foreach my $fine (@outstanding_fines) {
138
    foreach my $fine (@outstanding_fines) {
84
        my $amount_to_pay =
139
        my $amount_to_pay =
85
            $fine->amountoutstanding > $balance_remaining
140
            $fine->amountoutstanding > $balance_remaining
Lines 131-140 sub pay { Link Here
131
        }
186
        }
132
    )->store();
187
    )->store();
133
188
134
    my $branch = $userenv ? $userenv->{'branch'} : undef;
189
    $library_id ||= $userenv ? $userenv->{'branch'} : undef;
190
135
    UpdateStats(
191
    UpdateStats(
136
        {
192
        {
137
            branch         => $branch,
193
            branch         => $library_id,
138
            type           => 'payment',
194
            type           => 'payment',
139
            amount         => $amount,
195
            amount         => $amount,
140
            borrowernumber => $self->{patron_id},
196
            borrowernumber => $self->{patron_id},
Lines 160-165 sub pay { Link Here
160
            )
216
            )
161
        );
217
        );
162
    }
218
    }
219
220
    return $payment->id;
163
}
221
}
164
222
165
1;
223
1;
166
- 

Return to bug 15896