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

(-)a/t/db_dependent/Accounts.t (-9 / +13 lines)
Lines 36-42 BEGIN { Link Here
36
}
36
}
37
37
38
can_ok( 'C4::Accounts',
38
can_ok( 'C4::Accounts',
39
    qw( recordpayment
39
    qw( 
40
        getnextacctno
40
        getnextacctno
41
        chargelostitem
41
        chargelostitem
42
        manualinvoice
42
        manualinvoice
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
    $line1->_result->discard_changes;
160
    $line1->_result->discard_changes;
Lines 163-169 subtest "recordpayment() tests" => sub { Link Here
163
    my $count = $sth->fetchrow_array;
165
    my $count = $sth->fetchrow_array;
164
    is($count, 2, 'There is 2 lines as expected');
166
    is($count, 2, 'There is 2 lines as expected');
165
167
166
    # Testing recordpayment -------------------------
167
    # There is $100 in the account
168
    # There is $100 in the account
168
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
169
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
169
    my $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
170
    my $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
Lines 176-184 subtest "recordpayment() tests" => sub { Link Here
176
    # We make a $20 payment
177
    # We make a $20 payment
177
    my $borrowernumber = $borrower->borrowernumber;
178
    my $borrowernumber = $borrower->borrowernumber;
178
    my $data = '20.00';
179
    my $data = '20.00';
179
    my $sys_paytype;
180
    my $payment_note = '$20.00 payment note';
180
    my $payment_note = '$20.00 payment note';
181
    recordpayment($borrowernumber, $data, $sys_paytype, $payment_note);
181
    $account->pay( { amount => $data, note => $payment_note } );
182
182
    # There is now $280 in the account
183
    # There is now $280 in the account
183
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
184
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
184
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
185
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
Lines 187-192 subtest "recordpayment() tests" => sub { Link Here
187
        $amountleft += $line;
188
        $amountleft += $line;
188
    }
189
    }
189
    is($amountleft, 280, 'The account has $280 as expected' );
190
    is($amountleft, 280, 'The account has $280 as expected' );
191
190
    # Is the payment note well registered
192
    # Is the payment note well registered
191
    $sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1");
193
    $sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1");
192
    $sth->execute($borrower->borrowernumber);
194
    $sth->execute($borrower->borrowernumber);
Lines 196-202 subtest "recordpayment() tests" => sub { Link Here
196
    # We make a -$30 payment (a NEGATIVE payment)
198
    # We make a -$30 payment (a NEGATIVE payment)
197
    $data = '-30.00';
199
    $data = '-30.00';
198
    $payment_note = '-$30.00 payment note';
200
    $payment_note = '-$30.00 payment note';
199
    recordpayment($borrowernumber, $data, $sys_paytype, $payment_note);
201
    $account->pay( { amount => $data, note => $payment_note } );
202
200
    # There is now $310 in the account
203
    # There is now $310 in the account
201
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
204
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
202
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
205
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
Lines 214-220 subtest "recordpayment() tests" => sub { Link Here
214
    #We make a $150 payment ( > 1stLine )
217
    #We make a $150 payment ( > 1stLine )
215
    $data = '150.00';
218
    $data = '150.00';
216
    $payment_note = '$150.00 payment note';
219
    $payment_note = '$150.00 payment note';
217
    recordpayment($borrowernumber, $data, $sys_paytype, $payment_note);
220
    $account->pay( { amount => $data, note => $payment_note } );
221
218
    # There is now $160 in the account
222
    # There is now $160 in the account
219
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
223
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
220
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
224
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
Lines 232-238 subtest "recordpayment() tests" => sub { Link Here
232
    #We make a $200 payment ( > amountleft )
236
    #We make a $200 payment ( > amountleft )
233
    $data = '200.00';
237
    $data = '200.00';
234
    $payment_note = '$200.00 payment note';
238
    $payment_note = '$200.00 payment note';
235
    recordpayment($borrowernumber, $data, $sys_paytype, $payment_note);
239
    $account->pay( { amount => $data, note => $payment_note } );
240
236
    # There is now -$40 in the account
241
    # There is now -$40 in the account
237
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
242
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
238
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
243
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
239
- 

Return to bug 15899