update Inv

This commit is contained in:
Naz 2025-07-24 16:58:02 +08:00
parent 5298db78cb
commit 01ba9a6629
5 changed files with 166 additions and 154 deletions

View File

@ -36,9 +36,6 @@ namespace PSTW_CentralSystem.Areas.Inventory.Models
public string PartNumber { get; set; } = string.Empty;
public int CreatedByUserId { get; set; }
[ForeignKey("CreatedByUserId")]
public DateTime CreateDate { get; set; } = DateTime.Now;
public virtual UserModel? CreatedBy { get; set; }
[ForeignKey("CompanyId")]
public virtual CompanyModel? Company { get; set; }

View File

@ -634,10 +634,12 @@
"title": "Price(RM)",
"data": (row) => parseFloat(row.convertPrice).toFixed(2),
},
{
"title": "Register Date",
"data": "createDate",
},
// --- REMOVE ---
// {
// "title": "Register Date",
// "data": "createDate", // This is the problematic line
// },
// --------------
{
"title": "Warranty Until",
"data": "warranty",
@ -712,6 +714,7 @@
}
})
// Attach click event listener to the edit buttons
$('#itemDatatable tbody').off('click', '.edit-btn').on('click', '.edit-btn', function () {
const itemId = $(this).data('id');

View File

@ -182,7 +182,7 @@
<!-- Send Date -->
<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>
<span class="fixed-value text-truncate">{{ movement.sendDate }}</span>
<span class="fixed-value text-truncate">{{ formatDate(movement.sendDate) }}</span>
</div>
<!-- Receive Date -->
@ -277,7 +277,7 @@
<!-- Send Date -->
<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>
<span class="fixed-value text-truncate">{{ movement.sendDate }}</span>
<span class="fixed-value text-truncate">{{ formatDate(movement.sendDate) }}</span>
</div>
<!-- Receive Date -->
@ -398,7 +398,7 @@
<!-- Send Date -->
<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>
<span class="fixed-value text-truncate">{{ movement.sendDate }}</span>
<span class="fixed-value text-truncate">{{ formatDate(movement.sendDate) }}</span>
</div>
<!-- Receive Date -->
@ -490,7 +490,7 @@
<!-- Send Date -->
<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>
<span class="fixed-value text-truncate">{{ movement.sendDate }}</span>
<span class="fixed-value text-truncate">{{ formatDate(movement.sendDate) }}</span>
</div>
<!-- Receive Date -->
@ -830,6 +830,17 @@
]);
},
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) {
const start = (this.currentPageStation - 1) * 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 Code", data: "uniqueID" },
{ 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: "From User", data: "toUserName" },
{ title: "Last User", data: "lastUserName" },
@ -1044,7 +1055,7 @@
{ title: "Unique Id", data: "id" },
{ title: "Product Name", data: "productName", render: (data, type, full) => { return `${data} <br> ${renderFile(full.productImage)}`; } },
{ 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: "Action", data: "action" },
{ title: "Start Status", data: "toOther" },
@ -1069,7 +1080,7 @@
{ title: "Unique Id", data: "id" },
{ title: "Product Name", data: "productName", render: (data, type, full) => { return `${data} <br> ${renderFile(full.productImage)}`; }},
{ 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: "Station User PIC", data: "toUserName" },
{ title: "From Station", data: "toStationName" },

View File

@ -468,6 +468,17 @@
function renderDeleteButton(data) {
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({
"data": this.request.filter(req => req.status === "Requested"),
@ -479,7 +490,7 @@
{ "title": "Document / Picture", "data": "document", "render": (data, type, full) => renderDocument(data) },
{ "title": "Remark", "data": "remarkUser" },
{ "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": "Delete", "data": "requestID", "render": renderDeleteButton, "className": "align-middle" }
],
@ -498,8 +509,8 @@
{ "title": "Document / Picture", "data": "document", "render": (data, type, full) => renderDocument(data) },
{ "title": "Remark", "data": "remarkUser" },
{ "title": "Remark (Master)", "data": "remarkMasterInv" },
{ "title": "Request Date", "data": "requestDate" },
{ "title": "Approval Date", "data": "approvalDate" }
{ "title": "Request Date", "data": "requestDate", "render": (data) => formatDateTime(data) }, // Apply formatting here
{ "title": "Approval Date", "data": "approvalDate", "render": (data) => formatDateTime(data) } // Apply formatting here
],
responsive: true,
});

View File

@ -379,7 +379,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
var userRole = await _userManager.GetRolesAsync(user);
var isAdmin = userRole.Contains("SystemAdmin") || userRole.Contains("SuperAdmin") || userRole.Contains("Finance");
List<ItemModel> itemList = new List<ItemModel>();
List<ItemMovementModel> createDate = new List<ItemMovementModel>();
// Get the item list
if (isAdmin)
{
@ -418,15 +418,10 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
// Get the departments list (DepartmentId references Departments)
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
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.UniqueID,
item.CompanyId,
@ -450,7 +445,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
EndWDate = item.EndWDate.ToString("dd/MM/yyyy"),
InvoiceDate = item.InvoiceDate?.ToString("dd/MM/yyyy"),
item.Department?.DepartmentName,
RegisterDate = createDate,
//RegisterDate = createDate,
CreatedBy =item.CreatedBy!.UserName,
item.Product!.ProductName,
item.Product!.ProductShortName,
@ -497,9 +492,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
try
{
var product = await _centralDbContext.Products.FirstOrDefaultAsync(p => p.ProductId == item.ProductId) ?? throw new Exception("Product not found");
var inventoryMaster = await _centralDbContext.InventoryMasters
.Include("User")
.FirstOrDefaultAsync(i => i.UserId == item.CreatedByUserId) ?? new InventoryMasterModel { UserId = item.CreatedByUserId };
var inventoryMaster = await _centralDbContext.InventoryMasters.Include("User").FirstOrDefaultAsync(i => i.UserId == item.CreatedByUserId) ?? new InventoryMasterModel { UserId = item.CreatedByUserId };
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.CreateDate = DateTime.Now;
_centralDbContext.Items.Add(item);
_centralDbContext.Products.Update(product); // Update the product quantity
@ -584,7 +575,6 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
savedItem.EndWDate,
savedItem.InvoiceDate,
savedItem.PartNumber,
CreateDate = savedItem.CreateDate.ToString("dd/MM/yyyy HH:mm:ss")
};
return Json(updatedItem);
}