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