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

(-)a/C4/Accounts.pm (-5 / +5 lines)
Lines 90-98 sub chargelostitem { Link Here
90
    # first make sure the borrower hasn't already been charged for this item (for this issuance)
90
    # first make sure the borrower hasn't already been charged for this item (for this issuance)
91
    my $existing_charges = $account->lines->search(
91
    my $existing_charges = $account->lines->search(
92
        {
92
        {
93
            itemnumber     => $itemnumber,
93
            itemnumber      => $itemnumber,
94
            accounttype    => 'LOST',
94
            debit_type_code => 'LOST',
95
            issue_id       => $issue_id
95
            issue_id        => $issue_id
96
        }
96
        }
97
    )->count();
97
    )->count();
98
98
Lines 174-180 sub manualinvoice { Link Here
174
            date              => \'NOW()',
174
            date              => \'NOW()',
175
            amount            => $amount,
175
            amount            => $amount,
176
            description       => $desc,
176
            description       => $desc,
177
            accounttype       => $type,
177
            debit_type_code   => $type,
178
            amountoutstanding => $amountleft,
178
            amountoutstanding => $amountleft,
179
            itemnumber        => $itemnum || undef,
179
            itemnumber        => $itemnum || undef,
180
            issue_id          => $issue_id,
180
            issue_id          => $issue_id,
Lines 199-205 sub manualinvoice { Link Here
199
            borrowernumber    => $borrowernumber,
199
            borrowernumber    => $borrowernumber,
200
            amount            => $amount,
200
            amount            => $amount,
201
            description       => $desc,
201
            description       => $desc,
202
            accounttype       => $type,
202
            debit_type_code   => $type,
203
            amountoutstanding => $amountleft,
203
            amountoutstanding => $amountleft,
204
            note              => $note,
204
            note              => $note,
205
            itemnumber        => $itemnum,
205
            itemnumber        => $itemnum,
(-)a/C4/Circulation.pm (-7 / +7 lines)
Lines 2347-2356 sub _FixOverduesOnReturn { Link Here
2347
            # check for overdue fine
2347
            # check for overdue fine
2348
            my $accountlines = Koha::Account::Lines->search(
2348
            my $accountlines = Koha::Account::Lines->search(
2349
                {
2349
                {
2350
                    borrowernumber => $borrowernumber,
2350
                    borrowernumber  => $borrowernumber,
2351
                    itemnumber     => $item,
2351
                    itemnumber      => $item,
2352
                    accounttype    => 'OVERDUE',
2352
                    debit_type_code => 'OVERDUE',
2353
                    status         => 'UNRETURNED'
2353
                    status          => 'UNRETURNED'
2354
                }
2354
                }
2355
            );
2355
            );
2356
            return 0 unless $accountlines->count; # no warning, there's just nothing to fix
2356
            return 0 unless $accountlines->count; # no warning, there's just nothing to fix
Lines 2411-2419 sub _FixAccountForLostAndReturned { Link Here
2411
    # check for charge made for lost book
2411
    # check for charge made for lost book
2412
    my $accountlines = Koha::Account::Lines->search(
2412
    my $accountlines = Koha::Account::Lines->search(
2413
        {
2413
        {
2414
            itemnumber  => $itemnumber,
2414
            itemnumber      => $itemnumber,
2415
            accounttype => 'LOST',
2415
            debit_type_code => 'LOST',
2416
            status      => [ undef, { '<>' => 'RETURNED' } ]
2416
            status          => [ undef, { '<>' => 'RETURNED' } ]
2417
        },
2417
        },
2418
        {
2418
        {
2419
            order_by => { -desc => [ 'date', 'accountlines_id' ] }
2419
            order_by => { -desc => [ 'date', 'accountlines_id' ] }
(-)a/C4/Overdues.pm (-3 / +3 lines)
Lines 523-529 sub UpdateFine { Link Here
523
    my $overdues = Koha::Account::Lines->search(
523
    my $overdues = Koha::Account::Lines->search(
524
        {
524
        {
525
            borrowernumber    => $borrowernumber,
525
            borrowernumber    => $borrowernumber,
526
            accounttype       => [ 'OVERDUE', 'M' ],
526
            debit_type_code   => [ 'OVERDUE', 'M' ],
527
            amountoutstanding => { '<>' => 0 }
527
            amountoutstanding => { '<>' => 0 }
528
        }
528
        }
529
    );
529
    );
Lines 637-643 sub GetFine { Link Here
637
    my ( $itemnum, $borrowernumber ) = @_;
637
    my ( $itemnum, $borrowernumber ) = @_;
638
    my $dbh   = C4::Context->dbh();
638
    my $dbh   = C4::Context->dbh();
639
    my $query = q|SELECT sum(amountoutstanding) as fineamount FROM accountlines
639
    my $query = q|SELECT sum(amountoutstanding) as fineamount FROM accountlines
640
    where accounttype like 'OVERDUE'
640
    WHERE debit_type_code LIKE 'OVERDUE'
641
  AND amountoutstanding > 0 AND borrowernumber=?|;
641
  AND amountoutstanding > 0 AND borrowernumber=?|;
642
    my @query_param;
642
    my @query_param;
643
    push @query_param, $borrowernumber;
643
    push @query_param, $borrowernumber;
Lines 728-734 sub GetOverduesForBranch { Link Here
728
    LEFT JOIN itemtypes   ON itemtypes.itemtype       = $itype_link
728
    LEFT JOIN itemtypes   ON itemtypes.itemtype       = $itype_link
729
    LEFT JOIN branches    ON  branches.branchcode     = issues.branchcode
729
    LEFT JOIN branches    ON  branches.branchcode     = issues.branchcode
730
    WHERE (accountlines.amountoutstanding  != '0.000000')
730
    WHERE (accountlines.amountoutstanding  != '0.000000')
731
      AND (accountlines.accounttype         = 'OVERDUE' )
731
      AND (accountlines.debit_type_code     = 'OVERDUE' )
732
      AND (accountlines.status              = 'UNRETURNED' )
732
      AND (accountlines.status              = 'UNRETURNED' )
733
      AND (issues.branchcode =  ?   )
733
      AND (issues.branchcode =  ?   )
734
      AND (issues.date_due  < NOW())
734
      AND (issues.date_due  < NOW())
(-)a/Koha/Account.pm (-40 / +41 lines)
Lines 115-122 sub pay { Link Here
115
        # Same logic exists in Koha::Account::Line::apply
115
        # Same logic exists in Koha::Account::Line::apply
116
        if (   $new_amountoutstanding == 0
116
        if (   $new_amountoutstanding == 0
117
            && $fine->itemnumber
117
            && $fine->itemnumber
118
            && $fine->accounttype
118
            && $fine->debit_type_code
119
            && ( $fine->accounttype eq 'LOST' ) )
119
            && ( $fine->debit_type_code eq 'LOST' ) )
120
        {
120
        {
121
            C4::Circulation::ReturnLostItem( $self->{patron_id}, $fine->itemnumber );
121
            C4::Circulation::ReturnLostItem( $self->{patron_id}, $fine->itemnumber );
122
        }
122
        }
Lines 174-181 sub pay { Link Here
174
174
175
        if (   $fine->amountoutstanding == 0
175
        if (   $fine->amountoutstanding == 0
176
            && $fine->itemnumber
176
            && $fine->itemnumber
177
            && $fine->accounttype
177
            && $fine->debit_type_code
178
            && ( $fine->accounttype eq 'LOST' ) )
178
            && ( $fine->debit_type_code eq 'LOST' ) )
179
        {
179
        {
180
            C4::Circulation::ReturnLostItem( $self->{patron_id}, $fine->itemnumber );
180
            C4::Circulation::ReturnLostItem( $self->{patron_id}, $fine->itemnumber );
181
        }
181
        }
Lines 444-462 my $debit_line = Koha::Account->new({ patron_id => $patron_id })->add_debit( Link Here
444
);
444
);
445
445
446
$debit_type can be any of:
446
$debit_type can be any of:
447
  - overdue
448
  - lost_item
449
  - new_card
450
  - account
447
  - account
451
  - account_renew
448
  - account_renew
449
  - hold_expired
450
  - lost_item
452
  - sundry
451
  - sundry
452
  - new_card
453
  - overdue
453
  - processing
454
  - processing
454
  - rent
455
  - rent
455
  - rent_daily
456
  - rent_daily
456
  - rent_renewal
457
  - rent_renew
457
  - rent_daily_renewal
458
  - rent_daily_renew
458
  - reserve
459
  - reserve
459
  - manual
460
  - manual_debit
460
461
461
=cut
462
=cut
462
463
Lines 465-491 sub add_debit { Link Here
465
    my ( $self, $params ) = @_;
466
    my ( $self, $params ) = @_;
466
467
467
    # amount should always be a positive value
468
    # amount should always be a positive value
468
    my $amount       = $params->{amount};
469
    my $amount = $params->{amount};
469
470
470
    unless ( $amount > 0 ) {
471
    unless ( $amount > 0 ) {
471
        Koha::Exceptions::Account::AmountNotPositive->throw(
472
        Koha::Exceptions::Account::AmountNotPositive->throw(
472
            error => 'Debit amount passed is not positive'
473
            error => 'Debit amount passed is not positive' );
473
        );
474
    }
474
    }
475
475
476
    my $description  = $params->{description} // q{};
476
    my $description = $params->{description} // q{};
477
    my $note         = $params->{note} // q{};
477
    my $note        = $params->{note} // q{};
478
    my $user_id      = $params->{user_id};
478
    my $user_id     = $params->{user_id};
479
    my $interface    = $params->{interface};
479
    my $interface   = $params->{interface};
480
    my $library_id   = $params->{library_id};
480
    my $library_id  = $params->{library_id};
481
    my $type         = $params->{type};
481
    my $type        = $params->{type};
482
    my $item_id      = $params->{item_id};
482
    my $item_id     = $params->{item_id};
483
    my $issue_id     = $params->{issue_id};
483
    my $issue_id    = $params->{issue_id};
484
484
485
    unless ( $interface ) {
485
    unless ($interface) {
486
        Koha::Exceptions::MissingParameter->throw(
486
        Koha::Exceptions::MissingParameter->throw(
487
            error => 'The interface parameter is mandatory'
487
            error => 'The interface parameter is mandatory' );
488
        );
489
    }
488
    }
490
489
491
    my $schema = Koha::Database->new->schema;
490
    my $schema = Koha::Database->new->schema;
Lines 496-515 sub add_debit { Link Here
496
        );
495
        );
497
    }
496
    }
498
497
499
    my $account_type = $Koha::Account::account_type_debit->{$type};
498
    my $debit_type_code = $Koha::Account::account_type_debit->{$type};
500
499
501
    my $line;
500
    my $line;
502
503
    $schema->txn_do(
501
    $schema->txn_do(
504
        sub {
502
        sub {
505
503
506
            # Insert the account line
504
            # Insert the account line
507
            $line = Koha::Account::Line->new(
505
            $line = Koha::Account::Line->new(
508
                {   borrowernumber    => $self->{patron_id},
506
                {
507
                    borrowernumber    => $self->{patron_id},
509
                    date              => \'NOW()',
508
                    date              => \'NOW()',
510
                    amount            => $amount,
509
                    amount            => $amount,
511
                    description       => $description,
510
                    description       => $description,
512
                    accounttype       => $account_type,
511
                    debit_type_code   => $debit_type_code,
513
                    amountoutstanding => $amount,
512
                    amountoutstanding => $amount,
514
                    payment_type      => undef,
513
                    payment_type      => undef,
515
                    note              => $note,
514
                    note              => $note,
Lines 518-532 sub add_debit { Link Here
518
                    itemnumber        => $item_id,
517
                    itemnumber        => $item_id,
519
                    issue_id          => $issue_id,
518
                    issue_id          => $issue_id,
520
                    branchcode        => $library_id,
519
                    branchcode        => $library_id,
521
                    ( $type eq 'overdue' ? ( status => 'UNRETURNED' ) : ()),
520
                    ( $type eq 'overdue' ? ( status => 'UNRETURNED' ) : () ),
522
                }
521
                }
523
            )->store();
522
            )->store();
524
523
525
            # Record the account offset
524
            # Record the account offset
526
            my $account_offset = Koha::Account::Offset->new(
525
            my $account_offset = Koha::Account::Offset->new(
527
                {   debit_id => $line->id,
526
                {
528
                    type      => $Koha::Account::offset_type->{$type},
527
                    debit_id => $line->id,
529
                    amount    => $amount
528
                    type     => $Koha::Account::offset_type->{$type},
529
                    amount   => $amount
530
                }
530
                }
531
            )->store();
531
            )->store();
532
532
Lines 535-546 sub add_debit { Link Here
535
                    "FINES", 'CREATE',
535
                    "FINES", 'CREATE',
536
                    $self->{patron_id},
536
                    $self->{patron_id},
537
                    Dumper(
537
                    Dumper(
538
                        {   action            => "create_$type",
538
                        {
539
                            action            => "create_$type",
539
                            borrowernumber    => $self->{patron_id},
540
                            borrowernumber    => $self->{patron_id},
540
                            amount            => $amount,
541
                            amount            => $amount,
541
                            description       => $description,
542
                            description       => $description,
542
                            amountoutstanding => $amount,
543
                            amountoutstanding => $amount,
543
                            accounttype       => $account_type,
544
                            debit_type_code   => $debit_type_code,
544
                            note              => $note,
545
                            note              => $note,
545
                            itemnumber        => $item_id,
546
                            itemnumber        => $item_id,
546
                            manager_id        => $user_id,
547
                            manager_id        => $user_id,
Lines 636-648 sub non_issues_charges { Link Here
636
    push @not_fines, ( 'RENT', 'RENT_DAILY', 'RENT_RENEW', 'RENT_DAILY_RENEW' )
637
    push @not_fines, ( 'RENT', 'RENT_DAILY', 'RENT_RENEW', 'RENT_DAILY_RENEW' )
637
      unless C4::Context->preference('RentalsInNoissuesCharge');
638
      unless C4::Context->preference('RentalsInNoissuesCharge');
638
    unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
639
    unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
639
        my @man_inv = Koha::Account::DebitTypes->search({ system => 0 })->get_column('code');
640
        my @man_inv = Koha::Account::DebitTypes->search({ is_system => 0 })->get_column('code');
640
        push @not_fines, @man_inv;
641
        push @not_fines, @man_inv;
641
    }
642
    }
642
643
643
    return $self->lines->search(
644
    return $self->lines->search(
644
        {
645
        {
645
            debit_type => { -not_in => \@not_fines }
646
            debit_type_code => { -not_in => \@not_fines }
646
        },
647
        },
647
    )->total_outstanding;
648
    )->total_outstanding;
648
}
649
}
Lines 741-758 our $account_type_credit = { Link Here
741
our $account_type_debit = {
742
our $account_type_debit = {
742
    'account'          => 'ACCOUNT',
743
    'account'          => 'ACCOUNT',
743
    'account_renew'    => 'ACCOUNT_RENEW',
744
    'account_renew'    => 'ACCOUNT_RENEW',
744
    'overdue'          => 'OVERDUE',
745
    'hold_expired'     => 'HE',
745
    'lost_item'        => 'LOST',
746
    'lost_item'        => 'LOST',
746
    'new_card'         => 'N',
747
    'sundry'           => 'M',
747
    'sundry'           => 'M',
748
    'new_card'         => 'N',
749
    'overdue'          => 'OVERDUE',
748
    'processing'       => 'PF',
750
    'processing'       => 'PF',
749
    'rent'             => 'RENT',
751
    'rent'             => 'RENT',
750
    'rent_daily'       => 'RENT_DAILY',
752
    'rent_daily'       => 'RENT_DAILY',
751
    'rent_renew'       => 'RENT_RENEW',
753
    'rent_renew'       => 'RENT_RENEW',
752
    'rent_daily_renew' => 'RENT_DAILY_RENEW',
754
    'rent_daily_renew' => 'RENT_DAILY_RENEW',
753
    'reserve'          => 'Res',
755
    'reserve'          => 'Res',
754
    'manual_debit'     => 'M',
756
    'manual_debit'     => 'M'
755
    'hold_expired'     => 'HE'
756
};
757
};
757
758
758
=head1 AUTHORS
759
=head1 AUTHORS
(-)a/Koha/Account/Line.pm (-9 / +9 lines)
Lines 252-259 sub apply { Link Here
252
            # Same logic exists in Koha::Account::pay
252
            # Same logic exists in Koha::Account::pay
253
            if (   $debit->amountoutstanding == 0
253
            if (   $debit->amountoutstanding == 0
254
                && $debit->itemnumber
254
                && $debit->itemnumber
255
                && $debit->accounttype
255
                && $debit->debit_type_code
256
                && $debit->accounttype eq 'LOST' )
256
                && $debit->debit_type_code eq 'LOST' )
257
            {
257
            {
258
                C4::Circulation::ReturnLostItem( $self->borrowernumber, $debit->itemnumber );
258
                C4::Circulation::ReturnLostItem( $self->borrowernumber, $debit->itemnumber );
259
            }
259
            }
Lines 300-320 sub adjust { Link Here
300
        );
300
        );
301
    }
301
    }
302
302
303
    my $account_type   = $self->accounttype;
303
    my $debit_type_code = $self->debit_type_code;
304
    my $account_status = $self->status;
304
    my $account_status  = $self->status;
305
    unless (
305
    unless (
306
        (
306
        (
307
            exists(
307
            exists(
308
                $Koha::Account::Line::allowed_update->{$update_type}
308
                $Koha::Account::Line::allowed_update->{$update_type}
309
                  ->{$account_type}
309
                  ->{$debit_type_code}
310
            )
310
            )
311
            && ( $Koha::Account::Line::allowed_update->{$update_type}
311
            && ( $Koha::Account::Line::allowed_update->{$update_type}
312
                ->{$account_type} eq $account_status )
312
                ->{$debit_type_code} eq $account_status )
313
        )
313
        )
314
      )
314
      )
315
    {
315
    {
316
        Koha::Exceptions::Account::UnrecognisedType->throw(
316
        Koha::Exceptions::Account::UnrecognisedType->throw(
317
            error => 'Update type not allowed on this accounttype' );
317
            error => 'Update type not allowed on this debit_type' );
318
    }
318
    }
319
319
320
    my $schema = Koha::Database->new->schema;
320
    my $schema = Koha::Database->new->schema;
Lines 327-333 sub adjust { Link Here
327
            my $difference                = $amount - $amount_before;
327
            my $difference                = $amount - $amount_before;
328
            my $new_outstanding           = $amount_outstanding_before + $difference;
328
            my $new_outstanding           = $amount_outstanding_before + $difference;
329
329
330
            my $offset_type = $account_type;
330
            my $offset_type = $debit_type_code;
331
            $offset_type .= ( $difference > 0 ) ? "_INCREASE" : "_DECREASE";
331
            $offset_type .= ( $difference > 0 ) ? "_INCREASE" : "_DECREASE";
332
332
333
            # Catch cases that require patron refunds
333
            # Catch cases that require patron refunds
Lines 374-380 sub adjust { Link Here
374
                            amount            => $amount,
374
                            amount            => $amount,
375
                            description       => undef,
375
                            description       => undef,
376
                            amountoutstanding => $new_outstanding,
376
                            amountoutstanding => $new_outstanding,
377
                            accounttype       => $self->accounttype,
377
                            debit_type_code   => $self->debit_type_code,
378
                            note              => undef,
378
                            note              => undef,
379
                            itemnumber        => $self->itemnumber,
379
                            itemnumber        => $self->itemnumber,
380
                            manager_id        => undef,
380
                            manager_id        => undef,
(-)a/Koha/Schema/Result/AcDebitTypesBranch.pm (-4 / +4 lines)
Lines 28-34 __PACKAGE__->table("ac_debit_types_branches"); Link Here
28
  data_type: 'varchar'
28
  data_type: 'varchar'
29
  is_foreign_key: 1
29
  is_foreign_key: 1
30
  is_nullable: 1
30
  is_nullable: 1
31
  size: 16
31
  size: 64
32
32
33
=head2 branchcode
33
=head2 branchcode
34
34
Lines 41-47 __PACKAGE__->table("ac_debit_types_branches"); Link Here
41
41
42
__PACKAGE__->add_columns(
42
__PACKAGE__->add_columns(
43
  "debit_type_code",
43
  "debit_type_code",
44
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 16 },
44
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 64 },
45
  "branchcode",
45
  "branchcode",
46
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
46
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
47
);
47
);
Lines 89-96 __PACKAGE__->belongs_to( Link Here
89
);
89
);
90
90
91
91
92
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-09-26 15:59:23
92
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-04 07:57:30
93
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:y7zhbS7uj5zRCOskakhzLA
93
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:uVA4axnWjQjFOPqvM0hqyw
94
94
95
95
96
# You can replace this text with custom code or comments, and it will be preserved on regeneration
96
# You can replace this text with custom code or comments, and it will be preserved on regeneration
(-)a/Koha/Schema/Result/AccountDebitType.pm (-13 / +21 lines)
Lines 27-39 __PACKAGE__->table("account_debit_types"); Link Here
27
27
28
  data_type: 'varchar'
28
  data_type: 'varchar'
29
  is_nullable: 0
29
  is_nullable: 0
30
  size: 16
30
  size: 64
31
32
=head2 default_amount
33
34
  data_type: 'decimal'
35
  is_nullable: 1
36
  size: [28,6]
37
31
38
=head2 description
32
=head2 description
39
33
Lines 47-63 __PACKAGE__->table("account_debit_types"); Link Here
47
  default_value: 1
41
  default_value: 1
48
  is_nullable: 0
42
  is_nullable: 0
49
43
44
=head2 default_amount
45
46
  data_type: 'decimal'
47
  is_nullable: 1
48
  size: [28,6]
49
50
=head2 is_system
51
52
  data_type: 'tinyint'
53
  default_value: 0
54
  is_nullable: 0
55
50
=cut
56
=cut
51
57
52
__PACKAGE__->add_columns(
58
__PACKAGE__->add_columns(
53
  "code",
59
  "code",
54
  { data_type => "varchar", is_nullable => 0, size => 16 },
60
  { data_type => "varchar", is_nullable => 0, size => 64 },
55
  "default_amount",
56
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
57
  "description",
61
  "description",
58
  { data_type => "varchar", is_nullable => 1, size => 200 },
62
  { data_type => "varchar", is_nullable => 1, size => 200 },
59
  "can_be_added_manually",
63
  "can_be_added_manually",
60
  { data_type => "tinyint", default_value => 1, is_nullable => 0 },
64
  { data_type => "tinyint", default_value => 1, is_nullable => 0 },
65
  "default_amount",
66
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
67
  "is_system",
68
  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
61
);
69
);
62
70
63
=head1 PRIMARY KEY
71
=head1 PRIMARY KEY
Lines 100-112 Related object: L<Koha::Schema::Result::Accountline> Link Here
100
__PACKAGE__->has_many(
108
__PACKAGE__->has_many(
101
  "accountlines",
109
  "accountlines",
102
  "Koha::Schema::Result::Accountline",
110
  "Koha::Schema::Result::Accountline",
103
  { "foreign.debit_type" => "self.code" },
111
  { "foreign.debit_type_code" => "self.code" },
104
  { cascade_copy => 0, cascade_delete => 0 },
112
  { cascade_copy => 0, cascade_delete => 0 },
105
);
113
);
106
114
107
115
108
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-09-26 15:59:23
116
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-08 11:15:31
109
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jMTwuzzf39606BEjXzPGng
117
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:a3+iyqpi4NVpNjDkr9HM/w
110
118
111
119
112
# You can replace this text with custom code or comments, and it will be preserved on regeneration
120
# You can replace this text with custom code or comments, and it will be preserved on regeneration
(-)a/Koha/Schema/Result/Accountline.pm (-9 / +9 lines)
Lines 69-80 __PACKAGE__->table("accountlines"); Link Here
69
  is_nullable: 1
69
  is_nullable: 1
70
  size: 80
70
  size: 80
71
71
72
=head2 debit_type
72
=head2 debit_type_code
73
73
74
  data_type: 'varchar'
74
  data_type: 'varchar'
75
  is_foreign_key: 1
75
  is_foreign_key: 1
76
  is_nullable: 1
76
  is_nullable: 1
77
  size: 16
77
  size: 64
78
78
79
=head2 status
79
=head2 status
80
80
Lines 150-157 __PACKAGE__->add_columns( Link Here
150
  { data_type => "longtext", is_nullable => 1 },
150
  { data_type => "longtext", is_nullable => 1 },
151
  "accounttype",
151
  "accounttype",
152
  { data_type => "varchar", is_nullable => 1, size => 80 },
152
  { data_type => "varchar", is_nullable => 1, size => 80 },
153
  "debit_type",
153
  "debit_type_code",
154
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 16 },
154
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 64 },
155
  "status",
155
  "status",
156
  { data_type => "varchar", is_nullable => 1, size => 16 },
156
  { data_type => "varchar", is_nullable => 1, size => 16 },
157
  "payment_type",
157
  "payment_type",
Lines 261-267 __PACKAGE__->belongs_to( Link Here
261
  },
261
  },
262
);
262
);
263
263
264
=head2 debit_type
264
=head2 debit_type_code
265
265
266
Type: belongs_to
266
Type: belongs_to
267
267
Lines 270-278 Related object: L<Koha::Schema::Result::AccountDebitType> Link Here
270
=cut
270
=cut
271
271
272
__PACKAGE__->belongs_to(
272
__PACKAGE__->belongs_to(
273
  "debit_type",
273
  "debit_type_code",
274
  "Koha::Schema::Result::AccountDebitType",
274
  "Koha::Schema::Result::AccountDebitType",
275
  { code => "debit_type" },
275
  { code => "debit_type_code" },
276
  {
276
  {
277
    is_deferrable => 1,
277
    is_deferrable => 1,
278
    join_type     => "LEFT",
278
    join_type     => "LEFT",
Lines 342-349 __PACKAGE__->belongs_to( Link Here
342
);
342
);
343
343
344
344
345
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-09-26 15:59:23
345
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-08 11:15:31
346
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:d0RP5LSuBHb3UF0Fcof11g
346
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1Vgkg0JR7RqmkniOmUoUhQ
347
347
348
sub koha_objects_class {
348
sub koha_objects_class {
349
    'Koha::Account::Lines';
349
    'Koha::Account::Lines';
(-)a/catalogue/moredetail.pl (-1 / +1 lines)
Lines 179-185 foreach my $item (@items){ Link Here
179
        my $accountlines = Koha::Account::Lines->search(
179
        my $accountlines = Koha::Account::Lines->search(
180
            {
180
            {
181
                itemnumber        => $item->{itemnumber},
181
                itemnumber        => $item->{itemnumber},
182
                accounttype       => 'LOST',
182
                debit_type_code   => 'LOST',
183
                status            => [ undef, { '<>' => 'RETURNED' } ],
183
                status            => [ undef, { '<>' => 'RETURNED' } ],
184
                amountoutstanding => 0
184
                amountoutstanding => 0
185
            },
185
            },
(-)a/installer/data/mysql/atomicupdate/bug_23049_debit.perl (-17 / +29 lines)
Lines 1-6 Link Here
1
$DBversion = 'XXX';    # will be replaced by the RM
1
$DBversion = 'XXX';    # will be replaced by the RM
2
if ( CheckVersion($DBversion) ) {
2
if ( CheckVersion($DBversion) ) {
3
3
4
    # Adding account_debit_types
4
    $dbh->do(
5
    $dbh->do(
5
        qq{
6
        qq{
6
            CREATE TABLE IF NOT EXISTS account_debit_types (
7
            CREATE TABLE IF NOT EXISTS account_debit_types (
Lines 14-19 if ( CheckVersion($DBversion) ) { Link Here
14
          }
15
          }
15
    );
16
    );
16
17
18
    # Adding ac_debit_types_branches
17
    $dbh->do(
19
    $dbh->do(
18
        qq{
20
        qq{
19
            CREATE TABLE IF NOT EXISTS ac_debit_types_branches (
21
            CREATE TABLE IF NOT EXISTS ac_debit_types_branches (
Lines 25-30 if ( CheckVersion($DBversion) ) { Link Here
25
        }
27
        }
26
    );
28
    );
27
29
30
    # Populating account_debit_types
28
    $dbh->do(
31
    $dbh->do(
29
        qq{
32
        qq{
30
            INSERT IGNORE INTO account_debit_types (
33
            INSERT IGNORE INTO account_debit_types (
Lines 51-56 if ( CheckVersion($DBversion) ) { Link Here
51
        }
54
        }
52
    );
55
    );
53
56
57
    # Moving MANUAL_INV to account_debit_types
54
    $dbh->do(
58
    $dbh->do(
55
        qq{
59
        qq{
56
            INSERT IGNORE INTO account_debit_types (
60
            INSERT IGNORE INTO account_debit_types (
Lines 73-107 if ( CheckVersion($DBversion) ) { Link Here
73
          }
77
          }
74
    );
78
    );
75
79
76
    $dbh->do(
80
    # Adding debit_type_code to accountlines
77
        qq{
81
    unless ( column_exists('accountlines', 'debit_type_code') ) {
78
            ALTER IGNORE TABLE accountlines
82
        $dbh->do(
79
            ADD
83
            qq{
80
              debit_type varchar(64) DEFAULT NULL
84
                ALTER IGNORE TABLE accountlines
81
            AFTER
85
                ADD
82
              accounttype
86
                  debit_type_code varchar(64) DEFAULT NULL
83
          }
87
                AFTER
84
    );
88
                  accounttype
89
              }
90
        );
91
    }
85
92
86
    $dbh->do(
93
    # Linking debit_type_code in accountlines to code in account_debit_types
87
        qq{
94
    unless ( foreign_key_exists( 'accountlines', 'accountlines_ibfk_debit_type' ) ) {
88
        ALTER TABLE accountlines ADD CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type`) REFERENCES `account_debit_types` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
95
        $dbh->do(
89
          }
96
            qq{
90
    );
97
            ALTER TABLE accountlines ADD CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type_code`) REFERENCES `account_debit_types` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
98
              }
99
        );
100
    }
91
101
102
    # Adding a check constraints to accountlines
92
    $dbh->do(
103
    $dbh->do(
93
        qq{
104
        qq{
94
        ALTER TABLE accountlines ADD CONSTRAINT `accountlines_check_type` CHECK (accounttype IS NOT NULL OR debit_type IS NOT NULL)
105
        ALTER TABLE accountlines ADD CONSTRAINT `accountlines_check_type` CHECK (accounttype IS NOT NULL OR debit_type_code IS NOT NULL)
95
        }
106
        }
96
    );
107
    );
97
108
109
    # Populating debit_type_code
98
    $dbh->do(
110
    $dbh->do(
99
        qq{
111
        qq{
100
        UPDATE accountlines SET debit_type = accounttype, accounttype = NULL WHERE accounttype IN (SELECT code from account_debit_types)
112
        UPDATE accountlines SET debit_type_code = accounttype, accounttype = NULL WHERE accounttype IN (SELECT code from account_debit_types)
101
        }
113
        }
102
    );
114
    );
103
115
104
    # Clean up MANUAL_INV
116
    # Remove MANUAL_INV
105
    $dbh->do(
117
    $dbh->do(
106
        qq{
118
        qq{
107
        DELETE FROM authorised_values WHERE category = 'MANUAL_INV'
119
        DELETE FROM authorised_values WHERE category = 'MANUAL_INV'
(-)a/installer/data/mysql/kohastructure.sql (-4 / +4 lines)
Lines 2661-2667 CREATE TABLE `accountlines` ( Link Here
2661
  `amount` decimal(28,6) default NULL,
2661
  `amount` decimal(28,6) default NULL,
2662
  `description` LONGTEXT,
2662
  `description` LONGTEXT,
2663
  `accounttype` varchar(80) default NULL,
2663
  `accounttype` varchar(80) default NULL,
2664
  `debit_type` varchar(64) default NULL,
2664
  `debit_type_code` varchar(64) default NULL,
2665
  `status` varchar(16) default NULL,
2665
  `status` varchar(16) default NULL,
2666
  `payment_type` varchar(80) default NULL, -- optional authorised value PAYMENT_TYPE
2666
  `payment_type` varchar(80) default NULL, -- optional authorised value PAYMENT_TYPE
2667
  `amountoutstanding` decimal(28,6) default NULL,
2667
  `amountoutstanding` decimal(28,6) default NULL,
Lines 2674-2690 CREATE TABLE `accountlines` ( Link Here
2674
  PRIMARY KEY (`accountlines_id`),
2674
  PRIMARY KEY (`accountlines_id`),
2675
  KEY `acctsborridx` (`borrowernumber`),
2675
  KEY `acctsborridx` (`borrowernumber`),
2676
  KEY `timeidx` (`timestamp`),
2676
  KEY `timeidx` (`timestamp`),
2677
  KEY `debit_type` (`debit_type`),
2677
  KEY `debit_type_code` (`debit_type_code`),
2678
  KEY `itemnumber` (`itemnumber`),
2678
  KEY `itemnumber` (`itemnumber`),
2679
  KEY `branchcode` (`branchcode`),
2679
  KEY `branchcode` (`branchcode`),
2680
  KEY `manager_id` (`manager_id`),
2680
  KEY `manager_id` (`manager_id`),
2681
  CONSTRAINT `accountlines_check_type` CHECK (accounttype IS NOT NULL OR debit_type IS NOT NULL),
2681
  CONSTRAINT `accountlines_check_type` CHECK (accounttype IS NOT NULL OR debit_type_code IS NOT NULL),
2682
  CONSTRAINT `accountlines_ibfk_borrowers` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2682
  CONSTRAINT `accountlines_ibfk_borrowers` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2683
  CONSTRAINT `accountlines_ibfk_items` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2683
  CONSTRAINT `accountlines_ibfk_items` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2684
  CONSTRAINT `accountlines_ibfk_borrowers_2` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2684
  CONSTRAINT `accountlines_ibfk_borrowers_2` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
2685
  CONSTRAINT `accountlines_ibfk_branches` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
2685
  CONSTRAINT `accountlines_ibfk_branches` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
2686
  CONSTRAINT `accountlines_ibfk_registers` FOREIGN KEY (`register_id`) REFERENCES `cash_registers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
2686
  CONSTRAINT `accountlines_ibfk_registers` FOREIGN KEY (`register_id`) REFERENCES `cash_registers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
2687
  CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type`) REFERENCES `account_debit_types` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
2687
  CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type_code`) REFERENCES `account_debit_types` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
2688
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2688
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2689
2689
2690
--
2690
--
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-print.tt (-1 / +1 lines)
Lines 121-127 Link Here
121
                          , [% account.description | html %]
121
                          , [% account.description | html %]
122
                      [% END %]
122
                      [% END %]
123
                      &nbsp;
123
                      &nbsp;
124
                      [% IF ( account.itemnumber AND account.accounttype != 'OVERDUE' ) %]
124
                      [% IF ( account.itemnumber AND account.debit_type_code != 'OVERDUE' ) %]
125
                          <a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% account.item.biblionumber | uri %]&amp;itemnumber=[% account.itemnumber | uri %]">[% account.item.biblio.title | html %]</a>
125
                          <a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% account.item.biblionumber | uri %]&amp;itemnumber=[% account.itemnumber | uri %]">[% account.item.biblio.title | html %]</a>
126
                      [% END %]
126
                      [% END %]
127
                  </td>
127
                  </td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt (-1 / +1 lines)
Lines 74-80 Link Here
74
    [% END %]
74
    [% END %]
75
    <input type="hidden" name="itemnumber[% line.accountlines_id | html %]" value="[% line.itemnumber | html %]" />
75
    <input type="hidden" name="itemnumber[% line.accountlines_id | html %]" value="[% line.itemnumber | html %]" />
76
    <input type="hidden" name="description[% line.accountlines_id | html %]" value="[% line.description | html %]" />
76
    <input type="hidden" name="description[% line.accountlines_id | html %]" value="[% line.description | html %]" />
77
    <input type="hidden" name="accounttype[% line.accountlines_id | html %]" value="[% line.accounttype | html %]" />
77
    <input type="hidden" name="debit_type_code[% line.accountlines_id | html %]" value="[% line.debit_type_code | html %]" />
78
    <input type="hidden" name="amount[% line.accountlines_id | html %]" value="[% line.amount | html %]" />
78
    <input type="hidden" name="amount[% line.accountlines_id | html %]" value="[% line.amount | html %]" />
79
    <input type="hidden" name="accountlines_id[% line.accountlines_id | html %]" value="[% line.accountlines_id | html %]" />
79
    <input type="hidden" name="accountlines_id[% line.accountlines_id | html %]" value="[% line.accountlines_id | html %]" />
80
    <input type="hidden" name="amountoutstanding[% line.accountlines_id | html %]" value="[% line.amountoutstanding | html %]" />
80
    <input type="hidden" name="amountoutstanding[% line.accountlines_id | html %]" value="[% line.amountoutstanding | html %]" />
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt (-4 / +4 lines)
Lines 73-79 Link Here
73
    <input type="hidden" name="pay_individual" id="pay_individual" value="[% pay_individual | html %]" />
73
    <input type="hidden" name="pay_individual" id="pay_individual" value="[% pay_individual | html %]" />
74
    <input type="hidden" name="itemnumber" id="itemnumber" value="[% itemnumber | html %]" />
74
    <input type="hidden" name="itemnumber" id="itemnumber" value="[% itemnumber | html %]" />
75
    <input type="hidden" name="description" id="description" value="[% description | html %]" />
75
    <input type="hidden" name="description" id="description" value="[% description | html %]" />
76
    <input type="hidden" name="accounttype" id="accounttype" value="[% accounttype | html %]" />
76
    <input type="hidden" name="debit_type_code" id="debit_type_code" value="[% debit_type_code | html %]" />
77
    <input type="hidden" name="amount" id="amount" value="[% amount | html %]" />
77
    <input type="hidden" name="amount" id="amount" value="[% amount | html %]" />
78
    <input type="hidden" name="amountoutstanding" id="amountoutstanding" value="[% amountoutstanding | html %]" />
78
    <input type="hidden" name="amountoutstanding" id="amountoutstanding" value="[% amountoutstanding | html %]" />
79
    <input type="hidden" name="accountlines_id" id="accountlines_id" value="[% accountlines_id | html %]" />
79
    <input type="hidden" name="accountlines_id" id="accountlines_id" value="[% accountlines_id | html %]" />
Lines 97-103 Link Here
97
            <td>
97
            <td>
98
                [% individual_description | html %]
98
                [% individual_description | html %]
99
            </td>
99
            </td>
100
            <td>[% accounttype | html %]</td>
100
            <td>[% debit_type_code | html %]</td>
101
            <td class="debit">[% amount | format('%.2f') %]</td>
101
            <td class="debit">[% amount | format('%.2f') %]</td>
102
            <td class="debit">[% amountoutstanding | format('%.2f') %]</td>
102
            <td class="debit">[% amountoutstanding | format('%.2f') %]</td>
103
        </tr></tbody>
103
        </tr></tbody>
Lines 161-167 Link Here
161
    <input type="hidden" name="pay_individual" id="pay_individual" value="[% pay_individual | html %]" />
161
    <input type="hidden" name="pay_individual" id="pay_individual" value="[% pay_individual | html %]" />
162
    <input type="hidden" name="itemnumber" id="itemnumber" value="[% itemnumber | html %]" />
162
    <input type="hidden" name="itemnumber" id="itemnumber" value="[% itemnumber | html %]" />
163
    <input type="hidden" name="description" id="description" value="[% description | html %]" />
163
    <input type="hidden" name="description" id="description" value="[% description | html %]" />
164
    <input type="hidden" name="accounttype" id="accounttype" value="[% accounttype | html %]" />
164
    <input type="hidden" name="debit_type_code" id="debit_type_code" value="[% debit_type_code | html %]" />
165
    <input type="hidden" name="amount" id="amount" value="[% amount | html %]" />
165
    <input type="hidden" name="amount" id="amount" value="[% amount | html %]" />
166
    <input type="hidden" name="accountlines_id" id="accountlines_id" value="[% accountlines_id | html %]" />
166
    <input type="hidden" name="accountlines_id" id="accountlines_id" value="[% accountlines_id | html %]" />
167
    <input type="hidden" name="title" id="title" value="[% title | html %]" />
167
    <input type="hidden" name="title" id="title" value="[% title | html %]" />
Lines 179-185 Link Here
179
    <tfoot><tr><td colspan="3">Total amount outstanding:</td><td>[% amountoutstanding | format('%.2f') %]</td></tr></tfoot>
179
    <tfoot><tr><td colspan="3">Total amount outstanding:</td><td>[% amountoutstanding | format('%.2f') %]</td></tr></tfoot>
180
    <tbody><tr>
180
    <tbody><tr>
181
            <td>[% description | html %] [% title | html %]</td>
181
            <td>[% description | html %] [% title | html %]</td>
182
            <td>[% accounttype | html %]</td>
182
            <td>[% debit_type_code | html %]</td>
183
            <td class="debit">[% amount | format('%.2f') %]</td>
183
            <td class="debit">[% amount | format('%.2f') %]</td>
184
            <td class="debit">[% amountoutstanding | format('%.2f') %]</td>
184
            <td class="debit">[% amountoutstanding | format('%.2f') %]</td>
185
        </tr></tbody>
185
        </tr></tbody>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cash_register_stats.tt (-66 / +6 lines)
Lines 4-9 Link Here
4
[% USE Price %]
4
[% USE Price %]
5
[% USE ItemTypes %]
5
[% USE ItemTypes %]
6
[% SET footerjs = 1 %]
6
[% SET footerjs = 1 %]
7
[% PROCESS 'accounts.inc' %]
7
[% INCLUDE 'doc-head-open.inc' %]
8
[% INCLUDE 'doc-head-open.inc' %]
8
<title>Koha &rsaquo; Reports [% IF ( do_it ) %]&rsaquo; Cash register statistics &rsaquo; Results[% ELSE %]&rsaquo; Cash register statistics[% END %]</title>
9
<title>Koha &rsaquo; Reports [% IF ( do_it ) %]&rsaquo; Cash register statistics &rsaquo; Results[% ELSE %]&rsaquo; Cash register statistics[% END %]</title>
9
[% INCLUDE 'doc-head-close.inc' %]
10
[% INCLUDE 'doc-head-close.inc' %]
Lines 78-131 Link Here
78
                        <option value="FORW">Write off</option>
79
                        <option value="FORW">Write off</option>
79
                        [% END %]
80
                        [% END %]
80
81
81
                        [% IF transaction_type == "F" %]
82
                        <option value="F" selected="selected">Fine</option>
83
                        [% ELSE %]
84
                        <option value="F">Fine</option>
85
                        [% END %]
86
87
                        [% IF transaction_type == "FU" %]
88
                        <option value="FU" selected="selected">Accruing fine</option>
89
                        [% ELSE %]
90
                        <option value="FU">Accruing fine</option>
91
                        [% END %]
92
93
                        [% IF transaction_type == "PAY" %]
82
                        [% IF transaction_type == "PAY" %]
94
                        <option value="PAY" selected="selected">Payment</option>
83
                        <option value="PAY" selected="selected">Payment</option>
95
                        [% ELSE %]
84
                        [% ELSE %]
96
                        <option value="PAY">Payment</option>
85
                        <option value="PAY">Payment</option>
97
                        [% END %]
86
                        [% END %]
98
87
99
                        [% IF transaction_type == "A" %]
88
                        [% FOREACH debit_type IN debit_types %]
100
                        <option value="A" selected="selected">Account management fee</option>
89
                            [% IF transaction_type == debit_type.code %]
101
                        [% ELSE %]
90
                            <option value="[% debit_type.code | html %]" selected="selected">[% debit_type.description | html %]</option>
102
                        <option value="A">Account management fee</option>
103
                        [% END %]
104
105
                        [% IF transaction_type == "M" %]
106
                        <option value="M" selected="selected">Sundry</option>
107
                        [% ELSE %]
108
                        <option value="M">Sundry</option>
109
                        [% END %]
110
111
                        [% IF transaction_type == "L" %]
112
                        <option value="L" selected="selected">Lost item</option>
113
                        [% ELSE %]
114
                        <option value="L">Lost item</option>
115
                        [% END %]
116
117
                        [% IF transaction_type == "N" %]
118
                        <option value="N" selected="selected">New card</option>
119
                        [% ELSE %]
120
                        <option value="N">New card</option>
121
                        [% END %]
122
123
                        [% FOREACH manualinv IN manualinv_types %]
124
                            [% value_manualinv = manualinv.authorised_value|truncate(5, '') %]
125
                            [% IF transaction_type == value_manualinv %]
126
                            <option value="[% value_manualinv | html %]" selected="selected">[% manualinv.authorised_value | html %]</option>
127
                            [% ELSE %]
91
                            [% ELSE %]
128
                            <option value="[% value_manualinv | html %]">[% manualinv.authorised_value | html %]</option>
92
                            <option value="[% debit_type.code | html %]">[% debit_type.description | html %]</option>
129
                            [% END %]
93
                            [% END %]
130
                        [% END %]
94
                        [% END %]
131
                    </select>
95
                    </select>
Lines 197-228 Link Here
197
                <td>
161
                <td>
198
                    [% IF loopresul.accounttype == "ACT" %]
162
                    [% IF loopresul.accounttype == "ACT" %]
199
                        <span>All payments to the library</span>
163
                        <span>All payments to the library</span>
200
                    [% ELSIF loopresul.accounttype == "C" || loopresul.accounttype == "CR" %]
201
                        <span>Credit</span>
202
                    [% ELSIF loopresul.accounttype == "FORW" || loopresul.accounttype == "W" %]
203
                        <span>Write off</span>
204
                    [% ELSIF loopresul.accounttype == "F" %]
205
                        <span>Fine</span>
206
                    [% ELSIF loopresul.accounttype == "FU" %]
207
                        <span>Accruing fine</span>
208
                    [% ELSIF loopresul.accounttype == "Pay" %]
209
                        <span>Payment</span>
210
                    [% ELSIF loopresul.accounttype == "A" %]
211
                        <span>Account management fee</span>
212
                    [% ELSIF loopresul.accounttype == "M" %]
213
                        <span>Sundry</span>
214
                    [% ELSIF loopresul.accounttype == "LOST" %]
215
                        <span>Lost item</span>
216
                    [% ELSIF loopresul.accounttype == "N" %]
217
                        <span>New card</span>
218
                    [% ELSE %]
164
                    [% ELSE %]
219
                        [% FOREACH manualinv IN manualinv_types %]
165
                        [%- PROCESS account_type_description account=loopresul -%]
220
                            [% value_manualinv = manualinv.authorised_value|truncate(5, '') %]
221
                            [% IF loopresul.accounttype == value_manualinv %]
222
                            <span>[% manualinv.authorised_value | html %]</span>
223
                            [% LAST %]
224
                            [% END %]
225
                        [% END %]
226
                    [% END %]
166
                    [% END %]
227
                </td>
167
                </td>
228
                <td>[% loopresul.note | html %]</td>
168
                <td>[% loopresul.note | html %]</td>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/account-table.inc (-24 / +31 lines)
Lines 170-200 Link Here
170
</form>
170
</form>
171
171
172
[%- BLOCK account_type_description -%]
172
[%- BLOCK account_type_description -%]
173
    [%- SWITCH account.accounttype -%]
173
    <span>
174
        [%- CASE 'Pay'              -%]<span>Payment
174
    [%- IF account.accounttype -%]
175
        [%- CASE 'VOID'             -%]<span>Voided
175
        [%- SWITCH account.accounttype -%]
176
        [%- CASE 'N'                -%]<span>New card
176
            [%- CASE 'Pay'              -%]Payment
177
        [%- CASE 'OVERDUE'          -%]<span>Fine
177
            [%- CASE 'W'                -%]Writeoff
178
        [%- CASE 'ACCOUNT'          -%]<span>Account creation fee
178
            [%- CASE 'FOR'              -%]Forgiven
179
        [%- CASE 'ACCOUNT_RENEW'    -%]<span>Account renewal fee
179
            [%- CASE 'PAY'              -%]Payment
180
        [%- CASE 'M'                -%]<span>Sundry
180
            [%- CASE 'WO'               -%]Writeoff
181
        [%- CASE 'LOST'             -%]<span>Lost item
181
            [%- CASE 'C'                -%]Credit
182
        [%- CASE 'W'                -%]<span>Writeoff
182
            [%- CASE 'LOST_RETURN'      -%]Lost item fee refund
183
        [%- CASE 'HE'               -%]<span>Hold waiting too long
183
            [%- CASE                    -%][% account.accounttype | html %]
184
        [%- CASE 'RENT'             -%]<span>Rental fee
184
        [%- END -%]
185
        [%- CASE 'RENT_DAILY'       -%]<span>Daily rental fee
185
    [%- ELSIF account.debit_type -%]
186
        [%- CASE 'RENT_RENEW'       -%]<span>Renewal of rental item
186
       [%- SWITCH account.debit_type -%]
187
        [%- CASE 'RENT_DAILT_RENEW' -%]<span>Renewal of dailt rental item
187
           [%- CASE 'ACCOUNT'          -%]Account creation fee
188
        [%- CASE 'FOR'              -%]<span>Forgiven
188
           [%- CASE 'ACCOUNT_RENEW'    -%]Account renewal fee
189
        [%- CASE 'PF'               -%]<span>Lost item processing fee
189
           [%- CASE 'HE'               -%]Hold waiting too long
190
        [%- CASE 'PAY'              -%]<span>Payment
190
           [%- CASE 'LOST'             -%]Lost item
191
        [%- CASE 'WO'               -%]<span>Writeoff
191
           [%- CASE 'M'                -%]Sundry
192
        [%- CASE 'C'                -%]<span>Credit
192
           [%- CASE 'N'                -%]New card
193
        [%- CASE 'LOST_RETURN'      -%]<span>Lost item fee refund
193
           [%- CASE 'OVERDUE'          -%]Fine
194
        [%- CASE 'Res'              -%]<span>Hold fee
194
           [%- CASE 'PF'               -%]Lost item processing fee
195
        [%- CASE                    -%]<span>[% account.accounttype | html %]
195
           [%- CASE 'RENT'             -%]Rental fee
196
           [%- CASE 'RENT_DAILY'       -%]Daily rental fee
197
           [%- CASE 'RENT_RENEW'       -%]Renewal of rental item
198
           [%- CASE 'RENT_DAILY_RENEW' -%]Rewewal of daily rental item
199
           [%- CASE 'Res'              -%]Hold fee
200
           [%- CASE                    -%][% account.debit_type.description | html %]
201
       [%- END -%]
196
    [%- END -%]
202
    [%- END -%]
197
    [%- PROCESS account_status_description account=account -%]</span>
203
    [%- PROCESS account_status_description account=account -%]
204
    </span>
198
[%- END -%]
205
[%- END -%]
199
206
200
[%- BLOCK account_status_description -%]
207
[%- BLOCK account_status_description -%]
(-)a/members/pay.pl (-2 / +2 lines)
Lines 104-110 elsif ( $input->param('confirm_writeoff') ) { Link Here
104
              . "borrowernumber=$borrowernumber"
104
              . "borrowernumber=$borrowernumber"
105
              . "&amount=" . $accountline->amount
105
              . "&amount=" . $accountline->amount
106
              . "&amountoutstanding=" . $accountline->amountoutstanding
106
              . "&amountoutstanding=" . $accountline->amountoutstanding
107
              . "&accounttype=" . $accountline->accounttype
107
              . "&debit_type_code=" . $accountline->debit_type_code
108
              . "&accountlines_id=" . $accountlines_id
108
              . "&accountlines_id=" . $accountlines_id
109
              . "&change_given=" . $change_given
109
              . "&change_given=" . $change_given
110
              . "&writeoff_individual=1"
110
              . "&writeoff_individual=1"
Lines 191-197 sub redirect_to_paycollect { Link Here
191
      "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber";
191
      "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber";
192
    $redirect .= q{&};
192
    $redirect .= q{&};
193
    $redirect .= "$action=1";
193
    $redirect .= "$action=1";
194
    $redirect .= get_for_redirect( 'accounttype', "accounttype$line_no", 0 );
194
    $redirect .= get_for_redirect( 'debit_type_code', "debit_type_code$line_no", 0 );
195
    $redirect .= get_for_redirect( 'amount', "amount$line_no", 1 );
195
    $redirect .= get_for_redirect( 'amount', "amount$line_no", 1 );
196
    $redirect .=
196
    $redirect .=
197
      get_for_redirect( 'amountoutstanding', "amountoutstanding$line_no", 1 );
197
      get_for_redirect( 'amountoutstanding', "amountoutstanding$line_no", 1 );
(-)a/members/paycollect.pl (-3 / +3 lines)
Lines 109-116 if ( $pay_individual || $writeoff_individual ) { Link Here
109
    } elsif ($writeoff_individual) {
109
    } elsif ($writeoff_individual) {
110
        $template->param( writeoff_individual => 1 );
110
        $template->param( writeoff_individual => 1 );
111
    }
111
    }
112
    my $accounttype       = $input->param('accounttype');
112
    my $debit_type_code   = $input->param('debit_type_code');
113
    $accountlines_id       = $input->param('accountlines_id');
113
    $accountlines_id      = $input->param('accountlines_id');
114
    my $amount            = $input->param('amount');
114
    my $amount            = $input->param('amount');
115
    my $amountoutstanding = $input->param('amountoutstanding');
115
    my $amountoutstanding = $input->param('amountoutstanding');
116
    my $itemnumber  = $input->param('itemnumber');
116
    my $itemnumber  = $input->param('itemnumber');
Lines 118-124 if ( $pay_individual || $writeoff_individual ) { Link Here
118
    my $title        = $input->param('title');
118
    my $title        = $input->param('title');
119
    $total_due = $amountoutstanding;
119
    $total_due = $amountoutstanding;
120
    $template->param(
120
    $template->param(
121
        accounttype       => $accounttype,
121
        debit_type_code    => $debit_type_code,
122
        accountlines_id    => $accountlines_id,
122
        accountlines_id    => $accountlines_id,
123
        amount            => $amount,
123
        amount            => $amount,
124
        amountoutstanding => $amountoutstanding,
124
        amountoutstanding => $amountoutstanding,
(-)a/members/printinvoice.pl (-2 / +2 lines)
Lines 82-89 my %row = ( Link Here
82
    'amount'                  => sprintf( "%.2f", $accountline->{'amount'} ),
82
    'amount'                  => sprintf( "%.2f", $accountline->{'amount'} ),
83
    'amountoutstanding' =>
83
    'amountoutstanding' =>
84
      sprintf( "%.2f", $accountline->{'amountoutstanding'} ),
84
      sprintf( "%.2f", $accountline->{'amountoutstanding'} ),
85
    accounttype => $accountline->{accounttype},
85
    'debit_type_code' => $accountline->{'debit_type_code'},
86
    'note'      => $accountline->{'note'},
86
    'note'            => $accountline->{'note'},
87
);
87
);
88
88
89
my @account_offsets = Koha::Account::Offsets->search( { debit_id => $accountline_object->id } );
89
my @account_offsets = Koha::Account::Offsets->search( { debit_id => $accountline_object->id } );
(-)a/misc/cronjobs/staticfines.pl (-1 / +1 lines)
Lines 229-235 for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) { Link Here
229
229
230
            my $desc        = "staticfine";
230
            my $desc        = "staticfine";
231
            my $query       = "INSERT INTO accountlines
231
            my $query       = "INSERT INTO accountlines
232
                        (borrowernumber,itemnumber,date,amount,description,accounttype,status,amountoutstanding)
232
                        (borrowernumber,itemnumber,date,amount,description,debit_type_code,status,amountoutstanding)
233
                                VALUES (?,?,now(),?,?,'OVERDUE','RETURNED',?)";
233
                                VALUES (?,?,now(),?,?,'OVERDUE','RETURNED',?)";
234
            my $sth2 = $dbh->prepare($query);
234
            my $sth2 = $dbh->prepare($query);
235
            $bigdebug and warn "query: $query\nw/ args: $borrowernumber, $itemnumber, $amount, $desc, $amount\n";
235
            $bigdebug and warn "query: $query\nw/ args: $borrowernumber, $itemnumber, $amount, $desc, $amount\n";
(-)a/opac/opac-user.pl (-2 / +2 lines)
Lines 186-192 if ( $pending_checkouts->count ) { # Useless test Link Here
186
            {
186
            {
187
                borrowernumber    => $patron->borrowernumber,
187
                borrowernumber    => $patron->borrowernumber,
188
                amountoutstanding => { '>' => 0 },
188
                amountoutstanding => { '>' => 0 },
189
                accounttype       => [ 'OVERDUE', 'LOST' ],
189
                debit_type_code   => [ 'OVERDUE', 'LOST' ],
190
                itemnumber        => $issue->{itemnumber}
190
                itemnumber        => $issue->{itemnumber}
191
            },
191
            },
192
        );
192
        );
Lines 196-202 if ( $pending_checkouts->count ) { # Useless test Link Here
196
            {
196
            {
197
                borrowernumber    => $patron->borrowernumber,
197
                borrowernumber    => $patron->borrowernumber,
198
                amountoutstanding => { '>' => 0 },
198
                amountoutstanding => { '>' => 0 },
199
                accounttype       => { 'LIKE' => 'RENT_%' },
199
                debit_type_code   => { 'LIKE' => 'RENT_%' },
200
                itemnumber        => $issue->{itemnumber}
200
                itemnumber        => $issue->{itemnumber}
201
            }
201
            }
202
        );
202
        );
(-)a/opac/sco/sco-main.pl (-4 / +4 lines)
Lines 240-249 elsif ( $patron && ( $op eq 'checkout' || $op eq 'renew' ) ) { Link Here
240
                    # Note that this should not be needed but since we do not have proper exception handling here we do it this way
240
                    # Note that this should not be needed but since we do not have proper exception handling here we do it this way
241
                    patron_has_hold_fee => Koha::Account::Lines->search(
241
                    patron_has_hold_fee => Koha::Account::Lines->search(
242
                        {
242
                        {
243
                            borrowernumber => $borrower->{borrowernumber},
243
                            borrowernumber  => $borrower->{borrowernumber},
244
                            accounttype    => 'Res',
244
                            debit_type_code => 'Res',
245
                            description    => $item->biblio->title,
245
                            description     => $item->biblio->title,
246
                            date           => $dtf->format_date(dt_from_string)
246
                            date            => $dtf->format_date(dt_from_string)
247
                        }
247
                        }
248
                      )->count,
248
                      )->count,
249
                );
249
                );
(-)a/reports/cash_register_stats.pl (-10 / +14 lines)
Lines 25-30 use C4::Circulation; Link Here
25
use DateTime;
25
use DateTime;
26
use Koha::DateUtils;
26
use Koha::DateUtils;
27
use Text::CSV::Encoded;
27
use Text::CSV::Encoded;
28
use List::Util qw/any/;
29
30
use Koha::Account::DebitTypes;
28
31
29
my $input            = new CGI;
32
my $input            = new CGI;
30
my $dbh              = C4::Context->dbh;
33
my $dbh              = C4::Context->dbh;
Lines 53-63 $template->param( Link Here
53
my $fromDate = dt_from_string;
56
my $fromDate = dt_from_string;
54
my $toDate   = dt_from_string;
57
my $toDate   = dt_from_string;
55
58
56
my $query_manualinv = "SELECT id, authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'";
59
my @debit_types =
57
my $sth_manualinv = $dbh->prepare($query_manualinv) or die "Unable to prepare query" . $dbh->errstr;
60
  Koha::Account::DebitTypes->search()->as_list;
58
$sth_manualinv->execute() or die "Unable to execute query " . $sth_manualinv->errstr;
59
my $manualinv_types = $sth_manualinv->fetchall_arrayref({});
60
61
61
62
if ($do_it) {
62
if ($do_it) {
63
63
Lines 73-81 if ($do_it) { Link Here
73
        $whereTType = q{};
73
        $whereTType = q{};
74
    } elsif ($transaction_type eq 'ACT') { #Active
74
    } elsif ($transaction_type eq 'ACT') { #Active
75
        $whereTType = q{ AND accounttype IN ('Pay','C') };
75
        $whereTType = q{ AND accounttype IN ('Pay','C') };
76
    } else { #Single transac type
76
    } elsif ($transaction_type eq 'FORW') {
77
        if ($transaction_type eq 'FORW') {
77
        $whereTType = q{ AND accounttype IN ('FOR','W') };
78
            $whereTType = q{ AND accounttype IN ('FOR','W') };
78
    } else {
79
        if ( any { $transaction_type eq $_->code } @debit_types ) {
80
            $whereTType = q{ AND debit_type_code = ? };
81
            push @extra_params, $transaction_type;
79
        } else {
82
        } else {
80
            $whereTType = q{ AND accounttype = ? };
83
            $whereTType = q{ AND accounttype = ? };
81
            push @extra_params, $transaction_type;
84
            push @extra_params, $transaction_type;
Lines 93-99 if ($do_it) { Link Here
93
    SELECT round(amount,2) AS amount, description,
96
    SELECT round(amount,2) AS amount, description,
94
        bo.surname AS bsurname, bo.firstname AS bfirstname, m.surname AS msurname, m.firstname AS mfirstname,
97
        bo.surname AS bsurname, bo.firstname AS bfirstname, m.surname AS msurname, m.firstname AS mfirstname,
95
        bo.cardnumber, br.branchname, bo.borrowernumber,
98
        bo.cardnumber, br.branchname, bo.borrowernumber,
96
        al.borrowernumber, DATE(al.date) as date, al.accounttype, al.amountoutstanding, al.note,
99
        al.borrowernumber, DATE(al.date) as date, al.accounttype, al.debit_type_code, al.amountoutstanding, al.note,
97
        bi.title, bi.biblionumber, i.barcode, i.itype
100
        bi.title, bi.biblionumber, i.barcode, i.itype
98
        FROM accountlines al
101
        FROM accountlines al
99
        LEFT JOIN borrowers bo ON (al.borrowernumber = bo.borrowernumber)
102
        LEFT JOIN borrowers bo ON (al.borrowernumber = bo.borrowernumber)
Lines 153-158 if ($do_it) { Link Here
153
                        $row->{branchname},
156
                        $row->{branchname},
154
                        $row->{date},
157
                        $row->{date},
155
                        $row->{accounttype},
158
                        $row->{accounttype},
159
                        $row->{debit_type},
156
                        $row->{note},
160
                        $row->{note},
157
                        $row->{amount},
161
                        $row->{amount},
158
                        $row->{title},
162
                        $row->{title},
Lines 182-188 $template->param( Link Here
182
    endDate          => $toDate,
186
    endDate          => $toDate,
183
    transaction_type => $transaction_type,
187
    transaction_type => $transaction_type,
184
    branchloop       => Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed,
188
    branchloop       => Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed,
185
    manualinv_types  => $manualinv_types,
189
    debit_types      => \@debit_types,
186
    CGIsepChoice => GetDelimiterChoices,
190
    CGIsepChoice => GetDelimiterChoices,
187
);
191
);
188
192
(-)a/t/db_dependent/Accounts.t (-46 / +47 lines)
Lines 26-31 use t::lib::TestBuilder; Link Here
26
use t::lib::Mocks;
26
use t::lib::Mocks;
27
27
28
use Koha::Account;
28
use Koha::Account;
29
use Koha::Account::DebitTypes;
29
use Koha::Account::Lines;
30
use Koha::Account::Lines;
30
use Koha::Account::Offsets;
31
use Koha::Account::Offsets;
31
use Koha::Notice::Messages;
32
use Koha::Notice::Messages;
Lines 92-98 my ($accountline) = Koha::Account::Lines->search( Link Here
92
        borrowernumber => $patron->{borrowernumber}
93
        borrowernumber => $patron->{borrowernumber}
93
    }
94
    }
94
);
95
);
95
is( $accountline->accounttype, $type, 'Accountline type set correctly for manualinvoice' );
96
is( $accountline->debit_type_code, $type, 'Debit type set correctly for manualinvoice' );
96
is( $accountline->amount, $amount, 'Accountline amount set correctly for manualinvoice' );
97
is( $accountline->amount, $amount, 'Accountline amount set correctly for manualinvoice' );
97
ok( $accountline->description =~ /^$description/, 'Accountline description set correctly for manualinvoice' );
98
ok( $accountline->description =~ /^$description/, 'Accountline description set correctly for manualinvoice' );
98
is( $accountline->note, $note, 'Accountline note set correctly for manualinvoice' );
99
is( $accountline->note, $note, 'Accountline note set correctly for manualinvoice' );
Lines 373-379 subtest "Koha::Account::pay writeoff tests" => sub { Link Here
373
374
374
    my $writeoff = Koha::Account::Lines->find( $id );
375
    my $writeoff = Koha::Account::Lines->find( $id );
375
376
376
    is( $writeoff->accounttype, 'W', 'Type is correct' );
377
    is( $writeoff->accounttype, 'W', 'Type is correct for writeoff' );
377
    is( $writeoff->description, 'Writeoff', 'Description is correct' );
378
    is( $writeoff->description, 'Writeoff', 'Description is correct' );
378
    is( $writeoff->amount, '-42.000000', 'Amount is correct' );
379
    is( $writeoff->amount, '-42.000000', 'Amount is correct' );
379
};
380
};
Lines 583-621 subtest "C4::Accounts::chargelostitem tests" => sub { Link Here
583
        t::lib::Mocks::mock_preference('useDefaultReplacementCost', '0');
584
        t::lib::Mocks::mock_preference('useDefaultReplacementCost', '0');
584
585
585
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor");
586
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor");
586
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'LOST' });
587
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'LOST' });
587
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
588
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'PF' });
588
        ok( !$lostfine, "No lost fine if no replacementcost or default when pref off");
589
        ok( !$lostfine, "No lost fine if no replacementcost or default when pref off");
589
        ok( !$procfee,  "No processing fee if no processing fee");
590
        ok( !$procfee,  "No processing fee if no processing fee");
590
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor");
591
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor");
591
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'LOST' });
592
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'LOST' });
592
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
593
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'PF' });
593
        ok( $lostfine->amount == 6.12, "Lost fine equals replacementcost when pref off and no default set");
594
        ok( $lostfine->amount == 6.12, "Lost fine equals replacementcost when pref off and no default set");
594
        ok( !$procfee,  "No processing fee if no processing fee");
595
        ok( !$procfee,  "No processing fee if no processing fee");
595
        $lostfine->delete();
596
        $lostfine->delete();
596
597
597
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor");
598
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor");
598
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'LOST' });
599
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'LOST' });
599
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
600
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'PF' });
600
        ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off");
601
        ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off");
601
        ok( !$procfee,  "No processing fee if no processing fee");
602
        ok( !$procfee,  "No processing fee if no processing fee");
602
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor");
603
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor");
603
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'LOST' });
604
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'LOST' });
604
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
605
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'PF' });
605
        ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set");
606
        ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set");
606
        ok( !$procfee,  "No processing fee if no processing fee");
607
        ok( !$procfee,  "No processing fee if no processing fee");
607
        $lostfine->delete();
608
        $lostfine->delete();
608
609
609
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor");
610
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor");
610
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'LOST' });
611
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'LOST' });
611
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
612
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'PF' });
612
        ok( !$lostfine, "No lost fine if no replacementcost and no default set when pref off");
613
        ok( !$lostfine, "No lost fine if no replacementcost and no default set when pref off");
613
        ok( $procfee->amount == 8.16,  "Processing fee if processing fee");
614
        ok( $procfee->amount == 8.16,  "Processing fee if processing fee");
614
        is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
615
        is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
615
        $procfee->delete();
616
        $procfee->delete();
616
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor");
617
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor");
617
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'LOST' });
618
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'LOST' });
618
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
619
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'PF' });
619
        ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and no default set");
620
        ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and no default set");
620
        ok( $procfee->amount == 8.16,  "Processing fee if processing fee");
621
        ok( $procfee->amount == 8.16,  "Processing fee if processing fee");
621
        is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
622
        is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
Lines 623-637 subtest "C4::Accounts::chargelostitem tests" => sub { Link Here
623
        $procfee->delete();
624
        $procfee->delete();
624
625
625
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
626
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
626
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' });
627
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
627
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
628
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' });
628
        ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off");
629
        ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off");
629
        ok( $procfee->amount == 2.04,  "Processing fee if processing fee");
630
        ok( $procfee->amount == 2.04,  "Processing fee if processing fee");
630
        is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
631
        is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
631
        $procfee->delete();
632
        $procfee->delete();
632
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
633
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
633
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' });
634
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
634
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
635
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' });
635
        ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set");
636
        ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set");
636
        ok( $procfee->amount == 2.04,  "Processing fee if processing fee");
637
        ok( $procfee->amount == 2.04,  "Processing fee if processing fee");
637
        is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
638
        is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
Lines 641-706 subtest "C4::Accounts::chargelostitem tests" => sub { Link Here
641
        t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
642
        t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
642
643
643
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor");
644
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor");
644
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'LOST' });
645
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'LOST' });
645
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
646
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'PF' });
646
        ok( !$lostfine, "No lost fine if no replacementcost or default when pref on");
647
        ok( !$lostfine, "No lost fine if no replacementcost or default when pref on");
647
        ok( !$procfee,  "No processing fee if no processing fee");
648
        ok( !$procfee,  "No processing fee if no processing fee");
648
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor");
649
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor");
649
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'LOST' });
650
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'LOST' });
650
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' });
651
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'PF' });
651
        is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set");
652
        is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set");
652
        ok( !$procfee,  "No processing fee if no processing fee");
653
        ok( !$procfee,  "No processing fee if no processing fee");
653
654
654
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor");
655
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor");
655
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'LOST' });
656
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'LOST' });
656
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
657
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'PF' });
657
        is( $lostfine->amount(), "16.320000", "Lost fine is default if no replacementcost but default set when pref on");
658
        is( $lostfine->amount(), "16.320000", "Lost fine is default if no replacementcost but default set when pref on");
658
        ok( !$procfee,  "No processing fee if no processing fee");
659
        ok( !$procfee,  "No processing fee if no processing fee");
659
        $lostfine->delete();
660
        $lostfine->delete();
660
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor");
661
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor");
661
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'LOST' });
662
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'LOST' });
662
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' });
663
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'PF' });
663
        is( $lostfine->amount, "6.120000" , "Lost fine equals replacementcost when pref on and default set");
664
        is( $lostfine->amount, "6.120000" , "Lost fine equals replacementcost when pref on and default set");
664
        ok( !$procfee,  "No processing fee if no processing fee");
665
        ok( !$procfee,  "No processing fee if no processing fee");
665
666
666
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor");
667
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor");
667
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'LOST' });
668
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'LOST' });
668
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
669
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'PF' });
669
        ok( !$lostfine, "No lost fine if no replacementcost and default not set when pref on");
670
        ok( !$lostfine, "No lost fine if no replacementcost and default not set when pref on");
670
        is( $procfee->amount, "8.160000",  "Processing fee if processing fee");
671
        is( $procfee->amount, "8.160000",  "Processing fee if processing fee");
671
        is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
672
        is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
672
        $procfee->delete();
673
        $procfee->delete();
673
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor");
674
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor");
674
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'LOST' });
675
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'LOST' });
675
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' });
676
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'PF' });
676
        is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set");
677
        is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set");
677
        is( $procfee->amount, "8.160000",  "Processing fee if processing fee");
678
        is( $procfee->amount, "8.160000",  "Processing fee if processing fee");
678
        is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
679
        is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" );
679
680
680
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
681
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
681
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' });
682
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
682
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
683
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' });
683
        is( $lostfine->amount, "4.080000", "Lost fine is default if no replacementcost but default set when pref on");
684
        is( $lostfine->amount, "4.080000", "Lost fine is default if no replacementcost but default set when pref on");
684
        is( $procfee->amount, "2.040000",  "Processing fee if processing fee");
685
        is( $procfee->amount, "2.040000",  "Processing fee if processing fee");
685
        is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
686
        is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
686
        $lostfine->delete();
687
        $lostfine->delete();
687
        $procfee->delete();
688
        $procfee->delete();
688
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
689
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
689
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' });
690
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
690
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
691
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' });
691
        is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and default set");
692
        is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and default set");
692
        is( $procfee->amount, "2.040000",  "Processing fee if processing fee");
693
        is( $procfee->amount, "2.040000",  "Processing fee if processing fee");
693
        is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
694
        is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
694
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
695
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
695
        my $lostfines = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' });
696
        my $lostfines = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
696
        my $procfees  = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
697
        my $procfees  = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' });
697
        ok( $lostfines->count == 1 , "Lost fine cannot be double charged for the same issue_id");
698
        ok( $lostfines->count == 1 , "Lost fine cannot be double charged for the same issue_id");
698
        ok( $procfees->count == 1,  "Processing fee cannot be double charged for the same issue_id");
699
        ok( $procfees->count == 1,  "Processing fee cannot be double charged for the same issue_id");
699
        MarkIssueReturned($cli_borrowernumber, $cli_itemnumber4);
700
        MarkIssueReturned($cli_borrowernumber, $cli_itemnumber4);
700
        $cli_issue_id_4X = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4 } })->{issue_id};
701
        $cli_issue_id_4X = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4 } })->{issue_id};
701
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
702
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
702
        $lostfines = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' });
703
        $lostfines = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
703
        $procfees  = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
704
        $procfees  = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' });
704
        ok( $lostfines->count == 2 , "Lost fine can be charged twice for the same item if they are distinct issue_id's");
705
        ok( $lostfines->count == 2 , "Lost fine can be charged twice for the same item if they are distinct issue_id's");
705
        ok( $procfees->count == 2,  "Processing fee can be charged twice for the same item if they are distinct issue_id's");
706
        ok( $procfees->count == 2,  "Processing fee can be charged twice for the same item if they are distinct issue_id's");
706
        $lostfines->delete();
707
        $lostfines->delete();
Lines 714-720 subtest "C4::Accounts::chargelostitem tests" => sub { Link Here
714
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, '1.99', "Perdedor");
715
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, '1.99', "Perdedor");
715
716
716
        # Lost Item Fee
717
        # Lost Item Fee
717
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' });
718
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
718
        ok($lostfine, "Lost fine created");
719
        ok($lostfine, "Lost fine created");
719
        is($lostfine->manager_id, $staff_id, "Lost fine manager_id set correctly");
720
        is($lostfine->manager_id, $staff_id, "Lost fine manager_id set correctly");
720
        is($lostfine->issue_id, $cli_issue_id_4X, "Lost fine issue_id set correctly");
721
        is($lostfine->issue_id, $cli_issue_id_4X, "Lost fine issue_id set correctly");
Lines 723-729 subtest "C4::Accounts::chargelostitem tests" => sub { Link Here
723
        is($lostfine->branchcode, $branchcode, "Lost fine branchcode set correctly");
724
        is($lostfine->branchcode, $branchcode, "Lost fine branchcode set correctly");
724
725
725
        # Processing Fee
726
        # Processing Fee
726
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
727
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' });
727
        ok($procfee, "Processing fee created");
728
        ok($procfee, "Processing fee created");
728
        is($procfee->manager_id, $staff_id, "Processing fee manager_id set correctly");
729
        is($procfee->manager_id, $staff_id, "Processing fee manager_id set correctly");
729
        is($procfee->issue_id, $cli_issue_id_4X, "Processing fee issue_id set correctly");
730
        is($procfee->issue_id, $cli_issue_id_4X, "Processing fee issue_id set correctly");
Lines 741-756 subtest "C4::Accounts::chargelostitem tests" => sub { Link Here
741
742
742
        t::lib::Mocks::mock_preference( 'FinesLog', 0 );
743
        t::lib::Mocks::mock_preference( 'FinesLog', 0 );
743
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
744
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
744
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' });
745
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
745
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
746
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' });
746
        is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No logs were added' );
747
        is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No logs were added' );
747
        $lostfine->delete();
748
        $lostfine->delete();
748
        $procfee->delete();
749
        $procfee->delete();
749
750
750
        t::lib::Mocks::mock_preference( 'FinesLog', 1 );
751
        t::lib::Mocks::mock_preference( 'FinesLog', 1 );
751
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
752
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor");
752
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' });
753
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' });
753
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
754
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' });
754
        is( $schema->resultset('ActionLog')->count(), $action_logs + 2, 'Logs were added' );
755
        is( $schema->resultset('ActionLog')->count(), $action_logs + 2, 'Logs were added' );
755
        $lostfine->delete();
756
        $lostfine->delete();
756
        $procfee->delete();
757
        $procfee->delete();
Lines 786-792 subtest "Koha::Account::non_issues_charges tests" => sub { Link Here
786
            interface   => 'commandline'
787
            interface   => 'commandline'
787
        }
788
        }
788
    );
789
    );
789
    Koha::Account::DebitTypes->new(
790
    Koha::Account::DebitTypes->find_or_create(
790
        {
791
        {
791
            code        => 'Copie',
792
            code        => 'Copie',
792
            description => 'Fee for copie',
793
            description => 'Fee for copie',
Lines 798-804 subtest "Koha::Account::non_issues_charges tests" => sub { Link Here
798
            borrowernumber    => $patron->borrowernumber,
799
            borrowernumber    => $patron->borrowernumber,
799
            date              => $today,
800
            date              => $today,
800
            description       => 'a Manual invoice fee',
801
            description       => 'a Manual invoice fee',
801
            debit_type        => 'Copie',
802
            debit_type_code   => 'Copie',
802
            amountoutstanding => $manual,
803
            amountoutstanding => $manual,
803
            interface         => 'commandline'
804
            interface         => 'commandline'
804
        }
805
        }
(-)a/t/db_dependent/Circulation.t (-21 / +21 lines)
Lines 911-917 subtest "CanBookBeRenewed tests" => sub { Link Here
911
    );
911
    );
912
912
913
    my $line = Koha::Account::Lines->search({ borrowernumber => $renewing_borrower->{borrowernumber} })->next();
913
    my $line = Koha::Account::Lines->search({ borrowernumber => $renewing_borrower->{borrowernumber} })->next();
914
    is( $line->accounttype, 'OVERDUE', 'Account line type is OVERDUE' );
914
    is( $line->debit_type_code, 'OVERDUE', 'Account line type is OVERDUE' );
915
    is( $line->status, 'UNRETURNED', 'Account line status is UNRETURNED' );
915
    is( $line->status, 'UNRETURNED', 'Account line status is UNRETURNED' );
916
    is( $line->amountoutstanding, '15.000000', 'Account line amount outstanding is 15.00' );
916
    is( $line->amountoutstanding, '15.000000', 'Account line amount outstanding is 15.00' );
917
    is( $line->amount, '15.000000', 'Account line amount is 15.00' );
917
    is( $line->amount, '15.000000', 'Account line amount is 15.00' );
Lines 927-933 subtest "CanBookBeRenewed tests" => sub { Link Here
927
    LostItem( $item_1->itemnumber, 'test', 1 );
927
    LostItem( $item_1->itemnumber, 'test', 1 );
928
928
929
    $line = Koha::Account::Lines->find($line->id);
929
    $line = Koha::Account::Lines->find($line->id);
930
    is( $line->accounttype, 'OVERDUE', 'Account type remains as OVERDUE' );
930
    is( $line->debit_type_code, 'OVERDUE', 'Account type remains as OVERDUE' );
931
    isnt( $line->status, 'UNRETURNED', 'Account status correctly changed from UNRETURNED to RETURNED' );
931
    isnt( $line->status, 'UNRETURNED', 'Account status correctly changed from UNRETURNED to RETURNED' );
932
932
933
    my $item = Koha::Items->find($item_1->itemnumber);
933
    my $item = Koha::Items->find($item_1->itemnumber);
Lines 2124-2130 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2124
        LostItem( $item->itemnumber, 1 );
2124
        LostItem( $item->itemnumber, 1 );
2125
2125
2126
        my $processing_fee_lines = Koha::Account::Lines->search(
2126
        my $processing_fee_lines = Koha::Account::Lines->search(
2127
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'PF' } );
2127
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'PF' } );
2128
        is( $processing_fee_lines->count, 1, 'Only one processing fee produced' );
2128
        is( $processing_fee_lines->count, 1, 'Only one processing fee produced' );
2129
        my $processing_fee_line = $processing_fee_lines->next;
2129
        my $processing_fee_line = $processing_fee_lines->next;
2130
        is( $processing_fee_line->amount + 0,
2130
        is( $processing_fee_line->amount + 0,
Lines 2133-2139 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2133
            $processfee_amount, 'The right PF amountoutstanding is generated' );
2133
            $processfee_amount, 'The right PF amountoutstanding is generated' );
2134
2134
2135
        my $lost_fee_lines = Koha::Account::Lines->search(
2135
        my $lost_fee_lines = Koha::Account::Lines->search(
2136
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2136
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'LOST' } );
2137
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2137
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2138
        my $lost_fee_line = $lost_fee_lines->next;
2138
        my $lost_fee_line = $lost_fee_lines->next;
2139
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2139
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
Lines 2159-2165 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2159
2159
2160
        $lost_fee_line->discard_changes; # reload from DB
2160
        $lost_fee_line->discard_changes; # reload from DB
2161
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2161
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2162
        is( $lost_fee_line->accounttype,
2162
        is( $lost_fee_line->debit_type_code,
2163
            'LOST', 'Lost fee now still has account type of LOST' );
2163
            'LOST', 'Lost fee now still has account type of LOST' );
2164
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2164
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2165
2165
Lines 2188-2194 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2188
        LostItem( $item->itemnumber, 1 );
2188
        LostItem( $item->itemnumber, 1 );
2189
2189
2190
        my $processing_fee_lines = Koha::Account::Lines->search(
2190
        my $processing_fee_lines = Koha::Account::Lines->search(
2191
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'PF' } );
2191
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'PF' } );
2192
        is( $processing_fee_lines->count, 1, 'Only one processing fee produced' );
2192
        is( $processing_fee_lines->count, 1, 'Only one processing fee produced' );
2193
        my $processing_fee_line = $processing_fee_lines->next;
2193
        my $processing_fee_line = $processing_fee_lines->next;
2194
        is( $processing_fee_line->amount + 0,
2194
        is( $processing_fee_line->amount + 0,
Lines 2197-2203 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2197
            $processfee_amount, 'The right PF amountoutstanding is generated' );
2197
            $processfee_amount, 'The right PF amountoutstanding is generated' );
2198
2198
2199
        my $lost_fee_lines = Koha::Account::Lines->search(
2199
        my $lost_fee_lines = Koha::Account::Lines->search(
2200
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2200
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'LOST' } );
2201
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2201
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2202
        my $lost_fee_line = $lost_fee_lines->next;
2202
        my $lost_fee_line = $lost_fee_lines->next;
2203
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2203
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
Lines 2227-2233 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2227
2227
2228
        $lost_fee_line->discard_changes;
2228
        $lost_fee_line->discard_changes;
2229
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2229
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2230
        is( $lost_fee_line->accounttype,
2230
        is( $lost_fee_line->debit_type_code,
2231
            'LOST', 'Lost fee now still has account type of LOST' );
2231
            'LOST', 'Lost fee now still has account type of LOST' );
2232
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2232
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2233
2233
Lines 2258-2264 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2258
        LostItem( $item->itemnumber, 1 );
2258
        LostItem( $item->itemnumber, 1 );
2259
2259
2260
        my $processing_fee_lines = Koha::Account::Lines->search(
2260
        my $processing_fee_lines = Koha::Account::Lines->search(
2261
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'PF' } );
2261
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'PF' } );
2262
        is( $processing_fee_lines->count, 1, 'Only one processing fee produced' );
2262
        is( $processing_fee_lines->count, 1, 'Only one processing fee produced' );
2263
        my $processing_fee_line = $processing_fee_lines->next;
2263
        my $processing_fee_line = $processing_fee_lines->next;
2264
        is( $processing_fee_line->amount + 0,
2264
        is( $processing_fee_line->amount + 0,
Lines 2267-2273 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2267
            $processfee_amount, 'The right PF amountoutstanding is generated' );
2267
            $processfee_amount, 'The right PF amountoutstanding is generated' );
2268
2268
2269
        my $lost_fee_lines = Koha::Account::Lines->search(
2269
        my $lost_fee_lines = Koha::Account::Lines->search(
2270
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2270
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'LOST' } );
2271
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2271
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2272
        my $lost_fee_line = $lost_fee_lines->next;
2272
        my $lost_fee_line = $lost_fee_lines->next;
2273
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2273
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
Lines 2283-2289 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2283
2283
2284
        $lost_fee_line->discard_changes;
2284
        $lost_fee_line->discard_changes;
2285
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2285
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2286
        is( $lost_fee_line->accounttype,
2286
        is( $lost_fee_line->debit_type_code,
2287
            'LOST', 'Lost fee now still has account type of LOST' );
2287
            'LOST', 'Lost fee now still has account type of LOST' );
2288
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2288
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2289
2289
Lines 2311-2317 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2311
        LostItem( $item->itemnumber, 1 );
2311
        LostItem( $item->itemnumber, 1 );
2312
2312
2313
        my $processing_fee_lines = Koha::Account::Lines->search(
2313
        my $processing_fee_lines = Koha::Account::Lines->search(
2314
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'PF' } );
2314
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'PF' } );
2315
        is( $processing_fee_lines->count, 1, 'Only one processing fee produced' );
2315
        is( $processing_fee_lines->count, 1, 'Only one processing fee produced' );
2316
        my $processing_fee_line = $processing_fee_lines->next;
2316
        my $processing_fee_line = $processing_fee_lines->next;
2317
        is( $processing_fee_line->amount + 0,
2317
        is( $processing_fee_line->amount + 0,
Lines 2320-2326 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2320
            $processfee_amount, 'The right PF amountoutstanding is generated' );
2320
            $processfee_amount, 'The right PF amountoutstanding is generated' );
2321
2321
2322
        my $lost_fee_lines = Koha::Account::Lines->search(
2322
        my $lost_fee_lines = Koha::Account::Lines->search(
2323
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2323
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'LOST' } );
2324
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2324
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2325
        my $lost_fee_line = $lost_fee_lines->next;
2325
        my $lost_fee_line = $lost_fee_lines->next;
2326
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2326
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
Lines 2367-2373 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2367
2367
2368
        $lost_fee_line->discard_changes;
2368
        $lost_fee_line->discard_changes;
2369
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2369
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2370
        is( $lost_fee_line->accounttype,
2370
        is( $lost_fee_line->debit_type_code,
2371
            'LOST', 'Lost fee now still has account type of LOST' );
2371
            'LOST', 'Lost fee now still has account type of LOST' );
2372
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2372
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2373
2373
Lines 2424-2430 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2424
        LostItem( $item_id, 1 );
2424
        LostItem( $item_id, 1 );
2425
2425
2426
        my $lost_fee_lines = Koha::Account::Lines->search(
2426
        my $lost_fee_lines = Koha::Account::Lines->search(
2427
            { borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } );
2427
            { borrowernumber => $patron->id, itemnumber => $item_id, debit_type_code => 'LOST' } );
2428
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2428
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2429
        my $lost_fee_line = $lost_fee_lines->next;
2429
        my $lost_fee_line = $lost_fee_lines->next;
2430
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2430
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
Lines 2461-2467 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2461
2461
2462
        is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PF - payment (LOST_RETURN)' );
2462
        is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PF - payment (LOST_RETURN)' );
2463
2463
2464
        my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, accounttype => 'OVERDUE', status => 'UNRETURNED' })->next;
2464
        my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, debit_type_code => 'OVERDUE', status => 'UNRETURNED' })->next;
2465
        is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' );
2465
        is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' );
2466
    };
2466
    };
2467
};
2467
};
Lines 2491-2497 subtest '_FixOverduesOnReturn' => sub { Link Here
2491
    my $accountline = Koha::Account::Line->new(
2491
    my $accountline = Koha::Account::Line->new(
2492
        {
2492
        {
2493
            borrowernumber => $patron->{borrowernumber},
2493
            borrowernumber => $patron->{borrowernumber},
2494
            accounttype    => 'OVERDUE',
2494
            debit_type_code    => 'OVERDUE',
2495
            status         => 'UNRETURNED',
2495
            status         => 'UNRETURNED',
2496
            itemnumber     => $item->itemnumber,
2496
            itemnumber     => $item->itemnumber,
2497
            amount => 99.00,
2497
            amount => 99.00,
Lines 2511-2517 subtest '_FixOverduesOnReturn' => sub { Link Here
2511
    ## Run again, with exemptfine enabled
2511
    ## Run again, with exemptfine enabled
2512
    $accountline->set(
2512
    $accountline->set(
2513
        {
2513
        {
2514
            accounttype    => 'OVERDUE',
2514
            debit_type_code    => 'OVERDUE',
2515
            status         => 'UNRETURNED',
2515
            status         => 'UNRETURNED',
2516
            amountoutstanding => 99.00,
2516
            amountoutstanding => 99.00,
2517
        }
2517
        }
Lines 2558-2564 subtest '_FixAccountForLostAndReturned returns undef if patron is deleted' => su Link Here
2558
    my $accountline = Koha::Account::Line->new(
2558
    my $accountline = Koha::Account::Line->new(
2559
        {
2559
        {
2560
            borrowernumber => $patron->id,
2560
            borrowernumber => $patron->id,
2561
            accounttype    => 'L',
2561
            debit_type_code    => 'LOST',
2562
            status         => undef,
2562
            status         => undef,
2563
            itemnumber     => $item->itemnumber,
2563
            itemnumber     => $item->itemnumber,
2564
            amount => 99.00,
2564
            amount => 99.00,
Lines 3033-3044 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
3033
    is( $lines->count, 2 );
3033
    is( $lines->count, 2 );
3034
3034
3035
    my $line = $lines->next;
3035
    my $line = $lines->next;
3036
    is( $line->accounttype, 'RENT',       'The issue of item with issuing charge generates an accountline of the correct type' );
3036
    is( $line->debit_type_code, 'RENT',       'The issue of item with issuing charge generates an accountline of the correct type' );
3037
    is( $line->branchcode,  $library->id, 'AddIssuingCharge correctly sets branchcode' );
3037
    is( $line->branchcode,  $library->id, 'AddIssuingCharge correctly sets branchcode' );
3038
    is( $line->description, '',     'AddIssue does not set a hardcoded description for the accountline' );
3038
    is( $line->description, '',     'AddIssue does not set a hardcoded description for the accountline' );
3039
3039
3040
    $line = $lines->next;
3040
    $line = $lines->next;
3041
    is( $line->accounttype, 'RENT_RENEW', 'The renewal of item with issuing charge generates an accountline of the correct type' );
3041
    is( $line->debit_type_code, 'RENT_RENEW', 'The renewal of item with issuing charge generates an accountline of the correct type' );
3042
    is( $line->branchcode,  $library->id, 'AddRenewal correctly sets branchcode' );
3042
    is( $line->branchcode,  $library->id, 'AddRenewal correctly sets branchcode' );
3043
    is( $line->description, '', 'AddRenewal does not set a hardcoded description for the accountline' );
3043
    is( $line->description, '', 'AddRenewal does not set a hardcoded description for the accountline' );
3044
3044
(-)a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t (-1 / +1 lines)
Lines 87-93 is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check Link Here
87
87
88
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->id })->next();
88
my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->id })->next();
89
is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" );
89
is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" );
90
is( $accountline->accounttype, "LOST", "Account type is LOST" );
90
is( $accountline->debit_type_code, "LOST", "Debit type is LOST" );
91
91
92
my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id })->next();
92
my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id })->next();
93
is( $offset->type, 'Lost Item', 'Got correct offset type' );
93
is( $offset->type, 'Lost Item', 'Got correct offset type' );
(-)a/t/db_dependent/Circulation/Returns.t (-1 / +1 lines)
Lines 277-283 subtest 'Handle ids duplication' => sub { Link Here
277
    my $issue_id = $original_checkout->issue_id;
277
    my $issue_id = $original_checkout->issue_id;
278
    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
278
    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
279
    is( $account_lines->count, 1, '1 account line should exist for this issue_id' );
279
    is( $account_lines->count, 1, '1 account line should exist for this issue_id' );
280
    is( $account_lines->next->accounttype, 'RENT', 'patron has been charged the rentalcharge' );
280
    is( $account_lines->next->debit_type_code, 'RENT', 'patron has been charged the rentalcharge' );
281
    $account_lines->delete;
281
    $account_lines->delete;
282
282
283
    # Create an existing entry in old_issue
283
    # Create an existing entry in old_issue
(-)a/t/db_dependent/Koha/Account.t (-5 / +5 lines)
Lines 343-349 subtest 'add_debit() tests' => sub { Link Here
343
        'No log was added'
343
        'No log was added'
344
    );
344
    );
345
    is(
345
    is(
346
        $line_1->accounttype,
346
        $line_1->debit_type_code,
347
        $Koha::Account::account_type_debit->{'rent'},
347
        $Koha::Account::account_type_debit->{'rent'},
348
        'Account type is correctly set'
348
        'Account type is correctly set'
349
    );
349
    );
Lines 370-376 subtest 'add_debit() tests' => sub { Link Here
370
        'Log was added'
370
        'Log was added'
371
    );
371
    );
372
    is(
372
    is(
373
        $line_2->accounttype,
373
        $line_2->debit_type_code,
374
        $Koha::Account::account_type_debit->{'rent'},
374
        $Koha::Account::account_type_debit->{'rent'},
375
        'Account type is correctly set'
375
        'Account type is correctly set'
376
    );
376
    );
Lines 657-663 subtest 'pay() handles lost items when paying a specific lost fee' => sub { Link Here
657
            borrowernumber => $patron->id,
657
            borrowernumber => $patron->id,
658
            itemnumber     => $item->id,
658
            itemnumber     => $item->id,
659
            date           => \'NOW()',
659
            date           => \'NOW()',
660
            accounttype    => 'LOST',
660
            debit_type_code    => 'LOST',
661
            interface      => 'cli',
661
            interface      => 'cli',
662
            amount => '1',
662
            amount => '1',
663
            amountoutstanding => '1',
663
            amountoutstanding => '1',
Lines 730-736 subtest 'pay() handles lost items when paying by amount ( not specifying the los Link Here
730
            borrowernumber => $patron->id,
730
            borrowernumber => $patron->id,
731
            itemnumber     => $item->id,
731
            itemnumber     => $item->id,
732
            date           => \'NOW()',
732
            date           => \'NOW()',
733
            accounttype    => 'LOST',
733
            debit_type_code    => 'LOST',
734
            interface      => 'cli',
734
            interface      => 'cli',
735
            amount => '1',
735
            amount => '1',
736
            amountoutstanding => '1',
736
            amountoutstanding => '1',
Lines 801-807 subtest 'Koha::Account::Line::apply() handles lost items' => sub { Link Here
801
            borrowernumber    => $patron->id,
801
            borrowernumber    => $patron->id,
802
            itemnumber        => $item->id,
802
            itemnumber        => $item->id,
803
            date              => \'NOW()',
803
            date              => \'NOW()',
804
            accounttype       => 'LOST',
804
            debit_type_code       => 'LOST',
805
            interface         => 'cli',
805
            interface         => 'cli',
806
            amount            => '1',
806
            amount            => '1',
807
            amountoutstanding => '1',
807
            amountoutstanding => '1',
(-)a/t/db_dependent/Koha/Account/DebitTypes.t (-2 lines)
Lines 52-59 my $new_debit_type_2 = Koha::Account::DebitType->new( Link Here
52
    }
52
    }
53
)->store;
53
)->store;
54
54
55
my $defaults                  = Koha::Account::DebitType::defaults;
56
my $number_of_system_types    = scalar @{$defaults};
57
my $retrieved_debit_types_all = Koha::Account::DebitTypes->search();
55
my $retrieved_debit_types_all = Koha::Account::DebitTypes->search();
58
try {
56
try {
59
    $retrieved_debit_types_all->delete;
57
    $retrieved_debit_types_all->delete;
(-)a/t/db_dependent/Koha/Account/Lines.t (-15 / +15 lines)
Lines 46-52 subtest 'patron() tests' => sub { Link Here
46
    my $line = Koha::Account::Line->new(
46
    my $line = Koha::Account::Line->new(
47
    {
47
    {
48
        borrowernumber => $patron->{borrowernumber},
48
        borrowernumber => $patron->{borrowernumber},
49
        accounttype    => "OVERDUE",
49
        debit_type_code    => "OVERDUE",
50
        status         => "RETURNED",
50
        status         => "RETURNED",
51
        amount         => 10,
51
        amount         => 10,
52
        interface      => 'commandline',
52
        interface      => 'commandline',
Lines 86-92 subtest 'item() tests' => sub { Link Here
86
    {
86
    {
87
        borrowernumber => $patron->{borrowernumber},
87
        borrowernumber => $patron->{borrowernumber},
88
        itemnumber     => $item->itemnumber,
88
        itemnumber     => $item->itemnumber,
89
        accounttype    => "OVERDUE",
89
        debit_type_code    => "OVERDUE",
90
        status         => "RETURNED",
90
        status         => "RETURNED",
91
        amount         => 10,
91
        amount         => 10,
92
        interface      => 'commandline',
92
        interface      => 'commandline',
Lines 115-121 subtest 'total_outstanding() tests' => sub { Link Here
115
115
116
    my $debit_1 = Koha::Account::Line->new(
116
    my $debit_1 = Koha::Account::Line->new(
117
        {   borrowernumber    => $patron->id,
117
        {   borrowernumber    => $patron->id,
118
            accounttype       => "OVERDUE",
118
            debit_type_code       => "OVERDUE",
119
            status            => "RETURNED",
119
            status            => "RETURNED",
120
            amount            => 10,
120
            amount            => 10,
121
            amountoutstanding => 10,
121
            amountoutstanding => 10,
Lines 125-131 subtest 'total_outstanding() tests' => sub { Link Here
125
125
126
    my $debit_2 = Koha::Account::Line->new(
126
    my $debit_2 = Koha::Account::Line->new(
127
        {   borrowernumber    => $patron->id,
127
        {   borrowernumber    => $patron->id,
128
            accounttype       => "OVERDUE",
128
            debit_type_code       => "OVERDUE",
129
            status            => "RETURNED",
129
            status            => "RETURNED",
130
            amount            => 10,
130
            amount            => 10,
131
            amountoutstanding => 10,
131
            amountoutstanding => 10,
Lines 138-144 subtest 'total_outstanding() tests' => sub { Link Here
138
138
139
    my $credit_1 = Koha::Account::Line->new(
139
    my $credit_1 = Koha::Account::Line->new(
140
        {   borrowernumber    => $patron->id,
140
        {   borrowernumber    => $patron->id,
141
            accounttype       => "OVERDUE",
141
            debit_type_code       => "OVERDUE",
142
            status            => "RETURNED",
142
            status            => "RETURNED",
143
            amount            => -10,
143
            amount            => -10,
144
            amountoutstanding => -10,
144
            amountoutstanding => -10,
Lines 151-157 subtest 'total_outstanding() tests' => sub { Link Here
151
151
152
    my $credit_2 = Koha::Account::Line->new(
152
    my $credit_2 = Koha::Account::Line->new(
153
        {   borrowernumber    => $patron->id,
153
        {   borrowernumber    => $patron->id,
154
            accounttype       => "OVERDUE",
154
            debit_type_code       => "OVERDUE",
155
            status            => "RETURNED",
155
            status            => "RETURNED",
156
            amount            => -10,
156
            amount            => -10,
157
            amountoutstanding => -10,
157
            amountoutstanding => -10,
Lines 164-170 subtest 'total_outstanding() tests' => sub { Link Here
164
164
165
    my $credit_3 = Koha::Account::Line->new(
165
    my $credit_3 = Koha::Account::Line->new(
166
        {   borrowernumber    => $patron->id,
166
        {   borrowernumber    => $patron->id,
167
            accounttype       => "OVERDUE",
167
            debit_type_code       => "OVERDUE",
168
            status            => "RETURNED",
168
            status            => "RETURNED",
169
            amount            => -100,
169
            amount            => -100,
170
            amountoutstanding => -100,
170
            amountoutstanding => -100,
Lines 195-201 subtest 'is_credit() and is_debit() tests' => sub { Link Here
195
    my $debit = Koha::Account::Line->new(
195
    my $debit = Koha::Account::Line->new(
196
    {
196
    {
197
        borrowernumber => $patron->id,
197
        borrowernumber => $patron->id,
198
        accounttype    => "OVERDUE",
198
        debit_type_code    => "OVERDUE",
199
        status         => "RETURNED",
199
        status         => "RETURNED",
200
        amount         => 10,
200
        amount         => 10,
201
        interface      => 'commandline',
201
        interface      => 'commandline',
Lines 220-226 subtest 'apply() tests' => sub { Link Here
220
220
221
    my $debit_1 = Koha::Account::Line->new(
221
    my $debit_1 = Koha::Account::Line->new(
222
        {   borrowernumber    => $patron->id,
222
        {   borrowernumber    => $patron->id,
223
            accounttype       => "OVERDUE",
223
            debit_type_code       => "OVERDUE",
224
            status            => "RETURNED",
224
            status            => "RETURNED",
225
            amount            => 10,
225
            amount            => 10,
226
            amountoutstanding => 10,
226
            amountoutstanding => 10,
Lines 230-236 subtest 'apply() tests' => sub { Link Here
230
230
231
    my $debit_2 = Koha::Account::Line->new(
231
    my $debit_2 = Koha::Account::Line->new(
232
        {   borrowernumber    => $patron->id,
232
        {   borrowernumber    => $patron->id,
233
            accounttype       => "OVERDUE",
233
            debit_type_code       => "OVERDUE",
234
            status            => "RETURNED",
234
            status            => "RETURNED",
235
            amount            => 100,
235
            amount            => 100,
236
            amountoutstanding => 100,
236
            amountoutstanding => 100,
Lines 293-299 subtest 'apply() tests' => sub { Link Here
293
    my $credit_2 = $account->add_credit({ amount => 20, interface => 'commandline' });
293
    my $credit_2 = $account->add_credit({ amount => 20, interface => 'commandline' });
294
    my $debit_3  = Koha::Account::Line->new(
294
    my $debit_3  = Koha::Account::Line->new(
295
        {   borrowernumber    => $patron->id,
295
        {   borrowernumber    => $patron->id,
296
            accounttype       => "OVERDUE",
296
            debit_type_code       => "OVERDUE",
297
            status            => "RETURNED",
297
            status            => "RETURNED",
298
            amount            => 100,
298
            amount            => 100,
299
            amountoutstanding => 100,
299
            amountoutstanding => 100,
Lines 343-349 subtest 'Keep account info when related patron, staff or item is deleted' => sub Link Here
343
        borrowernumber => $patron->borrowernumber,
343
        borrowernumber => $patron->borrowernumber,
344
        manager_id     => $staff->borrowernumber,
344
        manager_id     => $staff->borrowernumber,
345
        itemnumber     => $item->itemnumber,
345
        itemnumber     => $item->itemnumber,
346
        accounttype    => "OVERDUE",
346
        debit_type_code    => "OVERDUE",
347
        status         => "RETURNED",
347
        status         => "RETURNED",
348
        amount         => 10,
348
        amount         => 10,
349
        interface      => 'commandline',
349
        interface      => 'commandline',
Lines 382-388 subtest 'adjust() tests' => sub { Link Here
382
382
383
    my $debit_1 = Koha::Account::Line->new(
383
    my $debit_1 = Koha::Account::Line->new(
384
        {   borrowernumber    => $patron->id,
384
        {   borrowernumber    => $patron->id,
385
            accounttype       => "OVERDUE",
385
            debit_type_code       => "OVERDUE",
386
            status            => "RETURNED",
386
            status            => "RETURNED",
387
            amount            => 10,
387
            amount            => 10,
388
            amountoutstanding => 10,
388
            amountoutstanding => 10,
Lines 392-398 subtest 'adjust() tests' => sub { Link Here
392
392
393
    my $debit_2 = Koha::Account::Line->new(
393
    my $debit_2 = Koha::Account::Line->new(
394
        {   borrowernumber    => $patron->id,
394
        {   borrowernumber    => $patron->id,
395
            accounttype       => "OVERDUE",
395
            debit_type_code       => "OVERDUE",
396
            status            => "UNRETURNED",
396
            status            => "UNRETURNED",
397
            amount            => 100,
397
            amount            => 100,
398
            amountoutstanding => 100,
398
            amountoutstanding => 100,
Lines 406-412 subtest 'adjust() tests' => sub { Link Here
406
    qr/Update type not recognised/, 'Exception thrown for unrecognised type';
406
    qr/Update type not recognised/, 'Exception thrown for unrecognised type';
407
407
408
    throws_ok { $debit_1->adjust( { amount => 50, type => 'overdue_update', interface => 'commandline' } ) }
408
    throws_ok { $debit_1->adjust( { amount => 50, type => 'overdue_update', interface => 'commandline' } ) }
409
    qr/Update type not allowed on this accounttype/,
409
    qr/Update type not allowed on this debit_type/,
410
      'Exception thrown for type conflict';
410
      'Exception thrown for type conflict';
411
411
412
    # Increment an unpaid fine
412
    # Increment an unpaid fine
(-)a/t/db_dependent/Koha/Patron.t (-3 / +3 lines)
Lines 112-120 subtest 'add_enrolment_fee_if_needed() tests' => sub { Link Here
112
112
113
        my @debits = $account->outstanding_debits;
113
        my @debits = $account->outstanding_debits;
114
        is( scalar @debits, 3, '3 enrolment fees' );
114
        is( scalar @debits, 3, '3 enrolment fees' );
115
        is( $debits[0]->accounttype, 'ACCOUNT', 'Account type set correctly' );
115
        is( $debits[0]->debit_type_code, 'ACCOUNT', 'Account type set correctly' );
116
        is( $debits[1]->accounttype, 'ACCOUNT', 'Account type set correctly' );
116
        is( $debits[1]->debit_type_code, 'ACCOUNT', 'Account type set correctly' );
117
        is( $debits[2]->accounttype, 'ACCOUNT_RENEW', 'Account type set correctly' );
117
        is( $debits[2]->debit_type_code, 'ACCOUNT_RENEW', 'Account type set correctly' );
118
118
119
        $schema->storage->txn_rollback;
119
        $schema->storage->txn_rollback;
120
    };
120
    };
(-)a/t/db_dependent/Reserves.t (-1 / +1 lines)
Lines 739-745 subtest 'ChargeReserveFee tests' => sub { Link Here
739
739
740
    is( ref($line), 'Koha::Account::Line' , 'Returns a Koha::Account::Line object');
740
    is( ref($line), 'Koha::Account::Line' , 'Returns a Koha::Account::Line object');
741
    ok( $line->is_debit, 'Generates a debit line' );
741
    ok( $line->is_debit, 'Generates a debit line' );
742
    is( $line->accounttype, 'Res' , 'generates Res accounttype');
742
    is( $line->debit_type_code, 'Res' , 'generates Res debit_type');
743
    is( $line->borrowernumber, $patron->id , 'generated line belongs to the passed patron');
743
    is( $line->borrowernumber, $patron->id , 'generated line belongs to the passed patron');
744
    is( $line->amount, $fee , 'amount set correctly');
744
    is( $line->amount, $fee , 'amount set correctly');
745
    is( $line->amountoutstanding, $fee , 'amountoutstanding set correctly');
745
    is( $line->amountoutstanding, $fee , 'amountoutstanding set correctly');
(-)a/t/db_dependent/api/v1/patrons_accounts.t (-6 / +5 lines)
Lines 65-71 subtest 'get_balance() tests' => sub { Link Here
65
            date              => \'NOW()',
65
            date              => \'NOW()',
66
            amount            => 50,
66
            amount            => 50,
67
            description       => "A description",
67
            description       => "A description",
68
            accounttype       => "N", # New card
68
            debit_type_code   => "N", # New card
69
            amountoutstanding => 50,
69
            amountoutstanding => 50,
70
            manager_id        => $patron->borrowernumber,
70
            manager_id        => $patron->borrowernumber,
71
            branchcode        => $library->id,
71
            branchcode        => $library->id,
Lines 80-86 subtest 'get_balance() tests' => sub { Link Here
80
            date              => \'NOW()',
80
            date              => \'NOW()',
81
            amount            => 50.01,
81
            amount            => 50.01,
82
            description       => "A description",
82
            description       => "A description",
83
            accounttype       => "N", # New card
83
            debit_type_code   => "N", # New card
84
            amountoutstanding => 50.01,
84
            amountoutstanding => 50.01,
85
            manager_id        => $patron->borrowernumber,
85
            manager_id        => $patron->borrowernumber,
86
            branchcode        => $library->id,
86
            branchcode        => $library->id,
Lines 183-189 subtest 'add_credit() tests' => sub { Link Here
183
            date              => \'NOW()',
183
            date              => \'NOW()',
184
            amount            => 10,
184
            amount            => 10,
185
            description       => "A description",
185
            description       => "A description",
186
            accounttype       => "N",                       # New card
186
            debit_type_code   => "N",                       # New card
187
            amountoutstanding => 10,
187
            amountoutstanding => 10,
188
            manager_id        => $patron->borrowernumber,
188
            manager_id        => $patron->borrowernumber,
189
            interface         => 'test',
189
            interface         => 'test',
Lines 194-200 subtest 'add_credit() tests' => sub { Link Here
194
            date              => \'NOW()',
194
            date              => \'NOW()',
195
            amount            => 15,
195
            amount            => 15,
196
            description       => "A description",
196
            description       => "A description",
197
            accounttype       => "N",                       # New card
197
            debit_type_code   => "N",                       # New card
198
            amountoutstanding => 15,
198
            amountoutstanding => 15,
199
            manager_id        => $patron->borrowernumber,
199
            manager_id        => $patron->borrowernumber,
200
            interface         => 'test',
200
            interface         => 'test',
Lines 221-227 subtest 'add_credit() tests' => sub { Link Here
221
            date              => \'NOW()',
221
            date              => \'NOW()',
222
            amount            => 100,
222
            amount            => 100,
223
            description       => "A description",
223
            description       => "A description",
224
            accounttype       => "N",                       # New card
224
            debit_type_code   => "N",                       # New card
225
            amountoutstanding => 100,
225
            amountoutstanding => 100,
226
            manager_id        => $patron->borrowernumber,
226
            manager_id        => $patron->borrowernumber,
227
            interface         => 'test',
227
            interface         => 'test',
228
- 

Return to bug 23049