Versionsnummer in Dokumentationen für 3.6.1 angepasst
[kivitendo-erp.git] / SL / PriceSource / CustomerPrice.pm
1 package SL::PriceSource::CustomerPrice;
2
3 use strict;
4 use parent qw(SL::PriceSource::Base);
5
6 use SL::PriceSource::Price;
7 use SL::Locale::String;
8 use SL::DB::PartCustomerPrice;
9 # use List::UtilsBy qw(min_by max_by);
10
11 sub name { 'customer_price' }
12
13 sub description { t8('Customer specific Price') }
14
15 sub available_prices {
16   my ($self, %params) = @_;
17
18   return () if !$self->part;
19   return () if !$self->record->is_sales;
20
21   map { $self->make_price_from_customerprice($_) }
22   grep { $_->customer_id == $self->record->customer_id }
23   $self->part->customerprices;
24 }
25
26 sub available_discounts { }
27
28 sub price_from_source {
29   my ($self, $source, $spec) = @_;
30
31   my $customerprice = SL::DB::Manager::PartCustomerPrice->find_by(id => $spec);
32
33   return $self->make_price_from_customerprice($customerprice);
34
35 }
36
37 sub best_price {
38   my ($self, %params) = @_;
39
40   return () if !$self->record->is_sales;
41
42 #  min_by { $_->price } $self->available_prices;
43 #  max_by { $_->price } $self->available_prices;
44   &available_prices;
45
46 }
47
48 sub best_discount { }
49
50 sub make_price_from_customerprice {
51   my ($self, $customerprice) = @_;
52
53   return SL::PriceSource::Price->new(
54     price        => $customerprice->price,
55     spec         => $customerprice->id,
56     description  => $customerprice->customer_partnumber,
57     price_source => $self,
58   );
59 }
60
61
62 1;