vendors => SL::DB::Manager::Vendor->get_all };
}
+sub force_allow_columns {
+ return ();
+}
+
sub init_vc_by {
my ($self) = @_;
eval "require " . $self->class;
my %unwanted = map { ( $_ => 1 ) } (qw(itime mtime), map { $_->name } @{ $self->class->meta->primary_key_columns });
+ delete $unwanted{$_} for ($self->force_allow_columns);
+
my %profile;
for my $col ($self->class->meta->columns) {
next if $unwanted{$col};
return SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'Contacts' ]);
}
+sub force_allow_columns {
+ return qw(cp_id);
+}
+
sub check_objects {
my ($self) = @_;
$self->controller->track_progress(phase => 'building data', progress => 0);
- my $i;
- my $num_data = scalar @{ $self->controller->data };
+ my $i = 0;
+ my $num_data = scalar @{ $self->controller->data };
+ my $update_policy = $self->controller->profile->get('update_policy') || 'update_existing';
+ my %contacts_by_id = map { ( $_->cp_id => $_ ) } @{ $self->existing_objects };
+ my $methods = $self->controller->headers->{methods};
+ my %used_methods = map { ( $_ => 1 ) } @{ $methods };
+
foreach my $entry (@{ $self->controller->data }) {
$self->controller->track_progress(progress => $i/$num_data * 100) if $i % 100 == 0;
+ my $object = $entry->{object};
+ if ($object->cp_id) {
+ my $existing_contact = $contacts_by_id{ $object->cp_id };
+ if (!$existing_contact) {
+ $contacts_by_id{ $object->cp_id } = $object;
+
+ } elsif ($update_policy eq 'skip') {
+ push(@{ $entry->{errors} }, $::locale->text('Skipping due to existing entry in database'));
+ next;
+
+ } elsif ($update_policy eq 'update_existing') {
+ # Update existing customer/vendor records.
+ $entry->{object_to_save} = $existing_contact;
+
+ $object->cp_cv_id($existing_contact->cp_cv_id);
+
+ foreach (qw(cp_name cp_gender)) {
+ $object->$_($existing_contact->$_) if !$object->$_;
+ }
+
+ $existing_contact->$_( $entry->{object}->$_ ) for @{ $methods };
+
+ push @{ $entry->{information} }, $::locale->text('Updating existing entry in database');
+
+ } else {
+ $object->cp_id(undef);
+ }
+ }
+
$self->check_name($entry);
$self->check_vc($entry, 'cp_cv_id');
$self->check_gender($entry);
$self->handle_cvars($entry);
+
+ my @cleaned_fields = $self->clean_fields(qr{[\r\n]}, $object, qw(cp_title cp_givenname cp_name cp_email cp_phone1 cp_phone2 cp_fax cp_mobile1 cp_mobile2 cp_satphone cp_satfax
+ cp_privatphone cp_privatemail cp_abteilung cp_street cp_zipcode cp_city cp_position));
+
+ push @{ $entry->{information} }, $::locale->text('Illegal characters have been removed from the following fields: #1', join(', ', @cleaned_fields))
+ if @cleaned_fields;
} continue {
$i++;
}
{ name => 'cp_fax', description => $::locale->text('Fax') },
{ name => 'cp_gender', description => $::locale->text('Gender') },
{ name => 'cp_givenname', description => $::locale->text('Given Name') },
+ { name => 'cp_id', description => $::locale->text('Database ID') },
{ name => 'cp_mobile1', description => $::locale->text('Mobile1') },
{ name => 'cp_mobile2', description => $::locale->text('Mobile2') },
{ name => 'cp_name', description => $::locale->text('Name') },
'Execution type' => 'Ausführungsart',
'Existing Buchungsgruppen' => 'Existierende Buchungsgruppen',
'Existing Datasets' => 'Existierende Datenbanken',
+ 'Existing contacts (with column \'cp_id\')' => 'Existierende Ansprechpersonen (mit Spalte \'cp_id\')',
'Existing customers/vendors with same customer/vendor number' => 'Existierende Kunden/Lieferanten mit derselben Kunden-/Lieferantennummer',
'Existing file on server' => 'Auf dem Server existierende Datei',
'Existing pending follow-ups for this item' => 'Noch nicht erledigte Wiedervorlagen für dieses Dokument',
'Individual Items' => 'Einzelteile',
'Information' => 'Information',
'Insert with new customer/vendor number' => 'Mit neuer Kunden-/Lieferantennummer anlegen',
+ 'Insert with new database ID' => 'Neu anlegen mit neuer Datenbank-ID',
'Insert with new part number' => 'Mit neuer Artikelnummer einfügen',
'Interest' => 'Zinsen',
'Interest Rate' => 'Zinssatz',
'You can either create a new database or chose an existing database.' => 'Sie können entweder eine neue Datenbank erstellen oder eine existierende auswählen.',
'You can find information on the migration in the upgrade chapter of the documentation.' => 'Informationen über die Migration sind in der Upgrade Kapitel in der Dokumentation zu finden.',
'You can only delete datasets that are not in use.' => 'Sie können nur Datenbanken löschen, die momentan nicht in Benutzung sind.',
+ 'You can update existing contacts by providing the \'cp_id\' column with their database IDs. Otherwise: ' => 'Sie können existierende Einträge aktualisieren, indem Sie eine Spalte \'cp_id\' mit der Datenbank-ID des Eintrags mitgeben. Andernfalls: ',
'You can use the following strings in the long description and all translations. They will be replaced by their actual values by kivitendo before they\'re output.' => 'Sie können die folgenden Begriffe in den Langtexten und allen Übersetzungen benutzen. Sie werden von kivitendo vor der Ausgabe durch ihren tatsächlichen Wert ersetzt.',
'You cannot adjust the price for pricegroup "#1" by a negative percentage.' => 'Sie können den Preis für Preisgruppe "#1" um einen negativen Prozentwert anpassen.',
'You cannot continue before all required modules are installed.' => 'Sie können nicht fortfahren, bevor alle benötigten Pakete installiert sind.',
--- /dev/null
+[%- USE LxERP -%][%- USE L -%]
+<tr>
+ <th align="right">[%- LxERP.t8("Existing contacts (with column 'cp_id')") %]:</th>
+ <td colspan="10">
+ [% opts = [ [ 'update_existing', LxERP.t8('Update properties of existing entries') ], [ 'insert_new', LxERP.t8('Insert with new database ID') ], [ 'skip', LxERP.t8('Skip entry') ] ] %]
+ [% L.select_tag('settings.update_policy', opts, default = SELF.profile.get('update_policy'), style = 'width: 300px') %]
+ </td>
+</tr>
[%- IF SELF.type == 'contacts' %]
<p>
+ [%- LxERP.t8("You can update existing contacts by providing the 'cp_id' column with their database IDs. Otherwise: ") %]
[%- LxERP.t8('At least one of the columns #1, customer, customernumber, vendor, vendornumber (depending on the target table) is required for matching the entry to an existing customer or vendor.', 'cp_cv_id') %]
</p>
[%- INCLUDE 'csv_import/_form_parts.html' %]
[%- ELSIF SELF.type == 'customers_vendors' %]
[%- INCLUDE 'csv_import/_form_customers_vendors.html' %]
+[%- ELSIF SELF.type == 'contacts' %]
+ [%- INCLUDE 'csv_import/_form_contacts.html' %]
[%- END %]
<tr>