1 package SL::PriceSource::CustomerPrice;
 
   4 use parent qw(SL::PriceSource::Base);
 
   6 use SL::PriceSource::Price;
 
   7 use SL::Locale::String;
 
   8 use SL::DB::PartCustomerPrice;
 
   9 # use List::UtilsBy qw(min_by max_by);
 
  11 sub name { 'customer_price' }
 
  13 sub description { t8('Customer specific Price') }
 
  15 sub available_prices {
 
  16   my ($self, %params) = @_;
 
  18   return () if !$self->part;
 
  19   return () if !$self->record->is_sales;
 
  21   map { $self->make_price_from_customerprice($_) }
 
  22   grep { $_->customer_id == $self->record->customer_id }
 
  23   $self->part->customerprices;
 
  26 sub available_discounts { }
 
  28 sub price_from_source {
 
  29   my ($self, $source, $spec) = @_;
 
  31   my $customerprice = SL::DB::Manager::PartCustomerPrice->find_by(id => $spec);
 
  33   return $self->make_price_from_customerprice($customerprice);
 
  38   my ($self, %params) = @_;
 
  40   return () if !$self->record->is_sales;
 
  42 #  min_by { $_->price } $self->available_prices;
 
  43 #  max_by { $_->price } $self->available_prices;
 
  50 sub make_price_from_customerprice {
 
  51   my ($self, $customerprice) = @_;
 
  53   return SL::PriceSource::Price->new(
 
  54     price        => $customerprice->price,
 
  55     spec         => $customerprice->id,
 
  56     description  => $customerprice->customer_partnumber,
 
  57     price_source => $self,