From: Bernd Bleßmann Date: Fri, 15 Mar 2013 12:32:20 +0000 (+0100) Subject: Abteilungen und Projekte behandeln. X-Git-Tag: release-3.1.0beta1~22^2~151 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=d9cf6b762b186a447ea5abac79c50893341f42ca;p=kivitendo-erp.git Abteilungen und Projekte behandeln. --- diff --git a/SL/Controller/CsvImport/Order.pm b/SL/Controller/CsvImport/Order.pm index 689a6bb77..92e30e2a8 100644 --- a/SL/Controller/CsvImport/Order.pm +++ b/SL/Controller/CsvImport/Order.pm @@ -11,6 +11,7 @@ use SL::DB::OrderItem; use SL::DB::Part; use SL::DB::PaymentTerm; use SL::DB::Contact; +use SL::DB::Department; use SL::TransNumber; use parent qw(SL::Controller::CsvImport::BaseMulti); @@ -18,7 +19,7 @@ use parent qw(SL::Controller::CsvImport::BaseMulti); use Rose::Object::MakeMethods::Generic ( - 'scalar --get_set_init' => [ qw(settings languages_by all_parts parts_by all_contacts contacts_by) ], + 'scalar --get_set_init' => [ qw(settings languages_by all_parts parts_by all_contacts contacts_by all_departments departments_by all_projects projects_by) ], ); @@ -77,8 +78,14 @@ sub setup_displayable_columns { { name => 'payment_id', description => $::locale->text('Payment terms (database ID)') }, { name => 'payment', description => $::locale->text('Payment terms (name)') }, { name => 'taxzone_id', description => $::locale->text('Steuersatz') }, - { name => 'contact_id', description => $::locale->text('Contact Person (database ID)') }, + { name => 'cp_id', description => $::locale->text('Contact Person (database ID)') }, { name => 'contact', description => $::locale->text('Contact Person (name)') }, + { name => 'department_id', description => $::locale->text('Department (database ID)') }, + { name => 'department', description => $::locale->text('Department (description)') }, + { name => 'globalproject_id', description => $::locale->text('Document Project (database ID)') }, + { name => 'globalprojectnumber', description => $::locale->text('Document Project (number)') }, + { name => 'globalproject', description => $::locale->text('Document Project (description)') }, + ); $self->add_displayable_columns('OrderItem', @@ -123,6 +130,30 @@ sub init_contacts_by { return $cby; } +sub init_all_departments { + my ($self) = @_; + + return SL::DB::Manager::Department->get_all; +} + +sub init_departments_by { + my ($self) = @_; + + return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_departments } } ) } qw(id description) }; +} + +sub init_all_projects { + my ($self) = @_; + + return SL::DB::Manager::Project->get_all; +} + +sub init_projects_by { + my ($self) = @_; + + return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_projects } } ) } qw(id projectnumber description) }; +} + sub check_objects { my ($self) = @_; @@ -149,6 +180,8 @@ sub check_objects { $self->check_contact($entry); $self->check_language($entry); $self->check_payment($entry); + $self->check_department($entry); + $self->check_project($entry, global => 1); if ($vc_obj) { # copy from customer if not given @@ -178,8 +211,8 @@ sub check_objects { $self->add_info_columns($self->settings->{'order_column'}, { header => $::locale->text('Customer/Vendor'), method => 'vc_name' }); $self->add_columns($self->settings->{'order_column'}, - map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(business payment)); - + map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(payment language department globalproject)); + $self->add_columns($self->settings->{'order_column'}, 'globalproject_id') if exists $self->controller->data->[0]->{raw_data}->{globalprojectnumber}; foreach my $entry (@{ $self->controller->data }) { if ($entry->{raw_data}->{datatype} eq $self->settings->{'item_column'} && $entry->{object}->can('part')) { @@ -365,13 +398,13 @@ sub check_contact { my $object = $entry->{object}; - # Check wether or non contact ID is valid. + # Check wether or not contact ID is valid. if ($object->cp_id && !$self->contacts_by->{cp_id}->{ $object->cp_id }) { push @{ $entry->{errors} }, $::locale->text('Error: Invalid contact'); return 0; } - # Map number to ID if given. + # Map name to ID if given. if (!$object->cp_id && $entry->{raw_data}->{contact}) { my $cp = $self->contacts_by->{cp_name}->{ $entry->{raw_data}->{contact} }; if (!$cp) { @@ -395,6 +428,73 @@ 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 save_objects { my ($self, %params) = @_;