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

(-)a/members/maninvoice.pl (-19 / +35 lines)
Lines 91-125 if ($add) { Link Here
91
    my $note       = $input->param('note');
91
    my $note       = $input->param('note');
92
    my $debit_type = $input->param('type');
92
    my $debit_type = $input->param('type');
93
93
94
    # If LOST try to match barcode to Item and then try to match Item + Borrower to an Issue.
94
    # If barcode is passed, attempt to find the associated item
95
    my $failed;
95
    my $failed;
96
    my $item_id;
96
    my $item_id;
97
    my $issue_id;
97
    my $barcode = $input->param('barcode');
98
    my $barcode = $input->param('barcode');
98
    if ($barcode) {
99
    if ($barcode) {
100
        my $old_item_id;
99
        my $item = Koha::Items->find( { barcode => $barcode } );
101
        my $item = Koha::Items->find( { barcode => $barcode } );
100
        if ($item) {
102
        if ($item) {
101
            $item_id = $item->itemnumber;
103
            $item_id = $item->itemnumber;
102
        }
104
        }
103
        else {
105
        else {
104
            $template->param( error => 'itemnumber' );
106
            my $old_itemnumber = $dbh->selectrow_array(
105
            $failed = 1;
107
                "SELECT itemnumber FROM deleted_items WHERE barcode=?",
108
                undef, $barcode );
109
            unless ($old_itemnumber) {
110
                $template->param( error => 'itemnumber' );
111
                $failed = 1;
112
            }
113
        }
114
115
        my $issue_id;
116
        if ( $debit_type eq 'LOST' && ( $item_id || $old_itemnumber ) ) {
117
            my $itemnumber = $item_id // $old_itemnumber;
118
            my $checkouts  = Koha::Checkouts->search(
119
                {
120
                    itemnumber     => $itemnumber,
121
                    borrowernumber => $borrowernumber
122
                }
123
            );
124
            my $checkout =
125
                $checkouts->count
126
              ? $checkouts->next
127
              : Koha::Old::Checkouts->search(
128
                {
129
                    itemnumber     => $itemnumber,
130
                    borrowernumber => $borrowernumber
131
                },
132
                { order_by => { -desc => 'returndate' }, rows => 1 }
133
            )->next;
134
            $issue_id = $checkout ? $checkout->issue_id : undef;
106
        }
135
        }
107
    }
108
    my $issue_id;
109
    if ( $debit_type eq 'LOST' && $item_id ) {
110
        my $checkouts = Koha::Checkouts->search(
111
            { itemnumber => $item_id, borrowernumber => $borrowernumber } );
112
        my $checkout =
113
            $checkouts->count
114
          ? $checkouts->next
115
          : Koha::Old::Checkouts->search(
116
            { itemnumber => $item_id, borrowernumber => $borrowernumber },
117
            { order_by   => { -desc => 'returndate' }, rows => 1 }
118
        )->next;
119
        $issue_id = $checkout ? $checkout->issue_id : undef;
120
    }
136
    }
121
137
122
    unless ($failed) {
138
    if ( !$failed ) {
123
        try {
139
        try {
124
            $patron->account->add_debit(
140
            $patron->account->add_debit(
125
                {
141
                {
Lines 148-154 if ($add) { Link Here
148
            my $error = $_;
164
            my $error = $_;
149
            if ( ref($error) eq 'Koha::Exceptions::Object::FKConstraint' ) {
165
            if ( ref($error) eq 'Koha::Exceptions::Object::FKConstraint' ) {
150
                $template->param( error => $error->broken_fk );
166
                $template->param( error => $error->broken_fk );
151
            } else {
167
            }
168
            else {
152
                $template->param( error => '1' );
169
                $template->param( error => '1' );
153
            }
170
            }
154
        }
171
        }
155
- 

Return to bug 22393