+sub check_price_factor {
+ my ($self, $entry) = @_;
+
+ my $object = $entry->{object};
+
+ # Check wether or not price_factor ID is valid.
+ if ($object->price_factor_id && !$self->price_factors_by->{id}->{ $object->price_factor_id }) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid price factor');
+ return 0;
+ }
+
+ # Map description to ID if given.
+ if (!$object->price_factor_id && $entry->{raw_data}->{price_factor}) {
+ my $price_factor = $self->price_factors_by->{description}->{ $entry->{raw_data}->{price_factor} };
+ if (!$price_factor) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid price factor');
+ return 0;
+ }
+
+ $object->price_factor_id($price_factor->id);
+ }
+
+ return 1;
+}
+
+sub check_pricegroup {
+ my ($self, $entry) = @_;
+
+ my $object = $entry->{object};
+
+ # Check wether or not pricegroup ID is valid.
+ if ($object->pricegroup_id && !$self->pricegroups_by->{id}->{ $object->pricegroup_id }) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid price group');
+ return 0;
+ }
+
+ # Map pricegroup to ID if given.
+ if (!$object->pricegroup_id && $entry->{raw_data}->{pricegroup}) {
+ my $pricegroup = $self->pricegroups_by->{pricegroup}->{ $entry->{raw_data}->{pricegroup} };
+ if (!$pricegroup) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid price group');
+ return 0;
+ }
+
+ $object->pricegroup_id($pricegroup->id);
+ }
+
+ return 1;
+}
+
+sub check_currency {
+ my ($self, $entry) = @_;
+
+ my $object = $entry->{object};
+
+ # Check whether or not currency ID is valid.
+ if ($object->currency_id && !$self->currencies_by->{id}->{ $object->currency_id }) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid currency');
+ return 0;
+ }
+
+ # Map name to ID if given.
+ if (!$object->currency_id && $entry->{raw_data}->{currency}) {
+ my $currency = $self->currencies_by->{name}->{ $entry->{raw_data}->{currency} };
+ if (!$currency) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid currency');
+ return 0;
+ }
+
+ $object->currency_id($currency->id);
+ }
+
+ return 1;
+}
+
+sub add_items_to_order {
+ my ($self) = @_;
+
+ # add orderitems to order
+ my $order_entry;
+ my @orderitems;
+ foreach my $entry (@{ $self->controller->data }) {
+ # search first order
+ if ($entry->{raw_data}->{datatype} eq $self->_order_column) {
+
+ # new order entry: add collected orderitems to the previous one
+ if (defined $order_entry) {
+ $order_entry->{object}->orderitems(@orderitems);
+ @orderitems = ();
+ }
+
+ $order_entry = $entry;
+
+ } elsif ( defined $order_entry && $entry->{raw_data}->{datatype} eq $self->_item_column ) {
+ # collect orderitems to add to order (if they have no errors)
+ # ( add_orderitems does not work here if we want to call
+ # calculate_prices_and_taxes afterwards ...
+ # so collect orderitems and add them at once )
+ push @orderitems, $entry->{object} if (scalar @{ $entry->{errors} } == 0);
+ }
+ }
+ # add last collected orderitems to last order
+ $order_entry->{object}->orderitems(@orderitems) if $order_entry;
+}
+
+sub handle_prices_and_taxes() {
+ my ($self) = @_;