update Inv
This commit is contained in:
parent
5298db78cb
commit
01ba9a6629
@ -36,9 +36,6 @@ namespace PSTW_CentralSystem.Areas.Inventory.Models
|
|||||||
public string PartNumber { get; set; } = string.Empty;
|
public string PartNumber { get; set; } = string.Empty;
|
||||||
public int CreatedByUserId { get; set; }
|
public int CreatedByUserId { get; set; }
|
||||||
[ForeignKey("CreatedByUserId")]
|
[ForeignKey("CreatedByUserId")]
|
||||||
|
|
||||||
public DateTime CreateDate { get; set; } = DateTime.Now;
|
|
||||||
|
|
||||||
public virtual UserModel? CreatedBy { get; set; }
|
public virtual UserModel? CreatedBy { get; set; }
|
||||||
[ForeignKey("CompanyId")]
|
[ForeignKey("CompanyId")]
|
||||||
public virtual CompanyModel? Company { get; set; }
|
public virtual CompanyModel? Company { get; set; }
|
||||||
|
|||||||
@ -634,10 +634,12 @@
|
|||||||
"title": "Price(RM)",
|
"title": "Price(RM)",
|
||||||
"data": (row) => parseFloat(row.convertPrice).toFixed(2),
|
"data": (row) => parseFloat(row.convertPrice).toFixed(2),
|
||||||
},
|
},
|
||||||
{
|
// --- REMOVE ---
|
||||||
"title": "Register Date",
|
// {
|
||||||
"data": "createDate",
|
// "title": "Register Date",
|
||||||
},
|
// "data": "createDate", // This is the problematic line
|
||||||
|
// },
|
||||||
|
// --------------
|
||||||
{
|
{
|
||||||
"title": "Warranty Until",
|
"title": "Warranty Until",
|
||||||
"data": "warranty",
|
"data": "warranty",
|
||||||
@ -712,6 +714,7 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// Attach click event listener to the edit buttons
|
// Attach click event listener to the edit buttons
|
||||||
$('#itemDatatable tbody').off('click', '.edit-btn').on('click', '.edit-btn', function () {
|
$('#itemDatatable tbody').off('click', '.edit-btn').on('click', '.edit-btn', function () {
|
||||||
const itemId = $(this).data('id');
|
const itemId = $(this).data('id');
|
||||||
|
|||||||
@ -182,7 +182,7 @@
|
|||||||
<!-- Send Date -->
|
<!-- Send Date -->
|
||||||
<div class="d-flex flex-wrap align-items-center gap-2 flex-grow-1" style="max-width:285px; min-width:285px;">
|
<div class="d-flex flex-wrap align-items-center gap-2 flex-grow-1" style="max-width:285px; min-width:285px;">
|
||||||
<h4 class="fixed-label m-0 text-nowrap">{{movement.action === 'Assign' ? 'Assign Date' : 'Send Date'}}</h4>
|
<h4 class="fixed-label m-0 text-nowrap">{{movement.action === 'Assign' ? 'Assign Date' : 'Send Date'}}</h4>
|
||||||
<span class="fixed-value text-truncate">{{ movement.sendDate }}</span>
|
<span class="fixed-value text-truncate">{{ formatDate(movement.sendDate) }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Receive Date -->
|
<!-- Receive Date -->
|
||||||
@ -277,7 +277,7 @@
|
|||||||
<!-- Send Date -->
|
<!-- Send Date -->
|
||||||
<div class="d-flex flex-wrap align-items-center gap-2 flex-grow-1" style="max-width:285px; min-width:285px;">
|
<div class="d-flex flex-wrap align-items-center gap-2 flex-grow-1" style="max-width:285px; min-width:285px;">
|
||||||
<h4 class="fixed-label m-0 text-nowrap">{{movement.action === 'Assign' ? 'Assign Date' : 'Send Date'}}</h4>
|
<h4 class="fixed-label m-0 text-nowrap">{{movement.action === 'Assign' ? 'Assign Date' : 'Send Date'}}</h4>
|
||||||
<span class="fixed-value text-truncate">{{ movement.sendDate }}</span>
|
<span class="fixed-value text-truncate">{{ formatDate(movement.sendDate) }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Receive Date -->
|
<!-- Receive Date -->
|
||||||
@ -398,7 +398,7 @@
|
|||||||
<!-- Send Date -->
|
<!-- Send Date -->
|
||||||
<div class="d-flex flex-wrap align-items-center gap-2 flex-grow-1" style="max-width:285px; min-width:285px;">
|
<div class="d-flex flex-wrap align-items-center gap-2 flex-grow-1" style="max-width:285px; min-width:285px;">
|
||||||
<h4 class="fixed-label m-0 text-nowrap">{{movement.action === 'Assign' ? 'Assign Date' : 'Send Date'}}</h4>
|
<h4 class="fixed-label m-0 text-nowrap">{{movement.action === 'Assign' ? 'Assign Date' : 'Send Date'}}</h4>
|
||||||
<span class="fixed-value text-truncate">{{ movement.sendDate }}</span>
|
<span class="fixed-value text-truncate">{{ formatDate(movement.sendDate) }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Receive Date -->
|
<!-- Receive Date -->
|
||||||
@ -490,7 +490,7 @@
|
|||||||
<!-- Send Date -->
|
<!-- Send Date -->
|
||||||
<div class="d-flex flex-wrap align-items-center gap-2 flex-grow-1" style="max-width:285px; min-width:285px;">
|
<div class="d-flex flex-wrap align-items-center gap-2 flex-grow-1" style="max-width:285px; min-width:285px;">
|
||||||
<h4 class="fixed-label m-0 text-nowrap">{{movement.action === 'Assign' ? 'Assign Date' : 'Send Date'}}</h4>
|
<h4 class="fixed-label m-0 text-nowrap">{{movement.action === 'Assign' ? 'Assign Date' : 'Send Date'}}</h4>
|
||||||
<span class="fixed-value text-truncate">{{ movement.sendDate }}</span>
|
<span class="fixed-value text-truncate">{{ formatDate(movement.sendDate) }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Receive Date -->
|
<!-- Receive Date -->
|
||||||
@ -830,6 +830,17 @@
|
|||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
formatDate(dateString) {
|
||||||
|
if (!dateString) return '';
|
||||||
|
const date = new Date(dateString);
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(date.getDate()).padStart(2, '0');
|
||||||
|
const hours = String(date.getHours()).padStart(2, '0');
|
||||||
|
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||||
|
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||||
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||||
|
},
|
||||||
paginatedItemsStation(item) {
|
paginatedItemsStation(item) {
|
||||||
const start = (this.currentPageStation - 1) * this.itemsPerPageStation;
|
const start = (this.currentPageStation - 1) * this.itemsPerPageStation;
|
||||||
const end = start + this.itemsPerPageStation;
|
const end = start + this.itemsPerPageStation;
|
||||||
@ -1024,7 +1035,7 @@
|
|||||||
{ title: "Product Name", data: "productName", render: (data, type, full) => { return `${data} <br> ${renderFile(full.productImage)}`; } },
|
{ title: "Product Name", data: "productName", render: (data, type, full) => { return `${data} <br> ${renderFile(full.productImage)}`; } },
|
||||||
{ title: "Product Code", data: "uniqueID" },
|
{ title: "Product Code", data: "uniqueID" },
|
||||||
{ title: "Action", data: "action" },
|
{ title: "Action", data: "action" },
|
||||||
{ title: "Send Date", data: "sendDate" },
|
{ title: "Send Date", data: "sendDate", render: this.formatDate.bind(this) },
|
||||||
{ title: "Start Status", data: "toOther" },
|
{ title: "Start Status", data: "toOther" },
|
||||||
{ title: "From User", data: "toUserName" },
|
{ title: "From User", data: "toUserName" },
|
||||||
{ title: "Last User", data: "lastUserName" },
|
{ title: "Last User", data: "lastUserName" },
|
||||||
@ -1044,7 +1055,7 @@
|
|||||||
{ title: "Unique Id", data: "id" },
|
{ title: "Unique Id", data: "id" },
|
||||||
{ title: "Product Name", data: "productName", render: (data, type, full) => { return `${data} <br> ${renderFile(full.productImage)}`; } },
|
{ title: "Product Name", data: "productName", render: (data, type, full) => { return `${data} <br> ${renderFile(full.productImage)}`; } },
|
||||||
{ title: "Product Code", data: "uniqueID" },
|
{ title: "Product Code", data: "uniqueID" },
|
||||||
{ title: "Send Date", data: "sendDate" },
|
{ title: "Send Date", data: "sendDate", render: this.formatDate.bind(this) },
|
||||||
{ title: "Receive Date", data: "receiveDate" },
|
{ title: "Receive Date", data: "receiveDate" },
|
||||||
{ title: "Action", data: "action" },
|
{ title: "Action", data: "action" },
|
||||||
{ title: "Start Status", data: "toOther" },
|
{ title: "Start Status", data: "toOther" },
|
||||||
@ -1069,7 +1080,7 @@
|
|||||||
{ title: "Unique Id", data: "id" },
|
{ title: "Unique Id", data: "id" },
|
||||||
{ title: "Product Name", data: "productName", render: (data, type, full) => { return `${data} <br> ${renderFile(full.productImage)}`; }},
|
{ title: "Product Name", data: "productName", render: (data, type, full) => { return `${data} <br> ${renderFile(full.productImage)}`; }},
|
||||||
{ title: "Product Code", data: "uniqueID" },
|
{ title: "Product Code", data: "uniqueID" },
|
||||||
{ title: "Assign Date", data: "sendDate" },
|
{ title: "Assign Date", data: "sendDate", render: this.formatDate.bind(this) },
|
||||||
{ title: "Action", data: "action" },
|
{ title: "Action", data: "action" },
|
||||||
{ title: "Station User PIC", data: "toUserName" },
|
{ title: "Station User PIC", data: "toUserName" },
|
||||||
{ title: "From Station", data: "toStationName" },
|
{ title: "From Station", data: "toStationName" },
|
||||||
|
|||||||
@ -468,6 +468,17 @@
|
|||||||
function renderDeleteButton(data) {
|
function renderDeleteButton(data) {
|
||||||
return `<button type="button" class="btn btn-danger delete-btn" data-id="${data}">Delete</button>`;
|
return `<button type="button" class="btn btn-danger delete-btn" data-id="${data}">Delete</button>`;
|
||||||
}
|
}
|
||||||
|
function formatDateTime(dateString) {
|
||||||
|
if (!dateString) return '';
|
||||||
|
const date = new Date(dateString);
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(date.getDate()).padStart(2, '0');
|
||||||
|
const hours = String(date.getHours()).padStart(2, '0');
|
||||||
|
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||||
|
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||||
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||||
|
}
|
||||||
|
|
||||||
this.pendingRequestDatatable = $('#requestDatatable').DataTable({
|
this.pendingRequestDatatable = $('#requestDatatable').DataTable({
|
||||||
"data": this.request.filter(req => req.status === "Requested"),
|
"data": this.request.filter(req => req.status === "Requested"),
|
||||||
@ -479,7 +490,7 @@
|
|||||||
{ "title": "Document / Picture", "data": "document", "render": (data, type, full) => renderDocument(data) },
|
{ "title": "Document / Picture", "data": "document", "render": (data, type, full) => renderDocument(data) },
|
||||||
{ "title": "Remark", "data": "remarkUser" },
|
{ "title": "Remark", "data": "remarkUser" },
|
||||||
{ "title": "Station Deploy", "data": "stationName", "render": (data) => data || "Self Assign" },
|
{ "title": "Station Deploy", "data": "stationName", "render": (data) => data || "Self Assign" },
|
||||||
{ "title": "Request Date", "data": "requestDate" },
|
{ "title": "Request Date", "data": "requestDate", "render": (data) => formatDateTime(data) }, // Apply formatting here
|
||||||
{ "title": "Status", "data": "status" },
|
{ "title": "Status", "data": "status" },
|
||||||
{ "title": "Delete", "data": "requestID", "render": renderDeleteButton, "className": "align-middle" }
|
{ "title": "Delete", "data": "requestID", "render": renderDeleteButton, "className": "align-middle" }
|
||||||
],
|
],
|
||||||
@ -498,8 +509,8 @@
|
|||||||
{ "title": "Document / Picture", "data": "document", "render": (data, type, full) => renderDocument(data) },
|
{ "title": "Document / Picture", "data": "document", "render": (data, type, full) => renderDocument(data) },
|
||||||
{ "title": "Remark", "data": "remarkUser" },
|
{ "title": "Remark", "data": "remarkUser" },
|
||||||
{ "title": "Remark (Master)", "data": "remarkMasterInv" },
|
{ "title": "Remark (Master)", "data": "remarkMasterInv" },
|
||||||
{ "title": "Request Date", "data": "requestDate" },
|
{ "title": "Request Date", "data": "requestDate", "render": (data) => formatDateTime(data) }, // Apply formatting here
|
||||||
{ "title": "Approval Date", "data": "approvalDate" }
|
{ "title": "Approval Date", "data": "approvalDate", "render": (data) => formatDateTime(data) } // Apply formatting here
|
||||||
],
|
],
|
||||||
responsive: true,
|
responsive: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -379,7 +379,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
|||||||
var userRole = await _userManager.GetRolesAsync(user);
|
var userRole = await _userManager.GetRolesAsync(user);
|
||||||
var isAdmin = userRole.Contains("SystemAdmin") || userRole.Contains("SuperAdmin") || userRole.Contains("Finance");
|
var isAdmin = userRole.Contains("SystemAdmin") || userRole.Contains("SuperAdmin") || userRole.Contains("Finance");
|
||||||
List<ItemModel> itemList = new List<ItemModel>();
|
List<ItemModel> itemList = new List<ItemModel>();
|
||||||
List<ItemMovementModel> createDate = new List<ItemMovementModel>();
|
|
||||||
// Get the item list
|
// Get the item list
|
||||||
if (isAdmin)
|
if (isAdmin)
|
||||||
{
|
{
|
||||||
@ -418,15 +418,10 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
|||||||
// Get the departments list (DepartmentId references Departments)
|
// Get the departments list (DepartmentId references Departments)
|
||||||
var departments = await _centralDbContext.Departments.ToListAsync();
|
var departments = await _centralDbContext.Departments.ToListAsync();
|
||||||
|
|
||||||
var createDates = await _centralDbContext.ItemMovements.Where(r => r.Action == "Register").ToListAsync();
|
|
||||||
|
|
||||||
// Buat dictionary agar lebih cepat dicari berdasarkan ItemID
|
|
||||||
var createDateDict = await _centralDbContext.ItemMovements.Where(r => r.Action == "Register").GroupBy(r => r.ItemId).ToDictionaryAsync(g => g.Key, g => g.Min(m => m.Date));
|
|
||||||
|
|
||||||
// Now join items with users and departments manually
|
// Now join items with users and departments manually
|
||||||
var itemListWithDetails = itemList.Select(item => new
|
var itemListWithDetails = itemList.Select(item => new
|
||||||
{
|
{
|
||||||
createDate = createDateDict.ContainsKey(item.ItemID) ? createDateDict[item.ItemID].ToString("dd/MM/yyyy HH:mm:ss") : null,
|
// createDate = createDateDict.ContainsKey(item.ItemID) ? createDateDict[item.ItemID].ToString("dd/MM/yyyy HH:mm:ss") : null,
|
||||||
item.ItemID,
|
item.ItemID,
|
||||||
item.UniqueID,
|
item.UniqueID,
|
||||||
item.CompanyId,
|
item.CompanyId,
|
||||||
@ -450,7 +445,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
|||||||
EndWDate = item.EndWDate.ToString("dd/MM/yyyy"),
|
EndWDate = item.EndWDate.ToString("dd/MM/yyyy"),
|
||||||
InvoiceDate = item.InvoiceDate?.ToString("dd/MM/yyyy"),
|
InvoiceDate = item.InvoiceDate?.ToString("dd/MM/yyyy"),
|
||||||
item.Department?.DepartmentName,
|
item.Department?.DepartmentName,
|
||||||
RegisterDate = createDate,
|
//RegisterDate = createDate,
|
||||||
CreatedBy =item.CreatedBy!.UserName,
|
CreatedBy =item.CreatedBy!.UserName,
|
||||||
item.Product!.ProductName,
|
item.Product!.ProductName,
|
||||||
item.Product!.ProductShortName,
|
item.Product!.ProductShortName,
|
||||||
@ -497,9 +492,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var product = await _centralDbContext.Products.FirstOrDefaultAsync(p => p.ProductId == item.ProductId) ?? throw new Exception("Product not found");
|
var product = await _centralDbContext.Products.FirstOrDefaultAsync(p => p.ProductId == item.ProductId) ?? throw new Exception("Product not found");
|
||||||
var inventoryMaster = await _centralDbContext.InventoryMasters
|
var inventoryMaster = await _centralDbContext.InventoryMasters.Include("User").FirstOrDefaultAsync(i => i.UserId == item.CreatedByUserId) ?? new InventoryMasterModel { UserId = item.CreatedByUserId };
|
||||||
.Include("User")
|
|
||||||
.FirstOrDefaultAsync(i => i.UserId == item.CreatedByUserId) ?? new InventoryMasterModel { UserId = item.CreatedByUserId };
|
|
||||||
|
|
||||||
if (product.Category == "Disposable")
|
if (product.Category == "Disposable")
|
||||||
{
|
{
|
||||||
@ -516,8 +509,6 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
|||||||
item.Quantity = 1; // Force quantity to 1 for Assets/Parts if it's not already
|
item.Quantity = 1; // Force quantity to 1 for Assets/Parts if it's not already
|
||||||
}
|
}
|
||||||
|
|
||||||
item.CreateDate = DateTime.Now;
|
|
||||||
|
|
||||||
_centralDbContext.Items.Add(item);
|
_centralDbContext.Items.Add(item);
|
||||||
_centralDbContext.Products.Update(product); // Update the product quantity
|
_centralDbContext.Products.Update(product); // Update the product quantity
|
||||||
|
|
||||||
@ -584,7 +575,6 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
|
|||||||
savedItem.EndWDate,
|
savedItem.EndWDate,
|
||||||
savedItem.InvoiceDate,
|
savedItem.InvoiceDate,
|
||||||
savedItem.PartNumber,
|
savedItem.PartNumber,
|
||||||
CreateDate = savedItem.CreateDate.ToString("dd/MM/yyyy HH:mm:ss")
|
|
||||||
};
|
};
|
||||||
return Json(updatedItem);
|
return Json(updatedItem);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user