Revision d0a22ba8
Von Moritz Bunkus vor mehr als 8 Jahren hinzugefügt
SL/Controller/CustomerVendor.pm | ||
---|---|---|
565 | 565 |
) |
566 | 566 |
}; |
567 | 567 |
|
568 |
$data->{contact_cvars} = { |
|
569 |
map { |
|
570 |
my $cvar = $_; |
|
571 |
my $result = { type => $cvar->config->type }; |
|
572 |
|
|
573 |
if ($cvar->config->type eq 'number') { |
|
574 |
$result->{value} = $::form->format_amount(\%::myconfig, $cvar->value, -2); |
|
575 |
|
|
576 |
} elsif ($result->{type} =~ m{customer|vendor|part}) { |
|
577 |
my $object = $cvar->value; |
|
578 |
my $method = $result->{type} eq 'part' ? 'description' : 'name'; |
|
579 |
|
|
580 |
$result->{id} = int($cvar->number_value) || undef; |
|
581 |
$result->{value} = $object ? $object->$method // '' : ''; |
|
582 |
|
|
583 |
} else { |
|
584 |
$result->{value} = $cvar->value; |
|
585 |
} |
|
586 |
|
|
587 |
( $cvar->config->name => $result ) |
|
588 |
|
|
589 |
} grep { $_->is_valid } @{ $self->{contact}->cvars_by_config } |
|
590 |
}; |
|
568 |
$data->{contact_cvars} = $self->_prepare_cvar_configs_for_ajaj($self->{contact}->cvars_by_config); |
|
591 | 569 |
|
592 | 570 |
$self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 }); |
593 | 571 |
} |
... | ... | |
706 | 684 |
return $self->{_is_orphaned} = !$dummy; |
707 | 685 |
} |
708 | 686 |
|
687 |
sub _copy_form_to_cvars { |
|
688 |
my ($self, %params) = @_; |
|
689 |
|
|
690 |
foreach my $cvar (@{ $params{target}->cvars_by_config }) { |
|
691 |
my $value = $params{source}->{$cvar->config->name}; |
|
692 |
$value = $::form->parse_amount(\%::myconfig, $value) if $cvar->config->type eq 'number'; |
|
693 |
|
|
694 |
$cvar->value($value); |
|
695 |
} |
|
696 |
} |
|
697 |
|
|
709 | 698 |
sub _instantiate_args { |
710 | 699 |
my ($self) = @_; |
711 | 700 |
|
... | ... | |
728 | 717 |
|
729 | 718 |
$self->{cv}->hourly_rate($::instance_conf->get_customer_hourly_rate) if $self->is_customer && !$self->{cv}->hourly_rate; |
730 | 719 |
|
731 |
foreach my $cvar (@{$self->{cv}->cvars_by_config()}) { |
|
732 |
my $value = $::form->{cv_cvars}->{$cvar->config->name}; |
|
733 |
|
|
734 |
if ( $cvar->config->type eq 'number' ) { |
|
735 |
$value = $::form->parse_amount(\%::myconfig, $value); |
|
736 |
} |
|
737 |
|
|
738 |
$cvar->value($value); |
|
739 |
} |
|
740 |
|
|
741 | 720 |
if ( $::form->{note}->{id} ) { |
742 | 721 |
$self->{note} = SL::DB::Note->new(id => $::form->{note}->{id})->load(); |
743 | 722 |
$self->{note_followup} = $self->{note}->follow_up; |
... | ... | |
774 | 753 |
} |
775 | 754 |
$self->{contact}->assign_attributes(%{$::form->{contact}}); |
776 | 755 |
|
777 |
foreach my $cvar (@{$self->{contact}->cvars_by_config()}) { |
|
778 |
my $value = $::form->{contact_cvars}->{$cvar->config->name}; |
|
779 |
|
|
780 |
if ( $cvar->config->type eq 'number' ) { |
|
781 |
$value = $::form->parse_amount(\%::myconfig, $value); |
|
782 |
} |
|
783 |
|
|
784 |
$cvar->value($value); |
|
785 |
} |
|
756 |
$self->_copy_form_to_cvars(target => $self->{cv}, source => $::form->{cv_cvars}); |
|
757 |
$self->_copy_form_to_cvars(target => $self->{contact}, source => $::form->{contact_cvars}); |
|
786 | 758 |
} |
787 | 759 |
|
788 | 760 |
sub _load_customer_vendor { |
... | ... | |
954 | 926 |
$::request->{layout}->add_javascripts('kivi.CustomerVendor.js'); |
955 | 927 |
} |
956 | 928 |
|
929 |
sub _prepare_cvar_configs_for_ajaj { |
|
930 |
my ($self, $cvars) = @_; |
|
931 |
|
|
932 |
return { |
|
933 |
map { |
|
934 |
my $cvar = $_; |
|
935 |
my $result = { type => $cvar->config->type }; |
|
936 |
|
|
937 |
if ($cvar->config->type eq 'number') { |
|
938 |
$result->{value} = $::form->format_amount(\%::myconfig, $cvar->value, -2); |
|
939 |
|
|
940 |
} elsif ($result->{type} eq 'date') { |
|
941 |
$result->{value} = $cvar->value ? $cvar->value->to_kivitendo : undef; |
|
942 |
|
|
943 |
} elsif ($result->{type} =~ m{customer|vendor|part}) { |
|
944 |
my $object = $cvar->value; |
|
945 |
my $method = $result->{type} eq 'part' ? 'description' : 'name'; |
|
946 |
|
|
947 |
$result->{id} = int($cvar->number_value) || undef; |
|
948 |
$result->{value} = $object ? $object->$method // '' : ''; |
|
949 |
|
|
950 |
} else { |
|
951 |
$result->{value} = $cvar->value; |
|
952 |
} |
|
953 |
|
|
954 |
( $cvar->config->name => $result ) |
|
955 |
|
|
956 |
} grep { $_->is_valid } @{ $cvars } |
|
957 |
}; |
|
958 |
} |
|
959 |
|
|
957 | 960 |
sub normalize_name { |
958 | 961 |
my ($self) = @_; |
959 | 962 |
|
Auch abrufbar als: Unified diff
CustomerVendor: CVar-Aufbereitungs- und -Speicher-Code in eigene Subs ausgelagert