+ $::request->{layout}->add_javascripts("$_.js") for qw (kivi.CustomerVendor kivi.File kivi.CustomerVendorTurnover ckeditor/ckeditor ckeditor/adapters/jquery);
+
+ $self->_setup_form_action_bar;
+}
+
+sub _setup_form_action_bar {
+ my ($self) = @_;
+
+ my $no_rights = $self->user_has_edit_rights ? undef
+ : $self->{cv}->is_customer ? t8("You don't have the rights to edit this customer.")
+ : t8("You don't have the rights to edit this vendor.");
+
+ for my $bar ($::request->layout->get('actionbar')) {
+ $bar->add(
+ combobox => [
+ action => [
+ t8('Save'),
+ submit => [ '#form', { action => "CustomerVendor/save" } ],
+ checks => [ 'check_taxzone_and_ustid' ],
+ accesskey => 'enter',
+ disabled => $no_rights,
+ ],
+ action => [
+ t8('Save and Close'),
+ submit => [ '#form', { action => "CustomerVendor/save_and_close" } ],
+ checks => [ 'check_taxzone_and_ustid' ],
+ disabled => $no_rights,
+ ],
+ ], # end of combobox "Save"
+
+ combobox => [
+ action => [ t8('Workflow') ],
+ (action => [
+ t8('Save and AP Transaction'),
+ submit => [ '#form', { action => "CustomerVendor/save_and_ap_transaction" } ],
+ checks => [ 'check_taxzone_and_ustid' ],
+ disabled => $no_rights,
+ ]) x !!$self->is_vendor,
+ (action => [
+ t8('Save and AR Transaction'),
+ submit => [ '#form', { action => "CustomerVendor/save_and_ar_transaction" } ],
+ checks => [ 'check_taxzone_and_ustid' ],
+ disabled => $no_rights,
+ ]) x !$self->is_vendor,
+ action => [
+ t8('Save and Invoice'),
+ submit => [ '#form', { action => "CustomerVendor/save_and_invoice" } ],
+ checks => [ 'check_taxzone_and_ustid' ],
+ disabled => $no_rights,
+ ],
+ action => [
+ t8('Save and Order'),
+ submit => [ '#form', { action => "CustomerVendor/save_and_order" } ],
+ checks => [ 'check_taxzone_and_ustid' ],
+ disabled => $no_rights,
+ ],
+ (action => [
+ t8('Save and RFQ'),
+ submit => [ '#form', { action => "CustomerVendor/save_and_rfq" } ],
+ checks => [ 'check_taxzone_and_ustid' ],
+ disabled => $no_rights,
+ ]) x !!$self->is_vendor,
+ (action => [
+ t8('Save and Quotation'),
+ submit => [ '#form', { action => "CustomerVendor/save_and_quotation" } ],
+ checks => [ 'check_taxzone_and_ustid' ],
+ disabled => $no_rights,
+ ]) x !$self->is_vendor,
+ ], # end of combobox "Workflow"
+
+ action => [
+ t8('Delete'),
+ submit => [ '#form', { action => "CustomerVendor/delete" } ],
+ confirm => t8('Do you really want to delete this object?'),
+ disabled => !$self->{cv}->id ? t8('This object has not been saved yet.')
+ : !$self->is_orphaned ? t8('This object has already been used.')
+ : $no_rights,
+ ],
+
+ 'separator',
+
+ action => [
+ t8('History'),
+ call => [ 'kivi.CustomerVendor.showHistoryWindow', $self->{cv}->id ],
+ disabled => !$self->{cv}->id ? t8('This object has not been saved yet.') : undef,
+ ],
+ );
+ }
+}
+
+sub _prepare_cvar_configs_for_ajaj {
+ my ($self, $cvars) = @_;
+
+ return {
+ map {
+ my $cvar = $_;
+ my $result = { type => $cvar->config->type };
+
+ if ($cvar->config->type eq 'number') {
+ $result->{value} = $::form->format_amount(\%::myconfig, $cvar->value, -2);
+
+ } elsif ($result->{type} eq 'date') {
+ $result->{value} = $cvar->value ? $cvar->value->to_kivitendo : undef;
+
+ } elsif ($result->{type} =~ m{customer|vendor|part}) {
+ my $object = $cvar->value;
+ my $method = $result->{type} eq 'part' ? 'description' : 'name';
+
+ $result->{id} = int($cvar->number_value) || undef;
+ $result->{value} = $object ? $object->$method // '' : '';
+
+ } else {
+ $result->{value} = $cvar->value;
+ }
+
+ ( $cvar->config->name => $result )
+
+ } grep { $_->is_valid } @{ $cvars }
+ };