Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 73f7989f

Von Bernd Bleßmann vor mehr als 2 Jahren hinzugefügt

  • ID 73f7989fcf23410ebd879d5150f6a13913ca2b90
  • Vorgänger d6fed9b5
  • Nachfolger 1b58f5da

Auftrags-Controller: Preisquellenermittlung in eigene Funktion ausgelagert

Unterschiede anzeigen:

SL/Controller/Order.pm
899 899

  
900 900
  my $record       = $self->order;
901 901
  my $item         = SL::DB::OrderItem->new(%$form_attr);
902
  my $part         = SL::DB::Part->new(id => $::form->{add_item}->{parts_id})->load;
903
  my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
904

  
905
  $item->unit($part->unit);
902
  $item->unit($item->part->unit);
906 903

  
907
  my $price_src;
908
  if ( $part->is_assortment ) {
909
    # add assortment items with price 0, as the components carry the price
910
    $price_src = $price_source->price_from_source("");
911
    $price_src->price(0);
912
  } elsif (defined $item->sellprice) {
913
    $price_src = $price_source->price_from_source("");
914
    $price_src->price($item->sellprice);
915
  } else {
916
    $price_src = $price_source->best_price
917
               ? $price_source->best_price
918
               : $price_source->price_from_source("");
919
    $price_src->price($::form->round_amount($price_src->price / $record->exchangerate, 5)) if $record->exchangerate;
920
    $price_src->price(0) if !$price_source->best_price;
921
  }
922

  
923
  my $discount_src;
924
  if (defined $item->discount) {
925
    $discount_src = $price_source->discount_from_source("");
926
    $discount_src->discount($item->discount);
927
  } else {
928
    $discount_src = $price_source->best_discount
929
                  ? $price_source->best_discount
930
                  : $price_source->discount_from_source("");
931
    $discount_src->discount(0) if !$price_source->best_discount;
932
  }
904
  my ($price_src, $discount_src) = get_best_price_and_discount_source($record, $item, 0);
933 905

  
934 906
  $self->js
935 907
    ->val     ('#add_item_unit',                $item->unit)
936
    ->val     ('#add_item_description',         $part->description)
908
    ->val     ('#add_item_description',         $item->part->description)
937 909
    ->val     ('#add_item_sellprice_as_number', '')
938 910
    ->attr    ('#add_item_sellprice_as_number', 'placeholder', $price_src->price_as_number)
939 911
    ->attr    ('#add_item_sellprice_as_number', 'title',       $price_src->source_description)
......
1238 1210
    $item->description($texts->{description});
1239 1211
    $item->longdescription($texts->{longdescription});
1240 1212

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

  
1243
    my $price_src;
1244
    if ($item->part->is_assortment) {
1245
    # add assortment items with price 0, as the components carry the price
1246
      $price_src = $price_source->price_from_source("");
1247
      $price_src->price(0);
1248
    } else {
1249
      $price_src = $price_source->best_price
1250
                 ? $price_source->best_price
1251
                 : $price_source->price_from_source("");
1252
      $price_src->price($::form->round_amount($price_src->price / $self->order->exchangerate, 5)) if $self->order->exchangerate;
1253
      $price_src->price(0) if !$price_source->best_price;
1254
    }
1255

  
1256
    my $discount_src;
1257
    $discount_src = $price_source->best_discount
1258
                  ? $price_source->best_discount
1259
                  : $price_source->discount_from_source("");
1260
    $discount_src->discount(0) if !$price_source->best_discount;
1213
    my ($price_src, $discount_src) = get_best_price_and_discount_source($self->order, $item, 1);
1261 1214

  
1262 1215
    $item->sellprice($price_src->price);
1263 1216
    $item->active_price_source($price_src);
......
1710 1663
  }
1711 1664

  
1712 1665
  $item->assign_attributes(%$attr);
1666
  $item->qty(1.0)                   if !$item->qty;
1667
  $item->unit($item->part->unit)    if !$item->unit;
1713 1668

  
1714
  my $part         = SL::DB::Part->new(id => $attr->{parts_id})->load;
1715
  my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
1716

  
1717
  $item->qty(1.0)          if !$item->qty;
1718
  $item->unit($part->unit) if !$item->unit;
1719

  
1720
  my $price_src;
1721
  if ( $part->is_assortment ) {
1722
    # add assortment items with price 0, as the components carry the price
1723
    $price_src = $price_source->price_from_source("");
1724
    $price_src->price(0);
1725
  } elsif (defined $item->sellprice) {
1726
    $price_src = $price_source->price_from_source("");
1727
    $price_src->price($item->sellprice);
1728
  } else {
1729
    $price_src = $price_source->best_price
1730
               ? $price_source->best_price
1731
               : $price_source->price_from_source("");
1732
    $price_src->price($::form->round_amount($price_src->price / $record->exchangerate, 5)) if $record->exchangerate;
1733
    $price_src->price(0) if !$price_source->best_price;
1734
  }
1735

  
1736
  my $discount_src;
1737
  if (defined $item->discount) {
1738
    $discount_src = $price_source->discount_from_source("");
1739
    $discount_src->discount($item->discount);
1740
  } else {
1741
    $discount_src = $price_source->best_discount
1742
                  ? $price_source->best_discount
1743
                  : $price_source->discount_from_source("");
1744
    $discount_src->discount(0) if !$price_source->best_discount;
1745
  }
1669
  my ($price_src, $discount_src) = get_best_price_and_discount_source($record, $item, 0);
1746 1670

  
1747 1671
  my %new_attr;
1748
  $new_attr{part}                   = $part;
1749
  $new_attr{description}            = $part->description     if ! $item->description;
1750
  $new_attr{price_factor_id}        = $part->price_factor_id if ! $item->price_factor_id;
1672
  $new_attr{description}            = $item->part->description     if ! $item->description;
1673
  $new_attr{qty}                    = 1.0                          if ! $item->qty;
1674
  $new_attr{price_factor_id}        = $item->part->price_factor_id if ! $item->price_factor_id;
1751 1675
  $new_attr{sellprice}              = $price_src->price;
1752 1676
  $new_attr{discount}               = $discount_src->discount;
1753 1677
  $new_attr{active_price_source}    = $price_src;
1754 1678
  $new_attr{active_discount_source} = $discount_src;
1755
  $new_attr{longdescription}        = $part->notes           if ! defined $attr->{longdescription};
1679
  $new_attr{longdescription}        = $item->part->notes           if ! defined $attr->{longdescription};
1756 1680
  $new_attr{project_id}             = $record->globalproject_id;
1757
  $new_attr{lastcost}               = $record->is_sales ? $part->lastcost : 0;
1681
  $new_attr{lastcost}               = $record->is_sales ? $item->part->lastcost : 0;
1758 1682

  
1759 1683
  # add_custom_variables adds cvars to an orderitem with no cvars for saving, but
1760 1684
  # they cannot be retrieved via custom_variables until the order/orderitem is
1761 1685
  # saved. Adding empty custom_variables to new orderitem here solves this problem.
1762 1686
  $new_attr{custom_variables} = [];
1763 1687

  
1764
  my $texts = get_part_texts($part, $record->language_id, description => $new_attr{description}, longdescription => $new_attr{longdescription});
1688
  my $texts = get_part_texts($item->part, $record->language_id, description => $new_attr{description}, longdescription => $new_attr{longdescription});
1765 1689

  
1766 1690
  $item->assign_attributes(%new_attr, %{ $texts });
1767 1691

  
......
2514 2438
  return $texts;
2515 2439
}
2516 2440

  
2441
sub get_best_price_and_discount_source {
2442
  my ($record, $item, $ignore_given) = @_;
2443

  
2444
  my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
2445

  
2446
  my $price_src;
2447
  if ( $item->part->is_assortment ) {
2448
    # add assortment items with price 0, as the components carry the price
2449
    $price_src = $price_source->price_from_source("");
2450
    $price_src->price(0);
2451
  } elsif (!$ignore_given && defined $item->sellprice) {
2452
    $price_src = $price_source->price_from_source("");
2453
    $price_src->price($item->sellprice);
2454
  } else {
2455
    $price_src = $price_source->best_price
2456
               ? $price_source->best_price
2457
               : $price_source->price_from_source("");
2458
    $price_src->price($::form->round_amount($price_src->price / $record->exchangerate, 5)) if $record->exchangerate;
2459
    $price_src->price(0) if !$price_source->best_price;
2460
  }
2461

  
2462
  my $discount_src;
2463
  if (!$ignore_given && defined $item->discount) {
2464
    $discount_src = $price_source->discount_from_source("");
2465
    $discount_src->discount($item->discount);
2466
  } else {
2467
    $discount_src = $price_source->best_discount
2468
                  ? $price_source->best_discount
2469
                  : $price_source->discount_from_source("");
2470
    $discount_src->discount(0) if !$price_source->best_discount;
2471
  }
2472

  
2473
  return ($price_src, $discount_src);
2474
}
2475

  
2517 2476
sub sales_order_type {
2518 2477
  'sales_order';
2519 2478
}

Auch abrufbar als: Unified diff