use Koha::Illrequest::Logger;
use Koha::Patron;
use Koha::AuthorisedValues;
+use Koha::Biblios;
+use Koha::Items;
+use Koha::ItemTypes;
+use Koha::Libraries;
+use C4::Items qw( AddItem );
+use C4::Circulation qw( CanBookBeIssued AddIssue );
use base qw(Koha::Object);
name => 'Requested',
ui_method_name => 'Confirm request',
method => 'confirm',
- next_actions => [ 'REQREV', 'COMP' ],
+ next_actions => [ 'REQREV', 'COMP', 'CHK' ],
ui_method_icon => 'fa-check',
},
GENREQ => {
name => 'Requested from partners',
ui_method_name => 'Place request with partners',
method => 'generic_confirm',
- next_actions => [ 'COMP' ],
+ next_actions => [ 'COMP', 'CHK' ],
ui_method_icon => 'fa-send-o',
},
REQREV => {
name => 'Completed',
ui_method_name => 'Mark completed',
method => 'mark_completed',
- next_actions => [ ],
+ next_actions => [ 'CHK' ],
ui_method_icon => 'fa-check',
},
KILL => {
next_actions => [ ],
ui_method_icon => 'fa-trash',
},
+ CHK => {
+ prev_actions => [ 'REQ', 'GENREQ', 'COMP' ],
+ id => 'CHK',
+ name => 'Checked out',
+ ui_method_name => 'Check out',
+ method => 'check_out',
+ next_actions => [ ],
+ ui_method_icon => 'fa-upload',
+ }
};
}
return $require_moderation->{$self->status};
}
+=head3 check_out
+
+ my $stage_summary = $request->check_out;
+
+Handle the check_out method. The first stage involves gathering the required
+data from the user via a form, the second stage creates an item and tries to
+issue it to the patron. If successful, it notifies the patron, then it
+returns a summary of how things went
+
+=cut
+
+sub check_out {
+ my ( $self, $params ) = @_;
+
+ # Objects required by the template
+ my $itemtypes = Koha::ItemTypes->search(
+ {},
+ { order_by => ['description'] }
+ );
+ my $libraries = Koha::Libraries->search(
+ {},
+ { order_by => ['branchcode'] }
+ );
+ my $biblio = Koha::Biblios->find({
+ biblionumber => $self->biblio_id
+ });
+ # Find all statistical patrons
+ my $statistical_patrons = Koha::Patrons->search(
+ { 'category_type' => 'x' },
+ { join => { 'categorycode' => 'borrowers' } }
+ );
+
+ if (!$params->{stage} || $params->{stage} eq 'init') {
+ # Present a form to gather the required data
+ #
+ # We may be viewing this page having previously tried to issue
+ # the item (in which case, we may already have created an item)
+ # so we pass the biblio for this request
+ return {
+ method => 'check_out',
+ stage => 'form',
+ value => {
+ itemtypes => $itemtypes,
+ libraries => $libraries,
+ statistical => $statistical_patrons,
+ biblio => $biblio
+ }
+ };
+ } elsif ($params->{stage} eq 'form') {
+ # Validate what we've got and return with an error if we fail
+ my $errors = {};
+ if (!$params->{item_type} || length $params->{item_type} == 0) {
+ $errors->{item_type} = 1;
+ }
+ if ($params->{inhouse} && length $params->{inhouse} > 0) {
+ my $patron_count = Koha::Patrons->search({
+ cardnumber => $params->{inhouse}
+ })->count();
+ if ($patron_count != 1) {
+ $errors->{inhouse} = 1;
+ }
+ }
+
+ # Check we don't have more than one item for this bib,
+ # if we do, something very odd is going on
+ # Having 1 is OK, it means we're likely trying to issue
+ # following a previously failed attempt, the item exists
+ # so we'll use it
+ my @items = $biblio->items->as_list;
+ my $item_count = scalar @items;
+ if ($item_count > 1) {
+ $errors->{itemcount} = 1;
+ }
+
+ # Failed validation, go back to the form
+ if (%{$errors}) {
+ return {
+ method => 'check_out',
+ stage => 'form',
+ value => {
+ params => $params,
+ statistical => $statistical_patrons,
+ itemtypes => $itemtypes,
+ libraries => $libraries,
+ biblio => $biblio,
+ errors => $errors
+ }
+ };
+ }
+
+ # Passed validation
+ #
+ # Create an item if one doesn't already exist,
+ # if one does, use that
+ my $itemnumber;
+ if ($item_count == 0) {
+ my $item_hash = {
+ homebranch => $params->{branchcode},
+ holdingbranch => $params->{branchcode},
+ location => $params->{branchcode},
+ itype => $params->{item_type},
+ barcode => 'ILL-' . $self->illrequest_id
+ };
+ my (undef, undef, $item_no) =
+ AddItem($item_hash, $self->biblio_id);
+ $itemnumber = $item_no;
+ } else {
+ $itemnumber = $items[0]->itemnumber;
+ }
+ # Check we have an item before going forward
+ if (!$itemnumber) {
+ return {
+ method => 'check_out',
+ stage => 'form',
+ value => {
+ params => $params,
+ itemtypes => $itemtypes,
+ libraries => $libraries,
+ statistical => $statistical_patrons,
+ errors => { item_creation => 1 }
+ }
+ };
+ }
+
+ # Do the check out
+ #
+ # Gather what we need
+ my $target_item = Koha::Items->find( $itemnumber );
+ # Determine who we're issuing to
+ my $patron = $params->{inhouse} && length $params->{inhouse} > 0 ?
+ Koha::Patrons->find({ cardnumber => $params->{inhouse} }) :
+ $self->patron;
+
+ my @issue_args = (
+ $patron,
+ scalar $target_item->barcode
+ );
+ if ($params->{duedate} && length $params->{duedate} > 0) {
+ push @issue_args, $params->{duedate};
+ }
+ # Check if we can check out
+ my ( $error, $confirm, $alerts, $messages ) =
+ C4::Circulation::CanBookBeIssued(@issue_args);
+
+ # If we got anything back saying we can't check out,
+ # return it to the template
+ my $problems = {};
+ if ( $error && %{$error} ) { $problems->{error} = $error };
+ if ( $confirm && %{$confirm} ) { $problems->{confirm} = $confirm };
+ if ( $alerts && %{$alerts} ) { $problems->{alerts} = $alerts };
+ if ( $messages && %{$messages} ) { $problems->{messages} = $messages };
+
+ if (%{$problems}) {
+ return {
+ method => 'check_out',
+ stage => 'form',
+ value => {
+ params => $params,
+ itemtypes => $itemtypes,
+ libraries => $libraries,
+ statistical => $statistical_patrons,
+ patron => $patron,
+ biblio => $biblio,
+ check_out_errors => $problems
+ }
+ };
+ }
+
+ # We can allegedly check out, so make it so
+ # For some reason, AddIssue requires an unblessed Patron
+ $issue_args[0] = $patron->unblessed;
+ my $issue = C4::Circulation::AddIssue(@issue_args);
+
+ if ($issue && %{$issue}) {
+ # Update the request status
+ $self->status('CHK')->store;
+ return {
+ method => 'check_out',
+ stage => 'done_check_out',
+ value => {
+ params => $params,
+ patron => $patron,
+ check_out => $issue
+ }
+ };
+ } else {
+ return {
+ method => 'check_out',
+ stage => 'form',
+ value => {
+ params => $params,
+ itemtypes => $itemtypes,
+ libraries => $libraries,
+ errors => { item_check_out => 1 }
+ }
+ };
+ }
+ }
+
+}
+
=head3 generic_confirm
my $stage_summary = $illRequest->generic_confirm;
<h1>Cancel a confirmed request</h1>
[% PROCESS $whole.template %]
+ [% ELSIF query_type == 'check_out' and !whole.error %]
+ [% IF !whole.stage || whole.stage == 'form' %]
+ <h1 id="ill-issue-title">Issue requested item to [% request.patron.firstname %] [% request.patron.surname %]</h1>
+ [% IF !request.biblio_id || request.biblio_id.length == 0 %]
+ <div class="alert">This item cannot be issued as it has no biblio record associated with it</div>
+ [% END %]
+ [% IF whole.value.errors.itemcount %]
+ <div class="alert">The bibliographic record for this request has multiple items, it should only have one. Please fix this then try again.</div>
+ [% END %]
+ [% IF whole.value.errors.item_creation %]
+ <div class="alert">An unknown error occurred while trying to add an item</div>
+ [% END %]
+ [% IF whole.value.errors.item_check_out %]
+ <div class="alert">An unknown error occurred while trying to check out the item</div>
+ [% END %]
+ [% IF whole.value.check_out_errors %]
+ [% IF whole.value.check_out_errors.error.STATS %]
+ <div class="alert">
+ Local use recorded
+ </div>
+ [% ELSE %]
+ <div class="alert">
+ There was a problem checking this item out, please check for problems with the <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% whole.value.patron.borrowernumber %]">patron's account</a>
+ </div>
+ [% END %]
+ [% END %]
+ [% IF request.biblio_id && request.biblio_id.length > 0 && !whole.value.check_out_errors.error.STATS %]
+ <form method="POST" action="/cgi-bin/koha/ill/ill-requests.pl">
+ <fieldset class="rows">
+ <legend>Check out details</legend>
+ [% items = whole.value.biblio.items.unblessed %]
+ [% IF items.size == 1 %]
+ <p>The bibliographic record for this request already has an item attached to it, you are about to check it out</p>
+ [% ELSE %]
+ <p>A bibliographic record for this request exists, but no item. You are about to create an item and check it out</p>
+ [% END %]
+ <ol>
+ <li class="ill_checkout_inhouse">
+ <label for="inhouse" class="ill_checkout_inhouse_label">Statistical patron:</label>
+ <select id="ill_checkout_inhouse_select" name="inhouse" class="ill_checkout_inhouse_select">
+ <option value=""></option>
+ [% FOREACH stat IN whole.value.statistical %]
+ [% IF stat.borrowernumber == params.inhouse %]
+ <option value="[% stat.cardnumber %]" selected>[% stat.firstname %] [% stat.surname %]</option>
+ [% ELSE %]
+ <option value="[% stat.cardnumber %]">[% stat.firstname %] [% stat.surname %]</option>
+ [% END %]
+ [% END %]
+ </select>
+ [% IF whole.value.errors.inhouse %]
+ <span class="required">You must choose a valid patron</span>
+ [% END %]
+ <div class="hint">If you do not wish to check out the item to [% request.patron.firstname | html %] [% request.patron.surname | html %] and would rather issue it to an in-house statistical patron, choose the patron here</div>
+ </li>
+ <li class="ill_checkout_item_type">
+ <label for="item_type" class="ill_checkout_item_type_label required">Item type:</label>
+ [% IF items.size != 1 %]
+ <select id="ill_checkout_item_type_select" name="item_type" required>
+ [% FOREACH type IN whole.value.itemtypes %]
+ [% IF type.itemtype == params.item_type %]
+ <option value="[% type.itemtype | html %]" selected>
+ [% ELSE %]
+ <option value="[% type.itemtype | html %]">
+ [% END %]
+ [% type.description | html %]
+ </option>
+ [% END %]
+ </select>
+ [% ELSE %]
+ [% FOREACH type IN whole.value.itemtypes %]
+ [% IF type.itemtype == items.0.itype %]
+ [% type.description | html %]
+ [% END %]
+ [% END %]
+ [% END %]
+ [% IF whole.value.errors.item_type %]
+ <span class="required">You must choose an item type</span>
+ [% END %]
+ </li>
+ [% IF items.size == 1 %]
+ <li>
+ <label for="barcode" class="ill_checkout_barcode_label">Item barcode:</label>
+ [% items.0.barcode %]
+ </li>
+ [% END %]
+ <li class="ill_checkout_branchcode">
+ <label for="branchcode" class="ill_checkout_branchcode_label required">Library:</label>
+ [% branchcode = items.size == 1 ? items.0.homebranch : params.branchcode ? params.branchcode : request.branchcode %]
+ [% IF items.size != 1 %]
+ <select name="branchcode" id="ill_checkout_branchcode_select" required>
+ [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode ) %]
+ </select>
+ [% ELSE %]
+ [% FOREACH branch IN whole.value.libraries.unblessed %]
+ [% IF branch.branchcode == branchcode %]
+ [% branch.branchname %]
+ [% END %]
+ [% END %]
+ [% END %]
+ [% IF whole.value.errors.branchcode %]
+ <span class="required">You must choose a branch</span>
+ [% END %]
+ </li>
+ <li class="ill_checkout_due_date">
+ <label for="duedate" class="ill_checkout_duedate_label">Due date:</label>
+ <input name="duedate" id="ill_checkout_duedate_input" type="text" value="[% params.duedate | html %]"> [% INCLUDE 'date-format.inc' %]
+ <div class="hint">If you do not specify a due date, it will be set according to circulation rules</p>
+ </li>
+ </ol>
+ </fieldset>
+ <fieldset class="action">
+ <input type="hidden" value="check_out" name="method">
+ <input type="hidden" value="form" name="stage">
+ [% IF items.size == 1 %]
+ <input name="branchcode" type="hidden" value="[% branchcode %]">
+ <input name="item_type" type="hidden" value="[% items.0.itype %]">
+ [% END %]
+ <input type="hidden" value="[% request.illrequest_id | html %]" name="illrequest_id">
+ <input type="submit" value="Submit">
+ <a class="cancel" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&illrequest_id=[% request.id | html %]">Cancel</a>
+ </fieldset>
+ </form>
+ [% END %]
+ [% IF whole.value.check_out_errors.error.STATS %]
+ <a class="cancel" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&illrequest_id=[% request.id | html %]">Return to request</a>
+ [% END %]
+ [% ELSIF whole.stage == 'done_check_out' %]
+ <h1>Item checked out</h1>
+ <fieldset class="rows">
+ <legend>Check out details</legend>
+ <ol>
+ <li>
+ <label>Checked out to:</label>
+ [% whole.value.patron.firstname | html %] [% whole.value.patron.surname | html %]
+ </li>
+ <li>
+ <label>Due date:</label>
+ [% whole.value.check_out.date_due | $KohaDates with_hours => 1 %]
+ </li>
+ </ol>
+ </fieldset>
+ <fieldset class="action">
+ <a class="cancel" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&illrequest_id=[% request.id | html %]">Return to request</a>
+ </fieldset>
+ [% END %]
+
[% ELSIF query_type == 'generic_confirm' %]
<h1>Place request with partner libraries</h1>
[% IF error %]
[% INCLUDE 'datatables.inc' %]
[% INCLUDE 'columns_settings.inc' %]
[% INCLUDE 'calendar.inc' %]
+ [% Asset.js("lib/jquery/plugins/jquery-ui-timepicker-addon.min.js") | $raw %]
[% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
<script>
var prefilters = '[% prefilters | $raw %]';
// Set column settings
var columns_settings = [% ColumnsSettings.GetColumns( 'illrequests', 'ill-requests', 'ill-requests', 'json' ) %];
+ $("#ill_checkout_duedate_input").datetimepicker({
+ hour: 23,
+ minute: 59
+ }).on("change", function(e, value) {
+ if ( ! is_valid_date( $(this).val() ) ) {$(this).val("");}
+ });
+ </script>
+ <script>
+ $('#ill_checkout_inhouse_select').on('change', function() {
+ if ($(this).val().length > 0) {
+ $('.ill_checkout_due_date').hide();
+ } else {
+ $('.ill_checkout_due_date').show();
+ }
+ });
</script>
[% INCLUDE 'ill-list-table-strings.inc' %]
[% Asset.js("js/ill-list-table.js") | $raw %]
+ [% Asset.js("js/ill-check-out.js") | $raw %]
[% END %]
[% TRY %]