pull update
This commit is contained in:
commit
92ce4b6267
@ -22,11 +22,7 @@ namespace PSTW_CentralSystem.Areas.Inventory.Controllers.Admin
|
|||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult ItemRequest()
|
public IActionResult ItemRequestMaster()
|
||||||
{
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
public IActionResult ItemRequestAdmin()
|
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ namespace PSTW_CentralSystem.Areas.Inventory.Controllers
|
|||||||
{
|
{
|
||||||
[Area("Inventory")]
|
[Area("Inventory")]
|
||||||
|
|
||||||
//[Authorize(Policy = "RoleModulePolicy")]
|
[Authorize(Policy = "RoleModulePolicy")]
|
||||||
public class ItemMovementController : Controller
|
public class ItemMovementController : Controller
|
||||||
{
|
{
|
||||||
// GET: Inventory
|
// GET: Inventory
|
||||||
@ -20,6 +20,16 @@ namespace PSTW_CentralSystem.Areas.Inventory.Controllers
|
|||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IActionResult ItemRequest()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult UserDashboard()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[HttpPost("/i/{id}")]
|
[HttpPost("/i/{id}")]
|
||||||
public IActionResult ItemRecognization(string id, [FromBody] ItemModel item)
|
public IActionResult ItemRecognization(string id, [FromBody] ItemModel item)
|
||||||
|
|||||||
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
namespace PSTW_CentralSystem.Areas.Inventory.Models
|
namespace PSTW_CentralSystem.Areas.Inventory.Models
|
||||||
{
|
{
|
||||||
|
[Table("request")]
|
||||||
public class RequestModel
|
public class RequestModel
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
@ -20,9 +21,9 @@ namespace PSTW_CentralSystem.Areas.Inventory.Models
|
|||||||
public string? remark { get; set; }
|
public string? remark { get; set; }
|
||||||
public string? status { get; set; }
|
public string? status { get; set; }
|
||||||
public DateTime requestDate { get; set; }
|
public DateTime requestDate { get; set; }
|
||||||
public DateTime approvalDate { get; set; }
|
public DateTime? approvalDate { get; set; }
|
||||||
public int RequestQuantity { get; set; }
|
public int RequestQuantity { get; set; }
|
||||||
public byte[]? Document { get; set; }
|
public string? Document { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,785 +0,0 @@
|
|||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Product Request";
|
|
||||||
Layout = "~/Views/Shared/_Layout.cshtml";
|
|
||||||
}
|
|
||||||
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
|
|
||||||
<div id="requestProduct" class="row">
|
|
||||||
<div class="row card">
|
|
||||||
<div class="card-header">
|
|
||||||
<button id="addRequestBtn" class="btn btn-success col-md-3 col-lg-3 m-1 col-12"><i class="fa fa-plus"></i> 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="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">×</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<div class="container-fluid">
|
|
||||||
<form v-on:submit.prevent="addRequest" 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-6">
|
|
||||||
|
|
||||||
<!-- Product Dropdown -->
|
|
||||||
<div class="form-group row">
|
|
||||||
<label class="col-sm-4 col-form-label">To Station</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<div class="dropdown">
|
|
||||||
<select class="btn btn-primary dropdown-toggle col-md-10" v-model="selectedtoStation" :disabled="currentUserCompanyDept != null" required>
|
|
||||||
<option class="btn-light" value="" disabled selected>Select Station</option>
|
|
||||||
<option class="btn-light" v-for="(station, index) in stations" :key="index" :value="station.stationId">{{station.stationName}}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Quantity Dropdown -->
|
|
||||||
<div class="form-group row">
|
|
||||||
<label class="col-sm-4 col-form-label">To Store:</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<select class="btn btn-primary dropdown-toggle col-md-10" v-model="selectedtoStore" :disabled="currentUserCompanyDept != null" required>
|
|
||||||
<option class="btn-light" value="" disabled selected>Select Store</option>
|
|
||||||
<option class="btn-light" v-for="(store, index) in stores" :key="index" :value="store.companyId">{{ store.storeName }}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Station Dropdown -->
|
|
||||||
<div class="form-group row">
|
|
||||||
<label class="col-sm-4 col-form-label">To User:</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<select class="btn btn-primary dropdown-toggle col-md-10" v-model="selectedtoUser" :disabled="currentUserCompanyDept != null" required>
|
|
||||||
<option class="btn-light" value="" disabled selected>Select User</option>
|
|
||||||
<option class="btn-light" v-for="(user, index) in users" :key="index" :value="user.id">{{ user.fullName }}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Remark Dropdown -->
|
|
||||||
<div class="form-group row">
|
|
||||||
<label class="col-sm-4 col-form-label">Last User:</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<select class="btn btn-primary dropdown-toggle col-md-10" v-model="selectedlastUser" :disabled="currentUserCompanyDept != null" required>
|
|
||||||
<option class="btn-light" value="" disabled selected>Select Store</option>
|
|
||||||
<option class="btn-light" v-for="(store, index) in stores" :key="index" :value="store.companyId">{{ store.storeName }}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Document/Picture Dropdown -->
|
|
||||||
<div class="form-group row">
|
|
||||||
<label class="col-sm-4 col-form-label">Last Store:</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<select class="btn btn-primary dropdown-toggle col-md-10" v-model="selectedlastStore" :disabled="currentUserCompanyDept != null" required>
|
|
||||||
<option class="btn-light" value="" disabled selected>Select Store</option>
|
|
||||||
<option class="btn-light" v-for="(store, index) in stores" :key="index" :value="store.companyId">{{ store.storeName }}</option>
|
|
||||||
</select>
|
|
||||||
</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>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
@{
|
|
||||||
await Html.RenderPartialAsync("_ValidationScriptsPartial");
|
|
||||||
}
|
|
||||||
<script>
|
|
||||||
$(function () {
|
|
||||||
app.mount('#requestProduct');
|
|
||||||
|
|
||||||
// Attach a click event listener to elements with the class 'btn-success'.
|
|
||||||
$('#addRequestBtn').on('click', function () {
|
|
||||||
// Show the modal with the ID 'addManufacturerModal'.
|
|
||||||
$('#requestModal').modal('show');
|
|
||||||
});
|
|
||||||
$('.closeModal').on('click', function () {
|
|
||||||
// Show the modal with the ID 'addManufacturerModal'.
|
|
||||||
$('.modal').modal('hide');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
const app = Vue.createApp({
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
requestId : null,
|
|
||||||
userId : null,
|
|
||||||
stationId : null,
|
|
||||||
productId : null,
|
|
||||||
remark: "",
|
|
||||||
document: null,
|
|
||||||
quantity: 0,
|
|
||||||
status: "",
|
|
||||||
requestDate : null,
|
|
||||||
approvalDate : null,
|
|
||||||
productCategory: "",
|
|
||||||
|
|
||||||
productName: null,
|
|
||||||
productCategory: null,
|
|
||||||
stations: [],
|
|
||||||
selectedProduct: "",
|
|
||||||
selectedStation: "",
|
|
||||||
selectedCategory: "",
|
|
||||||
showRequestModal: false,
|
|
||||||
loading: false,
|
|
||||||
request: [],
|
|
||||||
currentUser: null,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.fetchRequest();
|
|
||||||
this.fetchUser();
|
|
||||||
this.fetchProducts();
|
|
||||||
this.fetchStation();
|
|
||||||
},
|
|
||||||
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 : {};
|
|
||||||
},
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
async addRequest() {
|
|
||||||
try {
|
|
||||||
const requiredFields = ['stationId', 'productId', 'quantity', 'productCategory'];
|
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestData = {
|
|
||||||
ProductId: this.productId,
|
|
||||||
StationId: this.stationId,
|
|
||||||
UserId: this.userId,
|
|
||||||
ProductCategory: this.productCategory,
|
|
||||||
RequestQuantitiy: this.quantity,
|
|
||||||
Document: this.document,
|
|
||||||
remark: this.remark,
|
|
||||||
status: this.status,
|
|
||||||
requestDate: this.requestDate,
|
|
||||||
approvalDate: this.approvalDate,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Proceed to send the data to the API
|
|
||||||
const response = await fetch('/InvMainAPI/AddRequest', {
|
|
||||||
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();
|
|
||||||
|
|
||||||
// Reset the form
|
|
||||||
this.resetForm();
|
|
||||||
} 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');
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
initiateTable() {
|
|
||||||
self = this;
|
|
||||||
this.requestDatatable = $('#requestDatatable').DataTable({
|
|
||||||
"data": this.items,
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"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}`);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Print",
|
|
||||||
"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": "Remark",
|
|
||||||
"data": "remark",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Status",
|
|
||||||
"data": "status",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Request Date",
|
|
||||||
"data": "requestDate",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Approval Date",
|
|
||||||
"data": "approvalDate",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Reject",
|
|
||||||
"data": "requestId",
|
|
||||||
"render": function (data) {
|
|
||||||
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,
|
|
||||||
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');
|
|
||||||
// });
|
|
||||||
});
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
// Attach click event listener to the delete buttons
|
|
||||||
$('#requestDatatable tbody').on('click', '.reject-btn', function () {
|
|
||||||
const itemId = $(this).data('id');
|
|
||||||
self.rejectRequest(itemId);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#requestDatatable tbody').on('click', '.approve-btn', function () {
|
|
||||||
const itemId = $(this).data('id');
|
|
||||||
self.approveRequest(itemId);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#requestDatatable tbody').on('click', '.print-btn', function () {
|
|
||||||
const $button = $(this); // The clicked button
|
|
||||||
const $row = $button.closest('tr'); // The parent row of the button
|
|
||||||
const itemId = $button.data('id'); // Get the item ID from the button's data attribute
|
|
||||||
|
|
||||||
let imageSrc;
|
|
||||||
|
|
||||||
// Check if the table is collapsed
|
|
||||||
if ($row.hasClass('child')) {
|
|
||||||
// For collapsed view: Look for the closest `.dtr-data` that contains the img
|
|
||||||
imageSrc = $row.prev('tr').find('td:nth-child(1) img').attr('src');
|
|
||||||
} else {
|
|
||||||
// For expanded view: Find the img in the first column of the current row
|
|
||||||
imageSrc = $row.find('td:nth-child(1) img').attr('src');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (imageSrc) {
|
|
||||||
self.printItem(itemId, imageSrc); // Call the print function with the itemId and imageSrc
|
|
||||||
} else {
|
|
||||||
console.error("Image source not found.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.loading = false;
|
|
||||||
},
|
|
||||||
|
|
||||||
async fetchRequest() {
|
|
||||||
try {
|
|
||||||
// const token = localStorage.getItem('token'); // Get the token from localStorage
|
|
||||||
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
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch item');
|
|
||||||
}
|
|
||||||
this.items = await response.json();
|
|
||||||
|
|
||||||
if (this.requestDatatable) {
|
|
||||||
this.requestDatatable.clear().destroy();
|
|
||||||
}
|
|
||||||
this.initiateTable();
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.error('Error fetching item:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async fetchProducts() {
|
|
||||||
try {
|
|
||||||
// const token = localStorage.getItem('token'); // Get the token from localStorage
|
|
||||||
const response = await fetch('/InvMainAPI/ProductList', {
|
|
||||||
method: 'POST', // Specify the HTTP method
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json', // Set content type
|
|
||||||
// 'Authorization': `Bearer ${token}` // Include the token in the headers
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch products');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.products = await response.json();
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.error('Error fetching products:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async fetchCompanies() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/AdminAPI/GetDepartmentWithCompanyList', {
|
|
||||||
method: 'POST', // Specify the HTTP method
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch companies');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.companies = await response.json();
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching products:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async fetchSuppliers() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/InvMainAPI/SupplierList', {
|
|
||||||
method: 'POST', // Specify the HTTP method
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch suppliers');
|
|
||||||
}
|
|
||||||
this.suppliers = await response.json(); // Get the full response object
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching suppliers:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async fetchStation() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/InvMainAPI/StationList', {
|
|
||||||
method: 'POST', // Specify the HTTP method
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch suppliers');
|
|
||||||
}
|
|
||||||
this.stations = await response.json(); // Get the full response object
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching suppliers:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async fetchStore() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/InvMainAPI/StoreList/', {
|
|
||||||
method: 'POST', // Specify the HTTP method
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch suppliers');
|
|
||||||
}
|
|
||||||
this.stores = await response.json(); // Get the full response object
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching suppliers:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async fetchUsers() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/InvMainAPI/UserList', {
|
|
||||||
method: 'POST', // Specify the HTTP method
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch suppliers');
|
|
||||||
}
|
|
||||||
this.users = await response.json(); // Get the full response object
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching suppliers:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async fetchCurrencyData() {
|
|
||||||
try {
|
|
||||||
// Fetch currency data from the API
|
|
||||||
const response = await fetch('https://openexchangerates.org/api/currencies.json'); // Example API
|
|
||||||
this.currencies = await response.json();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching currency data:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
convertCurrency() {
|
|
||||||
// Your currency conversion logic here
|
|
||||||
console.log('Selected currency:', this.currency);
|
|
||||||
},
|
|
||||||
resetForm() {
|
|
||||||
this.company = '';
|
|
||||||
this.Dept = null;
|
|
||||||
this.productName = null;
|
|
||||||
this.imageProduct = null;
|
|
||||||
this.serialNumber = '';
|
|
||||||
this.quantity = 1;
|
|
||||||
this.supplierName = null;
|
|
||||||
this.purchaseDate = null;
|
|
||||||
this.PO = null;
|
|
||||||
this.currency = 'MYR';
|
|
||||||
this.DefaultPrice = 0.01;
|
|
||||||
this.currencyRate = 1;
|
|
||||||
this.convertPrice = 0.01;
|
|
||||||
this.DODate = null;
|
|
||||||
this.warranty = 0;
|
|
||||||
this.EndWDate = null;
|
|
||||||
this.invoiceDate = null;
|
|
||||||
this.selectedProduct = '';
|
|
||||||
this.selectedSupplier = '';
|
|
||||||
this.selectedCompany = this.currentUserCompanyDept.companyId;
|
|
||||||
this.selectedDepartment = '';
|
|
||||||
this.selectedTeamType = '';
|
|
||||||
this.partNumber = null;
|
|
||||||
},
|
|
||||||
|
|
||||||
// FRONT END FUNCTIONS
|
|
||||||
//----------------------//
|
|
||||||
//Calculate Total Price
|
|
||||||
convertCurrency() {
|
|
||||||
const total = this.DefaultPrice * this.currencyRate;
|
|
||||||
this.convertPrice = total.toFixed(2);
|
|
||||||
this.DefaultPrice = this.DefaultPrice
|
|
||||||
// .replace(/[^0-9.]/g, '') // Remove non-numeric characters except decimal points
|
|
||||||
// .replace(/(\..*)\..*/g, '$1') // Allow only one decimal point
|
|
||||||
// .replace(/^(\d*\.\d{0,2})\d*$/, '$1'); // Limit to two decimal places
|
|
||||||
|
|
||||||
},
|
|
||||||
calculateWarrantyEndDate() {
|
|
||||||
// Check if DODate and warranty are valid
|
|
||||||
if (!this.DODate || isNaN(Date.parse(this.DODate))) {
|
|
||||||
this.EndWDate = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const DODates = new Date(this.DODate);
|
|
||||||
const warrantyMonth = parseInt(this.warranty);
|
|
||||||
|
|
||||||
// Ensure warranty is a valid number
|
|
||||||
if (!isNaN(warrantyMonth)) {
|
|
||||||
DODates.setMonth(DODates.getMonth() + warrantyMonth);
|
|
||||||
this.EndWDate = DODates.toISOString().split('T')[0];
|
|
||||||
} else {
|
|
||||||
this.EndWDate = null;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async approveRequest(itemId) {
|
|
||||||
// if (!confirm("Are you sure you want to approve this request?")) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
try {
|
|
||||||
const response = await fetch(`/InvMainAPI/ApproveRequest/${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.requestDatatable.row(row)
|
|
||||||
.data({ ...this.requestDatatable.row(row)
|
|
||||||
.data(), status: "Approved" })
|
|
||||||
.draw();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
alert(result.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
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.requestDatatable.row(row)
|
|
||||||
.data({ ...this.requestDatatable.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;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async printItem(itemId, imgSrc) {
|
|
||||||
try {
|
|
||||||
this.thisQRInfo.uniqueID = itemId;
|
|
||||||
const uniqueQR = itemId;
|
|
||||||
const container = document.getElementById("QrContainer");
|
|
||||||
|
|
||||||
if (!container) {
|
|
||||||
console.error("Container not found.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Safely set image content
|
|
||||||
const sanitizedImgSrc = encodeURI(imgSrc); // Sanitize the URL
|
|
||||||
container.innerHTML = `<img src="${sanitizedImgSrc}" alt="QR Code" class="text-center " />`;
|
|
||||||
|
|
||||||
// Fetch QR information
|
|
||||||
const qrInfo = this.getPrintedQR(uniqueQR);
|
|
||||||
if (!qrInfo) {
|
|
||||||
console.error("QR Info not found.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.thisQRInfo = qrInfo;
|
|
||||||
this.thisQRInfo.imgSrc = sanitizedImgSrc
|
|
||||||
this.thisQRInfo.imgContainer = container.innerHTML
|
|
||||||
$(`#QrItemModal`).modal('show'); // Show modal
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.error("Error generating QR code:", error);
|
|
||||||
alert("An error occurred while generating the QR code.");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async fetchUser() {
|
|
||||||
try {
|
|
||||||
const response = await fetch(`/IdentityAPI/GetUserInformation/`, {
|
|
||||||
method: 'POST',
|
|
||||||
});
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
this.currentUser = data?.userInfo || null;
|
|
||||||
const companyDeptData = await this.currentUser.department;
|
|
||||||
this.currentUserCompanyDept = companyDeptData;
|
|
||||||
this.selectedCompany = companyDeptData?.companyId || "";
|
|
||||||
this.selectedDepartment = companyDeptData?.departmentId || "";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.error(`Failed to fetch user: ${response.statusText}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.error('There was a problem with the fetch operation:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
getPrintedQR(uniqueID) {
|
|
||||||
if (!this.items || !Array.isArray(this.items)) {
|
|
||||||
console.error("Items list is not available or is not an array.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return this.items.find(item => item.uniqueID === uniqueID);
|
|
||||||
},
|
|
||||||
printQRInfo() {
|
|
||||||
// Create a virtual DOM element
|
|
||||||
const virtualElement = document.createElement('div');
|
|
||||||
virtualElement.style.width = '330px '; // Match label size for 2 inches at 203 DPI
|
|
||||||
virtualElement.style.height = '160px';
|
|
||||||
virtualElement.style.position = 'absolute';
|
|
||||||
virtualElement.style.left = '-9999px'; // Position offscreen to avoid rendering on the main UI
|
|
||||||
// virtualElement.style.border = '1px solid #000'; // Optional: Add a border for debugging dimensions
|
|
||||||
|
|
||||||
// Populate the virtual DOM with content
|
|
||||||
virtualElement.innerHTML = `
|
|
||||||
<div class="container-fluid my-3 QrPrintFont" style="font-family: 'OCR A', monospace;">
|
|
||||||
<div class="row" >
|
|
||||||
<div class="col-5 text-center d-flex align-items-center justify-content-center">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-12">
|
|
||||||
<div>${this.thisQRInfo.imgContainer}</div>
|
|
||||||
<div class="col-12 h4"style="font-family: 'Arial', monospace;"><b>${this.thisQRInfo.uniqueID}</b></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-7 d-flex align-items-center justify-content-left">
|
|
||||||
<div class="row-fluid">
|
|
||||||
<div class="col-12 h3"style="font-family: 'Verdana', monospace;"><b>${this.thisQRInfo.departmentName}</b></div>
|
|
||||||
<div class="col-12 h4"style="font-family: 'Arial', monospace;"><b>${this.thisQRInfo.productShortName}</b></div>
|
|
||||||
<div class="col-12 h4"style="font-family: 'Arial', monospace;"><b>${this.thisQRInfo.serialNumber??"-"}</b></div>
|
|
||||||
<div class="col-12 h4"style="font-family: 'Arial', monospace;"><b>${this.thisQRInfo.partNumber}</b></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
// Append the virtual DOM to the body (temporarily)
|
|
||||||
document.body.appendChild(virtualElement);
|
|
||||||
|
|
||||||
// Wait for the font to be loaded (important for custom fonts like OCR-A)
|
|
||||||
document.fonts.load('1em "OCR A"').then(() => {
|
|
||||||
// Use html2canvas to convert the virtual DOM to an image
|
|
||||||
html2canvas(virtualElement, {
|
|
||||||
scale: 1, // Increase scale for sharper images
|
|
||||||
}).then((canvas) => {
|
|
||||||
// Convert the canvas to an image
|
|
||||||
const imgData = canvas.toDataURL('image/png');
|
|
||||||
// Open the image in a new tab for preview (optional)
|
|
||||||
// const newWindow = window.open();
|
|
||||||
// newWindow.location.href = imgData;
|
|
||||||
// console.log(imgData)
|
|
||||||
// Use printJS to print the image
|
|
||||||
printJS({
|
|
||||||
printable: imgData,
|
|
||||||
type: 'image',
|
|
||||||
css: '/../lib/bootstrap/dist/css/bootstrap.css',
|
|
||||||
style: `
|
|
||||||
@@media print {
|
|
||||||
@@page {
|
|
||||||
margin: 5px 5px 0px 5px;
|
|
||||||
}
|
|
||||||
body { margin: 0; }
|
|
||||||
}
|
|
||||||
`
|
|
||||||
});
|
|
||||||
|
|
||||||
// Remove the virtual DOM from the body after use
|
|
||||||
document.body.removeChild(virtualElement);
|
|
||||||
}).catch((error) => {
|
|
||||||
console.error("Error generating image:", error);
|
|
||||||
// Remove the virtual DOM if an error occurs
|
|
||||||
document.body.removeChild(virtualElement);
|
|
||||||
});
|
|
||||||
}).catch((error) => {
|
|
||||||
console.error("Error loading font:", error);
|
|
||||||
// Remove the virtual DOM if font loading fails
|
|
||||||
document.body.removeChild(virtualElement);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
},
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
}
|
|
||||||
@ -1,783 +1 @@
|
|||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Product Request";
|
|
||||||
Layout = "~/Views/Shared/_Layout.cshtml";
|
|
||||||
}
|
|
||||||
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
|
|
||||||
<div id="requestProduct" class="row">
|
|
||||||
<div class="row card">
|
|
||||||
<div class="card-header">
|
|
||||||
<button id="addRequestBtn" class="btn btn-success col-md-3 col-lg-3 m-1 col-12"><i class="fa fa-plus"></i> 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="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">×</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
<div class="container-fluid">
|
|
||||||
<form v-on:submit.prevent="addRequest" 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-6">
|
|
||||||
|
|
||||||
<!-- Product Dropdown -->
|
|
||||||
<div class="form-group row">
|
|
||||||
<label class="col-sm-4 col-form-label">To Station</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<div class="dropdown">
|
|
||||||
<select class="btn btn-primary dropdown-toggle col-md-10" v-model="selectedtoStation" :disabled="currentUserCompanyDept != null" required>
|
|
||||||
<option class="btn-light" value="" disabled selected>Select Station</option>
|
|
||||||
<option class="btn-light" v-for="(station, index) in stations" :key="index" :value="station.stationId">{{station.stationName}}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Quantity Dropdown -->
|
|
||||||
<div class="form-group row">
|
|
||||||
<label class="col-sm-4 col-form-label">To Store:</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<select class="btn btn-primary dropdown-toggle col-md-10" v-model="selectedtoStore" :disabled="currentUserCompanyDept != null" required>
|
|
||||||
<option class="btn-light" value="" disabled selected>Select Store</option>
|
|
||||||
<option class="btn-light" v-for="(store, index) in stores" :key="index" :value="store.companyId">{{ store.storeName }}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Station Dropdown -->
|
|
||||||
<div class="form-group row">
|
|
||||||
<label class="col-sm-4 col-form-label">To User:</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<select class="btn btn-primary dropdown-toggle col-md-10" v-model="selectedtoUser" :disabled="currentUserCompanyDept != null" required>
|
|
||||||
<option class="btn-light" value="" disabled selected>Select User</option>
|
|
||||||
<option class="btn-light" v-for="(user, index) in users" :key="index" :value="user.id">{{ user.fullName }}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Remark Dropdown -->
|
|
||||||
<div class="form-group row">
|
|
||||||
<label class="col-sm-4 col-form-label">Last User:</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<select class="btn btn-primary dropdown-toggle col-md-10" v-model="selectedlastUser" :disabled="currentUserCompanyDept != null" required>
|
|
||||||
<option class="btn-light" value="" disabled selected>Select Store</option>
|
|
||||||
<option class="btn-light" v-for="(store, index) in stores" :key="index" :value="store.companyId">{{ store.storeName }}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Document/Picture Dropdown -->
|
|
||||||
<div class="form-group row">
|
|
||||||
<label class="col-sm-4 col-form-label">Last Store:</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<select class="btn btn-primary dropdown-toggle col-md-10" v-model="selectedlastStore" :disabled="currentUserCompanyDept != null" required>
|
|
||||||
<option class="btn-light" value="" disabled selected>Select Store</option>
|
|
||||||
<option class="btn-light" v-for="(store, index) in stores" :key="index" :value="store.companyId">{{ store.storeName }}</option>
|
|
||||||
</select>
|
|
||||||
</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>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
@{
|
|
||||||
await Html.RenderPartialAsync("_ValidationScriptsPartial");
|
|
||||||
}
|
|
||||||
<script>
|
|
||||||
$(function () {
|
|
||||||
app.mount('#requestProduct');
|
|
||||||
|
|
||||||
// Attach a click event listener to elements with the class 'btn-success'.
|
|
||||||
$('#addRequestBtn').on('click', function () {
|
|
||||||
// Show the modal with the ID 'addManufacturerModal'.
|
|
||||||
$('#requestModal').modal('show');
|
|
||||||
});
|
|
||||||
$('.closeModal').on('click', function () {
|
|
||||||
// Show the modal with the ID 'addManufacturerModal'.
|
|
||||||
$('.modal').modal('hide');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
const app = Vue.createApp({
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
requestId : null,
|
|
||||||
userId : null,
|
|
||||||
stationId : null,
|
|
||||||
productId : null,
|
|
||||||
remark: "",
|
|
||||||
document: null,
|
|
||||||
quantity: 0,
|
|
||||||
status: "",
|
|
||||||
requestDate : null,
|
|
||||||
approvalDate : null,
|
|
||||||
selectedCategory: "",
|
|
||||||
|
|
||||||
productName: null,
|
|
||||||
productCategory: null,
|
|
||||||
stations: [],
|
|
||||||
selectedProduct: "",
|
|
||||||
selectedStation: "",
|
|
||||||
showRequestModal: false,
|
|
||||||
loading: false,
|
|
||||||
request: [],
|
|
||||||
currentUser: null,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.fetchRequest();
|
|
||||||
this.fetchUser();
|
|
||||||
this.fetchProducts();
|
|
||||||
this.fetchStation();
|
|
||||||
},
|
|
||||||
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 : {};
|
|
||||||
},
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
async addRequest() {
|
|
||||||
try {
|
|
||||||
const requiredFields = ['stationId', 'productId', 'quantity', 'productCategory'];
|
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestData = {
|
|
||||||
ProductId: this.productId,
|
|
||||||
StationId: this.stationId,
|
|
||||||
UserId: this.userId,
|
|
||||||
RequestQuantitiy: this.quantity,
|
|
||||||
Document: this.document,
|
|
||||||
remark: this.remark,
|
|
||||||
status: this.status,
|
|
||||||
requestDate: this.requestDate,
|
|
||||||
approvalDate: this.approvalDate,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Proceed to send the data to the API
|
|
||||||
const response = await fetch('/InvMainAPI/AddRequest', {
|
|
||||||
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();
|
|
||||||
|
|
||||||
// Reset the form
|
|
||||||
this.resetForm();
|
|
||||||
} 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');
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
initiateTable() {
|
|
||||||
self = this;
|
|
||||||
this.requestDatatable = $('#requestDatatable').DataTable({
|
|
||||||
"data": this.items,
|
|
||||||
"columns": [
|
|
||||||
{
|
|
||||||
"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}`);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Print",
|
|
||||||
"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": "Remark",
|
|
||||||
"data": "remark",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Status",
|
|
||||||
"data": "status",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Request Date",
|
|
||||||
"data": "requestDate",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Approval Date",
|
|
||||||
"data": "approvalDate",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Reject",
|
|
||||||
"data": "requestId",
|
|
||||||
"render": function (data) {
|
|
||||||
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,
|
|
||||||
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');
|
|
||||||
// });
|
|
||||||
});
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
// Attach click event listener to the delete buttons
|
|
||||||
$('#requestDatatable tbody').on('click', '.reject-btn', function () {
|
|
||||||
const itemId = $(this).data('id');
|
|
||||||
self.rejectRequest(itemId);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#requestDatatable tbody').on('click', '.approve-btn', function () {
|
|
||||||
const itemId = $(this).data('id');
|
|
||||||
self.approveRequest(itemId);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#requestDatatable tbody').on('click', '.print-btn', function () {
|
|
||||||
const $button = $(this); // The clicked button
|
|
||||||
const $row = $button.closest('tr'); // The parent row of the button
|
|
||||||
const itemId = $button.data('id'); // Get the item ID from the button's data attribute
|
|
||||||
|
|
||||||
let imageSrc;
|
|
||||||
|
|
||||||
// Check if the table is collapsed
|
|
||||||
if ($row.hasClass('child')) {
|
|
||||||
// For collapsed view: Look for the closest `.dtr-data` that contains the img
|
|
||||||
imageSrc = $row.prev('tr').find('td:nth-child(1) img').attr('src');
|
|
||||||
} else {
|
|
||||||
// For expanded view: Find the img in the first column of the current row
|
|
||||||
imageSrc = $row.find('td:nth-child(1) img').attr('src');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (imageSrc) {
|
|
||||||
self.printItem(itemId, imageSrc); // Call the print function with the itemId and imageSrc
|
|
||||||
} else {
|
|
||||||
console.error("Image source not found.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.loading = false;
|
|
||||||
},
|
|
||||||
|
|
||||||
async fetchRequest() {
|
|
||||||
try {
|
|
||||||
// const token = localStorage.getItem('token'); // Get the token from localStorage
|
|
||||||
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
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch item');
|
|
||||||
}
|
|
||||||
this.items = await response.json();
|
|
||||||
|
|
||||||
if (this.requestDatatable) {
|
|
||||||
this.requestDatatable.clear().destroy();
|
|
||||||
}
|
|
||||||
this.initiateTable();
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.error('Error fetching item:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async fetchProducts() {
|
|
||||||
try {
|
|
||||||
// const token = localStorage.getItem('token'); // Get the token from localStorage
|
|
||||||
const response = await fetch('/InvMainAPI/ProductList', {
|
|
||||||
method: 'POST', // Specify the HTTP method
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json', // Set content type
|
|
||||||
// 'Authorization': `Bearer ${token}` // Include the token in the headers
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch products');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.products = await response.json();
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.error('Error fetching products:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async fetchCompanies() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/AdminAPI/GetDepartmentWithCompanyList', {
|
|
||||||
method: 'POST', // Specify the HTTP method
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch companies');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.companies = await response.json();
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching products:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async fetchSuppliers() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/InvMainAPI/SupplierList', {
|
|
||||||
method: 'POST', // Specify the HTTP method
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch suppliers');
|
|
||||||
}
|
|
||||||
this.suppliers = await response.json(); // Get the full response object
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching suppliers:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async fetchStation() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/InvMainAPI/StationList', {
|
|
||||||
method: 'POST', // Specify the HTTP method
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch suppliers');
|
|
||||||
}
|
|
||||||
this.stations = await response.json(); // Get the full response object
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching suppliers:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async fetchStore() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/InvMainAPI/StoreList/', {
|
|
||||||
method: 'POST', // Specify the HTTP method
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch suppliers');
|
|
||||||
}
|
|
||||||
this.stores = await response.json(); // Get the full response object
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching suppliers:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async fetchUsers() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('/InvMainAPI/UserList', {
|
|
||||||
method: 'POST', // Specify the HTTP method
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Failed to fetch suppliers');
|
|
||||||
}
|
|
||||||
this.users = await response.json(); // Get the full response object
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching suppliers:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async fetchCurrencyData() {
|
|
||||||
try {
|
|
||||||
// Fetch currency data from the API
|
|
||||||
const response = await fetch('https://openexchangerates.org/api/currencies.json'); // Example API
|
|
||||||
this.currencies = await response.json();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching currency data:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
convertCurrency() {
|
|
||||||
// Your currency conversion logic here
|
|
||||||
console.log('Selected currency:', this.currency);
|
|
||||||
},
|
|
||||||
resetForm() {
|
|
||||||
this.company = '';
|
|
||||||
this.Dept = null;
|
|
||||||
this.productName = null;
|
|
||||||
this.imageProduct = null;
|
|
||||||
this.serialNumber = '';
|
|
||||||
this.quantity = 1;
|
|
||||||
this.supplierName = null;
|
|
||||||
this.purchaseDate = null;
|
|
||||||
this.PO = null;
|
|
||||||
this.currency = 'MYR';
|
|
||||||
this.DefaultPrice = 0.01;
|
|
||||||
this.currencyRate = 1;
|
|
||||||
this.convertPrice = 0.01;
|
|
||||||
this.DODate = null;
|
|
||||||
this.warranty = 0;
|
|
||||||
this.EndWDate = null;
|
|
||||||
this.invoiceDate = null;
|
|
||||||
this.selectedProduct = '';
|
|
||||||
this.selectedSupplier = '';
|
|
||||||
this.selectedCompany = this.currentUserCompanyDept.companyId;
|
|
||||||
this.selectedDepartment = '';
|
|
||||||
this.selectedTeamType = '';
|
|
||||||
this.partNumber = null;
|
|
||||||
},
|
|
||||||
|
|
||||||
// FRONT END FUNCTIONS
|
|
||||||
//----------------------//
|
|
||||||
//Calculate Total Price
|
|
||||||
convertCurrency() {
|
|
||||||
const total = this.DefaultPrice * this.currencyRate;
|
|
||||||
this.convertPrice = total.toFixed(2);
|
|
||||||
this.DefaultPrice = this.DefaultPrice
|
|
||||||
// .replace(/[^0-9.]/g, '') // Remove non-numeric characters except decimal points
|
|
||||||
// .replace(/(\..*)\..*/g, '$1') // Allow only one decimal point
|
|
||||||
// .replace(/^(\d*\.\d{0,2})\d*$/, '$1'); // Limit to two decimal places
|
|
||||||
|
|
||||||
},
|
|
||||||
calculateWarrantyEndDate() {
|
|
||||||
// Check if DODate and warranty are valid
|
|
||||||
if (!this.DODate || isNaN(Date.parse(this.DODate))) {
|
|
||||||
this.EndWDate = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const DODates = new Date(this.DODate);
|
|
||||||
const warrantyMonth = parseInt(this.warranty);
|
|
||||||
|
|
||||||
// Ensure warranty is a valid number
|
|
||||||
if (!isNaN(warrantyMonth)) {
|
|
||||||
DODates.setMonth(DODates.getMonth() + warrantyMonth);
|
|
||||||
this.EndWDate = DODates.toISOString().split('T')[0];
|
|
||||||
} else {
|
|
||||||
this.EndWDate = null;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async approveRequest(itemId) {
|
|
||||||
// if (!confirm("Are you sure you want to approve this request?")) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
try {
|
|
||||||
const response = await fetch(`/InvMainAPI/ApproveRequest/${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.requestDatatable.row(row)
|
|
||||||
.data({ ...this.requestDatatable.row(row)
|
|
||||||
.data(), status: "Approved" })
|
|
||||||
.draw();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
alert(result.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
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.requestDatatable.row(row)
|
|
||||||
.data({ ...this.requestDatatable.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;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async printItem(itemId, imgSrc) {
|
|
||||||
try {
|
|
||||||
this.thisQRInfo.uniqueID = itemId;
|
|
||||||
const uniqueQR = itemId;
|
|
||||||
const container = document.getElementById("QrContainer");
|
|
||||||
|
|
||||||
if (!container) {
|
|
||||||
console.error("Container not found.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Safely set image content
|
|
||||||
const sanitizedImgSrc = encodeURI(imgSrc); // Sanitize the URL
|
|
||||||
container.innerHTML = `<img src="${sanitizedImgSrc}" alt="QR Code" class="text-center " />`;
|
|
||||||
|
|
||||||
// Fetch QR information
|
|
||||||
const qrInfo = this.getPrintedQR(uniqueQR);
|
|
||||||
if (!qrInfo) {
|
|
||||||
console.error("QR Info not found.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.thisQRInfo = qrInfo;
|
|
||||||
this.thisQRInfo.imgSrc = sanitizedImgSrc
|
|
||||||
this.thisQRInfo.imgContainer = container.innerHTML
|
|
||||||
$(`#QrItemModal`).modal('show'); // Show modal
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.error("Error generating QR code:", error);
|
|
||||||
alert("An error occurred while generating the QR code.");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async fetchUser() {
|
|
||||||
try {
|
|
||||||
const response = await fetch(`/IdentityAPI/GetUserInformation/`, {
|
|
||||||
method: 'POST',
|
|
||||||
});
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
this.currentUser = data?.userInfo || null;
|
|
||||||
const companyDeptData = await this.currentUser.department;
|
|
||||||
this.currentUserCompanyDept = companyDeptData;
|
|
||||||
this.selectedCompany = companyDeptData?.companyId || "";
|
|
||||||
this.selectedDepartment = companyDeptData?.departmentId || "";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.error(`Failed to fetch user: ${response.statusText}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.error('There was a problem with the fetch operation:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
getPrintedQR(uniqueID) {
|
|
||||||
if (!this.items || !Array.isArray(this.items)) {
|
|
||||||
console.error("Items list is not available or is not an array.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return this.items.find(item => item.uniqueID === uniqueID);
|
|
||||||
},
|
|
||||||
printQRInfo() {
|
|
||||||
// Create a virtual DOM element
|
|
||||||
const virtualElement = document.createElement('div');
|
|
||||||
virtualElement.style.width = '330px '; // Match label size for 2 inches at 203 DPI
|
|
||||||
virtualElement.style.height = '160px';
|
|
||||||
virtualElement.style.position = 'absolute';
|
|
||||||
virtualElement.style.left = '-9999px'; // Position offscreen to avoid rendering on the main UI
|
|
||||||
// virtualElement.style.border = '1px solid #000'; // Optional: Add a border for debugging dimensions
|
|
||||||
|
|
||||||
// Populate the virtual DOM with content
|
|
||||||
virtualElement.innerHTML = `
|
|
||||||
<div class="container-fluid my-3 QrPrintFont" style="font-family: 'OCR A', monospace;">
|
|
||||||
<div class="row" >
|
|
||||||
<div class="col-5 text-center d-flex align-items-center justify-content-center">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-12">
|
|
||||||
<div>${this.thisQRInfo.imgContainer}</div>
|
|
||||||
<div class="col-12 h4"style="font-family: 'Arial', monospace;"><b>${this.thisQRInfo.uniqueID}</b></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-7 d-flex align-items-center justify-content-left">
|
|
||||||
<div class="row-fluid">
|
|
||||||
<div class="col-12 h3"style="font-family: 'Verdana', monospace;"><b>${this.thisQRInfo.departmentName}</b></div>
|
|
||||||
<div class="col-12 h4"style="font-family: 'Arial', monospace;"><b>${this.thisQRInfo.productShortName}</b></div>
|
|
||||||
<div class="col-12 h4"style="font-family: 'Arial', monospace;"><b>${this.thisQRInfo.serialNumber??"-"}</b></div>
|
|
||||||
<div class="col-12 h4"style="font-family: 'Arial', monospace;"><b>${this.thisQRInfo.partNumber}</b></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
// Append the virtual DOM to the body (temporarily)
|
|
||||||
document.body.appendChild(virtualElement);
|
|
||||||
|
|
||||||
// Wait for the font to be loaded (important for custom fonts like OCR-A)
|
|
||||||
document.fonts.load('1em "OCR A"').then(() => {
|
|
||||||
// Use html2canvas to convert the virtual DOM to an image
|
|
||||||
html2canvas(virtualElement, {
|
|
||||||
scale: 1, // Increase scale for sharper images
|
|
||||||
}).then((canvas) => {
|
|
||||||
// Convert the canvas to an image
|
|
||||||
const imgData = canvas.toDataURL('image/png');
|
|
||||||
// Open the image in a new tab for preview (optional)
|
|
||||||
// const newWindow = window.open();
|
|
||||||
// newWindow.location.href = imgData;
|
|
||||||
// console.log(imgData)
|
|
||||||
// Use printJS to print the image
|
|
||||||
printJS({
|
|
||||||
printable: imgData,
|
|
||||||
type: 'image',
|
|
||||||
css: '/../lib/bootstrap/dist/css/bootstrap.css',
|
|
||||||
style: `
|
|
||||||
@@media print {
|
|
||||||
@@page {
|
|
||||||
margin: 5px 5px 0px 5px;
|
|
||||||
}
|
|
||||||
body { margin: 0; }
|
|
||||||
}
|
|
||||||
`
|
|
||||||
});
|
|
||||||
|
|
||||||
// Remove the virtual DOM from the body after use
|
|
||||||
document.body.removeChild(virtualElement);
|
|
||||||
}).catch((error) => {
|
|
||||||
console.error("Error generating image:", error);
|
|
||||||
// Remove the virtual DOM if an error occurs
|
|
||||||
document.body.removeChild(virtualElement);
|
|
||||||
});
|
|
||||||
}).catch((error) => {
|
|
||||||
console.error("Error loading font:", error);
|
|
||||||
// Remove the virtual DOM if font loading fails
|
|
||||||
document.body.removeChild(virtualElement);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
},
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
}
|
|
||||||
495
Areas/Inventory/Views/ItemMovement/ItemRequest.cshtml
Normal file
495
Areas/Inventory/Views/ItemMovement/ItemRequest.cshtml
Normal file
@ -0,0 +1,495 @@
|
|||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Product Request";
|
||||||
|
Layout = "~/Views/Shared/_Layout.cshtml";
|
||||||
|
}
|
||||||
|
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartialUser.cshtml");
|
||||||
|
<div id="requestProduct" class="row">
|
||||||
|
|
||||||
|
<!-- Document Preview Modal -->
|
||||||
|
<div id="documentModal" class="modal fade" tabindex="-1" role="dialog">
|
||||||
|
<div class="modal-dialog modal-lg" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">Document Preview</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body text-center">
|
||||||
|
<img id="documentPreview" src="" alt="Document" class="img-fluid" style="max-height: 80vh;">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="row card">
|
||||||
|
<div class="card-header">
|
||||||
|
<button id="addRequestBtn" class="btn btn-success col-md-3 col-lg-3 m-1 col-12"><i class="fa fa-plus"></i> 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="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">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<form v-on:submit.prevent="addRequest" 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 Dropdown -->
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-sm-4 col-form-label">Product</label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<select class="btn btn-primary form-select" v-model="productId" required>
|
||||||
|
<option class="btn-light" value="" disabled selected>Select Product</option>
|
||||||
|
<option class="btn-light" v-for="(item, index) in products" :key="index" :value="item.productId">
|
||||||
|
{{ item.productName + ' (' + item.modelNo + ')' }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Category Dropdown -->
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-sm-4 col-form-label">Category:</label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<div class="">
|
||||||
|
<select class="btn btn-primary form-select" v-model="productCategory" required>
|
||||||
|
<option class="btn-light" value="" selected disabled>Select Category</option>
|
||||||
|
<option class="btn-light" v-for="(item, index) in categories" :key="item" :value="item">{{ item ?? 'Select Category' }}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Quantity Input -->
|
||||||
|
<div class="form-group row d-flex align-items-center">
|
||||||
|
<label class="col-sm-4 col-form-label">Quantity:</label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<input type="number" class="form-control" v-model="quantity" required />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Station Dropdown -->
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-sm-4 col-form-label">Station:</label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<select class="btn btn-primary form-select" v-model="stationId" required>
|
||||||
|
<option class="btn-light" value="" disabled selected>Select Station</option>
|
||||||
|
<option class="btn-light" v-for="(item, index) in stations" :key="index" :value="item.stationId">
|
||||||
|
{{ item.stationName }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Remark Input (Wider) -->
|
||||||
|
<div class="form-group row d-flex align-items-center">
|
||||||
|
<label class="col-sm-4 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-4 col-form-label">Document/Picture:</label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<input type="file" class="form-control-file" v-on:change="handleFileUpload" />
|
||||||
|
</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>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
@{
|
||||||
|
await Html.RenderPartialAsync("_ValidationScriptsPartial");
|
||||||
|
}
|
||||||
|
<script>
|
||||||
|
$(function () {
|
||||||
|
app.mount('#requestProduct');
|
||||||
|
|
||||||
|
// Attach a click event listener to elements with the class 'btn-success'.
|
||||||
|
$('#addRequestBtn').on('click', function () {
|
||||||
|
$('#requestModal').modal('show');
|
||||||
|
});
|
||||||
|
$('.closeModal').on('click', function () {
|
||||||
|
$('.modal').modal('hide');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
const app = Vue.createApp({
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
requestId : null,
|
||||||
|
userId : null,
|
||||||
|
stationId : null,
|
||||||
|
productId : null,
|
||||||
|
remark: "",
|
||||||
|
document: null,
|
||||||
|
quantity: 0,
|
||||||
|
status: "",
|
||||||
|
requestDate : null,
|
||||||
|
approvalDate : null,
|
||||||
|
productCategory: "",
|
||||||
|
|
||||||
|
productName: null,
|
||||||
|
productCategory: null,
|
||||||
|
stations: [],
|
||||||
|
selectedProduct: "",
|
||||||
|
selectedStation: "",
|
||||||
|
selectedCategory: "",
|
||||||
|
categories: ["Asset", "Part", "Disposable"],
|
||||||
|
showRequestModal: false,
|
||||||
|
loading: false,
|
||||||
|
products: [],
|
||||||
|
request: [],
|
||||||
|
currentUser: null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async mounted() {
|
||||||
|
this.fetchProducts();
|
||||||
|
this.fetchStation();
|
||||||
|
await this.fetchUser();
|
||||||
|
await Promise.all([
|
||||||
|
this.fetchRequest(),
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
|
||||||
|
showProduct() {
|
||||||
|
if (!this.selectedProduct) {
|
||||||
|
return []; // No company selected, return empty list
|
||||||
|
}
|
||||||
|
const product = this.products.find(c => c.productId === this.selectedProduct);
|
||||||
|
return product ? product : {};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleFileUpload(event) {
|
||||||
|
const file = event.target.files[0];
|
||||||
|
if (file) {
|
||||||
|
this.document = file.name;
|
||||||
|
} else {
|
||||||
|
this.document = null; // Ensure null if no file selected
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async addRequest() {
|
||||||
|
try {
|
||||||
|
const requiredFields = ['stationId', 'productId', 'quantity', 'productCategory'];
|
||||||
|
|
||||||
|
this.userId = this.currentUser.id;
|
||||||
|
this.status = "Request";
|
||||||
|
this.requestDate = new Date().toISOString();
|
||||||
|
|
||||||
|
// Loop through required fields and check if any are null or empty
|
||||||
|
for (let field of requiredFields) {
|
||||||
|
if (!this[field]) {
|
||||||
|
alert('Request Error', `Please fill in required fields: ${field}.`, 'warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare data as JSON (No file upload)
|
||||||
|
const requestData = {
|
||||||
|
ProductId: this.productId,
|
||||||
|
StationId: this.stationId,
|
||||||
|
UserId: this.userId,
|
||||||
|
ProductCategory: this.productCategory,
|
||||||
|
RequestQuantity: this.quantity,
|
||||||
|
remark: this.remark || '',
|
||||||
|
status: this.status,
|
||||||
|
requestDate: this.requestDate,
|
||||||
|
approvalDate: this.approvalDate ? this.approvalDate : null,
|
||||||
|
document: this.document // ✅ Store only the file name/path
|
||||||
|
};
|
||||||
|
|
||||||
|
$('.modal').modal('hide');
|
||||||
|
|
||||||
|
// Send the data to the API
|
||||||
|
const response = await fetch('/InvMainAPI/AddRequest', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(requestData) // ✅ Send JSON (No file upload)
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
alert('Success!', 'Request form has been successfully submitted.', 'success');
|
||||||
|
const requestItem = await response.json();
|
||||||
|
this.request.push(requestItem);
|
||||||
|
this.fetchRequest();
|
||||||
|
this.resetForm();
|
||||||
|
} else {
|
||||||
|
throw new Error('Failed to submit form.');
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
alert('Inventory PSTW Error', `An error occurred: ${error.message}`, 'error');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
initiateTable() {
|
||||||
|
self = this;
|
||||||
|
this.requestDatatable = $('#requestDatatable').DataTable({
|
||||||
|
"data": this.request,
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"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}`);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Product Id",
|
||||||
|
"data": "productId",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Product Category",
|
||||||
|
"data": "productCategory",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Request Quantity",
|
||||||
|
"data": "requestQuantity",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Document / Picture",
|
||||||
|
"data": "document",
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"title": "Remark",
|
||||||
|
"data": "remark",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Status",
|
||||||
|
"data": "status",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Request Date",
|
||||||
|
"data": "requestDate",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Approval Date",
|
||||||
|
"data": "approvalDate",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Delete",
|
||||||
|
"data": "requestId",
|
||||||
|
"render": function (data) {
|
||||||
|
var deleteButton = `<button type="button" class="btn btn-danger delete-btn" data-id="${data}">Delete</button>`;
|
||||||
|
return deleteButton;
|
||||||
|
},
|
||||||
|
"className": "align-middle",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
responsive: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
$('#requestDatatable tbody').off('click', '.delete-btn');
|
||||||
|
|
||||||
|
$('#requestDatatable tbody').on('click', '.delete-btn', function () {
|
||||||
|
const requestId = $(this).data('id');
|
||||||
|
self.deleteRequestItem(requestId);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
this.loading = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
async fetchRequest() {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const response = await fetch(`/InvMainAPI/ItemRequestListEachUser/${this.userId}`,
|
||||||
|
{
|
||||||
|
method: 'GET', // Specify the HTTP method
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json', // Set content type
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Failed to fetch request List');
|
||||||
|
}
|
||||||
|
this.request = await response.json();
|
||||||
|
|
||||||
|
if ($.fn.dataTable.isDataTable('#requestDatatable')) {
|
||||||
|
$('#requestDatatable').DataTable().clear().destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.initiateTable();
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error('Error fetching request List:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async fetchProducts() {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/InvMainAPI/ProductList', {
|
||||||
|
method: 'POST', // Specify the HTTP method
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json', // Set content type
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Failed to fetch products');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.products = await response.json();
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error('Error fetching products:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async fetchStation() {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/InvMainAPI/StationList', {
|
||||||
|
method: 'POST', // Specify the HTTP method
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Failed to fetch suppliers');
|
||||||
|
}
|
||||||
|
this.stations = await response.json(); // Get the full response object
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching suppliers:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async fetchUser() {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/IdentityAPI/GetUserInformation/`, {
|
||||||
|
method: 'POST',
|
||||||
|
});
|
||||||
|
if (response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
|
this.currentUser = data?.userInfo || null;
|
||||||
|
this.userId = await this.currentUser.id;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error(`Failed to fetch user: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error('There was a problem with the fetch operation:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
resetForm() {
|
||||||
|
this.requestId = null;
|
||||||
|
this.userId = null;
|
||||||
|
this.stationId = null;
|
||||||
|
this.productId = null;
|
||||||
|
this.remark = "";
|
||||||
|
this.document = null;
|
||||||
|
this.quantity = 0;
|
||||||
|
this.status = "";
|
||||||
|
this.requestDate = null;
|
||||||
|
this.approvalDate = null;
|
||||||
|
this.productCategory = "";
|
||||||
|
|
||||||
|
this.productName = null;
|
||||||
|
this.productCategory = null;
|
||||||
|
this.stations = [];
|
||||||
|
this.selectedProduct = "";
|
||||||
|
this.selectedStation = "";
|
||||||
|
this.selectedCategory = "";
|
||||||
|
this.showRequestModal = false;
|
||||||
|
this.loading = false;
|
||||||
|
this.product = [];
|
||||||
|
this.request = [];
|
||||||
|
this.currentUser = null;
|
||||||
|
},
|
||||||
|
|
||||||
|
async deleteRequestItem(requestId) {
|
||||||
|
if (!confirm("Are you sure you want to delete this request?")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/InvMainAPI/DeleteRequest/${requestId}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
alert(result.message);
|
||||||
|
|
||||||
|
if ($.fn.dataTable.isDataTable('#requestDatatable')) {
|
||||||
|
const table = $('#requestDatatable').DataTable();
|
||||||
|
table.row($(`.delete-btn[data-id="${requestId}"]`).closest('tr')).remove().draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.request = this.request.filter(req => req.requestId !== requestId);
|
||||||
|
} else {
|
||||||
|
alert(result.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error("Error deleting item:", error);
|
||||||
|
alert("An error occurred while deleting the item.");
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
}
|
||||||
90
Areas/Inventory/Views/ItemMovement/UserDashboard.cshtml
Normal file
90
Areas/Inventory/Views/ItemMovement/UserDashboard.cshtml
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Dashboard";
|
||||||
|
Layout = "~/Views/Shared/_Layout.cshtml";
|
||||||
|
}
|
||||||
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
<div class="container" id="invUser">
|
||||||
|
<div class="row">
|
||||||
|
<div class="text-center">
|
||||||
|
<p><h1 class="display-4">Inventory User Dashboard</h1></p>
|
||||||
|
<p v-show="currentUserCompanyDept.departmentName"><h2 class="display-6">Store: {{ currentUserCompanyDept.departmentName }}</h2></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartialUser.cshtml");
|
||||||
|
</div>
|
||||||
|
@section Scripts {
|
||||||
|
@{
|
||||||
|
await Html.RenderPartialAsync("_ValidationScriptsPartial");
|
||||||
|
}
|
||||||
|
<script>
|
||||||
|
$(function () {
|
||||||
|
app.mount('#invUser');
|
||||||
|
|
||||||
|
$('.closeModal').on('click', function () {
|
||||||
|
// Show the modal with the ID 'addManufacturerModal'.
|
||||||
|
$('.modal').modal('hide');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
const app = Vue.createApp({
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
currentUser: null,
|
||||||
|
currentUserCompanyDept: {
|
||||||
|
departmentName: null,
|
||||||
|
departmentId: null
|
||||||
|
},
|
||||||
|
reportData: null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.fetchUser();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async fetchUser() {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/IdentityAPI/GetUserInformation/`, {
|
||||||
|
method: 'POST',
|
||||||
|
});
|
||||||
|
if (response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
|
this.currentUser = data?.userInfo || null;
|
||||||
|
const companyDeptData = await this.currentUser.department;
|
||||||
|
const userRole = this.currentUser.role;
|
||||||
|
if(userRole == "SuperAdmin" || userRole == "SystemAdmin"){
|
||||||
|
this.currentUserCompanyDept = {departmentId : 0, departmentName : "All"}
|
||||||
|
this.fetchInventoryReport(0);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this.currentUserCompanyDept = companyDeptData;
|
||||||
|
this.fetchInventoryReport(companyDeptData.departmentId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error(`Failed to fetch user: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error('There was a problem with the fetch operation:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async fetchInventoryReport(deptId){
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/InvMainAPI/GetInventoryReport/` + deptId, {
|
||||||
|
method: 'POST',
|
||||||
|
});
|
||||||
|
if (response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
|
this.reportData = data;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error(`Failed to fetch user: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error('There was a problem with the fetch operation:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
}
|
||||||
@ -76,7 +76,7 @@
|
|||||||
|
|
||||||
<div class="col-6 col-md-6 col-lg-3">
|
<div class="col-6 col-md-6 col-lg-3">
|
||||||
<div class="card card-hover">
|
<div class="card card-hover">
|
||||||
<a asp-area="Inventory" asp-controller="InventoryMaster" asp-action="ItemRequest">
|
<a asp-area="Inventory" asp-controller="InventoryMaster" asp-action="ItemRequestMaster">
|
||||||
<div class="box bg-info text-center">
|
<div class="box bg-info text-center">
|
||||||
<h1 class="font-light text-white">
|
<h1 class="font-light text-white">
|
||||||
<i class="mdi mdi-checkbox-multiple-blank"></i>
|
<i class="mdi mdi-checkbox-multiple-blank"></i>
|
||||||
|
|||||||
28
Areas/Inventory/Views/_InventoryPartialUser.cshtml
Normal file
28
Areas/Inventory/Views/_InventoryPartialUser.cshtml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-6 col-md-6 col-lg-3">
|
||||||
|
<div class="card card-hover">
|
||||||
|
<a asp-area="Inventory" asp-controller="ItemMovement" asp-action="ItemRequest">
|
||||||
|
<div class="box bg-info text-center">
|
||||||
|
<h1 class="font-light text-white">
|
||||||
|
<i class="mdi mdi-checkbox-multiple-blank"></i>
|
||||||
|
</h1>
|
||||||
|
<h6 class="text-white">Product Request</h6>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-6 col-md-6 col-lg-3">
|
||||||
|
<div class="card card-hover">
|
||||||
|
<a asp-area="Inventory" asp-controller="ItemMovement" asp-action="Qr">
|
||||||
|
<div class="box bg-success text-center">
|
||||||
|
<h1 class="font-light text-white">
|
||||||
|
<i class="mdi mdi-checkbox-multiple-blank-circle"></i>
|
||||||
|
</h1>
|
||||||
|
<h6 class="text-white">QR Scanner</h6>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@ -1,4 +1,4 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@ -730,10 +730,8 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
|||||||
#endregion ItemMovement
|
#endregion ItemMovement
|
||||||
|
|
||||||
#region ItemRequestUser
|
#region ItemRequestUser
|
||||||
|
|
||||||
[HttpPost("AddRequest")]
|
[HttpPost("AddRequest")]
|
||||||
public async Task<IActionResult> AddRequest([FromBody] RequestModel request, [FromQuery] int UserId)
|
public async Task<IActionResult> AddRequest([FromBody] RequestModel request)
|
||||||
|
|
||||||
{
|
{
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
{
|
{
|
||||||
@ -745,9 +743,9 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
|||||||
_centralDbContext.Requests.Add(request);
|
_centralDbContext.Requests.Add(request);
|
||||||
await _centralDbContext.SaveChangesAsync();
|
await _centralDbContext.SaveChangesAsync();
|
||||||
|
|
||||||
//ini akan paparkan user punya table sahaja.
|
var updatedList = await _centralDbContext.Requests
|
||||||
|
.Where(r => r.UserId == request.UserId)
|
||||||
var updatedList = await _centralDbContext.Requests.Where(r => r.UserId == UserId).ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
return Json(updatedList);
|
return Json(updatedList);
|
||||||
}
|
}
|
||||||
@ -757,20 +755,22 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("ItemRequestListEachUser/{id}")]
|
|
||||||
public async Task<IActionResult> ItemRequestListEachUser(int UserId)
|
|
||||||
|
[HttpGet("ItemRequestListEachUser/{userId}")]
|
||||||
|
public async Task<IActionResult> ItemRequestListEachUser(int userId)
|
||||||
{
|
{
|
||||||
|
var requests = await _centralDbContext.Requests
|
||||||
|
.Where(r => r.UserId == userId).ToListAsync();
|
||||||
|
|
||||||
var itemRequestList = await _centralDbContext.Requests.Where(r => r.UserId == UserId).ToListAsync();
|
return Ok(requests);
|
||||||
|
|
||||||
return Json(itemRequestList);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpDelete("DeleteRequest/{id}")]
|
|
||||||
public async Task<IActionResult> DeleteRequest(int id)
|
[HttpDelete("DeleteRequest/{requestId}")]
|
||||||
|
public async Task<IActionResult> DeleteRequest(int requestId)
|
||||||
{
|
{
|
||||||
var request = await _centralDbContext.Requests.FindAsync(id);
|
var request = await _centralDbContext.Requests.FindAsync(requestId);
|
||||||
if (request == null)
|
if (request == null)
|
||||||
{
|
{
|
||||||
return NotFound(new { success = false, message = "Request not found" });
|
return NotFound(new { success = false, message = "Request not found" });
|
||||||
|
|||||||
@ -6,6 +6,10 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Areas\Inventory\Views\InventoryMaster\ItemRequestMaster.cshtml" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.11" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.11" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.11" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.11" />
|
||||||
|
|||||||
@ -440,6 +440,13 @@
|
|||||||
<i class="mdi mdi-view-dashboard"></i><span class="hide-menu">AdminDashboard</span>
|
<i class="mdi mdi-view-dashboard"></i><span class="hide-menu">AdminDashboard</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="sidebar-item">
|
||||||
|
<a class="sidebar-link waves-effect waves-dark sidebar-link"
|
||||||
|
asp-area="Inventory" asp-controller="ItemMovement" asp-action="UserDashboard"
|
||||||
|
aria-expanded="false">
|
||||||
|
<i class="mdi mdi-view-dashboard"></i><span class="hide-menu">UserDashboard</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
<li class="sidebar-item">
|
<li class="sidebar-item">
|
||||||
<a class="sidebar-link waves-effect waves-dark sidebar-link"
|
<a class="sidebar-link waves-effect waves-dark sidebar-link"
|
||||||
asp-area="Inventory" asp-controller="InventoryMaster" asp-action="ProductRegistration"
|
asp-area="Inventory" asp-controller="InventoryMaster" asp-action="ProductRegistration"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user