Revision 5e2c22ef
Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt
SL/Controller/Reclamation.pm | ||
---|---|---|
|
||
$self->render(
|
||
'reclamation/form',
|
||
title => $self->get_title_for('add'),
|
||
title => $self->type_data->text('add'),
|
||
%{$self->{template_args}},
|
||
);
|
||
}
|
||
... | ... | |
}
|
||
|
||
my $order = SL::DB::Order->new(id => $::form->{from_id})->load;
|
||
my $target_type = $order->is_sales ? SALES_RECLAMATION_TYPE()
|
||
: PURCHASE_RECLAMATION_TYPE();
|
||
my $reclamation = SL::Model::Record->new_from_workflow($order, $target_type);
|
||
my $reclamation = SL::Model::Record->new_from_workflow($order, $self->type);
|
||
|
||
$self->reclamation($reclamation);
|
||
|
||
... | ... | |
|
||
$self->render(
|
||
'reclamation/form',
|
||
title => $self->get_title_for('add'),
|
||
title => $self->type_data->text('add'),
|
||
%{$self->{template_args}},
|
||
);
|
||
}
|
||
... | ... | |
}
|
||
|
||
my $delivery_order = SL::DB::DeliveryOrder->new(id => $::form->{from_id})->load;
|
||
my $target_type = $delivery_order->is_sales ? SALES_RECLAMATION_TYPE()
|
||
: PURCHASE_RECLAMATION_TYPE();
|
||
my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $target_type);
|
||
my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $self->type);
|
||
|
||
$self->reclamation($reclamation);
|
||
|
||
... | ... | |
|
||
$self->render(
|
||
'reclamation/form',
|
||
title => $self->get_title_for('add'),
|
||
title => $self->type_data->text('add'),
|
||
%{$self->{template_args}},
|
||
);
|
||
}
|
||
... | ... | |
}
|
||
|
||
my $invoice = SL::DB::Invoice->new(id => $::form->{from_id})->load;
|
||
my $target_type = SALES_RECLAMATION_TYPE();
|
||
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $target_type);
|
||
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $self->type);
|
||
|
||
$self->reclamation($reclamation);
|
||
|
||
... | ... | |
|
||
$self->render(
|
||
'reclamation/form',
|
||
title => $self->get_title_for('add'),
|
||
title => $self->type_data->text('add'),
|
||
%{$self->{template_args}},
|
||
);
|
||
}
|
||
... | ... | |
require SL::DB::PurchaseInvoice;
|
||
my $invoice = SL::DB::PurchaseInvoice->new(id => $::form->{from_id})->load;
|
||
$invoice->{type} = $invoice->invoice_type; #can't add type → invoice_type in SL/DB/PurchaseInvoice
|
||
my $target_type = PURCHASE_RECLAMATION_TYPE();
|
||
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $target_type);
|
||
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $self->type);
|
||
|
||
$self->reclamation($reclamation);
|
||
|
||
... | ... | |
|
||
$self->render(
|
||
'reclamation/form',
|
||
title => $self->get_title_for('add'),
|
||
title => $self->type_data->text('add'),
|
||
%{$self->{template_args}},
|
||
);
|
||
}
|
||
... | ... | |
|
||
$self->render(
|
||
'reclamation/form',
|
||
title => $self->get_title_for('edit'),
|
||
title => $self->type_data->text('edit'),
|
||
%{$self->{template_args}},
|
||
);
|
||
}
|
||
... | ... | |
|
||
|
||
SL::Model::Record->delete($self->reclamation);
|
||
flash_later('info', t8('The reclamation has been deleted'));
|
||
flash_later('info', $self->type_data->text('delete'));
|
||
|
||
my @redirect_params = (
|
||
action => 'add',
|
||
... | ... | |
|
||
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);
|
||
$self->type_data->properties('is_customer') ?
|
||
t8('Cannot send E-mail without customer given')
|
||
: t8('Cannot send E-mail without vendor given'))
|
||
->render($self);
|
||
}
|
||
|
||
my $form = Form->new;
|
||
... | ... | |
email_form => $email_form,
|
||
show_bcc => $::auth->assert('email_bcc', 'may fail'),
|
||
FILES => \%files,
|
||
is_customer => $self->cv eq 'customer',
|
||
is_customer => $self->type_data->properties('is_customer'),
|
||
ALL_EMPLOYEES => $self->{all_employees},
|
||
);
|
||
|
||
... | ... | |
|
||
$self->recalc();
|
||
|
||
my $cv_method = $self->cv;
|
||
|
||
if ( $self->reclamation->customervendor->contacts
|
||
&& scalar @{ $self->reclamation->customervendor->contacts } > 0) {
|
||
$self->js->show('#cp_row');
|
||
... | ... | |
sub action_show_customer_vendor_details_dialog {
|
||
my ($self) = @_;
|
||
|
||
my $is_sales = ($self->cv eq 'customer');
|
||
my $is_customer = ($self->type_data->properties('is_customer'));
|
||
my $cv;
|
||
if ($is_sales) {
|
||
if ($is_customer) {
|
||
$cv = SL::DB::Customer->new(id => $::form->{cv_id})->load;
|
||
} else {
|
||
$cv = SL::DB::Vendor->new(id => $::form->{cv_id})->load;
|
||
... | ... | |
$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;
|
||
$details{pricegroup} = $cv->pricegroup->pricegroup if !$is_customer && $cv->pricegroup;
|
||
|
||
foreach my $entry (@{ $cv->shipto }) {
|
||
push @{ $details{SHIPTO} }, { map { $_ => $entry->$_ } @{$entry->meta->columns} };
|
||
... | ... | |
}
|
||
|
||
$_[0]->render('common/show_vc_details', { layout => 0 },
|
||
is_customer => !$is_sales,
|
||
is_customer => $is_customer,
|
||
%details);
|
||
}
|
||
|
||
... | ... | |
|
||
$self->render(
|
||
'reclamation/form',
|
||
title => $self->get_title_for('edit'),
|
||
title => $self->type_data->text('edit'),
|
||
%{$self->{template_args}}
|
||
);
|
||
}
|
||
... | ... | |
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;
|
||
$self->type_data->properties('customervendor');
|
||
}
|
||
|
||
sub init_search_cvpartnumber {
|
||
... | ... | |
|
||
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';
|
||
if ($self->type_data->properties('is_customer')) {
|
||
$search_cvpartnumber = !!$user_prefs->get_sales_search_customer_partnumber()
|
||
} else {
|
||
$search_cvpartnumber = !!$user_prefs->get_purchase_search_makemodel();
|
||
}
|
||
|
||
return $search_cvpartnumber;
|
||
}
|
||
... | ... | |
language => t8('Language'),
|
||
department => t8('Department'),
|
||
globalproject => t8('Project Number'),
|
||
cv_record_number => ($self->type eq SALES_RECLAMATION_TYPE() ? t8('Customer Record Number') : t8('Vendor Record Number')),
|
||
cv_record_number => ($self->type_data->properties('is_customer') ? t8('Customer Record Number') : t8('Vendor Record Number')),
|
||
transaction_description => t8('Description'),
|
||
notes => t8('Notes'),
|
||
intnotes => t8('Internal Notes'),
|
||
... | ... | |
|
||
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 ]) } ];
|
||
return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(where => $self->type_data->part_classification_query()) } ];
|
||
}
|
||
|
||
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);
|
||
$::auth->assert($self->type_data->rights('edit'));
|
||
}
|
||
|
||
# build the selection box for contacts
|
||
... | ... | |
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});
|
||
}
|
||
}
|
||
|
||
my $form_reclamation_items = delete $::form->{reclamation}->{reclamation_items};
|
||
... | ... | |
? SL::DB::Manager::ReclamationItem->get_all(where => [id => $self->item_ids_to_delete])
|
||
: undef;
|
||
|
||
SL::Model::Record->save($self->order,
|
||
SL::Model::Record->save($self->reclamation,
|
||
with_validity_token => { scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE(), token => $::form->{form_validity_token} },
|
||
delete_custom_shipto => $self->is_custom_shipto_to_delete || $self->reclamation->custom_shipto->is_empty,
|
||
items_to_delete => $items_to_delete,
|
||
... | ... | |
|
||
# check for direct delivery
|
||
# copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
|
||
if ($::form->{type} eq PURCHASE_RECLAMATION_TYPE()) {
|
||
if (!$self->type_data->properties('is_customer')) {
|
||
if ($::form->{use_shipto}) {
|
||
my $custom_shipto = $source_reclamation->shipto->clone('SL::DB::Reclamation');
|
||
$self->reclamation->custom_shipto($custom_shipto) if $custom_shipto;
|
||
... | ... | |
|
||
$self->render(
|
||
'reclamation/form',
|
||
title => $self->get_title_for('add'),
|
||
title => $self->type_data->text('add'),
|
||
%{$self->{template_args}}
|
||
);
|
||
}
|
||
... | ... | |
sub => sub { $_[0]->closed ? t8('Yes') : t8('No') },
|
||
},
|
||
);
|
||
if ($self->type eq SALES_RECLAMATION_TYPE()) {
|
||
if ($self->type_data->properties('is_customer')) {
|
||
$column_defs{customer} = ({
|
||
raw_data => sub { $_[0]->customervendor->presenter->customer(display => 'table-cell', callback => $callback) },
|
||
sub => sub { $_[0]->customervendor->name },
|
||
... | ... | |
},
|
||
sub => sub { $_[0]->contact ? $_[0]->contact->cp_name : '' },
|
||
});
|
||
} elsif ($self->type eq PURCHASE_RECLAMATION_TYPE()) {
|
||
} else {
|
||
$column_defs{vendor} = ({
|
||
raw_data => sub { $_[0]->customervendor->presenter->vendor(display => 'table-cell', callback => $callback) },
|
||
sub => sub { $_[0]->customervendor->name },
|
||
... | ... | |
{ output => 0 },
|
||
models => $self->models
|
||
),
|
||
title => $self->type eq SALES_RECLAMATION_TYPE() ? t8('Sales Reclamations') : t8('Purchase Reclamations'),
|
||
title => $self->type_data->text('list'),
|
||
allow_pdf_export => 1,
|
||
allow_csv_export => 1,
|
||
);
|
||
... | ... | |
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 => [
|
||
... | ... | |
$::instance_conf->get_reclamation_warn_duplicate_parts,
|
||
$::instance_conf->get_reclamation_warn_no_reqdate,
|
||
],
|
||
only_if => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
|
||
only_if => $self->type_data->show_menu('save_and_sales_reclamation'),
|
||
],
|
||
action => [
|
||
t8('Save and Purchase Reclamation'),
|
||
call => [ 'kivi.Reclamation.purchase_reclamation_check_for_direct_delivery' ],
|
||
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
|
||
only_if => $self->type_data->show_menu('save_and_purchase_reclamation'),
|
||
],
|
||
action => [
|
||
t8('Save and Order'),
|
||
... | ... | |
$::instance_conf->get_reclamation_warn_duplicate_parts,
|
||
$::instance_conf->get_reclamation_warn_no_reqdate,
|
||
],
|
||
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
|
||
only_if => $self->type_data->show_menu('save_and_rma_delivery_order'),
|
||
],
|
||
action => [
|
||
t8('Save and Supplier Delivery Order'),
|
||
... | ... | |
$::instance_conf->get_reclamation_warn_duplicate_parts,
|
||
$::instance_conf->get_reclamation_warn_no_reqdate,
|
||
],
|
||
only_if => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
|
||
only_if => $self->type_data->show_menu('save_and_supplier_delivery_order'),
|
||
],
|
||
action => [
|
||
t8('Save and Credit Note'),
|
||
... | ... | |
$::instance_conf->get_reclamation_warn_duplicate_parts,
|
||
$::instance_conf->get_reclamation_warn_no_reqdate,
|
||
],
|
||
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
|
||
only_if => $self->type_data->show_menu('save_and_credit_note'),
|
||
],
|
||
], # end of combobox "Workflow"
|
||
|
||
... | ... | |
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,
|
||
only_if => $self->type_data->show_menu('delete'),
|
||
],
|
||
|
||
combobox => [
|
||
... | ... | |
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') {
|
||
if (!$self->reclamation->is_sales) {
|
||
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') {
|
||
} elsif ($self->reclamation->is_sales) {
|
||
my @cps = grep { $_->customer_id eq $self->reclamation->customervendor->id } @{$item->part->customerprices};
|
||
$item->{cvpartnumber} = $cps[0]->customer_partnumber if scalar @cps;
|
||
}
|
Auch abrufbar als: Unified diff
Controller::Reclamation: nutze TypeData