1 -- @tag: delivery_orders
2 -- @description: Lieferscheine als eigener Beleg
3 -- @depends: release_2_4_3 price_factors
4 CREATE TABLE delivery_orders (
5 id integer NOT NULL DEFAULT nextval('id'),
6 donumber text NOT NULL,
8 transdate date DEFAULT now(),
16 closed boolean DEFAULT false,
17 delivered boolean DEFAULT false,
20 department_id integer,
25 globalproject_id integer,
27 transaction_description text,
30 itime timestamp DEFAULT now(),
34 FOREIGN KEY (vendor_id) REFERENCES vendor (id),
35 FOREIGN KEY (customer_id) REFERENCES customer (id),
36 FOREIGN KEY (employee_id) REFERENCES employee (id),
37 FOREIGN KEY (cp_id) REFERENCES contacts (cp_id),
38 FOREIGN KEY (language_id) REFERENCES language (id),
39 FOREIGN KEY (globalproject_id) REFERENCES project (id),
40 FOREIGN KEY (salesman_id) REFERENCES employee (id)
43 CREATE TRIGGER mtime_delivery_orders BEFORE UPDATE ON delivery_orders
44 FOR EACH ROW EXECUTE PROCEDURE set_mtime();
46 CREATE SEQUENCE delivery_order_items_id;
48 CREATE TABLE delivery_order_items (
49 id integer NOT NULL DEFAULT nextval('delivery_order_items_id'),
50 delivery_order_id integer NOT NULL,
51 parts_id integer NOT NULL,
54 sellprice numeric(15,5),
65 lastcost numeric(15,5),
66 price_factor_id integer,
67 price_factor numeric(15,5) DEFAULT 1,
68 marge_price_factor numeric(15,5) DEFAULT 1,
70 itime timestamp DEFAULT now(),
74 FOREIGN KEY (delivery_order_id) REFERENCES delivery_orders (id),
75 FOREIGN KEY (parts_id) REFERENCES parts (id),
76 FOREIGN KEY (project_id) REFERENCES project (id),
77 FOREIGN KEY (price_factor_id) REFERENCES price_factors (id)
80 CREATE TRIGGER mtime_delivery_order_items_id BEFORE UPDATE ON delivery_order_items
81 FOR EACH ROW EXECUTE PROCEDURE set_mtime();
83 ALTER TABLE defaults ADD COLUMN pdonumber text;
84 ALTER TABLE defaults ADD COLUMN sdonumber text;
85 UPDATE defaults SET pdonumber = '0', sdonumber = '0';
87 CREATE TABLE delivery_order_items_stock (
88 id integer NOT NULL DEFAULT nextval('id'),
89 delivery_order_item_id integer NOT NULL,
91 qty numeric(15,5) NOT NULL,
92 unit varchar(20) NOT NULL,
93 warehouse_id integer NOT NULL,
94 bin_id integer NOT NULL,
97 itime timestamp DEFAULT now(),
101 FOREIGN KEY (delivery_order_item_id) REFERENCES delivery_order_items (id),
102 FOREIGN KEY (warehouse_id) REFERENCES warehouse (id),
103 FOREIGN KEY (bin_id) REFERENCES bin (id)
106 CREATE TRIGGER mtime_delivery_order_items_stock BEFORE UPDATE ON delivery_order_items_stock
107 FOR EACH ROW EXECUTE PROCEDURE set_mtime();