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.
23 use Koha::DateUtils qw( dt_from_string output_pref );
25 use base qw(Koha::Object);
29 Koha::Acquisition::Order Object class
38 my ( $self, $params ) = @_;
40 my $schema = Koha::Database->new->schema;
41 my @columns = $schema->source('Aqorder')->columns;
44 { map { exists $params->{$_} ? ( $_ => $params->{$_} ) : () } @columns };
45 return $self->SUPER::new($values);
51 my $schema = Koha::Database->new->schema;
52 # Override quantity for standing orders
53 $self->quantity(1) if ( $self->basketno && $schema->resultset('Aqbasket')->find( $self->basketno )->is_standing );
55 # if these parameters are missing, we can't continue
56 for my $key (qw( basketno quantity biblionumber budget_id )) {
57 croak "Cannot insert order: Mandatory parameter $key is missing"
61 $self->quantityreceived(0) unless $self->quantityreceived;
62 $self->entrydate(output_pref( { dt => dt_from_string, dateformat => 'iso' } )) unless $self->entrydate;
64 $self->ordernumber(undef) unless $self->ordernumber;
65 $self = $self->SUPER::store( $self );
67 unless ( $self->parent_ordernumber ) {
68 $self->set( { parent_ordernumber => $self->ordernumber } );
69 $self = $self->SUPER::store( $self );
77 $order->add_item( $itemnumber );
79 Link an item to this order.
84 my ( $self, $itemnumber ) = @_;
86 my $schema = Koha::Database->new->schema;
87 my $rs = $schema->resultset('AqordersItem');
88 $rs->create({ ordernumber => $self->ordernumber, itemnumber => $itemnumber });