Revision 19fce727
Von Bernd Bleßmann vor etwa 1 Jahr hinzugefügt
SL/DB/MetaSetup/PartsPriceHistory.pm | ||
---|---|---|
9 | 9 |
__PACKAGE__->meta->table('parts_price_history'); |
10 | 10 |
|
11 | 11 |
__PACKAGE__->meta->columns( |
12 |
id => { type => 'serial', not_null => 1 }, |
|
13 |
lastcost => { type => 'numeric', precision => 15, scale => 5 }, |
|
14 |
listprice => { type => 'numeric', precision => 15, scale => 5 }, |
|
15 |
part_id => { type => 'integer', not_null => 1 }, |
|
16 |
sellprice => { type => 'numeric', precision => 15, scale => 5 }, |
|
17 |
valid_from => { type => 'timestamp', not_null => 1 }, |
|
12 |
id => { type => 'serial', not_null => 1 }, |
|
13 |
lastcost => { type => 'numeric', precision => 15, scale => 5 }, |
|
14 |
listprice => { type => 'numeric', precision => 15, scale => 5 }, |
|
15 |
part_id => { type => 'integer', not_null => 1 }, |
|
16 |
price_factor => { type => 'numeric', default => 1, precision => 15, scale => 5 }, |
|
17 |
sellprice => { type => 'numeric', precision => 15, scale => 5 }, |
|
18 |
valid_from => { type => 'timestamp', not_null => 1 }, |
|
18 | 19 |
); |
19 | 20 |
|
20 | 21 |
__PACKAGE__->meta->primary_key_columns([ 'id' ]); |
sql/Pg-upgrade2/parts_price_history_add_price_factor.sql | ||
---|---|---|
1 |
-- @tag: parts_price_history_add_price_factor |
|
2 |
-- @description: Preisfaktor für Entwicklung der Stammdatenpreise |
|
3 |
-- @depends: add_parts_price_history2 |
|
4 |
|
|
5 |
ALTER TABLE parts_price_history ADD COLUMN price_factor NUMERIC(15, 5) DEFAULT 1; |
|
6 |
|
|
7 |
CREATE OR REPLACE FUNCTION add_parts_price_history_entry() RETURNS "trigger" AS $$ |
|
8 |
BEGIN |
|
9 |
IF (TG_OP = 'UPDATE') |
|
10 |
AND ((OLD.lastcost IS NULL AND NEW.lastcost IS NULL) OR (OLD.lastcost = NEW.lastcost)) |
|
11 |
AND ((OLD.listprice IS NULL AND NEW.listprice IS NULL) OR (OLD.listprice = NEW.listprice)) |
|
12 |
AND ((OLD.sellprice IS NULL AND NEW.sellprice IS NULL) OR (OLD.sellprice = NEW.sellprice)) |
|
13 |
AND ((OLD.price_factor_id IS NULL AND NEW.price_factor_id IS NULL) OR |
|
14 |
( (SELECT factor FROM price_factors WHERE price_factors.id = OLD.price_factor_id) = (SELECT factor FROM price_factors WHERE price_factors.id = NEW.price_factor_id) )) |
|
15 |
THEN |
|
16 |
RETURN NEW; |
|
17 |
END IF; |
|
18 |
|
|
19 |
INSERT INTO parts_price_history (part_id, lastcost, listprice, sellprice, price_factor, valid_from) |
|
20 |
VALUES (NEW.id, NEW.lastcost, NEW.listprice, NEW.sellprice, COALESCE((SELECT factor FROM price_factors WHERE price_factors.id = NEW.price_factor_id), 1), now()); |
|
21 |
|
|
22 |
RETURN NEW; |
|
23 |
END; |
|
24 |
$$ LANGUAGE plpgsql; |
Auch abrufbar als: Unified diff
Preisfaktor mit in Preishistorie aufnehmen: DB und Rose