X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fam.pl;h=c28656795682d5ac501c385dbf4e8fd8b46d66ca;hb=3f4a45a96efc9e44bc3cd58874128dc36cc667cf;hp=7894f4cd2a7bf20f5e3bda699633368b1fe1cd6b;hpb=9ceafde6395689d82f625f1d63ff6eb384b87b96;p=kivitendo-erp.git diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index 7894f4cd2..c28656795 100644 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -35,19 +35,24 @@ use SL::AM; use SL::CA; use SL::Form; use SL::User; +use SL::USTVA; +use SL::Iconv; +use CGI::Ajax; +use CGI; use Data::Dumper; 1; -require "$form->{path}/common.pl"; +require "bin/mozilla/common.pl"; # end of main -sub add { &{"add_$form->{type}"} } -sub edit { &{"edit_$form->{type}"} } -sub save { &{"save_$form->{type}"} } -sub delete { &{"delete_$form->{type}"} } +sub add { call_sub("add_$form->{type}"); } +sub delete { call_sub("delete_$form->{type}"); } +sub save { call_sub("save_$form->{type}"); } +sub edit { call_sub("edit_$form->{type}"); } +sub continue { call_sub($form->{"nextsub"}); } sub add_account { $lxdebug->enter_sub(); @@ -57,7 +62,7 @@ sub add_account { AM->get_account(\%myconfig, \%$form); $form->{callback} = - "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&password=$form->{password}" + "$form->{script}?action=list_account&login=$form->{login}&password=$form->{password}" unless $form->{callback}; &account_header; @@ -85,127 +90,108 @@ sub edit_account { sub account_header { $lxdebug->enter_sub(); + if ( $form->{action} eq 'edit_account') { + $form->{account_exists} = '1'; + } + $form->{title} = $locale->text("$form->{title} Account"); - $checked{ $form->{charttype} } = "checked"; - $checked{"$form->{category}_"} = "checked"; - $checked{CT_tax} = ($form->{CT_tax}) ? "" : "checked"; + $form->{"$form->{charttype}_checked"} = "checked"; + $form->{"$form->{category}_checked"} = "checked"; - $form->{description} =~ s/\"/"/g; + $form->{select_tax} = ""; + + my @tax_report_pos = USTVA->report_variables({ + myconfig => \%myconfig, + form => $form, + type => '', + attribute => 'position', + calc => '', + }); if (@{ $form->{TAXKEY} }) { - foreach $item (@{ $form->{TAXKEY} }) { - if ($item->{tax} == $form->{tax}) { - $form->{selecttaxkey} .= - ""; + $form->{selectnewaccount} = qq||; } foreach $item (@{ $form->{NEWACCOUNT} }) { if ($item->{id} == $form->{new_chart_id}) { $form->{selectnewaccount} .= - ""; + qq||; } elsif (!$form->{new_chart_valid}) { $form->{selectnewaccount} .= - ""; + qq||; } } } - $newaccount = qq| - - - - - - - - - -
| . $locale->text('Folgekonto') . qq|| . $locale->text('Gültig ab') . qq|
- - |; - - $form->{selectustva} = "\n|; %eur = (1 => "Umsatzerlöse", 2 => "sonstige Erlöse", 3 => "Privatanteile", @@ -238,22 +224,16 @@ sub account_header { 30 => "Ausserordentlicher Aufwand", 31 => "Betriebliche Steuern"); foreach $item (sort({ $a <=> $b } keys(%eur))) { + my $text = H(SL::Iconv::convert("ISO-8859-15", $dbcharset, $eur{$item})); if ($item == $form->{pos_eur}) { - $form->{selecteur} .= "\n|; } else { - $form->{selecteur} .= "\n|; } } - $eur = qq| - - | . $locale->text('EUER') . qq| - - - |; - - $form->{selectbwa} = "\n|; %bwapos = (1 => 'Umsatzerlöse', 2 => 'Best.Verdg.FE/UE', @@ -278,192 +258,89 @@ sub account_header { 34 => 'Verr.kalk.Kosten', 35 => 'Steuern Eink.u.Ertr.'); foreach $item (sort({ $a <=> $b } keys %bwapos)) { + my $text = H(SL::Iconv::convert("ISO-8859-15", $dbcharset, $bwapos{$item})); if ($item == $form->{pos_bwa}) { - $form->{selectbwa} .= "\n|; + foreach $item ((1, 2, 3, 4)) { + if ($item == $form->{pos_bilanz}) { + $select_bilanz .= qq|"; + } - - - - - - - - - - - -
$form->{title}
- - + if (!$myconfig{"default_media"}) { + $myconfig{"default_media"} = "screen"; + } + my %selected = ($myconfig{"default_media"} => "selected"); + my $default_media = qq| + + + |; - map { print "$column_header{$_}\n" } @column_index; + %selected = (); + $selected{$myconfig{"default_printer_id"}} = "selected" + if ($myconfig{"default_printer_id"}); + my $default_printer = qq||; + AM->printer(\%myconfig, $form); + foreach my $printer (@{$form->{"ALL"}}) { + $default_printer .= qq||; + } - print qq| - -|; + %countrycodes = User->country_codes; + $countrycodes = ''; + foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} } + keys %countrycodes + ) { + $countrycodes .= + ($myconfig{countrycode} eq $key) + ? " -|; - $column_data{code} = - qq||; - $column_data{description} = qq||; +# css dir has styles that are not intended as general layouts. +# reverting to hardcoded list + @all = qw(lx-office-erp.css Win2000.css); + foreach $item (@all) { + if ($item eq $myconfig{stylesheet}) { + $selectstylesheet .= qq| -|; - - $column_data{code} = - qq||; - $column_data{description} = qq||; - + $selectstylesheet .= qq| -|; } + $selectstylesheet .= "
{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{code}$ref->{description}
{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{code}$ref->{description}
-

- -
-
{script}> - - - - - -{path}> -{login}> -{password}> + $form->{title} = $locale->text('Edit Preferences for') . qq| $form->{login}|; -|; + $form->header; - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; + if ($myconfig{menustyle} eq "old") { + $menustyle_old = "checked"; + } elsif ($myconfig{menustyle} eq "neu") { + $menustyle_neu = "checked"; + } elsif ($myconfig{menustyle} eq "v3") { + $menustyle_v3 = "checked"; } - print qq| -
- - - -|; - - $lxdebug->leave_sub(); -} - -sub sic_header { - $lxdebug->enter_sub(); - - $form->{title} = $locale->text("$form->{title} SIC"); - - # $locale->text('Add SIC') - # $locale->text('Edit SIC') - - $form->{code} =~ s/\"/"/g; - $form->{description} =~ s/\"/"/g; - - $checked = ($form->{sictype} eq 'H') ? "checked" : ""; - - $form->header; + my ($show_form_details, $hide_form_details); + $myconfig{"show_form_details"} = 1 + unless (defined($myconfig{"show_form_details"})); + $show_form_details = "checked" if ($myconfig{"show_form_details"}); + $hide_form_details = "checked" unless ($myconfig{"show_form_details"}); print qq|
{script}> - -{code}> + + + + - - - - - - - - - - - - - - - - - -
$form->{title}
$form->{title}
| . $locale->text('Code') . qq|{code}>
| - . $locale->text('Heading') . qq|
| . $locale->text('Description') . qq|

-|; - - $lxdebug->leave_sub(); -} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -sub save_sic { - $lxdebug->enter_sub(); - - $form->isblank("code", $locale->text('Code missing!')); - $form->isblank("description", $locale->text('Description missing!')); - AM->save_sic(\%myconfig, \%$form); - $form->redirect($locale->text('SIC saved!')); - - $lxdebug->leave_sub(); -} - -sub delete_sic { - $lxdebug->enter_sub(); - - AM->delete_sic(\%myconfig, \%$form); - $form->redirect($locale->text('SIC deleted!')); - - $lxdebug->leave_sub(); -} - -sub display_stylesheet { - $lxdebug->enter_sub(); - - $form->{file} = "css/$myconfig{stylesheet}"; - &display_form; - - $lxdebug->leave_sub(); -} - -sub display_form { - $lxdebug->enter_sub(); - - $form->{file} =~ s/^(.:)*?\/|\.\.\///g; - $form->{file} =~ s/^\/*//g; - $form->{file} =~ s/$userspath//; - - $form->error("$!: $form->{file}") unless -f $form->{file}; - - AM->load_template(\%$form); - - $form->{title} = $form->{file}; - - # if it is anything but html - if ($form->{file} !~ /\.html$/) { - $form->{body} = "
\n$form->{body}\n
"; - } - - $form->header; - - print qq| - - -$form->{body} - -{script}> - -{file}> - - -{path}> -{login}> -{password}> - -|; - - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - print qq| - - - - -|; - - $lxdebug->leave_sub(); -} - -sub edit_template { - $lxdebug->enter_sub(); - - AM->load_template(\%$form); - - $form->{title} = $locale->text('Edit Template'); - - # convert   to &nbsp; - $form->{body} =~ s/ /&nbsp;/gi; - - $form->header; - - print qq| - - -{script}> - -{file}> - - -{path}> -{login}> -{password}> - - - - - -
-|; - - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - print q| - - - - - -|; - - $lxdebug->leave_sub(); -} - -sub save_template { - $lxdebug->enter_sub(); - - AM->save_template(\%$form); - $form->redirect($locale->text('Template saved!')); - - $lxdebug->leave_sub(); -} - -sub config { - $lxdebug->enter_sub(); - - # get defaults for account numbers and last numbers - AM->defaultaccounts(\%myconfig, \%$form); - - foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) { - $dateformat .= - ($item eq $myconfig{dateformat}) - ? "
| . $locale->text('Name') . qq|
| . $locale->text('Password') . qq|
| . $locale->text('E-mail') . qq|
| . $locale->text('Signature') . qq|
| . $locale->text('Phone') . qq|
| . $locale->text('Fax') . qq|
| . $locale->text('Company') . qq|
| . $locale->text('Address') . qq|
| . $locale->text('Date Format') . qq|
| . $locale->text('Output Number Format') . qq|
- - -
$form->{title}
- - - - - - - - - - - - - - - - - - - + + - - + + - - - - - - + + - - + + + + + + - - - + + + - - + + - - - + + - - + + - - + + - - - - - + + @@ -3046,16 +2602,8 @@ sub config { -
| . $locale->text('Name') . qq|
| . $locale->text('Password') . qq|
| . $locale->text('E-mail') . qq|
| . $locale->text('Signature') . qq|
| . $locale->text('Phone') . qq|| . $locale->text('Dropdown Limit') . qq|
| . $locale->text('Fax') . qq|| . $locale->text('Language') . qq|
| . $locale->text('Company') . qq|
| . $locale->text('Address') . qq|| . $locale->text('Stylesheet') . qq|
| . $locale->text('Date Format') . qq|| . $locale->text('Setup Menu') . qq| | . + $locale->text("Top (CSS)") . qq| +  | . + $locale->text("Top (Javascript)") . qq| +  | . + $locale->text("Old (on the side)") . qq|
| . $locale->text('Form details (second row)') . qq|  + +   +
| . $locale->text('Output Number Format') . qq|
| . $locale->text("Print options") . qq|
| . $locale->text('Input Number Format') . qq|| . $locale->text('Default template format') . qq|
| . $locale->text('Dropdown Limit') . qq|| . $locale->text('Default output medium') . qq|
| . $locale->text('Language') . qq|| . $locale->text('Default printer') . qq|
| . $locale->text('Stylesheet') . qq|| . $locale->text('Number of copies') . qq|
| . $locale->text('Setup Menu') . qq| New -  Old
 
- - - - - -
| . $locale->text('Year End') . qq| (mm/dd) {defaults}{yearend}>| . $locale->text('Weight Unit') . qq|
-
| @@ -3182,20 +2730,13 @@ print qq|
-{path}> {login}> {password}>
|; - - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } + . $locale->text('Save') . qq|"> - print qq| @@ -3219,26 +2760,6 @@ sub save_preferences { $lxdebug->leave_sub(); } -sub backup { - $lxdebug->enter_sub(); - - if ($form->{media} eq 'email') { - $form->error($locale->text('No email address for') . " $myconfig{name}") - unless ($myconfig{email}); - - $form->{OUT} = "$sendmail"; - - } - - AM->backup(\%myconfig, \%$form, $userspath); - - if ($form->{media} eq 'email') { - $form->redirect($locale->text('Backup sent to') . qq| $myconfig{email}|); - } - - $lxdebug->leave_sub(); -} - sub audit_control { $lxdebug->enter_sub(); @@ -3259,7 +2780,6 @@ sub audit_control {
{script}> -{path}> {login}> {password}> @@ -3325,205 +2845,6 @@ sub doclose { $lxdebug->leave_sub(); } -sub add_warehouse { - $lxdebug->enter_sub(); - - $form->{title} = "Add"; - - $form->{callback} = - "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&password=$form->{password}" - unless $form->{callback}; - - &warehouse_header; - &form_footer; - - $lxdebug->leave_sub(); -} - -sub edit_warehouse { - $lxdebug->enter_sub(); - - $form->{title} = "Edit"; - - AM->get_warehouse(\%myconfig, \%$form); - - &warehouse_header; - &form_footer; - - $lxdebug->leave_sub(); -} - -sub list_warehouse { - $lxdebug->enter_sub(); - - AM->warehouses(\%myconfig, \%$form); - - $form->{callback} = - "$form->{script}?action=list_warehouse&path=$form->{path}&login=$form->{login}&password=$form->{password}"; - - $callback = $form->escape($form->{callback}); - - $form->{title} = $locale->text('Warehouses'); - - @column_index = qw(description); - - $column_header{description} = - qq|| - . $locale->text('Description') - . qq||; - - $form->header; - - print qq| - - - - - - - - - - - - - -
$form->{title}
- - -|; - - map { print "$column_header{$_}\n" } @column_index; - - print qq| - -|; - - foreach $ref (@{ $form->{ALL} }) { - - $i++; - $i %= 2; - - print qq| - -|; - - $column_data{description} = - qq||; - - map { print "$column_data{$_}\n" } @column_index; - - print qq| - -|; - } - - print qq| -
{script}?action=edit_warehouse&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}
-

- -
-{script}> - - - - - -{path}> -{login}> -{password}> - -|; - - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - print qq| -
- - - -|; - - $lxdebug->leave_sub(); -} - -sub warehouse_header { - $lxdebug->enter_sub(); - - $form->{title} = $locale->text("$form->{title} Warehouse"); - - # $locale->text('Add Warehouse') - # $locale->text('Edit Warehouse') - - $form->{description} =~ s/\"/"/g; - - if (($rows = $form->numtextrows($form->{description}, 60)) > 1) { - $description = - qq||; - } else { - $description = - qq||; - } - - $form->header; - - print qq| - - -
{script}> - -{id}> - - - - - - - - - - - - - - -
$form->{title}
| . $locale->text('Description') . qq|$description

-|; - - $lxdebug->leave_sub(); -} - -sub save_warehouse { - $lxdebug->enter_sub(); - - $form->isblank("description", $locale->text('Description missing!')); - AM->save_warehouse(\%myconfig, \%$form); - $form->redirect($locale->text('Warehouse saved!')); - - $lxdebug->leave_sub(); -} - -sub delete_warehouse { - $lxdebug->enter_sub(); - - AM->delete_warehouse(\%myconfig, \%$form); - $form->redirect($locale->text('Warehouse deleted!')); - - $lxdebug->leave_sub(); -} - -sub continue { - $lxdebug->enter_sub(); - - &{ $form->{nextsub} }; - - $lxdebug->leave_sub(); -} - sub edit_units { $lxdebug->enter_sub(); @@ -3533,15 +2854,11 @@ sub edit_units { @languages = AM->language(\%myconfig, $form, 1); - @unit_list = (); - foreach $name (sort({ lc($a) cmp lc($b) } grep({ !$units->{$_}->{"base_unit"} } keys(%{$units})))) { - map({ push(@unit_list, $units->{$_}); } - sort({ ($units->{$a}->{"resolved_factor"} * 1) <=> ($units->{$b}->{"resolved_factor"} * 1) } - grep({ $units->{$_}->{"resolved_base_unit"} eq $name } keys(%{$units})))); - } + @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units})); + my $i = 1; foreach (@unit_list) { - $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"}, 5) if ($_->{"factor"}); + $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"}); $_->{"UNITLANGUAGES"} = []; foreach my $lang (@languages) { push(@{ $_->{"UNITLANGUAGES"} }, @@ -3558,12 +2875,15 @@ sub edit_units { $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 })); + "LANGUAGES" => \@languages, + "updownlink" => $updownlink })); $lxdebug->leave_sub(); } @@ -3573,7 +2893,8 @@ sub add_unit { $form->isblank("new_name", $locale->text("The name is missing.")); $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}); - $form->show_generic_error($locale->text("A unit with this name does already exist.")) if ($units->{$form->{"new_name"}}); + $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"}) { @@ -3698,3 +3019,228 @@ sub save_unit { $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(); +}