X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FCsvImport%2FOrder.pm;h=73240e2e3a4f7447a840a962a9245dbce12b3123;hb=ea507623073ea48951f1c1ba38f2a0841b14d47a;hp=fe7301936a43869ad18a745520bca6a30d120527;hpb=e0e3eee4eb59b7d6fbe17fe9ad12167b6b8a388b;p=kivitendo-erp.git diff --git a/SL/Controller/CsvImport/Order.pm b/SL/Controller/CsvImport/Order.pm index fe7301936..73240e2e3 100644 --- a/SL/Controller/CsvImport/Order.pm +++ b/SL/Controller/CsvImport/Order.pm @@ -25,7 +25,7 @@ use parent qw(SL::Controller::CsvImport::BaseMulti); use Rose::Object::MakeMethods::Generic ( - 'scalar --get_set_init' => [ qw(settings languages_by parts_by contacts_by departments_by projects_by ct_shiptos_by taxzones_by price_factors_by pricegroups_by) ], + 'scalar --get_set_init' => [ qw(settings languages_by parts_by contacts_by ct_shiptos_by price_factors_by pricegroups_by) ], ); @@ -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) = @_; @@ -156,6 +166,7 @@ sub setup_displayable_columns { { name => 'ordnumber', description => $::locale->text('Order Number') }, { name => 'parts_id', description => $::locale->text('Part (database ID)') }, { name => 'partnumber', description => $::locale->text('Part Number') }, + { name => 'position', description => $::locale->text('position') }, { name => 'project_id', description => $::locale->text('Project (database ID)') }, { name => 'projectnumber', description => $::locale->text('Project (number)') }, { name => 'project', description => $::locale->text('Project (description)') }, @@ -200,20 +211,6 @@ sub init_contacts_by { return $cby; } -sub init_departments_by { - my ($self) = @_; - - my $all_departments = SL::DB::Manager::Department->get_all; - return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_departments } } ) } qw(id description) }; -} - -sub init_projects_by { - my ($self) = @_; - - my $all_projects = SL::DB::Manager::Project->get_all; - return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_projects } } ) } qw(id projectnumber description) }; -} - sub init_ct_shiptos_by { my ($self) = @_; @@ -226,13 +223,6 @@ sub init_ct_shiptos_by { return $sby; } -sub init_taxzones_by { - my ($self) = @_; - - my $all_taxzones = SL::DB::Manager::TaxZone->get_all; - return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_taxzones } } ) } qw(id description) }; -} - sub init_price_factors_by { my ($self) = @_; @@ -341,36 +331,6 @@ sub handle_order { $self->handle_employee($entry); } -# ToDo: salesman by name -sub handle_salesman { - my ($self, $entry) = @_; - - my $object = $entry->{object}; - my $vc_obj = SL::DB::Customer->new(id => $object->customer_id)->load if $object->customer_id; - $vc_obj = SL::DB::Vendor->new(id => $object->vendor_id)->load if (!$vc_obj && $object->vendor_id); - - # salesman from customer/vendor or login if not given - if (!$object->salesman) { - if ($vc_obj && $vc_obj->salesman_id) { - $object->salesman(SL::DB::Manager::Employee->find_by(id => $vc_obj->salesman_id)); - } else { - $object->salesman(SL::DB::Manager::Employee->find_by(login => $::myconfig{login})); - } - } -} - -# ToDo: employee by name -sub handle_employee { - my ($self, $entry) = @_; - - my $object = $entry->{object}; - - # employee from login if not given - if (!$object->employee_id) { - $object->employee_id(SL::DB::Manager::Employee->find_by(login => $::myconfig{login})->id); - } -} - sub check_language { my ($self, $entry) = @_; @@ -431,7 +391,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; @@ -448,6 +408,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 { @@ -466,7 +437,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,71 +461,6 @@ sub check_contact { return 1; } -sub check_department { - my ($self, $entry) = @_; - - my $object = $entry->{object}; - - # Check wether 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; - } - - # Map description to ID if given. - if (!$object->department_id && $entry->{raw_data}->{department}) { - my $dep = $self->departments_by->{description}->{ $entry->{raw_data}->{department} }; - if (!$dep) { - push @{ $entry->{errors} }, $::locale->text('Error: Invalid department'); - return 0; - } - - $object->department_id($dep->id); - } - - return 1; -} - -sub check_project { - my ($self, $entry, %params) = @_; - - my $id_column = ($params{global} ? 'global' : '') . 'project_id'; - my $number_column = ($params{global} ? 'global' : '') . 'projectnumber'; - my $description_column = ($params{global} ? 'global' : '') . 'project'; - - my $object = $entry->{object}; - - # Check wether 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; - } - - # Map number to ID if given. - if (!$object->$id_column && $entry->{raw_data}->{$number_column}) { - my $proj = $self->projects_by->{projectnumber}->{ $entry->{raw_data}->{$number_column} }; - if (!$proj) { - push @{ $entry->{errors} }, $::locale->text('Error: Invalid project'); - return 0; - } - - $object->$id_column($proj->id); - } - - # Map description to ID if given. - if (!$object->$id_column && $entry->{raw_data}->{$description_column}) { - my $proj = $self->projects_by->{description}->{ $entry->{raw_data}->{$description_column} }; - if (!$proj) { - push @{ $entry->{errors} }, $::locale->text('Error: Invalid project'); - return 0; - } - - $object->$id_column($proj->id); - } - - return 1; -} - sub check_ct_shipto { my ($self, $entry) = @_; @@ -563,7 +469,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,37 +478,12 @@ sub check_ct_shipto { return 1; } -sub check_taxzone { - my ($self, $entry) = @_; - - my $object = $entry->{object}; - - # Check wether or not taxzone ID is valid. - if ($object->taxzone_id && !$self->taxzones_by->{id}->{ $object->taxzone_id }) { - push @{ $entry->{errors} }, $::locale->text('Error: Invalid tax zone'); - return 0; - } - - # Map description to ID if given. - if (!$object->taxzone_id && $entry->{raw_data}->{taxzone}) { - my $taxzone = $self->taxzones_by->{description}->{ $entry->{raw_data}->{taxzone} }; - if (!$taxzone) { - push @{ $entry->{errors} }, $::locale->text('Error: Invalid tax zone'); - return 0; - } - - $object->taxzone_id($taxzone->id); - } - - return 1; -} - sub check_price_factor { my ($self, $entry) = @_; 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; @@ -627,7 +508,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; @@ -654,10 +535,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 = (); @@ -684,7 +565,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;