X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FDB%2FPriceRule.pm;h=1c43d4a966ce96acd12006392f92c73324657c19;hb=c5057972d03f3546494fabe72224785e5a0a1714;hp=7dfd197037f7d38688c8177f52c75cd0f0d7ec06;hpb=247ff32761c458cf04d46a40fbf3161b2c5d57e5;p=kivitendo-erp.git diff --git a/SL/DB/PriceRule.pm b/SL/DB/PriceRule.pm index 7dfd19703..1c43d4a96 100644 --- a/SL/DB/PriceRule.pm +++ b/SL/DB/PriceRule.pm @@ -7,7 +7,6 @@ use strict; use SL::DB::MetaSetup::PriceRule; use SL::DB::Manager::PriceRule; -use Rose::DB::Object::Helpers qw(clone_and_reset); use SL::Locale::String qw(t8); __PACKAGE__->meta->add_relationship( @@ -44,15 +43,19 @@ sub is_sales { : $_[0]->type eq 'vendor' ? 0 : do { die 'wrong type' }; } -sub price_or_discount { +sub price_type { my ($self, $value) = @_; if (@_ > 1) { - my $number = $self->price || $self->discount; - if ($value) { + my $number = $self->price || $self->discount || $self->reduction; + if ($value == SL::DB::Manager::PriceRule::PRICE_NEW()) { + $self->price($number); + } elsif ($value == SL::DB::Manager::PriceRule::PRICE_REDUCED_MASTER_DATA()) { + $self->reduction($number); + } elsif ($value == SL::DB::Manager::PriceRule::PRICE_DISCOUNT()) { $self->discount($number); } else { - $self->price($number); + die 'unknown price_or_discount value'; } $self->price_or_discount_state($value); } @@ -61,14 +64,29 @@ sub price_or_discount { sub price_or_discount_as_number { my ($self, @slurp) = @_; + my $type = $self->price_type; + + $self->price(undef) unless $type == SL::DB::Manager::PriceRule::PRICE_NEW(); + $self->reduction(undef) unless $type == SL::DB::Manager::PriceRule::PRICE_REDUCED_MASTER_DATA(); + $self->discount(undef) unless $type == SL::DB::Manager::PriceRule::PRICE_DISCOUNT(); - $self->price_or_discount ? $self->price(undef) : $self->discount(undef); - $self->price_or_discount ? $self->discount_as_number(@slurp) : $self->price_as_number(@slurp); + + if ($type == SL::DB::Manager::PriceRule::PRICE_NEW()) { + return $self->price_as_number(@slurp) + } elsif ($type == SL::DB::Manager::PriceRule::PRICE_REDUCED_MASTER_DATA()) { + return $self->reduction_as_number(@slurp); + } elsif ($type == SL::DB::Manager::PriceRule::PRICE_DISCOUNT()) { + return $self->discount_as_number(@slurp) + } else { + die 'unknown price_or_discount'; + } } sub init_price_or_discount_state { - defined $_[0]->price ? 0 - : defined $_[0]->discount ? 1 : 0 + defined $_[0]->price ? SL::DB::Manager::PriceRule::PRICE_NEW() + : defined $_[0]->reduction ? SL::DB::Manager::PriceRule::PRICE_REDUCED_MASTER_DATA() + : defined $_[0]->discount ? SL::DB::Manager::PriceRule::PRICE_DISCOUNT() + : SL::DB::Manager::PriceRule::PRICE_NEW(); } sub validate { @@ -76,8 +94,9 @@ sub validate { my @errors; push @errors, $::locale->text('The name must not be empty.') if !$self->name; - push @errors, $::locale->text('Price or discount must not be zero.') if !$self->price && !$self->discount; - push @errors, $::locale->text('Pirce rules must have at least one rule.') if !@{[ $self->items ]}; + push @errors, $::locale->text('Price or discount must not be zero.') if !$self->price && !$self->discount && !$self->reduction; + push @errors, $::locale->text('Price rules must have at least one rule.') if !@{[ $self->items ]}; + push @errors, $_->validate for $self->items; return @errors; } @@ -95,7 +114,7 @@ sub clone_and_reset_deep { sub full_description { my ($self) = @_; - my $items = join ', ', map { $_->full_description } $self->items; + my $items = $self->item_summary; my $price = $self->price_or_discount ? t8('Discount #1%', $self->discount_as_number) : t8('Price #1', $self->price_as_number); @@ -103,6 +122,10 @@ sub full_description { sprintf "%s: %s (%s)", $self->name, $price, $items; } +sub item_summary { + join ', ', map { $_->full_description } $_[0]->items; +} + sub in_use { my ($self) = @_; @@ -119,5 +142,12 @@ sub in_use { || SL::DB::Manager::InvoiceItem->get_all_count(query => [ active_price_source => $price_source_spec ]); } +sub priority_as_text { + my ($self) = @_; + + return t8('Override') if $self->priority == 4; + t8('Normal'); +} + 1;