diff --git a/Areas/Inventory/Models/RequestModel.cs b/Areas/Inventory/Models/RequestModel.cs
index 3480ed6..d54dfe0 100644
--- a/Areas/Inventory/Models/RequestModel.cs
+++ b/Areas/Inventory/Models/RequestModel.cs
@@ -7,10 +7,10 @@ namespace PSTW_CentralSystem.Areas.Inventory.Models
{
[Key]
public int requestId { get; set; }
- public int DepartmentId { get; set; }
- [ForeignKey("DepartmentId")]
- public virtual ItemModel? Department { get; set; }
- [ForeignKey("ItemID")]
+ //public int DepartmentId { get; set; }
+ //[ForeignKey("DepartmentId")]
+ //public virtual ItemModel? Department { get; set; }
+ //[ForeignKey("ItemID")]
public string? remark { get; set; }
public string? status { get; set; }
public DateTime requestDate { get; set; }
diff --git a/Areas/Inventory/Views/InventoryMaster/ItemRequest.cshtml b/Areas/Inventory/Views/InventoryMaster/ItemRequest.cshtml
index 93559de..c892ec3 100644
--- a/Areas/Inventory/Views/InventoryMaster/ItemRequest.cshtml
+++ b/Areas/Inventory/Views/InventoryMaster/ItemRequest.cshtml
@@ -648,8 +648,8 @@
"data": this.items,
"columns": [
{
- "title": "Unique Id",
- "data": "itemId",
+ "title": "Request ID",
+ "data": "requestId",
"createdCell": function (td, cellData, rowData, row, col) {
// Assign a unique ID to the
element
$(td).attr('id', `qr${cellData}`);
@@ -657,110 +657,98 @@
},
{
"title": "Print",
- "data": "itemId",
+ "data": "requestId",
"render": function (data, type, full, meta) {
var printButton = ``;
return printButton;
},
"className": "align-middle",
},
- {
- "title": "To User",
- "data": "toUser",
- },
- {
- "title": "Last User",
- "data": "lastStore",
- },
- {
- "title": "Action",
- "data": "action",
- },
- {
- "title": "Latest Status",
- "data": "latestStatus",
- },
- {
- "title": "Quantity",
- "data": "quantity",
- },
- {
- "title": "To Station",
- "data": "toStation",
- },
- {
- "title": "To Store",
- "data": "toStore",
- },
- {
- "title": "To Other",
- "data": "toOther",
- },
{
"title": "Remark",
"data": "remark",
},
{
- "title": "Note",
- "data": "consignmentNote",
+ "title": "Status",
+ "data": "status",
+ },
+ {
+ "title": "Request Date",
+ "data": "requestDate",
},
{
- "title": "Send Date",
- "data": "date",
+ "title": "Approval Date",
+ "data": "approvalDate",
},
- {
- "title": "Last User",
- "data": "lastUser",
- },
- {
- "title": "Last Store",
- "data": "lastStore",
- },
- {
- "title": "Last Station",
- "data": "lastStation",
- },
- {
- "title": "Latest Status",
- "data": "latestStatus",
- },
- {
- "title": "Receive Date",
- "data": "date",
- },
- {
- "title": "Completion",
- "data": "movementComplete",
- },
-
// {
- // "title": "Warranty Until",
- // "data": "warranty",
- // "render": function (data, type, full, meta) {
- // if (data > 0) { return full.endWDate }
- // else { return data }
- // }
+ // "title": "Quantity",
+ // "data": "quantity",
// },
// {
- // "title": "Location",
- // "data": "currentUser",
- // "render": function (data, type, full, meta) {
- // currentUser = data ?? null;
- // currentStore = full.currentStore ?? 'N/A';
- // currentStation = full.currentStation ?? 'N/A';
- // return `User: ${currentUser}
- // Store: ${currentStore}
- // Station: ${currentStation}`
- // }
+ // "title": "To Station",
+ // "data": "toStation",
+ // },
+ // {
+ // "title": "To Store",
+ // "data": "toStore",
+ // },
+ // {
+ // "title": "To Other",
+ // "data": "toOther",
+ // },
+ // {
+ // "title": "Remark",
+ // "data": "remark",
+ // },
+ // {
+ // "title": "Note",
+ // "data": "consignmentNote",
+ // },
+ // {
+ // "title": "Send Date",
+ // "data": "date",
+ // },
+ // {
+ // "title": "Last User",
+ // "data": "lastUser",
+ // },
+ // {
+ // "title": "Last Store",
+ // "data": "lastStore",
+ // },
+ // {
+ // "title": "Last Station",
+ // "data": "lastStation",
+ // },
+ // {
+ // "title": "Latest Status",
+ // "data": "latestStatus",
+ // },
+ // {
+ // "title": "Receive Date",
+ // "data": "date",
+ // },
+ // {
+ // "title": "Completion",
+ // "data": "movementComplete",
// },
{
- "title": "Delete",
- "data": "itemId",
+ "title": "Reject",
+ "data": "requestId",
"render": function (data) {
- var deleteButton = ``;
+ var deleteButton = ``;
return deleteButton;
},
"className": "align-middle",
+ },
+ {
+ "title": "Approve",
+ "data": "requestId",
+ "render": function (data) {
+ var approveButton = ``;
+ return approveButton;
+ },
+ "className": "align-middle",
}
],
responsive: true,
@@ -769,10 +757,10 @@
const api = this.api();
api.rows().every(function () {
const data = this.data(); // Row data
- const containerId = `qr${data.itemId}`;
+ const containerId = `qr${data.requestId}`;
const container = $(`#${containerId}`);
container.empty();
- container.append(`${data.itemId}`);
+ container.append(`${data.requestId}`);
// console.log(container[0]);
if (container) {
// Generate QR code only if not already generated
@@ -793,9 +781,14 @@
})
// Attach click event listener to the delete buttons
- $('#itemDatatable tbody').on('click', '.delete-btn', function () {
+ $('#itemDatatable tbody').on('click', '.reject-btn', function () {
const itemId = $(this).data('id');
- self.deleteItem(itemId);
+ self.rejectRequest(itemId);
+ });
+
+ $('#itemDatatable tbody').on('click', '.approve-btn', function () {
+ const itemId = $(this).data('id');
+ self.approveRequest(itemId);
});
$('#itemDatatable tbody').on('click', '.print-btn', function () {
@@ -827,8 +820,8 @@
async fetchItem() {
try {
// const token = localStorage.getItem('token'); // Get the token from localStorage
- const response = await fetch('/InvMainAPI/ItemMovementList', {
- method: 'POST', // Specify the HTTP method
+ const response = await fetch('/InvMainAPI/ItemRequestList', {
+ method: 'GET', // Specify the HTTP method
headers: {
'Content-Type': 'application/json', // Set content type
// 'Authorization': `Bearer ${token}` // Include the token in the headers
@@ -927,7 +920,7 @@
},
async fetchStore() {
try {
- const response = await fetch('/InvMainAPI/StoreList', {
+ const response = await fetch('/InvMainAPI/StoreList/', {
method: 'POST', // Specify the HTTP method
headers: {
'Content-Type': 'application/json'
@@ -1028,13 +1021,13 @@
this.EndWDate = null;
}
},
- async deleteItem(itemId) {
- if (!confirm("Are you sure you want to delete this item?")) {
- return;
- }
+ async approveRequest(itemId) {
+ // if (!confirm("Are you sure you want to approve this request?")) {
+ // return;
+ // }
try {
- const response = await fetch(`/InvMainAPI/DeleteItem/${itemId}`, {
- method: 'DELETE',
+ const response = await fetch(`/InvMainAPI/ApproveRequest/${itemId}`, {
+ method: 'POST',
headers: {
'Content-Type': 'application/json',
},
@@ -1043,18 +1036,56 @@
if (result.success) {
alert(result.message);
- // Remove the row from DataTables
- this.itemDatatable
- .row($(`.delete-btn[data-id="${itemId}"]`).closest('tr'))
- .remove()
+
+ //static update
+ const row = $(`.approve-btn[data-id="${itemId}"]`).closest('tr');
+ this.itemDatatable.row(row)
+ .data({ ...this.itemDatatable.row(row)
+ .data(), status: "Approved" })
.draw();
+
} else {
alert(result.message);
}
}
catch (error) {
- console.error("Error deleting item:", error);
- alert("An error occurred while deleting the item.");
+ console.error("Error approving request:", error);
+ // alert("An error occurred while approving the request.");
+ }
+ finally {
+ this.loading = false;
+ }
+ },
+ async rejectRequest(itemId) {
+ if (!confirm("Are you sure you want to reject this request?")) {
+ return;
+ }
+ try {
+ const response = await fetch(`/InvMainAPI/RejectRequest/${itemId}`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ });
+ const result = await response.json();
+
+ if (result.success) {
+ alert(result.message);
+
+ //static update
+ const row = $(`.approve-btn[data-id="${itemId}"]`).closest('tr');
+ this.itemDatatable.row(row)
+ .data({ ...this.itemDatatable.row(row)
+ .data(), status: "Rejected" })
+ .draw();
+
+ } else {
+ alert(result.message);
+ }
+ }
+ catch (error) {
+ console.error("Error rejecting request:", error);
+ // alert("An error occurred while rejecting the request.");
}
finally {
this.loading = false;
diff --git a/Controllers/API/Inventory/InvMainAPI.cs b/Controllers/API/Inventory/InvMainAPI.cs
index c852c2d..713376b 100644
--- a/Controllers/API/Inventory/InvMainAPI.cs
+++ b/Controllers/API/Inventory/InvMainAPI.cs
@@ -627,6 +627,51 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
#endregion ItemMovement
+ #region ItemRequest
+
+ [HttpGet("ItemRequestList")]
+ public async Task ItemRequestList()
+ {
+
+ var itemRequestList = await _centralDbContext.Request.ToListAsync();
+ return Json(itemRequestList);
+
+ }
+
+ [HttpPost("ApproveRequest/{id}")]
+ public async Task ApproveRequest(int id)
+ {
+ var Request = await _centralDbContext.Request.FindAsync(id);
+ if (Request == null)
+ {
+ return NotFound(new { success = false, message = "Request not found" });
+ }
+
+ Request.status = "Approved";
+ Request.approvalDate = DateTime.UtcNow;
+ _centralDbContext.SaveChanges();
+
+ return Ok(new { success = true, message = "Request Approved Successfully", data = Request });
+ }
+
+ [HttpPost("RejectRequest/{id}")]
+ public async Task RejectRequest(int id)
+ {
+ var Request = await _centralDbContext.Request.FindAsync(id);
+ if (Request == null)
+ {
+ return NotFound(new { success = false, message = "Request not found" });
+ }
+
+ Request.status = "Rejected";
+ Request.approvalDate = DateTime.UtcNow;
+ _centralDbContext.SaveChanges();
+
+ return Ok(new { success = true, message="Request Rejected Successfully", data=Request });
+ }
+
+ #endregion ItemRequest
+
#region ItemReport
[HttpPost("GetInventoryReport/{deptId}")]
@@ -764,5 +809,29 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
return Ok(new { success = true, message = "Station deleted successfully" });
}
#endregion Station
+
+ #region Store
+
+ [HttpPost("StoreList")]
+ public async Task StoreList()
+ {
+ var storeList = await _centralDbContext.Stores.ToListAsync();
+ return Json(storeList);
+ }
+
+
+ #endregion Store
+
+ #region User
+
+ [HttpPost("UserList")]
+ public async Task UserList()
+ {
+ var userList = await _centralDbContext.Users.ToListAsync();
+ return Json(userList);
+ }
+
+
+ #endregion User
}
}
diff --git a/DBContext/CentralSystemContext.cs b/DBContext/CentralSystemContext.cs
index 4811aa7..f53e6ff 100644
--- a/DBContext/CentralSystemContext.cs
+++ b/DBContext/CentralSystemContext.cs
@@ -91,7 +91,7 @@ namespace PSTW_CentralSystem.DBContext
public DbSet Departments { get; set; }
public DbSet Manufacturers { get; set; }
public DbSet Items { get; set; }
- public DbSet Requests { get; set; }
+ public DbSet Request { get; set; }
public DbSet Products { get; set; }
public DbSet Suppliers { get; set; }
public DbSet InventoryMasters { get; set; }
|