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

(-)a/C4/Accounts.pm (+8 lines)
Lines 141-146 sub chargelostitem{ Link Here
141
    if ($usedefaultreplacementcost && $amount == 0 && $defaultreplacecost){
141
    if ($usedefaultreplacementcost && $amount == 0 && $defaultreplacecost){
142
        $replacementprice = $defaultreplacecost;
142
        $replacementprice = $defaultreplacecost;
143
    }
143
    }
144
145
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
146
144
    # first make sure the borrower hasn't already been charged for this item
147
    # first make sure the borrower hasn't already been charged for this item
145
    # FIXME this should be more exact
148
    # FIXME this should be more exact
146
    #       there is no reason a user can't lose an item, find and return it, and lost it again
149
    #       there is no reason a user can't lose an item, find and return it, and lost it again
Lines 168-173 sub chargelostitem{ Link Here
168
                    itemnumber        => $itemnumber,
171
                    itemnumber        => $itemnumber,
169
                    note              => $processingfeenote,
172
                    note              => $processingfeenote,
170
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
173
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
174
                    branchcode        => $branchcode,
171
                }
175
                }
172
            )->store();
176
            )->store();
173
177
Lines 207-212 sub chargelostitem{ Link Here
207
                    amountoutstanding => $replacementprice,
211
                    amountoutstanding => $replacementprice,
208
                    itemnumber        => $itemnumber,
212
                    itemnumber        => $itemnumber,
209
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
213
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
214
                    branchcode        => $branchcode,
210
                }
215
                }
211
            )->store();
216
            )->store();
212
217
Lines 271-276 sub manualinvoice { Link Here
271
    my $accountno  = getnextacctno($borrowernumber);
276
    my $accountno  = getnextacctno($borrowernumber);
272
    my $amountleft = $amount;
277
    my $amountleft = $amount;
273
278
279
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
280
274
    my $accountline = Koha::Account::Line->new(
281
    my $accountline = Koha::Account::Line->new(
275
        {
282
        {
276
            borrowernumber    => $borrowernumber,
283
            borrowernumber    => $borrowernumber,
Lines 283-288 sub manualinvoice { Link Here
283
            itemnumber        => $itemnum || undef,
290
            itemnumber        => $itemnum || undef,
284
            note              => $note,
291
            note              => $note,
285
            manager_id        => $manager_id,
292
            manager_id        => $manager_id,
293
            branchcode        => $branchcode,
286
        }
294
        }
287
    )->store();
295
    )->store();
288
296
(-)a/C4/Circulation.pm (-10 / +22 lines)
Lines 52-57 use Koha::Patrons; Link Here
52
use Koha::Patron::Debarments;
52
use Koha::Patron::Debarments;
53
use Koha::Database;
53
use Koha::Database;
54
use Koha::Libraries;
54
use Koha::Libraries;
55
use Koha::Account::Lines;
55
use Koha::Holds;
56
use Koha::Holds;
56
use Koha::RefundLostItemFeeRule;
57
use Koha::RefundLostItemFeeRule;
57
use Koha::RefundLostItemFeeRules;
58
use Koha::RefundLostItemFeeRules;
Lines 2847-2864 sub AddRenewal { Link Here
2847
    # Charge a new rental fee, if applicable?
2848
    # Charge a new rental fee, if applicable?
2848
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2849
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2849
    if ( $charge > 0 ) {
2850
    if ( $charge > 0 ) {
2850
        my $accountno = getnextacctno( $borrowernumber );
2851
        my $accountno = C4::Accounts::getnextacctno( $borrowernumber );
2851
        my $manager_id = 0;
2852
        my $manager_id = 0;
2852
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2853
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2853
        $sth = $dbh->prepare(
2854
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2854
                "INSERT INTO accountlines
2855
        Koha::Account::Line->new(
2855
                    (date, borrowernumber, accountno, amount, manager_id,
2856
            {
2856
                    description,accounttype, amountoutstanding, itemnumber)
2857
                date              => dt_from_string(),
2857
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2858
                borrowernumber    => $borrowernumber,
2858
        );
2859
                accountno         => $accountno,
2859
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2860
                amount            => $charge,
2860
            "Renewal of Rental Item " . $biblio->title . " $item->{'barcode'}",
2861
                manager_id        => $manager_id,
2861
            'Rent', $charge, $itemnumber );
2862
                accounttype       => 'Rent',
2863
                amountoutstanding => $charge,
2864
                itemnumber        => $itemnumber,
2865
                branchcode        => $branchcode,
2866
                description       => 'Renewal of Rental Item '
2867
                  . $biblio->title
2868
                  . " $item->{'barcode'}",
2869
            }
2870
        )->store();
2862
    }
2871
    }
2863
2872
2864
    # Send a renewal slip according to checkout alert preferencei
2873
    # Send a renewal slip according to checkout alert preferencei
Lines 3192-3197 sub AddIssuingCharge { Link Here
3192
    my $manager_id  = 0;
3201
    my $manager_id  = 0;
3193
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
3202
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
3194
3203
3204
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
3205
3195
    my $accountline = Koha::Account::Line->new(
3206
    my $accountline = Koha::Account::Line->new(
3196
        {
3207
        {
3197
            borrowernumber    => $checkout->borrowernumber,
3208
            borrowernumber    => $checkout->borrowernumber,
Lines 3201-3206 sub AddIssuingCharge { Link Here
3201
            amount            => $charge,
3212
            amount            => $charge,
3202
            amountoutstanding => $charge,
3213
            amountoutstanding => $charge,
3203
            manager_id        => $manager_id,
3214
            manager_id        => $manager_id,
3215
            branchcode        => $branchcode,
3204
            description       => 'Rental',
3216
            description       => 'Rental',
3205
            accounttype       => 'Rent',
3217
            accounttype       => 'Rent',
3206
            date              => \'NOW()',
3218
            date              => \'NOW()',
(-)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 519-531 sub GetOtherReserves { Link Here
519
520
520
sub ChargeReserveFee {
521
sub ChargeReserveFee {
521
    my ( $borrowernumber, $fee, $title ) = @_;
522
    my ( $borrowernumber, $fee, $title ) = @_;
522
    return if !$fee || $fee==0; # the last test is needed to include 0.00
523
523
    my $accquery = qq{
524
    return if !$fee || $fee == 0;    # the last test is needed to include 0.00
524
INSERT INTO accountlines ( borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding ) VALUES (?, ?, NOW(), ?, ?, 'Res', ?)
525
525
    };
526
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
526
    my $dbh = C4::Context->dbh;
527
    my $nextacctno = C4::Accounts::getnextacctno($borrowernumber);
527
    my $nextacctno = &getnextacctno( $borrowernumber );
528
528
    $dbh->do( $accquery, undef, ( $borrowernumber, $nextacctno, $fee, "Reserve Charge - $title", $fee ) );
529
    Koha::Account::Line->new(
530
        {
531
            borrowernumber    => $borrowernumber,
532
            accountno         => $nextacctno,
533
            date              => dt_from_string(),
534
            amount            => $fee,
535
            description       => "Reserve Charge - $title",
536
            accounttype       => 'Res',
537
            amountoutstanding => $fee,
538
        }
539
    )->store();
529
}
540
}
530
541
531
=head2 GetReserveFee
542
=head2 GetReserveFee
(-)a/Koha/Account.pm (-2 / +2 lines)
Lines 79-84 sub pay { Link Here
79
    my $offset_type  = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment';
79
    my $offset_type  = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment';
80
80
81
    my $userenv = C4::Context->userenv;
81
    my $userenv = C4::Context->userenv;
82
    $library_id ||= $userenv ? $userenv->{branch} : undef;
82
83
83
    my $patron = Koha::Patrons->find( $self->{patron_id} );
84
    my $patron = Koha::Patrons->find( $self->{patron_id} );
84
85
Lines 223-228 sub pay { Link Here
223
            payment_type      => $payment_type,
224
            payment_type      => $payment_type,
224
            amountoutstanding => 0 - $balance_remaining,
225
            amountoutstanding => 0 - $balance_remaining,
225
            manager_id        => $manager_id,
226
            manager_id        => $manager_id,
227
            branchcode        => $library_id,
226
            note              => $note,
228
            note              => $note,
227
        }
229
        }
228
    )->store();
230
    )->store();
Lines 232-239 sub pay { Link Here
232
        $o->store();
234
        $o->store();
233
    }
235
    }
234
236
235
    $library_id ||= $userenv ? $userenv->{'branch'} : undef;
236
237
    UpdateStats(
237
    UpdateStats(
238
        {
238
        {
239
            branch         => $library_id,
239
            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 => 28;
21
use Test::More tests => 41;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 71-76 $context->mock( 'userenv', sub { Link Here
71
        branch => $branchcode,
71
        branch => $branchcode,
72
    };
72
    };
73
});
73
});
74
my $userenv_branchcode = $branchcode;
75
76
# Test chargelostitem
77
my $itemtype = $builder->build( { source => 'Itemtype' } );
78
my $item   = $builder->build( { source => 'Item', value => { itype => $itemtype->{itemtype} } } );
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|);
74
121
75
# Testing purge_zero_balance_fees
122
# Testing purge_zero_balance_fees
76
123
Lines 136-142 $dbh->do(q|DELETE FROM accountlines|); Link Here
136
183
137
subtest "Koha::Account::pay tests" => sub {
184
subtest "Koha::Account::pay tests" => sub {
138
185
139
    plan tests => 13;
186
    plan tests => 14;
140
187
141
    # Create a borrower
188
    # Create a borrower
142
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
189
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
Lines 259-264 subtest "Koha::Account::pay tests" => sub { Link Here
259
    is( $payment->amount(), '-42.000000', "Payment paid the specified fine" );
306
    is( $payment->amount(), '-42.000000', "Payment paid the specified fine" );
260
    $line3 = Koha::Account::Lines->find( $line3->id );
307
    $line3 = Koha::Account::Lines->find( $line3->id );
261
    is( $line3->amountoutstanding, '0.000000', "Specified fine is paid" );
308
    is( $line3->amountoutstanding, '0.000000', "Specified fine is paid" );
309
    is( $payment->branchcode, $userenv_branchcode, 'Branchcode set correctly' );
262
};
310
};
263
311
264
subtest "Koha::Account::pay particular line tests" => sub {
312
subtest "Koha::Account::pay particular line tests" => sub {
265
- 

Return to bug 19066