Skip to content

Commit

Permalink
Merge branches 'main' and 'main' of https://github.com/ReEkaF/TA_PAW
Browse files Browse the repository at this point in the history
  • Loading branch information
UmarMuchtar committed Nov 26, 2023
2 parents 43498ec + f14913c commit 713060f
Show file tree
Hide file tree
Showing 141 changed files with 4,599 additions and 4,146 deletions.
487 changes: 0 additions & 487 deletions SQL/store_TA.sql

This file was deleted.

280 changes: 114 additions & 166 deletions sql/TA.sql → _sql/PAW2023-1-E05_dump.sql

Large diffs are not rendered by default.

180 changes: 180 additions & 0 deletions _sql/ddl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*==============================================================*/
/* DBMS name: MySQL 5.0 */
/* Created on: 21/11/2023 21:33:12 */
/*==============================================================*/


drop table if exists cart_items;

drop table if exists categories;

drop table if exists customers;

drop table if exists order_details;

drop table if exists orders;

drop table if exists payment_methods;

drop table if exists plants;

drop table if exists roles;

drop table if exists staffs;

drop table if exists suppliers;

/*==============================================================*/
/* Table: cart_items */
/*==============================================================*/
create table cart_items
(
customer_id int not null,
plant_id int not null,
cart_item_qty int not null,
primary key (customer_id, plant_id)
);

/*==============================================================*/
/* Table: categories */
/*==============================================================*/
create table categories
(
category_id int not null auto_increment,
category_name varchar(50) not null,
primary key (category_id)
);

/*==============================================================*/
/* Table: customers */
/*==============================================================*/
create table customers
(
customer_id int not null auto_increment,
customer_name varchar(255) not null,
customer_phone varchar(17) not null,
customer_email varchar(255) not null,
customer_password varchar(255) not null,
customer_photo varchar(255),
primary key (customer_id)
);

/*==============================================================*/
/* Table: order_details */
/*==============================================================*/
create table order_details
(
order_detail_id int not null auto_increment,
order_id int not null,
plant_id int not null,
order_detail_qty int not null,
order_detail_unit_price int not null,
primary key (order_detail_id)
);

/*==============================================================*/
/* Table: orders */
/*==============================================================*/
create table orders
(
order_id int not null auto_increment,
customer_id int not null,
payment_method_id int not null,
order_date date not null,
order_status varchar(50) not null,
order_total_price int not null,
primary key (order_id)
);

/*==============================================================*/
/* Table: payment_methods */
/*==============================================================*/
create table payment_methods
(
payment_method_id int not null auto_increment,
payment_method_name varchar(255) not null,
payment_method_number varchar(50) not null,
payment_method_bank varchar(50) not null,
payment_method_logo varchar(255) not null,
primary key (payment_method_id)
);

/*==============================================================*/
/* Table: plants */
/*==============================================================*/
create table plants
(
plant_id int not null auto_increment,
supplier_id int not null,
category_id int not null,
plant_name varchar(255) not null,
plant_price int not null,
plant_stock int not null,
plant_photo varchar(255) not null,
primary key (plant_id)
);

/*==============================================================*/
/* Table: roles */
/*==============================================================*/
create table roles
(
role_id int not null auto_increment,
role_name varchar(50) not null,
primary key (role_id)
);

/*==============================================================*/
/* Table: staffs */
/*==============================================================*/
create table staffs
(
staff_id int not null auto_increment,
role_id int not null,
staff_name varchar(255) not null,
staff_phone varchar(17) not null,
staff_email varchar(255) not null,
staff_password varchar(255) not null,
staff_photo varchar(255),
primary key (staff_id)
);

/*==============================================================*/
/* Table: suppliers */
/*==============================================================*/
create table suppliers
(
supplier_id int not null auto_increment,
supplier_name varchar(255) not null,
supplier_phone varchar(17) not null,
supplier_address text not null,
primary key (supplier_id)
);

alter table cart_items add constraint FK_cart_item_customer foreign key (customer_id)
references customers (customer_id) on delete restrict on update restrict;

alter table cart_items add constraint FK_cart_item_plant foreign key (plant_id)
references plants (plant_id) on delete restrict on update restrict;

alter table order_details add constraint FK_order_detail_order foreign key (order_id)
references orders (order_id) on delete restrict on update restrict;

alter table order_details add constraint FK_order_detail_plant foreign key (plant_id)
references plants (plant_id) on delete restrict on update restrict;

alter table orders add constraint FK_customer_order foreign key (customer_id)
references customers (customer_id) on delete restrict on update restrict;

alter table orders add constraint FK_payment_method_order foreign key (payment_method_id)
references payment_methods (payment_method_id) on delete restrict on update restrict;

alter table plants add constraint FK_category_plant foreign key (category_id)
references categories (category_id) on delete restrict on update restrict;

alter table plants add constraint FK_plant_supplier foreign key (supplier_id)
references suppliers (supplier_id) on delete restrict on update restrict;

alter table staffs add constraint FK_role_staff foreign key (role_id)
references roles (role_id) on delete restrict on update restrict;

67 changes: 67 additions & 0 deletions _sql/dml.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
INSERT INTO `categories` (`category_name`) VALUES
('Mawar'),
('Melati'),
('Lavender'),
('Bunga Sepatu');

INSERT INTO `customers` (`customer_name`, `customer_phone`, `customer_email`, `customer_password`) VALUES
-- ('Naufal Alifiansyah', '081234567891', 'naufal@example.com', 'Password@123'),
-- ('Shafy Gunawan', '081234567891', 'shafy@example.com', 'Password@123');
('Naufal Alifiansyah', '081234567891', 'naufal@example.com', '$2y$10$YpsuVarBbWQP9bDd4K4pI.JjpAP.unxUWAsS/XJHofTR/PdcEV8Bu'),
('Shafy Gunawan', '081234567891', 'shafy@example.com', '$2y$10$YpsuVarBbWQP9bDd4K4pI.JjpAP.unxUWAsS/XJHofTR/PdcEV8Bu');

INSERT INTO `roles` (`role_name`) VALUES
('administrator'),
('manager');

INSERT INTO `staffs` (`role_id`, `staff_name`, `staff_phone`, `staff_email`, `staff_password`) VALUES
-- (1, 'Andre Eka', '081234567891', 'andre@example.com', 'Password@123'),
-- (2, 'Umar Muchtar', '081234567891', 'umar@example.com', 'Password@123');
(1, 'Andre Eka', '081234567891', 'andre@example.com', '$2y$10$YpsuVarBbWQP9bDd4K4pI.JjpAP.unxUWAsS/XJHofTR/PdcEV8Bu'),
(2, 'Umar Muchtar', '081234567891', 'umar@example.com', '$2y$10$YpsuVarBbWQP9bDd4K4pI.JjpAP.unxUWAsS/XJHofTR/PdcEV8Bu');

INSERT INTO `suppliers` (`supplier_name`, `supplier_phone`, `supplier_address`) VALUES
('PT Nusa Bangsa', '081234567891', 'Jl. Semarang No. 33 Surabaya'),
('PT Taman Indah', '081234567891', 'Jl. Pahlawan No. 17 Bangkalan'),
('PT Kebun Merdeka', '081234567891', 'Jl. Telang Indah No. 19 Bangkalan'),
('PT Rumput Hijau', '081234567891', 'Jl. Cempaka No. 27 Surabaya');

INSERT INTO `plants` (`supplier_id`, `category_id`, `plant_name`, `plant_price`, `plant_stock`, `plant_photo`) VALUES
(1, 1, 'Mawar Double Delight', 50000, 20, '655eea074f000.jpg'),
(1, 1, 'Mawar Eden', 75000, 15, '655eeb2c4929e.jpg'),
(1, 1, 'Mawar Mega Putih', 20000, 15, '655eed4066c32.jpeg'),
(1, 1, 'Mawar Putri', 25000, 12, '655eed59ed050.jpg'),
(1, 1, 'Mawar Sunsprite', 22000, 13, '655eef0382fe4.jpg'),
(2, 2, 'Melati Gambir', 17000, 16, '655eef3c6c515.jpg'),
(2, 2, 'Melati Putih', 10000, 18, '655eef669e1eb.jpg'),
(2, 2, 'Melati Raja', 18000, 19, '655eef95e2da9.jpg'),
(2, 2, 'Melati Primpose', 27000, 20, '655eefbc9a3b2.jpg'),
(2, 2, 'Melati Spanyol', 35000, 22, '655ef006584e5.jpg'),
(3, 3, 'Lavender English', 32000, 30, '655f09fb45a67.jpg'),
(3, 3, 'Lavender Putih', 50000, 20, '655f184e3e176.jpg'),
(3, 3, 'Lavender Sage', 31000, 23, '65601b3b0fff0.jpg'),
(3, 3, 'Lavendula Pedunculata', 32000, 13, '65601b8dd7bc1.jpeg'),
(4, 4, 'Hibiscus Calyphyllus', 24000, 5, '6560397845cc6.jpg'),
(4, 4, 'Hibiscus Cannabinus', 30000, 11, '656039cc98fdf.jpg'),
(4, 4, 'Hibiscus Coccineus', 23000, 13, '656039f17b993.jpg'),
(4, 4, 'Hibiscus Acetosella', 34000, 14, '65603a5a2c572.jpg'),
(4, 4, 'Hibiscus Genevil', 29000, 17, '65603a9c34bad.jpeg'),
(4, 4, 'Hibiscus Rosa Sinensis', 37000, 29, '65603ac4ddcb0.jpg');

INSERT INTO `payment_methods` (`payment_method_name`, `payment_method_number`, `payment_method_bank`, `payment_method_logo`) VALUES
('PT FloraFavs Indonesia', '673892017384', 'Permata', 'permata.svg'),
('PT FloraFavs Indonesia', '923456129083', 'BCA', 'bca.svg'),
('PT FloraFavs Indonesia', '384789263892', 'Mandiri', 'mandiri.svg');

INSERT INTO `orders` (`customer_id`, `payment_method_id`, `order_date`, `order_status`, `order_total_price`) VALUES
(1, 1, '2023-11-17', 'paid', 40000),
(2, 2, '2023-11-17', 'unpaid', 100000),
(2, 3, '2023-11-19', 'paid', 120000);

INSERT INTO `order_details` (`order_id`, `plant_id`, `order_detail_qty`, `order_detail_unit_price`) VALUES
(1, 3, 1, 20000),
(1, 7, 2, 10000),
(2, 12, 2, 50000),
(3, 2, 1, 75000),
(3, 3, 1, 20000),
(3, 4, 1, 25000);
35 changes: 35 additions & 0 deletions add-to-cart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

session_start();

if (!isset($_SESSION['customer_id'])) {
header("Location: ./login.php");
exit();
}

if (!isset($_POST['plant_id'])) {
header("Location: ./products.php");
exit();
}

require_once('data/cart-item.php');

$customer_id = $_SESSION['customer_id'];
$plant_id = $_POST['plant_id'];

$cart_item = find_cart_item($customer_id, $plant_id);

if (!$cart_item) {
save_cart_item($customer_id, $plant_id);
} else {
update_cart_item($customer_id, $plant_id, $cart_item['cart_item_qty'] + 1);
}

if (isset($_POST['buy_now'])) {
header('Location: ./cart.php');
exit();
}

$previous_page = $_SERVER['HTTP_REFERER'];
header("Location: $previous_page");
exit();
64 changes: 28 additions & 36 deletions admin/categories.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
<?php

$page = 'categories';
$title = 'Categories';
session_start();

if (!isset($_SESSION['staff_id'])) {
header("Location: ./login.php");
exit();
}

require_once('layouts/header.php');
require_once('../data/category.php');
require_once('../data/plant.php');

$categories = get_categories();

$page = 'categories';
$title = 'Kategori';
require('layouts/header.php');

?>

<!-- your content in here -->
<div class="admin">
<div class="admin__header">
<h1 class="admin__title">Categories</h1>
<h1 class="admin__title">Kategori</h1>
<div class="admin__actions">
<a href="./category-add.php" class="admin__button">Add Category</a>
<a href="./category-add.php" class="admin__button">Tambah Kategori</a>
</div>
</div>
<div class="admin__body">
Expand All @@ -21,39 +32,20 @@
<thead>
<tr>
<th>No.</th>
<th>Name</th>
<th>Related Products</th>
<th>Nama</th>
<th>Produk Terkait</th>
</tr>
</thead>
<tbody>
<tr>
<td>1.</td>
<td>
<a href="./category-single.php">Category 1</a>
</td>
<td>23</td>
</tr>
<tr>
<td>1.</td>
<td>
<a href="./category-single.php">Category 1</a>
</td>
<td>23</td>
</tr>
<tr>
<td>1.</td>
<td>
<a href="./category-single.php">Category 1</a>
</td>
<td>23</td>
</tr>
<tr>
<td>1.</td>
<td>
<a href="./category-single.php">Category 1</a>
</td>
<td>23</td>
</tr>
<?php foreach ($categories as $i => $category) : ?>
<tr>
<td><?= $i + 1 ?>.</td>
<td>
<a href="./category-single.php?category_id=<?= $category['category_id'] ?>"><?= $category['category_name'] ?></a>
</td>
<td><?= count_related_plants_based_on_category($category['category_id'])['count_related_plants'] ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
Expand All @@ -63,6 +55,6 @@

<?php

require_once('layouts/footer.php');
require('layouts/footer.php');

?>
Loading

0 comments on commit 713060f

Please sign in to comment.