X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FOE.pm;h=e36a635eea77884047a6f5a6ecdcda11a0ead5a1;hb=dcb372751d2a810aabcb850532a72f3c3133c5f5;hp=13e735a384fcec8b3d3f738129301787efb9335c;hpb=50133d13d307d4172a0a3c1bd5a283e29609756a;p=kivitendo-erp.git diff --git a/SL/OE.pm b/SL/OE.pm index 13e735a38..e36a635ee 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -45,6 +45,7 @@ use SL::DB::PeriodicInvoicesConfig; use SL::DB::Status; use SL::DB::Tax; use SL::DBUtils; +use SL::HTML::Restrict; use SL::IC; use SL::TransNumber; @@ -330,6 +331,7 @@ sub save { # connect to database, turn off autocommit my $dbh = $form->get_standard_dbh; + my $restricter = SL::HTML::Restrict->create; my ($query, @values, $sth, $null); my $exchangerate = 0; @@ -415,25 +417,27 @@ sub save { $form->{"lastcost_$i"} = $form->parse_amount($myconfig, $form->{"lastcost_$i"}); - # set values to 0 if nothing entered - $form->{"discount_$i"} = $form->parse_amount($myconfig, $form->{"discount_$i"}) / 100; - - $form->{"sellprice_$i"} = $form->parse_amount($myconfig, $form->{"sellprice_$i"}); - $fxsellprice = $form->{"sellprice_$i"}; + # keep entered selling price + my $fxsellprice = + $form->parse_amount($myconfig, $form->{"sellprice_$i"}); - my ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/); - $dec = length($dec); + my ($dec) = ($fxsellprice =~ /\.(\d+)/); + $dec = length $dec; my $decimalplaces = ($dec > 2) ? $dec : 2; - $discount = $form->round_amount($form->{"sellprice_$i"} * $form->{"discount_$i"}, $decimalplaces); - $form->{"sellprice_$i"} = $form->round_amount($form->{"sellprice_$i"} - $discount, $decimalplaces); + # undo discount formatting + $form->{"discount_$i"} = $form->parse_amount($myconfig, $form->{"discount_$i"}) / 100; - $form->{"inventory_accno_$i"} *= 1; - $form->{"expense_accno_$i"} *= 1; + # deduct discount + $form->{"sellprice_$i"} = $fxsellprice * (1 - $form->{"discount_$i"}); + # round linetotal at least to 2 decimal places $price_factor = $price_factors{ $form->{"price_factor_id_$i"} } || 1; $linetotal = $form->round_amount($form->{"sellprice_$i"} * $form->{"qty_$i"} / $price_factor, 2); + $form->{"inventory_accno_$i"} *= 1; + $form->{"expense_accno_$i"} *= 1; + @taxaccounts = split(/ /, $form->{"taxaccounts_$i"}); $taxrate = 0; $taxdiff = 0; @@ -500,7 +504,7 @@ sub save { (SELECT factor FROM price_factors WHERE id = ?), ?)|; push(@values, conv_i($orderitems_id), conv_i($form->{id}), conv_i($form->{"id_$i"}), - $form->{"description_$i"}, $form->{"longdescription_$i"}, + $form->{"description_$i"}, $restricter->process($form->{"longdescription_$i"}), $form->{"qty_$i"}, $baseqty, $fxsellprice, $form->{"discount_$i"}, $form->{"unit_$i"}, conv_date($reqdate), conv_i($form->{"project_id_$i"}), @@ -662,7 +666,7 @@ sub load_periodic_invoice_config { my $config_obj = SL::DB::Manager::PeriodicInvoicesConfig->find_by(oe_id => $form->{id}); if ($config_obj) { - my $config = { map { $_ => $config_obj->$_ } qw(active terminated periodicity start_date_as_date end_date_as_date extend_automatically_by ar_chart_id + my $config = { map { $_ => $config_obj->$_ } qw(active terminated periodicity start_date_as_date end_date_as_date first_billing_date_as_date extend_automatically_by ar_chart_id print printer_id copies) }; $form->{periodic_invoices_config} = YAML::Dump($config); } @@ -1348,7 +1352,7 @@ sub order_details { push(@{ $form->{TEMPLATE_ARRAYS}->{taxnumber} }, $form->{"${item}_taxnumber"}); my $tax_obj = SL::DB::Manager::Tax->find_by(taxnumber => $form->{"${item}_taxnumber"}); - my $description = $tax_obj->translated_attribute('taxdescription', $form->{language_id}, 0) if $tax_obj; + my $description = $tax_obj ? $tax_obj->translated_attribute('taxdescription', $form->{language_id}, 0) : ''; push(@{ $form->{TEMPLATE_ARRAYS}->{taxdescription} }, $description . q{ } . 100 * $form->{"${item}_rate"} . q{%}); } @@ -1383,6 +1387,8 @@ sub order_details { $form->{delivery_term} = SL::DB::Manager::DeliveryTerm->find_by(id => $form->{delivery_term_id} || undef); $form->{delivery_term}->description_long($form->{delivery_term}->translated_attribute('description_long', $form->{language_id})) if $form->{delivery_term} && $form->{language_id}; + $::form->{order} = SL::DB::Manager::Order->find_by(id => $::form->{id}); + $main::lxdebug->leave_sub(); }