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;
23 use Koha::Acquisition::Funds;
24 use Koha::Acquisition::Invoices;
25 use Koha::Subscriptions;
27 use Koha::DateUtils qw( dt_from_string output_pref );
29 use base qw(Koha::Object);
33 Koha::Acquisition::Order Object class
41 Overloaded I<new> method for backwards compatibility.
46 my ( $self, $params ) = @_;
48 my $schema = Koha::Database->new->schema;
49 my @columns = $schema->source('Aqorder')->columns;
52 { map { exists $params->{$_} ? ( $_ => $params->{$_} ) : () } @columns };
53 return $self->SUPER::new($values);
58 Overloaded I<store> method for backwards compatibility.
65 my $schema = Koha::Database->new->schema;
66 # Override quantity for standing orders
67 $self->quantity(1) if ( $self->basketno && $schema->resultset('Aqbasket')->find( $self->basketno )->is_standing );
69 # if these parameters are missing, we can't continue
70 for my $key (qw( basketno quantity biblionumber budget_id )) {
71 croak "Cannot insert order: Mandatory parameter $key is missing"
75 if (not defined $self->{created_by}) {
76 my $userenv = C4::Context->userenv;
78 $self->created_by($userenv->{number});
82 $self->quantityreceived(0) unless $self->quantityreceived;
83 $self->entrydate(dt_from_string) unless $self->entrydate;
85 $self->ordernumber(undef) unless $self->ordernumber;
86 $self = $self->SUPER::store( $self );
88 unless ( $self->parent_ordernumber ) {
89 $self->set( { parent_ordernumber => $self->ordernumber } );
90 $self = $self->SUPER::store( $self );
98 $order->add_item( $itemnumber );
100 Link an item to this order.
105 my ( $self, $itemnumber ) = @_;
107 my $schema = Koha::Database->new->schema;
108 my $rs = $schema->resultset('AqordersItem');
109 $rs->create({ ordernumber => $self->ordernumber, itemnumber => $itemnumber });
114 my $basket = Koha::Acquisition::Orders->find( $id )->basket;
116 Returns the basket associated to the order.
122 my $basket_rs = $self->_result->basketno;
123 return Koha::Acquisition::Basket->_new_from_dbic( $basket_rs );
128 my $fund = $order->fund
130 Returns the fund (aqbudgets) associated to the order.
136 my $fund_rs = $self->_result->budget;
137 return Koha::Acquisition::Fund->_new_from_dbic( $fund_rs );
142 my $invoice = $order->invoice
144 Returns the invoice associated to the order.
150 my $invoice_rs = $self->_result->invoiceid;
151 return unless $invoice_rs;
152 return Koha::Acquisition::Invoice->_new_from_dbic( $invoice_rs );
157 my $subscription = $order->subscription
159 Returns the subscription associated to the order.
165 my $subscription_rs = $self->_result->subscriptionid;
166 return unless $subscription_rs;
167 return Koha::Subscription->_new_from_dbic( $subscription_rs );
170 =head2 Internal methods