X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=bin%2Fmozilla%2Fam.pl;h=137243877fcc6116fde8c2ea67963011a5412d11;hb=6ebad56e58db857141565f397c555524cba43109;hp=4d3a88f337f325e9e70ae4e28f90f56885e81f4b;hpb=08882e8ce50b1e317d313dac8f27d306dae4492d;p=kivitendo-erp.git diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index 4d3a88f33..137243877 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,326 +2845,498 @@ sub doclose { $lxdebug->leave_sub(); } -sub add_warehouse { +sub edit_units { $lxdebug->enter_sub(); - $form->{title} = "Add"; + $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_"); + AM->units_in_use(\%myconfig, $form, $units); + map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units})); - $form->{callback} = - "$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&password=$form->{password}" - unless $form->{callback}; + @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++; + } - &warehouse_header; - &form_footer; + $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 edit_warehouse { +sub add_unit { $lxdebug->enter_sub(); - $form->{title} = "Edit"; + $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"}}); - AM->get_warehouse(\%myconfig, \%$form); + 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"}})); - &warehouse_header; - &form_footer; + $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 list_warehouse { +sub set_unit_languages { $lxdebug->enter_sub(); - AM->warehouses(\%myconfig, \%$form); + my ($unit, $languages, $idx) = @_; - $form->{callback} = - "$form->{script}?action=list_warehouse&path=$form->{path}&login=$form->{login}&password=$form->{password}"; + $unit->{"LANGUAGES"} = []; - $callback = $form->escape($form->{callback}); + foreach my $lang (@{$languages}) { + push(@{ $unit->{"LANGUAGES"} }, + { "id" => $lang->{"id"}, + "localized" => $form->{"localized_${idx}_$lang->{id}"}, + "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"}, + }); + } - $form->{title} = $locale->text('Warehouses'); + $lxdebug->leave_sub(); +} - @column_index = qw(description); +sub save_unit { + $lxdebug->enter_sub(); - $column_header{description} = - qq|| - . $locale->text('Description') - . qq||; + $old_units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_"); + AM->units_in_use(\%myconfig, $form, $old_units); - $form->header; + @languages = AM->language(\%myconfig, $form, 1); - print qq| - + $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)); + } - - - - - - - - - - - -
$form->{title}
- - -|; + 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; + } - map { print "$column_header{$_}\n" } @column_index; + 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)); + } - print qq| - -|; + if ($form->{"delete_$i"}) { + push(@delete_units, $old_unit->{"name"}); + next; + } - foreach $ref (@{ $form->{ALL} }) { + $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i)); - $i++; - $i %= 2; + $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); + } - print qq| - -|; + 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; + } + } - $column_data{description} = - qq||; + foreach $unit (values(%{$new_units})) { + next if ($unit->{"unchanged_unit"}); - map { print "$column_data{$_}\n" } @column_index; + 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"})); + } + } + } - print qq| - -|; + 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 qq| -
{script}?action=edit_warehouse&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}
-

+ 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(); +} -
-{script}> +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); -{path}> -{login}> -{password}> + edit_units(); -|; + $lxdebug->leave_sub(); +} - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } +sub add_tax { + $lxdebug->enter_sub(); - print qq| -
+ $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 warehouse_header { +sub edit_tax { $lxdebug->enter_sub(); - $form->{title} = $locale->text("$form->{title} Warehouse"); + $form->{title} = $locale->text('Edit'); - # $locale->text('Add Warehouse') - # $locale->text('Edit Warehouse') + AM->get_tax(\%myconfig, \%$form); + _get_taxaccount_selection(); - $form->{description} =~ s/\"/"/g; + $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2); - if (($rows = $form->numtextrows($form->{description}, 60)) > 1) { - $description = - qq||; - } else { - $description = - qq||; - } + $form->header(); + + my $parameters_ref = { + }; + + # Ausgabe des Templates + print($form->parse_html_template2('am/edit_tax', $parameters_ref)); - $form->header; + $lxdebug->leave_sub(); +} - print qq| - +sub list_tax { + $lxdebug->enter_sub(); -
{script}> + AM->taxes(\%myconfig, \%$form); -{id}> - + map { $_->{rate} = $form->format_amount(\%myconfig, $_->{rate}, 2) } @{ $form->{TAX} }; - - - - - - - - - - - - -
$form->{title}
| . $locale->text('Description') . qq|$description

-|; + $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 save_warehouse { +sub _get_taxaccount_selection{ $lxdebug->enter_sub(); - $form->isblank("description", $locale->text('Description missing!')); - AM->save_warehouse(\%myconfig, \%$form); - $form->redirect($locale->text('Warehouse saved!')); + AM->get_tax_accounts(\%myconfig, \%$form); + + map { $_->{selected} = $form->{chart_id} == $_->{id} } @{ $form->{ACCOUNTS} }; $lxdebug->leave_sub(); } -sub delete_warehouse { +sub save_tax { $lxdebug->enter_sub(); - AM->delete_warehouse(\%myconfig, \%$form); - $form->redirect($locale->text('Warehouse deleted!')); + $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 continue { +sub delete_tax { $lxdebug->enter_sub(); - &{ $form->{nextsub} }; + AM->delete_tax(\%myconfig, \%$form); + $form->redirect($locale->text('Tax deleted!')); $lxdebug->leave_sub(); } -sub edit_units { +sub add_price_factor { $lxdebug->enter_sub(); - $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_"); - AM->units_in_use(\%myconfig, $form, $units); - map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units})); + $form->{title} = $locale->text('Add Price Factor'); + $form->{callback} ||= build_std_url('action=add_price_factor'); + $form->{fokus} = 'description'; - @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})))); - } - map({ $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"}, 5) if ($_->{"factor"}); } @unit_list); + $form->header(); + print $form->parse_html_template2('am/edit_price_factor'); - $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}); - $ddbox = AM->unit_select_data($units, undef, 1); + $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->{"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 })); + print $form->parse_html_template2('am/edit_price_factor'); $lxdebug->leave_sub(); } -sub add_unit { +sub list_price_factors { $lxdebug->enter_sub(); - $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"}}); + AM->get_all_price_factors(\%myconfig, \%$form); - 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"}})); + my $previous; + foreach my $current (@{ $form->{PRICE_FACTORS} }) { + if ($previous) { + $previous->{next_id} = $current->{id}; + $current->{previous_id} = $previous->{id}; + } - $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"}; - } + $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1); - AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, $form->{"unit_type"}); + $previous = $current; + } - $form->{"saved_message"} = $locale->text("The unit has been saved."); + $form->{callback} = build_std_url('action=list_price_factors'); + $form->{title} = $locale->text('Price Factors'); + $form->{url_base} = build_std_url('callback'); - edit_units(); + $form->header(); + print $form->parse_html_template2('am/list_price_factors'); $lxdebug->leave_sub(); } -sub save_unit { +sub save_price_factor { $lxdebug->enter_sub(); - $old_units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_"); - AM->units_in_use(\%myconfig, $form, $old_units); + $form->isblank("description", $locale->text('Description missing!')); + $form->isblank("factor", $locale->text('Factor missing!')); - $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)); - } + $form->{factor} = $form->parse_amount(\%myconfig, $form->{factor}); - 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; - next; - } + AM->save_price_factor(\%myconfig, $form); - 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)); - } + $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor saved!')) if ($form->{callback}); - if ($form->{"delete_$i"}) { - push(@delete_units, $old_unit->{"name"}); - next; - } + $form->redirect($locale->text('Price factor saved!')); - $form->isblank("name_$i", sprintf($locale->text("The name is missing in row %d."), $i)); + $lxdebug->leave_sub(); +} - $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; - } +sub delete_price_factor { + $lxdebug->enter_sub(); - 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; - } - } + AM->delete_price_factor(\%myconfig, \%$form); - foreach $unit (values(%{$new_units})) { - next if ($unit->{"unchanged_unit"}); + $form->{callback} .= '&MESSAGE=' . $form->escape($locale->text('Price factor deleted!')) if ($form->{callback}); - 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"})); - } - } - } + $form->redirect($locale->text('Price factor deleted!')); - AM->save_units(\%myconfig, $form, $form->{"unit_type"}, $new_units, \@delete_units); + $lxdebug->leave_sub(); +} - $form->{"saved_message"} = $locale->text("The units have been saved."); +sub swap_price_factors { + $lxdebug->enter_sub(); - edit_units(); + AM->swap_sortkeys(\%myconfig, $form, 'price_factors'); + list_price_factors(); $lxdebug->leave_sub(); } +