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

(-)a/C4/Accounts.pm (+8 lines)
Lines 159-164 sub chargelostitem{ Link Here
159
    unless ($existing_charges) {
159
    unless ($existing_charges) {
160
        #add processing fee
160
        #add processing fee
161
        if ($processfee && $processfee > 0){
161
        if ($processfee && $processfee > 0){
162
            my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
162
            my $accountline = Koha::Account::Line->new(
163
            my $accountline = Koha::Account::Line->new(
163
                {
164
                {
164
                    borrowernumber    => $borrowernumber,
165
                    borrowernumber    => $borrowernumber,
Lines 171-176 sub chargelostitem{ Link Here
171
                    itemnumber        => $itemnumber,
172
                    itemnumber        => $itemnumber,
172
                    note              => $processingfeenote,
173
                    note              => $processingfeenote,
173
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
174
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
175
                    branchcode        => $branchcode,
174
                }
176
                }
175
            )->store();
177
            )->store();
176
178
Lines 194-199 sub chargelostitem{ Link Here
194
                    note              => $accountline->note,
196
                    note              => $accountline->note,
195
                    itemnumber        => $accountline->itemnumber,
197
                    itemnumber        => $accountline->itemnumber,
196
                    manager_id        => $accountline->manager_id,
198
                    manager_id        => $accountline->manager_id,
199
                    branchcode        => $branchcode,
197
                }));
200
                }));
198
            }
201
            }
199
        }
202
        }
Lines 274-279 sub manualinvoice { Link Here
274
    my $accountno  = getnextacctno($borrowernumber);
277
    my $accountno  = getnextacctno($borrowernumber);
275
    my $amountleft = $amount;
278
    my $amountleft = $amount;
276
279
280
    $itemnum ||= undef;
281
282
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
283
277
    my $accountline = Koha::Account::Line->new(
284
    my $accountline = Koha::Account::Line->new(
278
        {
285
        {
279
            borrowernumber    => $borrowernumber,
286
            borrowernumber    => $borrowernumber,
Lines 286-291 sub manualinvoice { Link Here
286
            itemnumber        => $itemnum || undef,
293
            itemnumber        => $itemnum || undef,
287
            note              => $note,
294
            note              => $note,
288
            manager_id        => $manager_id,
295
            manager_id        => $manager_id,
296
            branchcode        => $branchcode,
289
        }
297
        }
290
    )->store();
298
    )->store();
291
299
(-)a/C4/Circulation.pm (-11 / +22 lines)
Lines 51-56 use Koha::Patrons; Link Here
51
use Koha::Patron::Debarments;
51
use Koha::Patron::Debarments;
52
use Koha::Database;
52
use Koha::Database;
53
use Koha::Libraries;
53
use Koha::Libraries;
54
use Koha::Account::Lines;
54
use Koha::Holds;
55
use Koha::Holds;
55
use Koha::RefundLostItemFeeRule;
56
use Koha::RefundLostItemFeeRule;
56
use Koha::RefundLostItemFeeRules;
57
use Koha::RefundLostItemFeeRules;
Lines 2859-2876 sub AddRenewal { Link Here
2859
    # Charge a new rental fee, if applicable?
2860
    # Charge a new rental fee, if applicable?
2860
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2861
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2861
    if ( $charge > 0 ) {
2862
    if ( $charge > 0 ) {
2862
        my $accountno = getnextacctno( $borrowernumber );
2863
        my $accountno = C4::Accounts::getnextacctno( $borrowernumber );
2863
        my $manager_id = 0;
2864
        my $manager_id = 0;
2864
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2865
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2865
        $sth = $dbh->prepare(
2866
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2866
                "INSERT INTO accountlines
2867
        Koha::Account::Line->new(
2867
                    (date, borrowernumber, accountno, amount, manager_id,
2868
            {
2868
                    description,accounttype, amountoutstanding, itemnumber)
2869
                date              => dt_from_string(),
2869
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2870
                borrowernumber    => $borrowernumber,
2870
        );
2871
                accountno         => $accountno,
2871
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2872
                amount            => $charge,
2872
            "Renewal of Rental Item " . $biblio->title . " $item->{'barcode'}",
2873
                manager_id        => $manager_id,
2873
            'Rent', $charge, $itemnumber );
2874
                accounttype       => 'Rent',
2875
                amountoutstanding => $charge,
2876
                itemnumber        => $itemnumber,
2877
                branchcode        => $branchcode,
2878
                description       => 'Renewal of Rental Item '
2879
                  . $biblio->title
2880
                  . " $item->{'barcode'}",
2881
            }
2882
        )->store();
2874
    }
2883
    }
2875
2884
2876
    # Send a renewal slip according to checkout alert preferencei
2885
    # Send a renewal slip according to checkout alert preferencei
Lines 3202-3207 sub AddIssuingCharge { Link Here
3202
    my $manager_id  = 0;
3211
    my $manager_id  = 0;
3203
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
3212
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
3204
3213
3214
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
3205
    my $accountline = Koha::Account::Line->new(
3215
    my $accountline = Koha::Account::Line->new(
3206
        {
3216
        {
3207
            borrowernumber    => $borrowernumber,
3217
            borrowernumber    => $borrowernumber,
Lines 3210-3222 sub AddIssuingCharge { Link Here
3210
            amount            => $charge,
3220
            amount            => $charge,
3211
            amountoutstanding => $charge,
3221
            amountoutstanding => $charge,
3212
            manager_id        => $manager_id,
3222
            manager_id        => $manager_id,
3223
            branchcode        => $branchcode,
3213
            description       => 'Rental',
3224
            description       => 'Rental',
3214
            accounttype       => 'Rent',
3225
            accounttype       => 'Rent',
3215
            date              => \'NOW()',
3226
            date              => \'NOW()',
3216
        }
3227
        }
3217
    )->store();
3228
    )->store();
3218
3229
3219
    Koha::Account::Offset->new(
3230
    return Koha::Account::Offset->new(
3220
        {
3231
        {
3221
            debit_id => $accountline->id,
3232
            debit_id => $accountline->id,
3222
            type     => 'Rental Fee',
3233
            type     => 'Rental Fee',
(-)a/C4/Reserves.pm (-7 / +18 lines)
Lines 48-53 use Koha::IssuingRules; Link Here
48
use Koha::Items;
48
use Koha::Items;
49
use Koha::ItemTypes;
49
use Koha::ItemTypes;
50
use Koha::Patrons;
50
use Koha::Patrons;
51
use Koha::Account::Lines;
51
52
52
use List::MoreUtils qw( firstidx any );
53
use List::MoreUtils qw( firstidx any );
53
use Carp;
54
use Carp;
Lines 508-520 sub GetOtherReserves { Link Here
508
509
509
sub ChargeReserveFee {
510
sub ChargeReserveFee {
510
    my ( $borrowernumber, $fee, $title ) = @_;
511
    my ( $borrowernumber, $fee, $title ) = @_;
511
    return if !$fee || $fee==0; # the last test is needed to include 0.00
512
512
    my $accquery = qq{
513
    return if !$fee || $fee == 0;    # the last test is needed to include 0.00
513
INSERT INTO accountlines ( borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding ) VALUES (?, ?, NOW(), ?, ?, 'Res', ?)
514
514
    };
515
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
515
    my $dbh = C4::Context->dbh;
516
    my $nextacctno = C4::Accounts::getnextacctno($borrowernumber);
516
    my $nextacctno = &getnextacctno( $borrowernumber );
517
517
    $dbh->do( $accquery, undef, ( $borrowernumber, $nextacctno, $fee, "Reserve Charge - $title", $fee ) );
518
    Koha::Account::Line->new(
519
        {
520
            borrowernumber    => $borrowernumber,
521
            accountno         => $nextacctno,
522
            date              => dt_from_string(),
523
            amount            => $fee,
524
            description       => "Reserve Charge - $title",
525
            accounttype       => 'Res',
526
            amountoutstanding => $fee,
527
        }
528
    )->store();
518
}
529
}
519
530
520
=head2 GetReserveFee
531
=head2 GetReserveFee
(-)a/Koha/Account.pm (-2 / +3 lines)
Lines 75-80 sub pay { Link Here
75
    my $account_type = $params->{account_type};
75
    my $account_type = $params->{account_type};
76
    my $offset_type  = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment';
76
    my $offset_type  = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment';
77
77
78
    $library_id ||= C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
79
78
    my $userenv = C4::Context->userenv;
80
    my $userenv = C4::Context->userenv;
79
81
80
    # We should remove accountno, it is no longer needed
82
    # We should remove accountno, it is no longer needed
Lines 217-222 sub pay { Link Here
217
            accounttype       => $account_type,
219
            accounttype       => $account_type,
218
            amountoutstanding => 0 - $balance_remaining,
220
            amountoutstanding => 0 - $balance_remaining,
219
            manager_id        => $manager_id,
221
            manager_id        => $manager_id,
222
            branchcode        => $library_id,
220
            note              => $note,
223
            note              => $note,
221
        }
224
        }
222
    )->store();
225
    )->store();
Lines 226-233 sub pay { Link Here
226
        $o->store();
229
        $o->store();
227
    }
230
    }
228
231
229
    $library_id ||= $userenv ? $userenv->{'branch'} : undef;
230
231
    UpdateStats(
232
    UpdateStats(
232
        {
233
        {
233
            branch         => $library_id,
234
            branch         => $library_id,
(-)a/t/db_dependent/Accounts.t (-3 / +49 lines)
Lines 18-24 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 23;
21
use Test::More tests => 36;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 72-77 $context->mock( 'userenv', sub { Link Here
72
        branch => $branchcode,
72
        branch => $branchcode,
73
    };
73
    };
74
});
74
});
75
my $userenv_branchcode = $branchcode;
76
77
# Test chargelostitem
78
my $item   = $builder->build( { source => 'Item' } );
79
my $patron = $builder->build( { source => 'Borrower' } );
80
my $amount = '5.000000';
81
my $description = "Test fee!";
82
chargelostitem( $patron->{borrowernumber}, $item->{itemnumber}, $amount, $description );
83
my ($accountline) = Koha::Account::Lines->search(
84
    {
85
        borrowernumber => $patron->{borrowernumber}
86
    }
87
);
88
is( $accountline->amount, $amount, 'Accountline amount set correctly for chargelostitem' );
89
is( $accountline->description, $description, 'Accountline description set correctly for chargelostitem' );
90
is( $accountline->branchcode, $branchcode, 'Accountline branchcode set correctly for chargelostitem' );
91
$dbh->do(q|DELETE FROM accountlines|);
92
93
# Test manualinvoice, reuse some of the vars from testing chargelostitem
94
my $type = 'L';
95
my $note = 'Test note!';
96
manualinvoice( $patron->{borrowernumber}, $item->{itemnumber}, $description, $type, $amount, $note );
97
($accountline) = Koha::Account::Lines->search(
98
    {
99
        borrowernumber => $patron->{borrowernumber}
100
    }
101
);
102
is( $accountline->accounttype, $type, 'Accountline type set correctly for manualinvoice' );
103
is( $accountline->amount, $amount, 'Accountline amount set correctly for manualinvoice' );
104
ok( $accountline->description =~ /^$description/, 'Accountline description set correctly for manualinvoice' );
105
is( $accountline->note, $note, 'Accountline note set correctly for manualinvoice' );
106
is( $accountline->branchcode, $branchcode, 'Accountline branchcode set correctly for manualinvoice' );
107
108
# Test _FixAccountForLostAndReturned, use the accountline from the manualinvoice to test
109
C4::Circulation::_FixAccountForLostAndReturned( $item->{itemnumber} );
110
my ( $accountline_fee, $accountline_payment ) = Koha::Account::Lines->search(
111
    {
112
        borrowernumber => $patron->{borrowernumber}
113
    }
114
);
115
is( $accountline_fee->accounttype, 'LR', 'Lost item fee account type updated to LR' );
116
is( $accountline_fee->amountoutstanding, '0.000000', 'Lost item fee amount outstanding updated to 0' );
117
is( $accountline_payment->accounttype, 'CR', 'Lost item fee account type is CR' );
118
is( $accountline_payment->amount, "-$amount", 'Lost item refund amount is correct' );
119
is( $accountline_payment->branchcode, $branchcode, 'Lost item refund branchcode is set correctly' );
120
$dbh->do(q|DELETE FROM accountlines|);
75
121
76
# Testing purge_zero_balance_fees
122
# Testing purge_zero_balance_fees
77
123
Lines 137-143 $dbh->do(q|DELETE FROM accountlines|); Link Here
137
183
138
subtest "Koha::Account::pay tests" => sub {
184
subtest "Koha::Account::pay tests" => sub {
139
185
140
    plan tests => 12;
186
    plan tests => 13;
141
187
142
    # Create a borrower
188
    # Create a borrower
143
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
189
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
Lines 257-262 subtest "Koha::Account::pay tests" => sub { Link Here
257
    is( $payment->amount(), '-42.000000', "Payment paid the specified fine" );
303
    is( $payment->amount(), '-42.000000', "Payment paid the specified fine" );
258
    $line3 = Koha::Account::Lines->find( $line3->id );
304
    $line3 = Koha::Account::Lines->find( $line3->id );
259
    is( $line3->amountoutstanding, '0.000000', "Specified fine is paid" );
305
    is( $line3->amountoutstanding, '0.000000', "Specified fine is paid" );
306
    is( $payment->branchcode, $userenv_branchcode, 'Branchcode set correctly' );
260
};
307
};
261
308
262
subtest "Koha::Account::pay particular line tests" => sub {
309
subtest "Koha::Account::pay particular line tests" => sub {
263
- 

Return to bug 19066