: empty_price();
}
+sub discount_from_source {
+ my ($self, $source) = @_;
+ my ($source_name, $spec) = split m{/}, $source, 2;
+
+ my $class = SL::PriceSource::ALL->price_source_class_by_name($source_name);
+
+ return $class
+ ? $class->new(record_item => $self->record_item, record => $self->record)->discount_from_source($source, $spec)
+ : empty_discount();
+}
+
sub available_prices {
map { $_->available_prices } $_[0]->all_price_sources;
}
);
}
+sub empty_discount {
+ SL::PriceSource::Discount->new(
+ description => t8('None (PriceSource Discount)'),
+ );
+}
+
1;
__END__
Attempts to retrieve a formerly calculated price with the same conditions
+=item C<discount_from_source>
+
+Attempts to retrieve a formerly calculated discount with the same conditions
+
=item C<available_prices>
Returns all available prices.
+=item C<available_discounts>
+
+Returns all available discounts.
+
=item C<best_price>
Attempts to get the best available price. returns L<empty_price> if no price is found.
+=item C<best_discount>
+
+Attempts to get the best available discount. returns L<empty_discount> if no discount is found.
+
=item C<empty_price>
A special empty price, that does not change the previously entered price, and
opens the price field to manual changes.
+=item C<empty_discount>
+
+A special empty discount, that does not change the previously entered discount, and
+opens the discount field to manual changes.
+
=back
=head1 SEE ALSO
L<SL::PriceSource::Base>,
L<SL::PriceSource::Price>,
+L<SL::PriceSource::Discount>,
L<SL::PriceSource::ALL>
=head1 BUGS AND CAVEATS
sub price_from_source { die 'price_from_source needs to be implemented:' . "@_" }
+sub discount_from_source { die 'discount_from_source needs to be implemented:' . "@_" }
+
sub part {
$_[0]->record_item->part;
}
);
}
-sub price_from_source {
+sub price_from_source { }
+
+sub discount_from_source {
my ($self, $source, $spec) = @_;
my $business = SL::DB::Business->load_cached($spec);
);
}
-sub price_from_source {
+sub price_from_source { }
+
+sub discount_from_source {
my ($self, $source, $spec) = @_;
my $customer = SL::DB::Customer->load_cached($spec);
}
+sub discount_from_source { }
+
sub best_price {
my ($self, %params) = @_;
: do { die "unknown spec '$spec'" };
}
+sub discount_from_source { }
+
sub best_price {
$_[0]->record->is_sales
? $_[0]->make_sellprice
sub price_from_source {
my ($self, $source, $spec) = @_;
+ my $rule = SL::DB::Manager::PriceRule->find_by(id => $spec);
+ if ($rule->price_type != SL::DB::Manager::PriceRule::PRICE_DISCOUNT()) {
+ return $self->make_price_from_rule($rule);
+ }
+
+ return;
+}
+
+sub discount_from_source {
+ my ($self, $source, $spec) = @_;
+
my $rule = SL::DB::Manager::PriceRule->find_by(id => $spec);
if ($rule->price_type == SL::DB::Manager::PriceRule::PRICE_DISCOUNT()) {
return $self->make_discount_from_rule($rule);
- } else {
- return $self->make_price_from_rule($rule);
}
+
+ return;
}
sub best_price {
return $self->make_price($price);
}
+sub discount_from_source { }
+
sub best_price {
my ($self, %params) = @_;
);
}
-sub price_from_source {
+sub price_from_source { }
+
+sub discount_from_source {
my ($self, $source, $spec) = @_;
my $vendor = SL::DB::Vendor->load_cached($spec);
if ($form->{"id_${i}"} && !$is_delivery_order) {
my $price_source = SL::PriceSource->new(record_item => $record_item, record => $record);
my $price = $price_source->price_from_source($::form->{"active_price_source_$i"});
- my $discount = $price_source->price_from_source($::form->{"active_discount_source_$i"});
+ my $discount = $price_source->discount_from_source($::form->{"active_discount_source_$i"});
my $best_price = $price_source->best_price;
my $best_discount = $price_source->best_discount;
$column_data{price_source} .= $cgi->button(-value => $price->source_description, -onClick => "kivi.io.price_chooser($i)");