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

(-)a/C4/Accounts.pm (+8 lines)
Lines 107-112 sub chargelostitem{ Link Here
107
    if ($usedefaultreplacementcost && $amount == 0 && $defaultreplacecost){
107
    if ($usedefaultreplacementcost && $amount == 0 && $defaultreplacecost){
108
        $replacementprice = $defaultreplacecost;
108
        $replacementprice = $defaultreplacecost;
109
    }
109
    }
110
111
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
112
110
    # first make sure the borrower hasn't already been charged for this item
113
    # first make sure the borrower hasn't already been charged for this item
111
    # FIXME this should be more exact
114
    # FIXME this should be more exact
112
    #       there is no reason a user can't lose an item, find and return it, and lost it again
115
    #       there is no reason a user can't lose an item, find and return it, and lost it again
Lines 137-142 sub chargelostitem{ Link Here
137
                    itemnumber        => $itemnumber,
140
                    itemnumber        => $itemnumber,
138
                    note              => $processingfeenote,
141
                    note              => $processingfeenote,
139
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
142
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
143
                    branchcode        => $branchcode,
140
                }
144
                }
141
            )->store();
145
            )->store();
142
146
Lines 177-182 sub chargelostitem{ Link Here
177
                    amountoutstanding => $replacementprice,
181
                    amountoutstanding => $replacementprice,
178
                    itemnumber        => $itemnumber,
182
                    itemnumber        => $itemnumber,
179
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
183
                    manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
184
                    branchcode        => $branchcode,
180
                }
185
                }
181
            )->store();
186
            )->store();
182
187
Lines 241-246 sub manualinvoice { Link Here
241
    my $accountno  = getnextacctno($borrowernumber);
246
    my $accountno  = getnextacctno($borrowernumber);
242
    my $amountleft = $amount;
247
    my $amountleft = $amount;
243
248
249
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
250
244
    my $accountline = Koha::Account::Line->new(
251
    my $accountline = Koha::Account::Line->new(
245
        {
252
        {
246
            borrowernumber    => $borrowernumber,
253
            borrowernumber    => $borrowernumber,
Lines 253-258 sub manualinvoice { Link Here
253
            itemnumber        => $itemnum || undef,
260
            itemnumber        => $itemnum || undef,
254
            note              => $note,
261
            note              => $note,
255
            manager_id        => $manager_id,
262
            manager_id        => $manager_id,
263
            branchcode        => $branchcode,
256
        }
264
        }
257
    )->store();
265
    )->store();
258
266
(-)a/C4/Circulation.pm (-9 / +21 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 2878-2892 sub AddRenewal { Link Here
2878
        my $accountno = C4::Accounts::getnextacctno( $borrowernumber );
2879
        my $accountno = C4::Accounts::getnextacctno( $borrowernumber );
2879
        my $manager_id = 0;
2880
        my $manager_id = 0;
2880
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2881
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2881
        $sth = $dbh->prepare(
2882
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2882
                "INSERT INTO accountlines
2883
        Koha::Account::Line->new(
2883
                    (date, borrowernumber, accountno, amount, manager_id,
2884
            {
2884
                    description,accounttype, amountoutstanding, itemnumber)
2885
                date              => dt_from_string(),
2885
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2886
                borrowernumber    => $borrowernumber,
2886
        );
2887
                accountno         => $accountno,
2887
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2888
                amount            => $charge,
2888
            "Renewal of Rental Item " . $biblio->title . " $item->{'barcode'}",
2889
                manager_id        => $manager_id,
2889
            'Rent', $charge, $itemnumber );
2890
                accounttype       => 'Rent',
2891
                amountoutstanding => $charge,
2892
                itemnumber        => $itemnumber,
2893
                branchcode        => $branchcode,
2894
                description       => 'Renewal of Rental Item '
2895
                  . $biblio->title
2896
                  . " $item->{'barcode'}",
2897
            }
2898
        )->store();
2890
    }
2899
    }
2891
2900
2892
    # Send a renewal slip according to checkout alert preferencei
2901
    # Send a renewal slip according to checkout alert preferencei
Lines 3220-3225 sub AddIssuingCharge { Link Here
3220
    my $manager_id  = 0;
3229
    my $manager_id  = 0;
3221
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
3230
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
3222
3231
3232
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
3233
3223
    my $accountline = Koha::Account::Line->new(
3234
    my $accountline = Koha::Account::Line->new(
3224
        {
3235
        {
3225
            borrowernumber    => $checkout->borrowernumber,
3236
            borrowernumber    => $checkout->borrowernumber,
Lines 3229-3234 sub AddIssuingCharge { Link Here
3229
            amount            => $charge,
3240
            amount            => $charge,
3230
            amountoutstanding => $charge,
3241
            amountoutstanding => $charge,
3231
            manager_id        => $manager_id,
3242
            manager_id        => $manager_id,
3243
            branchcode        => $branchcode,
3232
            description       => 'Rental',
3244
            description       => 'Rental',
3233
            accounttype       => 'Rent',
3245
            accounttype       => 'Rent',
3234
            date              => \'NOW()',
3246
            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 219-224 sub pay { Link Here
219
            payment_type      => $payment_type,
220
            payment_type      => $payment_type,
220
            amountoutstanding => 0 - $balance_remaining,
221
            amountoutstanding => 0 - $balance_remaining,
221
            manager_id        => $manager_id,
222
            manager_id        => $manager_id,
223
            branchcode        => $library_id,
222
            note              => $note,
224
            note              => $note,
223
        }
225
        }
224
    )->store();
226
    )->store();
Lines 228-235 sub pay { Link Here
228
        $o->store();
230
        $o->store();
229
    }
231
    }
230
232
231
    $library_id ||= $userenv ? $userenv->{'branch'} : undef;
232
233
    UpdateStats(
233
    UpdateStats(
234
        {
234
        {
235
            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 => 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 69-74 $context->mock( 'userenv', sub { Link Here
69
        branch => $branchcode,
69
        branch => $branchcode,
70
    };
70
    };
71
});
71
});
72
my $userenv_branchcode = $branchcode;
73
74
# Test chargelostitem
75
my $itemtype = $builder->build( { source => 'Itemtype' } );
76
my $item   = $builder->build( { source => 'Item', value => { itype => $itemtype->{itemtype} } } );
77
my $patron = $builder->build( { source => 'Borrower' } );
78
my $amount = '5.000000';
79
my $description = "Test fee!";
80
chargelostitem( $patron->{borrowernumber}, $item->{itemnumber}, $amount, $description );
81
my ($accountline) = Koha::Account::Lines->search(
82
    {
83
        borrowernumber => $patron->{borrowernumber}
84
    }
85
);
86
is( $accountline->amount, $amount, 'Accountline amount set correctly for chargelostitem' );
87
is( $accountline->description, $description, 'Accountline description set correctly for chargelostitem' );
88
is( $accountline->branchcode, $branchcode, 'Accountline branchcode set correctly for chargelostitem' );
89
$dbh->do(q|DELETE FROM accountlines|);
90
91
# Test manualinvoice, reuse some of the vars from testing chargelostitem
92
my $type = 'L';
93
my $note = 'Test note!';
94
manualinvoice( $patron->{borrowernumber}, $item->{itemnumber}, $description, $type, $amount, $note );
95
($accountline) = Koha::Account::Lines->search(
96
    {
97
        borrowernumber => $patron->{borrowernumber}
98
    }
99
);
100
is( $accountline->accounttype, $type, 'Accountline type set correctly for manualinvoice' );
101
is( $accountline->amount, $amount, 'Accountline amount set correctly for manualinvoice' );
102
ok( $accountline->description =~ /^$description/, 'Accountline description set correctly for manualinvoice' );
103
is( $accountline->note, $note, 'Accountline note set correctly for manualinvoice' );
104
is( $accountline->branchcode, $branchcode, 'Accountline branchcode set correctly for manualinvoice' );
105
106
# Test _FixAccountForLostAndReturned, use the accountline from the manualinvoice to test
107
C4::Circulation::_FixAccountForLostAndReturned( $item->{itemnumber} );
108
my ( $accountline_fee, $accountline_payment ) = Koha::Account::Lines->search(
109
    {
110
        borrowernumber => $patron->{borrowernumber}
111
    }
112
);
113
is( $accountline_fee->accounttype, 'LR', 'Lost item fee account type updated to LR' );
114
is( $accountline_fee->amountoutstanding, '0.000000', 'Lost item fee amount outstanding updated to 0' );
115
is( $accountline_payment->accounttype, 'CR', 'Lost item fee account type is CR' );
116
is( $accountline_payment->amount, "-$amount", 'Lost item refund amount is correct' );
117
is( $accountline_payment->branchcode, $branchcode, 'Lost item refund branchcode is set correctly' );
118
$dbh->do(q|DELETE FROM accountlines|);
72
119
73
# Testing purge_zero_balance_fees
120
# Testing purge_zero_balance_fees
74
121
Lines 134-140 $dbh->do(q|DELETE FROM accountlines|); Link Here
134
181
135
subtest "Koha::Account::pay tests" => sub {
182
subtest "Koha::Account::pay tests" => sub {
136
183
137
    plan tests => 13;
184
    plan tests => 14;
138
185
139
    # Create a borrower
186
    # Create a borrower
140
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
187
    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