Lines 1-95
Link Here
|
1 |
package Koha::Acquisition::Order; |
1 |
package Koha::Acquisition::Order; |
2 |
|
2 |
|
|
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it under the |
6 |
# terms of the GNU General Public License as published by the Free Software |
7 |
# Foundation; either version 3 of the License, or (at your option) any later |
8 |
# version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
13 |
# |
14 |
# You should have received a copy of the GNU General Public License along |
15 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
16 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 |
|
3 |
use Modern::Perl; |
18 |
use Modern::Perl; |
4 |
|
19 |
|
|
|
20 |
use Carp qw( croak ); |
21 |
|
5 |
use Koha::Database; |
22 |
use Koha::Database; |
6 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
23 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
7 |
|
24 |
|
8 |
use Carp qw( croak ); |
25 |
use base qw(Koha::Object); |
9 |
|
26 |
|
10 |
use base qw( Class::Accessor ); |
27 |
=head1 NAME |
11 |
|
28 |
|
12 |
# TODO fetch order from itemnumber (GetOrderFromItemnnumber) |
29 |
Koha::Acquisition::Order Object class |
13 |
# TODO Move code from GetOrder |
30 |
|
14 |
sub fetch { |
31 |
=head1 API |
15 |
my ( $class, $params ) = @_; |
32 |
|
16 |
my $ordernumber = $params->{ordernumber}; |
33 |
=head2 Class Methods |
17 |
return unless $ordernumber; |
|
|
18 |
my $schema = Koha::Database->new->schema; |
19 |
|
34 |
|
20 |
my $order = |
35 |
=cut |
21 |
$schema->resultset('Aqorder')->find( { ordernumber => $ordernumber }, |
36 |
|
22 |
{ result_class => 'DBIx::Class::ResultClass::HashRefInflator' } ); |
37 |
sub new { |
23 |
return $class->new( $order ); |
38 |
my ( $self, $params ) = @_; |
|
|
39 |
|
40 |
my $schema = Koha::Database->new->schema; |
41 |
my @columns = $schema->source('Aqorder')->columns; |
42 |
|
43 |
my $values = |
44 |
{ map { exists $params->{$_} ? ( $_ => $params->{$_} ) : () } @columns }; |
45 |
return $self->SUPER::new($values); |
24 |
} |
46 |
} |
25 |
|
47 |
|
26 |
sub insert { |
48 |
sub store { |
27 |
my ($self) = @_; |
49 |
my ($self) = @_; |
28 |
|
50 |
|
29 |
my $schema = Koha::Database->new->schema; |
51 |
my $schema = Koha::Database->new->schema; |
30 |
# Override quantity for standing orders |
52 |
# Override quantity for standing orders |
31 |
$self->{quantity} = 1 if ( $self->{basketno} && $schema->resultset('Aqbasket')->find( $self->{basketno} )->is_standing ); |
53 |
$self->quantity(1) if ( $self->basketno && $schema->resultset('Aqbasket')->find( $self->basketno )->is_standing ); |
32 |
|
54 |
|
33 |
# if these parameters are missing, we can't continue |
55 |
# if these parameters are missing, we can't continue |
34 |
for my $key (qw( basketno quantity biblionumber budget_id )) { |
56 |
for my $key (qw( basketno quantity biblionumber budget_id )) { |
35 |
croak "Cannot insert order: Mandatory parameter $key is missing" |
57 |
croak "Cannot insert order: Mandatory parameter $key is missing" |
36 |
unless $self->{$key}; |
58 |
unless $self->$key; |
37 |
} |
59 |
} |
38 |
|
60 |
|
39 |
$self->{quantityreceived} ||= 0; |
61 |
$self->quantityreceived(0) unless $self->quantityreceived; |
40 |
$self->{entrydate} ||= |
62 |
$self->entrydate(output_pref( { dt => dt_from_string, dateformat => 'iso' } )) unless $self->entrydate; |
41 |
output_pref( { dt => dt_from_string, dateformat => 'iso' } ); |
|
|
42 |
|
43 |
my @columns = $schema->source('Aqorder')->columns; |
44 |
|
45 |
$self->{ordernumber} ||= undef; |
46 |
|
63 |
|
47 |
my $rs = $schema->resultset('Aqorder')->create( |
64 |
$self->ordernumber(undef) unless $self->ordernumber; |
48 |
{ |
65 |
$self = $self->SUPER::store( $self ); |
49 |
map { |
|
|
50 |
exists $self->{$_} ? ( $_ => $self->{$_} ) : () |
51 |
} @columns |
52 |
} |
53 |
); |
54 |
$self->{ordernumber} = $rs->id; |
55 |
|
66 |
|
56 |
unless ( $self->{parent_ordernumber} ) { |
67 |
unless ( $self->parent_ordernumber ) { |
57 |
$self->{parent_ordernumber} = $self->{ordernumber}; |
68 |
$self->set( { parent_ordernumber => $self->ordernumber } ); |
58 |
$rs->update( { parent_ordernumber => $self->{parent_ordernumber} } ); |
69 |
$self = $self->SUPER::store( $self ); |
59 |
} |
70 |
} |
60 |
|
71 |
|
61 |
return $self; |
72 |
return $self; |
62 |
} |
73 |
} |
63 |
|
74 |
|
|
|
75 |
=head3 add_item |
76 |
|
77 |
$order->add_item( $itemnumber ); |
78 |
|
79 |
Link an item to this order. |
80 |
|
81 |
=cut |
82 |
|
64 |
sub add_item { |
83 |
sub add_item { |
65 |
my ( $self, $itemnumber ) = @_; |
84 |
my ( $self, $itemnumber ) = @_; |
|
|
85 |
|
66 |
my $schema = Koha::Database->new->schema; |
86 |
my $schema = Koha::Database->new->schema; |
67 |
my $rs = $schema->resultset('AqordersItem'); |
87 |
my $rs = $schema->resultset('AqordersItem'); |
68 |
$rs->create({ ordernumber => $self->{ordernumber}, itemnumber => $itemnumber }); |
88 |
$rs->create({ ordernumber => $self->ordernumber, itemnumber => $itemnumber }); |
69 |
} |
89 |
} |
70 |
|
90 |
|
71 |
# TODO Move code from ModItemOrder |
91 |
=head3 _type |
72 |
sub update_item { |
|
|
73 |
die "not implemented yet"; |
74 |
} |
75 |
|
76 |
sub del_item { |
77 |
die "not implemented yet"; |
78 |
} |
79 |
|
92 |
|
80 |
# TODO Move code from ModOrder |
93 |
=cut |
81 |
sub update { |
|
|
82 |
die "not implemented yet"; |
83 |
} |
84 |
|
85 |
# TODO Move code from DelOrder |
86 |
sub delete { |
87 |
die "not implemented yet"; |
88 |
} |
89 |
|
94 |
|
90 |
# TODO Move code from TransferOrder |
95 |
sub _type { |
91 |
sub transfer { |
96 |
return 'Aqorder'; |
92 |
die "not implemented yet"; |
|
|
93 |
} |
97 |
} |
94 |
|
98 |
|
95 |
1; |
99 |
1; |