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

(-)a/Koha/Account.pm (+28 lines)
Lines 492-497 sub add_debit { Link Here
492
    my $transaction_type = $params->{transaction_type};
492
    my $transaction_type = $params->{transaction_type};
493
    my $item_id          = $params->{item_id};
493
    my $item_id          = $params->{item_id};
494
    my $issue_id         = $params->{issue_id};
494
    my $issue_id         = $params->{issue_id};
495
    my $hold_id          = $params->{hold_id};
495
496
496
    my $old_issue_id;
497
    my $old_issue_id;
497
    if ($issue_id) {
498
    if ($issue_id) {
Lines 503-508 sub add_debit { Link Here
503
        }
504
        }
504
    }
505
    }
505
506
507
    my $old_hold_id;
508
    if ($hold_id) {
509
        my $hold = Koha::Holds->find($hold_id);
510
        unless ($hold) {
511
            my $old_hold = Koha::Old::Holds->find($hold_id);
512
            if ($old_hold) {
513
                $hold_id     = undef;
514
                $old_hold_id = $old_hold->id;
515
            } else {
516
517
                # Neither current nor old hold exists, keep hold_id as is for now
518
                # The caller will need to handle this case
519
                $hold_id = undef;
520
            }
521
        }
522
    }
523
506
    my $line;
524
    my $line;
507
    my $schema = Koha::Database->new->schema;
525
    my $schema = Koha::Database->new->schema;
508
    try {
526
    try {
Lines 533-538 sub add_debit { Link Here
533
                            ? ( old_issue_id => $old_issue_id )
551
                            ? ( old_issue_id => $old_issue_id )
534
                            : ()
552
                            : ()
535
                        ),
553
                        ),
554
                        (
555
                            $hold_id
556
                            ? ( reserve_id => $hold_id )
557
                            : ()
558
                        ),
559
                        (
560
                            $old_hold_id
561
                            ? ( old_reserve_id => $old_hold_id )
562
                            : ()
563
                        ),
536
                        branchcode  => $library_id,
564
                        branchcode  => $library_id,
537
                        register_id => $cash_register,
565
                        register_id => $cash_register,
538
                        (
566
                        (
(-)a/Koha/Account/Line.pm (+23 lines)
Lines 104-109 sub checkout { Link Here
104
    return $result;
104
    return $result;
105
}
105
}
106
106
107
=head3 hold
108
109
    my $hold = $account_line->hold;
110
111
Get the hold associated with this account line (if any)
112
113
=cut
114
115
sub hold {
116
    my ($self) = @_;
117
118
    my $result;
119
    if ( $self->reserve_id ) {
120
        my $hold_rs = $self->_result->reserve;
121
        $result = Koha::Hold->_new_from_dbic($hold_rs) if $hold_rs;
122
    } elsif ( $self->old_reserve_id ) {
123
        my $old_hold_rs = $self->_result->old_reserve;
124
        $result = Koha::Old::Hold->_new_from_dbic($old_hold_rs) if $old_hold_rs;
125
    }
126
127
    return $result;
128
}
129
107
=head3 library
130
=head3 library
108
131
109
Returns a Koha::Library object representing where the accountline was recorded
132
Returns a Koha::Library object representing where the accountline was recorded
(-)a/Koha/Hold.pm (-2 / +39 lines)
Lines 949-955 sub cancel { Link Here
949
                        interface  => C4::Context->interface,
949
                        interface  => C4::Context->interface,
950
                        library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
950
                        library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
951
                        type       => 'RESERVE_EXPIRED',
951
                        type       => 'RESERVE_EXPIRED',
952
                        item_id    => $self->itemnumber
952
                        item_id    => $self->itemnumber,
953
                        hold_id    => $self->id,
953
                    }
954
                    }
954
                ) if $charge;
955
                ) if $charge;
955
            }
956
            }
Lines 1329-1334 sub charge_hold_fee { Link Here
1329
            description => $self->biblio->title,
1330
            description => $self->biblio->title,
1330
            type        => 'RESERVE',
1331
            type        => 'RESERVE',
1331
            item_id     => $self->itemnumber,
1332
            item_id     => $self->itemnumber,
1333
            hold_id     => $self->id,
1332
            user_id     => C4::Context->userenv ? C4::Context->userenv->{number} : undef,
1334
            user_id     => C4::Context->userenv ? C4::Context->userenv->{number} : undef,
1333
            library_id  => C4::Context->userenv ? C4::Context->userenv->{branch} : undef,
1335
            library_id  => C4::Context->userenv ? C4::Context->userenv->{branch} : undef,
1334
            interface   => C4::Context->interface,
1336
            interface   => C4::Context->interface,
Lines 1466-1472 sub _move_to_old { Link Here
1466
    my ($self) = @_;
1468
    my ($self) = @_;
1467
    my $hold_infos = $self->unblessed;
1469
    my $hold_infos = $self->unblessed;
1468
    require Koha::Old::Hold;
1470
    require Koha::Old::Hold;
1469
    return Koha::Old::Hold->new($hold_infos)->store;
1471
1472
    # Create the old hold record
1473
    my $old_hold = Koha::Old::Hold->new($hold_infos)->store;
1474
1475
    # Update any linked accountlines to point to old_reserve_id instead of reserve_id
1476
    $self->_result->search_related('accountlines')->update(
1477
        {
1478
            old_reserve_id => $self->id,
1479
            reserve_id     => undef,
1480
        }
1481
    );
1482
1483
    return $old_hold;
1470
}
1484
}
1471
1485
1472
=head3 to_api_mapping
1486
=head3 to_api_mapping
Lines 1562-1567 sub strings_map { Link Here
1562
    return $strings;
1576
    return $strings;
1563
}
1577
}
1564
1578
1579
=head3 debits
1580
1581
    my $debits = $hold->debits;
1582
1583
Get all debit account lines (charges) associated with this hold
1584
1585
=cut
1586
1587
sub debits {
1588
    my ($self) = @_;
1589
1590
    my $accountlines_rs = $self->_result->search_related(
1591
        'accountlines',
1592
        {
1593
            credit_type_code => undef,    # Only debits (no credits)
1594
        },
1595
        {
1596
            order_by => { -desc => 'timestamp' },
1597
        }
1598
    );
1599
    return Koha::Account::Debits->_new_from_dbic($accountlines_rs);
1600
}
1601
1565
=head2 Internal methods
1602
=head2 Internal methods
1566
1603
1567
=head3 _type
1604
=head3 _type
(-)a/Koha/Old/Hold.pm (-1 / +24 lines)
Lines 105-110 sub anonymize { Link Here
105
    return $self->update( { borrowernumber => $anonymous_id } );
105
    return $self->update( { borrowernumber => $anonymous_id } );
106
}
106
}
107
107
108
=head3 debits
109
110
    my $debits = $old_hold->debits;
111
112
Get all debit account lines (charges) associated with this old hold
113
114
=cut
115
116
sub debits {
117
    my ($self) = @_;
118
119
    my $accountlines_rs = $self->_result->search_related(
120
        'accountlines',
121
        {
122
            credit_type_code => undef,    # Only debits (no credits)
123
        },
124
        {
125
            # Optimize with proper ordering and potential prefetching
126
            order_by => { -desc => 'timestamp' },
127
        }
128
    );
129
    return Koha::Account::Debits->_new_from_dbic($accountlines_rs);
130
}
131
108
=head2 Internal methods
132
=head2 Internal methods
109
133
110
=head3 _type
134
=head3 _type
111
- 

Return to bug 40817