1 package SL::PriceSource::Customer;
4 use parent qw(SL::PriceSource::Base);
7 use SL::PriceSource::Discount;
8 use SL::Locale::String;
10 sub name { 'customer_discount' }
12 sub description { t8('Customer Discount') }
14 sub available_prices { }
16 sub available_discounts {
17 my ($self, %params) = @_;
19 return if $self->part->not_discountable;
20 return unless $self->record->is_sales;
21 return unless $self->record->customer;
22 return unless $self->record->customer->discount != 0;
24 SL::PriceSource::Discount->new(
25 discount => $self->record->customer->discount,
26 spec => $self->record->customer->id,
27 description => t8('Customer Discount'),
28 price_source => $self,
32 sub price_from_source {
33 my ($self, $source, $spec) = @_;
35 my $customer = SL::DB::Customer->load_cached($spec);
38 return SL::PriceSource::Discount->new(
39 missing => t8('Could not load this customer'),
40 price_source => $self,
44 if (!$self->record->customer) {
45 return SL::PriceSource::Discount->new(
46 discount => $customer->discount,
47 spec => $customer->id,
48 description => t8('Customer Discount'),
49 price_source => $self,
50 invalid => t8('This discount is only valid in sales documents'),
54 if ($customer->id != $self->record->customer->id) {
55 return SL::PriceSource::Discount->new(
56 discount => $customer->discount,
57 spec => $customer->id,
58 description => t8('Customer Discount'),
59 price_source => $self,
60 invalid => t8('This discount is only valid for customer #1', $customer->full_description),
64 return SL::PriceSource::Discount->new(
65 discount => $customer->discount,
66 spec => $customer->id,
67 description => t8('Customer Discount'),
68 price_source => $self,