Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 20785479 authored by 65160375's avatar 65160375
Browse files

update

parent 5a8a9957
Branches master
No related tags found
No related merge requests found
...@@ -66,7 +66,7 @@ const updateStaff = async(req, res, next) => { ...@@ -66,7 +66,7 @@ const updateStaff = async(req, res, next) => {
const staffResult = await staffModel.findOneBy('id',id); const staffResult = await staffModel.findOneBy('id',id);
if(staffResult == null) return res.status(404).send("Not Found."); if(staffResult == null) return res.status(404).send("Not Found.");
await staffModel.updateBy('id',id,{ name,role,user_id: user_id == 0 ? null : user_id }); await staffModel.updateBy('id',id,{ name,role: !role || role == undefined ? staffResult.role : role,user_id: user_id == 0 ? null : user_id });
res.redirect("/staff/manage/" + id); res.redirect("/staff/manage/" + id);
}; };
......
...@@ -2,15 +2,23 @@ const Auth = require("../models/auth"); ...@@ -2,15 +2,23 @@ const Auth = require("../models/auth");
const Table = require("../models/table"); const Table = require("../models/table");
const TableStatus = require("../models/tablestatus"); const TableStatus = require("../models/tablestatus");
const TableTypes = require("../models/tabletypes"); const TableTypes = require("../models/tabletypes");
const User = require("../models/user");
const tableModel = new Table(); const tableModel = new Table();
const tableTypesModel = new TableTypes(); const tableTypesModel = new TableTypes();
const tableStatusModel = new TableStatus(); const tableStatusModel = new TableStatus();
const userModel = new User();
const showIndex = async(req, res, next) => { const showIndex = async(req, res, next) => {
const { query } = req.query;
const authResult = await Auth.getSessionData(req.session.token); const authResult = await Auth.getSessionData(req.session.token);
const tableResult = await tableModel.findAllJoinTypes() || [ ]; var tableResult;
if(!query) {
tableResult = await tableModel.findAllJoinTypesUsers() || [ ];
}
else tableResult = await tableModel.searchJoinTypes(query) || [ ];
const tableStatusResult = await tableStatusModel.findAll() || [ ]; const tableStatusResult = await tableStatusModel.findAll() || [ ];
res.render("restaurant/table/index",{ role: authResult.role,tableResult: tableResult,tableStatusData: tableStatusResult }); res.render("restaurant/table/index",{ role: authResult.role,tableResult: tableResult,tableStatusData: tableStatusResult });
...@@ -27,20 +35,24 @@ const showCreate = async(req, res, next) => { ...@@ -27,20 +35,24 @@ const showCreate = async(req, res, next) => {
const showManage = async(req, res, next) => { const showManage = async(req, res, next) => {
const { id } = req.params; const { id } = req.params;
const authResult = await Auth.getSessionData(req.session.token); const authResult = await Auth.getSessionData(req.session.token);
const tableResult = await tableModel.findOneJoinTypesByID(id) || [ ]; const tableResult = await tableModel.findOneJoinTypesUsersByID(id) || [ ];
if(tableResult == null) return res.status(404).send("Not Found."); if(tableResult == null) return res.status(404).send("Not Found.");
const tableTypesResult = await tableTypesModel.findAll() || [ ]; const tableTypesResult = await tableTypesModel.findAll() || [ ];
const tableStatusResult = await tableStatusModel.findAll() || [ ]; const tableStatusResult = await tableStatusModel.findAll() || [ ];
const usersResult = await userModel.findAll() || [ ];
console.log(tableResult);
res.render("restaurant/table/manage",{ role: authResult.role,tableData: tableResult,tableTypeData: tableTypesResult,tableStatusData: tableStatusResult }); res.render("restaurant/table/manage",{ role: authResult.role,tableData: tableResult,tableTypeData: tableTypesResult,tableStatusData: tableStatusResult,usersData: usersResult });
}; };
const updateTable = async(req, res, next) => { const updateTable = async(req, res, next) => {
const { id,table_number,table_type,table_status } = req.body; const { id,table_number,table_type,table_status,user_id } = req.body;
console.log(id);
const tableResult = await tableModel.findOneBy('id',id); const tableResult = await tableModel.findOneBy('id',id);
if(tableResult == null) return res.status(404).send("Not Found."); if(tableResult == null) return res.status(404).send("Not Found.");
await tableModel.updateBy('id',id,{ table_number, table_type, table_status }); await tableModel.updateBy('id',id,{ table_number, table_type, table_status,user_id: user_id == 0 ? null : user_id });
res.redirect("/table/manage/" + id); res.redirect("/table/manage/" + id);
}; };
......
...@@ -5,20 +5,31 @@ class Table extends SQLModel { ...@@ -5,20 +5,31 @@ class Table extends SQLModel {
constructor() { constructor() {
super("tables"); super("tables");
} }
async findAllJoinTypes() { async findAllJoinTypesUsers() {
let query = `SELECT tt.id AS type_id,tt.*,tb.* FROM ${this.tableName} AS tb JOIN table_types AS tt ON tb.table_type = tt.id WHERE 1`; let query = `SELECT tt.id AS type_id, tt.*, tb.*, u.phone_number FROM ${this.tableName} AS tb JOIN table_types AS tt ON tb.table_type = tt.id LEFT JOIN users AS u ON tb.user_id = u.id WHERE 1;`;
const [result] = await db.mysql.query(query); const [result] = await db.mysql.query(query);
if (!result || result.length == 0) return null; if (!result || result.length == 0) return null;
return result; return result;
} }
async findOneJoinTypesByID(id) { async findOneJoinTypesUsersByID(id) {
let query = `SELECT tt.id AS type_id,tb.* FROM ${this.tableName} AS tb JOIN table_types AS tt ON tb.table_type = tt.id WHERE tb.id = ?`; let query = `SELECT tt.id AS type_id, tb.*, u.phone_number FROM ${this.tableName} AS tb JOIN table_types AS tt ON tb.table_type = tt.id LEFT JOIN users AS u ON tb.user_id = u.id WHERE tb.id = ?`;
const [result] = await db.mysql.query(query,[id]); const [result] = await db.mysql.query(query,[id]);
if (!result || result.length == 0) return null; if (!result || result.length == 0) return null;
return result[0]; return result[0];
} }
async searchJoinTypes(value, orderBy = null) {
let query = `SELECT tt.id AS type_id,tt.*,tb.* FROM ${this.tableName} AS tb JOIN table_types AS tt ON tb.table_type = tt.id WHERE tb.table_number LIKE ? OR tb.table_type LIKE ? OR tt.description LIKE ?`;
if (orderBy) {
query += ` ORDER BY ${orderBy}`;
}
const [result] = await db.mysql.query(query, [`%${value}%`,`%${value}%`,`%${value}%`]);
if (!result || result.length == 0) return null;
return result;
}
}; };
module.exports = Table; module.exports = Table;
\ No newline at end of file
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<p class="card-text">วันเวลาที่จอง: <span id="queue-date"></span></p> <p class="card-text">วันเวลาที่จอง: <span id="queue-date"></span></p>
<p class="card-text">ประเภทโต๊ะ: <span id="queue-table"></span></p> <p class="card-text">ประเภทโต๊ะ: <span id="queue-table"></span></p>
<p class="card-text">จำนวนที่นั่ง: <span id="queue-size"></span></p> <p class="card-text">จำนวนที่นั่ง: <span id="queue-size"></span></p>
<a href="#" class="btn btn-primary wh-100">Go somewhere</a> <!-- <a href="#" class="btn btn-primary wh-100">Go somewhere</a> -->
</div> </div>
</div> </div>
</div> </div>
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<!-- Centered block container --> <!-- Centered block container -->
<div class="mx-5 d-flex justify-content-center align-items-center" style="height: 40vh;"> <div class="mx-5 d-flex justify-content-center align-items-center" style="height: 40vh;">
<div class="row row-cols-3 g-3"> <!-- Grid with 3 columns --> <div class="row row-cols-3 g-3"> <!-- Grid with 3 columns -->
<% if(role === "Administrator") { %> <% if(role === "Administrator" || role === "Reception") { %>
<!-- <div class="col"> <!-- <div class="col">
<a href="/table"> <a href="/table">
<div class="bg-success text-white d-flex flex-column justify-content-center align-items-center mx-5" style="width: 100px; height: 120px;"> <div class="bg-success text-white d-flex flex-column justify-content-center align-items-center mx-5" style="width: 100px; height: 120px;">
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<label for="role">ตำแหน่ง</label> <label for="role">ตำแหน่ง</label>
<select id="role" name="role" class="form-control" <%= isSelf == true ? "disabled" : "" %>> <select id="role" name="role" class="form-control" <%= isSelf == true ? "disabled" : "" %>>
<% rolesData.forEach(element=> { %> <% rolesData.forEach(element=> { %>
<option value="<%= element.name %>" <%=staffData.role==element.role ? 'selected' : '' %>><%= element.name %></option> <option value="<%= element.name %>" <%=staffData.role == element.name ? 'selected' : '' %>><%= element.name %></option>
<% }) %> <% }) %>
</select> </select>
</div> </div>
...@@ -50,7 +50,6 @@ ...@@ -50,7 +50,6 @@
<option value="<%= element.id %>" <%=staffData.user_id==element.id ? 'selected' : '' %>>(<%= element.id %>) <%= element.phone_number %></option> <option value="<%= element.id %>" <%=staffData.user_id==element.id ? 'selected' : '' %>>(<%= element.id %>) <%= element.phone_number %></option>
<% }) %> <% }) %>
</select> </select>
<!-- <input type="text" class="form-control" name="user_id" id="user_id" placeholder="กรอกไอดีบัญชีผู้ใช้ของพนักงาน" value="<%= staffData.user_id %>"> -->
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="phone_number">เบอร์โทรศัพท์</label> <label for="phone_number">เบอร์โทรศัพท์</label>
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<form method="POST" action="/table/create"> <form method="POST" action="/table/create">
<div class="form-group"> <div class="form-group">
<label for="table_number">หมายเลขโต๊ะ</label> <label for="table_number">หมายเลขโต๊ะ</label>
<input type="number" class="form-control" name="table_number" id="table_number" placeholder="หมายเลขของโต๊ะ"> <input type="number" class="form-control" name="table_number" id="table_number" placeholder="หมายเลขของโต๊ะ" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="table_type">ประเภทโต๊ะ</label> <label for="table_type">ประเภทโต๊ะ</label>
......
...@@ -22,11 +22,17 @@ ...@@ -22,11 +22,17 @@
</div> </div>
<div class="container px-3 py-3"> <div class="container px-3 py-3">
<h5>จัดการโต๊ะภายในร้าน</h5> <h5>จัดการโต๊ะภายในร้าน</h5>
<table class="table table-dark"> <form action="/table" method="GET" class="input-group flex-grow-1">
<span class="input-group-text"><i class="fa fa-magnifying-glass"></i></span>
<input type="text" class="form-control" name="query" placeholder="ค้นหาจากหมายเลขหรือประเภทโต๊ะ" aria-label="searchinput">
</form>
<table class="table table-dark my-2">
<thead> <thead>
<tr> <tr>
<th scope="col">หมายเลขโต๊ะ</th> <th scope="col">หมายเลขโต๊ะ</th>
<th scope="col">ประเภทโต๊ะ</th> <th scope="col">ประเภทโต๊ะ</th>
<th scope="col">จำนวนที่นั่ง</th>
<th scope="col">ผู้ใช้ที่กำลังใช้งาน</th>
<th scope="col">สถานะ</th> <th scope="col">สถานะ</th>
</tr> </tr>
</thead> </thead>
...@@ -34,7 +40,13 @@ ...@@ -34,7 +40,13 @@
<% tableResult.forEach(element => { %> <% tableResult.forEach(element => { %>
<tr onclick="window.location.href='/table/manage/<%= element.id %>'"> <tr onclick="window.location.href='/table/manage/<%= element.id %>'">
<th scope="row"><%= element.table_number %></th> <th scope="row"><%= element.table_number %></th>
<td>(<%= element.type_id %>) <%= element.description %> | <%= element.capacity_min %> - <%= element.capacity_max %> คน</td> <td>(<%= element.type_id %>) <%= element.description %></td>
<td><%= element.capacity_min %> - <%= element.capacity_max %> คน</td>
<% if (element.user_id != null) { %>
<td>(<%= element.user_id %>) <%= element.phone_number %></td>
<% } else {%>
<td></td>
<% } %>
<td><%= tableStatusData[element.table_status].name %></td> <td><%= tableStatusData[element.table_status].name %></td>
</tr> </tr>
<% }) %> <% }) %>
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<div class="form-group"> <div class="form-group">
<label for="table_number">หมายเลขโต๊ะ</label> <label for="table_number">หมายเลขโต๊ะ</label>
<input type="number" class="form-control" name="table_number" id="table_number" placeholder="หมายเลขของโต๊ะ" <input type="number" class="form-control" name="table_number" id="table_number" placeholder="หมายเลขของโต๊ะ"
value="<%= tableData.table_number %>"> value="<%= tableData.table_number %>" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="table_type">ประเภทโต๊ะ</label> <label for="table_type">ประเภทโต๊ะ</label>
...@@ -51,6 +51,15 @@ ...@@ -51,6 +51,15 @@
<% }) %> <% }) %>
</select> </select>
</div> </div>
<div class="form-group">
<label for="user_id">บัญชีผู้ใช้</label>
<select id="user_id" name="user_id" class="form-control">
<option value="0" <%=tableData.user_id==null ? 'selected' : '' %>>ไม่ระบุ</option>
<% usersData.forEach(element=> { %>
<option value="<%= element.id %>" <%=tableData.user_id==element.id ? 'selected' : '' %>>(<%= element.id %>) <%= element.phone_number %></option>
<% }) %>
</select>
</div>
<button type="submit" class="my-2 btn btn-success">บันทึก</button> <button type="submit" class="my-2 btn btn-success">บันทึก</button>
</form> </form>
</div> </div>
......
...@@ -27,19 +27,19 @@ ...@@ -27,19 +27,19 @@
<form method="POST" action="/tabletype/create"> <form method="POST" action="/tabletype/create">
<div class="form-group"> <div class="form-group">
<label for="id">รหัสของประเภท</label> <label for="id">รหัสของประเภท</label>
<input type="text" class="form-control" name="id" id="id" placeholder="รหัสของประเภท"> <input type="text" class="form-control" name="id" id="id" placeholder="รหัสของประเภท" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="description">รายละเอียด</label> <label for="description">รายละเอียด</label>
<input type="text" class="form-control" name="description" id="description" placeholder="รายละเอียด"> <input type="text" class="form-control" name="description" id="description" placeholder="รายละเอียด" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="capacity_min">จำนวนที่นั่งต่ำสุด</label> <label for="capacity_min">จำนวนที่นั่งต่ำสุด</label>
<input type="number" class="form-control" name="capacity_min" id="capacity_min" placeholder="จำนวนที่นั่งต่ำสุด" min="1"> <input type="number" class="form-control" name="capacity_min" id="capacity_min" placeholder="จำนวนที่นั่งต่ำสุด" min="1" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="capacity_max">จำนวนที่นั่งสูงสุด</label> <label for="capacity_max">จำนวนที่นั่งสูงสุด</label>
<input type="number" class="form-control" name="capacity_max" id="capacity_max" placeholder="จำนวนที่นั่งสูงสุด" min="1"> <input type="number" class="form-control" name="capacity_max" id="capacity_max" placeholder="จำนวนที่นั่งสูงสุด" min="1" required>
</div> </div>
<button type="submit" class="my-2 btn btn-success">เพิ่ม</button> <button type="submit" class="my-2 btn btn-success">เพิ่ม</button>
</form> </form>
......
...@@ -32,19 +32,19 @@ ...@@ -32,19 +32,19 @@
<input type="hidden" name="tid" value="<%= tableTypeData.id %>"> <input type="hidden" name="tid" value="<%= tableTypeData.id %>">
<div class="form-group"> <div class="form-group">
<label for="id">รหัสของประเภท</label> <label for="id">รหัสของประเภท</label>
<input type="text" class="form-control" name="id" id="id" placeholder="รหัสของประเภท" value="<%= tableTypeData.id %>"> <input type="text" class="form-control" name="id" id="id" placeholder="รหัสของประเภท" value="<%= tableTypeData.id %>" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="description">รายละเอียด</label> <label for="description">รายละเอียด</label>
<input type="text" class="form-control" name="description" id="description" placeholder="รายละเอียด" value="<%= tableTypeData.description %>"> <input type="text" class="form-control" name="description" id="description" placeholder="รายละเอียด" value="<%= tableTypeData.description %>" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="capacity_min">จำนวนที่นั่งต่ำสุด</label> <label for="capacity_min">จำนวนที่นั่งต่ำสุด</label>
<input type="number" class="form-control" name="capacity_min" id="capacity_min" placeholder="จำนวนที่นั่งต่ำสุด" value="<%= tableTypeData.capacity_min %>" min="1"> <input type="number" class="form-control" name="capacity_min" id="capacity_min" placeholder="จำนวนที่นั่งต่ำสุด" value="<%= tableTypeData.capacity_min %>" min="1" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="capacity_max">จำนวนที่นั่งสูงสุด</label> <label for="capacity_max">จำนวนที่นั่งสูงสุด</label>
<input type="number" class="form-control" name="capacity_max" id="capacity_max" placeholder="จำนวนที่นั่งสูงสุด" value="<%= tableTypeData.capacity_max %>" min="1"> <input type="number" class="form-control" name="capacity_max" id="capacity_max" placeholder="จำนวนที่นั่งสูงสุด" value="<%= tableTypeData.capacity_max %>" min="1" required>
</div> </div>
<button type="submit" class="my-2 btn btn-success">บันทึก</button> <button type="submit" class="my-2 btn btn-success">บันทึก</button>
</form> </form>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment