use DateTime;
use Koha::Database;
+use Koha::DateUtils qw/ dt_from_string /;
use Koha::Email;
use Koha::Exceptions::Ill;
use Koha::Illcomments;
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);
ui_method_name => 'Check out',
needs_prefs => [ 'CirculateILL' ],
needs_perms => [ 'user_circulate_circulate_remaining_permissions' ],
+ # An array of functions that all must return true
+ needs_all => [ sub { my $r = shift; return $r->biblio; } ],
method => 'check_out',
next_actions => [ ],
ui_method_icon => 'fa-upload',
},
- RET => {
- prev_actions => [ 'CHK' ],
- id => 'RET',
- name => 'Returned to library',
- ui_method_name => 'Check in',
- method => 'check_in',
- next_actions => [ 'COMP' ],
- ui_method_icon => 'fa-download',
- }
+ RET => {
+ prev_actions => [ 'CHK' ],
+ id => 'RET',
+ name => 'Returned to library',
+ ui_method_name => 'Check in',
+ method => 'check_in',
+ next_actions => [ 'COMP' ],
+ ui_method_icon => 'fa-download',
+ }
};
}
sub mark_completed {
my ( $self ) = @_;
$self->status('COMP')->store;
- $self->completed(DateTime->now)->store;
+ $self->completed(dt_from_string())->store;
return {
error => 0,
status => '',
return $require_moderation->{$self->status};
}
+=head3 biblio
+
+ my $biblio = $request->biblio;
+
+For a given request, return the biblio associated with it,
+or undef if none exists
+
+=cut
+
+sub biblio {
+ my ( $self ) = @_;
+
+ return if !$self->biblio_id;
+
+ return Koha::Biblios->find({
+ biblionumber => $self->biblio_id
+ });
+}
+
=head3 check_out
my $stage_summary = $request->check_out;
{},
{ order_by => ['branchcode'] }
);
- my $biblio = Koha::Biblios->find({
- biblionumber => $self->biblio_id
- });
+ my $biblio = $self->biblio;
+
# Find all statistical patrons
my $statistical_patrons = Koha::Patrons->search(
{ 'category_type' => 'x' },
my $itemnumber;
if ($item_count == 0) {
my $item_hash = {
+ biblionumber => $self->biblio_id,
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;
+ try {
+ my $item = Koha::Item->new($item_hash)->store;
+ $itemnumber = $item->itemnumber;
+ };
} else {
$itemnumber = $items[0]->itemnumber;
}