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

(-)a/C4/Accounts.pm (-76 lines)
Lines 132-213 sub chargelostitem { Link Here
132
    }
132
    }
133
}
133
}
134
134
135
=head2 manualinvoice
136
137
  &manualinvoice($borrowernumber, $itemnumber, $description, $type,
138
                 $amount, $note);
139
140
This function is now deprecated and not used anywhere within koha. It is due for complete removal in 19.11
141
142
=cut
143
144
sub manualinvoice {
145
    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
146
147
    deprecated "C4::Accounts::manualinvoice is deprecated in favor of Koha::Account->add_debit";
148
149
    my $manager_id = C4::Context->userenv ? C4::Context->userenv->{'number'} : undef;
150
    my $dbh      = C4::Context->dbh;
151
    my $amountleft = $amount;
152
153
    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
154
155
    my $issue_id;
156
    if ( $type eq 'LOST' && $itemnum ) {
157
        my $checkouts = Koha::Checkouts->search(
158
            { itemnumber => $itemnum, borrowernumber => $borrowernumber } );
159
        my $checkout =
160
            $checkouts->count
161
          ? $checkouts->next
162
          : Koha::Old::Checkouts->search(
163
            { itemnumber => $itemnum, borrowernumber => $borrowernumber },
164
            { order_by   => { -desc => 'returndate' }, rows => 1 }
165
        )->next;
166
        $issue_id = $checkout ? $checkout->issue_id : undef;
167
    }
168
169
    my $accountline = Koha::Account::Line->new(
170
        {
171
            borrowernumber    => $borrowernumber,
172
            date              => \'NOW()',
173
            amount            => $amount,
174
            description       => $desc,
175
            debit_type_code   => $type,
176
            amountoutstanding => $amountleft,
177
            itemnumber        => $itemnum || undef,
178
            issue_id          => $issue_id,
179
            note              => $note,
180
            manager_id        => $manager_id,
181
            interface         => C4::Context->interface,
182
            branchcode        => $branchcode,
183
        }
184
    )->store();
185
186
    my $account_offset = Koha::Account::Offset->new(
187
        {
188
            debit_id => $accountline->id,
189
            type     => 'Manual Debit',
190
            amount   => $amount,
191
        }
192
    )->store();
193
194
    if ( C4::Context->preference("FinesLog") ) {
195
        logaction("FINES", 'CREATE',$borrowernumber,Dumper({
196
            action            => 'create_fee',
197
            borrowernumber    => $borrowernumber,
198
            amount            => $amount,
199
            description       => $desc,
200
            debit_type_code   => $type,
201
            amountoutstanding => $amountleft,
202
            note              => $note,
203
            itemnumber        => $itemnum,
204
            manager_id        => $manager_id,
205
        }));
206
    }
207
208
    return 0;
209
}
210
211
=head2 purge_zero_balance_fees
135
=head2 purge_zero_balance_fees
212
136
213
  purge_zero_balance_fees( $days );
137
  purge_zero_balance_fees( $days );
(-)a/t/db_dependent/Accounts.t (-30 / +1 lines)
Lines 18-24 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 33;
21
use Test::More tests => 27;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 45-51 BEGIN { Link Here
45
can_ok( 'C4::Accounts',
45
can_ok( 'C4::Accounts',
46
    qw(
46
    qw(
47
        chargelostitem
47
        chargelostitem
48
        manualinvoice
49
        purge_zero_balance_fees )
48
        purge_zero_balance_fees )
50
);
49
);
51
50
Lines 73-105 $context->mock( 'userenv', sub { Link Here
73
$context->mock( 'interface', sub { return "commandline" } );
72
$context->mock( 'interface', sub { return "commandline" } );
74
my $userenv_branchcode = $branchcode;
73
my $userenv_branchcode = $branchcode;
75
74
76
# Test manualinvoice
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;
81
my $description = "Test fee!";
82
my $type = 'LOST';
83
my $note = 'Test note!';
84
warning_like {
85
    C4::Accounts::manualinvoice( $patron->{borrowernumber},
86
        $item->{itemnumber}, $description, $type, $amount, $note )
87
}
88
qr/C4::Accounts::manualinvoice is deprecated in favor of Koha::Account->add_debit/,
89
  "deprecation warning received for manualinvoice";
90
my ($accountline) = Koha::Account::Lines->search(
91
    {
92
        borrowernumber => $patron->{borrowernumber}
93
    }
94
);
95
is( $accountline->debit_type_code, $type, 'Debit type set correctly for manualinvoice' );
96
is( $accountline->amount+0, $amount, 'Accountline amount set correctly for manualinvoice' );
97
ok( $accountline->description =~ /^$description/, 'Accountline description set correctly for manualinvoice' );
98
is( $accountline->note, $note, 'Accountline note set correctly for manualinvoice' );
99
is( $accountline->branchcode, $branchcode, 'Accountline branchcode set correctly for manualinvoice' );
100
101
$dbh->do(q|DELETE FROM accountlines|);
102
103
# Testing purge_zero_balance_fees
75
# Testing purge_zero_balance_fees
104
76
105
# The 3rd value in the insert is 'days ago' --
77
# The 3rd value in the insert is 'days ago' --
106
- 

Return to bug 22394