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 855-861 sub cancel { Link Here
855
                        interface  => C4::Context->interface,
855
                        interface  => C4::Context->interface,
856
                        library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
856
                        library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
857
                        type       => 'RESERVE_EXPIRED',
857
                        type       => 'RESERVE_EXPIRED',
858
                        item_id    => $self->itemnumber
858
                        item_id    => $self->itemnumber,
859
                        hold_id    => $self->id,
859
                    }
860
                    }
860
                ) if $charge;
861
                ) if $charge;
861
            }
862
            }
Lines 1221-1226 sub charge_hold_fee { Link Here
1221
            description => $self->biblio->title,
1222
            description => $self->biblio->title,
1222
            type        => 'RESERVE',
1223
            type        => 'RESERVE',
1223
            item_id     => $self->itemnumber,
1224
            item_id     => $self->itemnumber,
1225
            hold_id     => $self->id,
1224
            user_id     => C4::Context->userenv ? C4::Context->userenv->{number} : undef,
1226
            user_id     => C4::Context->userenv ? C4::Context->userenv->{number} : undef,
1225
            library_id  => C4::Context->userenv ? C4::Context->userenv->{branch} : undef,
1227
            library_id  => C4::Context->userenv ? C4::Context->userenv->{branch} : undef,
1226
            interface   => C4::Context->interface,
1228
            interface   => C4::Context->interface,
Lines 1358-1364 sub _move_to_old { Link Here
1358
    my ($self) = @_;
1360
    my ($self) = @_;
1359
    my $hold_infos = $self->unblessed;
1361
    my $hold_infos = $self->unblessed;
1360
    require Koha::Old::Hold;
1362
    require Koha::Old::Hold;
1361
    return Koha::Old::Hold->new($hold_infos)->store;
1363
1364
    # Create the old hold record
1365
    my $old_hold = Koha::Old::Hold->new($hold_infos)->store;
1366
1367
    # Update any linked accountlines to point to old_reserve_id instead of reserve_id
1368
    $self->_result->search_related('accountlines')->update(
1369
        {
1370
            old_reserve_id => $self->id,
1371
            reserve_id     => undef,
1372
        }
1373
    );
1374
1375
    return $old_hold;
1362
}
1376
}
1363
1377
1364
=head3 to_api_mapping
1378
=head3 to_api_mapping
Lines 1450-1455 sub strings_map { Link Here
1450
    return $strings;
1464
    return $strings;
1451
}
1465
}
1452
1466
1467
=head3 debits
1468
1469
    my $debits = $hold->debits;
1470
1471
Get all debit account lines (charges) associated with this hold
1472
1473
=cut
1474
1475
sub debits {
1476
    my ($self) = @_;
1477
1478
    my $accountlines_rs = $self->_result->search_related(
1479
        'accountlines',
1480
        {
1481
            credit_type_code => undef,    # Only debits (no credits)
1482
        },
1483
        {
1484
            order_by => { -desc => 'timestamp' },
1485
        }
1486
    );
1487
    return Koha::Account::Debits->_new_from_dbic($accountlines_rs);
1488
}
1489
1453
=head2 Internal methods
1490
=head2 Internal methods
1454
1491
1455
=head3 _type
1492
=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