X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=bin%2Fmozilla%2Fcommon.pl;h=d01d19f58d0bc96cbc9914df51eb7ef8f8c14c47;hb=14562379bf33cf4b4388c6cf594ee8fc56ae3f87;hp=a6f7ef48c6ab49b9c07eecf0aba10cac1243a98b;hpb=ac5522802741d3092b371ab6b57199cb8a587bf9;p=kivitendo-erp.git diff --git a/bin/mozilla/common.pl b/bin/mozilla/common.pl index a6f7ef48c..d01d19f58 100644 --- a/bin/mozilla/common.pl +++ b/bin/mozilla/common.pl @@ -9,12 +9,12 @@ # ###################################################################### -use Carp; use SL::Common; -use SL::DBUtils; +use SL::DB::Helper::Mappings; +use SL::DB; +use SL::DBUtils qw(do_query); use SL::Form; -use SL::MoreCommon; -use SL::Helper::Flash; +use SL::MoreCommon qw(restore_form save_form); use strict; @@ -169,12 +169,11 @@ sub part_selection_internal { 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; 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')"; + $::request->{layout}->add_javascripts_inline("part_selected('1')"); } map { $parts->[$_]->{selected} = $_ ? 0 : 1; } (0..$#{$parts}); @@ -197,10 +196,9 @@ sub part_selection_internal { $form->{formname} ||= 'Form'; $form->{title} = $locale->text("Select a part"); - $form->header(); + $form->header(no_layout => 1); print $form->parse_html_template("generic/part_selection", { "HEADER" => \@header, - "PARTS" => $parts, - "onload" => $onload }); + "PARTS" => $parts, }); $main::lxdebug->leave_sub(); } @@ -222,11 +220,10 @@ sub delivery_customer_selection { 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})) { - $onload = "customer_selected('1')"; + $::request->{layout}->add_javascripts_inline("customer_selected('1')"); } my $callback = "$form->{script}?action=delivery_customer_selection&"; @@ -247,10 +244,9 @@ sub delivery_customer_selection { @header_sort); $form->{"title"} = $locale->text("Select a Customer"); - $form->header(); + $form->header(no_layout => 1); print $form->parse_html_template("generic/select_delivery_customer", { "HEADER" => \@header, - "DELIVERY" => $delivery, - "onload" => $onload }); + "DELIVERY" => $delivery, }); $main::lxdebug->leave_sub(); } @@ -272,11 +268,10 @@ sub vendor_selection { 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})) { - $onload = "vendor_selected('1')"; + $::request->{layout}->add_javascripts_inline("vendor_selected('1')"); } my $callback = "$form->{script}?action=vendor_selection&"; @@ -297,10 +292,9 @@ sub vendor_selection { @header_sort); $form->{"title"} = $locale->text("Select a Customer"); - $form->header(); + $form->header(no_layout => 1); print $form->parse_html_template("generic/select_vendor", { "HEADER" => \@header, - "VENDOR" => $vendor, - "onload" => $onload }); + "VENDOR" => $vendor, }); $main::lxdebug->leave_sub(); } @@ -317,7 +311,6 @@ sub calculate_qty { 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. foreach my $item (split m/;/, $variable_string) { next unless $item =~ m/^ \s* (\w+) \s* = \s* (\w+) \s* (\w+) \s* $/x; @@ -341,25 +334,9 @@ sub calculate_qty { $form->{formel} = $formel; $form->{title} = $locale->text("Please enter values"); - $form->header(); + $form->header(no_layout => 1); print $form->parse_html_template("generic/calculate_qty", { "HEADER" => \@header, - "VARIABLES" => \@variable, - "onload" => $onload }); - - $main::lxdebug->leave_sub(); -} - -# ------------------------------------------------------------------------- - -sub set_longdescription { - $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"); + "VARIABLES" => \@variable, }); $main::lxdebug->leave_sub(); } @@ -386,100 +363,11 @@ sub NTI { } sub format_dates { - $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})) { - $form->{$idx} = $locale->reformat_date(\%myconfig, $form->{$idx}, - $dateformat, $longformat); - - } elsif (ref($form->{$idx}) eq "ARRAY") { - for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) { - $form->{$idx}->[$i] = - $locale->reformat_date(\%myconfig, $form->{$idx}->[$i], - $dateformat, $longformat); - } - } - } - - $main::lxdebug->leave_sub(); + return $::form->format_dates(@_); } sub reformat_numbers { - $main::lxdebug->enter_sub(); - - my ($numberformat, $places, @indices) = @_; - - 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})) { - $form->{$idx} = $form->parse_amount(\%myconfig, $form->{$idx}); - - } elsif (ref($form->{$idx}) eq "ARRAY") { - for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) { - $form->{$idx}->[$i] = - $form->parse_amount(\%myconfig, $form->{$idx}->[$i]); - } - } - } - - my $saved_numberformat = $myconfig{"numberformat"}; - $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})) { - $form->{$idx} = $form->format_amount(\%myconfig, $form->{$idx}, $places); - - } elsif (ref($form->{$idx}) eq "ARRAY") { - for (my $i = 0; $i < scalar(@{$form->{$idx}}); $i++) { - $form->{$idx}->[$i] = - $form->format_amount(\%myconfig, $form->{$idx}->[$i], $places); - } - } - } - - $myconfig{"numberformat"} = $saved_numberformat; - - $main::lxdebug->leave_sub(); + return $::form->reformat_numbers(@_); } # ------------------------------------------------------------------------- @@ -496,12 +384,24 @@ sub show_history { $sort =~ s/.*\.(.*)/$1/; $form->{title} = $locale->text("History"); - $form->header(); + $form->header(no_layout => 1); + + my $callback = build_std_url(qw(action longdescription trans_id_type input_name)); + my $restriction; + if ( $form->{trans_id_type} eq 'glid' ) { + $restriction = "AND ( snumbers LIKE 'invnumber%' OR what_done LIKE '%Buchungsnummer%' OR snumbers LIKE 'gltransaction%' ) "; + } elsif ( $form->{trans_id_type} eq 'id' ) { + $restriction = " AND ( snumbers NOT LIKE 'invnumber_%' AND snumbers NOT LIKE 'gltransaction%' AND (what_done NOT LIKE '%Buchungsnummer%' OR what_done IS null))"; + } else { + $restriction = ''; + }; + print $form->parse_html_template( "common/show_history", { - "DATEN" => $form->get_history($dbh,$form->{input_name},"",$form->{order}), + "DATEN" => $form->get_history($dbh,$form->{input_name},$restriction,$form->{order}), "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0"), uc($sort) => 1, - uc($sort)."BY" => $sortby + uc($sort)."BY" => $sortby, + callback => $callback, } ); $dbh->disconnect(); @@ -528,9 +428,6 @@ sub call_sub { $form->error(sprintf($locale->text("Attempt to call an undefined sub named '%s'"), $name)); } - $::called_subs{$name}++; - confess "RECURSION DETECTION: call_sub($name) called " . $::called_subs{$name} . " time(s)" if $::called_subs{$name} > 10; - { no strict "refs"; &{ $name }(@_); @@ -555,10 +452,11 @@ sub show_vc_details { $locale->text("No vendor has been selected yet.")); Common->get_vc_details(\%myconfig, $form, $form->{vc}, $form->{vc_id}); + $form->{discount_as_percent} = $form->format_amount(\%::myconfig, $form->parse_amount(\%::myconfig, $form->{discount}) * 100, 2); $form->{title} = $form->{vc} eq "customer" ? $locale->text("Customer details") : $locale->text("Vendor details"); - $form->header(); + $form->header(no_layout => 1); print $form->parse_html_template("common/show_vc_details", { "is_customer" => $form->{vc} eq "customer" }); $main::lxdebug->leave_sub(); @@ -596,10 +494,12 @@ sub mark_as_paid_common { 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, datepaid = current_date WHERE id = ?|; - do_query($form, $dbh, $query, $form->{id}); - $dbh->commit(); + SL::DB->client->with_transaction(sub { + my $dbh ||= SL::DB->client->dbh; + my $query = qq|UPDATE $db_name SET paid = amount, datepaid = current_date WHERE id = ?|; + do_query($form, $dbh, $query, $form->{id}); + 1; + }) or do { $::form->error(SL::DB->client->error) }; $form->redirect($locale->text("Marked as paid")); } else { @@ -610,17 +510,19 @@ sub mark_as_paid_common { $referer =~ /^(.*)\?action\=[^\&]*(\&.*)$/; $script = $1; $callback = $2; + } elsif ($referer =~ /RESTORE_FORM_FROM_SESSION_ID/){ + $referer =~ /^(.*)\?RESTORE_FORM_FROM_SESSION_ID\=(.*)$/; + $script = $1; + $callback = ""; } 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|
|; print qq| |; print qq||; - print qq|