X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FCsvImport%2FOrder.pm;h=e0935c0e6ca521e19d550116549f0b1ba33213c4;hb=da300db2eb33f9aa35bef69784b9d9d3ee0c92c8;hp=907d900a2eb70a8bf7ff63dd384027ab1bf6c608;hpb=c049c916806a208b33a2f1e8b2292946ed1d6202;p=kivitendo-erp.git diff --git a/SL/Controller/CsvImport/Order.pm b/SL/Controller/CsvImport/Order.pm index 907d900a2..e0935c0e6 100644 --- a/SL/Controller/CsvImport/Order.pm +++ b/SL/Controller/CsvImport/Order.pm @@ -6,6 +6,7 @@ use strict; use List::MoreUtils qw(any); use SL::Helper::Csv; +use SL::Controller::CsvImport::Helper::Consistency; use SL::DB::Order; use SL::DB::OrderItem; use SL::DB::Part; @@ -24,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 currencies_by) ], + 'scalar --get_set_init' => [ qw(settings languages_by parts_by contacts_by departments_by projects_by ct_shiptos_by price_factors_by pricegroups_by) ], ); @@ -33,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) = @_; @@ -101,6 +112,8 @@ sub setup_displayable_columns { { name => 'currency_id', description => $::locale->text('Currency (database ID)') }, { name => 'cusordnumber', description => $::locale->text('Customer Order Number') }, { name => 'delivered', description => $::locale->text('Delivered') }, + { name => 'delivery_term_id', description => $::locale->text('Delivery terms (database ID)') }, + { name => 'delivery_term', description => $::locale->text('Delivery terms (name)') }, { name => 'employee_id', description => $::locale->text('Employee (database ID)') }, { name => 'intnotes', description => $::locale->text('Internal Notes') }, { name => 'marge_percent', description => $::locale->text('Margepercent') }, @@ -153,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)') }, @@ -223,13 +237,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) = @_; @@ -244,12 +251,6 @@ sub init_pricegroups_by { return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_pricegroups } } ) } qw(id pricegroup) }; } -sub init_currencies_by { - my ($self) = @_; - - return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_currencies } } ) } qw(id name) }; -} - sub check_objects { my ($self) = @_; @@ -275,7 +276,7 @@ sub check_objects { { header => $::locale->text('Customer/Vendor'), method => 'vc_name' }); # Todo: access via ->[0] ok? Better: search first order column and use this $self->add_columns($self->_order_column, - map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(payment language department globalproject taxzone cp currency)); + map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(payment delivery_term language department globalproject taxzone cp currency)); $self->add_columns($self->_order_column, 'globalproject_id') if exists $self->controller->data->[0]->{raw_data}->{globalprojectnumber}; $self->add_columns($self->_order_column, 'cp_id') if exists $self->controller->data->[0]->{raw_data}->{contact}; @@ -326,11 +327,12 @@ sub handle_order { $self->check_contact($entry); $self->check_language($entry); $self->check_payment($entry); + $self->check_delivery_term($entry); $self->check_department($entry); $self->check_project($entry, global => 1); $self->check_ct_shipto($entry); $self->check_taxzone($entry); - $self->check_currency($entry); + $self->check_currency($entry, take_default => 0); if ($vc_obj) { # copy from customer if not given @@ -348,7 +350,8 @@ 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; + my $vc_obj; + $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 @@ -416,6 +419,8 @@ sub handle_item { $object->description($part_obj->description) unless $object->description; $object->longdescription($part_obj->notes) unless $object->longdescription; $object->unit($part_obj->unit) unless $object->unit; + $object->sellprice($part_obj->sellprice) unless defined $object->sellprice; + $object->lastcost($part_obj->lastcost) unless defined $object->lastcost; # set to 0 if not given $object->discount(0) unless $object->discount; @@ -431,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; @@ -448,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 { @@ -466,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; @@ -495,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; @@ -524,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; @@ -563,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,37 +588,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 +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; @@ -647,31 +638,6 @@ sub check_pricegroup { 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) = @_; @@ -679,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 = (); @@ -709,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;