X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fio.pl;h=a89a311979145591a7e1457ba90f41964b59bc22;hb=853991311bc6804da985219eb28d86114e359cc6;hp=9f5cadf24d201f8e904a2a3b3bf67dd4697af9f8;hpb=47da14db313eaeb6cd2d260dc60e1c56a9437efc;p=kivitendo-erp.git diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 9f5cadf24..a89a31197 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -40,7 +40,7 @@ use Carp; use CGI; use List::MoreUtils qw(any uniq apply); -use List::Util qw(min max first); +use List::Util qw(sum min max first); use List::UtilsBy qw(sort_by uniq_by); use SL::ClientJS; @@ -126,8 +126,6 @@ sub _check_io_auth { sub display_row { $main::lxdebug->enter_sub(); - _check_io_auth(); - my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; @@ -373,8 +371,9 @@ sub display_row { } } - my $edit_prices = $main::auth->assert('edit_prices', 1) && (!$::form->{"active_price_source_$i"} || !$price || $price->editable); - my $edit_discounts = $main::auth->assert('edit_prices', 1) && !$::form->{"active_discount_source_$i"}; + my $right_to_edit_prices = (!$is_purchase && $main::auth->assert('sales_edit_prices', 1)) || ($is_purchase && $main::auth->assert('purchase_edit_prices', 1)); + my $edit_prices = $right_to_edit_prices && (!$::form->{"active_price_source_$i"} || !$price || $price->editable); + my $edit_discounts = $right_to_edit_prices && !$::form->{"active_discount_source_$i"}; $column_data{sellprice} = (!$edit_prices) ? $cgi->hidden( -name => "sellprice_$i", -id => "sellprice_$i", -value => $sellprice_value) . $sellprice_value : $cgi->textfield(-name => "sellprice_$i", -id => "sellprice_$i", -size => 10, -class => "numeric", -value => $sellprice_value); @@ -920,7 +919,6 @@ sub order { $item->price_factor_id(undef) if !$item->price_factor_id; $item->project_id(undef) if !$item->project_id; - $item->discount($item->discount/100.0); # autovivify all cvars that are not in the form (cvars_by_config can do it). # workaround to pre-parse number-cvars (parse_custom_variable_values does not parse number values). @@ -1289,6 +1287,10 @@ sub print_form { $form->{TEMPLATE_DRIVER_OPTIONS}->{variable_content_types} = $form->get_variable_content_types(); } + if ($form->{format} =~ m{pdf}) { + _maybe_attach_zugferd_data($form); + } + $form->isblank("email", $locale->text('E-mail address missing!')) if ($form->{media} eq 'email'); $form->isblank("${inv}date", @@ -1655,12 +1657,10 @@ sub relink_accounts { my $form = $main::form; my %myconfig = %main::myconfig; - _check_io_auth(); - $form->{"taxaccounts"} =~ s/\s*$//; $form->{"taxaccounts"} =~ s/^\s*//; foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) { - map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber)); + map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber tax_id)); # add tax_id ? } $form->{"taxaccounts"} = ""; @@ -1851,7 +1851,7 @@ sub _remove_billed_or_delivered_rows { # TODO: both of these are makeshift so that price sources can operate on rdbo objects. if # this ever gets rewritten in controller style, throw this out sub _make_record_item { - my ($row) = @_; + my ($row, %params) = @_; my $class = { sales_order => 'OrderItem', @@ -1899,12 +1899,19 @@ sub _make_record_item { if ($obj->meta->column($method)->isa('Rose::DB::Object::Metadata::Column::Date')) { $obj->${\"$method\_as_date"}($value); } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::(?:Numeric|Float|DoublePrecsion)$/) { - $obj->${\"$method\_as_number"}($value); + $obj->${\"$method\_as_number"}(($value // '') eq '' ? undef : $value); } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::Boolean$/) { $obj->$method(!!$value); + } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::(?:Big)?(?:Int(?:eger)?|Serial)$/) { + $obj->$method(($value // '') eq '' ? undef : $value * 1); } else { $obj->$method($value); } + + if ($method eq 'discount') { + $obj->discount($obj->discount / 100.0); + } + } else { $obj->{__additional_form_attributes}{$method} = $value; } @@ -1914,6 +1921,11 @@ sub _make_record_item { $obj->part(SL::DB::Part->load_cached($::form->{"id_$row"})); } + if ($obj->can('qty')) { + $obj->qty( $obj->qty * $params{factor}); + $obj->base_qty($obj->base_qty * $params{factor}); + } + return $obj; } @@ -1933,6 +1945,8 @@ sub _make_record { : do { die 'unknown invoice type' }; } + my $factor = $::form->{type} =~ m{credit_note} ? -1 : 1; + return unless $class; $class = 'SL::DB::' . $class; @@ -1950,9 +1964,11 @@ sub _make_record { if ($obj->meta->column($method)->isa('Rose::DB::Object::Metadata::Column::Date')) { $obj->${\"$method\_as_date"}($::form->{$method}); } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::(?:Numeric|Float|DoublePrecsion)$/) { - $obj->${\"$method\_as_number"}($::form->{$method}); + $obj->${\"$method\_as_number"}(($::form->{$method} // '') eq '' ? undef : $::form->{$method}); } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::Boolean$/) { $obj->$method(!!$::form->{$method}); + } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::(?:Big)?(?:Int(?:eger)?|Serial)$/) { + $obj->$method(($::form->{$method} // '') eq '' ? undef : $::form->{$method} * 1); } else { $obj->$method($::form->{$method}); } @@ -1961,12 +1977,21 @@ sub _make_record { my @items; for my $i (1 .. $::form->{rowcount}) { next unless $::form->{"id_$i"}; - push @items, _make_record_item($i); + push @items, _make_record_item($i, factor => $factor); } $obj->items(@items) if @items; $obj->is_sales(!!$obj->customer_id) if $class eq 'SL::DB::DeliveryOrder'; + if ($class eq 'SL::DB::Invoice') { + my $paid = $factor * + sum + map { $::form->parse_amount(\%::myconfig, $::form->{$_}) } + grep { m{^paid_\d+$} } + keys %{ $::form }; + $obj->paid($paid); + } + return $obj; } @@ -1975,7 +2000,7 @@ sub setup_sales_purchase_print_options { $print_form->{printers} = SL::DB::Manager::Printer->get_all_sorted; $print_form->{languages} = SL::DB::Manager::Language->get_all_sorted; - $print_form->{$_} = $::form->{$_} for qw(type media language_id printer_id storno); + $print_form->{$_} = $::form->{$_} for qw(type media language_id printer_id storno formname groupitems); return SL::Helper::PrintOptions->get_print_options( form => $print_form, @@ -2054,6 +2079,9 @@ sub show_sales_purchase_email_dialog { $email = '' if $::form->{type} eq 'purchase_delivery_order'; + $::form->{language} = $::form->get_template_language(\%::myconfig); + $::form->{language} = "_" . $::form->{language}; + my $email_form = { to => $email, cc => $email_cc, @@ -2101,3 +2129,36 @@ sub send_sales_purchase_email { print $::form->redirect_header($script . '?action=edit&id=' . $::form->escape($id) . '&type=' . $::form->escape($type)); } + +sub _maybe_attach_zugferd_data { + my ($form) = @_; + + my $record = _make_record(); + + return if !$record + || !$record->can('customer') + || !$record->customer + || !$record->can('create_pdf_a_print_options') + || !$record->can('create_zugferd_data') + || !$record->customer->create_zugferd_invoices_for_this_customer; + + eval { + my $xmlfile = File::Temp->new; + $xmlfile->print($record->create_zugferd_data); + $xmlfile->close; + + $form->{TEMPLATE_DRIVER_OPTIONS}->{pdf_a} = $record->create_pdf_a_print_options(zugferd_xmp_data => $record->create_zugferd_xmp_data); + $form->{TEMPLATE_DRIVER_OPTIONS}->{pdf_attachments} = [ + { source => $xmlfile, + name => 'ZUGFeRD-invoice.xml', + description => $::locale->text('ZUGFeRD invoice'), + relationship => '/Alternative', + mime_type => 'text/xml', + } + ]; + }; + + if (my $e = SL::X::ZUGFeRDValidation->caught) { + $::form->error($e->message); + } +}