1 package Koha
::Acquisition
::Order
;
3 # This file is part of Koha.
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
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.
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.
22 use Koha
::Acquisition
::Baskets
;
24 use Koha
::DateUtils
qw( dt_from_string output_pref );
26 use base
qw(Koha::Object);
30 Koha::Acquisition::Order Object class
38 Overloaded I<new> method for backwards compatibility.
43 my ( $self, $params ) = @_;
45 my $schema = Koha
::Database
->new->schema;
46 my @columns = $schema->source('Aqorder')->columns;
49 { map { exists $params->{$_} ?
( $_ => $params->{$_} ) : () } @columns };
50 return $self->SUPER::new
($values);
55 Overloaded I<store> method for backwards compatibility.
62 my $schema = Koha
::Database
->new->schema;
63 # Override quantity for standing orders
64 $self->quantity(1) if ( $self->basketno && $schema->resultset('Aqbasket')->find( $self->basketno )->is_standing );
66 # if these parameters are missing, we can't continue
67 for my $key (qw( basketno quantity biblionumber budget_id )) {
68 croak
"Cannot insert order: Mandatory parameter $key is missing"
72 $self->quantityreceived(0) unless $self->quantityreceived;
73 $self->entrydate(dt_from_string
) unless $self->entrydate;
75 $self->ordernumber(undef) unless $self->ordernumber;
76 $self = $self->SUPER::store
( $self );
78 unless ( $self->parent_ordernumber ) {
79 $self->set( { parent_ordernumber
=> $self->ordernumber } );
80 $self = $self->SUPER::store
( $self );
88 $order->add_item( $itemnumber );
90 Link an item to this order.
95 my ( $self, $itemnumber ) = @_;
97 my $schema = Koha
::Database
->new->schema;
98 my $rs = $schema->resultset('AqordersItem');
99 $rs->create({ ordernumber
=> $self->ordernumber, itemnumber
=> $itemnumber });
104 my $basket = Koha::Acquisition::Orders->find( $id )->basket;
106 Returns the basket associated to the order.
112 my $basket_rs = $self->_result->basketno;
113 return Koha
::Acquisition
::Basket
->_new_from_dbic( $basket_rs );
116 =head2 Internal methods