b707ae8f8d0e90805c6590afdf02d0a6d07d994e
[kivitendo-erp.git] / SL / Controller / CsvImport / Contact.pm
1 package SL::Controller::CsvImport::Contact;
2
3 use strict;
4
5 use SL::Helper::Csv;
6 use SL::DB::CustomVariable;
7 use SL::DB::CustomVariableConfig;
8
9 use parent qw(SL::Controller::CsvImport::Base);
10
11 use Rose::Object::MakeMethods::Generic
12 (
13  scalar => [ qw(table) ],
14 );
15
16 sub init_class {
17   my ($self) = @_;
18   $self->class('SL::DB::Contact');
19 }
20
21 sub init_all_cvar_configs {
22   my ($self) = @_;
23
24   return SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'Contacts' ]);
25 }
26
27 sub check_objects {
28   my ($self) = @_;
29
30   foreach my $entry (@{ $self->controller->data }) {
31     $self->check_name($entry);
32     $self->check_vc($entry, 'cp_cv_id');
33     $self->check_gender($entry);
34     $self->handle_cvars($entry);
35   }
36
37   $self->add_info_columns({ header => $::locale->text('Customer/Vendor'), method => 'vc_name' });
38   $self->add_cvar_raw_data_columns;
39 }
40
41 sub check_name {
42   my ($self, $entry) = @_;
43
44   my $name     =  $entry->{object}->cp_name;
45   $name        =~ s/^\s+//;
46   $name        =~ s/\s+$//;
47
48   push @{ $entry->{errors} }, $::locale->text('Error: Name missing') unless $name;
49 }
50
51 sub check_gender {
52   my ($self, $entry) = @_;
53
54   push @{ $entry->{errors} }, $::locale->text('Error: Gender (cp_gender) missing or invalid') if ($entry->{object}->cp_gender ne 'm') && ($entry->{object}->cp_gender ne 'f');
55 }
56
57 sub get_duplicate_check_fields {
58   return {
59     cp_name => {
60       label     => $::locale->text('Name'),
61       default   => 1,
62       maker     => sub {
63         my $o = shift;
64         return join(
65                  '--',
66                  $o->cp_cv_id,
67                  map(
68                    { s/[\s,\.\-]//g; $_ }
69                    $o->cp_name
70                  )
71         );
72       }
73     },
74   };
75 }
76
77 sub field_lengths {
78   return ( cp_title     => 75,
79            cp_givenname => 75,
80            cp_name      => 75,
81            cp_phone1    => 75,
82            cp_phone2    => 75,
83            cp_gender    =>  1,
84          );
85 }
86
87 sub setup_displayable_columns {
88   my ($self) = @_;
89
90   $self->SUPER::setup_displayable_columns;
91   $self->add_cvar_columns_to_displayable_columns;
92
93   $self->add_displayable_columns({ name => 'cp_abteilung',   description => $::locale->text('Department')                    },
94                                  { name => 'cp_birthday',    description => $::locale->text('Birthday')                      },
95                                  { name => 'cp_cv_id',       description => $::locale->text('Customer/Vendor (database ID)') },
96                                  { name => 'cp_email',       description => $::locale->text('E-mail')                        },
97                                  { name => 'cp_fax',         description => $::locale->text('Fax')                           },
98                                  { name => 'cp_gender',      description => $::locale->text('Gender')                        },
99                                  { name => 'cp_givenname',   description => $::locale->text('Given Name')                    },
100                                  { name => 'cp_mobile1',     description => $::locale->text('Mobile1')                       },
101                                  { name => 'cp_mobile2',     description => $::locale->text('Mobile2')                       },
102                                  { name => 'cp_name',        description => $::locale->text('Name')                          },
103                                  { name => 'cp_phone1',      description => $::locale->text('Phone1')                        },
104                                  { name => 'cp_phone2',      description => $::locale->text('Phone2')                        },
105                                  { name => 'cp_privatemail', description => $::locale->text('Private E-mail')                },
106                                  { name => 'cp_privatphone', description => $::locale->text('Private Phone')                 },
107                                  { name => 'cp_project',     description => $::locale->text('Project')                       },
108                                  { name => 'cp_satfax',      description => $::locale->text('Sat. Fax')                      },
109                                  { name => 'cp_satphone',    description => $::locale->text('Sat. Phone')                    },
110                                  { name => 'cp_title',       description => $::locale->text('Title')                         },
111
112                                  { name => 'customer',       description => $::locale->text('Customer (name)')               },
113                                  { name => 'customernumber', description => $::locale->text('Customer Number')               },
114                                  { name => 'vendor',         description => $::locale->text('Vendor (name)')                 },
115                                  { name => 'vendornumber',   description => $::locale->text('Vendor Number')                 },
116                                 );
117 }
118
119 1;