item request api

This commit is contained in:
ameerulrasyid 2025-02-20 07:42:06 +08:00
parent 5f4e8c6c22
commit d9e67e6139
4 changed files with 207 additions and 107 deletions

View File

@ -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; }

View File

@ -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 <td> element
$(td).attr('id', `qr${cellData}`);
@ -657,110 +657,98 @@
},
{
"title": "Print",
"data": "itemId",
"data": "requestId",
"render": function (data, type, full, meta) {
var printButton = `<button type="button" class="btn btn-success print-btn" data-id="${data}">Print</button>`;
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": "Send Date",
"data": "date",
"title": "Request Date",
"data": "requestDate",
},
{
"title": "Last User",
"data": "lastUser",
"title": "Approval Date",
"data": "approvalDate",
},
{
"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}<br>
// Store: ${currentStore}<br>
// 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 = `<button type="button" class="btn btn-danger delete-btn" data-id="${data}">Delete</button>`;
var deleteButton = `<button type="button" class="btn btn-danger reject-btn" data-id="${data}">Reject</button>`;
return deleteButton;
},
"className": "align-middle",
},
{
"title": "Approve",
"data": "requestId",
"render": function (data) {
var approveButton = `<button type="button" class="btn btn-success approve-btn" data-id="${data}">Approve</button>`;
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;

View File

@ -627,6 +627,51 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
#endregion ItemMovement
#region ItemRequest
[HttpGet("ItemRequestList")]
public async Task<IActionResult> ItemRequestList()
{
var itemRequestList = await _centralDbContext.Request.ToListAsync();
return Json(itemRequestList);
}
[HttpPost("ApproveRequest/{id}")]
public async Task<IActionResult> 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<IActionResult> 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<IActionResult> StoreList()
{
var storeList = await _centralDbContext.Stores.ToListAsync();
return Json(storeList);
}
#endregion Store
#region User
[HttpPost("UserList")]
public async Task<IActionResult> UserList()
{
var userList = await _centralDbContext.Users.ToListAsync();
return Json(userList);
}
#endregion User
}
}

View File

@ -91,7 +91,7 @@ namespace PSTW_CentralSystem.DBContext
public DbSet<DepartmentModel> Departments { get; set; }
public DbSet<ManufacturerModel> Manufacturers { get; set; }
public DbSet<ItemModel> Items { get; set; }
public DbSet<RequestModel> Requests { get; set; }
public DbSet<RequestModel> Request { get; set; }
public DbSet<ProductModel> Products { get; set; }
public DbSet<SupplierModel> Suppliers { get; set; }
public DbSet<InventoryMasterModel> InventoryMasters { get; set; }