X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/f7b15d4334848fad1bcd0b569eff5139f9a6ba4d..69e526ee5:/bin/mozilla/am.pl diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index b3ec6045c..b3ca071c0 100644 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -42,12 +42,13 @@ use SL::Form; use SL::User; use SL::USTVA; use SL::Iconv; +use SL::Locale::String qw(t8); use SL::TODO; use SL::DB::Printer; use SL::DB::Tax; use SL::DB::Language; use SL::DB::Default; -use SL::DBUtils qw(selectall_array_query); +use SL::DBUtils qw(selectall_array_query conv_dateq); use CGI; require "bin/mozilla/common.pl"; @@ -108,7 +109,6 @@ sub edit_account { } &account_header; - &form_footer; $main::lxdebug->leave_sub(); } @@ -371,6 +371,8 @@ sub account_header { my $ChartTypeIsAccount = ($form->{charttype} eq "A") ? "1":""; my $AccountIsPosted = ($form->{orphaned} ) ? "":"1"; + setup_am_edit_account_action_bar(); + $form->header(); my $parameters_ref = { @@ -614,207 +616,6 @@ sub delete_account { $main::lxdebug->leave_sub(); } -sub add_lead { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - - $main::auth->assert('config'); - - $form->{title} = "Add"; - - $form->{callback} = "am.pl?action=add_lead" unless $form->{callback}; - - &lead_header; - &form_footer; - - $main::lxdebug->leave_sub(); -} - -sub edit_lead { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - - $main::auth->assert('config'); - - $form->{title} = "Edit"; - - AM->get_lead(\%myconfig, \%$form); - - &lead_header; - - $form->{orphaned} = 1; - &form_footer; - - $main::lxdebug->leave_sub(); -} - -sub list_lead { - $::lxdebug->enter_sub; - $::auth->assert('config'); - - AM->lead(\%::myconfig, $::form); - - $::form->{callback} = "am.pl?action=list_lead"; - $::form->{title} = $::locale->text('Lead'); - - $::form->header; - print $::form->parse_html_template('am/lead_list'); - - $::lxdebug->leave_sub; -} - -sub lead_header { - $::lxdebug->enter_sub; - $::auth->assert('config'); - - # $locale->text('Add Lead') - # $locale->text('Edit Lead') - $::form->{title} = $::locale->text("$::form->{title} Lead"); - - $::form->header; - print $::form->parse_html_template('am/lead_header'); - - $::lxdebug->leave_sub; -} - -sub save_lead { - $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!')); - AM->save_lead(\%myconfig, \%$form); - $form->redirect($locale->text('lead saved!')); - - $main::lxdebug->leave_sub(); -} - -sub delete_lead { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; - - $main::auth->assert('config'); - - AM->delete_lead(\%myconfig, \%$form); - $form->redirect($locale->text('lead deleted!')); - - $main::lxdebug->leave_sub(); -} - -sub add_language { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - - $main::auth->assert('config'); - - $form->{title} = "Add"; - - $form->{callback} = "am.pl?action=add_language" unless $form->{callback}; - - &language_header; - &form_footer; - - $main::lxdebug->leave_sub(); -} - -sub edit_language { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - - $main::auth->assert('config'); - - $form->{title} = "Edit"; - - AM->get_language(\%myconfig, \%$form); - - &language_header; - - $form->{orphaned} = 1; - &form_footer; - - $main::lxdebug->leave_sub(); -} - -sub list_language { - $::lxdebug->enter_sub; - $::auth->assert('config'); - - AM->language(\%::myconfig, $::form); - - $::form->{callback} = "am.pl?action=list_language"; - $::form->{title} = $::locale->text('Languages'); - - $::form->header; - - print $::form->parse_html_template('am/language_list'); - - $::lxdebug->leave_sub; -} - -sub language_header { - $::lxdebug->enter_sub; - $::auth->assert('config'); - - # $locale->text('Add Language') - # $locale->text('Edit Language') - $::form->{title} = $::locale->text("$::form->{title} Language"); - - $::form->header; - - print $::form->parse_html_template('am/language_header', { - numberformats => [ '1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00" ], - dateformats => [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ], - }); - - $::lxdebug->leave_sub; -} - -sub save_language { - $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('Language missing!')); - $form->isblank("template_code", $locale->text('Template Code missing!')); - $form->isblank("article_code", $locale->text('Article Code missing!')); - AM->save_language(\%myconfig, \%$form); - $form->redirect($locale->text('Language saved!')); - - $main::lxdebug->leave_sub(); -} - -sub delete_language { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; - - $main::auth->assert('config'); - - AM->delete_language(\%myconfig, \%$form); - $form->redirect($locale->text('Language deleted!')); - - $main::lxdebug->leave_sub(); -} - sub _build_cfg_options { my $form = $main::form; my %myconfig = %main::myconfig; @@ -914,6 +715,8 @@ sub config { $form->{title} = $locale->text('Edit Preferences for #1', $::myconfig{login}); + setup_am_config_action_bar(); + $form->header(); $form->{full_signature} = $form->create_email_signature(); @@ -1005,7 +808,7 @@ sub edit_units { 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 @languages = @{ SL::DB::Manager::Language->get_all_sorted }; my @unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units})); @@ -1015,11 +818,11 @@ sub edit_units { $_->{"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"}, + { "idx" => $i, + "unit" => $_->{"name"}, + "language_id" => $lang->id, + "localized" => $_->{"LANGUAGES"}->{$lang->template_code}->{"localized"}, + "localized_plural" => $_->{"LANGUAGES"}->{$lang->template_code}->{"localized_plural"}, }); } $i++; @@ -1064,11 +867,11 @@ sub add_unit { } my @languages; - foreach my $lang (AM->language(\%myconfig, $form, 1)) { + foreach my $lang (@{ SL::DB::Manager::Language->get_all_sorted }) { 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}"}, + push(@languages, { "id" => $lang->id, + "localized" => $form->{"new_localized_" . $lang->id}, + "localized_plural" => $form->{"new_localized_plural_" . $lang->id}, }); } @@ -1094,9 +897,9 @@ sub set_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}"}, + { "id" => $lang->id, + "localized" => $form->{"localized_${idx}_" . $lang->id}, + "localized_plural" => $form->{"localized_plural_${idx}_" . $lang->id}, }); } @@ -1115,7 +918,7 @@ sub save_unit { 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 @languages = @{ SL::DB::Manager::Language->get_all_sorted }; my $new_units = {}; my @delete_units = (); @@ -1251,14 +1054,22 @@ sub show_am_history { $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 $snumbers_where = ''; + my $snumbers_value; + if ($form->{'searchid'}) { + $snumbers_where = ' WHERE snumbers = ?'; + $snumbers_value = $searchNo{$form->{'what2search'}} . '_' . $form->{'searchid'}; + } else { + $snumbers_where = ' WHERE snumbers ~ ?'; + $snumbers_value = '^' . $searchNo{$form->{'what2search'}}; + } + my $query = qq|SELECT trans_id AS id FROM history_erp $snumbers_where|; - my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query); + my @ids = grep { $_ * 1 } selectall_array_query($form, $dbh, $query, $snumbers_value); my $daten .= shift @ids; - $daten .= join '', map { " OR trans_id = $_" } @ids; - + if (scalar(@ids) > 0 ) { + $daten .= ' OR trans_id IN (' . join(',', @ids) . ')'; + } my ($sort, $sortby) = split(/\-\-/, $form->{order}); $sort =~ s/.*\.(.*)$/$1/; @@ -1299,10 +1110,10 @@ sub add_tax { $form->{expense} = 1; $form->{costs} = 1; + setup_am_edit_tax_action_bar(); $form->header(); my $parameters_ref = { -# ChartTypeIsAccount => $ChartTypeIsAccount, LANGUAGES => SL::DB::Manager::Language->get_all_sorted, }; @@ -1336,6 +1147,7 @@ sub edit_tax { $form->{rate} = $form->format_amount(\%myconfig, $form->{rate}, 2); + setup_am_edit_tax_action_bar(); $form->header(); my $parameters_ref = { @@ -1366,13 +1178,11 @@ sub list_tax { $form->{title} = $locale->text('Tax-O-Matic'); + setup_am_list_tax_action_bar(); $form->header(); - my $parameters_ref = { - }; - # Ausgabe des Templates - print($form->parse_html_template('am/list_tax', $parameters_ref)); + print($form->parse_html_template('am/list_tax')); $main::lxdebug->leave_sub(); } @@ -1443,111 +1253,6 @@ sub delete_tax { $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->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'); - - 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); - - foreach my $current (@{ $form->{PRICE_FACTORS} }) { - $current->{factor} = $form->format_amount(\%myconfig, $current->{factor} * 1); - } - - $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 add_warehouse { $main::lxdebug->enter_sub(); @@ -1675,3 +1380,86 @@ sub save_bin { $main::lxdebug->leave_sub(); } + +sub setup_am_config_action_bar { + my %params = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Save'), + submit => [ '#form', { action => "save_preferences" } ], + accesskey => 'enter', + ], + ); + } +} + +sub setup_am_edit_account_action_bar { + my %params = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + combobox => [ + action => [ + t8('Save'), + submit => [ '#form', { action => "save_account" } ], + disabled => $::form->{id} && !$::form->{orphaned} ? t8('The object is in use and cannot be changed.') + : undef, + accesskey => 'enter', + ], + + action => [ + t8('Save as new'), + submit => [ '#form', { action => "save_as_new_account" } ], + disabled => !$::form->{id} ? t8('The object has not been saved yet.') : undef, + ], + ], + + action => [ + t8('Delete'), + submit => [ '#form', { action => "delete_account" } ], + disabled => !$::form->{id} ? t8('The object has not been saved yet.') + : $::form->{id} && !$::form->{orphaned} ? t8('The object is in use and cannot be deleted.') + : undef, + confirm => t8('Do you really want to delete this object?'), + ], + ); + } +} + +sub setup_am_list_tax_action_bar { + my %params = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + link => [ + t8('Add'), + link => 'am.pl?action=add_tax', + ], + ); + } +} + +sub setup_am_edit_tax_action_bar { + my %params = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Save'), + submit => [ '#form', { action => "save_tax" } ], + accesskey => 'enter', + ], + + action => [ + t8('Delete'), + submit => [ '#form', { action => "delete_tax" } ], + disabled => !$::form->{id} ? t8('The object has not been saved yet.') + : !$::form->{orphaned} || $::form->{tax_already_used} ? t8('The object is in use and cannot be deleted.') + : undef, + confirm => t8('Do you really want to delete this object?'), + ], + ); + } +}