1 package SL::PriceSource::Business;
4 use parent qw(SL::PriceSource::Base);
7 use SL::PriceSource::Discount;
8 use SL::Locale::String;
10 sub name { 'business' }
12 sub description { t8('Business') }
14 sub available_prices { }
16 sub available_discounts {
17 my ($self, %params) = @_;
19 return unless $self->customer_vendor;
20 return unless $self->customer_vendor->business;
21 return unless $self->customer_vendor->business->discount != 0;
23 SL::PriceSource::Discount->new(
24 discount => $self->customer_vendor->business->discount,
25 spec => $self->customer_vendor->business->id,
26 description => t8('Business Discount'),
27 price_source => $self,
31 sub price_from_source {
32 my ($self, $source, $spec) = @_;
34 my $business = SL::DB::Business->load_cached($spec);
37 return SL::PriceSource::Discount->new(
38 missing => t8('Could not load this business'),
39 price_source => $self,
43 if (!$self->customer_vendor) {
44 return SL::PriceSource::Discount->new(
45 discount => $business->discount,
46 spec => $business->id,
47 description => t8('Business Discount'),
48 price_source => $self,
49 invalid => t8('This discount is only valid in records with customer or vendor'),
53 if (!$self->customer_vendor->business ||
54 $business->id != $self->customer_vendor->business->id) {
55 return SL::PriceSource::Discount->new(
56 discount => $business->discount,
57 spec => $business->id,
58 description => t8('Business Discount'),
59 price_source => $self,
60 invalid => t8('This discount is only valid for business #1', $business->displayable_name),
64 return SL::PriceSource::Discount->new(
65 discount => $business->discount,
66 spec => $business->id,
67 description => t8('Business Discount'),
68 price_source => $self,