Lines 35-40
use Koha::AuthorisedValue;
Link Here
|
35 |
use Koha::Illrequest::Logger; |
35 |
use Koha::Illrequest::Logger; |
36 |
use Koha::Patron; |
36 |
use Koha::Patron; |
37 |
use Koha::AuthorisedValues; |
37 |
use Koha::AuthorisedValues; |
|
|
38 |
use Koha::Biblios; |
39 |
use Koha::Items; |
40 |
use Koha::ItemTypes; |
41 |
use Koha::Libraries; |
42 |
use C4::Items qw( AddItem ); |
43 |
use C4::Circulation qw( CanBookBeIssued AddIssue ); |
38 |
|
44 |
|
39 |
use base qw(Koha::Object); |
45 |
use base qw(Koha::Object); |
40 |
|
46 |
|
Lines 425-431
sub _core_status_graph {
Link Here
|
425 |
name => 'Requested', |
431 |
name => 'Requested', |
426 |
ui_method_name => 'Confirm request', |
432 |
ui_method_name => 'Confirm request', |
427 |
method => 'confirm', |
433 |
method => 'confirm', |
428 |
next_actions => [ 'REQREV', 'COMP' ], |
434 |
next_actions => [ 'REQREV', 'COMP', 'CHK' ], |
429 |
ui_method_icon => 'fa-check', |
435 |
ui_method_icon => 'fa-check', |
430 |
}, |
436 |
}, |
431 |
GENREQ => { |
437 |
GENREQ => { |
Lines 434-440
sub _core_status_graph {
Link Here
|
434 |
name => 'Requested from partners', |
440 |
name => 'Requested from partners', |
435 |
ui_method_name => 'Place request with partners', |
441 |
ui_method_name => 'Place request with partners', |
436 |
method => 'generic_confirm', |
442 |
method => 'generic_confirm', |
437 |
next_actions => [ 'COMP' ], |
443 |
next_actions => [ 'COMP', 'CHK' ], |
438 |
ui_method_icon => 'fa-send-o', |
444 |
ui_method_icon => 'fa-send-o', |
439 |
}, |
445 |
}, |
440 |
REQREV => { |
446 |
REQREV => { |
Lines 470-476
sub _core_status_graph {
Link Here
|
470 |
name => 'Completed', |
476 |
name => 'Completed', |
471 |
ui_method_name => 'Mark completed', |
477 |
ui_method_name => 'Mark completed', |
472 |
method => 'mark_completed', |
478 |
method => 'mark_completed', |
473 |
next_actions => [ ], |
479 |
next_actions => [ 'CHK' ], |
474 |
ui_method_icon => 'fa-check', |
480 |
ui_method_icon => 'fa-check', |
475 |
}, |
481 |
}, |
476 |
KILL => { |
482 |
KILL => { |
Lines 482-487
sub _core_status_graph {
Link Here
|
482 |
next_actions => [ ], |
488 |
next_actions => [ ], |
483 |
ui_method_icon => 'fa-trash', |
489 |
ui_method_icon => 'fa-trash', |
484 |
}, |
490 |
}, |
|
|
491 |
CHK => { |
492 |
prev_actions => [ 'REQ', 'GENREQ', 'COMP' ], |
493 |
id => 'CHK', |
494 |
name => 'Checked out', |
495 |
ui_method_name => 'Check out', |
496 |
method => 'check_out', |
497 |
next_actions => [ ], |
498 |
ui_method_icon => 'fa-upload', |
499 |
} |
485 |
}; |
500 |
}; |
486 |
} |
501 |
} |
487 |
|
502 |
|
Lines 1023-1028
sub requires_moderation {
Link Here
|
1023 |
return $require_moderation->{$self->status}; |
1038 |
return $require_moderation->{$self->status}; |
1024 |
} |
1039 |
} |
1025 |
|
1040 |
|
|
|
1041 |
=head3 check_out |
1042 |
|
1043 |
my $stage_summary = $request->check_out; |
1044 |
|
1045 |
Handle the check_out method. The first stage involves gathering the required |
1046 |
data from the user via a form, the second stage creates an item and tries to |
1047 |
issue it to the patron. If successful, it notifies the patron, then it |
1048 |
returns a summary of how things went |
1049 |
|
1050 |
=cut |
1051 |
|
1052 |
sub check_out { |
1053 |
my ( $self, $params ) = @_; |
1054 |
|
1055 |
# Objects required by the template |
1056 |
my $itemtypes = Koha::ItemTypes->search( |
1057 |
{}, |
1058 |
{ order_by => ['description'] } |
1059 |
); |
1060 |
my $libraries = Koha::Libraries->search( |
1061 |
{}, |
1062 |
{ order_by => ['branchcode'] } |
1063 |
); |
1064 |
my $biblio = Koha::Biblios->find({ |
1065 |
biblionumber => $self->biblio_id |
1066 |
}); |
1067 |
# Find all statistical patrons |
1068 |
my $statistical_patrons = Koha::Patrons->search( |
1069 |
{ 'category_type' => 'x' }, |
1070 |
{ join => { 'categorycode' => 'borrowers' } } |
1071 |
); |
1072 |
|
1073 |
if (!$params->{stage} || $params->{stage} eq 'init') { |
1074 |
# Present a form to gather the required data |
1075 |
# |
1076 |
# We may be viewing this page having previously tried to issue |
1077 |
# the item (in which case, we may already have created an item) |
1078 |
# so we pass the biblio for this request |
1079 |
return { |
1080 |
method => 'check_out', |
1081 |
stage => 'form', |
1082 |
value => { |
1083 |
itemtypes => $itemtypes, |
1084 |
libraries => $libraries, |
1085 |
statistical => $statistical_patrons, |
1086 |
biblio => $biblio |
1087 |
} |
1088 |
}; |
1089 |
} elsif ($params->{stage} eq 'form') { |
1090 |
# Validate what we've got and return with an error if we fail |
1091 |
my $errors = {}; |
1092 |
if (!$params->{item_type} || length $params->{item_type} == 0) { |
1093 |
$errors->{item_type} = 1; |
1094 |
} |
1095 |
if ($params->{inhouse} && length $params->{inhouse} > 0) { |
1096 |
my $patron_count = Koha::Patrons->search({ |
1097 |
cardnumber => $params->{inhouse} |
1098 |
})->count(); |
1099 |
if ($patron_count != 1) { |
1100 |
$errors->{inhouse} = 1; |
1101 |
} |
1102 |
} |
1103 |
|
1104 |
# Check we don't have more than one item for this bib, |
1105 |
# if we do, something very odd is going on |
1106 |
# Having 1 is OK, it means we're likely trying to issue |
1107 |
# following a previously failed attempt, the item exists |
1108 |
# so we'll use it |
1109 |
my @items = $biblio->items->as_list; |
1110 |
my $item_count = scalar @items; |
1111 |
if ($item_count > 1) { |
1112 |
$errors->{itemcount} = 1; |
1113 |
} |
1114 |
|
1115 |
# Failed validation, go back to the form |
1116 |
if (%{$errors}) { |
1117 |
return { |
1118 |
method => 'check_out', |
1119 |
stage => 'form', |
1120 |
value => { |
1121 |
params => $params, |
1122 |
statistical => $statistical_patrons, |
1123 |
itemtypes => $itemtypes, |
1124 |
libraries => $libraries, |
1125 |
biblio => $biblio, |
1126 |
errors => $errors |
1127 |
} |
1128 |
}; |
1129 |
} |
1130 |
|
1131 |
# Passed validation |
1132 |
# |
1133 |
# Create an item if one doesn't already exist, |
1134 |
# if one does, use that |
1135 |
my $itemnumber; |
1136 |
if ($item_count == 0) { |
1137 |
my $item_hash = { |
1138 |
homebranch => $params->{branchcode}, |
1139 |
holdingbranch => $params->{branchcode}, |
1140 |
location => $params->{branchcode}, |
1141 |
itype => $params->{item_type}, |
1142 |
barcode => 'ILL-' . $self->illrequest_id |
1143 |
}; |
1144 |
my (undef, undef, $item_no) = |
1145 |
AddItem($item_hash, $self->biblio_id); |
1146 |
$itemnumber = $item_no; |
1147 |
} else { |
1148 |
$itemnumber = $items[0]->itemnumber; |
1149 |
} |
1150 |
# Check we have an item before going forward |
1151 |
if (!$itemnumber) { |
1152 |
return { |
1153 |
method => 'check_out', |
1154 |
stage => 'form', |
1155 |
value => { |
1156 |
params => $params, |
1157 |
itemtypes => $itemtypes, |
1158 |
libraries => $libraries, |
1159 |
statistical => $statistical_patrons, |
1160 |
errors => { item_creation => 1 } |
1161 |
} |
1162 |
}; |
1163 |
} |
1164 |
|
1165 |
# Do the check out |
1166 |
# |
1167 |
# Gather what we need |
1168 |
my $target_item = Koha::Items->find( $itemnumber ); |
1169 |
# Determine who we're issuing to |
1170 |
my $patron = $params->{inhouse} && length $params->{inhouse} > 0 ? |
1171 |
Koha::Patrons->find({ cardnumber => $params->{inhouse} }) : |
1172 |
$self->patron; |
1173 |
|
1174 |
my @issue_args = ( |
1175 |
$patron, |
1176 |
scalar $target_item->barcode |
1177 |
); |
1178 |
if ($params->{duedate} && length $params->{duedate} > 0) { |
1179 |
push @issue_args, $params->{duedate}; |
1180 |
} |
1181 |
# Check if we can check out |
1182 |
my ( $error, $confirm, $alerts, $messages ) = |
1183 |
C4::Circulation::CanBookBeIssued(@issue_args); |
1184 |
|
1185 |
# If we got anything back saying we can't check out, |
1186 |
# return it to the template |
1187 |
my $problems = {}; |
1188 |
if ( $error && %{$error} ) { $problems->{error} = $error }; |
1189 |
if ( $confirm && %{$confirm} ) { $problems->{confirm} = $confirm }; |
1190 |
if ( $alerts && %{$alerts} ) { $problems->{alerts} = $alerts }; |
1191 |
if ( $messages && %{$messages} ) { $problems->{messages} = $messages }; |
1192 |
|
1193 |
if (%{$problems}) { |
1194 |
return { |
1195 |
method => 'check_out', |
1196 |
stage => 'form', |
1197 |
value => { |
1198 |
params => $params, |
1199 |
itemtypes => $itemtypes, |
1200 |
libraries => $libraries, |
1201 |
statistical => $statistical_patrons, |
1202 |
patron => $patron, |
1203 |
biblio => $biblio, |
1204 |
check_out_errors => $problems |
1205 |
} |
1206 |
}; |
1207 |
} |
1208 |
|
1209 |
# We can allegedly check out, so make it so |
1210 |
# For some reason, AddIssue requires an unblessed Patron |
1211 |
$issue_args[0] = $patron->unblessed; |
1212 |
my $issue = C4::Circulation::AddIssue(@issue_args); |
1213 |
|
1214 |
if ($issue && %{$issue}) { |
1215 |
# Update the request status |
1216 |
$self->status('CHK')->store; |
1217 |
return { |
1218 |
method => 'check_out', |
1219 |
stage => 'done_check_out', |
1220 |
value => { |
1221 |
params => $params, |
1222 |
patron => $patron, |
1223 |
check_out => $issue |
1224 |
} |
1225 |
}; |
1226 |
} else { |
1227 |
return { |
1228 |
method => 'check_out', |
1229 |
stage => 'form', |
1230 |
value => { |
1231 |
params => $params, |
1232 |
itemtypes => $itemtypes, |
1233 |
libraries => $libraries, |
1234 |
errors => { item_check_out => 1 } |
1235 |
} |
1236 |
}; |
1237 |
} |
1238 |
} |
1239 |
|
1240 |
} |
1241 |
|
1026 |
=head3 generic_confirm |
1242 |
=head3 generic_confirm |
1027 |
|
1243 |
|
1028 |
my $stage_summary = $illRequest->generic_confirm; |
1244 |
my $stage_summary = $illRequest->generic_confirm; |