update
This commit is contained in:
parent
082be76c51
commit
5a786d221d
@ -27,11 +27,11 @@
|
|||||||
<div class="modal-dialog modal-dialog-centered modal-md" role="document">
|
<div class="modal-dialog modal-dialog-centered modal-md" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title" id="QrItemModalLabel">{{thisQRInfo.uniqueID}}</h5>
|
<h5 class="modal-title" id="QrItemModalLabel"></h5>
|
||||||
<button type="button" class="closeModal btn-close" data-bs-dismiss="modal" aria-label="Close" v-on:click="showItemModal=false"></button>
|
<button type="button" class="closeModal btn-close" data-bs-dismiss="modal" aria-label="Close" v-on:click="showItemModal=false"></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body d-flex justify-content-center align-items-center">
|
<div class="modal-body d-flex justify-content-center align-items-center">
|
||||||
<div class="container">
|
<div class="container" style="font-family: 'OCR A', monospace;">
|
||||||
<div class="row" ref="qrInfo" id="qrInfo">
|
<div class="row" ref="qrInfo" id="qrInfo">
|
||||||
<div class="col-5 text-center">
|
<div class="col-5 text-center">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -45,6 +45,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-7 d-flex align-items-center justify-content-center">
|
<div class="col-7 d-flex align-items-center justify-content-center">
|
||||||
<div class="text-center fs-4 text">
|
<div class="text-center fs-4 text">
|
||||||
|
<div class="col-12 my-3">
|
||||||
|
{{thisQRInfo.uniqueID}}
|
||||||
|
</div>
|
||||||
<div class="col-12 my-3">
|
<div class="col-12 my-3">
|
||||||
{{thisQRInfo.departmentName}}
|
{{thisQRInfo.departmentName}}
|
||||||
</div>
|
</div>
|
||||||
@ -318,11 +321,10 @@
|
|||||||
@* Submit and Reset Buttons *@
|
@* Submit and Reset Buttons *@
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<div class="col-sm-8 offset-sm-3">
|
<div class="col-sm-8 offset-sm-3">
|
||||||
<button type="button" v-on:click="resetForm" class="btn btn-secondary">Reset</button>
|
<button type="button" v-on:click="resetForm" class="btn btn-secondary m-1">Reset</button>
|
||||||
<input type="submit" class="btn btn-primary" value="Submit" />
|
<button type="submit" class="btn btn-primary m-1">Submit</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -508,6 +510,10 @@
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
// If the form submission was successful, display a success message
|
// If the form submission was successful, display a success message
|
||||||
alert('Success!', 'Item form has been successfully submitted.', 'success');
|
alert('Success!', 'Item form has been successfully submitted.', 'success');
|
||||||
|
const updatedItem = await response.json();
|
||||||
|
this.items.push(updatedItem);
|
||||||
|
|
||||||
|
this.fetchItem();
|
||||||
|
|
||||||
// Reset the form
|
// Reset the form
|
||||||
this.resetForm();
|
this.resetForm();
|
||||||
@ -569,16 +575,6 @@
|
|||||||
else { return data }
|
else { return data }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// "title": "Image",
|
|
||||||
// "data": "imageProduct",
|
|
||||||
// "render": function (data, type, full, meta) {
|
|
||||||
// var image = `<a href="${data}" target="_blank" data-lightbox="image-1">
|
|
||||||
// <img src="${data}" alt="Image" class="img-thumbnail" style="width: 100px; height: 100px;" />
|
|
||||||
// </a>`;
|
|
||||||
// return image;
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
"title": "Print",
|
"title": "Print",
|
||||||
"data": "uniqueID",
|
"data": "uniqueID",
|
||||||
@ -604,6 +600,8 @@
|
|||||||
const data = this.data(); // Row data
|
const data = this.data(); // Row data
|
||||||
const containerId = `qr${data.uniqueID}`;
|
const containerId = `qr${data.uniqueID}`;
|
||||||
const container = $(`#${containerId}`);
|
const container = $(`#${containerId}`);
|
||||||
|
container.empty();
|
||||||
|
container.append(`${data.uniqueID}`);
|
||||||
// console.log(container[0]);
|
// console.log(container[0]);
|
||||||
if (container) {
|
if (container) {
|
||||||
// Generate QR code only if not already generated
|
// Generate QR code only if not already generated
|
||||||
@ -613,7 +611,7 @@
|
|||||||
height: 150,
|
height: 150,
|
||||||
colorDark: "#000000",
|
colorDark: "#000000",
|
||||||
colorLight: "#ffffff",
|
colorLight: "#ffffff",
|
||||||
correctLevel: QRCode.CorrectLevel.H
|
correctLevel: QRCode.CorrectLevel.M
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -643,7 +641,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (imageSrc) {
|
if (imageSrc) {
|
||||||
console.log(imageSrc);
|
|
||||||
self.printItem(itemId, imageSrc); // Call the print function with the itemId and imageSrc
|
self.printItem(itemId, imageSrc); // Call the print function with the itemId and imageSrc
|
||||||
} else {
|
} else {
|
||||||
console.error("Image source not found.");
|
console.error("Image source not found.");
|
||||||
@ -669,6 +666,9 @@
|
|||||||
}
|
}
|
||||||
this.items = await response.json();
|
this.items = await response.json();
|
||||||
|
|
||||||
|
if (this.itemDatatable) {
|
||||||
|
this.itemDatatable.clear().destroy();
|
||||||
|
}
|
||||||
this.initiateTable();
|
this.initiateTable();
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
@ -753,24 +753,23 @@
|
|||||||
this.productName = null;
|
this.productName = null;
|
||||||
this.imageProduct = null;
|
this.imageProduct = null;
|
||||||
this.serialNumber = '';
|
this.serialNumber = '';
|
||||||
this.quantity = 0;
|
this.quantity = 1;
|
||||||
this.supplierName = null;
|
this.supplierName = null;
|
||||||
this.purchaseDate = null;
|
this.purchaseDate = null;
|
||||||
this.PO = null;
|
this.PO = null;
|
||||||
this.currency = null;
|
this.currency = 'MYR';
|
||||||
this.DefaultPrice = null;
|
this.DefaultPrice = 0.01;
|
||||||
this.currencyRate = null;
|
this.currencyRate = 1;
|
||||||
this.convertPrice = null;
|
this.convertPrice = 0.01;
|
||||||
this.DODate = null;
|
this.DODate = null;
|
||||||
this.warranty = null;
|
this.warranty = 0;
|
||||||
this.EndWDate = null;
|
this.EndWDate = null;
|
||||||
this.invoiceDate = null;
|
this.invoiceDate = null;
|
||||||
this.selectedProduct = "";
|
this.selectedProduct = '';
|
||||||
this.selectedSupplier = "";
|
this.selectedSupplier = '';
|
||||||
this.selectedCompany = "";
|
this.selectedCompany = this.currentUserCompanyDept.companyId;
|
||||||
this.selectedDepartment = "";
|
this.selectedDepartment = '';
|
||||||
this.currentUserCompanyDept = null;
|
this.selectedTeamType = '';
|
||||||
this.selectedTeamType = "";
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// FRONT END FUNCTIONS
|
// FRONT END FUNCTIONS
|
||||||
@ -835,33 +834,6 @@
|
|||||||
this.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async generateItemQr(itemId) {
|
|
||||||
try {
|
|
||||||
// Clear any existing QR code in the container
|
|
||||||
const container = document.getElementById(QrContainer);
|
|
||||||
if (!container) {
|
|
||||||
console.error(`Container with ID ${containerId} not found.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Clear any existing QR code in the container
|
|
||||||
container.innerHTML = '';
|
|
||||||
|
|
||||||
// Generate the QR code
|
|
||||||
new QRCode(container, {
|
|
||||||
text: itemId,
|
|
||||||
width: 128,
|
|
||||||
height: 128,
|
|
||||||
colorDark: "#000000",
|
|
||||||
colorLight: "#ffffff",
|
|
||||||
correctLevel: QRCode.CorrectLevel.H
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.error("Error generating QR code:", error);
|
|
||||||
alert("An error occurred while generating the QR code.");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async printItem(itemId, imgSrc) {
|
async printItem(itemId, imgSrc) {
|
||||||
try {
|
try {
|
||||||
this.thisQRInfo.uniqueID = itemId;
|
this.thisQRInfo.uniqueID = itemId;
|
||||||
@ -875,7 +847,7 @@
|
|||||||
|
|
||||||
// Safely set image content
|
// Safely set image content
|
||||||
const sanitizedImgSrc = encodeURI(imgSrc); // Sanitize the URL
|
const sanitizedImgSrc = encodeURI(imgSrc); // Sanitize the URL
|
||||||
container.innerHTML = `<img src="${sanitizedImgSrc}" alt="QR Code" class="text-center img-fluid" />`;
|
container.innerHTML = `<img src="${sanitizedImgSrc}" alt="QR Code" class="text-center "style="width: 150px; height: 150px;" />`;
|
||||||
|
|
||||||
// Fetch QR information
|
// Fetch QR information
|
||||||
const qrInfo = this.getPrintedQR(uniqueQR);
|
const qrInfo = this.getPrintedQR(uniqueQR);
|
||||||
@ -884,7 +856,9 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.thisQRInfo = qrInfo; // Save the QR info to a property
|
this.thisQRInfo = qrInfo;
|
||||||
|
this.thisQRInfo.imgSrc = sanitizedImgSrc
|
||||||
|
this.thisQRInfo.imgContainer = container.innerHTML
|
||||||
$(`#QrItemModal`).modal('show'); // Show modal
|
$(`#QrItemModal`).modal('show'); // Show modal
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
@ -962,27 +936,30 @@
|
|||||||
printQRInfo() {
|
printQRInfo() {
|
||||||
// Create a virtual DOM element
|
// Create a virtual DOM element
|
||||||
const virtualElement = document.createElement('div');
|
const virtualElement = document.createElement('div');
|
||||||
virtualElement.style.width = '500px'; // Set dimensions
|
virtualElement.style.width = '340px '; // Match label size for 2 inches at 203 DPI
|
||||||
virtualElement.style.height = 'auto';
|
virtualElement.style.height = '180px';
|
||||||
virtualElement.style.position = 'absolute';
|
virtualElement.style.position = 'absolute';
|
||||||
virtualElement.style.left = '-9999px'; // Position offscreen
|
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
|
// Populate the virtual DOM with content
|
||||||
virtualElement.innerHTML = `
|
virtualElement.innerHTML = `
|
||||||
<div class="row" id="qrInfo">
|
<div class="container" style="font-family: 'OCR A', monospace;">
|
||||||
<div class="col-5 text-center">
|
<div class="row" ref="qrInfo" id="qrInfo">
|
||||||
<div id="QrContainer">
|
<div class="col-5 text-center d-flex align-items-center justify-content-center">
|
||||||
<!-- QR Code can be dynamically inserted here -->
|
<div class="row">
|
||||||
|
<div class="col-12 ">
|
||||||
|
<div>${this.thisQRInfo.imgContainer}</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<p>${this.thisQRInfo.uniqueID}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-7 d-flex align-items-center justify-content-center">
|
<div class="col-7 d-flex align-items-center justify-content-center">
|
||||||
<div class="text-center fs-4 text">
|
<div class="text-center fs-4 text">
|
||||||
<div>${this.thisQRInfo.departmentName}</div>
|
<div class="col-12 h3">${this.thisQRInfo.uniqueID}</div>
|
||||||
<div>${this.thisQRInfo.productName}</div>
|
<div class="col-12 h3">${this.thisQRInfo.departmentName}</div>
|
||||||
<div>${this.thisQRInfo.endWDate}</div>
|
<div class="col-12 h3">${this.thisQRInfo.productName}</div>
|
||||||
|
<div class="col-12 h3">${this.thisQRInfo.endWDate}</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -991,15 +968,19 @@
|
|||||||
// Append the virtual DOM to the body (temporarily)
|
// Append the virtual DOM to the body (temporarily)
|
||||||
document.body.appendChild(virtualElement);
|
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
|
// Use html2canvas to convert the virtual DOM to an image
|
||||||
html2canvas(virtualElement, {
|
html2canvas(virtualElement, {
|
||||||
scale: 10, // Increase scale for sharper image
|
scale: 1, // Increase scale for sharper images
|
||||||
useCORS: true,
|
|
||||||
allowTaint: true,
|
|
||||||
}).then((canvas) => {
|
}).then((canvas) => {
|
||||||
// Convert the canvas to an image
|
// Convert the canvas to an image
|
||||||
const imgData = canvas.toDataURL('image/png');
|
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
|
// Use printJS to print the image
|
||||||
printJS({
|
printJS({
|
||||||
printable: imgData,
|
printable: imgData,
|
||||||
@ -1008,18 +989,9 @@
|
|||||||
style: `
|
style: `
|
||||||
@@media print {
|
@@media print {
|
||||||
@@page {
|
@@page {
|
||||||
margin-top: 15px;
|
margin: 2px;
|
||||||
margin-bottom: 15px;
|
|
||||||
}
|
}
|
||||||
body { margin: 0; }
|
body { margin: 0; }
|
||||||
img {
|
|
||||||
display: block;
|
|
||||||
margin: auto;
|
|
||||||
width: auto;
|
|
||||||
max-width: 100%;
|
|
||||||
height: auto;
|
|
||||||
max-height: 100vh;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
@ -1031,8 +1003,14 @@
|
|||||||
// Remove the virtual DOM if an error occurs
|
// Remove the virtual DOM if an error occurs
|
||||||
document.body.removeChild(virtualElement);
|
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>
|
</script>
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
<span class="visually-hidden">Loading...</span>
|
<span class="visually-hidden">Loading...</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<table class="table table-bordered table-hover" id="manufacturerTable"></table>
|
<table class="table table-bordered table-hover table-striped no-wrap" id="manufacturerTable" style="width:100%;border-style: solid; border-width: 1px"></table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal fade" id="addManufacturerModal" tabindex="-1" role="dialog" aria-labelledby="addManufacturerModalLabel" aria-hidden="true">
|
<div class="modal fade" id="addManufacturerModal" tabindex="-1" role="dialog" aria-labelledby="addManufacturerModalLabel" aria-hidden="true">
|
||||||
|
|||||||
@ -2,8 +2,10 @@
|
|||||||
ViewData["Title"] = "User Form";
|
ViewData["Title"] = "User Form";
|
||||||
Layout = "~/Views/Shared/_Layout.cshtml";
|
Layout = "~/Views/Shared/_Layout.cshtml";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
|
||||||
<div id="registerSupplier">
|
<div id="registerSupplier">
|
||||||
<form v-on:submit.prevent="addSupplier" data-aos="fade-right">
|
<form v-on:submit.prevent="addSupplier" data-aos="fade-right" id="registerSupplierForm" v-if="registerSupplierForm">
|
||||||
<div class="container register" data-aos="fade-right">
|
<div class="container register" data-aos="fade-right">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@*Right Side*@
|
@*Right Side*@
|
||||||
@ -27,19 +29,10 @@
|
|||||||
<label class="col-sm-3">Supplier Gender:</label>
|
<label class="col-sm-3">Supplier Gender:</label>
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<button class="btn btn-primary dropdown-toggle w-100" type="button" data-toggle="dropdown" aria-expanded="false">
|
<select class="btn btn-primary dropdown-toggle w-100" v-model="supplierGender" required data-toggle="dropdown" aria-expanded="false">
|
||||||
<span id="updateGender">{{ supplierGender || 'Select Gender' }}</span>
|
<option value="" selected>Select Gender</option>
|
||||||
</button>
|
<option v-for="(item, index) in gender" :key="index" :value="item">{{ item }}</option>
|
||||||
<div class="dropdown-menu w-100 p-3">
|
</select>
|
||||||
<div class="form-check">
|
|
||||||
<input class="form-check-input" type="radio" name="supplierGender" id="Male" value="Male" v-on:click="updateGender('Male')" v-model="supplierGender">
|
|
||||||
<label class="form-check-label" for="Male">Male</label>
|
|
||||||
</div>
|
|
||||||
<div class="form-check">
|
|
||||||
<input class="form-check-input" type="radio" name="supplierGender" id="Female" value="Female" v-on:click="updateGender('Female')" v-model="supplierGender">
|
|
||||||
<label class="form-check-label" for="Female">Female</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -63,8 +56,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<div class="col-sm-9 offset-sm-3">
|
<div class="col-sm-9 offset-sm-3">
|
||||||
<button type="button" v-on:click="resetForm" class="btn btn-secondary">Reset</button>
|
<button type="button" v-on:click="resetForm" class="btn btn-secondary m-1">Reset</button>
|
||||||
<input type="submit" class="btn btn-primary">
|
<button type="submit" class="btn btn-primary m-1">Submit</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -74,20 +67,82 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
<div class="row card">
|
||||||
|
<div class="card-header">
|
||||||
|
<button id="addSupplierBtn" :class="['btn', 'col-md-3', 'col-lg-3', 'm-1', 'col-12', registerSupplierForm ? 'btn-danger' : 'btn-success']" v-on:click="registerSupplierForm = !registerSupplierForm"><i :class="['fa', registerSupplierForm ? 'fa-minus' : 'fa-plus']"></i> {{registerSupplierForm ? 'Hide Add Supplier' : 'Show Add Supplier'}}</button>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<table class="table table-bordered table-hover table-striped no-wrap" id="supplierDatatable" style="width:100%;border-style: solid; border-width: 1px"></table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@section Scripts {
|
||||||
|
@{
|
||||||
|
await Html.RenderPartialAsync("_ValidationScriptsPartial");
|
||||||
|
}
|
||||||
|
<script>
|
||||||
|
$(function () {
|
||||||
|
app.mount('#registerSupplier');
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
|
// Attach a click event listener to elements with the class 'btn-success'.
|
||||||
<script>
|
$('#addSupplierBtn').on('click', function () {
|
||||||
new Vue({
|
// Show the modal with the ID 'addManufacturerModal'.
|
||||||
el: '#registerSupplier',
|
$('#registerSupplierModal').modal('show');
|
||||||
data: {
|
});
|
||||||
|
$('.closeModal').on('click', function () {
|
||||||
|
// Show the modal with the ID 'addManufacturerModal'.
|
||||||
|
$('.modal').modal('hide');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
const app = Vue.createApp({
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
supplierName : null,
|
supplierName : null,
|
||||||
supplierEmail : null,
|
supplierEmail : null,
|
||||||
supplierGender : null,
|
supplierGender : '',
|
||||||
supplierPhoneNo : null
|
supplierPhoneNo : null,
|
||||||
|
suuppliers: null,
|
||||||
|
supplierDatatable: null,
|
||||||
|
gender: ["Male", "Female", "Helicopter"],
|
||||||
|
registerSupplierForm: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted(){
|
||||||
|
this.fetchSuppliers();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async fetchSuppliers() {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/InvMainAPI/SupplierList', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json();
|
||||||
|
console.error('Error response:', errorData);
|
||||||
|
this.errorMessage = 'Error: ' + (errorData.message || 'Unknown error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.supplierDatatable){
|
||||||
|
this.supplierDatatable.clear().destroy();
|
||||||
|
}
|
||||||
|
const suppliers = await response.json();
|
||||||
|
this.suppliers = suppliers;
|
||||||
|
|
||||||
|
if (this.itemDatatable) {
|
||||||
|
this.itemDatatable.clear().destroy();
|
||||||
|
}
|
||||||
|
this.initiateTable();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching suppliers:', error);
|
||||||
|
this.errorMessage = 'Error: ' + error.message;
|
||||||
|
}
|
||||||
|
},
|
||||||
async addSupplier() {
|
async addSupplier() {
|
||||||
|
$('#loadingModal').modal('show');
|
||||||
// Create the payload
|
// Create the payload
|
||||||
const formData = {
|
const formData = {
|
||||||
supplierName: this.supplierName,
|
supplierName: this.supplierName,
|
||||||
@ -103,13 +158,13 @@
|
|||||||
// Loop through required fields and check if any are null or empty
|
// Loop through required fields and check if any are null or empty
|
||||||
for (let field of requiredFields) {
|
for (let field of requiredFields) {
|
||||||
if (this[field] === null || this[field] === '') {
|
if (this[field] === null || this[field] === '') {
|
||||||
swal('Product Error', `Please fill in required fields: ${field}.`, 'warning');
|
alert('Product Error', `Please fill in required fields: ${field}.`, 'warning');
|
||||||
return; // Exit early if validation fails
|
return; // Exit early if validation fails
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Proceed to send the data as raw JSON string
|
// Proceed to send the data as raw JSON string
|
||||||
const response = await fetch('/api/Supplier', {
|
const response = await fetch('/InvMainAPI/AddSupplier', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@ -123,25 +178,98 @@
|
|||||||
this.errorMessage = 'Error: ' + (errorData.message || 'Unknown error');
|
this.errorMessage = 'Error: ' + (errorData.message || 'Unknown error');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
swal('Success!', 'Supplier form has been successfully submitted.', 'success');
|
alert('Success!', 'Supplier form has been successfully submitted.', 'success');
|
||||||
|
this.fetchSuppliers();
|
||||||
this.resetForm();
|
this.resetForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
}
|
||||||
|
catch (error) {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
swal('Product Error', `An error occurred: ${error.message}`, 'error');
|
alert('Product Error', `An error occurred: ${error.message}`, 'error');
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
await new Promise(resolve => {
|
||||||
|
$('#loadingModal').on('shown.bs.modal', resolve);
|
||||||
|
});
|
||||||
|
$('#loadingModal').modal('hide');
|
||||||
}
|
}
|
||||||
,
|
},
|
||||||
resetForm() {
|
resetForm() {
|
||||||
this.supplierName = null;
|
this.supplierName = null;
|
||||||
this.supplierEmail = null;
|
this.supplierEmail = null;
|
||||||
this.supplierGender = null;
|
this.supplierGender = '';
|
||||||
this.supplierPhoneNo = null;
|
this.supplierPhoneNo = null;
|
||||||
},
|
},
|
||||||
updateGender(supplierGender){
|
initiateTable() {
|
||||||
this.supplierGender = supplierGender;
|
self = this;
|
||||||
|
this.supplierDatatable = $('#supplierDatatable').DataTable({
|
||||||
|
"data": this.suppliers,
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"title": "Supplier Name",
|
||||||
|
"data": "supplierName",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Supplier Gender",
|
||||||
|
"data": "supplierGender",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Supplier Email",
|
||||||
|
"data": "supplierEmail",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Supplier Phone No",
|
||||||
|
"data": "supplierPhoneNo",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Delete",
|
||||||
|
"data": "supplierId",
|
||||||
|
"render": function (data) {
|
||||||
|
var deleteButton = `<button type="button" class="btn btn-danger delete-btn" data-id="${data}">Delete</button>`;
|
||||||
|
return deleteButton;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
responsive: true,
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
// Attach click event listener to the delete buttons
|
||||||
|
$('#supplierDatatable tbody').on('click', '.delete-btn', function () {
|
||||||
|
const supplierId = $(this).data('id');
|
||||||
|
self.deleteSupplier(supplierId);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.loading = false;
|
||||||
|
},
|
||||||
|
async deleteSupplier(supplierId) {
|
||||||
|
if (!confirm("Are you sure you want to delete this supplier?")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/InvMainAPI/DeleteSupplier/${supplierId}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ supplierId })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json();
|
||||||
|
console.error('Error response:', errorData);
|
||||||
|
this.errorMessage = 'Error: ' + (errorData.message || 'Unknown error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.fetchSuppliers();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error deleting supplier:', error);
|
||||||
|
this.errorMessage = 'Error: ' + error.message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
}
|
||||||
@ -205,6 +205,41 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
|||||||
return Json(supplierList);
|
return Json(supplierList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("AddSupplier")]
|
||||||
|
public async Task<IActionResult> AddSupplier([FromBody] SupplierModel supplier)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return BadRequest(ModelState);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_centralDbContext.Suppliers.Add(supplier);
|
||||||
|
await _centralDbContext.SaveChangesAsync();
|
||||||
|
var updatedList = await _centralDbContext.Suppliers.ToListAsync();
|
||||||
|
return Json(updatedList);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("DeleteSupplier/{id}")]
|
||||||
|
public async Task<IActionResult> DeleteSupplier(int id)
|
||||||
|
{
|
||||||
|
var supplier = await _centralDbContext.Suppliers.FindAsync(id);
|
||||||
|
if (supplier == null)
|
||||||
|
{
|
||||||
|
return NotFound(new { success = false, message = "Supplier not found" });
|
||||||
|
}
|
||||||
|
|
||||||
|
_centralDbContext.Suppliers.Remove(supplier);
|
||||||
|
await _centralDbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
return Ok(new { success = true, message = "Supplier deleted successfully" });
|
||||||
|
}
|
||||||
#endregion Supplier
|
#endregion Supplier
|
||||||
|
|
||||||
#region Item
|
#region Item
|
||||||
|
|||||||
33
Controllers/InventoryController.cs
Normal file
33
Controllers/InventoryController.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PSTW_CentralSystem.Areas.Inventory.Models;
|
||||||
|
using PSTW_CentralSystem.DBContext;
|
||||||
|
using PSTW_CentralSystem.Models;
|
||||||
|
|
||||||
|
namespace PSTW_CentralSystem.Controllers
|
||||||
|
{
|
||||||
|
public class InventoryController : Controller
|
||||||
|
{
|
||||||
|
private readonly ILogger<InventoryController> _logger;
|
||||||
|
private readonly CentralSystemContext _centralDbContext;
|
||||||
|
public InventoryController(ILogger<InventoryController> logger, CentralSystemContext centralDbContext)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_centralDbContext = centralDbContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("ItemInformation/{Id}")]
|
||||||
|
public async Task<IActionResult> ItemInformation(int Id)
|
||||||
|
{
|
||||||
|
var item = await _centralDbContext.Items.FindAsync(Id);
|
||||||
|
return View(Json(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("ItemInformation/{id}")]
|
||||||
|
public IActionResult ItemInformation(int id, [FromBody] ItemModel item)
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -327,6 +327,19 @@
|
|||||||
},
|
},
|
||||||
updateUppercase(event, index, key) {
|
updateUppercase(event, index, key) {
|
||||||
this.departments[index][key] = event.target.value.toUpperCase();
|
this.departments[index][key] = event.target.value.toUpperCase();
|
||||||
|
|
||||||
|
if (key === 'departmentCode') {
|
||||||
|
//check if the code is already exist from compdeptlist[index1].departments[index2].departmentCode
|
||||||
|
for (let index1 = 0; index1 < this.compDeptList.length; index1++) {
|
||||||
|
for (let index2 = 0; index2 < this.compDeptList[index1].departments.length; index2++) {
|
||||||
|
if (this.departments[index].departmentCode === this.compDeptList[index1].departments[index2].departmentCode) {
|
||||||
|
alert("Department Code already exist");
|
||||||
|
this.departments[index].departmentCode = '';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
resetDetails(){
|
resetDetails(){
|
||||||
this.company = null;
|
this.company = null;
|
||||||
|
|||||||
@ -22,6 +22,8 @@
|
|||||||
type="image/png"
|
type="image/png"
|
||||||
sizes="16x16"
|
sizes="16x16"
|
||||||
href="/assets/images/favicon.png" />
|
href="/assets/images/favicon.png" />
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=OCR+A&display=swap" rel="stylesheet">
|
||||||
|
|
||||||
<!-- Custom CSS -->
|
<!-- Custom CSS -->
|
||||||
<link rel="stylesheet" href="~/assets/libs/select2/dist/css/select2.min.css" />
|
<link rel="stylesheet" href="~/assets/libs/select2/dist/css/select2.min.css" />
|
||||||
<link rel="stylesheet" href="~/assets/libs/jquery-minicolors/jquery.minicolors.css" />
|
<link rel="stylesheet" href="~/assets/libs/jquery-minicolors/jquery.minicolors.css" />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user