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

(-)a/C4/Accounts.pm (+8 lines)
Lines 140-145 sub chargelostitem{ Link Here
140
    if ($usedefaultreplacementcost && $amount == 0 && $defaultreplacecost){
140
    if ($usedefaultreplacementcost && $amount == 0 && $defaultreplacecost){
141
        $replacementprice = $defaultreplacecost;
141
        $replacementprice = $defaultreplacecost;
142
    }
142
    }
143
144
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
145
143
    # first make sure the borrower hasn't already been charged for this item
146
    # first make sure the borrower hasn't already been charged for this item
144
    # FIXME this should be more exact
147
    # FIXME this should be more exact
145
    #       there is no reason a user can't lose an item, find and return it, and lost it again
148
    #       there is no reason a user can't lose an item, find and return it, and lost it again
Lines 167-172 sub chargelostitem{ Link Here
167
                    itemnumber        => $itemnumber,
170
                    itemnumber        => $itemnumber,
168
                    note              => $processingfeenote,
171
                    note              => $processingfeenote,
169
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
172
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
173
                    branchcode        => $branchcode,
170
                }
174
                }
171
            )->store();
175
            )->store();
172
176
Lines 206-211 sub chargelostitem{ Link Here
206
                    amountoutstanding => $replacementprice,
210
                    amountoutstanding => $replacementprice,
207
                    itemnumber        => $itemnumber,
211
                    itemnumber        => $itemnumber,
208
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
212
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
213
                    branchcode        => $branchcode,
209
                }
214
                }
210
            )->store();
215
            )->store();
211
216
Lines 270-275 sub manualinvoice { Link Here
270
    my $accountno  = getnextacctno($borrowernumber);
275
    my $accountno  = getnextacctno($borrowernumber);
271
    my $amountleft = $amount;
276
    my $amountleft = $amount;
272
277
278
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
279
273
    my $accountline = Koha::Account::Line->new(
280
    my $accountline = Koha::Account::Line->new(
274
        {
281
        {
275
            borrowernumber    => $borrowernumber,
282
            borrowernumber    => $borrowernumber,
Lines 282-287 sub manualinvoice { Link Here
282
            itemnumber        => $itemnum || undef,
289
            itemnumber        => $itemnum || undef,
283
            note              => $note,
290
            note              => $note,
284
            manager_id        => $manager_id,
291
            manager_id        => $manager_id,
292
            branchcode        => $branchcode,
285
        }
293
        }
286
    )->store();
294
    )->store();
287
295
(-)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 2851-2868 sub AddRenewal { Link Here
2851
    # Charge a new rental fee, if applicable?
2852
    # Charge a new rental fee, if applicable?
2852
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2853
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2853
    if ( $charge > 0 ) {
2854
    if ( $charge > 0 ) {
2854
        my $accountno = getnextacctno( $borrowernumber );
2855
        my $accountno = C4::Accounts::getnextacctno( $borrowernumber );
2855
        my $manager_id = 0;
2856
        my $manager_id = 0;
2856
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2857
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2857
        $sth = $dbh->prepare(
2858
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2858
                "INSERT INTO accountlines
2859
        Koha::Account::Line->new(
2859
                    (date, borrowernumber, accountno, amount, manager_id,
2860
            {
2860
                    description,accounttype, amountoutstanding, itemnumber)
2861
                date              => dt_from_string(),
2861
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2862
                borrowernumber    => $borrowernumber,
2862
        );
2863
                accountno         => $accountno,
2863
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2864
                amount            => $charge,
2864
            "Renewal of Rental Item " . $biblio->title . " $item->{'barcode'}",
2865
                manager_id        => $manager_id,
2865
            'Rent', $charge, $itemnumber );
2866
                accounttype       => 'Rent',
2867
                amountoutstanding => $charge,
2868
                itemnumber        => $itemnumber,
2869
                branchcode        => $branchcode,
2870
                description       => 'Renewal of Rental Item '
2871
                  . $biblio->title
2872
                  . " $item->{'barcode'}",
2873
            }
2874
        )->store();
2866
    }
2875
    }
2867
2876
2868
    # Send a renewal slip according to checkout alert preferencei
2877
    # Send a renewal slip according to checkout alert preferencei
Lines 3196-3201 sub AddIssuingCharge { Link Here
3196
    my $manager_id  = 0;
3205
    my $manager_id  = 0;
3197
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
3206
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
3198
3207
3208
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
3209
3199
    my $accountline = Koha::Account::Line->new(
3210
    my $accountline = Koha::Account::Line->new(
3200
        {
3211
        {
3201
            borrowernumber    => $checkout->borrowernumber,
3212
            borrowernumber    => $checkout->borrowernumber,
Lines 3205-3210 sub AddIssuingCharge { Link Here
3205
            amount            => $charge,
3216
            amount            => $charge,
3206
            amountoutstanding => $charge,
3217
            amountoutstanding => $charge,
3207
            manager_id        => $manager_id,
3218
            manager_id        => $manager_id,
3219
            branchcode        => $branchcode,
3208
            description       => 'Rental',
3220
            description       => 'Rental',
3209
            accounttype       => 'Rent',
3221
            accounttype       => 'Rent',
3210
            date              => \'NOW()',
3222
            date              => \'NOW()',
(-)a/C4/Reserves.pm (-7 / +18 lines)
Lines 49-54 use Koha::Items; Link Here
49
use Koha::ItemTypes;
49
use Koha::ItemTypes;
50
use Koha::Patrons;
50
use Koha::Patrons;
51
use Koha::CirculationRules;
51
use Koha::CirculationRules;
52
use Koha::Account::Lines;
52
53
53
use List::MoreUtils qw( firstidx any );
54
use List::MoreUtils qw( firstidx any );
54
use Carp;
55
use Carp;
Lines 566-578 sub GetOtherReserves { Link Here
566
567
567
sub ChargeReserveFee {
568
sub ChargeReserveFee {
568
    my ( $borrowernumber, $fee, $title ) = @_;
569
    my ( $borrowernumber, $fee, $title ) = @_;
569
    return if !$fee || $fee==0; # the last test is needed to include 0.00
570
570
    my $accquery = qq{
571
    return if !$fee || $fee == 0;    # the last test is needed to include 0.00
571
INSERT INTO accountlines ( borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding ) VALUES (?, ?, NOW(), ?, ?, 'Res', ?)
572
572
    };
573
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
573
    my $dbh = C4::Context->dbh;
574
    my $nextacctno = C4::Accounts::getnextacctno($borrowernumber);
574
    my $nextacctno = &getnextacctno( $borrowernumber );
575
575
    $dbh->do( $accquery, undef, ( $borrowernumber, $nextacctno, $fee, "Reserve Charge - $title", $fee ) );
576
    Koha::Account::Line->new(
577
        {
578
            borrowernumber    => $borrowernumber,
579
            accountno         => $nextacctno,
580
            date              => dt_from_string(),
581
            amount            => $fee,
582
            description       => "Reserve Charge - $title",
583
            accounttype       => 'Res',
584
            amountoutstanding => $fee,
585
        }
586
    )->store();
576
}
587
}
577
588
578
=head2 GetReserveFee
589
=head2 GetReserveFee
(-)a/Koha/Account.pm (-2 / +2 lines)
Lines 81-86 sub pay { Link Here
81
    my $offset_type  = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment';
81
    my $offset_type  = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment';
82
82
83
    my $userenv = C4::Context->userenv;
83
    my $userenv = C4::Context->userenv;
84
    $library_id ||= $userenv ? $userenv->{branch} : undef;
84
85
85
    my $patron = Koha::Patrons->find( $self->{patron_id} );
86
    my $patron = Koha::Patrons->find( $self->{patron_id} );
86
87
Lines 225-230 sub pay { Link Here
225
            payment_type      => $payment_type,
226
            payment_type      => $payment_type,
226
            amountoutstanding => 0 - $balance_remaining,
227
            amountoutstanding => 0 - $balance_remaining,
227
            manager_id        => $manager_id,
228
            manager_id        => $manager_id,
229
            branchcode        => $library_id,
228
            note              => $note,
230
            note              => $note,
229
        }
231
        }
230
    )->store();
232
    )->store();
Lines 234-241 sub pay { Link Here
234
        $o->store();
236
        $o->store();
235
    }
237
    }
236
238
237
    $library_id ||= $userenv ? $userenv->{'branch'} : undef;
238
239
    UpdateStats(
239
    UpdateStats(
240
        {
240
        {
241
            branch         => $library_id,
241
            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