X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/c653b98f17446bf3dab478e5361b1bc6df822e61..89b2668811eac6023ad58322e2f9970ddb6a27c9:/SL/PriceSource/Business.pm diff --git a/SL/PriceSource/Business.pm b/SL/PriceSource/Business.pm new file mode 100644 index 000000000..ca66c5dba --- /dev/null +++ b/SL/PriceSource/Business.pm @@ -0,0 +1,78 @@ +package SL::PriceSource::Business; + +use strict; +use parent qw(SL::PriceSource::Base); + +use SL::DB::Business; +use SL::PriceSource::Discount; +use SL::Locale::String; + +sub name { 'business' } + +sub description { t8('Business') } + +sub available_prices { } + +sub available_discounts { + my ($self, %params) = @_; + + return unless $self->customer_vendor; + return unless $self->customer_vendor->business; + return unless $self->customer_vendor->business->discount != 0; + + SL::PriceSource::Discount->new( + discount => $self->customer_vendor->business->discount, + spec => $self->customer_vendor->business->id, + description => t8('Business Discount'), + price_source => $self, + ); +} + +sub price_from_source { + my ($self, $source, $spec) = @_; + + my $business = SL::DB::Business->load_cached($spec); + + if (!$business) { + return SL::PriceSource::Discount->new( + missing => t8('Could not load this business'), + price_source => $self, + ) + } + + if (!$self->customer_vendor) { + return SL::PriceSource::Discount->new( + discount => $business->discount, + spec => $business->id, + description => t8('Business Discount'), + price_source => $self, + invalid => t8('This discount is only valid in records with customer or vendor'), + ) + } + + if ($business->id != $self->customer_vendor->business->id) { + return SL::PriceSource::Discount->new( + discount => $business->discount, + spec => $business->id, + description => t8('Business Discount'), + price_source => $self, + invalid => t8('This discount is only valid for business #1', $business->full_description), + ) + } + + return SL::PriceSource::Discount->new( + discount => $business->discount, + spec => $business->id, + description => t8('Business Discount'), + price_source => $self, + ); +} + +sub best_price { } + +sub best_discount { + &available_discounts; +} + +1; +