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

(-)a/members/maninvoice.pl (-13 / +24 lines)
Lines 38-43 use Koha::Patrons; Link Here
38
38
39
use Koha::Patron::Categories;
39
use Koha::Patron::Categories;
40
40
41
use Try::Tiny;
42
41
my $input=new CGI;
43
my $input=new CGI;
42
my $flagsrequired = { borrowers => 'edit_borrowers' };
44
my $flagsrequired = { borrowers => 'edit_borrowers' };
43
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Lines 78-100 if ($add){ Link Here
78
        my $amount=$input->param('amount');
80
        my $amount=$input->param('amount');
79
        my $type=$input->param('type');
81
        my $type=$input->param('type');
80
        my $note    = $input->param('note');
82
        my $note    = $input->param('note');
81
        my $error   = manualinvoice( $borrowernumber, $itemnum, $desc, $type, $amount, $note );
83
        try {
82
        if ($error) {
84
            my $account = $patron->account;
83
            if ( $error =~ /FOREIGN KEY/ && $error =~ /itemnumber/ ) {
85
            my $invoice = $account->add_debit(
84
                $template->param( 'ITEMNUMBER' => 1 );
86
                {
85
            }
87
                    amount      => $amount,
86
            $template->param( csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $input->cookie('CGISESSID') }) );
88
                    item_id     => $itemnum,
87
            $template->param( 'ERROR' => $error );
89
                    description => $desc,
88
            output_html_with_http_headers $input, $cookie, $template->output;
90
                    type        => $type,
89
        } else {
91
                    note        => $note
92
                }
93
            );
90
94
91
            if ( C4::Context->preference('AccountAutoReconcile') ) {
95
            if ( C4::Context->preference('AccountAutoReconcile') ) {
92
                $patron->account->reconcile_balance;
96
                $patron->account->reconcile_balance;
93
            }
97
            }
94
95
            print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
96
            exit;
97
        }
98
        }
99
        catch {
100
            if ( $_->isa('Koha::Exceptions::Object::FKConstraint') $error =~ /FOREIGN KEY/ && $error =~ /itemnumber/ ) {
101
                $template->param( 'ITEMNUMBER' => 1 ) if ($_->broken_fk eq 'itemnumber');
102
                $template->param( 'ERROR' => $_->message );
103
            }
104
            $template->param( csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $input->cookie('CGISESSID') }) );
105
            output_html_with_http_headers $input, $cookie, $template->output;
106
        };
107
108
        print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
109
        exit;
98
    }
110
    }
99
} else {
111
} else {
100
112
101
- 

Return to bug 21756