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

(-)a/t/db_dependent/Accounts.t (-9 / +13 lines)
Lines 35-41 BEGIN { Link Here
35
}
35
}
36
36
37
can_ok( 'C4::Accounts',
37
can_ok( 'C4::Accounts',
38
    qw( recordpayment
38
    qw(
39
        makepayment
39
        makepayment
40
        getnextacctno
40
        getnextacctno
41
        chargelostitem
41
        chargelostitem
Lines 136-142 for my $data (@test_data) { Link Here
136
136
137
$dbh->do(q|DELETE FROM accountlines|);
137
$dbh->do(q|DELETE FROM accountlines|);
138
138
139
subtest "recordpayment() tests" => sub {
139
subtest "Koha::Account::pay tests" => sub {
140
140
141
    plan tests => 10;
141
    plan tests => 10;
142
142
Lines 153-158 subtest "recordpayment() tests" => sub { Link Here
153
    $borrower->branchcode( $branchcode );
153
    $borrower->branchcode( $branchcode );
154
    $borrower->store;
154
    $borrower->store;
155
155
156
    my $account = Koha::Account->new({ patron_id => $borrower->id });
157
156
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 100 })->store();
158
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 100 })->store();
157
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 200 })->store();
159
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 200 })->store();
158
160
Lines 161-167 subtest "recordpayment() tests" => sub { Link Here
161
    my $count = $sth->fetchrow_array;
163
    my $count = $sth->fetchrow_array;
162
    is($count, 2, 'There is 2 lines as expected');
164
    is($count, 2, 'There is 2 lines as expected');
163
165
164
    # Testing recordpayment -------------------------
165
    # There is $100 in the account
166
    # There is $100 in the account
166
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
167
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
167
    my $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
168
    my $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
Lines 174-182 subtest "recordpayment() tests" => sub { Link Here
174
    # We make a $20 payment
175
    # We make a $20 payment
175
    my $borrowernumber = $borrower->borrowernumber;
176
    my $borrowernumber = $borrower->borrowernumber;
176
    my $data = '20.00';
177
    my $data = '20.00';
177
    my $sys_paytype;
178
    my $payment_note = '$20.00 payment note';
178
    my $payment_note = '$20.00 payment note';
179
    recordpayment($borrowernumber, $data, $sys_paytype, $payment_note);
179
    $account->pay( { amount => $data, note => $payment_note } );
180
180
    # There is now $280 in the account
181
    # There is now $280 in the account
181
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
182
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
182
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
183
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
Lines 185-190 subtest "recordpayment() tests" => sub { Link Here
185
        $amountleft += $line;
186
        $amountleft += $line;
186
    }
187
    }
187
    is($amountleft, 280, 'The account has $280 as expected' );
188
    is($amountleft, 280, 'The account has $280 as expected' );
189
188
    # Is the payment note well registered
190
    # Is the payment note well registered
189
    $sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1");
191
    $sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1");
190
    $sth->execute($borrower->borrowernumber);
192
    $sth->execute($borrower->borrowernumber);
Lines 194-200 subtest "recordpayment() tests" => sub { Link Here
194
    # We make a -$30 payment (a NEGATIVE payment)
196
    # We make a -$30 payment (a NEGATIVE payment)
195
    $data = '-30.00';
197
    $data = '-30.00';
196
    $payment_note = '-$30.00 payment note';
198
    $payment_note = '-$30.00 payment note';
197
    recordpayment($borrowernumber, $data, $sys_paytype, $payment_note);
199
    $account->pay( { amount => $data, note => $payment_note } );
200
198
    # There is now $310 in the account
201
    # There is now $310 in the account
199
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
202
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
200
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
203
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
Lines 212-218 subtest "recordpayment() tests" => sub { Link Here
212
    #We make a $150 payment ( > 1stLine )
215
    #We make a $150 payment ( > 1stLine )
213
    $data = '150.00';
216
    $data = '150.00';
214
    $payment_note = '$150.00 payment note';
217
    $payment_note = '$150.00 payment note';
215
    recordpayment($borrowernumber, $data, $sys_paytype, $payment_note);
218
    $account->pay( { amount => $data, note => $payment_note } );
219
216
    # There is now $160 in the account
220
    # There is now $160 in the account
217
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
221
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
218
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
222
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
Lines 230-236 subtest "recordpayment() tests" => sub { Link Here
230
    #We make a $200 payment ( > amountleft )
234
    #We make a $200 payment ( > amountleft )
231
    $data = '200.00';
235
    $data = '200.00';
232
    $payment_note = '$200.00 payment note';
236
    $payment_note = '$200.00 payment note';
233
    recordpayment($borrowernumber, $data, $sys_paytype, $payment_note);
237
    $account->pay( { amount => $data, note => $payment_note } );
238
234
    # There is now -$40 in the account
239
    # There is now -$40 in the account
235
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
240
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
236
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
241
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
237
- 

Return to bug 15899