@@ -118,7 +133,7 @@
@@ -209,20 +224,24 @@
},
methods: {
handleFileUpload(event) {
- const file = event.target.files[0];
+ const file = event.target.files[0];
+
if (file) {
- this.document = file.name;
+ const reader = new FileReader();
+ reader.onload = (e) => {
+ this.document = e.target.result.split(',')[1]; // Get Base64 string (remove metadata)
+ };
+ reader.readAsDataURL(file);
} else {
- this.document = null; // Ensure null if no file selected
+ this.document = null;
}
},
-
async addRequest() {
try {
const requiredFields = ['stationId', 'productId', 'quantity', 'productCategory'];
this.userId = this.currentUser.id;
- this.status = "Request";
+ this.status = "Requested";
this.requestDate = new Date().toISOString();
// Loop through required fields and check if any are null or empty
@@ -243,8 +262,8 @@
remark: this.remark || '',
status: this.status,
requestDate: this.requestDate,
- approvalDate: this.approvalDate ? this.approvalDate : null,
- document: this.document // ✅ Store only the file name/path
+ approvalDate: this.approvalDate ? this.approvalDate : null,
+ document: this.document
};
$('.modal').modal('hide');
@@ -255,7 +274,7 @@
headers: {
'Content-Type': 'application/json'
},
- body: JSON.stringify(requestData) // ✅ Send JSON (No file upload)
+ body: JSON.stringify(requestData)
});
if (response.ok) {
@@ -278,7 +297,95 @@
initiateTable() {
self = this;
this.requestDatatable = $('#requestDatatable').DataTable({
- "data": this.request,
+ "data": this.request.filter(request => request.status == "Requested"),
+ "columns": [
+ {
+ "title": "Request ID",
+ "data": "requestId",
+ "createdCell": function (td, cellData, rowData, row, col) {
+ // Assign a unique ID to the
element
+ $(td).attr('id', `qr${cellData}`);
+ },
+ },
+ {
+ "title": "Product Id",
+ "data": "productId",
+ },
+ {
+ "title": "Product Category",
+ "data": "productCategory",
+ },
+ {
+ "title": "Request Quantity",
+ "data": "requestQuantity",
+ },
+
+ {
+ "title": "Document / Picture",
+ "data": "document",
+ "render": function (data, type, full, meta) {
+ if (!data) {
+ return "No Document";
+ }
+
+ // Check if the document is an image based on file extension
+ var isImage = /\.(jpeg|jpg|png|gif)$/i.test(data);
+ var isPdf = /\.pdf$/i.test(data);
+
+ if (isImage) {
+ return `
+
+ `;
+ }
+ else if (isPdf) {
+ return `
+
+ View PDF
+ `;
+ } else {
+ return `Download File`;
+ }
+ },
+ },
+ {
+ "title": "Remark",
+ "data": "remarkUser",
+ },
+ {
+ "title": "Request Date",
+ "data": "requestDate",
+ },
+ {
+ "title": "Status",
+ "data": "status",
+ },
+ {
+ "title": "Delete",
+ "data": "requestId",
+ "render": function (data) {
+ var deleteButton = ``;
+ return deleteButton;
+ },
+ "className": "align-middle",
+ // "title": "Delete",
+ // "data": "requestId",
+ // "render": function (data, type, row) {
+ // if (row.status === "Approved" || row.status === "Rejected") {
+ // return ``;
+ // } else {
+ // return ``;
+ // }
+ // },
+ // "className": "align-middle",
+ }
+
+ ],
+ responsive: true,
+ });
+ this.requestDatatable = $('#settledrequestDatatable').DataTable({
+ "data": this.request.filter(request => request.status !== "Requested"),
"columns": [
{
"title": "Request ID",
@@ -303,15 +410,38 @@
{
"title": "Document / Picture",
"data": "document",
- },
+ "render": function (data, type, full, meta) {
+ if (!data) {
+ return "No Document";
+ }
- {
- "title": "Remark",
- "data": "remark",
+ // Check if the document is an image based on file extension
+ var isImage = /\.(jpeg|jpg|png|gif)$/i.test(data);
+ var isPdf = /\.pdf$/i.test(data);
+
+ if (isImage) {
+ return `
+
+ `;
+ } else if (isPdf) {
+ return `
+
+ View PDF
+ `;
+ } else {
+ return `Download File`;
+ }
+ },
},
{
- "title": "Status",
- "data": "status",
+ "title": "Remark",
+ "data": "remarkUser",
+ },
+ {
+ "title": "Remark (Master)",
+ "data": "remarkMasterInv",
},
{
"title": "Request Date",
@@ -322,21 +452,13 @@
"data": "approvalDate",
},
{
- "title": "Delete",
- "data": "requestId",
- "render": function (data, type, row) {
- if (row.status === "Approved" || row.status === "Rejected") {
- return ``;
- } else {
- return ``;
- }
- },
- "className": "align-middle",
+ "title": "Status",
+ "data": "status",
}
],
responsive: true,
- })
+ });
$('#requestDatatable tbody').off('click', '.delete-btn');
@@ -368,6 +490,9 @@
if ($.fn.dataTable.isDataTable('#requestDatatable')) {
$('#requestDatatable').DataTable().clear().destroy();
}
+ if ($.fn.dataTable.isDataTable('#settledrequestDatatable')) {
+ $('#settledrequestDatatable').DataTable().clear().destroy();
+ }
this.initiateTable();
}
diff --git a/Areas/Inventory/Views/ItemMovement/QrUser.cshtml b/Areas/Inventory/Views/ItemMovement/QrUser.cshtml
index dba0ca4..858c036 100644
--- a/Areas/Inventory/Views/ItemMovement/QrUser.cshtml
+++ b/Areas/Inventory/Views/ItemMovement/QrUser.cshtml
@@ -38,6 +38,17 @@
+
+
+
+ ![Product Image]()
+
+
+ {{ thisItem.uniqueID }}
+
+
+
+
-
@@ -199,13 +255,14 @@
}
try {
+ // Disable button
const formData = {
Id: this.thisItem.movementId,
LastStation: this.selectedStation,
- receiveDate: new Date().toISOString(),
LatestStatus: "Delivered",
- MovementComplete: true,
+ ReceiveDate: new Date().toISOString(),
+ MovementComplete: true
};
const response = await fetch('/InvMainAPI/UpdateItemMovementUser', {
@@ -218,8 +275,46 @@
if (response.ok) {
alert('Success! Item movement has been successfully submitted.');
- // this.displayStatus = "return";
- // this.resetForm();
+ this.thisItem = await response.json();
+ this.displayStatus = "return";
+ this.resetForm();
+ } else {
+ throw new Error('Failed to submit form.');
+ }
+ } catch (error) {
+ console.error('Error:', error);
+ alert('Inventory PSTW Error: An error occurred.');
+ }
+ },
+ async returnItemMovement() {
+ if (!confirm("Are you sure you already receive this item?")) {
+ return false;
+ }
+
+ try {
+ // Disable button
+
+ const formData = {
+ Id: this.thisItem.movementId,
+ LastStation: this.selectedStation,
+ LatestStatus: "Delivered",
+ ReceiveDate: new Date().toISOString(),
+ MovementComplete: true
+ };
+
+ const response = await fetch('/InvMainAPI/UpdateItemMovementUser', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(formData)
+ });
+
+ if (response.ok) {
+ alert('Success! Item movement has been successfully submitted.');
+ this.thisItem = await response.json();
+ this.displayStatus = "return";
+ this.resetForm();
} else {
throw new Error('Failed to submit form.');
}
diff --git a/Controllers/API/Inventory/InvMainAPI.cs b/Controllers/API/Inventory/InvMainAPI.cs
index eba8a50..94e49c1 100644
--- a/Controllers/API/Inventory/InvMainAPI.cs
+++ b/Controllers/API/Inventory/InvMainAPI.cs
@@ -745,6 +745,31 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
try
{
+ if (!string.IsNullOrEmpty(request.Document))
+ {
+ var bytes = Convert.FromBase64String(request.Document);
+ string filePath = "";
+
+ string uniqueName = $"{request.ProductId}_{Guid.NewGuid()}";
+
+ if (IsImage(bytes))
+ {
+ filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/media/inventory/request", uniqueName + request.UserId + "_Request.jpg");
+ request.Document = "/media/inventory/request/" + uniqueName + request.UserId + "_Request.jpg";
+ }
+ else if (IsPdf(bytes))
+ {
+ filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/media/inventory/request", uniqueName + request.UserId + "_Request.pdf");
+ request.Document = "/media/inventory/request/" + uniqueName + request.UserId + "_Request.pdf";
+ }
+ else
+ {
+ return BadRequest("Unsupported file format.");
+ }
+
+ await System.IO.File.WriteAllBytesAsync(filePath, bytes);
+ }
+
_centralDbContext.Requests.Add(request);
await _centralDbContext.SaveChangesAsync();
@@ -759,6 +784,28 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
return BadRequest(ex.Message);
}
}
+ private bool IsImage(byte[] bytes)
+ {
+ // JPEG file signature: FF D8 FF
+ if (bytes.Length > 2 && bytes[0] == 0xFF && bytes[1] == 0xD8 && bytes[2] == 0xFF)
+ return true;
+
+ // PNG file signature: 89 50 4E 47 0D 0A 1A 0A
+ if (bytes.Length > 7 && bytes[0] == 0x89 && bytes[1] == 0x50 && bytes[2] == 0x4E && bytes[3] == 0x47)
+ return true;
+
+ // GIF file signature: GIF87a or GIF89a
+ if (bytes.Length > 5 && bytes[0] == 0x47 && bytes[1] == 0x49 && bytes[2] == 0x46)
+ return true;
+
+ return false;
+ }
+
+ private bool IsPdf(byte[] bytes)
+ {
+ // PDF file signature: 25 50 44 46 (ASCII for "%PDF")
+ return bytes.Length > 3 && bytes[0] == 0x25 && bytes[1] == 0x50 && bytes[2] == 0x44 && bytes[3] == 0x46;
+ }
[HttpGet("ItemRequestListEachUser/{userId}")]
public async Task ItemRequestListEachUser(int userId)
@@ -999,10 +1046,6 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
[HttpPost("UpdateItemMovementUser")]
public async Task UpdateItemMovementUser([FromBody] ItemMovementModel receiveMovement)
{
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
try
{
diff --git a/wwwroot/Media/Inventory/Images/Ts02Abc.jpg b/wwwroot/Media/Inventory/Images/SL1500 3G.jpg
similarity index 100%
rename from wwwroot/Media/Inventory/Images/Ts02Abc.jpg
rename to wwwroot/Media/Inventory/Images/SL1500 3G.jpg
diff --git a/wwwroot/Media/Inventory/request/2 Request.jpg b/wwwroot/Media/Inventory/request/2 Request.jpg
new file mode 100644
index 0000000..900137c
Binary files /dev/null and b/wwwroot/Media/Inventory/request/2 Request.jpg differ
|