E-Mails als HTML verschicken: Bearbeiten Benutzer-Signatur (Admin-Bereich)
[kivitendo-erp.git] / SL / PriceSource / Business.pm
1 package SL::PriceSource::Business;
2
3 use strict;
4 use parent qw(SL::PriceSource::Base);
5
6 use SL::DB::Business;
7 use SL::PriceSource::Discount;
8 use SL::Locale::String;
9
10 sub name { 'business' }
11
12 sub description { t8('Business') }
13
14 sub available_prices { }
15
16 sub available_discounts {
17   my ($self, %params) = @_;
18
19   return unless $self->customer_vendor;
20   return unless $self->customer_vendor->business;
21   return unless $self->customer_vendor->business->discount != 0;
22
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,
28   );
29 }
30
31 sub price_from_source { }
32
33 sub discount_from_source {
34   my ($self, $source, $spec) = @_;
35
36   my $business = SL::DB::Business->load_cached($spec);
37
38   if (!$business) {
39     return SL::PriceSource::Discount->new(
40       missing      => t8('Could not load this business'),
41       price_source => $self,
42     )
43   }
44
45   if (!$self->customer_vendor) {
46     return SL::PriceSource::Discount->new(
47       discount     => $business->discount,
48       spec         => $business->id,
49       description  => t8('Business Discount'),
50       price_source => $self,
51       invalid      => t8('This discount is only valid in records with customer or vendor'),
52     )
53   }
54
55   if (!$self->customer_vendor->business ||
56       $business->id != $self->customer_vendor->business->id) {
57     return SL::PriceSource::Discount->new(
58       discount     => $business->discount,
59       spec         => $business->id,
60       description  => t8('Business Discount'),
61       price_source => $self,
62       invalid      => t8('This discount is only valid for business #1', $business->displayable_name),
63     )
64   }
65
66   return SL::PriceSource::Discount->new(
67     discount     => $business->discount,
68     spec         => $business->id,
69     description  => t8('Business Discount'),
70     price_source => $self,
71   );
72 }
73
74 sub best_price { }
75
76 sub best_discount {
77   &available_discounts;
78 }
79
80 1;
81