Revision 58190585
Von Moritz Bunkus vor mehr als 8 Jahren hinzugefügt
SL/DB/Helper/ALL.pm | ||
---|---|---|
71 | 71 |
use SL::DB::OrderItem; |
72 | 72 |
use SL::DB::Part; |
73 | 73 |
use SL::DB::PartsGroup; |
74 |
use SL::DB::PartsPriceHistory; |
|
74 | 75 |
use SL::DB::PaymentTerm; |
75 | 76 |
use SL::DB::PeriodicInvoice; |
76 | 77 |
use SL::DB::PeriodicInvoicesConfig; |
SL/DB/Helper/Mappings.pm | ||
---|---|---|
152 | 152 |
oe => 'order', |
153 | 153 |
parts => 'part', |
154 | 154 |
partsgroup => 'parts_group', |
155 |
parts_price_history => 'PartsPriceHistory', |
|
155 | 156 |
payment_terms => 'payment_term', |
156 | 157 |
periodic_invoices => 'periodic_invoice', |
157 | 158 |
periodic_invoices_configs => 'periodic_invoices_config', |
SL/DB/Manager/PartsPriceHistory.pm | ||
---|---|---|
1 |
package SL::DB::Manager::PartsPriceHistory; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use parent qw(SL::DB::Helper::Manager); |
|
6 |
|
|
7 |
sub object_class { 'SL::DB::PartsPriceHistory' } |
|
8 |
|
|
9 |
__PACKAGE__->make_manager_methods; |
|
10 |
|
|
11 |
1; |
SL/DB/MetaSetup/PartsPriceHistory.pm | ||
---|---|---|
1 |
# This file has been auto-generated. Do not modify it; it will be overwritten |
|
2 |
# by rose_auto_create_model.pl automatically. |
|
3 |
package SL::DB::PartsPriceHistory; |
|
4 |
|
|
5 |
use strict; |
|
6 |
|
|
7 |
use parent qw(SL::DB::Object); |
|
8 |
|
|
9 |
__PACKAGE__->meta->table('parts_price_history'); |
|
10 |
|
|
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 }, |
|
18 |
); |
|
19 |
|
|
20 |
__PACKAGE__->meta->primary_key_columns([ 'id' ]); |
|
21 |
|
|
22 |
__PACKAGE__->meta->foreign_keys( |
|
23 |
part => { |
|
24 |
class => 'SL::DB::Part', |
|
25 |
key_columns => { part_id => 'id' }, |
|
26 |
}, |
|
27 |
); |
|
28 |
|
|
29 |
1; |
|
30 |
; |
SL/DB/PartsPriceHistory.pm | ||
---|---|---|
1 |
# This file has been auto-generated only because it didn't exist. |
|
2 |
# Feel free to modify it at will; it will not be overwritten automatically. |
|
3 |
|
|
4 |
package SL::DB::PartsPriceHistory; |
|
5 |
|
|
6 |
use strict; |
|
7 |
|
|
8 |
use SL::DB::MetaSetup::PartsPriceHistory; |
|
9 |
use SL::DB::Manager::PartsPriceHistory; |
|
10 |
|
|
11 |
__PACKAGE__->meta->initialize; |
|
12 |
|
|
13 |
1; |
sql/Pg-upgrade2/add_parts_price_history.sql | ||
---|---|---|
1 |
-- @tag: add_parts_price_history |
|
2 |
-- @description: Tabelle für Entwicklung der Stammdatenpreise |
|
3 |
-- @depends: release_3_4_0 |
|
4 |
DROP TRIGGER IF EXISTS add_parts_price_history_entry_after_changes_on_parts ON parts; |
|
5 |
DROP FUNCTION IF EXISTS add_parts_price_history_entry(); |
|
6 |
DROP TABLE IF EXISTS parts_price_history; |
|
7 |
|
|
8 |
CREATE TABLE parts_price_history ( |
|
9 |
id SERIAL, |
|
10 |
part_id INTEGER NOT NULL, |
|
11 |
valid_from TIMESTAMP NOT NULL, |
|
12 |
lastcost NUMERIC(15, 5), |
|
13 |
listprice NUMERIC(15, 5), |
|
14 |
sellprice NUMERIC(15, 5), |
|
15 |
|
|
16 |
PRIMARY KEY (id), |
|
17 |
FOREIGN KEY (part_id) REFERENCES parts (id) ON DELETE CASCADE |
|
18 |
); |
|
19 |
|
|
20 |
INSERT INTO parts_price_history (part_id, valid_from, lastcost, listprice, sellprice) |
|
21 |
SELECT id, COALESCE(COALESCE(mtime, itime), now()), lastcost, listprice, sellprice |
|
22 |
FROM parts; |
|
23 |
|
|
24 |
CREATE FUNCTION add_parts_price_history_entry() RETURNS "trigger" AS $$ |
|
25 |
BEGIN |
|
26 |
IF (TG_OP = 'UPDATE') AND (OLD.lastcost = NEW.lastcost) AND (OLD.listprice = NEW.listprice) AND (OLD.sellprice = NEW.sellprice) THEN |
|
27 |
RETURN NEW; |
|
28 |
END IF; |
|
29 |
|
|
30 |
INSERT INTO parts_price_history (part_id, lastcost, listprice, sellprice, valid_from) |
|
31 |
VALUES (NEW.id, NEW.lastcost, NEW.listprice, NEW.sellprice, now()); |
|
32 |
|
|
33 |
RETURN NEW; |
|
34 |
END; |
|
35 |
$$ LANGUAGE plpgsql; |
|
36 |
|
|
37 |
CREATE TRIGGER add_parts_price_history_entry_after_changes_on_parts |
|
38 |
AFTER INSERT OR UPDATE on parts |
|
39 |
FOR EACH ROW EXECUTE PROCEDURE add_parts_price_history_entry(); |
Auch abrufbar als: Unified diff
Artikelpreishistorie automatisch über Trigger speichern