1 package Koha::Acquisition::Order;
6 use Koha::DateUtils qw( dt_from_string output_pref );
10 use base qw( Class::Accessor );
12 # TODO fetch order from itemnumber (GetOrderFromItemnnumber)
13 # TODO Move code from GetOrder
15 my ( $class, $params ) = @_;
16 my $ordernumber = $params->{ordernumber};
17 return unless $ordernumber;
18 my $schema = Koha::Database->new->schema;
21 $schema->resultset('Aqorder')->find( { ordernumber => $ordernumber },
22 { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } );
23 return $class->new( $order );
29 # if these parameters are missing, we can't continue
30 for my $key (qw( basketno quantity biblionumber budget_id )) {
31 croak "Cannot insert order: Mandatory parameter $key is missing"
35 $self->{quantityreceived} ||= 0;
36 $self->{entrydate} ||=
37 output_pref( { dt => dt_from_string, dateformat => 'iso' } );
39 my $schema = Koha::Database->new->schema;
40 my @columns = $schema->source('Aqorder')->columns;
42 $self->{ordernumber} ||= undef;
44 my $rs = $schema->resultset('Aqorder')->create(
47 exists $self->{$_} ? ( $_ => $self->{$_} ) : ()
51 $self->{ordernumber} = $rs->id;
53 unless ( $self->{parent_ordernumber} ) {
54 $self->{parent_ordernumber} = $self->{ordernumber};
55 $rs->update( { parent_ordernumber => $self->{parent_ordernumber} } );
62 my ( $self, $itemnumber ) = @_;
63 my $schema = Koha::Database->new->schema;
64 my $rs = $schema->resultset('AqordersItem');
65 $rs->create({ ordernumber => $self->{ordernumber}, itemnumber => $itemnumber });
68 # TODO Move code from ModItemOrder
70 die "not implemented yet";
74 die "not implemented yet";
77 # TODO Move code from ModOrder
79 die "not implemented yet";
82 # TODO Move code from DelOrder
84 die "not implemented yet";
87 # TODO Move code from TransferOrder
89 die "not implemented yet";