commit 40c2f02412b20d0b561905b44d1d91b19292d525
Author: Tamino Steinert <tamino.steinert@tamino.st>
Date:   Thu Dec 9 15:08:56 2021 +0100

    Reclamation: Controller and Templates created
    
        also for ReclamationReason
    
        Changes in SL/DB/Shipto.pm, SL/DB/Helper/TransNumberGenerator.pm,
        SL/Controller/File.pm and SL/Webdav.pm for Reclamation
    
        Links in menus added for:
          - Reclamation/add
          - Reclamation/list
          - ReclamationReason/list

diff --git a/SL/Controller/File.pm b/SL/Controller/File.pm
index 8dacec241..1ef5bc37d 100644
--- a/SL/Controller/File.pm
+++ b/SL/Controller/File.pm
@@ -58,6 +58,7 @@ my %file_types = (
   'sales_quotation'             => { gen => 1, gltype => '',   dir =>'SalesQuotation',       model => 'Order',          right => 'import_ar'  },
   'sales_order'                 => { gen => 5, gltype => '',   dir =>'SalesOrder',           model => 'Order',          right => 'import_ar'  },
   'sales_delivery_order'        => { gen => 1, gltype => '',   dir =>'SalesDeliveryOrder',   model => 'DeliveryOrder',  right => 'import_ar'  },
+  'sales_reclamation'           => { gen => 5, gltype => '',   dir =>'SalesReclamation',     model => 'Reclamation',    right => 'import_ar'  },
   'invoice'                     => { gen => 1, gltype => 'ar', dir =>'SalesInvoice',         model => 'Invoice',        right => 'import_ar'  },
   'invoice_for_advance_payment' => { gen => 1, gltype => 'ar', dir =>'SalesInvoice',         model => 'Invoice',        right => 'import_ar'  },
   'final_invoice'               => { gen => 1, gltype => 'ar', dir =>'SalesInvoice',         model => 'Invoice',        right => 'import_ar'  },
@@ -65,6 +66,7 @@ my %file_types = (
   'request_quotation'           => { gen => 7, gltype => '',   dir =>'RequestForQuotation',  model => 'Order',          right => 'import_ap'  },
   'purchase_order'              => { gen => 7, gltype => '',   dir =>'PurchaseOrder',        model => 'Order',          right => 'import_ap'  },
   'purchase_delivery_order'     => { gen => 7, gltype => '',   dir =>'PurchaseDeliveryOrder',model => 'DeliveryOrder',  right => 'import_ap'  },
+  'purchase_reclamation'        => { gen => 7, gltype => '',   dir =>'PurchaseReclamation',  model => 'Reclamation',    right => 'import_ap'  },
   'purchase_invoice'            => { gen => 6, gltype => 'ap', dir =>'PurchaseInvoice',      model => 'PurchaseInvoice',right => 'import_ap'  },
   'vendor'                      => { gen => 0, gltype => '',   dir =>'Vendor',               model => 'Vendor',         right => 'xx'         },
   'customer'                    => { gen => 1, gltype => '',   dir =>'Customer',             model => 'Customer',       right => 'xx'         },
diff --git a/SL/Controller/Reclamation.pm b/SL/Controller/Reclamation.pm
new file mode 100644
index 000000000..bd551b405
--- /dev/null
+++ b/SL/Controller/Reclamation.pm
@@ -0,0 +1,2570 @@
+package SL::Controller::Reclamation;
+
+use strict;
+use parent qw(SL::Controller::Base);
+
+use SL::Helper::Flash qw(flash_later);
+use SL::Presenter::Tag qw(select_tag hidden_tag div_tag);
+use SL::Locale::String qw(t8);
+use SL::SessionFile::Random;
+use SL::PriceSource;
+use SL::ReportGenerator;
+use SL::Controller::Helper::ReportGenerator;
+use SL::Webdav;
+use SL::File;
+use SL::MIME;
+use SL::Util qw(trim);
+use SL::YAML;
+use SL::DB::History;
+use SL::DB::Reclamation;
+use SL::DB::ReclamationItem;
+use SL::DB::Default;
+use SL::DB::Printer;
+use SL::DB::Language;
+use SL::DB::RecordLink;
+use SL::DB::Shipto;
+use SL::DB::Translation;
+
+use SL::Helper::CreatePDF qw(:all);
+use SL::Helper::PrintOptions;
+use SL::Helper::ShippedQty;
+use SL::Helper::UserPreferences::PositionsScrollbar;
+use SL::Helper::UserPreferences::UpdatePositions;
+
+use SL::Controller::Helper::GetModels;
+
+use List::Util qw(first sum0);
+use List::UtilsBy qw(sort_by uniq_by);
+use List::MoreUtils qw(any none pairwise first_index);
+use English qw(-no_match_vars);
+use File::Spec;
+use Cwd;
+use Sort::Naturally;
+
+# for _link_to_records
+use SL::DB::Order;
+use SL::DB::OrderItem;
+use SL::DB::DeliveryOrder;
+use SL::DB::DeliveryOrderItem;
+use SL::DB::Invoice;
+use SL::DB::PurchaseInvoice;
+use SL::DB::InvoiceItem;
+
+use Rose::Object::MakeMethods::Generic
+(
+ scalar => [ qw(item_ids_to_delete is_custom_shipto_to_delete) ],
+ 'scalar --get_set_init' => [qw(
+    all_price_factors cv models p part_picker_classification_ids reclamation
+    search_cvpartnumber show_update_button type valid_types
+ )],
+);
+
+
+# safety
+__PACKAGE__->run_before('check_auth');
+
+__PACKAGE__->run_before('recalc',
+                        only => [qw(
+                          save save_as_new print preview_pdf send_email
+                          save_and_show_email_dialog
+                          workflow_save_and_sales_or_purchase_reclamation
+                       )]);
+
+__PACKAGE__->run_before('get_unalterable_data',
+                        only => [qw(
+                          save save_as_new print preview_pdf send_email
+                          save_and_show_email_dialog
+                          workflow_save_and_sales_or_purchase_reclamation
+                        )]);
+
+#
+# actions
+#
+
+# add a new reclamation
+sub action_add {
+  my ($self) = @_;
+
+  $self->reclamation->transdate(DateTime->now_local());
+
+  $self->pre_render();
+
+  $self->render(
+    'reclamation/form',
+    title => $self->get_title_for('add'),
+    %{$self->{template_args}},
+  );
+}
+
+# edit an existing reclamation
+sub action_edit {
+  my ($self) = @_;
+
+  unless ($::form->{id}) {
+    $self->js->flash('error', t8("Can't edit unsaved reclamation. No 'id' was given."));
+    return $self->js->render();
+  }
+
+  $self->load_reclamation;
+
+  $self->recalc();
+  $self->pre_render();
+
+  $self->render(
+    'reclamation/form',
+    title => $self->get_title_for('edit'),
+    %{$self->{template_args}},
+  );
+}
+
+# delete the reclamation
+sub action_delete {
+  my ($self) = @_;
+
+  my $errors = $self->delete();
+
+  if (scalar @{ $errors }) {
+    $self->js->flash('error', $_) foreach @{ $errors };
+    return $self->js->render();
+  }
+
+  flash_later('info', t8('The reclamation has been deleted'));
+
+  my @redirect_params = (
+    action => 'add',
+    type   => $self->type,
+  );
+
+  $self->redirect_to(@redirect_params);
+}
+
+# save the reclamation
+sub action_save {
+  my ($self) = @_;
+
+  my $errors = $self->save();
+  if (scalar @{ $errors }) {
+    $self->js->flash('error', $_) foreach @{ $errors };
+    return $self->js->render();
+  }
+  flash_later('info', t8('The reclamation has been saved'));
+
+  my @redirect_params = (
+    action => 'edit',
+    type   => $self->type,
+    id     => $self->reclamation->id,
+  );
+  $self->redirect_to(@redirect_params);
+}
+
+sub action_list {
+  my ($self) = @_;
+
+  $self->_setup_search_action_bar;
+  $self->prepare_report;
+  $self->report_generator_list_objects(report => $self->{report}, objects => $self->models->get);
+}
+
+# save the reclamation as new document an open it for edit
+sub action_save_as_new {
+  my ($self) = @_;
+
+  my $reclamation = $self->reclamation;
+
+  if (!$reclamation->id) {
+    $self->js->flash('error', t8('This object has not been saved yet.'));
+    return $self->js->render();
+  }
+
+  # load reclamation from db to check if values changed
+  my $saved_reclamation = SL::DB::Reclamation->new(id => $reclamation->id)->load;
+
+  my %new_attrs;
+  # If it has been changed manually then use it as-is, otherwise change.
+  $new_attrs{record_number} = (trim($reclamation->record_number) eq $saved_reclamation->record_number)
+                            ? ''
+                            : trim($reclamation->record_number);
+  $new_attrs{transdate} = ($reclamation->transdate == $saved_reclamation->transdate)
+                        ? DateTime->today_local
+                        : $reclamation->transdate;
+  if ($reclamation->reqdate == $saved_reclamation->reqdate) {
+    $new_attrs{reqdate} = '';
+  } else {
+    $new_attrs{reqdate} = $reclamation->reqdate;
+  }
+
+  # Update employee
+  $new_attrs{employee}  = SL::DB::Manager::Employee->current;
+
+  # Create new record from current one
+  $self->reclamation(
+           SL::DB::Reclamation->new_from(
+             $reclamation,
+             destination_type   => $reclamation->type,
+             attributes         => \%new_attrs,
+             no_linked_records => 1,
+           )
+         );
+
+  # save
+  $self->action_save();
+}
+
+# print the reclamation
+#
+# This is called if "print" is pressed in the print dialog.
+# If PDF creation was requested and succeeded, the pdf is offered for download
+# via send_file (which uses ajax in this case).
+sub action_print {
+  my ($self) = @_;
+
+  $self->save_with_render_error();
+
+  $self->js_reset_reclamation_and_item_ids_after_save;
+
+  my $format      = $::form->{print_options}->{format};
+  my $media       = $::form->{print_options}->{media};
+  my $formname    = $::form->{print_options}->{formname};
+  my $copies      = $::form->{print_options}->{copies};
+  my $groupitems  = $::form->{print_options}->{groupitems};
+  my $printer_id  = $::form->{print_options}->{printer_id};
+
+  # only pdf and opendocument by now
+  if (none { $format eq $_ } qw(pdf opendocument opendocument_pdf)) {
+    return $self->js->flash('error', t8('Format \'#1\' is not supported yet/anymore.', $format))->render;
+  }
+
+  # only screen or printer by now
+  if (none { $media eq $_ } qw(screen printer)) {
+    return $self->js->flash('error', t8('Media \'#1\' is not supported yet/anymore.', $media))->render;
+  }
+
+  # create a form for generate_attachment_filename
+  my $form   = Form->new;
+  $form->{record_number} = $self->reclamation->record_number;
+  $form->{type}          = $self->type;
+  $form->{format}        = $format;
+  $form->{formname}      = $formname;
+  $form->{language}      = '_' . $self->reclamation->language->template_code if $self->reclamation->language;
+  my $pdf_filename       = $form->generate_attachment_filename();
+
+  my $pdf;
+  my @errors = generate_pdf($self->reclamation, \$pdf, {
+                              format     => $format,
+                              formname   => $formname,
+                              language   => $self->reclamation->language,
+                              printer_id => $printer_id,
+                              groupitems => $groupitems,
+                            });
+  if (scalar @errors) {
+    return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render;
+  }
+
+  if ($media eq 'screen') { # screen/download
+    $self->js->flash('info', t8('The PDF has been created'));
+    $self->send_file(
+      \$pdf,
+      type         => SL::MIME->mime_type_from_ext($pdf_filename),
+      name         => $pdf_filename,
+      js_no_render => 1,
+    );
+  } elsif ($media eq 'printer') { # printer
+    my $printer_id = $::form->{print_options}->{printer_id};
+    SL::DB::Printer->new(id => $printer_id)->load->print_document(
+      copies  => $copies,
+      content => $pdf,
+    );
+    $self->js->flash('info', t8('The PDF has been printed'));
+  }
+
+  my @warnings = store_pdf_to_webdav_and_filemanagement($self->reclamation, $pdf, $pdf_filename);
+  if (scalar @warnings) {
+    $self->js->flash('warning', $_) for @warnings;
+  }
+
+  $self->save_history('PRINTED');
+
+  $self->js
+    ->run('kivi.ActionBar.setEnabled', '#save_and_email_action')
+    ->render;
+}
+
+sub action_preview_pdf {
+  my ($self) = @_;
+
+  $self->save_with_render_error();
+
+  $self->js_reset_reclamation_and_item_ids_after_save;
+
+  my $format      = 'pdf';
+  my $media       = 'screen';
+  my $formname    = $self->type;
+
+  # only pdf
+  # create a form for generate_attachment_filename
+  my $form   = Form->new;
+  $form->{record_number} = $self->reclamation->record_number;
+  $form->{type}          = $self->type;
+  $form->{format}        = $format;
+  $form->{formname}      = $formname;
+  $form->{language}      = '_' . $self->reclamation->language->template_code if $self->reclamation->language;
+  my $pdf_filename       = $form->generate_attachment_filename();
+
+  my $pdf;
+  my @errors = generate_pdf($self->reclamation, \$pdf, {
+                             format     => $format,
+                             formname   => $formname,
+                             language   => $self->reclamation->language,
+                           });
+  if (scalar @errors) {
+    return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render;
+  }
+  $self->save_history('PREVIEWED');
+  $self->js->flash('info', t8('The PDF has been previewed'));
+  # screen/download
+  $self->send_file(
+    \$pdf,
+    type         => SL::MIME->mime_type_from_ext($pdf_filename),
+    name         => $pdf_filename,
+    js_no_render => 0,
+  );
+}
+
+# open the email dialog
+sub action_save_and_show_email_dialog {
+  my ($self) = @_;
+
+  $self->save_with_render_error();
+
+  unless ($self->reclamation->customervendor) {
+    return $self->js->flash('error',
+                            $self->cv eq 'customer' ?
+                                t8('Cannot send E-mail without customer given')
+                              : t8('Cannot send E-mail without vendor given'))
+                    ->render($self);
+  }
+
+  my $form = Form->new;
+  $form->{record_number}    = $self->reclamation->record_number;
+  $form->{cv_record_number} = $self->reclamation->cv_record_number;
+  $form->{formname}         = $self->type;
+  $form->{type}             = $self->type;
+  $form->{language}         = '_' . $self->reclamation->language->template_code if $self->reclamation->language;
+  $form->{language_id}      = $self->reclamation->language->id                  if $self->reclamation->language;
+  $form->{format}           = 'pdf';
+  $form->{cp_id}            = $self->reclamation->contact->cp_id if $self->reclamation->contact;
+
+  my $email_form;
+  $email_form->{to}   = $self->reclamation->contact->cp_email if $self->reclamation->contact;
+  $email_form->{to} ||= $self->reclamation->customervendor->email;
+  $email_form->{cc}   = $self->reclamation->customervendor->cc;
+  $email_form->{bcc}  = join ', ', grep $_, $self->reclamation->customervendor->bcc, SL::DB::Default->get->global_bcc;
+  # TODO: get addresses from shipto, if any
+  $email_form->{subject}             = $form->generate_email_subject();
+  $email_form->{attachment_filename} = $form->generate_attachment_filename();
+  $email_form->{message}             = $form->generate_email_body();
+  $email_form->{js_send_function}    = 'kivi.Reclamation.send_email()';
+
+  my %files = $self->get_files_for_email_dialog();
+  $self->{all_employees} = SL::DB::Manager::Employee->get_all(query => [ deleted => 0 ]);
+  my $dialog_html = $self->render('common/_send_email_dialog', { output => 0 },
+                                  email_form  => $email_form,
+                                  show_bcc    => $::auth->assert('email_bcc', 'may fail'),
+                                  FILES       => \%files,
+                                  is_customer => $self->cv eq 'customer',
+                                  ALL_EMPLOYEES => $self->{all_employees},
+  );
+
+  $self->js
+      ->run('kivi.Reclamation.show_email_dialog', $dialog_html)
+      ->reinit_widgets
+      ->render($self);
+}
+
+# send email
+#
+# TODO: handling error messages: flash is not displayed in dialog, but in the main form
+sub action_send_email {
+  my ($self) = @_;
+
+  my $errors = $self->save();
+
+  if (scalar @{ $errors }) {
+    $self->js->run('kivi.Reclamation.close_email_dialog');
+    $self->js->flash('error', $_) foreach @{ $errors };
+    return $self->js->render();
+  }
+
+  $self->js_reset_reclamation_and_item_ids_after_save;
+
+  # move $::form->{email_form} to $::form
+  my $email_form  = delete $::form->{email_form};
+  my %field_names = (to => 'email');
+  $::form->{ $field_names{$_} // $_ } = $email_form->{$_} for keys %{ $email_form };
+
+  # for Form::cleanup which may be called in Form::send_email
+  $::form->{cwd}    = getcwd();
+  $::form->{tmpdir} = $::lx_office_conf{paths}->{userspath};
+
+  $::form->{$_}     = $::form->{print_options}->{$_} for keys %{$::form->{print_options}};
+  $::form->{media}  = 'email';
+
+  if (($::form->{attachment_policy} // '') !~ m{^(?:old_file|no_file)$}) {
+    my $pdf;
+    my @errors = generate_pdf($self->reclamation, \$pdf, {
+                               media      => $::form->{media},
+                               format     => $::form->{print_options}->{format},
+                               formname   => $::form->{print_options}->{formname},
+                               language   => $self->reclamation->language,
+                               printer_id => $::form->{print_options}->{printer_id},
+                               groupitems => $::form->{print_options}->{groupitems}
+                             });
+    if (scalar @errors) {
+      return $self->js->flash('error', t8('Conversion to PDF failed: #1', $errors[0]))->render($self);
+    }
+
+    my @warnings = store_pdf_to_webdav_and_filemanagement($self->reclamation, $pdf, $::form->{attachment_filename});
+    if (scalar @warnings) {
+      flash_later('warning', $_) for @warnings;
+    }
+
+    my $sfile = SL::SessionFile::Random->new(mode => "w");
+    $sfile->fh->print($pdf);
+    $sfile->fh->close;
+
+    $::form->{tmpfile} = $sfile->file_name;
+    $::form->{tmpdir}  = $sfile->get_path; # for Form::cleanup which may be called in Form::send_email
+  }
+
+  $::form->{id} = $self->reclamation->id; # this is used in SL::Mailer to create a linked record to the mail
+  $::form->send_email(\%::myconfig, 'pdf');
+
+  # internal notes
+  my $intnotes = $self->reclamation->intnotes;
+  $intnotes   .= "\n\n" if $self->reclamation->intnotes;
+  $intnotes   .= t8('[email]')                                       . "\n";
+  $intnotes   .= t8('Date')       . ": " . $::locale->format_date_object(
+                                             DateTime->now_local,
+                                             precision => 'seconds') . "\n";
+  $intnotes   .= t8('To (email)') . ": " . $::form->{email}          . "\n";
+  $intnotes   .= t8('Cc')         . ": " . $::form->{cc}             . "\n"    if $::form->{cc};
+  $intnotes   .= t8('Bcc')        . ": " . $::form->{bcc}            . "\n"    if $::form->{bcc};
+  $intnotes   .= t8('Subject')    . ": " . $::form->{subject}        . "\n\n";
+  $intnotes   .= t8('Message')    . ": " . $::form->{message};
+
+  $self->reclamation->update_attributes(intnotes => $intnotes);
+
+  $self->save_history('MAILED');
+
+  flash_later('info', t8('The email has been sent.'));
+
+  my @redirect_params = (
+    action => 'edit',
+    type   => $self->type,
+    id     => $self->reclamation->id,
+  );
+
+  $self->redirect_to(@redirect_params);
+}
+
+# workflow from purchase to sales reclamation
+sub action_save_and_sales_reclamation {
+  $_[0]->workflow_save_and_sales_or_purchase_reclamation();
+}
+
+# workflow from sales to purchase reclamation
+sub action_save_and_purchase_reclamation {
+  $_[0]->workflow_save_and_sales_or_purchase_reclamation();
+}
+
+# set form elements in respect to a changed customer or vendor
+#
+# This action is called on an change of the customer/vendor picker.
+sub action_customer_vendor_changed {
+  my ($self) = @_;
+
+  $self->setup_reclamation_from_cv($self->reclamation);
+  $self->recalc();
+
+  my $cv_method = $self->cv;
+
+  if ( $self->reclamation->customervendor->contacts
+       && scalar @{ $self->reclamation->customervendor->contacts } > 0) {
+    $self->js->show('#cp_row');
+  } else {
+    $self->js->hide('#cp_row');
+  }
+
+  if ($self->reclamation->customervendor->shipto
+      && scalar @{ $self->reclamation->customervendor->shipto } > 0) {
+    $self->js->show('#shipto_selection');
+  } else {
+    $self->js->hide('#shipto_selection');
+  }
+
+  $self->js->val( '#reclamation_salesman_id', $self->reclamation->salesman_id) if $self->reclamation->is_sales;
+
+  $self->js
+    ->replaceWith('#reclamation_cp_id',            $self->build_contact_select)
+    ->replaceWith('#reclamation_shipto_id',        $self->build_shipto_select)
+    ->replaceWith('#shipto_inputs  ',              $self->build_shipto_inputs)
+    ->replaceWith('#business_info_row',            $self->build_business_info_row)
+    ->val(        '#reclamation_taxzone_id',       $self->reclamation->taxzone_id)
+    ->val(        '#reclamation_taxincluded',      $self->reclamation->taxincluded)
+    ->val(        '#reclamation_currency_id',      $self->reclamation->currency_id)
+    ->val(        '#reclamation_payment_id',       $self->reclamation->payment_id)
+    ->val(        '#reclamation_delivery_term_id', $self->reclamation->delivery_term_id)
+    ->val(        '#reclamation_intnotes',         $self->reclamation->intnotes)
+    ->val(        '#reclamation_language_id',      $self->reclamation->customervendor->language_id)
+    ->focus(      '#reclamation_' . $self->cv . '_id')
+    ->run('kivi.Reclamation.update_exchangerate');
+
+  $self->js_redisplay_amounts_and_taxes;
+  $self->js_redisplay_cvpartnumbers;
+  $self->js->render();
+}
+
+# open the dialog for customer/vendor details
+sub action_show_customer_vendor_details_dialog {
+  my ($self) = @_;
+
+  my $is_sales = ($self->cv eq 'customer');
+  my $cv;
+  if ($is_sales) {
+    $cv = SL::DB::Customer->new(id => $::form->{cv_id})->load;
+  } else {
+    $cv = SL::DB::Vendor->new(id => $::form->{cv_id})->load;
+  }
+
+  my %details = map { $_ => $cv->$_ } @{$cv->meta->columns};
+  $details{discount_as_percent} = $cv->discount_as_percent;
+  $details{creditlimt}          = $cv->creditlimit_as_number;
+  $details{business}            = $cv->business->description      if $cv->business;
+  $details{language}            = $cv->language_obj->description  if $cv->language_obj;
+  $details{delivery_terms}      = $cv->delivery_term->description if $cv->delivery_term;
+  $details{payment_terms}       = $cv->payment->description       if $cv->payment;
+  $details{pricegroup}          = $cv->pricegroup->pricegroup     if !$is_sales && $cv->pricegroup;
+
+  foreach my $entry (@{ $cv->shipto }) {
+    push @{ $details{SHIPTO} },   { map { $_ => $entry->$_ } @{$entry->meta->columns} };
+  }
+  foreach my $entry (@{ $cv->contacts }) {
+    push @{ $details{CONTACTS} }, { map { $_ => $entry->$_ } @{$entry->meta->columns} };
+  }
+
+  $_[0]->render('common/show_vc_details', { layout => 0 },
+                is_customer => !$is_sales,
+                %details);
+}
+
+# called if a unit in an existing item row is changed
+sub action_unit_changed {
+  my ($self) = @_;
+
+  my $idx  = first_index { $_ eq $::form->{item_id} } @{ $::form->{reclamationitem_ids} };
+  my $item = $self->reclamation->items_sorted->[$idx];
+
+  my $old_unit_obj = SL::DB::Unit->new(name => $::form->{old_unit})->load;
+  $item->sellprice($item->unit_obj->convert_to($item->sellprice, $old_unit_obj));
+
+  $self->recalc();
+
+  $self->js
+    ->run('kivi.Reclamation.update_sellprice', $::form->{item_id}, $item->sellprice_as_number);
+  $self->js_redisplay_line_values;
+  $self->js_redisplay_amounts_and_taxes;
+  $self->js->render();
+}
+
+# add an item row for a new item entered in the input row
+sub action_add_item {
+  my ($self) = @_;
+
+  delete $::form->{add_item}->{create_part_type};
+
+  my $form_attr = $::form->{add_item};
+
+  unless ($form_attr->{parts_id}) {
+    $self->js->flash('error', t8("No part was selected."));
+    return $self->js->render();
+  }
+
+
+  my $item = new_item($self->reclamation, $form_attr);
+
+  $self->reclamation->add_items($item);
+
+  $self->recalc();
+
+  $self->get_item_cvpartnumber($item);
+
+  my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
+  my $row_as_html = $self->p->render('reclamation/tabs/basic_data/_row',
+                                     ITEM => $item,
+                                     ID   => $item_id,
+                                     SELF => $self,
+  );
+
+  if ($::form->{insert_before_item_id}) {
+    $self->js
+      ->before ('.row_entry:has(#item_' . $::form->{insert_before_item_id} . ')', $row_as_html);
+  } else {
+    $self->js
+      ->append('#row_table_id', $row_as_html);
+  }
+
+  if ( $item->part->is_assortment ) {
+    $form_attr->{qty_as_number} = 1 unless $form_attr->{qty_as_number};
+    foreach my $assortment_item ( @{$item->part->assortment_items} ) {
+      my $attr = { parts_id => $assortment_item->parts_id,
+                   qty      => $assortment_item->qty * $::form->parse_amount(\%::myconfig, $form_attr->{qty_as_number}), # TODO $form_attr->{unit}
+                   unit     => $assortment_item->unit,
+                   description => $assortment_item->part->description,
+                 };
+      my $item = new_item($self->reclamation, $attr);
+
+      # set discount to 100% if item isn't supposed to be charged, overwriting any customer discount
+      $item->discount(1) unless $assortment_item->charge;
+
+      $self->reclamation->add_items( $item );
+      $self->recalc();
+      $self->get_item_cvpartnumber($item);
+      my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
+      my $row_as_html = $self->p->render('reclamation/tabs/basic_data/_row',
+                                         ITEM => $item,
+                                         ID   => $item_id,
+                                         SELF => $self,
+      );
+      if ($::form->{insert_before_item_id}) {
+        $self->js
+          ->before ('.row_entry:has(#item_' . $::form->{insert_before_item_id} . ')', $row_as_html);
+      } else {
+        $self->js
+          ->append('#row_table_id', $row_as_html);
+      }
+    };
+  };
+
+  $self->js
+    ->val('.add_item_input', '')
+    ->run('kivi.Reclamation.init_row_handlers')
+    ->run('kivi.Reclamation.renumber_positions')
+    ->focus('#add_item_parts_id_name');
+
+  $self->js->run('kivi.Reclamation.row_table_scroll_down') if !$::form->{insert_before_item_id};
+
+  $self->js_redisplay_amounts_and_taxes;
+  $self->js->render();
+}
+
+# add item rows for multiple items at once
+sub action_add_multi_items {
+  my ($self) = @_;
+
+  my @form_attr = grep { $_->{qty_as_number} } @{ $::form->{add_items} };
+  unless (scalar(@form_attr)) {
+    $self->js->flash('error', t8("No part was selected."));
+    return $self->js->render();
+  }
+
+  my @items;
+  foreach my $attr (@form_attr) {
+    my $item = new_item($self->reclamation, $attr);
+    push @items, $item;
+    if ( $item->part->is_assortment ) {
+      foreach my $assortment_item ( @{$item->part->assortment_items} ) {
+        my $attr = { parts_id => $assortment_item->parts_id,
+                     qty      => $assortment_item->qty * $item->qty, # TODO $form_attr->{unit}
+                     unit     => $assortment_item->unit,
+                     description => $assortment_item->part->description,
+                   };
+        my $item = new_item($self->reclamation, $attr);
+
+        # set discount to 100% if item isn't supposed to be charged, overwriting any customer discount
+        $item->discount(1) unless $assortment_item->charge;
+        push @items, $item;
+      }
+    }
+  }
+  $self->reclamation->add_items(@items);
+
+  $self->recalc();
+
+  foreach my $item (@items) {
+    $self->get_item_cvpartnumber($item);
+    my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
+    my $row_as_html = $self->p->render('reclamation/tabs/basic_data/_row',
+                                       ITEM => $item,
+                                       ID   => $item_id,
+                                       SELF => $self,
+    );
+
+    if ($::form->{insert_before_item_id}) {
+      $self->js
+        ->before ('.row_entry:has(#item_' . $::form->{insert_before_item_id} . ')', $row_as_html);
+    } else {
+      $self->js
+        ->append('#row_table_id', $row_as_html);
+    }
+  }
+
+  $self->js
+    ->run('kivi.Part.close_picker_dialogs')
+    ->run('kivi.Reclamation.init_row_handlers')
+    ->run('kivi.Reclamation.renumber_positions')
+    ->focus('#add_item_parts_id_name');
+
+  $self->js->run('kivi.Reclamation.row_table_scroll_down') if !$::form->{insert_before_item_id};
+
+  $self->js_redisplay_amounts_and_taxes;
+  $self->js->render();
+}
+
+# recalculate all linetotals, amounts and taxes and redisplay them
+sub action_recalc_amounts_and_taxes {
+  my ($self) = @_;
+
+  $self->recalc();
+
+  $self->js_redisplay_line_values;
+  $self->js_redisplay_amounts_and_taxes;
+  $self->js->render();
+}
+
+sub action_update_exchangerate {
+  my ($self) = @_;
+
+  my $data = {
+    is_standard   => $self->reclamation->currency_id == $::instance_conf->get_currency_id,
+    currency_name => $self->reclamation->currency->name,
+    exchangerate  => $self->reclamation->daily_exchangerate_as_null_number,
+  };
+
+  $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
+}
+
+# redisplay item rows if they are sorted by an attribute
+sub action_reorder_items {
+  my ($self) = @_;
+
+  my %sort_keys = (
+    partnumber   => sub { $_[0]->part->partnumber },
+    description  => sub { $_[0]->description },
+    reason       => sub { $_[0]->reason eq undef ? "" : $_[0]->reason->name },
+    reason_description_ext => sub { $_[0]->reason_description_ext },
+    reason_description_int => sub { $_[0]->reason_description_int },
+    shipped_qty  => sub { $_[0]->shipped_qty },
+    qty          => sub { $_[0]->qty },
+    sellprice    => sub { $_[0]->sellprice },
+    discount     => sub { $_[0]->discount },
+    cvpartnumber => sub { $_[0]->{cvpartnumber} },
+  );
+
+  $self->get_item_cvpartnumber($_) for @{$self->reclamation->items_sorted};
+
+  if ($::form->{order_by} eq 'shipped_qty') {
+    # Calculate shipped qtys here to prevent calling calculate for every item
+    # via the items method. Do not use write_to_objects to prevent
+    # reclamation->delivered to be set, because this should be the value from
+    # db, which can be set manually or is set when linked delivery orders are
+    # saved.
+    SL::Helper::ShippedQty->new->calculate($self->reclamation)->write_to(\@{$self->reclamation->items});
+  }
+
+  my $method = $sort_keys{$::form->{order_by}};
+  my @to_sort = map { { old_pos => $_->position, order_by => $method->($_) } } @{ $self->reclamation->items_sorted };
+  if ($::form->{sort_dir}) {
+    if ( $::form->{order_by} =~ m/qty|sellprice|discount/ ){
+      @to_sort = sort { $a->{order_by} <=> $b->{order_by} } @to_sort;
+    } else {
+      @to_sort = sort { $a->{order_by} cmp $b->{order_by} } @to_sort;
+    }
+  } else {
+    if ( $::form->{order_by} =~ m/qty|sellprice|discount/ ){
+      @to_sort = sort { $b->{order_by} <=> $a->{order_by} } @to_sort;
+    } else {
+      @to_sort = sort { $b->{order_by} cmp $a->{order_by} } @to_sort;
+    }
+  }
+  $self->js
+    ->run('kivi.Reclamation.redisplay_items', \@to_sort)
+    ->render;
+}
+
+# show the popup to choose a price/discount source
+sub action_price_popup {
+  my ($self) = @_;
+
+  my $idx  = first_index { $_ eq $::form->{item_id} } @{ $::form->{reclamation_items_ids} };
+  my $item = $self->reclamation->items_sorted->[$idx];
+  if ($item->is_linked_to_record) {
+    $self->js->flash('error', t8("Can't change price of a linked item"));
+    return $self->js->render();
+  }
+
+  $self->render_price_dialog($item);
+}
+
+# save the reclamation in a session variable and redirect to the part controller
+sub action_create_part {
+  my ($self) = @_;
+
+  my $previousform = $::auth->save_form_in_session(non_scalars => 1);
+
+  my $callback     = $self->url_for(
+    action       => 'return_from_create_part',
+    type         => $self->type, # type is needed for check_auth on return
+    previousform => $previousform,
+  );
+
+  flash_later('info', t8('You are adding a new part while you are editing another document. You will be redirected to your document when saving the new part or aborting this form.'));
+
+  my @redirect_params = (
+    controller => 'Part',
+    action     => 'add',
+    part_type  => $::form->{add_item}->{create_part_type},
+    callback   => $callback,
+    show_abort => 1,
+  );
+
+  $self->redirect_to(@redirect_params);
+}
+
+sub action_return_from_create_part {
+  my ($self) = @_;
+
+  $self->{created_part} = SL::DB::Part->new(id => delete $::form->{new_parts_id})->load if $::form->{new_parts_id};
+
+  $::auth->restore_form_from_session(delete $::form->{previousform});
+
+  # set item ids to new fake id, to identify them as new items
+  foreach my $item (@{$self->reclamation->items_sorted}) {
+    $item->{new_fake_id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
+  }
+
+  $self->recalc();
+  $self->get_unalterable_data();
+  $self->pre_render();
+
+  # trigger rendering values for second row/longdescription as hidden, because
+  # they are loaded only on demand. So we need to keep the values from the
+  # source.
+  $_->{render_second_row}      = 1 for @{ $self->reclamation->items_sorted };
+  $_->{render_longdescription} = 1 for @{ $self->reclamation->items_sorted };
+
+  $self->render(
+    'reclamation/form',
+    title => $self->get_title_for('edit'),
+    %{$self->{template_args}}
+  );
+}
+
+# load the second row for one or more items
+#
+# This action gets the html code for all items second rows by rendering a template for
+# the second row and sets the html code via client js.
+sub action_load_second_rows {
+  my ($self) = @_;
+
+  foreach my $item_id (@{ $::form->{reclamation_items_ids} }) {
+    my $idx  = first_index { $_ eq $item_id } @{ $::form->{reclamation_items_ids} };
+    my $item = $self->reclamation->items_sorted->[$idx];
+
+    $self->js_load_second_row($item, $item_id, 0);
+  }
+
+  $self->js->run('kivi.Reclamation.init_row_handlers') if $self->reclamation->is_sales; # for lastcosts change-callback
+
+  $self->js->render();
+}
+
+# update description, notes and sellprice from master data
+sub action_update_row_from_master_data {
+  my ($self) = @_;
+
+  foreach my $item_id (@{ $::form->{item_ids} }) {
+    my $idx   = first_index { $_ eq $item_id } @{ $::form->{reclamationitem_ids} };
+    my $item  = $self->reclamation->items_sorted->[$idx];
+
+    if ($item->is_linked_to_record) {
+      $self->js->flash_later('error', t8("Can't change data of a linked item. Part: " . $item->part->partnumber));
+      next;
+    }
+
+    my $texts = get_part_texts($item->part, $self->reclamation->language_id);
+
+    $item->description($texts->{description});
+    $item->longdescription($texts->{longdescription});
+
+    my $price_source = SL::PriceSource->new(record_item => $item, record => $self->reclamation);
+
+    my $price_src;
+    if ($item->part->is_assortment) {
+    # add assortment items with price 0, as the components carry the price
+      $price_src = $price_source->price_from_source("");
+      $price_src->price(0);
+    } else {
+      $price_src = $price_source->best_price
+                 ? $price_source->best_price
+                 : $price_source->price_from_source("");
+      $price_src->price($::form->round_amount($price_src->price / $self->reclamation->exchangerate, 5)) if $self->reclamation->exchangerate;
+      $price_src->price(0) if !$price_source->best_price;
+    }
+
+    $item->sellprice($price_src->price);
+    $item->active_price_source($price_src);
+
+    $self->js
+      ->run('kivi.Reclamation.update_sellprice', $item_id, $item->sellprice_as_number)
+      ->html('.row_entry:has(#item_' . $item_id
+             . ') [name = "partnumber"] a', $item->part->partnumber)
+      ->val ('.row_entry:has(#item_' . $item_id
+             . ') [name = "reclamation.reclamation_items[].description"]',
+             $item->description)
+      ->val ('.row_entry:has(#item_' . $item_id
+             . ') [name = "reclamation.reclamation_items[].longdescription"]',
+             $item->longdescription);
+
+    if ($self->search_cvpartnumber) {
+      $self->get_item_cvpartnumber($item);
+      $self->js->html('.row_entry:has(#item_' . $item_id
+                      . ') [name = "cvpartnumber"]', $item->{cvpartnumber});
+    }
+  }
+
+  $self->recalc();
+  $self->js_redisplay_line_values;
+  $self->js_redisplay_amounts_and_taxes;
+
+  $self->js->render();
+}
+
+sub js_load_second_row {
+  my ($self, $item, $item_id, $do_parse) = @_;
+
+  if ($do_parse) {
+    # Parse values from form (they are formated while rendering (template)).
+    # Workaround to pre-parse number-cvars (parse_custom_variable_values does
+    # not parse number values). This parsing is not necessary at all, if we
+    # assure that the second row/cvars are only loaded once.
+    foreach my $var (@{ $item->cvars_by_config }) {
+      if ($var->config->type eq 'number' && exists($var->{__unparsed_value})) {
+        $var->unparsed_value($::form->parse_amount(\%::myconfig, $var->{__unparsed_value}));
+      }
+    }
+    $item->parse_custom_variable_values;
+  }
+
+  my $row_as_html = $self->p->render('reclamation/tabs/basic_data/_second_row', ITEM => $item, TYPE => $self->type);
+
+  $self->js
+    ->html('#second_row_' . $item_id, $row_as_html)
+    ->data('#second_row_' . $item_id, 'loaded', 1);
+}
+
+sub js_redisplay_line_values {
+  my ($self) = @_;
+
+  my @data = map {[
+       $::form->format_amount(\%::myconfig, $_->{linetotal}, 2, 0),
+      ]} @{ $self->reclamation->items_sorted };
+
+  $self->js
+    ->run('kivi.Reclamation.redisplay_line_values', $self->reclamation->is_sales, \@data);
+}
+
+sub js_redisplay_amounts_and_taxes {
+  my ($self) = @_;
+
+  if (scalar @{ $self->reclamation->taxes }) {
+    $self->js->show('#taxincluded_row_id');
+  } else {
+    $self->js->hide('#taxincluded_row_id');
+  }
+
+  if ($self->reclamation->taxincluded) {
+    $self->js->hide('#subtotal_row_id');
+  } else {
+    $self->js->show('#subtotal_row_id');
+  }
+
+  $self->js
+    ->html('#netamount_id', $::form->format_amount(\%::myconfig, $self->reclamation->netamount, -2))
+    ->html('#amount_id',    $::form->format_amount(\%::myconfig, $self->reclamation->amount,    -2))
+    ->remove('.tax_row')
+    ->insertBefore($self->build_tax_rows, '#amount_row_id');
+}
+
+sub js_redisplay_cvpartnumbers {
+  my ($self) = @_;
+
+  $self->get_item_cvpartnumber($_) for @{$self->reclamation->items_sorted};
+
+  my @data = map {[$_->{cvpartnumber}]} @{ $self->reclamation->items_sorted };
+
+  $self->js
+    ->run('kivi.Reclamation.redisplay_cvpartnumbers', \@data);
+}
+sub js_reset_reclamation_and_item_ids_after_save {
+  my ($self) = @_;
+
+  $self->js
+    ->val('#id', $self->reclamation->id)
+    ->val('#converted_from_record_type_ref', '')
+    ->val('#converted_from_record_id',  '')
+    ->val('#reclamation_record_number', $self->reclamation->record_number);
+
+  my $idx = 0;
+  foreach my $form_item_id (@{ $::form->{reclamationitem_ids} }) {
+    next if !$self->reclamation->items_sorted->[$idx]->id;
+    next if $form_item_id !~ m{^new};
+    $self->js
+      ->val ('[name="reclamationitem_ids[+]"][value="' . $form_item_id . '"]',
+             $self->reclamation->items_sorted->[$idx]->id)
+      ->val ('#item_' . $form_item_id,
+             $self->reclamation->items_sorted->[$idx]->id)
+      ->attr('#item_' . $form_item_id, "id",
+             'item_' . $self->reclamation->items_sorted->[$idx]->id);
+  } continue {
+    $idx++;
+  }
+  $self->js->val('[name="converted_from_record_item_type_refs[+]"]', '');
+  $self->js->val('[name="converted_from_record_item_ids[+]"]', '');
+}
+
+#
+# helpers
+#
+
+sub init_valid_types {
+  [ sales_reclamation_type(), purchase_reclamation_type() ];
+}
+
+sub init_type {
+  my ($self) = @_;
+
+  if (none { $::form->{type} eq $_ } @{$self->valid_types}) {
+    die "Not a valid type for reclamation";
+  }
+
+  $self->type($::form->{type});
+}
+
+sub init_cv {
+  my ($self) = @_;
+
+  my $cv = (any { $self->type eq $_ } (sales_reclamation_type()))   ? 'customer'
+         : (any { $self->type eq $_ } (purchase_reclamation_type())) ? 'vendor'
+         : die "Not a valid type for reclamation";
+
+  return $cv;
+}
+
+sub init_search_cvpartnumber {
+  my ($self) = @_;
+
+  my $user_prefs = SL::Helper::UserPreferences::PartPickerSearch->new();
+  my $search_cvpartnumber;
+  $search_cvpartnumber = !!$user_prefs->get_sales_search_customer_partnumber() if $self->cv eq 'customer';
+  $search_cvpartnumber = !!$user_prefs->get_purchase_search_makemodel()        if $self->cv eq 'vendor';
+
+  return $search_cvpartnumber;
+}
+
+sub init_show_update_button {
+  my ($self) = @_;
+
+  !!SL::Helper::UserPreferences::UpdatePositions->new()->get_show_update_button();
+}
+
+sub init_models {
+  my ($self) = @_;
+
+  SL::Controller::Helper::GetModels->new(
+    controller => $self,
+    sorted => {
+      _default  => {
+        by  => 'record_number',
+        dir => 0,
+      },
+      id                      => t8('ID'),
+      record_number           => t8('Reclamation Number'),
+      employee_id             => t8('Employee'),
+      salesman_id             => t8('Salesman'),
+      customer_id             => t8('Customer'),
+      vendor_id               => t8('Vendor'),
+      contact_id              => t8('Contact'),
+      language_id             => t8('Language'),
+      department_id           => t8('Department'),
+      globalproject_id        => t8('Project Number'),
+      cv_record_number        => ($self->type eq 'sales_reclamation' ? t8('Customer Record Number') : t8('Vendor Record Number')),
+      transaction_description => t8('Description'),
+      notes                   => t8('Notes'),
+      intnotes                => t8('Internal Notes'),
+      shippingpoint           => t8('Shipping Point'),
+      shipvia                 => t8('Ship via'),
+      shipto_id               => t8('Shipping Address'),
+      amount                  => t8('Total'),
+      netamount               => t8('Subtotal'),
+      delivery_term_id        => t8('Delivery Terms'),
+      payment_id              => t8('Payment Terms'),
+      currency_id             => t8('Currency'),
+      exchangerate            => t8('Exchangerate'),
+      taxincluded             => t8('Tax Included'),
+      taxzone_id              => t8('Tax zone'),
+      tax_point               => t8('Tax point'),
+      reqdate                 => t8('Due Date'),
+      transdate               => t8('Booking Date'),
+      itime                   => t8('Creation Time'),
+      mtime                   => t8('Last modification Time'),
+      delivered               => t8('Delivered'),
+      closed                  => t8('Closed'),
+    },
+    query => [
+      SL::DB::Manager::Reclamation->type_filter($self->type),
+      (salesman_id => SL::DB::Manager::Employee->current->id) x ($self->reclamation->is_sales  && !$::auth->assert('sales_all_edit', 1)),
+      (employee_id => SL::DB::Manager::Employee->current->id) x ($self->reclamation->is_sales  && !$::auth->assert('sales_all_edit', 1)),
+      (employee_id => SL::DB::Manager::Employee->current->id) x (!$self->reclamation->is_sales && !$::auth->assert('purchase_all_edit', 1)),
+    ],
+  );
+}
+
+sub init_p {
+  SL::Presenter->get;
+}
+
+sub init_reclamation {
+  $_[0]->make_reclamation;
+}
+
+sub init_all_price_factors {
+  SL::DB::Manager::PriceFactor->get_all;
+}
+
+sub init_part_picker_classification_ids {
+  my ($self)    = @_;
+  my $attribute = 'used_for_' . ($self->type eq sales_reclamation_type() ? 'sale' : 'purchase');
+
+  return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(where => [ $attribute => 1 ]) } ];
+}
+
+sub check_auth {
+  my ($self) = @_;
+
+  my $right_for = { map { $_ => $_.'_edit' } @{$self->valid_types} };
+
+  my $right   = $right_for->{ $self->type };
+  $right    ||= 'DOES_NOT_EXIST';
+
+  $::auth->assert($right);
+}
+
+# build the selection box for contacts
+#
+# Needed, if customer/vendor changed.
+sub build_contact_select {
+  my ($self) = @_;
+
+  select_tag('reclamation.contact_id', [ $self->reclamation->customervendor->contacts ],
+    value_key  => 'cp_id',
+    title_key  => 'full_name_dep',
+    default    => $self->reclamation->contact_id,
+    with_empty => 1,
+    style      => 'width: 300px',
+  );
+}
+
+# build the selection box for shiptos
+#
+# Needed, if customer/vendor changed.
+sub build_shipto_select {
+  my ($self) = @_;
+
+  select_tag('reclamation.shipto_id',
+             [ {displayable_id => t8("No/individual shipping address"),
+                shipto_id => '',
+               },
+               $self->reclamation->customervendor->shipto
+             ],
+             value_key  => 'shipto_id',
+             title_key  => 'displayable_id',
+             default    => $self->reclamation->shipto_id,
+             with_empty => 0,
+             style      => 'width: 300px',
+  );
+}
+
+# build the inputs for the cusom shipto dialog
+#
+# Needed, if customer/vendor changed.
+sub build_shipto_inputs {
+  my ($self) = @_;
+
+  my $content = $self->p->render('common/_ship_to_dialog',
+                                 cv_obj      => $self->reclamation->customervendor,
+                                 cs_obj      => $self->reclamation->custom_shipto,
+                                 cvars       => $self->reclamation->custom_shipto->cvars_by_config,
+                                 id_selector => '#reclamation_shipto_id');
+
+  div_tag($content, id => 'shipto_inputs');
+}
+
+# render the info line for business
+#
+# Needed, if customer/vendor changed.
+sub build_business_info_row
+{
+  $_[0]->p->render('reclamation/tabs/basic_data/_business_info_row', SELF => $_[0]);
+}
+
+# build the rows for displaying taxes
+#
+# Called if amounts where recalculated and redisplayed.
+sub build_tax_rows {
+  my ($self) = @_;
+
+  my $rows_as_html;
+  foreach my $tax (sort { $a->{tax}->rate cmp $b->{tax}->rate } @{ $self->reclamation->taxes }) {
+    $rows_as_html .= $self->p->render(
+                       'reclamation/tabs/basic_data/_tax_row',
+                       TAX => $tax,
+                       TAXINCLUDED => $self->reclamation->taxincluded,
+                     );
+  }
+  return $rows_as_html;
+}
+
+sub render_price_dialog {
+  my ($self, $record_item) = @_;
+
+  my $price_source = SL::PriceSource->new(
+                       record_item => $record_item,
+                       record => $self->reclamation,
+                     );
+
+  $self->js
+    ->run(
+      'kivi.io.price_chooser_dialog',
+      t8('Available Prices'),
+      $self->render(
+        'reclamation/tabs/basic_data/_price_sources_dialog',
+        { output => 0 },
+        price_source => $price_source,
+      ),
+    )
+    ->reinit_widgets;
+
+#   if (@errors) {
+#     $self->js->text('#dialog_flash_error_content', join ' ', @errors);
+#     $self->js->show('#dialog_flash_error');
+#   }
+
+  $self->js->render;
+}
+
+sub load_reclamation {
+  my ($self) = @_;
+
+  return if !$::form->{id};
+
+  $self->reclamation(SL::DB::Reclamation->new(id => $::form->{id})->load);
+
+  # Add an empty custom shipto to the reclamation, so that the dialog can render
+  # the cvar inputs. You need a custom shipto object to call cvars_by_config to
+  # get the cvars.
+  if (!$self->reclamation->custom_shipto) {
+    $self->reclamation->custom_shipto(SL::DB::Shipto->new(module => 'RC', custom_variables => []));
+  }
+
+  return $self->reclamation;
+}
+
+# load or create a new reclamation object
+#
+# And assign changes from the form to this object.
+# If the reclamation is loaded from db, check if items are deleted in the form,
+# remove them form the object and collect them for removing from db on saving.
+# Then create/update items from form (via make_item) and add them.
+sub make_reclamation {
+  my ($self) = @_;
+
+  # add_items adds items to an reclamation with no items for saving, but they
+  # cannot be retrieved via items until the reclamation is saved. Adding empty
+  # items to new reclamation here solves this problem.
+  my $reclamation;
+  if ($::form->{id}) {
+    $reclamation = SL::DB::Reclamation->new(id => $::form->{id})->load();
+  } else {
+    $reclamation = SL::DB::Reclamation->new(
+                     reclamation_items  => [],
+                     currency_id => $::instance_conf->get_currency_id(),
+                   );
+    my $cv_id_method = $self->cv . '_id';
+    if ($::form->{$cv_id_method}) {
+      $reclamation->$cv_id_method($::form->{$cv_id_method});
+      $self->setup_reclamation_from_cv($reclamation);
+    }
+  }
+
+  my $form_reclamation_items = delete $::form->{reclamation}->{reclamation_items};
+
+  $reclamation->assign_attributes(%{$::form->{reclamation}});
+
+  $self->setup_custom_shipto_from_form($reclamation, $::form);
+
+  # remove deleted items
+  $self->item_ids_to_delete([]);
+  foreach my $idx (reverse 0..$#{$reclamation->reclamation_items}) {
+    my $item = $reclamation->reclamation_items->[$idx];
+    if (none { $item->id == $_->{id} } @{$form_reclamation_items}) {
+      splice @{$reclamation->reclamation_items}, $idx, 1;
+      push @{$self->item_ids_to_delete}, $item->id;
+    }
+  }
+
+  my @items;
+  my $pos = 1;
+  foreach my $form_attr (@{$form_reclamation_items}) {
+    my $item = make_item($reclamation, $form_attr);
+    $item->position($pos);
+    push @items, $item;
+    $pos++;
+  }
+  $reclamation->add_items(grep {!$_->id} @items);
+
+  return $reclamation;
+}
+
+# create or update items from form
+#
+# Make item objects from form values. For items already existing read from db.
+# Create a new item else. And assign attributes.
+sub make_item {
+  my ($record, $attr) = @_;
+
+  my $item;
+  $item = first { $_->id == $attr->{id} } @{$record->items} if $attr->{id};
+
+  my $is_new = !$item;
+
+  # add_custom_variables adds cvars to an reclamation_item with no cvars for
+  # saving, but they cannot be retrieved via custom_variables until the
+  # reclamation/reclamation_item is saved. Adding empty custom_variables to new
+  # reclamationitem here solves this problem.
+  $item ||= SL::DB::ReclamationItem->new(custom_variables => []);
+
+  $item->assign_attributes(%$attr);
+
+  if ($is_new) {
+    my $texts = get_part_texts($item->part, $record->language_id);
+    $item->longdescription($texts->{longdescription})              if !defined $attr->{longdescription};
+    $item->project_id($record->globalproject_id)                   if !defined $attr->{project_id};
+    $item->lastcost($record->is_sales ? $item->part->lastcost : 0) if !defined $attr->{lastcost_as_number};
+  }
+
+  return $item;
+}
+
+# create a new item
+#
+# This is used to add one item
+sub new_item {
+  my ($record, $attr) = @_;
+
+  my $item = SL::DB::ReclamationItem->new;
+
+  # Remove attributes where the user left or set the inputs empty.
+  # So these attributes will be undefined and we can distinguish them
+  # from zero later on.
+  for (qw(qty_as_number sellprice_as_number discount_as_percent)) {
+    delete $attr->{$_} if $attr->{$_} eq '';
+  }
+
+  $item->assign_attributes(%$attr);
+
+  my $part         = SL::DB::Part->new(id => $attr->{parts_id})->load;
+  my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
+  $item->unit($part->unit) if !$item->unit;
+
+  my $price_src;
+  if ( $part->is_assortment ) {
+    # add assortment items with price 0, as the components carry the price
+    $price_src = $price_source->price_from_source("");
+    $price_src->price(0);
+  } elsif (defined $item->sellprice) {
+    $price_src = $price_source->price_from_source("");
+    $price_src->price($item->sellprice);
+  } else {
+    $price_src = $price_source->best_price
+               ? $price_source->best_price
+               : $price_source->price_from_source("");
+    if ($record->exchangerate) {
+      $price_src->price($::form->round_amount($price_src->price / $record->exchangerate, 5));
+    }
+    $price_src->price(0) if !$price_source->best_price;
+  }
+
+  my $discount_src;
+  if (defined $item->discount) {
+    $discount_src = $price_source->discount_from_source("");
+    $discount_src->discount($item->discount);
+  } else {
+    $discount_src = $price_source->best_discount
+                  ? $price_source->best_discount
+                  : $price_source->discount_from_source("");
+    $discount_src->discount(0) if !$price_source->best_discount;
+  }
+
+  my %new_attr;
+  $new_attr{part}                   = $part;
+  $new_attr{description}            = $part->description     if ! $item->description;
+  $new_attr{qty}                    = 1.0                    if ! $item->qty;
+  $new_attr{price_factor_id}        = $part->price_factor_id if ! $item->price_factor_id;
+  $new_attr{sellprice}              = $price_src->price;
+  $new_attr{discount}               = $discount_src->discount;
+  $new_attr{active_price_source}    = $price_src;
+  $new_attr{active_discount_source} = $discount_src;
+  $new_attr{longdescription}        = $part->notes           if ! defined $attr->{longdescription};
+  $new_attr{project_id}             = $record->globalproject_id;
+  $new_attr{lastcost}               = $record->is_sales ? $part->lastcost : 0;
+
+  # add_custom_variables adds cvars to an reclamationitem with no cvars for saving, but
+  # they cannot be retrieved via custom_variables until the reclamation/reclamationitem is
+  # saved. Adding empty custom_variables to new reclamationitem here solves this problem.
+  $new_attr{custom_variables} = [];
+
+  my $texts = get_part_texts($part, $record->language_id,
+                description => $new_attr{description},
+                longdescription => $new_attr{longdescription},
+              );
+
+  $item->assign_attributes(%new_attr, %{ $texts });
+
+  $item->reclamation($record);
+  return $item;
+}
+
+sub setup_reclamation_from_cv {
+  my ($self, $reclamation) = @_;
+
+  $reclamation->$_($reclamation->customervendor->$_) for (qw(taxzone_id payment_id delivery_term_id currency_id));
+
+  $reclamation->intnotes($reclamation->customervendor->notes);
+
+  if ($reclamation->is_sales ) {
+    $reclamation->salesman_id($reclamation->customer->salesman_id || SL::DB::Manager::Employee->current->id);
+    $reclamation->taxincluded(
+      defined($reclamation->customervendor->taxincluded_checked)
+        ? $reclamation->customervendor->taxincluded_checked
+        : $::myconfig{taxincluded_checked}
+    );
+  }
+
+}
+
+# setup custom shipto from form
+#
+# The dialog returns form variables starting with 'shipto' and cvars starting
+# with 'shiptocvar_'.
+# Mark it to be deleted if a shipto from master data is selected
+# (i.e. reclamation has a shipto).
+# Else, update or create a new custom shipto. If the fields are empty, it
+# will not be saved on save.
+sub setup_custom_shipto_from_form {
+  my ($self, $reclamation, $form) = @_;
+
+  if ($reclamation->shipto) {
+    $self->is_custom_shipto_to_delete(1);
+  } else {
+    my $custom_shipto =    $reclamation->custom_shipto
+                        || $reclamation->custom_shipto(
+                             SL::DB::Shipto->new(module => 'RC', custom_variables => [])
+                           );
+
+    my $shipto_cvars  = {map { my ($key) = m{^shiptocvar_(.+)}; $key => delete $form->{$_}} grep { m{^shiptocvar_} } keys %$form};
+    my $shipto_attrs  = {map {                                  $_   => delete $form->{$_}} grep { m{^shipto}      } keys %$form};
+
+    $custom_shipto->assign_attributes(%$shipto_attrs);
+    $custom_shipto->cvar_by_name($_)->value($shipto_cvars->{$_}) for keys %$shipto_cvars;
+  }
+}
+
+# recalculate prices and taxes
+#
+# Using the PriceTaxCalculator. Store linetotals in the item objects.
+sub recalc {
+  my ($self) = @_;
+
+  my %pat = $self->reclamation->calculate_prices_and_taxes();
+
+  pairwise { $a->{linetotal} = $b->{linetotal} } @{$self->reclamation->items_sorted}, @{$pat{items}};
+}
+
+# get data for saving, printing, ..., that is not changed in the form
+#
+# Only cvars for now.
+sub get_unalterable_data {
+  my ($self) = @_;
+
+  foreach my $item (@{ $self->reclamation->items }) {
+    # 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).
+    foreach my $var (@{ $item->cvars_by_config }) {
+      if ($var->config->type eq 'number' && exists($var->{__unparsed_value})) {
+        $var->unparsed_value($::form->parse_amount(\%::myconfig, $var->{__unparsed_value}));
+      }
+    }
+    $item->parse_custom_variable_values;
+  }
+}
+
+# delete the reclamation
+#
+# And remove related files in the spool directory
+sub delete {
+  my ($self) = @_;
+
+  my $errors = [];
+  my $db     = $self->reclamation->db;
+
+  $db->with_transaction(
+    sub {
+      my @spoolfiles = grep { $_ } map { $_->spoolfile } @{ SL::DB::Manager::Status->get_all(where => [ trans_id => $self->reclamation->id ]) };
+      $self->reclamation->delete;
+      my $spool = $::lx_office_conf{paths}->{spool};
+      unlink map { "$spool/$_" } @spoolfiles if $spool;
+
+      $self->save_history('DELETED');
+
+      1;
+  }) || push(@{$errors}, $db->error);
+
+  return $errors;
+}
+
+# save the reclamation
+#
+# And delete items that are deleted in the form.
+sub save {
+  my ($self) = @_;
+
+  my $errors = [];
+  my $db     = $self->reclamation->db;
+
+  $db->with_transaction(sub {
+    # delete custom shipto if it is to be deleted or if it is empty
+    if ($self->reclamation->custom_shipto
+        && ($self->is_custom_shipto_to_delete
+            || $self->reclamation->custom_shipto->is_empty)
+       ) {
+      $self->reclamation->custom_shipto->delete if $self->reclamation->custom_shipto->shipto_id;
+      $self->reclamation->custom_shipto(undef);
+    }
+
+    SL::DB::ReclamationItem->new(id => $_)->delete for @{$self->item_ids_to_delete || []};
+    $self->reclamation->save(cascade => 1);
+
+    $self->_link_to_records();
+
+    $self->save_history('SAVED');
+
+    1;
+  }) || push(@{$errors}, $db->error);
+
+  return $errors;
+}
+
+sub _link_to_records {
+  my ($self) = @_;
+  my %allowed_linked_records = map {$_ => 1} qw(
+    SL::DB::Reclamation
+  );
+  my %allowed_linked_record_items = map {$_ => 1} qw(
+    SL::DB::ReclamationItem
+  );
+
+  my $from_record_id = delete $::form->{converted_from_record_id};
+  $from_record_id ||= $self->reclamation->{converted_from_record_id};
+  if ($from_record_id) {
+    my $from_record_type = delete $::form->{converted_from_record_type_ref};
+    $from_record_type ||= $self->reclamation->{converted_from_record_type_ref};
+    unless ($allowed_linked_records{$from_record_type}) {
+      croak("Not allowed converted_from_record_type_ref: '" . $from_record_type);
+    }
+    my $src = ${from_record_type}->new(id => $from_record_id)->load;
+    $src->link_to_record($self->reclamation);
+    #clear converted_from;
+    delete $self->reclamation->{$_} for qw(converted_from_record_id converted_from_record_type_ref);
+
+    if (scalar @{ $::form->{converted_from_record_item_ids} || [] }) {
+      my $idx = -1;
+      my $from_record_item_ids = delete $::form->{converted_from_record_item_ids} ;
+      my $from_record_item_type_refs = delete $::form->{converted_from_record_item_type_refs} ;
+      for my $idx (0 .. $#{ $self->reclamation->items_sorted }) {
+        my $from_item_id = $from_record_item_ids->[$idx];
+        my $reclamation_item = $self->reclamation->items_sorted->[$idx];
+        $from_item_id ||= $reclamation_item->{converted_from_record_item_id};
+        next if !$from_item_id;
+        my $from_item_type = $from_record_item_type_refs->[$idx];
+        $from_item_type ||= $reclamation_item->{converted_from_record_item_type_ref};
+        unless ($allowed_linked_record_items{$from_item_type}) {
+          croak("Not allowed converted_from_record_item_type_ref: '" . $from_item_type);
+        }
+        my $src_item = ${from_item_type}->new(id => $from_item_id)->load;
+        $src_item->link_to_record($reclamation_item);
+        #clear converted_from;
+        delete $reclamation_item->{$_} for qw(converted_from_record_item_id converted_from_record_item_type_ref);
+      }
+    }
+  }
+}
+
+sub save_with_render_error {
+  my ($self) = @_;
+
+  my $errors = $self->save();
+
+  if (scalar @{ $errors }) {
+    $self->js->flash('error', $_) foreach @{ $errors };
+    return $self->js->render();
+  }
+}
+
+# sales → purchase or purchase → sales
+sub workflow_save_and_sales_or_purchase_reclamation {
+  my ($self) = @_;
+
+  # always save
+  $self->save_with_render_error();
+
+  my $destination_type = $::form->{type} eq purchase_reclamation_type() ? sales_reclamation_type()
+                       : $::form->{type} eq sales_reclamation_type()    ? purchase_reclamation_type()
+                       : '';
+
+  # check for direct delivery
+  # copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
+  my $custom_shipto;
+  if (   ($::form->{type} eq sales_reclamation_type())
+      && ($destination_type eq purchase_reclamation_type())
+      && $::form->{use_shipto}
+      && $self->reclamation->shipto ) {
+    $custom_shipto = $self->reclamation->shipto->clone('SL::DB::Reclamation');
+  }
+
+  $self->reclamation(
+    SL::DB::Reclamation->new_from(
+      $self->reclamation,
+      destination_type => $destination_type,
+  ));
+
+  if ($::form->{type} eq sales_reclamation_type() && $destination_type eq purchase_reclamation_type()) {
+    if ($::form->{use_shipto}) {
+      $self->reclamation->custom_shipto($custom_shipto) if $custom_shipto;
+    } else {
+      # remove any custom shipto if not wanted
+      $self->reclamation->custom_shipto(SL::DB::Shipto->new(module => 'RC', custom_variables => []));
+    }
+  }
+
+  $self->reinit_after_new_reclamation();
+
+  $self->render(
+    'reclamation/form',
+    title => $self->get_title_for('add'),
+    %{$self->{template_args}}
+  );
+}
+
+sub reinit_after_new_reclamation {
+  my ($self) = @_;
+
+  # change form type
+  $::form->{type} = $self->reclamation->type if $self->reclamation->type;
+  $self->type($self->init_type);
+  $self->cv  ($self->init_cv);
+  $self->check_auth;
+
+  $self->recalc();
+  $self->get_unalterable_data();
+  $self->pre_render();
+
+  # trigger rendering values for second row as hidden, because they
+  # are loaded only on demand. So we need to keep the values from the
+  # source.
+  $_->{render_second_row} = 1 for @{ $self->reclamation->items_sorted };
+}
+
+sub pre_render {
+  my ($self) = @_;
+
+  $self->{all_taxzones}               = SL::DB::Manager::TaxZone->get_all_sorted();
+  $self->{all_currencies}             = SL::DB::Manager::Currency->get_all_sorted();
+  $self->{all_departments}            = SL::DB::Manager::Department->get_all_sorted();
+  $self->{all_languages}              = SL::DB::Manager::Language->get_all_sorted();
+  $self->{all_employees}              = SL::DB::Manager::Employee->get_all(
+                                          where => [ or => [
+                                                        id => $self->reclamation->employee_id,
+                                                        deleted => 0 ] ],
+                                                     sort_by => 'name');
+  $self->{all_salesmen}               = SL::DB::Manager::Employee->get_all(
+                                          where => [ or => [
+                                                        id => $self->reclamation->salesman_id,
+                                                        deleted => 0 ] ],
+                                          sort_by => 'name');
+  $self->{all_payment_terms}          = SL::DB::Manager::PaymentTerm->get_all_sorted(
+                                          where => [ or => [
+                                                        id => $self->reclamation->payment_id,
+                                                        obsolete => 0 ] ]);
+  $self->{all_delivery_terms}         = SL::DB::Manager::DeliveryTerm->get_all_sorted();
+  $self->{current_employee_id}        = SL::DB::Manager::Employee->current->id;
+
+  $self->{positions_scrollbar_height} = SL::Helper::UserPreferences::PositionsScrollbar->new()->get_height();
+
+  my $print_form = Form->new('');
+  $print_form->{type}        = $self->type;
+  $print_form->{printers}    = SL::DB::Manager::Printer->get_all_sorted;
+  $self->{print_options}     = SL::Helper::PrintOptions->get_print_options(
+    form => $print_form,
+    options => {dialog_name_prefix => 'print_options.',
+                show_headers       => 1,
+                no_queue           => 1,
+                no_postscript      => 1,
+                no_opendocument    => 0,
+                no_html            => 1},
+  );
+  foreach my $item (@{$self->reclamation->reclamation_items}) {
+    my $price_source = SL::PriceSource->new(record_item => $item, record => $self->reclamation);
+    $item->active_price_source(   $price_source->price_from_source(   $item->active_price_source   ));
+    $item->active_discount_source($price_source->discount_from_source($item->active_discount_source));
+  }
+
+  # Calculate shipped qtys here to prevent calling calculate for every item via
+  # the items method. Do not use write_to_objects to prevent
+  # reclamation->delivered to be set, because this should be the value from db,
+  # which can be set manually or is set when linked delivery orders are saved.
+  SL::Helper::ShippedQty->new->calculate($self->reclamation)->write_to(\@{$self->reclamation->items});
+
+  if ($self->reclamation->record_number && $::instance_conf->get_webdav) {
+    my $webdav = SL::Webdav->new(
+      type     => $self->type,
+      number   => $self->reclamation->record_number,
+    );
+    my @all_objects = $webdav->get_all_objects;
+    @{ $self->{template_args}->{WEBDAV} } = map { { name => $_->filename,
+                                                    type => t8('File'),
+                                                    link => File::Spec->catfile($_->full_filedescriptor),
+                                                } } @all_objects;
+  }
+
+  $self->get_item_cvpartnumber($_) for @{$self->reclamation->items_sorted};
+
+  $::request->{layout}->use_javascript("${_}.js") for
+    qw(kivi.SalesPurchase kivi.Reclamation kivi.File ckeditor/ckeditor
+       ckeditor/adapters/jquery calculate_qty kivi.Validator follow_up
+       show_history
+      );
+  $self->_setup_edit_action_bar;
+}
+
+sub prepare_report {
+  my ($self)      = @_;
+
+  my $report      = SL::ReportGenerator->new(\%::myconfig, $::form);
+
+  $self->models->disable_plugin('paginated') if $report->{options}{output_format} =~ /^(pdf|csv)$/i;
+  $self->models->add_additional_url_params(type => $self->type);
+  $self->models->finalize; # for filter laundering
+
+  my $callback    = $self->models->get_callback;
+
+  $self->{report} = $report;
+
+  # TODO(Tamino): shipto_id is not linked to custom_shipto
+  my @columns_order = qw(
+    id
+    record_number
+    employee_id
+    salesman_id
+    customer_id
+    vendor_id
+    contact_id
+    language_id
+    department_id
+    globalproject_id
+    cv_record_number
+    transaction_description
+    notes
+    intnotes
+    shippingpoint
+    shipvia
+    amount
+    netamount
+    delivery_term_id
+    payment_id
+    currency_id
+    exchangerate
+    taxincluded
+    taxzone_id
+    tax_point
+    reqdate
+    transdate
+    itime
+    mtime
+    delivered
+    closed
+  );
+
+  my @default_columns = qw(
+    record_number
+    employee_id
+    department_id
+    globalproject_id
+    cv_record_number
+    transaction_description
+    amount
+    reqdate
+    transdate
+    itime
+    mtime
+    delivered
+    closed
+  );
+
+  my %column_defs = (
+    id => {
+      obj_link => sub {$self->url_for(action => 'edit', id => $_[0]->id, type => $self->type, callback => $callback)},
+      sub      => sub { $_[0]->id },
+    },
+    record_number => {
+      obj_link => sub {$self->url_for(action => 'edit', id => $_[0]->id, type => $self->type, callback => $callback)},
+      sub      => sub { $_[0]->record_number },
+    },
+    employee_id => {
+      sub      => sub { $_[0]->employee ? $_[0]->employee->name : '' },
+    },
+    salesman_id => {
+      sub      => sub { $_[0]->salesman ? $_[0]->salesman->name : '' },
+    },
+    language_id => {
+      sub      => sub { $_[0]->language ? $_[0]->language->article_code : '' },
+    },
+    department_id => {
+      sub      => sub { $_[0]->department ? $_[0]->department->description : '' },
+    },
+    globalproject_id => {
+      obj_link => sub { $_[0]->globalproject_id ?
+       $self->url_for(
+          controller => "controller.pl",
+          action => 'Project/edit',
+          id => $_[0]->globalproject_id,
+          callback => $callback
+        ) : '' },
+      sub      => sub { !$_[0]->globalproject ? '' : $_[0]->globalproject->projectnumber },
+    },
+    cv_record_number => {
+      sub      => sub { $_[0]->cv_record_number },
+    },
+    transaction_description => {
+      sub      => sub { $_[0]->transaction_description },
+    },
+    notes => {
+      sub      => sub { $_[0]->notes },
+    },
+    intnotes => {
+      sub      => sub { $_[0]->intnotes },
+    },
+    shippingpoint => {
+      sub      => sub { $_[0]->shippingpoint },
+    },
+    shipvia => {
+      sub      => sub { $_[0]->shipvia },
+    },
+    # TODO(Tamino): custom ship to is not safed in reclamation
+    #shipto_id => {
+    #  sub      => sub { $_[0]->shipto ? $_[0]->shipto->shiptoname : '' },
+    #},
+    amount  => {
+      sub      => sub { $_[0]->amount_as_number },
+    },
+    netamount  => {
+      sub      => sub { $_[0]->netamount_as_number },
+    },
+    delivery_term_id => {
+      obj_link => sub { $_[0]->delivery_term_id ?
+       $self->url_for(
+          controller => "controller.pl",
+          action => 'DeliveryTerm/edit',
+          id => $_[0]->delivery_term_id,
+          callback => $callback
+        ) : '' },
+      sub      => sub { $_[0]->delivery_term ? $_[0]->delivery_term->description : '' },
+    },
+    payment_id => {
+      obj_link => sub { $_[0]->payment_id ?
+       $self->url_for(
+          controller => "controller.pl",
+          action => 'PaymentTerm/edit',
+          id => $_[0]->payment_id,
+          callback => $callback
+        ) : '' },
+      sub      => sub { $_[0]->payment ? $_[0]->payment->description : '' },
+    },
+    currency_id => {
+      sub      => sub { $_[0]->currency ? $_[0]->currency->name : '' },
+    },
+    exchangerate  => {
+      sub      => sub { $_[0]->exchangerate ? $_[0]->exchangerate_as_number : '' },
+    },
+    taxincluded => {
+      sub      => sub { $_[0]->taxincluded ? t8('Yes') : t8('No') },
+    },
+    taxzone_id => {
+      obj_link => sub { $_[0]->taxzone_id ?
+       $self->url_for(
+          controller => "controller.pl",
+          action => 'Taxzones/edit',
+          id => $_[0]->taxzone_id,
+          callback => $callback
+        ) : '' },
+      sub      => sub { $_[0]->taxzone ? $_[0]->taxzone->description : '' },
+    },
+    tax_point  => {
+      sub      => sub { $_[0]->tax_point ? ($_[0]->tax_point)->to_kivitendo(precision => 'day') : '' },
+    },
+    reqdate  => {
+      sub      => sub { $_[0]->reqdate ? ($_[0]->reqdate)->to_kivitendo(precision => 'day') : '' },
+    },
+    transdate  => {
+      sub      => sub { $_[0]->transdate ? ($_[0]->transdate)->to_kivitendo(precision => 'day') : '' },
+    },
+    itime      => {
+      sub      => sub { $_[0]->itime->to_kivitendo(precision => 'minute') }
+    },
+    mtime      => {
+      sub      => sub { $_[0]->mtime ? $_[0]->mtime->to_kivitendo(precision => 'minute') : '' }
+    },
+    delivered => {
+      sub      => sub { $_[0]->delivered ? t8('Yes') : t8('No') },
+    },
+    closed => {
+      sub      => sub { $_[0]->closed ? t8('Yes') : t8('No') },
+    },
+  );
+  if ($self->type eq sales_reclamation_type()) {
+    $column_defs{customer_id} = ({
+      raw_data => sub { $_[0]->customervendor->presenter->customer(display => 'table-cell', callback => $callback) },
+      sub      => sub { $_[0]->customervendor->name },
+    });
+    $column_defs{contact_id} = ({
+      obj_link => sub { $self->url_for(
+          controller => "controller.pl",
+          action => 'CustomerVendor/edit',
+          db => 'customer',
+          id => $_[0]->customer_id
+        ) . '#contacts'
+      },
+      sub      => sub { $_[0]->contact ? $_[0]->contact->cp_name : '' },
+    });
+  } elsif ($self->type eq purchase_reclamation_type()) {
+    $column_defs{vendor_id} = ({
+      raw_data => sub { $_[0]->customervendor->presenter->vendor(display => 'table-cell', callback => $callback) },
+      sub      => sub { $_[0]->customervendor->name },
+    });
+    $column_defs{contact_id} = ({
+      obj_link => sub { $self->url_for(
+          controller => "controller.pl",
+          action => 'CustomerVendor/edit',
+          db => 'vendor',
+          id => $_[0]->vendor_id
+        ) . "#contacts"
+      },
+      sub      => sub { $_[0]->contact ? $_[0]->contact->cp_name : '' },
+    });
+  }
+  $column_defs{$_}->{text} ||= t8( $self->models->get_sort_spec->{$_}->{title} || $_ ) for keys %column_defs;
+
+  my @columns_to_show = grep { $::form->{"include_in_report_$_"}} keys %column_defs;
+  unless (scalar(@columns_to_show)){ @columns_to_show = @default_columns; }
+
+  my %active_in_report = map { $_ => 1 } @columns_to_show;
+  $self->models->add_additional_url_params(map { "include_in_report_" . $_ => 1 } @columns_to_show); #for reorder
+  my %columns_in_report = map {$_ => $column_defs{$_}} @columns_to_show;
+
+  ## add cvars TODO(Tamino): Add own cvars
+  #my %cvar_column_defs = map {
+  #  my $cfg = $_;
+  #  (('cvar_' . $cfg->name) => {
+  #    sub     => sub { my $var = $_[0]->cvar_by_name($cfg->name); $var ? $var->value_as_text : '' },
+  #    text    => $cfg->description,
+  #    visible => $self->include_cvars->{ $cfg->name } ? 1 : 0,
+  #  })
+  #} @{ $self->includeable_cvar_configs };
+
+  #push @columns, map { 'cvar_' . $_->name } @{ $self->includeable_cvar_configs };
+  #%column_defs = (%column_defs, %cvar_column_defs);
+
+  #my @cvar_column_form_names = ('_include_cvars_from_form', map { "include_cvars_" . $_->name } @{ $self->includeable_cvar_configs });
+
+  # make all sortable
+  my @sortable    = keys %columns_in_report;
+
+  $report->set_options(
+    std_column_visibility => 1,
+    controller_class      => 'Reclamation',
+    output_format         => 'HTML',
+    raw_top_info_text     => $self->render(
+     'reclamation/_report_top',
+     { output => 0 },
+     type => $self->type,
+     active_in_report => \%active_in_report,
+    ),
+    raw_bottom_info_text  => $self->render(
+     'reclamation/_report_bottom',
+     { output => 0 },
+     models => $self->models
+    ),
+    title                 => $self->type eq sales_reclamation_type() ? t8('Sales Reclamations') : t8('Purchase Reclamations'),
+    allow_pdf_export      => 1,
+    allow_csv_export      => 1,
+  );
+  $report->set_columns(%columns_in_report);
+  $report->set_column_order(@columns_order);
+  #$report->set_export_options(qw(list filter), @cvar_column_form_names); TODO(Tamino): for cvars
+  $report->set_export_options(qw(list filter));
+  $report->set_options_from_form;
+  $self->models->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable);
+}
+
+sub _setup_edit_action_bar {
+  my ($self, %params) = @_;
+
+  my $deletion_allowed = ($self->type eq sales_reclamation_type()
+                          && $::instance_conf->get_sales_reclamation_show_delete)
+                      || ($self->type eq purchase_reclamation_type()
+                          && $::instance_conf->get_purchase_reclamation_show_delete);
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      combobox => [
+        action => [
+          t8('Save'),
+          call      => [
+            'kivi.Reclamation.save', 'save',
+            $::instance_conf->get_reclamation_warn_duplicate_parts,
+            $::instance_conf->get_reclamation_warn_no_reqdate,
+          ],
+          checks    => [
+            ['kivi.validate_form','#reclamation_form'],
+          ],
+        ],
+        action => [
+          t8('Save as new'),
+          call      => [
+            'kivi.Reclamation.save', 'save_as_new',
+            $::instance_conf->get_reclamation_warn_duplicate_parts,
+          ],
+          disabled  => !$self->reclamation->id ? t8('This object has not been saved yet.') : undef,
+        ],
+      ], # end of combobox "Save"
+
+      combobox => [
+        action => [
+          t8('Workflow'),
+        ],
+        action => [
+          t8('Save and Sales Reclamation'),
+          call      => [
+            'kivi.Reclamation.save', 'save_and_sales_reclamation',
+            $::instance_conf->get_reclamation_warn_duplicate_parts,
+            $::instance_conf->get_reclamation_warn_no_reqdate,
+          ],
+          only_if  => (any { $self->type eq $_ } (purchase_reclamation_type())),
+        ],
+        action => [
+          t8('Save and Purchase Reclamation'),
+          call      => [ 'kivi.Reclamation.purchase_reclamation_check_for_direct_delivery' ],
+          only_if   => (any { $self->type eq $_ } (sales_reclamation_type())),
+        ],
+      ], # end of combobox "Workflow"
+
+      combobox => [
+        action => [
+          t8('Export'),
+        ],
+        action => [
+          t8('Save and preview PDF'),
+           call => [
+             'kivi.Reclamation.save', 'preview_pdf',
+             $::instance_conf->get_reclamation_warn_duplicate_parts,
+             $::instance_conf->get_reclamation_warn_no_reqdate,
+           ],
+        ],
+        action => [
+          t8('Save and print'),
+          call => [
+            'kivi.Reclamation.show_print_options',
+            $::instance_conf->get_reclamation_warn_duplicate_parts,
+            $::instance_conf->get_reclamation_warn_no_reqdate,
+          ],
+        ],
+        action => [
+          t8('Save and E-mail'),
+          id   => 'save_and_email_action',
+          call => [
+            'kivi.Reclamation.save', 'save_and_show_email_dialog',
+            $::instance_conf->get_reclamation_warn_duplicate_parts,
+            $::instance_conf->get_reclamation_warn_no_reqdate,
+          ],
+          disabled => !$self->reclamation->id ? t8('This object has not been saved yet.') : undef,
+        ],
+        action => [
+          t8('Download attachments of all parts'),
+          call     => [ 'kivi.File.downloadReclamationitemsFiles', $::form->{type}, $::form->{id} ],
+          disabled => !$self->reclamation->id ? t8('This object has not been saved yet.') : undef,
+          only_if  => $::instance_conf->get_doc_storage,
+        ],
+      ], # end of combobox "Export"
+
+      action => [
+        t8('Delete'),
+        call     => [ 'kivi.Reclamation.delete_reclamation' ],
+        confirm  => t8('Do you really want to delete this object?'),
+        disabled => !$self->reclamation->id ? t8('This object has not been saved yet.') : undef,
+        only_if  => $deletion_allowed,
+      ],
+
+      combobox => [
+        action => [
+          t8('more')
+        ],
+        action => [
+          t8('Follow-Up'),
+          call     => [ 'kivi.Reclamation.follow_up_window' ],
+          disabled => !$self->reclamation->id ? t8('This object has not been saved yet.') : undef,
+          only_if  => $::auth->assert('productivity', 1),
+        ],
+        action => [
+          t8('History'),
+          call     => [ 'set_history_window', $self->reclamation->id, 'id' ],
+          disabled => !$self->reclamation->id ? t8('This record has not been saved yet.') : undef,
+        ],
+      ], # end of combobox "more"
+    );
+  }
+}
+
+sub _setup_search_action_bar {
+  my ($self, %params) = @_;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      action => [
+        t8('Update'),
+        submit    => [ '#search_form', { action => 'Reclamation/list', type => $self->type } ],
+        accesskey => 'enter',
+      ],
+      link => [
+        t8('Add'),
+        link => $self->url_for(action => 'add', type => $self->type),
+      ],
+    );
+  }
+}
+
+sub generate_pdf {
+  my ($reclamation, $pdf_ref, $params) = @_;
+
+  my @errors = ();
+
+  my $print_form = Form->new('');
+  $print_form->{type}        = $reclamation->type;
+  $print_form->{formname}    = $params->{formname} || $reclamation->type;
+  $print_form->{format}      = $params->{format}   || 'pdf';
+  $print_form->{media}       = $params->{media}    || 'file';
+  $print_form->{groupitems}  = $params->{groupitems};
+  $print_form->{printer_id}  = $params->{printer_id};
+  $print_form->{media}       = 'file'       if $print_form->{media} eq 'screen';
+
+  $reclamation->language($params->{language});
+
+  # Make reclamation available in template
+  $print_form->{reclamation} = $reclamation;
+
+  my $template_ext;
+  my $template_type;
+  if ($print_form->{format} =~ /(opendocument|oasis)/i) {
+    $template_ext  = 'odt';
+    $template_type = 'OpenDocument';
+  }
+
+  # search for the template
+  my ($template_file, @template_files) = SL::Helper::CreatePDF->find_template(
+    name        => $print_form->{formname},
+    extension   => $template_ext,
+    email       => $print_form->{media} eq 'email',
+    language    => $params->{language},
+    printer_id  => $print_form->{printer_id},
+  );
+
+  if (!defined $template_file) {
+    push @errors, t8(
+      'Cannot find matching template for this print request. Please contact your template maintainer. I tried these: #1.',
+      join ', ',
+      map { "'$_'"} @template_files
+    );
+  }
+
+  return @errors if scalar @errors;
+
+  $print_form->throw_on_error(sub {
+    eval {
+      $print_form->prepare_for_printing;
+
+      $$pdf_ref = SL::Helper::CreatePDF->create_pdf(
+        format        => $print_form->{format},
+        template_type => $template_type,
+        template      => $template_file,
+        variables     => $print_form,
+      );
+      1;
+    } || push @errors, ref($EVAL_ERROR) eq 'SL::X::FormError' ? $EVAL_ERROR->error : $EVAL_ERROR;
+  });
+
+  return @errors;
+}
+
+sub get_files_for_email_dialog {
+  my ($self) = @_;
+
+  my %files = map { ($_ => []) } qw(versions files cv_files project_files part_files);
+
+  return %files if !$::instance_conf->get_doc_storage;
+
+  if ($self->reclamation->id) {
+    $files{versions} = [
+      SL::File->get_all_versions(
+        object_id => $self->reclamation->id,
+        object_type => $self->reclamation->type,
+        file_type => 'document')
+    ];
+    $files{files} = [
+      SL::File->get_all(
+        object_id => $self->reclamation->id,
+        object_type => $self->reclamation->type,
+        file_type => 'attachment')
+    ];
+    $files{cv_files} = [
+      SL::File->get_all(
+        object_id => $self->reclamation->customervendor->id,
+        object_type => $self->cv,
+        file_type => 'attachment')
+    ];
+    $files{project_files} = [
+      SL::File->get_all(
+        object_id => $self->reclamation->globalproject_id,
+        object_type => 'project',
+        file_type => 'attachment')
+    ];
+  }
+
+  my @parts =
+    uniq_by { $_->{id} }
+    map {
+      +{ id         => $_->part->id,
+         partnumber => $_->part->partnumber }
+    } @{$self->reclamation->items_sorted};
+
+  foreach my $part (@parts) {
+    my @pfiles = SL::File->get_all(object_id => $part->{id}, object_type => 'part');
+    push @{ $files{part_files} }, map { +{ %{ $_ }, partnumber => $part->{partnumber} } } @pfiles;
+  }
+
+  foreach my $key (keys %files) {
+    $files{$key} = [ sort_by { lc $_->{db_file}->{file_name} } @{ $files{$key} } ];
+  }
+
+  return %files;
+}
+
+sub get_title_for {
+  my ($self, $action) = @_;
+
+  return '' if none { lc($action)} qw(add edit);
+
+  # for locales:
+  # t8("Add Sales Reclamation");
+  # t8("Add Purchase Reclamation");
+  # t8("Edit Sales Reclamation");
+  # t8("Edit Purchase Reclamation");
+
+  $action = ucfirst(lc($action));
+  return $self->type eq sales_reclamation_type()    ? t8("$action Sales Reclamation")
+       : $self->type eq purchase_reclamation_type() ? t8("$action Purchase Reclamation")
+       : '';
+}
+
+sub get_item_cvpartnumber {
+  my ($self, $item) = @_;
+
+  return if !$self->search_cvpartnumber;
+  return if !$self->reclamation->customervendor;
+
+  if ($self->cv eq 'vendor') {
+    my @mms = grep { $_->make eq $self->reclamation->customervendor->id } @{$item->part->makemodels};
+    $item->{cvpartnumber} = $mms[0]->model if scalar @mms;
+  } elsif ($self->cv eq 'customer') {
+    my @cps = grep { $_->customer_id eq $self->reclamation->customervendor->id } @{$item->part->customerprices};
+    $item->{cvpartnumber} = $cps[0]->customer_partnumber if scalar @cps;
+  }
+}
+
+sub get_part_texts {
+  my ($part_or_id, $language_or_id, %defaults) = @_;
+
+  my $part        = ref($part_or_id)     ? $part_or_id         : SL::DB::Part->load_cached($part_or_id);
+  my $language_id = ref($language_or_id) ? $language_or_id->id : $language_or_id;
+  my $texts       = {
+    description     => $defaults{description}     // $part->description,
+    longdescription => $defaults{longdescription} // $part->notes,
+  };
+
+  return $texts unless $language_id;
+
+  my $translation = SL::DB::Manager::Translation->get_first(
+    where => [
+      parts_id    => $part->id,
+      language_id => $language_id,
+    ]);
+
+  $texts->{description}     = $translation->translation     if $translation && $translation->translation;
+  $texts->{longdescription} = $translation->longdescription if $translation && $translation->longdescription;
+
+  return $texts;
+}
+
+sub sales_reclamation_type {
+  'sales_reclamation';
+}
+
+sub purchase_reclamation_type {
+  'purchase_reclamation';
+}
+
+sub save_and_redirect_to {
+  my ($self, %params) = @_;
+
+  $self->save_with_render_error();
+
+  flash_later('info', t8('The reclamation has been saved'));
+
+  $self->redirect_to(%params);
+}
+
+sub save_history {
+  my ($self, $addition) = @_;
+
+  SL::DB::History->new(
+    trans_id    => $self->reclamation->id,
+    employee_id => SL::DB::Manager::Employee->current->id,
+    what_done   => $self->reclamation->type,
+    snumbers    => 'record_number_' . $self->reclamation->record_number,
+    addition    => $addition,
+  )->save;
+}
+
+sub store_pdf_to_webdav_and_filemanagement {
+  my($reclamation, $content, $filename) = @_;
+
+  my @errors;
+
+  # copy file to webdav folder
+  if ($reclamation->record_number && $::instance_conf->get_webdav_documents) {
+    my $webdav = SL::Webdav->new(
+      type     => $reclamation->type,
+      number   => $reclamation->record_number,
+    );
+    my $webdav_file = SL::Webdav::File->new(
+      webdav   => $webdav,
+      filename => $filename,
+    );
+    eval {
+      $webdav_file->store(data => \$content);
+      1;
+    } or do {
+      push @errors, t8('Storing PDF to webdav folder failed: #1', $@);
+    };
+  }
+  if ($reclamation->id && $::instance_conf->get_doc_storage) {
+    eval {
+      SL::File->save(object_id     => $reclamation->id,
+                     object_type   => $reclamation->type,
+                     mime_type     => 'application/pdf',
+                     source        => 'created',
+                     file_type     => 'document',
+                     file_name     => $filename,
+                     file_contents => $content);
+      1;
+    } or do {
+      push @errors, t8('Storing PDF in storage backend failed: #1', $@);
+    };
+  }
+
+  return @errors;
+}
+
+1;
+
+__END__
+
+=encoding utf-8
+
+=head1 NAME
+
+SL::Controller::Reclamation - controller for reclamations
+
+=head1 SYNOPSIS
+
+This is a new form to enter reclamations, written with the use
+of controller and java script techniques.
+
+The aim is to provide the user a good experience and a fast workflow.
+
+=head2 Key Features
+
+=over 4
+
+=item *
+
+One input row, so that input happens every time at the same place.
+
+=item *
+
+Use of pickers where possible.
+
+=item *
+
+Possibility to enter more than one item at once.
+
+=item *
+
+Item list in a scrollable area, so that the workflow buttons stay at
+the bottom.
+
+=item *
+
+Ordering item rows with drag and drop is possible. Sorting item rows is possible
+(by partnumber, description, reason, reason_description_int,
+reason_description_ext, qty, sellprice and discount for now).
+
+=item *
+
+No C<update> is necessary. All entries and calculations are managed
+with ajax-calls and the page only reloads on C<save>.
+
+=item *
+
+User can see changes immediately, because of the use of java script
+and ajax.
+
+=item *
+
+Parts that are linked though RecordLinks are protected against price editing.
+
+=back
+
+=head1 CODE
+
+=head2 Layout
+
+=over 4
+
+=item * C<SL/Controller/Reclamation.pm>
+
+the controller
+
+=item * C<template/webpages/reclamation/form.html>
+
+main form
+
+=item * C<template/webpages/reclamation/tabs/basic_data.html>
+
+Main tab for basic_data.
+
+This is the only tab here for now. "webdav", "documents", "attachements" and
+"linked records" tabs are reused from generic code.
+
+=over 4
+
+=item * C<template/webpages/reclamation/tabs/basic_data/_business_info_row.html>
+
+For displaying information on business type
+
+=item * C<template/webpages/reclamation/tabs/basic_data/_item_input.html>
+
+The input line for items
+
+=item * C<template/webpages/reclamation/tabs/basic_data/_row.html>
+
+One row for already entered items
+
+=item * C<template/webpages/reclamation/tabs/basic_data/_second_row.html>
+
+Foldable second row for already entered items with more fields
+
+=item * C<template/webpages/reclamation/tabs/basic_data/_tax_row.html>
+
+Displaying tax information
+
+=item * C<template/webpages/reclamation/tabs/basic_data/_price_sources_dialog.html>
+
+Dialog for selecting price and discount sources
+
+=back
+
+=item * C<js/kivi.Reclamation.js>
+
+java script functions
+
+=back
+
+=head1 KNOWN BUGS AND CAVEATS
+
+=over 4
+
+=item *
+
+Table header is not sticky in the scrolling area.
+
+=item *
+
+Sorting does not include C<position>, neither does reordering.
+
+This behavior was implemented intentionally. But we can discuss, which behavior
+should be implemented.
+
+=back
+
+=head1 To discuss / Nice to have
+
+=over 4
+
+=item *
+
+Possibility to select PriceSources in input row?
+
+=item *
+
+This controller uses a (changed) copy of the template for the PriceSource
+dialog. Maybe there could be used one code source.
+
+=item *
+
+A warning when leaving the page without saveing unchanged inputs.
+
+=back
+
+=head1 AUTHOR
+
+Tamino Steinert E<lt>tamino.steinert@tamino.stE<gt>
+
+=cut
diff --git a/SL/Controller/ReclamationReason.pm b/SL/Controller/ReclamationReason.pm
new file mode 100644
index 000000000..c91cea2b9
--- /dev/null
+++ b/SL/Controller/ReclamationReason.pm
@@ -0,0 +1,280 @@
+package SL::Controller::ReclamationReason;
+
+use strict;
+
+use parent qw(SL::Controller::Base);
+
+use SL::DB::ReclamationReason;
+use SL::Helper::Flash;
+use SL::Locale::String;
+use List::MoreUtils qw(any);
+use SL::CVar;
+
+use Rose::Object::MakeMethods::Generic (
+  scalar                  => [ qw(reclamation_reason) ],
+  'scalar --get_set_init' => [ qw(reclamation_reason) ],
+);
+
+__PACKAGE__->run_before('check_auth');
+__PACKAGE__->run_before('load_reclamation_reason', only => [ qw(edit delete) ]);
+
+sub check_auth {
+  $::auth->assert('config');
+}
+
+#
+# actions
+#
+
+sub action_list {
+  my ($self, %params) = @_;
+
+  $self->setup_list_action_bar;
+  $self->render(
+    'reclamation_reason/list',
+    title => $::locale->text('Reclamation Reasons'),
+    RECLAMATION_REASONS => SL::DB::Manager::ReclamationReason->get_all_sorted(),
+  );
+}
+
+sub action_sort_list {
+  my ($self, %params) = @_;
+
+  $self->setup_sort_list_action_bar;
+  $self->render(
+    'reclamation_reason/sort_list',
+    title => $::locale->text('reclamation reasons'),
+    RECLAMATION_REASONS => SL::DB::Manager::ReclamationReason->get_all_sorted(),
+  );
+}
+
+sub action_new {
+  my ($self) = @_;
+
+  $self->reclamation_reason(SL::DB::ReclamationReason->new());
+  $self->show_form(title => t8('Add reclamation reason'));
+}
+
+sub action_edit {
+  my ($self) = @_;
+
+  $self->show_form(
+    title       => t8('Edit reclamation reason'),
+  );
+}
+
+sub action_save {
+  my ($self) = @_;
+
+  if ($::form->{id}) {
+    $self->load_reclamation_reason();
+  }
+
+  $self->create_or_save;
+}
+
+sub action_delete {
+  my ($self) = @_;
+
+  if (!$self->reclamation_reason->db->with_transaction(sub {
+    $self->reclamation_reason->delete();
+    flash_later('info',  $::locale->text('The reclamation reason has been deleted.'));
+
+    1;
+  })) {
+    flash_later('error', $::locale->text('The reclamation reason is in use and cannot be deleted.'))
+  };
+
+  $self->redirect_to(action => 'list');
+}
+
+#
+# ajax actions
+#
+
+sub action_reorder {
+  my ($self) = @_;
+
+  SL::DB::ReclamationReason->reorder_list(@{ $::form->{reclamation_reason_id} || [] });
+
+  $self->render(\'', { type => 'json' });
+}
+
+#
+# action bars
+#
+
+sub setup_form_action_bar {
+  my ($self) = @_;
+
+  my $is_new = !$self->reclamation_reason->id;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      action => [
+        $is_new ? t8('Create') : t8('Save'),
+        submit    => [ '#form', { action => 'ReclamationReason/save' } ],
+        checks    => [ 'kivi.validate_form' ],
+        accesskey => 'enter',
+      ],
+      action => [
+        t8('Delete'),
+        submit   => [ '#form', { action => 'ReclamationReason/delete' } ],
+        confirm  => t8('Do you really want to delete this reclamation reason?'),
+        only_if  => !$is_new,
+      ],
+      link => [
+        t8('Abort'),
+        link => $self->url_for(action => 'list'),
+      ],
+    );
+  }
+  $::request->layout->add_javascripts('kivi.Validator.js');
+}
+
+sub setup_list_action_bar {
+  my ($self) = @_;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      link => [
+        t8('Add'),
+        link => $self->url_for(action => 'new'),
+      ],
+      link => [
+        t8('Sort'),
+        link => $self->url_for(action => 'sort_list'),
+      ],
+    );
+  }
+}
+
+sub setup_sort_list_action_bar {
+  my ($self) = @_;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+      link => [
+        t8('Add'),
+        link => $self->url_for(action => 'new'),
+      ],
+      link => [
+        t8('List'),
+        link => $self->url_for(action => 'list'),
+      ],
+    );
+  }
+}
+
+#
+# helpers
+#
+
+sub create_or_save {
+  my ($self) = @_;
+
+  unless ($self->reclamation_reason) {
+    $self->reclamation_reason(SL::DB::ReclamationReason->new());
+  }
+
+  my $is_new = !$self->reclamation_reason->id;
+
+  my $params = delete($::form->{reclamation_reason}) || { };
+  delete $params->{id};
+
+  my @errors;
+
+  my $db = $self->reclamation_reason->db;
+  if (!$db->with_transaction(sub {
+
+    # assign attributes and validate
+    $self->reclamation_reason->assign_attributes( %{$params} ) ;
+
+    push(@errors, $self->reclamation_reason->validate); # check data before DB error
+
+    if (@errors) {
+      die @errors . "\n";
+    };
+    $self->reclamation_reason->save;
+    1;
+  })) {
+    die @errors ? join("\n", @errors) . "\n" : $db->error . "\n";
+  }
+
+  flash_later('info', $is_new ? t8('The reclamation reason has been created.') : t8('The reclamation reason has been saved.'));
+  $self->redirect_to(action => 'list');
+}
+
+sub show_form {
+  my ($self, %params) = @_;
+
+  $self->setup_form_action_bar;
+  $self->render(
+    'reclamation_reason/form',
+    %params,
+  );
+}
+
+sub load_reclamation_reason {
+  my ($self) = @_;
+
+  $self->reclamation_reason(SL::DB::ReclamationReason->new(id => $::form->{id})->load);
+}
+
+1;
+
+__END__
+
+=encoding utf-8
+
+=head1 NAME
+
+SL::Controller::ReclamationReason - controller for reclamation_reasons
+
+=head1 SYNOPSIS
+
+This is a small controller to add end edit reclamation_reasons.
+
+=head2 Key Features
+
+=over 4
+
+=item *
+
+Adding, editing, deleting and sorting of reclamation reasons.
+
+=item *
+
+Reasons can be valid for purchase, sales or both.
+
+=back
+
+=head1 CODE
+
+=head2 Layout
+
+=over 4
+
+=item * C<SL/Controller/ReclamationReason.pm>
+
+the controller
+
+=item * C<template/webpages/reclamation_reason/form.html>
+
+main form
+
+=item * C<template/webpages/reclamation_reason/list.html>
+
+list form
+
+=item * C<template/webpages/reclamation_reason/sort_list.html>
+
+sorting form
+
+=back
+
+=head1 AUTHOR
+
+Tamino Steinert E<lt>tamino.steinert@tamino.stE<gt>
+
+=cut
diff --git a/SL/DB/Helper/TransNumberGenerator.pm b/SL/DB/Helper/TransNumberGenerator.pm
index eb89ea8b3..06e309389 100644
--- a/SL/DB/Helper/TransNumberGenerator.pm
+++ b/SL/DB/Helper/TransNumberGenerator.pm
@@ -19,6 +19,10 @@ sub do_scoping {
   SL::DB::Manager::DeliveryOrder->type_filter($_[0]);
 }
 
+sub rec_scoping {
+  SL::DB::Manager::Reclamation->type_filter($_[0]);
+}
+
 sub parts_scoping {
  # SL::DB::Manager::Part->type_filter($_[0]);
 }
@@ -32,6 +36,8 @@ my %specs = ( ar                      => { number_column => 'invnumber',
               purchase_delivery_order => { number_column => 'donumber',       number_range_column => 'pdonumber',      scoping => \&do_scoping,    },
               supplier_delivery_order => { number_column => 'donumber',       number_range_column => 'sudonumber',     scoping => \&do_scoping,    },
               rma_delivery_order      => { number_column => 'donumber',       number_range_column => 'rdonumber',      scoping => \&do_scoping,    },
+              sales_reclamation       => { number_column => 'record_number',  number_range_column => 's_reclamation_record_number',scoping => \&rec_scoping,   },
+              purchase_reclamation    => { number_column => 'record_number',  number_range_column => 'p_reclamation_record_number',scoping => \&rec_scoping,   },
               customer                => { number_column => 'customernumber', number_range_column => 'customernumber',                             },
               vendor                  => { number_column => 'vendornumber',   number_range_column => 'vendornumber',                               },
               part                    => { number_column => 'partnumber',     number_range_column => 'articlenumber',  scoping => \&parts_scoping, },
diff --git a/SL/DB/Shipto.pm b/SL/DB/Shipto.pm
index 6cfcba66f..a1a075634 100644
--- a/SL/DB/Shipto.pm
+++ b/SL/DB/Shipto.pm
@@ -65,6 +65,7 @@ sub clone {
   my $module = $type =~ m{::Order$}               ? 'OE'
              : $type =~ m{::DeliveryOrder$}       ? 'DO'
              : $type =~ m{::Invoice$}             ? 'AR'
+             : $type =~ m{::Reclamation$}         ? 'RC'
              : $type =~ m{::(?:Customer|Vendor)$} ? 'CT'
              :                                      croak "Unsupported target class '$type'";
 
diff --git a/SL/Webdav.pm b/SL/Webdav.pm
index 85f6249ad..e51a1ab37 100644
--- a/SL/Webdav.pm
+++ b/SL/Webdav.pm
@@ -25,6 +25,8 @@ my %type_to_path = (
   purchase_delivery_order     => 'einkaufslieferscheine',
   supplier_delivery_order     => 'beistelllieferscheine',
   rma_delivery_order          => 'retourenlieferscheine',
+  purchase_reclamation        => 'einkaufsreklamation',
+  sales_reclamation           => 'verkaufsreklamation',
   credit_note                 => 'gutschriften',
   invoice                     => 'rechnungen',
   invoice_for_advance_payment => 'rechnungen',
diff --git a/js/kivi.Reclamation.js b/js/kivi.Reclamation.js
new file mode 100644
index 000000000..1716fbbec
--- /dev/null
+++ b/js/kivi.Reclamation.js
@@ -0,0 +1,860 @@
+namespace('kivi.Reclamation', function(ns) {
+  ns.check_cv = function() {
+    if ($('#type').val() == 'sales_reclamation') {
+      if ($('#reclamation_customer_id').val() === '') {
+        alert(kivi.t8('Please select a customer.'));
+        return false;
+      }
+    } else  {
+      if ($('#reclamation_vendor_id').val() === '') {
+        alert(kivi.t8('Please select a vendor.'));
+        return false;
+      }
+    }
+    return true;
+  };
+
+  ns.check_duplicate_parts = function(question) {
+    var id_arr = $('[name="reclamation.reclamation_items[].parts_id"]').map(function() { return this.value; }).get();
+
+    var i, obj = {}, pos = [];
+
+    for (i = 0; i < id_arr.length; i++) {
+      var id = id_arr[i];
+      if (obj.hasOwnProperty(id)) {
+        pos.push(i + 1);
+      }
+      obj[id] = 0;
+    }
+
+    if (pos.length > 0) {
+      question = question || kivi.t8("Do you really want to continue?");
+      return confirm(kivi.t8("There are duplicate parts at positions") + "\n"
+                     + pos.join(', ') + "\n"
+                     + question);
+    }
+    return true;
+  };
+
+  ns.check_valid_reqdate = function() {
+    if ($('#reclamation_reqdate_as_date').val() === '') {
+      alert(kivi.t8('Please select a due date.'));
+      return false;
+    } else {
+      return true;
+    }
+  };
+
+  ns.check_valid_reasons = function() {
+    var positions_with_empty = [];
+
+    $('.row_entry').each(function(idx, elt) {
+      if ($(elt).find('[name="reclamation.reclamation_items[].reason_id"]').val() == '') {
+        positions_with_empty.push(idx+1);
+      }
+    });
+
+    if (positions_with_empty.length > 0) {
+      alert(kivi.t8("There are parts with no reclamation reason at position:") + "\n"
+            + positions_with_empty.join(', ') );
+      return false;
+    } else {
+      return true;
+    }
+  };
+
+  ns.save = function(action, warn_on_duplicates, warn_on_reqdate) {
+    if (!ns.check_cv()) return;
+    if (warn_on_duplicates && !ns.check_duplicate_parts()) return;
+    if (warn_on_reqdate    && !ns.check_valid_reqdate())   return;
+    if (!ns.check_valid_reasons())                     return;
+
+    var data = $('#reclamation_form').serializeArray();
+    data.push({ name: 'action', value: 'Reclamation/' + action });
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  ns.delete_reclamation = function() {
+    var data = $('#reclamation_form').serializeArray();
+    data.push({ name: 'action', value: 'Reclamation/delete' });
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  ns.show_print_options = function(warn_on_duplicates, warn_on_reqdate) {
+    if (!ns.check_cv()) return;
+    if (warn_on_duplicates && !ns.check_duplicate_parts(kivi.t8("Do you really want to print?"))) return;
+    if (warn_on_reqdate    && !ns.check_valid_reqdate())   return;
+
+    kivi.popup_dialog({
+      id: 'print_options',
+      dialog: {
+        title: kivi.t8('Print options'),
+        width:  800,
+        height: 300
+      }
+    });
+  };
+
+  ns.print = function() {
+    $('#print_options').dialog('close');
+
+    var data = $('#reclamation_form').serializeArray();
+    data = data.concat($('#print_options_form').serializeArray());
+    data.push({ name: 'action', value: 'Reclamation/print' });
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  var email_dialog;
+
+  ns.setup_send_email_dialog = function() {
+    kivi.SalesPurchase.show_all_print_options_elements();
+    kivi.SalesPurchase.show_print_options_elements([ 'sendmode', 'media', 'copies', 'remove_draft' ], false);
+
+    $('#print_options_form table').first().remove().appendTo('#email_form_print_options');
+
+    var to_focus = $('#email_form_to').val() === '' ? 'to' : 'subject';
+    $('#email_form_' + to_focus).focus();
+  };
+
+  ns.finish_send_email_dialog = function() {
+    kivi.SalesPurchase.show_all_print_options_elements();
+
+    $('#email_form_print_options table').first().remove().prependTo('#print_options_form');
+    return true;
+  };
+
+  ns.show_email_dialog = function(html) {
+    var id            = 'send_email_dialog';
+    var dialog_params = {
+      id:     id,
+      width:  800,
+      height: 600,
+      title:  kivi.t8('Send email'),
+      modal:  true,
+      beforeClose: kivi.Reclamation.finish_send_email_dialog,
+      close: function(event, ui) {
+        email_dialog.remove();
+      }
+    };
+
+    $('#' + id).remove();
+
+    email_dialog = $('<div style="display:none" id="' + id + '"></div>').appendTo('body');
+    email_dialog.html(html);
+    email_dialog.dialog(dialog_params);
+
+    kivi.Reclamation.setup_send_email_dialog();
+
+    $('.cancel').click(ns.close_email_dialog);
+
+    return true;
+  };
+
+  ns.send_email = function() {
+    // push button only once -> slow response from mail server
+    ns.email_dialog_disable_send();
+
+    var data = $('#reclamation_form').serializeArray();
+    data = data.concat($('[name^="email_form."]').serializeArray());
+    data = data.concat($('[name^="print_options."]').serializeArray());
+    data.push({ name: 'action', value: 'Reclamation/send_email' });
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  ns.email_dialog_disable_send = function() {
+    // disable mail send event to prevent
+    // impatient users to send multiple times
+    $('#send_email').prop('disabled', true);
+  };
+
+  ns.close_email_dialog = function() {
+    email_dialog.dialog("close");
+  };
+
+  ns.set_number_in_title = function(elt) {
+    $('#nr_in_title').html($(elt).val());
+  };
+
+  ns.reload_cv_dependent_selections = function() {
+    $('#reclamation_shipto_id').val('');
+    var data = $('#reclamation_form').serializeArray();
+    data.push({ name: 'action', value: 'Reclamation/customer_vendor_changed' });
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  ns.reformat_number = function(event) {
+    $(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2));
+  };
+
+  ns.reformat_number_as_null_number = function(event) {
+    if ($(event.target).val() === '') {
+      return;
+    }
+    ns.reformat_number(event);
+  };
+
+  ns.update_exchangerate = function(event) {
+    if (!ns.check_cv()) {
+      $('#reclamation_currency_id').val($('#old_currency_id').val());
+      return;
+    }
+
+    var rate_input = $('#reclamation_exchangerate_as_null_number');
+    // unset exchangerate if currency changed
+    if ($('#reclamation_currency_id').val() !== $('#old_currency_id').val()) {
+      rate_input.val('');
+    }
+
+    // only set exchangerate if unset
+    if (rate_input.val() !== '') {
+      return;
+    }
+
+    var data = $('#reclamation_form').serializeArray();
+    data.push({ name: 'action', value: 'Reclamation/update_exchangerate' });
+
+    $.ajax({
+      url: 'controller.pl',
+      data: data,
+      method: 'POST',
+      dataType: 'json',
+      success: function(data){
+        if (!data.is_standard) {
+          $('#currency_name').text(data.currency_name);
+          if (data.exchangerate) {
+            rate_input.val(data.exchangerate);
+          } else {
+            rate_input.val('');
+          }
+          $('#exchangerate_settings').show();
+        } else {
+          rate_input.val('');
+          $('#exchangerate_settings').hide();
+        }
+        if ($('#reclamation_currency_id').val() != $('#old_currency_id').val() ||
+            !data.is_standard && data.exchangerate != $('#old_exchangerate').val()) {
+          kivi.display_flash('warning', kivi.t8('You have changed the currency or exchange rate. Please check prices.'));
+        }
+        $('#old_currency_id').val($('#reclamation_currency_id').val());
+        $('#old_exchangerate').val(data.exchangerate);
+      }
+    });
+  };
+
+  ns.exchangerate_changed = function(event) {
+    if (kivi.parse_amount($('#reclamation_exchangerate_as_null_number').val()) != kivi.parse_amount($('#old_exchangerate').val())) {
+      kivi.display_flash('warning', kivi.t8('You have changed the currency or exchange rate. Please check prices.'));
+      $('#old_exchangerate').val($('#reclamation_exchangerate_as_null_number').val());
+    }
+  };
+
+  ns.recalc_amounts_and_taxes = function() {
+    var data = $('#reclamation_form').serializeArray();
+    data.push({ name: 'action', value: 'Reclamation/recalc_amounts_and_taxes' });
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  ns.unit_change = function(event) {
+    var row           = $(event.target).parents("tbody").first();
+    var item_id_dom   = $(row).find('[name="reclamation_item_ids[+]"]');
+    var sellprice_dom = $(row).find('[name="reclamation.reclamation_items[].sellprice_as_number"]');
+    var select_elt    = $(row).find('[name="reclamation.reclamation_items[].unit"]');
+
+    var oldval = $(select_elt).data('oldval');
+    $(select_elt).data('oldval', $(select_elt).val());
+
+    var data = $('#reclamation_form').serializeArray();
+    data.push({ name: 'action',           value: 'Reclamation/unit_changed'     },
+              { name: 'item_id',          value: item_id_dom.val()        },
+              { name: 'old_unit',         value: oldval                   },
+              { name: 'sellprice_dom_id', value: sellprice_dom.attr('id') });
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  ns.update_sellprice = function(item_id, price_str) {
+    var row       = $('#item_' + item_id).parents("tbody").first();
+    var price_elt = $(row).find('[name="reclamation.reclamation_items[].sellprice_as_number"]');
+    var html_elt  = $(row).find('[name="sellprice_text"]');
+    price_elt.val(price_str);
+    html_elt.html(price_str);
+  };
+
+  ns.load_second_row = function(row) {
+    var item_id_dom = $(row).find('[name="reclamation_item_ids[+]"]');
+    var div_elt     = $(row).find('[name="second_row"]');
+
+    if ($(div_elt).data('loaded') == 1) {
+      return;
+    }
+    var data = $('#reclamation_form').serializeArray();
+    data.push({ name: 'action',     value: 'Reclamation/load_second_rows' },
+              { name: 'item_ids[]', value: item_id_dom.val()        });
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  ns.load_all_second_rows = function() {
+    var rows = $('.row_entry').filter(function(idx, elt) {
+      return $(elt).find('[name="second_row"]').data('loaded') != 1;
+    });
+
+    var item_ids = $.map(rows, function(elt) {
+      var item_id = $(elt).find('[name="reclamation_item_ids[+]"]').val();
+      return { name: 'item_ids[]', value: item_id };
+    });
+
+    if (item_ids.length == 0) {
+      return;
+    }
+
+    var data = $('#reclamation_form').serializeArray();
+    data.push({ name: 'action', value: 'Reclamation/load_second_rows' });
+    data = data.concat(item_ids);
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  ns.hide_second_row = function(row) {
+    $(row).children().not(':first').hide();
+    $(row).data('expanded', 0);
+    var elt = $(row).find('.expand');
+    elt.attr('src', "image/expand.svg");
+    elt.attr('alt', kivi.t8('Show details'));
+    elt.attr('title', kivi.t8('Show details'));
+  };
+
+  ns.show_second_row = function(row) {
+    $(row).children().not(':first').show();
+    $(row).data('expanded', 1);
+    var elt = $(row).find('.expand');
+    elt.attr('src', "image/collapse.svg");
+    elt.attr('alt', kivi.t8('Hide details'));
+    elt.attr('title', kivi.t8('Hide details'));
+  };
+
+  ns.toggle_second_row = function(row) {
+    if ($(row).data('expanded') == 1) {
+      ns.hide_second_row(row);
+    } else {
+      ns.show_second_row(row);
+    }
+  };
+
+  ns.init_row_handlers = function() {
+    kivi.run_once_for('.recalc', 'on_change_recalc', function(elt) {
+      $(elt).change(ns.recalc_amounts_and_taxes);
+    });
+
+    kivi.run_once_for('.reformat_number', 'on_change_reformat', function(elt) {
+      $(elt).change(ns.reformat_number);
+    });
+
+    kivi.run_once_for('.unitselect', 'on_change_unit_with_oldval', function(elt) {
+      $(elt).data('oldval', $(elt).val());
+      $(elt).change(ns.unit_change);
+    });
+
+    kivi.run_once_for('.row_entry', 'on_kbd_click_show_hide', function(elt) {
+      $(elt).keydown(function(event) {
+        var row;
+        if (event.keyCode == 40 && event.shiftKey === true) {
+          // shift arrow down
+          event.preventDefault();
+          row = $(event.target).parents(".row_entry").first();
+          ns.load_second_row(row);
+          ns.show_second_row(row);
+          return false;
+        }
+        if (event.keyCode == 38 && event.shiftKey === true) {
+          // shift arrow up
+          event.preventDefault();
+          row = $(event.target).parents(".row_entry").first();
+          ns.hide_second_row(row);
+          return false;
+        }
+      });
+    });
+
+    kivi.run_once_for('.expand', 'expand_second_row', function(elt) {
+      $(elt).click(function(event) {
+        event.preventDefault();
+        var row = $(event.target).parents(".row_entry").first();
+        ns.load_second_row(row);
+        ns.toggle_second_row(row);
+        return false;
+      })
+    });
+
+  };
+
+  ns.redisplay_line_values = function(is_sales, data) {
+    $('.row_entry').each(function(idx, elt) {
+      $(elt).find('[name="linetotal"]').html(data[idx][0]);
+      if (is_sales && $(elt).find('[name="second_row"]').data('loaded') == 1) {
+        var mt = data[idx][1];
+        var mp = data[idx][2];
+        var h  = '<span';
+        if (mt[0] === '-') h += ' class="plus0"';
+        h += '>' + mt + '&nbsp;&nbsp;' + mp + '%';
+        h += '</span>';
+        $(elt).find('[name="linemargin"]').html(h);
+      }
+    });
+  };
+
+  ns.redisplay_cvpartnumbers = function(data) {
+    $('.row_entry').each(function(idx, elt) {
+      $(elt).find('[name="cvpartnumber"]').html(data[idx][0]);
+    });
+  };
+
+  ns.renumber_positions = function() {
+    $('.row_entry [name="position"]').each(function(idx, elt) {
+      $(elt).html(idx+1);
+    });
+    $('.row_entry').each(function(idx, elt) {
+      $(elt).data("position", idx+1);
+    });
+  };
+
+  ns.reorder_items = function(order_by) {
+    var dir = $('#' + order_by + '_header_id a img').attr("data-sort-dir");
+    $('#row_table_id thead a img').remove();
+
+    var src;
+    if (dir == "1") {
+      dir = "0";
+      src = "image/up.png";
+    } else {
+      dir = "1";
+      src = "image/down.png";
+    }
+
+    $('#' + order_by + '_header_id a').append('<img border=0 data-sort-dir=' + dir + ' src=' + src + ' alt="' + kivi.t8('sort items') + '">');
+
+    var data = $('#reclamation_form').serializeArray();
+    data.push({ name: 'action',   value: 'Reclamation/reorder_items' },
+              { name: 'order_by', value: order_by              },
+              { name: 'sort_dir', value: dir                   });
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  ns.redisplay_items = function(data) {
+    var old_rows = $('.row_entry').detach();
+    var new_rows = [];
+    $(data).each(function(idx, elt) {
+      new_rows.push(old_rows[elt.old_pos - 1]);
+    });
+    $(new_rows).appendTo($('#row_table_id'));
+    ns.renumber_positions();
+  };
+
+  ns.get_insert_before_item_id = function(wanted_pos) {
+    if (wanted_pos === '') return;
+
+    var insert_before_item_id;
+    // selection by data does not seem to work if data is changed at runtime
+    // var elt = $('.row_entry [data-position="' + wanted_pos + '"]');
+    $('.row_entry').each(function(idx, elt) {
+      if ($(elt).data("position") == wanted_pos) {
+        insert_before_item_id = $(elt).find('[name="reclamation_item_ids[+]"]').val();
+        return false;
+      }
+    });
+
+    return insert_before_item_id;
+  };
+
+  ns.add_item = function() {
+    if ($('#add_item_parts_id').val() === '') return;
+    if (!ns.check_cv()) return;
+
+    $('#row_table_id thead a img').remove();
+
+    var insert_before_item_id = ns.get_insert_before_item_id($('#add_item_position').val());
+
+    var data = $('#reclamation_form').serializeArray();
+    data.push({ name: 'action', value: 'Reclamation/add_item' },
+              { name: 'insert_before_item_id', value: insert_before_item_id });
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  ns.open_multi_items_dialog = function() {
+    if (!ns.check_cv()) return;
+
+    var pp = $("#add_item_parts_id").data("part_picker");
+    pp.o.multiple=1;
+    pp.open_dialog();
+  };
+
+  ns.add_multi_items = function(data) {
+    var insert_before_item_id = ns.get_insert_before_item_id($('#multi_items_position').val());
+    data = data.concat($('#reclamation_form').serializeArray());
+    data.push({ name: 'action', value: 'Reclamation/add_multi_items' },
+              { name: 'insert_before_item_id', value: insert_before_item_id });
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  ns.delete_reclamation_item_row = function(clicked) {
+    var row = $(clicked).parents("tbody").first();
+    $(row).remove();
+
+    ns.renumber_positions();
+    ns.recalc_amounts_and_taxes();
+  };
+
+  ns.row_table_scroll_down = function() {
+    $('#row_table_scroll_id').scrollTop($('#row_table_scroll_id')[0].scrollHeight);
+  };
+
+  ns.show_longdescription_dialog = function(clicked) {
+    var row                 = $(clicked).parents("tbody").first();
+    var position            = $(row).find('[name="position"]').html();
+    var partnumber          = $(row).find('[name="partnumber"]').html();
+    var description_elt     = $(row).find('[name="reclamation.reclamation_items[].description"]');
+    var longdescription_elt = $(row).find('[name="reclamation.reclamation_items[].longdescription"]');
+
+    var params = {
+      runningnumber:           position,
+      partnumber:              partnumber,
+      description:             description_elt.val(),
+      default_longdescription: longdescription_elt.val(),
+      set_function:            function(val) {
+        longdescription_elt.val(val);
+      }
+    };
+
+    kivi.SalesPurchase.edit_longdescription_with_params(params);
+  };
+
+  ns.price_chooser_item_row = function(clicked) {
+    if (!ns.check_cv()) return;
+    var row         = $(clicked).parents("tbody").first();
+    var item_id_dom = $(row).find('[name="reclamation_items_ids[+]"]');
+
+    var data = $('#reclamation_form').serializeArray();
+    data.push({ name: 'action',  value: 'Reclamation/price_popup' },
+              { name: 'item_id', value: item_id_dom.val()   });
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  ns.update_price_source = function(item_id, source, descr, price_str, price_editable) {
+    var row        = $('#item_' + item_id).parents("tbody").first();
+    var source_elt = $(row).find('[name="reclamation.reclamation_items[].active_price_source"]');
+    var button_elt = $(row).find('[name="price_chooser_button"]');
+
+    button_elt.val(button_elt.val().replace(/.*\|/, descr + " |"));
+    source_elt.val(source);
+
+    var editable_div_elt     = $(row).find('[name="editable_price"]');
+    var not_editable_div_elt = $(row).find('[name="not_editable_price"]');
+    if (price_editable == 1 && source === '') {
+      // editable
+      $(editable_div_elt).show();
+      $(not_editable_div_elt).hide();
+      $(editable_div_elt).find(':input').prop("disabled", false);
+      $(not_editable_div_elt).find(':input').prop("disabled", true);
+    } else {
+      // not editable
+      $(editable_div_elt).hide();
+      $(not_editable_div_elt).show();
+      $(editable_div_elt).find(':input').prop("disabled", true);
+      $(not_editable_div_elt).find(':input').prop("disabled", false);
+    }
+
+    if (price_str) {
+      var price_elt = $(row).find('[name="reclamation.reclamation_items[].sellprice_as_number"]');
+      var html_elt  = $(row).find('[name="sellprice_text"]');
+      price_elt.val(price_str);
+      html_elt.html(price_str);
+      ns.recalc_amounts_and_taxes();
+    }
+
+    kivi.io.close_dialog();
+  };
+
+  ns.update_discount_source = function(item_id, source, descr, discount_str, price_editable) {
+    var row        = $('#item_' + item_id).parents("tbody").first();
+    var source_elt = $(row).find('[name="reclamation.reclamation_items[].active_discount_source"]');
+    var button_elt = $(row).find('[name="price_chooser_button"]');
+
+    button_elt.val(button_elt.val().replace(/\|.*/, "| " + descr));
+    source_elt.val(source);
+
+    var editable_div_elt     = $(row).find('[name="editable_discount"]');
+    var not_editable_div_elt = $(row).find('[name="not_editable_discount"]');
+    if (price_editable == 1 && source === '') {
+      // editable
+      $(editable_div_elt).show();
+      $(not_editable_div_elt).hide();
+      $(editable_div_elt).find(':input').prop("disabled", false);
+      $(not_editable_div_elt).find(':input').prop("disabled", true);
+    } else {
+      // not editable
+      $(editable_div_elt).hide();
+      $(not_editable_div_elt).show();
+      $(editable_div_elt).find(':input').prop("disabled", true);
+      $(not_editable_div_elt).find(':input').prop("disabled", false);
+    }
+
+    if (discount_str) {
+      var discount_elt = $(row).find('[name="reclamation.reclamation_items[].discount_as_percent"]');
+      var html_elt     = $(row).find('[name="discount_text"]');
+      discount_elt.val(discount_str);
+      html_elt.html(discount_str);
+      ns.recalc_amounts_and_taxes();
+    }
+
+    kivi.io.close_dialog();
+  };
+
+  ns.show_cv_details_dialog = function() {
+    if (!ns.check_cv()) return;
+    var cv;
+    var cv_id;
+    var title;
+    if ($('#type').val() == 'sales_reclamation') {
+      cv    = 'customer';
+      cv_id = $('#reclamation_customer_id').val();
+      title = kivi.t8('Customer details');
+    } else {
+      cv    = 'vendor';
+      cv_id = $('#reclamation_vendor_id').val();
+      title = kivi.t8('Vendor details');
+    }
+
+    kivi.popup_dialog({
+      url:    'controller.pl',
+      data:   { action: 'Reclamation/show_customer_vendor_details_dialog',
+                type  : $('#type').val(),
+                cv    : cv,
+                cv_id : cv_id
+              },
+      id:     'jq_customer_vendor_details_dialog',
+      dialog: {
+        title:  title,
+        width:  800,
+        height: 650
+      }
+    });
+    return true;
+  };
+
+  ns.update_row_from_master_data = function(clicked) {
+    var row = $(clicked).parents("tbody").first();
+    var item_id_dom = $(row).find('[name="reclamation_item_ids[+]"]');
+
+    var data = $('#reclamation_form').serializeArray();
+    data.push({ name: 'action', value: 'Reclamation/update_row_from_master_data' });
+    data.push({ name: 'item_ids[]', value: item_id_dom.val() });
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  ns.update_all_rows_from_master_data = function() {
+    var item_ids = $.map($('.row_entry'), function(elt) {
+      var item_id = $(elt).find('[name="reclamation_item_ids[+]"]').val();
+      return { name: 'item_ids[]', value: item_id };
+    });
+
+    if (item_ids.length == 0) {
+      return;
+    }
+
+    var data = $('#reclamation_form').serializeArray();
+    data.push({ name: 'action', value: 'Reclamation/update_row_from_master_data' });
+    data = data.concat(item_ids);
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+  ns.show_calculate_qty_dialog = function(clicked) {
+    var row        = $(clicked).parents("tbody").first();
+    var input_id   = $(row).find('[name="reclamation.reclamation_items[].qty_as_number"]').attr('id');
+    var formula_id = $(row).find('[name="formula[+]"]').attr('id');
+
+    calculate_qty_selection_dialog("", input_id, "", formula_id);
+    return true;
+  };
+
+  ns.edit_custom_shipto = function() {
+    if (!ns.check_cv()) return;
+
+    kivi.SalesPurchase.edit_custom_shipto();
+  };
+
+  ns.purchase_reclamation_check_for_direct_delivery = function() {
+    if ($('#type').val() != 'sales_reclamation') {
+      kivi.submit_form_with_action($('#reclamation_form'), 'Reclamation/save_and_purchase_reclamation');
+    }
+
+    var empty = true;
+    var shipto;
+    if ($('#reclamation_shipto_id').val() !== '') {
+      empty = false;
+      shipto = $('#reclamation_shipto_id option:selected').text();
+    } else {
+      $('#shipto_inputs [id^="shipto"]').each(function(idx, elt) {
+        if (!empty)                                     return true;
+        if (/^shipto_to_copy/.test($(elt).prop('id')))  return true;
+        if (/^shiptocp_gender/.test($(elt).prop('id'))) return true;
+        if (/^shiptocvar_/.test($(elt).prop('id')))     return true;
+        if ($(elt).val() !== '') {
+          empty = false;
+          return false;
+        }
+      });
+      var shipto_elements = [];
+      $([$('#shiptoname').val(), $('#shiptostreet').val(), $('#shiptozipcode').val(), $('#shiptocity').val()]).each(function(idx, elt) {
+        if (elt !== '') shipto_elements.push(elt);
+      });
+      shipto = shipto_elements.join('; ');
+    }
+
+    var use_it = false;
+    if (!empty) {
+      ns.direct_delivery_dialog(shipto);
+    } else {
+      kivi.submit_form_with_action($('#reclamation_form'), 'Reclamation/save_and_purchase_reclamation');
+    }
+  };
+
+  ns.direct_delivery_callback = function(accepted) {
+    $('#direct-delivery-dialog').dialog('close');
+
+    if (accepted) {
+      $('<input type="hidden" name="use_shipto">').appendTo('#reclamation_form').val('1');
+    }
+
+    kivi.submit_form_with_action($('#reclamation_form'), 'Reclamation/purchase_reclamation');
+  };
+
+  ns.direct_delivery_dialog = function(shipto) {
+    $('#direct-delivery-dialog').remove();
+
+    var text1 = kivi.t8('You have entered or selected the following shipping address for this customer:');
+    var text2 = kivi.t8('Do you want to carry this shipping address over to the new purchase reclamation so that the vendor can deliver the goods directly to your customer?');
+    var html  = '<div id="direct-delivery-dialog"><p>' + text1 + '</p><p>' + shipto + '</p><p>' + text2 + '</p>';
+    html      = html + '<hr><p>';
+    html      = html + '<input type="button" value="' + kivi.t8('Yes') + '" size="30" onclick="kivi.Reclamation.direct_delivery_callback(true)">';
+    html      = html + '&nbsp;';
+    html      = html + '<input type="button" value="' + kivi.t8('No')  + '" size="30" onclick="kivi.Reclamation.direct_delivery_callback(false)">';
+    html      = html + '</p></div>';
+    $(html).hide().appendTo('#reclamation_form');
+
+    kivi.popup_dialog({id: 'direct-delivery-dialog',
+                       dialog: {title:  kivi.t8('Carry over shipping address'),
+                                height: 300,
+                                width:  500 }});
+  };
+
+  ns.follow_up_window = function() {
+    var id   = $('#id').val();
+    var type = $('#type').val();
+    var number_info = $('#reclamation_record_number').val();
+
+    var name_info = '';
+    if ($('#type').val() == 'sales_reclamation') {
+      name_info = $('#reclamation_customer_id_name').val();
+    } else if ($('#type').val() == 'purchase_reclamation') {
+      name_info = $('#reclamation_vendor_id_name').val();
+    }
+
+    var info = '';
+    if (number_info !== '') { info += ' (' + number_info + ')' }
+    if (name_info   !== '') { info += ' (' + name_info + ')' }
+
+    if (!$('#follow_up_rowcount').lenght) {
+      $('<input type="hidden" name="follow_up_rowcount"        id="follow_up_rowcount">').appendTo('#reclamation_form');
+      $('<input type="hidden" name="follow_up_trans_id_1"      id="follow_up_trans_id_1">').appendTo('#reclamation_form');
+      $('<input type="hidden" name="follow_up_trans_type_1"    id="follow_up_trans_type_1">').appendTo('#reclamation_form');
+      $('<input type="hidden" name="follow_up_trans_info_1"    id="follow_up_trans_info_1">').appendTo('#reclamation_form');
+      $('<input type="hidden" name="follow_up_trans_subject_1" id="follow_up_trans_subject_1">').appendTo('#reclamation_form');
+    }
+    $('#follow_up_rowcount').val(1);
+    $('#follow_up_trans_id_1').val(id);
+    $('#follow_up_trans_type_1').val(type);
+    $('#follow_up_trans_info_1').val(info);
+    $('#follow_up_trans_subject_1').val($('#reclamation_transaction_description').val());
+
+    follow_up_window();
+  };
+
+  ns.create_part = function() {
+    var data = $('#reclamation_form').serializeArray();
+    data.push({ name: 'action', value: 'Reclamation/create_part' });
+
+    $.post("controller.pl", data, kivi.eval_json_result);
+  };
+
+});
+
+$(function() {
+  if ($('#type').val() == 'sales_reclamation') {
+    $('#reclamation_customer_id').change(kivi.Reclamation.reload_cv_dependent_selections);
+  } else {
+    $('#reclamation_vendor_id').change(kivi.Reclamation.reload_cv_dependent_selections);
+  }
+
+  $('#reclamation_currency_id').change(kivi.Reclamation.update_exchangerate);
+  $('#reclamation_transdate_as_date').change(kivi.Reclamation.update_exchangerate);
+  $('#reclamation_exchangerate_as_null_number').change(kivi.Reclamation.exchangerate_changed);
+
+  if ($('#type').val() == 'sales_reclamation') {
+    $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.sellprice, -2)) });
+  } else {
+    $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.lastcost, -2)) });
+  }
+  $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_description').val(o.description) });
+  $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_unit').val(o.unit) });
+
+  $('.add_item_input').keydown(function(event) {
+    if (event.keyCode == 13) {
+      event.preventDefault();
+      kivi.Reclamation.add_item();
+      return false;
+    }
+  });
+
+  kivi.Reclamation.init_row_handlers();
+
+  $('#row_table_id').on('sortstop', function(event, ui) {
+    $('#row_table_id thead a img').remove();
+    kivi.Reclamation.renumber_positions();
+  });
+
+  $('#expand_all').on('click', function(event) {
+    event.preventDefault();
+    if ($('#expand_all').data('expanded') == 1) {
+      $('#expand_all').data('expanded', 0);
+      $('#expand_all').attr('src', 'image/expand.svg');
+      $('#expand_all').attr('alt', kivi.t8('Show all details'));
+      $('#expand_all').attr('title', kivi.t8('Show all details'));
+      $('.row_entry').each(function(idx, elt) {
+        kivi.Reclamation.hide_second_row(elt);
+      });
+    } else {
+      $('#expand_all').data('expanded', 1);
+      $('#expand_all').attr('src', "image/collapse.svg");
+      $('#expand_all').attr('alt', kivi.t8('Hide all details'));
+      $('#expand_all').attr('title', kivi.t8('Hide all details'));
+      kivi.Reclamation.load_all_second_rows();
+      $('.row_entry').each(function(idx, elt) {
+        kivi.Reclamation.show_second_row(elt);
+      });
+    }
+    return false;
+  });
+
+  $('.reformat_number_as_null_number').change(kivi.Reclamation.reformat_number_as_null_number);
+
+});
diff --git a/menus/user/00-erp.yaml b/menus/user/00-erp.yaml
index 10d356b1b..4de532570 100644
--- a/menus/user/00-erp.yaml
+++ b/menus/user/00-erp.yaml
@@ -208,6 +208,15 @@
   params:
     action: add
     type: sales_delivery_order
+- parent: ar
+  id: ar_add_sales_reclamation
+  name: Add Sales Reclamation
+    #icon: reclamation_add TODO(Tamino): add icons
+  order: 450
+  access: sales_reclamation_edit
+  params:
+    action: Reclamation/add
+    type: sales_reclamation
 - parent: ar
   id: ar_add_sales_invoice
   name: Add Sales Invoice
@@ -300,6 +309,15 @@
   params:
     action: search
     type: sales_delivery_order
+- parent: ar_reports
+  id: ar_report_sales_reclamation
+  name: Sales Reclamation
+    #icon: reclamation_add TODO(Tamino): add icons
+  order: 450
+  access: sales_reclamation_edit
+  params:
+    action: Reclamation/list
+    type: sales_reclamation
 - parent: ar_reports
   id: ar_reports_invoices_credit_notes_ar_transactions
   name: Invoices, Credit Notes & AR Transactions
@@ -419,6 +437,15 @@
   params:
     action: add
     type: purchase_delivery_order
+- parent: ap
+  id: ap_add_purchase_reclamation
+  name: Add Purchase Reclamation
+    #icon: reclamation_add TODO(Tamino): add icons
+  order: 350
+  access: purchase_reclamation_edit
+  params:
+    action: Reclamation/add
+    type: purchase_reclamation
 - parent: ap
   id: ap_add_vendor_invoice
   name: Add Vendor Invoice
@@ -479,6 +506,15 @@
   params:
     action: search
     type: supplier_delivery_order
+- parent: ap_reports
+  id: ap_report_purchase_reclamation
+  name: Purchase Reclamation
+    #icon: reclamation_add TODO(Tamino): add icons
+  order: 370
+  access: purchase_reclamation_edit
+  params:
+    action: Reclamation/list
+    type: purchase_reclamation
 - parent: ap_reports
   id: ap_reports_vendor_invoices_ap_transactions
   name: Vendor Invoices & AP Transactions
@@ -1179,6 +1215,13 @@
   params:
     action: SimpleSystemSetting/list
     type: price_factor
+- parent: system
+  id: system_reclamation_reasons
+  name: Reclamation Reasons
+  order: 1220
+  params:
+    action: ReclamationReason/list
+    type: reclamation_reason
 - parent: system
   id: system_greetings
   name: Greetings
diff --git a/templates/webpages/reclamation/_filter.html b/templates/webpages/reclamation/_filter.html
new file mode 100644
index 000000000..e87c19b95
--- /dev/null
+++ b/templates/webpages/reclamation/_filter.html
@@ -0,0 +1,354 @@
+[%- USE HTML %][%- USE L %][%- USE LxERP %]
+
+[%- SET filter_element_hash = {
+'1' = {
+  'text' = LxERP.t8("Reclamation Reason"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.reclamation_items.reason.name:substr::ilike',
+  'input_default' = filter.reclamation_items.reason.name_substr__ilike,
+},
+'2' = {
+  'text' = LxERP.t8("Reclamation ID"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.id:number',
+  'input_default' = filter.id_number,
+  'report_id' = 'id',
+},
+'3' = {
+  'text' = LxERP.t8("Reclamation Number"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.record_number:substr::ilike',
+  'input_default' = filter.record_number_substr__ilike,
+  'report_id' = 'record_number',
+},
+'4' = {
+  'text' = LxERP.t8("Employee Name"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.employee.name:substr::ilike',
+  'input_default' = filter.employee.name_substr__ilike,
+  'report_id' = 'employee_id',
+},
+'5' = {
+  'text' = LxERP.t8("Salesman Name"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.salesman.name:substr::ilike',
+  'input_default' = filter.salesman.name_substr__ilike,
+  'report_id' = 'salesman_id',
+},
+# 6,7 for Customer/Vendor
+'8' = {
+  'text' = LxERP.t8("Contact Name"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.contact.cp_name:substr::ilike',
+  'input_default' = filter.contact.cp_name_substr__ilike,
+  'report_id' = 'contact_id',
+},
+'9' = {
+  'text' = LxERP.t8("Language Code"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.language.article_code:substr::ilike',
+  'input_default' = filter.language.article_code_substr__ilike,
+    'report_id' = 'language_id',
+},
+'10' = {
+  'text' = LxERP.t8("Department Description"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.department.description:substr::ilike',
+  'input_default' = filter.department.description_substr__ilike,
+    'report_id' = 'department_id',
+},
+'11' = {
+  'text' = LxERP.t8("Project Number"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.globalproject.projectnumber:substr::ilike',
+  'input_default' = filter.globalproject.projectnumber_substr__ilike,
+  'report_id' = 'globalproject_id',
+},
+'12' = {
+  'text' = LxERP.t8("Project Description"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.globalproject.description:substr::ilike',
+  'input_default' = filter.globalproject.description_substr__ilike,
+},
+# 13 cv_record_number
+'14' = {
+  'text' = LxERP.t8("Description"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.transaction_description:substr::ilike',
+  'input_default' = filter.transaction_description_substr__ilike,
+  'report_id' = 'transaction_description',
+},
+'15' = {
+  'text' = LxERP.t8("Notes"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.notes:substr::ilike',
+  'input_default' = filter.notes_substr__ilike,
+  'report_id' = 'notes',
+},
+'16' = {
+  'text' = LxERP.t8("Internal Notes"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.intnotes:substr::ilike',
+  'input_default' = filter.intnotes_substr__ilike,
+  'report_id' = 'intnotes',
+},
+'17' = {
+  'text' = LxERP.t8("Shipping Point"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.shippingpoint:substr::ilike',
+  'input_default' = filter.shippingpoint_substr__ilike,
+  'report_id' = 'shippingpoint',
+},
+'18' = {
+  'text' = LxERP.t8("Ship via"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.shipvia:substr::ilike',
+  'input_default' = filter.shipvia_substr__ilike,
+  'report_id' = 'shipvia',
+},
+'19' = {
+  'text' = LxERP.t8("Total"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.amount:number',
+  'input_default' = filter.amount_number,
+  'report_id' = 'amount',
+},
+'20' = {
+  'text' = LxERP.t8("Subtotal"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.netamount:number',
+  'input_default' = filter.netamount_number,
+  'report_id' = 'netamount',
+},
+'21' = {
+  'text' = LxERP.t8("Delivery Term"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.delivery_term.description:substr::ilike',
+  'input_default' = filter.delivery_term.description_substr__ilike,
+  'report_id' = 'delivery_term_id',
+},
+'22' = {
+  'text' = LxERP.t8("Payment Term"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.payment.description:substr::ilike',
+  'input_default' = filter.payment.description_substr__ilike,
+  'report_id' = 'payment_id',
+},
+'23' = {
+  'text' = LxERP.t8("Currency"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.currency.name:substr::ilike',
+  'input_default' = filter.currency.name_substr__ilike,
+  'report_id' = 'currency_id',
+},
+'24' = {
+  'text' = LxERP.t8("Exchangerate"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.exchangerate:number',
+  'input_default' = filter.exchangerate_number,
+  'report_id' = 'exchangerate',
+},
+'25' = {
+  'text' = LxERP.t8("Tax included"),
+  'input_type' = 'yes_no_tag'
+  'input_name' = 'filter.taxincluded',
+  'input_default' = filter.taxincluded,
+  'report_id' = 'taxincluded',
+},
+'26' = {
+  'text' = LxERP.t8("Tax Zone"),
+  'input_type' = 'input_tag'
+  'input_name' = 'filter.taxzone.description:substr::ilike',
+  'input_default' = filter.taxzone.description_substr__ilike,
+  'report_id' = 'taxzone_id',
+},
+'27' = {
+  'text' = LxERP.t8("Tax Point"),
+  'input_type' = 'date_tag'
+  'input_name' = 'tax_point',
+  'report_id' = 'tax_point',
+},
+'28' = {
+  'text' = LxERP.t8("Due Date"),
+  'input_type' = 'date_tag'
+  'input_name' = 'reqdate',
+  'report_id' = 'reqdate',
+},
+'29' = {
+  'text' = LxERP.t8("Booking Date"),
+  'input_type' = 'date_tag'
+  'input_name' = 'transdate',
+  'report_id' = 'transdate',
+},
+'30' = {
+  'text' = LxERP.t8("Creation Time"),
+  'input_type' = 'date_tag'
+  'input_name' = 'itime',
+  'report_id' = 'itime',
+},
+'31' = {
+  'text' = LxERP.t8("Last modified Time"),
+  'input_type' = 'date_tag'
+  'input_name' = 'mtime',
+  'report_id' = 'mtime',
+},
+'32' = {
+  'text' = LxERP.t8("Delivered"),
+  'input_type' = 'yes_no_tag'
+  'input_name' = 'filter.delivered',
+  'input_default' = filter.delivered,
+  'report_id' = 'delivered',
+},
+'33' = {
+  'text' = LxERP.t8("Closed"),
+  'input_type' = 'yes_no_tag'
+  'input_name' = 'filter.closed',
+  'input_default' = filter.closed,
+  'report_id' = 'closed',
+},
+
+} %]
+
+[%- IF SELF.type == 'sales_reclamation' %]
+[%- filter_element_hash.import( {
+  '6' = {
+    'text' = LxERP.t8("Customer Name"),
+    'input_type' = 'input_tag'
+    'input_name' = 'filter.customer.name:substr::ilike',
+    'input_default' = filter.customer.name_substr__ilike,
+    'report_id' = 'customer_id',
+  },
+  '7' = {
+    'text' = LxERP.t8("Customer Number"),
+    'input_type' = 'input_tag'
+    'input_name' = 'filter.customer.customernumber:substr::ilike',
+    'input_default' = filter.customer.customernumber_substr__ilike,
+  }
+  '13' = {
+    'text' = LxERP.t8("Customer Record Numeber"),
+    'input_type' = 'input_tag'
+    'input_name' = 'filter.cv_record_number:substr::ilike',
+    'input_default' = filter.cv_record_number_substr__ilike,
+    'report_id' = 'cv_record_number',
+  },
+} ) %]
+[%- ELSE %]
+[%- filter_element_hash.import( {
+  '6' = {
+    'text' = LxERP.t8("Vendor"),
+    'input_type' = 'input_tag'
+    'input_name' = 'filter.vendor.name:substr::ilike',
+    'input_default' = filter.vendor.name_substr__ilike,
+    'report_id' = 'vendor_id',
+  },
+  '7' = {
+    'text' = LxERP.t8("Vendor Number"),
+    'input_type' = 'input_tag'
+    'input_name' = 'filter.vendor.vendornumber:substr::ilike',
+    'input_default' = filter.vendor.vendornumber_substr__ilike,
+  }
+  '13' = {
+    'text' = LxERP.t8("Vendor Record Numeber"),
+    'input_type' = 'input_tag'
+    'input_name' = 'filter.cv_record_number:substr::ilike',
+    'input_default' = filter.cv_record_number_substr__ilike,
+    'report_id' = 'cv_record_number',
+  },
+} ) %]
+[%- END %]
+[% # L.dump(filter_element_list) %]
+[% # L.dump(active_in_report) %]
+
+<div class="filter_toggle" style="display:none">
+ <a href="#" onClick="$('.filter_toggle').toggle(); $('#filter_customer_name_substr_ilike').focus();">[% LxERP.t8("Show Filter") %]</a>
+</div>
+
+<div class="filter_toggle">
+ <a href="#" onClick="javascript:$('.filter_toggle').toggle()">[% LxERP.t8("Hide Filter") %]</a>
+
+ <form method="post" action="controller.pl" id="search_form">
+  [%- L.hidden_tag("_include_cvars_from_form", 1) %]
+
+  <p>
+   <table>
+    [%- SET count=0 %]
+    [%- SET table_size_count=0 %]
+    [%- SET size = filter_element_hash.size %]
+    <tr> <td>
+     <table>
+      [%- WHILE count < size %]
+      [%- SET count=count + 1 %]
+      [%- SET filter_element = filter_element_hash.${count} %]
+      <tr>
+       <th align="right">[% filter_element.text %]</th>
+       [%- IF filter_element.input_type == 'input_tag' %]
+         <td>[% L.input_tag(filter_element.input_name, filter_element.input_default)%]</td>
+       [%- ELSIF filter_element.input_type == 'yes_no_tag' %]
+         <td align="middle">[% L.yes_no_tag(filter_element.input_name, NONE , default=filter_element.input_default, with_empty=1) %]</td>
+       [%- ELSIF filter_element.input_type == 'date_tag' %]
+         <td>
+          <table>
+           <tr>
+            <th> [% LxERP.t8("After") %] </th>
+            <td>[% L.date_tag("filter.${filter_element.input_name}:date::ge", filter.${"${filter_element.input_name}_date__ge"})%]</td>
+           </tr><tr>
+            <th> [% LxERP.t8("Before") %] </th>
+            <td>[% L.date_tag("filter.${filter_element.input_name}:date::le", filter.${"${filter_element.input_name}_date__le"})%]</td>
+           </tr>
+          </table>
+         [%- SET table_size_count=table_size_count + 1 %]
+         </td>
+       [%- END %]
+       [%- IF filter_element.report_id %]
+       <td align="left">[% L.checkbox_tag("include_in_report_${filter_element.report_id}", checked=active_in_report.${filter_element.report_id}, for_submit=1) %]</td>
+       [%- END %]
+      </tr>
+      [%- SET table_size_count=table_size_count + 1 %]
+    [%- IF (table_size_count > 7) %]
+    [%- SET table_size_count=0 %]
+     </table>
+    </td>
+    <td>
+     <table>
+    [%- END %]
+      [%- END %]
+     </table>
+    </td> </tr>
+
+    [%- FOREACH cvar_cfg = SELF.cvar_configs %]
+    [%- IF cvar_cfg.searchable %]
+    <tr>
+      <th align="right">[% HTML.escape(cvar_cfg.description) %]</th>
+      <td>[% INCLUDE 'common/render_cvar_filter_input.html' cvar_cfg=cvar_cfg cvar_ %]</td>
+    </tr>
+    [%- END %]
+    [%-END %]
+
+    [%- IF SELF.includeable_cvar_configs.size %]
+     <tr>
+      <th align="right">[% LxERP.t8("Include in Report") %]</th>
+      <td>
+       <table>
+        <tr>
+         [%- FOREACH cvar_cfg = SELF.includeable_cvar_configs %]
+          <td>
+           [%- name__ = cvar_cfg.name;
+              L.checkbox_tag("include_cvars_" _ name__, value="1", checked=(SELF.include_cvars.$name__ ? 1 : ''), label=cvar_cfg.description) %]
+          </td>
+          [%- IF !loop.last && ((loop.count % 3) == 0) %]
+           </tr><tr>
+          [%- END %]
+         [%- END %]
+        </tr>
+       </table>
+      </td>
+     </tr>
+    [%- END %]
+
+   </table>
+  </p>
+ </form>
+ <p>
+ <a href="#" onClick="javascript:$('.filter_toggle').toggle()">[% LxERP.t8("Hide Filter") %]</a>
+</div>
+
diff --git a/templates/webpages/reclamation/_report_bottom.html b/templates/webpages/reclamation/_report_bottom.html
new file mode 100644
index 000000000..da08e0758
--- /dev/null
+++ b/templates/webpages/reclamation/_report_bottom.html
@@ -0,0 +1,2 @@
+[% USE L %]
+[%- L.paginate_controls(models=models) %]
diff --git a/templates/webpages/reclamation/_report_top.html b/templates/webpages/reclamation/_report_top.html
new file mode 100644
index 000000000..de50f02e6
--- /dev/null
+++ b/templates/webpages/reclamation/_report_top.html
@@ -0,0 +1,3 @@
+[%- USE L %]
+[%- PROCESS "reclamation/_filter.html" filter=SELF.models.filtered.laundered active_in_report=active_in_report %]
+ <hr>
diff --git a/templates/webpages/reclamation/form.html b/templates/webpages/reclamation/form.html
new file mode 100644
index 000000000..9bcf83c22
--- /dev/null
+++ b/templates/webpages/reclamation/form.html
@@ -0,0 +1,60 @@
+[%- USE T8 %]
+[%- USE LxERP %]
+[%- USE L %]
+[%- USE HTML %]
+[% # L.dump( SELF.reclamation.items_sorted ) %]
+
+<h1>[% FORM.title %] [% SELF.reclamation.id %] <span id='nr_in_title'>[%- SELF.reclamation.number -%]</span></h1>
+
+<div id="print_options" style="display:none">
+  <form method="post" action="controller.pl" id="print_options_form">
+    [% SELF.print_options %]
+    <br>
+    [% L.button_tag('kivi.Reclamation.print()', LxERP.t8('Print')) %]
+    <a href="#" onclick="$('#print_options').dialog('close');">[% LxERP.t8("Cancel") %]</a>
+  </form>
+</div>
+
+<div id="shipto_dialog" class="hidden"></div>
+
+<form method="post" action="controller.pl" id="reclamation_form">
+  [% L.hidden_tag('callback',             FORM.callback) %]
+  [% L.hidden_tag('type',                 FORM.type) %]
+  [% L.hidden_tag('id',                   SELF.reclamation.id) %]
+  [% L.hidden_tag('converted_from_record_type_ref', SELF.reclamation.converted_from_record_type_ref) %]
+  [% L.hidden_tag('converted_from_record_id',  SELF.reclamation.converted_from_record_id) %]
+
+  [%- INCLUDE 'common/flash.html' %]
+
+  <div class="tabwidget" id="reclamation_tabs">
+    <ul>
+      <li><a href="#ui-tabs-basic-data">[% 'Basic Data' | $T8 %]</a></li>
+[%- IF INSTANCE_CONF.get_webdav %]
+      <li><a href="#ui-tabs-webdav">[% 'WebDAV' | $T8 %]</a></li>
+[%- END %]
+[%- IF SELF.reclamation.id AND INSTANCE_CONF.get_doc_storage %]
+      <li><a href="controller.pl?action=File/list&file_type=document&object_type=[% HTML.escape(FORM.type) %]&object_id=[% HTML.url(SELF.reclamation.id) %]">[% 'Documents' | $T8 %]</a></li>
+      <li><a href="controller.pl?action=File/list&file_type=attachment&object_type=[% HTML.escape(FORM.type) %]&object_id=[% HTML.url(SELF.reclamation.id) %]">[% 'Attachments' | $T8 %]</a></li>
+[%- END %]
+[%- IF SELF.reclamation.id %]
+      <li><a href="controller.pl?action=RecordLinks/ajax_list&object_model=Reclamation&object_id=[% SELF.reclamation.id %]">[% 'Linked Records' | $T8 %]</a></li>
+[%- END %]
+    </ul>
+
+    [% PROCESS "reclamation/tabs/basic_data.html" %]
+    [% PROCESS 'webdav/_list.html' %]
+    <div id="ui-tabs-1">
+      [%- LxERP.t8("Loading...") %]
+    </div>
+
+    <div id="shipto_inputs" class="hidden">
+      [%- PROCESS 'common/_ship_to_dialog.html'
+        cv_obj=SELF.reclamation.customervendor
+        cs_obj=SELF.reclamation.custom_shipto
+        cvars=SELF.reclamation.custom_shipto.cvars_by_config
+        id_selector='#reclamation_shipto_id' %]
+    </div>
+
+  </div>
+
+</form>
diff --git a/templates/webpages/reclamation/tabs/basic_data.html b/templates/webpages/reclamation/tabs/basic_data.html
new file mode 100644
index 000000000..e74156e1b
--- /dev/null
+++ b/templates/webpages/reclamation/tabs/basic_data.html
@@ -0,0 +1,334 @@
+[%- USE T8 %]
+[%- USE HTML %]
+[%- USE LxERP %]
+[%- USE L %]
+[%- USE P %]
+
+[%- INCLUDE 'generic/set_longdescription.html' %]
+
+<div id="ui-tabs-basic-data">
+  <table width="100%">
+    <tr valign="top">
+      <td>
+        <table width="100%">
+          <tr>
+            <th align="right">[%- SELF.cv == "customer" ? LxERP.t8('Customer') : LxERP.t8('Vendor') -%]</th>
+            [% SET cv_id = SELF.cv _ '_id' %]
+            <td>
+              [% P.customer_vendor.picker("reclamation.${SELF.cv}" _ '_id', SELF.reclamation.$cv_id, type=SELF.cv, style='width: 300px') %]
+              [% P.button_tag("kivi.Reclamation.show_cv_details_dialog()", LxERP.t8("Details (one letter abbreviation)")) %]
+            </td>
+          </tr>
+
+          <tr id='contact_row' [%- IF !SELF.reclamation.${SELF.cv}.contacts.size %]style='display:none'[%- END %]>
+            <th align="right">[% 'Contact Person' | $T8 %]</th>
+            <td>[% L.select_tag('reclamation.contact_id',
+                                SELF.reclamation.${SELF.cv}.contacts,
+                                default=SELF.reclamation.contact_id,
+                                title_key='full_name_dep',
+                                value_key='cp_id',
+                                with_empty=1,
+                                style='width: 300px') %]</td>
+          </tr>
+
+          <tr>
+            <th align="right">[% 'Shipping Address' | $T8 %]</th>
+            <td>
+              <span id='shipto_selection' [%- IF !SELF.reclamation.${SELF.cv}.shipto.size %] style='display:none'[%- END %] >
+                [% shiptos = [ { shipto_id => "", displayable_id => LxERP.t8("No/individual shipping address") } ] ;
+                   FOREACH s = SELF.reclamation.${SELF.cv}.shipto ;
+                     shiptos.push(s) ;
+                   END ;
+                   L.select_tag('reclamation.shipto_id',
+                                 shiptos,
+                                 default=SELF.reclamation.shipto_id,
+                                 title_key='displayable_id',
+                                 value_key='shipto_id',
+                                 with_empty=0,
+                                 style='width: 300px') %]
+              </span>
+              [% L.button_tag("kivi.Reclamation.edit_custom_shipto()", LxERP.t8("Custom shipto")) %]
+            </td>
+          </tr>
+
+          [%- PROCESS reclamation/tabs/basic_data/_business_info_row.html SELF=SELF %]
+
+          <tr>
+            <th align="right">[% 'Tax rate' | $T8 %]</th>
+            <td>[% L.select_tag('reclamation.taxzone_id', SELF.all_taxzones, default=SELF.reclamation.taxzone_id, title_key='description', style='width: 300px', class='recalc') %]</td>
+          </tr>
+
+          [% SET currency_id = SELF.reclamation.currency_id || INSTANCE_CONF.get_currency_id  # use default currency for new reclamation %]
+          <tr id="currency_settings">
+            <th align="right">[% 'Currency' | $T8 %]</th>
+            <td>[% L.select_tag('reclamation.currency_id', SELF.all_currencies, default=currency_id, value_key='id', title_key='name') %]</td>
+          </tr>
+          <tr id="exchangerate_settings" [%- IF SELF.reclamation.currency_id==INSTANCE_CONF.get_currency_id %]style='display:none'[%- END %]>
+            <th align="right">[% 'Exchangerate' | $T8 %]</th>
+            <td> 1 <span id="currency_name">[% SELF.reclamation.currency.name %]</span> =
+              [% L.input_tag('reclamation.exchangerate_as_null_number', SELF.reclamation.exchangerate_as_null_number, size="15", class="reformat_number_as_null_number numeric") %]
+              [% INSTANCE_CONF.default_currency %]
+              [% L.hidden_tag('old_currency_id', currency_id) %]
+              [% L.hidden_tag('old_exchangerate', SELF.reclamation.exchangerate_as_null_number) %]
+            </td>
+          </tr>
+
+[%- IF SELF.all_languages.size %]
+          <tr>
+            <th align="right">[% 'Language' | $T8 %]</th>
+            <td>
+              [% L.select_tag('reclamation.language_id', SELF.all_languages, default=SELF.reclamation.language_id, title_key='description', with_empty=1, style='width:300px') %]
+            </td>
+          </tr>
+[%- END %]
+
+[%- IF SELF.all_departments.size %]
+          <tr>
+            <th align="right">[% 'Department' | $T8 %]</th>
+            <td>
+              [% L.select_tag('reclamation.department_id', SELF.all_departments, default=SELF.reclamation.department_id, title_key='description', with_empty=1, style='width:300px') %]
+            </td>
+          </tr>
+[%- END %]
+
+          <tr>
+            <th align="right">[% 'Shipping Point' | $T8 %]</th>
+            <td>[% L.input_tag('reclamation.shippingpoint', SELF.reclamation.shippingpoint, style='width: 300px') %]</td>
+          </tr>
+
+          <tr>
+            <th align="right">[% 'Ship via' | $T8 %]</th>
+            <td>[% L.input_tag('reclamation.shipvia', SELF.reclamation.shipvia, style='width: 300px') %]</td>
+          </tr>
+
+          <tr>
+            <th align="right">[% 'Transaction description' | $T8 %]</th>
+            <td>[% L.input_tag('reclamation.transaction_description', SELF.reclamation.transaction_description, 'data-validate'=INSTANCE_CONF.get_require_transaction_description_ps ? 'required' : '', style='width: 300px') %]</td>
+          </tr>
+
+          <tr>
+            <th align="right">[% 'Project Number' | $T8 %]</th>
+            <td>[% P.project.picker('reclamation.globalproject_id', SELF.reclamation.globalproject_id, style='width: 300px') %]</td>
+          </tr>
+
+        </table>
+      </td>
+
+      <td align="right">
+        <table>
+
+          <tr>
+            <td colspan="2" align="center">
+              [%- IF SELF.reclamation.id %]
+                <label for="reclamation.delivered">[% 'Delivery Order(s) for full qty created' | $T8 %]</label>
+                [% L.yes_no_tag('reclamation.delivered', SELF.reclamation.delivered) %]
+                <label for="reclamation.closed">[% 'Closed' | $T8 %]</label>
+                [% L.yes_no_tag('reclamation.closed', SELF.reclamation.closed) %]
+              [%- END %]
+            </td>
+          </tr>
+
+          <tr>
+            <th align="right">[% 'Employee' | $T8 %]</th>
+            <td>[% L.select_tag('reclamation.employee_id',
+              SELF.all_employees,
+              default=(SELF.reclamation.employee_id ? SELF.reclamation.employee_id : SELF.current_employee_id),
+              title_key='safe_name') %]</td>
+          </tr>
+
+          [% IF SELF.cv == 'customer' %]
+          <tr>
+            <th align="right">[% 'Salesman' | $T8 %]</th>
+            <td>[% L.select_tag('reclamation.salesman_id',
+              SELF.all_salesmen,
+              default=(SELF.reclamation.salesman_id ? SELF.reclamation.salesman_id : SELF.current_employee_id),
+              title_key='safe_name') %]</td>
+          </tr>
+          [% END %]
+
+          <tr>
+            <th width="70%" align="right" nowrap>[% 'Reclamation Number' | $T8 %]</th>
+            <td>[% L.input_tag('reclamation.record_number', SELF.reclamation.record_number, size = 11, onchange='kivi.Reclamation.set_number_in_title(this)') %]</td>
+          </tr>
+
+          <tr>
+            <th width="70%" align="right" nowrap>[% 'Customer Record Number' | $T8 %]</th>
+            <td>[% L.input_tag('reclamation.cv_record_number', SELF.reclamation.cv_record_number, size = 11) %]</td>
+          </tr>
+
+          <tr>
+            <th width="70%" align="right" nowrap>[% 'Reclamation Date' | $T8 %]</th>
+            <td>[% L.date_tag('reclamation.transdate_as_date', SELF.reclamation.transdate_as_date) %]</td>
+          </tr>
+
+          <tr>
+            <th width="70%" align="right" nowrap>[% 'Tax point' | $T8 %]</th>
+            <td>[% L.date_tag('reclamation.tax_point_as_date', SELF.reclamation.tax_point_as_date, class="recalc") %]</td>
+          </tr>
+
+          <tr>
+            <th width="70%" align="right" nowrap>[% 'Due Date' | $T8 %]</th>
+            <td>[% L.date_tag('reclamation.reqdate_as_date', SELF.reclamation.reqdate_as_date, class="recalc") %]</td>
+          </tr>
+
+          <tr>
+            <th width="70%" align="right" nowrap>[% 'Insert Date' | $T8 %]</th>
+            <td>[% SELF.reclamation.itime_as_date %]</td>
+          </tr>
+
+        </table>
+
+      </td>
+    </tr>
+  </table>
+
+  [%- PROCESS reclamation/tabs/basic_data/_item_input.html SELF=SELF %]
+
+  [% L.button_tag('kivi.Reclamation.open_multi_items_dialog()', LxERP.t8('Add multiple items')) %]
+
+  <table width="100%">
+    <tr>
+      <td>
+        [%- IF SELF.positions_scrollbar_height -%]
+          [%- SET scroll_style = 'style="overflow-y: auto; height:' _ SELF.positions_scrollbar_height _ 'vh;"' -%]
+        [%- ELSE -%]
+          [%- SET scroll_style = '' -%]
+        [%- END -%]
+        <div id="row_table_scroll_id" [%- scroll_style -%]>
+          <table id="row_table_id" width="100%">
+            <thead>
+              <tr class="listheading">
+                <th class="listheading" style='text-align:center' nowrap width="1">
+                  [%- IF MYCONFIG.show_form_details %]
+                    [%- L.img_tag(src="image/collapse.svg", alt=LxERP.t8('Hide all details'), title=LxERP.t8('Hide all details'), id='expand_all', "data-expanded"="1") %]
+                  [%- ELSE %]
+                    [%- L.img_tag(src="image/expand.svg", alt=LxERP.t8('Show all details'), title=LxERP.t8('Show all details'), id='expand_all') %]
+                  [%- END %]
+                </th>
+                <th class="listheading" nowrap width="3" >[%- 'position'     | $T8 %] </th>
+                <th class="listheading" style='text-align:center' nowrap width="1"><img src="image/updown.png" alt="[%- LxERP.t8('reorder item') %]"></th>
+                <th class="listheading" style='text-align:center' nowrap width="1"><img src="image/close.png" alt="[%- LxERP.t8('delete item') %]"></th>
+                [%- IF SELF.show_update_button -%]
+                <th class="listheading" style='text-align:center' nowrap width="1">
+                  [%- L.img_tag(src="image/rotate_cw.svg",
+                                alt=LxERP.t8('Update from master data'),
+                                title= LxERP.t8('Update from master data'),
+                                onclick="if (!confirm('" _ LxERP.t8("Are you sure to update all positions from master data?") _ "')) return false; kivi.Reclamation.update_all_rows_from_master_data();",
+                                id='update_from_master') %]
+                </th>
+                [%- END %]
+                <th id="partnumber_header_id"   class="listheading" nowrap width="15"><a href='#' onClick='javascript:kivi.Reclamation.reorder_items("partnumber")'> [%- 'Partnumber'  | $T8 %]</a></th>
+                [%- IF SELF.search_cvpartnumber -%]
+                <th id="cvpartnumber_header_id" class="listheading" nowrap width="15"><a href='#' onClick='javascript:kivi.Reclamation.reorder_items("cvpartnumber")' > [%- SELF.cv == "customer" ? LxERP.t8('Customer Part Number') : LxERP.t8('Model') %]</a></th>
+                [%- END -%]
+                <th id="partclass_header_id"    class="listheading" nowrap width="2">[%- 'Type'  | $T8 %]</th>
+                <th id="description_header_id"  class="listheading" nowrap           ><a href='#' onClick='javascript:kivi.Reclamation.reorder_items("description")'>[%- 'Description' | $T8 %]</a></th>
+                <th id="reason_header_id"   class="listheading" nowrap width="100"><a href='#' onClick='javascript:kivi.Reclamation.reorder_items("reason")'>[%- 'Reason' | $T8 %]</a></th>
+                <th id="reason_description_ext_header_id"  class="listheading" nowrap ><a href='#' onClick='javascript:kivi.Reclamation.reorder_items("reason_description_ext")'>[%- 'Reason Description Extern' | $T8 %]</a></th>
+                <th id="reason_description_int_header_id"  class="listheading" nowrap ><a href='#' onClick='javascript:kivi.Reclamation.reorder_items("reason_description_int")'>[%- 'Reason Description Intern' | $T8 %]</a></th>
+                <th id="shipped_qty_header_id"  class="listheading" nowrap width="5" ><a href='#' onClick='javascript:kivi.Reclamation.reorder_items("shipped_qty")'>[%- 'Delivered'   | $T8 %]</a></th>
+                <th id="qty_header_id"          class="listheading" nowrap width="5" ><a href='#' onClick='javascript:kivi.Reclamation.reorder_items("qty")'>        [%- 'Qty'         | $T8 %]</a></th>
+                <th class="listheading" nowrap width="5" >[%- 'Price Factor' | $T8 %] </th>
+                <th class="listheading" nowrap width="5" >[%- 'Unit'         | $T8 %] </th>
+                <th class="listheading" nowrap width="5" >[%- 'Price Source' | $T8 %] </th>
+                <th id="sellprice_header_id"   class="listheading" nowrap width="15" ><a href='#' onClick='javascript:kivi.Reclamation.reorder_items("sellprice")'> [%- 'Price'       | $T8 %]</a></th>
+                <th id="discount_header_id"    class="listheading" nowrap width="15" ><a href='#' onClick='javascript:kivi.Reclamation.reorder_items("discount")'>  [%- 'Discount'    | $T8 %]</a></th>
+                <th class="listheading" nowrap width="10">[%- 'Extended'     | $T8 %] </th>
+              </tr>
+            </thead>
+
+            [%- FOREACH item = SELF.reclamation.items_sorted %]
+              [%- PROCESS reclamation/tabs/basic_data/_row.html ITEM=item ID=(item.id||item.new_fake_id) -%]
+            [%- END %]
+
+          </table>
+        </div>
+
+      </td>
+    </tr>
+
+    <tr>
+    </tr>
+
+    <tr>
+      <td colspan="100%" width="100%">
+        <table width="100%">
+          <tr>
+            <td>
+              <table>
+                <tr>
+                  <th align="left">[% 'Notes' | $T8 %]</th>
+                  <th align="left">[% 'Internal Notes' | $T8 %]</th>
+                </tr>
+                <tr valign="top">
+                  <td>
+                    [% L.textarea_tag('reclamation.notes', SELF.reclamation.notes, wrap="soft", style="width: 350px; height: 150px", class="texteditor") %]
+                  </td>
+                  <td>
+                    [% L.textarea_tag('reclamation.intnotes', SELF.reclamation.intnotes, wrap="soft", style="width: 350px; height: 150px") %]
+                  </td>
+                </tr>
+              </table>
+            </td>
+
+            <td>
+              <table>
+                <tr>
+                  <th align="right">[% 'Payment Terms' | $T8 %]</th>
+                  <td>[% L.select_tag('reclamation.payment_id',
+                                      SELF.all_payment_terms,
+                                      default = SELF.reclamation.payment_id,
+                                      with_empty = 1,
+                                      title_key = 'description',
+                                      style = 'width: 250px') %]</td>
+                </tr>
+                <tr>
+                  <th align="right">[% 'Delivery Terms' | $T8 %]</th>
+                  <td>[% L.select_tag('reclamation.delivery_term_id',
+                                      SELF.all_delivery_terms,
+                                      default = SELF.reclamation.delivery_term_id,
+                                      with_empty = 1,
+                                      title_key = 'description',
+                                      style = 'width: 250px') %]</td>
+                </tr>
+              </table>
+            </td>
+
+
+            <td align="right">
+              <table>
+                <tr id="taxincluded_row_id" [%- IF !SELF.taxes.size %]style="display:none"[%- END %]>
+                  <td align=right colspan="2">
+                    <label for="reclamation.taxincluded"><b>[% 'Tax Included' | $T8 %]</b></label>
+                    [% L.yes_no_tag('reclamation.taxincluded', SELF.reclamation.taxincluded, class='recalc') %]
+                  </td>
+                </tr>
+
+                <tr id="subtotal_row_id" [%- IF SELF.reclamation.taxincluded %]style="display:none"[%- END %]>
+                  <th align="right">[%- 'Subtotal' | $T8 %]</th>
+                  <td align="right">
+                    [%- L.div_tag(SELF.reclamation.netamount_as_number, id='netamount_id') %]
+                  </td>
+                </tr>
+                [%- FOREACH tax = SELF.reclamation.taxes %]
+                  [%- PROCESS reclamation/tabs/basic_data/_tax_row.html TAX=tax TAXINCLUDED=SELF.reclamation.taxincluded %]
+                [%- END %]
+                <tr id="amount_row_id">
+                  <th align="right">[%- 'Total' | $T8 %]</th>
+                  <td align="right">
+                    [%- L.div_tag(SELF.reclamation.amount_as_number, id='amount_id') %]
+                  </td>
+                </tr>
+              </table>
+            </td>
+
+          </tr>
+        </table>
+      </td>
+    </tr>
+
+  </table>
+
+</div>
+
+[% L.sortable_element('#row_table_id') %]
diff --git a/templates/webpages/reclamation/tabs/basic_data/_business_info_row.html b/templates/webpages/reclamation/tabs/basic_data/_business_info_row.html
new file mode 100644
index 000000000..183ae2556
--- /dev/null
+++ b/templates/webpages/reclamation/tabs/basic_data/_business_info_row.html
@@ -0,0 +1,10 @@
+[%- USE T8 %][%- USE HTML %]
+
+<tr id='business_info_row' [%- IF !SELF.reclamation.customervendor.business_id %]style='display:none'[%- END %]>
+  <th align="right">[%- IF SELF.cv == 'customer' -%]
+                      [%- 'Customer type' | $T8 -%]
+                    [%- ELSE -%]
+                      [%- 'Vendor type' | $T8 -%]
+                    [%- END -%]</th>
+  <td>[% HTML.escape(SELF.reclamation.customervendor.business.description) %]; [% 'Trade Discount' | $T8 %] [% SELF.reclamation.customervendor.business.discount_as_percent %] %</td>
+</tr>
diff --git a/templates/webpages/reclamation/tabs/basic_data/_item_input.html b/templates/webpages/reclamation/tabs/basic_data/_item_input.html
new file mode 100644
index 000000000..de0fd59c4
--- /dev/null
+++ b/templates/webpages/reclamation/tabs/basic_data/_item_input.html
@@ -0,0 +1,49 @@
+[%- USE T8 %][%- USE HTML %][%- USE LxERP %][%- USE L %][%- USE P %]
+
+ <div>
+  <table id="input_row_table_id">
+    <thead>
+      <tr class="listheading">
+        <th class="listheading" nowrap >[%- '+'            | $T8 %] </th>
+        <th class="listheading" nowrap >[%- 'position'     | $T8 %] </th>
+        <th class="listheading" nowrap >[%- 'Part'         | $T8 %] </th>
+        <th class="listheading" nowrap >[%- 'Description'  | $T8 %] </th>
+        <th class="listheading" nowrap width="5" >[%- 'Qty'          | $T8 %] </th>
+        <th class="listheading" nowrap width="15">[%- 'Price'        | $T8 %] </th>
+        <th class="listheading" nowrap width="5" >[%- 'Discount'     | $T8 %] </th>
+        <th></th>
+      </tr>
+    </thead>
+    <tbody>
+      <tr valign="top" class="listrow">
+        <td class="tooltipster-html" title="[%- 'Create a new part' | $T8 -%]">
+          [% SET type_options = [[ 'part', LxERP.t8('Part') ], [ 'assembly', LxERP.t8('Assembly') ], [ 'service', LxERP.t8('Service') ] ] %]
+          [%- IF INSTANCE_CONF.get_feature_experimental_assortment %]
+            [%- type_options.push([ 'assortment', LxERP.t8('Assortment')]) %]
+          [%- END %]
+          [% L.select_tag('add_item.create_part_type', type_options) %]
+          [% L.button_tag('kivi.Reclamation.create_part()', LxERP.t8('+')) %]
+        </td>
+        <td>[% L.input_tag('add_item.position', '', size = 5, class="add_item_input numeric") %]</td>
+        <td>
+          [%- SET PARAM_KEY = SELF.cv == "customer" ? 'with_customer_partnumber' : 'with_makemodel' -%]
+          [%- SET PARAM_VAL = SELF.search_cvpartnumber -%]
+          [% P.part.picker('add_item.parts_id', SELF.created_part, style='width: 300px', class="add_item_input",
+                            fat_set_item=1,
+                            multiple_pos_input=1,
+                            action={set_multi_items='kivi.Reclamation.add_multi_items'},
+                            classification_id=SELF.part_picker_classification_ids.as_list.join(','),
+                            $PARAM_KEY=PARAM_VAL) %]</td>
+        <td>[% L.input_tag('add_item.description', SELF.created_part.description, class="add_item_input") %]</td>
+        <td>
+          [% L.input_tag('add_item.qty_as_number', '', size = 5, class="add_item_input numeric") %]
+          [% L.hidden_tag('add_item.unit', SELF.created_part.unit, class="add_item_input") %]
+        </td>
+        [%- SET price = LxERP.format_amount(((SELF.type == 'sales_reclamation') ? SELF.created_part.sellprice : SELF.created_part.lastcost), -2) -%]
+        <td>[% L.input_tag('add_item.sellprice_as_number', price, size = 10, class="add_item_input numeric") %]</td>
+        <td>[% L.input_tag('add_item.discount_as_percent', '', size = 5, class="add_item_input numeric") %]</td>
+        <td>[% L.button_tag('kivi.Reclamation.add_item()', LxERP.t8('Add part')) %]</td>
+      </tr>
+    </tbody>
+  </table>
+ </div>
diff --git a/templates/webpages/reclamation/tabs/basic_data/_price_sources_dialog.html b/templates/webpages/reclamation/tabs/basic_data/_price_sources_dialog.html
new file mode 100644
index 000000000..75221aca9
--- /dev/null
+++ b/templates/webpages/reclamation/tabs/basic_data/_price_sources_dialog.html
@@ -0,0 +1,110 @@
+[%- USE T8 %]
+[%- USE HTML %]
+[%- USE L %]
+[%- USE LxERP %]
+[%-  #L.dump( price_source ) %]
+
+[% SET best_price = price_source.best_price %]
+[% SET best_discount = price_source.best_discount %]
+
+[% SET price_editable = 0 %]
+[% IF (FORM.type == "sales_reclamation") %]
+  [% SET price_editable = AUTH.assert('sales_edit_prices', 1) %]
+[% END %]
+[% IF (FORM.type == "purchase_reclamation") %]
+  [% SET price_editable = AUTH.assert('purchase_edit_prices', 1) %]
+[% END %]
+
+[% SET exfactor = price_source.record.exchangerate ? 1 / price_source.record.exchangerate : 1 %]
+[% SET exnoshow = price_source.record.currency_id==INSTANCE_CONF.get_currency_id %]
+[% SET places   = exnoshow ? -2 : 5 %]
+  <h2>[% 'Prices' | $T8 %]</h2>
+
+  <table>
+   <tr class='listheading'>
+    <th></th>
+    <th>[% 'Price Source' | $T8 %]</th>
+    <th>[% 'Price' | $T8 %]</th>
+    <th [%- IF exnoshow -%]style='display:none'[%- END %]>
+      [% 'Price' | $T8 -%]/[%- price_source.record.currency.name %]
+    </th>
+    <th>[% 'Best Price' | $T8 %]</th>
+    <th>[% 'Details' | $T8 %]</th>
+   </tr>
+   <tr class='listrow'>
+[%- IF price_source.record_item.active_price_source %]
+    <td>[% L.button_tag('kivi.Reclamation.update_price_source(\'' _ FORM.item_id _ '\', \'\', \'' _ LxERP.t8('None (PriceSource)') _ '\', \'\', ' _ price_editable _ ')', LxERP.t8('Select')) %]</td>
+[%- ELSE %]
+    <td><b>[% 'Selected' | $T8 %]</b></td>
+[%- END %]
+    <td>[% 'None (PriceSource)' | $T8 %]</td>
+    <td>-</td>
+    <td [%- IF exnoshow -%]style='display:none'[%- END %]>-</td>
+    <td></td>
+    <td></td>
+   </tr>
+   [%- FOREACH price IN price_source.available_prices %]
+    <tr class='listrow'>
+[%- IF price_source.record_item.active_price_source != price.source %]
+     <td>[% L.button_tag('kivi.Reclamation.update_price_source(\'' _ FORM.item_id _ '\', \'' _ price.source _ '\', \'' _ price.source_description _ '\', \'' _ LxERP.format_amount(price.price * exfactor, places) _ '\', ' _ price_editable _ ')', LxERP.t8('Select')) %]</td>
+[%- ELSIF price_source.record_item.sellprice * 1 != price.price * 1 %]
+     <td>[% L.button_tag('kivi.Reclamation.update_price_source(\'' _ FORM.item_id _ '\', \'' _ price.source _ '\', \'' _ price.source_description _ '\', \'' _ LxERP.format_amount(price.price * exfactor, places) _ '\', ' _ price_editable _ ')', LxERP.t8('Update Price')) %]</td>
+[%- ELSE %]
+    <td><b>[% 'Selected' | $T8 %]</b></td>
+[% END %]
+     <td>[% price.source_description | html %]</td>
+     <td>[% price.price_as_number %]</td>
+     <td [%- IF exnoshow -%]style='display:none'[%- END %]>
+       [% LxERP.format_amount(price.price * exfactor, places) %]
+     </td>
+[% IF price.source == best_price.source %]
+     <td align='center'>&#x2022;</td>
+[% ELSE %]
+     <td></td>
+[% END %]
+     <td>[% price.description | html %]</td>
+    </tr>
+   [%- END %]
+  </table>
+
+  <h2>[% 'Discounts' | $T8 %]</h2>
+
+  <table>
+   <tr class='listheading'>
+    <th></th>
+    <th>[% 'Price Source' | $T8 %]</th>
+    <th>[% 'Discount' | $T8 %]</th>
+    <th>[% 'Best Discount' | $T8 %]</th>
+    <th>[% 'Details' | $T8 %]</th>
+   </tr>
+   <tr class='listrow'>
+[%- IF price_source.record_item.active_discount_source %]
+    <td>[% L.button_tag('kivi.Reclamation.update_discount_source(\'' _ FORM.item_id _ '\', \'\', \'' _ LxERP.t8('None (PriceSource Discount)') _ '\', \'\', ' _ price_editable _ ')', LxERP.t8('Select')) %]</td>
+[%- ELSE %]
+    <td><b>[% 'Selected' | $T8 %]</b></td>
+[%- END %]
+    <td>[% 'None (PriceSource Discount)' | $T8 %]</td>
+    <td>-</td>
+    <td></td>
+    <td></td>
+   </tr>
+   [%- FOREACH price IN price_source.available_discounts %]
+    <tr class='listrow'>
+[%- IF price_source.record_item.active_discount_source != price.source %]
+     <td>[% L.button_tag('kivi.Reclamation.update_discount_source(\'' _ FORM.item_id _ '\', \'' _ price.source _ '\', \'' _ price.source_description _ '\', \'' _ price.discount_as_percent _ '\', ' _ price_editable _ ')', LxERP.t8('Select')) %]</td>
+[%- ELSIF price_source.record_item.discount * 1 != price.discount * 1 %]
+     <td>[% L.button_tag('kivi.Reclamation.update_discount_source(\'' _ FORM.item_id _ '\', \'' _ price.source _ '\', \'' _ price.source_description _ '\', \'' _ price.discount_as_percent  _ '\', ' _ price_editable _ ')', LxERP.t8('Update Discount')) %]</td>
+[%- ELSE %]
+    <td><b>[% 'Selected' | $T8 %]</b></td>
+[% END %]
+     <td>[% price.source_description | html %]</td>
+     <td>[% price.discount_as_percent %] %</td>
+[% IF price.source == best_discount.source %]
+     <td align='center'>&#x2022;</td>
+[% ELSE %]
+     <td></td>
+[% END %]
+     <td>[% price.description | html %]</td>
+    </tr>
+   [%- END %]
+  </table>
diff --git a/templates/webpages/reclamation/tabs/basic_data/_row.html b/templates/webpages/reclamation/tabs/basic_data/_row.html
new file mode 100644
index 000000000..a9213a754
--- /dev/null
+++ b/templates/webpages/reclamation/tabs/basic_data/_row.html
@@ -0,0 +1,187 @@
+[%- USE T8 %]
+[%- USE HTML %]
+[%- USE LxERP %]
+[%- USE L %]
+[%- USE P %]
+[% # L.dump( ITEM ) %]
+
+<tbody class="row_entry listrow" data-position="[%- HTML.escape(ITEM.position) -%]"[%- IF MYCONFIG.show_form_details -%] data-expanded="1"[%- END -%]>
+  <tr>
+  [% L.hidden_tag("reclamation_items_ids[+]", ID) %]
+  [% L.hidden_tag("converted_from_record_item_type_refs[+]", ITEM.converted_from_record_item_type_ref) %]
+  [% L.hidden_tag("converted_from_record_item_ids[+]",       ITEM.converted_from_record_item_id) %]
+  [% L.hidden_tag("reclamation.reclamation_items[+].id", ITEM.id, id='item_' _ ID) %]
+  [% L.hidden_tag("reclamation.reclamation_items[].parts_id", ITEM.parts_id) %]
+    <td align="center">
+      [%- IF MYCONFIG.show_form_details %]
+        [% L.img_tag(src="image/collapse.svg",
+                     alt=LxERP.t8('Hide details'), title=LxERP.t8('Hide details'), class="expand") %]
+      [%- ELSE %]
+        [% L.img_tag(src="image/expand.svg",
+                     alt=LxERP.t8('Show details'), title=LxERP.t8('Show details'), class="expand") %]
+      [%- END %]
+    </td>
+    <td>
+      <div name="position" class="numeric">
+        [% HTML.escape(ITEM.position) %]
+      </div>
+    </td>
+    <td align="center">
+      <img src="image/updown.png" alt="[%- LxERP.t8('reclamation item') %]" class="dragdrop">
+    </td>
+    <td align="center">
+      [%- L.button_tag("kivi.Reclamation.delete_reclamation_item_row(this)",
+                       LxERP.t8("X"),
+                       confirm=LxERP.t8("Are you sure?")) %]
+    </td>
+    [%- IF SELF.show_update_button -%]
+    <td align="center">
+      [%- L.img_tag(src="image/rotate_cw.svg",
+                    alt=LxERP.t8('Update from master data'),
+                    title= LxERP.t8('Update from master data'),
+                    onclick="if (!confirm('" _ LxERP.t8("Are you sure to update this position from master data?") _ "')) return false; kivi.Reclamation.update_row_from_master_data(this);",
+                    id='update_from_master') %]
+    </td>
+    [%- END -%]
+    <td>
+      <div name="partnumber">
+        [%- P.link_tag(SELF.url_for(controller='Part', action='edit', 'part.id'=ITEM.part.id), ITEM.part.partnumber, target="_blank", title=LxERP.t8('Open in new window')) -%]
+      </div>
+    </td>
+    [%- IF SELF.search_cvpartnumber -%]
+    <td>
+      <div name="cvpartnumber">[% HTML.escape(ITEM.cvpartnumber) %]</div>
+    </td>
+    [%- END -%]
+    <td>
+      <div name="partclassification">[% ITEM.part.presenter.typeclass_abbreviation %]</div>
+    </td>
+    <td>
+      [% L.areainput_tag("reclamation.reclamation_items[].description",
+                     ITEM.description,
+                     size='40',
+                     style='width: 300px') %]
+      [%- L.hidden_tag("reclamation.reclamation_items[].longdescription", ITEM.longdescription) %]
+      [%- L.button_tag("kivi.Reclamation.show_longdescription_dialog(this)", LxERP.t8("L")) %]
+    </td>
+    <td>[% L.select_tag("reclamation.reclamation_items[].reason_id",
+                        SELF.reclamation.valid_reclamation_reasons,
+                        default=ITEM.reason_id,
+                        title_key = 'name',
+                        value_key = 'id',
+                        with_empty=1,) %]
+    </td>
+    <td>
+      [% L.areainput_tag("reclamation.reclamation_items[].reason_description_ext",
+                     ITEM.reason_description_ext,
+                     size='40',
+                     style='width: 150px') %]
+    </td>
+    <td>
+      [% L.areainput_tag("reclamation.reclamation_items[].reason_description_int",
+                     ITEM.reason_description_int,
+                     size='40',
+                     style='width: 150px') %]
+    </td>
+    <td nowrap>
+      [%- L.div_tag(LxERP.format_amount(ITEM.shipped_qty, 2, 0) _ ' ' _ ITEM.unit, name="shipped_qty", class="numeric") %]
+    </td>
+    <td nowrap>
+      [%- L.input_tag("reclamation.reclamation_items[].qty_as_number",
+                      ITEM.qty_as_number,
+                      size = 5,
+                      class="recalc reformat_number numeric") %]
+      [%- IF ITEM.part.formel -%]
+        [%- L.button_tag("kivi.Reclamation.show_calculate_qty_dialog(this)", LxERP.t8("*/")) %]
+        [%- L.hidden_tag("formula[+]", ITEM.part.formel) -%]
+      [%- END -%]
+    </td>
+    <td>
+      [%- L.select_tag("reclamation.reclamation_items[].price_factor_id",
+                       SELF.all_price_factors,
+                       default = ITEM.price_factor_id,
+                       title_key = 'description',
+                       with_empty = 1,
+                       class="recalc") %]
+    </td>
+    <td nowrap>
+      [%- L.select_tag("reclamation.reclamation_items[].unit",
+                      ITEM.part.available_units,
+                      default = ITEM.unit,
+                      title_key = 'name',
+                      value_key = 'name',
+                      class = 'unitselect') %]
+    </td>
+    <td>
+      [%- SET EDIT_PRICE_SOURCE = !(ITEM.is_linked_to_record) %]
+      <div name="editable_price_source" [%- IF !EDIT_PRICE_SOURCE %]style="display:none"[%- END %]>
+        [%- L.button_tag("kivi.Reclamation.price_chooser_item_row(this)",
+                         ITEM.active_price_source.source_description _ ' | ' _ ITEM.active_discount_source.source_description,
+                         name = "price_chooser_button") %]
+      </div>
+      <div name="not_editable_price_source" [%- IF EDIT_PRICE_SOURCE %]style="display:none"[%- END %]>
+        [%- L.div_tag(ITEM.active_price_source.description _ ' | ' _ ITEM.active_discount_source.source_description, style="white-space:nowrap;") %]
+      </div>
+    </td>
+    [% SET RIGHT_TO_EDIT_PRICES = 0 %]
+    [% IF (SELF.type == "sales_reclamation") %]
+      [% SET RIGHT_TO_EDIT_PRICES = AUTH.assert('sales_edit_prices', 1) %]
+    [% END %]
+    [% IF (SELF.type == "purchase_reclamation") %]
+      [% SET RIGHT_TO_EDIT_PRICES = AUTH.assert('purchase_edit_prices', 1) %]
+    [% END %]
+    <td>
+      [%- L.hidden_tag("reclamation.reclamation_items[].active_price_source", ITEM.active_price_source.source) %]
+      [%- SET EDIT_PRICE = (RIGHT_TO_EDIT_PRICES && ITEM.active_price_source.source == '' && !ITEM.is_linked_to_record) %]
+      <div name="editable_price" [%- IF !EDIT_PRICE %]style="display:none"[%- END %] class="numeric">
+        [%- L.input_tag("reclamation.reclamation_items[].sellprice_as_number",
+                        ITEM.sellprice_as_number,
+                        size = 10,
+                        disabled=(EDIT_PRICE? '' : 1),
+                        class="recalc reformat_number numeric") %]
+      </div>
+      <div name="not_editable_price" [%- IF EDIT_PRICE %]style="display:none"[%- END %]>
+        [%- L.div_tag(ITEM.sellprice_as_number, name="sellprice_text", class="numeric") %]
+        [%- L.hidden_tag("reclamation.reclamation_items[].sellprice_as_number",
+                         ITEM.sellprice_as_number,
+                         disabled=(EDIT_PRICE? 1 : '')) %]
+      </div>
+    </td>
+    <td>
+      [%- L.hidden_tag("reclamation.reclamation_items[].active_discount_source", ITEM.active_discount_source.source) %]
+      [%- SET EDIT_DISCOUNT = (RIGHT_TO_EDIT_PRICES && ITEM.active_discount_source.source == '' && !ITEM.is_linked_to_record) %]
+      <div name="editable_discount" [%- IF !EDIT_DISCOUNT %]style="display:none"[%- END %] class="numeric">
+        [%- L.input_tag("reclamation.reclamation_items[].discount_as_percent",
+                        ITEM.discount_as_percent,
+                        size = 5,
+                        disabled=(EDIT_DISCOUNT? '' : 1),
+                        class="recalc reformat_number numeric") %]
+      </div>
+      <div name="not_editable_discount" [%- IF EDIT_DISCOUNT %]style="display:none"[%- END %]>
+        [%- L.div_tag(ITEM.discount_as_percent, name="discount_text", class="numeric") %]
+        [%- L.hidden_tag("reclamation.reclamation_items[].discount_as_percent",
+                         ITEM.discount_as_percent,
+                         disabled=(EDIT_DISCOUNT? 1 : '')) %]
+      </div>
+    </td>
+    <td align="right">
+      [%- L.div_tag(LxERP.format_amount(ITEM.linetotal, 2, 0), name="linetotal") %]
+    </td>
+
+  </tr>
+
+  <tr [%- IF !MYCONFIG.show_form_details -%]style="display:none"[%- END -%]>
+    <td colspan="100%">
+      [%- IF MYCONFIG.show_form_details || ITEM.render_second_row %]
+        <div name="second_row" data-loaded="1">
+          [%- PROCESS reclamation/tabs/basic_data/_second_row.html ITEM=ITEM TYPE=SELF.type %]
+        </div>
+      [%- ELSE %]
+        <div name="second_row" id="second_row_[% ID %]">
+          [%- LxERP.t8("Loading...") %]
+        </div>
+      [%- END %]
+    </td>
+  </tr>
+
+</tbody>
diff --git a/templates/webpages/reclamation/tabs/basic_data/_second_row.html b/templates/webpages/reclamation/tabs/basic_data/_second_row.html
new file mode 100644
index 000000000..728fd7152
--- /dev/null
+++ b/templates/webpages/reclamation/tabs/basic_data/_second_row.html
@@ -0,0 +1,49 @@
+[%- USE T8 %]
+[%- USE HTML %]
+[%- USE LxERP %]
+[%- USE L %]
+[%- USE P %]
+
+<table>
+  <tr><td colspan="100%">
+      <b>[%- 'Serial No.' | $T8 %]</b>&nbsp;
+      [%- L.input_tag("reclamation.reclamation_items[].serialnumber", ITEM.serialnumber, size = 15) %]&nbsp;
+    <b>[%- 'Project' | $T8 %]</b>&nbsp;
+    [% P.project.picker("reclamation.reclamation_items[].project_id", ITEM.project_id, size = 15) %]&nbsp;
+      <b>[%- 'Reqdate' | $T8 %]</b>&nbsp;
+      [% L.date_tag("reclamation.reclamation_items[].reqdate_as_date", ITEM.reqdate_as_date) %]&nbsp;
+    [%- IF (TYPE == "sales_reclamation") %]
+      <b>[%- 'LP' | $T8 %]</b>&nbsp;
+      [%- LxERP.format_amount(ITEM.part.listprice, 2, 0) %]&nbsp;
+      <b>[%- 'EK' | $T8 %]</b>&nbsp;
+        [%- L.input_tag("reclamation.reclamation_items[].lastcost_as_number",
+                        ITEM.lastcost_as_number,
+                        size = 5,
+                        class="recalc reformat_number numeric") %]&nbsp;
+    [%- END %]
+    <b>[%- 'On Hand' | $T8 %]</b>&nbsp;
+      <span[%- IF ITEM.part.onhand < ITEM.part.rop -%] class="numeric plus0"[%- END -%]>
+        [%- ITEM.part.onhand_as_number -%]&nbsp;[%- ITEM.part.unit -%]
+      </span>&nbsp;
+  </td></tr>
+
+  <tr>
+    [%- SET n = 0 %]
+    [%- FOREACH var = ITEM.cvars_by_config %]
+      [%- NEXT UNLESS (var.config.processed_flags.editable && ITEM.part.cvar_by_name(var.config.name).is_valid) %]
+      [%- SET n = n + 1 %]
+    <th>
+      [% var.config.description %]
+    </th>
+    <td>
+      [% L.hidden_tag('reclamation.reclamation_items[].custom_variables[+].config_id', var.config.id) %]
+      [% L.hidden_tag('reclamation.reclamation_items[].custom_variables[].id', var.id) %]
+      [% L.hidden_tag('reclamation.reclamation_items[].custom_variables[].sub_module', var.sub_module) %]
+      [% INCLUDE 'common/render_cvar_input.html' var_name='reclamation.reclamation_items[].custom_variables[].unparsed_value' %]
+    </td>
+      [%- IF (n % (MYCONFIG.form_cvars_nr_cols || 3)) == 0 %]
+        </tr><tr>
+      [%- END %]
+    [%- END %]
+  </tr>
+</table>
diff --git a/templates/webpages/reclamation/tabs/basic_data/_tax_row.html b/templates/webpages/reclamation/tabs/basic_data/_tax_row.html
new file mode 100644
index 000000000..aa09a3a86
--- /dev/null
+++ b/templates/webpages/reclamation/tabs/basic_data/_tax_row.html
@@ -0,0 +1,15 @@
+[%- USE T8 %]
+[%- USE HTML %]
+[%- USE LxERP %]
+[%- USE L %]
+
+<tr class="tax_row">
+  <th align="right">[%- IF TAXINCLUDED %][%- 'Including' | $T8 %]&nbsp;[%- END %][%- TAX.tax.taxdescription %] [% TAX.tax.rate_as_percent %]%</th>
+  <td align="right">[%- LxERP.format_amount(TAX.amount, 2, 0) %]</td>
+</tr>
+[%- IF TAXINCLUDED %]
+<tr class="tax_row">
+  <th align="right">[%- 'Net amount' | $T8 %]</th>
+  <td align="right">[%- LxERP.format_amount(TAX.netamount, 2, 0) %]</td>
+</tr>
+[%- END%]
diff --git a/templates/webpages/reclamation_reason/_sort_list_row.html b/templates/webpages/reclamation_reason/_sort_list_row.html
new file mode 100644
index 000000000..00499cec8
--- /dev/null
+++ b/templates/webpages/reclamation_reason/_sort_list_row.html
@@ -0,0 +1,9 @@
+[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE T8 -%][% USE P %]
+[% FOREACH reason = RECLAMATION_REASONS %]
+<tr class="listrow" id="reclamation_reason_id_[% reason.id %]">
+  <td align="center" class="dragdrop"><img src="image/updown.png" alt="[%- LxERP.t8('reorder item') %]"></td>
+  <td><a href="[% SELF.url_for(action='edit', id=reason.id) %]">[% HTML.escape(reason.name) %]</a></td>
+  <td>[% reason.description | $T8 %]</td>
+  <td>[% reason.valid_for | $T8 %]</td>
+</tr>
+[% END %]
diff --git a/templates/webpages/reclamation_reason/form.html b/templates/webpages/reclamation_reason/form.html
new file mode 100644
index 000000000..dc5fe0a95
--- /dev/null
+++ b/templates/webpages/reclamation_reason/form.html
@@ -0,0 +1,30 @@
+[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE P -%][%- USE T8 -%]
+[% INCLUDE 'common/flash.html' %]
+
+<h1>[% HTML.escape(title) %]</h1>
+<div style="padding-left:2em">
+[% SET style="width: 400px" %]
+
+<form action="controller.pl" method="post" id="form">
+[%- L.hidden_tag("id", SELF.reclamation_reason.id) %]
+
+<table>
+  <tr>
+    <th align="right">[% 'Name' | $T8 %]</th>
+    <td>[%- L.input_tag("reclamation_reason.name", SELF.reclamation_reason.name, "data-validate"="required", "data-title"=LxERP.t8("Name")) %]</td>
+  </tr>
+  <tr>
+    <th align="right">[% 'Description' | $T8 %]</th>
+    <td>[%- L.textarea_tag("reclamation_reason.description", SELF.reclamation_reason.description, "data-validate"="required", cols = 50 rows = 2, "data-title"=LxERP.t8("Description")) %]</td>
+  </tr>
+  <tr>
+    <th align="right">[% 'Valid for Sales' | $T8 %]</th>
+     <td align="left">[% L.checkbox_tag("reclamation_reason.valid_for_sales", checked=reclamation_reason.valid_for_sales, for_submit=1) %]</td>
+  </tr>
+  <tr>
+    <th align="right">[% 'Valid for Purchase' | $T8 %]</th>
+     <td align="left">[% L.checkbox_tag("reclamation_reason.valid_for_purchase", checked=reclamation_reason.valid_for_purchase, for_submit=1) %]</td>
+  </tr>
+</table>
+</form>
+</div>
diff --git a/templates/webpages/reclamation_reason/list.html b/templates/webpages/reclamation_reason/list.html
new file mode 100644
index 000000000..859c474a6
--- /dev/null
+++ b/templates/webpages/reclamation_reason/list.html
@@ -0,0 +1,28 @@
+[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE T8 -%]
+[%- INCLUDE 'common/flash.html' %]
+
+<h1>[% title %]</h1>
+
+<p>
+ <table id="partsgroup_list">
+  <thead>
+   <tr class="listheading">
+    <th>[% 'Reclamation Reason'      | $T8 %]</th>
+    <th>[% 'Description' | $T8 %]</th>
+    <th>[% 'Valid for Sales' | $T8 %]</th>
+    <th>[% 'Valid for Purchase' | $T8 %]</th>
+   </tr>
+  </thead>
+
+  <tbody>
+    [%- FOREACH reason = RECLAMATION_REASONS %]
+    <tr class="listrow" id="reason_id_[% reason.id %]">
+    <td><a href="[% SELF.url_for(action='edit', id=reason.id) %]">[% HTML.escape(reason.name) %]
+[% # reason.level %]</a></td>
+    <td>[% reason.description | html %]</td>
+    <td>[% (reason.valid_for_sales? 'Yes' : 'No') | $T8 %]</td>
+    <td>[% (reason.valid_for_purchase? 'Yes' : 'No') | $T8 %]</td>
+   [%- END %]
+  </tbody>
+ </table>
+</p>
diff --git a/templates/webpages/reclamation_reason/sort_list.html b/templates/webpages/reclamation_reason/sort_list.html
new file mode 100644
index 000000000..9f73e73fa
--- /dev/null
+++ b/templates/webpages/reclamation_reason/sort_list.html
@@ -0,0 +1,24 @@
+[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE P -%][%- USE T8 -%]
+[% INCLUDE 'common/flash.html' %]
+
+<h1>[% HTML.escape(title) %]</h1>
+[% SET style="width: 400px" %]
+
+<form method="post" action="controller.pl" id="form">
+<table id="reclamation_reasons">
+ <thead>
+  <tr>
+    <th align="center"><img src="image/updown.png" alt="[%- LxERP.t8('reorder item') %]"></th>
+    <th align="left">[% 'Reclamation Reason' | $T8 %]</th>
+    <th align="left">[% 'Description' | $T8 %]</th>
+    <th align="left">[% 'Valid for'    | $T8 %]</th>
+  </tr>
+ </thead>
+
+ <tbody id="table_body">
+  [% PROCESS 'reclamation_reason/_sort_list_row.html', RECLAMATION_REASONS = RECLAMATION_REASONS %]
+  </tbody>
+</table>
+</form>
+
+[% L.sortable_element('#table_body', url=SELF.url_for(action='reorder'), with='reclamation_reason_id') %]
