- @languages = AM->language(\%myconfig, $form, 1);
-
- @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, $form->{"unit_type"});
- $ddbox = AM->unit_select_data($units, undef, 1);
-
- my $updownlink = build_std_url("action=swap_units", "unit_type");
-
- $form->{"title"} = sprintf($locale->text("Add and edit %s"), $form->{"unit_type"} eq "dimension" ? $locale->text("dimension units") : $locale->text("service units"));
- $form->header();
- print($form->parse_html_template("am/edit_units",
- { "UNITS" => \@unit_list,
- "NEW_BASE_UNIT_DDBOX" => $ddbox,
- "LANGUAGES" => \@languages,
- "updownlink" => $updownlink }));
-
- $lxdebug->leave_sub();
-}
-
-sub add_unit {
- $lxdebug->enter_sub();
-
- $form->isblank("new_name", $locale->text("The name is missing."));
- $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"});
- $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, $form->{"unit_type"}, \@languages);
-
- $form->{"saved_message"} = $locale->text("The unit has been saved.");
-
- edit_units();
-
- $lxdebug->leave_sub();
-}
-
-sub set_unit_languages {
- $lxdebug->enter_sub();
-
- 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}"},
- });
- }
-
- $lxdebug->leave_sub();
-}
-
-sub save_unit {
- $lxdebug->enter_sub();
-
- $old_units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_");
- AM->units_in_use(\%myconfig, $form, $old_units);
-
- @languages = AM->language(\%myconfig, $form, 1);
-
- $new_units = {};
- @delete_units = ();
- foreach $i (1..($form->{"rowcount"} * 1)) {
- $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 $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 $unit (values(%{$new_units})) {
- next if ($unit->{"unchanged_unit"});
-
- map({ $_->{"seen"} = 0; } values(%{$new_units}));
- $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, $form->{"unit_type"}, $new_units, \@delete_units);
-
- $form->{"saved_message"} = $locale->text("The units have been saved.");
-
- edit_units();
-
- $lxdebug->leave_sub();
-}
-
-sub show_history_search {
- $lxdebug->enter_sub();
-
- $form->{title} = $locale->text("History Search");
- $form->header();
-
- print $form->parse_html_template("/common/search_history");
-
- $lxdebug->leave_sub();
-}
-
-sub show_am_history {
- $lxdebug->enter_sub();
- 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" => "projectnummer",
- "Buchungsnummer" => "ordnumber",
- "Eingangsrechnungnummer" => "invnumber",
- "Ausgangsrechnungnummer" => "invnumber",
- "Mahnungsnummer" => "dunning_id"
- );
-
- my $restriction;
- my $tempNo = 0;
- foreach(split(/\,/, $form->{einschraenkungen})) {
- if($tempNo == 0) {
- $restriction .= " AND addition = '" . $_ . "'";
- $tempNo = 1;
- }
- else {
- $restriction .= " OR addition = '" . $_ . "'";
- }
- }
- $restriction .= (($form->{transdate} ne "" && $form->{reqdate} ne "")
- ? qq| AND st.itime::date >= '| . $form->{transdate} . qq|' AND st.itime::date <= '| . $form->{reqdate} . qq|'|
- : (($form->{transdate} ne "" && $form->{reqdate} eq "")
- ? qq| AND st.itime::date >= '| . $form->{transdate} . qq|'|
- : ($form->{transdate} eq "" && $form->{reqdate} ne "")
- ? qq| AND st.itime::date <= '| . $form->{reqdate} . qq|'|
- : ""
- )
- );
- $restriction .= ($form->{mitarbeiter} eq "" ? ""
- : ($form->{mitarbeiter} =~ /^[0-9]*$/
- ? " AND employee_id = " . $form->{mitarbeiter}
- : " AND employee_id = " . &get_employee_id($form->{mitarbeiter}, $dbh)));
-
- my $dbh = $form->dbconnect(\%myconfig);
- 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 $sth = $dbh->prepare($query);
-
- $sth->execute() || $form->dberror($query);
-
- $form->{title} = $locale->text("History Search");
- $form->header();
-
- my $i = 1;
- my $daten = qq||;
- while(my $hash_ref = $sth->fetchrow_hashref()){
- if($i) {
- $daten .= $hash_ref->{id};
- $i = 0;
- }
- else {
- $daten .= " OR trans_id = " . $hash_ref->{id};
- }
- }
-
- my ($sort, $sortby) = split(/\-\-/, $form->{order});
- $sort =~ s/.*\.(.*)$/$1/;
-
- 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
- });
- $dbh->disconnect();
- $lxdebug->leave_sub();
-}
-
-sub get_employee_id {
- $lxdebug->enter_sub();
- my $query = qq|SELECT id FROM employee WHERE name = '| . $_[0] . qq|'|;
- my $sth = $_[1]->prepare($query);
- $sth->execute() || $form->dberror($query);
- my $return = $sth->fetch();
- $sth->finish();
- return ${$return}[0];
- $lxdebug->leave_sub();
-}
-
-sub swap_units {
- $lxdebug->enter_sub();
-
- my $dir = $form->{"dir"} eq "down" ? "down" : "up";
- my $unit_type = $form->{"unit_type"} eq "dimension" ?
- "dimension" : "service";
- AM->swap_units(\%myconfig, $form, $dir, $form->{"name"}, $unit_type);
-
- edit_units();
-
- $lxdebug->leave_sub();
-}
-
-sub add_tax {
- $lxdebug->enter_sub();
-
- $form->{title} = $locale->text('Add');
-
- $form->{callback} =
- "$form->{script}?action=add_tax&login=$form->{login}&password=$form->{password}"
- unless $form->{callback};
-
- _get_taxaccount_selection();
-
- $form->header();
-
- my $parameters_ref = {
-# ChartTypeIsAccount => $ChartTypeIsAccount,
- };
-
- # Ausgabe des Templates
- print($form->parse_html_template2('am/edit_tax', $parameters_ref));
-
- $lxdebug->leave_sub();
-}
-
-sub edit_tax {
- $lxdebug->enter_sub();
-
- $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_template2('am/edit_tax', $parameters_ref));
-
- $lxdebug->leave_sub();
-}
-
-sub list_tax {
- $lxdebug->enter_sub();
-
- 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();
-
- # Ausgabe des Templates
- print($form->parse_html_template2('am/list_tax', $parameters_ref));
-
- $lxdebug->leave_sub();
-}
-
-sub _get_taxaccount_selection{
- $lxdebug->enter_sub();
-
- AM->get_tax_accounts(\%myconfig, \%$form);
-
- map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} };
-
- $lxdebug->leave_sub();
-}
-
-sub save_tax {
- $lxdebug->enter_sub();
-
- $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!'));
-
- $lxdebug->leave_sub();
-}
-
-sub delete_tax {
- $lxdebug->enter_sub();
-
- AM->delete_tax(\%myconfig, \%$form);
- $form->redirect($locale->text('Tax deleted!'));
-
- $lxdebug->leave_sub();
-}
-
-sub add_price_factor {
- $lxdebug->enter_sub();
-
- $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_template2('am/edit_price_factor');
-
- $lxdebug->leave_sub();
-}
-
-sub edit_price_factor {
- $lxdebug->enter_sub();
-
- $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_template2('am/edit_price_factor');
-
- $lxdebug->leave_sub();
-}
-
-sub list_price_factors {
- $lxdebug->enter_sub();
-
- 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;