X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fcommon.pl;h=17dac992e529617cb37beeb279f52212b372cb4c;hb=6156d51ea0360382df95007e10a874f24f4dd81a;hp=e2bc13fcd8aa17d6fe6a0f4e4ad1439879ca41a5;hpb=8c7e44938a661e035f62840e1e177353240ace5d;p=kivitendo-erp.git diff --git a/bin/mozilla/common.pl b/bin/mozilla/common.pl index e2bc13fcd..17dac992e 100644 --- a/bin/mozilla/common.pl +++ b/bin/mozilla/common.pl @@ -14,8 +14,12 @@ use SL::DBUtils; use SL::Form; use SL::MoreCommon; +use strict; + sub build_std_url { - $lxdebug->enter_sub(2); + $main::lxdebug->enter_sub(2); + + my $form = $main::form; my $script = $form->{script}; @@ -40,151 +44,42 @@ sub build_std_url { my $url = "${script}?" . join('&', @parts); - $lxdebug->leave_sub(2); + $main::lxdebug->leave_sub(2); return $url; } # ------------------------------------------------------------------------- -## Customers/Vendors - -sub check_customer_or_vendor { - $lxdebug->enter_sub(); - - my ($field, $cov_selected_nextsub, $is_vendor) = @_; - - if ($form->{"f_${field}"} eq $form->{"f_old_${field}"}) { - $lxdebug->leave_sub(); - return 1; - } - - my $type = $is_vendor ? $locale->text("vendor") : $locale->text("customer"); - - my $old_form = save_form(); - $form->{"name"} = $form->{"f_${field}"}; - $form->{"obsolete"} = 1; - my $covs; - $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, "name", 1, $is_vendor); - restore_form($old_form); - - if (0 == scalar(@{$covs})) { - $form->header(); - $form->show_generic_error(sprintf($locale->text("There is no %s whose name matches '%s'."), $type, $form->{"f_${field}"})); - - $lxdebug->leave_sub(); - return 0; - - } - - if (1 != scalar(@{$covs})) { - # If there is more than one CoV with the same name - # then we have to check if the ID is set, too. Otherwise - # we'd be stuck in an endless loop. - if ($form->{"f_${field}_id"}) { - foreach my $cov (@{$covs}) { - if (($form->{"f_${field}_id"} == $cov->{"id"}) && - ($form->{"f_${field}"} eq $cov->{"name"})) { - $lxdebug->leave_sub(); - return 1; - } - } - } - - $form->{"cov_selected_nextsub"} = $cov_selected_nextsub; - $form->{"check_cov_field"} = $field; - select_customer_or_vendor("cov_selected", $is_vendor, @{$covs}); - $lxdebug->leave_sub(); - return 0; - } - - $form->{"f_${field}_id"} = $covs->[0]->{"id"}; - $form->{"f_${field}"} = $covs->[0]->{"name"}; - - $lxdebug->leave_sub(); - - return 1; -} - -sub select_customer_or_vendor { - $lxdebug->enter_sub(); - - my ($callback_sub, $is_vendor, @covs) = @_; - - my $old_form = save_form(); - - if (0 == scalar(@covs)) { - delete($form->{"name"}); - $form->{"obsolete"} = 1; - my $c = Common->retrieve_customers_or_vendors(\%myconfig, $form, "name", 1, $is_vendor); - restore_form($old_form); - @covs = @{$c}; - } - - $form->header(); - print($form->parse_html_template("generic/select_customer_or_vendor", - { "COVS" => \@covs, - "old_form" => $old_form, - "title" => $is_vendor ? $locale->text("Select a vendor") : $locale->text("Select a customer"), - "nextsub" => "select_cov_internal", - "callback_sub" => $callback_sub })); - - $lxdebug->leave_sub(); -} - -sub cov_selected { - $lxdebug->enter_sub(); - my ($new_id, $new_name) = @_; - - my $field = $form->{"check_cov_field"}; - delete($form->{"check_cov_field"}); - - $form->{"f_${field}_id"} = $new_id; - $form->{"f_${field}"} = $new_name; - $form->{"f_old_${field}"} = $new_name; - - &{ $form->{"cov_selected_nextsub"} }(); - - $lxdebug->leave_sub(); -} - -sub select_cov_internal { - $lxdebug->enter_sub(); - - my ($new_id, $new_name, $callback_sub); - - my $new_id = $form->{"new_id_" . $form->{"selection"}}; - my $new_name = $form->{"new_name_" . $form->{"selection"}}; - my $callback_sub = $form->{"callback_sub"}; - - restore_form($form->{"old_form"}); - - &{ $callback_sub }($new_id, $new_name); - - $lxdebug->leave_sub(); -} - sub select_part { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); my ($callback_sub, @parts) = @_; + my $form = $main::form; + my $locale = $main::locale; + my $remap_parts_id = 0; - if (defined($parts[0]->{"parts_id"}) && !defined($parts[0]->{"id"})) { + if (defined($parts[0]->{parts_id}) && !defined($parts[0]->{id})) { $remap_parts_id = 1; - map({ $_->{"id"} = $_->{"parts_id"}; } @parts); + map { $_->{id} = $_->{parts_id}; } @parts; } my $remap_partnumber = 0; - if (defined($parts[0]->{"partnumber"}) && !defined($parts[0]->{"number"})) { + if (defined($parts[0]->{partnumber}) && !defined($parts[0]->{number})) { $remap_partnumber = 1; - map({ $_->{"number"} = $_->{"partnumber"}; } @parts); + map { $_->{number} = $_->{partnumber}; } @parts; } my $has_charge = 0; - if (defined($parts[0]->{"chargenumber"})) { + if (defined($parts[0]->{chargenumber})) { $has_charge = 1; - map({ $_->{"has_charge"} = 1; } @parts); + map { $_->{has_charge} = 1; } @parts; + } + my $has_ean = 0; + if (defined($parts[0]->{ean})) { + $has_ean = 1; + map { $_->{has_ean} = 1; } @parts; } my $old_form = save_form(); @@ -197,18 +92,21 @@ sub select_part { "nextsub" => "select_part_internal", "callback_sub" => $callback_sub, "has_charge" => $has_charge, + "has_ean" => $has_ean, "remap_parts_id" => $remap_parts_id, "remap_partnumber" => $remap_partnumber }); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub select_part_internal { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; my ($new_item, $callback_sub); - my $re = "^new_.*_" . $form->{"selection"}; + my $re = "^new_.*_$form->{selection}\$"; foreach (grep /$re/, keys %{ $form }) { my $new_key = $_; @@ -227,325 +125,96 @@ sub select_part_internal { delete $new_item->{number}; } - my $callback_sub = $form->{callback_sub}; + $callback_sub = $form->{callback_sub}; restore_form($form->{old_form}); call_sub($callback_sub, $new_item); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub part_selection_internal { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - $order_by = "description"; + my $order_by = "description"; $order_by = $form->{"order_by"} if (defined($form->{"order_by"})); - $order_dir = 1; + my $order_dir = 1; $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"})); - %options = map { $_ => 1 } split m/:/, $form->{options}; + my %options; - map { $form->{$_} = 1 if ($options{$_}) } qw(no_services no_assemblies stockable); + foreach my $opt (split m/:/, $form->{options}) { + if ($opt =~ /=/) { + my ($key, $value) = split m/=/, $opt, 2; + $options{$key} = $value; + + } else { + $options{$opt} = 1; + } + } + + map { $form->{$_} = $options{$_} if ($options{$_}) } qw(no_services no_assemblies assemblies click_button); + + my $parts = Common->retrieve_parts(\%myconfig, $form, $order_by, $order_dir); + my $onload; - $parts = Common->retrieve_parts(\%myconfig, $form, $order_by, $order_dir); - map({ $parts->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$parts})); if (0 == scalar(@{$parts})) { $form->show_generic_information($locale->text("No part was found matching the search parameters.")); } elsif (1 == scalar(@{$parts})) { $onload = "part_selected('1')"; } - my $callback = "$form->{script}?action=part_selection_internal&"; - map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" } - (qw(partnumber description input_partnumber input_description input_partsid), grep({ /^[fl]_/ } keys %$form))); + map { $parts->[$_]->{selected} = $_ ? 0 : 1; } (0..$#{$parts}); + + my $callback = build_std_url('action=part_selection_internal', qw(partnumber description input_partnumber input_description input_partsid), + grep({ /^[fl]_/ } keys %{ $form })); - my @header_sort = qw(partnumber description); - my %header_title = ( "partnumber" => $locale->text("Part Number"), + my @header_sort = qw(partnumber description); + my %header_title = ( "partnumber" => $locale->text("Part Number"), "description" => $locale->text("Part description"), ); my @header = map(+{ "column_title" => $header_title{$_}, - "column" => $_, - "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir), + "column" => $_, + "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir), }, @header_sort); - $form->{"title"} = $locale->text("Select a part"); + $form->{formname} ||= 'Form'; + + $form->{title} = $locale->text("Select a part"); $form->header(); print $form->parse_html_template("generic/part_selection", { "HEADER" => \@header, "PARTS" => $parts, "onload" => $onload }); - $lxdebug->leave_sub(); -} - -# ------------------------------------------------------------------------- - -sub project_selection_internal { - $lxdebug->enter_sub(); - - $auth->check_right($form->{login}, 'project_edit'); - - my %valid_order_by_fields = ('description' => 1, 'projectnumber' => 1); - - $order_by = "description"; - $order_by = $form->{order_by} if ($valid_order_by_fields{$form->{order_by}}); - $order_dir = !defined $form->{order_dir} ? 1 : $form->{order_dir} ? 1 : 0; - - $projects = Common->retrieve_projects(\%myconfig, $form, $order_by, $order_dir); - - if (1 == scalar @{ $projects }) { - $onload = "project_selected('1')"; - } - - my $callback = build_std_url('action=project_selection_internal', qw(projectnumber description input_projectnumber input_description input_project_id), - grep { /^[fl]_/ } keys %{ $form }); - - my @header_sort = qw(projectnumber description); - my %header_title = ( "projectnumber" => $locale->text("Project Number"), - "description" => $locale->text("Project description"), - ); - - my @header = - map(+{ "column_title" => $header_title{$_}, - "column" => $_, - "callback" => $callback . "&order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir), - }, - @header_sort); - - $form->{title} = $locale->text("Select a project"); - $form->header(); - print $form->parse_html_template("generic/project_selection", { "HEADER" => \@header, - "PROJECTS" => $projects, - "onload" => $onload }); - - $lxdebug->leave_sub(); -} - -sub new_project { - $lxdebug->enter_sub(); - - delete @{$form}{qw(action login password)}; - - my $callback = build_std_url('action=project_created', grep { '' eq ref $form->{$_} } keys %{ $form }); - - my $argv = "action=add&type=project&callback=" . E($callback); - - exec("perl", "pe.pl", $argv); -} - -sub project_created { - $lxdebug->enter_sub(); - - $form->{title} = $locale->text("Select a project"); - $form->header(); - - my $args = { - 'PROJECTS' => [ { map { $_ => $form->{"new_$_"} } qw(id projectnumber description) } ], - 'HEADER' => [], - 'onload' => "project_selected('1')", - }; - - print $form->parse_html_template("generic/project_selection", $args); - - $lxdebug->leave_sub(); -} - -sub project_selection_check { - $lxdebug->enter_sub(); - - my ($id_field, $number_field, $description_field, $project_selected_nextsub, $prefix) = @_; - - $prefix = "f_" unless defined($prefix); - - if (!$form->{"${prefix}${number_field}"} && - (!$description_field || !$form->{"${prefix}${description_field}"})) { - delete $form->{"${prefix}${id_field}"}; - delete $form->{"${prefix}old_${number_field}"}; - delete $form->{"${prefix}old_${description_field}"} if ($description_field); - - $lxdebug->leave_sub(); - return 1; - } - - if (($form->{"${prefix}${number_field}"} eq $form->{"${prefix}old_${number_field}"}) && - (!$description_field || - (($form->{"${prefix}${description_field}"} eq $form->{"${prefix}old_${description_field}"})))) { - $lxdebug->leave_sub(); - return 1; - } - - my $old_form = save_form(); - - $form->{projectnumber} = $form->{"${prefix}${number_field}"}; - $form->{full_search} = 1; - - if ($description_field) { - $form->{description} = $form->{"${prefix}${description_field}"}; - } else { - delete $form->{description}; - } - - my $projects = Common->retrieve_projects(\%myconfig, $form, "projectnumber", 1); - restore_form($old_form); - - if (0 == scalar @{$projects}) { - $form->error(sprintf($locale->text("There is no project whose project number matches '%s'."), $form->{"${prefix}${number_field}"})); - - $lxdebug->leave_sub(); - return 0; - } - - if (1 != scalar(@{$projects})) { - $form->{project_selected_nextsub} = $project_selected_nextsub; - $form->{check_project_id_field} = $id_field; - $form->{check_project_number_field} = $number_field; - $form->{check_project_description_field} = $description_field; - - project_selection("project_selection_selected", $prefix, @{ $projects }); - - $lxdebug->leave_sub(); - return 0; - } - - $form->{"${prefix}${id_field}"} = $projects->[0]->{id}; - $form->{"${prefix}${number_field}"} = $projects->[0]->{projectnumber}; - $form->{"${prefix}old_${number_field}"} = $projects->[0]->{projectnumber}; - - if ($description_field) { - $form->{"${prefix}${description_field}"} = $projects->[0]->{description}; - $form->{"${prefix}old_${description_field}"} = $projects->[0]->{description}; - } - - $lxdebug->leave_sub(); - - return 1; -} - -sub project_selection { - $lxdebug->enter_sub(); - - my ($callback_sub, $prefix, @projects) = @_; - - if (0 == scalar @projects) { - my $old_form = save_form(); - map { delete($form->{$_}); } qw(projectnumber description); - - @projects = @{ Common->retrieve_projects(\%myconfig, $form, "projectnumber", 1) }; - - restore_form($old_form); - } - - $form->header(); - print $form->parse_html_template("generic/select_project", - { "PROJECTS" => \@projects, - "old_form" => save_form(qw(login password)), - "title" => $locale->text("Select an project"), - "nextsub" => "project_selection_step2", - "prefix" => $prefix, - "callback_sub" => $callback_sub }); - - $lxdebug->leave_sub(); -} - -sub project_selection_step2 { - $lxdebug->enter_sub(); - - my ($new_id, $new_name, $callback_sub); - - my $new_id = $form->{"new_id_" . $form->{selection}}; - my $new_number = $form->{"new_number_" . $form->{selection}}; - my $new_description = $form->{"new_description_" . $form->{selection}}; - my $callback_sub = $form->{callback_sub}; - my $prefix = $form->{prefix}; - - restore_form($form->{old_form}, 0, qw(login password)); - delete $form->{header}; - - call_sub($callback_sub, $new_id, $new_number, $new_description, $prefix); - - $lxdebug->leave_sub(); -} - -sub project_selection_selected { - $lxdebug->enter_sub(); - - my ($new_id, $new_number, $new_description, $prefix) = @_; - - my ($id_field, $number_field, $description_field) = ($form->{check_project_id_field}, $form->{check_project_number_field}, $form->{check_project_description_field}); - - map { delete $form->{"check_project_${_}_field"} } qw(id number description); - - $form->{"${prefix}${id_field}"} = $new_id; - $form->{"${prefix}${number_field}"} = $new_number; - $form->{"${prefix}old_${number_field}"} = $new_number; - - if ($description_field) { - $form->{"${prefix}${description_field}"} = $new_description; - $form->{"${prefix}old_${description_field}"} = $new_description; - } - - call_sub($form->{project_selected_nextsub}); - - $lxdebug->leave_sub(); -} - -# ------------------------------------------------------------------------- - -sub employee_selection_internal { - $lxdebug->enter_sub(); - - $order_by = "name"; - $order_by = $form->{"order_by"} if (defined($form->{"order_by"})); - $order_dir = 1; - $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"})); - - $employees = Common->retrieve_employees(\%myconfig, $form, $order_by, $order_dir); - map({ $employees->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$employees})); - if (0 == scalar(@{$employees})) { - $form->show_generic_information($locale->text("No employee was found matching the search parameters.")); - } elsif (1 == scalar(@{$employees})) { - $onload = "employee_selected('1')"; - } - - my $callback = "$form->{script}?action=employee_selection_internal&"; - map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" } - (qw(name input_name input_id), grep({ /^[fl]_/ } keys %$form))); - - my @header_sort = qw(name); - my %header_title = ( "name" => $locale->text("Name"), - ); - - my @header = - map(+{ "column_title" => $header_title{$_}, - "column" => $_, - "callback" => $callback . "order_by=${_}&order_dir=" . ($order_by eq $_ ? 1 - $order_dir : $order_dir), - }, - @header_sort); - - $form->{"title"} = $locale->text("Select an employee"); - $form->header(); - print($form->parse_html_template("generic/employee_selection", { "HEADER" => \@header, - "EMPLOYEES" => $employees, - "onload" => $onload })); - - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } # ------------------------------------------------------------------------- sub delivery_customer_selection { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - $order_by = "name"; + my $order_by = "name"; $order_by = $form->{"order_by"} if (defined($form->{"order_by"})); - $order_dir = 1; + my $order_dir = 1; $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"})); - $delivery = Common->retrieve_delivery_customer(\%myconfig, $form, $order_by, $order_dir); + my $delivery = Common->retrieve_delivery_customer(\%myconfig, $form, $order_by, $order_dir); map({ $delivery->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$delivery})); + + my $onload; if (0 == scalar(@{$delivery})) { $form->show_generic_information($locale->text("No Customer was found matching the search parameters.")); } elsif (1 == scalar(@{$delivery})) { @@ -575,21 +244,27 @@ sub delivery_customer_selection { "DELIVERY" => $delivery, "onload" => $onload }); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } # ------------------------------------------------------------------------- sub vendor_selection { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - $order_by = "name"; + my $order_by = "name"; $order_by = $form->{"order_by"} if (defined($form->{"order_by"})); - $order_dir = 1; + my $order_dir = 1; $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"})); - $vendor = Common->retrieve_vendor(\%myconfig, $form, $order_by, $order_dir); + my $vendor = Common->retrieve_vendor(\%myconfig, $form, $order_by, $order_dir); map({ $vendor->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$vendor})); + + my $onload; if (0 == scalar(@{$vendor})) { $form->show_generic_information($locale->text("No Vendor was found matching the search parameters.")); } elsif (1 == scalar(@{$vendor})) { @@ -619,81 +294,80 @@ sub vendor_selection { "VENDOR" => $vendor, "onload" => $onload }); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } # ------------------------------------------------------------------------- sub calculate_qty { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; - my @variable_sort = (); - my %variable_list = (); - my $unit_list = (); $form->{formel} =~ s/\r\n//g; my ($variable_string, $formel) = split /###/,$form->{formel}; + my @variable; + my $onload; # note! this sub is mostly called over a javascript invocation, and it's unlikey that onload is set. - - split m/;/, $variable_string; - foreach $item (@_) { - my($name, $valueunit) = split /=/,$item; - my($value, $unit) = split / /, $valueunit; - - push(@variable_sort, $value); - $variable_list{$value} = $name; - $unit_list{$value} = $unit; + foreach my $item (split m/;/, $variable_string) { + next unless $item =~ m/^ \s* (\w+) \s* = \s* (\w+) \s* (\w+) \s* $/x; + push @variable, { + description => $1, + name => $2, + unit => $3, + }; } my @header_sort = qw(variable value unit); - my %header_title = ( "variable" => $locale->text("Variable"), - "value" => $locale->text("Value"), - "unit" => $locale->text("Unit"), - ); - - my @variable = map(+{ "description" => $variable_list{$_}, - "name" => $_, - "unit" => $unit_list{$_} }, @variable_sort); + my %header_title = ( + variable => $locale->text("Variable"), + value => $locale->text("Value"), + unit => $locale->text("Unit"), + ); + my @header = map +{ + column_title => $header_title{$_}, + column => $_, + }, @header_sort; - my @header = - map(+{ "column_title" => $header_title{$_}, - "column" => $_, - }, - @header_sort); $form->{formel} = $formel; - $form->{"title"} = $locale->text("Please enter values"); + $form->{title} = $locale->text("Please enter values"); $form->header(); - print($form->parse_html_template("generic/calculate_qty", { "HEADER" => \@header, + print $form->parse_html_template("generic/calculate_qty", { "HEADER" => \@header, "VARIABLES" => \@variable, - "onload" => $onload })); + "onload" => $onload }); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } # ------------------------------------------------------------------------- sub set_longdescription { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my $locale = $main::locale; $form->{title} = $locale->text("Enter longdescription"); $form->header(); print $form->parse_html_template("generic/set_longdescription"); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } # ------------------------------------------------------------------------- sub H { - return $form->quote_html($_[0]); + return $main::locale->quote_special_chars('HTML', $_[0]); } sub Q { - return $form->quote($_[0]); + return $main::locale->quote_special_chars('URL@HTML', $_[0]); } sub E { - return $form->escape($_[0]); + return $main::form->escape($_[0]); } sub NTI { @@ -704,13 +378,25 @@ sub NTI { } sub format_dates { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); my ($dateformat, $longformat, @indices) = @_; + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + $dateformat = $myconfig{"dateformat"} unless ($dateformat); foreach my $idx (@indices) { + if ($form->{TEMPLATE_ARRAYS} && (ref($form->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) { + for (my $i = 0; $i < scalar(@{$form->{TEMPLATE_ARRAYS}->{$idx}}); $i++) { + $form->{TEMPLATE_ARRAYS}->{$idx}->[$i] = + $locale->reformat_date(\%myconfig, $form->{TEMPLATE_ARRAYS}->{$idx}->[$i], + $dateformat, $longformat); + } + } + next unless (defined($form->{$idx})); if (!ref($form->{$idx})) { @@ -726,18 +412,27 @@ sub format_dates { } } - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub reformat_numbers { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); my ($numberformat, $places, @indices) = @_; - return $lxdebug->leave_sub() + my $form = $main::form; + my %myconfig = %main::myconfig; + + return $main::lxdebug->leave_sub() if (!$numberformat || ($numberformat eq $myconfig{"numberformat"})); foreach my $idx (@indices) { + if ($form->{TEMPLATE_ARRAYS} && (ref($form->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) { + for (my $i = 0; $i < scalar(@{$form->{TEMPLATE_ARRAYS}->{$idx}}); $i++) { + $form->{TEMPLATE_ARRAYS}->{$idx}->[$i] = $form->parse_amount(\%myconfig, $form->{TEMPLATE_ARRAYS}->{$idx}->[$i]); + } + } + next unless (defined($form->{$idx})); if (!ref($form->{$idx})) { @@ -755,6 +450,12 @@ sub reformat_numbers { $myconfig{"numberformat"} = $numberformat; foreach my $idx (@indices) { + if ($form->{TEMPLATE_ARRAYS} && (ref($form->{TEMPLATE_ARRAYS}->{$idx}) eq "ARRAY")) { + for (my $i = 0; $i < scalar(@{$form->{TEMPLATE_ARRAYS}->{$idx}}); $i++) { + $form->{TEMPLATE_ARRAYS}->{$idx}->[$i] = $form->format_amount(\%myconfig, $form->{TEMPLATE_ARRAYS}->{$idx}->[$i], $places); + } + } + next unless (defined($form->{$idx})); if (!ref($form->{$idx})) { @@ -770,37 +471,45 @@ sub reformat_numbers { $myconfig{"numberformat"} = $saved_numberformat; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } # ------------------------------------------------------------------------- sub show_history { - $lxdebug->enter_sub(); - my $dbh = $form->dbconnect(\%myconfig); - my ($sort, $sortby) = split(/\-\-/, $form->{order}); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + my $dbh = $form->dbconnect(\%myconfig); + my ($sort, $sortby) = split(/\-\-/, $form->{order}); $sort =~ s/.*\.(.*)/$1/; - $form->{title} = $locale->text("History"); - $form->header(); - print $form->parse_html_template( "common/show_history", { - "DATEN" => $form->get_history($dbh,$form->{input_name},"",$form->{order}), - "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0"), - uc($sort) => 1, - uc($sort)."BY" => $sortby - } ); - - $dbh->disconnect(); - $lxdebug->leave_sub(); + $form->{title} = $locale->text("History"); + $form->header(); + print $form->parse_html_template( "common/show_history", { + "DATEN" => $form->get_history($dbh,$form->{input_name},"",$form->{order}), + "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0"), + uc($sort) => 1, + uc($sort)."BY" => $sortby + } ); + + $dbh->disconnect(); + $main::lxdebug->leave_sub(); } # ------------------------------------------------------------------------- sub call_sub { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); my $name = shift; + my $form = $main::form; + my $locale = $main::locale; + if (!$name) { $form->error($locale->text("Trying to call a sub without a name")); } @@ -811,15 +520,22 @@ sub call_sub { $form->error(sprintf($locale->text("Attempt to call an undefined sub named '%s'"), $name)); } - &{ $name }(@_); + { + no strict "refs"; + &{ $name }(@_); + } - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } # ------------------------------------------------------------------------- sub show_vc_details { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; $form->{vc} = $form->{vc} eq "customer" ? "customer" : "vendor"; $form->isblank("vc_id", @@ -834,13 +550,15 @@ sub show_vc_details { $form->header(); print $form->parse_html_template("common/show_vc_details", { "is_customer" => $form->{vc} eq "customer" }); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } # ------------------------------------------------------------------------- sub retrieve_partunits { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; my @part_ids = grep { $_ } map { $form->{"id_${_}"} } (1..$form->{rowcount}); @@ -853,26 +571,39 @@ sub retrieve_partunits { } } - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } # ------------------------------------------------------------------------- sub mark_as_paid_common { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); my ($myconfig, $db_name) = @_; + my $form = $main::form; + my $locale = $main::locale; + if($form->{mark_as_paid}) { my $dbh ||= $form->get_standard_dbh($myconfig); - my $query = qq|UPDATE $db_name SET paid = amount WHERE id = ?|; + my $query = qq|UPDATE $db_name SET paid = amount, datepaid = current_date WHERE id = ?|; do_query($form, $dbh, $query, $form->{id}); $dbh->commit(); $form->redirect($locale->text("Marked as paid")); } else { my $referer = $ENV{HTTP_REFERER}; - $referer =~ s/^(.*)action\=.*\&(.*)$/$1action\=mark_as_paid\&mark_as_paid\=1\&id\=$form->{id}\&$2/; + my $script; + my $callback; + if ($referer =~ /action/) { + $referer =~ /^(.*)\?action\=[^\&]*(\&.*)$/; + $script = $1; + $callback = $2; + } else { + $script = $referer; + $callback = ""; + } + $referer = $script . "?action=mark_as_paid&mark_as_paid=1&id=$form->{id}" . $callback; $form->header(); print qq||; print qq|

|.$locale->text('Mark as paid?').qq|

|; @@ -881,21 +612,27 @@ sub mark_as_paid_common { print qq||; } - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub cov_selection_internal { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $order_by = "name"; + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + my $order_by = "name"; $order_by = $form->{"order_by"} if (defined($form->{"order_by"})); - $order_dir = 1; + my $order_dir = 1; $order_dir = $form->{"order_dir"} if (defined($form->{"order_dir"})); my $type = $form->{"is_vendor"} ? $locale->text("vendor") : $locale->text("customer"); - $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, $order_by, $order_dir, $form->{"is_vendor"}, $form->{"allow_both"}); + my $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, $order_by, $order_dir, $form->{"is_vendor"}, $form->{"allow_both"}); map({ $covs->[$_]->{"selected"} = $_ ? 0 : 1; } (0..$#{$covs})); + + my $onload; if (0 == scalar(@{$covs})) { $form->show_generic_information(sprintf($locale->text("No %s was found matching the search parameters."), $type)); } elsif (1 == scalar(@{$covs})) { @@ -904,7 +641,7 @@ sub cov_selection_internal { my $callback = "$form->{script}?action=cov_selection_internal&"; map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" } - (qw(login path password name input_name input_id is_vendor allow_both), grep({ /^[fl]_/ } keys %$form))); + (qw(name input_name input_id is_vendor allow_both), grep({ /^[fl]_/ } keys %$form))); my @header_sort = qw(name address contact); my %header_title = ( "name" => $locale->text("Name"), @@ -924,7 +661,7 @@ sub cov_selection_internal { $cov->{address} =~ s{^,}{}x; $cov->{address} =~ s{\ +}{\ }gx; - $cov->{contact} = join " ", map { $cov->{$_} } qw(cp_greeting cp_title cp_givenname cp_name); + $cov->{contact} = join " ", map { $cov->{$_} } qw(cp_gender cp_title cp_givenname cp_name); $cov->{contact} =~ s{\ +}{\ }gx; } @@ -934,93 +671,107 @@ sub cov_selection_internal { "COVS" => $covs, "onload" => $onload })); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } -sub check_cov2 { - $lxdebug->enter_sub(); - my $callback_sub = shift; +# Functions to call add routines beneath different reports - if (!$form->{customer} - || ($form->{customer} eq $form->{old_customer}) - || ("$form->{customer}--$form->{customer_id}" eq $form->{old_customer})) { - $lxdebug->leave_sub(); - return; - } +sub sales_invoice { + $main::lxdebug->enter_sub(); - $old_name = $form->{name}; - $form->{name} = $form->{customer}; + $main::auth->assert('invoice_edit'); - my $covs = Common->retrieve_customers_or_vendors(\%myconfig, $form, "name", "ASC", 0, 1); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - $form->{name} = $old_name; + $form->{script} = 'is.pl'; + my $script = "is"; + $form->{type} = "invoice"; + $locale = new Locale "$myconfig{countrycode}", "$script"; - if (0 == scalar @{$covs}) { - $form->show_generic_information(sprintf($locale->text("No %s was found matching the search parameters."), $type)); + require "bin/mozilla/$form->{script}"; + &add; - } elsif (1 == scalar @{ $covs }) { - $form->{customer} = $covs->[0]->{name}; - $form->{old_customer} = $covs->[0]->{name}; - $form->{customer_id} = $covs->[0]->{id}; - $form->{customer_is_vendor} = $covs->[0]->{customer_is_vendor}; + $main::lxdebug->leave_sub(); +} - } else { - $form->{new_cov_nextsub} = $callback_sub; +sub ar_transaction { + $main::lxdebug->enter_sub(); - delete @{$form}{qw(customer customer_is_vendor customer_id old_customer action)}; - my @hidden = map { { 'key' => $_, 'value' => $form->{$_} } } grep { '' eq ref $form->{$_} } keys %{ $form }; + $main::auth->assert('general_ledger'); - foreach my $cov (@{ $covs }) { - $cov->{address} = "$cov->{street}, $cov->{zipcode} $cov->{city}"; - $cov->{address} =~ s{^,}{}x; - $cov->{address} =~ s{\ +}{\ }gx; + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - $cov->{contact} = join " ", map { $cov->{$_} } qw(cp_greeting cp_title cp_givenname cp_name); - $cov->{contact} =~ s{\ +}{\ }gx; - } + $form->{script} = 'ar.pl'; + my $script = "ar"; + $locale = new Locale "$myconfig{countrycode}", "$script"; - $form->{title} = $locale->text("Select a vendor or customer"); - $form->header(); + require "bin/mozilla/$form->{script}"; + &add; + + $main::lxdebug->leave_sub(); +} - print $form->parse_html_template("generic/cov_selection2", { "COVS" => $covs, "HIDDEN" => \@hidden }); +sub vendor_invoice { + $main::lxdebug->enter_sub(); - exit 0; - } + $main::auth->assert('invoice_edit'); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; + + $form->{script} = 'ir.pl'; + my $script = "ir"; + $form->{type} = "invoice"; + $locale = new Locale "$myconfig{countrycode}", "$script"; + + require "bin/mozilla/$form->{script}"; + &add; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } -sub cov_selected2 { - $lxdebug->enter_sub(); +sub ap_transaction { + $main::lxdebug->enter_sub(); - if (!$form->{new_cov} || !$form->{new_cov_nextsub}) { - $form->error($locale->text('No customer has been selected.')); - } + $main::auth->assert('general_ledger'); + + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - map { $form->{$_} = $form->{"new_cov_${_}_$form->{new_cov}"} } qw(customer customer_id customer_is_vendor); - $form->{old_customer} = $form->{customer}; + $form->{script} = 'ap.pl'; + my $script = "ap"; + $locale = new Locale "$myconfig{countrycode}", "$script"; - &{ $form->{new_cov_nextsub} }(); + require "bin/mozilla/$form->{script}"; + &add; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } -sub select_item_selection_internal { - $lxdebug->enter_sub(); +sub gl_transaction { + $main::lxdebug->enter_sub(); - @items = SystemBrace->retrieve_select_items(\%myconfig, $form, $form->{"select_item_type"}); - if (0 == scalar(@items)) { - $form->show_generic_information($locale->text("No item was found.")); - } elsif (1 == scalar(@items)) { - $onload = "select_item_selected('1')"; - } + $main::auth->assert('general_ledger'); - $form->{"title"} = $locale->text("Select an entry"); - $form->header(); - print($form->parse_html_template("generic/select_item_selection", { "SELECT_ITEMS" => \@items, - "onload" => $onload })); + my $form = $main::form; + my %myconfig = %main::myconfig; + my $locale = $main::locale; - $lxdebug->leave_sub(); + $form->{script} = 'gl.pl'; + my $script = "gl"; + $locale = new Locale "$myconfig{countrycode}", "$script"; + + require "bin/mozilla/$form->{script}"; + &add; + + $main::lxdebug->leave_sub(); } + 1;