-- phpMyAdmin SQL Dump
-- version 4.8.5
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3306
-- Generation Time: Feb 20, 2021 at 06:42 PM
-- Server version: 5.7.26
-- PHP Version: 7.2.18

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `racuni2021`
--
CREATE DATABASE IF NOT EXISTS `racuni2021` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `racuni2021`;

-- --------------------------------------------------------

--
-- Table structure for table `gradovi`
--

DROP TABLE IF EXISTS `gradovi`;
CREATE TABLE IF NOT EXISTS `gradovi` (
  `grad` varchar(50) NOT NULL,
  PRIMARY KEY (`grad`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `gradovi`
--

INSERT INTO `gradovi` (`grad`) VALUES
('Beograd'),
('Kragujevac'),
('Nis'),
('Novi Sad');

-- --------------------------------------------------------

--
-- Table structure for table `korisnici`
--

DROP TABLE IF EXISTS `korisnici`;
CREATE TABLE IF NOT EXISTS `korisnici` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ime_prezime` varchar(150) NOT NULL,
  `grad` varchar(50) NOT NULL,
  `adresa` varchar(150) NOT NULL,
  `stan` int(5) NOT NULL,
  `pin` varchar(4) NOT NULL,
  `novac` double NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_grad` (`grad`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `korisnici`
--

INSERT INTO `korisnici` (`id`, `ime_prezime`, `grad`, `adresa`, `stan`, `pin`, `novac`) VALUES
(1, 'Petar Petrovic', 'Beograd', 'Nehruova 15', 1, '1234', 21868.63),
(2, 'Tijana Tijanic', 'Nis', 'Beogradska 72', 3, '4321', 12000),
(3, 'Sara Saric', 'Kragujevac', 'Cetinjska 23', 11, '1234', 16513.15),
(4, 'Bil Gejts', 'Beograd', 'BW St. Regis 1', 9000, '2455', 500000000000000),
(5, 'Niko Nikic', 'Novi Sad', 'Nema ulice', 0, '0000', 150);

-- --------------------------------------------------------

--
-- Table structure for table `racuni`
--

DROP TABLE IF EXISTS `racuni`;
CREATE TABLE IF NOT EXISTS `racuni` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tip` varchar(50) NOT NULL,
  `korisnik` int(11) NOT NULL,
  `mesec` varchar(10) NOT NULL,
  `iznos` double NOT NULL,
  `placen` tinyint(1) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `jedinstveno` (`tip`,`korisnik`,`mesec`) USING BTREE,
  KEY `fk_korisnik` (`korisnik`),
  KEY `fk_tip` (`tip`)
) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `racuni`
--

INSERT INTO `racuni` (`id`, `tip`, `korisnik`, `mesec`, `iznos`, `placen`) VALUES
(1, 'infostan', 4, '2021-02', 13134.52, 0),
(2, 'infostan', 4, '2021-01', 12077.01, 1),
(3, 'mobilni', 5, '2021-02', 611.2, 0),
(4, 'infostan', 4, '2020-12', 14806.89, 0),
(5, 'mobilni', 5, '2021-01', 611.66, 0),
(6, 'infostan', 3, '2021-02', 4587.2, 1),
(7, 'mobilni', 4, '2021-02', 3199, 0),
(8, 'infostan', 1, '2021-02', 10803.26, 0),
(9, 'infostan', 5, '2021-02', 521.09, 1),
(10, 'kablovska', 2, '2021-02', 2999, 1),
(11, 'infostan', 3, '2021-01', 4567.2, 1),
(12, 'mobilni', 4, '2021-01', 3199, 0),
(13, 'struja', 2, '2021-02', 4093.49, 0),
(14, 'mobilni', 1, '2021-02', 599, 0),
(15, 'infostan', 3, '2020-12', 4574.14, 1),
(16, 'infostan', 1, '2021-01', 10000.38, 0),
(17, 'struja', 1, '2021-02', 2211.38, 1),
(18, 'infostan', 5, '2021-01', 568.31, 1),
(19, 'kablovska', 2, '2021-01', 2999, 1),
(20, 'struja', 2, '2021-01', 3506.66, 1),
(21, 'struja', 1, '2021-01', 2603.35, 0),
(22, 'infostan', 5, '2020-12', 896.87, 0),
(23, 'struja', 2, '2020-12', 3528.1, 1),
(24, 'infostan', 1, '2020-12', 9999.08, 1),
(25, 'infostan', 1, '2020-11', 10395.05, 0),
(26, 'infostan', 5, '2020-11', 945.6, 1),
(27, 'struja', 3, '2021-02', 3739.43, 0),
(28, 'kablovska', 4, '2021-02', 3999, 1),
(29, 'kablovska', 4, '2021-01', 3999, 0),
(30, 'mobilni', 3, '2021-02', 1799, 0),
(31, 'mobilni', 5, '2020-12', 599, 0),
(32, 'struja', 4, '2021-02', 2755.97, 1),
(33, 'struja', 5, '2021-02', 678.35, 0),
(34, 'infostan', 2, '2021-02', 4792.11, 1),
(35, 'kablovska', 1, '2021-02', 2899, 1),
(36, 'struja', 5, '2021-01', 725.03, 0),
(37, 'infostan', 2, '2021-01', 4067.09, 1),
(38, 'mobilni', 3, '2021-01', 1849, 1),
(39, 'kablovska', 1, '2021-01', 2899, 0),
(40, 'kablovska', 1, '2020-12', 2899, 1),
(41, 'infostan', 2, '2020-12', 4833.43, 1),
(42, 'infostan', 2, '2020-11', 4672.24, 1),
(44, 'kablovska', 2, '2020-12', 2999, 0),
(45, 'struja', 5, '2020-12', 513.28, 0),
(46, 'struja', 5, '2020-11', 695.49, 1),
(47, 'struja', 4, '2021-01', 3247.8, 1),
(48, 'struja', 4, '2020-12', 2698.93, 0),
(49, 'mobilni', 1, '2021-01', 744.63, 1),
(50, 'mobilni', 1, '2020-12', 599, 1),
(51, 'mobilni', 3, '2020-12', 1799, 1),
(52, 'struja', 1, '2020-12', 3336.33, 0);

-- --------------------------------------------------------

--
-- Table structure for table `tipovi_racuna`
--

DROP TABLE IF EXISTS `tipovi_racuna`;
CREATE TABLE IF NOT EXISTS `tipovi_racuna` (
  `tip` varchar(50) NOT NULL,
  PRIMARY KEY (`tip`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tipovi_racuna`
--

INSERT INTO `tipovi_racuna` (`tip`) VALUES
('infostan'),
('kablovska'),
('mobilni'),
('struja');

--
-- Constraints for dumped tables
--

--
-- Constraints for table `korisnici`
--
ALTER TABLE `korisnici`
  ADD CONSTRAINT `fk_grad` FOREIGN KEY (`grad`) REFERENCES `gradovi` (`grad`) ON UPDATE CASCADE;

--
-- Constraints for table `racuni`
--
ALTER TABLE `racuni`
  ADD CONSTRAINT `fk_korisnik` FOREIGN KEY (`korisnik`) REFERENCES `korisnici` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_tip` FOREIGN KEY (`tip`) REFERENCES `tipovi_racuna` (`tip`) ON UPDATE CASCADE;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
