View | Details | Raw Unified | Return to bug 26582
Collapse All | Expand All

(-)a/Koha/Acquisition/Basket.pm (+48 lines)
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
(-)a/Koha/Exceptions/Acquisition/Basket.pm (-1 / +47 lines)
Line 0 Link Here
0
- 
1
package Koha::Exceptions::Acquisition::Basket;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Exception::Class (
21
22
    'Koha::Exceptions::Acquisition::Basket' => {
23
        description => 'Something went wrong!',
24
    },
25
    'Koha::Exceptions::Acquisition::Basket::AlreadyClosed' => {
26
        isa         => 'Koha::Exceptions::Acquisition::Basket',
27
        description => 'Basket is already closed'
28
    }
29
);
30
31
=head1 NAME
32
33
Koha::Exceptions::Acquisition::Basket - Base class for Basket exceptions
34
35
=head1 Exceptions
36
37
=head2 Koha::Exceptions::Acquisition::Basket
38
39
Generic Nasket exception
40
41
=head2 Koha::Exceptions::Acquisition::Basket::AlreadyClosed
42
43
Exception to be used when an already closed basket is asked to be closed.
44
45
=cut
46
47
1;

Return to bug 26582