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

(-)a/C4/Accounts.pm (-88 / +2 lines)
Lines 116-211 was made. Link Here
116
# FIXME - I'm not at all sure about the above, because I don't
116
# FIXME - I'm not at all sure about the above, because I don't
117
# understand what the acct* tables in the Koha database are for.
117
# understand what the acct* tables in the Koha database are for.
118
sub makepayment {
118
sub makepayment {
119
120
    #here we update both the accountoffsets and the account lines
121
    #updated to check, if they are paying off a lost item, we return the item
122
    # from their card, and put a note on the item record
123
    my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_;
119
    my ( $accountlines_id, $borrowernumber, $accountno, $amount, $user, $branch, $payment_note ) = @_;
124
    my $dbh = C4::Context->dbh;
125
    my $manager_id = 0;
126
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
127
128
    # begin transaction
129
    my $nextaccntno = getnextacctno($borrowernumber);
130
    my $newamtos    = 0;
131
    my $sth         = $dbh->prepare("SELECT * FROM accountlines WHERE accountlines_id=?");
132
    $sth->execute( $accountlines_id );
133
    my $data = $sth->fetchrow_hashref;
134
135
    my $payment;
136
    if ( $data->{'accounttype'} eq "Pay" ){
137
        my $udp = 		
138
            $dbh->prepare(
139
                "UPDATE accountlines
140
                    SET amountoutstanding = 0
141
                    WHERE accountlines_id = ?
142
                "
143
            );
144
        $udp->execute($accountlines_id);
145
    }else{
146
        my $udp = 		
147
            $dbh->prepare(
148
                "UPDATE accountlines
149
                    SET amountoutstanding = 0
150
                    WHERE accountlines_id = ?
151
                "
152
            );
153
        $udp->execute($accountlines_id);
154
155
         # create new line
156
        my $payment = 0 - $amount;
157
        $payment_note //= "";
158
        
159
        my $ins = 
160
            $dbh->prepare( 
161
                "INSERT 
162
                    INTO accountlines (borrowernumber, accountno, date, amount, itemnumber, description, accounttype, amountoutstanding, manager_id, note)
163
                    VALUES ( ?, ?, now(), ?, ?, '', 'Pay', 0, ?, ?)"
164
            );
165
        $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note);
166
    }
167
168
    if ( C4::Context->preference("FinesLog") ) {
169
        logaction("FINES", 'MODIFY', $borrowernumber, Dumper({
170
            action                => 'fee_payment',
171
            borrowernumber        => $borrowernumber,
172
            old_amountoutstanding => $data->{'amountoutstanding'},
173
            new_amountoutstanding => 0,
174
            amount_paid           => $data->{'amountoutstanding'},
175
            accountlines_id       => $data->{'accountlines_id'},
176
            accountno             => $data->{'accountno'},
177
            manager_id            => $manager_id,
178
        }));
179
120
180
121
    return Koha::Account->new( { patron_id => $borrowernumber } )
181
        logaction("FINES", 'CREATE',$borrowernumber,Dumper({
122
      ->pay( { accountlines_id => $accountlines_id, amount => $amount, library_id => $branch, note => $payment_note } );
182
            action            => 'create_payment',
183
            borrowernumber    => $borrowernumber,
184
            accountno         => $nextaccntno,
185
            amount            => $payment,
186
            amountoutstanding => 0,,
187
            accounttype       => 'Pay',
188
            accountlines_paid => [$data->{'accountlines_id'}],
189
            manager_id        => $manager_id,
190
        }));
191
    }
192
193
    UpdateStats({
194
        branch => $branch,
195
        type   => 'payment',
196
        amount => $amount,
197
        borrowernumber => $borrowernumber,
198
        accountno => $accountno
199
    });
200
201
    #check to see what accounttype
202
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
203
        C4::Circulation::ReturnLostItem( $borrowernumber, $data->{'itemnumber'} );
204
    }
205
    my $sthr = $dbh->prepare("SELECT max(accountlines_id) AS lastinsertid FROM accountlines");
206
    $sthr->execute();
207
    my $datalastinsertid = $sthr->fetchrow_hashref;
208
    return $datalastinsertid->{'lastinsertid'};
209
}
123
}
210
124
211
=head2 getnextacctno
125
=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