From 761f4a3f4efbe238058efe99939698c0624d3181 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Fri, 24 Apr 2020 15:16:09 +0200 Subject: [PATCH] Anreden: Kunden-/Lieferantenstamm: Freitext-Feld und/oder Auswahlliste MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Die Anrede 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 greetings gespeichert. In der Mandantenkonfiguration ist das Freitext-Feld (altes Verhalten) abschaltbar. Todo: Fremdschlüsselbeziehung zwischen customer/vendor und greetings --- SL/Controller/CustomerVendor.pm | 29 +++++++++---------- SL/DB/Greeting.pm | 9 ++++++ SL/DB/MetaSetup/Default.pm | 1 + locale/de/all | 2 ++ locale/en/all | 2 ++ .../defaults_vc_greetings_use_textfield.sql | 6 ++++ .../webpages/client_config/_features.html | 5 ++++ .../customer_vendor/tabs/billing.html | 8 +++-- 8 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 sql/Pg-upgrade2/defaults_vc_greetings_use_textfield.sql diff --git a/SL/Controller/CustomerVendor.pm b/SL/Controller/CustomerVendor.pm index 0fdd832df..91b362719 100644 --- a/SL/Controller/CustomerVendor.pm +++ b/SL/Controller/CustomerVendor.pm @@ -9,6 +9,7 @@ use SL::JSON; use SL::DBUtils; use SL::Helper::Flash; use SL::Locale::String; +use SL::Util qw(trim); use SL::Controller::Helper::GetModels; use SL::Controller::Helper::ReportGenerator; use SL::Controller::Helper::ParseFilter; @@ -17,6 +18,7 @@ use SL::DB::Customer; use SL::DB::Vendor; use SL::DB::Business; use SL::DB::Employee; +use SL::DB::Greeting; use SL::DB::Language; use SL::DB::TaxZone; use SL::DB::Note; @@ -161,6 +163,11 @@ sub _save { $::dispatcher->end_request; } + $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 $db = $self->{cv}->db; $db->with_transaction(sub { @@ -186,6 +193,8 @@ sub _save { $self->{cv}->save(cascade => 1); + SL::DB::Greeting->new(description => $self->{cv}->greeting)->save if $save_greeting; + $self->{contact}->cp_cv_id($self->{cv}->id); if( $self->{contact}->cp_name ne '' || $self->{contact}->cp_givenname ne '' ) { $self->{contact}->save(cascade => 1); @@ -922,21 +931,11 @@ sub _pre_render { $self->{all_employees} = SL::DB::Manager::Employee->get_all(query => [ deleted => 0 ]); - $query = - 'SELECT DISTINCT(greeting) - FROM customer - WHERE greeting IS NOT NULL AND greeting != \'\' - UNION - SELECT DISTINCT(greeting) - FROM vendor - WHERE greeting IS NOT NULL AND greeting != \'\' - ORDER BY greeting'; - $self->{all_greetings} = [ - map( - { $_->{greeting}; } - selectall_hashref_query($::form, $dbh, $query) - ) - ]; + $self->{all_greetings} = SL::DB::Manager::Greeting->get_all_sorted(); + if ($self->{cv}->id && $self->{cv}->greeting && !grep {$self->{cv}->greeting eq $_->description} @{$self->{all_greetings}}) { + unshift @{$self->{all_greetings}}, (SL::DB::Greeting->new(description => $self->{cv}->greeting)); + } + $query = 'SELECT DISTINCT(cp_title) AS title diff --git a/SL/DB/Greeting.pm b/SL/DB/Greeting.pm index fa0fa82bf..c43edf92f 100644 --- a/SL/DB/Greeting.pm +++ b/SL/DB/Greeting.pm @@ -5,9 +5,18 @@ package SL::DB::Greeting; use strict; +use SL::Util qw(trim); + use SL::DB::MetaSetup::Greeting; use SL::DB::Manager::Greeting; __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 76373ea14..5224492fc 100644 --- a/SL/DB/MetaSetup/Default.pm +++ b/SL/DB/MetaSetup/Default.pm @@ -167,6 +167,7 @@ __PACKAGE__->meta->columns( transfer_default_use_master_default_bin => { type => 'boolean', default => 'false' }, transfer_default_warehouse_for_assembly => { type => 'boolean', default => 'false' }, transport_cost_reminder_article_number_id => { type => 'integer' }, + vc_greetings_use_textfield => { type => 'boolean' }, vendornumber => { type => 'text' }, version => { type => 'varchar', length => 8 }, vertreter => { type => 'boolean', default => 'false' }, diff --git a/locale/de/all b/locale/de/all index 51f5989f5..5f05135d2 100755 --- a/locale/de/all +++ b/locale/de/all @@ -3819,6 +3819,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) 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', 'Use default booking group because wanted is missing' => 'Fehlende Buchungsgruppe, deshalb Standardbuchungsgruppe', @@ -3829,6 +3830,7 @@ $self->{texts} = { 'Use linked items' => 'Verknüpfte Positionen verwenden', '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 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 49abaf3d1..55084c8f9 100644 --- a/locale/en/all +++ b/locale/en/all @@ -3818,6 +3818,7 @@ $self->{texts} = { 'Use UStVA' => '', 'Use WebDAV Repository' => '', 'Use WebDAV Storage backend' => '', + '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\'' => '', 'Use default booking group because wanted is missing' => '', @@ -3828,6 +3829,7 @@ $self->{texts} = { 'Use linked items' => '', '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 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_vc_greetings_use_textfield.sql b/sql/Pg-upgrade2/defaults_vc_greetings_use_textfield.sql new file mode 100644 index 000000000..b5729cf30 --- /dev/null +++ b/sql/Pg-upgrade2/defaults_vc_greetings_use_textfield.sql @@ -0,0 +1,6 @@ +-- @tag: defaults_vc_greetings_use_textfield +-- @description: Auswahl, ob Freitext-Feld für Anrede im Kunden-/Lieferantenstamm angeboten wird +-- @depends: release_3_5_5 + +ALTER TABLE defaults ADD COLUMN vc_greetings_use_textfield BOOLEAN; +UPDATE defaults SET vc_greetings_use_textfield = TRUE; diff --git a/templates/webpages/client_config/_features.html b/templates/webpages/client_config/_features.html index 6538afabc..cd11a848e 100644 --- a/templates/webpages/client_config/_features.html +++ b/templates/webpages/client_config/_features.html @@ -134,6 +134,11 @@ [% L.yes_no_tag('defaults.normalize_vc_names', SELF.defaults.normalize_vc_names) %] [% LxERP.t8('Automatic deletion of leading, trailing and excessive (repetitive) spaces in customer or vendor names') %] + + [% LxERP.t8('Use text field for greetings') %] + [% 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('Hourly Rate') %] diff --git a/templates/webpages/customer_vendor/tabs/billing.html b/templates/webpages/customer_vendor/tabs/billing.html index cb10dc943..21697713a 100644 --- a/templates/webpages/customer_vendor/tabs/billing.html +++ b/templates/webpages/customer_vendor/tabs/billing.html @@ -54,8 +54,12 @@ [% 'Greeting' | $T8 %] - [% L.input_tag('cv.greeting', SELF.cv.greeting) %] - [% L.select_tag('cv_greeting_select', SELF.all_greetings, default = SELF.cv.greeting, with_empty = 1, onchange = '$("#cv_greeting").val(this.value);') %] + [%- IF INSTANCE_CONF.get_vc_greetings_use_textfield -%] + [% L.input_tag('cv.greeting', SELF.cv.greeting) %] + [% L.select_tag('cv_greeting_select', SELF.all_greetings, default = SELF.cv.greeting, value_key = 'description', title_key = 'description', with_empty = 1, onchange = '$("#cv_greeting").val(this.value);') %] + [%- ELSE -%] + [% L.select_tag('cv.greeting', SELF.all_greetings, default = SELF.cv.greeting, value_key = 'description', title_key = 'description', with_empty = 1) %] + [%- END -%] -- 2.20.1