From: Sven Schöling Date: Thu, 27 Oct 2011 12:39:33 +0000 (+0200) Subject: Merge branch 'master' of vc.linet-services.de:public/lx-office-erp X-Git-Tag: release-2.7.0beta1~194 X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/commitdiff_plain/45970e731c7e0c8a3d469a1c344af20c18987c20?hp=6ae13887a4bd2fb056010ae7bd22b652c8c5d116 Merge branch 'master' of vc.linet-services.de:public/lx-office-erp --- diff --git a/SL/AM.pm b/SL/AM.pm index ab712c852..70f56f925 100644 --- a/SL/AM.pm +++ b/SL/AM.pm @@ -1333,6 +1333,7 @@ sub retrieve_units { $main::lxdebug->enter_sub(); my ($self, $myconfig, $form, $prefix) = @_; + $prefix ||= ''; my $dbh = $form->get_standard_dbh; diff --git a/SL/Auth.pm b/SL/Auth.pm index 7ca8d0bfd..37586b8ff 100644 --- a/SL/Auth.pm +++ b/SL/Auth.pm @@ -512,7 +512,7 @@ sub restore_session { my $self = shift; $session_id = $::request->{cgi}->cookie($self->get_session_cookie_name()); - $session_id =~ s|[^0-9a-f]||g; + $session_id =~ s|[^0-9a-f]||g if $session_id; $self->{SESSION} = { }; diff --git a/SL/CA.pm b/SL/CA.pm index c200b664e..52d2b0baf 100644 --- a/SL/CA.pm +++ b/SL/CA.pm @@ -84,7 +84,7 @@ sub all_accounts { $amount{ $ref->{accno} } = $ref->{amount}; } - my $where = "AND c.id = $chart_id" if ($chart_id ne ''); + my $where = $chart_id ne '' ? "AND c.id = $chart_id" : ''; $query = qq{ SELECT diff --git a/SL/Common.pm b/SL/Common.pm index c0bca0195..371bb8a7d 100644 --- a/SL/Common.pm +++ b/SL/Common.pm @@ -496,8 +496,8 @@ sub save_email_status { $intnotes .= "\n\n" if ($intnotes); - my $cc = $main::locale->text('Cc') . ": $form->{cc}\n" if $form->{cc}; - my $bcc = $main::locale->text('Bcc') . ": $form->{bcc}\n" if $form->{bcc}; + my $cc = $form->{cc} ? $main::locale->text('Cc') . ": $form->{cc}\n" : ''; + my $bcc = $form->{bcc} ? $main::locale->text('Bcc') . ": $form->{bcc}\n" : ''; my $now = scalar localtime; $intnotes .= $main::locale->text('[email]') . "\n" diff --git a/SL/Controller/Helper/ParseFilter.pm b/SL/Controller/Helper/ParseFilter.pm new file mode 100644 index 000000000..3753d1618 --- /dev/null +++ b/SL/Controller/Helper/ParseFilter.pm @@ -0,0 +1,302 @@ +package SL::Controller::Helper::ParseFilter; + +use strict; + +use Exporter qw(import); +our @EXPORT = qw(parse_filter); + +use DateTime; +use SL::Helper::DateTime; +use List::MoreUtils qw(uniq); +use Data::Dumper; + +my %filters = ( + date => sub { DateTime->from_lxoffice($_[0]) }, + number => sub { $::form->parse_amount(\%::myconfig, $_[0]) }, + percent => sub { $::form->parse_amount(\%::myconfig, $_[0]) / 100 }, + head => sub { $_[0] . '%' }, + tail => sub { '%' . $_[0] }, + substr => sub { '%' . $_[0] . '%' }, +); + +my %methods = ( + lt => sub { +{ lt => $_[0] } }, + gt => sub { +{ gt => $_[0] } }, + ilike => sub { +{ ilike => $_[0] } }, + like => sub { +{ like => $_[0] } }, + enable => sub { ;;;; }, +); + +sub parse_filter { + my ($filter, %params) = @_; + + my $hint_objects = $params{with_objects} || []; + + my ($flattened, $objects) = _pre_parse($filter, $hint_objects, '', %params); + + my $query = _parse_filter($flattened, %params); + + _launder_keys($filter) unless $params{no_launder}; + + return + ($query && @$query ? (query => $query) : ()), + ($objects && @$objects ? ( with_objects => [ uniq @$objects ]) : ()); +} + +sub _launder_keys { + my ($filter) = @_; + return unless ref $filter eq 'HASH'; + my @keys = keys %$filter; + for my $key (@keys) { + my $orig = $key; + $key =~ s/:/_/g; + $filter->{$key} = $filter->{$orig}; + _launder_keys($filter->{$key}); + }; + + return $filter; +} + +sub _pre_parse { + my ($filter, $with_objects, $prefix, %params) = @_; + + return () unless 'HASH' eq ref $filter; + $with_objects ||= []; + + my @result; + + while (my ($key, $value) = each %$filter) { + next if !defined $value || $value eq ''; # 0 is fine + if ('HASH' eq ref $value) { + my ($query, $more_objects) = _pre_parse($value, $with_objects, _prefix($prefix, $key)); + push @result, @$query if $query; + push @$with_objects, $key, ($more_objects ? @$more_objects : ()); + } else { + push @result, _prefix($prefix, $key) => $value; + } + } + + return \@result, $with_objects; +} + +sub _parse_filter { + my ($flattened, %params) = @_; + + return () unless 'ARRAY' eq ref $flattened; + + my %sorted = ( @$flattened ); + + my @keys = sort { length($b) <=> length($a) } keys %sorted; + for my $key (@keys) { + next unless $key =~ /^(.*\b)::$/; + $sorted{$1 . '::' . delete $sorted{$key} } = delete $sorted{$1} if $sorted{$1} && $sorted{$key}; + } + + my %result; + while (my ($key, $value) = each %sorted) { + ($key, $value) = _apply_all($key, $value, qr/\b:(\w+)/, { %filters, %{ $params{filters} || {} } }); + ($key, $value) = _apply_all($key, $value, qr/\b::(\w+)/, { %methods, %{ $params{methods} || {} } }); + $result{$key} = $value; + } + return [ %result ]; +} + +sub _prefix { + join '.', grep $_, @_; +} + +sub _apply { + my ($value, $name, $filters) = @_; + return $value unless $name && $filters->{$name}; + return [ map { _apply($_, $name, $filters) } @$value ] if 'ARRAY' eq ref $value; + return $filters->{$name}->($value); +} + +sub _apply_all { + my ($key, $value, $re, $subs) = @_; + + while ($key =~ s/$re//) { + $value = _apply($value, $1, $subs); + } + + return $key, $value; +} + +1; + +__END__ + +=head1 NAME + +SL::Controller::Helper::ParseFilter - Convert a form filter spec into a RDBO get_all filter + +=head1 SYNOPSIS + + use SL::Controller::Helper::ParseFilter; + SL::DB::Object->get_all(parse_filter($::form->{filter})); + + # or more complex + SL::DB::Object->get_all(parse_filter($::form->{filter}, + with_objects => [ qw(part customer) ])); + +=head1 DESCRIPTION + +A search filter will usually search for things in relations of the actual +search target. A search for sales orders may be filtered by the name of the +customer. L alloes you to search for these by filtering them prefixed with their table: + + query => [ + 'customer.name' => 'John Doe', + 'department.description' => [ ilike => '%Sales%' ], + 'orddate' => [ lt => DateTime->today ], + ] + +Unfortunately, if you specify them in you form as these strings, the form +parser will convert them into nested structures like this: + + $::form = bless { + filter => { + customer => { + name => 'John Doe', + }, + }, + }, Form; + +And the substring match requires you to recognize the ilike, and modify the value. + +C tries to ease this by recognizing these structures and +providing suffixes for common search patterns. + +=head1 FUNCTIONS + +=over 4 + +=item C + +First argument is the filter from form. It is highly recommended that you put +all filter attributes into a named container as to not confuse them with the +rest of your form. + +Nested structures will be parsed and interpreted as foreign references. For +example if you search for Ls, this input will search for those with a +specific L: + + [% L.select_tag('filter.salesman.id', ...) %] + +Additionally you can add modifier to the name to set a certain method: + + [% L.input_tag('filter.department.description:substr::ilike', ...) %] + +This will add the "% .. %" wildcards for substr matching in SQL, and add an +C<< ilike => $value >> block around it to match case insensitively. + +As a rule all value filters require a single colon and must be placed before +match method suffixes, which are appended with 2 colons. See below for a full +list of modifiers. + +The reason for the method being last is that it is possible to specify the +method in another input. Suppose you want a date input and a separate +before/after/equal select, you can use the following: + + [% L.date_tag('filter.appointed_date:date', ... ) %] + +and later + + [% L.select_tag('filter.appointed_date::', ... ) %] + +The special empty method will be used to set the method for the previous +method-less input. + +=item Laundering filter + +Unfortunately Template cannot parse the postfixes if you want to +rerender the filter. For this reason all colons filter keys are by +default laundered into underscores. If you don't want this to happen +pass C<< no_launder => 1 >> as a parameter. A full select_tag then +loks like this: + + [% L.input_tag('filter.price:number::lt', filter.price_number__lt) %] + + +=back + +=head1 FILTERS (leading with :) + +The following filters are built in, and can be used. + +=over 4 + +=item date + +Parses the input string with C<< DateTime->from_lxoffice >> + +=item number + +Pasres the input string with C<< Form->parse_amount >> + +=item percent + +Parses the input string with C<< Form->parse_amount / 100 >> + +=item head + +Adds "%" at the end of the string. + +=item tail + +Adds "%" at the end of the string. + +=item substr + +Adds "% .. %" around the search string. + +=back + +=head2 METHODS (leading with ::) + +=over 4 + +=item lt + +=item gt + +=item ilike + +=item like + +All these are recognized like the L methods. + +=back + +=head1 BUGS AND CAVEATS + +This will not properly handle multiple versions of the same object in different +context. + +Suppose you want all Ls which have either themselves a certain +customer, or are linked to a L with this customer, the +following will not work as you expect: + + # does not work! + L.input_tag('customer.name:substr::ilike', ...) + L.input_tag('invoice.customer.name:substr::ilike', ...) + +This will sarch for orders whoe invoice has the _same_ customer, which matches +both inputs. This is because tables are aliased by their name and not by their +position in with_objects. + +=head1 TODO + +=over 4 + +=item * + +Additional filters shoud be pluggable. + +=back + +=head1 AUTHOR + +Sven Schöling Es.schoeling@linet-services.deE + +=cut diff --git a/SL/DATEV.pm b/SL/DATEV.pm index 6c6f1c744..7f38c88c1 100644 --- a/SL/DATEV.pm +++ b/SL/DATEV.pm @@ -942,7 +942,7 @@ sub kne_stammdatenexport { push @values, $form->{accnoto}; } - my $where_str = ' WHERE ' . join(' AND ', map { "($_)" } @where) if (scalar @where); + my $where_str = @where ? ' WHERE ' . join(' AND ', map { "($_)" } @where) : ''; my $query = qq|SELECT c.accno, c.description FROM chart c diff --git a/SL/DB/Helper/Sorted.pm b/SL/DB/Helper/Sorted.pm index 9442c842e..1b6c42a3c 100644 --- a/SL/DB/Helper/Sorted.pm +++ b/SL/DB/Helper/Sorted.pm @@ -47,7 +47,7 @@ sub _get_sort_spec { sub _make_sort_spec { my ($class) = @_; - my %sort_spec = $class->_sort_spec if defined &{ "${class}::_sort_spec" }; + my %sort_spec = defined &{ "${class}::_sort_spec" } ? $class->_sort_spec : (); my $meta = $class->object_class->meta; diff --git a/SL/DO.pm b/SL/DO.pm index 5b5cf1d13..0d2a5ec21 100644 --- a/SL/DO.pm +++ b/SL/DO.pm @@ -408,7 +408,7 @@ sub mark_orders_if_delivered { 'to_table' => 'delivery_orders', 'to_id' => $params{do_id}); - my ($oe_id) = $links[0]->{from_id} if (scalar @links); + my $oe_id = @links ? $links[0]->{from_id} : undef; return $main::lxdebug->leave_sub() if (!$oe_id); diff --git a/SL/Form.pm b/SL/Form.pm index da832f871..15d66cec9 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -2341,7 +2341,7 @@ sub _get_taxcharts { $key = $params; } - my $where = ' WHERE ' . join(' AND ', map { "($_)" } @where) if (@where); + my $where = @where ? ' WHERE ' . join(' AND ', map { "($_)" } @where) : ''; my $query = qq|SELECT * FROM tax $where ORDER BY taxkey|; @@ -2456,7 +2456,7 @@ sub _get_customers { my $options = ref $key eq 'HASH' ? $key : { key => $key }; $options->{key} ||= "all_customers"; - my $limit_clause = "LIMIT $options->{limit}" if $options->{limit}; + my $limit_clause = $options->{limit} ? "LIMIT $options->{limit}" : ''; my @where; push @where, qq|business_id IN (SELECT id FROM business WHERE salesman)| if $options->{business_is_salesman}; @@ -3665,8 +3665,8 @@ sub prepare_for_printing { $extension = 'xls'; } - my $printer_code = '_' . $self->{printer_code} if $self->{printer_code}; - my $email_extension = '_email' if -f "$self->{templates}/$self->{formname}_email${language}${printer_code}.${extension}"; + my $printer_code = $self->{printer_code} ? '_' . $self->{printer_code} : ''; + my $email_extension = -f "$::myconfig{templates}/$self->{formname}_email${language}.${extension}" ? '_email' : ''; $self->{IN} = "$self->{formname}${email_extension}${language}${printer_code}.${extension}"; # Format dates. diff --git a/SL/IC.pm b/SL/IC.pm index 82b43cd4c..8fd928167 100644 --- a/SL/IC.pm +++ b/SL/IC.pm @@ -1048,7 +1048,7 @@ sub all_parts { my $select_clause = join ', ', map { $token_builder->($_, 1) } @select_tokens; my $join_clause = join ' ', @joins{ grep $joins_needed{$_}, @join_order }; my $where_clause = join ' AND ', map { "($_)" } @where_tokens; - my $group_clause = ' GROUP BY ' . join ', ', map { $token_builder->($_) } @group_tokens if scalar @group_tokens; + my $group_clause = @group_tokens ? ' GROUP BY ' . join ', ', map { $token_builder->($_) } @group_tokens : ''; my %oe_flag_to_cvar = ( bought => 'invoice', diff --git a/SL/IS.pm b/SL/IS.pm index c9a44281d..3aa0d3ca9 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -1440,7 +1440,7 @@ sub retrieve_invoice { my ($sth, $ref, $query); - my $query_transdate = ", current_date AS invdate" if !$form->{id}; + my $query_transdate = !$form->{id} ? ", current_date AS invdate" : ''; $query = qq|SELECT diff --git a/SL/OE.pm b/SL/OE.pm index bfa43f235..969402692 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -190,7 +190,7 @@ SQL } if ($form->{periodic_invoices_active} ne $form->{periodic_invoices_inactive}) { - my $not = 'NOT' if ($form->{periodic_invoices_inactive}); + my $not = $form->{periodic_invoices_inactive} ? 'NOT' : ''; $query .= qq| AND ${not} COALESCE(pcfg.active, 'f')|; } diff --git a/SL/Projects.pm b/SL/Projects.pm index c25e75ae3..d3df51fdd 100644 --- a/SL/Projects.pm +++ b/SL/Projects.pm @@ -104,7 +104,7 @@ sub search_projects { } - my $where = 'WHERE ' . join(' AND ', map { "($_)" } @filters) if (scalar @filters); + my $where = @filters ? 'WHERE ' . join(' AND ', map { "($_)" } @filters) : ''; my $sortorder = $params{sort} ? $params{sort} : "projectnumber"; $sortorder =~ s/[^a-z_]//g; diff --git a/SL/RecordLinks.pm b/SL/RecordLinks.pm index cef2c4df0..da63872d4 100644 --- a/SL/RecordLinks.pm +++ b/SL/RecordLinks.pm @@ -193,7 +193,7 @@ sub delete { add_token(\@where_tokens, \@where_values, col => $col, val => $params{$col}) if $params{$col}; } - my $where = "WHERE ". join ' AND ', map { "($_)" } @where_tokens if scalar @where_tokens; + my $where = @where_tokens ? "WHERE ". join ' AND ', map { "($_)" } @where_tokens : ''; my $query = "DELETE FROM record_links $where"; do_query($form, $dbh, $query, @where_values); diff --git a/SL/ReportGenerator.pm b/SL/ReportGenerator.pm index 441eb159d..6b9990180 100644 --- a/SL/ReportGenerator.pm +++ b/SL/ReportGenerator.pm @@ -564,8 +564,8 @@ sub generate_pdf_content { my $font_height = $font_size + 2 * $padding; my $title_font_height = $font_size + 2 * $padding; - my $header_height = 2 * $title_font_height if ($opts->{title}); - my $footer_height = 2 * $font_height if ($pdfopts->{number}); + my $header_height = $opts->{title} ? 2 * $title_font_height : undef; + my $footer_height = $pdfopts->{number} ? 2 * $font_height : undef; my $top_text_height = 0; diff --git a/SL/SEPA.pm b/SL/SEPA.pm index 32e763cdb..ced75be7e 100644 --- a/SL/SEPA.pm +++ b/SL/SEPA.pm @@ -305,7 +305,7 @@ sub list_exports { push @where, 'se.vc = ?'; push @values, $vc; - my $where = ' WHERE ' . join(' AND ', map { "(${_})" } @where) if (@where); + my $where = @where ? ' WHERE ' . join(' AND ', map { "(${_})" } @where) : ''; my $query = qq|SELECT se.id, se.employee_id, se.executed, se.closed, itime::date AS export_date, diff --git a/SL/USTVA.pm b/SL/USTVA.pm index 1cec7447c..abbf4a32c 100644 --- a/SL/USTVA.pm +++ b/SL/USTVA.pm @@ -113,8 +113,8 @@ sub report_variables { my $attribute = $arg_ref->{attribute}; # my $dec_places = (defined $arg_ref->{dec_places}) ? $arg_ref->{dec_places}:undef; - my $where_type = "AND tax.report_headings.type = '$type'" if ( $type ); - my $where_dcp = "AND tax.report_variables.dec_places = '$dec_places'" if ( defined $dec_places ); + my $where_type = $type ? "AND tax.report_headings.type = '$type'" : ''; + my $where_dcp = defined $dec_places ? "AND tax.report_variables.dec_places = '$dec_places'" : ''; my $query = qq| SELECT $attribute diff --git a/SL/WH.pm b/SL/WH.pm index 04b1914e0..2a5039d29 100644 --- a/SL/WH.pm +++ b/SL/WH.pm @@ -351,7 +351,7 @@ sub get_warehouse_journal { $sort_order = $filter{order} unless $sort_order; my $sort_spec = "${sort_col} " . ($sort_order ? " DESC" : " ASC"); - my $where_clause = join(" AND ", @filter_ary) . " AND " if (@filter_ary); + my $where_clause = @filter_ary ? join(" AND ", @filter_ary) . " AND " : ''; $select_tokens{'trans'} = { "parts_id" => "i1.parts_id", diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index 111e14e94..b6996d169 100644 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -2051,7 +2051,8 @@ sub show_am_history { my $dbh = $form->dbconnect(\%myconfig); - my $restriction = qq| AND (| . join(' OR ', map { " addition = " . $dbh->quote($_) } split(m/\,/, $form->{einschraenkungen})) . qq|)| if $form->{einschraenkungen}; + my $restriction; + $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+$/) { diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index 6d24657f3..f62294eaa 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -285,7 +285,8 @@ sub form_header { my $notes = qq||; - my $department = qq| + my $department; + $department = qq| | . $locale->text('Department') . qq| diff --git a/bin/mozilla/gl.pl b/bin/mozilla/gl.pl index 6ef1ca3e3..625490dc8 100644 --- a/bin/mozilla/gl.pl +++ b/bin/mozilla/gl.pl @@ -234,7 +234,8 @@ sub search { } (@{ $form->{all_departments} || [] }); } - my $department = qq| + my $department; + $department = qq| | . $locale->text('Department') . qq| @@ -1017,7 +1018,7 @@ sub display_rows { my $projectnumber_hidden = qq| |; - my $copy2credit = 'onkeyup="copy_debit_to_credit()"' if $i == 1; + my $copy2credit = $i == 1 ? 'onkeyup="copy_debit_to_credit()"' : ''; print qq| $accno @@ -1079,10 +1080,9 @@ sub form_header { $form->{title} = $locale->text("$title General Ledger Transaction"); my $readonly = ($form->{id}) ? "readonly" : ""; - my $show_details_checked = "checked" if $form->{show_details}; - - my $ob_transaction_checked = "checked" if $form->{ob_transaction}; - my $cb_transaction_checked = "checked" if $form->{cb_transaction}; + my $show_details_checked = $form->{show_details} ? "checked" : ''; + my $ob_transaction_checked = $form->{ob_transaction} ? "checked" : ''; + my $cb_transaction_checked = $form->{cb_transaction} ? "checked" : ''; # $locale->text('Add General Ledger Transaction') # $locale->text('Edit General Ledger Transaction') @@ -1410,7 +1410,7 @@ $follow_ups_block } else { if ($form->{draft_id}) { - my $remove_draft_checked = 'checked' if ($form->{remove_draft}); + my $remove_draft_checked = $form->{remove_draft} ? 'checked' : ''; print qq|

\n| . qq| | . qq| \n| diff --git a/bin/mozilla/ic.pl b/bin/mozilla/ic.pl index 215ec16ab..a30378123 100644 --- a/bin/mozilla/ic.pl +++ b/bin/mozilla/ic.pl @@ -1273,7 +1273,7 @@ sub generate_report { my %subtotals = map { $_ => 0 } ('onhand', @subtotal_columns); my %totals = map { $_ => 0 } @subtotal_columns; my $idx = 0; - my $same_item = $form->{parts}[0]{ $form->{sort} } if (scalar @{ $form->{parts} }); + my $same_item = @{ $form->{parts} } ? $form->{parts}[0]{ $form->{sort} } : undef; my $defaults = AM->get_defaults(); diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index a4e027d6c..2d23c76ae 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -359,7 +359,7 @@ sub display_row { # calculate onhand if ($form->{"id_$i"}) { my $part = IC->get_basic_part_info(id => $form->{"id_$i"}); - my $onhand_color = 'color="#ff0000"' if $part->{onhand} < $part->{rop}; + my $onhand_color = $part->{onhand} < $part->{rop} ? 'color="#ff0000"' : ''; push @ROW2, { value => sprintf "%s %s %s", $locale->text('On Hand'), $onhand_color, @@ -1457,7 +1457,7 @@ sub print_form { $extension = 'xls'; } - my $email_extension = '_email' if (($form->{media} eq 'email') && (-f "$myconfig{templates}/$form->{formname}_email$form->{language}${printer_code}.${extension}")); + my $email_extension = (($form->{media} eq 'email') && (-f "$myconfig{templates}/$form->{formname}_email$form->{language}${printer_code}.${extension}")) ? '_email' : ''; $form->{IN} = "$form->{formname}${email_extension}$form->{language}${printer_code}.${extension}"; diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index 19f546db3..686de618b 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -489,7 +489,7 @@ sub update { $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate}) unless $recursive_call; $form->{print_and_post} = 0 if $form->{second_run}; - my $taxincluded = "checked" if $form->{taxincluded}; + my $taxincluded = $form->{taxincluded} ? "checked" : ''; $form->{update} = 1; &check_name("customer"); diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index 24540eed8..c9ddfa5be 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -1301,7 +1301,10 @@ sub invoice { $form->{quodate} = $form->{transdate}; } - my $payment_id = $form->{payment_id} if $form->{payment_id}; + my $payment_id; + if ($form->{payment_id}) { + $payment_id = $form->{payment_id}; + } # if the name changed get new values if (&check_name($form->{vc})) { diff --git a/bin/mozilla/pe.pl b/bin/mozilla/pe.pl index 532dcfac5..a9cee792d 100644 --- a/bin/mozilla/pe.pl +++ b/bin/mozilla/pe.pl @@ -42,604 +42,183 @@ use strict; # end of main sub add { - $main::lxdebug->enter_sub(); + $::lxdebug->enter_sub; + $::auth->assert('config'); - $main::auth->assert('config'); + $::form->{title} = "Add"; + $::form->{callback} ||= "$::form->{script}?action=add&type=$::form->{type}"; - my $form = $main::form; + call_sub("form_$::form->{type}"); - $form->{title} = "Add"; - - # construct callback - $form->{callback} = - "$form->{script}?action=add&type=$form->{type}" - unless $form->{callback}; - - call_sub("form_$form->{type}_header"); - call_sub("form_$form->{type}_footer"); - - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } sub edit { - $main::lxdebug->enter_sub(); + $::lxdebug->enter_sub; + $::auth->assert('config'); - $main::auth->assert('config'); + $::form->{title} = "Edit"; - my $form = $main::form; - my %myconfig = %main::myconfig; - - # show history button - $form->{javascript} = qq||; - #/show hhistory button - $form->{title} = "Edit"; - - if ($form->{type} eq 'partsgroup') { - PE->get_partsgroup(\%myconfig, \%$form); + if ($::form->{type} eq 'partsgroup') { + PE->get_partsgroup(\%::myconfig, $::form); } - if ($form->{type} eq 'pricegroup') { - PE->get_pricegroup(\%myconfig, \%$form); + if ($::form->{type} eq 'pricegroup') { + PE->get_pricegroup(\%::myconfig, $::form); } - call_sub("form_$form->{type}_header"); - call_sub("form_$form->{type}_footer"); + call_sub("form_$::form->{type}"); - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } sub search { - $main::lxdebug->enter_sub(); - - $main::auth->assert('config'); - - my $form = $main::form; - my $locale = $main::locale; - - my ($report, $sort, $number); - if ($form->{type} eq 'partsgroup') { - $report = "partsgroup_report"; - $sort = 'partsgroup'; - $form->{title} = $locale->text('Groups'); - - $number = qq| - - | . $locale->text('Group') . qq| - - -|; - - } - - # for pricesgroups - if ($form->{type} eq 'pricegroup') { - $report = "pricegroup_report"; - $sort = 'pricegroup'; - $form->{title} = $locale->text('Pricegroup'); + $::lxdebug->enter_sub; + $::auth->assert('config'); - $number = qq| - - | . $locale->text('Pricegroup') . qq| - - -|; + $::form->header; + print $::form->parse_html_template('pe/search', { + is_pricegroup => $::form->{type} eq 'pricegroup', + }); - } - - $form->header; - - print qq| - - -

{script}> - - -{type}> - - - - - - - - - - - - -
$form->{title}
- - $number - - - - -
 | . $locale->text('All') . qq| -  | . $locale->text('Orphaned') . qq|
-

- - - -
- -
- - - -|; - - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } sub save { - $main::lxdebug->enter_sub(); - - $main::auth->assert('config'); + $::lxdebug->enter_sub; + $::auth->assert('config'); - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; - - if ($form->{type} eq 'partsgroup') { - $form->isblank("partsgroup", $locale->text('Group missing!')); - PE->save_partsgroup(\%myconfig, \%$form); - $form->redirect($locale->text('Group saved!')); + if ($::form->{type} eq 'partsgroup') { + $::form->isblank("partsgroup", $::locale->text('Group missing!')); + PE->save_partsgroup(\%::myconfig, $::form); + $::form->redirect($::locale->text('Group saved!')); } # choice pricegroup and save - if ($form->{type} eq 'pricegroup') { - $form->isblank("pricegroup", $locale->text('Pricegroup missing!')); - PE->save_pricegroup(\%myconfig, \%$form); - $form->redirect($locale->text('Pricegroup saved!')); + if ($::form->{type} eq 'pricegroup') { + $::form->isblank("pricegroup", $::locale->text('Pricegroup missing!')); + PE->save_pricegroup(\%::myconfig, $::form); + $::form->redirect($::locale->text('Pricegroup saved!')); } # saving the history - if(!exists $form->{addition} && $form->{id} ne "") { - $form->{snumbers} = qq|projectnumber_| . $form->{projectnumber}; - $form->{addition} = "SAVED"; - $form->save_history; + if(!exists $::form->{addition} && $::form->{id} ne "") { + $::form->{snumbers} = qq|projectnumber_| . $::form->{projectnumber}; + $::form->{addition} = "SAVED"; + $::form->save_history; } # /saving the history - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } sub delete { - $main::lxdebug->enter_sub(); - - $main::auth->assert('config'); - - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; + $::lxdebug->enter_sub; + $::auth->assert('config'); - PE->delete_tuple(\%myconfig, \%$form); + PE->delete_tuple(\%::myconfig, $::form); - if ($form->{type} eq 'partsgroup') { - $form->redirect($locale->text('Group deleted!')); + if ($::form->{type} eq 'partsgroup') { + $::form->redirect($::locale->text('Group deleted!')); } - if ($form->{type} eq 'pricegroup') { - $form->redirect($locale->text('Pricegroup deleted!')); + if ($::form->{type} eq 'pricegroup') { + $::form->redirect($::locale->text('Pricegroup deleted!')); } # saving the history - if(!exists $form->{addition}) { - $form->{snumbers} = qq|projectnumber_| . $form->{projectnumber}; - $form->{addition} = "DELETED"; - $form->save_history; + if(!exists $::form->{addition}) { + $::form->{snumbers} = qq|projectnumber_| . $::form->{projectnumber}; + $::form->{addition} = "DELETED"; + $::form->save_history; } # /saving the history - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } -sub continue { call_sub($main::form->{"nextsub"}); } +sub continue { call_sub($::form->{nextsub}); } sub partsgroup_report { - $main::lxdebug->enter_sub(); + $::lxdebug->enter_sub; + $::auth->assert('config'); - $main::auth->assert('config'); + $::form->{$_} = $::form->unescape($::form->{$_}) for qw(partsgroup); + PE->partsgroups(\%::myconfig, $::form); - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; + my $callback = build_std_url("action=partsgroup_report", qw(type status)); - map { $form->{$_} = $form->unescape($form->{$_}) } qw(partsgroup); - PE->partsgroups(\%myconfig, \%$form); + my $option = ''; + $option .= $::locale->text('All') if $::form->{status} eq 'all'; + $option .= $::locale->text('Orphaned') if $::form->{status} eq 'orphaned'; - my $callback = - "$form->{script}?action=partsgroup_report&type=$form->{type}&status=$form->{status}"; - - my ($option); - if ($form->{status} eq 'all') { - $option = $locale->text('All'); - } - if ($form->{status} eq 'orphaned') { - $option .= $locale->text('Orphaned'); - } - if ($form->{partsgroup}) { - $callback .= "&partsgroup=$form->{partsgroup}"; - $option .= "\n
" . $locale->text('Group') . " : $form->{partsgroup}"; + if ($::form->{partsgroup}) { + $callback .= "&partsgroup=$::form->{partsgroup}"; + $option .= ", " . $::locale->text('Group') . " : $::form->{partsgroup}"; } - my @column_index = $form->sort_columns(qw(partsgroup)); - my %column_header; - $column_header{partsgroup} = - qq|| . $locale->text('Group') . qq||; - - $form->{title} = $locale->text('Groups'); - - $form->header; - - print qq| - - - - - - - - - - - - - - - - -
$form->{title}
$option
- - -|; - - map { print "$column_header{$_}\n" } @column_index; - - print qq| - -|; - # escape callback - $form->{callback} = $callback; - - # escape callback for href - $callback = $form->escape($callback); - - my ($i, %column_data); - foreach my $ref (@{ $form->{item_list} }) { - - $i++; - $i %= 2; - - print qq| - -|; - - $column_data{partsgroup} = - qq||; - map { print "$column_data{$_}\n" } @column_index; - - print " - -"; - } - - print qq| -
{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&callback=$callback>$ref->{partsgroup}
-

- -
-
{script}> - - - -{type}> - - + $::form->{callback} = $callback; -
+ $::form->header; + print $::form->parse_html_template('pe/partsgroup_report', { + option => $option, + callback => $callback, + editlink => build_std_url('action=edit', qw(type status callback)), + }); - - -|; - - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } -sub form_partsgroup_header { - $main::lxdebug->enter_sub(); - - $main::auth->assert('config'); - - my $form = $main::form; - my $locale = $main::locale; - - $form->{title} = $locale->text("$form->{title} Group"); +sub form_partsgroup { + $::lxdebug->enter_sub; + $::auth->assert('config'); # $locale->text('Add Group') # $locale->text('Edit Group') + $::form->{title} = $::locale->text("$::form->{title} Group"); - $form->{partsgroup} =~ s/\"/"/g; - - $form->header; - - print qq| - - -
{script}> - -{id}> -{type}> - - - - - - - - - - - - -
$form->{title}
- - - - - -
| . $locale->text('Group') . qq|
-

-|; - - $main::lxdebug->leave_sub(); -} + $::form->header; + print $::form->parse_html_template('pe/partsgroup_form'); -sub form_partsgroup_footer { - $main::lxdebug->enter_sub(); - - $main::auth->assert('config'); - - my $form = $main::form; - my $locale = $main::locale; - - print qq| - - - -
-|; - - if ($form->{id} && $form->{orphaned}) { - print qq| -|; - } - -# button for saving history -print qq| - {id} - . qq|); name=history id=history value=| - . $locale->text('history') - . qq|>|; -# /button for saving history - print qq| -
- - - -|; - - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } -################################# -# get pricesgroups and build up html-code -# sub pricegroup_report { - $main::lxdebug->enter_sub(); + $::lxdebug->enter_sub; + $::auth->assert('config'); - $main::auth->assert('config'); + $::form->{$_} = $::form->unescape($::form->{$_}) for qw(pricegroup); + PE->pricegroups(\%::myconfig, $::form); - my $form = $main::form; - my %myconfig = %main::myconfig; - my $locale = $main::locale; + my $callback = build_std_url('action=pricegroup_report', qw(type status)); - map { $form->{$_} = $form->unescape($form->{$_}) } qw(pricegroup); - PE->pricegroups(\%myconfig, \%$form); + my $option = ''; + $option .= $::locale->text('All') if $::form->{status} eq 'all'; + $option .= $::locale->text('Orphaned') if $::form->{status} eq 'orphaned'; - my $callback = - "$form->{script}?action=pricegroup_report&type=$form->{type}&status=$form->{status}"; - - my $option; - if ($form->{status} eq 'all') { - $option = $locale->text('All'); - } - if ($form->{status} eq 'orphaned') { - $option .= $locale->text('Orphaned'); + if ($::form->{pricegroup}) { + $callback .= "&pricegroup=$::form->{pricegroup}"; + $option .= ", " . $::locale->text('Pricegroup') . " : $::form->{pricegroup}"; } - if ($form->{pricegroup}) { - $callback .= "&pricegroup=$form->{pricegroup}"; - $option .= - "\n
" . $locale->text('Pricegroup') . " : $form->{pricegroup}"; - } - - my @column_index = $form->sort_columns(qw(pricegroup)); - my %column_header; - $column_header{pricegroup} = - qq|| - . $locale->text('Pricegroup') - . qq||; - - $form->{title} = $locale->text('Pricegroup'); - - $form->header; - - print qq| - - - - - - - - - - - - - - - - -
$form->{title}
$option
- - -|; - - map { print "$column_header{$_}\n" } @column_index; - - print qq| - -|; # escape callback - $form->{callback} = $callback; - - # escape callback for href - $callback = $form->escape($callback); - - my ($i, %column_data); - foreach my $ref (@{ $form->{item_list} }) { - - $i++; - $i %= 2; + $::form->{callback} = $callback; - print qq| - -|; - $column_data{pricegroup} = - qq||; + $::form->header; + print $::form->parse_html_template('pe/pricegroup_report', { + option => $option, + callback => $callback, + editlink => build_std_url('action=edit', qw(type status callback)), + }); - map { print "$column_data{$_}\n" } @column_index; - - print " - -"; - } - - print qq| -
{script}?action=edit&type=$form->{type}&status=$form->{status}&id=$ref->{id}&callback=$callback>$ref->{pricegroup}
-

- -
-
{script}> - - - -{type}> - - - -
- - - -|; - - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } -####################### -#build up pricegroup_header -# -sub form_pricegroup_header { - $main::lxdebug->enter_sub(); - - $main::auth->assert('config'); - - my $form = $main::form; - my $locale = $main::locale; +sub form_pricegroup { + $::lxdebug->enter_sub; + $::auth->assert('config'); # $locale->text('Add Pricegroup') # $locale->text('Edit Pricegroup') + $::form->{title} = $::locale->text("$::form->{title} Pricegroup"); - $form->{title} = $locale->text("$form->{title} Pricegroup"); - - $form->{pricegroup} =~ s/\"/"/g; - - $form->header; - - print qq| - - -
{script}> - -{id}> -{type}> - - - - - - - - - - - - -
$form->{title}
- - - - - -
| . $locale->text('Preisgruppe') . qq|
-

-|; - - $main::lxdebug->leave_sub(); -} -###################### -#build up pricegroup_footer -# -sub form_pricegroup_footer { - $main::lxdebug->enter_sub(); - - $main::auth->assert('config'); - - my $form = $main::form; - my $locale = $main::locale; - - print qq| - - - -
-|; - - if ($form->{id} && $form->{orphaned}) { - print qq| -|; - } + $::form->header; + print $::form->parse_html_template('pe/pricegroup_form'); -# button for saving history -print qq| - {id} - . qq|); name=history id=history value=| - . $locale->text('history') - . qq|>|; -# /button for saving history - print qq| -
- - - -|; - - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } diff --git a/bin/mozilla/rp.pl b/bin/mozilla/rp.pl index 062c44f4e..dc1b15384 100644 --- a/bin/mozilla/rp.pl +++ b/bin/mozilla/rp.pl @@ -158,7 +158,8 @@ sub report { map { $form->{selectdepartment} .= "