Lines 23-28
use Koha::Database;
Link Here
|
23 |
use Koha::DateUtils qw( dt_from_string ); |
23 |
use Koha::DateUtils qw( dt_from_string ); |
24 |
use Koha::Acquisition::BasketGroups; |
24 |
use Koha::Acquisition::BasketGroups; |
25 |
use Koha::Acquisition::Orders; |
25 |
use Koha::Acquisition::Orders; |
|
|
26 |
use Koha::Exceptions::Acquisition::Basket; |
26 |
use Koha::Patrons; |
27 |
use Koha::Patrons; |
27 |
|
28 |
|
28 |
use base qw( Koha::Object Koha::Object::Mixin::AdditionalFields ); |
29 |
use base qw( Koha::Object Koha::Object::Mixin::AdditionalFields ); |
Lines 155-160
sub authorizer {
Link Here
|
155 |
return scalar Koha::Patrons->find($self->authorisedby); |
156 |
return scalar Koha::Patrons->find($self->authorisedby); |
156 |
} |
157 |
} |
157 |
|
158 |
|
|
|
159 |
=head3 closed |
160 |
|
161 |
if ( $basket->closed ) { ... } |
162 |
|
163 |
Returns a boolean value representing if the basket is closed. |
164 |
|
165 |
=cut |
166 |
|
167 |
sub closed { |
168 |
my ($self) = @_; |
169 |
|
170 |
return ($self->closedate) ? 1 : 0; |
171 |
} |
172 |
|
173 |
=head3 close |
174 |
|
175 |
$basket->close; |
176 |
|
177 |
Close the basket and mark all open orders as ordered. |
178 |
|
179 |
A I<Koha::Exceptions::Acquisition::Basket::AlreadyClosed> exception is thrown |
180 |
if the basket is already closed. |
181 |
|
182 |
=cut |
183 |
|
184 |
sub close { |
185 |
my ($self) = @_; |
186 |
|
187 |
Koha::Exceptions::Acquisition::Basket::AlreadyClosed->throw |
188 |
if $self->closed; |
189 |
|
190 |
$self->_result->result_source->schema->txn_do( |
191 |
sub { |
192 |
my $open_orders = $self->orders->search( |
193 |
{ |
194 |
orderstatus => { not_in => [ 'complete', 'cancelled' ] } |
195 |
} |
196 |
); |
197 |
# Mark open orders as ordered |
198 |
$open_orders->update({ orderstatus => 'ordered' }, { no_triggers => 1 }); |
199 |
# set as closed |
200 |
$self->set({ closedate => \'NOW()' })->store; |
201 |
} |
202 |
); |
203 |
|
204 |
return $self; |
205 |
} |
158 |
|
206 |
|
159 |
=head3 to_api |
207 |
=head3 to_api |
160 |
|
208 |
|