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

(-)a/members/maninvoice.pl (-49 / +45 lines)
Lines 97-155 if ($add) { Link Here
97
    my $barcode = $input->param('barcode');
97
    my $barcode = $input->param('barcode');
98
    if ($barcode) {
98
    if ($barcode) {
99
        my $item = Koha::Items->find( { barcode => $barcode } );
99
        my $item = Koha::Items->find( { barcode => $barcode } );
100
        if ($item) {
100
        unless ( $item ) {
101
            $item_id = $item->itemnumber;
102
        }
103
        else {
104
            $template->param( error => 'itemnumber' );
101
            $template->param( error => 'itemnumber' );
105
            $failed = 1;
102
            $failed = 1;
106
        }
103
        } else {
107
    }
104
            $item_id = $item->itemnumber;
108
    my $issue_id;
105
            my $issue_id;
109
    if ( $debit_type eq 'LOST' && $item_id ) {
106
            if ( $debit_type eq 'LOST' && $item_id ) {
110
        my $checkouts = Koha::Checkouts->search(
107
                my $checkouts = Koha::Checkouts->search(
111
            { itemnumber => $item_id, borrowernumber => $borrowernumber } );
108
                    { itemnumber => $item_id, borrowernumber => $borrowernumber } );
112
        my $checkout =
109
                my $checkout =
113
            $checkouts->count
110
                    $checkouts->count
114
          ? $checkouts->next
111
                  ? $checkouts->next
115
          : Koha::Old::Checkouts->search(
112
                  : Koha::Old::Checkouts->search(
116
            { itemnumber => $item_id, borrowernumber => $borrowernumber },
113
                    { itemnumber => $item_id, borrowernumber => $borrowernumber },
117
            { order_by   => { -desc => 'returndate' }, rows => 1 }
114
                    { order_by   => { -desc => 'returndate' }, rows => 1 }
118
        )->next;
115
                )->next;
119
        $issue_id = $checkout ? $checkout->issue_id : undef;
116
                $issue_id = $checkout ? $checkout->issue_id : undef;
120
    }
117
            }
121
118
122
    unless ($failed) {
119
            try {
123
        try {
120
                $patron->account->add_debit(
124
            $patron->account->add_debit(
121
                    {
125
                {
122
                        amount      => $amount,
126
                    amount      => $amount,
123
                        description => $desc,
127
                    description => $desc,
124
                        note        => $note,
128
                    note        => $note,
125
                        user_id     => $logged_in_user->borrowernumber,
129
                    user_id     => $logged_in_user->borrowernumber,
126
                        interface   => 'intranet',
130
                    interface   => 'intranet',
127
                        library_id  => $library_id,
131
                    library_id  => $library_id,
128
                        type        => $debit_type,
132
                    type        => $debit_type,
129
                        item_id     => $item_id,
133
                    item_id     => $item_id,
130
                        issue_id    => $issue_id
134
                    issue_id    => $issue_id
131
                    }
132
                );
133
134
                if ( C4::Context->preference('AccountAutoReconcile') ) {
135
                    $patron->account->reconcile_balance;
135
                }
136
                }
136
            );
137
137
    
138
                print $input->redirect(
138
            if ( C4::Context->preference('AccountAutoReconcile') ) {
139
                    "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"
139
                $patron->account->reconcile_balance;
140
                );
141
                exit;
140
            }
142
            }
141
    
143
            catch {
142
            print $input->redirect(
144
                my $error = $_;
143
                "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"
145
                if ( ref($error) eq 'Koha::Exceptions::Object::FKConstraint' ) {
144
            );
146
                    $template->param( error => $error->broken_fk );
145
            exit;
147
                } else {
146
        }
148
                    $template->param( error => '1' );
147
        catch {
149
                }
148
            my $error = $_;
149
            if ( ref($error) eq 'Koha::Exceptions::Object::FKConstraint' ) {
150
                $template->param( error => $error->broken_fk );
151
            } else {
152
                $template->param( error => '1' );
153
            }
150
            }
154
        }
151
        }
155
    }
152
    }
156
- 

Return to bug 22393