1 package SL::Controller::ClientConfig;
4 use parent qw(SL::Controller::Base);
9 __PACKAGE__->run_before('check_auth');
13 my ($self, %params) = @_;
15 $self->{posting_options} = [ { title => $::locale->text("never"), value => 0 },
16 { title => $::locale->text("every time"), value => 1 },
17 { title => $::locale->text("on the same day"), value => 2 }, ];
18 $self->{payment_options} = [ { title => $::locale->text("never"), value => 0 },
19 { title => $::locale->text("every time"), value => 1 },
20 { title => $::locale->text("on the same day"), value => 2 }, ];
21 $self->{accounting_options} = [ { title => $::locale->text("Accrual"), value => "accrual" },
22 { title => $::locale->text("cash"), value => "cash" }, ];
23 $self->{inventory_options} = [ { title => $::locale->text("perpetual"), value => "perpetual" },
24 { title => $::locale->text("periodic"), value => "periodic" }, ];
25 $self->{profit_options} = [ { title => $::locale->text("balance"), value => "balance" },
26 { title => $::locale->text("income"), value => "income" }, ];
28 map { $self->{$_} = SL::DB::Default->get->$_ } qw(is_changeable ir_changeable ar_changeable ap_changeable gl_changeable);
30 $self->{payments_changeable} = SL::DB::Default->get->payments_changeable;
32 map { $self->{$_} = SL::DB::Default->get->$_ } qw(is_show_mark_as_paid ir_show_mark_as_paid ar_show_mark_as_paid ap_show_mark_as_paid);
34 map { $self->{$_} = SL::DB::Default->get->$_ } qw(accounting_method inventory_system profit_determination);
36 $self->{show_bestbefore} = SL::DB::Default->get->show_bestbefore;
38 map { $self->{$_} = SL::DB::Default->get->$_ } qw(datev_check_on_sales_invoice datev_check_on_purchase_invoice datev_check_on_ar_transaction datev_check_on_ap_transaction datev_check_on_gl_transaction);
39 # datev check: not implemented yet:
40 #check_on_cash_and_receipt = 0
42 #check_on_sepa_import = 0
44 map { $self->{$_} = SL::DB::Default->get->$_ } qw(sales_order_show_delete purchase_order_show_delete sales_delivery_order_show_delete purchase_delivery_order_show_delete);
46 # All warehouse / transfer default values
47 map { $self->{$_} = SL::DB::Default->get->$_ } qw(transfer_default transfer_default_use_master_default_bin transfer_default_ignore_onhand
48 warehouse_id_ignore_onhand bin_id_ignore_onhand warehouse_id bin_id);
50 # for the default warehouse and bin we get the list and
51 # set a empty value with warehouse_id and bin_id = 0
52 map { $self->{$_} = SL::DB::Default->get->$_ } qw(warehouse_id bin_id);
53 $::form->get_lists('warehouses' => { 'key' => 'WAREHOUSES',
55 $self->{WAREHOUSES} = $::form->{WAREHOUSES};
56 # leerer lagerplatz mit id 0
57 my $no_default_bin_entry = { 'id' => '0', description => '--', 'BINS' => [ { id => '0', description => ''} ] };
58 push @ { $self->{WAREHOUSES} }, $no_default_bin_entry;
60 # set defaults to empty
61 if (my $max = scalar @{ $self->{WAREHOUSES} }) {
62 $self->{warehouse_id} ||= $self->{WAREHOUSES}->[$max -1]->{id};
63 $self->{bin_id} ||= $self->{WAREHOUSES}->[$max -1]->{BINS}->[0]->{id};
64 $self->{warehouse_id_ignore_onhand} ||= $self->{WAREHOUSES}->[$max -1]->{id};
65 $self->{bin_id_ignore_onhand} ||= $self->{WAREHOUSES}->[$max -1]->{BINS}->[0]->{id};
68 $self->{show_weight} = SL::DB::Default->get->show_weight;
70 $self->render('client_config/form', title => $::locale->text('Client Configuration'));
75 my ($self, %params) = @_;
77 map { SL::DB::Default->get->update_attributes($_ => $::form->{$_}); } qw(is_changeable ir_changeable ar_changeable ap_changeable gl_changeable);
79 SL::DB::Default->get->update_attributes('payments_changeable' => $::form->{payments_changeable});
81 map { SL::DB::Default->get->update_attributes($_ => $::form->{$_}); } qw(is_show_mark_as_paid ir_show_mark_as_paid ar_show_mark_as_paid ap_show_mark_as_paid);
83 map { SL::DB::Default->get->update_attributes($_ => $::form->{$_}); } qw(accounting_method inventory_system profit_determination);
85 SL::DB::Default->get->update_attributes('show_bestbefore' => $::form->{show_bestbefore});
87 map { SL::DB::Default->get->update_attributes($_ => $::form->{$_}); } qw(datev_check_on_sales_invoice datev_check_on_purchase_invoice datev_check_on_ar_transaction datev_check_on_ap_transaction datev_check_on_gl_transaction);
89 map { SL::DB::Default->get->update_attributes($_ => $::form->{$_}); } qw(sales_order_show_delete purchase_order_show_delete sales_delivery_order_show_delete purchase_delivery_order_show_delete);
91 # undef warehouse_id if the empty value is selected
92 if ( ($::form->{warehouse_id} == 0) && ($::form->{bin_id} == 0) ) {
93 undef $::form->{warehouse_id};
94 undef $::form->{bin_id};
96 # undef warehouse_id_ignore_onhand if the empty value is selected
97 if ( ($::form->{warehouse_id_ignore_onhand} == 0) && ($::form->{bin_id_ignore_onhand} == 0) ) {
98 undef $::form->{warehouse_id_ignore_onhand};
99 undef $::form->{bin_id_ignore_onhand};
102 # All warehouse / transfer default values
103 map { SL::DB::Default->get->update_attributes($_ => $::form->{$_}); } qw(transfer_default transfer_default_use_master_default_bin transfer_default_ignore_onhand
104 warehouse_id_ignore_onhand bin_id_ignore_onhand warehouse_id bin_id);
106 SL::DB::Default->get->update_attributes('show_weight' => $::form->{show_weight});
108 flash_later('info', $::locale->text('Client Configuration saved!'));
110 $self->redirect_to(action => 'edit');
114 #################### private stuff ##########################
117 $::auth->assert('admin');