Mandantenkonfiguration vereinfacht & in mehrere Dateien gespalten und in Tab-Dialog...
[kivitendo-erp.git] / SL / Controller / ClientConfig.pm
1 package SL::Controller::ClientConfig;
2
3 use strict;
4 use parent qw(SL::Controller::Base);
5
6 use SL::DB::Default;
7 use SL::Helper::Flash;
8 use SL::Locale::String qw(t8);
9
10 __PACKAGE__->run_before('check_auth');
11
12 use Rose::Object::MakeMethods::Generic (
13   'scalar --get_set_init' => [ qw(defaults all_warehouses posting_options payment_options accounting_options inventory_options profit_options) ],
14 );
15
16 sub action_edit {
17   my ($self, %params) = @_;
18   $self->edit_form;
19 }
20
21 sub action_save {
22   my ($self, %params) = @_;
23
24   my $defaults = delete($::form->{defaults}) || {};
25
26   # undef several fields if an empty value has been selected.
27   foreach (qw(warehouse_id bin_id warehouse_id_ignore_onhand bin_id_ignore_onhand)) {
28     undef $defaults->{$_} if !$defaults->{$_};
29   }
30
31   $self->defaults->update_attributes(%{ $defaults });
32
33   flash_later('info', t8('Client Configuration saved!'));
34
35   $self->redirect_to(action => 'edit');
36 }
37
38 #
39 # initializers
40 #
41
42 sub init_defaults       { SL::DB::Default->get }
43 sub init_all_warehouses { SL::DB::Manager::Warehouse->get_all_sorted }
44
45 sub init_posting_options {
46   [ { title => t8("never"),           value => 0           },
47     { title => t8("every time"),      value => 1           },
48     { title => t8("on the same day"), value => 2           }, ]
49 }
50
51 sub init_payment_options {
52   [ { title => t8("never"),           value => 0           },
53     { title => t8("every time"),      value => 1           },
54     { title => t8("on the same day"), value => 2           }, ]
55 }
56
57 sub init_accounting_options {
58   [ { title => t8("Accrual"),         value => "accrual"   },
59     { title => t8("cash"),            value => "cash"      }, ]
60 }
61
62 sub init_inventory_options {
63   [ { title => t8("perpetual"),       value => "perpetual" },
64     { title => t8("periodic"),        value => "periodic"  }, ]
65 }
66
67 sub init_profit_options {
68   [ { title => t8("balance"),         value => "balance"   },
69     { title => t8("income"),          value => "income"    }, ]
70 }
71
72 #
73 # filters
74 #
75
76 sub check_auth {
77   $::auth->assert('admin');
78 }
79
80 #
81 # helpers
82 #
83
84 sub edit_form {
85   my ($self) = @_;
86   $self->render('client_config/form', title => t8('Client Configuration'));
87 }
88
89 1;