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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt (-22 / +30 lines)
Lines 36-64 Link Here
36
                </ul>
36
                </ul>
37
                <div class="tabs-container">
37
                <div class="tabs-container">
38
38
39
                [% IF ( ERROR ) %]
39
                [% IF error == 'itemnumber' %]
40
                [% IF ( ITEMNUMBER ) %]
40
                    <div id="error_message" class="dialog alert">
41
                  ERROR an invalid itemnumber was entered, please hit back and try again
41
                        Error: Invalid barcode entered, please try again
42
                    </div>
43
                [% ELSIF error %]
44
                    <div id="error_message" class="dialog alert">
45
                        An error occured, please try again: [% error %]
46
                    </div>
42
                [% END %]
47
                [% END %]
43
                [% ELSE %]
48
                <form action="/cgi-bin/koha/members/maninvoice.pl" method="post" id="maninvoice">
44
                <form action="/cgi-bin/koha/members/maninvoice.pl" method="post" id="maninvoice"><input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber | html %]" />
49
                    <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber | html %]" />
45
                    <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
50
                    <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
46
            <fieldset class="rows">
51
                    <fieldset class="rows">
47
            <legend>Manual invoice</legend>
52
                        <legend>Manual invoice</legend>
48
            <ol>
53
                        <ol>
49
                      <li>
54
                            <li>
50
                        <label for="type">Type: </label>
55
                                <label for="type">Type: </label>
51
                        <select name="type" id="type">
56
                                <select name="type" id="type">
52
                          [% FOREACH debit_type IN debit_types %]
57
                                    [% FOREACH debit_type IN debit_types %]
53
                            <option value="[% debit_type.code | html %]">[% debit_type.description | html %]</option>
58
                                    [% IF debit_type.code == type %]
54
                          [% END %]
59
                                    <option value="[% debit_type.code | html %]" selected="selected">[% debit_type.description | html %]</option>
55
                        </select>
60
                                    [% ELSE %]
56
                      </li>
61
                                    <option value="[% debit_type.code | html %]">[% debit_type.description | html %]</option>
57
              <li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
62
                                    [% END %]
58
                      <li><label for="desc">Description: </label><input type="text" name="desc" id="desc" size="50" /></li>
63
                                    [% END %]
59
                      <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
64
                                </select>
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>
65
                            </li>
61
            </ol>
66
                            <li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" value="[% barcode %]" /></li>
67
                            <li><label for="desc">Description: </label><input type="text" name="desc" id="desc" size="50" value="[% desc %]" /></li>
68
                            <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" value="[% note %]" /></li>
69
                            <li><label for="amount">Amount: </label><input type="number" name="amount" id="amount" required="required" step="any" min="0" value="[% amount %]" /> Example: 5.00</li>
70
                        </ol>
62
                    </fieldset>
71
                    </fieldset>
63
                    <fieldset class="action">
72
                    <fieldset class="action">
64
                        <button type="submit" name="add" value="save">Save</button>
73
                        <button type="submit" name="add" value="save">Save</button>
Lines 67-73 Link Here
67
                    </fieldset>
76
                    </fieldset>
68
                </form>
77
                </form>
69
78
70
                [% END %]
71
                </div>
79
                </div>
72
            </div>
80
            </div>
73
81
(-)a/members/maninvoice.pl (-64 / +123 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 32-39 use C4::Accounts; Link Here
32
use C4::Items;
33
use C4::Items;
33
use Koha::Token;
34
use Koha::Token;
34
35
35
use Koha::Items;
36
use Koha::Patrons;
36
use Koha::Patrons;
37
use Koha::Items;
38
use Koha::Old::Items;
39
use Koha::Checkouts;
40
use Koha::Old::Checkouts;
37
41
38
use Koha::Patron::Categories;
42
use Koha::Patron::Categories;
39
use Koha::Account::DebitTypes;
43
use Koha::Account::DebitTypes;
Lines 60-66 unless ($patron) { Link Here
60
    exit;
64
    exit;
61
}
65
}
62
66
67
my $logged_in_user = Koha::Patrons->find($loggedinuser);
68
output_and_exit_if_error(
69
    $input, $cookie,
70
    $template,
71
    {
72
        module         => 'members',
73
        logged_in_user => $logged_in_user,
74
        current_patron => $patron
75
    }
76
);
77
63
my $library_id = C4::Context->userenv->{'branch'};
78
my $library_id = C4::Context->userenv->{'branch'};
79
my $desc       = $input->param('desc');
80
my $amount     = $input->param('amount');
81
my $note       = $input->param('note');
82
my $debit_type = $input->param('type');
83
my $barcode    = $input->param('barcode');
84
$template->param(
85
    desc    => $desc,
86
    amount  => $amount,
87
    note    => $note,
88
    type    => $debit_type,
89
    barcode => $barcode
90
);
64
91
65
my $add = $input->param('add');
92
my $add = $input->param('add');
66
if ($add) {
93
if ($add) {
Lines 72-147 if ($add) { Link Here
72
        }
99
        }
73
      );
100
      );
74
101
75
# Note: If the logged in user is not allowed to see this patron an invoice can be forced
102
    # 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
103
    # Here we are trusting librarians not to hack the system
77
    my $barcode = $input->param('barcode');
104
    my $desc       = $input->param('desc');
78
    my $itemnum;
105
    my $amount     = $input->param('amount');
106
    my $note       = $input->param('note');
107
    my $debit_type = $input->param('type');
108
109
    # If barcode is passed, attempt to find the associated item
110
    my $failed;
111
    my $item_id;
112
    my $issue_id;
79
    if ($barcode) {
113
    if ($barcode) {
80
        my $item = Koha::Items->find( { barcode => $barcode } );
114
        my $item = Koha::Items->find( { barcode => $barcode } );
81
        $itemnum = $item->itemnumber if $item;
115
        if ($item) {
82
    }
116
            $item_id = $item->itemnumber;
83
    my $desc   = $input->param('desc');
84
    my $amount = $input->param('amount');
85
    my $type   = $input->param('type');
86
    my $note   = $input->param('note');
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
        }
117
        }
94
        $template->param(
118
        else {
95
            csrf_token => Koha::Token->new->generate_csrf(
119
            $item = Koha::Old::Items->find( { barcode => $barcode } );
96
                { session_id => scalar $input->cookie('CGISESSID') }
120
            if ($item) {
97
            )
121
                $item_id = $item->itemnumber;
98
        );
122
            }
99
        $template->param( 'ERROR' => $error );
123
            else {
100
        output_html_with_http_headers $input, $cookie, $template->output;
124
                $template->param( error => 'itemnumber' );
101
    }
125
                $failed = 1;
102
    else {
126
            }
103
104
        if ( C4::Context->preference('AccountAutoReconcile') ) {
105
            $patron->account->reconcile_balance;
106
        }
127
        }
107
128
108
        if ($add eq 'save and pay') {
129
        if ( ( $debit_type eq 'LOST' ) && $item_id ) {
109
            print $input->redirect(
130
            my $checkouts = Koha::Checkouts->search(
110
                "/cgi-bin/koha/members/pay.pl?borrowernumber=$borrowernumber"
131
                {
111
            );
132
                    itemnumber     => $item_id,
112
        } else {
133
                    borrowernumber => $borrowernumber
113
            print $input->redirect(
134
                }
114
                "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"
115
            );
135
            );
136
            my $checkout =
137
                $checkouts->count
138
              ? $checkouts->next
139
              : Koha::Old::Checkouts->search(
140
                {
141
                    itemnumber     => $item_id,
142
                    borrowernumber => $borrowernumber
143
                },
144
                { order_by => { -desc => 'returndate' }, rows => 1 }
145
            )->next;
146
            $issue_id = $checkout ? $checkout->issue_id : undef;
116
        }
147
        }
117
118
        exit;
119
    }
148
    }
120
}
121
else {
122
149
123
    my $logged_in_user = Koha::Patrons->find($loggedinuser)
150
    unless ($failed) {
124
      or die "Not logged in";
151
        try {
125
    output_and_exit_if_error(
152
            $patron->account->add_debit(
126
        $input, $cookie,
153
                {
127
        $template,
154
                    amount      => $amount,
128
        {
155
                    description => $desc,
129
            module         => 'members',
156
                    note        => $note,
130
            logged_in_user => $logged_in_user,
157
                    user_id     => $logged_in_user->borrowernumber,
131
            current_patron => $patron
158
                    interface   => 'intranet',
159
                    library_id  => $library_id,
160
                    type        => $debit_type,
161
                    item_id     => $item_id,
162
                    issue_id    => $issue_id
163
                }
164
            );
165
166
            if ( C4::Context->preference('AccountAutoReconcile') ) {
167
                $patron->account->reconcile_balance;
168
            }
169
170
            if ( $add eq 'save and pay' ) {
171
                print $input->redirect(
172
                    "/cgi-bin/koha/members/pay.pl?borrowernumber=$borrowernumber"
173
                );
174
            }
175
            else {
176
                print $input->redirect(
177
                    "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"
178
                );
179
            }
180
181
            exit;
182
        }
183
        catch {
184
            my $error = $_;
185
            if ( ref($error) eq 'Koha::Exceptions::Object::FKConstraint' ) {
186
                $template->param( error => $error->broken_fk );
187
            }
188
            else {
189
                $template->param( error => $error );
190
            }
132
        }
191
        }
133
    );
192
    }
134
135
    my @debit_types = Koha::Account::DebitTypes->search_with_library_limits(
136
        { can_be_invoiced => 1, archived => 0 },
137
        {}, $library_id );
138
    $template->param( debit_types => \@debit_types );
139
    $template->param(
140
        csrf_token => Koha::Token->new->generate_csrf(
141
            { session_id => scalar $input->cookie('CGISESSID') }
142
        ),
143
        patron    => $patron,
144
        finesview => 1,
145
    );
146
    output_html_with_http_headers $input, $cookie, $template->output;
147
}
193
}
148
- 
194
195
my @debit_types = Koha::Account::DebitTypes->search_with_library_limits(
196
  { can_be_invoiced => 1, archived => 0 },
197
  {}, $library_id );
198
199
$template->param(
200
  debit_types => \@debit_types,
201
  csrf_token  => Koha::Token->new->generate_csrf(
202
      { session_id => scalar $input->cookie('CGISESSID') }
203
  ),
204
  patron    => $patron,
205
  finesview => 1,
206
  );
207
output_html_with_http_headers $input, $cookie, $template->output;

Return to bug 22393