update station and request
This commit is contained in:
parent
9b31a50115
commit
f8ef2b449c
@ -30,5 +30,10 @@ namespace PSTW_CentralSystem.Areas.Inventory.Controllers.Admin
|
|||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IActionResult StationRegistration()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
Areas/Inventory/Models/RequestModel.cs
Normal file
20
Areas/Inventory/Models/RequestModel.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using PSTW_CentralSystem.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
namespace PSTW_CentralSystem.Areas.Inventory.Models
|
||||||
|
{
|
||||||
|
public class RequestModel
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public int requestId { get; set; }
|
||||||
|
public int DepartmentId { get; set; }
|
||||||
|
[ForeignKey("DepartmentId")]
|
||||||
|
public virtual ItemModel? Department { get; set; }
|
||||||
|
[ForeignKey("ItemID")]
|
||||||
|
public string? remark { get; set; }
|
||||||
|
public string? status { get; set; }
|
||||||
|
public DateTime requestDate { get; set; }
|
||||||
|
public DateTime approvalDate { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
298
Areas/Inventory/Views/InventoryMaster/StationRegistration.cshtml
Normal file
298
Areas/Inventory/Views/InventoryMaster/StationRegistration.cshtml
Normal file
@ -0,0 +1,298 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Station";
|
||||||
|
Layout = "~/Views/Shared/_Layout.cshtml";
|
||||||
|
}
|
||||||
|
|
||||||
|
@await Html.PartialAsync("~/Areas/Inventory/Views/_InventoryPartial.cshtml");
|
||||||
|
<div id="registerStation">
|
||||||
|
<form v-on:submit.prevent="addStation" data-aos="fade-right" id="registerStationForm" v-if="registerStationForm">
|
||||||
|
<div class="container register" data-aos="fade-right">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-9 register-rights" data-aos="fade-right">
|
||||||
|
<div class="tab-content" id="myTabContent" data-aos="fade-right">
|
||||||
|
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab" data-aos="fade-right">
|
||||||
|
<h3 class="register-heading">REGISTRATION STATION</h3>
|
||||||
|
<div class="row register-form">
|
||||||
|
<div class="col-md-61">
|
||||||
|
|
||||||
|
@* Station Name *@
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="stationName" class="col-sm-3">Station Name:</label>
|
||||||
|
<div class="col-sm-9">
|
||||||
|
<input type="text" id="stationName" name="stationName" class="form-control" required v-model="stationName">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@* User ID *@
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-sm-4 col-form-label">Station User PIC</label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<div class="dropdown">
|
||||||
|
<select class="btn btn-primary dropdown-toggle col-md-10" v-model="selectedUserName" :disabled="currentUser != null" required v-on:change="updateDepartment()">
|
||||||
|
<option class="btn-light" value="" disabled selected>Select User</option>
|
||||||
|
<option v-for="(technicianUser, index) in users" :key="index" :value="technicianUser.fullname">
|
||||||
|
{{ technicianUser.fullname }}
|
||||||
|
</option>
|
||||||
|
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@* Department ID *@
|
||||||
|
<!-- Department Dropdown -->
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-sm-4 col-form-label">Department: </label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<!-- Use a span to keep the same space occupied -->
|
||||||
|
<span v-if="selectedDepartment">{{ selectedDepartment }}</span>
|
||||||
|
<span v-else>No department assigned</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="col-sm-9 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 class="row card">
|
||||||
|
<div class="card-header">
|
||||||
|
<button id="addStationBtn" :class="['btn', 'col-md-3', 'col-lg-3', 'm-1', 'col-12', registerStationForm ? 'btn-danger' : 'btn-success']" v-on:click="registerStationForm = !registerStationForm"><i :class="['fa', registerStationForm ? 'fa-minus' : 'fa-plus']"></i> {{registerStationForm ? 'Hide Add Station' : 'Show Add Station'}}</button>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<table class="table table-bordered table-hover table-striped no-wrap" id="stationDatatable" style="width:100%;border-style: solid; border-width: 1px"></table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@section Scripts {
|
||||||
|
@{
|
||||||
|
await Html.RenderPartialAsync("_ValidationScriptsPartial");
|
||||||
|
}
|
||||||
|
<script>
|
||||||
|
$(function () {
|
||||||
|
app.mount('#registerStation');
|
||||||
|
|
||||||
|
// Attach a click event listener to elements with the class 'btn-success'.
|
||||||
|
$('#addStationBtn').on('click', function () {
|
||||||
|
// Show the modal with the ID 'addStationModal'.
|
||||||
|
$('#registerStationModal').modal('show');
|
||||||
|
});
|
||||||
|
$('.closeModal').on('click', function () {
|
||||||
|
// Show the modal with the ID 'addStationModal'.
|
||||||
|
$('.modal').modal('hide');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
const app = Vue.createApp({
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
stationName: null,
|
||||||
|
stationUserPIC: null,
|
||||||
|
departmentId : null,
|
||||||
|
selectedUserName : null,
|
||||||
|
selectedDepartment: null,
|
||||||
|
stations: null,
|
||||||
|
currentUser: null,
|
||||||
|
users : null,
|
||||||
|
registerStationForm: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.fetchUsers();
|
||||||
|
this.fetchStations();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async fetchUsers() {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/IdentityAPI/GetTechnicianUserInformation/`, {
|
||||||
|
method: 'POST',
|
||||||
|
});
|
||||||
|
if (response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
|
this.users = data.technicianUsers;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error(`Failed to fetch user: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error('There was a problem with the fetch operation:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async fetchStations() {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/InvMainAPI/StationList', {
|
||||||
|
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.stationDatatable) {
|
||||||
|
this.stationDatatable.clear().destroy();
|
||||||
|
}
|
||||||
|
const stations = await response.json();
|
||||||
|
this.stations = stations;
|
||||||
|
|
||||||
|
if ($.fn.dataTable.isDataTable('#stationDatatable')) {
|
||||||
|
$('#stationDatatable').DataTable().clear().destroy();
|
||||||
|
}
|
||||||
|
this.initiateTable();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching stations:', error);
|
||||||
|
this.errorMessage = 'Error: ' + error.message;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async addStation() {
|
||||||
|
$('#loadingModal').modal('show');
|
||||||
|
// Create the payload
|
||||||
|
const formData = {
|
||||||
|
StationName: this.stationName,
|
||||||
|
StationPicID: this.stationUserPIC,
|
||||||
|
DepartmentId: this.departmentId,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// List of required fields
|
||||||
|
const requiredFields = ['stationName', 'stationUserPIC', 'departmentId'];
|
||||||
|
|
||||||
|
// Loop through required fields and check if any are null or empty
|
||||||
|
for (let field of requiredFields) {
|
||||||
|
if (this[field] === null || this[field] === '') {
|
||||||
|
alert('Station Error', `Please fill in required fields: ${field}.`, 'warning');
|
||||||
|
return; // Exit early if validation fails
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Proceed to send the data as raw JSON string
|
||||||
|
const response = await fetch('/InvMainAPI/AddStation', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(formData) // Convert the formData to a JSON string
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.fetchStations();
|
||||||
|
$('#loadingModal').modal('hide');
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json();
|
||||||
|
console.error('Error response:', errorData);
|
||||||
|
this.errorMessage = 'Error: ' + (errorData.message || 'Unknown error');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.fetchStations();
|
||||||
|
this.resetForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
alert('Station Error', `An error occurred: ${error.message}`, 'error');
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
await new Promise(resolve => {
|
||||||
|
$('#loadingModal').on('shown.bs.modal', resolve);
|
||||||
|
});
|
||||||
|
$('#loadingModal').modal('hide');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
resetForm() {
|
||||||
|
this.selectedUserName = null;
|
||||||
|
this.selectedDepartment = null;
|
||||||
|
this.stationName = null;
|
||||||
|
this.stationUserPIC = null;
|
||||||
|
this.departmentId = '';
|
||||||
|
},
|
||||||
|
initiateTable() {
|
||||||
|
self = this;
|
||||||
|
this.stationDatatable = $('#stationDatatable').DataTable({
|
||||||
|
"data": this.stations,
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"title": "Station Name",
|
||||||
|
"data": "stationName",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Station User PIC",
|
||||||
|
"data": "stationPicID",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Department ID",
|
||||||
|
"data": "departmentId",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Delete",
|
||||||
|
"data": "stationId",
|
||||||
|
"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
|
||||||
|
$('#stationDatatable tbody').on('click', '.delete-btn', function () {
|
||||||
|
const stationId = $(this).data('id');
|
||||||
|
self.deleteStation(stationId);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.loading = false;
|
||||||
|
},
|
||||||
|
updateDepartment() {
|
||||||
|
// Find the selected user by their full name
|
||||||
|
const selectedUser = this.users.find(user => user.fullname === this.selectedUserName);
|
||||||
|
if (selectedUser) {
|
||||||
|
this.stationUserPIC = selectedUser.id;
|
||||||
|
this.departmentId = selectedUser.department.departmentId;
|
||||||
|
this.selectedDepartment = selectedUser.department.departmentName; // Set department name
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async deleteStation(stationId) {
|
||||||
|
if (!confirm("Are you sure you want to delete this station?")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/InvMainAPI/DeleteStation/${stationId}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ stationId })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json();
|
||||||
|
console.error('Error response:', errorData);
|
||||||
|
this.errorMessage = 'Error: ' + (errorData.message || 'Unknown error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.fetchStations();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error deleting stations:', error);
|
||||||
|
this.errorMessage = 'Error: ' + error.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
}
|
||||||
@ -107,7 +107,7 @@
|
|||||||
supplierAddress : null,
|
supplierAddress : null,
|
||||||
supplierPhoneNo : null,
|
supplierPhoneNo : null,
|
||||||
supplierPIC : null,
|
supplierPIC : null,
|
||||||
suuppliers: null,
|
suppliers: null,
|
||||||
supplierDatatable: null,
|
supplierDatatable: null,
|
||||||
gender: ["Male", "Female", "Helicopter"],
|
gender: ["Male", "Female", "Helicopter"],
|
||||||
registerSupplierForm: false
|
registerSupplierForm: false
|
||||||
|
|||||||
@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PSTW_CentralSystem.DBContext;
|
using PSTW_CentralSystem.DBContext;
|
||||||
using PSTW_CentralSystem.Models;
|
using PSTW_CentralSystem.Models;
|
||||||
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
@ -63,6 +64,45 @@ namespace PSTW_CentralSystem.Controllers.API
|
|||||||
return StatusCode(500, $"An error occurred: {ex.Message}");
|
return StatusCode(500, $"An error occurred: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("GetTechnicianUserInformation")]
|
||||||
|
public async Task<IActionResult> GetTechnicianUserInformation()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var users = await _identityDbContext.Users
|
||||||
|
.Include(u => u.Department)
|
||||||
|
.ToListAsync(); // Retrieve all users with department info
|
||||||
|
|
||||||
|
var technicianUsers = new List<object>();
|
||||||
|
|
||||||
|
foreach (var user in users)
|
||||||
|
{
|
||||||
|
var roles = await _userManager.GetRolesAsync(user);
|
||||||
|
if (roles.Contains("Technician"))
|
||||||
|
{
|
||||||
|
technicianUsers.Add(new
|
||||||
|
{
|
||||||
|
id = user.Id,
|
||||||
|
fullname = user.FullName,
|
||||||
|
department = user.Department
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!technicianUsers.Any())
|
||||||
|
{
|
||||||
|
return NotFound(new { message = "No technicians found" });
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(new { technicianUsers = technicianUsers });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, new { message = $"An error occurred: {ex.Message}" });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
#endregion User
|
#endregion User
|
||||||
|
|
||||||
#region LDAP Login
|
#region LDAP Login
|
||||||
|
|||||||
@ -610,5 +610,50 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Station
|
||||||
|
[HttpPost("StationList")]
|
||||||
|
public async Task<IActionResult> StationList()
|
||||||
|
{
|
||||||
|
var stationList = await _centralDbContext.Stations.ToListAsync();
|
||||||
|
return Json(stationList);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("AddStation")]
|
||||||
|
public async Task<IActionResult> AddStation([FromBody] StationModel station)
|
||||||
|
{
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
{
|
||||||
|
return BadRequest(ModelState);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_centralDbContext.Stations.Add(station);
|
||||||
|
await _centralDbContext.SaveChangesAsync();
|
||||||
|
var updatedList = await _centralDbContext.Stations.ToListAsync();
|
||||||
|
return Json(updatedList);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return BadRequest(ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("DeleteStation/{id}")]
|
||||||
|
public async Task<IActionResult> DeleteStation(int id)
|
||||||
|
{
|
||||||
|
var station = await _centralDbContext.Stations.FindAsync(id);
|
||||||
|
if (station == null)
|
||||||
|
{
|
||||||
|
return NotFound(new { success = false, message = "Station not found" });
|
||||||
|
}
|
||||||
|
|
||||||
|
_centralDbContext.Stations.Remove(station);
|
||||||
|
await _centralDbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
return Ok(new { success = true, message = "Station deleted successfully" });
|
||||||
|
}
|
||||||
|
#endregion Station
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,6 +91,7 @@ namespace PSTW_CentralSystem.DBContext
|
|||||||
public DbSet<DepartmentModel> Departments { get; set; }
|
public DbSet<DepartmentModel> Departments { get; set; }
|
||||||
public DbSet<ManufacturerModel> Manufacturers { get; set; }
|
public DbSet<ManufacturerModel> Manufacturers { get; set; }
|
||||||
public DbSet<ItemModel> Items { get; set; }
|
public DbSet<ItemModel> Items { get; set; }
|
||||||
|
public DbSet<RequestModel> Requests { get; set; }
|
||||||
public DbSet<ProductModel> Products { get; set; }
|
public DbSet<ProductModel> Products { get; set; }
|
||||||
public DbSet<SupplierModel> Suppliers { get; set; }
|
public DbSet<SupplierModel> Suppliers { get; set; }
|
||||||
public DbSet<InventoryMasterModel> InventoryMasters { get; set; }
|
public DbSet<InventoryMasterModel> InventoryMasters { get; set; }
|
||||||
|
|||||||
@ -454,6 +454,13 @@
|
|||||||
<i class="mdi mdi-view-dashboard"></i><span class="hide-menu">Item Registration</span>
|
<i class="mdi mdi-view-dashboard"></i><span class="hide-menu">Item Registration</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="sidebar-item">
|
||||||
|
<a class="sidebar-link waves-effect waves-dark sidebar-link"
|
||||||
|
asp-area="Inventory" asp-controller="InventoryMaster" asp-action="StationRegistration"
|
||||||
|
aria-expanded="false">
|
||||||
|
<i class="mdi mdi-view-dashboard"></i><span class="hide-menu">Station Registration</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li class="sidebar-item">
|
<li class="sidebar-item">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user