create table OrganizacionaJedinica ( org_id int not null PRIMARY KEY enable, naziv varchar2(50) not null );
create table Uposlenik ( uposlenik_id int not null PRIMARY KEY enable, org_id int, ime varchar2(50) not null, prezime varchar2(50) not null, datum_zaposlenja date, telefon varchar2(30), plata int, mail varchar2(100), username varchar2(40), password varchar2(40), CONSTRAINT fk_Uposlenik_org_id FOREIGN KEY (org_id) REFERENCES OrganizacionaJedinica(org_id) enable );
create table Kupac( kupac_id int not null PRIMARY KEY enable, naziv varchar2(100) not null, adresa varchar2(100), telefon varchar2(30), mail varchar2(100) );
create table Artikal ( artikal_id int not null PRIMARY KEY enable, naziv_artikla varchar2(50) not null, vrsta_artikla varchar2(50), cijena number(8,2) );
create table NarudzbenicaKupca ( narudzbenica_id int not null PRIMARY KEY enable, kupac_id int, uposlenik_id int, datum_narudzbe date, CONSTRAINT fk_NaruKupca_kupac_id FOREIGN KEY (kupac_id) REFERENCES Kupac (kupac_id) enable, CONSTRAINT fk_NaruKupca_uposlenik_id FOREIGN KEY (uposlenik_id) REFERENCES Uposlenik (uposlenik_id) enable );
create table StavkaNarudzbeniceKupca ( redni_br int not null, narudzbenica_id int REFERENCES NarudzbenicaKupca (narudzbenica_id) not null, artikal_id int, naru_kolicina int, PRIMARY KEY (redni_br, narudzbenica_id) enable, CONSTRAINT fk_StavkaNaruKupca_artikal_id FOREIGN KEY (artikal_id) REFERENCES Artikal (artikal_id) enable );
create table OtpremnicaKupca ( otpremnica_id int not null PRIMARY KEY enable, narudzbenica_id int, kupac_id int, datum_otpreme date, CONSTRAINT fk_OtprKupca_narudzbenica_id FOREIGN KEY (narudzbenica_id) REFERENCES NarudzbenicaKupca (narudzbenica_id) enable, CONSTRAINT fk_OtpremnicaKupca_kupac_id FOREIGN KEY (kupac_id) REFERENCES Kupac (kupac_id) enable );
create table StavkaOtpremniceKupca ( redni_br int not null, otpremnica_id int REFERENCES OtpremnicaKupca (otpremnica_id) not null, artikal_id int, otpr_kolicina int, PRIMARY KEY (redni_br, otpremnica_id) enable, CONSTRAINT fk_StavkaOtprKupca_artikal_id FOREIGN KEY (artikal_id) REFERENCES Artikal (artikal_id) enable );
create table PlatnaKartica ( kartica_id int not null, kupac_id int REFERENCES Kupac (kupac_id) not null, datum_isteka date, PRIMARY KEY (kartica_id, kupac_id) enable );
create table Racun ( racun_id int not null PRIMARY KEY enable, otpremnica_id int, kupac_id int, datum date,
iznos number(8,2), CONSTRAINT fk_Otpremnica_otpremnica_id FOREIGN KEY (otpremnica_id) REFERENCES OtpremnicaKupca (otpremnica_id) enable, CONSTRAINT fk_Kupac_kupac_id FOREIGN KEY (kupac_id) REFERENCES Kupac (kupac_id) enable );
create table Uplatnica ( uplatnica_id int not null PRIMARY KEY enable, kartica_id int, kupac_id int, racun_id int, datum_uplate date, iznos_uplate number(8,2), CONSTRAINT fk_PlatnaKartica_kartica_id FOREIGN KEY (kartica_id, kupac_id) REFERENCES PlatnaKartica (kartica_id, kupac_id) enable, CONSTRAINT fk_Racun_racun_id FOREIGN KEY (racun_id) REFERENCES Racun (racun_id) enable );
CREATE SEQUENCE seq_uposlenik MINVALUE 1 START WITH 1 INCREMENT BY 1 CACHE 10;
CREATE SEQUENCE seq_organizaciona_jed MINVALUE 10 START WITH 10 INCREMENT BY 5 CACHE 10;