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

(-)a/Koha/Account.pm (-3 / +2 lines)
Lines 81-87 sub pay { Link Here
81
    my $lines         = $params->{lines};
81
    my $lines         = $params->{lines};
82
    my $type          = $params->{type} || 'PAYMENT';
82
    my $type          = $params->{type} || 'PAYMENT';
83
    my $payment_type  = $params->{payment_type} || undef;
83
    my $payment_type  = $params->{payment_type} || undef;
84
    my $offset_type   = $params->{offset_type} || $type eq 'WRITEOFF' ? 'Writeoff' : 'Payment';
85
    my $cash_register = $params->{cash_register};
84
    my $cash_register = $params->{cash_register};
86
    my $item_id       = $params->{item_id};
85
    my $item_id       = $params->{item_id};
87
86
Lines 358-364 sub payin_amount { Link Here
358
                $credit = $credit->apply(
357
                $credit = $credit->apply(
359
                    {
358
                    {
360
                        debits      => $params->{debits},
359
                        debits      => $params->{debits},
361
                        offset_type => $params->{type}
360
                        offset_type => $Koha::Account::offset_type->{$params->{type}}
362
                    }
361
                    }
363
                );
362
                );
364
            }
363
            }
Lines 370-376 sub payin_amount { Link Here
370
                $credit = $credit->apply(
369
                $credit = $credit->apply(
371
                    {
370
                    {
372
                        debits      => [ $self->outstanding_debits->as_list ],
371
                        debits      => [ $self->outstanding_debits->as_list ],
373
                        offset_type => $params->{type}
372
                        offset_type => $Koha::Account::offset_type->{$params->{type}}
374
                    }
373
                    }
375
                );
374
                );
376
            }
375
            }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt (-1 / +1 lines)
Lines 66-72 Link Here
66
                            <li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
66
                            <li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
67
                            <li><label for="desc">Description: </label><input type="text" name="desc" size="50" id="desc" /></li>
67
                            <li><label for="desc">Description: </label><input type="text" name="desc" size="50" id="desc" /></li>
68
                            <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
68
                            <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
69
                            <li><label for="amount">Amount: </label><input type="text" inputmode="decimal" pattern="^\d+(\.\d{2})?$" name="amount" id="amount" required="required" value=""/> Example: 5.00</li>
69
                            <li><label for="amount">Amount: </label><input type="text" inputmode="decimal" pattern="^\d+(\.\d{2})?$" name="amount" id="amount" required="required" min="0" value=""/> Example: 5.00</li>
70
                        </ol>
70
                        </ol>
71
                    </fieldset>
71
                    </fieldset>
72
72
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt (-1 / +1 lines)
Lines 79-85 Link Here
79
                            <li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" value="[% barcode | html %]" /></li>
79
                            <li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" value="[% barcode | html %]" /></li>
80
                            <li><label for="desc">Description: </label><input type="text" name="desc" id="desc" size="50" value="[% desc | html %]" /></li>
80
                            <li><label for="desc">Description: </label><input type="text" name="desc" id="desc" size="50" value="[% desc | html %]" /></li>
81
                            <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" value="[% note | html %]" /></li>
81
                            <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" value="[% note | html %]" /></li>
82
                            <li><label for="amount">Amount: </label><input type="text" inputmode="decimal" pattern="^\d+(\.\d{2})?$" name="amount" id="amount" required="required" value="[% amount | $Price on_editing => 1 %]" /> Example: 5.00</li>
82
                            <li><label for="amount">Amount: </label><input type="text" inputmode="decimal" pattern="^\d+(\.\d{2})?$" name="amount" id="amount" required="required" min="0" value="[% amount | $Price on_editing => 1 %]" /> Example: 5.00</li>
83
                        </ol>
83
                        </ol>
84
                    </fieldset>
84
                    </fieldset>
85
                    <fieldset class="action">
85
                    <fieldset class="action">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt (-4 / +4 lines)
Lines 155-165 Link Here
155
155
156
    <li>
156
    <li>
157
        <label for="paid">Amount being paid: </label>
157
        <label for="paid">Amount being paid: </label>
158
        <input name="paid" id="paid" type="text" step="0.01" value="[% amountoutstanding | $Price on_editing => 1 %]"/>
158
        <input name="paid" id="paid" type="text" step="0.01" min="0" value="[% amountoutstanding | $Price on_editing => 1 %]"/>
159
    </li>
159
    </li>
160
    <li>
160
    <li>
161
        <label for="collected">Amount tendered: </label>
161
        <label for="collected">Amount tendered: </label>
162
        <input name="collected" id="collected" type="text" step="0.01" value="[% amountoutstanding | $Price on_editing => 1 %]"/>
162
        <input name="collected" id="collected" type="text" step="0.01" min="0" value="[% amountoutstanding | $Price on_editing => 1 %]"/>
163
    </li>
163
    </li>
164
    <li>
164
    <li>
165
        <label>Change to give: </label>
165
        <label>Change to give: </label>
Lines 285-296 Link Here
285
        [% ELSE %]
285
        [% ELSE %]
286
            <label for="paid">Amount being paid: </label>
286
            <label for="paid">Amount being paid: </label>
287
        [% END %]
287
        [% END %]
288
        <input name="paid" id="paid" type="text" step="0.01" value="[% total | $Price on_editing => 1 %]"/>
288
        <input name="paid" id="paid" type="text" step="0.01" min="0" value="[% total | $Price on_editing => 1 %]"/>
289
    </li>
289
    </li>
290
    [% IF type != 'WRITEOFF' %]
290
    [% IF type != 'WRITEOFF' %]
291
        <li>
291
        <li>
292
            <label for="collected">Amount tendered: </label>
292
            <label for="collected">Amount tendered: </label>
293
            <input name="collected" id="collected" type="text" step="0.01" value="[% total | $Price on_editing => 1 %]"/>
293
            <input name="collected" id="collected" type="text" step="0.01" min="0" value="[% total | $Price on_editing => 1 %]"/>
294
        </li>
294
        </li>
295
        <li>
295
        <li>
296
            <label>Change to give: </label>
296
            <label>Change to give: </label>
(-)a/t/db_dependent/Accounts.t (-24 / +11 lines)
Lines 20-25 use Modern::Perl; Link Here
20
20
21
use Test::More tests => 27;
21
use Test::More tests => 27;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Exception;
23
use Test::Warn;
24
use Test::Warn;
24
25
25
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
Lines 143-149 $dbh->do(q|DELETE FROM accountlines|); Link Here
143
144
144
subtest "Koha::Account::pay tests" => sub {
145
subtest "Koha::Account::pay tests" => sub {
145
146
146
    plan tests => 14;
147
    plan tests => 13;
147
148
148
    # Create a borrower
149
    # Create a borrower
149
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
150
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
Lines 201-238 subtest "Koha::Account::pay tests" => sub { Link Here
201
    my $note = $sth->fetchrow_array;
202
    my $note = $sth->fetchrow_array;
202
    is($note,'$20.00 payment note', '$20.00 payment note is registered');
203
    is($note,'$20.00 payment note', '$20.00 payment note is registered');
203
204
204
    # We make a -$30 payment (a NEGATIVE payment)
205
    # We attempt to make a -$30 payment (a NEGATIVE payment)
205
    $data = '-30.00';
206
    $data = '-30.00';
206
    $payment_note = '-$30.00 payment note';
207
    $payment_note = '-$30.00 payment note';
207
    $account->pay( { amount => $data, note => $payment_note } );
208
    throws_ok { $account->pay( { amount => $data, note => $payment_note } ) } qr//, 'Croaked on call to pay with negative amount';
208
209
    # There is now $310 in the account
210
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
211
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
212
    $amountleft = 0;
213
    for my $line ( @$amountoutstanding ) {
214
        $amountleft += $line;
215
    }
216
    is($amountleft, 310, 'The account has $310 as expected' );
217
    # Is the payment note well registered
218
    $sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1");
219
    $sth->execute($borrower->borrowernumber);
220
    $note = $sth->fetchrow_array;
221
    is($note,'-$30.00 payment note', '-$30.00 payment note is registered');
222
209
223
    #We make a $150 payment ( > 1stLine )
210
    #We make a $150 payment ( > 1stLine )
224
    $data = '150.00';
211
    $data = '150.00';
225
    $payment_note = '$150.00 payment note';
212
    $payment_note = '$150.00 payment note';
226
    $account->pay( { amount => $data, note => $payment_note } );
213
    $account->pay( { amount => $data, note => $payment_note } );
227
214
228
    # There is now $160 in the account
215
    # There is now $130 in the account
229
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
216
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
230
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
217
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
231
    $amountleft = 0;
218
    $amountleft = 0;
232
    for my $line ( @$amountoutstanding ) {
219
    for my $line ( @$amountoutstanding ) {
233
        $amountleft += $line;
220
        $amountleft += $line;
234
    }
221
    }
235
    is($amountleft, 160, 'The account has $160 as expected' );
222
    is($amountleft, 130, 'The account has $130 as expected' );
236
223
237
    # Is the payment note well registered
224
    # Is the payment note well registered
238
    $sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1");
225
    $sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1");
Lines 245-258 subtest "Koha::Account::pay tests" => sub { Link Here
245
    $payment_note = '$200.00 payment note';
232
    $payment_note = '$200.00 payment note';
246
    $account->pay( { amount => $data, note => $payment_note } );
233
    $account->pay( { amount => $data, note => $payment_note } );
247
234
248
    # There is now -$40 in the account
235
    # There is now -$70 in the account
249
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
236
    $sth = $dbh->prepare("SELECT amountoutstanding FROM accountlines WHERE borrowernumber=?");
250
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
237
    $amountoutstanding = $dbh->selectcol_arrayref($sth, {}, $borrower->borrowernumber);
251
    $amountleft = 0;
238
    $amountleft = 0;
252
    for my $line ( @$amountoutstanding ) {
239
    for my $line ( @$amountoutstanding ) {
253
        $amountleft += $line;
240
        $amountleft += $line;
254
    }
241
    }
255
    is($amountleft, -40, 'The account has -$40 as expected, (credit situation)' );
242
    is($amountleft, -70, 'The account has -$70 as expected, (credit situation)' );
256
243
257
    # Is the payment note well registered
244
    # Is the payment note well registered
258
    $sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1");
245
    $sth = $dbh->prepare("SELECT note FROM accountlines WHERE borrowernumber=? ORDER BY accountlines_id DESC LIMIT 1");
Lines 352-358 subtest "Koha::Account::pay writeoff tests" => sub { Link Here
352
    my $writeoff = Koha::Account::Lines->find( $id );
339
    my $writeoff = Koha::Account::Lines->find( $id );
353
340
354
    is( $writeoff->credit_type_code, 'WRITEOFF', 'Type is correct for WRITEOFF' );
341
    is( $writeoff->credit_type_code, 'WRITEOFF', 'Type is correct for WRITEOFF' );
355
    is( $writeoff->description, 'Writeoff', 'Description is correct' );
342
    is( $writeoff->description, '', 'Description is correct' );
356
    is( $writeoff->amount+0, -42, 'Amount is correct' );
343
    is( $writeoff->amount+0, -42, 'Amount is correct' );
357
};
344
};
358
345
Lines 411-417 subtest "More Koha::Account::pay tests" => sub { Link Here
411
        is( $stat->type, 'payment', "Correct statistic type" );
398
        is( $stat->type, 'payment', "Correct statistic type" );
412
        is( $stat->branch, $branch, "Correct branch logged to statistics" );
399
        is( $stat->branch, $branch, "Correct branch logged to statistics" );
413
        is( $stat->borrowernumber, $borrowernumber, "Correct borrowernumber logged to statistics" );
400
        is( $stat->borrowernumber, $borrowernumber, "Correct borrowernumber logged to statistics" );
414
        is( $stat->value+0, $amount, "Correct amount logged to statistics" );
401
        is( $stat->value+0, -$amount, "Correct amount logged to statistics" );
415
    }
402
    }
416
};
403
};
417
404
Lines 471-477 subtest "Even more Koha::Account::pay tests" => sub { Link Here
471
        is( $stat->type, 'payment', "Correct statistic type" );
458
        is( $stat->type, 'payment', "Correct statistic type" );
472
        is( $stat->branch, $branch, "Correct branch logged to statistics" );
459
        is( $stat->branch, $branch, "Correct branch logged to statistics" );
473
        is( $stat->borrowernumber, $borrowernumber, "Correct borrowernumber logged to statistics" );
460
        is( $stat->borrowernumber, $borrowernumber, "Correct borrowernumber logged to statistics" );
474
        is( $stat->value+0, $partialamount, "Correct amount logged to statistics" );
461
        is( $stat->value+0, -$partialamount, "Correct amount logged to statistics" );
475
    }
462
    }
476
};
463
};
477
464
(-)a/t/db_dependent/Koha/Account.t (-5 / +4 lines)
Lines 1395-1409 subtest 'Koha::Account::payin_amount() tests' => sub { Link Here
1395
    is( $offset->amount * 1, -10, 'Correct offset amount recorded' );
1395
    is( $offset->amount * 1, -10, 'Correct offset amount recorded' );
1396
    $offset = $offsets->next;
1396
    $offset = $offsets->next;
1397
    is( $offset->debit_id, $debit_1->id, "Offset added against debit_1");
1397
    is( $offset->debit_id, $debit_1->id, "Offset added against debit_1");
1398
    is( $offset->type,       'PAYMENT', "Payment used for offset_type" );
1398
    is( $offset->type,       'Payment', "Payment used for offset_type" );
1399
    is( $offset->amount * 1, -2,      'Correct amount offset against debit_1' );
1399
    is( $offset->amount * 1, -2,      'Correct amount offset against debit_1' );
1400
    $offset = $offsets->next;
1400
    $offset = $offsets->next;
1401
    is( $offset->debit_id, $debit_2->id, "Offset added against debit_2");
1401
    is( $offset->debit_id, $debit_2->id, "Offset added against debit_2");
1402
    is( $offset->type,       'PAYMENT', "Payment used for offset_type" );
1402
    is( $offset->type,       'Payment', "Payment used for offset_type" );
1403
    is( $offset->amount * 1, -3,      'Correct amount offset against debit_2' );
1403
    is( $offset->amount * 1, -3,      'Correct amount offset against debit_2' );
1404
    $offset = $offsets->next;
1404
    $offset = $offsets->next;
1405
    is( $offset->debit_id, $debit_3->id, "Offset added against debit_3");
1405
    is( $offset->debit_id, $debit_3->id, "Offset added against debit_3");
1406
    is( $offset->type,       'PAYMENT', "Payment used for offset_type" );
1406
    is( $offset->type,       'Payment', "Payment used for offset_type" );
1407
    is( $offset->amount * 1, -5,      'Correct amount offset against debit_3' );
1407
    is( $offset->amount * 1, -5,      'Correct amount offset against debit_3' );
1408
1408
1409
    my $debit_5 = $account->add_debit( { amount => 5, interface => 'commandline', type => 'OVERDUE' } );
1409
    my $debit_5 = $account->add_debit( { amount => 5, interface => 'commandline', type => 'OVERDUE' } );
Lines 1428-1434 subtest 'Koha::Account::payin_amount() tests' => sub { Link Here
1428
    is( $offset->amount * 1, -2.50, 'Correct offset amount recorded' );
1428
    is( $offset->amount * 1, -2.50, 'Correct offset amount recorded' );
1429
    $offset = $offsets->next;
1429
    $offset = $offsets->next;
1430
    is( $offset->debit_id, $debit_5->id, "Offset added against debit_5");
1430
    is( $offset->debit_id, $debit_5->id, "Offset added against debit_5");
1431
    is( $offset->type,       'PAYMENT', "PAYMENT used for offset_type" );
1431
    is( $offset->type,       'Payment', "Payment used for offset_type" );
1432
    is( $offset->amount * 1, -2.50,      'Correct amount offset against debit_5' );
1432
    is( $offset->amount * 1, -2.50,      'Correct amount offset against debit_5' );
1433
1433
1434
    $schema->storage->txn_rollback;
1434
    $schema->storage->txn_rollback;
1435
- 

Return to bug 27636