text: -- phpMyAdmin SQL Dump
  -- version 4.9.1
  -- https://www.phpmyadmin.net/
  --
  -- Host: 127.0.0.1
  -- Generation Time: Jan 02, 2020 at 03:36 PM
  -- Server version: 10.4.8-MariaDB
  -- PHP Version: 7.3.11
  
  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: `tokoonline`
  --
  
  -- --------------------------------------------------------
  
  --
  -- Table structure for table `tb_barang`
  --
  
  CREATE TABLE `tb_barang` (
    `id_brg` int(11) NOT NULL,
    `nama_brg` varchar(120) NOT NULL,
    `keterangan_brg` varchar(225) NOT NULL,
    `kategori_brg` varchar(60) NOT NULL,
    `harga_brg` int(11) NOT NULL,
    `stok_brg` int(4) NOT NULL,
    `gambar_brg` text NOT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  
  --
  -- Dumping data for table `tb_barang`
  --
  
  INSERT INTO `tb_barang` (`id_brg`, `nama_brg`, `keterangan_brg`, `kategori_brg`, `harga_brg`, `stok_brg`, `gambar_brg`) VALUES
  (3, 'Kamera', 'Kamera merek canon dengan lensa yang bisa diputar', 'Electronics', 450000, 7, 'kamera.jpg'),
  (8, 'Laptop Dewa', 'Jan maen maen dengan laptop gahar seperti ini ya men', 'Electronics', 680000, 12, 'laptop.jpg'),
  (13, 'Henphone', 'Ini adalah Henphone anti kura kura men', 'Electronics', 245000, 21, 'hp.jpg'),
  (14, 'Sepatu Boljug', 'Boljuh adalah Boleh Juga kalo gatau', 'Clothes', 120000, 4, 'sepatuallstar.png'),
  (15, 'Sepatu Lagi Dungz', 'Pokonya bagus dah gausah nanya nanya lagi', 'Clothes', 35000, 8, 'sepatu.jpg');
  
  -- --------------------------------------------------------
  
  --
  -- Table structure for table `tb_invoice`
  --
  
  CREATE TABLE `tb_invoice` (
    `id` int(11) NOT NULL,
    `nama` varchar(56) NOT NULL,
    `alamat` varchar(256) NOT NULL,
    `tgl_pesan` datetime NOT NULL,
    `batas_bayar` datetime NOT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  
  --
  -- Dumping data for table `tb_invoice`
  --
  
  INSERT INTO `tb_invoice` (`id`, `nama`, `alamat`, `tgl_pesan`, `batas_bayar`) VALUES
  (8, 'Bagus Surapadi', 'Dimana mana Saja', '2019-12-28 09:53:47', '2019-12-29 09:53:47'),
  (9, 'Sodara Osas', 'Di Afrika Selatan Deket Perumahan OShas', '2019-12-28 13:48:06', '2019-12-29 13:48:06');
  
  -- --------------------------------------------------------
  
  --
  -- Table structure for table `tb_pesanan`
  --
  
  CREATE TABLE `tb_pesanan` (
    `id` int(11) NOT NULL,
    `id_invoice` int(11) NOT NULL,
    `id_brg` int(11) NOT NULL,
    `nama_brg` varchar(50) NOT NULL,
    `jumlah_brg` int(3) NOT NULL,
    `harga_brg` int(10) NOT NULL,
    `pilihan` text NOT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  
  --
  -- Dumping data for table `tb_pesanan`
  --
  
  INSERT INTO `tb_pesanan` (`id`, `id_invoice`, `id_brg`, `nama_brg`, `jumlah_brg`, `harga_brg`, `pilihan`) VALUES
  (9, 8, 8, 'Laptop Dewa', 1, 680000, ''),
  (10, 8, 13, 'Henphone', 1, 245000, ''),
  (11, 8, 14, 'Sepatu Boljug', 2, 120000, ''),
  (12, 8, 15, 'Sepatu Lagi Dungz', 1, 35000, ''),
  (13, 9, 8, 'Laptop Dewa', 3, 680000, ''),
  (14, 9, 15, 'Sepatu Lagi Dungz', 1, 35000, ''),
  (15, 9, 14, 'Sepatu Boljug', 2, 120000, ''),
  (16, 9, 3, 'Kamera', 1, 450000, '');
  
  --
  -- Triggers `tb_pesanan`
  --
  DELIMITER $$
  CREATE TRIGGER `pesanan_penjualan` AFTER INSERT ON `tb_pesanan` FOR EACH ROW BEGIN
  		UPDATE tb_barang SET stok_brg = stok_brg-NEW.jumlah_brg
      	WHERE id_brg = NEW.id_brg;
  END
  $$
  DELIMITER ;
  
  -- --------------------------------------------------------
  
  --
  -- Table structure for table `tb_user`
  --
  
  CREATE TABLE `tb_user` (
    `id` int(11) NOT NULL,
    `name` varchar(56) NOT NULL,
    `username` varchar(56) NOT NULL,
    `password` varchar(56) NOT NULL,
    `role_id` tinyint(1) NOT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  
  --
  -- Dumping data for table `tb_user`
  --
  
  INSERT INTO `tb_user` (`id`, `name`, `username`, `password`, `role_id`) VALUES
  (1, 'admin', 'admin', 'admin123', 1),
  (2, 'Bambank Surapadi', 'UcupKucup', '1234321', 2);
  
  --
  -- Indexes for dumped tables
  --
  
  --
  -- Indexes for table `tb_barang`
  --
  ALTER TABLE `tb_barang`
    ADD PRIMARY KEY (`id_brg`);
  
  --
  -- Indexes for table `tb_invoice`
  --
  ALTER TABLE `tb_invoice`
    ADD PRIMARY KEY (`id`);
  
  --
  -- Indexes for table `tb_pesanan`
  --
  ALTER TABLE `tb_pesanan`
    ADD PRIMARY KEY (`id`);
  
  --
  -- Indexes for table `tb_user`
  --
  ALTER TABLE `tb_user`
    ADD PRIMARY KEY (`id`);
  
  --
  -- AUTO_INCREMENT for dumped tables
  --
  
  --
  -- AUTO_INCREMENT for table `tb_barang`
  --
  ALTER TABLE `tb_barang`
    MODIFY `id_brg` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;
  
  --
  -- AUTO_INCREMENT for table `tb_invoice`
  --
  ALTER TABLE `tb_invoice`
    MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
  
  --
  -- AUTO_INCREMENT for table `tb_pesanan`
  --
  ALTER TABLE `tb_pesanan`
    MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17;
  
  --
  -- AUTO_INCREMENT for table `tb_user`
  --
  ALTER TABLE `tb_user`
    MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
  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 */;
  