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

(-)a/Koha/Account.pm (-2 / +2 lines)
Lines 413-419 sub add_credit { Link Here
413
                $line = Koha::Account::Line->new(
413
                $line = Koha::Account::Line->new(
414
                    {
414
                    {
415
                        borrowernumber    => $self->{patron_id},
415
                        borrowernumber    => $self->{patron_id},
416
                        date              => \'NOW()',
416
                        date              => dt_from_string,
417
                        amount            => $amount,
417
                        amount            => $amount,
418
                        description       => $description,
418
                        description       => $description,
419
                        credit_type_code  => $credit_type,
419
                        credit_type_code  => $credit_type,
Lines 560-566 sub add_debit { Link Here
560
                $line = Koha::Account::Line->new(
560
                $line = Koha::Account::Line->new(
561
                    {
561
                    {
562
                        borrowernumber    => $self->{patron_id},
562
                        borrowernumber    => $self->{patron_id},
563
                        date              => \'NOW()',
563
                        date              => dt_from_string,
564
                        amount            => $amount,
564
                        amount            => $amount,
565
                        description       => $description,
565
                        description       => $description,
566
                        debit_type_code   => $debit_type,
566
                        debit_type_code   => $debit_type,
(-)a/Koha/Account/Line.pm (-9 / +16 lines)
Lines 247-252 sub void { Link Here
247
                        debit_id  => $fee_paid->id,
247
                        debit_id  => $fee_paid->id,
248
                        amount    => $amount_paid,
248
                        amount    => $amount_paid,
249
                        type      => 'Void Payment',
249
                        type      => 'Void Payment',
250
                        created_on => dt_from_string
250
                    }
251
                    }
251
                )->store();
252
                )->store();
252
            }
253
            }
Lines 341-347 sub cancel { Link Here
341
            # A 'cancellation' is a 'credit'
342
            # A 'cancellation' is a 'credit'
342
            $cancellation = Koha::Account::Line->new(
343
            $cancellation = Koha::Account::Line->new(
343
                {
344
                {
344
                    date              => \'NOW()',
345
                    date              => dt_from_string,
345
                    amount            => 0 - $self->amount,
346
                    amount            => 0 - $self->amount,
346
                    credit_type_code  => 'CANCELLATION',
347
                    credit_type_code  => 'CANCELLATION',
347
                    status            => 'ADDED',
348
                    status            => 'ADDED',
Lines 357-363 sub cancel { Link Here
357
                {
358
                {
358
                    credit_id => $cancellation->accountlines_id,
359
                    credit_id => $cancellation->accountlines_id,
359
                    type      => 'CANCELLATION',
360
                    type      => 'CANCELLATION',
360
                    amount    => $self->amount
361
                    amount    => $self->amount,
362
                    created_on => dt_from_string
361
                }
363
                }
362
            )->store();
364
            )->store();
363
365
Lines 465-471 sub reduce { Link Here
465
            # A 'reduction' is a 'credit'
467
            # A 'reduction' is a 'credit'
466
            $reduction = Koha::Account::Line->new(
468
            $reduction = Koha::Account::Line->new(
467
                {
469
                {
468
                    date              => \'NOW()',
470
                    date              => dt_from_string,
469
                    amount            => 0 - $params->{amount},
471
                    amount            => 0 - $params->{amount},
470
                    credit_type_code  => $params->{reduction_type},
472
                    credit_type_code  => $params->{reduction_type},
471
                    status            => 'ADDED',
473
                    status            => 'ADDED',
Lines 481-487 sub reduce { Link Here
481
                {
483
                {
482
                    credit_id => $reduction->accountlines_id,
484
                    credit_id => $reduction->accountlines_id,
483
                    type      => uc( $params->{reduction_type} ),
485
                    type      => uc( $params->{reduction_type} ),
484
                    amount    => $params->{amount}
486
                    amount    => $params->{amount},
487
                    created_on => dt_from_string
485
                }
488
                }
486
            )->store();
489
            )->store();
487
490
Lines 506-512 sub reduce { Link Here
506
                        credit_id => $reduction->accountlines_id,
509
                        credit_id => $reduction->accountlines_id,
507
                        debit_id  => $self->accountlines_id,
510
                        debit_id  => $self->accountlines_id,
508
                        type      => uc( $params->{reduction_type} ),
511
                        type      => uc( $params->{reduction_type} ),
509
                        amount    => 0
512
                        amount    => 0,
513
                        created_on => dt_from_string
510
                    }
514
                    }
511
                )->store();
515
                )->store();
512
            }
516
            }
Lines 586-591 sub apply { Link Here
586
                    debit_id  => $debit->id,
590
                    debit_id  => $debit->id,
587
                    amount    => $amount_to_cancel * -1,
591
                    amount    => $amount_to_cancel * -1,
588
                    type      => $offset_type,
592
                    type      => $offset_type,
593
                    created_on => dt_from_string
589
                }
594
                }
590
            )->store();
595
            )->store();
591
596
Lines 687-693 sub payout { Link Here
687
            # A 'payout' is a 'debit'
692
            # A 'payout' is a 'debit'
688
            $payout = Koha::Account::Line->new(
693
            $payout = Koha::Account::Line->new(
689
                {
694
                {
690
                    date              => \'NOW()',
695
                    date              => dt_from_string,
691
                    amount            => $amount,
696
                    amount            => $amount,
692
                    debit_type_code   => 'PAYOUT',
697
                    debit_type_code   => 'PAYOUT',
693
                    payment_type      => $params->{payout_type},
698
                    payment_type      => $params->{payout_type},
Lines 704-710 sub payout { Link Here
704
                {
709
                {
705
                    debit_id => $payout->accountlines_id,
710
                    debit_id => $payout->accountlines_id,
706
                    type     => 'PAYOUT',
711
                    type     => 'PAYOUT',
707
                    amount   => $amount
712
                    amount   => $amount,
713
                    created_on => dt_from_string
708
                }
714
                }
709
            )->store();
715
            )->store();
710
716
Lines 801-807 sub adjust { Link Here
801
            # Update the account line
807
            # Update the account line
802
            $self->set(
808
            $self->set(
803
                {
809
                {
804
                    date              => \'NOW()',
810
                    date              => dt_from_string,
805
                    amount            => $amount,
811
                    amount            => $amount,
806
                    amountoutstanding => $new_outstanding,
812
                    amountoutstanding => $new_outstanding,
807
                }
813
                }
Lines 812-818 sub adjust { Link Here
812
                {
818
                {
813
                    debit_id => $self->id,
819
                    debit_id => $self->id,
814
                    type     => $offset_type,
820
                    type     => $offset_type,
815
                    amount   => $difference
821
                    amount   => $difference,
822
                    created_on => dt_from_string
816
                }
823
                }
817
            )->store();
824
            )->store();
818
825
(-)a/t/db_dependent/Koha/Account/Line.t (-4 / +21 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Test::More tests => 14;
22
use Test::More tests => 14;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::MockModule;
24
use Test::MockModule;
25
use Time::Fake;
25
26
26
use DateTime;
27
use DateTime;
27
28
Lines 466-471 subtest 'adjust() tests' => sub { Link Here
466
    plan tests => 29;
467
    plan tests => 29;
467
468
468
    $schema->storage->txn_begin;
469
    $schema->storage->txn_begin;
470
    my $faketime = DateTime->now->subtract( hours => 4 );
471
    Time::Fake->offset($faketime->epoch);
469
472
470
    # count logs before any actions
473
    # count logs before any actions
471
    my $action_logs = $schema->resultset('ActionLog')->search()->count;
474
    my $action_logs = $schema->resultset('ActionLog')->search()->count;
Lines 510-522 subtest 'adjust() tests' => sub { Link Here
510
513
511
    is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' );
514
    is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' );
512
    is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' );
515
    is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' );
513
    isnt( $debit_2->date, undef, 'Date has been set' );
516
    is( $debit_2->date, $faketime->strftime('%F %T'), "Instance time was used to set date");
514
517
515
    my $offsets = Koha::Account::Offsets->search( { debit_id => $debit_2->id } );
518
    my $offsets = Koha::Account::Offsets->search( { debit_id => $debit_2->id } );
516
    is( $offsets->count, 1, 'An offset is generated for the increment' );
519
    is( $offsets->count, 1, 'An offset is generated for the increment' );
517
    my $THIS_offset = $offsets->next;
520
    my $THIS_offset = $offsets->next;
518
    is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' );
521
    is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' );
519
    is( $THIS_offset->type, 'OVERDUE_INCREASE', 'Adjust type stored correctly' );
522
    is( $THIS_offset->type, 'OVERDUE_INCREASE', 'Adjust type stored correctly' );
523
    is( $THIS_offset->created_on, $faketime->strftime('%F %T'), "Instance time was used to set created_on date");
520
524
521
    is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' );
525
    is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' );
522
526
Lines 777-782 subtest "payout() tests" => sub { Link Here
777
    plan tests => 18;
781
    plan tests => 18;
778
782
779
    $schema->storage->txn_begin;
783
    $schema->storage->txn_begin;
784
    my $faketime = DateTime->now->subtract( hours => 4 );
785
    Time::Fake->offset($faketime->epoch);
780
786
781
    # Create a borrower
787
    # Create a borrower
782
    my $categorycode =
788
    my $categorycode =
Lines 906-920 subtest "payout() tests" => sub { Link Here
906
    is( $credit1->amountoutstanding + 0,
912
    is( $credit1->amountoutstanding + 0,
907
        -10, 'Credit has an new amount outstanding of -10' );
913
        -10, 'Credit has an new amount outstanding of -10' );
908
    is( $credit1->status(), 'PAID', "Credit has a new status of PAID" );
914
    is( $credit1->status(), 'PAID', "Credit has a new status of PAID" );
915
    is( $payout->date, $faketime->strftime('%F %T'), "Instance time was used to set payout date");
909
916
917
    Time::Fake->reset;
910
    $schema->storage->txn_rollback;
918
    $schema->storage->txn_rollback;
911
};
919
};
912
920
913
subtest "reduce() tests" => sub {
921
subtest "reduce() tests" => sub {
914
922
915
    plan tests => 29;
923
    plan tests => 31;
916
924
917
    $schema->storage->txn_begin;
925
    $schema->storage->txn_begin;
926
    my $faketime = DateTime->now->subtract( hours => 4 );
927
    Time::Fake->offset($faketime->epoch);
918
928
919
    # Create a borrower
929
    # Create a borrower
920
    my $categorycode =
930
    my $categorycode =
Lines 1033-1038 subtest "reduce() tests" => sub { Link Here
1033
    is( $debit1->status(), 'DISCOUNTED', "Debit status updated to DISCOUNTED");
1043
    is( $debit1->status(), 'DISCOUNTED', "Debit status updated to DISCOUNTED");
1034
    is( $account->balance() * 1, -5,        "Account balance is -5" );
1044
    is( $account->balance() * 1, -5,        "Account balance is -5" );
1035
    is( $reduction->status(),    'APPLIED', "Reduction status is 'APPLIED'" );
1045
    is( $reduction->status(),    'APPLIED', "Reduction status is 'APPLIED'" );
1046
    is( $reduction->date(), $faketime->strftime('%F %T'), "Instance time was used to set reduction date");
1036
1047
1037
    my $offsets = Koha::Account::Offsets->search(
1048
    my $offsets = Koha::Account::Offsets->search(
1038
        { credit_id => $reduction->id, debit_id => $debit1->id } );
1049
        { credit_id => $reduction->id, debit_id => $debit1->id } );
Lines 1041-1046 subtest "reduce() tests" => sub { Link Here
1041
    is( $THE_offset->amount * 1,
1052
    is( $THE_offset->amount * 1,
1042
        -5, 'Correct amount was applied against debit' );
1053
        -5, 'Correct amount was applied against debit' );
1043
    is( $THE_offset->type, 'DISCOUNT', "Offset type set to 'DISCOUNT'" );
1054
    is( $THE_offset->type, 'DISCOUNT', "Offset type set to 'DISCOUNT'" );
1055
    is( $THE_offset->created_on, $faketime->strftime('%F %T'), "Instance time was used to set created_on date");
1044
1056
1045
    # Zero offset created when zero outstanding
1057
    # Zero offset created when zero outstanding
1046
    # (Refund another 5 on paid debt of 20)
1058
    # (Refund another 5 on paid debt of 20)
Lines 1087-1099 subtest "reduce() tests" => sub { Link Here
1087
    'Koha::Exceptions::Account::IsNotDebit',
1099
    'Koha::Exceptions::Account::IsNotDebit',
1088
      '->reduce() cannot be used on a payout debit';
1100
      '->reduce() cannot be used on a payout debit';
1089
1101
1102
    Time::Fake->reset;
1090
    $schema->storage->txn_rollback;
1103
    $schema->storage->txn_rollback;
1091
};
1104
};
1092
1105
1093
subtest "cancel() tests" => sub {
1106
subtest "cancel() tests" => sub {
1094
    plan tests => 16;
1107
    plan tests => 18;
1095
1108
1096
    $schema->storage->txn_begin;
1109
    $schema->storage->txn_begin;
1110
    my $faketime = DateTime->now->subtract( hours => 4 );
1111
    Time::Fake->offset($faketime->epoch);
1097
1112
1098
    my $library = $builder->build_object( { class => 'Koha::Libraries' });
1113
    my $library = $builder->build_object( { class => 'Koha::Libraries' });
1099
    my $patron  = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->branchcode } });
1114
    my $patron  = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->branchcode } });
Lines 1175-1180 subtest "cancel() tests" => sub { Link Here
1175
        0, "Debit amountoutstanding reduced to 0" );
1190
        0, "Debit amountoutstanding reduced to 0" );
1176
    is( $debit1->status(), 'CANCELLED', "Debit status updated to CANCELLED" );
1191
    is( $debit1->status(), 'CANCELLED', "Debit status updated to CANCELLED" );
1177
    is( $account->balance() * 1, 15, "Account balance is 15" );
1192
    is( $account->balance() * 1, 15, "Account balance is 15" );
1193
    is( $cancellation->date, $faketime->strftime('%F %T'), "Instance time was used to set cancellation date");
1178
1194
1179
    my $offsets = Koha::Account::Offsets->search(
1195
    my $offsets = Koha::Account::Offsets->search(
1180
        { credit_id => $cancellation->id, debit_id => $debit1->id } );
1196
        { credit_id => $cancellation->id, debit_id => $debit1->id } );
Lines 1184-1190 subtest "cancel() tests" => sub { Link Here
1184
        -10, 'Correct amount was applied against debit' );
1200
        -10, 'Correct amount was applied against debit' );
1185
    is( $THE_offset->type, 'CANCELLATION',
1201
    is( $THE_offset->type, 'CANCELLATION',
1186
        "Offset type set to 'CANCELLATION'" );
1202
        "Offset type set to 'CANCELLATION'" );
1203
    is( $THE_offset->created_on, $faketime->strftime('%F %T'), "Instance time was used to set created_on date");
1187
1204
1205
    Time::Fake->reset;
1188
    $schema->storage->txn_rollback;
1206
    $schema->storage->txn_rollback;
1189
};
1207
};
1190
1208
1191
- 

Return to bug 27574