Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 3d820036

Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt

  • ID 3d8200365bdd53653f7b00209e736c68424d7e3a
  • Vorgänger 31ead75c
  • Nachfolger 30e1cefc

Pflichtenhefte: beim Erstellen von Aufträgen zus. Artikel anlegen

Unterschiede anzeigen:

SL/Controller/RequirementSpecOrder.pm
66 66
  $sections_by_id{ $_->{id} }->update_attributes(order_part_id => $_->{order_part_id}) for @{ $section_attrs };
67 67

  
68 68
  # 2. Create actual quotation/order.
69
  my $order = $self->create_order(sections => $sections);
69
  my $order = $self->create_order(sections => $sections, additional_parts => [ $self->requirement_spec->parts ]);
70 70
  $order->db->with_transaction(sub {
71 71
    $order->save;
72 72

  
......
280 280
  return $item;
281 281
}
282 282

  
283
sub create_additional_part_order_item {
284
  my ($self, %params) = @_;
285

  
286
  my $add_part        = $params{additional_part};
287
  my $item            = $params{item} || SL::DB::OrderItem->new;
288
  my $part            = $self->parts->{ $add_part->part_id };
289
  my $translation     = $params{language_id} ? first { $params{language_id} == $_->language_id } @{ $part->translations } : {};
290
  my $description     = $item->description              || $add_part->description;
291
  my $longdescription = $translation->{longdescription} || $part->notes;
292

  
293
  $item->assign_attributes(
294
    parts_id        => $part->id,
295
    description     => $description,
296
    longdescription => $longdescription,
297
    qty             => $add_part->qty,
298
    unit            => $add_part->unit->name,
299
    sellprice       => $add_part->unit->convert_to($part->sellprice, $part->unit_obj),
300
    lastcost        => $part->lastcost,
301
    discount        => 0,
302
    project_id      => $self->requirement_spec->project_id,
303
  );
304

  
305
  return $item;
306
}
307

  
283 308
sub create_order {
284 309
  my ($self, %params) = @_;
285 310

  
286
  $self->{parts} = { map { ($_->{id} => $_) } @{ SL::DB::Manager::Part->get_all(where => [ id => [ uniq map { $_->{order_part_id} } @{ $params{sections} } ] ]) } };
311
  my @part_ids = (
312
    map({ $_->{order_part_id} } @{ $params{sections} }),
313
    map({ $_->part_id         } @{ $params{additional_parts} }),
314
  );
315
  $self->{parts} = { map { ($_->{id} => $_) } @{ SL::DB::Manager::Part->get_all(where => [ id => [ uniq @part_ids ] ]) } };
287 316

  
288 317
  my $customer   = SL::DB::Customer->new(id => $::form->{customer_id})->load;
289
  my @orderitems = map { $self->create_order_item(section => $_, language_id => $customer->language_id) } @{ $params{sections} };
318
  my @orderitems = map { $self->create_order_item(                section => $_,         language_id => $customer->language_id) } @{ $params{sections} };
319
  my @add_items  = map { $self->create_additional_part_order_item(additional_part => $_, language_id => $customer->language_id) } @{ $params{additional_parts} };
290 320
  my $employee   = SL::DB::Manager::Employee->current;
291 321
  my $order      = SL::DB::Order->new(
292 322
    globalproject_id        => $self->requirement_spec->project_id,
293 323
    transdate               => DateTime->today_local,
294 324
    reqdate                 => $::form->{quotation} && $customer->payment_id ? $customer->payment->calc_date : undef,
295 325
    quotation               => !!$::form->{quotation},
296
    orderitems              => \@orderitems,
326
    orderitems              => [ @orderitems, @add_items ],
297 327
    customer_id             => $customer->id,
298 328
    taxincluded             => $customer->taxincluded,
299 329
    intnotes                => $customer->notes,

Auch abrufbar als: Unified diff