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

(-)a/Koha/Account/Line.pm (-1 / +111 lines)
Lines 205-210 sub apply { Link Here
205
    return $available_credit;
205
    return $available_credit;
206
}
206
}
207
207
208
=head3 adjust
209
210
This method allows updating a debit or credit on a patron's account
211
212
my $account_line = Koha::Account->find({ accountlines_id => $line_id })->update(
213
    {
214
        amount       => $amount,
215
        type         => $update_type,
216
    }
217
);
218
219
$update_type can be any of:
220
  - fine_increment
221
222
=cut
223
224
sub adjust {
225
    my ( $self, $params ) = @_;
226
227
    my $amount       = $params->{amount};
228
    my $update_type  = $params->{type};
229
230
    unless ( exists($Koha::Account::Line::offset_type->{$update_type}) ) {
231
        Koha::Exceptions::Account::UnrecognisedType->throw(
232
            error => 'Update type not recognised'
233
        );
234
    }
235
236
    my $account_type = $self->accounttype;
237
    unless ( $Koha::Account::Line::allowed_update->{$update_type} eq $account_type ) {
238
        Koha::Exceptions::Account::UnrecognisedType->throw(
239
            error => 'Update type not allowed on this accounttype'
240
        );
241
    }
242
243
    my $schema = Koha::Database->new->schema;
244
245
    $schema->txn_do(
246
        sub {
247
248
            my $amount_before             = $self->amount;
249
            my $amount_outstanding_before = $self->amountoutstanding;
250
            my $difference                = $amount - $amount_before;
251
            my $new_outstanding           = $amount_outstanding_before + $difference;
252
253
            # Update the account line
254
            $self->set(
255
                {   
256
                    date              => \'NOW()',
257
                    amount            => $amount,
258
                    amountoutstanding => $new_outstanding,
259
                    ( $update_type eq 'fine_increment' ? ( lastincrement => $difference ) : ()),
260
                }
261
            )->store();
262
263
            # Record the account offset
264
            my $account_offset = Koha::Account::Offset->new(
265
                {
266
                    debit_id => $self->id,
267
                    type     => $Koha::Account::Line::offset_type->{$update_type},
268
                    amount   => $difference
269
                }
270
            )->store();
271
272
            if ( C4::Context->preference("FinesLog") ) {
273
                logaction(
274
                    "FINES", 'UPDATE', #undef becomes UPDATE in UpdateFine
275
                    $self->borrowernumber,
276
                    Dumper(
277
                        {   action            => $update_type,
278
                            borrowernumber    => $self->borrowernumber,
279
                            accountno         => $self->accountno,
280
                            amount            => $amount,
281
                            description       => undef,
282
                            amountoutstanding => $new_outstanding,
283
                            accounttype       => $self->accounttype,
284
                            note              => undef,
285
                            itemnumber        => $self->itemnumber,
286
                            manager_id        => undef,
287
                        }
288
                    )
289
                ) if ( $update_type eq 'fine_increment' );
290
            }
291
        }
292
    );
293
294
    return $self;
295
}
296
208
=head3 is_credit
297
=head3 is_credit
209
298
210
    my $bool = $line->is_credit;
299
    my $bool = $line->is_credit;
Lines 242-244 sub _type { Link Here
242
}
331
}
243
332
244
1;
333
1;
245
- 
334
335
=head2 Name mappings
336
337
=head3 $offset_type
338
339
=cut
340
341
our $offset_type = { 'fine_increment' => 'Fine Update', };
342
343
=head3 $allowed_update
344
345
=cut
346
347
our $allowed_update = { 'fine_increment' => 'FU', };
348
349
=head1 AUTHORS
350
351
Kyle M Hall <kyle.m.hall@gmail.com>
352
Tomás Cohen Arazi <tomascohen@gmail.com>
353
Martin Renvoize <martin.renvoize@ptfs-europe.com>
354
355
=cut

Return to bug 21748