From 1dd6d84aa18d0a0ec9e36f02eae743625cd569e9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Fri, 8 May 2020 16:50:27 +0200 Subject: [PATCH] Titel von Ansprechpersonen: Freitext-Feld und/oder Auswahlliste MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Der Titel wird entweder nur mit einer Auswahlliste angezeigt oder mit Freitext-Feld und Auswahlliste. Das ist annähernd das alte Verhalten - im Freitext-Feld eingegebener Text wird auch in contact_titles gespeichert. In der Mandantenkonfiguration ist das Freitext-Feld (altes Verhalten) abschaltbar. Todo: Fremdschlüsselbeziehung zwischen contacts und contact_titles --- SL/Controller/CustomerVendor.pm | 32 ++++++++++--------- SL/DB/ContactTitle.pm | 9 ++++++ SL/DB/MetaSetup/Default.pm | 1 + js/kivi.CustomerVendor.js | 8 +++-- locale/de/all | 2 ++ locale/en/all | 2 ++ .../defaults_contact_titles_use_textfield.sql | 6 ++++ .../webpages/client_config/_features.html | 5 +++ .../customer_vendor/tabs/contacts.html | 8 +++-- 9 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 sql/Pg-upgrade2/defaults_contact_titles_use_textfield.sql diff --git a/SL/Controller/CustomerVendor.pm b/SL/Controller/CustomerVendor.pm index 91b362719..e741dd6d5 100644 --- a/SL/Controller/CustomerVendor.pm +++ b/SL/Controller/CustomerVendor.pm @@ -17,6 +17,7 @@ use SL::Controller::Helper::ParseFilter; use SL::DB::Customer; use SL::DB::Vendor; use SL::DB::Business; +use SL::DB::ContactTitle; use SL::DB::Employee; use SL::DB::Greeting; use SL::DB::Language; @@ -164,9 +165,14 @@ sub _save { } $self->{cv}->greeting(trim $self->{cv}->greeting); - my $save_greeting = $self->{cv}->greeting - && $::instance_conf->get_vc_greetings_use_textfield - && SL::DB::Manager::Greeting->get_all_count(where => [description => $self->{cv}->greeting]) == 0; + my $save_greeting = $self->{cv}->greeting + && $::instance_conf->get_vc_greetings_use_textfield + && SL::DB::Manager::Greeting->get_all_count(where => [description => $self->{cv}->greeting]) == 0; + + $self->{contact}->cp_title(trim($self->{contact}->cp_title)); + my $save_contact_title = $self->{contact}->cp_title + && $::instance_conf->get_contact_titles_use_textfield + && SL::DB::Manager::ContactTitle->get_all_count(where => [description => $self->{contact}->cp_title]) == 0; my $db = $self->{cv}->db; @@ -197,6 +203,8 @@ sub _save { $self->{contact}->cp_cv_id($self->{cv}->id); if( $self->{contact}->cp_name ne '' || $self->{contact}->cp_givenname ne '' ) { + SL::DB::ContactTitle->new(description => $self->{contact}->cp_title)->save if $save_contact_title; + $self->{contact}->save(cascade => 1); } @@ -936,18 +944,12 @@ sub _pre_render { unshift @{$self->{all_greetings}}, (SL::DB::Greeting->new(description => $self->{cv}->greeting)); } - - $query = - 'SELECT DISTINCT(cp_title) AS title - FROM contacts - WHERE cp_title IS NOT NULL AND cp_title != \'\' - ORDER BY cp_title'; - $self->{all_titles} = [ - map( - { $_->{title}; } - selectall_hashref_query($::form, $dbh, $query) - ) - ]; + $self->{all_contact_titles} = SL::DB::Manager::ContactTitle->get_all_sorted(); + foreach my $contact (@{ $self->{cv}->contacts }) { + if ($contact->cp_title && !grep {$contact->cp_title eq $_->description} @{$self->{all_contact_titles}}) { + unshift @{$self->{all_contact_titles}}, (SL::DB::ContactTitle->new(description => $contact->cp_title)); + } + } $self->{all_currencies} = SL::DB::Manager::Currency->get_all(); diff --git a/SL/DB/ContactTitle.pm b/SL/DB/ContactTitle.pm index 427921445..95737d9c9 100644 --- a/SL/DB/ContactTitle.pm +++ b/SL/DB/ContactTitle.pm @@ -5,9 +5,18 @@ package SL::DB::ContactTitle; use strict; +use SL::Util qw(trim); + use SL::DB::MetaSetup::ContactTitle; use SL::DB::Manager::ContactTitle; __PACKAGE__->meta->initialize; +__PACKAGE__->before_save('_before_save_trim_content'); + +sub _before_save_trim_content { + $_[0]->description(trim($_[0]->description)); + return 1; +} + 1; diff --git a/SL/DB/MetaSetup/Default.pm b/SL/DB/MetaSetup/Default.pm index 5224492fc..ecb92185e 100644 --- a/SL/DB/MetaSetup/Default.pm +++ b/SL/DB/MetaSetup/Default.pm @@ -40,6 +40,7 @@ __PACKAGE__->meta->columns( co_ustid => { type => 'text' }, coa => { type => 'text' }, company => { type => 'text' }, + contact_titles_use_textfield => { type => 'boolean' }, create_part_if_not_found => { type => 'boolean', default => 'false' }, create_zugferd_invoices => { type => 'integer' }, currency_id => { type => 'integer', not_null => 1 }, diff --git a/js/kivi.CustomerVendor.js b/js/kivi.CustomerVendor.js index 2c192872a..7c50f05f6 100644 --- a/js/kivi.CustomerVendor.js +++ b/js/kivi.CustomerVendor.js @@ -67,10 +67,13 @@ namespace('kivi.CustomerVendor', function(ns) { kivi.CustomerVendor.setCustomVariablesFromAJAJ(data.contact_cvars, 'contact_cvars_'); - if ( contactId ) + if ( contactId ) { $('#action_delete_contact').show(); - else + $('#contact_cp_title_select').val(contact['cp_title']); + } else { $('#action_delete_contact').hide(); + $('#contact_cp_title_select, #contact_cp_abteilung_select').val(''); + } if (data.contact.disable_cp_main === 1) $("#contact_cp_main").prop("disabled", true); else @@ -79,7 +82,6 @@ namespace('kivi.CustomerVendor', function(ns) { params.onFormSet(); }); - $('#contact_cp_title_select, #contact_cp_abteilung_select').val(''); }; var mapSearchStmts = [ diff --git a/locale/de/all b/locale/de/all index 3c5ec2ad9..d7c8e7249 100755 --- a/locale/de/all +++ b/locale/de/all @@ -3822,6 +3822,7 @@ $self->{texts} = { 'Use UStVA' => 'UStVA verwenden', 'Use WebDAV Repository' => 'Verwende WebDAV', 'Use WebDAV Storage backend' => 'Verwende WebDAV-Backend', + 'Use a text field to enter (new) contact titles if enabled. Otherwise, only a drop down box is offered.' => 'Textfeld zusätzlich zur Eingabe (neuer) Titel von Ansprechpersonen verwenden. Sonst wird nur eine Auswahlliste angezeigt.', 'Use a text field to enter (new) greetings if enabled. Otherwise, only a drop down box is offered.' => 'Textfeld zusätzlich zur Eingabe (neuer) Anreden verwenden. Sonst wird nur eine Auswahlliste angezeigt.', 'Use as new' => 'Als neu verwenden', 'Use default booking group because setting is \'all\'' => 'Standardbuchungsgruppe wird verwendet', @@ -3834,6 +3835,7 @@ $self->{texts} = { 'Use master default bin for Default Transfer, if no default bin for the part is configured' => 'Standardlagerplatz für Ein- / Auslagern über Standard-Lagerplatz, falls für die Ware kein expliziter Lagerplatz konfiguriert ist', 'Use settings from client configuration' => 'Einstellungen aus Mandantenkonfiguration folgen', 'Use text field for greetings' => 'Textfeld für Anreden verwenden', + 'Use text field for title of contacts' => 'Textfeld für Titel von Ansprechpersonen verwenden', 'Use this storage backend for all generated PDF-Files' => 'Verwende dieses Backend für generierte PDF-Dateien', 'Use this storage backend for all uploaded attachments' => 'Verwende dieses Backend für hochgeladene Dateien', 'Use this storage backend for uploaded images' => 'Verwende dieses Backend für hochgeladene Bilder', diff --git a/locale/en/all b/locale/en/all index 56561d538..4ef9a6398 100644 --- a/locale/en/all +++ b/locale/en/all @@ -3821,6 +3821,7 @@ $self->{texts} = { 'Use UStVA' => '', 'Use WebDAV Repository' => '', 'Use WebDAV Storage backend' => '', + 'Use a text field to enter (new) contact titles if enabled. Otherwise, only a drop down box is offered.' => '', 'Use a text field to enter (new) greetings if enabled. Otherwise, only a drop down box is offered.' => '', 'Use as new' => '', 'Use default booking group because setting is \'all\'' => '', @@ -3833,6 +3834,7 @@ $self->{texts} = { 'Use master default bin for Default Transfer, if no default bin for the part is configured' => '', 'Use settings from client configuration' => '', 'Use text field for greetings' => '', + 'Use text field for title of contacts' => '', 'Use this storage backend for all generated PDF-Files' => '', 'Use this storage backend for all uploaded attachments' => '', 'Use this storage backend for uploaded images' => '', diff --git a/sql/Pg-upgrade2/defaults_contact_titles_use_textfield.sql b/sql/Pg-upgrade2/defaults_contact_titles_use_textfield.sql new file mode 100644 index 000000000..dd71616ec --- /dev/null +++ b/sql/Pg-upgrade2/defaults_contact_titles_use_textfield.sql @@ -0,0 +1,6 @@ +-- @tag: defaults_contact_titles_use_textfield +-- @description: Auswahl, ob Freitext-Feld für Titel von Ansprechpersonen im Kunden-/Lieferantenstamm angeboten wird +-- @depends: release_3_5_5 + +ALTER TABLE defaults ADD COLUMN contact_titles_use_textfield BOOLEAN; +UPDATE defaults SET contact_titles_use_textfield = TRUE; diff --git a/templates/webpages/client_config/_features.html b/templates/webpages/client_config/_features.html index cd11a848e..d7b5e4995 100644 --- a/templates/webpages/client_config/_features.html +++ b/templates/webpages/client_config/_features.html @@ -139,6 +139,11 @@ [% L.yes_no_tag('defaults.vc_greetings_use_textfield', SELF.defaults.vc_greetings_use_textfield) %] [% LxERP.t8('Use a text field to enter (new) greetings if enabled. Otherwise, only a drop down box is offered.') %] + + [% LxERP.t8('Use text field for title of contacts') %] + [% L.yes_no_tag('defaults.contact_titles_use_textfield', SELF.defaults.contact_titles_use_textfield) %] + [% LxERP.t8('Use a text field to enter (new) contact titles if enabled. Otherwise, only a drop down box is offered.') %] + [% LxERP.t8('Hourly Rate') %] diff --git a/templates/webpages/customer_vendor/tabs/contacts.html b/templates/webpages/customer_vendor/tabs/contacts.html index c18bd98ae..4adabb207 100644 --- a/templates/webpages/customer_vendor/tabs/contacts.html +++ b/templates/webpages/customer_vendor/tabs/contacts.html @@ -45,8 +45,12 @@ [% 'Title' | $T8 %] - [% L.input_tag('contact.cp_title', SELF.contact.cp_title, size = 40) %] - [% L.select_tag('contact_cp_title_select', SELF.all_titles, with_empty = 1, onchange = '$("#contact_cp_title").val(this.value);') %] + [%- IF INSTANCE_CONF.get_contact_titles_use_textfield -%] + [% L.input_tag('contact.cp_title', SELF.contact.cp_title, size = 40) %] + [% L.select_tag('contact_cp_title_select', SELF.all_contact_titles, default = SELF.contact.cp_title, value_key = 'description', title_key = 'description', with_empty = 1, onchange = '$("#contact_cp_title").val(this.value);') %] + [%- ELSE -%] + [% L.select_tag('contact.cp_title', SELF.all_contact_titles, default = SELF.contact.cp_title, value_key = 'description', title_key = 'description', with_empty = 1) %] + [%- END -%] -- 2.20.1