This commit is contained in:
ArifHilmi 2025-02-26 16:28:14 +08:00
commit 788ab1aa5a
4 changed files with 189 additions and 43 deletions

View File

@ -227,6 +227,11 @@
"title": "Product Name", "title": "Product Name",
"data": "productName", "data": "productName",
}, },
{
"title": "User ID",
"data": "userName",
},
{ {
"title": "Product Category", "title": "Product Category",
"data": "productCategory", "data": "productCategory",
@ -268,10 +273,10 @@
"title": "User Remark", "title": "User Remark",
"data": "remarkUser", "data": "remarkUser",
}, },
{ // {
"title": "InvMaster Remark", // "title": "InvMaster Remark",
"data": "remarkMasterInv", // "data": "remarkMasterInv",
}, // },
{ {
"title": "Status", "title": "Status",
"data": "status", "data": "status",

View File

@ -128,6 +128,7 @@
<option class="btn-light" value="store">Assign to Store</option> <option class="btn-light" value="store">Assign to Store</option>
<option class="btn-light" value="supplier">Assign to Supplier</option> <option class="btn-light" value="supplier">Assign to Supplier</option>
<option class="btn-light" value="faulty">Faulty</option> <option class="btn-light" value="faulty">Faulty</option>
<option class="btn-light" value="receive" hidden>Receive</option>
</select> </select>
</div> </div>
</div> </div>
@ -301,10 +302,28 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</form> </form>
<div v-if="selectedAction === 'receive'">
<form v-on:submit.prevent="receiveItemMovement" data-aos="fade-right">
<div class="row register-form">
<div style="display: flex; justify-content: center; margin-top: 20px;">
<button type="submit" class="btn btn-primary" style="width: 200px; padding: 10px; font-size: 16px;">
Receive
</button>
</div>
</div>
</form>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -374,7 +393,7 @@
this.startScanner(); this.startScanner();
this.fetchUsers(); this.fetchUsers();
this.fetchStores(); this.fetchStores();
// this.fetchItem('ARA00500008'); for testing only. clear this //this.fetchItem('ARA00500008'); // for testing only. clear this
}, },
computed: { computed: {
filteredDepartments() { filteredDepartments() {
@ -420,17 +439,17 @@
const formData = { const formData = {
...(this.selectedAction === 'user' ? { toUser: this.currentUser.id, toOther: 'On Delivery', SendDate: this.assigndate, lastUser: this.selectedUser, MovementComplete: false,} : {}), ...(this.selectedAction === 'user' ? { toUser: this.currentUser.id, toOther: 'On Delivery', SendDate: this.assigndate, lastUser: this.selectedUser, MovementComplete: false,} : {}),
...(this.selectedAction === 'store' ? { toUser: this.currentUser.id, toOther: 'On Delivery', SendDate: this.assigndate, lastUser: this.selectedStore, MovementComplete: false,} : {}), ...(this.selectedAction === 'store' ? { toUser: this.currentUser.id, toOther: 'On Delivery', SendDate: this.assigndate, lastUser: this.selectedStore, MovementComplete: false, ItemId: this.thisItem.itemID, Action: 'Stock Out', Quantity: 1,} : {}),
...(this.selectedAction === 'supplier' ? { toUser: this.currentUser.id, toOther: this.selectedOther, SendDate: this.assigndate, Remark: this.remark + '. Item sent to ' + this.selectedSupplier + ' for ' + this.selectedOther,lastUser: this.currentUser.id, MovementComplete: false, } : {}), ...(this.selectedAction === 'supplier' ? { toUser: this.currentUser.id, toOther: this.selectedOther, SendDate: this.assigndate, Remark: this.remark + '. Item sent to ' + this.selectedSupplier + ' for ' + this.selectedOther,lastUser: this.currentUser.id, MovementComplete: false, ItemId: this.thisItem.itemID, Action: 'Stock Out', Quantity: 1, } : {}),
...(this.selectedAction === 'faulty' ? { toUser: this.currentUser.id,toOther: 'Faulty', Date: new Date(now.getTime() + 8 * 60 * 60 * 1000).toISOString(), Remark: this.remark, ConsignmentNote: this.document, MovementComplete: true, } : {}), ...(this.selectedAction === 'faulty' ? { toUser: this.currentUser.id,toOther: 'Faulty', Date: new Date(now.getTime() + 8 * 60 * 60 * 1000).toISOString(), Remark: this.remark, ConsignmentNote: this.document, MovementComplete: true, ItemId: this.thisItem.itemID, Action: 'Stock Out', Quantity: 1,} : {}),
ItemId: this.thisItem.itemID, ItemId: this.thisItem.itemID,
Action: 'Stock Out', Action: 'Stock Out',
Quantity: 1, Quantity: 1,
}; };
try { try {
// Proceed to send the data to the API // Proceed to send the data to the API
@ -464,11 +483,61 @@
alert('Inventory PSTW Error', `An error occurred: ${error.message}`, 'error'); alert('Inventory PSTW Error', `An error occurred: ${error.message}`, 'error');
} }
},
async receiveItemMovement() {
if (this.showProduct.category == "Disposable") {
this.serialNumber = "";
}
const now = new Date();
const formData = {
Id: this.thisItem.movementId,
ReceiveDate: new Date(now.getTime() + 8 * 60 * 60 * 1000).toISOString(),
};
try {
// Proceed to send the data to the API
const response = await fetch('/InvMainAPI/UpdateItemMovementMaster', {
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');
const updatedItem = await response.json();
// this.items.push(updatedItem);
console.log(updatedItem);
// Reset the form
this.resetForm();
window.location.href = '/Inventory/InventoryMaster/ItemMovement';
} 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');
}
}, },
startScanner() { startScanner() {
const config = { const config = {
fps: 60, fps: 60,
qrbox: 200 qrbox: 400
}; };
navigator.mediaDevices.getUserMedia({ navigator.mediaDevices.getUserMedia({
@ -505,7 +574,13 @@
method: 'POST',} method: 'POST',}
); );
if (response.ok) { if (response.ok) {
// this.thisItem = await response.json();
this.thisItem = await response.json(); this.thisItem = await response.json();
console.log(this.thisItem);
if (this.thisItem.toOther === "Return" && this.thisItem.lastUser == this.currentUserId) {
this.selectedAction = "receive";
}
} else { } else {

View File

@ -548,7 +548,7 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
public async Task<IActionResult> ItemMovementList() public async Task<IActionResult> ItemMovementList()
{ {
var itemMovementList = await _centralDbContext.ItemMovements.ToListAsync(); var itemMovementList = await _centralDbContext.ItemMovements.Include(i => i.NextUser).ToListAsync();
//var itemList = await _centralDbContext.Items.ToListAsync(); //var itemList = await _centralDbContext.Items.ToListAsync();
int itemrow = 0; int itemrow = 0;
@ -556,9 +556,12 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
{ {
id = itemrow++, id = itemrow++,
item, // Includes all properties of the original item item, // Includes all properties of the original item
QRString = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.Value}/I/{item.ItemId}" // Generate QR String QRString = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.Value}/I/{item.ItemId}", // Generate QR String
userName = item.NextUser?.FullName
}).ToList(); }).ToList();
Console.WriteLine(Json(itemMovementList)); //Console.WriteLine(Json(itemMovementList));
//return Json(itemMovementList); //return Json(itemMovementList);
return Json(itemMovementListWithQR); return Json(itemMovementListWithQR);
} }
@ -574,13 +577,13 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
try try
{ {
if (itemmovement.ToUser == null) //if (itemmovement.ToUser == null)
{ //{
throw new Exception("itemmovement.ToUser is null"); // throw new Exception("itemmovement.ToUser is null");
} //}
//var inventoryMaster = await _centralDbContext.InventoryMasters.Include("User").FirstOrDefaultAsync(i => i.UserId == itemmovement.ToUser) ?? new InventoryMasterModel { UserId = itemmovement.ToUser }; //var inventoryMaster = await _centralDbContext.InventoryMasters.Include("User").FirstOrDefaultAsync(i => i.UserId == itemmovement.ToUser) ?? new InventoryMasterModel { UserId = itemmovement.ToUser };
var inventoryMaster = await _centralDbContext.InventoryMasters.FirstOrDefaultAsync(i => i.UserId == itemmovement.ToUser); var inventoryMaster = await _centralDbContext.InventoryMasters.Include("User").FirstOrDefaultAsync(i => i.UserId == itemmovement.ToUser);
if (inventoryMaster != null) if (inventoryMaster != null)
{ {
itemmovement.ToStore = inventoryMaster.StoreId; itemmovement.ToStore = inventoryMaster.StoreId;
@ -633,17 +636,41 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
updateItem.ItemStatus = 8; updateItem.ItemStatus = 8;
} }
Console.WriteLine("updateItem.MovementId" + updateItem.MovementId); //Console.WriteLine("updateItem.MovementId" + updateItem.MovementId);
Console.WriteLine("itemmovement.Id" + itemmovement.Id); //Console.WriteLine("itemmovement.Id" + itemmovement.Id);
updateItem.MovementId = itemmovement.Id; updateItem.MovementId = itemmovement.Id;
_centralDbContext.Items.Update(updateItem); _centralDbContext.Items.Update(updateItem);
}
await _centralDbContext.SaveChangesAsync(); // save changes for table item - movementid await _centralDbContext.SaveChangesAsync(); // save changes for table item - movementid
return Json(itemmovement);
}
return Json(new
{
itemmovement.Id,
itemmovement.ItemId,
itemmovement.ToStation,
itemmovement.ToStore,
itemmovement.ToUser,
itemmovement.ToOther,
itemmovement.sendDate,
itemmovement.Action,
itemmovement.Quantity,
itemmovement.Remark,
itemmovement.ConsignmentNote,
itemmovement.Date,
itemmovement.LastUser,
itemmovement.LastStore,
itemmovement.LastStation,
itemmovement.LatestStatus,
itemmovement.receiveDate,
itemmovement.MovementComplete
});
//return Json(itemmovement);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -652,6 +679,45 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
} }
[HttpPost("UpdateItemMovementMaster")]
public async Task<IActionResult> UpdateItemMovementMaster([FromBody] ItemMovementModel receiveMovement)
{
try
{
var updatedList = await _centralDbContext.ItemMovements.FindAsync(receiveMovement.Id);
if (updatedList == null)
{
return NotFound("Item movement record not found.");
}
updatedList.LatestStatus = "Delivered";
updatedList.receiveDate = receiveMovement.receiveDate;
updatedList.MovementComplete = true;
_centralDbContext.ItemMovements.Update(updatedList);
await _centralDbContext.SaveChangesAsync();
//var receiveItems = await _centralDbContext.Items.FindAsync(receiveMovement.ItemId);
//if (receiveItems != null)
//{
// receiveItems.ItemStatus = 3;
// _centralDbContext.Items.Update(receiveItems);
// await _centralDbContext.SaveChangesAsync(); // Simpan perubahan
//}
return Json(updatedList);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
#endregion ItemMovement #endregion ItemMovement
#region ItemMovementUser #region ItemMovementUser
@ -835,13 +901,13 @@ namespace PSTW_CentralSystem.Controllers.API.Inventory
public async Task<IActionResult> ItemRequestList() public async Task<IActionResult> ItemRequestList()
{ {
var itemRequestList = await _centralDbContext.Requests.Include(i => i.Product).ToListAsync(); var itemRequestList = await _centralDbContext.Requests.Include(i => i.Product).Include(i => i.User).ToListAsync();
return Json(itemRequestList.Select(i => new return Json(itemRequestList.Select(i => new
{ {
i.requestId, i.requestId,
productName = i.Product?.ProductName, productName = i.Product?.ProductName,
i.ProductId, i.ProductId,
i.UserId, userName = i.User?.FullName,
i.status, i.status,
i.StationId, i.StationId,
i.RequestQuantity, i.RequestQuantity,

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB