|
Lines 128-141
sub store {
Link Here
|
| 128 |
|
128 |
|
| 129 |
# Assign item at booking time |
129 |
# Assign item at booking time |
| 130 |
if ( !$self->item_id ) { |
130 |
if ( !$self->item_id ) { |
| 131 |
$self->item_id( |
131 |
$self->_assign_item_for_booking; |
| 132 |
$self->biblio->assign_item_for_booking( |
|
|
| 133 |
{ |
| 134 |
start_date => $self->start_date, |
| 135 |
end_date => $self->end_date |
| 136 |
} |
| 137 |
) |
| 138 |
); |
| 139 |
} |
132 |
} |
| 140 |
|
133 |
|
| 141 |
$self = $self->SUPER::store; |
134 |
$self = $self->SUPER::store; |
|
Lines 145-150
sub store {
Link Here
|
| 145 |
return $self; |
138 |
return $self; |
| 146 |
} |
139 |
} |
| 147 |
|
140 |
|
|
|
141 |
=head3 _assign_item_for_booking |
| 142 |
|
| 143 |
$self->_assign_item_for_booking; |
| 144 |
|
| 145 |
Used internally in Koha::Booking->store to ensure we have an item assigned for the booking. |
| 146 |
|
| 147 |
=cut |
| 148 |
|
| 149 |
sub _assign_item_for_booking { |
| 150 |
my ($self) = @_; |
| 151 |
|
| 152 |
my $biblio = $self->biblio; |
| 153 |
|
| 154 |
my $start_date = dt_from_string( $self->start_date ); |
| 155 |
my $end_date = dt_from_string( $self->end_date ); |
| 156 |
|
| 157 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
| 158 |
|
| 159 |
my $existing_bookings = $biblio->bookings( |
| 160 |
[ |
| 161 |
start_date => { |
| 162 |
'-between' => [ |
| 163 |
$dtf->format_datetime($start_date), |
| 164 |
$dtf->format_datetime($end_date) |
| 165 |
] |
| 166 |
}, |
| 167 |
end_date => { |
| 168 |
'-between' => [ |
| 169 |
$dtf->format_datetime($start_date), |
| 170 |
$dtf->format_datetime($end_date) |
| 171 |
] |
| 172 |
}, |
| 173 |
{ |
| 174 |
start_date => { '<' => $dtf->format_datetime($start_date) }, |
| 175 |
end_date => { '>' => $dtf->format_datetime($end_date) } |
| 176 |
} |
| 177 |
] |
| 178 |
); |
| 179 |
|
| 180 |
my $checkouts = |
| 181 |
$biblio->current_checkouts->search( { date_due => { '>=' => $dtf->format_datetime($start_date) } } ); |
| 182 |
|
| 183 |
my $bookable_items = $biblio->bookable_items->search( |
| 184 |
{ |
| 185 |
itemnumber => [ |
| 186 |
'-and' => { '-not_in' => $existing_bookings->_resultset->get_column('item_id')->as_query }, |
| 187 |
{ '-not_in' => $checkouts->_resultset->get_column('itemnumber')->as_query } |
| 188 |
] |
| 189 |
}, |
| 190 |
{ rows => 1 } |
| 191 |
); |
| 192 |
|
| 193 |
my $itemnumber = $bookable_items->single->itemnumber; |
| 194 |
return $self->item_id($itemnumber); |
| 195 |
} |
| 196 |
|
| 148 |
=head3 get_items_that_can_fill |
197 |
=head3 get_items_that_can_fill |
| 149 |
|
198 |
|
| 150 |
my $items = $bookings->get_items_that_can_fill(); |
199 |
my $items = $bookings->get_items_that_can_fill(); |
| 151 |
- |
|
|