X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fio.pl;h=2f0fb95cdaf9ea4952671ac4a124bf5e59580c29;hb=71450c6ad8b6d495f605ab2d9db911122e6e114a;hp=1ce4c18a2bbe1ba96ca04d466a24fdbe9c0ac89f;hpb=5155c356275075630740e00448a251df929104d8;p=kivitendo-erp.git diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 1ce4c18a2..2f0fb95cd 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -54,7 +54,9 @@ use SL::IO; use SL::File; use SL::PriceSource; use SL::Presenter::Part; +use SL::Util qw(trim); +use SL::DB::AuthUser; use SL::DB::Contact; use SL::DB::Currency; use SL::DB::Customer; @@ -1203,6 +1205,15 @@ sub print_form { if ($form->{formname} eq "invoice") { $form->{label} = $locale->text('Invoice'); } + + if ($form->{formname} eq "invoice_for_advance_payment") { + $form->{label} = $locale->text('Invoice for Advance Payment'); + } + + if ($form->{formname} eq "final_invoice") { + $form->{label} = $locale->text('Final Invoice'); + } + if ($form->{formname} eq 'sales_order') { $inv = "ord"; $due = "req"; @@ -1300,7 +1311,7 @@ sub print_form { } $form->{TEMPLATE_DRIVER_OPTIONS} = { }; - if (any { $form->{type} eq $_ } qw(sales_quotation sales_order sales_delivery_order invoice request_quotation purchase_order purchase_delivery_order credit_note)) { + if (any { $form->{type} eq $_ } qw(sales_quotation sales_order sales_delivery_order invoice invoice_for_advance_payment final_invoice request_quotation purchase_order purchase_delivery_order credit_note)) { $form->{TEMPLATE_DRIVER_OPTIONS}->{variable_content_types} = $form->get_variable_content_types(); } @@ -1883,6 +1894,8 @@ sub _make_record_item { sales_quotation => 'OrderItem', request_quotation => 'OrderItem', invoice => 'InvoiceItem', + invoice_for_advance_payment => 'InvoiceItem', + final_invoice => 'InvoiceItem', credit_note => 'InvoiceItem', purchase_invoice => 'InvoiceItem', purchase_delivery_order => 'DeliveryOrderItem', @@ -2113,7 +2126,10 @@ sub show_sales_purchase_email_dialog { $body_params{fallback_translation_type} = "preset_text_invoice"; } - $::form->{all_employees} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]); + my @employees_with_email = grep { + my $user = SL::DB::Manager::AuthUser->find_by(login => $_->login); + $user && !!trim($user->get_config_value('email')); + } @{ SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]) }; my $email_form = { to => $email, @@ -2131,7 +2147,7 @@ sub show_sales_purchase_email_dialog { FILES => \%files, is_customer => $::form->{vc} eq 'customer', is_invoice_mail => ($record_email && $::form->{type} eq 'invoice'), - ALL_EMPLOYEES => $::form->{all_employees}, + ALL_EMPLOYEES => \@employees_with_email, }); print $::form->ajax_response_header, $html; @@ -2151,7 +2167,18 @@ sub send_sales_purchase_email { $::form->{media} = 'email'; - if (($::form->{attachment_policy} // '') =~ m{^(?:old_file|no_file)$}) { + $::form->{attachment_policy} //= ''; + + # Is an old file version available? + my $attfile; + if ($::form->{attachment_policy} eq 'old_file') { + $attfile = SL::File->get_all(object_id => $id, + object_type => $type, + file_type => 'document', + print_variant => $::form->{formname},); + } + + if ($::form->{attachment_policy} eq 'no_file' || ($::form->{attachment_policy} eq 'old_file' && $attfile)) { $::form->send_email(\%::myconfig, 'pdf'); } else { @@ -2196,3 +2223,35 @@ sub _maybe_attach_zugferd_data { $::form->error($e->message); } } + +sub download_factur_x_xml { + my ($form) = @_; + + my $record = _make_record(); + + die 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; + + my $xml_content = eval { $record->create_zugferd_data }; + + if (my $e = SL::X::ZUGFeRDValidation->caught) { + $::form->error($e->message); + } + + my $attachment_filename = $::form->generate_attachment_filename; + $attachment_filename =~ s{\.[^.]+$}{.xml}; + my %headers = ( + '-type' => 'application/xml', + '-connection' => 'close', + '-attachment' => $attachment_filename, + '-content-length' => length($xml_content), + ); + + print $::request->cgi->header(%headers); + + $::locale->with_raw_io(\*STDOUT, sub { print $xml_content }); +}