X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fio.pl;h=5050e6aa2e5a35b979ca257ae173a0f00838850a;hb=8a2d9daf01083e1271cf6118591bb2c242734261;hp=c34913a71484ee298a5ca8368da30c4cfcebdbb1;hpb=1ed2847584d7d52092876817cd6678126f9e9421;p=kivitendo-erp.git diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index c34913a71..5050e6aa2 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -46,6 +46,9 @@ use SL::CT; use SL::IC; use SL::IO; +use SL::DB::Language; +use SL::DB::Printer; + require "bin/mozilla/common.pl"; use strict; @@ -338,7 +341,19 @@ sub display_row { $form->{"marge_percent_$i"} = 0; my $marge_color; - my $real_sellprice = $linetotal; + 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->{"lastcost_$i"} * $form->{"qty_$i"} / ( $form->{"marge_price_factor_$i"} || 1 ); my $marge_percent_warn = $myconfig{marge_percent_warn} * 1 || 15; my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1; @@ -385,7 +400,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}"; } @@ -540,6 +555,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->{$_}) } @@ -1325,12 +1345,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); @@ -1375,7 +1397,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; @@ -1424,7 +1446,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+$/ || @@ -1473,17 +1495,32 @@ 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"; - $form->{IN} = "$form->{formname}${email_extension}$form->{language}${printer_code}.${extension}"; + $form->{IN} = undef; + for my $filename (@template_files) { + if (-f "$myconfig{templates}/$filename") { + $form->{IN} = $filename; + last; + } + } + + 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}; @@ -1510,7 +1547,8 @@ sub print_form { } $filename .= ($form->{postscript}) ? '.ps' : '.pdf'; - $form->{OUT} = ">" . $::lx_office_conf{paths}->{spool} . "/$filename"; + $form->{OUT} = $::lx_office_conf{paths}->{spool} . "/$filename"; + $form->{OUT_MODE} = '>'; # add type $form->{queued} .= " $form->{formname} $filename"; @@ -1538,6 +1576,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} = "";