X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/ae47b240b0a1d1d793240c660feeb3f0532122ab..826f6eb2b3e:/SL/Controller/CsvImport/Order.pm?ds=sidebyside diff --git a/SL/Controller/CsvImport/Order.pm b/SL/Controller/CsvImport/Order.pm index 2f6b4e7a3..e0935c0e6 100644 --- a/SL/Controller/CsvImport/Order.pm +++ b/SL/Controller/CsvImport/Order.pm @@ -34,6 +34,16 @@ sub init_class { $self->class(['SL::DB::Order', 'SL::DB::OrderItem']); } +sub set_profile_defaults { + my ($self) = @_; + + $self->controller->profile->_set_defaults( + order_column => $::locale->text('Order'), + item_column => $::locale->text('OrderItem'), + max_amount_diff => 0.02, + ); +}; + sub init_settings { my ($self) = @_; @@ -426,7 +436,7 @@ sub check_part { my $object = $entry->{object}; - # Check wether or non part ID is valid. + # Check whether or not part ID is valid. if ($object->parts_id && !$self->parts_by->{id}->{ $object->parts_id }) { push @{ $entry->{errors} }, $::locale->text('Error: Invalid part'); return 0; @@ -443,6 +453,17 @@ sub check_part { $object->parts_id($part->id); } + # Map description to ID if given. + if (!$object->parts_id && $entry->{raw_data}->{description}) { + my $part = $self->parts_by->{description}->{ $entry->{raw_data}->{description} }; + if (!$part) { + push @{ $entry->{errors} }, $::locale->text('Error: Invalid part'); + return 0; + } + + $object->parts_id($part->id); + } + if ($object->parts_id) { $entry->{info_data}->{partnumber} = $self->parts_by->{id}->{ $object->parts_id }->partnumber; } else { @@ -461,7 +482,7 @@ sub check_contact { my $cp_cv_id = $object->customer_id || $object->vendor_id; return 0 unless $cp_cv_id; - # Check wether or not contact ID is valid. + # Check whether or not contact ID is valid. if ($object->cp_id && !$self->contacts_by->{'cp_cv_id+cp_id'}->{ $cp_cv_id . '+' . $object->cp_id }) { push @{ $entry->{errors} }, $::locale->text('Error: Invalid contact'); return 0; @@ -490,7 +511,7 @@ sub check_department { my $object = $entry->{object}; - # Check wether or not department ID is valid. + # Check whether or not department ID is valid. if ($object->department_id && !$self->departments_by->{id}->{ $object->department_id }) { push @{ $entry->{errors} }, $::locale->text('Error: Invalid department'); return 0; @@ -519,7 +540,7 @@ sub check_project { my $object = $entry->{object}; - # Check wether or not projetc ID is valid. + # Check whether or not projetc ID is valid. if ($object->$id_column && !$self->projects_by->{id}->{ $object->$id_column }) { push @{ $entry->{errors} }, $::locale->text('Error: Invalid project'); return 0; @@ -558,7 +579,7 @@ sub check_ct_shipto { my $trans_id = $object->customer_id || $object->vendor_id; return 0 unless $trans_id; - # Check wether or not shipto ID is valid. + # Check whether or not shipto ID is valid. if ($object->shipto_id && !$self->ct_shiptos_by->{'trans_id+shipto_id'}->{ $trans_id . '+' . $object->shipto_id }) { push @{ $entry->{errors} }, $::locale->text('Error: Invalid shipto'); return 0; @@ -572,7 +593,7 @@ sub check_price_factor { my $object = $entry->{object}; - # Check wether or not price_factor ID is valid. + # Check whether 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; @@ -597,7 +618,7 @@ sub check_pricegroup { my $object = $entry->{object}; - # Check wether or not pricegroup ID is valid. + # Check whether 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; @@ -624,10 +645,10 @@ sub add_items_to_order { my $order_entry; my @orderitems; foreach my $entry (@{ $self->controller->data }) { - # search first order + # search first/next order if ($entry->{raw_data}->{datatype} eq $self->_order_column) { - # new order entry: add collected orderitems to the previous one + # next order entry: add collected orderitems to the previous one if (defined $order_entry) { $order_entry->{object}->orderitems(@orderitems); @orderitems = (); @@ -654,7 +675,7 @@ sub handle_prices_and_taxes() { foreach my $entry (@{ $self->controller->data }) { next if @{ $entry->{errors} }; - if ($entry->{raw_data}->{datatype} eq $self->_order_column) { + if ($entry->{raw_data}->{datatype} eq $self->_order_column && $entry->{object}->orderitems) { $entry->{object}->calculate_prices_and_taxes;