use Rose::Object::MakeMethods::Generic
(
scalar => [ qw(parts) ],
- 'scalar --get_set_init' => [ qw(requirement_spec rs_order js h_unit_name all_customers all_parts) ],
+ 'scalar --get_set_init' => [ qw(requirement_spec rs_order js h_unit_name all_customers all_parts_time_unit) ],
);
__PACKAGE__->run_before('setup');
sub action_new {
my ($self) = @_;
+ if (!@{ $self->all_parts_time_unit }) {
+ 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)
->render($self);
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;
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 };
sub action_edit_assignment {
my ($self) = @_;
+ if (!@{ $self->all_parts_time_unit }) {
+ 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/edit_assignment', { output => 0 }, make_part_title => sub { $_[0]->partnumber . ' ' . $_[0]->description });
$self->js->html('#' . TAB_ID(), $html)
->render($self);
my ($self) = @_;
$::auth->assert('sales_quotation_edit');
- $::request->{layout}->use_stylesheet("${_}.css") for qw(jquery.contextMenu requirement_spec);
+ $::request->{layout}->use_stylesheet("${_}.css") for qw(jquery.contextMenu requirement_spec autocomplete_part);
$::request->{layout}->use_javascript("${_}.js") for qw(jquery.jstree jquery/jquery.contextMenu client_js requirement_spec);
return 1;
}
sub init_all_customers { SL::DB::Manager::Customer->get_all_sorted }
-sub init_all_parts { SL::DB::Manager::Part->get_all_sorted }
sub init_h_unit_name { first { SL::DB::Manager::Unit->find_by(name => $_) } qw(Std h Stunde) };
sub init_rs_order { SL::DB::RequirementSpecOrder->new(id => $::form->{rs_order_id})->load };
+sub init_all_parts_time_unit {
+ my ($self) = @_;
+
+ return [] unless $self->h_unit_name;
+
+ my @convertible_unit_names = map { $_->name } @{ SL::DB::Manager::Unit->find_by(name => $self->h_unit_name)->convertible_units };
+
+ return SL::DB::Manager::Part->get_all_sorted(where => [ unit => \@convertible_unit_names ]);
+}
+
#
# helpers
#
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->$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;
$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,