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

(-)a/C4/Circulation.pm (-14 / +41 lines)
Lines 34-41 use C4::Items qw( ModItemTransfer ModDateLastSeen CartToShelf ); Link Here
34
use C4::Accounts;
34
use C4::Accounts;
35
use C4::ItemCirculationAlertPreference;
35
use C4::ItemCirculationAlertPreference;
36
use C4::Message;
36
use C4::Message;
37
use C4::Log qw( logaction );    # logaction
37
use C4::Log                 qw( logaction );                 # logaction
38
use C4::Overdues;
38
use C4::Overdues            qw( branch_for_fee_context );
39
use C4::RotatingCollections qw(GetCollectionItemBranches);
39
use C4::RotatingCollections qw(GetCollectionItemBranches);
40
use Algorithm::CheckDigits  qw( CheckDigits );
40
use Algorithm::CheckDigits  qw( CheckDigits );
41
41
Lines 4446-4465 sub LostItem { Link Here
4446
            or warn "_FixOverduesOnReturn($borrowernumber, $itemnumber...) failed!";    # zero is OK, check defined
4446
            or warn "_FixOverduesOnReturn($borrowernumber, $itemnumber...) failed!";    # zero is OK, check defined
4447
4447
4448
        if ( C4::Context->preference('WhenLostChargeReplacementFee') ) {
4448
        if ( C4::Context->preference('WhenLostChargeReplacementFee') ) {
4449
            C4::Accounts::chargelostitem(
4449
            my $desc = sprintf(
4450
                $borrowernumber,
4450
                "%s %s %s",
4451
                $itemnumber,
4451
                $issues->{'title'}          || q{},
4452
                $issues->{'replacementprice'},
4452
                $issues->{'barcode'}        || q{},
4453
                sprintf(
4453
                $issues->{'itemcallnumber'} || q{},
4454
                    "%s %s %s",
4455
                    $issues->{'title'}          || q{},
4456
                    $issues->{'barcode'}        || q{},
4457
                    $issues->{'itemcallnumber'} || q{},
4458
                ),
4459
            );
4454
            );
4460
4455
4461
            #FIXME : Should probably have a way to distinguish this from an item that really was returned.
4456
            # interface: cron if called from longoverdue, otherwise current interface
4462
            #warn " $issues->{'borrowernumber'}  /  $itemnumber ";
4457
            my $interface =
4458
                ( $mark_lost_from && $mark_lost_from eq 'cronjob' )
4459
                ? 'cron'
4460
                : C4::Context->interface;
4461
            my $library_id = $params && ref($params) eq 'HASH' ? $params->{library_id} : undef;
4462
4463
            if ( !defined $library_id ) {
4464
                my $item_obj  = Koha::Items->find($itemnumber);
4465
                my $issue_obj = Koha::Checkouts->search(
4466
                    {
4467
                        itemnumber     => $itemnumber,
4468
                        borrowernumber => $borrowernumber,
4469
                    }
4470
                )->next;
4471
                $library_id = branch_for_fee_context(
4472
                    fee_type => 'LOST',
4473
                    patron   => $patron,
4474
                    item     => $item_obj,
4475
                    issue    => $issue_obj,
4476
                );
4477
            }
4478
4479
            Koha::Account->new( { patron_id => $borrowernumber } )->add_debit(
4480
                {
4481
                    amount      => $issues->{'replacementprice'} + 0,
4482
                    type        => 'LOST',
4483
                    description => $desc,
4484
                    interface   => $interface,
4485
                    library_id  => $library_id,
4486
                    item_id     => $itemnumber,
4487
                    ( $issues->{issue_id} ? ( issue_id => $issues->{issue_id} ) : () ),
4488
                }
4489
            );
4463
        }
4490
        }
4464
4491
4465
        MarkIssueReturned( $borrowernumber, $itemnumber, undef, $patron->privacy, $params ) if $mark_returned;
4492
        MarkIssueReturned( $borrowernumber, $itemnumber, undef, $patron->privacy, $params ) if $mark_returned;
(-)a/C4/Overdues.pm (-1 / +42 lines)
Lines 30-36 use C4::Accounts; Link Here
30
use C4::Context;
30
use C4::Context;
31
use Koha::Account::Lines;
31
use Koha::Account::Lines;
32
use Koha::Account::Offsets;
32
use Koha::Account::Offsets;
33
use Koha::Checkouts;
33
use Koha::DateUtils qw( output_pref );
34
use Koha::DateUtils qw( output_pref );
35
use Koha::Items;
34
use Koha::Libraries;
36
use Koha::Libraries;
35
use Koha::Recalls;
37
use Koha::Recalls;
36
use Koha::Logger;
38
use Koha::Logger;
Lines 55-60 BEGIN { Link Here
55
        GetOverdueMessageTransportTypes
57
        GetOverdueMessageTransportTypes
56
        parse_overdues_letter
58
        parse_overdues_letter
57
        GetIssuesIteminfo
59
        GetIssuesIteminfo
60
        branch_for_fee_context
58
    );
61
    );
59
}
62
}
60
63
Lines 327-332 sub CalcFine { Link Here
327
    return ( $amount, $units_minus_grace, $chargeable_units );
330
    return ( $amount, $units_minus_grace, $chargeable_units );
328
}
331
}
329
332
333
# Resolve which branch’s rules control a fee, honoring CircControl/LostChargesControl and HomeOrHoldingBranch.
334
335
sub branch_for_fee_context {
336
    my (%args) = @_;
337
338
    my $fee_type = $args{fee_type} // 'OVERDUE';
339
340
    my $control_pref =
341
        $fee_type eq 'LOST' || $fee_type eq 'PROCESSING'
342
        ? C4::Context->preference('LostChargesControl')
343
        : C4::Context->preference('CircControl');
344
    my $hoh_pref    = C4::Context->preference('HomeOrHoldingBranch') // 'home';
345
    my $use_holding = ( $hoh_pref =~ /holding/i ) ? 1 : 0;
346
347
    my $patron_branch  = eval { $args{patron}->branchcode }  // $args{patron}->{branchcode};
348
    my $issuing_branch = eval { $args{issue}->branchcode }   // $args{issue}->{branchcode};
349
    my $item_home      = eval { $args{item}->homebranch }    // $args{item}->{homebranch};
350
    my $item_holding   = eval { $args{item}->holdingbranch } // $args{item}->{holdingbranch};
351
    my $item_branch    = $use_holding ? ( $item_holding // $item_home ) : $item_home;
352
353
    return
354
          ( $control_pref && $control_pref eq 'PatronLibrary' ) ? $patron_branch
355
        : ( $control_pref && $control_pref eq 'PickupLibrary' ) ? ( $issuing_branch // $patron_branch // $item_branch )
356
        :                                                         $item_branch;
357
}
358
330
=head2 get_chargeable_units
359
=head2 get_chargeable_units
331
360
332
    get_chargeable_units($unit, $start_date_ $end_date, $branchcode);
361
    get_chargeable_units($unit, $start_date_ $end_date, $branchcode);
Lines 651-656 sub UpdateFine { Link Here
651
            my $desc = $letter ? $letter->{content} : sprintf( "Item %s - due %s", $itemnum, output_pref($due) );
680
            my $desc = $letter ? $letter->{content} : sprintf( "Item %s - due %s", $itemnum, output_pref($due) );
652
681
653
            my $account = Koha::Account->new( { patron_id => $borrowernumber } );
682
            my $account = Koha::Account->new( { patron_id => $borrowernumber } );
683
684
            # Resolve the branch that controlled this OVERDUE fee
685
            my $patron_obj  = Koha::Patrons->find($borrowernumber);
686
            my $item_obj    = Koha::Items->find($itemnum);
687
            my $issue_obj   = Koha::Checkouts->find($issue_id);       # issuing branch if CircControl=PickupLibrary
688
            my $rule_branch = branch_for_fee_context(
689
                fee_type => 'OVERDUE',
690
                patron   => $patron_obj,
691
                item     => $item_obj,
692
                issue    => $issue_obj,
693
            );
694
654
            $accountline = $account->add_debit(
695
            $accountline = $account->add_debit(
655
                {
696
                {
656
                    amount      => $amount,
697
                    amount      => $amount,
Lines 658-664 sub UpdateFine { Link Here
658
                    note        => undef,
699
                    note        => undef,
659
                    user_id     => undef,
700
                    user_id     => undef,
660
                    interface   => C4::Context->interface,
701
                    interface   => C4::Context->interface,
661
                    library_id  => undef,       #FIXME: Should we grab the checkout or circ-control branch here perhaps?
702
                    library_id  => $rule_branch,             # record the branch used to calculate the fee
662
                    type        => 'OVERDUE',
703
                    type        => 'OVERDUE',
663
                    item_id     => $itemnum,
704
                    item_id     => $itemnum,
664
                    issue_id    => $issue_id,
705
                    issue_id    => $issue_id,
(-)a/misc/cronjobs/longoverdue.pl (-3 / +19 lines)
Lines 31-39 use warnings; Link Here
31
use Getopt::Long qw( GetOptions );
31
use Getopt::Long qw( GetOptions );
32
use Pod::Usage   qw( pod2usage );
32
use Pod::Usage   qw( pod2usage );
33
33
34
use Koha::Checkouts;
34
use C4::Circulation qw( LostItem MarkIssueReturned );
35
use C4::Circulation qw( LostItem MarkIssueReturned );
35
use C4::Context;
36
use C4::Context;
36
use C4::Log qw( cronlogaction );
37
use C4::Log      qw( cronlogaction );
38
use C4::Overdues qw( branch_for_fee_context );
37
use Koha::ItemTypes;
39
use Koha::ItemTypes;
38
use Koha::Patron::Categories;
40
use Koha::Patron::Categories;
39
use Koha::Patrons;
41
use Koha::Patrons;
Lines 522-528 foreach my $startrange ( sort keys %$lost ) { Link Here
522
            if ($confirm) {
524
            if ($confirm) {
523
                Koha::Items->find( $row->{itemnumber} )->itemlost($lostvalue)->store;
525
                Koha::Items->find( $row->{itemnumber} )->itemlost($lostvalue)->store;
524
                if ( $charge && $charge eq $lostvalue ) {
526
                if ( $charge && $charge eq $lostvalue ) {
525
                    LostItem( $row->{'itemnumber'}, 'cronjob', $mark_returned );
527
                    my $patron = Koha::Patrons->find( $row->{borrowernumber} );
528
                    my $item   = Koha::Items->find( $row->{itemnumber} );
529
                    my $issue  = Koha::Checkouts->search(
530
                        {
531
                            itemnumber     => $row->{itemnumber},
532
                            borrowernumber => $row->{borrowernumber},
533
                        }
534
                    )->next;    # issuing branch if available
535
                    my $rule_branch = branch_for_fee_context(
536
                        fee_type => 'LOST',
537
                        patron   => $patron,
538
                        item     => $item,
539
                        issue    => $issue,    # ok if undef
540
                    );
541
                    LostItem( $row->{itemnumber}, 'cronjob', $mark_returned, { library_id => $rule_branch } );
542
526
                } elsif ($mark_returned) {
543
                } elsif ($mark_returned) {
527
                    $patron ||= Koha::Patrons->find( $row->{borrowernumber} );
544
                    $patron ||= Koha::Patrons->find( $row->{borrowernumber} );
528
                    MarkIssueReturned( $row->{borrowernumber}, $row->{itemnumber}, undef, $patron->privacy );
545
                    MarkIssueReturned( $row->{borrowernumber}, $row->{itemnumber}, undef, $patron->privacy );
529
- 

Return to bug 35612