2019-06-10 18:27:57 +02:00
|
|
|
CREATE TABLE `zamowienia`
|
2019-06-10 12:19:10 +02:00
|
|
|
(
|
2019-06-10 18:27:57 +02:00
|
|
|
`id` int PRIMARY KEY,
|
|
|
|
`data_zamowienia` datetime,
|
|
|
|
`id_faktury` int,
|
|
|
|
`id_klienta` int
|
2019-06-10 12:19:10 +02:00
|
|
|
);
|
|
|
|
|
2019-06-10 18:27:57 +02:00
|
|
|
CREATE TABLE `klienci`
|
2019-06-10 12:19:10 +02:00
|
|
|
(
|
2019-06-10 18:27:57 +02:00
|
|
|
`id` int PRIMARY KEY,
|
|
|
|
`imie` varchar(255),
|
|
|
|
`nazwisko` varchar(255),
|
|
|
|
`miasto` varchar(255),
|
|
|
|
`ulica` varchar(255),
|
|
|
|
`nr_domu` varchar(255),
|
|
|
|
`nr_mieszkania` varchar(255),
|
|
|
|
`nazwa_firmy` varchar(255),
|
|
|
|
`nip` varchar(255)
|
2019-06-10 12:19:10 +02:00
|
|
|
);
|
|
|
|
|
2019-06-10 18:27:57 +02:00
|
|
|
CREATE TABLE `dostawcy`
|
2019-06-10 12:19:10 +02:00
|
|
|
(
|
2019-06-10 18:27:57 +02:00
|
|
|
`id` int PRIMARY KEY,
|
|
|
|
`nazwa_firmy` varchar(255),
|
|
|
|
`nip` varchar(255),
|
|
|
|
`miasto` varchar(255),
|
|
|
|
`ulica` varchar(255),
|
|
|
|
`nr_domu` varchar(255),
|
|
|
|
`nr_mieszkania` varchar(255)
|
2019-06-10 12:19:10 +02:00
|
|
|
);
|
|
|
|
|
2019-06-10 18:27:57 +02:00
|
|
|
CREATE TABLE `zamowienia_wiersze`
|
2019-06-10 12:19:10 +02:00
|
|
|
(
|
2019-06-10 18:27:57 +02:00
|
|
|
`id` int PRIMARY KEY,
|
|
|
|
`zamowienie_id` int,
|
|
|
|
`produkt_id` int,
|
|
|
|
`ilosc` int,
|
|
|
|
`cena` double,
|
|
|
|
`kwota_sprzedazy` double,
|
|
|
|
`koszt` double,
|
|
|
|
`kwota_kosztu` double,
|
|
|
|
`zysk` double
|
2019-06-10 12:19:10 +02:00
|
|
|
);
|
|
|
|
|
2019-06-10 18:27:57 +02:00
|
|
|
CREATE TABLE `produkty`
|
2019-06-10 12:19:10 +02:00
|
|
|
(
|
2019-06-10 18:27:57 +02:00
|
|
|
`id` int PRIMARY KEY,
|
|
|
|
`nazwa_produktu` varchar(255),
|
|
|
|
`cena` int
|
2019-06-10 12:19:10 +02:00
|
|
|
);
|
|
|
|
|
2019-06-10 18:27:57 +02:00
|
|
|
CREATE TABLE `produkty_przepisy`
|
2019-06-10 12:19:10 +02:00
|
|
|
(
|
2019-06-10 18:27:57 +02:00
|
|
|
`produkt_id` int,
|
|
|
|
`skladnik_id` int,
|
|
|
|
`ilosc` double
|
2019-06-10 12:19:10 +02:00
|
|
|
);
|
|
|
|
|
2019-06-10 18:27:57 +02:00
|
|
|
CREATE TABLE `skladniki`
|
2019-06-10 12:19:10 +02:00
|
|
|
(
|
2019-06-10 18:27:57 +02:00
|
|
|
`id` int PRIMARY KEY,
|
|
|
|
`nazwa_skladnika` varchar(255),
|
|
|
|
`koszt` double
|
2019-06-10 12:19:10 +02:00
|
|
|
);
|
|
|
|
|
2019-06-10 18:27:57 +02:00
|
|
|
CREATE TABLE `sladniki_transakcje`
|
|
|
|
(
|
|
|
|
`id` int PRIMARY KEY,
|
|
|
|
`data_transakcji` datetime,
|
|
|
|
`skladnik_id` int,
|
|
|
|
`zamowienia_wiersze_id` int,
|
|
|
|
`zakupy_wiersze_id` int,
|
|
|
|
`typ_transakcji` int,
|
|
|
|
`ilosc` double,
|
|
|
|
`koszt` double,
|
|
|
|
`cena` double,
|
|
|
|
`kwota_kosztu` double,
|
|
|
|
`kwota_sprzedazy` double,
|
|
|
|
`zysk` double
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE `zakupy`
|
|
|
|
(
|
|
|
|
`id` int PRIMARY KEY,
|
|
|
|
`id_faktury` int,
|
|
|
|
`id_dostawcy` int,
|
|
|
|
`data` datetime
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE `zakupy_wiersze`
|
|
|
|
(
|
|
|
|
`id` int PRIMARY KEY,
|
|
|
|
`id_zakupu` int,
|
|
|
|
`skladnik_id` int,
|
|
|
|
`ilosc` double,
|
|
|
|
`koszt` double
|
|
|
|
);
|
|
|
|
|
|
|
|
ALTER TABLE `zamowienia` ADD FOREIGN KEY (`id_klienta`) REFERENCES `klienci` (`id`);
|
|
|
|
|
|
|
|
ALTER TABLE `zamowienia_wiersze` ADD FOREIGN KEY (`zamowienie_id`) REFERENCES `zamowienia` (`id`);
|
|
|
|
|
|
|
|
ALTER TABLE `zamowienia_wiersze` ADD FOREIGN KEY (`produkt_id`) REFERENCES `produkty` (`id`);
|
|
|
|
|
|
|
|
ALTER TABLE `produkty_przepisy` ADD FOREIGN KEY (`produkt_id`) REFERENCES `produkty` (`id`);
|
|
|
|
|
|
|
|
ALTER TABLE `produkty_przepisy` ADD FOREIGN KEY (`skladnik_id`) REFERENCES `skladniki` (`id`);
|
|
|
|
|
|
|
|
ALTER TABLE `sladniki_transakcje` ADD FOREIGN KEY (`skladnik_id`) REFERENCES `skladniki` (`id`);
|
2019-06-10 12:19:10 +02:00
|
|
|
|
2019-06-10 18:27:57 +02:00
|
|
|
ALTER TABLE `sladniki_transakcje` ADD FOREIGN KEY (`zamowienia_wiersze_id`) REFERENCES `zamowienia_wiersze` (`id`);
|
2019-06-10 12:19:10 +02:00
|
|
|
|
2019-06-10 18:27:57 +02:00
|
|
|
ALTER TABLE `sladniki_transakcje` ADD FOREIGN KEY (`zakupy_wiersze_id`) REFERENCES `zakupy_wiersze` (`id`);
|
2019-06-10 12:19:10 +02:00
|
|
|
|
2019-06-10 18:27:57 +02:00
|
|
|
ALTER TABLE `zakupy` ADD FOREIGN KEY (`id_dostawcy`) REFERENCES `dostawcy` (`id`);
|
2019-06-10 12:19:10 +02:00
|
|
|
|
2019-06-10 18:27:57 +02:00
|
|
|
ALTER TABLE `zakupy_wiersze` ADD FOREIGN KEY (`id_zakupu`) REFERENCES `zakupy` (`id`);
|
2019-06-10 12:19:10 +02:00
|
|
|
|
2019-06-10 18:27:57 +02:00
|
|
|
ALTER TABLE `zakupy_wiersze` ADD FOREIGN KEY (`skladnik_id`) REFERENCES `skladniki` (`id`);
|
2019-06-10 12:19:10 +02:00
|
|
|
|