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 938-944 sub cancel { Link Here
938
                        interface  => C4::Context->interface,
938
                        interface  => C4::Context->interface,
939
                        library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
939
                        library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
940
                        type       => 'RESERVE_EXPIRED',
940
                        type       => 'RESERVE_EXPIRED',
941
                        item_id    => $self->itemnumber
941
                        item_id    => $self->itemnumber,
942
                        hold_id    => $self->id,
942
                    }
943
                    }
943
                ) if $charge;
944
                ) if $charge;
944
            }
945
            }
Lines 1309-1314 sub charge_hold_fee { Link Here
1309
            description => $self->biblio->title,
1310
            description => $self->biblio->title,
1310
            type        => 'RESERVE',
1311
            type        => 'RESERVE',
1311
            item_id     => $self->itemnumber,
1312
            item_id     => $self->itemnumber,
1313
            hold_id     => $self->id,
1312
            user_id     => C4::Context->userenv ? C4::Context->userenv->{number} : undef,
1314
            user_id     => C4::Context->userenv ? C4::Context->userenv->{number} : undef,
1313
            library_id  => C4::Context->userenv ? C4::Context->userenv->{branch} : undef,
1315
            library_id  => C4::Context->userenv ? C4::Context->userenv->{branch} : undef,
1314
            interface   => C4::Context->interface,
1316
            interface   => C4::Context->interface,
Lines 1446-1452 sub _move_to_old { Link Here
1446
    my ($self) = @_;
1448
    my ($self) = @_;
1447
    my $hold_infos = $self->unblessed;
1449
    my $hold_infos = $self->unblessed;
1448
    require Koha::Old::Hold;
1450
    require Koha::Old::Hold;
1449
    return Koha::Old::Hold->new($hold_infos)->store;
1451
1452
    # Create the old hold record
1453
    my $old_hold = Koha::Old::Hold->new($hold_infos)->store;
1454
1455
    # Update any linked accountlines to point to old_reserve_id instead of reserve_id
1456
    $self->_result->search_related('accountlines')->update(
1457
        {
1458
            old_reserve_id => $self->id,
1459
            reserve_id     => undef,
1460
        }
1461
    );
1462
1463
    return $old_hold;
1450
}
1464
}
1451
1465
1452
=head3 to_api_mapping
1466
=head3 to_api_mapping
Lines 1538-1543 sub strings_map { Link Here
1538
    return $strings;
1552
    return $strings;
1539
}
1553
}
1540
1554
1555
=head3 debits
1556
1557
    my $debits = $hold->debits;
1558
1559
Get all debit account lines (charges) associated with this hold
1560
1561
=cut
1562
1563
sub debits {
1564
    my ($self) = @_;
1565
1566
    my $accountlines_rs = $self->_result->search_related(
1567
        'accountlines',
1568
        {
1569
            credit_type_code => undef,    # Only debits (no credits)
1570
        },
1571
        {
1572
            order_by => { -desc => 'timestamp' },
1573
        }
1574
    );
1575
    return Koha::Account::Debits->_new_from_dbic($accountlines_rs);
1576
}
1577
1541
=head2 Internal methods
1578
=head2 Internal methods
1542
1579
1543
=head3 _type
1580
=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