Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f275cac9

Von Bernd Bleßmann vor etwa 8 Jahren hinzugefügt

  • ID f275cac9ddfb00d05435e73fc85f0a6c016095b8
  • Vorgänger 7c0f439c
  • Nachfolger 419fa9c6

Auftrags-Controller: PriceSources

Unterschiede anzeigen:

SL/Controller/Order.pm
18 18
use SL::DB::Project;
19 19
use SL::DB::Default;
20 20
use SL::DB::Unit;
21
use SL::DB::Price;
21 22

  
22 23
use SL::Helper::DateTime;
23 24
use SL::Helper::CreatePDF qw(:all);
24 25

  
25 26
use List::Util qw(max first);
26
use List::MoreUtils qw(none pairwise);
27
use List::MoreUtils qw(none pairwise first_index);
27 28
use English qw(-no_match_vars);
28 29
use File::Spec;
29 30

  
......
315 316
  my $item = SL::DB::OrderItem->new;
316 317
  $item->assign_attributes(%$form_attr);
317 318

  
318
  my $part        = SL::DB::Part->new(id => $form_attr->{parts_id})->load;
319
  my $cv_method   = $self->cv;
320
  my $cv_discount = $self->order->$cv_method? $self->order->$cv_method->discount : 0.0;
319
  my $part         = SL::DB::Part->new(id => $form_attr->{parts_id})->load;
320

  
321
  my $price_source = SL::PriceSource->new(record_item => $item, record => $self->order);
322

  
323
  my $price_src;
324
  if ($item->sellprice) {
325
    $price_src = $price_source->price_from_source("");
326
    $price_src->price($item->sellprice);
327
  } else {
328
    $price_src = $price_source->best_price
329
           ? $price_source->best_price
330
           : $price_source->price_from_source("");
331
    $price_src->price(0) if !$price_source->best_price;
332
  }
333

  
334
  my $discount_src;
335
  if ($item->discount) {
336
    $discount_src = $price_source->discount_from_source("");
337
    $discount_src->discount($item->discount);
338
  } else {
339
    $discount_src = $price_source->best_discount
340
                  ? $price_source->best_discount
341
                  : $price_source->discount_from_source("");
342
    $discount_src->discount(0) if !$price_source->best_discount;
343
  }
321 344

  
322 345
  my %new_attr;
323
  $new_attr{part}        = $part;
324
  $new_attr{description} = $part->description if ! $item->description;
325
  $new_attr{qty}         = 1.0                if ! $item->qty;
326
  $new_attr{unit}        = $part->unit;
327
  $new_attr{sellprice}   = $part->sellprice   if ! $item->sellprice;
328
  $new_attr{discount}    = $cv_discount       if ! $item->discount;
346
  $new_attr{part}                   = $part;
347
  $new_attr{description}            = $part->description if ! $item->description;
348
  $new_attr{qty}                    = 1.0                if ! $item->qty;
349
  $new_attr{sellprice}              = $price_src->price;
350
  $new_attr{discount}               = $discount_src->discount;
351
  $new_attr{active_price_source}    = $price_src;
352
  $new_attr{active_discount_source} = $discount_src;
329 353

  
330 354
  # add_custom_variables adds cvars to an orderitem with no cvars for saving, but
331 355
  # they cannot be retrieved via custom_variables until the order/orderitem is
......
364 388
  $self->js->render();
365 389
}
366 390

  
391
sub action_price_popup {
392
  my ($self) = @_;
393

  
394
  my $idx  = first_index { $_ eq $::form->{item_id} } @{ $::form->{orderitem_ids} };
395
  my $item = $self->order->items->[$idx];
396

  
397
  $self->render_price_dialog($item);
398
}
399

  
367 400
sub _js_redisplay_linetotals {
368 401
  my ($self) = @_;
369 402

  
......
476 509
}
477 510

  
478 511

  
512
sub render_price_dialog {
513
  my ($self, $record_item) = @_;
514

  
515
  my $price_source = SL::PriceSource->new(record_item => $record_item, record => $self->order);
516

  
517
  $self->js
518
    ->run(
519
      'kivi.io.price_chooser_dialog',
520
      t8('Available Prices'),
521
      $self->render('order/tabs/_price_sources_dialog', { output => 0 }, price_source => $price_source)
522
    )
523
    ->reinit_widgets;
524

  
525
#   if (@errors) {
526
#     $self->js->text('#dialog_flash_error_content', join ' ', @errors);
527
#     $self->js->show('#dialog_flash_error');
528
#   }
529

  
530
  $self->js->render;
531
}
532

  
479 533
sub _make_order {
480 534
  my ($self) = @_;
481 535

  
......
491 545
  return $order;
492 546
}
493 547

  
494

  
495 548
sub _recalc {
496 549
  my ($self) = @_;
497 550

  
......
520 573
    if ($item->id) {
521 574
      # load data from orderitems (db)
522 575
      my $db_item = SL::DB::OrderItem->new(id => $item->id)->load;
523
      $item->$_($db_item->$_) for qw(active_discount_source active_price_source longdescription);
576
      $item->$_($db_item->$_) for qw(longdescription);
524 577
    } else {
525 578
      # set data from part (or other sources)
526 579
      $item->longdescription($item->part->notes);
527
      #$item->active_price_source('');
528
      #$item->active_discount_source('');
529 580
    }
530 581

  
531 582
    # autovivify all cvars that are not in the form (cvars_by_config can do it).
......
591 642

  
592 643
  $self->{current_employee_id} = SL::DB::Manager::Employee->current->id;
593 644

  
645
  foreach  my $item (@{$self->order->items}) {
646
    my $price_source = SL::PriceSource->new(record_item => $item, record => $self->order);
647
    $item->active_price_source(   $price_source->price_from_source(   $item->active_price_source   ));
648
    $item->active_discount_source($price_source->discount_from_source($item->active_discount_source));
649

  
650
  }
651

  
594 652
  $::request->{layout}->use_javascript("${_}.js")  for qw(ckeditor/ckeditor ckeditor/adapters/jquery);
595 653
}
596 654

  

Auch abrufbar als: Unified diff