536 lines
28 KiB
Plaintext
536 lines
28 KiB
Plaintext
|
|
@{
|
|
ViewData["Title"] = "Item Form";
|
|
Layout = "~/Views/Shared/_Layout.cshtml";
|
|
|
|
}
|
|
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
|
|
<div id="registerItem" class="row">
|
|
<div class="card">
|
|
<form v-on:submit.prevent="addItem" data-aos="fade-right">
|
|
<div class="container register" data-aos="fade-right">
|
|
<div class="row" data-aos="fade-right">
|
|
@*Left Side*@
|
|
<div class="col-md-3 register-left">
|
|
<img src="https://media.licdn.com/dms/image/C4E03AQEJ_X-GwTi3xg/profile-displayphoto-shrink_200_200/0/1607307680517?e=2147483647&v=beta&t=UL8IX1nO9iqRxGrQrNZ1O_i4tpjnOVVecIktw-GB6QI" alt="" />
|
|
<h3>Welcome</h3>
|
|
<p>Registration Product! Click button to go Product Page</p>
|
|
<a href="@Url.Action("Product", "Home")" class="btn btn-primary">Product Registration</a><br />
|
|
</div>
|
|
|
|
@*Right Side*@
|
|
<div class="col-md-9 register-right">
|
|
<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">REGISTRATION ITEM</h3>
|
|
<div class="row register-form">
|
|
<div class="col-md-6">
|
|
|
|
<!-- Company Dropdown -->
|
|
<div class="form-group row">
|
|
<label class="col-sm-4 col-form-label">Company:</label>
|
|
<div class="col-sm-8">
|
|
<div class="dropdown">
|
|
<select class="btn btn-primary dropdown-toggle" v-model="selectedCompany" required>
|
|
<option class="btn-light" value="" disabled selected>Select Company</option>
|
|
<option class="btn-light" v-for="(item, index) in companies" :key="index" :value="item.companyId">{{item.companyName}}</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Department Dropdown -->
|
|
<div class="form-group row">
|
|
<label class="col-sm-4 col-form-label">Department:</label>
|
|
<div class="col-sm-8">
|
|
<select class="btn btn-primary dropdown-toggle" v-model="selectedDepartment" required>
|
|
<option class="btn-light" value="" disabled selected>Select Department</option>
|
|
<option class="btn-light" v-for="(dept, index) in filteredDepartments" :key="index" :value="dept.departmentId">{{ dept.departmentName }}</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
@* Product Name Coding *@
|
|
<div class="form-group row">
|
|
<label class="col-sm-4 col-form-label">Product Name:</label>
|
|
<div class="col-sm-8">
|
|
<div class="dropdown">
|
|
<select type="button" class="btn btn-primary dropdown-toggle" v-model="selectedProduct" 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>
|
|
</div>
|
|
|
|
@* Product Image Display *@
|
|
<div class="form-group row align-items-center">
|
|
<label for="imageProduct" class="col-sm-4 col-form-label">Product Image: </label>
|
|
<div class="col-sm-8">
|
|
<img v-if="showProduct.imageProduct" :src="showProduct.imageProduct" alt="Product Image" class="img-fluid" data-toggle="modal" data-target="#imageModal" />
|
|
<input type="hidden" id="imageProduct" name="imageProduct" v-model="showProduct">
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal -->
|
|
<div class="modal fade" id="imageModal" tabindex="-1" role="dialog" aria-labelledby="imageModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog modal-lg" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="imageModalLabel">Product Image</h5>
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<img :src="showProduct.imageProduct" alt="Product Image" class="img-fluid">
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@* Product Category Coding *@
|
|
<div class="form-group row">
|
|
<label class="col-sm-4 col-form-label">Product Category:</label>
|
|
<div class="col-sm-8">
|
|
<input type="text" id="category" name="category" v-model="showProduct.category" class="form-control" readonly />
|
|
</div>
|
|
</div>
|
|
|
|
@* Serial Number and Quantity Coding *@
|
|
<div v-if="showSerialNumber">
|
|
<div class="form-group row align-items-center">
|
|
<div class="col-sm-4">
|
|
<label for="serialNumber">Serial Number: </label>
|
|
</div>
|
|
<div class="col-sm-8">
|
|
<input type="text" id="serialNumber" name="serialNumber" v-if="showSerialNumber" v-model="serialNumber" class="form-control" v-bind:required="showSerialNumber">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-if="!showSerialNumber">
|
|
<div class="form-group row align-items-center">
|
|
<div class="col-sm-4">
|
|
<label for="quantity">Quantity: </label>
|
|
</div>
|
|
<div class="col-sm-8">
|
|
<input type="number" id="quantity" name="quantity" min="1" v-if="!showSerialNumber" v-model="quantity" class="form-control" v-bind:required="!showSerialNumber">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@* Supplier coding *@
|
|
<div class="form-group row align-items-center">
|
|
<label class="col-sm-4 col-form-label">Supplier: </label>
|
|
<div class="col-sm-8">
|
|
<div class="dropdown">
|
|
<select type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-expanded="false" v-model="selectedSupplier" required>
|
|
<option class="btn-light" value="" disabled selected>Select Supplier</option>
|
|
<option class="btn-light" v-for="(item, index) in suppliers">{{ item.supplierName }}</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@* Purchase Date coding *@
|
|
<div class="form-group row align-items-center">
|
|
<label for="purchaseDate" class="col-sm-4 col-form-label">Purchase Date: </label>
|
|
<div class="col-sm-8">
|
|
<input type="date" id="purchaseDate" name="purchaseDate" required v-model="purchaseDate" class="form-control">
|
|
</div>
|
|
</div>
|
|
|
|
@* PO coding *@
|
|
<div class="form-group row align-items-center">
|
|
<label for="PO" class="col-sm-4 col-form-label">Enter PO: </label>
|
|
<div class="col-sm-8">
|
|
<input type="text" id="PO" name="PO" required v-model="PO" placeholder="PO123456" class="form-control">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
@* Item Price in RM *@
|
|
<div class="form-group row">
|
|
<label for="priceInRM" class="col-sm-4">Item Price In(RM):</label>
|
|
<div class="col-sm-8">
|
|
<input type="number" id="priceInRM" name="priceInRM" class="form-control" placeholder="RM 00.00" step="0.01" v-on:input="convertCurrency()" required v-model="priceInRM">
|
|
</div>
|
|
</div>
|
|
|
|
@* Currency Selection *@
|
|
<div class="form-group row">
|
|
<label for="currency" class="col-sm-4">Select Currency:</label>
|
|
<div class="col-sm-8">
|
|
<select id="currency" name="currency" class="form-control" v-model="currency" v-on:change="convertCurrency()">
|
|
<option value="" disabled selected>Select a currency</option>
|
|
<option v-for="(name, code) in currencies" :key="code" :value="code">
|
|
{{ code }} - {{ name }}
|
|
</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
@* Currency Rate *@
|
|
<div class="form-group row">
|
|
<label for="currencyRate" class="col-sm-4">Currency Rate(%):</label>
|
|
<div class="col-sm-8">
|
|
<input type="number" id="currencyRate" name="currencyRate" class="form-control" placeholder="0.01%" step="0.01" v-on:input="convertCurrency()" required v-model="currencyRate">
|
|
</div>
|
|
</div>
|
|
|
|
@* Item Convert Price *@
|
|
<div class="form-group row">
|
|
<label for="convertPrice" class="col-sm-4">{{ currency ? 'Item Price (' + currency + ') : ' : 'Item Price : ' }}</label>
|
|
<div class="col-sm-8">
|
|
<input type="number" id="convertPrice" name="convertPrice" class="form-control" readonly v-model="convertPrice">
|
|
</div>
|
|
</div>
|
|
|
|
@* Delivery Order Date *@
|
|
<div class="form-group row">
|
|
<label for="DODate" class="col-sm-4">Enter DO Date:</label>
|
|
<div class="col-sm-8">
|
|
<input type="date" id="DODate" name="DODate" class="form-control" v-on:input="calculateWarrantyEndDate()" required v-model="DODate">
|
|
</div>
|
|
</div>
|
|
|
|
@* Warranty *@
|
|
<div class="form-group row">
|
|
<label for="warranty" class="col-sm-4">Enter Warranty Months(Number):</label>
|
|
<div class="col-sm-8">
|
|
<input type="number" id="warranty" name="warranty" class="form-control" placeholder="0 , 1 , 2 , 3, ..." step="1" min="0" v-on:input="calculateWarrantyEndDate()" required v-model="warranty">
|
|
</div>
|
|
</div>
|
|
|
|
@* Warranty End Date *@
|
|
<div class="form-group row">
|
|
<label for="EndWDate" class="col-sm-4">Warranty End:</label>
|
|
<div class="col-sm-8">
|
|
<input type="date" id="EndWDate" name="EndWDate" class="form-control" readonly v-model="EndWDate">
|
|
</div>
|
|
</div>
|
|
|
|
@* Invoice Date *@
|
|
<div class="form-group row">
|
|
<label for="invoiceDate" class="col-sm-4">Invoice Date:</label>
|
|
<div class="col-sm-8">
|
|
<input type="date" id="invoiceDate" name="invoiceDate" class="form-control" required v-model="invoiceDate">
|
|
</div>
|
|
</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">Reset</button>
|
|
<input type="submit" class="btn btn-primary" value="Submit" />
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
@*Vue Js - POST & RESET*@
|
|
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
|
|
<script>
|
|
new Vue({
|
|
el: '#registerItem',
|
|
data() {
|
|
return {
|
|
companies: [
|
|
{
|
|
companyId: 1,
|
|
companyName: "PSTW",
|
|
departments: [{ departmentId: 1, departmentName: "Air" }, { departmentId: 2, departmentName: "Marine" }, { departmentId: 3, departmentName: "River" }]
|
|
},
|
|
{
|
|
companyId: 2,
|
|
companyName: "TES",
|
|
departments: [{ departmentId: 1, departmentName: "Air" }],
|
|
},
|
|
],
|
|
company: "",
|
|
Dept: null,
|
|
productName: null,
|
|
imageProduct: null,
|
|
productCategory: null,
|
|
serialNumber: "",
|
|
quantity: 1,
|
|
supplierName: null,
|
|
purchaseDate: null,
|
|
PO: null,
|
|
currency: null,
|
|
priceInRM: null,
|
|
currencyRate: 1,
|
|
convertPrice: 0,
|
|
DODate: null,
|
|
warranty: 0,
|
|
EndWDate: null,
|
|
invoiceDate: null,
|
|
products: [],
|
|
depts: [],
|
|
suppliers: [
|
|
{
|
|
supplierId: 1,
|
|
supplierName: "Pang",
|
|
},
|
|
{
|
|
supplierId: 2,
|
|
supplierName: "Ms Kim",
|
|
},
|
|
],
|
|
showOtherCompany: false,
|
|
showOtherDept: false,
|
|
showOtherSupplier: false,
|
|
isModalOpen: false,
|
|
selectedProduct: "",
|
|
selectedSupplier: "",
|
|
selectedCompany: "",
|
|
selectedDepartment: "",
|
|
currencies: {},
|
|
}
|
|
},
|
|
mounted() {// Log the token to check its value
|
|
|
|
// Fetch companies, depts, and products from the API
|
|
this.fetchCurrencyData();
|
|
this.fetchCompanies();
|
|
this.fetchProducts();
|
|
this.fetchSuppliers();
|
|
},
|
|
computed: {
|
|
filteredDepartments() {
|
|
if (!this.selectedCompany) {
|
|
return []; // No company selected, return empty list
|
|
}
|
|
const company = this.companies.find(c => c.companyId === this.selectedCompany);
|
|
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 : {};
|
|
},
|
|
showSerialNumber() {
|
|
return this.showProduct.category === 'Item' || this.showProduct.category === 'Part';
|
|
},
|
|
},
|
|
methods: {
|
|
async addItem() {
|
|
const formData = {
|
|
CompanyId: this.selectedCompany,
|
|
DepartmentId: this.selectedDepartment,
|
|
ProductId: this.selectedProduct,
|
|
SerialNumber: this.serialNumber,
|
|
Quantity: this.quantity,
|
|
Supplier: this.selectedSupplier,
|
|
PurchaseDate: this.purchaseDate,
|
|
PONo: this.PO,
|
|
Currency: this.currency,
|
|
PriceInRM: this.priceInRM,
|
|
CurrencyRate: this.currencyRate,
|
|
ConvertPrice: this.convertPrice,
|
|
DODate: this.DODate,
|
|
Warranty: this.warranty,
|
|
EndWDate: this.EndWDate,
|
|
InvoiceDate: this.invoiceDate
|
|
};
|
|
|
|
try {
|
|
|
|
// Additional specific checks
|
|
if (this.showSerialNumber) {
|
|
this.quantity = 0;
|
|
if (this.serialNumber === null || this.serialNumber === '') {
|
|
alert('Serial Number Error', 'Serial Number must be filled when selecting Item or Part.', 'warning');
|
|
return;
|
|
}
|
|
}
|
|
else {
|
|
this.serialNumber = null;
|
|
if (this.quantity === 0 || this.quantity === null || this.quantity === '') {
|
|
alert('quantity Error', 'Quantity is required when selecting Disposable.', 'warning');
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Proceed to send the data to the API
|
|
const response = await fetch('/InvMainAPI/AddItem', {
|
|
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!', 'Item form has been successfully submitted.', 'success');
|
|
|
|
// 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');
|
|
}
|
|
|
|
},
|
|
|
|
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('/api/Item/GetCompanies', {
|
|
method: 'GET', // 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('/api/Item/GetSupplies', {
|
|
method: 'GET', // Specify the HTTP method
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error('Failed to fetch supplies');
|
|
}
|
|
this.supplies = await response.json(); // Get the full response object
|
|
|
|
} catch (error) {
|
|
console.error('Error fetching supplies:', 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 = null;
|
|
this.Dept = null;
|
|
this.productName = null;
|
|
this.imageProduct = null;
|
|
this.serialNumber = '';
|
|
this.quantity = 0;
|
|
this.supplierName = null;
|
|
this.purchaseDate = null;
|
|
this.PO = null;
|
|
this.currency = null;
|
|
this.priceInRM = null;
|
|
this.currencyRate = null;
|
|
this.convertPrice = null;
|
|
this.DODate = null;
|
|
this.warranty = null;
|
|
this.EndWDate = null;
|
|
this.invoiceDate = null;
|
|
this.showOtherCompany = false;
|
|
this.showOtherDept = false;
|
|
this.showOtherSupplier = false;
|
|
this.selectedCompany = null;
|
|
this.selectedSupplier = null;
|
|
},
|
|
|
|
// FRONT END FUNCTIONS
|
|
//----------------------//
|
|
//Calculate Total Price
|
|
convertCurrency() {
|
|
const total = this.priceInRM / this.currencyRate;
|
|
this.convertPrice = total.toFixed(2);
|
|
this.priceInRM = this.priceInRM
|
|
.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
|
|
|
|
},
|
|
|
|
openModal() {
|
|
this.isModalOpen = true; // Open the modal
|
|
},
|
|
closeModal() {
|
|
this.isModalOpen = false; // Close the modal
|
|
},
|
|
|
|
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;
|
|
}
|
|
},
|
|
},
|
|
});
|
|
</script> |