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

(-)a/Koha/Account.pm (-14 / +27 lines)
Lines 517-522 $debit_type can be any of: Link Here
517
  - RENT_RENEW
517
  - RENT_RENEW
518
  - RENT_DAILY_RENEW
518
  - RENT_DAILY_RENEW
519
  - RESERVE
519
  - RESERVE
520
  - PAYOUT
520
521
521
=cut
522
=cut
522
523
Lines 533-538 sub add_debit { Link Here
533
        }
534
        }
534
    }
535
    }
535
536
537
    # check for cash register if using cash
538
    Koha::Exceptions::Account::RegisterRequired->throw()
539
      if ( C4::Context->preference("UseCashRegisters")
540
        && defined( $params->{transaction_type} )
541
        && ( $params->{transaction_type} eq 'CASH' )
542
        && !defined( $params->{cash_register} ) );
543
536
    # amount should always be a positive value
544
    # amount should always be a positive value
537
    my $amount = $params->{amount};
545
    my $amount = $params->{amount};
538
    unless ( $amount > 0 ) {
546
    unless ( $amount > 0 ) {
Lines 540-554 sub add_debit { Link Here
540
            error => 'Debit amount passed is not positive' );
548
            error => 'Debit amount passed is not positive' );
541
    }
549
    }
542
550
543
    my $description = $params->{description} // q{};
551
    my $description      = $params->{description} // q{};
544
    my $note        = $params->{note} // q{};
552
    my $note             = $params->{note} // q{};
545
    my $user_id     = $params->{user_id};
553
    my $user_id          = $params->{user_id};
546
    my $interface   = $params->{interface};
554
    my $interface        = $params->{interface};
547
    my $library_id  = $params->{library_id};
555
    my $library_id       = $params->{library_id};
548
    my $debit_type  = $params->{type};
556
    my $cash_register    = $params->{cash_register};
549
    my $item_id     = $params->{item_id};
557
    my $debit_type       = $params->{type};
550
    my $issue_id    = $params->{issue_id};
558
    my $transaction_type = $params->{transaction_type};
551
    my $offset_type = $Koha::Account::offset_type->{$debit_type} // 'Manual Debit';
559
    my $item_id          = $params->{item_id};
560
    my $issue_id         = $params->{issue_id};
561
    my $offset_type      = $Koha::Account::offset_type->{$debit_type} // 'Manual Debit';
552
562
553
    my $line;
563
    my $line;
554
    my $schema = Koha::Database->new->schema;
564
    my $schema = Koha::Database->new->schema;
Lines 565-577 sub add_debit { Link Here
565
                        description       => $description,
575
                        description       => $description,
566
                        debit_type_code   => $debit_type,
576
                        debit_type_code   => $debit_type,
567
                        amountoutstanding => $amount,
577
                        amountoutstanding => $amount,
568
                        payment_type      => undef,
578
                        payment_type      => $transaction_type,
569
                        note              => $note,
579
                        note              => $note,
570
                        manager_id        => $user_id,
580
                        manager_id        => $user_id,
571
                        interface         => $interface,
581
                        interface         => $interface,
572
                        itemnumber        => $item_id,
582
                        itemnumber        => $item_id,
573
                        issue_id          => $issue_id,
583
                        issue_id          => $issue_id,
574
                        branchcode        => $library_id,
584
                        branchcode        => $library_id,
585
                        register_id       => $cash_register,
575
                        (
586
                        (
576
                            $debit_type eq 'OVERDUE'
587
                            $debit_type eq 'OVERDUE'
577
                            ? ( status => 'UNRETURNED' )
588
                            ? ( status => 'UNRETURNED' )
Lines 669-675 sub payout_amount { Link Here
669
    my $amount = $params->{amount};
680
    my $amount = $params->{amount};
670
    unless ( $amount > 0 ) {
681
    unless ( $amount > 0 ) {
671
        Koha::Exceptions::Account::AmountNotPositive->throw(
682
        Koha::Exceptions::Account::AmountNotPositive->throw(
672
            error => 'Debit amount passed is not positive' );
683
            error => 'Payout amount passed is not positive' );
673
    }
684
    }
674
685
675
    # Amount should always be less than or equal to outstanding credit
686
    # Amount should always be less than or equal to outstanding credit
Lines 696-707 sub payout_amount { Link Here
696
                {
707
                {
697
                    amount            => $params->{amount},
708
                    amount            => $params->{amount},
698
                    type              => 'PAYOUT',
709
                    type              => 'PAYOUT',
699
                    payment_type      => $params->{payout_type},
710
                    transaction_type  => $params->{payout_type},
700
                    amountoutstanding => $params->{amount},
711
                    amountoutstanding => $params->{amount},
701
                    manager_id        => $params->{staff_id},
712
                    manager_id        => $params->{staff_id},
702
                    interface         => $params->{interface},
713
                    interface         => $params->{interface},
703
                    branchcode        => $params->{branch},
714
                    branchcode        => $params->{branch},
704
                    register_id       => $params->{cash_register}
715
                    cash_register     => $params->{cash_register}
705
                }
716
                }
706
            );
717
            );
707
718
Lines 710-715 sub payout_amount { Link Here
710
                $credit->apply(
721
                $credit->apply(
711
                    { debits => [$payout], offset_type => 'PAYOUT' } );
722
                    { debits => [$payout], offset_type => 'PAYOUT' } );
712
                $payout->discard_changes;
723
                $payout->discard_changes;
724
                last if $payout->amountoutstanding == 0;
713
            }
725
            }
714
726
715
            # Set payout as paid
727
            # Set payout as paid
Lines 884-890 our $offset_type = { Link Here
884
    'RENT_RENEW'       => 'Rental Fee',
896
    'RENT_RENEW'       => 'Rental Fee',
885
    'RENT_DAILY_RENEW' => 'Rental Fee',
897
    'RENT_DAILY_RENEW' => 'Rental Fee',
886
    'OVERDUE'          => 'OVERDUE',
898
    'OVERDUE'          => 'OVERDUE',
887
    'RESERVE_EXPIRED'  => 'Hold Expired'
899
    'RESERVE_EXPIRED'  => 'Hold Expired',
900
    'PAYOUT'           => 'PAYOUT',
888
};
901
};
889
902
890
=head1 AUTHORS
903
=head1 AUTHORS
(-)a/t/db_dependent/Koha/Account.t (-3 / +30 lines)
Lines 1146-1152 subtest 'Koha::Account::pay() generates credit number (Koha::Account::Line->stor Link Here
1146
};
1146
};
1147
1147
1148
subtest 'Koha::Account::payout_amount() tests' => sub {
1148
subtest 'Koha::Account::payout_amount() tests' => sub {
1149
    plan tests => 21;
1149
    plan tests => 39;
1150
1150
1151
    $schema->storage->txn_begin;
1151
    $schema->storage->txn_begin;
1152
1152
Lines 1227-1238 subtest 'Koha::Account::payout_amount() tests' => sub { Link Here
1227
    is($credits->count, 1, "Payout was applied against oldest outstanding credits first");
1227
    is($credits->count, 1, "Payout was applied against oldest outstanding credits first");
1228
    is($credits->total_outstanding + 0, -10, "Total of 10 outstanding credit remaining");
1228
    is($credits->total_outstanding + 0, -10, "Total of 10 outstanding credit remaining");
1229
1229
1230
    my $offsets = Koha::Account::Offsets->search( { debit_id => $payout->id } );
1231
    is( $offsets->count, 4, 'Four offsets generated' );
1232
    my $offset = $offsets->next;
1233
    is( $offset->type, 'PAYOUT', 'PAYOUT offset added for payout line' );
1234
    is( $offset->amount * 1, 10, 'Correct offset amount recorded' );
1235
    $offset = $offsets->next;
1236
    is( $offset->credit_id, $credit_1->id, "Offset added against credit_1");
1237
    is( $offset->type,       'PAYOUT', "PAYOUT used for offset_type" );
1238
    is( $offset->amount * 1, -2,      'Correct amount offset against credit_1' );
1239
    $offset = $offsets->next;
1240
    is( $offset->credit_id, $credit_2->id, "Offset added against credit_2");
1241
    is( $offset->type,       'PAYOUT', "PAYOUT used for offset_type" );
1242
    is( $offset->amount * 1, -3,      'Correct amount offset against credit_2' );
1243
    $offset = $offsets->next;
1244
    is( $offset->credit_id, $credit_3->id, "Offset added against credit_3");
1245
    is( $offset->type,       'PAYOUT', "PAYOUT used for offset_type" );
1246
    is( $offset->amount * 1, -5,      'Correct amount offset against credit_3' );
1247
1230
    my $credit_5 = $account->add_credit( { amount => 5, interface => 'commandline' } );
1248
    my $credit_5 = $account->add_credit( { amount => 5, interface => 'commandline' } );
1231
    $credits = $account->outstanding_credits();
1249
    $credits = $account->outstanding_credits();
1232
    is($credits->count, 2, "New credit added");
1250
    is($credits->count, 2, "New credit added");
1233
    $payout_params->{amount} = 2.50;
1251
    $payout_params->{amount} = 2.50;
1234
    $payout_params->{credits} = [$credit_5];
1252
    $payout_params->{credits} = [$credit_5];
1235
    $account->payout_amount($payout_params);
1253
    $payout = $account->payout_amount($payout_params);
1236
1254
1237
    $credits = $account->outstanding_credits();
1255
    $credits = $account->outstanding_credits();
1238
    is($credits->count, 2, "Second credit not fully paid off");
1256
    is($credits->count, 2, "Second credit not fully paid off");
Lines 1242-1246 subtest 'Koha::Account::payout_amount() tests' => sub { Link Here
1242
    is($credit_4->amountoutstanding + 0, -10, "Credit 4 unaffected when credit_5 was passed to payout_amount");
1260
    is($credit_4->amountoutstanding + 0, -10, "Credit 4 unaffected when credit_5 was passed to payout_amount");
1243
    is($credit_5->amountoutstanding + 0, -2.50, "Credit 5 correctly reduced when payout_amount called with credit_5 passed");
1261
    is($credit_5->amountoutstanding + 0, -2.50, "Credit 5 correctly reduced when payout_amount called with credit_5 passed");
1244
1262
1263
    $offsets = Koha::Account::Offsets->search( { debit_id => $payout->id } );
1264
    is( $offsets->count, 2, 'Two offsets generated' );
1265
    $offset = $offsets->next;
1266
    is( $offset->type, 'PAYOUT', 'PAYOUT offset added for payout line' );
1267
    is( $offset->amount * 1, 2.50, 'Correct offset amount recorded' );
1268
    $offset = $offsets->next;
1269
    is( $offset->credit_id, $credit_5->id, "Offset added against credit_5");
1270
    is( $offset->type,       'PAYOUT', "PAYOUT used for offset_type" );
1271
    is( $offset->amount * 1, -2.50,      'Correct amount offset against credit_5' );
1272
1245
    $schema->storage->txn_rollback;
1273
    $schema->storage->txn_rollback;
1246
};
1274
};
1247
- 

Return to bug 24300