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

(-)a/circ/batch_holding.pl (+147 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2019 BibLibre
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use CGI qw ( -utf8 );
22
23
use C4::Output;
24
use C4::Auth;
25
use Koha::Items;
26
use C4::Reserves;
27
use List::MoreUtils qw/uniq/;
28
29
30
my $input = new CGI;
31
my $op           = $input->param('op');
32
my @itemnumbers;
33
34
my @errors;
35
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37
    {
38
        template_name   => "circ/batch_holding.tt",
39
        query           => $input,
40
        type            => "intranet",
41
        authnotrequired => 0,
42
    }
43
);
44
45
if ($op eq "show"){
46
    my $filefh = $input->upload('uploadfile');
47
    my $filecontent = $input->param('filecontent');
48
    my $borrowernumber = $input->param('borrowernumber');
49
    my $branch = $input->param('branch');
50
    my $action = $input->param('action');
51
    my @notfoundbarcodes;
52
53
    my @contentlist;
54
    if ($filefh){
55
        while (my $content=<$filefh>){
56
            $content =~ s/[\r\n]*$//;
57
            push @contentlist, $content if $content;
58
        }
59
60
        foreach my $barcode (@contentlist) {
61
            my $item = Koha::Items->find({ barcode => $barcode });
62
            if ($item) {
63
                push @itemnumbers,$item->itemnumber;
64
            } else {
65
                push @notfoundbarcodes, $barcode;
66
            }
67
        }
68
    } else {
69
        if ( my $list=$input->param('barcodelist')){
70
            push my @barcodelist, uniq( split(/\s\n/, $list) );
71
72
            foreach my $barcode (@barcodelist) {
73
74
                my $item = Koha::Items->find({ barcode => $barcode });
75
                if ($item) {
76
                    push @itemnumbers,$item->itemnumber;
77
                } else {
78
                    push @notfoundbarcodes, $barcode;
79
                }
80
            }
81
82
        }
83
    }
84
    if (@notfoundbarcodes) {
85
        my @notfoundbarcodesloop = map{{barcode=>$_}}@notfoundbarcodes;
86
        $template->param(notfoundbarcodes => \@notfoundbarcodesloop);
87
    }
88
    my @holdloop;
89
    if (@itemnumbers) {
90
        foreach my $itemnumber (@itemnumbers) {
91
            my $item = Koha::Items->find({ itemnumber => $itemnumber });
92
            my $holdable = CanItemBeReserved($borrowernumber, $item->itemnumber)->{status};
93
            push @holdloop, {
94
                                        'itemnumber' => $item->itemnumber,
95
                                        'barcode' => $item->barcode,
96
                                        'holdable' => ($action eq "cancel" || $holdable eq 'OK') ? 1 : 0,
97
                                      };
98
        }
99
100
    }
101
    $template->param(
102
        show => 1,
103
        holdloop => \@holdloop,
104
        borrowernumber => $borrowernumber,
105
        branch => $branch,
106
        action => $action,
107
    );
108
}
109
110
elsif ($op eq "result") {
111
    my $branch = $input->param('branch');
112
    my $borrowernumber = $input->param('borrowernumber');
113
    my $action = $input->param('action');
114
    my @itemnumbers = $input->multi_param('holdable');
115
    my @holdloop;
116
    foreach my $itemnumber (@itemnumbers) {
117
        if ($action eq "place") {
118
            my $item = Koha::Items->find({ itemnumber => $itemnumber });
119
            my $biblionumber = $item->biblionumber;
120
            my $reserve_id = AddReserve($branch, $borrowernumber, $biblionumber, undef, undef, undef, undef, undef, undef, $itemnumber, undef);
121
            push @holdloop, {
122
                                'itemnumber' => $itemnumber,
123
                                'reserve_id' => $reserve_id,
124
                            };
125
        } else {
126
            my $holds = Koha::Holds->search({ itemnumber => $itemnumber, borrowernumber => $borrowernumber });
127
            if ($holds) {
128
                while ( my $hold = $holds->next ) {
129
                    $hold->cancel;
130
                }
131
132
                push @holdloop, {
133
                                    'itemnumber' => $itemnumber,
134
                                };
135
            }
136
        }
137
    }
138
139
    $template->param(
140
        result => 1,
141
        holdloop => \@holdloop,
142
        cancel => $action eq "cancel" ? 1 : 0,
143
        place => $action eq "place" ? 1 : 0,
144
    );
145
146
}
147
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/batch_holding.tt (+165 lines)
Line 0 Link Here
1
[% USE Branches %]
2
[% INCLUDE 'doc-head-open.inc' %]
3
<title>Koha &rsaquo; Circulation &rsaquo; Batch holding</title>
4
[% INCLUDE 'doc-head-close.inc' %]
5
<script>
6
        // <![CDATA[
7
        $(document).ready(function() {
8
          $("#batchholdform").submit(function() {
9
            if (!$("#borrowernumber").val()) {
10
                alert(_("Please select a valid borrower."));
11
                return false;
12
            }
13
          });
14
          $("#findborrowerhold").autocomplete({
15
            source: "/cgi-bin/koha/circ/ysearch.pl",
16
            minLength: 3,
17
            select: function( event, ui ) {
18
                $( "#findborrowerhold" ).val( ui.item.surname + ', ' + ui.item.firstname + ' (' + ui.item.cardnumber + ')' );
19
                $( "#borrowernumber").val( ui.item.borrowernumber );
20
                return false;
21
           }
22
          })
23
          .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
24
            return $( "<li></li>" )
25
            .data( "ui-autocomplete-item", item )
26
            .append( "<a>" + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") <small>" + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "</small></a>" )
27
            .appendTo( ul );
28
          };
29
        });
30
      // ]]>
31
</script>
32
</head>
33
<body id="batch_holding">
34
35
[% INCLUDE 'header.inc' %]
36
[% INCLUDE 'cataloging-search.inc' %]
37
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/circ/circulation-home.pl">Circulation</a> &rsaquo; Batch holding</div>
38
39
<div id="doc" class="yui-t7">
40
41
<div id="bd">
42
        <div id="yui-main">
43
[% IF show %]
44
    [% IF ( notfoundbarcodes ) %]
45
      <div class="dialog alert"><p>Warning, the following barcodes were not found:</p></div>
46
      <table style="margin:auto;">
47
    <thead>
48
        <tr><th>Barcodes not found</th></tr>
49
    </thead>
50
    <tbody>
51
        [% FOREACH notfoundbarcode IN notfoundbarcodes %]
52
      <tr><td>[% notfoundbarcode.barcode %]</td></td>
53
        [% END %]
54
    </tbody>
55
      </table>
56
  [% END %] <!-- /notfoundbarcodes -->
57
58
  [% IF (holdloop) %]
59
    <h1>[% action %] holds on the following barcodes</h1>
60
    <form action="batch_holding.pl" method="POST">
61
    <ul>
62
    [% FOREACH hold IN holdloop %]
63
        <li>
64
        [% IF hold.holdable %]
65
        <input type="checkbox" name="holdable" checked="checked" value="[% hold.itemnumber %]" />
66
        [% hold.barcode %]
67
        [% ELSE %]
68
        [% hold.barcode %] (This item cannot be reserved)
69
        [% END %]
70
        </li>
71
    [% END %]
72
    </ul>
73
    <input type="hidden" name="op" value="result" />
74
    <input type="hidden" name="action" value="[% action %]" />
75
    <input type="hidden" name="branch" value="[% branch %]" />
76
    <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
77
        <input type="submit" />
78
    </form>
79
  [% ELSE %]
80
    <p>No reservation can be placed or cancelled.</p>
81
    <a href="batch_holding.pl">Batch place or cancel other items</a>
82
  [% END %]
83
84
[% ELSIF result %]
85
  [% IF (holdloop) %]
86
    <h1>Results</h1>
87
    <ul>
88
    [% IF place %]
89
        The following items have been reserved:
90
        <ul>
91
        [% FOREACH hold IN holdloop %]
92
            <li>itemnumber [% hold.itemnumber %], reserve_id [% hold.reserve_id %]</li>
93
        [% END %]
94
        </ul>
95
    [% END %]
96
    [% IF cancel %]
97
        The following reservations were cancelled:
98
        <ul>
99
        [% FOREACH hold IN holdloop %]
100
            <li>itemnumber [% hold.itemnumber %]</li>
101
        [% END %]
102
        </ul>
103
    [% END %]
104
    </ul>
105
  [% ELSE %]
106
    <p>No reservation could be placed or cancelled.</p>
107
  [% END %]
108
  <a href="batch_holding.pl">Batch place or cancel other items</a>
109
[% ELSE %]
110
            <h1>Batch holding</h1>
111
            <form method="post" enctype="multipart/form-data" action="/cgi-bin/koha/circ/batch_holding.pl" id="batchholdform">
112
                <fieldset class="rows">
113
                    <legend>Use a barcode file</legend>
114
                        <label for="uploadfile">File: </label> <input type="file" id="uploadfile" name="uploadfile" /></li>
115
                </fieldset>
116
                <fieldset class="rows">
117
                    <legend>Or scan items one by one</legend>
118
                    <ol>
119
                        <li>
120
                          <label for="barcodelist">Barcode list (one barcode per line): </label>
121
                          <textarea rows="10" cols="30" id="barcodelist" name="barcodelist"></textarea>
122
                        </li>
123
                    </ol>
124
                </fieldset>
125
                <fieldset class="rows">
126
                    <legend>Holding informations</legend>
127
                    <ol>
128
                        <li>
129
                            <label for="findborrowerhold">Borrower:</label>
130
                            <input type="hidden" id="borrowernumber" name="borrowernumber" />
131
                            <div class="autocomplete">
132
                                <input autocomplete="on" id="findborrowerhold" name="findborrowerhold" size="40" class="focus" type="text" />
133
                            </div>
134
                        </li>
135
                        <li>
136
                        <label for="branch">Holding branch:</label>
137
                        <select name="branch" id="branch" style="width:10em;">
138
                            [% PROCESS options_for_libraries libraries => Branches.all( unfiltered => 1 ) %]
139
                        </select>
140
141
                        </li>
142
                    </ol>
143
                </fieldset>
144
                <fieldset class="rows">
145
                    <legend>Action</legend>
146
                    <ol>
147
                        <li>
148
                            <input type="radio" name="action" id="action_place_holds" value="place" checked="checked">
149
                            <label for="action_place_holds">Place holds</label>
150
                        </li>
151
                        <li>
152
                            <input type="radio" name="action" id="action_cancel_holds" value="cancel">
153
                            <label for="action_cancel_holds">Cancel holds</label>
154
                        </li>
155
                    </ol>
156
                </fieldset>
157
                <input type="hidden" name="op" value="show" />
158
                <input type="submit" value="Continue" class="button" />
159
            </form>
160
[% END %]
161
</div>
162
</div>
163
</div>
164
165
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt (-1 / +5 lines)
Lines 73-78 Link Here
73
    <dt><a href="/cgi-bin/koha/tools/picture-upload.pl">Upload patron images</a></dt>
73
    <dt><a href="/cgi-bin/koha/tools/picture-upload.pl">Upload patron images</a></dt>
74
    <dd>Upload patron images in a batch or one at a time</dd>
74
    <dd>Upload patron images in a batch or one at a time</dd>
75
    [% END %]
75
    [% END %]
76
77
    [% IF ( CAN_user_reserveforothers_place_holds ) %]
78
    <dt><a href="/cgi-bin/koha/circ/batch_holding.pl">Batch holding</a></dt>
79
    <dd>Place holds in batch</dd>
80
    [% END %]
76
    </dl>
81
    </dl>
77
</div>
82
</div>
78
83
79
- 

Return to bug 23258