+ $main::lxdebug->leave_sub();
+}
+
+sub add_tax {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ $form->{title} = $locale->text('Add');
+
+ $form->{callback} ||= "am.pl?action=add_tax";
+
+ _get_taxaccount_selection();
+
+ $form->header();
+
+ my $parameters_ref = {
+# ChartTypeIsAccount => $ChartTypeIsAccount,
+ };
+
+ # Ausgabe des Templates
+ print($form->parse_html_template('am/edit_tax', $parameters_ref));
+
+ $main::lxdebug->leave_sub();
+}
+
+sub edit_tax {
+ $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');
+
+ AM->get_tax(\%myconfig, \%$form);
+ _get_taxaccount_selection();
+
+ $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2);
+
+ $form->header();
+
+ my $parameters_ref = {
+ };
+
+ # Ausgabe des Templates
+ print($form->parse_html_template('am/edit_tax', $parameters_ref));
+
+ $main::lxdebug->leave_sub();
+}
+
+sub list_tax {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ AM->taxes(\%myconfig, \%$form);
+
+ map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} };
+
+ $form->{callback} = build_std_url('action=list_tax');
+
+ $form->{title} = $locale->text('Tax-O-Matic');
+
+ $form->header();
+
+ my $parameters_ref = {
+ };
+
+ # Ausgabe des Templates
+ print($form->parse_html_template('am/list_tax', $parameters_ref));
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_taxaccount_selection{
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+
+ $main::auth->assert('config');
+
+ AM->get_tax_accounts(\%myconfig, \%$form);
+
+ map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
+
+ $main::lxdebug->leave_sub();
+}
+
+sub save_tax {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ $form->isblank("rate", $locale->text('Taxrate missing!'));
+ $form->isblank("taxdescription", $locale->text('Taxdescription missing!'));
+ $form->isblank("taxkey", $locale->text('Taxkey missing!'));
+
+ $form->{rate} = $form->parse_amount(\%myconfig, $form->{rate});
+
+ if ( $form->{rate} < 0 || $form->{rate} >= 100 ) {
+ $form->error($locale->text('Tax Percent is a number between 0 and 100'));
+ }
+
+ if ( $form->{rate} <= 0.99 && $form->{rate} > 0 ) {
+ $form->error($locale->text('Tax Percent is a number between 0 and 100'));
+ }
+
+ AM->save_tax(\%myconfig, \%$form);
+ $form->redirect($locale->text('Tax saved!'));
+
+ $main::lxdebug->leave_sub();
+}
+
+sub delete_tax {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ AM->delete_tax(\%myconfig, \%$form);
+ $form->redirect($locale->text('Tax deleted!'));
+
+ $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->{fokus} = 'description';
+
+ $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');
+ $form->{fokus} = 'description';
+
+ 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);
+
+ my $previous;
+ foreach my $current (@{ $form->{PRICE_FACTORS} }) {
+ if ($previous) {
+ $previous->{next_id} = $current->{id};
+ $current->{previous_id} = $previous->{id};
+ }
+
+ $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1);
+
+ $previous = $current;
+ }
+
+ $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 swap_price_factors {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+
+ $main::auth->assert('config');
+
+ AM->swap_sortkeys(\%myconfig, $form, 'price_factors');
+ list_price_factors();
+
+ $main::lxdebug->leave_sub();
+}
+
+sub add_warehouse {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ $form->{title} = $locale->text('Add Warehouse');
+ $form->{callback} ||= build_std_url('action=add_warehouse');
+ $form->{fokus} = 'description';
+
+ $form->header();
+ print $form->parse_html_template('am/edit_warehouse');
+
+ $main::lxdebug->leave_sub();
+}
+
+sub edit_warehouse {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ AM->get_warehouse(\%myconfig, $form);
+
+ $form->get_lists('employees' => 'EMPLOYEES');
+
+ $form->{title} = $locale->text('Edit Warehouse');
+ $form->{callback} ||= build_std_url('action=list_warehouses');
+ $form->{fokus} = 'description';
+
+ $form->header();
+ print $form->parse_html_template('am/edit_warehouse');
+
+ $main::lxdebug->leave_sub();
+}
+
+sub list_warehouses {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ AM->get_all_warehouses(\%myconfig, $form);
+
+ my $previous;
+ foreach my $current (@{ $form->{WAREHOUSES} }) {
+ if ($previous) {
+ $previous->{next_id} = $current->{id};
+ $current->{previous_id} = $previous->{id};
+ }
+
+ $previous = $current;
+ }
+
+ $form->{callback} = build_std_url('action=list_warehouses');
+ $form->{title} = $locale->text('Warehouses');
+ $form->{url_base} = build_std_url('callback');
+
+ $form->header();
+ print $form->parse_html_template('am/list_warehouses');
+
+ $main::lxdebug->leave_sub();
+}
+
+sub save_warehouse {
+ $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->{number_of_new_bins} = $form->parse_amount(\%myconfig, $form->{number_of_new_bins});
+
+ AM->save_warehouse(\%myconfig, $form);
+
+ $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse saved.')) if ($form->{callback});
+
+ $form->redirect($locale->text('Warehouse saved.'));
+
+ $main::lxdebug->leave_sub();
+}
+
+sub swap_warehouses {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+
+ $main::auth->assert('config');
+
+ AM->swap_sortkeys(\%myconfig, $form, 'warehouse');
+ list_warehouses();
+
+ $main::lxdebug->leave_sub();
+}
+
+sub delete_warehouse {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ if (!$form->{confirmed}) {
+ $form->{title} = $locale->text('Confirmation');
+
+ $form->header();
+ print $form->parse_html_template('am/confirm_delete_warehouse');
+ ::end_of_request();
+ }
+
+ if (AM->delete_warehouse(\%myconfig, $form)) {
+ $form->{callback} .= '&saved_message=' . E($locale->text('Warehouse deleted.')) if ($form->{callback});
+ $form->redirect($locale->text('Warehouse deleted.'));
+
+ } else {
+ $form->error($locale->text('The warehouse could not be deleted because it has already been used.'));
+ }
+
+ $main::lxdebug->leave_sub();
+}
+
+sub save_bin {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ AM->save_bins(\%myconfig, $form);
+
+ $form->{callback} .= '&saved_message=' . E($locale->text('Bins saved.')) if ($form->{callback});
+
+ $form->redirect($locale->text('Bins saved.'));
+
+ $main::lxdebug->leave_sub();