From: Moritz Bunkus
Date: Wed, 1 Feb 2017 13:41:51 +0000 (+0100)
Subject: SimpleSystemSetting: Umstellung von »Preisfaktoren«
X-Git-Tag: release-3.5.4~1558
X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=5e1de2f843f96657e16c7068991f9345c50484d5;p=kivitendo-erp.git
SimpleSystemSetting: Umstellung von »Preisfaktoren«
---
diff --git a/SL/AM.pm b/SL/AM.pm
index 2aa1ad2b6..1f9a573d0 100644
--- a/SL/AM.pm
+++ b/SL/AM.pm
@@ -1292,76 +1292,6 @@ sub delete_tax {
$main::lxdebug->leave_sub();
}
-sub save_price_factor {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- SL::DB->client->with_transaction(sub {
- my $dbh = SL::DB->client->dbh;
-
- my $query;
- my @values = ($form->{description}, conv_i($form->{factor}));
-
- if ($form->{id}) {
- $query = qq|UPDATE price_factors SET description = ?, factor = ? WHERE id = ?|;
- push @values, conv_i($form->{id});
-
- } else {
- $query = qq|INSERT INTO price_factors (description, factor, sortkey) VALUES (?, ?, (SELECT COALESCE(MAX(sortkey), 0) + 1 FROM price_factors))|;
- }
-
- do_query($form, $dbh, $query, @values);
- 1;
- }) or do { die SL::DB->client->error };
-
- $main::lxdebug->leave_sub();
-}
-
-sub get_all_price_factors {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- my $dbh = SL::DB->client->dbh;
-
- $form->{PRICE_FACTORS} = selectall_hashref_query($form, $dbh, qq|SELECT * FROM price_factors ORDER BY sortkey|);
-
- $main::lxdebug->leave_sub();
-}
-
-sub get_price_factor {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- # connect to database
- my $dbh = SL::DB->client->dbh;
-
- my $query = qq|SELECT description, factor,
- ((SELECT COUNT(*) FROM parts WHERE price_factor_id = ?) +
- (SELECT COUNT(*) FROM invoice WHERE price_factor_id = ?) +
- (SELECT COUNT(*) FROM orderitems WHERE price_factor_id = ?)) = 0 AS orphaned
- FROM price_factors WHERE id = ?|;
-
- ($form->{description}, $form->{factor}, $form->{orphaned}) = selectrow_query($form, $dbh, $query, (conv_i($form->{id})) x 4);
-
- $main::lxdebug->leave_sub();
-}
-
-sub delete_price_factor {
- $main::lxdebug->enter_sub();
-
- my ($self, $myconfig, $form) = @_;
-
- SL::DB->client->with_transaction(sub {
- do_query($form, SL::DB->client->dbh, qq|DELETE FROM price_factors WHERE id = ?|, conv_i($form->{id}));
- 1;
- }) or do { die SL::DB->client->error };
-
- $main::lxdebug->leave_sub();
-}
-
sub save_warehouse {
$main::lxdebug->enter_sub();
diff --git a/SL/Controller/SimpleSystemSetting.pm b/SL/Controller/SimpleSystemSetting.pm
index f03d97bef..0c78f1109 100644
--- a/SL/Controller/SimpleSystemSetting.pm
+++ b/SL/Controller/SimpleSystemSetting.pm
@@ -71,6 +71,20 @@ my %supported_types = (
],
},
+ price_factor => {
+ # Make locales.pl happy: $self->render("simple_system_setting/_price_factor_form")
+ class => 'PriceFactor',
+ titles => {
+ list => t8('Price Factors'),
+ add => t8('Add Price Factor'),
+ edit => t8('Edit Price Factor'),
+ },
+ list_attributes => [
+ { method => 'description', title => t8('Description') },
+ { method => 'factor_as_number', title => t8('Factor'), align => 'right' },
+ ],
+ },
+
pricegroup => {
# Make locales.pl happy: $self->render("simple_system_setting/_pricegroup_form")
class => 'Pricegroup',
diff --git a/SL/DB/PriceFactor.pm b/SL/DB/PriceFactor.pm
index af8b4ef2a..e5fab1ce7 100644
--- a/SL/DB/PriceFactor.pm
+++ b/SL/DB/PriceFactor.pm
@@ -8,6 +8,26 @@ use SL::DB::Helper::ActsAsList;
__PACKAGE__->meta->initialize;
+sub orphaned {
+ my ($self) = @_;
+
+ die 'not an accessor' if @_ > 1;
+
+ require SL::DB::DeliveryOrderItem;
+ require SL::DB::InvoiceItem;
+ require SL::DB::OrderItem;
+ require SL::DB::Part;
+
+ return 1 if !$self->id;
+
+ return 0 if SL::DB::Manager::DeliveryOrderItem->get_first(query => [ price_factor_id => $self->id ]);
+ return 0 if SL::DB::Manager::InvoiceItem ->get_first(query => [ price_factor_id => $self->id ]);
+ return 0 if SL::DB::Manager::OrderItem ->get_first(query => [ price_factor_id => $self->id ]);
+ return 0 if SL::DB::Manager::Part ->get_first(query => [ price_factor_id => $self->id ]);
+
+ return 1;
+}
+
1;
__END__
diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl
index 7f0441d04..d72b51184 100644
--- a/bin/mozilla/am.pl
+++ b/bin/mozilla/am.pl
@@ -1354,111 +1354,6 @@ sub delete_tax {
$main::lxdebug->leave_sub();
}
-sub add_price_factor {
- $main::lxdebug->enter_sub();
-
- my $form = $main::form;
- my $locale = $main::locale;
-
- $main::auth->assert('config');
-
- $form->{title} = $locale->text('Add Price Factor');
- $form->{callback} ||= build_std_url('action=add_price_factor');
-
- $form->header();
- print $form->parse_html_template('am/edit_price_factor');
-
- $main::lxdebug->leave_sub();
-}
-
-sub edit_price_factor {
- $main::lxdebug->enter_sub();
-
- my $form = $main::form;
- my %myconfig = %main::myconfig;
- my $locale = $main::locale;
-
- $main::auth->assert('config');
-
- $form->{title} = $locale->text('Edit Price Factor');
- $form->{callback} ||= build_std_url('action=add_price_factor');
-
- AM->get_price_factor(\%myconfig, $form);
-
- $form->{factor} = $form->format_amount(\%myconfig, $form->{factor} * 1);
-
- $form->header();
- print $form->parse_html_template('am/edit_price_factor');
-
- $main::lxdebug->leave_sub();
-}
-
-sub list_price_factors {
- $main::lxdebug->enter_sub();
-
- my $form = $main::form;
- my %myconfig = %main::myconfig;
- my $locale = $main::locale;
-
- $main::auth->assert('config');
-
- AM->get_all_price_factors(\%myconfig, \%$form);
-
- foreach my $current (@{ $form->{PRICE_FACTORS} }) {
- $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
- }
-
- $form->{callback} = build_std_url('action=list_price_factors');
- $form->{title} = $locale->text('Price Factors');
- $form->{url_base} = build_std_url('callback');
-
- $form->header();
- print $form->parse_html_template('am/list_price_factors');
-
- $main::lxdebug->leave_sub();
-}
-
-sub save_price_factor {
- $main::lxdebug->enter_sub();
-
- my $form = $main::form;
- my %myconfig = %main::myconfig;
- my $locale = $main::locale;
-
- $main::auth->assert('config');
-
- $form->isblank("description", $locale->text('Description missing!'));
- $form->isblank("factor", $locale->text('Factor missing!'));
-
- $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor});
-
- AM->save_price_factor(\%myconfig, $form);
-
- $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback});
-
- $form->redirect($locale->text('Price factor saved!'));
-
- $main::lxdebug->leave_sub();
-}
-
-sub delete_price_factor {
- $main::lxdebug->enter_sub();
-
- my $form = $main::form;
- my %myconfig = %main::myconfig;
- my $locale = $main::locale;
-
- $main::auth->assert('config');
-
- AM->delete_price_factor(\%myconfig, \%$form);
-
- $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback});
-
- $form->redirect($locale->text('Price factor deleted!'));
-
- $main::lxdebug->leave_sub();
-}
-
sub add_warehouse {
$main::lxdebug->enter_sub();
diff --git a/locale/de/all b/locale/de/all
index d14e80d13..4164e7c9a 100644
--- a/locale/de/all
+++ b/locale/de/all
@@ -10,7 +10,6 @@ use utf8;
# run locales.pl from this directory to rebuild the translation files
$self->{texts} = {
- ' (in use so no change allowed)' => ' (Faktor wird verwendet, keine Ãnderung erlaubt)',
' Date missing!' => ' Datum fehlt!',
' bytes, max=' => ' Bytes, Maximum=',
' missing!' => ' fehlt!',
@@ -1314,7 +1313,6 @@ $self->{texts} = {
'Extended status' => 'Erweiterter Status',
'Extension Of Time' => 'Dauerfristverlängerung',
'Factor' => 'Faktor',
- 'Factor missing!' => 'Der Faktor fehlt.',
'Falsches Datumsformat!' => 'Falsches Datumsformat!',
'Fax' => 'Fax',
'Features' => 'Features',
@@ -1940,6 +1938,7 @@ $self->{texts} = {
'Not obsolete' => 'Gültig',
'Note' => 'Hinweis',
'Note: Taxkeys must have a "valid from" date, and will not behave correctly without.' => 'Hinweis: Steuerschlüssel sind fehlerhaft ohne "Gültig ab" Datum',
+ 'Note: the object is already in use. Therefore some values cannot be changed.' => 'Anmerkung: das Objekt ist bereits in Benutzung. Einige Werte können daher nicht geändert werden.',
'Notes' => 'Bemerkungen',
'Notes (translation for #1)' => 'Bemerkungen (Ãbersetzung für #1)',
'Notes (will appear on hard copy)' => 'Bemerkungen',
@@ -2209,8 +2208,6 @@ $self->{texts} = {
'Price Types' => 'Preistypen',
'Price factor (database ID)' => 'Preisfaktor (Datenbank-ID)',
'Price factor (name)' => 'Preisfaktor (Name)',
- 'Price factor deleted!' => 'Preisfaktor gelöscht.',
- 'Price factor saved!' => 'Preisfaktor gespeichert.',
'Price group' => 'Preisgruppe',
'Price group (database ID)' => 'Preisgruppe (Datenbank-ID)',
'Price group (name)' => 'Preisgruppe (Name) ',
diff --git a/menus/user/00-erp.yaml b/menus/user/00-erp.yaml
index 84490b4a7..14b885433 100644
--- a/menus/user/00-erp.yaml
+++ b/menus/user/00-erp.yaml
@@ -1100,9 +1100,9 @@
id: system_price_factors
name: Price Factors
order: 1200
- module: am.pl
params:
- action: list_price_factors
+ action: SimpleSystemSetting/list
+ type: price_factor
- parent: system
id: system_departments
name: Departments
diff --git a/templates/webpages/am/edit_price_factor.html b/templates/webpages/am/edit_price_factor.html
deleted file mode 100644
index 0e484dfc5..000000000
--- a/templates/webpages/am/edit_price_factor.html
+++ /dev/null
@@ -1,38 +0,0 @@
-[%- USE T8 %]
-[%- USE HTML %]
-
[% title %]
-
-
- [% IF MESSAGE %]
[% MESSAGE %]
[% END %]
-
-
-
-
-
-
-
-
-
-
- [% IF id %][% IF orphaned %][% END %][% END %]
-
-
diff --git a/templates/webpages/am/list_price_factors.html b/templates/webpages/am/list_price_factors.html
deleted file mode 100644
index bc2d0f58a..000000000
--- a/templates/webpages/am/list_price_factors.html
+++ /dev/null
@@ -1,36 +0,0 @@
-[%- USE T8 %][% USE L %][% USE LxERP %]
-[% USE HTML %]
-