PriceSource: Rabattbehandlung
[kivitendo-erp.git] / SL / PriceSource / Price.pm
1 package SL::PriceSource::Price;
2
3 use strict;
4
5 use parent 'SL::DB::Object';
6 use Rose::Object::MakeMethods::Generic (
7   scalar => [ qw(price description spec price_source invalid missing) ],
8 );
9
10 require SL::DB::Helper::Attr;
11 SL::DB::Helper::Attr::make(__PACKAGE__,
12   price => 'numeric(15,5)',
13 );
14
15 sub source {
16   $_[0]->price_source
17   ? $_[0]->price_source->name . '/' . $_[0]->spec
18   : '';
19 }
20
21 sub full_description {
22   my ($self) = @_;
23
24   $self->price_source
25     ? $self->price_source->description . ': ' . $self->description
26     : $self->description
27 }
28
29 sub source_description {
30   my ($self) = @_;
31
32   $self->price_source
33     ? $self->price_source->description
34     : $self->description
35 }
36
37 sub to_str {
38   "source: @{[ $_[0]->source ]}, price: @{[ $_[0]->price ]}, description: @{[ $_[0]->description ]}"
39 }
40
41 1;
42
43 __END__
44
45 =encoding utf-8
46
47 =head1 NAME
48
49 SL::PriceSource::Price - contrainer to pass calculated prices around
50
51 =head1 SYNOPSIS
52
53   # in PriceSource::Base implementation
54   $price = SL::PriceSource::Price->new(
55     price        => 10.3,
56     spec         => '3', # something you can easily parse later
57     description  => t8('Fix price 10.3 for customer 3'),
58     price_source => $self,
59   )
60
61   # special empty price in SL::PriceSource, for internal use.
62   SL::PriceSource::Price->new(
63     description => t8('None (PriceSource)'),
64   );
65
66   # price can't be restored
67   SL::PriceSource::Price->new(
68     missing      => t8('Um, sorry, cannot find that one'),
69     price_source => $self,
70   );
71
72   # invalid price
73   SL::PriceSource::Price->new(
74     price        => $original_price,
75     spec         => $original_spec,
76     description  => $original_description,
77     invalid      => t8('Offer expired #1 weeks ago', $dt->delta_weeks),
78     price_source => $self,
79   );
80
81 =head1 DESCRIPTION
82
83 See L<SL::PriceSource> for information about the mechanism.
84
85 This is a container for prices that are generated by L<SL::PriceSource::Base>
86 implementations.
87
88 =head1 CONSTRUCTOR FIELDS
89
90 =over 4
91
92 =item C<price>
93
94 The price. A price of 0 is special and is considered undesirable. If passed as
95 part of C<available_prices> it will be filtered out. If returned as
96 C<best_price> or C<price_from_source> it will trigger a warning.
97
98 =item C<spec>
99
100 A unique string that can later be understood by the creating implementation.
101 Can be empty if the implementation only supports one price for a given
102 record_item.
103
104 =item C<description>
105
106 A localized short description of the origins of this price.
107
108 =item C<price_source>
109
110 A ref to the creating algorithm.
111
112 =item C<missing>
113
114 OPTIONAL. Both indicator and localized message that the price with this spec
115 could not be reproduced and should be changed.
116
117 If price is missing, you do not need to supply anything except C<source>.
118
119 =item C<invalid>
120
121 OPTIONAL. Both indicator and localized message that the conditions for this
122 price are no longer valid, and that the price should be changed.
123
124 If price is missing, you do not need to supply anything except C<source>.
125
126 =back
127
128 =head1 SEE ALSO
129
130 L<SL::PriceSource>,
131 L<SL::PriceSource::Base>,
132 L<SL::PriceSource::ALL>
133
134 =head1 BUGS
135
136 None yet. :)
137
138 =head1 AUTHOR
139
140 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>
141
142 =cut