Update Qr

This commit is contained in:
ArifHilmi 2025-03-10 22:28:46 +08:00
parent ed04371e3c
commit ce2a741450
14 changed files with 1874 additions and 373 deletions

View File

@ -26,6 +26,8 @@ namespace PSTW_CentralSystem.Areas.Inventory.Models
public DateTime? approvalDate { get; set; }
public int? RequestQuantity { get; set; }
public string? Document { get; set; }
public string? fromStoreItem { get; set; }
public string? assignStoreItem { get; set; }
}
}

View File

@ -49,7 +49,7 @@
margin-left: auto !important; /* Push Complete/Incomplete to right */
}
</style>
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml")
<div id="registerItem" class="row">
<div class="row mb-3" >
<h2 for="sortSelect" class="col-sm-1 col-form-h2" style="min-width:140px;">Sort by:</h2>

View File

@ -638,18 +638,27 @@
],
responsive: true,
drawCallback: function (settings) {
// Generate QR codes after rows are rendered
setTimeout(() => {
const api = this.api();
api.rows().every(function () {
const data = this.data(); // Row data
const data = this.data();
const containerId = `qr${data.uniqueID}`;
const container = $(`#${containerId}`);
container.empty();
container.append(`${data.uniqueID}`);
// console.log(container[0]);
if (container) {
// Generate QR code only if not already generated
new QRCode(container[0], {
const container = document.getElementById(containerId);
if (!container) {
return;
}
container.innerHTML = "";
container.append(data.uniqueID);
// Ensure qrString is valid before generating QR code
if (!data.qrString) {
return;
}
// Generate QR Code
new QRCode(container, {
text: data.qrString,
width: 100,
height: 100,
@ -657,12 +666,9 @@
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.M
});
}
// container.on('click', function() {
// window.open(data.qrString, '_blank');
// });
});
},
}, 100); // Small delay to ensure elements exist
}
})
// Attach click event listener to the delete buttons

View File

@ -2,36 +2,129 @@
ViewData["Title"] = "Product Request";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml")
<style>
.dropdown {
position: relative;
width: 100%;
}
.dropdown-toggle-box {
display: flex;
align-items: center;
border: 1px solid #ddd;
border-radius: 5px;
overflow: hidden;
}
.dropdown-toggle-box input {
flex: 1;
border: none;
padding: 8px;
}
.dropdown-btn {
border: none;
background-color: #007bff;
color: white;
padding: 8px 12px;
cursor: pointer;
}
.dropdown-content {
position: absolute;
width: 100%;
max-height: 200px;
overflow-y: auto;
background: #fff;
border: 1px solid #ddd;
z-index: 10;
}
.dropdown-content option {
padding: 10px;
cursor: pointer;
display: block;
}
.dropdown-content option:hover {
background-color: #f1f1f1;
}
.modal-body img {
max-width: 100%; /* Ensure it fits the modal */
max-height: 150px; /* Adjust max height */
display: block;
margin: auto;
}
</style>
<div id="requestProduct" class="row">
<div class="row mb-3">
<h2 for="sortSelect" class="col-sm-1 col-form-h2" style="min-width:150px;">Sort by:</h2>
<div class="col-sm-4">
<select id="sortSelect" class="form-control" v-model="sortBy" v-on:change="handleSorting">
<option value="tech">Technician</option>
<option value="master">Inventory Master</option>
</select>
</div>
</div>
<div v-show="sortBy === 'master'">
<div class="row card">
<div class="card-header">
<h2>Pending Request Master</h2>
<button id="addRequestBtn" class="btn btn-success col-md-3 col-lg-3 m-1 col-12"
v-on:click="showRequestModal = true">
<i class="fa fa-plus"></i>&nbsp;Add Request
</button>
</div>
<div class="card-body">
<table class="table table-bordered table-hover table-striped no-wrap" id="requestMasterDatatable" style=" width:100%;border-style: solid; border-width: 1px"></table>
</div>
</div>
<div class="row card">
<div class="card-header">
<h2>Pending Approval Request (Your Item)</h2>
</div>
<div class="card-body">
<table class="table table-bordered table-hover table-striped no-wrap" id="requestOtherMasterDatatable" style=" width:100%;border-style: solid; border-width: 1px"></table>
</div>
</div>
<div class="row card">
<div class="card-header">
<h2>Complete Request Master</h2>
</div>
<div class="card-body">
<table class="table table-bordered table-hover table-striped no-wrap" id="settledrequestMasterDatatable" style=" width:100%;border-style: solid; border-width: 1px"></table>
</div>
</div>
</div>
<div v-show="sortBy === 'tech'">
<div class="row card">
<div class="card-header">
<h2>Pending Request</h2>
@* <button id="addRequestBtn" class="btn btn-success col-md-3 col-lg-3 m-1 col-12"><i class="fa fa-plus"></i>&nbsp;Add Request</button> *@
</div>
<div class="card-body">
@* <div v-if="loading">
<div class="spinner-border text-info" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div> *@
<table class="table table-bordered table-hover table-striped no-wrap" id="requestDatatable" style=" width:100%;border-style: solid; border-width: 1px"></table>
</div>
</div>
<div class="row card">
<div class="card-header">
<h2>Complete Request</h2>
@* <button id="addRequestBtn" class="btn btn-success col-md-3 col-lg-3 m-1 col-12"><i class="fa fa-plus"></i>&nbsp;Add Request</button> *@
</div>
<div class="card-body">
@* <div v-if="loading">
<div class="spinner-border text-info" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div> *@
<table class="table table-bordered table-hover table-striped no-wrap" id="settledrequestDatatable" style=" width:100%;border-style: solid; border-width: 1px"></table>
</div>
</div>
</div>
<div class="modal fade" id="rejectModal" tabindex="-1" role="dialog" aria-labelledby="rejectRequestModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content">
@ -94,6 +187,165 @@
</div>
</div>
<div class="modal fade" id="requestModal" tabindex="-1" role="dialog" aria-labelledby="addRequestModalLabel" aria-hidden="true" >
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addRequestModalLabel">Add Request</h5>
<button type="button" class="closeModal" data-dismiss="modal" aria-label="Close" v-on:click="showRequestModal=false">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="container-fluid">
<form v-on:submit.prevent="addRequestMaster" data-aos="fade-right">
<div class="register" data-aos="fade-right">
<div class="row" data-aos="fade-right">
<div class="col-md-12">
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<h3 class="register-heading">PRODUCT REQUEST</h3>
<div class="row register-form">
<div class="col-md-13">
<!-- Product Name -->
<div class="form-group row">
<label class="col-sm-2 col-form-label">Product</label>
<div class="col-sm-8">
<div class="dropdown" v-click-outside="closeDropdown">
<!-- Button + Input dalam satu box -->
<div class="dropdown-toggle-box" v-on:click="dropdownOpen = !dropdownOpen">
<input type="text" class="form-control" v-model="searchQuery"
placeholder="Search product..." v-on:focus="dropdownOpen = true" v-on:click.stop />
<button type="button" class="btn btn-primary dropdown-btn" v-on:click.stop="dropdownOpen = !dropdownOpen">
</button>
</div>
<!-- Dropdown list -->
<div v-if="dropdownOpen" class="dropdown-content" v-on:click.stop>
<div v-for="(item, index) in filteredProducts"
:key="index" class="dropdown-item" v-on:mousedown.prevent="selectProduct(item)">
{{ item.productName + ' (' + item.modelNo + ')' }}
</div>
</div>
</div>
</div>
</div>
<!-- Category Dropdown -->
<div class="form-group row">
<label class="col-sm-2 col-form-label">Category:</label>
<div class="col-sm-8">
<input type="text" id="category" name="category" v-model="showProduct.category" class="form-control" readonly />
</div>
</div>
<!-- Image Product Dropdown-->
<div class="form-group row align-items-center">
<label for="imageProduct" class="col-sm-2 col-form-label">Product Image: </label>
<div class="col-sm-8">
<img v-if="showProduct.imageProduct" :src="showProduct.imageProduct" alt="Product Image" class="img-fluid" data-toggle="modal" data-target="#imageModal" />
<input type="hidden" id="imageProduct" name="imageProduct" v-model="showProduct">
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="imageModal" tabindex="-1" role="dialog" aria-labelledby="imageModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="imageModalLabel">Product Image</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<img :src="showProduct.imageProduct" alt="Product Image" class="img-fluid">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Quantity Input -->
<div class="form-group row d-flex align-items-center">
<label class="col-sm-2 col-form-label">Quantity:</label>
<div class="col-sm-8">
<input type="number" class="form-control" v-model="quantity" required />
</div>
</div>
@* Get the Item from who store *@
<div class="form-group row">
<label class="col-sm-2 col-form-label">Request From Store : </label>
<div class="col-sm-8">
<div class="dropdown">
<select class="btn btn-primary dropdown-toggle col-md-12" v-model="fromStoreItem" required>
<option class="btn-light" value="" selected disabled>Select Store</option>
<option class="btn-light" v-for="(item, index) in stores" :key="item" :value="item.id">{{ item.storeName ?? 'Select Store' }}</option>
</select>
</div>
</div>
</div>
<!-- Give Item to where store -->
<div class="form-group row">
<label class="col-sm-2 col-form-label">Send To Store : </label>
<div class="col-sm-8">
<div class="dropdown">
<select class="btn btn-primary dropdown-toggle col-md-12" data-toggle="dropdown" aria-expanded="false" v-model="assignStoreItem" required>
<option class="btn-light" value="" disabled selected>Select Store</option>
<option v-if="storeUser.length === 0" class="btn-light" disabled>No Store Assigned to You</option>
<option class="btn-light" v-for="(item, index) in storeUser" :key="index" :value="item.id">
{{ item.storeName }}
</option>
</select>
</div>
</div>
</div>
<!-- Remark Input (Wider) -->
<div class="form-group row d-flex align-items-center">
<label class="col-sm-2 col-form-label">Remark:</label>
<div class="col-sm-8">
<input type="text" class="form-control col-md-10" v-model="remark" />
</div>
</div>
<!-- Document/Picture Input -->
<div class="form-group row d-flex align-items-center">
<label class="col-sm-2 col-form-label">Document/Picture:</label>
<div class="col-sm-8">
<input type="file" id="document" name="document" class="form-control-file" v-on:change="handleFileUpload" accept="image/png, image/jpeg, application/pdf" />
</div>
</div>
@* Submit and Reset Buttons *@
<div class="form-group row">
<div class="col-sm-8 offset-sm-3">
<button type="button" v-on:click="resetForm" class="btn btn-secondary m-1">Reset</button>
<button type="submit" class="btn btn-primary m-1">Submit</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="approveModal" tabindex="-1" role="dialog" aria-labelledby="approveRequestModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content">
@ -194,50 +446,139 @@
requestDate : null,
approvalDate : null,
productCategory: "",
fromStoreItem : "",
assignStoreItem : "",
stores: null,
sortBy: "tech",
productName: null,
productCategory: null,
stations: [],
selectedProduct: "",
selectedStation: "",
selectedCategory: "",
selectedStore: "",
showRequestModal: false,
showRejectModal: false,
showApproveModal: false,
loading: false,
request: [],
currentUser: null,
currentUserId: null,
currentrequestID: "",
rejectremark: "",
approveremark: "",
storeUser: "",
searchQuery: "",
dropdownOpen: false,
showRequestModal: false,
}
},
mounted() {
async mounted() {
this.fetchRequest();
this.fetchUser();
this.fetchProducts();
this.fetchStation();
await this.fetchUser();
await Promise.all([
this.fetchStoreSpecific(this.currentUserId),
this.fetchStore(),
]);
},
watch: {
showRequestModal(newVal) {
if (newVal) {
$('#requestModal').modal('show');
} else {
$('#requestModal').modal('hide');
}
}
},
computed: {
// filteredDepartments() {
// if (!this.selectedCompany) {
// return []; No company selected, return empty list
// }
// const company = this.companies.find(c => c.companyId === this.selectedCompany);
// this.selectedDepartment = '';
// return company ? company.departments : [];
// },
// showProduct() {
// if (!this.selectedProduct) {
// return []; No company selected, return empty list
// }
// const product = this.products.find(c => c.productId === this.selectedProduct);
// return product ? product : {};
// },
showProduct() {
if (!this.productId) {
return []; // No company selected, return empty list
}
const product = this.products.find(c => c.productId === this.productId);
this.productCategory = product.category;
return product ? product : {};
},
filteredProducts() {
return this.products.filter(item =>
item.productName.toLowerCase().includes(this.searchQuery.toLowerCase()) ||
item.modelNo.toLowerCase().includes(this.searchQuery.toLowerCase())
);
}
},
methods: {
resetForm() {
this.rejectremark = "";
async addRequestMaster() {
try {
const requiredFields = ['productId', 'quantity', 'fromStoreItem', 'assignStoreItem'];
// Loop through required fields and check if any are null or empty
for (let field of requiredFields) {
if (this[field] === null || this[field] === '') {
alert('Request Error', `Please fill in required fields: ${field}.`, 'warning');
return; // Exit early if validation fails
}
}
this.userId = this.currentUser.id;
this.status = "Requested";
const now = new Date();
this.requestDate = new Date(now.getTime() + 8 * 60 * 60 * 1000).toISOString();
// Prepare data as JSON (No file upload)
const requestData = {
ProductId: this.productId,
StationId: null,
UserId: this.userId,
ProductCategory: this.productCategory,
RequestQuantity: this.quantity,
remarkUser: this.remark || '',
remarkMasterInv: '',
status: this.status,
requestDate: this.requestDate,
approvalDate: null,
fromStoreItem: this.fromStoreItem,
assignStoreItem: this.assignStoreItem,
Document: this.document
};
$('.modal').modal('hide');
// Proceed to send the data to the API
const response = await fetch('/InvMainAPI/AddRequestMaster', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
// 'Authorization': `Bearer ${this.token}`
},
body: JSON.stringify(formData)
});
if (response.ok) {
// If the form submission was successful, display a success message
alert('Success!', 'Request form has been successfully submitted.', 'success');
const requestItem = await response.json();
this.items.push(requestItem);
this.fetchRequest();
} else {
throw new Error('Failed to submit form.');
}
} catch (error) {
console.error('Error:', error);
// Displaying error message
alert('Inventory PSTW Error', `An error occurred: ${error.message}`, 'error');
}
},
async addRequest() {
try {
const requiredFields = ['stationId', 'productId', 'quantity', 'productCategory'];
@ -284,26 +625,13 @@
initiateTable() {
self = this;
this.requestDatatable = $('#requestDatatable').DataTable({
"data": this.items.filter(item => item.status == "Requested"),
"columns": [
{
"title": "Request ID",
"data": "requestID",
},
{
"title": "Action",
"data" :"requestID",
"render": function (data, type, row) {
function renderActionButtons(data, type, row) {
var actiontButtons = `<div class="row" style="padding: 5px;"> <button type="button" class="btn btn-success approve-btn" data-id="${data}">Approve</button></div> <div class="row" style="padding: 5px;"><button type="button" class="btn btn-danger reject-btn" data-id="${data}">Reject</button></div>`;
return actiontButtons
},
"className": "align-middle",
},
{
"title": "Product",
"data": "productName",
"render": function (data, type, full, meta) {
return actiontButtons;
}
function renderDocument(data, type, full, meta) {
if (!data) {
return "No Document";
}
@ -313,7 +641,6 @@
var isImage = /\.(jpeg|jpg|png|gif)$/i.test(imageSrc);
var isPdf = /\.pdf$/i.test(imageSrc);
// var imageSrc = full.productImage; Fallback to data if imgsrc is unavailable
console.log(full);
if (isImage) {
return ` <div class="row"><td>${data}</td></div>
@ -330,259 +657,106 @@
<br>View PDF
</a>`;
}
// else {
// return `<a href="${imageSrc}" target="_blank">Download File</a>`;
// }
},
},
{
"title": "Requested by User",
"data": "userName",
},
{
"title": "Requested by Station",
"data": "stationName",
},
{
"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 `<a href="${data}" target="_blank" data-lightbox="image-1">
<img src="${data}" alt="Image" class="img-thumbnail" style="width: 100px; height: 100px;" />
</a>`;
}
else if (isPdf) {
return `<a href="${data}" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/8/87/PDF_file_icon.svg"
alt="PDF Document" class="img-thumbnail"
style="width: 50px; height: 50px;" />
<br>View PDF
</a>`;
} else {
return `<a href="${data}" target="_blank">Download File</a>`;
}
},
},
{
"title": "User Remark",
"data": "remarkUser",
},
// {
// "title": "InvMaster Remark",
// "data": "remarkMasterInv",
// },
{
"title": "Status",
"data": "status",
},
{
"title": "Request Date",
"data": "requestDate",
},
{
"title": "Approval Date",
"data": "approvalDate",
},
// {
// "title": "Reject",
// "data" :"requestID",
// "render": function (data, type, row) {
// var rejectButton = `<button type="button" class="btn btn-danger reject-btn" data-id="${data}">Reject</button>`;
// return rejectButton
// },
// "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",
// }
this.requestDatatable = $('#requestDatatable').DataTable({
"data": this.items.filter(item => item.status === "Requested" && item.assignStoreItem == null),
"columns": [
{ "title": "Request ID", "data": "requestID" },
{ "title": "Action", "data": "requestID", "render": renderActionButtons, "className": "align-middle" },
{ "title": "Product", "data": "productName", "render": renderDocument },
{ "title": "Requested by User", "data": "userName" },
{ "title": "Requested by Station", "data": "stationName" },
{ "title": "Product Category", "data": "productCategory" },
{ "title": "Request Quantity", "data": "requestQuantity" },
{ "title": "Document/Picture", "data": "document", "render": renderDocument },
{ "title": "User Remark", "data": "remarkUser" },
{ "title": "Status", "data": "status" },
{ "title": "Request Date", "data": "requestDate" },
{ "title": "Approval Date", "data": "approvalDate" }
],
responsive: true,
drawCallback: function (settings) {
// Generate QR codes after rows are rendered
// const api = this.api();
// api.rows().every(function () {
// const data = this.data(); Row data
// const containerId = `qr${data.requestID}`;
// const container = $(`#${containerId}`);
// container.empty();
// container.append(`${data.requestID}`);
// console.log(container[0]);
// if (container) {
// Generate QR code only if not already generated
// new QRCode(container[0], {
// text: data.qrString,
// width: 100,
// height: 100,
// colorDark: "#000000",
// colorLight: "#ffffff",
// correctLevel: QRCode.CorrectLevel.M
// });
// }
// container.on('click', function() {
// window.open(data.qrString, '_blank');
// });
// });
},
drawCallback: function (settings) { }
});
this.settledrequestDatatable = $('#settledrequestDatatable').DataTable({
"data": this.items.filter(item => item.status !== "Requested"),
"data": this.items.filter(item => item.status !== "Requested" && item.assignStoreItem == null),
"columns": [
{
"title": "Request ID",
"data": "requestID",
},
{
"title": "Product",
"data": "productName",
"render": function (data, type, full, meta) {
if (!data) {
return "No Document";
}
var imageSrc = full.productImage;
// Check if the document is an image based on file extension
var isImage = /\.(jpeg|jpg|png|gif)$/i.test(imageSrc);
var isPdf = /\.pdf$/i.test(imageSrc);
// var imageSrc = full.productImage; Fallback to data if imgsrc is unavailable
if (isImage) {
return ` <div class="row"><td>${data}</td></div>
<a href="${imageSrc}" target="_blank" data-lightbox="image-1">
<img src="${imageSrc}" alt="Image" class="img-thumbnail" style="width: 100px; height: 100px;" />
</a>`;
}
else if (isPdf) {
return `<div class="row"><td>${data}</td></div>
<a href="${imageSrc}" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/8/87/PDF_file_icon.svg"
alt="PDF Document" class="img-thumbnail"
style="width: 50px; height: 50px;" />
<br>View PDF
</a>`;
}
// else {
// return `<a href="${imageSrc}" target="_blank">Download File</a>`;
// }
},
},
{
"title": "Requested by User",
"data": "userName",
},
{
"title": "Requested by Station",
"data": "stationName",
},
{
"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 `<a href="${data}" target="_blank" data-lightbox="image-1">
<img src="${data}" alt="Image" class="img-thumbnail" style="width: 100px; height: 100px;" />
</a>`;
}
else if (isPdf) {
return `<a href="${data}" target="_blank">
<img src="https://upload.wikimedia.org/wikipedia/commons/8/87/PDF_file_icon.svg"
alt="PDF Document" class="img-thumbnail"
style="width: 50px; height: 50px;" />
<br>View PDF
</a>`;
} else {
return `<a href="${data}" target="_blank">Download File</a>`;
}
},
},
{
"title": "User Remark",
"data": "remarkUser",
},
{
"title": "InvMaster Remark",
"data": "remarkMasterInv",
},
{
"title": "Status",
"data": "status",
},
{
"title": "Request Date",
"data": "requestDate",
},
{
"title": "Approval Date",
"data": "approvalDate",
},
// {
// "title": "Reject",
// "data" :null,
// "render": function (data, type, row) {
// return `<button type="button" class="btn btn-danger reject-btn"
// data-id="${row.requestID}"
// data-remark="${row.remark || ''}">
// Reject
// </button>`;
// },
// "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",
// }
{ "title": "Request ID", "data": "requestID" },
{ "title": "Product", "data": "productName", "render": renderDocument },
{ "title": "Requested by User", "data": "userName" },
{ "title": "Requested by Station", "data": "stationName" },
{ "title": "Product Category", "data": "productCategory" },
{ "title": "Request Quantity", "data": "requestQuantity" },
{ "title": "Document/Picture", "data": "document", "render": renderDocument },
{ "title": "User Remark", "data": "remarkUser" },
{ "title": "InvMaster Remark", "data": "remarkMasterInv" },
{ "title": "Status", "data": "status" },
{ "title": "Request Date", "data": "requestDate" },
{ "title": "Approval Date", "data": "approvalDate" }
],
responsive: true,
responsive: true
});
this.requestMasterDatatable = $('#requestMasterDatatable').DataTable({
"data": this.items.filter(item => item.assignStoreItem != null && item.status == "Requested" && item.userId == this.currentUserId),
"columns": [
{ "title": "Request ID", "data": "requestID" },
{ "title": "Action", "data": "requestID", "render": renderActionButtons, "className": "align-middle" },
{ "title": "Product", "data": "productName", "render": renderDocument },
{ "title": "Requested by User", "data": "userName" },
{ "title": "Requested by Station", "data": "stationName" },
{ "title": "Product Category", "data": "productCategory" },
{ "title": "Request Quantity", "data": "requestQuantity" },
{ "title": "Document/Picture", "data": "document", "render": renderDocument },
{ "title": "User Remark", "data": "remarkUser" },
{ "title": "Status", "data": "status" },
{ "title": "Request Date", "data": "requestDate" },
{ "title": "Approval Date", "data": "approvalDate" }
],
responsive: true,
drawCallback: function (settings) { }
});
this.requestOtherMasterDatatable = $('#requestOtherMasterDatatable').DataTable({
"data": this.items.filter(item => item.status != "Requested" && item.assignStoreItem != null && item.userId != this.currentUserId),
"columns": [
{ "title": "Request ID", "data": "requestID" },
{ "title": "Action", "data": "requestID", "render": renderActionButtons, "className": "align-middle" },
{ "title": "Product", "data": "productName", "render": renderDocument },
{ "title": "Requested by User", "data": "userName" },
{ "title": "Requested by Station", "data": "stationName" },
{ "title": "Product Category", "data": "productCategory" },
{ "title": "Request Quantity", "data": "requestQuantity" },
{ "title": "Document/Picture", "data": "document", "render": renderDocument },
{ "title": "User Remark", "data": "remarkUser" },
{ "title": "Status", "data": "status" },
{ "title": "Request Date", "data": "requestDate" },
{ "title": "Approval Date", "data": "approvalDate" }
],
responsive: true
});
// Attach click event listener to the delete buttons
this.settledrequestMasterDatatable = $('#settledrequestMasterDatatable').DataTable({
"data": this.items.filter(item => item.status != "Requested" && item.assignStoreItem != null && item.userId != this.currentUserId),
"columns": [
{ "title": "Request ID", "data": "requestID" },
{ "title": "Action", "data": "requestID", "render": renderActionButtons, "className": "align-middle" },
{ "title": "Product", "data": "productName", "render": renderDocument },
{ "title": "Requested by User", "data": "userName" },
{ "title": "Requested by Station", "data": "stationName" },
{ "title": "Product Category", "data": "productCategory" },
{ "title": "Request Quantity", "data": "requestQuantity" },
{ "title": "Document/Picture", "data": "document", "render": renderDocument },
{ "title": "User Remark", "data": "remarkUser" },
{ "title": "Status", "data": "status" },
{ "title": "Request Date", "data": "requestDate" },
{ "title": "Approval Date", "data": "approvalDate" }
],
responsive: true
});
// Attach event listeners
$('#requestDatatable tbody').on('click', '.reject-btn', function () {
const requestID = $(this).data('id');
self.rejectRequestModal(requestID);
@ -593,6 +767,19 @@
self.approveRequestModal(requestID);
});
$('#requestDatatable tbody').on('click', '.print-btn', function () {
const $button = $(this);
const $row = $button.closest('tr');
const itemId = $button.data('id');
let imageSrc = $row.hasClass('child') ? $row.prev('tr').find('td:nth-child(1) img').attr('src') : $row.find('td:nth-child(1) img').attr('src');
if (imageSrc) {
self.printItem(itemId, imageSrc);
} else {
console.error("Image source not found.");
}
});
$('#requestDatatable tbody').on('click', '.print-btn', function () {
const $button = $(this); // The clicked button
const $row = $button.closest('tr'); // The parent row of the button
@ -627,6 +814,7 @@
});
this.loading = false;
},
async fetchRequest() {
@ -648,6 +836,18 @@
if (this.requestDatatable) {
this.requestDatatable.clear().destroy();
}
if (this.settledrequestDatatable) {
this.settledrequestDatatable.clear().destroy();
}
if (this.requestMasterDatatable) {
this.requestMasterDatatable.clear().destroy();
}
if (this.requestOtherMasterDatatable) {
this.requestOtherMasterDatatable.clear().destroy();
}
if (this.settledrequestMasterDatatable) {
this.settledrequestMasterDatatable.clear().destroy();
}
this.initiateTable();
}
catch (error) {
@ -705,7 +905,26 @@
if (!response.ok) {
throw new Error('Failed to fetch suppliers');
}
this.stores = await response.json(); // Get the full response object
const data = await response.json();
this.stores = data.filter(stores => stores.id !== this.storeUser.storeId);
} catch (error) {
console.error('Error fetching suppliers:', error);
}
},
async fetchStoreSpecific(currentUserId) {
try {
const response = await fetch('/InvMainAPI/StoreSpecificMasterList/' + currentUserId, {
method: 'POST', // Specify the HTTP method
headers: {
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error('Failed to fetch store');
}
this.storeUser = await response.json(); // Get the full response object
} catch (error) {
console.error('Error fetching suppliers:', error);
@ -928,6 +1147,7 @@
this.currentUserCompanyDept = companyDeptData;
this.selectedCompany = companyDeptData?.companyId || "";
this.selectedDepartment = companyDeptData?.departmentId || "";
this.currentUserId = this.currentUser.id;
}
else {
console.error(`Failed to fetch user: ${response.statusText}`);
@ -938,10 +1158,62 @@
}
},
closeDropdown() {
this.dropdownOpen = false; // Tutup dropdown
},
selectProduct(item) {
this.selectedProduct = item;
this.productId = item.productId;
this.searchQuery = item.productName + " (" + item.modelNo + ")";
this.dropdownOpen = false;
},
closeModal() {
this.showRequestModal = false;
},
handleFileUpload(event) {
const file = event.target.files[0];
if (file) {
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;
}
},
resetForm() {
this.rejectremark = "";
},
handleSorting() {
this.fetchRequest();
},
},
directives: {
clickOutside: {
beforeMount(el, binding) {
el.clickOutsideEvent = (event) => {
// Make sure the click is outside the element
if (!el.contains(event.target) && el !== event.target) {
binding.value?.(); // Call the function to close the modal
}
};
setTimeout(() => {
document.body.addEventListener("click", el.clickOutsideEvent);
}, 0); // Delay to avoid triggering immediately when opening
},
beforeUnmount(el) {
document.body.removeEventListener("click", el.clickOutsideEvent);
}
}
}
});
</script>
}

View File

@ -3,7 +3,7 @@
Layout = "~/Views/Shared/_Layout.cshtml";
}
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml")
<div id="app">
<div class="row card">
<div class="card-header">

View File

@ -4,7 +4,7 @@
string userId = ViewBag.UserId;
}
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml")
<div class="row">
<div id="registerProduct" class="card m-1">
<div class="row" v-if="addSection == true">

View File

@ -3,7 +3,7 @@
Layout = "~/Views/Shared/_Layout.cshtml";
}
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml")
<div id="registerStation">
<form v-on:submit.prevent="addStation" data-aos="fade-right" id="registerStationForm" v-if="registerStationForm">
<div class="container register" data-aos="fade-right">

View File

@ -3,7 +3,7 @@
Layout = "~/Views/Shared/_Layout.cshtml";
}
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml")
<div id="registerSupplier">
<form v-on:submit.prevent="addSupplier" data-aos="fade-right" id="registerSupplierForm" v-if="registerSupplierForm">
<div class="container register" data-aos="fade-right">

View File

@ -969,6 +969,76 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
#endregion
#region ItemRequestAdmin
[HttpPost("AddRequestMaster")]
public async Task<IActionResult> AddRequestMaster([FromBody] RequestModel request)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
try
{
var findUniqueCode = _centralDbContext.Products.FirstOrDefault(r => r.ProductId == request.ProductId);
var findUniqueUser = _centralDbContext.Users.FirstOrDefault(r => r.Id == request.UserId);
if (!string.IsNullOrEmpty(request.Document))
{
var bytes = Convert.FromBase64String(request.Document);
string filePath = "";
var uniqueAbjad = new string(Enumerable.Range(0, 8).Select(_ => "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[new Random().Next(36)]).ToArray());
if (IsImage(bytes))
{
filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/media/inventory/request", findUniqueUser.FullName + " " + findUniqueCode.ModelNo + "(" + uniqueAbjad + ") Request.jpg");
request.Document = "/media/inventory/request/" + findUniqueUser.FullName + " " + findUniqueCode.ModelNo + "(" + uniqueAbjad + ") Request.jpg";
}
else if (IsPdf(bytes))
{
filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/media/inventory/request", findUniqueUser.FullName + " " + findUniqueCode.ModelNo + "_Request.pdf");
request.Document = "/media/inventory/request/" + findUniqueUser.FullName + " " + findUniqueCode.ModelNo + "(" + uniqueAbjad + ") Request.pdf";
}
else
{
return BadRequest("Unsupported file format.");
}
await System.IO.File.WriteAllBytesAsync(filePath, bytes);
}
_centralDbContext.Requests.Add(request);
await _centralDbContext.SaveChangesAsync();
var updatedList = await _centralDbContext.Requests
.Where(r => r.UserId == request.UserId)
.ToListAsync();
return Json(updatedList.Select(i => new
{
i.ProductId,
i.UserId,
i.status,
i.StationId,
i.RequestQuantity,
i.requestDate,
i.ProductCategory,
i.Document,
i.approvalDate,
i.remarkMasterInv,
i.remarkUser,
i.fromStoreItem,
i.assignStoreItem,
}));
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
[HttpGet("ItemRequestList")]
public async Task<IActionResult> ItemRequestList()
{
@ -991,6 +1061,8 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
i.approvalDate,
i.remarkMasterInv,
i.remarkUser,
i.assignStoreItem,
i.fromStoreItem,
}));
@ -1188,6 +1260,22 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
return Json(storeList);
}
[HttpPost("StoreSpecificMasterList/{userId}")]
public async Task<IActionResult> StoreSpecificMasterList(int userId)
{
var storeList = await _centralDbContext.InventoryMasters
.Where(i => i.UserId == userId)
.Select(i => i.StoreId) // Extract only StoreIds
.Distinct() // Avoid duplicate queries
.ToListAsync();
var storeSpecific = await _centralDbContext.Stores
.Where(s => storeList.Contains(s.Id)) // Fetch all relevant stores at once
.ToListAsync();
return Json(storeSpecific);
}
#endregion Store
#region AllUser

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,68 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PSTW_CentralSystem.Migrations
{
/// <inheritdoc />
public partial class UpdateTableRequest : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "assignStoreItem",
table: "request",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.AddColumn<string>(
name: "fromStoreItem",
table: "request",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.UpdateData(
table: "AspNetUsers",
keyColumn: "Id",
keyValue: 1,
columns: new[] { "ConcurrencyStamp", "PasswordHash", "SecurityStamp" },
values: new object[] { "407727d8-2266-45f2-9b48-ef3a450f09c6", "AQAAAAIAAYagAAAAEDc91vi8/AJwNGigDpnzFh7Iplvlph0VGj9GfG1zI6tY/jM/4f3P0CWVQZ/0oetzVg==", "2faceaca-f491-455a-9f10-3f641a5a7e0d" });
migrationBuilder.UpdateData(
table: "AspNetUsers",
keyColumn: "Id",
keyValue: 2,
columns: new[] { "ConcurrencyStamp", "PasswordHash", "SecurityStamp" },
values: new object[] { "8065f043-f8ed-4733-aa42-6ee6a1ebb636", "AQAAAAIAAYagAAAAEOmfi3vsFMnCUitXZqLgUaq5+Jqmigy8HrXwNqd8IELW2yvFQAMrfHLvJM5h0c+lfQ==", "46a8accc-305f-42e6-a4a2-376bfec07e84" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "assignStoreItem",
table: "request");
migrationBuilder.DropColumn(
name: "fromStoreItem",
table: "request");
migrationBuilder.UpdateData(
table: "AspNetUsers",
keyColumn: "Id",
keyValue: 1,
columns: new[] { "ConcurrencyStamp", "PasswordHash", "SecurityStamp" },
values: new object[] { "d801514b-2c36-4df7-9bb5-1c7e351ed27e", "AQAAAAIAAYagAAAAEBSoDiGEYlobLgzVcffYwvTtm1WnXpqrBBT1yYP+kruV4OTtizW7Sel94qAfqUjGcw==", "6132b0af-6a7f-4f38-8959-d049ed486e8f" });
migrationBuilder.UpdateData(
table: "AspNetUsers",
keyColumn: "Id",
keyValue: 2,
columns: new[] { "ConcurrencyStamp", "PasswordHash", "SecurityStamp" },
values: new object[] { "14f11e89-bb92-49dd-a8df-ec5b0d49df2d", "AQAAAAIAAYagAAAAEEvcS1SY+9pxZKH/P1l4TaodgW3SFSRfcZ+PnjB3MiMmEUSyYoo64AQtX0bOxFSX2g==", "6dca2498-5150-4369-9923-6f19a48258d4" });
}
}
}

View File

@ -422,6 +422,12 @@ namespace PSTW_CentralSystem.Migrations
b.Property<DateTime?>("approvalDate")
.HasColumnType("datetime(6)");
b.Property<string>("assignStoreItem")
.HasColumnType("longtext");
b.Property<string>("fromStoreItem")
.HasColumnType("longtext");
b.Property<string>("remarkMasterInv")
.HasColumnType("longtext");
@ -754,16 +760,16 @@ namespace PSTW_CentralSystem.Migrations
{
Id = 1,
AccessFailedCount = 0,
ConcurrencyStamp = "d801514b-2c36-4df7-9bb5-1c7e351ed27e",
ConcurrencyStamp = "407727d8-2266-45f2-9b48-ef3a450f09c6",
Email = "admin@pstw.com.my",
EmailConfirmed = true,
FullName = "MAAdmin",
LockoutEnabled = false,
NormalizedEmail = "ADMIN@PSTW.COM.MY",
NormalizedUserName = "ADMIN@PSTW.COM.MY",
PasswordHash = "AQAAAAIAAYagAAAAEBSoDiGEYlobLgzVcffYwvTtm1WnXpqrBBT1yYP+kruV4OTtizW7Sel94qAfqUjGcw==",
PasswordHash = "AQAAAAIAAYagAAAAEDc91vi8/AJwNGigDpnzFh7Iplvlph0VGj9GfG1zI6tY/jM/4f3P0CWVQZ/0oetzVg==",
PhoneNumberConfirmed = false,
SecurityStamp = "6132b0af-6a7f-4f38-8959-d049ed486e8f",
SecurityStamp = "2faceaca-f491-455a-9f10-3f641a5a7e0d",
TwoFactorEnabled = false,
UserInfoStatus = 1,
UserName = "admin@pstw.com.my"
@ -772,16 +778,16 @@ namespace PSTW_CentralSystem.Migrations
{
Id = 2,
AccessFailedCount = 0,
ConcurrencyStamp = "14f11e89-bb92-49dd-a8df-ec5b0d49df2d",
ConcurrencyStamp = "8065f043-f8ed-4733-aa42-6ee6a1ebb636",
Email = "sysadmin@pstw.com.my",
EmailConfirmed = true,
FullName = "SysAdmin",
LockoutEnabled = false,
NormalizedEmail = "SYSADMIN@PSTW.COM.MY",
NormalizedUserName = "SYSADMIN@PSTW.COM.MY",
PasswordHash = "AQAAAAIAAYagAAAAEEvcS1SY+9pxZKH/P1l4TaodgW3SFSRfcZ+PnjB3MiMmEUSyYoo64AQtX0bOxFSX2g==",
PasswordHash = "AQAAAAIAAYagAAAAEOmfi3vsFMnCUitXZqLgUaq5+Jqmigy8HrXwNqd8IELW2yvFQAMrfHLvJM5h0c+lfQ==",
PhoneNumberConfirmed = false,
SecurityStamp = "6dca2498-5150-4369-9923-6f19a48258d4",
SecurityStamp = "46a8accc-305f-42e6-a4a2-376bfec07e84",
TwoFactorEnabled = false,
UserInfoStatus = 1,
UserName = "sysadmin@pstw.com.my"

View File

@ -3,7 +3,7 @@
//"DefaultConnection": "Server=localhost;uid=root;Password='';Database=web_interface;"
//"DefaultConnection": "server=175.136.244.102;user id=root;password=tw_mysql_root;port=3306;database=web_interface"
//"CentralConnnection": "Server=192.168.12.12;Port=3306;uid=installer;password='pstw_mysql_installer';database=pstw_cs;", //DB_dev Local connection
"CentralConnnection": "Server=219.92.7.60;Port=3307;uid=installer;password='pstw_mysql_installer';database=pstw_cs_prod;" //DB_dev Public connection
"CentralConnnection": "Server=219.92.7.60;Port=3307;uid=installer;password='pstw_mysql_installer';database=pstw_cs;" //DB_dev Public connection
//"InventoryConnection": "Server=219.92.7.60;Port=3307;uid=installer;password='pstw_mysql_installer';database=pstw_cs_inventory;" //DB_dev connection
//"DefaultConnection": "Server=219.92.7.60;Port=3307;uid=intern;password='intern_mysql_acct';database=web_interface;"//DB_dev connection
},