X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fio.pl;h=0d7601ea6f9dd52539bd1f827454021894e00ae9;hb=493457086f727b713cca06c25c1c3bedb92185af;hp=c569ef8a53fcefb93e9537052cd3810dd8842103;hpb=be4f82541d41ee895fa3cbade337bdb65217de24;p=kivitendo-erp.git diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index c569ef8a5..0d7601ea6 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -38,7 +38,7 @@ use Carp; use CGI; -use CGI::Ajax; +use List::MoreUtils qw(any uniq); use List::Util qw(min max first); use SL::CVar; @@ -47,6 +47,10 @@ use SL::CT; use SL::IC; use SL::IO; +use SL::DB::Language; +use SL::DB::Printer; +use SL::Helper::Flash; + require "bin/mozilla/common.pl"; use strict; @@ -117,7 +121,7 @@ sub display_row { my $numrows = shift; - my ($readonly, $stock_in_out, $stock_in_out_title); + my ($stock_in_out, $stock_in_out_title); my $is_purchase = (first { $_ eq $form->{type} } qw(request_quotation purchase_order purchase_delivery_order)) || ($form->{script} eq 'ir.pl'); my $show_min_order_qty = first { $_ eq $form->{type} } qw(request_quotation purchase_order); @@ -125,8 +129,6 @@ sub display_row { my $is_s_p_order = (first { $_ eq $form->{type} } qw(sales_order purchase_order)); if ($is_delivery_order) { - $readonly = ' readonly' if ($form->{closed}); - if ($form->{type} eq 'sales_delivery_order') { $stock_in_out_title = $locale->text('Release From Stock'); $stock_in_out = 'out'; @@ -225,6 +227,7 @@ sub display_row { # adjust prices by unit, ignore if pricegroup changed if ((!$form->{"prices_$i"}) || ($form->{"new_pricegroup_$i"} == $form->{"old_pricegroup_$i"})) { $form->{"sellprice_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1; + $form->{"lastcost_$i"} *= AM->convert_unit($form->{"selected_unit_$i"}, $form->{"unit_old_$i"}, $all_units) || 1; $form->{"unit_old_$i"} = $form->{"selected_unit_$i"}; } my $this_unit = $form->{"unit_$i"}; @@ -247,7 +250,10 @@ sub display_row { $column_data{"unit"} = AM->unit_select_html($all_units, "unit_$i", $this_unit, $form->{"id_$i"} ? $form->{"unit_$i"} : undef); # / unit ending +#count the max of decimalplaces of sellprice and lastcost, so the same number of decimalplaces +#is shown for lastcost and sellprice. my $decimalplaces = ($form->{"sellprice_$i"} =~ /\.(\d+)/) ? max 2, length $1 : 2; + $decimalplaces = ($form->{"lastcost_$i"} =~ /\.(\d+)/) ? max $decimalplaces, length $1 : $decimalplaces; my $price_factor = $price_factors{$form->{"price_factor_id_$i"}} || 1; my $discount = $form->round_amount($form->{"qty_$i"} * $form->{"sellprice_$i"} * $form->{"discount_$i"} / 100 / $price_factor, 2); @@ -278,12 +284,16 @@ sub display_row { } # build in drop down list for pricesgroups + # $sellprice_value setzt den Wert etwas unabhängiger von der Darstellung. + # Hintergrund: Preisgruppen werden hier überprüft und neu berechnet. + # Vorher wurde der ganze cgi->textfield Block zweimal identisch eingebaut, dass passiert + # jetzt nach der Abfrage. + my $sellprice_value; if ($form->{"prices_$i"}) { $column_data{sellprice_pg} = qq||; - $column_data{sellprice} = $cgi->textfield(-name => "sellprice_$i", -size => 10, -onBlur => 'check_right_number_format(this)', -value => - (($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) + $sellprice_value =($form->{"new_pricegroup_$i"} != $form->{"old_pricegroup_$i"}) ? $form->format_amount(\%myconfig, $form->{"price_new_$i"}, $decimalplaces) - : $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces))); + : $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces); } else { # for last row and report # set pricegroup drop down list from report menu @@ -296,11 +306,22 @@ sub display_row { } else { $column_data{sellprice_pg} = qq| |; } - $column_data{sellprice} = $cgi->textfield(-name => "sellprice_$i", -size => 10, -onBlur => "check_right_number_format(this)", -value => - $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces)); + $sellprice_value = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces); } - $column_data{discount} = $cgi->textfield(-name => "discount_$i", -size => 3, -value => $form->format_amount(\%myconfig, $form->{"discount_$i"})); + # Falls der Benutzer die Preise nicht anpassen sollte, wird das entsprechende + # Textfield auf readonly gesetzt. Anm. von Sven: Manipulation der Preise ist + # immer noch möglich, konsequenterweise sollten diese NUR aus der Datenbank + # geholt werden. + my $edit_prices = $main::auth->assert('edit_prices', 1); + $column_data{sellprice} = (!$edit_prices) + ? $cgi->textfield(-readonly => "readonly", + -name => "sellprice_$i", -size => 10, -onBlur => "check_right_number_format(this)", -value => $sellprice_value) + : $cgi->textfield(-name => "sellprice_$i", -size => 10, -onBlur => "check_right_number_format(this)", -value => $sellprice_value); + $column_data{discount} = (!$edit_prices) + ? $cgi->textfield(-readonly => "readonly", + -name => "discount_$i", -size => 3, -value => $form->format_amount(\%myconfig, $form->{"discount_$i"})) + : $cgi->textfield(-name => "discount_$i", -size => 3, -value => $form->format_amount(\%myconfig, $form->{"discount_$i"})); $column_data{linetotal} = $form->format_amount(\%myconfig, $linetotal, 2); $column_data{bin} = $form->{"bin_$i"}; @@ -326,8 +347,20 @@ sub display_row { $form->{"marge_percent_$i"} = 0; my $marge_color; - my $real_sellprice = $linetotal; - my $real_lastcost = $form->{"lastcost_$i"} * $form->{"qty_$i"} / ( $form->{"marge_price_factor_$i"} || 1 ); + my $real_sellprice; + if ( $form->{taxincluded} and $form->{"qty_$i"} * 1 and $form->{$form->{"taxaccounts_$i"} . "_rate"} * 1) { + # if we use taxincluded we need to calculate the marge from the net_value + # all the marge calculations are based on linetotal which we need to + # convert to net first + + # there is no direct form value for the tax_rate of the item, but + # form->{taxaccounts_$i} gives the tax account (e.g. 3806) and 3806_rate + # gives the tax percentage (e.g. 0.19) + $real_sellprice = $linetotal / (1 + $form->{$form->{"taxaccounts_$i"} . "_rate"}); + } else { + $real_sellprice = $linetotal; + }; + my $real_lastcost = $form->round_amount($form->{"lastcost_$i"} * $form->{"qty_$i"} / $price_factor, 2); my $marge_percent_warn = $myconfig{marge_percent_warn} * 1 || 15; my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1; @@ -349,7 +382,7 @@ sub display_row {  %s |, $marge_color, $locale->text('Ertrag'),$form->{"marge_absolut_$i"}, $form->{"marge_percent_$i"}, $locale->text('LP'), $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2), - $locale->text('EK'), $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, 2) } + $locale->text('EK'), $form->format_amount(\%myconfig, $form->{"lastcost_$i"}, $decimalplaces) } if $form->{"id_$i"} && ($form->{type} =~ /^sales_/ || $form->{type} =~ /invoice/ || $form->{type} =~ /^credit_note$/ ) && !$is_delivery_order; $form->{"listprice_$i"} = $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2) @@ -373,7 +406,7 @@ sub display_row { if ($is_delivery_order) { map { $form->{"${_}_${i}"} = $form->format_amount(\%myconfig, $form->{"${_}_${i}"}) } qw(sellprice discount lastcost); - push @hidden_vars, qw(sellprice discount not_discountable price_factor_id lastcost); + push @hidden_vars, qw(sellprice discount not_discountable price_factor_id lastcost pricegroup_id); push @hidden_vars, "stock_${stock_in_out}_sum_qty", "stock_${stock_in_out}"; } @@ -456,7 +489,7 @@ sub select_item { } @{ $::form->{item_list} }; # delete action variable - delete @{$::form}{qw(action item_list header)}; + delete @{$::form}{qw(action item_list)}; print $::form->parse_html_template('io/select_item', { PREVIOUS_FORM => $previous_form, MODE => $mode, @@ -528,6 +561,11 @@ sub item_selected { $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"}, $decimalplaces); } + + # tradediscount + if ($::form->{tradediscount}) { + $::form->{"sellprice_$i"} *= 1 - $::form->{tradediscount}; + } } map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } @@ -765,6 +803,7 @@ sub validate_items { # check if items are valid if ($form->{rowcount} == 1) { + flash('warning', $::locale->text('The action you\'ve chosen has not been executed because the document does not contain any item yet.')); &update; ::end_of_request(); } @@ -930,6 +969,9 @@ sub edit_e_mail { $form->{"email"} = $form->{"cp_email"} if $form->{"cp_email"}; } + $form->{language} = $form->get_template_language(\%myconfig); + $form->{language} = "_" . $form->{language} if $form->{language}; + my $title = $locale->text('E-mail') . " " . $form->get_formname_translation(); $form->{oldmedia} = $form->{media}; @@ -938,7 +980,7 @@ sub edit_e_mail { my $attachment_filename = $form->generate_attachment_filename(); my $subject = $form->{subject} || $form->generate_email_subject(); - $form->{"fokus"} = $form->{"email"} ? "Form.subject" : "Form.email"; + $::request->{layout}->focus($form->{"email"} ? "#subject" : "#email"); $form->header; my (@dont_hide_key_list, %dont_hide_key, @hidden_keys); @@ -952,7 +994,7 @@ sub edit_e_mail { subject => $subject, print_options => print_options('inline' => 1), HIDDEN => [ map +{ name => $_, value => $form->{$_} }, @hidden_keys ], - SHOW_BCC => $myconfig{role} eq 'admin' }); + SHOW_BCC => $::auth->assert('email_bcc', 'may fail') }); $main::lxdebug->leave_sub(); } @@ -1047,11 +1089,12 @@ sub print_options { opthash("inline", $form->{SM}{inline}, $locale->text('In-line')) if ($form->{media} eq 'email'); + my $printable_templates = any { $::lx_office_conf{print_templates}->{$_} } qw(latex opendocument); push @MEDIA, grep $_, opthash("screen", $form->{OP}{screen}, $locale->text('Screen')), - ($form->{printers} && scalar @{ $form->{printers} } && $::lx_office_conf{print_templates}->{latex}) ? + ($printable_templates && $form->{printers} && scalar @{ $form->{printers} }) ? opthash("printer", $form->{OP}{printer}, $locale->text('Printer')) : undef, - ($::lx_office_conf{print_templates}->{latex} && !$options{no_queue}) ? + ($printable_templates && !$options{no_queue}) ? opthash("queue", $form->{OP}{queue}, $locale->text('Queue')) : undef if ($form->{media} ne 'email'); @@ -1313,12 +1356,14 @@ sub print_form { my $salesman_id_saved = $form->{salesman_id}; my $cp_id_saved = $form->{cp_id}; my $taxzone_id_saved = $form->{taxzone_id}; + my $currency_saved = $form->{currency}; call_sub("$form->{vc}_details") if ($form->{vc}); $form->{language_id} = $language_saved; $form->{payment_id} = $payment_id_saved; $form->{taxzone_id} = $taxzone_id_saved; + $form->{currency} = $currency_saved; $form->{"email"} = $saved_email if ($saved_email); $form->{"cc"} = $saved_cc if ($saved_cc); @@ -1363,7 +1408,7 @@ sub print_form { $form->get_shipto(\%myconfig); } - my @a = qw(name street zipcode city country contact); + my @a = qw(name department_1 department_2 street zipcode city country contact phone fax email); my $shipto = 1; @@ -1412,7 +1457,7 @@ sub print_form { format_dates($output_dateformat, $output_longdates, qw(invdate orddate quodate pldate duedate reqdate transdate shippingdate deliverydate validitydate paymentdate - datepaid transdate_oe deliverydate_oe + datepaid transdate_oe deliverydate_oe dodate employee_startdate employee_enddate ), grep({ /^datepaid_\d+$/ || @@ -1426,7 +1471,7 @@ sub print_form { reformat_numbers($output_numberformat, 2, qw(invtotal ordtotal quototal subtotal linetotal listprice sellprice netprice discount - tax taxbase total paid), + tax taxbase total paid payment), grep({ /^(?:linetotal|nodiscount_linetotal|listprice|sellprice|netprice|taxbase|discount|p_discount|discount_sub|nodiscount_sub|paid|subtotal|total|tax)_\d+$/ } keys(%{$form}))); reformat_numbers($output_numberformat, undef, @@ -1461,17 +1506,26 @@ sub print_form { $extension = 'xls'; } - my $email_extension = (($form->{media} eq 'email') && (-f "$myconfig{templates}/$form->{formname}_email$form->{language}${printer_code}.${extension}")) ? '_email' : ''; + # search for the template + my @template_files; + push @template_files, "$form->{formname}_email$form->{language}$printer_code.$extension" if $form->{media} eq 'email'; + push @template_files, "$form->{formname}$form->{language}$printer_code.$extension"; + push @template_files, "$form->{formname}.$extension"; + push @template_files, "default.$extension"; + @template_files = uniq @template_files; + $form->{IN} = first { -f "$myconfig{templates}/$_" } @template_files; - $form->{IN} = "$form->{formname}${email_extension}$form->{language}${printer_code}.${extension}"; + if (!defined $form->{IN}) { + $::form->error($::locale->text('Cannot find matching template for this print request. Please contact your template maintainer. I tried these: #1.', join ', ', map { "'$_'"} @template_files)); + } delete $form->{OUT}; if ($form->{media} eq 'printer') { - #$form->{OUT} = "| $form->{printer_command} &>/dev/null"; - $form->{OUT} = "| $form->{printer_command} "; + $form->{OUT} = $form->{printer_command}; + $form->{OUT_MODE} = '|-'; $form->{printed} .= " $form->{formname}"; - $form->{printed} =~ s/^ //; + $form->{printed} =~ s/^ //; } my $printed = $form->{printed}; @@ -1485,24 +1539,38 @@ sub print_form { my $emailed = $form->{emailed}; if ($form->{media} eq 'queue') { - my %queued = map { s|.*/|| } split / /, $form->{queued}; + my %queued = map { s|.*[/\\]||; $_ } split / /, $form->{queued}; my $filename; + my $suffix = ($form->{postscript}) ? '.ps' : '.pdf'; if ($filename = $queued{ $form->{formname} }) { - $form->{queued} =~ s/\Q$form->{formname} $filename\E//; unlink $::lx_office_conf{paths}->{spool} . "/$filename"; - $filename =~ s/\..*$//g; + delete $queued{ $form->{formname} }; + + $form->{queued} = join ' ', %queued; + $filename =~ s/\..*$//g; + $filename .= $suffix; + $form->{OUT} = $::lx_office_conf{paths}->{spool} . "/$filename"; + $form->{OUT_MODE} = '>'; + } else { - $filename = time; - $filename .= $$; + my $temp_fh; + ($temp_fh, $filename) = File::Temp::tempfile( + 'kivitendo-spoolXXXXXX', + SUFFIX => "$suffix", + DIR => $::lx_office_conf{paths}->{spool}, + UNLINK => 0, + ); + close $temp_fh; + $form->{OUT} = "$filename"; + # use >> for OUT_MODE because file is already created by File::Temp + $form->{OUT_MODE} = '>>'; + # strip directory so that only filename is stored in table status + ($filename) = $filename =~ /^$::lx_office_conf{paths}->{spool}\/(.*)/; } - $filename .= ($form->{postscript}) ? '.ps' : '.pdf'; - $form->{OUT} = ">" . $::lx_office_conf{paths}->{spool} . "/$filename"; - # add type $form->{queued} .= " $form->{formname} $filename"; - $form->{queued} =~ s/^ //; } my $queued = $form->{queued}; @@ -1526,6 +1594,17 @@ sub print_form { } # /saving the history + # prepare meta information for template introspection + $form->{template_meta} = { + formname => $form->{formname}, + language => SL::DB::Manager::Language->find_by_or_create(id => $form->{language_id}), + format => $form->{format}, + media => $form->{media}, + extension => $extension, + printer => SL::DB::Manager::Printer->find_by_or_create(id => $form->{printer_id}), + today => DateTime->today, + }; + $form->parse_template(\%myconfig); $form->{callback} = "";