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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt (-41 / +62 lines)
Lines 24-74 Link Here
24
        <div class="col-sm-10 col-sm-push-2">
24
        <div class="col-sm-10 col-sm-push-2">
25
            <main>
25
            <main>
26
26
27
            [% INCLUDE 'members-toolbar.inc' %]
27
                [% INCLUDE 'members-toolbar.inc' %]
28
28
29
            <!-- The manual invoice and credit buttons -->
29
                <!-- The manual invoice and credit buttons -->
30
            <div class="statictabs">
30
                <div class="statictabs">
31
                <ul>
31
                    <ul>
32
                    <li><a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | uri %]">Transactions</a></li>
32
                        <li><a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | uri %]">Transactions</a></li>
33
                    <li><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Make a payment</a></li>
33
                        <li><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Make a payment</a></li>
34
                    <li class="active"><a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual invoice</a></li>
34
                        <li class="active"><a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual invoice</a></li>
35
                    <li><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual credit</a></li>
35
                        <li><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual credit</a></li>
36
                </ul>
36
                    </ul>
37
                <div class="tabs-container">
37
                    <div class="tabs-container">
38
38
39
                [% IF ( ERROR ) %]
39
                        [% IF error %]
40
                [% IF ( ITEMNUMBER ) %]
40
                        <div class="dialog alert %]">
41
                  ERROR an invalid itemnumber was entered, please hit back and try again
41
                            An error occurred when adding this manual invoice:
42
                [% END %]
42
                            [% SWITCH error %]
43
                [% ELSE %]
43
                            [% CASE 'debit_type_code' %]
44
                <form action="/cgi-bin/koha/members/maninvoice.pl" method="post" id="maninvoice"><input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber | html %]" />
44
                                Debit type not found.
45
                    <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
45
                            [% CASE 'itemnumber' %]
46
            <fieldset class="rows">
46
                                Item not found.
47
            <legend>Manual invoice</legend>
47
                            [% CASE 'register_id' %]
48
            <ol>
48
                                Cash register not found.
49
                      <li>
49
                            [% CASE '1' %]
50
                        <label for="type">Type: </label>
50
                                An unhandled error occurred, please check your logs
51
                        <select name="type" id="type">
51
                            [% END %]
52
                          [% FOREACH debit_type IN debit_types %]
52
                        </div>
53
                            <option value="[% debit_type.code | html %]">[% debit_type.description | html %]</option>
53
                        [% END %]
54
                          [% END %]
55
                        </select>
56
                      </li>
57
              <li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
58
                      <li><label for="desc">Description: </label><input type="text" name="desc" id="desc" size="50" /></li>
59
                      <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
60
                      <li><label for="amount">Amount: </label><input type="number" name="amount" id="amount" required="required" value="" step="any" min="0" /> Example: 5.00</li>
61
            </ol>
62
                    </fieldset>
63
                    <fieldset class="action">
64
                        <input type="submit" name="add" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | html %]">Cancel</a>
65
                    </fieldset>
66
                </form>
67
54
68
                [% END %]
55
                        <form action="/cgi-bin/koha/members/maninvoice.pl" method="post" id="maninvoice"><input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber | html %]" />
69
                </div>
56
                            <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
70
            </div>
57
                            <fieldset class="rows">
58
                                <legend>Manual invoice</legend>
59
                                <ol>
60
                                    <li>
61
                                        <label for="type">Type: </label>
62
                                        <select name="type" id="type">
63
                                            [% FOREACH debit_type IN debit_types %]
64
                                            <option value="[% debit_type.code | html %]">[% debit_type.description | html %]</option>
65
                                            [% END %]
66
                                        </select>
67
                                    </li>
68
                                    <li>
69
                                        <label for="barcode">Barcode: </label>
70
                                        <input type="text" name="barcode" id="barcode" />
71
                                    </li>
72
                                    <li>
73
                                        <label for="desc">Description: </label>
74
                                        <input type="text" name="desc" id="desc" size="50" />
75
                                    </li>
76
                                    <li>
77
                                        <label for="note">Note: </label>
78
                                        <input type="text" name="note" size="50" id="note" />
79
                                    </li>
80
                                    <li>
81
                                        <label for="amount">Amount: </label>
82
                                        <input type="number" name="amount" id="amount" required="required" value="" step="any" min="0" /> Example: 5.00
83
                                    </li>
84
                                </ol>
85
                            </fieldset>
71
86
87
                            <fieldset class="action">
88
                                <input type="submit" name="add" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | html %]">Cancel</a>
89
                            </fieldset>
90
                        </form>
91
                    </div>
92
                </div>
72
            </main>
93
            </main>
73
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
94
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
74
95
(-)a/members/maninvoice.pl (-57 / +86 lines)
Lines 23-28 Link Here
23
# along with Koha; if not, see <http://www.gnu.org/licenses>.
23
# along with Koha; if not, see <http://www.gnu.org/licenses>.
24
24
25
use Modern::Perl;
25
use Modern::Perl;
26
use Try::Tiny;
26
27
27
use C4::Auth;
28
use C4::Auth;
28
use C4::Output;
29
use C4::Output;
Lines 60-65 unless ($patron) { Link Here
60
    exit;
61
    exit;
61
}
62
}
62
63
64
my $logged_in_user = Koha::Patrons->find($loggedinuser);
65
output_and_exit_if_error(
66
    $input, $cookie,
67
    $template,
68
    {
69
        module         => 'members',
70
        logged_in_user => $logged_in_user,
71
        current_patron => $patron
72
    }
73
);
74
63
my $library_id = C4::Context->userenv->{'branch'};
75
my $library_id = C4::Context->userenv->{'branch'};
64
76
65
my $add = $input->param('add');
77
my $add = $input->param('add');
Lines 72-140 if ($add) { Link Here
72
        }
84
        }
73
      );
85
      );
74
86
75
# Note: If the logged in user is not allowed to see this patron an invoice can be forced
87
    # Note: If the logged in user is not allowed to see this patron an invoice can be forced
76
# Here we are trusting librarians not to hack the system
88
    # Here we are trusting librarians not to hack the system
89
    my $desc       = $input->param('desc');
90
    my $amount     = $input->param('amount');
91
    my $note       = $input->param('note');
92
    my $debit_type = $input->param('type');
93
94
    # If LOST try to match barcode to Item and then try to match Item + Borrower to an Issue.
95
    my $failed;
96
    my $item_id;
77
    my $barcode = $input->param('barcode');
97
    my $barcode = $input->param('barcode');
78
    my $itemnum;
79
    if ($barcode) {
98
    if ($barcode) {
80
        my $item = Koha::Items->find( { barcode => $barcode } );
99
        my $item = Koha::Items->find( { barcode => $barcode } );
81
        $itemnum = $item->itemnumber if $item;
100
        if ($item) {
82
    }
101
            $item_id = $item->itemnumber;
83
    my $desc   = $input->param('desc');
102
        }
84
    my $amount = $input->param('amount');
103
        else {
85
    my $type   = $input->param('type');
104
            $template->param( error => 'itemnumber' );
86
    my $note   = $input->param('note');
105
            $failed = 1;
87
    my $error =
88
      C4::Accounts::manualinvoice( $borrowernumber, $itemnum, $desc, $type,
89
        $amount, $note );
90
    if ($error) {
91
        if ( $error =~ /FOREIGN KEY/ && $error =~ /itemnumber/ ) {
92
            $template->param( 'ITEMNUMBER' => 1 );
93
        }
106
        }
94
        $template->param(
95
            csrf_token => Koha::Token->new->generate_csrf(
96
                { session_id => scalar $input->cookie('CGISESSID') }
97
            )
98
        );
99
        $template->param( 'ERROR' => $error );
100
        output_html_with_http_headers $input, $cookie, $template->output;
101
    }
107
    }
102
    else {
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
    }
103
121
104
        if ( C4::Context->preference('AccountAutoReconcile') ) {
122
    unless ($failed) {
105
            $patron->account->reconcile_balance;
123
        try {
106
        }
124
            $patron->account->add_debit(
125
                {
126
                    amount      => $amount,
127
                    description => $desc,
128
                    note        => $note,
129
                    user_id     => $logged_in_user->borrowernumber,
130
                    interface   => 'intranet',
131
                    library_id  => $library_id,
132
                    type        => $debit_type,
133
                    item_id     => $item_id,
134
                    issue_id    => $issue_id
135
                }
136
            );
107
137
108
        print $input->redirect(
138
            if ( C4::Context->preference('AccountAutoReconcile') ) {
109
            "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"
139
                $patron->account->reconcile_balance;
110
        );
140
            }
111
        exit;
112
    }
113
}
114
else {
115
141
116
    my $logged_in_user = Koha::Patrons->find($loggedinuser)
142
            print $input->redirect(
117
      or die "Not logged in";
143
                "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"
118
    output_and_exit_if_error(
144
            );
119
        $input, $cookie,
145
            exit;
120
        $template,
146
        }
121
        {
147
        catch {
122
            module         => 'members',
148
            my $error = $_;
123
            logged_in_user => $logged_in_user,
149
            if ( ref($error) eq 'Koha::Exceptions::Object::FKConstraint' ) {
124
            current_patron => $patron
150
                $template->param( error => $error->broken_fk );
151
            } else {
152
                $template->param( error => '1' );
153
            }
125
        }
154
        }
126
    );
155
    }
127
128
    my @debit_types = Koha::Account::DebitTypes->search_with_library_limits(
129
        { can_be_added_manually => 1, archived => 0 },
130
        {}, $library_id );
131
    $template->param( debit_types => \@debit_types );
132
    $template->param(
133
        csrf_token => Koha::Token->new->generate_csrf(
134
            { session_id => scalar $input->cookie('CGISESSID') }
135
        ),
136
        patron    => $patron,
137
        finesview => 1,
138
    );
139
    output_html_with_http_headers $input, $cookie, $template->output;
140
}
156
}
141
- 
157
158
my @debit_types = Koha::Account::DebitTypes->search_with_library_limits(
159
    { can_be_added_manually => 1, archived => 0 },
160
    {}, $library_id );
161
162
$template->param(
163
    debit_types => \@debit_types,
164
    csrf_token  => Koha::Token->new->generate_csrf(
165
        { session_id => scalar $input->cookie('CGISESSID') }
166
    ),
167
    patron    => $patron,
168
    finesview => 1,
169
);
170
output_html_with_http_headers $input, $cookie, $template->output;

Return to bug 22393