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

(-)a/C4/Accounts.pm (+9 lines)
Lines 141-146 sub chargelostitem{ Link Here
141
    my $processfee = $itype->processfee;
141
    my $processfee = $itype->processfee;
142
    my $usedefaultreplacementcost = C4::Context->preference("useDefaultReplacementCost");
142
    my $usedefaultreplacementcost = C4::Context->preference("useDefaultReplacementCost");
143
    my $processingfeenote = C4::Context->preference("ProcessingFeeNote");
143
    my $processingfeenote = C4::Context->preference("ProcessingFeeNote");
144
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
144
    if ($usedefaultreplacementcost && $amount == 0 && $defaultreplacecost){
145
    if ($usedefaultreplacementcost && $amount == 0 && $defaultreplacecost){
145
        $replacementprice = $defaultreplacecost;
146
        $replacementprice = $defaultreplacecost;
146
    }
147
    }
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 210-215 sub chargelostitem{ Link Here
210
                    amountoutstanding => $replacementprice,
213
                    amountoutstanding => $replacementprice,
211
                    itemnumber        => $itemnumber,
214
                    itemnumber        => $itemnumber,
212
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
215
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
216
                    branchcode        => $branchcode,
213
                }
217
                }
214
            )->store();
218
            )->store();
215
219
Lines 274-279 sub manualinvoice { Link Here
274
    my $accountno  = getnextacctno($borrowernumber);
278
    my $accountno  = getnextacctno($borrowernumber);
275
    my $amountleft = $amount;
279
    my $amountleft = $amount;
276
280
281
    $itemnum ||= undef;
282
283
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
284
277
    my $accountline = Koha::Account::Line->new(
285
    my $accountline = Koha::Account::Line->new(
278
        {
286
        {
279
            borrowernumber    => $borrowernumber,
287
            borrowernumber    => $borrowernumber,
Lines 286-291 sub manualinvoice { Link Here
286
            itemnumber        => $itemnum || undef,
294
            itemnumber        => $itemnum || undef,
287
            note              => $note,
295
            note              => $note,
288
            manager_id        => $manager_id,
296
            manager_id        => $manager_id,
297
            branchcode        => $branchcode,
289
        }
298
        }
290
    )->store();
299
    )->store();
291
300
(-)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 2827-2844 sub AddRenewal { Link Here
2827
    # Charge a new rental fee, if applicable?
2828
    # Charge a new rental fee, if applicable?
2828
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2829
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2829
    if ( $charge > 0 ) {
2830
    if ( $charge > 0 ) {
2830
        my $accountno = getnextacctno( $borrowernumber );
2831
        my $accountno = C4::Accounts::getnextacctno( $borrowernumber );
2831
        my $manager_id = 0;
2832
        my $manager_id = 0;
2832
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2833
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2833
        $sth = $dbh->prepare(
2834
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2834
                "INSERT INTO accountlines
2835
        Koha::Account::Line->new(
2835
                    (date, borrowernumber, accountno, amount, manager_id,
2836
            {
2836
                    description,accounttype, amountoutstanding, itemnumber)
2837
                date              => dt_from_string(),
2837
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2838
                borrowernumber    => $borrowernumber,
2838
        );
2839
                accountno         => $accountno,
2839
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2840
                amount            => $charge,
2840
            "Renewal of Rental Item " . $biblio->title . " $item->{'barcode'}",
2841
                manager_id        => $manager_id,
2841
            'Rent', $charge, $itemnumber );
2842
                accounttype       => 'Rent',
2843
                amountoutstanding => $charge,
2844
                itemnumber        => $itemnumber,
2845
                branchcode        => $branchcode,
2846
                description       => 'Renewal of Rental Item '
2847
                  . $biblio->title
2848
                  . " $item->{'barcode'}",
2849
            }
2850
        )->store();
2842
    }
2851
    }
2843
2852
2844
    # Send a renewal slip according to checkout alert preferencei
2853
    # Send a renewal slip according to checkout alert preferencei
Lines 3170-3175 sub AddIssuingCharge { Link Here
3170
    my $manager_id  = 0;
3179
    my $manager_id  = 0;
3171
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
3180
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
3172
3181
3182
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
3173
    my $accountline = Koha::Account::Line->new(
3183
    my $accountline = Koha::Account::Line->new(
3174
        {
3184
        {
3175
            borrowernumber    => $borrowernumber,
3185
            borrowernumber    => $borrowernumber,
Lines 3178-3190 sub AddIssuingCharge { Link Here
3178
            amount            => $charge,
3188
            amount            => $charge,
3179
            amountoutstanding => $charge,
3189
            amountoutstanding => $charge,
3180
            manager_id        => $manager_id,
3190
            manager_id        => $manager_id,
3191
            branchcode        => $branchcode,
3181
            description       => 'Rental',
3192
            description       => 'Rental',
3182
            accounttype       => 'Rent',
3193
            accounttype       => 'Rent',
3183
            date              => \'NOW()',
3194
            date              => \'NOW()',
3184
        }
3195
        }
3185
    )->store();
3196
    )->store();
3186
3197
3187
    Koha::Account::Offset->new(
3198
    return Koha::Account::Offset->new(
3188
        {
3199
        {
3189
            debit_id => $accountline->id,
3200
            debit_id => $accountline->id,
3190
            type     => 'Rental Fee',
3201
            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 76-81 sub pay { Link Here
76
    my $account_type = $params->{account_type};
76
    my $account_type = $params->{account_type};
77
    my $offset_type  = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment';
77
    my $offset_type  = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment';
78
78
79
    $library_id ||= C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
80
79
    my $userenv = C4::Context->userenv;
81
    my $userenv = C4::Context->userenv;
80
82
81
    # We should remove accountno, it is no longer needed
83
    # We should remove accountno, it is no longer needed
Lines 218-223 sub pay { Link Here
218
            accounttype       => $account_type,
220
            accounttype       => $account_type,
219
            amountoutstanding => 0 - $balance_remaining,
221
            amountoutstanding => 0 - $balance_remaining,
220
            manager_id        => $manager_id,
222
            manager_id        => $manager_id,
223
            branchcode        => $library_id,
221
            note              => $note,
224
            note              => $note,
222
        }
225
        }
223
    )->store();
226
    )->store();
Lines 227-234 sub pay { Link Here
227
        $o->store();
230
        $o->store();
228
    }
231
    }
229
232
230
    $library_id ||= $userenv ? $userenv->{'branch'} : undef;
231
232
    UpdateStats(
233
    UpdateStats(
233
        {
234
        {
234
            branch         => $library_id,
235
            branch         => $library_id,
(-)a/t/db_dependent/Accounts.t (-3 / +50 lines)
Lines 18-24 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 24;
21
use Test::More tests => 37;
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 $itemtype = $builder->build( { source => 'Itemtype' } );
79
my $item   = $builder->build( { source => 'Item', value => { itype => $itemtype->{itemtype} } } );
80
my $patron = $builder->build( { source => 'Borrower' } );
81
my $amount = '5.000000';
82
my $description = "Test fee!";
83
chargelostitem( $patron->{borrowernumber}, $item->{itemnumber}, $amount, $description );
84
my ($accountline) = Koha::Account::Lines->search(
85
    {
86
        borrowernumber => $patron->{borrowernumber}
87
    }
88
);
89
is( $accountline->amount, $amount, 'Accountline amount set correctly for chargelostitem' );
90
is( $accountline->description, $description, 'Accountline description set correctly for chargelostitem' );
91
is( $accountline->branchcode, $userenv_branchcode, 'Accountline branchcode set correctly for chargelostitem' );
92
$dbh->do(q|DELETE FROM accountlines|);
93
94
# Test manualinvoice, reuse some of the vars from testing chargelostitem
95
my $type = 'L';
96
my $note = 'Test note!';
97
manualinvoice( $patron->{borrowernumber}, $item->{itemnumber}, $description, $type, $amount, $note );
98
($accountline) = Koha::Account::Lines->search(
99
    {
100
        borrowernumber => $patron->{borrowernumber}
101
    }
102
);
103
is( $accountline->accounttype, $type, 'Accountline type set correctly for manualinvoice' );
104
is( $accountline->amount, $amount, 'Accountline amount set correctly for manualinvoice' );
105
ok( $accountline->description =~ /^$description/, 'Accountline description set correctly for manualinvoice' );
106
is( $accountline->note, $note, 'Accountline note set correctly for manualinvoice' );
107
is( $accountline->branchcode, $branchcode, 'Accountline branchcode set correctly for manualinvoice' );
108
109
# Test _FixAccountForLostAndReturned, use the accountline from the manualinvoice to test
110
C4::Circulation::_FixAccountForLostAndReturned( $item->{itemnumber} );
111
my ( $accountline_fee, $accountline_payment ) = Koha::Account::Lines->search(
112
    {
113
        borrowernumber => $patron->{borrowernumber}
114
    }
115
);
116
is( $accountline_fee->accounttype, 'LR', 'Lost item fee account type updated to LR' );
117
is( $accountline_fee->amountoutstanding, '0.000000', 'Lost item fee amount outstanding updated to 0' );
118
is( $accountline_payment->accounttype, 'CR', 'Lost item fee account type is CR' );
119
is( $accountline_payment->amount, "-$amount", 'Lost item refund amount is correct' );
120
is( $accountline_payment->branchcode, $branchcode, 'Lost item refund branchcode is set correctly' );
121
$dbh->do(q|DELETE FROM accountlines|);
75
122
76
# Testing purge_zero_balance_fees
123
# Testing purge_zero_balance_fees
77
124
Lines 137-143 $dbh->do(q|DELETE FROM accountlines|); Link Here
137
184
138
subtest "Koha::Account::pay tests" => sub {
185
subtest "Koha::Account::pay tests" => sub {
139
186
140
    plan tests => 12;
187
    plan tests => 13;
141
188
142
    # Create a borrower
189
    # Create a borrower
143
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
190
    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" );
304
    is( $payment->amount(), '-42.000000', "Payment paid the specified fine" );
258
    $line3 = Koha::Account::Lines->find( $line3->id );
305
    $line3 = Koha::Account::Lines->find( $line3->id );
259
    is( $line3->amountoutstanding, '0.000000', "Specified fine is paid" );
306
    is( $line3->amountoutstanding, '0.000000', "Specified fine is paid" );
307
    is( $payment->branchcode, $userenv_branchcode, 'Branchcode set correctly' );
260
};
308
};
261
309
262
subtest "Koha::Account::pay particular line tests" => sub {
310
subtest "Koha::Account::pay particular line tests" => sub {
263
- 

Return to bug 19066