+sub swap_payment_terms {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+
+ $main::auth->assert('config');
+
+ AM->swap_sortkeys(\%myconfig, $form, "payment_terms");
+ list_payment();
+
+ $main::lxdebug->leave_sub();
+}
+
+sub edit_defaults {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ # get defaults for account numbers and last numbers
+ AM->defaultaccounts(\%myconfig, \%$form);
+ $form->{ALL_UNITS} = AM->convertible_units(AM->retrieve_all_units(), 'g');
+
+ map { $form->{"defaults_${_}"} = $form->{defaults}->{$_} } keys %{ $form->{defaults} };
+
+ foreach my $key (keys %{ $form->{IC} }) {
+ foreach my $accno (sort keys %{ $form->{IC}->{$key} }) {
+ my $array = "ACCNOS_" . uc($key);
+ $form->{$array} ||= [];
+
+ my $value = "${accno}--" . $form->{IC}->{$key}->{$accno}->{description};
+ push @{ $form->{$array} }, {
+ 'name' => $value,
+ 'value' => $value,
+ 'selected' => $form->{IC}->{$key}->{$accno}->{id} == $form->{defaults}->{$key},
+ };
+ }
+ }
+
+ $form->{title} = $locale->text('Ranges of numbers and default accounts');
+
+ $form->header();
+ print $form->parse_html_template('am/edit_defaults');
+
+ $main::lxdebug->leave_sub();
+}
+
+sub save_defaults {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my $locale = $main::locale;
+
+ AM->save_defaults();
+
+ $form->redirect($locale->text('Defaults saved.'));
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _build_cfg_options {
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+
+ my $idx = shift;
+ my $array = uc($idx) . 'S';
+
+ $form->{$array} = [];
+ foreach my $item (@_) {
+ push @{ $form->{$array} }, {
+ 'name' => $item,
+ 'value' => $item,
+ 'selected' => $item eq $myconfig{$idx},
+ };
+ }
+}
+
+sub config {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ _build_cfg_options('dateformat', qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd));
+ _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
+
+ my @formats = ();
+ if ($main::opendocument_templates && $main::openofficeorg_writer_bin &&
+ $main::xvfb_bin && (-x $main::openofficeorg_writer_bin) && (-x $main::xvfb_bin)) {
+ push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
+ "value" => "opendocument_pdf" });
+ }
+ if ($main::latex_templates) {
+ push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
+ }
+ push(@formats, { "name" => "HTML", "value" => "html" });
+ if ($main::latex_templates) {
+ push(@formats, { "name" => $locale->text("Postscript"),
+ "value" => "postscript" });
+ }
+ if ($main::opendocument_templates) {
+ push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
+ "value" => "opendocument" });
+ }
+
+ if (!$myconfig{"template_format"}) {
+ $myconfig{"template_format"} = "pdf";
+ }
+ $form->{TEMPLATE_FORMATS} = [];
+ foreach my $item (@formats) {
+ push @{ $form->{TEMPLATE_FORMATS} }, {
+ 'name' => $item->{name},
+ 'value' => $item->{value},
+ 'selected' => $item->{value} eq $myconfig{template_format},
+ };
+ }
+
+ if (!$myconfig{"default_media"}) {
+ $myconfig{"default_media"} = "screen";
+ }
+
+ my %selected = ($myconfig{"default_media"} => "selected");
+ $form->{MEDIA} = [
+ { 'name' => $locale->text('Screen'), 'value' => 'screen', 'selected' => $selected{screen}, },
+ { 'name' => $locale->text('Printer'), 'value' => 'printer', 'selected' => $selected{printer}, },
+ { 'name' => $locale->text('Queue'), 'value' => 'queue', 'selected' => $selected{queue}, },
+ ];
+
+ $form->{PRINTERS} = [];
+ foreach my $printer (SL::Printer->all_printers(%::myconfig)) {
+ push @{ $form->{PRINTERS} }, {
+ 'name' => $printer->{printer_description},
+ 'value' => $printer->{id},
+ 'selected' => $printer->{id} == $myconfig{default_printer_id},
+ };
+ }
+
+ my %countrycodes = User->country_codes;
+
+ $form->{COUNTRYCODES} = [];
+ foreach my $countrycode (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
+ push @{ $form->{COUNTRYCODES} }, {
+ 'name' => $countrycodes{$countrycode},
+ 'value' => $countrycode,
+ 'selected' => $countrycode eq $myconfig{countrycode},
+ };
+ }
+
+ $form->{STYLESHEETS} = [];
+ foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
+ push @{ $form->{STYLESHEETS} }, {
+ 'name' => $item,
+ 'value' => $item,
+ 'selected' => $item eq $myconfig{stylesheet},
+ };
+ }
+
+ $myconfig{show_form_details} = 1 unless (defined($myconfig{show_form_details}));
+ $form->{CAN_CHANGE_PASSWORD} = $main::auth->can_change_password();
+ $form->{todo_cfg} = { TODO->get_user_config('login' => $form->{login}) };
+
+ $form->{title} = $locale->text('Edit Preferences for #1', $form->{login});
+
+ $form->header();
+ print $form->parse_html_template('am/config');
+
+ $main::lxdebug->leave_sub();
+}
+
+sub save_preferences {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $form->{stylesheet} = $form->{usestylesheet};
+
+ TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
+
+ $form->redirect($locale->text('Preferences saved!')) if (AM->save_preferences(\%myconfig, \%$form, 0));
+ $form->error($locale->text('Cannot save preferences!'));
+
+ $main::lxdebug->leave_sub();
+}
+
+sub audit_control {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ $form->{title} = $locale->text('Audit Control');
+
+ AM->closedto(\%myconfig, \%$form);
+
+ $form->header;
+
+ print qq|
+<body>
+
+<form method=post action=am.pl>
+
+<table width=100%>
+ <tr><th class=listtop>$form->{title}</th></tr>
+ <tr height="5"></tr>
+ <tr>
+ <td>
+ <table>
+ <tr>
+ <th>| . $locale->text('Close Books up to') . qq|</th>
+ <td><input name=closedto size=11 title="$myconfig{dateformat}" value=$form->{closedto}></td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+</table>
+
+<hr size=3 noshade>
+
+<br>
+<input type=hidden name=nextsub value=doclose>
+
+<input type=submit class=submit name=action value="|
+ . $locale->text('Continue') . qq|">
+
+</form>
+
+</body>
+</html>
+|;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub doclose {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ AM->closebooks(\%myconfig, \%$form);
+
+ if ($form->{closedto}) {
+ $form->redirect(
+ $locale->text('Books closed up to') . " "
+ . $locale->date(\%myconfig, $form->{closedto}, 1));
+ } else {
+ $form->redirect($locale->text('Books are open'));
+ }
+
+ $main::lxdebug->leave_sub();
+}
+
+sub edit_units {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ my $units = AM->retrieve_units(\%myconfig, $form, "resolved_");
+ AM->units_in_use(\%myconfig, $form, $units);
+ map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units}));
+
+ my @languages = AM->language(\%myconfig, $form, 1);
+
+ my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units}));
+
+ my $i = 1;
+ foreach (@unit_list) {
+ $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"});
+ $_->{"UNITLANGUAGES"} = [];
+ foreach my $lang (@languages) {
+ push(@{ $_->{"UNITLANGUAGES"} },
+ { "idx" => $i,
+ "unit" => $_->{"name"},
+ "language_id" => $lang->{"id"},
+ "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"},
+ "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"},
+ });
+ }
+ $i++;
+ }
+
+ $units = AM->retrieve_units(\%myconfig, $form);
+ my $ddbox = AM->unit_select_data($units, undef, 1);
+
+ my $updownlink = build_std_url("action=swap_units");
+
+ $form->{"title"} = $locale->text("Add and edit units");
+ $form->header();
+ print($form->parse_html_template("am/edit_units",
+ { "UNITS" => \@unit_list,
+ "NEW_BASE_UNIT_DDBOX" => $ddbox,
+ "LANGUAGES" => \@languages,
+ "updownlink" => $updownlink }));
+
+ $main::lxdebug->leave_sub();
+}
+
+sub add_unit {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ $form->isblank("new_name", $locale->text("The name is missing."));
+ my $units = AM->retrieve_units(\%myconfig, $form);
+ my $all_units = AM->retrieve_units(\%myconfig, $form);
+ $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($all_units->{$form->{"new_name"}});
+
+ my ($base_unit, $factor);
+ if ($form->{"new_base_unit"}) {
+ $form->show_generic_error($locale->text("The base unit does not exist.")) unless (defined($units->{$form->{"new_base_unit"}}));
+
+ $form->isblank("new_factor", $locale->text("The factor is missing."));
+ $factor = $form->parse_amount(\%myconfig, $form->{"new_factor"});
+ $form->show_generic_error($locale->text("The factor is missing.")) unless ($factor);
+ $base_unit = $form->{"new_base_unit"};
+ }
+
+ my @languages;
+ foreach my $lang (AM->language(\%myconfig, $form, 1)) {
+ next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"});
+ push(@languages, { "id" => $lang->{"id"},
+ "localized" => $form->{"new_localized_$lang->{id}"},
+ "localized_plural" => $form->{"new_localized_plural_$lang->{id}"},
+ });
+ }
+
+ AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, \@languages);
+
+ $form->{"saved_message"} = $locale->text("The unit has been saved.");
+
+ edit_units();
+
+ $main::lxdebug->leave_sub();
+}
+
+sub set_unit_languages {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+
+ $main::auth->assert('config');
+
+ my ($unit, $languages, $idx) = @_;
+
+ $unit->{"LANGUAGES"} = [];
+
+ foreach my $lang (@{$languages}) {
+ push(@{ $unit->{"LANGUAGES"} },
+ { "id" => $lang->{"id"},
+ "localized" => $form->{"localized_${idx}_$lang->{id}"},
+ "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"},
+ });
+ }
+
+ $main::lxdebug->leave_sub();
+}
+
+sub save_unit {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ my $old_units = AM->retrieve_units(\%myconfig, $form, "resolved_");
+ AM->units_in_use(\%myconfig, $form, $old_units);
+
+ my @languages = AM->language(\%myconfig, $form, 1);
+
+ my $new_units = {};
+ my @delete_units = ();
+ foreach my $i (1..($form->{"rowcount"} * 1)) {
+ my $old_unit = $old_units->{$form->{"old_name_$i"}};
+ if (!$old_unit) {
+ $form->show_generic_error(sprintf($locale->text("The unit in row %d has been deleted in the meantime."), $i));
+ }
+
+ if ($form->{"unchangeable_$i"}) {
+ $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}};
+ $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1;
+ set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
+ next;
+ }
+
+ if ($old_unit->{"in_use"}) {
+ $form->show_generic_error(sprintf($locale->text("The unit in row %d has been used in the meantime and cannot be changed anymore."), $i));
+ }
+
+ if ($form->{"delete_$i"}) {
+ push(@delete_units, $old_unit->{"name"});
+ next;
+ }
+
+ $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i));
+
+ $form->show_generic_error(sprintf($locale->text("The name in row %d has already been used before."), $i)) if ($new_units->{$form->{"name_$i"}});
+ my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name));
+ $new_units->{$form->{"name_$i"}} = \%h;
+ $new_units->{$form->{"name_$i"}}->{"row"} = $i;
+ set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i);
+ }
+
+ foreach my $unit (values(%{$new_units})) {
+ next unless ($unit->{"old_name"});
+ if ($unit->{"base_unit"}) {
+ $form->show_generic_error(sprintf($locale->text("The base unit does not exist or it is about to be deleted in row %d."), $unit->{"row"}))
+ unless (defined($new_units->{$unit->{"base_unit"}}));
+ $unit->{"factor"} = $form->parse_amount(\%myconfig, $unit->{"factor"});
+ $form->show_generic_error(sprintf($locale->text("The factor is missing in row %d."), $unit->{"row"})) unless ($unit->{"factor"} >= 1.0);
+ } else {
+ $unit->{"base_unit"} = undef;
+ $unit->{"factor"} = undef;
+ }
+ }
+
+ foreach my $unit (values(%{$new_units})) {
+ next if ($unit->{"unchanged_unit"});
+
+ map({ $_->{"seen"} = 0; } values(%{$new_units}));
+ my $new_unit = $unit;
+ while ($new_unit->{"base_unit"}) {
+ $new_unit->{"seen"} = 1;
+ $new_unit = $new_units->{$new_unit->{"base_unit"}};
+ if ($new_unit->{"seen"}) {
+ $form->show_generic_error(sprintf($locale->text("The base unit relations must not contain loops (e.g. by saying that unit A's base unit is B, " .
+ "B's base unit is C and C's base unit is A) in row %d."), $unit->{"row"}));
+ }
+ }
+ }
+
+ AM->save_units(\%myconfig, $form, $new_units, \@delete_units);
+
+ $form->{"saved_message"} = $locale->text("The units have been saved.");
+
+ edit_units();
+
+ $main::lxdebug->leave_sub();
+}
+
+sub show_history_search {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ $form->{title} = $locale->text("History Search");
+ $form->header();
+
+ print $form->parse_html_template("common/search_history");
+
+ $main::lxdebug->leave_sub();
+}
+
+sub show_am_history {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+ my $locale = $main::locale;
+
+ $main::auth->assert('config');
+
+ my $callback = build_std_url(qw(action einschraenkungen fromdate todate mitarbeiter searchid what2search));
+ $form->{order} ||= 'h.itime--1';
+
+ my %search = ( "Artikelnummer" => "parts",
+ "Kundennummer" => "customer",
+ "Lieferantennummer" => "vendor",
+ "Projektnummer" => "project",
+ "Buchungsnummer" => "oe",
+ "Eingangsrechnungnummer" => "ap",
+ "Ausgangsrechnungnummer" => "ar",
+ "Mahnungsnummer" => "dunning"
+ );
+ my %searchNo = ( "Artikelnummer" => "partnumber",
+ "Kundennummer" => "customernumber",
+ "Lieferantennummer" => "vendornumber",
+ "Projektnummer" => "projectnumber",
+ "Buchungsnummer" => "ordnumber",
+ "Eingangsrechnungnummer" => "invnumber",
+ "Ausgangsrechnungnummer" => "invnumber",
+ "Mahnungsnummer" => "dunning_id"
+ );
+
+ my $dbh = $form->dbconnect(\%myconfig);
+
+ my $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen};
+ $restriction .= qq| AND h.itime::date >= | . conv_dateq($form->{fromdate}) if $form->{fromdate};
+ $restriction .= qq| AND h.itime::date <= | . conv_dateq($form->{todate}) if $form->{todate};
+ if ($form->{mitarbeiter} =~ m/^\d+$/) {
+ $restriction .= qq| AND employee_id = | . $form->{mitarbeiter};
+ } elsif ($form->{mitarbeiter}) {
+ $restriction .= qq| AND employee_id = (SELECT id FROM employee WHERE name ILIKE | . $dbh->quote('%' . $form->{mitarbeiter} . '%') . qq|)|;
+ }
+
+ my $query = qq|SELECT trans_id AS id FROM history_erp | .
+ ( $form->{'searchid'} ? qq| WHERE snumbers = '| . $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'} . qq|'|
+ : qq| WHERE snumbers ~ '^| . $searchNo{$form->{'what2search'}} . qq|'|);
+
+ my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query);
+ my $daten .= shift @ids;
+ $daten .= join '', map { " OR trans_id = $_" } @ids;
+
+ my ($sort, $sortby) = split(/\-\-/, $form->{order});
+ $sort =~ s/.*\.(.*)$/$1/;
+
+ $form->{title} = $locale->text("History Search");
+ $form->header();
+
+ print $form->parse_html_template("common/show_history",
+ { "DATEN" => $form->get_history($dbh, $daten, $restriction, $form->{order}),
+ "SUCCESS" => ($form->get_history($dbh, $daten, $restriction, $form->{order}) ne "0"),
+ "NONEWWINDOW" => 1,
+ uc($sort) => 1,
+ uc($sort) . "BY" => $sortby,
+ 'callback' => $callback,
+ });
+ $dbh->disconnect();
+
+ $main::lxdebug->leave_sub();
+}
+
+sub swap_units {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my %myconfig = %main::myconfig;
+
+ $main::auth->assert('config');
+
+ my $dir = $form->{"dir"} eq "down" ? "down" : "up";
+ AM->swap_units(\%myconfig, $form, $dir, $form->{"name"});
+
+ edit_units();
+
+ $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});