X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FRequirementSpecOrder.pm;h=f0f20d49675b28377274127fa46b09fc65c61eb5;hb=aaa2cd9291719d6a8f327606fc5aeeeb172b7ecb;hp=fc0fbea41924dd4ef822d205bc35c3b4c0b2626d;hpb=815cf361bd5ae8ae0e7002423be5d307993f69f5;p=kivitendo-erp.git diff --git a/SL/Controller/RequirementSpecOrder.pm b/SL/Controller/RequirementSpecOrder.pm index fc0fbea41..f0f20d496 100644 --- a/SL/Controller/RequirementSpecOrder.pm +++ b/SL/Controller/RequirementSpecOrder.pm @@ -17,7 +17,8 @@ use SL::DB::RequirementSpecOrder; use SL::Helper::Flash; use SL::Locale::String; -use constant TAB_ID => 'ui-tabs-4'; +use constant LIST_SELECTOR => '#quotations_and_orders'; +use constant FORMS_SELECTOR => '#quotations_and_orders_article_assignment,#quotations_and_orders_new,#quotations_and_orders_update'; use Rose::Object::MakeMethods::Generic ( @@ -44,8 +45,9 @@ sub action_new { return $self->js->flash('error', t8('This function requires the presence of articles with a time-based unit such as "h" or "min".'))->render($self); } - my $html = $self->render('requirement_spec_order/new', { output => 0 }, make_part_title => sub { $_[0]->partnumber . ' ' . $_[0]->description }); - $self->js->html('#' . TAB_ID(), $html) + my $html = $self->render('requirement_spec_order/new', { output => 0 }, make_part_title => sub { $_[0]->partnumber . ' ' . $_[0]->description }); + $self->js->hide(LIST_SELECTOR()) + ->after(LIST_SELECTOR(), $html) ->render($self); } @@ -72,7 +74,8 @@ sub action_create { # 3. Notify the user and return to list. my $html = $self->render('requirement_spec_order/list', { output => 0 }); - $self->js->html('#' . TAB_ID(), $html) + $self->js->replaceWith(LIST_SELECTOR(), $html) + ->remove(FORMS_SELECTOR()) ->flash('info', $::form->{quotation} ? t8('Sales quotation #1 has been created.', $order->quonumber) : t8('Sales order #1 has been created.', $order->ordnumber)) ->render($self); } @@ -99,7 +102,8 @@ sub action_update { make_section_title => sub { $_[0]->fb_number . ' ' . $_[0]->title }, ); - $self->js->html('#' . TAB_ID(), $html) + $self->js->hide(LIST_SELECTOR()) + ->after(LIST_SELECTOR(), $html) ->render($self); } @@ -111,6 +115,7 @@ sub action_do_update { my %orderitems_by_id = map { ($_->id => $_) } @{ $order->orderitems }; my %sections_by_id = map { ($_->id => $_) } @{ $sections }; $self->{parts} = { map { ($_->id => $_) } @{ SL::DB::Manager::Part->get_all(where => [ id => [ uniq map { $_->order_part_id } @{ $sections } ] ]) } }; + my $language_id = $self->requirement_spec->customer->language_id; my %sections_seen; @@ -119,11 +124,11 @@ sub action_do_update { my $section = $sections_by_id{ $attributes->{section_id} }; next unless $orderitem && $section; - $self->create_order_item(section => $section, item => $orderitem)->save; + $self->create_order_item(section => $section, item => $orderitem, language_id => $language_id)->save; $sections_seen{ $section->id } = 1; } - my @new_orderitems = map { $self->create_order_item(section => $_) } + my @new_orderitems = map { $self->create_order_item(section => $_, language_id => $language_id) } grep { !$sections_seen{ $_->id } } @{ $sections }; @@ -135,7 +140,8 @@ sub action_do_update { $self->init_requirement_spec; my $html = $self->render('requirement_spec_order/list', { output => 0 }); - $self->js->html('#' . TAB_ID(), $html) + $self->js->replaceWith(LIST_SELECTOR(), $html) + ->remove(FORMS_SELECTOR()) ->flash('info', $::form->{quotation} ? t8('Sales quotation #1 has been updated.', $order->quonumber) : t8('Sales order #1 has been updated.', $order->ordnumber)) ->render($self); } @@ -148,7 +154,8 @@ sub action_edit_assignment { } my $html = $self->render('requirement_spec_order/edit_assignment', { output => 0 }, make_part_title => sub { $_[0]->partnumber . ' ' . $_[0]->description }); - $self->js->html('#' . TAB_ID(), $html) + $self->js->hide(LIST_SELECTOR()) + ->after(LIST_SELECTOR(), $html) ->render($self); } @@ -158,7 +165,8 @@ sub action_save_assignment { SL::DB::RequirementSpecItem->new(id => $_->{id})->load->update_attributes(order_part_id => ($_->{order_part_id} || undef)) for @{ $sections }; my $html = $self->render('requirement_spec_order/list', { output => 0 }); - $self->js->html('#' . TAB_ID(), $html) + $self->js->replaceWith(LIST_SELECTOR(), $html) + ->remove(FORMS_SELECTOR()) ->render($self); } @@ -171,19 +179,11 @@ sub action_delete { $self->init_requirement_spec; my $html = $self->render('requirement_spec_order/list', { output => 0 }); - $self->js->html('#' . TAB_ID(), $html) + $self->js->replaceWith(LIST_SELECTOR(), $html) ->flash('info', $order->quotation ? t8('Sales quotation #1 has been deleted.', $order->quonumber) : t8('Sales order #1 has been deleted.', $order->ordnumber)) ->render($self); } -sub action_cancel { - my ($self) = @_; - - my $html = $self->render('requirement_spec_order/list', { output => 0 }); - $self->js->html('#' . TAB_ID(), $html) - ->render($self); -} - # # filters # @@ -237,22 +237,27 @@ sub create_order_item { my $section = $params{section}; my $item = $params{item} || SL::DB::OrderItem->new; my $part = $self->parts->{ $section->order_part_id }; - my $description = $section->{keep_description} ? $item->description : $part->description; + my $translation = $params{language_id} ? first { $params{language_id} == $_->language_id } @{ $part->translations } : {}; + my $description = $section->{keep_description} ? $item->description : ($translation->{translation} || $part->description); + my $longdescription = $translation->{longdescription} || $part->notes; if (!$section->{keep_description}) { - $description = '<%fb_number%> <%title%>' unless $description =~ m{<%}; - $description =~ s{<% (.+?) %>}{ $section->can($1) ? $section->$1 : '<' . t8('Invalid variable #1', $1) . '>' }egx; + foreach my $field (\$description, \$longdescription) { + $$field = '<%fb_number%> <%title%>' unless $$field =~ m{<%}; + $$field =~ s{<% (.+?) %>}{ $section->can($1) ? $section->$1 : '<' . t8('Invalid variable #1', $1) . '>' }egx; + } } $item->assign_attributes( - parts_id => $part->id, - description => $description, - qty => $section->time_estimation * 1, - unit => $self->h_unit_name, - sellprice => $::form->round_amount($self->requirement_spec->hourly_rate, 2), - lastcost => $part->lastcost, - discount => 0, - project_id => $self->requirement_spec->project_id, + parts_id => $part->id, + description => $description, + longdescription => $longdescription, + qty => $section->time_estimation * 1, + unit => $self->h_unit_name, + sellprice => $::form->round_amount($self->requirement_spec->hourly_rate, 2), + lastcost => $part->lastcost, + discount => 0, + project_id => $self->requirement_spec->project_id, ); return $item; @@ -263,9 +268,9 @@ sub create_order { $self->{parts} = { map { ($_->{id} => $_) } @{ SL::DB::Manager::Part->get_all(where => [ id => [ uniq map { $_->{order_part_id} } @{ $params{sections} } ] ]) } }; - my @orderitems = map { $self->create_order_item(section => $_) } @{ $params{sections} }; - my $employee = SL::DB::Manager::Employee->current; my $customer = SL::DB::Customer->new(id => $::form->{customer_id})->load; + my @orderitems = map { $self->create_order_item(section => $_, language_id => $customer->language_id) } @{ $params{sections} }; + my $employee = SL::DB::Manager::Employee->current; my $order = SL::DB::Order->new( globalproject_id => $self->requirement_spec->project_id, transdate => DateTime->today_local,